project QadFinancials > class BCInvoice > method CreateCIPosting2

Description

Create the CI Posting (Part 2 - Method too long)


Parameters


iiCInvoiceIdinputintegerCInvoice ID
iiPeriodYearinputintegerAccounting Year
iiPeriodPeriodinputintegerGL Period
itPostingDateinputdateposting date
iiCreditorIdinputintegerCreditor ID
icCreditorCodeinputcharacterSupplier Code
icCInvoiceTypeinputcharacterType of the creditor invoice
icDivisionCodeinputcharacterSub-Account Code
icJournalCodeinputcharacterDaybook Code
iiVoucherinputintegerVoucher
itTaxPointDateinputdatetax point date
icReferenceinputcharacterReference
icDescriptioninputcharacterDescription
idInvoiceAmountTCinputdecimalInvoice Amount in TC
idInvoiceAmountLCinputdecimalInvoice Amount in LC
idInvoiceAmountCCinputdecimalInvoice Amount in CC
icCurrencyCodeinputcharacterTransactial Currency Code
idExchangeRateinputdecimalexchange rate
idExchangeRateScaleinputdecimal
icCITextinputcharacterSI Text
icPostingTypeinputcharacterPosting Type
icGlCodeinputcharactergl account
icCostCentreCodeinputcharacterCost Center Code
icProjectCodeinputcharacterProject Code
ilOnlyControlAccountinputlogicalPosting only on the control account
icShipToCountryCodeinputcharacterCountry code of the ship to address
icTxclTaxClsinputcharacterTax Class of the Tax tab if filled, otherwise the tax class of the creditor
icTxuTaxUsageinputcharacterTax Usage of the Tax tab, if not filled, then pass the tax usage of the creditor
icTxenvTaxEnvinputcharacterTax environment of the tax tab, if not filled, pass the default value of it
icPaymentConditioninputcharacterPayment Condition
ilIsTaxInCityFromShipToinputlogicaltax in city flag of the ship to address
icPoNbrinputcharacterPo number
ilIsTaxableinputlogicalIs taxable flag
icControlCostCentreCodeinputcharacter
icControlProjectCodeinputcharacter
iiShipFromAddressIdinputintegerShip From Address ID : necessary to fill the federal tax, state tax, misc .... Not needed for manual journal entries
iiShipToAddressIdinputintegerShip To Address ID : necessary to fill the federal tax, state tax, misc .... Not needed for manual journal entries
ilIsLogisticMatchinginputlogicalIs logistic matching ?
ilGetDefaultSafsinputlogical
icBusinessRelationCodeinputcharacter
iiPrePayControlGLProfileIdinputinteger
iiInvControlGLProfileIdinputinteger
iiCnControlGLProfileIdinputinteger
icCInvoiceRowidinputcharacter
icBusinessRelationInterCoCodeinputcharacter
icShipFromCountryCodeinputcharacter
ilShipFromCountryIsEUCountryinputlogical
icCreditorTaxZoneinputcharacter
ilIsInitialStatusinputlogicalat modify : pass the initial value of the IsInitialStatus flag, in all other cases pass false
tApiCInvoiceVatinput-outputtemp-tabletemp table like cinvoicevat table
tDefaultSafsCIinputtemp-table
ilHandleCommunicationWithJEinputlogicaldo you want that this method handles the communication with the journal entry component or not ? If the instance of the journal entry is already started, pass false...
biBJournalEntryIdinput-outputintegerInstance of Journal Entry
biPostingIdinput-outputintegerID of the CI Posting
icRowIdinputcharacter
iiControlPostingLineIdinputinteger
itInvoiceDateinputdate
idCCExchangeRateinputdecimal
idCCExchangeRateScaleinputdecimal
ilCInvoiceIsForLegalDocinputlogical
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCInvoice.CreateCIPosting


program code (program3/bcinvoice.p)

assign oiReturnStatus       = -98
        viLocalReturnStatus = 0.
        
if vlCompanyPropertyIsAPUseInvDate = true
then assign vtExchangeRateDate = itInvoiceDate.
else assign vtExchangeRateDate = ?.


