project QadFinancials > class BBankEntry > method CreateDeduction

Description

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


Parameters


icCodeinputcharacterCode : can be creditor, debtor or employee
iiIdinputintegerId of the code
icInvoiceOrigininputcharacterInvoice Origin
itInvoiceDateinputdateInvoice Date
itInvoiceDueDateinputdateInvoice Due Date
idDeductionAmountTCinputdecimalDeductionAmount in TC
icInvoiceCurrencyCodeinputcharacterInvoice Currency Code
idDeductionExchangeRateinputdecimalDeduction Exchange Rate
idDeductionExchRateScaleinputdecimal
idDeductionAmountLCinputdecimalDeduction 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.
icDeductionCatCodeinputcharacterDeduction Category Code
iiDeductionCatLine_IDinputintegerDeductionCatLine ID
icDInvoiceDeductionStatusinputcharacterDeduction Status
icDInvoiceDeductionCustReferenceinputcharacterDeduction Customer reference.
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-3 GetExchangeRateType () in BBankEntry>.

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

    /* ====================== */
    /* replace unknown values */
    /* ====================== */
    if iiId = ? then assign iiId = 0.
    if icInvoiceOrigin = ? then assign icInvoiceOrigin = "":U.
    if idDeductionAmountTC = ? then assign idDeductionAmountTC = 0.
    if icInvoiceCurrencyCode = ? then assign icInvoiceCurrencyCode = "":U.
    if idDeductionExchangeRate = ? then assign idDeductionExchangeRate = 0.
    if idDeductionAmountLC = ? then assign idDeductionAmountLC = 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.
    if icDeductionCatCode = ? then assign icDeductionCatCode = '':U.
    if iiDeductionCatLine_ID = ? then assign iiDeductionCatLine_ID = 0.
    if icDInvoiceDeductionCustReference = ? then assign icDInvoiceDeductionCustReference = '':U.

    if icDeductionCatCode <> '':U and icDeductionCatCode <> ? then
    do:
        <Q-71 run DeductionCatLineByCode (all) (Read) (NoCache)
             (input viDomainID, (DomainId)
              input ?, (CompanyId)
              input icDeductionCatCode, (DeductionCode)
              output dataset tqDeductionCatLineByCode) in BDeductionCat>
        find first tqDeductionCatLineByCode
                where tqDeductionCatLineByCode.tcDeductionCatCode = icDeductionCatCode no-lock no-error.
        if not available tqDeductionCatLineByCode 
        then do: /*Deudction Cat Code does not exists.*/
           assign vcMessage = trim(#T-83'The Deduction Category Code $1 does not exist.':255(184710668)T-83#)
                  oiReturnStatus = -3.
                <M-16 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  icDeductionCatCode (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  ? (icRowid), 
                    input  'qadfin-587389':U (icFcMsgNumber), 
                    input  ? (icFcExplanation), 
                    input  ? (icFcIdentification), 
                    input  ? (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
              return.
           
        end.
        else if tqDeductionCatLineByCode.tlDeductionCatIsActive <> true
        then do: /*the deudction category code is not active*/
             assign vcMessage = trim(#T-69'The Deduction Category Code $1 is not active.':255(287312688)T-69#)
                    oiReturnStatus = -3.
             <M-67 run SetMessage
                (input  vcMessage (icMessage), 
                 input  icDeductionCatCode (icArguments), 
                 input  '':U (icFieldName), 
                 input  '':U (icFieldValue), 
                 input  'E':U (icType), 
                 input  3 (iiSeverity), 
                 input  ? (icRowid), 
                 input  'qadfin-536147':U (icFcMsgNumber), 
                 input  ? (icFcExplanation), 
                 input  ? (icFcIdentification), 
                 input  ? (icFcContext), 
                 output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
             return.
        end.
    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-45 RoundAmount
                                                                  (input  idDeductionAmountTC (idUnroundedAmount), 
                                                                   input  0 (iiCurrencyID), 
                                                                   input  icInvoiceCurrencyCode (icCurrencyCode)) in BBankEntry>
           /*
           tPossibleBankStateAlloc.BankStateAllocOpenBalTC  =  <M-64 RoundAmount
                                                                  (input  idDeductionAmountTC (idUnroundedAmount), 
                                                                   input  0 (iiCurrencyID), 
                                                                   input  icBankCurrencyCode (icCurrencyCode)) in BBankEntry>
           */
           tPossibleBankStateAlloc.BankStateAllocOpenBalTC  = 0
           tPossibleBankStateAlloc.tdDInvoiceDeductionTC    = <M-86 RoundAmount
                                                                 (input  idDeductionAmountTC (idUnroundedAmount), 
                                                                  input  0 (iiCurrencyID), 
                                                                  input  icInvoiceCurrencyCode (icCurrencyCode)) in BBankEntry>
           tPossibleBankStateAlloc.tcCurrencyCode           = icBankCurrencyCode 
           tPossibleBankStateAlloc.tcAllocAmountCrDt        = icNewBalanceCrDt
           tPossibleBankStateAlloc.tdDocBalance             = 0
           tPossibleBankStateAlloc.tcDocCredDebEmplCode     = icCode
           tPossibleBankStateAlloc.tiDocCredDebEmplId       = iiId
           tPossibleBankStateAlloc.tcDocCurrencyCode        = icInvoiceCurrencyCode
           tPossibleBankStateAlloc.tcDocBalanceCrDt         = icNewBalanceCrDt
           tPossibleBankStateAlloc.tdDocExchangeRate        = idDeductionExchangeRate
           tPossibleBankStateAlloc.tdDocExchangeRateScale   = idDeductionExchRateScale
           tPossibleBankStateAlloc.tcDocDescription         = icDescription
           tPossibleBankStateAlloc.tcDocDivisionCode        = icDivisionCode
           tPossibleBankStateAlloc.tcDocProjectCode         = icProjectCode
           tPossibleBankStateAlloc.tcDocCostCentreCode      = icCostCentre
           tPossibleBankStateAlloc.BankStateAllocAmountLC   = <M-68 RoundAmount
                                                                 (input  idDeductionAmountLC (idUnroundedAmount), 
                                                                  input  viCompanyLCId (iiCurrencyID), 
                                                                  input  vcCompanyLC (icCurrencyCode)) in BBankEntry>
           tPossibleBankStateAlloc.ttDocDueDate             = itInvoiceDueDate
           tPossibleBankStateAlloc.ttDocInvDate             = itInvoiceDate
           tPossibleBankStateAlloc.tcDocNumberReference     = trim(string(viBankPostingYear)) + "/":U + trim(vcBankPostingJournalCode) + "/":U + string(viBankPostingVoucher,"999999999":U)
           tPossibleBankStateAlloc.tdNewBalanceTC           = <M-44 RoundAmount
                                                                 (input  idDeductionAmountTC (idUnroundedAmount), 
                                                                  input  0 (iiCurrencyID), 
                                                                  input  icInvoiceCurrencyCode (icCurrencyCode)) in BBankEntry>
           tPossibleBankStateAlloc.tcNewBalanceCrDt         = icNewBalanceCrDt
           tPossibleBankStateAlloc.CInvoice_ID              = 0
           tPossibleBankStateAlloc.DInvoice_ID              = 0
           tPossibleBankStateAlloc.tcDInvoiceDeductionCode  = icDeductionCatCode
           tPossibleBankStateAlloc.tcDInvoiceDeductionStatus = icDInvoiceDeductionStatus
           /* give those fields a valid value, otherwise errors on save */
           tPossibleBankStateAlloc.tcCurrDifferenceCrDt     = {&CREDITDEBITABBREVIATION-DEBIT}
           tPossibleBankStateAlloc.tcCollBalanceCrDt        = {&CREDITDEBITABBREVIATION-DEBIT}
           tPossibleBankStateAlloc.tcCCCurrDifferenceCrDt   = {&CREDITDEBITABBREVIATION-DEBIT}
           tPossibleBankStateAlloc.tlUIFullAllocation       = true
           tPossibleBankStateAlloc.tcInvoiceDescription     = icDescription /*CA704890*/
           tPossibleBankStateAlloc.tcDInvoiceDIText         = trim(string(viBankPostingYear)) + "/":U + trim(vcBankPostingJournalCode) + "/":U + string(viBankPostingVoucher,"999999999":U)
           tPossibleBankStateAlloc.tcDInoviceDeductionCusReference = icDInvoiceDeductionCustReference.
                 
    if tPossibleBankStateAlloc.BankStateAllocAmountLC = 0
    then do:
        if icBankCurrencyCode = vcCompanyLC
        then assign tPossibleBankStateAlloc.BankStateAllocAmountLC = <M-13 RoundAmount
              (input  tPossibleBankStateAlloc.BankStateAllocAmountTC (idUnroundedAmount), 
               input  viCompanyLCId (iiCurrencyID), 
               input  vcCompanyLC (icCurrencyCode)) in business>.
    
        else do:
            <M-89 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-7 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 :
        /* =========================================== */
        /* fill the fields that are coming from debtor */
        /* =========================================== */
        when {&INVOICEORIGIN-DEBTOR}
        then do:
            <Q-6 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-82'The specified customer is not defined in the system.':150(327)T-82#)
                       oiReturnStatus = -3.
                <M-50 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-681654':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-46 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-DEDUCTIONINV}
                   tPossibleBankStateAlloc.tcDocBusinessRelationCode = tqDebtorByDebtor.tcBusinessRelationCode.
        end.
    end case.

    /* =============================================== */
    /* fill in the other fields based on previous ones */
    /* =============================================== */
    <M-28 run DefaultBankStateAllocBank
       (input  tPossibleBankStateAlloc.tcDocCurrencyCode (icDocCurrencyCode), 
        input  icBankCurrencyCode (icCurrencyCode), 
        input  idBankStateLineExtBankRate (idBankStateLineExtBankRate), 
        input  idBankStateLineExtRateScale (idBankStateLineExtBankRateScale), 
        input  icBankStateLineExtCurrency (icBankStateLineExtCurrency), 
        input  idDeductionAmountTC (idBankStateAllocAmountTC), 
        input  idDeductionAmountLC (idBankStateAllocAmountLC), 
        input  0 (idBankStateAllocDiscountTC), 
        input  0 (idBankStateAllocDiscountLC), 
        input  itInvoiceDate (itBankStateLineValueDate), 
        input  idDeductionExchangeRate (idDocExchangeRate), 
        input  idDeductionExchRateScale (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.