Description
Creates DDocuments
Parameters
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program5/bdpaymentselection.p)
/* tDPaySel record is in scope. Only continue if status is not INIT */
empty temp-table tDInvBalance.
empty temp-table tDPaymentLevelPayCode.
INCSEL_LOOP:
for each tDPaySel where tDPaySel.DPaySelStatus <> {&DOCUMENTSTATUS-INIT} and tDPaySel.tc_Status = "N"
on error undo, throw:
assign viPayCodeRowid = -1.
assign viDocRowId = -1.
for each tDIncSelLine where
tDIncSelLine.tc_ParentRowid = tDPaySel.tc_Rowid and
tDIncSelLine.tlIsSelected = true:
assign tDIncSelLine.tcPaymentLevelPayCode = "":U.
<Q-39 run DInvoiceBankPayCodeByDIBankID (all) (Read) (NoCache)
(input {&PAYFORMATGROUPLEVEL-PAYMENT}, (PayFormatGroupLevel)
input tDIncSelLine.tiDInvoiceId, (DInvoiceId)
input tDIncSelLine.tiBankNumberId, (BankNumberId)
output dataset tqDInvoiceBankPayCodeByDIBankID) in BDInvoice>
for each tqDInvoiceBankPayCodeByDIBankID:
find first tDPaymentLevelPayCode where
tDPaymentLevelPayCode.tiPayFormatGroupId = tqDInvoiceBankPayCodeByDIBankID.tiPayFormatGroup_ID and
tDPaymentLevelPayCode.tiPayFormatCodeId = tqDInvoiceBankPayCodeByDIBankID.tiPayFormatCode_ID and
tDPaymentLevelPayCode.tcPayCodeValue = tqDInvoiceBankPayCodeByDIBankID.tcDInvoiceBankPayCodeValue
no-error.
if not available tDPaymentLevelPayCode
then do:
create tDPaymentLevelPayCode.
assign tDPaymentLevelPayCode.tiPayFormatGroupId = tqDInvoiceBankPayCodeByDIBankID.tiPayFormatGroup_ID
tDPaymentLevelPayCode.tiPayFormatCodeId = tqDInvoiceBankPayCodeByDIBankID.tiPayFormatCode_ID
tDPaymentLevelPayCode.tcPayCodeValue = tqDInvoiceBankPayCodeByDIBankID.tcDInvoiceBankPayCodeValue
tDPaymentLevelPayCode.tcRowid = string(viPayCodeRowid)
viPayCodeRowid = viPayCodeRowid - 1.
end. /* if not available tDPaymentLevelPayCode */
if tDIncSelLine.tcPaymentLevelPayCode = "":U
then assign tDIncSelLine.tcPaymentLevelPayCode = tDPaymentLevelPayCode.tcRowid.
else assign tDIncSelLine.tcPaymentLevelPayCode = tDIncSelLine.tcPaymentLevelPayCode + chr(2) + tDPaymentLevelPayCode.tcRowid.
end. /* for each tqDInvoiceBankPayCodeByDIBankID: */
if tDPaySel.DPaySelIsDocPerDueDate
then if tDIncSelLine.ttDiscountDueDate = ? or
tDIncSelLine.tdIncSelLineDiscountTC = 0 or
tDIncSelLine.tdIncSelLineDiscountTC = ?
then find first tDDocumentPaySel where
tDDocumentPaySel.tcDebtorCode = tDIncSelLine.tcDebtorCode and
tDDocumentPaySel.tcCurrencyCode = tDIncSelLine.tcInvoiceCurrencyCode and
tDDocumentPaySel.DDocumentDueDate = tDIncSelLine.ttDueDate and
tDDocumentPaySel.DDocumentIncassoSelectCode = tDPaySel.DPaySelCode and
tDDocumentPaySel.BankNumber_ID = tDIncSelLine.tiBankNumberId and
tDDocumentPaySel.tcPaymentLevelPayCode = tDIncSelLine.tcPaymentLevelPayCode
no-error.
else find first tDDocumentPaySel where
tDDocumentPaySel.tcDebtorCode = tDIncSelLine.tcDebtorCode and
tDDocumentPaySel.tcCurrencyCode = tDIncSelLine.tcInvoiceCurrencyCode and
tDDocumentPaySel.DDocumentDueDate = tDIncSelLine.ttDiscountDueDate and
tDDocumentPaySel.DDocumentIncassoSelectCode = tDPaySel.DPaySelCode and
tDDocumentPaySel.BankNumber_ID = tDIncSelLine.tiBankNumberId and
tDDocumentPaySel.tcPaymentLevelPayCode = tDIncSelLine.tcPaymentLevelPayCode
no-error.
else find first tDDocumentPaySel where
tDDocumentPaySel.tcDebtorCode = tDIncSelLine.tcDebtorCode and
tDDocumentPaySel.tcCurrencyCode = tDIncSelLine.tcInvoiceCurrencyCode and
tDDocumentPaySel.DDocumentIncassoSelectCode = tDPaySel.DPaySelCode and
tDDocumentPaySel.BankNumber_ID = tDIncSelLine.tiBankNumberId and
tDDocumentPaySel.tcPaymentLevelPayCode = tDIncSelLine.tcPaymentLevelPayCode
no-error.
if not available tDDocumentPaySel
then do:
create tDDocumentPaySel.
assign
tDDocumentPaySel.tc_Status = "N":U
tDDocumentPaySel.tc_ParentRowid = tDPaySel.tc_Rowid /*if available tDPaySelRefDDoc then tDPaySelRefDDoc.tc_Rowid else "":U */ /* Assign manually because DDocument is the main table */
tDDocumentPaySel.BankNumber_ID = tDIncSelLine.tiBankNumberId
tDDocumentPaySel.tcPayFormatTypeCode = tDPaySel.tcPayFormatTypeCode
tDDocumentPaySel.DDocumentType = tDPaySel.tcPayFormatTypePayInstrument
tDDocumentPaySel.DDocumentSubType = if tDPaySel.DPaySelStatus = {&DOCUMENTSTATUS-INCASSO}
then {&DOCUMENTSUBTYPE-AUTO}
else {&DOCUMENTSUBTYPE-MAN}
tDDocumentPaySel.DDocumentYear = year(today)
tDDocumentPaySel.DDocumentReference = "":U
tDDocumentPaySel.DDocumentDueDate = if tDPaySel.DPaySelIsDocPerDueDate
then if tDIncSelLine.ttDiscountDueDate = ? or
tDIncSelLine.tdIncSelLineDiscountTC = 0 or
tDIncSelLine.tdIncSelLineDiscountTC = ?
then tDIncSelLine.ttDueDate
else tDIncSelLine.ttDiscountDueDate
else tDPaySel.DPaySelDate
tDDocumentPaySel.DDocumentStatus = tDPaySel.DPaySelStatus
tDDocumentPaySel.DDocumentIncassoSelectCode = tDPaySel.DPaySelCode
tDDocumentPaySel.tcDebtorCode = tDIncSelLine.tcDebtorCode
tDDocumentPaySel.tcGLCode = tDPaySel.tcGLCode
tDDocumentPaySel.tcCurrencyCode = tDIncSelLine.tcInvoiceCurrencyCode
tDDocumentPaySel.tcPaymentLevelPayCode = tDIncSelLine.tcPaymentLevelPayCode
tDDocumentPaySel.tcPostingText = substitute( "&1 &2",
#T-8'Payment Selection':30(880)T-8#,
tDPaySel.DPaySelCode)
tDDocumentPaySel.ttPostingDate = tDPaySel.DPaySelDate
tDDocumentPaySel.tc_Rowid = string(viDocRowID)
viDocRowId = viDocRowID - 1.
<Q-90 run BankNumberPrim (all) (Read) (Cache)
(input tDDocumentPaySel.BankNumber_ID, (BankNumberId)
input ?, (ParentObjectId)
input ?, (BankNumber)
input ?, (BankNumberExtension)
input ?, (BankPayFormatID)
output dataset tqBankNumberPrim) in BBankNumber>
find first tqBankNumberPrim where tqBankNumberPrim.tiBankNumber_ID = tDDocumentPaySel.BankNumber_ID no-error.
if available tqBankNumberPrim
then assign tDDocumentPaySel.tcDebtorBankNumber = tqBankNumberPrim.tcBankNumber.
assign vhFcComponent = ?.
<M-7 run GetNumber
(input tDDocumentPaySel.Company_ID (iiCompanyId),
input tDDocumentPaySel.DDocumentYear (iiNumbrYear),
input 'D':U + tDDocumentPaySel.DDocumentType (icNumbrType),
output tDDocumentPaySel.DDocumentNumber (oiNumber),
input viFcCurrentInstanceId (iiInstanceId),
input vcFcComponentName (icClassName),
output viFcReturnSuper (oiReturnStatus)) in BNumber>
if viFcReturnSuper < 0 or
oiReturnStatus = 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then leave INCSEL_LOOP.
end. /* if not available tDDocumentPaySel */
assign tDDocumentPaySel.DDocumentOriginalDebitTC = if tDIncSelLine.tcInvoiceAmountCrDt = {&CREDITDEBITABBREVIATION-DEBIT}
then tDDocumentPaySel.DDocumentOriginalDebitTC + tDIncSelLine.tdIncSelLineAmountTC
else tDDocumentPaySel.DDocumentOriginalDebitTC - tDIncSelLine.tdIncSelLineAmountTC.
assign tDDocumentPaySel.DPaySel_ID = tDPaySel.DPaySel_ID.
find first tDDocInvXref where
tDDocInvXref.tc_ParentRowid = tDDocumentPaySel.tc_Rowid and
tDDocInvXref.DInvoice_ID = tDIncSelLine.tiDInvoiceId no-error.
find first tDInvBalance where
tDInvBalance.tiDInvoiceId = tDIncSelLine.tiDInvoiceId no-error.
if not available tDInvBalance
then do:
create tDInvBalance.
assign tDInvBalance.tiDInvoiceId = tDIncSelLine.tiDInvoiceId
tDInvBalance.tdInvoiceBalance = tDIncSelLine.tdInvoiceBalance.
end. /* if not available tDInvBalance */
if available tDDocInvXref
then do:
assign tDDocInvXref.DDocumentInvoiceXrefAlloTC = tDDocInvXref.DDocumentInvoiceXrefAlloTC +
tDIncSelLine.tdIncSelLineAmountTC + tDIncSelLine.tdIncSelLineDiscountTC
tDDocInvXref.DDocumentInvoiceXrefDiscTC = tDDocInvXref.DDocumentInvoiceXrefDiscTC +
tDIncSelLine.tdIncSelLineDiscountTC
tDDocInvXref.tdDefaultDiscountAmount = tDDocInvXref.tdDefaultDiscountAmount + tDIncSelLine.tdDefaultDiscountAmountTC
tDDocInvXref.tdDefaultPaymentAmount = tDDocInvXref.tdDefaultPaymentAmount + tDIncSelLine.tdDefaultPaymentAmountTC.
end. /* if available tDDocInvXref */
else do:
create tDDocInvXref.
if viFcReturnSuper < 0
then leave INCSEL_LOOP.
assign tDDocInvXref.DDocumentInvoiceXrefAlloTC = tDIncSelLine.tdIncSelLineAmountTC + tDIncSelLine.tdIncSelLineDiscountTC
tDDocInvXRef.DDocumentInvoiceXrefPaidAmtTC = tDIncSelLine.tdIncSelLineAmountTC
tDDocInvXref.DDocumentInvoiceXrefDiscTC = tDIncSelLine.tdIncSelLineDiscountTC
tDDocInvXref.DInvoice_ID = tDIncSelLine.tiDInvoiceId
tDDocInvXref.tcAllocAmountCrDt = tDIncSelLine.tcIncSelLineAmountCrDt
tDDocInvXref.tcBusinessRelationCode = tDIncSelLine.tcBusinessRelationCode
tDDocInvXref.tcBusinessRelationName1 = tDIncSelLine.tcBusinessRelationName1
tDDocInvXref.tcDInvoiceBalanceCrDt = tDIncSelLine.tcInvoiceBalanceCrDt
tDDocInvXref.tcDInvoiceReference = tDIncSelLine.tcInvoiceNumber + "/":U +
tDIncSelLine.tcInvoiceDescription
tDDocInvXref.tcDInvoiceType = tDIncSelLine.tcInvoiceType
tDDocInvXref.tcCompanyCode = tDIncSelLine.tcCompanyCode
tDDocInvXref.tcCurrencyCode = tDIncSelLine.tcInvoiceCurrencyCode
tDDocInvXref.tcNewBalanceCrDt = tDIncSelLine.tcInvoiceBalanceCrDt
tDDocInvXref.tdDInvoiceBalance = tDInvBalance.tdInvoiceBalance
tDDocInvXref.tdDiscountPercentage = tDIncSelLine.tdDiscountPercentage
tDDocInvXref.ttDInvoiceDate = tDIncSelLine.ttInvoiceDate
tDDocInvXref.ttDInvoiceDiscountDueDate = tDIncSelLine.ttDiscountDueDate
tDDocInvXref.ttDInvoiceDueDate = tDIncSelLine.ttDueDate
tDDocInvXref.tdDefaultDiscountAmount = tDIncSelLine.tdDefaultDiscountAmountTC
tDDocInvXref.tdDefaultPaymentAmount = tDIncSelLine.tdDefaultPaymentAmountTC
tDDocInvXref.tcDebtorCode = tDIncSelLine.tcDebtorCode
tDDocInvXRef.tc_ParentRowid = tDDocumentPaySel.tc_Rowid
tDDocInvXRef.tc_Rowid = tDIncSelLine.tc_Rowid.
end. /* else do: */
assign tDDocInvXref.tdNewBalance = tDDocInvXref.tdDInvoiceBalance - tDDocInvXref.DDocumentInvoiceXrefAlloTC
tDDocInvXref.tlUIFullAllocation = tDDocInvXref.tdNewBalance = 0
tDInvBalance.tdInvoiceBalance = tDDocInvXref.tdNewBalance.
if ((tDDocInvXRef.tcDInvoiceType = {&INVOICETYPE-INVOICECORRECTION} or
tDDocInvXRef.tcDInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION}) and
tDDocInvXRef.tdNewBalance > 0) or
((tDDocInvXRef.tcDInvoiceType <> {&INVOICETYPE-INVOICECORRECTION} and
tDDocInvXRef.tcDInvoiceType <> {&INVOICETYPE-CREDITNOTECORRECTION}) and
tDDocInvXref.tdNewBalance < 0)
then do:
assign vcMessage = trim(substitute(#T-45'The payment amount entered for invoice (&1) exceeds the invoice amount.':150(56596)T-45#, tDDocInvXref.tcDInvoiceReference)) + chr(10) +
trim(substitute(#T-76'Payment Amount: &1':255(817460682)T-76#, string(tDDocInvXref.DDocumentInvoiceXrefAlloTC))) + chr(10) +
trim(substitute(#T-55'Invoice Balance: &1':255(647668842)T-55#, string(tDDocInvXRef.tdDInvoiceBalance)))
oiReturnStatus = -1.
<M-50 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-114039':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>
leave INCSEL_LOOP.
end. /* if tDDocInvXref.tdNewBalance < 0 */
for each tdIncSelLineStage where
tdIncSelLineStage.tc_ParentRowid = tDIncSelLine.tc_Rowid:
for first tDDocInvXRefStage
where tDDocInvXRefStage.tc_ParentRowid = tDDocInvXref.tc_Rowid
and tDDocInvXRefStage.DInvoiceStage_ID = tDIncSelLineStage.tiDInvoiceStageId:
assign tDDocInvXRefStage.tc_Status = "C":U.
end.
if not available tDDocInvXRefStage
then do:
create tDDocInvXRefStage.
end. /* if not available tDDocInvXRefStage */
assign tDDocInvXRefStage.DInvoiceStage_ID = tDIncSelLineStage.tiDInvoiceStageId
tDDocInvXRefStage.DDocInvoiceXrefStageAlloTC = tDIncSelLineStage.tdStageAllocAmountTC
tDDocInvXRefStage.DDocInvoiceXrefStagePaidAmtTC = tDIncSelLineStage.tdStagePaymentAmountTC
tDDocInvXRefStage.DDocInvoiceXrefStageDiscTC = tDIncSelLineStage.tdStageDiscountAmountTC
tDDocInvXRefStage.tdDefaultAllocAmountTC = tDIncSelLineStage.tdOpenStageAmountTC
tDDocInvXRefStage.tdDefaultPaymentAmountTC = tDIncSelLineStage.tdDefaultStagePaymentAmountTC
tDDocInvXRefStage.tdDefaultDiscountAmountTC = tDIncSelLineStage.tdDefaultStageDiscountAmountTC
tDDocInvXRefStage.tiDInvoice_ID = tDIncSelLine.tiDInvoiceId
tDDocInvXRefStage.tc_ParentRowid = tDIncSelLineStage.tc_ParentRowid
tDDocInvXRefStage.tc_Rowid = string(viPayCodeRowid).
viPayCodeRowid = viPayCodeRowid - 1.
end. /* for each tDIncSelLineStage */
end. /* for each tDIncSelLine */
end. /* for each tDPaySel */
if oiReturnStatus < 0
then return.
if not available tDDocumentPaySel then
return.
if viBDDocument9ID = 0 or
viBDDocument9ID = ?
then do:
<I-17 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "true"
&CLASS = "BDDocument"}>
end. /* if viBBankNumber4ID = 0 or */
else if not valid-handle(vhBDDocument9Inst)
then do:
<I-29 {bFcOpenInstance
&CLASS = "BDDocument"}>
end. /* not if viDDocument9ID = 0 or */
/* run a method to pass these to BDDocument */
<M-21 run UpdateDDocument
(input tDDocumentPaySel (tDDocToUpdate),
input tDDocInvXRef (tDDocInvXRefToUpdate),
input tDDocInvXRefStage (tDDocInvXRefStageToUpdate),
output viFcReturnSuper (oiReturnStatus)) in BDDocument>
if viFcReturnSuper < 0 or
oiReturnStatus = 0
then assign oiReturnStatus = viFcReturnSuper.
if valid-handle(vhBDDocument9Inst)
then do:
<I-80 {bFcCloseInstance
&CLASS = "BDDocument"}>
end.