project QadFinancials > class BDDocument > method AdditionalUpdatesPostingDeduction

Description

Update Deduction Posting.


Parameters


iiPeriodYearinputinteger
iiPeriodPeriodinputinteger
icJournalCodeinputcharacter
iiPostingIdinputinteger
icPostingRowidinputcharacter
blStart8input-outputlogical
iiPostingVoucherinputintegerPosting voucher number form the posting header
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDDocument.AdditionalUpdatesPostingXref


program code (program5/bddocument.p)

empty temp-table tOpenBalanceDDoc.

create tOpenBalanceDDoc.

assign tOpenBalanceDDoc.tcAction              = {&DAEMONACTION-SAVE}
       tOpenBalanceDDoc.tcDebtorCode          = tDDocumentInvoiceXref.tcDebtorCode
       tOpenBalanceDDoc.tcDivisionCode        = tDDocumentInvoiceXref.tcDivisionCode
       tOpenBalanceDDoc.tcProjectCode         = tDDocumentInvoiceXref.tcProjectCode
       tOpenBalanceDDoc.tcCostCentreCode      = tDDocumentInvoiceXref.tcCostCentreCode
       tOPenBalanceDDoc.tiBankNumber_ID       = tDDocument.BankNumber_ID
       tOpenBalanceDDoc.tcBankNumber          = tDDocument.tcDebtorBankNumber
       tOpenBalanceDDoc.tcInvoiceDescription  = string(iiPeriodYear) + "/":U +
                                                icJournalCode + "/":U +
                                                string(iiPostingVoucher, "999999999":U) + "/":U +
                                                tDDocumentInvoiceXref.tcDInvoiceReference
       tOpenBalanceDDoc.tcInvoiceReference    = substring(string(tDDocumentInvoiceXref.tcDinvoiceReference),1,20,'character':U)
       tOpenBalanceDDoc.tcInvoiceType         = {&INVOICETYPE-DEDUCTION}
       tOpenBalanceDDoc.tcJournalCode         = icJournalCode  
       tOpenBalanceDDoc.tcKey                 = "*":U
       tOpenBalanceDDoc.tcPostingText         = string(iiPeriodYear) + "/":U +
                                                icJournalCode + "/":U +
                                                string(iiPostingVoucher, "999999999":U) + "/":U +
                                                tDDocumentInvoiceXref.tcDInvoiceReference
       tOpenBalanceDDoc.tcPostingType         = {&POSTINGTYPE-DEBIT}
       tOpenBalanceDDoc.tcTCCurrencyCode      = tDDocument.tcCurrencyCode
       tOpenBalanceDDoc.tdInvoiceAmountTC     = tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC
       tOpenBalanceDDoc.tiCompanyId           = tDDocument.Company_ID
       tOpenBalanceDDoc.tiInvoiceVoucher      = iiPostingVoucher
       tOpenBalanceDDoc.tiPeriodPeriod        = iiPeriodPeriod
       tOpenBalanceDDoc.tiPeriodYear          = iiPeriodYear
       tOpenBalanceDDoc.tlOnlyControlAccount  = true
       tOpenBalanceDDoc.ttInvoiceDate         = tDDocument.ttPostingDate
       tOpenBalanceDDoc.ttInvoiceDueDate      = tDDocument.DDocumentDueDate
       tOpenBalanceDDoc.ttInvoiceTaxPointDate = tDDocument.ttPostingDate
       tOpenBalanceDDoc.ttPostingDate         = tDDocument.ttPostingDate no-error.

assign tDDocumentInvoiceXref.tcDInvoiceReference = tOpenBalanceDDoc.tcInvoiceReference no-error.
/* caculate the deduction invoice due date and credit term. */
assign vhFcComponent = ?.
<M-71 run GetDeductPrepayCreditTermDuedate
      (input  tOpenBalanceDDoc.tcInvoiceType (icInvoiceType), 
       input  tOpenBalanceDDoc.ttInvoiceDate (itInvoiceDate), 
       output vcPaymentConditionCode (ocPaymentConditionCode), 
       output vtInvoiceDueDate (otInvoiceDueDate), 
       output vtInvoiceDiscountDueDate (otInvoiceDiscountDueDate), 
       output viFcReturnSuper (oiReturnStatus)) in BPaymentCondition>
if viFcReturnSuper < 0 or
       oiReturnStatus  = 0
then assign oiReturnStatus = viFcReturnSuper.

if oiReturnStatus < 0
    then return.
