project QadFinancials > class BBankEntry > method CreatePrepayment

Description

Create a prepayment record : new record will be created in the grid nl tBankStateAlloc...., called by UI when pressing OK in Prepayment window


Parameters


icCodeinputcharacterCode : can be creditor, debtor or employee
iiIdinputintegerId of the code
icInvoiceOrigininputcharacterInvoice Origin
itInvoiceDateinputdateInvoice Date
itInvoiceDueDateinputdateInvoice Due Date
idPrepaymentAmountTCinputdecimalPrepaymentAmount in TC
icInvoiceCurrencyCodeinputcharacterInvoice Currency Code
idPrepaymentExchangeRateinputdecimalPrepayment Exchange Rate
idPrepaymentExchRateScaleinputdecimal
idPrepaymentAmountLCinputdecimalPrepayment Amount in LC
icNewBalanceCrDtinputcharacterSign of new balance nl debit or credit
icBankCurrencyCodeinputcharacterBank Currency Code
icRowIdinputcharacterRowId of Bank State Line
iiPostingIdinputintegerPosting ID of BankStateLine
icDescriptioninputcharacterdescription of prepayment
icDivisionCodeinputcharacterSub-Account
icProjectCodeinputcharacterproject
icCostCentreinputcharactercost centre
idBankStateLineExtBankRateinputdecimal
idBankStateLineExtRateScaleinputdecimal
icBankStateLineExtCurrencyinputcharacter
tPossibleBankStateAllocoutputtemp-tablethe newly created record.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program3/bbankentry.p)

