project QadFinancials > class BClosingPostingsReport > method CIRECBalance

report procedure

Description

CIRECBalance


Parameters


icLanguageCodeinputcharacterLanguage Code.
tFilterinputtemp-tableTemp table to store input parameters.
dcrCIRECBalanceoutputdatasetDataset of CIRECBalance.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program7/bclosingpostingsreport.p)

empty temp-table tqCIRECBalance.

<M-7 run GetReportLabels (input  'CIRECBalance':U (icReportName), 
                          input  icLanguageCode (icLanguageCode), 
                          input  tFilter (tFilter), 
                          output tqHeader (tqHeader), 
                          output tqFilter (tqFilter), 
                          output tqText (tqText), 
                          output oiReturnStatus (oiReturnStatus)) in BClosingPostingsReport>
if oiReturnStatus <> 0
then return.

/*assign tFilter*/
<M-1 run SetDataItemsBasedOnFilterTT (output viFcReturnSuper (oiReturnStatus)) in BClosingPostingsReport>

/*mandatory filter check*/
if viPeriodPeriodFilter = ? or viPeriodYearFilter = ?
then do:
    <M-8 run SetMessage
       (input  #T-13'Accounting Period filter not given.':255(999890582)T-13# (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QADFIN-3640':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output oiReturnStatus (oiReturnStatus)) in BClosingPostingsReport>
    assign oiReturnStatus = -1.                     
end.

if oiReturnStatus <> 0
then return.

/*get ID or code of CIREC*/
assign vcGLSystemTypeCode = {&GLSYSTEMTYPE-CIREC}.
<Q-4 run GLByGLSystemType (all) (Read) (NoCache)
   (input viCompanyId, (CompanyId)
    input vcGLSystemTypeCode, (GLSystemTypeCode)
    input ?, (GlTypeCode)
    input ?, (GlIsDivisionAccount)
    output dataset tqGLByGLSystemType) in BGL>
find first tqGLByGLSystemType no-error.
if not available tqGLByGLSystemType 
then do:
     assign vcMessage = trim (subst(#T-47'The system account '&1' is not defined.':255(450822482)T-47#,{&GLSYSTEMTYPE-CIREC-TR})).
     <M-90 run SetMessage
        (input  vcMessage (icMessage), 
         input  '':U (icArguments), 
         input  '':U (icFieldName), 
         input  '':U (icFieldValue), 
         input  'E':U (icType), 
         input  3 (iiSeverity), 
         input  '':U (icRowid), 
         input  'qadfin-880740':U (icFcMsgNumber), 
         input  '':U (icFcExplanation), 
         input  '':U (icFcIdentification), 
         input  '':U (icFcContext), 
         output oiReturnStatus (oiReturnStatus)) in BClosingPostingsReport>
    assign oiReturnStatus = -1.  
    return.
end.

assign vcGLCode        = tqGLByGLSystemType.tcGLCode
       vcGLDescription = tqGLByGLSystemType.tcGLDescription.


/*assign from to date filter for cirecclosingdate check*/
<Q-10 run PeriodByYearPeriod (all) (Read) (NoCache)
   (input viCompanyId, (CompanyId)
    input viPeriodYearFilter, (PeriodYear)
    input viPeriodPeriodFilter, (PeriodPeriod)
    input ?, (PeriodId)
    output dataset tqPeriodByYearPeriod) in BPeriod>                              
                              
find first tqPeriodByYearPeriod no-error.
if available tqPeriodByYearPeriod
then assign vtFromDateFilter = tqPeriodByYearPeriod.ttPeriodStartDate
            vtTillDateFilter = tqPeriodByYearPeriod.ttPeriodEndDate.
else do:
    <M-91 run SetMessage
       (input  #T-83'The entered GL period does not exist.':50(413993638)T-83# (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'qadfin-412098':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output oiReturnStatus (oiReturnStatus)) in BClosingPostingsReport>
    assign oiReturnStatus = -1.
    return.
end.

/* ========================================================================================= */
/* 1. Get the total balance  of all invoices which were open for CIREC on the specified date */
/* ========================================================================================= */
<Q-13 run CInvoiceCIRECPosting (all) (Read) (NoCache)
   (input viCompanyId, (CompanyId)
    input vtTillDateFilter, (EndOfDate)
    output dataset tqCInvoiceCIRECPosting) in BClosingPostingsReport>

/*create a tqCIRECBalanceRef for each CInvoice - 
this can be used if this consistency check fails, meaning finds an inconsistency */
assign viCInvoiceId               = 0
       vdINITPostingLineCreditLC  = 0
       vdINITPostingLineCreditCC  = 0
       vdINITPostingLineDebitLC   = 0
       vdINITPostingLineDebitCC   = 0
       vdALLOCPostingLineCreditLC = 0
       vdALLOCPostingLineCreditCC = 0
       vdALLOCPostingLineDebitLC  = 0
       vdALLOCPostingLineDebitCC  = 0.
       
for each tqCInvoiceCIRECPosting 
    break by tqCInvoiceCIRECPosting.tiCInvoice_ID:

    case tqCInvoiceCIRECPosting.tcCInvoicePostingType:
        when {&INVOICEPOSTINGTYPE-INITIAL}
        then assign vdINITPostingLineCreditLC  = vdINITPostingLineCreditLC  + tqCInvoiceCIRECPosting.tdPostingLineCreditLC
                    vdINITPostingLineCreditCC  = vdINITPostingLineCreditCC  + tqCInvoiceCIRECPosting.tdPostingLineCreditCC
               
                    vdINITPostingLineDebitLC   = vdINITPostingLineDebitLC   + tqCInvoiceCIRECPosting.tdPostingLineDebitLC
                    vdINITPostingLineDebitCC   = vdINITPostingLineDebitCC   + tqCInvoiceCIRECPosting.tdPostingLineDebitCC.
        when {&INVOICEPOSTINGTYPE-ALLOCATION}
        then assign vdALLOCPostingLineCreditLC = vdALLOCPostingLineCreditLC + tqCInvoiceCIRECPosting.tdPostingLineCreditLC
                    vdALLOCPostingLineCreditCC = vdALLOCPostingLineCreditCC + tqCInvoiceCIRECPosting.tdPostingLineCreditCC
               
                    vdALLOCPostingLineDebitLC  = vdALLOCPostingLineDebitLC  + tqCInvoiceCIRECPosting.tdPostingLineDebitLC
                    vdALLOCPostingLineDebitCC  = vdALLOCPostingLineDebitCC  + tqCInvoiceCIRECPosting.tdPostingLineDebitCC.
    end.
    
    if last-of (tqCInvoiceCIRECPosting.tiCInvoice_ID)
    then do:
        
        create tqCIRECBalanceRef.        
        
        assign tqCIRECBalanceRef.tcRowCode         = "CInvoice":U
               tqCIRECBalanceRef.tcJournalCode     = tqCInvoiceCIRECPosting.tcJournalCode
               tqCIRECBalanceRef.tiCInvoiceVoucher = tqCInvoiceCIRECPosting.tiCInvoiceVoucher
               tqCIRECBalanceRef.tcGLCode          = vcGLCode 
               tqCIRECBalanceRef.tcGLDescription   = vcGLDescription
               tqCIRECBalanceRef.tdCreditLC        = vdINITPostingLineCreditLC + vdALLOCPostingLineCreditLC
               tqCIRECBalanceRef.tdCreditCC        = vdINITPostingLineCreditCC + vdALLOCPostingLineCreditCC
               tqCIRECBalanceRef.tdDebitLC         = vdINITPostingLineDebitLC  + vdALLOCPostingLineDebitLC
               tqCIRECBalanceRef.tdDebitCC         = vdINITPostingLineDebitCC  + vdALLOCPostingLineDebitCC

               /*reset INIT and ALLOC values*/       
               vdINITPostingLineCreditLC  = 0
               vdINITPostingLineCreditCC  = 0
               vdINITPostingLineDebitLC   = 0
               vdINITPostingLineDebitCC   = 0
               vdALLOCPostingLineCreditLC = 0
               vdALLOCPostingLineCreditCC = 0
               vdALLOCPostingLineDebitLC  = 0
               vdALLOCPostingLineDebitCC  = 0.
    end.
end.

assign vdPostingLineCreditLC      = 0
       vdPostingLineCreditCC      = 0
       vdPostingLineDebitLC       = 0
       vdPostingLineDebitCC       = 0.

for each tqCIRECBalanceRef:
    assign
        vdPostingLineCreditLC = vdPostingLineCreditLC + tqCIRECBalanceRef.tdCreditLC
        vdPostingLineCreditCC = vdPostingLineCreditCC + tqCIRECBalanceRef.tdCreditCC
        vdPostingLineDebitLC  = vdPostingLineDebitLC  + tqCIRECBalanceRef.tdDebitLC
        vdPostingLineDebitCC  = vdPostingLineDebitCC  + tqCIRECBalanceRef.tdDebitCC.
end.

create tqCIRECBalanceRef.
assign tqCIRECBalanceRef.tcRowCode         = "CInvoiceSum":U
       tqCIRECBalanceRef.tcJournalCode     = "":U
       tqCIRECBalanceRef.tiCInvoiceVoucher = 0
       tqCIRECBalanceRef.tcGLCode          = vcGLCode
       tqCIRECBalanceRef.tcGLDescription   = vcGLDescription.

if vdPostingLineDebitLC - vdPostingLineCreditLC > 0
then assign tqCIRECBalanceRef.tdDebitLC   = vdPostingLineDebitLC - vdPostingLineCreditLC
            tqCIRECBalanceRef.tdCreditLC  = 0.
else assign tqCIRECBalanceRef.tdCreditLC  = vdPostingLineCreditLC - vdPostingLineDebitLC 
            tqCIRECBalanceRef.tdDebitLC   = 0.

if vdPostingLineDebitCC - vdPostingLineCreditCC > 0
then assign tqCIRECBalanceRef.tdDebitCC   = vdPostingLineDebitCC - vdPostingLineCreditCC
            tqCIRECBalanceRef.tdCreditCC  = 0.
else assign tqCIRECBalanceRef.tdCreditCC  = vdPostingLineCreditCC - vdPostingLineDebitCC 
            tqCIRECBalanceRef.tdDebitCC   = 0.
   
/*for each tqCIRECBalanceRef create and buffer-coppy to tqCIRECBalance*/
for each tqCIRECBalanceRef where tqCIRECBalanceRef.tcRowCode <> "CInvoice": 
    create tqCIRECBalance.
    buffer-copy tqCIRECBalanceRef to tqCIRECBalance.
end.


/* =================================================== */
/* 2. Calculate GL balances for CIREC from PostingHist */
/* =================================================== */
assign viYearPeriod = viPeriodYearFilter * 100 + viPeriodPeriodFilter.
<Q-11 run PostingHistByYearPeriodAndGL (all) (Read) (NoCache)
   (input viCompanyId, (CompanyId)
    input viYearPeriod, (yearperiod)
    input tqGLByGLSystemType.tiGL_ID, (GL_ID)
    output dataset tqPostingHistByYearPeriodAndGL) in BClosingPostingsReport >

assign vdPostingHistBalanceCreditLC = 0
       vdPostingHistBalanceCreditCC = 0
       vdPostingHistBalanceDebitLC  = 0
       vdPostingHistBalanceDebitCC  = 0.               

for each tqPostingHistByYearPeriodAndGL:

    assign vdPostingHistBalanceCreditLC = vdPostingHistBalanceCreditLC 
                       + if tqPostingHistByYearPeriodAndGL.tdPostingHistBalanceCreditLC = ? 
                         then 0 else tqPostingHistByYearPeriodAndGL.tdPostingHistBalanceCreditLC
           vdPostingHistBalanceCreditCC = vdPostingHistBalanceCreditCC 
                       + if tqPostingHistByYearPeriodAndGL.tdPostingHistBalanceCreditCC = ? 
                         then 0 else tqPostingHistByYearPeriodAndGL.tdPostingHistBalanceCreditCC
           vdPostingHistBalanceDebitLC = vdPostingHistBalanceDebitLC 
                       + if tqPostingHistByYearPeriodAndGL.tdPostingHistBalanceDebitLC = ? 
                         then 0 else tqPostingHistByYearPeriodAndGL.tdPostingHistBalanceDebitLC
           vdPostingHistBalanceDebitCC = vdPostingHistBalanceDebitCC 
                       + if tqPostingHistByYearPeriodAndGL.tdPostingHistBalanceDebitCC = ? 
                         then 0 else tqPostingHistByYearPeriodAndGL.tdPostingHistBalanceDebitCC.            
end.
 
/*create one extra record (RecType = 'PostingHistSum') with the LC, CC sums from PostingHist*/
create tqCIRECBalance.
assign tqCIRECBalance.tcRowCode         = "PostingHistSum":U
       tqCIRECBalance.tcJournalCode     = "":U
       tqCIRECBalance.tiCInvoiceVoucher = 0
       tqCIRECBalance.tcGLCode          = vcGLCode
       tqCIRECBalance.tcGLDescription   = vcGLDescription.

IF vdPostingHistBalanceDebitLC - vdPostingHistBalanceCreditLC > 0
then assign tqCIRECBalance.tdDebitLC    = vdPostingHistBalanceDebitLC - vdPostingHistBalanceCreditLC                    
            tqCIRECBalance.tdCreditLC   = 0.
else assign tqCIRECBalance.tdCreditLC   = vdPostingHistBalanceCreditLC - vdPostingHistBalanceDebitLC 
            tqCIRECBalance.tdDebitLC    = 0.
            
IF vdPostingHistBalanceDebitCC - vdPostingHistBalanceCreditCC > 0
then assign tqCIRECBalance.tdDebitCC    = vdPostingHistBalanceDebitCC - vdPostingHistBalanceCreditCC                    
            tqCIRECBalance.tdCreditCC   = 0.
else assign tqCIRECBalance.tdCreditCC   = vdPostingHistBalanceCreditCC - vdPostingHistBalanceDebitCC 
            tqCIRECBalance.tdDebitCC    = 0.