project QadFinancials > class BCreditorReport > method CreditorCIREC

report procedure


Parameters


icLanguageCodeinputcharacter
tFilterinputtemp-table
dcrCreditorCIRECoutputdataset
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program7/bcreditorreport.p)

assign vcAllocationStatus = "":U.

empty temp-table tqCreditorCIREC.
empty temp-table tBaseCIRECCopy.

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

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

/* Check If Filterfields are correct */
assign vcCErrorMessage = "":U.

if vcNatureFilter1 = "CURRENT":U
then do:
    if viFromAccYearFilter1 = ? or viFromAccYearFilter1 = 0
    then assign vcCErrorMessage = #T-7'The From GL Calendar filter requires a value.':50(1461)T-7# + chr(10).
    if viFromAccPeriodFilter1 = ? 
    then assign vcCErrorMessage = vcCErrorMessage + #T-8'The From GL Period filter requires a value':50(1462)T-8# + chr(10).
end.

if viToAccYearFilter1 = ? or viToAccYearFilter1 = 0
then assign vcCErrorMessage = vcCErrorMessage + #T-9'The To GL Calendar filter requires a value.':50(1463)T-9# + chr(10).
if viToAccPeriodFilter1 = ?
then assign vcCErrorMessage = vcCErrorMessage + #T-10'The To GL Period filter requires a value.':50(1464)T-10# + chr(10).

if vcNatureFilter1 = "HISTORY":U and not vlUnallocatedOnlyFilter1 
then assign vcCErrorMessage = vcCErrorMessage + #T-11'Backward analysis is only possible for unallocated invoices.':80(1465)T-11# + chr(10).

/* Get start and end dates of period given - for backward analysis */
if vcNatureFilter1 = "HISTORY":U 
then do:
    <Q-4 run GetPeriodDates (all) (Read) (NoCache)
          (input viCompanyId, (CompanyId)
           input viToAccPeriodFilter1, (Period)
           input viToAccYearFilter1, (Year)
           output dataset tqGetPeriodDates) in BCreditorReport >
    find first tqGetPeriodDates no-error.
    if not available tqGetPeriodDates 
    then assign vcCErrorMessage = vcCErrorMessage + #T-12'The GL period you entered is not defined in the system.':50(1466)t-12# + chr(10).
end.