/*JBA BTS 4906 use the correct exchange rate type*/
    assign vcExchangeRateType = <M-17 GetExchangeRateType () in BBankEntry>.

    assign vdExchangeRate       = 0
           vdExchangeRateScale  = 0.
    empty temp-table tPossibleBankStateAlloc.

    /* ====================== */
    /* replace unknown values */
    /* ====================== */
    if iiId = ? then assign iiId = 0.
    if icCode = ? then assign icCode = "":U.
    if icInvoiceOrigin = ? then assign icInvoiceOrigin = "":U.
    if idPrepaymentAmountTC = ? then assign idPrepaymentAmountTC = 0.
    if icInvoiceCurrencyCode = ? then assign icInvoiceCurrencyCode = "":U.
    if idPrepaymentExchangeRate = ? then assign idPrepaymentExchangeRate = 0.
    if idPrepaymentAmountLC = ? then assign idPrepaymentAmountLC = 0.
    if icNewBalanceCrDt = ? then assign icNewBalanceCrDt = "":U.
    if icBankCurrencyCode = ? then assign icBankCurrencyCode = "":U.
    if icRowId = ? then assign icRowId = "":U.
    if iiPostingId = ? then assign iiPostingId = 0.
    if icDescription = ? then assign icDescription = "":U.
    if icDivisionCode = ? then assign icDivisionCode = "":U.
    if icProjectCode = ? then assign icProjectCode = "":U.
    if icCostCentre = ? then assign icCostCentre = "":U.

    /* ========================= */
    /* validate input parameters */
    /* ========================= */
    if icInvoiceOrigin <> {&INVOICEORIGIN-CREDITOR} and 
       icInvoiceOrigin <> {&INVOICEORIGIN-DEBTOR}   and 
       icInvoiceOrigin <> {&INVOICEORIGIN-EMPLOYEE} 
    then do:
        assign vcMessage      = trim(substitute(#T-14'The following are valid options for the origin of the prepayment: &1, &2, &3.':150(325)T-14#,{&INVOICEORIGIN-CREDITOR-TR},{&INVOICEORIGIN-DEBTOR-TR},{&INVOICEORIGIN-EMPLOYEE-TR}))
               oiReturnStatus = -3.
        <M-2 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-742':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
        return.
    end.

    if icCode = "":U and iiId = 0
    then do:
        assign
            vcFieldName    = if icInvoiceOrigin = {&INVOICEORIGIN-CREDITOR} then {&INVOICEORIGIN-CREDITOR-TR}
                             else if icInvoiceOrigin = {&INVOICEORIGIN-DEBTOR} then {&INVOICEORIGIN-DEBTOR-TR}
                             else if icInvoiceOrigin = {&INVOICEORIGIN-EMPLOYEE} then {&INVOICEORIGIN-EMPLOYEE-TR}
                             else "":U
            vcMessage      = trim(substitute(#T-26'You must enter the &1 Code.':150(71315)T-26#, vcFieldName))
            oiReturnStatus = -3.
        <M-25 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  #T-27'Customer/Supplier':20(71316)T-27# (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QadFin-8687':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
        return.
    end.

    /* ======================================================= */
    /* create a record in the grid and fill the default fields */
    /* ======================================================= */
    create tPossibleBankStateAlloc.
    assign tPossibleBankStateAlloc.Company_ID               = viCompanyId
           tPossibleBankStateAlloc.tcCompanyCode            = vcCompanyCodeBE
           tPossibleBankStateAlloc.Posting_ID               = iiPostingId
           tPossibleBankStateAlloc.BankStateAllocAmountTC   =  <M-18 RoundAmount
                                                                  (input  idPrepaymentAmountTC (idUnroundedAmount), 
                                                                   input  0 (iiCurrencyID), 
                                                                   input  icInvoiceCurrencyCode (icCurrencyCode)) in BApplicationProperty>
           tPossibleBankStateAlloc.tcCurrencyCode           = icBankCurrencyCode
           tPossibleBankStateAlloc.tcAllocAmountCrDt        = icNewBalanceCrDt
           tPossibleBankStateAlloc.tdDocBalance             = 0
           tPossibleBankStateAlloc.tcDocCredDebEmplCode     = icCode
           tPossibleBankStateAlloc.tiDocCredDebEmplId       = iiId
           tPossibleBankStateAlloc.tcDocCurrencyCode        = icInvoiceCurrencyCode
           tPossibleBankStateAlloc.tcDocBalanceCrDt         = icNewBalanceCrDt
           tPossibleBankStateAlloc.tdDocExchangeRate        = idPrepaymentExchangeRate
           tPossibleBankStateAlloc.tdDocExchangeRateScale   = idPrepaymentExchRateScale
           tPossibleBankStateAlloc.tcDocDescription         = icDescription
           tPossibleBankStateAlloc.tcDocDivisionCode        = icDivisionCode
           tPossibleBankStateAlloc.tcDocProjectCode         = icProjectCode
           tPossibleBankStateAlloc.tcDocCostCentreCode      = icCostCentre
           tPossibleBankStateAlloc.BankStateAllocAmountLC   = <M-19 RoundAmount
                                                                 (input  idPrepaymentAmountLC (idUnroundedAmount), 
                                                                  input  viCompanyLCId (iiCurrencyID), 
                                                                  input  vcCompanyLC (icCurrencyCode)) in business>
           tPossibleBankStateAlloc.ttDocDueDate             = itInvoiceDueDate
           tPossibleBankStateAlloc.ttDocInvDate             = itInvoiceDate
           tPossibleBankStateAlloc.tcDocNumberReference     = trim(string(viBankPostingYear)) + "/":U + trim(vcBankPostingJournalCode) + "/":U + string(viBankPostingVoucher,"999999999":U)
           tPossibleBankStateAlloc.tdNewBalanceTC           = <M-20 RoundAmount
                                                                 (input  idPrepaymentAmountTC (idUnroundedAmount), 
                                                                  input  0 (iiCurrencyID), 
                                                                  input  icInvoiceCurrencyCode (icCurrencyCode)) in business>
           tPossibleBankStateAlloc.tcNewBalanceCrDt         = icNewBalanceCrDt
           tPossibleBankStateAlloc.CInvoice_ID              = 0
           tPossibleBankStateAlloc.DInvoice_ID              = 0
           /* give those fields a valid value, otherwise errors on save */
           tPossibleBankStateAlloc.tcCurrDifferenceCrDt     = {&CREDITDEBITABBREVIATION-CREDIT}
           tPossibleBankStateAlloc.tcCollBalanceCrDt        = {&CREDITDEBITABBREVIATION-CREDIT}
           tPossibleBankStateAlloc.tcCCCurrDifferenceCrDt   = {&CREDITDEBITABBREVIATION-CREDIT}
           tPossibleBankStateAlloc.tcInvoiceDescription     = icDescription /*CA704890*/
           tPossibleBankStateAlloc.tcDInvoiceDIText         = trim(string(viBankPostingYear)) + "/":U + trim(vcBankPostingJournalCode) + "/":U + string(viBankPostingVoucher,"999999999":U).
                 
    if tPossibleBankStateAlloc.BankStateAllocAmountLC = 0
    then do:
        if icBankCurrencyCode = vcCompanyLC
        then assign tPossibleBankStateAlloc.BankStateAllocAmountLC = <M-21 RoundAmount
              (input  tPossibleBankStateAlloc.BankStateAllocAmountTC (idUnroundedAmount), 
               input  viCompanyLCId (iiCurrencyID), 
               input  vcCompanyLC (icCurrencyCode)) in business>.
    
        else do:
            <M-95 run GetExchangeRate
               (input  viCompanyId (iiCompanyID), 
                input  ? (iiFromCurrencyID), 
                input  icBankCurrencyCode (icFromCurrencyCode), 
                input  viCompanyLCId (iiToCurrencyID), 
                input  ? (icToCurrencyCode), 
                input  ? (iiExchangeRateTypeID), 
                input  vcExchangeRateType (icExchangeRateTypeCode), 
                input  itInvoiceDate (itValidityDate), 
                output vdExchangeRate (odExchangeRate), 
                output vdExchangeRateScale (odExchangeScaleFactor), 
                output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
            if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
             then assign oiReturnStatus = viFcReturnSuper. 
    
             assign tPossibleBankStateAlloc.BankStateAllocAmountLC = <M-22 RoundAmount
              (input  tPossibleBankStateAlloc.BankStateAllocAmountTC * vdExchangeRate * vdExchangeRateScale (idUnroundedAmount), 
               input  viCompanyLCId (iiCurrencyID), 
               input  vcCompanyLC (icCurrencyCode)) in business>.
         end.
    end.
    /* ============================================= */
    /* fill the fields that are coming from creditor */
    /* ============================================= */
    case icInvoiceOrigin :
        when {&INVOICEORIGIN-CREDITOR}
        then do:
            <Q-3 run CreditorByCreditor (first) (Read) (NoCache)
               (input iiId, (CreditorId)
                input viCompanyId, (CompanyId)
                input if iiId = 0 then icCode else '':U, (CreditorCode)
                input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressType)
                output dataset tqCreditorByCreditor) in BCreditor >
            find first tqCreditorByCreditor no-error.
            if not available tqCreditorByCreditor
            then do:
                assign vcMessage      = trim(#T-15'The specified supplier is not defined in the system.':150(326)T-15#)
                       oiReturnStatus = -3.
                <M-4 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-744':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
                return.
            end.

            /* Validate that cost centre, project, and division are specified when required by the control account */
            <M-23 run ValidateCCProjDivForControlGL
               (input  tqCreditorByCreditor.tiPrePayControlGLProfile_ID (iiPrePayControlGLProfileId), 
                input  icCostCentre (icCostCentreCode), 
                input  icProjectCode (icProjectCode), 
                input  icDivisionCode (icDivisionCode), 
                output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
         
            if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
            then assign oiReturnStatus = viFcReturnSuper.

            assign tPossibleBankStateAlloc.BankStateAllocType        = {&BANKSTATEALLOCTYPE-NCINV}
                   tPossibleBankStateAlloc.tcDocBusinessRelationCode = tqCreditorByCreditor.tcBusinessRelationCode.
        end.
        
        /* =========================================== */
        /* fill the fields that are coming from debtor */
        /* =========================================== */
        when {&INVOICEORIGIN-DEBTOR}
        then do:
            <Q-8 run DebtorByDebtor (first) (Read) (NoCache)
               (input viCompanyId, (CompanyId)
                input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressType)
                input iiId, (DebtorId)
                input if iiId = 0 then icCode else '':U, (DebtorCode)
                output dataset tqDebtorByDebtor) in BDebtor >
            find first tqDebtorByDebtor no-error.
            if not available tqDebtorByDebtor
            then do:
                assign vcMessage      = trim(#T-16'The specified customer is not defined in the system.':150(327)T-16#)
                       oiReturnStatus = -3.
                <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-750':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
                return.
            end.
            
            /* Validate that cost centre, project, and division are specified when required by the control account */
            <M-24 run ValidateCCProjDivForControlGL
               (input  tqDebtorByDebtor.tiPrePayControlGLProfile_ID (iiPrePayControlGLProfileId), 
                input  icCostCentre (icCostCentreCode), 
                input  icProjectCode (icProjectCode), 
                input  icDivisionCode (icDivisionCode), 
                output viFcReturnSuper (oiReturnStatus)) in BBankEntry>

            if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
            then assign oiReturnStatus = viFcReturnSuper.

            assign tPossibleBankStateAlloc.BankStateAllocType        = {&BANKSTATEALLOCTYPE-NDINV}
                   tPossibleBankStateAlloc.tcDocBusinessRelationCode = tqDebtorByDebtor.tcBusinessRelationCode.
        end.
    end case.

    /* =============================================== */
    /* fill in the other fields based on previous ones */
    /* =============================================== */
    <M-6 run DefaultBankStateAllocBank
       (input  tPossibleBankStateAlloc.tcDocCurrencyCode (icDocCurrencyCode), 
        input  icBankCurrencyCode (icCurrencyCode), 
        input  idBankStateLineExtBankRate (idBankStateLineExtBankRate), 
        input  idBankStateLineExtRateScale (idBankStateLineExtBankRateScale), 
        input  icBankStateLineExtCurrency (icBankStateLineExtCurrency), 
        input  idPrepaymentAmountTC (idBankStateAllocAmountTC), 
        input  idPrepaymentAmountLC (idBankStateAllocAmountLC), 
        input  0 (idBankStateAllocDiscountTC), 
        input  0 (idBankStateAllocDiscountLC), 
        input  itInvoiceDate (itBankStateLineValueDate), 
        input  idPrepaymentExchangeRate (idDocExchangeRate), 
        input  idPrepaymentExchRateScale (idDocExchangeRateScale), 
        input  true (ilIsPrepayment), 
        input  tPossibleBankStateAlloc.BankStateAllocWHTAmtTC (idBankStateAllocWHTAmtTC), 
        output tPossibleBankStateAlloc.BankStateAllocBankAmountTC (odBankStateAllocBankAmountTC), 
        output tPossibleBankStateAlloc.BankStateAllocBankAmountLC (odBankStateAllocBankAmountLC), 
        output tPossibleBankStateAlloc.BankStateAllocBankRate (odBankStateAllocBankRate), 
        output tPossibleBankStateAlloc.BankStateAllocBankValDate (otBankStateAllocBankValueDate), 
        output tPossibleBankStateAlloc.BankStateAllocBankDiscTC (odBankStateAllocBankDiscTC), 
        output tPossibleBankStateAlloc.BankStateAllocBankDiscLC (odBankStateAllocBankDiscLC), 
        output tPossibleBankStateAlloc.BankStateAllocBankRteScale (odBankStateAllocBankRateScale), 
        output tPossibleBankStateAlloc.tdBankStateAllocBankWhtAmtTC (odBankStateAllocBankWHTAmtTC), 
        output tPossibleBankStateAlloc.BankStateAllocWHTAmtLC (odBankStateAllocBankWHTAmtLC), 
        output viFcReturnSuper (oiReturnStatus)) in BBankEntry>

    if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
    then assign oiReturnStatus = viFcReturnSuper.