assign tOpenBalanceDDoc.ttInvoiceDiscountDueDate = vtInvoiceDiscountDueDate
       tOpenBalanceDDoc.ttInvoiceDueDate = vtInvoiceDueDate
       tOpenBalanceDDoc.tcNormalPaymentConditionCode = vcPaymentConditionCode.
/* Get the default Division, CostCentreCode, and ProjectCode if not specified */
if tOpenBalanceDDoc.tcDivisionCode = "":U or
   tOpenBalanceDDoc.tcProjectCode = "":U or 
   tOpenBalanceDDoc.tcCostCentreCode = "":U
then do:
    assign vhFcComponent = ?.
     <M-74 run GetDefaultCCProjDivForDeduction
        (input  ? (iiId), 
         input  {&INVOICEORIGIN-DEBTOR} (icCode), 
         input  {&INVOICEORIGIN-DEBTOR} (icInvoiceOrigin), 
         output vcCostCentreCode (ocCostCentreCode), 
         output vcProjectCode (ocProjectCode), 
         output vcDivisionCode (ocDivisionCode), 
         output viFcReturnSuper (oiReturnStatus)) in BBankEntry>

    if tOpenBalanceDDoc.tcDivisionCode = "":U and
       vcDivisionCode <> "":U
    then assign tOpenBalanceDDoc.tcDivisionCode      = vcDivisionCode
                tDDocumentInvoiceXref.tcDivisionCode = vcDivisionCode.

    if tOpenBalanceDDoc.tcProjectCode = "":U and
       vcProjectCode <> "":U
    then assign tOpenBalanceDDoc.tcProjectCode = vcProjectCode.

    if tOpenBalanceDDoc.tcCostCentreCode = "":U and
       vcCostCentreCode <> "":U
    then assign tOpenBalanceDDoc.tcCostCentreCode = vcCostCentreCode.
end.

if tDDocument.tcCurrencyCode = vcCompanyLC
then assign tOpenBalanceDDoc.tdExchangeRateScale = 1
            tOpenBalanceDDoc.tdExchangeRateTCLC  = 1
            tOpenBalanceDDoc.tdInvoiceAmountLC   = tOpenBalanceDDoc.tdInvoiceAmountTC.
else do:
    <M-8 run GetExchangeRate
       (input  ? (iiCompanyID), 
        input  ? (iiFromCurrencyID), 
        input  tDDocument.tcCurrencyCode (icFromCurrencyCode), 
        input  viCompanyLCId (iiToCurrencyID), 
        input  ? (icToCurrencyCode), 
        input  ? (iiExchangeRateTypeID), 
        input  {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode), 
        input  tDDocument.ttPostingDate (itValidityDate), 
        output tOpenBalanceDDoc.tdExchangeRateTCLC (odExchangeRate), 
        output tOpenBalanceDDoc.tdExchangeRateScale (odExchangeScaleFactor), 
        output viFcReturnSuper (oiReturnStatus)) in BDDocument>
    if viFcReturnSuper < 0 or
       oiReturnStatus  = 0
    then assign oiReturnStatus = viFcReturnSuper.

    if oiReturnStatus < 0
    then return.

    assign tOpenBalanceDDoc.tdInvoiceAmountLC = <M-27 RoundAmount
                                                   (input  tOpenBalanceDDoc.tdInvoiceAmountTC * tOpenBalanceDDoc.tdExchangeRateTCLC * tOpenBalanceDDoc.tdExchangeRateScale (idUnroundedAmount), 
                                                    input  viCompanyLCId (iiCurrencyID), 
                                                    input  vcCompanyLC (icCurrencyCode)) in BDDocument>.
end.

assign tDDocumentInvoiceXref.tdLCExchangeRate      = tOpenBalanceDDoc.tdExchangeRateTCLC
       tDDocumentInvoiceXref.tdLCExchangeRateScale = tOpenBalanceDDoc.tdExchangeRateScale.

if vcCompanyCC = "":U or
   vcCompanyCC = ?
then assign tOpenBalanceDDoc.tdInvoiceAmountCC = 0.
else
if tDDocument.tcCurrencyCode = vcCompanyCC
then assign tOpenBalanceDDoc.tdInvoiceAmountCC  = tOpenBalanceDDoc.tdInvoiceAmountTC
            tOpenBalanceDDoc.tdExchangeRateTCCC = 1
            tOpenBalanceDDoc.tdCCExchangeRateScale = 1.
