project QadFinancials > class BAPMatchingReport > method InvoiceMatching

report procedure


Parameters


icLanguageCodeinputcharacter
tFilterinputtemp-table
dcrInvoiceMatchingoutputdataset
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program7/bapmatchingreport.p)

empty temp-table tqInvoiceMatching.
assign vlNoRecord = no.

<M-1 run GetReportLabels
   (input  'InvoiceMatching':U (icReportName), 
    input  icLanguageCode (icLanguageCode), 
    input  tFilter (tFilter), 
    output tqHeader (tqHeader), 
    output tqFilter (tqFilter), 
    output tqText (tqText), 
    output viFcReturnSuper (oiReturnStatus)) in BAPMatchingReport>

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

<M-13 run SetDataItemsBasedOnFilterTT
   (output viFcReturnSuper (oiReturnStatus)) in BAPMatchingReport>

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

if (vtFromInvoiceDateFilter = ? or vtToInvoiceDateFilter = ?) and
   (viFromInvoiceYearFilter = ? or viToInvoiceYearFilter = ?)
then do:
    <M-29 run SetMessage
       (input  #T-2'Invoice Date or Invoice Year must be filled':200(733708383)T-2# (icMessage), 
        input  '' (icArguments), 
        input  '' (icFieldName), 
        input  '' (icFieldValue), 
        input  'E' (icType), 
        input  3 (iiSeverity), 
        input  '' (icRowid), 
        input  'QadFin-9483':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output oiReturnStatus (oiReturnStatus)) in BAPMatchingReport>
    assign oiReturnStatus = -1.
    return.
end. /*if (vtFromInvoiceDateFilter = ? or vtToInvoiceDateFilter = ?) and*/


if vcMatchTypeFilter = ? 
then assign vlIsLogisticMatching = ?.
else if vcMatchTypeFilter = vcMatchTypeFINANCIAL
     then assign vlIsLogisticMatching = false.
     else assign vlIsLogisticMatching = true.

create tqFilter.
assign tqFilter.ti_Sequence          = 0
       tqFilter.tcBusinessFieldLabel = 'icActivityCode':U
       tqFilter.tcBusinessFieldName  = 'MatchStatusF':U
       tqFilter.tcParameterValue     = vcMatchStatusFilter.

<Q-17 run CInvoiceForUnmatchedReceipt  (Start) in BAPMatchingReport >
<Q-18 run PendingVoucherForReceipt  (Start) in BAPMatchingReport >
<Q-19 run CInvoiceForMatchingPosting  (Start) in BAPMatchingReport >
<Q-20 run CInvoiceForUnmatchedReceipt  (Start) in BAPMatchingReport >

