project QadFinancials > class BCDocumentReport > method CDocumentReportAll


Parameters


icCDocumentTypeinputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCDocumentReport.CDocumentReportAutoIncasso
method BCDocumentReport.CDocumentReportCheque
method BCDocumentReport.CDocumentReportDraft
method BCDocumentReport.CDocumentReportPromisNote
method BCDocumentReport.CDocumentReportSumStatement
method BCDocumentReport.CDocumentReportTransfer


program code (program4/bcdocumentreport.p)

empty temp-table tCDocumentPrintCDR.
empty temp-table tCDocumentReportAll.
empty temp-table tVoided.

/* Assign the filter-data-items based on the tFilter records  */
<M-1 run SetDataItemsBasedOnFilterTT
   (output viCCollectionNumber (oiCCollectionNumber), 
    output vtCDocumentCreationDateFrom (otCDocumentCreationDateFrom), 
    output vtCDocumentCreationDateTill (otCDocumentCreationDateTill), 
    output vtCDocumentDueDateFrom (otCDocumentDueDateFrom), 
    output vtCDocumentDueDateTill (otCDocumentDueDateTill), 
    output vlCDocumentIsOpen (olCDocumentIsOpen), 
    output viCDocumentNumberFrom (oiCDocumentNumberFrom), 
    output viCDocumentNumberTo (oiCDocumentNumberTo), 
    output viCDocumentPrePrintedNumberFrom (oiCDocumentPrePrintedNumberFrom), 
    output viCDocumentPrePrintedNumberTo (oiCDocumentPrePrintedNumberTo), 
    output vcCDocumentReference (ocCDocumentReference), 
    output vcCDocumentStatus (ocCDocumentStatus), 
    output vcCDocumentSubType (ocCDocumentSubType), 
    output vlCDocumentTimesPrinted (olCDocumentTimesPrinted), 
    output viCDocumentYear (oiCDocumentYear), 
    output vcCreditorCode (ocCreditorCode), 
    output vcCurrencyCode (ocCurrencyCode), 
    output vcPaySelCode (ocPaySelCode), 
    output vlIncreaseCDocumentTimesPrinted (olIncreaseCDocumentTimesPrinted), 
    output vlAssignCDocumentPrePrintedNum (olAssignCDocumentPrePrintedNum), 
    output viStartCDocumentPrePrintedNum (oiStartCDocumentPrePrintedNum), 
    output viSkipCDocumentPrePrintedNum (oiSkipCDocumentPrePrintedNum), 
    output viBankPayFormatID (oiBankPayformatID), 
    output vcPrintType (ocPrintType), 
    output vcCreditorBRNameFrom (ocCreditorFromBRName), 
    output vcCreditorBRNameTo (ocCreditorToBRName), 
    output viFcReturnSuper (oiReturnStatus)) in BCDocumentReport>

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