else
if vlDomainIsStatutory = false
then assign tOpenBalanceDDoc.tdInvoiceAmountCC = tOpenBalanceDDoc.tdInvoiceAmountLC
            tOpenBalanceDDoc.tdExchangeRateTCCC = tOpenBalanceDDoc.tdExchangeRateTCLC
            tOpenBalanceDDoc.tdCCExchangeRateScale = tOpenBalanceDDoc.tdExchangeRateScale.
else do:
    <M-12 run GetExchangeRate
       (input  ? (iiCompanyID), 
        input  ? (iiFromCurrencyID), 
        input  tDDocument.tcCurrencyCode (icFromCurrencyCode), 
        input  viCompanyCCId (iiToCurrencyID), 
        input  ? (icToCurrencyCode), 
        input  ? (iiExchangeRateTypeID), 
        input  {&EXCHANGERATETYPE-STATUTORY} (icExchangeRateTypeCode), 
        input  tDDocument.ttPostingDate (itValidityDate), 
        output vdCCRate (odExchangeRate), 
        output vdCCRateScale (odExchangeScaleFactor), 
        output viFcReturnSuper (oiReturnStatus)) in BDDocument>
    if viFcReturnSuper < 0 or
       oiReturnStatus  = 0
    then assign oiReturnStatus = viFcReturnSuper.

    if oiReturnStatus < 0
    then return.

    assign  tOpenBalanceDDoc.tdExchangeRateTCCC    = vdCCRate
            tOpenBalanceDDoc.tdCCExchangeRateScale = vdCCRateScale
            tOpenBalanceDDoc.tdInvoiceAmountCC     = <M-67 RoundAmount
                                                        (input  tOpenBalanceDDoc.tdInvoiceAmountTC * vdCCRate * vdCCRateScale (idUnroundedAmount), 
                                                         input  viCompanyCCId (iiCurrencyID), 
                                                         input  vcCompanyCC (icCurrencyCode)) in BDDocument>.
end.

assign tDDocumentInvoiceXref.tdCCExchangeRate      = tOpenBalanceDDoc.tdExchangeRateTCCC
       tDDocumentInvoiceXref.tdCCExchangeRateScale = tOpenBalanceDDoc.tdCCExchangeRateScale.

assign vhFcComponent = ?.

/*get system account "Deduction"*/
<Q-33 run GLByGLSystemType (all) (Read) (Cache)
   (input viCompanyID, (CompanyId)
    input {&GLSYSTEMTYPE-DEDUCTION}, (GLSystemTypeCode)
    input {&GLTYPECODE-SYST}, (GlTypeCode)
    input ?, (GlIsDivisionAccount)
    output dataset tqGLByGLSystemType) in BGL>

find first tqGLByGLSystemType where
               tqGLByGLSystemType.tcGLSystemTypeCode = {&GLSYSTEMTYPE-DEDUCTION} and
               tqGLByGLSystemType.tcGLTypeCode       = {&GLTYPECODE-SYST}
               no-error.
