project QadFinancials > class BDDocument > method AdditionalUpdatesPostingPrePayment


Parameters


iiPeriodYearinputinteger
iiPeriodPeriodinputinteger
icJournalCodeinputcharacter
iiPostingIdinputinteger
icPostingRowidinputcharacter
blStart6input-outputlogical
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  = tDDocumentInvoiceXref.tcDInvoiceReference
       tOpenBalanceDDoc.tcInvoiceReference    = substring(string(tDDocumentInvoiceXref.tcDinvoiceReference),1,20,'character':U)
       tOpenBalanceDDoc.tcInvoiceType         = {&INVOICETYPE-PREPAYMENT}
       tOpenBalanceDDoc.tcJournalCode         = icJournalCode
       tOpenBalanceDDoc.tcKey                 = "*":U
       tOpenBalanceDDoc.tcPostingText         = tDDocumentInvoiceXref.tcDInvoiceReference
       tOpenBalanceDDoc.tcPostingType         = {&POSTINGTYPE-CREDIT}
       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-79 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.

if oiReturnStatus = 0 and vcPaymentConditionCode <> '':U and vcPaymentConditionCode <> ? then
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-16 run GetDefaultCCProjDivForPrePay
       (input  ? (iiId), 
        input  tOpenBalanceDDoc.tcDebtorCode (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.

/* ================================================================= */
/* Get payment condition for the prepayment                          */
/* ================================================================= */
/*
<M-42 run AdditionalUpdatesPostingPrePaymentPayCond
   (input  tOpenBalanceDDoc.tcDebtorCode (icDebtorCode), 
    output tOpenBalanceDDoc.tcNormalPaymentConditionCode (ocPaymentConditionCode), 
    output viFcReturnSuper (oiReturnStatus)) in BDDocument> */

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

if tDDocument.tcCurrencyCode = vcCompanyLC
then assign tOpenBalanceDDoc.tdExchangeRateScale = 1
            tOpenBalanceDDoc.tdExchangeRateTCLC  = 1
            tOpenBalanceDDoc.tdInvoiceAmountLC   = tOpenBalanceDDoc.tdInvoiceAmountTC.
else do:
    <M-1 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-11 RoundAmount
          (input  tOpenBalanceDDoc.tdInvoiceAmountTC * tOpenBalanceDDoc.tdExchangeRateTCLC * tOpenBalanceDDoc.tdExchangeRateScale (idUnroundedAmount), 
           input  viCompanyLCId (iiCurrencyID), 
           input  vcCompanyLC (icCurrencyCode)) in business>.
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-13 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-12 RoundAmount
                                                        (input  tOpenBalanceDDoc.tdInvoiceAmountTC * vdCCRate * vdCCRateScale (idUnroundedAmount), 
                                                         input  viCompanyCCId (iiCurrencyID), 
                                                         input  vcCompanyCC (icCurrencyCode)) in business>.
end.

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

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

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

    assign blStart8 = true.
end.

/* Create the Prepayment there */
<M-8 run CreateDInvoices
          (input-output tOpenBalanceDDoc (tDIOpenBalance), 
           input  viBJournalEntryDDocID (iiBJournalEntryId), 
           input  iiPostingId (iiPostingId), 
           output vcDInvoiceID (ocNewRecordInfo), 
           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 Discount Account */
if tDDocumentInvoiceXref.DDocumentInvoiceXrefDiscTC <> 0
then do:
    /* Refind the OpenBalance record */
    find first tOpenBalanceDDoc
               no-error.

    /* Get Discount Account */
    <M-9 run AdditionalUpdatesGetBankGLInfo
       (input  true (ilErrorIfNoDiscountAccount), 
        input  false (ilErrorIfNoCurrency), 
        output vcDiscountGLAccount (ocDiscountGLAccount), 
        output vcIntBankGLAccount (ocInterestGLAccount), 
        output viFcReturnSuper (oiReturnStatus)) in BDDocument>

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

    if oiReturnStatus < 0
    then return.

    /* Create the Posting */
    assign vdAmountLC = <M-15 RoundAmount
          (input  tDDocumentInvoiceXref.DDocumentInvoiceXrefDiscTC * tOpenBalanceDDoc.tdExchangeRateTCLC * tOpenBalanceDDoc.tdExchangeRateScale (idUnroundedAmount), 
           input  viCompanyLCId (iiCurrencyID), 
           input  vcCompanyLC (icCurrencyCode)) in business>.

    <M-10 run AddStandardPosting
       (input  icPostingRowid (icPostingtcRowid), 
        input  tBankGLInfoDDoc.tcDiscGLCode (icGLCode), 
        input  tOpenBalanceDDoc.tcDivisionCode (icDivisionCode), 
        input  '':U (icCostCentreCode), 
        input  '':U (icCostCentreText), 
        input  '':U (icProjectCode), 
        input  '':U (icProjectText), 
        input  '':U (icIntercoBusinessRelationCode), 
        input  tDDocument.tcCurrencyCode (icCurrencyCode), 
        input  tDDocumentInvoiceXref.DDocumentInvoiceXrefDiscTC (idDebitTC), 
        input  vdAmountLC (idDebitLC), 
        input  0 (idDebitCC), 
        input  0 (idDebitPC), 
        input  0 (idCreditTC), 
        input  0 (idCreditLC), 
        input  0 (idCreditCC), 
        input  0 (idCreditPC), 
        input  0 (idQty), 
        input  tDDocument.tcPostingText (icLineText), 
        input  '':U (icSafText), 
        input  tDefaultSafsDDoc (tDefaultSafs), 
        input  '':U (icExchangeRateType), 
        input  tOpenBalanceDDoc.tdExchangeRateTCLC (idExchangeRate), 
        input  tOpenBalanceDDoc.tdExchangeRateScale (idExchangeRateScale), 
        input  tOpenBalanceDDoc.tdExchangeRateTCCC (idPostingLineCCRate), 
        input  tOpenBalanceDDoc.tdCCExchangeRateScale (idPostingLineCCScale), 
        output viPostingLineId (oiPostingLineId), 
        input  0 (iiSafStructureId), 
        input  '':U (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 return.
end.