project QadFinancials > class BDInvoice > method DefaultValuesValidate
Description
some extra validations on input fields
Parameters
tDIDefault | input | temp-table | some screen-values that you need to default other fields |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program3/bdinvoice.p)
/* check if there is one record available */
find first tDIDefault no-error.
if not available tDIDefault
then do:
assign vcMessage = (#T-27'No input record was found. You must define for which fields the value must default.':255(978)t-27#)
oiReturnStatus = -1.
<M-2 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-619':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
return.
end.
if tDIDefault.tcDInvoiceType <> "":U and tDIDefault.tcDInvoiceType <> ? and tDIDefault.tcDInvoiceType <> {&INVOICETYPE-INVOICE} and tDIDefault.tcDInvoiceType <> {&INVOICETYPE-FINANCECHARGE} and tDIDefault.tcDInvoiceType <> {&INVOICETYPE-CREDITNOTE} and tDIDefault.tcDInvoiceType <> {&INVOICETYPE-INVOICECORRECTION} and tDIDefault.tcDInvoiceType <> {&INVOICETYPE-CREDITNOTECORRECTION}
then do:
assign vcMessage = trim(substitute(#T-28'The invoice must be of type &1, &2, &3, &4 or &5.':255(57309)t-28#, {&INVOICETYPE-INVOICE}, {&INVOICETYPE-FINANCECHARGE}, {&INVOICETYPE-CREDITNOTE}, {&INVOICETYPE-INVOICECORRECTION}, {&INVOICETYPE-CREDITNOTECORRECTION}))
oiReturnStatus = -1.
<M-3 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-632':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
return.
end.
if tDIDefault.tiDebtorId <> 0 or tDIDefault.tcDebtorCode <> "":U
then do:
<Q-5 assign vlFcQueryRecordsAvailable = DebtorPrim (NoCache)
(input viCompanyId, (CompanyId)
input if tDIDefault.tiDebtorId = 0 then tDIDefault.tcDebtorCode else '':U, (DebtorCode)
input tDIDefault.tiDebtorId, (Debtor_ID)) in BDebtor >
if not vlFcQueryRecordsAvailable
then do:
if tDIDefault.tcFieldName = {&INVOICEFIELDNAME-GENERALINFO}
then do:
assign vcMessage = trim(#T-29'The specified customer is not defined in the system.':255(49406)t-29#)
oiReturnStatus = -1.
<M-6 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-904':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
return.
end.
else do:
assign oiReturnStatus = -1.
return.
end.
end.
end.
if tDIDefault.tcFieldName = "":U
then do:
assign vcMessage = trim(#T-30'You must enter the field name.':255(979)T-30#)
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-478':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
return.
end.
if tDIDefault.tcFieldName = {&INVOICEFIELDNAME-DITEXT} and
tDIDefault.tcDInvoiceDIText = "":U
then do:
assign oiReturnStatus = -1.
return.
end.
/* transaction end country and original tc must be passed to, but can be blank */
if tDIDefault.tcFieldName = {&INVOICEFIELDNAME-DEBTOR} and
((tDIDefault.tiDebtorId = 0 and
tDIDefault.tcDebtorCode = "":U) or
tDIDefault.tcDInvoiceType = "":U or
tDIDefault.ttDInvoiceDate = ? )
then do:
assign oiReturnStatus = -1.
return.
end.
if tDIDefault.tcFieldName = {&INVOICEFIELDNAME-DEBTORVATNUMBER} and
((tDIDefault.tiDebtorVatNumberId = 0 and
tDIDefault.tcDebtorVatNumber = "":U) or
(tDIDefault.tiDebtorId = 0 and
tDIDefault.tcDebtorCode = "":U))
then do:
assign oiReturnStatus = -1.
return.
end.
/* original tc and lc must be passed but can be blank */
if tDIDefault.tcFieldName = {&INVOICEFIELDNAME-CURRENCY} and
((tDIDefault.tiCurrencyId = 0 and
tDIDefault.tcCurrencyCode = "":U) or
tDIDefault.ttDInvoiceDate = ?)
then do:
assign oiReturnStatus = -1.
return.
end.
if tDIDefault.tcFieldName = {&INVOICEFIELDNAME-DESCRIPTION} and
tDIDefault.tcDInvoiceDescription = "":U
then do:
assign oiReturnStatus = -1.
return.
end.
if tDIDefault.tcFieldName = {&INVOICEFIELDNAME-DISCOUNTPAYMCOND} and
(tDIDefault.tiDiscountPaymentConditionId = 0 or
tDIDefault.ttDInvoiceDate = ?)
then do:
assign oiReturnStatus = -1.
return.
end.
if tDIDefault.tcFieldName = {&INVOICEFIELDNAME-DIVISION} and
((tDIDefault.tiDivisionId = 0 and
tDIDefault.tcDivisionCode = "":U) or
tDIDefault.tcDInvoiceType = "":U)
then do:
assign oiReturnStatus = -1.
return.
end.
/* original tc and lc must be passed but can be blank */
if tDIDefault.tcFieldName = {&INVOICEFIELDNAME-INVOICEDATE} and
(tDIDefault.ttDInvoiceDate = ? or
(tDIDefault.tiCurrencyId = 0 and
tDIDefault.tcCurrencyCode = "":U))
then do:
assign oiReturnStatus = -1.
return.
end.
/* original tc, own vatnumber and transaction end must be passed but can be blank */
if tDIDefault.tcFieldName = {&INVOICEFIELDNAME-INVOICETYPE} and
(tDIDefault.ttDInvoiceDate = ? or
(tDIDefault.tiDebtorId = 0 and
tDIDefault.tcDebtorCode = "":U) )
then do:
assign oiReturnStatus = -1.
return.
end.
if tDIDefault.tcFieldName = {&INVOICEFIELDNAME-LINKEDINVOICE} and
(tDIDefault.tiLinkedPeriodYear = 0 or
tDIDefault.tiLinkedDInvoiceVoucher = 0 or
tDIDefault.tcLinkedJournalCode = "":U)
then do:
assign oiReturnStatus = -1.
return.
end.
if tDIDefault.tcFieldName = {&INVOICEFIELDNAME-NORMALPAYMCOND} and
((tDIDefault.tiNormalPaymentConditionId = 0 and
tDIDefault.tcNormalPaymentConditionCode = "":U) or
tDIDefault.ttDInvoiceDate = ?)
then do:
assign oiReturnStatus = -1.
return.
end.
/* original tc must be passed but can be blank */
if tDIDefault.tcFieldName = {&INVOICEFIELDNAME-ORIGINALLC} and
(tDIDefault.tdDInvoiceOriginalLC = 0 or
(tDIDefault.tiCurrencyId = 0 and
tDIDefault.tcCurrencyCode = "":U) or
tDIDefault.ttDInvoiceDate = ?)
then do:
assign oiReturnStatus = -1.
return.
end.
/* original lc must be passed but can be blank */
if tDIDefault.tcFieldName = {&INVOICEFIELDNAME-ORIGINALTC} and
(tDIDefault.tdDInvoiceOriginalTC = 0 or
(tDIDefault.tiCurrencyId = 0 and
tDIDefault.tcCurrencyCode = "":U) or
tDIDefault.ttDInvoiceDate = ? or
tDIDefault.tcDInvoiceType = "":U)
then do:
assign oiReturnStatus = -1.
return.
end.
if tDIDefault.tcFieldName = {&INVOICEFIELDNAME-OWNVATNUMBER} and
tDIDefault.tiOwnVatNumberId = 0 and
tDIDefault.tcOwnVatNumber = "":U
then do:
assign oiReturnStatus = -1.
return.
end.
if tDIDefault.tcfieldname = {&INVOICEFIELDNAME-REASON} and
tDIDefault.tiReasonId = 0 and
tDIDefault.tcReasonCode = "":U
then do:
assign oiReturnStatus = -1.
return.
end.
if tDIDefault.tcFieldName = {&INVOICEFIELDNAME-GENERALINFO} and
((tDIDefault.tiDebtorId = 0 and
tDIDefault.tcDebtorCode = "":U) or
tDIDefault.tcDInvoiceType = "":U or
tDIDefault.tdDInvoiceOriginalTC = ? or
tDIDefault.ttDInvoiceTaxPointDate = ?)
then do:
assign vcMessage = trim(#T-31'You must enter a value in the following fields: Customer, Invoice Type, TC Invoice Amount, and Tax Point Date.':255(1756)t-31#)
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-905':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
return.
end.
if tDIDefault.tcFieldName = {&INVOICEFIELDNAME-YEAR} and
(tDIDefault.tiPeriodYear = 0 or
(tDIDefault.tcJournalCode = "":U and
tDIDefault.tiJournalId = 0 and
tDIDefault.tcDAJournalCode = "":U))
then do:
assign oiReturnStatus = -1.
return.
end.
/* no test on journal because you have to set it blank again so the number must be reset again too */
if tDIDefault.tcFieldName = {&INVOICEFIELDNAME-JOURNAL} and
tDIDefault.tiPeriodYear = 0
then do:
assign oiReturnStatus = -1.
return.
end.
/* no test on DA journal because you have to set it blank again so the number must be reset again too */
if tDIDefault.tcFieldName = {&INVOICEFIELDNAME-DAJOURNAL} and
tDIDefault.tiPeriodYear = 0
then do:
assign oiReturnStatus = -1.
return.
end.
/* extra validations for general info : all validation that are normally done on save */
/* are done here */
if tDIDefault.tcFieldName = {&INVOICEFIELDNAME-GENERALINFO}
then do:
if (tDIDefault.tiDebtorId <> 0 and tDIDefault.tiDebtorId <> ?) or
(tDIDefault.tcDebtorCode <> "":U and tDIDefault.tcDebtorCode <> ?)
then do :
<Q-8 run DebtorByDebtor (first) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressType)
input tDIDefault.tiDebtorId, (DebtorId)
input if (tdidefault.tidebtorId = 0 or tdidefault.tidebtorId = ?) then tdidefault.tcdebtorCode else '':U, (DebtorCode)
output dataset tqDebtorByDebtor) in BDebtor >
if tDIDefault.tiDebtorId <> 0 and tDIDefault.tiDebtorId <> ?
then find first tqDebtorByDebtor where
tqDebtorByDebtor.tiDebtor_ID = tDIDefault.tiDebtorId
no-error.
else find first tqDebtorByDebtor where
tqDebtorByDebtor.tcDebtorCode = tDIDefault.tcDebtorCode
no-error.
if available tqDebtorByDebtor
then do:
assign viControlGLProfileId = if tDIDefault.tcDInvoiceType = {&INVOICETYPE-INVOICE} or tDIDefault.tcDInvoiceType = {&INVOICETYPE-FINANCECHARGE} or tDIDefault.tcDInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
then tqDebtorByDebtor.tiInvControlGLProfile_ID
else if tDIDefault.tcDInvoiceType = {&INVOICETYPE-CREDITNOTE} or tDIDefault.tcDInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION}
then tqDebtorByDebtor.tiCnControlGLProfile_ID
else tqDebtorByDebtor.tiInvControlGLProfile_ID.
<M-9 run ValDebtorId (input tqDebtorByDebtor.tiDebtor_ID (iiTargetField),
input 'tDInvoice.Debtor_ID':U (icTargetFieldName),
input '':U (icRowid),
input tqDebtorByDebtor.tlDebtorIsActive (ilActive),
input tqDebtorByDebtor.tlDebtorIsLockedCredLim (ilLocked),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
end.
else do:
assign vcMessage = trim(substitute(#T-32'The customer &1 (&2) is not defined in the system or is invalid.':255(1757)t-32#,tDIDefault.tcDebtorCode,string(tDIDefault.tiDebtorId)))
oiReturnStatus = -1.
<M-22 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-941':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end.
end.
if (tDIDefault.tiPeriodYear <> 0 and tDIDefault.tiPeriodYear <> ?) and
(tDIDefault.tiPeriodPeriod <> 0 and tDIDefault.tiPeriodPeriod <> ?)
then do :
<Q-11 run PeriodByYearPeriod (first) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input tDIDefault.tiPeriodYear, (PeriodYear)
input tDIDefault.tiPeriodPeriod, (PeriodPeriod)
input ?, (PeriodId)
output dataset tqPeriodByYearPeriod) in BPeriod >
find first tqPeriodByYearPeriod where
tqPeriodByYearPeriod.tiPeriodYear = tDIDefault.tiPeriodYear and
tqPeriodByYearPeriod.tiPeriodPeriod = tDIDefault.tiPeriodPeriod
no-error.
if available tqPeriodByYearPeriod
then do:
<M-13 run ValPeriodId (input tqPeriodByYearPeriod.tiPeriod_ID (iiTargetField),
input 'tDInvoice.Period_ID':U (icTargetFieldName),
input '':U (icRowid),
input tqPeriodByYearPeriod.tcPeriodStatus (icPeriodStatus),
input tqPeriodByYearPeriod.tlPeriodIsPostingSalesAllow (ilIsPostingSalesAllowed),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
end.
else do:
assign vcMessage = trim(substitute(#T-33'The GL period &1/&2 is not defined in the system or is invalid.':255(983)t-33#,string(tDIDefault.tiPeriodYear),string(tDIDefault.tiPeriodPeriod)))
oiReturnStatus = -1.
<M-23 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-942':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end.
end.
<M-38 run ValidateDInvoiceExchangeRate
(input tDIDefault.tdDInvoiceExchangeRate (idDinvoiceExchangeRate),
input '':U (icRowid),
input ? (iiCurrencyID),
input ? (icDInvoiceReference),
input tDIDefault.tcCurrencyCode (icCurrencyCode),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
<M-39 run ValDInvoiceRateScale (input tDIDefault.tdDInvoiceExchangeRateScale (idTargetField),
input 'tDInvoice.DInvoiceRateScale':U (icTargetFieldName),
input '':U (icRowid),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
<M-10 run ValidateInvoiceDate
(input tDIDefault.ttDinvoiceDate (itDinvoiceInvoiceDate),
input '':U (icRowid),
input tDIDefault.ttDInvoicePostingDate (itDInvoicePostingDate),
input tDIDefault.tcDInvoiceType (icDInvoiceType),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
<M-37 run ValidateComponentAllPostOrigiNotNeg
(input tDIDefault.tdDInvoiceOriginalTC (idTargetField),
input if tDIDefault.tcDInvoiceType begins 'INV':U then 'tDInvoice.DInvoiceOriginalDebitTC':U else 'tDInvoice.DInvoiceOriginalCreditTC':U (icTargetFieldName),
input '':U (icRowid),
input tDIDefault.tcDInvoiceType (icDInvoiceType),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if (tDIDefault.tiDivisionId <> 0 and tDIDefault.tiDivisionId <> ?) or
(tDIDefault.tcDivisionCode <> "":U and tDIDefault.tcDivisionCode <> ?)
then do :
<Q-15 run DivisionByIdCodeDetails (first) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input tdidefault.tcdivisionCode, (DivisionCode)
input ?, (DivisionDescription)
input ?, (DivisionIsActive)
input tDIDefault.tiDivisionId, (DivisionId)
output dataset tqDivisionByIdCodeDetails) in BDivision >
if tDIDefault.tiDivisionId <> 0 and tDIDefault.tiDivisionId <> ?
then find first tqDivisionByIdCodeDetails where
tqDivisionByIdCodeDetails.tiDivision_ID = tDIDefault.tiDivisionId
no-error.
else find first tqDivisionByIdCodeDetails where
tqDivisionByIdCodeDetails.tcDivisionCode = tDIDefault.tcDivisionCode
no-error.
end.
<M-19 run ValidateComponentAllCheckAmountDateDebt (input tDIDefault.tcDInvoiceType (icDInvoiceType),
input tDIDefault.tdDInvoiceOriginalTC (idDInvoiceOriginalTC),
input tDIDefault.ttDinvoiceDate (itDInvoiceDate),
input tDIDefault.tiDebtorId (iiDebtorId),
input if tdidefault.tidebtorId = 0 then tdidefault.tcdebtorCode else '':U (icDebtorCode),
input tDIDefault.tiCurrencyId (iiCurrencyId),
input if tdidefault.ticurrencyId = 0 then tdidefault.tccurrencyCode else '':U (icCurrencyCode),
input '':U (icRowId),
input 0 (iiDInvoiceId),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
end.