project QadFinancials > class BDDocument > method CreateDDocumentHeader

Description

This method create Customer Document Header


Parameters


iiDebtorIdinputinteger
icDebtorCodeinputcharacter
iiCurrencyIdinputinteger
icCurrencyCodeinputcharacter
iiBankNumberIdinputinteger
iiGL_IDinputinteger
icGLCodeinputcharacter
itTransactionDateinputdate
idOriginalDebitTCinputdecimal
biDDocumentIdinput-outputinteger
ocRowIdoutputcharacter
bcReferenceinput-outputcharacter
icDocumentTypeinputcharacter
icBankImpLineRefinputcharacter
icBankImpLineRowIDinputcharacter
ocMessageReferenceoutputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBankImportLine.ProcessBankImpLineNewDDocument


program code (program6/bddocument.p)

/* =================================================================================================== */
/* Method      : CreateDDocumentHeader                                                                 */
/* Desc        : This method creates customer document header                                          */
/* --------------------------------------------------------------------------------------------------- */
/* Params:                                                                                             */
/* =================================================================================================== */
assign oiReturnStatus = -98.

/* =================================================================================================== */
/* If payment already exists just do dataload                                                          */
/* =================================================================================================== */
if biDDocumentId <> 0 and biDDocumentId <> ?
then do:
    <M-10 run DataLoad
       (input  '':U (icRowids), 
        input  string(biDDocumentID) (icPkeys), 
        input  '':U (icObjectIds), 
        input  '':U (icFreeform), 
        input  true (ilKeepPrevious), 
        output viFcReturnSuper (oiReturnStatus)) in BDDocument>

    find first tDDocument where
               tDDocument.DDocument_ID = biDDocumentId
               no-error.
    if available tDDocument
    then do:
        assign ocRowId = tDDocument.tc_Rowid
               oiReturnStatus = 0.
        return.        
    end.
end.

/* =================================================================================================== */
/* Normalize input parameters                                                                          */
/* =================================================================================================== */
if iiDebtorId       = 0 then assign iiDebtorId     = ?.
if iiCurrencyId     = 0 then assign iiCurrencyId   = ?.
if iiBankNumberId   = 0 then assign iiBankNumberId = ?.

/* =================================================================================================== */
/* Validate  input parameters                                                                          */
/* =================================================================================================== */
if iiDebtorId    = ? or
   iiCurrencyId  = ? or
   iiBankNumberId= ? or
   itTransactionDate = ?
