project QadFinancials > class BDCollection > method ExportDOM80


Parameters


iiDCollectionIdinputinteger
ilDuplicateinputlogical
itSpilDateinputdate
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDCollection.Export


program code (program5/bdcollection.p)

/* Get the collection */
<Q-1 run DCollectionByID (all) (Read) (NoCache)
   (input ?, (CompanyId)
    input iiDCollectionId, (CollectionId)
    output dataset tqDCollectionByID) in BDCollection >

find tqDCollectionByID where
     tqDCollectionByID.tiDCollection_ID = iiDCollectionId
     no-error.

if not available tqDCollectionByID
then do:
    <M-2 run SetMessage
       (input  trim(#T-22'The customer payment collection $1 cannot be found.':250(1635)T-22#) (icMessage), 
        input  string(iiDCollectionId) (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QADFIN-2947':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BDCollection>

    assign oiReturnStatus = -1.
    return.
end.

/* Get the Current Company VatNumber / Name */
<Q-16 run CompanyPropertyByIdCode (all) (Read) (NoCache)
   (input tqDCollectionByID.tiCompany_ID, (CompanyId)
    input ?, (CompanyPropertyId)
    input ?, (BusinessRelationId)
    input ?, (CurrencyId)
    input ?, (CompanyPropertyCode)
    input ?, (CompanyCode)
    input ?, (BusinessRelationCode)
    input ?, (CurrencyCode)
    output dataset tqCompanyPropertyByIdCode) in BCompanyProperty >

find first tqCompanyPropertyByIdCode where
           tqCompanyPropertyByIdCode.tiCompany_ID = tqDCollectionByID.tiCompany_ID
           no-error.

if available tqCompanyPropertyByIdCode
then do:
    <Q-17 run BusinessRelationByIdCode (all) (Read) (NoCache)
       (input tqCompanyPropertyByIdCode.tiBusinessRelation_ID, (BusinessRelationId)
        input ?, (BusinessRelationCode)
        output dataset tqBusinessRelationByIdCode) in BBusinessRelation >

    find first tqBusinessRelationByIdCode where
               tqBusinessRelationByIdCode.tiBusinessRelation_ID = tqCompanyPropertyByIdCode.tiBusinessRelation_ID
               no-error.

    if available tqBusinessRelationByIdCode
    then do:
        assign vcCompanyName = tqBusinessRelationByIdCode.tcBusinessRelationName1.

        <Q-18 run AddressByAddressType (all) (Read) (NoCache)
           (input tqBusinessRelationByIdCode.tiBusinessRelation_ID, (BusinessRelationId)
            input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode)
            output dataset tqAddressByAddressType) in BBusinessRelation >

        find first tqAddressByAddressType where
                   tqAddressByAddressType.tiBusinessRelation_ID = tqBusinessRelationByIdCode.tiBusinessRelation_ID and
                   tqAddressByAddressType.tcAddressTypeCode     = {&ADDRESSTYPECODESYSTEM-HEADOFFICE}
                   no-error.

        if available tqAddressByAddressType
        then do:
            <Q-19 run VatNumberForMyCompany (all) (Read) (NoCache)
               (input tqDCollectionByID.tiCompany_ID, (CompanyId)
                input tqAddressByAddressType.tiCountry_ID, (IdentityCountryCode)
                output dataset tqVatNumberForMyCompany) in BBusinessRelation >

            find first tqVatNumberForMyCompany where
                       tqVatNumberForMyCompany.tiIdentityCountry_ID = tqAddressByAddressType.tiCountry_ID
                       no-error.

            if available tqVatNumberForMyCompany
            then assign vcVatNumberIdentity = string(decimal(replace(tqVatNumberForMyCompany.tcVatNumberIdentity, ".":U, "":U)), "99999999999":U).
        end.
    end.
end.

/* Get the Current Company BankNumber */
<Q-5 run BankNumberByParentID (all) (Read) (NoCache)
   (input tqDCollectionByID.tiGL_ID, (ParentObjectId)
    input {&BANKNUMBERPARENTTYPE-GL}, (BankNumberParentType)
    input true, (BankNumberIsDefault)
    input tqDCollectionByID.tiCompany_ID, (CompanyId)
    output dataset tqBankNumberByParentID) in BBankNumber >

find first tqBankNumberByParentID
           no-error.

if available tqBankNumberByParentID 
then assign vcBankNumber = string(decimal(replace(tqBankNumberByParentID.tcBankNumber, ".":U, "":U)), "999999999999":U)
            vcBankCode   = substring(trim(vcBankNumber), 1, 3,"CHARACTER":U).

/* Create the headerrecord (Beginopname) */
create tExport.

assign tExport.tcValue = "0":U                                                               +
                         "0000":U                                                            +
                         <M-6 FormatDateDDMMYY (input  today (itDate)) in BDCollection>      +
                         string(vcBankCode,"999":U)                                          +
                         "02":U                                                              +
                         string(tqDCollectionById.tcDCollectionReference, "x(10)":U)         +
                         string(vcVatNumberIdentity,"99999999999":U)                         +
                         string(vcVatNumberIdentity,"99999999999":U)                         +
                         string(vcBankNumber,"999999999999":U)                               +
                         "5":U                                                               +
                        (if ilDuplicate
                         then "D":U
                         else " ":U)                                                         +
                         <M-7 FormatDateDDMMYY (input  itSpilDate (itDate)) in BDCollection> +
                         fill(" ":U, 60)
       tExport.tiSeq   = 1.

<Q-8 run DDocumentByCollectionID (all) (Read) (NoCache)
   (input tqDCollectionByID.tiCompany_ID, (CompanyId)
    input tqDCollectionByID.tiDCollection_ID, (DCollectionID)
    input ?, (DDocumentID)
    input {&DOCUMENTSTATUS-INCASSO} + ',':U + {&DOCUMENTSTATUS-DISCONT}, (DDocumentStatus)
    output dataset tqDDocumentByCollectionID) in BDDocument >

assign viA           = 1
       vdDOMNrsTotal = 0
       vdTotalLC     = 0.

/* Create incasso records 1 (Gegevensopname) */
<Q-9 run DebtorByDebtor
   (Start) in BDebtor >

DCollections:
for each tqDDocumentByCollectionID:
    <Q-10 run DebtorByDebtor (first) (Read) (NoCache)
       (input tqDCollectionByID.tiCompany_ID, (CompanyId)
        input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressType)
        input tqDDocumentByCollectionID.tiDebtor_ID, (DebtorId)
        input ?, (DebtorCode)
        output dataset tqDebtorByDebtor) in BDebtor >

    find first tqDebtorByDebtor no-error.

    if not available tqDebtorByDebtor             
    or(tqDebtorByDebtor.tiDomiciliationNumber = 0 or tqDebtorByDebtor.tiDomiciliationNumber = ?)
    then do:
            
            <M-20 run SetMessage
               (input  trim(#T-23'You have chosen file format $1, but the domiciliation number for customer $2 was not entered. The system cannot continue.':250(1637)T-23#) (icMessage), 
                input  {&DCOLLECTIONEXPORTTYPE-DOM80-TR} + chr(2) + tqDDocumentByCollectionID.tcDebtorCode (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QADFIN-3011':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BDCollection>
            assign oiReturnStatus = -1.
            return.
    end.
    else do:

        <M-21 run ValidateByExportType (input  {&DCOLLECTIONEXPORTTYPE-DOM80} (icBankFileFormat), 
                                input  tqDebtorByDebtor.tiDebtor_ID (iiDebtorID), 
                                input  tqDebtorByDebtor.tcDebtorCode (icDebtorCode), 
                                output viFcReturnSuper (oiReturnStatus)) in BDCollection>
        if viFcReturnSuper < 0
        then do:
            assign oiReturnStatus = -1.
            return.
        END.

        create tExport.

        assign viA                   = viA + 1
               vcDomiciliationNumber = string(tqDebtorByDebtor.tiDomiciliationNumber)
               vdDOMNrsTotal         = vdDOMNrsTotal + tqDebtorByDebtor.tiDomiciliationNumber
               vdTotalLC             = vdTotalLC + tqDDocumentByCollectionID.tdDDocumentOriginalDebitLC
               tExport.tcValue       = "1":U                                                     +
                                       string(viA - 1, "9999":U)                                 +
                                       <M-11 LessSignificantX (input  decimal(vcDomiciliationNumber) (idValueIn), 
                                                               input  12 (iiX)) in BDCollection> +
                                       "1":U                                                     +
                                       <M-12 LessSignificantX (input  decimal(replace(string(tqDDocumentByCollectionID.tdDDocumentOriginalDebitLC, '999999999999999.99':U), '.':U, '':U)) (idValueIn), 
                                                               input  12 (iiX)) in BDCollection> +
                                       string(vcCompanyName, "x(26)":U)                          +
                                       fill(" ":U, 30)                                           +
                                       fill("0":U, 12)
               tExport.tiSeq         = viA.
    end.
end.

<Q-13 run DebtorByDebtor
   (Stop) in BDebtor >

/* Create the footerrecord (Eindopname) */
create tExport.

assign tExport.tcValue = "9":U                                                      +
                         <M-14 LessSignificantX (input  viA - 1 (idValueIn), 
                                                 input  4 (iiX)) in BDCollection>   +
                         replace(string(vdTotalLC, "9999999999.99":U), ".":U, "":U) +
                         <M-15 LessSignificantX (input  vdDOMNrsTotal (idValueIn), 
                                                 input  15 (iiX)) in BDCollection>  +
                         fill("0":U, 13)                                            +
                         fill(" ":U, 65)
       tExport.tiSeq   = viA + 1.