project QadFinancials > class BDInvoice > method CreateDIPostingValidate
Description
validate the input parameters of the posting
Parameters
biDInvoiceId | input-output | integer | DInvoice ID |
biPeriodId | input-output | integer | Period ID |
biPeriodYear | input-output | integer | Year of the accounting period |
biPeriodPeriod | input-output | integer | Period of Accounting Period |
biJournalId | input-output | integer | Journal ID |
bcJournalCode | input-output | character | Daybook Code |
biDebtorId | input-output | integer | Debtor ID |
bcDebtorCode | input-output | character | Customer Code |
biDivisionId | input-output | integer | Division ID |
bcDivisionCode | input-output | character | Sub-Account Code |
biCurrencyId | input-output | integer | |
bcCurrencyCode | input-output | character | Currency Code |
itPostingDate | input | date | posting date |
bcDInvoiceType | input-output | character | Invoice Type |
bcPostingType | input-output | character | Posting Type |
idExchangeRateCC | input | decimal | |
idExchangeRateScaleCC | input | decimal | |
idInvoiceAmountCC | input | decimal | |
idInvoiceAmountTC | input | decimal | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program3/bdinvoice.p)
/* replace unknown values */
if biDInvoiceId = ? then assign biDInvoiceId = 0.
if biPeriodId = ? then assign biPeriodId = 0.
if biPeriodYear = ? then assign biPeriodYear = 0.
if biPeriodPeriod = ? then assign biPeriodPeriod = 0.
if biDebtorId = ? then assign biDebtorId = 0.
if bcDebtorCode = ? then assign bcDebtorCode = "":U.
if bcDInvoiceType = ? then assign bcDInvoiceType = "":U.
if biDivisionId = ? then assign biDivisionId = 0.
if bcDivisionCode = ? then assign bcDivisionCode = "":U.
if biJournalId = ? then assign biJournalId = 0.
if bcJournalCode = ? then assign bcJournalCode = "":U.
if biCurrencyID = ? then assign biCurrencyID = 0.
if bcCurrencyCode = ? then assign bcCurrencyCode = "":U.
if idInvoiceAmountCC = ? then assign idInvoiceAmountCC = 0.
if idInvoiceAmountTC = ? then assign idInvoiceAmountTC = 0.
if idExchangeRateCC = ? then assign idExchangeRateCC = 0.
if idExchangeRateScaleCC = ? then assign idExchangeRateScaleCC = 0.
/*******************/
/* Validate statutory exchange rate and amount entered on customer opening balance screen */
if idInvoiceAmountCC <> 0 and
idExchangeRateCC <> 0 and
idExchangeRateScaleCC <> 0
then do:
<Q-48 run CurrencyByCurrRoundingMethod (all) (Read) (NoCache)
(input viCompanyCCId, (CurrencyID)
input ?, (CurrencyCode)
input ?, (RoundingMethodCode)
output dataset tqCurrencyByCurrRoundingMethod) in BCurrency>
find tqCurrencyByCurrRoundingMethod where
tqCurrencyByCurrRoundingMethod.tiCurrency_ID = viCompanyCCId
no-error.
if not available tqCurrencyByCurrRoundingMethod
then do:
assign vcMessage = trim(substitute(#T-83'Setup-error: unable to find the rounding-method for the statutory-currency (&1 / &2)':255(630405194)T-83#,vcCompanyLC,viCompanyLCId)).
<M-55 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-544476':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
assign oiReturnStatus = -1.
end. /* if not available tqCurrencyByCurrRoundingMethod */
assign vdActualInvoiceAmountCC = <M-50 RoundAmount
(input idInvoiceAmountTC * idExchangeRateCC * idExchangeRateScaleCC (idUnroundedAmount),
input viCompanyCCId (iiCurrencyID),
input '':U (icCurrencyCode)) in BDInvoice>.
if vdActualInvoiceAmountCC <> 0 and abs(idInvoiceAmountCC - vdActualInvoiceAmountCC) > abs(tqCurrencyByCurrRoundingMethod.tdRoundingMethodUnit)
then do:
assign vcMessage = trim(substitute(#T-26'Statutory Currency Amount :(&1) does not match statutory currency exchange rate :(&2) for Customer : (&3)':255(100987883)T-26#,idInvoiceAmountCC,idExchangeRateCC,bcDebtorCode)).
<M-70 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'Debtor Code':U (icFieldName),
input bcDebtorCode (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-482690':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
assign oiReturnStatus = -1.
end.
end. /* if idinvoiceamountcc */
/*****************************************/
/* ============== */
/* search invoice */
/* ============== */
find first tDInvoice where
tDInvoice.DInvoice_ID = biDInvoiceId
NO-error.
if not available tDInvoice
then do:
assign vcMessage = trim(#T-16'The specified customer invoice is not defined in the system.':150(49408)t-16#)
oiReturnStatus = -1.
<M-1 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-468':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end.
/* ========================== */
/* check mandatory parameters */
/* ========================== */
if (biPeriodId = 0 and biPeriodYear = 0 and biPeriodPeriod = 0) or
(biJournalId = 0 and bcJournalCode = "":U)
then do:
assign vcMessage = trim(#T-17'You must enter the GL period and daybook.':150(1064)T-17#)
oiReturnStatus = -1.
<M-7 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-475':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end.
if biDebtorId = 0 and bcDebtorCode = "":U
then do:
assign vcMessage = trim(#T-18'You must specify a customer.':150(49407)t-18#)
oiReturnStatus = -1.
<M-8 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-476':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end.
/* ======================================================= */
/* get the period year and period if only the id is filled */
/* ======================================================= */
if (biPeriodId <> 0 and
biPeriodYear = 0 and
biPeriodPeriod = 0) or
(biPeriodId = 0 and
biPeriodYear <> 0 and
biPeriodPeriod <> 0)
then do:
<Q-2 run PeriodPrim (all) (Read) (NoCache)
(input tDInvoice.Company_ID, (CompanyId)
input biPeriodId, (PeriodId)
input if biPeriodId = 0 then biPeriodYear else ?, (PeriodYear)
input if biPeriodId = 0 then biPeriodPeriod else ?, (PeriodPeriod)
output dataset tqPeriodPrim) in BPeriod >
find first tqPeriodPrim no-error.
if not available tqPeriodPrim
then do:
assign vcMessage = trim(#T-19'The specified GL period is not defined in the system.':150(341)t-19#)
oiReturnStatus = -1.
<M-9 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-477':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end.
else assign biPeriodYear = tqPeriodPrim.tiPeriodYear
biPeriodPeriod = tqPeriodPrim.tiPeriodPeriod
biPeriodId = tqPeriodPrim.tiPeriod_ID.
end.
/* ============================================= */
/* get the journal code if only the id is filled */
/* ============================================= */
if (bcJournalCode = "":U and biJournalId <> 0) or
(bcJournalCode <> "":U and biJournalId = 0) or
(bcJournalCode <> "":U and biJournalId <> 0)
then do:
<Q-3 run JournalPrim (all) (Read) (NoCache)
(input tDInvoice.Company_ID, (CompanyId)
input if bijournalId = 0 then bcjournalCode else '':U, (JournalCode)
input biJournalId, (JournalID)
output dataset tqJournalPrim) in BJournal >
find first tqJournalPrim no-error.
if not available tqJournalPrim
then do:
assign vcMessage = trim(#T-20'The specified daybook is not defined in the system.':150(343)t-20#)
oiReturnStatus = -1.
<M-10 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-469':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end.
else assign bcJournalCode = tqJournalPrim.tcJournalCode.
end.
/* =================================================== */
/* get the debtor id if only the debtor code is filled */
/* =================================================== */
if biDebtorId = 0 and bcDebtorCode <> "":U
then do:
<Q-4 run DebtorPrim (all) (Read) (NoCache)
(input tDInvoice.Company_ID, (CompanyId)
input bcDebtorCode, (DebtorCode)
input ?, (Debtor_ID)
output dataset tqDebtorPrim) in BDebtor >
find first tqDebtorPrim no-error.
if NOT available tqDebtorPrim
then do:
assign vcMessage = trim(#T-21'The specified customer is not defined in the system.':150(49409)t-21#)
oiReturnStatus = -1.
<M-11 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-470':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end.
else assign biDebtorId = tqDebtorPrim.tiDebtor_ID.
end.
/* ======================================================= */
/* get the division code if only the division id is filled */
/* ======================================================= */
if biDivisionId <> 0 and bcDivisionCode = "":U
then do:
<Q-5 run DivisionPrim (all) (Read) (NoCache)
(input tDInvoice.Company_ID, (CompanyId)
input biDivisionId, (DivisionID)
input '':U, (DivisionCode)
output dataset tqDivisionPrim) in BDivision >
find first tqDivisionPrim no-error.
if not available tqDivisionPrim
then do:
assign vcMessage = trim(#T-22'The specified sub-account is not defined in the system.':150(1066)t-22#)
oiReturnStatus = -1.
<M-12 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-471':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end.
else assign bcDivisionCode = tqDivisionPrim.tcDivisionCode.
end.
/* ======================================================= */
/* get the currency code if only the currency id is filled */
/* ======================================================= */
if biCurrencyID <> 0 and bcCurrencyCode = "":U
then do:
<Q-6 run CurrencyPrim (all) (Read) (NoCache)
(input ?, (CurrencyCode)
input biCurrencyID, (Currency_ID)
output dataset tqCurrencyPrim) in BCurrency >
find first tqCurrencyPrim no-error.
if not available tqCurrencyPrim
then do:
assign vcMessage = trim(#T-23'The specified currency is not defined in the system.':150(1067)t-23#)
oiReturnStatus = -1.
<M-13 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-472':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end.
else assign bcCurrencyCode = tqCurrencyPrim.tcCurrencyCode.
end.
/* ========================= */
/* posting date is mandatory */
/* ========================= */
if itPostingDate = ?
then do:
assign vcMessage = trim(#T-24'You must enter the posting date.':150(1068)T-24#)
oiReturnStatus = -1.
<M-14 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-473':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end.
/* ========================================== */
/* invoice type must be invoice, creditnote */
/* ========================================== */
assign vlFound = false.
assign vcINVOICETYPES ={&INVOICETYPES}.
do viCounter = num-entries(vcINVOICETYPES,chr(2)) to 2 by -1 :
if bcDInvoiceType = entry(viCounter,vcINVOICETYPES,chr(2))
then do:
assign vlFound = true.
leave.
end.
end.
if not vlFound
then do:
assign vcMessage = trim(substitute(#T-25'The invoice type must be &1, &2, &3, &4, &5, or &6.':255(14384)t-25#,{&INVOICETYPE-INVOICE-TR},{&INVOICETYPE-CREDITNOTE-TR},{&INVOICETYPE-ADJUSTMENT-TR},{&INVOICETYPE-PREPAYMENT-TR}, {&INVOICETYPE-INVOICECORRECTION-TR}, {&INVOICETYPE-CREDITNOTECORRECTION-TR}))
oiReturnStatus = -1.
<M-15 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-474':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end.
/* update the posting type, in case at create of invoice, you must do that so you can update balance fields */
if bcPostingType = "":U
then assign bcPostingType = if bcDInvoiceType = {&INVOICETYPE-INVOICE} or bcDInvoiceType = {&INVOICETYPE-FINANCECHARGE} or bcDInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
then {&POSTINGTYPE-DEBIT}
else if bcDInvoiceType = {&INVOICETYPE-CREDITNOTE} or bcDInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION}
then {&POSTINGTYPE-CREDIT}
else "":U.