project QadFinancials > class BPaymentSelection > method StoreSelectedObjects

Description

StoreSelectedObjects


Parameters


iiPaySel_IDinputintegerPaySel_ID
tProposedLineinputtemp-tableProposed Line-PaySelLine records will be created by this dataset. It means that for every selected object a link to payment selection will be created.
tProposedLineStageinputtemp-table
icGlCodeinputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program4/bpaymentselection.p)

find first tPaySel where
           tPaySel.PaySel_ID = iiPaySel_ID
           no-error.

if not available tPaySel
then do:
    <M-3 run SetMessage
       (input  trim(#T-22'The specified payment selection ID ($1) is not defined in the system or is invalid. No record was found with this ID.':100(2996)t-22#) (icMessage), 
        input  string(iiPaySel_ID) (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QADFIN-553':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>

    assign oiReturnStatus = -1.
    return.
end.

/* Get header bank number */
if icGlCode <> "":U and
   icGlCode <> ?
then do:
    <Q-12 run GLPrim (all) (Read) (NoCache)
       (input tPaySel.Company_ID, (CompanyId)
        input icGlCode, (GLCode)
        input ?, (GLId)
        output dataset tqGLPrim) in BGL>

    find first tqGLPrim
               no-error.
end.

if icGlCode = "":U or
   icGlCode = ?    or
   not available tqGLPrim
then do:
    <M-13 run SetMessage
       (input  trim(#T-23'The specified bank account code $1 is invalid.':80(2997)t-23#) (icMessage), 
        input  icGlCode (icArguments), 
        input  'tPaySel.tcGLCode':U (icFieldName), 
        input  tPaySel.tcGLCode (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QADFIN-1341':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>

    assign oiReturnStatus = -1.
    return.
end.

/* Get bank country and currency code */
<M-14 run GetBankCntryByGL
   (input  tqGLPrim.tiGL_ID (iiBankGL_Id), 
    output vcBankCurrency (ocCurrency), 
    output vcBankCountry (ocBankCountry), 
    output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>

if viFcReturnSuper < 0 or
   oiReturnStatus  = 0
then assign oiReturnStatus = viFcReturnSuper.

if oiReturnStatus < 0
then return.

empty temp-table tPaySelPrepayRefPS.

for each tPaySelLine where
         tPaySelLine.tc_Status = "N":U:
    assign tPaySelLine.tc_Status = "":U.
end.

assign vlQPP = false.

<M-27 run CalculatePaySelLine
   (input  yes (ilPrepaymentOnly), 
    output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>

assign vlStart1 = false.

for each tProposedLine where
        (tProposedLine.tc_Status = "N":U  or
         tProposedLine.tc_Status = "C":U) and
         tProposedLine.tlProposedLineIsSelected:
         
    if tProposedLine.tc_Status = "N":U and
      (not can-find(first tPaySelLine where
                          tPaySelLine.tc_ParentRowid            = tPaySel.tc_Rowid          and
                          tPaySelLine.tc_Status                <> "D":U                     and
                          tPaySelLine.PaySelLineParentObject_ID = tProposedLine.tiObject_ID and
                          tPaySelLine.PaySelLineObjectType      = tProposedLine.tcObjectType) or
       tProposedLine.tlIsMultiple = true)
    then do:
        /* for every selected proposed line create PaySelLine */
        <M-1 run AddDetailLine (input  'PaySelLine':U (icTable), 
                        input  tPaySel.tc_Rowid (icParentRowid), 
                        output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>

        if viFcReturnSuper < 0 or
           oiReturnStatus  = 0
        then assign oiReturnStatus = viFcReturnSuper.

        if oiReturnStatus < 0
        then return.
    end.
    else do:
        find first tPaySelLine where
                   tPaySelLine.tc_ParentRowid            = tPaySel.tc_Rowid          and
                   tPaySelLine.PaySelLineParentObject_ID = tProposedLine.tiObject_ID and
                   tPaySelLine.PaySelLineObjectType      = tProposedLine.tcObjectType
                   no-error.

        if not available tPaySelLine
        then do:
            <M-4 run SetMessage
               (input  trim(#T-25'The payment selection line to update was not found (object ID = $1).':200(2999)t-25#) (icMessage), 
                input  string(tProposedLine.tiObject_ID) (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QADFIN-576':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>

            assign oiReturnStatus = -1.
            return.
        end.
    end.

    assign tPaySelLine.PaySelLineParentObject_ID     = tProposedLine.tiObject_ID
           tPaySelLine.PaySelLineObjectType          = tProposedLine.tcObjectType
           tPaySelLine.tlProposedLineIsSelected      = tProposedLine.tlProposedLineIsSelected
           tPaySelLine.BankNumber_ID                 = tProposedLine.tiBankNumber_ID
           tPaySelLine.tcExternalNumber              = tProposedLine.tcExternalNumber
           tPaySelLine.tcInternalNumber              = tProposedLine.tcInternalNumber
           tPaySelLine.tcCreditorCode                = tProposedLine.tcCreditorCode
           tPaySelLine.tcBusinessRelationCode        = tProposedLine.tcBusinessRelationCode
           tPaySelLine.tcInvoiceCurrencyCode         = tProposedLine.tcInvoiceCurrencyCode
           tPaySelLine.ttInvoiceDate                 = tProposedLine.ttInvoiceDate
           tPaySelLine.tiInvoiceCompany_ID           = tProposedLine.tiInvoiceCompany_ID
           tPaySelLine.tc_Status                     = tProposedLine.tc_Status
           tPaySelLine.PaySelLineAmountTC            = tProposedLine.tdPaymentAmountTC
           tPaySelLine.PaySelLineDiscountTC          = tProposedLine.tdDiscountTC
           tPaySelLine.PaySelLineIntAmtTC            = tProposedLine.tdInterestTC
           tPaySelLine.tdOpenInvoiceAmountTC         = tProposedLine.tdOpenInvoiceAmountTC 
           tPaySelLine.tdInitiallyAllocatedWHTAmntTC = tProposedLine.tdInitiallyAllocatedWHTAmntTC
           tPaySelLine.tcInvoiceCrDt                 = tProposedLine.tcOpenInvAmntDebitCreditAbbr
           tPaySelLine.tcPaymentCrDt                 = tProposedLine.tcPaymentAmntDebitCreditAbbr
           tPaySelLine.tcDivisionCode                = tProposedLine.tcDivisionCode
           tPaySelLine.PaySelLineWHTAmtTC            = tProposedLine.tdWHTAmtTC
           tPaySelLine.PaySelLineWHTAmtLC            = tProposedLine.tdWHTAmtLC
           tPaySelLine.PaySelLineWHTAmtCC            = tProposedLine.tdWHTAmtCC
           tPaySelLine.tdWHTTaxableFeeTC             = tProposedLine.tdWHTTaxableFeeTC
           tPaySelLine.tdWHTTCLCExchangeRate         = tProposedLine.tdWHTTCLCExchangeRate
           tPaySelLine.tdWHTTCLCRateScale            = tProposedLine.tdWHTTCLCRateScale
           tPaySelLine.tdWHTTCCCExchangeRate         = tProposedLine.tdWHTTCCCExchangeRate
           tPaySelLine.tdWHTTCCCRateScale            = tProposedLine.tdWHTTCCCRateScale
           tPaySelLine.tdTotWHTAmtTC                 = tProposedLine.tdTotWHTAmtTC
           tPaySelLine.tdTotWHTAmtLC                 = tProposedLine.tdTotWHTAmtLC
           tPaySelLine.tdCInvoiceTotWHTBaseTC        = tProposedLine.tdCInvoiceTotWHTBaseTC
           tPaySelLine.tdWHTPerc                     = tProposedLine.tdWHTPerc
           tPaySelLine.tlUpdateTax                   = tProposedLine.tlUpdateTax
           tPaySelLine.tdCInvoiceWHTAmtTC            = tProposedLine.tdCInvoiceWHTAmtTC
           tPaySelLine.tdCInvoiceOriginalTC          = tProposedLine.tdCInvoiceOriginalTC
           tPaySelLine.tdCInvoiceTotWHTTC            = tProposedLine.tdCInvoiceTotWHTTC.

    /* process the stage records */                             
    for each tProposedLineStage
        where tProposedLineStage.tiProposedLine_ID = tProposedLine.tiProposedLine_ID and
              tProposedLineStage.tiObject_ID       = tProposedLine.tiObject_ID:

            for first tPaySelLineStage 
                where tPaySelLineStage.tc_ParentRowid = tPaySelLine.tc_Rowid
                    and tPaySelLineStage.CInvoiceStage_ID = tProposedLineStage.tiCInvoiceStage_ID:
                if tProposedLine.tc_Status = "D":U
                then assign tPaySelLineStage.tc_Status = tProposedLine.tc_Status.
                else if vcActivityCode = {&PAYMENTSELECTIONACTIVITY-MODIFY}
                then assign tPaySelLineStage.tc_Status = "C":U.
            end.

            if not available tPaySelLineStage
            then do:
                <M-42 run AddDetailLine
                   (input  'PaySelLineStage':U (icTable), 
                    input  tPaySelLine.tc_rowid (icParentRowid), 
                    output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
                  if viFcReturnSuper < 0 or
                      oiReturnStatus  = 0
                  then assign oiReturnStatus = viFcReturnSuper.
    
                 if oiReturnStatus < 0
                then return.
            end.
            
            assign 
                tPaySelLineStage.CInvoiceStage_ID          = tProposedLineStage.tiCInvoiceStage_ID
                tPaySelLineStage.PaySelLine_ID             = tPaySelLine.PaySelLine_ID                
                tPaySelLineStage.PaySelLineStageDiscAmntTC = tProposedLineStage.tdStageDiscountAmountTC
                tPaySelLineStage.PaySelLineStageIntAmtTC   = tProposedLineStage.tdStageInterestAmountTC
                tPaySelLineStage.PaySelLineStageOpenAmntTC = tProposedLineStage.tdOpenStageAmountTC
                tPaySelLineStage.PaySelLineStageOrigAmntTC = tProposedLineStage.tdOriginalStageAmounTC
                tPaySelLineStage.PaySelLineStagePaymAmntTC = tProposedLineStage.tdStagePaymentAmountTC
                tPaySelLineStage.PaySelLineStageWHTAmtTC   = tProposedLineStage.tdWHTAmtTC. 
   end.                             

    /* Get the diskette format in order to split the collections */
    if tPaySelLine.BankNumber_ID <> ? and
       tPaySelLine.BankNumber_ID <> 0 and
       tPaySelLine.BankNumber_ID <> -999999
    then do:           
        
        <Q-45 run BankNumberPrim (all) (Read) (NoCache)
           (input tPaySelLine.BankNumber_ID, (BankNumberId)
            input ?, (ParentObjectId)
            input '':U, (BankNumber)
            input '':U, (BankNumberExtension)
            input ?, (BankPayFormatID)
            output dataset tqBankNumberPrim) in BBankNumber>
         
        find first tqBankNumberPrim no-error.

        if available tqBankNumberPrim and
           tqBankNumberPrim.tiBankPayFormat_ID <> ? and
           tqBankNumberPrim.tiBankPayFormat_ID <> 0
        then do:
            
            <Q-46 run BankPayFormatPrim (all) (Read) (NoCache)
               (input ?, (BankNumberId)
                input tqBankNumberPrim.tiBankPayFormat_ID, (BankPayFormatId)
                input ?, (PayFormatTypeCode)
                output dataset tqBankPayFormatPrim) in BBankPayFormat>

            for first tqBankPayFormatPrim:
                assign tPaySelLine.PayFormatTypeCode = tqBankPayFormatPrim.tcPayFormatTypeCode.
            end.
        end.
    end.

    if  tProposedLine.tcObjectType = {&PAYMENTSELECTIONTYPE-PREPAYMENT}
    then do:
        if tProposedLine.tc_Status = "N":U and
           not can-find(tPaySelPrepayRefPS where
                        tPaySelPrepayRefPS.PaySelPrepay_ID = tProposedLine.tiObject_ID)
        then do:
            create tPaySelPrepayRefPS.

            assign viPrepayment_ID                       = viPrepayment_ID - 1
                   tPaySelPrepayRefPS.PaySelPrepay_ID      = viPrepayment_ID
                   tPaySelPrepayRefPS.tc_Rowid             = string(viPrepayment_ID)
                   tPaySelLine.PaySelLineParentObject_ID = viPrepayment_ID.
        end.
        else do:
            find first tPaySelPrepayRefPS where
                       tPaySelPrepayRefPS.PaySelPrepay_ID = tProposedLine.tiObject_ID
                       no-error.

            if not available tPaySelPrepayRefPS
            then do:
                <M-5 run SetMessage
                   (input  trim(#T-26'The prepayment to update was not found (object ID = $1).':200(3000)t-26#) (icMessage), 
                    input  string(tProposedLine.tiObject_ID) (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'D':U (icType), 
                    input  3 (iiSeverity), 
                    input  '':U (icRowid), 
                    input  'QADFIN-577':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>

                assign oiReturnStatus = -1.
                return.
            end.
        end.

        assign tPaySelPrepayRefPS.tcBusinessRelationCode    = tProposedLine.tcBusinessRelationCode
               tPaySelPrepayRefPS.tcCurrencyCode            = tProposedLine.tcInvoiceCurrencyCode
               tPaySelPrepayRefPS.tcCreditorCode            = tProposedLine.tcCreditorCode
               tPaySelPrepayRefPS.PaySelPrepayReferenceText = tProposedLine.tcExternalNumber
               tPaySelPrepayRefPS.tc_Status                 = tProposedLine.tc_Status
               tPaySelPrepayRefPS.PaySelPrepayAmountToPayTC = tProposedLine.tdPaymentAmountTC.
    end.
end.

for each tProposedLine where
         tProposedLine.tlProposedLineIsSelected = false:
    find first tPaySelLine where
               tPaySelLine.tc_ParentRowid            = tPaySel.tc_Rowid          and
               tPaySelLine.PaySelLineParentObject_ID = tProposedLine.tiObject_ID and
               tPaySelLine.PaySelLineObjectType      = tProposedLine.tcObjectType and 
               tPaySelLine.BankNumber_ID  = tProposedLine.tiBankNumber_ID
                no-error.

    if not available tPaySelLine
    then next.

    if tPaySelLine.tc_Status = "N":U or
       tPaySelLine.tc_Rowid begins "-":U
    then assign tPaySelLine.tc_Status = "":U.
    else assign tPaySelLine.tc_Status = "D":U.
    
    assign tPaySelLine.tlProposedLineIsSelected  = tProposedLine.tlProposedLineIsSelected.

    if tProposedLine.tcObjectType = {&PAYMENTSELECTIONTYPE-PREPAYMENT}
    then do:
        find first tPaySelPrepayRefPS where
                   tPaySelPrepayRefPS.PaySelPrepay_ID = tProposedLine.tiObject_ID
                   no-error.

        if available tPaySelPrepayRefPS
        then assign tPaySelPrepayRefPS.tc_Status = "D":U.
    end.
end.