project QadFinancials > class BERSProcessor > method GetERSPendingVouchersERSOpt

Description

Calculate ERS Option for one receipt line.


Parameters


icCreditorCodeinputcharacter
icSiteCodeinputcharacter
icPartCodeinputcharacter
biERSOptioninput-outputinteger
biERSPriceListOptioninput-outputinteger
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BERSProcessor.GetERSLegalDocumentsLC
method BERSProcessor.GetERSLegalDocumentsNoLC
method BERSProcessor.GetERSPendingVouchersPORec


program code (program5/bersprocessor.p)

/* =================================================================================================== */
/* Method      : GetERSPendingVocuherERSOpt                                                            */
/* Desc        : Calculate ERS Option for pending voucher                                              */
/* --------------------------------------------------------------------------------------------------- */
/* Params:  (I)  CreditorCode         Code of creditor (vendor)                                        */
/*          (I)  SiteCode             Code of site                                                     */
/*          (I)  PartCode             Code of item                                                     */
/*          (IO) ERSOption            ERS option (input values comes from purchase order detail,       */
/*                                    output value is calcuated based input values and hiearchical     */
/*                                    definition)                                                      */
/*                                    0 - input - calcualate ERS Option for Creditor, Site, Item       */
/*                                    1 - input - output - No ERS Processing                           */
/*                                    2 - input - output - Create SI in Initial Status                 */
/*                                    3 - input - output - Create SI in Finished Status                */
/* =================================================================================================== */


/* =================================================================================================== */
/* Precondition - does calculation only if needed (when 0 - calculate ERS option just now)             */
/* =================================================================================================== */
if biERSOption <> 0 then return.

/* =================================================================================================== */
/* Default values                                                                                      */
/* =================================================================================================== */
assign biERSOption = 3.

assign oiReturnStatus = -98.

/* =================================================================================================== */
/* Get ERS Options by Vendor, Site and Item                                                            */
/* =================================================================================================== */
if icPartCode <> ? and icPartCode <> "":U
then do:   
    <Q-2 run ERSMasterByVendSiteItem (all) (Read) (NoCache)
       (input vcDomainCode, (Domain)
        input icCreditorCode, (Vendor)
        input icSiteCode, (Site)
        input icPartCode, (Item)
        output dataset tqERSMasterByVendSiteItem) in BMfgERSMaster >
    find first tqERSMasterByVendSiteItem where
               tqERSMasterByVendSiteItem.tcers_domain = vcDomainCode   and
               tqERSMasterByVendSiteItem.tcers_vend   = icCreditorCode and
               tqERSMasterByVendSiteItem.tcers_site   = icSiteCode     and
               tqERSMasterByVendSiteItem.tcers_part   = icPartCode no-error.
    if available tqERSMasterByVendSiteItem
    then do:
        assign biERSOption          = tqERSMasterByVendSiteItem.tiers_opt
               biERSPriceListOption = tqERSMasterByVendSiteItem.tiers_pr_lst_tp
               oiReturnStatus       = max(0, oiReturnStatus).
        return.
    end.
end. /* if icPartCode <> ? and */

/* =================================================================================================== */
/* Get ERS Options by Vendor and Site                                                                  */
/* =================================================================================================== */
<Q-4 run ERSMasterByVendSiteItem (all) (Read) (NoCache)
   (input vcDomainCode, (Domain)
    input icCreditorCode, (Vendor)
    input icSiteCode, (Site)
    input '':U, (Item)
    output dataset tqERSMasterByVendSiteItem) in BMfgERSMaster >
find first tqERSMasterByVendSiteItem where
           tqERSMasterByVendSiteItem.tcers_domain = vcDomainCode   and
           tqERSMasterByVendSiteItem.tcers_vend   = icCreditorCode and
           tqERSMasterByVendSiteItem.tcers_site   = icSiteCode     and
           tqERSMasterByVendSiteItem.tcers_part   = '':U no-error.
if available tqERSMasterByVendSiteItem
then do:
    assign vlERSVendFound       = true
           biERSOption          = minimum(biERSOption, tqERSMasterByVendSiteItem.tiers_opt)
           biERSPriceListOption = tqERSMasterByVendSiteItem.tiers_pr_lst_tp
           oiReturnStatus       = max(0, oiReturnStatus).
    return.
end.