/* set values for report Supplier Check Print */
if icCDocumentType = {&DOCUMENTTYPECREDITOR-CHEQUE} or icCDocumentType = {&DOCUMENTTYPECREDITOR-DRAFT}
then do:

    /* start --- zhc defect 10249-0021 */
    /* Do validation for the mismatching of Bank Pay Format and Payment Selection */
    if vcPaySelCode <> ? and vcPaySelCode <> '':U and viBankPayFormatID <> ? and viBankPayFormatID <> 0
    then do:
        <Q-121 run GetPayFormatByPaySelCode (all) (Read) (NoCache)
           (input viCompanyId, (CompanyId)
            input vcPaySelCode, (PaySelCode)
            output dataset tqGetPayFormatByPaySelCode) in BCDocumentReport >
        find first tqGetPayFormatByPaySelCode no-error.
        if not available tqGetPayFormatByPaySelCode
        then return.

        /*<Q-125 run BankPayFormatPrim (all) (Read) (NoCache)
           (input ?, (BankNumberId)
            input viBankPayFormatID, (BankPayFormatId)
            input '':U, (PayFormatTypeCode)
            output dataset tqBankPayFormatPrim) in BBankPayFormat >*/
        <Q-126 run BankPayFormatByID (all) (Read) (NoCache)
           (input viBankPayFormatID, (BankPayFormatId)
            input viCompanyId, (CompanyId)
            output dataset tqBankPayFormatByID) in BBankPayFormat >
        find first tqBankPayFormatByID no-error.
        if not available tqBankPayFormatByID
        then return.

        if tqGetPayFormatByPaySelCode.tcPayFormatTypeCode <> tqBankPayFormatByID.tcPayFormatTypeCode or
           tqGetPayFormatByPaySelCode.tcBankNumber <> tqBankPayFormatByID.tcBankNumber
        then do:
            assign vcMessage = trim(#T-124'The payment selection that you specified has another bank number or payment format than the one that you specified.':200(69478)T-124#).
            <M-123 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-8028':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BCDocumentReport>
            assign oiReturnStatus = -1.
            return.
        end. /* if tqGetPayFormatByPaySelCode.tcPayFormatTypeCode <> tqBankPayFormatPrim.tcPayFormatTypeCode */
    end. /* if vcPaySelCode <> ? and vcPaySelCode <> '':U */
    /* end --- zhc defect 10249-0021 */

    if viBankPayFormatID = ? or 
       viBankPayFormatID = 0 or
       vcPrintType       = ? or
       vcPrintType       = '':U
    then do:        
        assign vcMessage = trim(#T-113'You must enter a bank payment format and a print type.':200(65755)T-113#).
        <M-112 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-7463':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BCDocumentReport>
        assign oiReturnStatus = -1.
        return.
    end. /* if viBankPayFormatID = ? or  */
    /* to get next preprint number for TEST and FINAL print */
    if (vcPrintType = {&PRINTTYPE-FINAL}  or 
        vcPrintType = {&PRINTTYPE-TEST})  and
       (viStartCDocumentPrePrintedNum = ? or
        viStartCDocumentPrePrintedNum = 0) 
    then do:                 
        /* to get next number and assign to start from number */
        <Q-114 run BankPayFormatPrim (all) (Read) (NoCache)
           (input ?, (BankNumberId)
            input viBankPayFormatID, (BankPayFormatId)
            input '':U, (PayFormatTypeCode)
            output dataset tqBankPayFormatPrim) in BBankPayFormat >
        find first tqBankPayFormatPrim no-error.
        if available tqBankPayFormatPrim
        then do:             
            if tqBankPayFormatPrim.tiBankPayFormatNextCheckNbr <> ? and 
               tqBankPayFormatPrim.tiBankPayFormatNextCheckNbr <> 0
            then assign viStartCDocumentPrePrintedNum = tqBankPayFormatPrim.tiBankPayFormatNextCheckNbr.
            else do:                 
                assign vcMessage = trim(#T-116'You must first enter the Next Pre-Printed Number on the bank payment format first.':255(65758)T-116#).
                <M-115 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  'tqBankPayFormatPrim.tiBankPayFormatNextCheckNbr':U (icFieldName), 
                    input  string(tqBankPayFormatPrim.tiBankPayFormatNextCheckNbr) (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  '':U (icRowid), 
                    input  'QadFin-7465':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BCDocumentReport>
                assign oiReturnStatus = -1.
                return.
            end. /* else do */
        end. /* if available */
    end. /* if vcPrintType = {&PRINTTYPE-FINAL} or vcPrintType = {&PRINTTYPE-TEST} */

    if vcPrintType = {&PRINTTYPE-TEST}
    then do:         
        assign vlAssignCDocumentPrePrintedNum  = true /* zhc defect 10249-0022: Modify the assigned value from false to true */
               vlIncreaseCDocumentTimesPrinted = false
               vlCDocumentTimesPrinted         = true.
    end. /* if vcPrintType = {&PRINTTYPE-TEST} */
    
    if vcPrintType = {&PRINTTYPE-FINAL}
    then do:
        assign vlAssignCDocumentPrePrintedNum  = true
               vlIncreaseCDocumentTimesPrinted = true
               vlCDocumentTimesPrinted         = true.
    end. /* if vcPrintType = {&PRINTTYPE-FINAL} */

    if vcPrintType = {&PRINTTYPE-PRINTDUPL}
    then do:
        assign vlAssignCDocumentPrePrintedNum  = false
               vlIncreaseCDocumentTimesPrinted = true
               vlCDocumentTimesPrinted         = false
               /*viStartCDocumentPrePrintedNum   = ?*/.
    end. /* if vcPrintType = {&PRINTTYPE-PRINTDUPL} */
end. /* if icCDocumentType = {&DOCUMENTTYPECREDITOR-CHEQUE} */

assign viOriginalStartNum = viStartCDocumentPrePrintedNum.
assign viStartCDocumentPrePrintedNum = viStartCDocumentPrePrintedNum - 1.

/* Get CDocument Data */
<Q-63 run CDocumentByFilter (all) (Read) (NoCache)
   (input viCompanyId, (CompanyId)
    input viCCollectionNumber, (CCollectionNumber)
    input vtCDocumentCreationDateFrom, (CDocumentCreationDateFrom)
    input vtCDocumentCreationDateTill, (CDocumentCreationDateTill)
    input vtCDocumentDueDateFrom, (CDocumentDueDateFrom)
    input vtCDocumentDueDateTill, (CDocumentDueDateTill)
    input vlCDocumentIsOpen, (CDocumentIsOpen)
    input viCDocumentNumberFrom, (CDocumentNumberFrom)
    input viCDocumentNumberTo, (CDocumentNumberTo)
    input viCDocumentPrePrintedNumberFrom, (CDocumentPrePrintedNumberFr)
    input viCDocumentPrePrintedNumberTo, (CDocumentPrePrintedNumberTo)
    input vcCDocumentReference, (CDocumentReference)
    input vcCDocumentStatus, (CDocumentStatus)
    input vcCDocumentSubType, (CDocumentSubType)
    input if vlCDocumentTimesPrinted then 1 else ?, (CDocumentTimesPrinted)
    input viCDocumentYear, (CDocumentYear)
    input vcCreditorCode, (CreditorCode)
    input vcCurrencyCode, (CurrencyCode)
    input vcPaySelCode, (PaySelCode)
    input icCDocumentType, (CDocumentType)
    input if vlCDocumentTimesPrinted then ? else 1, (CDocumentTimesPrintedMin)
    input vcCreditorBRNameFrom, (BusinessRelationNameFrom)
    input vcCreditorBRNameTo, (BusinessRelationNameTo)
    input viBankPayFormatID, (BankPayFormatID)
    output dataset tqCDocumentByFilter) in BCDocumentReport >

find first tqCDocumentByFilter
           no-error.

if not available tqCDocumentByFilter
then return.

/* Get company data */
<Q-53 run CompanyPropertyByCompanyId (all) (Read) (NoCache)
   (input viCompanyId, (CompanyId)
    input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode)
    output dataset tqCompanyPropertyByCompanyId) in BCDocumentReport >

find first tqCompanyPropertyByCompanyId where
           tqCompanyPropertyByCompanyId.tiCompany_ID      = viCompanyId and
           tqCompanyPropertyByCompanyId.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-HEADOFFICE}
           no-error.

/* Initialize */
<Q-51 run CDocumentInvoiceXrefByCDocId (Start) in BCDocumentReport >
<Q-54 run BankNumberByParent (Start) in BCDocumentReport >
<Q-69 run AddressByBusRelAddressType (Start) in BCDocumentReport >
<Q-71 run VatNumberByBusRelCountry (Start) in BCDocumentReport >

/* Process Data */
for each tqCDocumentByFilter where tqCDocumentByFilter.tcCDocumentStatus <> {&DOCUMENTSTATUS-VOID}
    and tqCDocumentByFilter.tcCDocumentStatus <> {&DOCUMENTSTATUS-BOUNCED}:
    

    /* Get Address Info */
    <Q-73 run AddressByBusRelAddressType (all) (Read) (NoCache)
          (input tqCDocumentByFilter.tiBusinessRelation_ID, (BusinessRelationId)
           input {&ADDRESSTYPECODESYSTEM-PAYM}, (AddressTypeCode)
           output dataset tqAddressByBusRelAddressType) in BCDocumentReport >

    find first tqAddressByBusRelAddressType where
               tqAddressByBusRelAddressType.tiBusinessRelation_ID = tqCDocumentByFilter.tiBusinessRelation_ID and
               tqAddressByBusRelAddressType.tcAddressTypeCode     = {&ADDRESSTYPECODESYSTEM-PAYM}
               no-error.

    if not available tqAddressByBusRelAddressType
    then do:
        <Q-74 run AddressByBusRelAddressType (all) (Read) (NoCache)
           (input tqCDocumentByFilter.tiBusinessRelation_ID, (BusinessRelationId)
            input {&ADDRESSTYPECODESYSTEM-REMITTANCE}, (AddressTypeCode)
            output dataset tqAddressByBusRelAddressType) in BCDocumentReport >

        find first tqAddressByBusRelAddressType where
                   tqAddressByBusRelAddressType.tiBusinessRelation_ID = tqCDocumentByFilter.tiBusinessRelation_ID and
                   tqAddressByBusRelAddressType.tcAddressTypeCode     = {&ADDRESSTYPECODESYSTEM-REMITTANCE}
                   no-error.

        if not available tqAddressByBusRelAddressType
        then do:
            <Q-127 run AddressByBusRelAddressType (all) (Read) (NoCache)
               (input tqCDocumentByFilter.tiBusinessRelation_ID, (BusinessRelationId)
                input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode)
                output dataset tqAddressByBusRelAddressType) in BCDocumentReport >

            find first tqAddressByBusRelAddressType where
                       tqAddressByBusRelAddressType.tiBusinessRelation_ID = tqCDocumentByFilter.tiBusinessRelation_ID and
                       tqAddressByBusRelAddressType.tcAddressTypeCode     = {&ADDRESSTYPECODESYSTEM-HEADOFFICE}
                       no-error.
        end.
    end.

    /* Get VAT Number */
    <Q-75 run VatNumberByBusRelCountry (all) (Read) (NoCache)
          (input tqCDocumentByFilter.tiBusinessRelation_ID, (BusinessRelationID)
           input tqAddressByBusRelAddressType.tiCountry_ID, (CountryID)
           output dataset tqVatNumberByBusRelCountry) in BCDocumentReport >

    find first tqVatNumberByBusRelCountry where
               tqVatNumberByBusRelCountry.tiBusinessRelation_ID = tqCDocumentByFilter.tiBusinessRelation_ID and
               tqVatNumberByBusRelCountry.tiIdentityCountry_ID  = tqAddressByBusRelAddressType.tiCountry_ID
               no-error.

    /* Get linked invoices */
    assign viNumInvoices = 0.

    <Q-64 run CDocumentInvoiceXrefByCDocId (all) (Read) (NoCache)
          (input ?, (CompanyId)
           input tqCDocumentByFilter.tiCDocument_ID, (CDocumentID)
           output dataset tqCDocumentInvoiceXrefByCDocId) in BCDocumentReport >

    if can-find(first tqCDocumentInvoiceXrefByCDocId where
                      tqCDocumentInvoiceXrefByCDocId.tiCDocument_ID = tqCDocumentByFilter.tiCDocument_ID)
    then for each tqCDocumentInvoiceXrefByCDocId where
                  tqCDocumentInvoiceXrefByCDocId.tiCDocument_ID = tqCDocumentByFilter.tiCDocument_ID break by tqCDocumentInvoiceXrefByCDocId.tiCInvoice_ID:
      <M-480 run CDocumentReportAllCreate
          (input  vcAmountInText (icAmountInText), 
           input   tqCDocumentInvoiceXrefByCDocId.tiCInvoice_ID (iiCInvoiceid), 
           output viFcReturnSuper (oiReturnStatus)) in BCDocumentReport>                             
                                    
        if viFcReturnSuper < 0 or
           oiReturnStatus  = 0
        then assign oiReturnStatus = viFcReturnSuper.

        if oiReturnStatus < 0
        then return.

        assign tCDocumentReportAll.tiPayFormatTypeLinesPerPage     = tqCDocumentByFilter.tiPayFormatTypeLinesPerPage 
               tCDocumentReportAll.tcCDocRepCInvoiceCreditorCode   = tqCDocumentInvoiceXrefByCDocId.tcCreditorCode
               tCDocumentReportAll.tcCDocRepCInvoiceCurrencyCode   = tqCDocumentInvoiceXrefByCDocId.tcCurrencyCode
               tCDocumentReportAll.tiDocRepCInvoiceCurrNumberOfDec = tqCDocumentInvoiceXrefByCDocId.tiCurrencyNumberOfDecimals
               tCDocumentReportAll.tcCDocRepCInvoiceJournalCode    = tqCDocumentInvoiceXrefByCDocId.tcJournalCode
               tCDocumentReportAll.tcCDocRepCInvoiceReference      = tqCDocumentInvoiceXrefByCDocId.tcCInvoiceReference
               tCDocumentReportAll.tdCDocRepCInvoiceBalanceTC      = abs(tqCDocumentInvoiceXrefByCDocId.tdCInvoiceBalanceTC)
               tCDocumentReportAll.tdCDocRepCInvoiceXRefAmountTC   = tqCDocumentInvoiceXrefByCDocId.tdCDocumentInvoiceXrefAlloTC
               tCDocumentReportAll.tdCDocRepCInvoiceXRefDiscAmTC   = tqCDocumentInvoiceXrefByCDocId.tdCDocumentInvoiceXrefDiscTC
               tCDocumentReportAll.tdCDocRepCInvoiceXRefPaidAmtTC  = tqCDocumentInvoiceXrefByCDocId.tdCDocumentInvoiceXRefPaidAmtTC
               tCDocumentReportAll.tiCDocRepCInvoicePeriod         = tqCDocumentInvoiceXrefByCDocId.tiPeriodPeriod
               tCDocumentReportAll.tiCDocRepCInvoiceVoucher        = tqCDocumentInvoiceXrefByCDocId.tiCInvoiceVoucher
               tCDocumentReportAll.tiCDocRepCInvoiceYear           = tqCDocumentInvoiceXrefByCDocId.tiPeriodYear
               tCDocumentReportAll.ttCDocRepCInvoiceDate           = tqCDocumentInvoiceXrefByCDocId.ttCInvoiceDate
               tCDocumentReportAll.ttCDocRepCInvoiceDiscountDueDat = tqCDocumentInvoiceXrefByCDocId.ttCInvoiceDiscountDueDate
               tCDocumentReportAll.ttCDocRepCInvoiceDueDate        = tqCDocumentInvoiceXrefByCDocId.ttCInvoiceDueDate
               tCDocumentReportAll.tdCDocRepCInvoiceTotalAllocTC   = tCDocumentReportAll.tdCDocRepCInvoiceTotalAllocTC - tqCDocumentInvoiceXrefByCDocId.tdCDocumentInvoiceXrefAlloTC
               tCDocumentReportAll.tdCDocRepCInvoiceTotalBalanceTC = tCDocumentReportAll.tdCDocRepCInvoiceTotalBalanceTC - tqCDocumentInvoiceXrefByCDocId.tdCInvoiceBalanceTC
               tCDocumentReportAll.tdCDocRepCInvoiceTotalDiscTC    = if tqCDocumentInvoiceXrefByCDocId.tdCDocumentInvoiceXrefAlloTC < 0
                                                                     then tCDocumentReportAll.tdCDocRepCInvoiceTotalDiscTC + tqCDocumentInvoiceXrefByCDocId.tdCDocumentInvoiceXrefDiscTC
                                                                     else tCDocumentReportAll.tdCDocRepCInvoiceTotalDiscTC - tqCDocumentInvoiceXrefByCDocId.tdCDocumentInvoiceXrefDiscTC
               viNumInvoices                                       = viNumInvoices + 1
                                                                         
               tCDocumentReportAll.tcCDocRepCInvoiceType           = tqCDocumentInvoiceXrefByCDocId.tcCInvoiceType
               tCDocumentReportAll.tdCDocRepInvOrigDebitTC         = tqCDocumentInvoiceXrefByCDocId.tdCInvoiceOriginalDebitTC
               tCDocumentReportAll.tdCDocRepInvOrigCreditTC        = tqCDocumentInvoiceXrefByCDocId.tdCInvoiceOriginalCreditTC
               tCDocumentReportAll.tdCDocRepInvBalanceDebitTC      = tqCDocumentInvoiceXrefByCDocId.tdCInvoiceBalanceDebitTC
               tCDocumentReportAll.tdCDocRepInvBalanceCreditTC     = tqCDocumentInvoiceXrefByCDocId.tdCInvoiceBalanceCreditTC
               tCDocumentReportAll.tcCInvoiceDescription           = tqCDocumentInvoiceXrefByCDocId.tcCInvoiceDescription
               tCDocumentReportAll.tiCreditor_ID                   = tqCDocumentInvoiceXrefByCDocId.tiCreditor_ID
               tCDocumentReportAll.tiCInvoice_ID                   = tqCDocumentInvoiceXrefByCDocId.tiCInvoice_ID
               tCDocumentReportAll.tiPaySelLine_ID                 = tqCDocumentInvoiceXrefByCDocId.tiPaySelLine_ID
               tCDocumentReportAll.tcCreditorDebtorNumber          = tqCDocumentInvoiceXrefByCDocId.tcCreditorDebtorNumber.
    end.
    else do:
         <M-90 run CDocumentReportAllCreate
             (input  vcAmountInText (icAmountInText), 
              input  0 (iiCInvoiceid), 
              output viFcReturnSuper (oiReturnStatus)) in BCDocumentReport>                          

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

        if oiReturnStatus < 0
        then return.
    end.
    
    /* Increase Times Printed */
    if vlIncreaseCDocumentTimesPrinted
    then do:
        find first tCDocumentPrintCDR where
                   tCDocumentPrintCDR.tiCDocumentId = tqCDocumentByFilter.tiCDocument_ID
                   no-error.

        if not available tCDocumentPrintCDR
        then do:
            create tCDocumentPrintCDR.

            assign tCDocumentPrintCDR.tiCDocumentId                   = tqCDocumentByFilter.tiCDocument_ID
                   tCDocumentPrintCDR.tiCDocumentPrePrintedNumber     = 0
                   tCDocumentPrintCDR.tlIncreaseCDocumentTimesPrinted = false.
        end.

        assign tCDocumentPrintCDR.tlIncreaseCDocumentTimesPrinted = true.
    end.
   
    /* Assign Pre-Printed Number */
    if vlAssignCDocumentPrePrintedNum
    then do:
        find first tCDocumentPrintCDR where
                   tCDocumentPrintCDR.tiCDocumentId = tqCDocumentByFilter.tiCDocument_ID
                   no-error.

        if not available tCDocumentPrintCDR
        then do:
            create tCDocumentPrintCDR.

            assign tCDocumentPrintCDR.tiCDocumentId                   = tqCDocumentByFilter.tiCDocument_ID
                   tCDocumentPrintCDR.tiCDocumentPrePrintedNumber     = 0
                   tCDocumentPrintCDR.tlIncreaseCDocumentTimesPrinted = false.
        end.

        assign viA                                            = if viSkipCDocumentPrePrintedNum = 0 or
                                                                   viSkipCDocumentPrePrintedNum = ?
                                                                then 1
                                                                else trunc(viNumInvoices / viSkipCDocumentPrePrintedNum, 0) + 1
               viStartCDocumentPrePrintedNum                  = viStartCDocumentPrePrintedNum + viA
               tCDocumentPrintCDR.tiCDocumentPrePrintedNumber = viStartCDocumentPrePrintedNum.
    end.

    <Q-89 run CDocumentById (all) (Read) (NoCache)
       (input tqCDocumentByFilter.tiCompany_ID, (CompanyId)
        input tqCDocumentByFilter.tiCDocument_ID, (CDocument_ID)
        output dataset tqCDocumentById) in BCDocument >

    FOR FIRST tqCDocumentByID WHERE 
              tqCDocumentByID.tiCDocument_ID = tqCDocumentByFilter.tiCDocument_ID:
        assign tCDocumentReportAll.tiPayFormatTypeLinesPerPage = tqCDocumentById.tiPayFormatTypeLinesPerPage.
    END. 
    
end.

<Q-72 run VatNumberByBusRelCountry (Stop) in BCDocumentReport >
<Q-70 run AddressByBusRelAddressType (Stop) in BCDocumentReport >
<Q-55 run BankNumberByParent (Stop) in BCDocumentReport >
<Q-52 run CDocumentInvoiceXrefByCDocId (Stop) in BCDocumentReport >

FOR EACH tCDocumentReportAll:
    /* Cheque Amount */
    if tCDocumentReportAll.tcCDocRepDocumentType = {&DOCUMENTTYPECREDITOR-CHEQUE-TR} or
       tCDocumentReportAll.tcCDocRepDocumentType = {&DOCUMENTTYPECREDITOR-DRAFT-TR}
    then do:
       vdAmount = ABS(tCDocumentReportAll.tdCDocRepOrigDebitTC - tCDocumentReportAll.tdCDocRepOrigCreditTC).
       tCDocumentReportAll.tiCDocRepChequeDollars = INT(TRUNCATE(vdAmount, 0)).
       tCDocumentReportAll.tiCDocRepChequeCents = INT((vdAmount - tCDocumentReportAll.tiCDocRepChequeDollars) * 100).

        <Q-107 run GetCurrDesc (all) (Read) (NoCache)
           (input tCDocumentReportAll.tcCurrencyCode, (CurrencyCode)
            output dataset tqGetCurrDesc) in BCDocumentReport >
        
        find first tqGetCurrDesc no-lock no-error.
        if available tqGetCurrDesc then do:    
           tCDocumentReportAll.tcDollarCurrency = tqGetCurrDesc.tcCurrencyDescription.
           tCDocumentReportAll.tcCentCurrency = tqGetCurrDesc.tcCurrencyDecimalDescription.    
        end.
    end.
END.     

/* voiding if the number of invoices exceeds the number per page */
viCount = 0.
FOR EACH tCDocumentReportAll BREAK BY tCDocumentReportAll.tiCDocumentID:
    assign
        viLinesPerPage = tCDocumentReportAll.tiPayFormatTypeLinesPerPage
        tCDocumentReportAll.tcReportDocID = 
            SUBST("&1.&2",STRING(tCDocumentReportAll.tiCDocumentID),
                  STRING(TRUNCATE(viCount / viLinesPerPage,0))).

     /* Create voided payment if number of invoices exceeds lines per page */
     if (viCount > 0 and 
        (if viLinesPerPage <> 0 then viCount mod viLinesPerPage = 0 else false))
     then do:
        create tVoided.
        assign
           tVoided.tcReportDocID = tCDocumentReportAll.tcReportDocID
           tVoided.tlVoid = yes.
     end.   
     viCount = viCount + 1.
     IF LAST-OF (tCDocumentReportAll.tiCDocumentID) THEN DO:
         viCount = 0.
     END. 
END.                                     


if not ((icCDocumentType = {&DOCUMENTTYPECREDITOR-CHEQUE} or
         icCDocumentType = {&DOCUMENTTYPECREDITOR-DRAFT}) and
         vcPrintType <> {&PRINTTYPE-FINAL})
then do:
    for each tCDocumentPrintCDR no-lock:
        for each tCDocumentReportAll where tCDocumentReportAll.tiCDocumentID = tCDocumentPrintCDR.tiCDocumentId no-lock:
             assign tCDocumentReportAll.tiCDocRepPrePrintedNum = tCDocumentPrintCDR.tiCDocumentPrePrintedNumber.
        end.
    end.
end. /* if not ((icCDocumentType = {&DOCUMENTTYPECREDITOR-CHEQUE} */

/* Assign pre-printed check numbers */
if(vlAssignCDocumentPrePrintedNum = true) then do:
    viCheckNumber = viOriginalStartNum - 1.
    if vlSortByCreditorCode = true
    then do:
        for each tCDocumentReportAll break by tCDocumentReportAll.tcCDocRepCredCode by tCDocumentReportAll.tcReportDocID:
            /* All payments on the same page should have the same check number */
            /* incrementing check number when moving to the next document      */
            if(first-of(tCDocumentReportAll.tcReportDocID)) then do:
                assign
                    viCheckNumber = viCheckNumber + 1
                    tCDocumentReportAll.tiCDocRepPrePrintedNum = viCheckNumber.
            end.
            else do:
                assign
                    tCDocumentReportAll.tiCDocRepPrePrintedNum = viCheckNumber.
            end.
        end.
    end. /* if vlSortByCreditorCode = true */
    else do:
        for each tCDocumentReportAll break by tCDocumentReportAll.tcCDocRepCredName1 by tCDocumentReportAll.tcReportDocID:
            /* All payments on the same page should have the same check number */
            /* incrementing check number when moving to the next document      */
            if(first-of(tCDocumentReportAll.tcReportDocID)) then do:
                assign
                    viCheckNumber = viCheckNumber + 1
                    tCDocumentReportAll.tiCDocRepPrePrintedNum = viCheckNumber.
            end.
            else do:
                assign
                    tCDocumentReportAll.tiCDocRepPrePrintedNum = viCheckNumber.
            end.
        end.
    end. /* if vlSortByCreditorCode = false */
end.

<M-128 run CDocumentReportAllSub
   (input  icCDocumentType (icCDocumentType), 
    input  vcPrintType (icPrintType), 
    input  vlAssignCDocumentPrePrintedNum (ilAssignCDocumentPrePrintedNum), 
    input  vlIncreaseCDocumentTimesPrinted (ilIncreaseCDocumentTimesPrinted), 
    output viFcReturnSuper (oiReturnStatus)) in BCDocumentReport>


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