project QadFinancials > class BYearClosing > method AdditionalUpdatesPostingCloseOpenPL

Description

Submethod of AdditionalUpdatesPostingCloseOpen to close the Profit & Loss Accounts


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BYearClosing.AdditionalUpdatesPostingCloseOpen


program code (program5/byearclosing.p)

assign oiReturnStatus = -98.
    
/* Closing Postings for PL accounts */
assign vlHeaderCreated = false
       viCnt           = 0.

assign vcPostingText = trim(#T-4'Year-End Closing: P&L Closing.':200(999890617)T-4#)
       vcPostingText = substring (vcPostingText,1,40,"CHARACTER").

for each tPostingHistClosing where
         tPostingHistClosing.tlClosingGLIsBalanceAcc = false
         by tPostingHistClosing.tcClosingGLCode
         by tPostingHistClosing.tcClosingDivisionCode:

    /* make sure either debit or credit is 0 */
    assign vdDebitLC  = tPostingHistClosing.tdClosingDebitLC
           vdCreditLC = tPostingHistClosing.tdClosingCreditLC
           vdDebitCC  = tPostingHistClosing.tdClosingDebitCC
           vdCreditCC = tPostingHistClosing.tdClosingCreditCC
           tPostingHistClosing.tdClosingDebitLC  = tPostingHistClosing.tdClosingDebitLC  - min(vdDebitLC, vdCreditLC)
           tPostingHistClosing.tdClosingCreditLC = tPostingHistClosing.tdClosingCreditLC - min(vdDebitLC, vdCreditLC)
           tPostingHistClosing.tdClosingDebitCC  = tPostingHistClosing.tdClosingDebitCC  - min(vdDebitCC, vdCreditCC)
           tPostingHistClosing.tdClosingCreditCC = tPostingHistClosing.tdClosingcreditCC - min(vdDebitCC, vdCreditCC).

    if tPostingHistClosing.tdClosingDebitLC  = 0 and
       tPostingHistClosing.tdClosingCreditLC = 0 and
       tPostingHistClosing.tdClosingDebitCC  = 0 and
       tPostingHistClosing.tdClosingCreditCC = 0
    then next.                   
         
    if vlHeaderCreated = false
    then do:
               
        <M-1 run AddPostingHeader
           (input  tYearClosing.Company_ID (iiCompanyId), 
            input  tYearClosing.YearClosingAccountingYear (iiPeriodYear), 
            input  tqPeriodByYearPeriod.tiPeriodPeriod + 1 (iiPeriodPeriod), 
            input  tYearClosing.tcClosingPLJournalCode (icJournalCode), 
            input  '' (icReportingJournalCode), 
            input  0 (iiVoucher), 
            input  tqPeriodByYearPeriod.ttPeriodEndDate (itPostingDate), 
            input  ? (itValueDate), 
            input  vcPostingText (icPostingText), 
            input  '':U (icPostingBusinessRelationText), 
            input  '':U (icPostingInvoiceReferenceText), 
            input  '':U (icPostingParentText), 
            input  viBPeriodYearClosingID (iiBPeriodId), 
            input  ? (icPostingOriginAddressCode), 
            input  ? (icPostingOriginDocument), 
            input  ? (icPostingOriginDocumentType), 
            input  '':U (icBatchNumber), 
            input  ? (icBankImpLineRef), 
            output viPostingID (oiPostingId), 
            output vcPLPostingRowid (ocRowid), 
            output viPostingVoucher (oiPostingVoucher), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>

        assign vlHeaderCreated = true.                           
        if viFcReturnSuper <> 0 and oiReturnStatus >= 0
        then assign oiReturnStatus = viFcReturnSuper.                           
        if viFcReturnSuper < 0 
        then return.
        
        /* Update Additional GL Numbering date */
        if vlIsAddGLNbr
        then do:
            <M-26 run SetNumberingDate
               (input  viPostingID (iiPostingID), 
                input  tYearClosing.YearClosingCloAddGLNbrDate (itNbrDate), 
                output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
            if viFcReturnSuper <> 0 and oiReturnStatus >= 0
            then assign oiReturnStatus = viFcReturnSuper.                           
            if viFcReturnSuper < 0 
            then return.
        end.
    end. /* if vlHeaderCreated = false */
    
    /* Fill allocation key for Open Item postings */
    if tPostingHistClosing.tcClosingGLTypeCode = {&GLTYPECODE-OPEN}
    then assign viCnt           = viCnt + 1
                vcAllocationKey = trim("PostingId-":U) + trim(string(viPostingID)) + trim("-Nbr-":U) + trim(string(viCnt)).                    
    else assign vcAllocationKey = '':U.

    <M-2 run AddStandardPosting
       (input  vcPLPostingRowid (icPostingtcRowid), 
        input  tPostingHistClosing.tcClosingGLCode (icGLCode), 
        input  if tYearClosing.YearClosingIsInclDivision = true then tPostingHistClosing.tcClosingDivisionCode else '' (icDivisionCode), 
        input  '':U (icCostCentreCode), 
        input  '':U (icCostCentreText), 
        input  '':U (icProjectCode), 
        input  '':U (icProjectText), 
        input  '':U (icIntercoBusinessRelationCode), 
        input  vcCompanyLC (icCurrencyCode), 
        input  tPostingHistClosing.tdClosingCreditLC (idDebitTC), 
        input  tPostingHistClosing.tdClosingCreditLC (idDebitLC), 
        input  tPostingHistClosing.tdClosingCreditCC (idDebitCC), 
        input  0 (idDebitPC), 
        input  tPostingHistClosing.tdClosingDebitLC (idCreditTC), 
        input  tPostingHistClosing.tdClosingDebitLC (idCreditLC), 
        input  tPostingHistClosing.tdClosingDebitCC (idCreditCC), 
        input  0 (idCreditPC), 
        input  0 (idQty), 
        input  vcPostingText (icLineText), 
        input  '':U (icSafText), 
        input  tDefaultSaf (tDefaultSafs), 
        input  {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateType), 
        input  1 (idExchangeRate), 
        input  1 (idExchangeRateScale), 
        input  ? (idPostingLineCCRate), 
        input  ? (idPostingLineCCScale), 
        output viPostingLineID (oiPostingLineId), 
        input  0 (iiSafStructureId), 
        input  '':U (icSafStructureCode), 
        input  '':U (icAllocationKey), 
        input  false (ilLinkedCrCyDaemonReqExists), 
        output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>   

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

    /* Create Tax Accounts if necessary */        
    if tPostingHistClosing.tcClosingGLTypeCode = {&GLTYPECODE-VAT}
    then do:
        assign vdCCExchangeRate = if tPostingHistClosing.tdClosingCreditLC <> 0 and
                                     tPostingHistClosing.tdClosingCreditLC <> ?
                                  then tPostingHistClosing.tdClosingCreditCC / tPostingHistClosing.tdClosingCreditLC
                                  else tPostingHistClosing.tdClosingDebitCC / tPostingHistClosing.tdClosingDebitLC.

        <M-5 run AdditionalUpdatesPostingTaxAccount
           (input  tYearClosing.Company_ID (iiCompanyId), 
            input  tYearClosing.YearClosingDefTaxCode (icDefaultTaxCode), 
            input  vcPLPostingRowid (icPostingtcRowid), 
            input  viPostingLineID (iiPostingLineId), 
            input  vcCompanyLC (icCurrencyCode), 
            input  tqPeriodByYearPeriod.ttPeriodEndDate (itTaxPointDate), 
            input  tPostingHistClosing.tcClosingGLCode (icTaxGLCode), 
            input  1 (idExchangeRate), 
            input  vdCCExchangeRate (idCCExchangeRate), 
            input  1 (idCCExchangeRateScale), 
            output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
        if viFcReturnSuper <> 0 and oiReturnStatus >= 0
        then assign oiReturnStatus = viFcReturnSuper.                           
        if viFcReturnSuper < 0 
        then return.    
    end.        
end. /* for each tPostingHistClosing where GLIsBalanceAcc = false */              

/* Create Postinglines for the transfer PL to BS we did in Add.Upd.PostingTrans */
assign vcPostingText = trim(#T-62'Year-End Closing: PL transfer to BS.':200(56442)T-62#)
       vcPostingText = substring (vcPostingText,1,40,"CHARACTER").

 for each tPLAmounts where
          tPLAmounts.tdPLAmountsCC <> 0 or 
          tPLAmounts.tdPLAmountsLC <> 0:

    <M-8 run AddStandardPosting
       (input  vcPLPostingRowid (icPostingtcRowid), 
        input  if tplamounts.tcPLAmountsDivisionCode = '':U then tYearClosing.tcClosingPLGLCode else tYearClosing.tcClosingPLDivGLCode (icGLCode), 
        input  if tYearClosing.YearClosingIsInclDivision = true then tPLAmounts.tcPLAmountsDivisionCode else '' (icDivisionCode), 
        input  '':U (icCostCentreCode), 
        input  '':U (icCostCentreText), 
        input  '':U (icProjectCode), 
        input  '':U (icProjectText), 
        input  '':U (icIntercoBusinessRelationCode), 
        input  vcCompanyLC (icCurrencyCode), 
        input  if tplamounts.tdPLAmountsLC <= 0 then 0 else tplamounts.tdPLAmountsLC (idDebitTC), 
        input  if tplamounts.tdPLAmountsLC <= 0 then 0 else tplamounts.tdPLAmountsLC (idDebitLC), 
        input  if tplamounts.tdPLAmountsCC <= 0 then 0 else tplamounts.tdPLAmountsCC (idDebitCC), 
        input  0 (idDebitPC), 
        input  if tplamounts.tdPLAmountsLC <= 0 then - tplamounts.tdPLAmountsLC else 0 (idCreditTC), 
        input  if tplamounts.tdPLAmountsLC <= 0 then - tplamounts.tdPLAmountsLC else 0 (idCreditLC), 
        input  if tplamounts.tdPLAmountsCC <= 0 then - tplamounts.tdPLAmountsCC else 0 (idCreditCC), 
        input  0 (idCreditPC), 
        input  0 (idQty), 
        input  vcPostingText (icLineText), 
        input  '':U (icSafText), 
        input  tDefaultSaf (tDefaultSafs), 
        input  {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateType), 
        input  1 (idExchangeRate), 
        input  1 (idExchangeRateScale), 
        input  ? (idPostingLineCCRate), 
        input  ? (idPostingLineCCScale), 
        output viPostingLineID (oiPostingLineId), 
        input  0 (iiSafStructureId), 
        input  '':U (icSafStructureCode), 
        input  '':U (icAllocationKey), 
        input  false (ilLinkedCrCyDaemonReqExists), 
        output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>  

    if viFcReturnSuper <> 0 and oiReturnStatus >= 0
    then assign oiReturnStatus = viFcReturnSuper.                           
    if viFcReturnSuper < 0 
    then return.                      
end. /* for each tPLAmounts */                                       

if oiReturnStatus = -98
then assign oiReturnStatus = 0.