/* =================================================================================================== */
/* Get ERS Options by Vendor and Item                                                                  */
/* =================================================================================================== */
if icPartCode <> ? and icPartCode <> "":U
then do:
    <Q-11 run ERSMasterByVendSiteItem (all) (Read) (NoCache)
       (input vcDomainCode, (Domain)
        input icCreditorCode, (Vendor)
        input '':U, (Site)
        input icPartCode, (Item)
        output dataset tqERSMasterByVendSiteItem) in BMfgERSMaster>
    find first tqERSMasterByVendSiteItem where
               tqERSMasterByVendSiteItem.tcers_domain = vcDomainCode   and
               tqERSMasterByVendSiteItem.tcers_vend   = icCreditorCode and
               tqERSMasterByVendSiteItem.tcers_site   = '':U           and
               tqERSMasterByVendSiteItem.tcers_part   = icPartCode no-error.
    if available tqERSMasterByVendSiteItem
    then do:
        assign vlERSVendFound         = true
               biERSOption          = minimum(biERSOption, tqERSMasterByVendSiteItem.tiers_opt)
               biERSPriceListOption = tqERSMasterByVendSiteItem.tiers_pr_lst_tp.
    end.
end.    

/* =================================================================================================== */
/* Get ERS Options by Site                                                                             */
/* =================================================================================================== */
<Q-5 run ERSMasterByVendSiteItem (all) (Read) (NoCache)
   (input vcDomainCode, (Domain)
    input '':U, (Vendor)
    input icSiteCode, (Site)
    input '':U, (Item)
    output dataset tqERSMasterByVendSiteItem) in BMfgERSMaster >
find first tqERSMasterByVendSiteItem where
           tqERSMasterByVendSiteItem.tcers_domain = vcDomainCode   and
           tqERSMasterByVendSiteItem.tcers_vend   = '':U           and
           tqERSMasterByVendSiteItem.tcers_site   = icSiteCode     and
           tqERSMasterByVendSiteItem.tcers_part   = '':U no-error.
if available tqERSMasterByVendSiteItem
then do:
    assign vlERSSiteFound = true
           biERSOption    = minimum(biERSOption, tqERSMasterByVendSiteItem.tiers_opt).
    if vlERSVendFound
    then do:
        assign oiReturnStatus = max(0, oiReturnStatus).
        return.
    end.
end.

/* =================================================================================================== */
/* Get ERS Options by Supplier                                                                         */
/* =================================================================================================== */
<Q-6 run ERSMasterByVendSiteItem (all) (Read) (NoCache)
   (input vcDomainCode, (Domain)
    input icCreditorCode, (Vendor)
    input '':U, (Site)
    input '':U, (Item)
    output dataset tqERSMasterByVendSiteItem) in BMfgERSMaster >
find first tqERSMasterByVendSiteItem where
           tqERSMasterByVendSiteItem.tcers_domain = vcDomainCode   and
           tqERSMasterByVendSiteItem.tcers_vend   = icCreditorCode and
           tqERSMasterByVendSiteItem.tcers_site   = '':U           and
           tqERSMasterByVendSiteItem.tcers_part   = '':U no-error.
if available tqERSMasterByVendSiteItem
then do:
    assign vlERSVendFound = true
           biERSOption          = minimum(biERSOption, tqERSMasterByVendSiteItem.tiers_opt)
           biERSPriceListOption = tqERSMasterByVendSiteItem.tiers_pr_lst_tp.
    if vlERSSiteFound
    then do:
        assign oiReturnStatus = max(0, oiReturnStatus).
        return.
    end.
end.

/* =================================================================================================== */
/* Raise Error if not ERS definition found                                                             */
/* =================================================================================================== */
if not vlERSSiteFound
then do:
    assign vcMessage = #T-7'The ERS definition for site &1 is not defined.':255(70341)t-7#
           vcMessage = substitute(vcMessage, icSiteCode).
    <M-8 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-8368':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
    assign oiReturnStatus = -1.
end.

if not vlERSVendFound
then do:
    assign vcMessage = #T-10'The ERS definition for supplier &1 is not defined.':255(70342)t-10#
           vcMessage = substitute(vcMessage, icCreditorCode).
    <M-9 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-8369':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
    assign oiReturnStatus = -1.
end.

/* =================================================================================================== */
/* Because we failed to find ERS definition - exclude this from ERS processing                         */
/* =================================================================================================== */
assign biERSOption = 1.

/* =================================================================================================== */
/* Return                                                                                              */
/* =================================================================================================== */
if oiReturnStatus = -98 then assign oiReturnStatus = 0.