do viAPCompanyIterator = 1 to viAPCompanyEntries:
   assign vhFcComponent = ?.
   <M-21 run CrossCompanyValues
      (input  viAPCompanyIterator (iiEntryNumber), 
       output viFcReturnSuper (oiReturnStatus)) in BAPMatchingReport>

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

    empty temp-table tSelectedPeriod.
    assign vhFcComponent = ?.
    <M-22 run GetPeriodsOfRange
       (input  vtFromInvoiceDateFilter (itFromDate), 
        input  vtToInvoiceDateFilter (itTillDate), 
        input  viFromInvoiceYearFilter * 100 (iiFromYearPeriod), 
        input  viToInvoiceYearFilter * 100 + 99 (iiTillYearPeriod), 
        input  viAPCurrentCompany_ID (iiCompany_ID), 
        output tSelectedPeriod (tSelectedPeriods), 
        output viFcReturnSuper (oiReturnStatus)) in BPeriod>

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

    for each tSelectedPeriod
        by tSelectedPeriod.tiCompany_ID by tSelectedPeriod.tiPeriodYearPeriod:

        if tSelectedPeriod.tiPeriod_ID = 0 or
           tSelectedPeriod.tiPeriod_ID = ?
        then do:
            <M-23 run SetMessage
               (input  #T-1'Period Id is missing in Period table':40(71127)T-1# (icMessage), 
                input  '' (icArguments), 
                input  '' (icFieldName), 
                input  '' (icFieldValue), 
                input  'E' (icType), 
                input  3 (iiSeverity), 
                input  '' (icRowid), 
                input  'QadFin-8664':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output oiReturnStatus (oiReturnStatus)) in BAPMatchingReport>
            assign oiReturnStatus = -1.
            return.
        end.

        if vcMatchStatusFilter = vcMatchStatusMATCHED or vcMatchStatusFilter = ?
        then do:
            <Q-2 run CInvoiceForMatchedReceipt (all) (Read) (NoCache)
               (input vcCreditorCodeFromFilter, (FromCreditorCode)
                input vcCreditorCodeToFilter, (ToCreditorCode)
                input vcFromInvoiceJournalFilter, (FromInvoiceJournal)
                input vcToInvoiceJournalFilter, (ToInvoiceJournal)
                input viInvoiceNumberFilter, (InvoiceVoucher)
                input viToInvoiceNumberFilter, (ToInvoiceVoucher)
                input vtFromInvoiceDateFilter, (FromPostingDate)
                input vtToInvoiceDateFilter, (ToPostingDate)
                input vcInvoiceRefFilter, (InvoiceReference)
                input vlIsLogisticMatching, (IsLogisticMatching)
                input vtFromMatchDateFilter, (FromMatchingDate)
                input vtToMatchDateFilter, (ToMatchingDate)
                input viAPCurrentCompany_ID, (CompanyId)
                input vtInvoiceDateFilter, (PostingDate)
                input viFromInvoiceNumberFilter, (FromInvoiceVoucher)
                input viCreditorIDAPMFilter, (CreditorID)
                input tSelectedPeriod.tiPeriod_ID, (Period_ID)
                input viJournalIDFilter, (Journal_ID)
                output dataset tqCInvoiceForMatchedReceipt) in BAPMatchingReport >
            for each tqCInvoiceForMatchedReceipt 
                break by tqCInvoiceForMatchedReceipt.tiCInvoice_ID:
                if tqCInvoiceForMatchedReceipt.tlCInvoiceIsLogisticMatching = yes                   and
                   tqCInvoiceForMatchedReceipt.tcPvoDomain                   <> ?                    and 
                   tqCInvoiceForMatchedReceipt.tcPvoDomain                   <> "":U                 and
                   tqCInvoiceForMatchedReceipt.tiPvoID                       <> ?                    and
                   tqCInvoiceForMatchedReceipt.tiPvoID                       <> 0                    and
                   (tqCInvoiceForMatchedReceipt.tcCInvoiceAllocationStatus = {&ALLOCSTATUS-ANY} or
                    tqCInvoiceForMatchedReceipt.tcCInvoiceAllocationStatus = {&ALLOCSTATUS-ALLOC})   
                then do:              
                    <Q-9 run PendingVoucherForReceipt (all) (Read) (NoCache)
                       (input tqCInvoiceForMatchedReceipt.tcPvoDomain, (PvoDomain)
                        input tqCInvoiceForMatchedReceipt.tiPvoID, (PvoId)
                        input tqCInvoiceForMatchedReceipt.tiPvodLineID, (PvodLineId)
                        output dataset tqPendingVoucherForReceipt) in BAPMatchingReport >
                    for each tqPendingVoucherForReceipt:
                        create tqInvoiceMatching.
                        buffer-copy tqCInvoiceForMatchedReceipt to tqInvoiceMatching.
                        assign  tqInvoiceMatching.tlInvoiceIsMatched = true
                                tqInvoiceMatching.ttprh_rcp_date     = tqPendingVoucherForReceipt.ttprh_rcp_date
                                tqInvoiceMatching.tiprh_line         = tqPendingVoucherForReceipt.tiprh_line
                                tqInvoiceMatching.tdReceiptAmount    = tqPendingVoucherForReceipt.tdprh_pur_cost * tqPendingVoucherForReceipt.tdprh_rcvd * tqPendingVoucherForReceipt.tdprh_um_conv * tqPendingVoucherForReceipt.tdprh_ex_rate / tqPendingVoucherForReceipt.tdprh_ex_rate2
                                tqInvoiceMatching.tcprh_vend         = tqPendingVoucherForReceipt.tcprh_vend
                                tqInvoiceMatching.tcprh_receiver     = tqPendingVoucherForReceipt.tcprh_receiver
                                tqInvoiceMatching.tcprh_part         = tqPendingVoucherForReceipt.tcprh_part
                                tqInvoiceMatching.tcprh_nbr          = tqPendingVoucherForReceipt.tcprh_nbr
                                tqInvoiceMatching.tcprh_um           = tqPendingVoucherForReceipt.tcprh_um
                                tqInvoiceMatching.tcMatchType        = vcMatchStatusFilter.
                        assign  tqInvoiceMatching.tiCurrencyNumberOfDecimals = tqCInvoiceForMatchedReceipt.tiCurrencyNumberOfDecimals
                                tqInvoiceMatching.tiQtyNumDec                = tqCInvoiceForMatchedReceipt.tiCompanyPropertyQtyNumDec.
                    end. /*for each tqPendingVoucherForReceipt:*/
                end. /* if tqCInvoiceForMatchedReceipt.tlCInvoiceIsLogisticMatching = yes and... */
                else if tqCInvoiceForMatchedReceipt.tlCInvoiceIsLogisticMatching = no  and
                       (tqCInvoiceForMatchedReceipt.tcCInvoiceAllocationStatus = {&ALLOCSTATUS-ANY}   or
                        tqCInvoiceForMatchedReceipt.tcCInvoiceAllocationStatus = {&ALLOCSTATUS-ALLOC} or
                        tqCInvoiceForMatchedReceipt.tcCInvoiceAllocationStatus = {&ALLOCSTATUS-TRANSALLOC})
                then do:
                    create tqInvoiceMatching.
                    buffer-copy tqCInvoiceForMatchedReceipt to tqInvoiceMatching.
                    assign  tqInvoiceMatching.tlInvoiceIsMatched = true
                            tqInvoiceMatching.tcMatchType        = vcMatchStatusFilter
                            tqInvoiceMatching.ttAPMatchingDate   = tqCInvoiceForMatchedReceipt.ttPostingDate.
                    assign  tqInvoiceMatching.tiCurrencyNumberOfDecimals = tqCInvoiceForMatchedReceipt.tiCurrencyNumberOfDecimals
                            tqInvoiceMatching.tiQtyNumDec                = tqCInvoiceForMatchedReceipt.tiCompanyPropertyQtyNumDec.
                end. /* if tqCInvoiceForMatchedReceipt.tlCInvoiceIsLogisticMatching = no... */
            end.  /* for each tqCInvoiceForMatchedReceipt */

            <Q-16 run CInvoiceForMatchingPosting (all) (Read) (NoCache)
               (input viCompanyIDFilter, (CompanyId)
                input vcCreditorCodeFromFilter, (FromCreditorCode)
                input vcCreditorCodeToFilter, (ToCreditorCode)
                input vcFromInvoiceJournalFilter, (FromInvoiceJournal)
                input vcToInvoiceJournalFilter, (ToInvoiceJournal)
                input viFromInvoiceNumberFilter, (FromInvoiceVoucher)
                input viToInvoiceNumberFilter, (ToInvoiceVoucher)
                input vcInvoiceRefFilter, (InvoiceReference)
                input vlIsLogisticMatching, (IsLogisticMatching)
                input viInvoiceNumberFilter, (InvoiceNumber)
                input vtFromInvoiceDateFilter, (FromInvoiceDate)
                input vtToInvoiceDateFilter, (ToInvoiceDate)
                input vtInvoiceDateFilter, (InvoiceDate)
                input viCreditorIDAPMFilter, (CreditorID)
                input tSelectedPeriod.tiPeriod_ID, (Period_ID)
                input viJournalIDFilter, (Journal_ID)
                output dataset tqCInvoiceForMatchingPosting) in BAPMatchingReport >

            for each tqCInvoiceForMatchedReceipt where 
                     tqCInvoiceForMatchedReceipt.tcCInvoiceAllocationStatus   = {&ALLOCSTATUS-ANY}         or
                     tqCInvoiceForMatchedReceipt.tcCInvoiceAllocationStatus   = {&ALLOCSTATUS-ALLOC}       or
                    (tqCInvoiceForMatchedReceipt.tcCInvoiceAllocationStatus   = {&ALLOCSTATUS-TRANSALLOC} and
                     tqCInvoiceForMatchedReceipt.tlCInvoiceIsLogisticMatching = no)
                break by tqCInvoiceForMatchedReceipt.tiCInvoice_ID:
                if first-of(tqCInvoiceForMatchedReceipt.tiCInvoice_ID)
                then do:
                    for each tqCInvoiceForMatchingPosting where 
                             tqCInvoiceForMatchingPosting.tiCInvoice_ID = tqCInvoiceForMatchedReceipt.tiCInvoice_ID:
                        create tqInvoiceMatching.
                        buffer-copy tqCInvoiceForMatchingPosting to tqInvoiceMatching.
                        assign tqInvoiceMatching.tlInvoiceIsMatched = ?
                               tqInvoiceMatching.tcMatchType        = vcMatchStatusFilter.
                        assign   tqInvoiceMatching.tiCurrencyNumberOfDecimals = tqCInvoiceForMatchingPosting.tiCurrencyNumberOfDecimals
                                 tqInvoiceMatching.tiQtyNumDec                = tqCInvoiceForMatchingPosting.tiCompanyPropertyQtyNumDec.
                    end. /*tqCInvoiceForMatchingPosting*/
                end. /* if first-of(tqCInvoiceForMatchedReceipt.tiCInvoice_ID) */
            end. /* for each tqCInvoiceForMatchedReceipt where tqCInvoiceForMatchedReceipt.tcCInvoiceAllocationStatus = {&ALLOCSTATUS-ANY} ... */
        end. /*if vcMatchStatusFilter = "MATCHED":U or vcMatchStatusFilter = ?*/
        if vcMatchStatusFilter = vcMatchStatusUNMATCHED or vcMatchStatusFilter = ?
        then do:
            <Q-25 run CInvoiceForUnmatchedReceipt (all) (Read) (NoCache)
               (input viAPCurrentCompany_ID, (CompanyId)
                input vcCreditorCodeFromFilter, (FromCreditorCode)
                input vcCreditorCodeToFilter, (ToCreditorCode)
                input vcFromInvoiceJournalFilter, (FromInvoiceJournal)
                input vcToInvoiceJournalFilter, (ToInvoiceJournal)
                input viFromInvoiceNumberFilter, (FromInvoiceVoucher)
                input viToInvoiceNumberFilter, (ToInvoiceVoucher)
                input vtFromInvoiceDateFilter, (FromPostingDate)
                input vtToInvoiceDateFilter, (ToPostingDate)
                input vcInvoiceRefFilter, (InvoiceReference)
                input vlIsLogisticMatching, (IsLogisticMatching)
                input tSelectedPeriod.tiPeriod_ID, (Period_ID)
                input viJournalIDFilter, (Journal_ID)
                input viCreditorIDAPMFilter, (CreditorID)
                output dataset tqCInvoiceForUnmatchedReceipt) in BAPMatchingReport >
            for each tqCInvoiceForUnmatchedReceipt 
                     break by tqCInvoiceForUnmatchedReceipt.tiCInvoice_ID:
                if last-of(tqCInvoiceForUnmatchedReceipt.tiCInvoice_ID) then
                do:        
                    create tqInvoiceMatching.
                    buffer-copy tqCInvoiceForUnmatchedReceipt to tqInvoiceMatching.
                    assign tqInvoiceMatching.tlInvoiceIsMatched = false
                           tqInvoiceMatching.tcMatchType = vcMatchStatusFilter.
                    assign tqInvoiceMatching.tiCurrencyNumberOfDecimals = tqCInvoiceForUnmatchedReceipt.tiCurrencyNumberOfDecimals
                           tqInvoiceMatching.tiQtyNumDec                = tqCInvoiceForUnmatchedReceipt.tiCompanyPropertyQtyNumDec.
                end. /*if last-of(tqCInvoiceForUnmatchedReceipt.tiCInvoice_ID) */
            end. /*for each tqCInvoiceForUnmatchedReceipt:*/
        end. /*if vcMatchStatusFilter = "UNMATCHED":U or vcMatchStatusFilter = ?*/
    end. /* for each tSelectedPeriod */