if not available tqGLByGLSystemType
then do:  
     assign vcMessage = trim(#T-9'The system account for Deduction Suspends has not been defined':255(352726945)T-9#). 
    <M-25 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E' (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'qadfin-627089':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BDDocument> 
 
   if viFcReturnSuper < 0 or oiReturnStatus  = 0
    then assign oiReturnStatus = viFcReturnSuper.

   if oiReturnStatus < 0
    then return.
   
end.


<M-45 run AdditionalUpdatesGetDeductionJournalCode
   (input  tDDocument.tcGLCode (icBankGLAccount), 
    output vcDeductionJournalCode (ocDeductionJournalCode), 
    output viFcReturnSuper (oiReturnStatus)) in BDDocument>
if viFcReturnSuper < 0 or
   oiReturnStatus  = 0
then assign oiReturnStatus = viFcReturnSuper.

if oiReturnStatus < 0
then return.

assign tOpenBalanceDDoc.tcJournalCode = vcDeductionJournalCode.


empty temp-table tDInvoiceDeduction.
for each tApiDInvoiceDeduction where
                        tApiDInvoiceDeduction.tc_ParentRowid = tDDocumentInvoiceXref.tcDInvoiceDeductionParentRowID no-lock:
      if tDDocument.tcCurrencyCode = vcCompanyLC then
           assign vdDInvoiceDeductionLC = tApiDInvoiceDeduction.DInvoiceDeductionTC.
      else
      do:
           assign vdDInvoiceDeductionLC = <M-92 RoundAmount
                                             (input  tApiDInvoiceDeduction.DInvoiceDeductionTC * tOpenBalanceDDoc.tdExchangeRateTCLC * tOpenBalanceDDoc.tdExchangeRateScale (idUnroundedAmount), 
                                              input  viCompanyLCId (iiCurrencyID), 
                                              input  vcCompanyLC (icCurrencyCode)) in BDDocument>.
      end.

      if vcCompanyCC = "":U or
         vcCompanyCC = ?
      then assign vdDInvoiceDeductionCC = 0.
      else
      if tDDocument.tcCurrencyCode = vcCompanyCC
      then assign vdDInvoiceDeductionCC  = tApiDInvoiceDeduction.DInvoiceDeductionTC.
      else
      if vlDomainIsStatutory = false
      then assign vdDInvoiceDeductionCC = vdDInvoiceDeductionLC.
      else do:
           assign vdDInvoiceDeductionCC = <M-61 RoundAmount
                                             (input  tApiDInvoiceDeduction.DInvoiceDeductionTC * vdCCRate * vdCCRateScale (idUnroundedAmount), 
                                              input  viCompanyCCId (iiCurrencyID), 
                                              input  vcCompanyCC (icCurrencyCode)) in BDDocument>.
      end.
  
      assign viDInvoiceDeductionRowID = viDInvoiceDeductionRowID - 1.
      create tDInvoiceDeduction.
      assign tDInvoiceDeduction.DeductionCatLine_ID = tApiDInvoiceDeduction.DeductionCatLine_ID
             tDInvoiceDeduction.DInvoiceDeductionTC = tApiDInvoiceDeduction.DInvoiceDeductionTC
             tDInvoiceDeduction.DInvoiceDeductionLC = vdDInvoiceDeductionLC
             tDInvoiceDeduction.DInvoiceDeductionCC = vdDInvoiceDeductionCC
             tDInvoiceDeduction.tcDeductionCatCode = tApiDInvoiceDeduction.tcDeductionCatCode
             tDInvoiceDeduction.tc_Rowid = string(viDInvoiceDeductionRowID)
             tDInvoiceDeduction.tc_ParentRowid = tOpenBalanceDDoc.tcKey
             tDInvoiceDeduction.PaidDInvoice_ID = if tApiDInvoiceDeduction.PaidDInvoice_ID = ? then 0 else tApiDInvoiceDeduction.PaidDInvoice_ID
             tDInvoiceDeduction.DInvoiceDeductionComment = tApiDInvoiceDeduction.DInvoiceDeductionComment
             tDInvoiceDeduction.DInvoiceDeductionSequence = tApiDInvoiceDeduction.DInvoiceDeductionSequence
             tDInvoiceDeduction.DInvoiceDeductionCustRef = if tApiDInvoiceDeduction.DInvoiceDeductionCustRef = ? then '' else tApiDInvoiceDeduction.DInvoiceDeductionCustRef
             tDInvoiceDeduction.DInvoiceDeductionPromotionCode = if tApiDInvoiceDeduction.DInvoiceDeductionPromotionCode = ? then '' else tApiDInvoiceDeduction.DInvoiceDeductionPromotionCode
             tDInvoiceDeduction.DInvoiceDeductionStatus = tApiDInvoiceDeduction.DInvoiceDeductionStatus.
end.

/*find the deduction detail of the documents */
/* Start Debtor Invoice component */
if not blStart8
then do:
    if viBDInvoiceDDocID = 0 or
       viBDInvoiceDDocID = ?
    then do:
        <I-49 {bFcStartAndOpenInstance
             &ADD-TO-TRANSACTION   = "yes"
             &CLASS                = "BDInvoice"}>

        assign vlBDInvoiceDDocWasStartedHere = true.
    end.
    else do:
        <I-77 {bFcOpenInstance
             &CLASS           = "BDInvoice"}>
    end.

    assign blStart8 = true.
end.

<M-55 run CreateDInvoicesDeduction
   (input-output tOpenBalanceDDoc (tDIOpenBalanceDeduction), 
    input  viBJournalEntryDDocID (iiBJournalEntryId), 
    input  0 (iiPostingId), 
    output vcDInvoiceID (ocNewRecordInfo), 
    input  tDInvoiceDeduction (tDIDeduction), 
    output viFcReturnSuper (oiReturnStatus)) in BDInvoice>

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

if oiReturnStatus < 0
then return.

/* Assign DInvoice_ID to DDocumentInvoiceXref */
assign tDDocumentInvoiceXref.DInvoice_ID = int(entry(2, vcDInvoiceID)). 

/* Create Posting on Deduction Suspends Account */
if tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC <> 0
then do:
    /* Refind the OpenBalance record */
    find first tOpenBalanceDDoc
               no-error.

    /* Get Discount Account */
   /*
    <M-67 RoundAmount
       (input  tOpenBalanceDDoc.tdInvoiceAmountTC * vdCCRate * vdCCRateScale (idUnroundedAmount), 
        input  viCompanyCCId (iiCurrencyID), 
        input  vcCompanyCC (icCurrencyCode)) in BDDocument>
  
    if viFcReturnSuper < 0 or
       oiReturnStatus  = 0
    then assign oiReturnStatus = viFcReturnSuper.

    if oiReturnStatus < 0
    then return.
    */
    /* Create the Posting */
    
    assign vdAmountLC = <M-14 RoundAmount
                           (input  tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC * tOpenBalanceDDoc.tdExchangeRateTCLC * tOpenBalanceDDoc.tdExchangeRateScale (idUnroundedAmount), 
                            input  viCompanyLCId (iiCurrencyID), 
                            input  vcCompanyLC (icCurrencyCode)) in BDDocument>
           vdAmountCC = <M-91 RoundAmount
                           (input  tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC * tOpenBalanceDDoc.tdExchangeRateTCCC * tOpenBalanceDDoc.tdCCExchangeRateScale (idUnroundedAmount), 
                            input  viCompanyCCId (iiCurrencyID), 
                            input  vcCompanyCC (icCurrencyCode)) in BDDocument>.
    
    if viFcReturnSuper < 0 or
       oiReturnStatus  = 0
    then assign oiReturnStatus = viFcReturnSuper.

    if oiReturnStatus < 0
    then return.
    
    /* assign vdAmountLC = tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC. */
    empty temp-table tDefaultSafsDDoc.
    vcDeductionPostingText         = string(iiPeriodYear) + "/":U +
                                             tOpenBalanceDDoc.tcJournalCode + "/":U +
                                             string(tOpenBalanceDDoc.tiInvoiceVoucher, "999999999":U) + "/":U +
                                             tDDocumentInvoiceXref.tcDInvoiceReference.
    /*start BJournalEntry */
    if viBJournalEntryDDocID = 0 or
                       viBJournalEntryDDocID = ?
    then do:
           <I-1 {bFcStartAndOpenInstance
                             &ADD-TO-TRANSACTION   = "false"
                             &CLASS                = "BJournalEntry"}>
                        
    end.
    else do:
           <I-18 {bFcOpenInstance
                             &CLASS           = "BJournalEntry"}>
    end.
    <M-10 run AddStandardPosting
       (input  icPostingRowid (icPostingtcRowid), 
        input  tqGLByGLSystemType.tcGLCode (icGLCode), 
        input  ? (icDivisionCode), 
        input  ? (icCostCentreCode), 
        input  ? (icCostCentreText), 
        input  ? (icProjectCode), 
        input  ? (icProjectText), 
        input  ? (icIntercoBusinessRelationCode), 
        input  tDDocument.tcCurrencyCode (icCurrencyCode), 
        input  tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC (idDebitTC), 
        input  vdAmountLC (idDebitLC), 
        input  vdAmountCC (idDebitCC), 
        input  0 (idDebitPC), 
        input  0 (idCreditTC), 
        input  0 (idCreditLC), 
        input  0 (idCreditCC), 
        input  0 (idCreditPC), 
        input  0 (idQty), 
        input  vcDeductionPostingText (icLineText), 
        input  ? (icSafText), 
        input  tDefaultSafsDDoc (tDefaultSafs), 
        input  {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateType), 
        input  tOpenBalanceDDoc.tdExchangeRateTCLC (idExchangeRate), 
        input  tOpenBalanceDDoc.tdExchangeRateScale (idExchangeRateScale), 
        input  tOpenBalanceDDoc.tdExchangeRateTCCC (idPostingLineCCRate), 
        input  tOpenBalanceDDoc.tdCCExchangeRateScale (idPostingLineCCScale), 
        output viPostingLineId (oiPostingLineId), 
        input  ? (iiSafStructureId), 
        input  ? (icSafStructureCode), 
        input  ? (icAllocationKey), 
        input  false (ilLinkedCrCyDaemonReqExists), 
        output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>

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

    if oiReturnStatus < 0
    then do:
       <I-87 {bFcCloseInstance
            &CLASS           = "BJournalEntry"}>
       return.
    end.
    
    /* ========================================================================================================= */
    /* Normally we would here close 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                                               */
    /* ========================================================================================================= */
    
end.