if vcCErrorMessage <> "":U
then do:
     <M-3 run SetMessage (input  vcCErrorMessage (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-936':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BCreditorReport>               
    assign oiReturnStatus = -1.
    return.
end.

/* Setting default values */
if vlUnallocatedOnlyFilter1 = ? then assign vlUnallocatedOnlyFilter1 = yes.
if vcNatureFilter1 = ? then assign vcNatureFilter1 = "CURRENT":U.

/* Transform period from YYYY/PP to YYYYPP form 
   For BACKWARDS view the from period has to be undefined */
/* If Nature = Current then get all currently unallocated invoices within period given */
assign viToAccPeriodFilter1  = (viToAccYearFilter1 * 100) + viToAccPeriodFilter1.

assign viFromAccPeriodFilter1 = (viFromAccYearFilter1 * 100) + viFromAccPeriodFilter1
       vcAllocationStatus = if vlUnallocatedOnlyFilter1 then {&ALLOCSTATUS-ALLOC} else ?       
       viAllocPeriod = ?
       vtDatePeriod = ?
       vcPostingType = ?.

if vcNatureFilter1 = "HISTORY":U then assign vcAllocationStatus = {&ALLOCSTATUS-ALLOC}.

/* Calling Base querry : get all records that have no allocation and are created within period given*/
<Q-2 run BaseCIREC (all) (Read) (NoCache)
          (input viCompanyId, (CompanyId)
           input vcCandoCreditorCodeFilter1, (CandoCreditorCode)
           input vcCandoBRCodeFilter1, (CandoBRCode)
           input vcFromBRCodeFilter1, (FromBRCode)
           input vcFromCreditorCodeFilter1, (FromCreditorCode)
           input viToAccPeriodFilter1, (ToAccPeriod)
           input vcToBRCodeFilter1, (ToBRCode)
           input vcToCreditorCodeFilter1, (ToCreditorCode)
           input viFromAccPeriodFilter1, (FromAccPeriod)
           input vcAllocationStatus, (AllocationStatus)
           input viAllocPeriod, (AllocPeriod)
           input vtDatePeriod, (DatePeriod)
           input vcPostingType, (PostingType)
           output dataset tqBaseCIREC) in BCreditorReport >

/* Now if we make analysis backwards, we have to get all records that were allocated after given period. */
if vcNatureFilter1 = "HISTORY":U 
then do:
    for each tqBaseCIREC:
        create tBaseCIRECCopy.
        buffer-copy tqBaseCIREC to tBaseCIRECCopy.
    end.

    assign vcAllocationStatus = {&ALLOCSTATUS-TRANSALLOC}
           viAllocPeriod = viToAccPeriodFilter1
           vtDatePeriod = tqGetPeriodDates.ttPeriodEndDate
           vcPostingType = {&INVOICEPOSTINGTYPE-ALLOCATION}
           viFromAccPeriodFilter1 = ?
           viToAccPeriodFilter1   = ?.

    <Q-5 run BaseCIREC (all) (Read) (NoCache)
          (input viCompanyId, (CompanyId)
           input vcCandoCreditorCodeFilter1, (CandoCreditorCode)
           input vcCandoBRCodeFilter1, (CandoBRCode)
           input vcFromBRCodeFilter1, (FromBRCode)
           input vcFromCreditorCodeFilter1, (FromCreditorCode)
           input viToAccPeriodFilter1, (ToAccPeriod)
           input vcToBRCodeFilter1, (ToBRCode)
           input vcToCreditorCodeFilter1, (ToCreditorCode)
           input viFromAccPeriodFilter1, (FromAccPeriod)
           input vcAllocationStatus, (AllocationStatus)
           input viAllocPeriod, (AllocPeriod)
           input vtDatePeriod, (DatePeriod)
           input vcPostingType, (PostingType)
           output dataset tqBaseCIREC) in BCreditorReport >

    for each tBaseCIRECCopy:
        create tqBaseCIREC.
        buffer-copy tBaseCIRECCopy to tqBaseCIREC. 
    end.
end.

for each tqBaseCIREC break by tqBaseCIREC.tiCInvoice_ID:

    if first-of (tqBaseCIREC.tiCInvoice_ID) 
    then assign vlIsHeaderCreated = false.

    if (tqBaseCIREC.tcCInvoicePostingType = {&INVOICEPOSTINGTYPE-INITIAL} or vcNatureFilter1 = "HISTORY":U) and 
        not vlIsHeaderCreated
    then do:
        create tqCreditorCIREC.
        assign tqCreditorCIREC.tcBusinessRelationName1 = tqBaseCIREC.tcBusinessRelationName1
               tqCreditorCIREC.tcCreditorCode          = tqBaseCIREC.tcCreditorCode
               tqCreditorCIREC.tcCurrencyCode          = tqBaseCIREC.tcCurrencyCode
               tqCreditorCIREC.tiCurrencyNumberOfDecimals = tqBaseCIREC.tiCurrencyNumberOfDecimals
               tqCreditorCIREC.ttCInvoiceDate          = tqBaseCIREC.ttCInvoicePostingDate
               tqCreditorCIREC.tcJournalCode           = tqBaseCIREC.tcCInvoiceJournalCode
               tqCreditorCIREC.tiCInvoiceVoucher       = tqBaseCIREC.tiCInvoiceVoucher
               tqCreditorCIREC.tcCInvoiceReference     = tqBaseCIREC.tcCInvoiceReference
               tqCreditorCIREC.tiLinkedPeriod          = tqBaseCIREC.tiLinkedPerioPeriod
               tqCreditorCIREC.tiLinkedYear            = tqBaseCIREC.tiLinkedPeriodYear
               tqCreditorCIREC.tiLinkedCInvoiceVoucher = tqBaseCIREC.tiLinkedCInvoiceVoucher
               tqCreditorCIREC.tcLinkedJournalCode     = tqBaseCIREC.tcLinkedJournalCode
               tqCreditorCIREC.tcReasonCode            = tqBaseCIREC.tcReasonCode
               tqCreditorCIREC.tiCInvoice_ID           = tqBaseCIREC.tiCInvoice_ID.

        assign vlIsHeaderCreated = true.

        if vcNatureFilter1 = "CURRENT":U or tqBaseCIREC.tcCInvoicePostingType = {&INVOICEPOSTINGTYPE-INITIAL} 
        then assign tqCreditorCIREC.tcAllocationStatus      = tqBaseCIREC.tcCInvoicePostingType
                    tqCreditorCIREC.tdCInvoiceBalanceTC     = tqBaseCIREC.tdPostingLineDebitTC - tqBaseCIREC.tdPostingLineCreditTC
                    tqCreditorCIREC.tdCInvoiceBalanceLC     = tqBaseCIREC.tdPostingLineDebitLC - tqBaseCIREC.tdPostingLineCreditLC.
        else assign tqCreditorCIREC.tcAllocationStatus      = {&INVOICEPOSTINGTYPE-INITIAL}
                    tqCreditorCIREC.tdCInvoiceBalanceTC     = - (tqBaseCIREC.tdPostingLineDebitTC - tqBaseCIREC.tdPostingLineCreditTC)
                    tqCreditorCIREC.tdCInvoiceBalanceLC     = - (tqBaseCIREC.tdPostingLineDebitLC - tqBaseCIREC.tdPostingLineCreditLC).
    end.
    if tqBaseCIREC.tcCInvoicePostingType = {&INVOICEPOSTINGTYPE-ALLOCATION} /*and vcNatureFilter1 <> "HISTORY":U*/
    then do:
        create tqCreditorCIREC.
        assign tqCreditorCIREC.tiCInvoice_ID           = tqBaseCIREC.tiCInvoice_ID
               tqCreditorCIREC.tcCreditorCode          = tqBaseCIREC.tcCreditorCode
               tqCreditorCIREC.tcCurrencyCode          = tqBaseCIREC.tcCurrencyCode
               tqCreditorCIREC.tiCurrencyNumberOfDecimals = tqBaseCIREC.tiCurrencyNumberOfDecimals
               tqCreditorCIREC.tcAllocatedJournalCode  = tqBaseCIREC.tcPostingJournalCode /* To change in condition */
               tqCreditorCIREC.tiAllocatedVoucher      = tqBaseCIREC.tiPostingVoucher
               tqCreditorCIREC.ttAllocatedDate         = tqBaseCIREC.ttPostingDate
               tqCreditorCIREC.tcAllocationStatus      = tqBaseCIREC.tcCInvoicePostingType
               tqCreditorCIREC.tlIsTransientAllocation = if tqBaseCIREC.tcCInvoiceAllocationStatus = {&ALLOCSTATUS-TRANSALLOC} then yes else no
               tqCreditorCIREC.tdCInvoiceBalanceTC     = tqBaseCIREC.tdPostingLineDebitTC - tqBaseCIREC.tdPostingLineCreditTC
               tqCreditorCIREC.tdCInvoiceBalanceLC     = tqBaseCIREC.tdPostingLineDebitLC - tqBaseCIREC.tdPostingLineCreditLC.
    end.
end.