project QadFinancials > class BAPMatching > method AdditionalUpdatesAllLinesPLReceiptPvod

Description

AdditionalUpdatesAllLinesPLReceiptPvod; submethod of AdditionalUpdatesAllLines that is located in the same segment and that takes care of the creation of a posting-line for the Pvod_det in case of non-logistic-charges


Parameters


icAPMatchingPostingRowidIDinputcharacterAPMatchingPostingRowidID
icPostingTextinputcharacterPosting Text
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BAPMatching.AdditionalUpdatesAllLines


program code (program6/bapmatching.p)

 /* ===================================================================================================== */
/* This applies to lines for logistic-charges and for other-lines (independant on the item-type)         */
/* Create a posting-line based on the values of tAPMatchingLn.APMatchingLnMatchQty and                   */
/* tAPMatchingLn.APMatchingLnPvodUnitPrice and store the PostingLine_ID in                               */
/* tAPMatchingLn.PvodPostingLine_ID                                                                      */
/* The amount equals the UnitPrice-TC (at receipt) * Qty (invoiced qty)                                  */
/* Create a tPendingVoucherUpdateAPM record and assign all fields properly                               */
/* ===================================================================================================== */

/* ======================== */
/* Set default ReturnStatus */
/* ======================== */
assign oiReturnStatus = -98.

/* ============================================================================ */
/* First check whether everything is availablable what is supposed to be avail  */
/* ============================================================================ */
if not available tAPMatching   or 
   not available tAPMatchingLn or 
   not available tqPendingVoucherForMatchingAcc 
