project QadFinancials > class BDInvoice > method ApiCreateDebtorInvoicesV01
Description
This method allows external parties to Create Debtor Invoices.
The invoice itself, the DI posting (non-taxable) and the movement record will be created.
Following tables will be updated : DInvoice, DInvoicePosting, DInvoiceMovement
(The balance and the status will also be updated.)
The voucher will be returned through the input output temp-table.
PostCondition
After the execution of the method the records in the temp-tables are created as new debtor invoices. The invoice itself, the DI posting (non-taxable) and the movement records are created.
Parameters
tDIOpenBalance | input-output | temp-table | Temp-table used for the creation of Debtor-Opening-Balances |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program9/bdinvoice.p)
/* create the debtor adjustment : create dinvoice, diposting, dinvoicemovement, dinvoiceposting and */
/* update the balance and status fields */
<M-18 run CreateDInvoices
(input-output tDIOpenBalance (tDIOpenBalance),
input ? (iiBJournalEntryId),
input ? (iiPostingId),
output vcParam (ocNewRecordInfo),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.
/* extra validation for the prepayment open balance creation */
/* this can not be done in CreateDInvoicesValidate because the validation should only be done to Supplier Open Balance Create */
for each tDIOpenBalance where tDIOpenBalance.tcInvoiceType = {&INVOICETYPE-PREPAYMENT}:
/* Get The JournalType */
<Q-44 run JournalByJournalLayerType (all) (Read) (NoCache)
(input ?, (JournalId)
input tDIOpenBalance.tcJournalCode, (JournalCode)
input viCompanyId, (CompanyId)
input ?, (LayerTypeCode)
output dataset tqJournalByJournalLayerType) in BJournal >
find first tqJournalByJournalLayerType where
tqJournalByJournalLayerType.tcJournalCode = tDIOpenBalance.tcJournalCode
no-error.
/* no need to validate the availablility because it has been done in CreateDInvoiceValidate method */
if tDIOpenBalance.tcInvoiceType = {&INVOICETYPE-PREPAYMENT} and tqJournalByJournalLayerType.tcJournalTypeCode <> {&JOURNALTYPE-DEBTORADJUSTMENT}
then do :
assign oiReturnStatus = -1.
<M-97 run SetMessage
(input trim(#T-28'For opening balances of type Prepayment a daybook of type Customer Adjustment should be used.':150(733759401)T-28#) (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-874130':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end. /* if available */
end. /* end of For each */
if oiReturnStatus < 0
then return.
/* ============================================================================= */
/* Extra work for Deuduction Invoice, create one detail line for deduction */
/* ============================================================================= */
for each tDIOpenBalance where tDIOpenBalance.tcInvoiceType = {&INVOICETYPE-DEDUCTION}:
/* Get The JournalType */
<Q-68 run JournalByJournalLayerType (all) (Read) (NoCache)
(input ?, (JournalId)
input tDIOpenBalance.tcJournalCode, (JournalCode)
input viCompanyId, (CompanyId)
input ?, (LayerTypeCode)
output dataset tqJournalByJournalLayerType) in BJournal>
find first tqJournalByJournalLayerType where
tqJournalByJournalLayerType.tcJournalCode = tDIOpenBalance.tcJournalCode
no-error.
/* no need to validate the availablility because it has been done in CreateDInvoiceValidate method */
if tqJournalByJournalLayerType.tcJournalTypeCode <> {&JOURNALTYPE-DEDUCTION}
then do :
<M-22 run SetMessage
(input #T-27'For opening balances of type deduction a daybook of type customer deduction shoud be used.':150(339612029)T-27# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-597891':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
assign oiReturnStatus = -1.
return.
end.
/*validate the deduction code */
<M-74 run ValDeductionCatLine
(input-output viDeductionCatLine_ID (biDeductionCatLineID),
input '':U (icTargetFieldName),
input '':U (icRowid),
input tDIOpenBalance.tcDeductionCatCode (icDeductionCatCode),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0
then do:
assign oiReturnStatus = viFcReturnSuper.
return.
end.
find first tDInvoice where
tDInvoice.tc_Status = "N":U and
tDInvoice.DInvoice_ID = tDIOpenBalance.tiInvoiceId no-lock no-error.
if not available tDInvoice then
do:
assign oiReturnStatus = -1.
return.
end.
/* Need to assign balance value, since it will skip in the later method "ValidateComponentPre" */
assign tDInvoice.DInvoiceBalanceDebitTC = tDInvoice.DInvoiceOriginalDebitTC
tDInvoice.DInvoiceBalanceCreditTC = tDInvoice.DInvoiceOriginalCreditTC
tDInvoice.DInvoiceBalanceDebitLC = tDInvoice.DInvoiceOriginalDebitLC
tDInvoice.DInvoiceBalanceCreditLC = tDInvoice.DInvoiceOriginalCreditLC
tDInvoice.DInvoiceBalanceDebitCC = tDInvoice.DInvoiceOriginalDebitCC
tDInvoice.DInvoiceBalanceCreditCC = tDInvoice.DInvoiceOriginalCreditCC
tDInvoice.DInvoiceBalanceTC = tDInvoice.DInvoiceBalanceDebitTC - tDInvoice.DInvoiceBalanceCreditTC
tDInvoice.DInvoiceBalanceLC = tDInvoice.DInvoiceBalanceDebitLC - tDInvoice.DInvoiceBalanceCreditLC
tDInvoice.DInvoiceBalanceCC = tDInvoice.DInvoiceBalanceDebitCC - tDInvoice.DInvoiceBalanceCreditCC
tDInvoice.DInvoiceIsOpen = tDInvoice.DInvoiceBalanceTC <> 0 or
tDInvoice.DInvoiceBalanceLC <> 0 or
tDInvoice.DInvoiceBalanceCC <> 0.
/*Create new detail line for deduction */
<M-75 run AddDetailLine
(input 'DInvoiceDeduction':U (icTable),
input tDInvoice.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0
then do:
assign oiReturnStatus = viFcReturnSuper.
return.
end.
assign tDInvoiceDeduction.DeductionCatLine_ID = viDeductionCatLine_ID
tDInvoiceDeduction.DInvoiceDeductionStatus = {&INVOICEDEDUCTSTATUS-PENDING}
tDInvoiceDeduction.DInvoiceDeductionCC = tDIOpenBalance.tdInvoiceAmountCC
tDInvoiceDeduction.DInvoiceDeductionTC = tDIOpenBalance.tdInvoiceAmountTC
tDInvoiceDeduction.DInvoiceDeductionLC = tDIOpenBalance.tdInvoiceAmountLC
tDInvoiceDeduction.PaidDInvoice_ID = 0.
tDInvoiceDeduction.DInvoiceDeductionCreateDate = today.
end.
/* =============================== */
/* Set Actvity */
/* =============================== */
if can-find (first tDInvoice where
tDInvoice.tc_Status = "N":U)
then assign vcActivityCode = "Create":U.
else if can-find (first tDInvoice where
tDInvoice.tc_Status = "C":U)
then assign vcActivityCode = "Modify":U.
/* validate */
<M-91 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.
/* additional updates */
<M-3 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.
/* save */
<M-12 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.
<M-78 run GetOpeningBalanceVoucher
(input-output tDIOpenBalance (tDIOpenBalance),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or
oiReturnStatus = 0
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.