then do:
    assign vcMessage = trim(#T-1'You have not entered all the mandatory values.':255(999890613)T-1#)
           vcContext = 'iiDebtorId=&1|iiCurrencyId=&2|iiBankNumberId=&3|itTransactionData=&4':U
           vcContext = substitute(vcContext, iiDebtorId, iiCurrencyId,iiBankNumberId,itTransactionDate)
           vcContext = replace(vcContext, '|':U, chr(2)).
    <M-2 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'S':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-7578':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  vcContext (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BDDocument>
    assign oiReturnStatus = -1.
    return.
end.

/* =================================================================================================== */
/* Cretate new DDocunent header                                                                        */
/* =================================================================================================== */
<M-3 run AddDetailLine
   (input  'DDocument':U (icTable), 
    input  '':U (icParentRowid), 
    output viFcReturnSuper (oiReturnStatus)) in BDDocument>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper <  0 then return.

assign tDDocument.Debtor_ID        = iiDebtorId
       tDDocument.Currency_ID      = iiCurrencyId
       tDDocument.BankNumber_ID    = iiBankNumberId
       tDDocument.DDocumentYear    = year(itTransactionDate)
       tDDocument.DDocumentStatus  = {&DOCUMENTSTATUS-INIT}
       tDDocument.DDocumentSubType = {&DOCUMENTSUBTYPE-MAN}
       tDDocument.DDocumentType    = icDocumentType
       tDDocument.DDocumentOriginalDebitTC   = idOriginalDebitTC
       tDDocument.DDocumentReference         = bcReference
       tDDocument.DDocumentCreationDate      = itTransactionDate
       tDDocument.ttPostingDate              = itTransactionDate
       tDDocument.DDocumentBankImpRef        = icBankImpLineRef
       tDDocument.tcExternalUniqueIdentifier = icBankImpLineRowID.

/*Initiate the mandatory calculate field of DDocument */
<Q-4 run BankNumberPrim (all) (Read) (NoCache)
   (input iiBankNumberId, (BankNumberId)
    input ?, (ParentObjectId)
    input ?, (BankNumber)
    input ?, (BankNumberExtension)
    input ?, (BankPayFormatID)
    output dataset tqBankNumberPrim) in BBankNumber >

find first tqBankNumberPrim no-error.
if available tqBankNumberPrim
then assign tDDocument.tcDebtorBankNumber = tqBankNumberPrim.tcBankNumber.

if icDebtorCode <> ? and icDebtorCode <> ''
then assign tDDocument.tcDebtorCode = icDebtorCode.
else do:
    <Q-6 run DebtorPrim (all) (Read) (NoCache)
       (input ?, (CompanyId)
        input ?, (DebtorCode)
        input iiDebtorId, (Debtor_ID)
        output dataset tqDebtorPrim) in BDebtor>
    find first tqDebtorPrim no-error.
    if available tqDebtorPrim
    then assign tDDocument.tcDebtorCode = tqDebtorPrim.tcDebtorCode.
end.

if icCurrencyCode <> ? and icCurrencyCode <> ''
then assign tDDocument.tcCurrencyCode = icCurrencyCode.
else do:
    if iiCurrencyId = viCompanyLCId
    then assign tDDocument.tcCurrencyCode = vcCompanyLC.
    else
    if iiCurrencyId = viCompanyCCId
    then assign tDDocument.tcCurrencyCode = vcCompanyCC.
    else do:
        <Q-7 run CurrencyPrim (all) (Read) (Cache)
           (input ?, (CurrencyCode)
            input iiCurrencyId, (Currency_ID)
            output dataset tqCurrencyPrim) in BCurrency>
        find first tqCurrencyPrim no-error.
        if available tqCurrencyPrim
        then assign tDDocument.tcCurrencyCode = tqCurrencyPrim.tcCurrencyCode.
    end.
end.

if iiGL_ID <> 0 and iiGL_ID <> ? and icGLCode <> '' and icGLCode <> ?
then assign tDDocument.tcGLCode = icGLCode
            tDDocument.GL_ID    = iiGL_ID.
else do:
    <Q-8 run BankNumberOwnBankGLByID (all) (Read) (Cache)
       (input iiBankNumberId, (BankNumber_ID)
        input ?, (CompanyId)
        output dataset tqBankNumberOwnBankGLByID) in BBankNumber>

    find first tqBankNumberOwnBankGLByID no-error.
    if available tqBankNumberOwnBankGLByID
    then assign tDDocument.tcGLCode = tqBankNumberOwnBankGLByID.tcGLCode
                tDDocument.GL_ID    = tqBankNumberOwnBankGLByID.tiGL_ID .
end.

assign vhFcComponent = ?.
 <M-5 run GetNumber
    (input  tDDocument.Company_ID (iiCompanyId), 
     input  tDDocument.DDocumentYear (iiNumbrYear), 
     input  'D':U + tDDocument.DDocumentType (icNumbrType), 
     output tDDocument.DDocumentNumber (oiNumber), 
     input  viFcCurrentInstanceId (iiInstanceId), 
     input  vcFcComponentName (icClassName), 
     output viFcReturnSuper (oiReturnStatus)) in BNumber>

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

if viFcReturnSuper < 0 then return.

assign biDDocumentId = tDDocument.DDocument_ID
       ocRowId       = tDDocument.tc_Rowid.

if tDDocument.DDocumentReference = '':U or tDDocument.DDocumentReference = ?
then assign tDDocument.DDocumentReference = substring(string(tDDocument.tcDebtorCode + string(tDDocument.DDocumentNumber) + string(time)),1,40,'Character')
            bcReference = tDDocument.DDocumentReference
            ocMessageReference = string(tDDocument.DDocumentYear) + "/" +
                                 string(tDDocument.DDocumentNumber) + "/" +
                                 icBankImpLineRef.

if oiReturnStatus = -98 then assign oiReturnStatus = 0.