then do :
    assign oiReturnStatus  = -3
           vcMsgAPMatching = trim(substitute(#T-27'Internal error: information is missing.':255(49818)T-27#)) + chr(10) + 
                             trim(substitute(#T-28'Available matching header: &1.':234(49819)T-28#,available (tAPMatching))) + chr(10) + 
                             trim(substitute(#T-29'Available matching details: &1.':234(49820)T-29#,available (tAPMatchingLn))) + chr(10) + 
                             trim(substitute(#T-30'Available pending invoice details: &1.':234(49821)T-30#,available (tqPendingVoucherForMatchingAcc))) + chr(10) + 
                             trim(substitute(#T-32'Technical details: &1.':222(55526)T-32#, "Receipt/10":U)).
    <M-26 run SetMessage (input  vcMsgAPMatching (icMessage), 
                 input  '':U (icArguments), 
                 input  '':U (icFieldName), 
                 input  '':U (icFieldValue), 
                 input  'E':U (icType), 
                 input  3 (iiSeverity), 
                 input  '':U (icRowid), 
                 input  'QadFin-5413':U (icFcMsgNumber), 
                 input  '':U (icFcExplanation), 
                 input  '':U (icFcIdentification), 
                 input  '':U (icFcContext), 
                 output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
    Return.
end. /* if not avail */ 

if tAPMatchingLn.APMatchingLnPvodIsLgCharge = false and 
   available tqPendingVoucherForMatchingAcc = false
then do : 
    assign oiReturnStatus  = -3
           vcMsgAPMatching = trim(substitute(#T-44'Internal error: information is missing.':255(49818)T-44#)) + chr(10) + 
                             trim(substitute(#T-49'The system cannot find the receipt history of the pending invoice detail based on its domain and ID (&1/&2/&3).':255(49445)T-49#,tAPMatchingLn.PvoDomain,string(tAPMatchingLn.PvoID),string(tAPMatchingLn.PvodLineID))).
    <M-43 run SetMessage (input  vcMsgAPMatching (icMessage), 
                 input  '':U (icArguments), 
                 input  '':U (icFieldName), 
                 input  '':U (icFieldValue), 
                 input  'E':U (icType), 
                 input  3 (iiSeverity), 
                 input  '':U (icRowid), 
                 input  'QadFin-6514':U (icFcMsgNumber), 
                 input  '':U (icFcExplanation), 
                 input  '':U (icFcIdentification), 
                 input  '':U (icFcContext), 
                 output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
    Return.
end. /* if tAPMatchingLn.APMatchingLnPvodIsLgCharge = false and */

if viBMfgPOReceiptFromAPMID = 0 or 
   viBMfgPOReceiptFromAPMID = ? or
   valid-handle(vhBMfgPOReceiptFromAPMInst) = false
then do :
    assign oiReturnStatus  = -3
           vcMsgAPMatching = trim(substitute(#T-52'Internal error: information on the PO Receipt instance is not available.':255(63578)T-52#)) + chr(10) + 
                             trim(substitute(#T-53'Instance-ID of class &1: &2.':255(63583)T-53#,"BMfgPOReceipt":U,string(viBMfgPOReceiptFromAPMID)))  + chr(10) + 
                             trim(substitute(#T-54'Valid-handle to class &1: &2.':255(63582)T-54#,"BMfgPOReceipt":U,string(valid-handle(vhBMfgPOReceiptFromAPMInst)))).
    <M-51 run SetMessage (input  vcMsgAPMatching (icMessage), 
                 input  '':U (icArguments), 
                 input  '':U (icFieldName), 
                 input  '':U (icFieldValue), 
                 input  'E':U (icType), 
                 input  3 (iiSeverity), 
                 input  '':U (icRowid), 
                 input  'QadFin-6517':U (icFcMsgNumber), 
                 input  '':U (icFcExplanation), 
                 input  '':U (icFcIdentification), 
                 input  '':U (icFcContext), 
                 output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
    Return.
end. /* if viBMfgPOReceiptFromAPMID = 0 or */

/* ================================================================================================ */
/* Make a call to an instance-less method in BMfgPOReceipt that will return the GL, Division,       */
/* Project and CostCentre that we should use on the posting-line that compensates the receipt       */
/* Note that class BMfgPOReceipt was started (in another transaction) in the beginning of the most  */
/* outer-loop and will be stopped after the the most outer-loop.                                    */
/* See methods AdditionalUpdatesAllQueriesStart and AdditionalUpdatesAllQueriesStop for this        */
/* After this call, we fill the project in case it was still empty                                  */
/* ================================================================================================ */
/* CA779219 - In case 'Create GL Transactions is disabled, we use the account of the matching grid */

<Q-16 run DomainForInventoryControlFile (all) (Read) (Cache)
   (input tAPMatchingLn.PvoDomain, (DomainCode)
    output dataset tqDomainForInventoryControlFile) in BMfgDomain>
    
find first tqDomainForInventoryControlFile where 
           tqDomainForInventoryControlFile.tcicc_domain = tAPMatchingLn.PvoDomain
           no-lock no-error.

if available tqDomainForInventoryControlFile and 
   tqDomainForInventoryControlFile.tlicc_gl_tran = false and
   tAPMatchingLn.APMatchingLnPvodIsLgCharge      = false and
   tAPMatchingLn.APMatchingLnPvodItemType        = {&APMATCHINGLNPVODITEMTYPE-MEMO}
then do :
    assign vcGLCode         = tAPMatchingLn.tcGLCode
           vcDivisionCode   = tAPMatchingLn.tcDivisionCode
           vcCostCentreCode = tAPMatchingLn.tcCostCentreCode
           vcProjectCode    = tAPMatchingLn.tcProjectCode.
end.

else do :   
    /* CA779219 */         
    
    <M-50 run GetAccountInformationOnPOReceipt
       (input  tAPMatching.Company_ID (iiCompanyID), 
        input  tAPMatchingLn.PvoDomain (icDomainCode), 
        input  tAPMatchingLn.APMatchingLnPvodIsLgCharge (ilReceiptIsLogisticCharge), 
        input  (if tAPMatchingLn.APMatchingLnPvodIsLgCharge = false then tqPendingVoucherForMatchingAcc.tcprh_type else '':U) (icReceiptPrhType), 
        input  (if tAPMatchingLn.APMatchingLnPvodIsLgCharge = false then tqPendingVoucherForMatchingAcc.tcprh_vend else '':U) (icReceiptPrhVendor), 
        input  (if tAPMatchingLn.APMatchingLnPvodIsLgCharge = false then tqPendingVoucherForMatchingAcc.tcvd_type else '':U) (icReceiptVendorType), 
        input  (if tAPMatchingLn.APMatchingLnPvodIsLgCharge = false then tqPendingVoucherForMatchingAcc.tcpvo_part else '':U) (icReceiptItemCode), 
        input  (if tAPMatchingLn.APMatchingLnPvodIsLgCharge = false then tqPendingVoucherForMatchingAcc.tcpt_prod_line else '':U) (icReceiptProductLineCode), 
        input  (if tAPMatchingLn.APMatchingLnPvodIsLgCharge = false then tqPendingVoucherForMatchingAcc.tcprh_site else '':U) (icReceiptSiteCode), 
        input  tAPMatchingLn.APMatchingLnPvodGLCode (icReceiptLogisticChargeGLCode), 
        input  tAPMatchingLn.APMatchingLnPvodDivCode (icReceiptLogisticChargeDivCode), 
        input  tAPMatchingLn.APMatchingLnPvodPrjCode (icReceiptLogisticChargePrjCode), 
        input  tAPMatchingLn.APMatchingLnPvodCCCode (icReceiptLogisticChargeCCCode), 
        output vcGLCode (ocGLCode), 
        output vcDivisionCode (ocDivisionCode), 
        output vcProjectCode (ocProjectCode), 
        output vcCostCentreCode (ocCostCentreCode), 
        output viFcReturnSuper (oiReturnStatus)) in BMfgPOReceipt>

    if viFcReturnSuper <> 0
    then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then Return.

    if vcProjectCode = "":U or 
       vcProjectCode = ?
    then assign vcProjectCode = tAPMatchingLn.APMatchingLnPvodPrjCode.
end.

/* ==================================================== */
/* Check wether we have a G/L account by now            */
/* If the Op Alloc Code is filled, the GL will be blank */
/* ==================================================== */
if (vcGLCode = "":U or 
    vcGLCode = ?      ) and
   (tAPMatchingLn.APMatchingLnOpAllocCode = "":U or
    tAPMatchingLn.APMatchingLnOpAllocCode = ?)
then do:
    assign oiReturnStatus  = -3
           vcMsgAPMatching = trim(substitute(#T-22'Cannot find the pending invoice details to create the posting line on the receipt accounts  (Domain: &1, Pinv: &2, Pinv-det: &3).':255(55533)T-22#,tAPMatchingLn.PvoDomain,string(tAPMatchingLn.PvoID),string(tAPMatchingLn.PvodLineID))).
    <M-21 run SetMessage (input  vcMsgAPMatching (icMessage), 
                 input  '':U (icArguments), 
                 input  '':U (icFieldName), 
                 input  '':U (icFieldValue), 
                 input  'E':U (icType), 
                 input  3 (iiSeverity), 
                 input  '':U (icRowid), 
                 input  'QadFin-5408':U (icFcMsgNumber), 
                 input  '':U (icFcExplanation), 
                 input  '':U (icFcIdentification), 
                 input  '':U (icFcContext), 
                 output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
    Return.
end. /* if vcGLCode = "":U or */

/* ==================================================================================== */
/* Create the posting line that reverses the receipt posting-line for the allocated qty */                                                                      
/* - we use the GL-Div-CC-PRJ as stated above                                           */
/* - the amount equals the:                                                             */
/*   - For finshed pvo: UnitPrice-TC (at receipt) * Qty (Open qty)                      */
/*   - For non-finshed pvo: UnitPrice-TC (at receipt) * Qty (Allocated qty)             */
/*   increased with the original taxes with AccrueAtReceipt                             */
/*   decreased with the original retained taxes of the pvod that are AccruedAtReceipt   */
/* - Positive amounts: posted on Credit                                                 */
/* - Negative amounts: posted on Debit                                                  */ 
/* Note that we have to pass the CC-amouts as well because if we do not do it here,     */
/* than BPosting will calculate them based on the Posting-date but we want to use the   */
/* exchange-rates of the receipt-date (use LC as base for the CC-calculation as the     */
/* posting uses the same construction)                                                  */
/* ==================================================================================== */
assign vdAmountTC     = tAPMatchingLn.APMatchingLnReceiptAmtTC 
                        + tAPMatchingLn.tdAPMatchingLnOrigARRecTaxTC 
                        + tAPMatchingLn.tdAPMatchingLnOrigARNRecTaxTC 
                        - tAPMatchingLn.tdAPMatchingLnOrigARRetainTaxTC
       vdUnroundedLC  = vdAmountTC * tAPMatchingLn.APMatchingLnPvodExchRate2 / tAPMatchingLn.APMatchingLnPvodExchRate
       vdAmountTC     = <M-65 RoundAmount
                           (input  vdAmountTC (idUnroundedAmount), 
                            input  ? (iiCurrencyID), 
                            input  tAPMatchingLn.APMatchingLnPvodCurrency (icCurrencyCode)) in BAPMatching>
       vdAmountLC     = <M-55 RoundAmount
                           (input  vdUnroundedLC (idUnroundedAmount), 
                            input  viCompanyLCId (iiCurrencyID), 
                            input  ? (icCurrencyCode)) in BAPMatching>
       vdAmountCC     = if viCompanyCCID = viCompanyLCID
                        then vdAmountLC 
                        else if vcCompanyCC = tAPMatchingLn.APMatchingLnPvodCurrency then vdAmountTC
                        else      /* NOTE; The CC-value posted on the receipt-account should be calculated based upon the rounded LC-value */
                                  /* Mathematically it should be more correct to start the caluclation of the CC-value based upon the rounded LC-value but as the operational side starts the calculation from the rounded-amoutn, we have to act the same here as we would otherwise have a difference we cannot get rid off */
                                  /* See also FIN-2072 as this change was made based upon that ticket */
                                  /* Note that a similar chnage is made in method ValidateComponentPreValidateAPMLn1 */
                                  <M-56 RoundAmount
                                     (input  vdAmountLC * tAPMatchingLn.APMatchingLnPvodCCRate * tAPMatchingLn.APMatchingLnPvodCCScale (idUnroundedAmount), 
                                      input  viCompanyCCId (iiCurrencyID), 
                                      input  ? (icCurrencyCode)) in BAPMatching>
       vdDebitTC      = if tAPMatching.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
                           tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE}
                        then if vdAmountTC > 0 then vdAmountTC       else 0
                        else if vdAmountTC < 0 then vdAmountTC       else 0
       vdDebitLC      = if tAPMatching.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
                           tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE}
                        then if vdAmountLC > 0 then vdAmountLC       else 0
                        else if vdAmountLC < 0 then vdAmountLC       else 0
       vdDebitCC      = if tAPMatching.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
                           tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE}
                        then if vdAmountCC > 0 then vdAmountCC       else 0
                        else if vdAmountCC < 0 then vdAmountCC       else 0
       vdCreditTC     = if tAPMatching.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
                           tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE}
                        then if vdAmountTC < 0 then vdAmountTC * -1  else 0
                        else if vdAmountTC > 0 then vdAmountTC * -1  else 0
       vdCreditLC     = if tAPMatching.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
                           tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE}
                        then if vdAmountLC < 0 then vdAmountLC * -1  else 0
                        else if vdAmountLC > 0 then vdAmountLC * -1  else 0
       vdCreditCC     = if tAPMatching.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
                           tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE}
                        then if vdAmountCC < 0 then vdAmountCC * -1  else 0
                        else if vdAmountCC > 0 then vdAmountCC * -1  else 0.   

/* The Operational Allocation Code is only passed when the GL code from APMatchingLn is used */
<M-40 run AdditionalUpdatesAllLinesPLAddPostingLine
   (input  icAPMatchingPostingRowidID (icAPMatchingPostingRowId), 
    input  vcGLCode (icGLCode), 
    input  vcDivisionCode (icDivisionCode), 
    input  vcCostCentreCode (icCostCentreCode), 
    input  vcProjectCode (icProjectCode), 
    input  (if vcGLCode = '' or vcGLCode = ? then tAPMatchingLn.APMatchingLnOpAllocCode else '') (icOpAllocCode), 
    input  vdDebitTC (idDebitTC), 
    input  vdDebitLC (idDebitLC), 
    input  vdDebitCC (idDebitCC), 
    input  vdCreditTC (idCreditTC), 
    input  vdCreditLC (idCreditLC), 
    input  vdCreditCC (idCreditCC), 
    input  icPostingText (icPostingText), 
    input  tAPMatchingLn.APMatchingLnPvodExchRate2 / tAPMatchingLn.APMatchingLnPvodExchRate (idTCLCExchangeRate), 
    input  1 (idTCLCExchangeScale), 
    input  ? (idTCCCExchangeRate), 
    input  ? (idTCCCExchangeScale), 
    input  tDefaultSafsOperAPM (tDefaultSafsAPM), 
    output tAPMatchingLn.PvoPostingLine_ID (oiPostingLineId), 
    input  false (ilisCallForVarianceOrTax), 
    output viFcReturnSuper (oiReturnStatus)) in BAPMatching>

if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper <  0 then return.

/* ===================== */
/* Set ReturnStatus = OK */
/* ===================== */
if oiReturnStatus = -98
then assign oiReturnStatus = 0.