POSTING2BLOCK: DO : 
    
    if not ilOnlyControlAccount  /* SIREC or other a/c */
    then do:
        if icGlCode = "":U  /* SIREC */
        then do:
            /* CC Amounts passed to addStandardPosting need to be ? instead of 0 */
            assign vdCIRECDebitTC = ?
                   vdCIRECDebitLC = ?
                   vdCIRECDebitCC = ?
                   vdCIRECCreditTC = ?
                   vdCIRECCreditLC = ?
                   vdCIRECCreditCC = ?.
            <Q-131 run GLByGLSystemType (all) (Read) (NoCache)
               (input viCompanyId, (CompanyId)
                input {&GLSYSTEMTYPE-CIREC}, (GLSystemTypeCode)
                input {&GLTYPECODE-SYST}, (GlTypeCode)
                input ?, (GlIsDivisionAccount)
                output dataset tqGLByGLSystemType) in BGL >
            find first tqGLByGLSystemType where
                       tqGLByGLSystemType.tcGLSystemTypeCode = {&GLSYSTEMTYPE-CIREC} and
                       tqGLByGLSystemType.tcGLTypeCode       = {&GLTYPECODE-SYST}
                       no-error.
            if not available tqGLByGLSystemType
            then do:
                <M-127 run SetMessage
                   (input  trim(#T-150'The system could not find an Unmatched Invoices account record.':150(1054)T-150#) (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  tCInvoice.tc_Rowid (icRowid), 
                    input  'QadFin-9517':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
                assign viLocalReturnStatus = -1.
                if ilHandleCommunicationWithJE = true
                then do:
                    <I-144 {bFcCloseInstance
                         &CLASS           = "BJournalEntry"}>
                end. 
                leave POSTING2BLOCK.
            end. /* if not avail tqGLByGLSystemType */
            assign vlTax = false.
            for each tApiCInvoiceVat where 
                     tApiCInvoiceVat.tc_ParentRowid = icCInvoiceRowid and
                     tApiCInvoiceVat.tc_Status     <> "D":U:
                if tApiCInvoiceVat.CInvoiceVatIsAccrRcpUs          = false and
                   tApiCInvoiceVat.CInvoiceVatNonRecTaxAmtTC      <> ?     and
                  (abs(tApiCInvoiceVat.CInvoiceVatVatDebitTC - 
                       tApiCInvoiceVat.CInvoiceVatVatCreditTC) -
                   tApiCInvoiceVat.CInvoiceVatNonRecTaxAmtTC)     <> 0 
                then do:
                    accumulate tApiCInvoiceVat.CInvoiceVatVatDebitTC (total).
                    accumulate tApiCInvoiceVat.CInvoiceVatVatCreditTC (total).
                    accumulate tApiCInvoiceVat.CInvoiceVatNonRecTaxAmtTC (total).
                    assign vlTax = true.
                end. /* if tApiCInvoiceVat.CInvoiceVatIsAccrRcpUs = false and .. */
            end. /* for each tApiCInvoiceVat where */

            assign vdCIRECDebitTC  = if icCInvoiceType = {&INVOICETYPE-INVOICE} or
                                        icCInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
                                     then if vlTax
                                          then idInvoiceAmountTC - ((accum total tApiCInvoiceVat.CInvoiceVatVatDebitTC) - (accum total tApiCInvoiceVat.CInvoiceVatNonRecTaxAmtTC)) + (accum total tApiCInvoiceVat.CInvoiceVatVatCreditTC)
                                          else idInvoiceAmountTC
                                     else 0
                   vdCIRECCreditTC = if icCInvoiceType = {&INVOICETYPE-INVOICE} or
                                        icCInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
                                     then 0
                                     else if vlTax
                                          then idInvoiceAmountTC - ((accum total tApiCInvoiceVat.CInvoiceVatVatCreditTC) - (accum total tApiCInvoiceVat.CInvoiceVatNonRecTaxAmtTC)) + (accum total tApiCInvoiceVat.CInvoiceVatVatDebitTC)
                                          else idInvoiceAmountTC
                   vdCIRECDebitLC  = if icCurrencyCode = vcCompanyLC
                                     then vdCIRECDebitTC
                                     else <M-122 RoundAmount
                                             (input  vdCIRECDebitTC * idExchangeRate * idExchangeRateScale (idUnroundedAmount), 
                                              input  viCompanyLCId (iiCurrencyID), 
                                              input  vcCompanyLC (icCurrencyCode)) in BCInvoice>
                   vdCIRECCreditLC = if icCurrencyCode = vcCompanyLC
                                     then vdCIRECCreditTC
                                     else <M-123 RoundAmount
                                             (input  vdCIRECCreditTC * idExchangeRate * idExchangeRateScale (idUnroundedAmount), 
                                              input  viCompanyLCId (iiCurrencyID), 
                                              input  vcCompanyLC (icCurrencyCode)) in BCInvoice>
                   vdCIRECDebitCC  = if icCurrencyCode = vcCompanyCC
                                     then vdCIRECDebitTC
                                     else if vdCIRECDebitCC        = ? or 
                                             idCCExchangeRate      = ? or 
                                             idCCExchangeRate      = 0 or 
                                             idCCExchangeRateScale = ? or 
                                             idCCExchangeRateScale = 0
                                          then ?
                                          else <M-43 RoundAmount
                                                  (input  vdCIRECDebitTC * idCCExchangeRate * idCCExchangeRateScale (idUnroundedAmount), 
                                                   input  viCompanyCCId (iiCurrencyID), 
                                                   input  vcCompanyCC (icCurrencyCode)) in BCInvoice>
                   vdCIRECCreditCC = if icCurrencyCode = vcCompanyCC
                                     then vdCIRECCreditTC
                                     else if vdCIRECDebitCC        = ? or 
                                             idCCExchangeRate      = ? or 
                                             idCCExchangeRate      = 0 or 
                                             idCCExchangeRateScale = ? or 
                                             idCCExchangeRateScale = 0
                                          then ?
                                          else <M-23 RoundAmount
                                                  (input  vdCIRECCreditTC * idCCExchangeRate * idCCExchangeRateScale (idUnroundedAmount), 
                                                   input  viCompanyCCId (iiCurrencyID), 
                                                   input  vcCompanyCC (icCurrencyCode)) in BCInvoice>
                   vlCIREC         = true.
            if idInvoiceAmountCC <> 0 and 
               idInvoiceAmountCC <> ? 
            then do:
                if vcCompanyCC = icCurrencyCode 
                then assign vdCIRECDebitCC  =  vdCIRECDebitTC
                            vdCIRECCreditCC =  vdCIRECCreditTC.
                else if vcCompanyCC = vcCompanyLC
                     then assign vdCIRECDebitCC  =  vdCIRECDebitLC
                                 vdCIRECCreditCC =  vdCIRECCreditLC.
                     else do: 
                         assign vdExRateCC      = idInvoiceAmountLC / idInvoiceAmountCC
                                vdExRateScaleCC = 1
                                vdCIRECDebitCC  = <M-147 RoundAmount
                                                     (input  vdCIRECDebitLC / (vdExRateCC * vdExRateScaleCC) (idUnroundedAmount), 
                                                      input  viCompanyCCId (iiCurrencyID), 
                                                      input  vcCompanyCC (icCurrencyCode)) in BCInvoice>
                                vdCIRECCreditCC = <M-148 RoundAmount
                                                     (input  vdCIRECCreditLC / (vdExRateCC * vdExRateScaleCC) (idUnroundedAmount), 
                                                      input  viCompanyCCId (iiCurrencyID), 
                                                      input  vcCompanyCC (icCurrencyCode)) in BCInvoice>.                    
                     end. /* else do: */
            end. /* if idInvoiceAmountCC <> 0 and idInvoiceAmountCC <> ? */
            <M-112 run AddStandardPosting
               (input  icRowId (icPostingtcRowid), 
                input  tqGLByGLSystemType.tcGLCode (icGLCode), 
                input  icDivisionCode (icDivisionCode), 
                input  icCostCentreCode (icCostCentreCode), 
                input  icCIText (icCostCentreText), 
                input  icProjectCode (icProjectCode), 
                input  icCIText (icProjectText), 
                input  icBusinessRelationInterCoCode (icIntercoBusinessRelationCode), 
                input  icCurrencyCode (icCurrencyCode), 
                input  vdCIRECDebitTC (idDebitTC), 
                input  vdCIRECDebitLC (idDebitLC), 
                input  vdCIRECDebitCC (idDebitCC), 
                input  0 (idDebitPC), 
                input  vdCIRECCreditTC (idCreditTC), 
                input  vdCIRECCreditLC (idCreditLC), 
                input  vdCIRECCreditCC (idCreditCC), 
                input  0 (idCreditPC), 
                input  0 (idQty), 
                input  icCIText (icLineText), 
                input  icCIText (icSafText), 
                input  tDefaultSafsCI (tDefaultSafs), 
                input  {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateType), 
                input  idExchangeRate (idExchangeRate), 
                input  idExchangeRateScale (idExchangeRateScale), 
                input  idCCExchangeRate (idPostingLineCCRate), 
                input  idCCExchangeRateScale (idPostingLineCCScale), 
                output viCIRECPostingLineId (oiPostingLineId), 
                input  ? (iiSafStructureId), 
                input  ? (icSafStructureCode), 
                input  ? (icAllocationKey), 
                input  false (ilLinkedCrCyDaemonReqExists), 
                input  vtExchangeRateDate (itExchangeRateDate), 
                output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>

            if viFcReturnSuper < 0 or
               viLocalReturnStatus  = 0
            then assign viLocalReturnStatus = viFcReturnSuper.
            if viLocalReturnStatus < 0
            then do:
                if ilHandleCommunicationWithJE = true
                then do:
                    <I-26 {bFcCloseInstance
                         &CLASS           = "BJournalEntry"}>
                end.
                return.
            end.    
                
                
            /* I19 requirement for Brazil ============================================================== */
            /* Update posting line to control account to contain legal document number filled in         */
            /* ========================================================================================= */
            if ilCInvoiceIsForLegalDoc
            then do:
                <M-18 run SetPostingLineLegalDocNumber
                   (input  ? (icPostingLineTcRowID), 
                    input  viCIRECPostingLineId (iiPostingLineID), 
                    input  entry(1, icReference) (icLegalDocumentNumber), 
                    output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
                
                if viFcReturnSuper < 0 or
                   viLocalReturnStatus  = 0
                then assign viLocalReturnStatus = viFcReturnSuper.
                if viLocalReturnStatus < 0
                then do:
                    if ilHandleCommunicationWithJE = true
                    then do:
                        <I-35 {bFcCloseInstance
                             &CLASS           = "BJournalEntry"}>
                    end.
                    return.
                end.    
            end. /* if ilCInvoiceIsForLegalDoc */
        end. /* if icGlCode = "":U */
        else do: /* Other ac */
            <M-116 run CreateCIPostingCalculateAmounts
               (input  no (ilIsCreditorControlAccount), 
                input  icCInvoiceType (icCInvoiceType), 
                input  idInvoiceAmountTC (idInvoiceAmountTC), 
                input  idInvoiceAmountLC (idInvoiceAmountLC), 
                input  idInvoiceAmountCC (idInvoiceAmountCC), 
                input  icPostingType (icPostingType), 
                output vdDebitTC (odDebitTC), 
                output vdDebitLC (odDebitLC), 
                output vdDebitCC (odDebitCC), 
                output vdCreditTC (odCreditTC), 
                output vdCreditLC (odCreditLC), 
                output vdCreditCC (odCreditCC), 
                output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
            if viFcReturnSuper < 0 or
               viLocalReturnStatus  = 0
            then assign viLocalReturnStatus = viFcReturnSuper.
            if viLocalReturnStatus < 0
            then do:
                if ilHandleCommunicationWithJE = true
                then do:
                    <I-137 {bFcCloseInstance
                         &CLASS           = "BJournalEntry"}>
                end.
                return.
            end.
            <M-113 run AddStandardPosting
               (input  icRowId (icPostingtcRowid), 
                input  icGlCode (icGLCode), 
                input  icDivisionCode (icDivisionCode), 
                input  icCostCentreCode (icCostCentreCode), 
                input  icCIText (icCostCentreText), 
                input  icProjectCode (icProjectCode), 
                input  icCIText (icProjectText), 
                input  icBusinessRelationInterCoCode (icIntercoBusinessRelationCode), 
                input  icCurrencyCode (icCurrencyCode), 
                input  vdDebitTC (idDebitTC), 
                input  vdDebitLC (idDebitLC), 
                input  vdDebitCC (idDebitCC), 
                input  0 (idDebitPC), 
                input  vdCreditTC (idCreditTC), 
                input  vdCreditLC (idCreditLC), 
                input  vdCreditCC (idCreditCC), 
                input  0 (idCreditPC), 
                input  0 (idQty), 
                input  icCIText (icLineText), 
                input  icCIText (icSafText), 
                input  tDefaultSafsCI (tDefaultSafs), 
                input  {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateType), 
                input  idExchangeRate (idExchangeRate), 
                input  idExchangeRateScale (idExchangeRateScale), 
                input  idCCExchangeRate (idPostingLineCCRate), 
                input  idCCExchangeRateScale (idPostingLineCCScale), 
                output viPostingLineId (oiPostingLineId), 
                input  ? (iiSafStructureId), 
                input  ? (icSafStructureCode), 
                input  ? (icAllocationKey), 
                input  false (ilLinkedCrCyDaemonReqExists), 
                input  vtExchangeRateDate (itExchangeRateDate), 
                output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
                
            if viFcReturnSuper < 0 or
               viLocalReturnStatus  = 0
            then assign viLocalReturnStatus = viFcReturnSuper.
            if viLocalReturnStatus < 0
            then do:
                if ilHandleCommunicationWithJE = true
                then do:
                    <I-8 {bFcCloseInstance
                         &CLASS           = "BJournalEntry"}>
                end. 
                leave POSTING2BLOCK.
            end. /* if viLocalReturnStatus < 0 */
            
            /* I19 requirement for Brazil ============================================================== */
            /* Update posting line to control account to contain legal document number filled in         */
            /* ========================================================================================= */
            if ilCInvoiceIsForLegalDoc
            then do:
                <M-75 run SetPostingLineLegalDocNumber
                   (input  ? (icPostingLineTcRowID), 
                    input  viPostingLineId (iiPostingLineID), 
                    input  entry(1, icReference) (icLegalDocumentNumber), 
                    output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
                
                if viFcReturnSuper < 0 or
                   viLocalReturnStatus  = 0
                then assign viLocalReturnStatus = viFcReturnSuper.
                if viLocalReturnStatus < 0
                then do:
                    if ilHandleCommunicationWithJE = true
                    then do:
                        <I-96 {bFcCloseInstance
                             &CLASS           = "BJournalEntry"}>
                    end. 
                    leave POSTING2BLOCK.
                end. /* if viLocalReturnStatus < 0 */  
            end. /* if ilCInvoiceIsForLegalDoc */
        end. /* if icGlCode = "":U */
    end. /* if not ilOnlyControlAccount */
    
    if ilHandleCommunicationWithJE = true
    then do:
        /* ========================================================================================================= */
        /* Normally we would here close the communication to BJournalEntry but we will not do it for performance     */
        /* reasons as this way the Commit of the transaction does not have to re-open the instance to commit it.     */
        /* And in all other scenario's the instance of the class ill be closed by the de-activiate procedure of the  */
        /* appserver that is executed after each call to the appserver                                               */
        /* ========================================================================================================= */
        /* In the special case BCI:CreareCIPosting2 we need to keep the CloseInstance of BJE in the code as The UI   */
        /* first opens the BJE-instance, then calls CreateCIPosting, then calls CreateMFPosting and then closes the  */
        /* BJE-instance. But after calling CreateCIPosting, the UI opens the BJE-instance itself and as such we need */
        /* to close the instance in CreateCIPosting (and its sub-methods).                                           */
        /* ========================================================================================================= */
        <I-17 {bFcCloseInstance
             &CLASS           = "BJournalEntry"}>
    end. /* if ilHandleCommunicationWithJE = true */
    
    if viLocalReturnStatus < 0
    then do:
        <M-125 run StopExternalInstances  (output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
        leave POSTING2BLOCK.
    end.
    if viCIRECPostingLineId <> ? and
       viCIRECPostingLineId <> 0
    then do:
        <M-117 run UpdateCInvoicePosting
           (input  tCInvoice.tc_Rowid (icCInvoiceRowId), 
            input  iiCInvoiceId (iiCInvoiceId), 
            input  biPostingId (iiPostingId), 
            input  viCIRECPostingLineId (iiCIRECPostingLineId), 
            input  {&INVOICEPOSTINGTYPE-INITIAL} (icCInvoicePostingType), 
            output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
        if viFcReturnSuper < 0 or
           viLocalReturnStatus  = 0
        then assign viLocalReturnStatus = viFcReturnSuper.
        if viLocalReturnStatus < 0
        then leave POSTING2BLOCK.
    end.
    <M-120 run CreateCIPostingExt
       (input  iiCInvoiceId (iiCInvoiceId), 
        input  icCInvoiceType (icCInvoiceType), 
        input  idInvoiceAmountTC (idInvoiceAmountTC), 
        input  idInvoiceAmountLC (idInvoiceAmountLC), 
        input  idInvoiceAmountCC (idInvoiceAmountCC), 
        input  icPostingType (icPostingType), 
        input  iiControlPostingLineId (iiControlPostingLineId), 
        input  ilIsInitialStatus (ilIsInitialStatus), 
        output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    if viFcReturnSuper < 0 or viLocalReturnStatus  = 0
    then assign viLocalReturnStatus = viFcReturnSuper.
    
end. /* POSTING2BLOCK */

assign oiReturnStatus = viLocalReturnStatus.