end. /* do viAPCompanyIterator = 1 to viAPCompanyEntries: */
<Q-24 run PendingVoucherForReceipt  (Stop) in BAPMatchingReport >
<Q-27 run CInvoiceForUnmatchedReceipt  (Stop) in BAPMatchingReport >
<Q-28 run CInvoiceForMatchingPosting  (Stop) in BAPMatchingReport >

/* notify UI to suppress Matched Invoices part */
find first tqInvoiceMatching no-error.
if not available tqInvoiceMatching
then do:
    create tqFilter.
    assign tqFilter.ti_Sequence          = 0
           tqFilter.tcBusinessFieldLabel = 'icActivityCode':U
           tqFilter.tcBusinessFieldName  = 'MatchInvoice':U
           tqFilter.tcParameterValue     = 'NONE':U.
    create tqInvoiceMatching.
    assign tqInvoiceMatching.tiCInvoice_ID = -99
           tqInvoiceMatching.tlInvoiceIsMatched = yes.
end. /* if not available tqInvoiceMatching */

/* notify UI to suppress Unmatched Invoices part */
find first tqInvoiceMatching where tqInvoiceMatching.tlInvoiceIsMatched = false no-error.
if not available tqInvoiceMatching
then do:
    create tqFilter.
    assign tqFilter.ti_Sequence          = 0
           tqFilter.tcBusinessFieldLabel = 'icActivityCode':U
           tqFilter.tcBusinessFieldName  = 'UnmatchInvoice':U
           tqFilter.tcParameterValue     = 'NONE':U.

    create tqInvoiceMatching.
    assign tqInvoiceMatching.tiCInvoice_ID = -99
           tqInvoiceMatching.tlInvoiceIsMatched = no.
end. /* if not available tqInvoiceMatching */

/* if there is no matching invoices & unmatching invoices, then delete all tqInvoiceMatching records */
find first tqInvoiceMatching where tqInvoiceMatching.tiCInvoice_ID <> -99 no-error.
if not available tqInvoiceMatching
then assign vlNoRecord = yes.
if vlNoRecord = yes
then do:
    for each tqInvoiceMatching where tqInvoiceMatching.tiCInvoice_ID = -99:
        delete tqInvoiceMatching.
    end.
end. /* if not available tqInvoiceMatching */