Description
OIAdjCommit; Save the whole adjustment: validations
Parameters
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program8/bopenitemadjustment.p)
/* ====================================== */
/* Exception handling - processing block */
/* ====================================== */
assign oiReturnStatus = -98
viLocalReturnStatus = 0.
VALIDATIONTWOBLOCK : DO :
/* ==================== */
/* Go through all lines */
/* ==================== */
for each tOIAdj no-lock:
/* Warnings for locked and non approved invoice adjustments */
<Q-14 run ReasonByIdCode (all) (Read) (NoCache)
(input ?, (ReasonId)
input tOIAdj.tcReasonCode, (ReasonCode)
output dataset tqReasonByIdCode) in BReason>
find first tqReasonByIdCode where
tqReasonByIdCode.tcReasonCode = tOIAdj.tcReasonCode no-error.
if available tqReasonByIdCode
then do:
if tqReasonByIdCode.tlReasonIsLockPayment
then do:
/* Invoice is locked for payment give warning */
vcMsgOIAdj = trim(substitute(#T-95'The Invoice &1 that you have selected for allocation has a status &2. This indicates the Invoice is locked for payment':255(486157981)T-95#, tOIAdj.tcCInvoiceReference, tOIAdj.tcReasonCode)).
<M-39 run SetMessage
(input vcMsgOIAdj (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input tOIAdj.tcCInvoiceReference (icFieldValue),
input 'W':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-860048':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
viLocalReturnStatus = +1.
end. /* if tqReasonByIdCode.tlReasonIsLockPayment */
if not tqReasonByIdCode.tlReasonIsInvoiceApproved
then do:
/* Invoice is not approved give warning */
vcMsgOIAdj = trim(substitute(#T-76'The Invoice &1 that you have selected for allocation has a status &2. This indicates the Invoice is not approved':255(127705806)T-76#, tOIAdj.tcCInvoiceReference, tOIAdj.tcReasonCode)).
<M-18 run SetMessage
(input vcMsgOIAdj (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input tOIAdj.tcCInvoiceReference (icFieldValue),
input 'W':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-241432':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
viLocalReturnStatus = +1.
end. /* if not tqReasonByIdCode.tlReasonIsInvoiceApproved */
end. /* if available tqReasonByIdCode */
/* ======================================================================================== */
/* - The adjustmentAmountLC and -TC are mandatory and the exchange-rate cannot be zero */
/* ======================================================================================== */
if tOIAdj.tdAdjustmentExchangeRate = 0 or
tOIAdj.tdAdjustmentExchangeRate = ?
then do :
assign viLocalReturnStatus = -1
vcMsgOIAdj = trim(#T-247'The adjustment exchange rate cannot be zero.':255(69701)T-247#) + chr(10) +
trim(substitute(#T-249'Invoice origin: &1.':255(2921)T-249#,tOIAdj.tcInvoiceOrigin)) + chr(10) +
trim(substitute(#T-250'Invoice type: &1.':255(2922)T-250#,tOIAdj.tcInvoiceType)) + chr(10) +
trim(substitute(#T-240'Invoice number: &1.':255(2923)T-240#,tOIAdj.tcInvoiceNumberReference)).
<M-201 run SetMessage
(input vcMsgOIAdj (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8155':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
end. /* if tOIAdj.tdAdjustmentExchangeRate = 0 or */
/* ======================================================================================== */
/* - The adjustmentAmount should be the difference between the New and Original Balance */
/* ======================================================================================== */
if (tOIAdj.tdAdjustmentAmountLC = 0 or
tOIAdj.tdAdjustmentAmountLC = ?) and
(tOIAdj.tdAdjustmentAmountTC = 0 or
tOIAdj.tdAdjustmentAmountTC = ?)
then do :
assign viLocalReturnStatus = -1
vcMsgOIAdj = trim(substitute(#T-241'The adjustment amount in base currency (&1) and the adjustment amount in transaction currency (&2) cannot both be zero.':255(2927)T-241#,(if tOIAdj.tdAdjustmentAmountLC = ? then "?":U else string(tOIAdj.tdAdjustmentAmountLC)),(if tOIAdj.tdAdjustmentAmountTC = ? then "?":U else string(tOIAdj.tdAdjustmentAmountTC)))) + " ":U + trim(#T-242'Details':255(2920)T-242#) + ";":U + chr(10) +
trim(substitute(#T-243'Invoice origin: &1.':255(2921)T-243#,tOIAdj.tcInvoiceOrigin)) + chr(10) +
trim(substitute(#T-244'Invoice type: &1.':255(2922)T-244#,tOIAdj.tcInvoiceType)) + chr(10) +
trim(substitute(#T-245'Invoice number: &1.':255(2923)T-245#,tOIAdj.tcInvoiceNumberReference)).
<M-202 run SetMessage
(input vcMsgOIAdj (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8156':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
end. /* if tOIAdj.tdAdjustmentAmountLC = 0 or */
if (tOIAdj.tcAdjustmentCrDt = tOIAdj.tcInvoiceBalanceCrDt and
tOIAdj.tdNewBalanceTC <> tOIAdj.tdInvoiceBalanceTC + tOIAdj.tdAdjustmentAmountTC) or
(tOIAdj.tcAdjustmentCrDt <> tOIAdj.tcInvoiceBalanceCrDt and
tOIAdj.tdNewBalanceTC <> tOIAdj.tdInvoiceBalanceTC - tOIAdj.tdAdjustmentAmountTC)
then do :
assign viLocalReturnStatus = -1
vcMsgOIAdj = trim(substitute(#T-251'The adjustment amount (&1) should be the difference between the original open balance (&2) and the newly entered open balance (&3).':255(69519)T-251#,tOIAdj.tdAdjustmentAmountTC,tOIAdj.tdInvoiceBalanceTC,tOIAdj.tdNewBalanceTC)) + chr(10) +
trim(substitute(#T-259'Invoice origin: &1':255(69553)T-259#,tOIAdj.tcInvoiceOrigin)) + chr(10) +
trim(substitute(#T-264'Invoice type: &1.':255(2922)T-264#,tOIAdj.tcInvoiceType)) + chr(10) +
trim(substitute(#T-263'Invoice number: &1':255(69557)T-263#,tOIAdj.tcInvoiceNumberReference)) + chr(10) +
trim(substitute(#T-262'Original open balance: &1':255(69556)T-262#,string(tOIAdj.tdInvoiceBalanceTC) + " ":U + tOIAdj.tcInvoiceBalanceCrDt)) + chr(10) +
trim(substitute(#T-261'New open balance: &1.':255(69555)T-261#,string(tOIAdj.tdNewBalanceTC) + " ":U + tOIAdj.tcNewBalanceCrDt)) + chr(10) +
trim(substitute(#T-260'Adjustment amount: &1':255(69554)T-260#,string(tOIAdj.tdAdjustmentAmountTC) + " ":U + tOIAdj.tcAdjustmentCrDt)).
<M-198 run SetMessage
(input vcMsgOIAdj (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8152':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
end. /* if (tOIAdj.tcAdjustmentCrDt = tOIAdj.tcInvoiceBalanceCrDt and */
/* ======================================================================================== */
/* - The CInvoiceHoldAmountTC can only be filled for real movements on Creditor-Invoices */
/* ======================================================================================== */
if tOIAdj.tdCInvoiceHoldAmountTC <> ? and
tOIAdj.tdCInvoiceHoldAmountTC <> 0 and
(tOIAdj.tlIsNewOpenItem = true or
tOIAdj.tcInvoiceOrigin <> {&INVOICEORIGIN-CREDITOR})
then do :
assign viLocalReturnStatus = -1
vcMsgOIAdj = trim(substitute(#T-246'You can only specify a hold amount (&1) for an adjustment to a supplier invoice.':255(63334)T-246#,string(tOIAdj.tdCInvoiceHoldAmountTC))) + chr(10) +
trim(substitute(#T-266'Invoice origin: &1.':255(2921)T-266#,tOIAdj.tcInvoiceOrigin)) + chr(10) +
trim(substitute(#T-267'New open item: &1.':255(69565)T-267#,(if tOIAdj.tlIsNewOpenItem = true then #T-268'Yes':20(69566)T-268# else #T-269'No':20(69567)T-269#))).
<M-194 run SetMessage
(input vcMsgOIAdj (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8150':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
end. /* if tOIAdj.tdCInvoiceHoldAmountTC <> ? and */
/* ======================================================================================== */
/* - NewBalanceCrDt has to be the same as InvoiceBalanceCrDt */
/* ======================================================================================== */
if tOIAdj.tcNewBalanceCrDt <> tOIAdj.tcInvoiceBalanceCrDt
then do :
assign viLocalReturnStatus = -1
vcMsgOIAdj = trim(substitute(#T-278'The Credit/Debit indication of the new-balance (&1) shoudl equal the Credit/Debit indication of the open-balance (&2)':255(71261)T-278#,string(tOIAdj.tdNewBalanceTC) + " ":U + tOIAdj.tcNewBalanceCrDt,string(tOIAdj.tdInvoiceBalanceTC) + " ":U + tOIAdj.tcInvoiceBalanceCrDt)) + chr(10) +
trim(substitute(#T-279'Invoice origin: &1.':255(2921)T-279#,tOIAdj.tcInvoiceOrigin)).
<M-277 run SetMessage
(input vcMsgOIAdj (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8667':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
end. /* if tOIAdj.tcNewBalanceCrDt <> tOIAdj.tcInvoiceBalanceCrDt */
/* ======================================================================================== */
/* - AdjustmentCrDt has to be the same as InvoiceBalanceCrDt in some cases */
/* - AdjustmentCrDt has to be the opposite from InvoiceBalanceCrDt in some cases */
/* ======================================================================================== */
if tOIAdj.tdInvoiceBalanceTC = 0 or
(tOIAdj.tdNewBalanceTC > 0 and
tOIAdj.tdNewBalanceTC > tOIAdj.tdInvoiceBalanceTC) or
(tOIAdj.tdNewBalanceTC < 0 and
tOIAdj.tdNewBalanceTC < tOIAdj.tdInvoiceBalanceTC)
then do :
if tOIAdj.tcInvoiceBalanceCrDt <> tOIAdj.tcAdjustmentCrDt and
(tOIAdj.tcInvoiceType <> {&INVOICETYPE-INVOICECORRECTION} and
tOIAdj.tcInvoiceType <> {&INVOICETYPE-CREDITNOTECORRECTION})
then do :
assign viLocalReturnStatus = -1
vcMsgOIAdj = trim(substitute(#T-292'The DR/CR indication of the adjustment (&1) must be the same as the DR/CR indication of the open-balance (&2) for this type of movement.':255(413974099)T-292#,string(tOIAdj.tdAdjustmentAmountTC) + " ":U + tOIAdj.tcAdjustmentCrDt,string(tOIAdj.tdInvoiceBalanceTC) + " ":U + tOIAdj.tcInvoiceBalanceCrDt)) + chr(10) +
trim(substitute(#T-293'Invoice origin: &1.':255(2921)T-293#,tOIAdj.tcInvoiceOrigin)).
<M-291 run SetMessage
(input vcMsgOIAdj (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8670':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
end. /* if tOIAdj.tcInvoiceBalanceCrDt <> tOIAdj.tcAdjustmentCrDt */
end. /* if tOIAdj.tdInvoiceBalanceTC = 0 or */
else if tOIAdj.tcInvoiceBalanceCrDt = tOIAdj.tcAdjustmentCrDt
then do :
assign viLocalReturnStatus = -1
vcMsgOIAdj = trim(substitute(#T-295'The DR/CR indication of the adjustment (&1) must be the opposite of the DR/CR indication of the open-balance (&2) for this type of movement.':255(591297086)T-295#,string(tOIAdj.tdAdjustmentAmountTC) + " ":U + tOIAdj.tcAdjustmentCrDt,string(tOIAdj.tdInvoiceBalanceTC) + " ":U + tOIAdj.tcInvoiceBalanceCrDt)) + chr(10) +
trim(substitute(#T-296'Invoice origin: &1.':255(2921)T-296#,tOIAdj.tcInvoiceOrigin)).
<M-294 run SetMessage
(input vcMsgOIAdj (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8671':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
end. /* if tOIAdj.tcInvoiceBalanceCrDt = tOIAdj.tcAdjustmentCrDt */
/* ======================================================================================== */
/* - NewBalanceTC has to have the same sign as InvoiceBalanceTC */
/* ======================================================================================== */
if (tOIAdj.tdNewBalanceTC < 0 and
tOIAdj.tdInvoiceBalanceTC > 0) or
(tOIAdj.tdNewBalanceTC > 0 and
tOIAdj.tdInvoiceBalanceTC < 0)
then do :
if tOIAdj.tdNewBalanceTC < 0
then assign vcMsgOIAdj = trim(substitute(#T-284'The new-balance (&1) cannot be negative as the open-balance (&2) was positive.':255(71262)T-284#,tOIAdj.tdNewBalanceTC,tOIAdj.tdInvoiceBalanceTC)).
else assign vcMsgOIAdj = trim(substitute(#T-286'The new-balance (&1) cannot be positive as the open-balance (&2) was negative.':255(71263)T-286#,tOIAdj.tdNewBalanceTC,tOIAdj.tdInvoiceBalanceTC)).
assign viLocalReturnStatus = -1.
vcMsgOIAdj = vcMsgOIAdj + chr(10) +
trim(substitute(#T-285'Invoice origin: &1.':255(2921)T-285#,tOIAdj.tcInvoiceOrigin)).
<M-283 run SetMessage
(input vcMsgOIAdj (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8668':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
end. /* if (tOIAdj.tdNewBalanceTC < 0 and */
/* ===================================================================================================== */
/* - AdjustmentAmountTC has to be postive - exception for InvoiceCorrections and CreditNoteCorrections */
/* ===================================================================================================== */
if (tOIAdj.tdNewBalanceTC > 0 and
(tOIAdj.tcInvoiceType = {&INVOICETYPE-INVOICECORRECTION} or
tOIAdj.tcInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION})) or
(tOIAdj.tdAdjustmentAmountTC < 0 and
tOIAdj.tcInvoiceType <> {&INVOICETYPE-INVOICECORRECTION} and
tOIAdj.tcInvoiceType <> {&INVOICETYPE-CREDITNOTECORRECTION})
then do :
assign viLocalReturnStatus = -1.
vcMsgOIAdj = trim(substitute(#T-288'The adjustment-amount (&1) can only be negative for movements on corrections.':255(71286)T-288#,tOIAdj.tdAdjustmentAmountTC)) + chr(10) +
trim(substitute(#T-290'Invoice origin: &1.':255(2921)T-290#,tOIAdj.tcInvoiceOrigin)).
<M-287 run SetMessage
(input vcMsgOIAdj (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8669':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
end. /* if (tOIAdj.tdAdjustmentAmountTC > 0 and */
/* =============================================================================== */
/* - AdjustmentDiscountAmountTC has to have the same sign as AdjustmentAmountTC */
/* =============================================================================== */
if (tOIAdj.tdAdjustmentAmountTC > 0 and
tOIAdj.tdAdjustmentDiscountAmountTC < 0) or
(tOIAdj.tdAdjustmentAmountTC < 0 and
tOIAdj.tdAdjustmentDiscountAmountTC > 0)
then do :
assign viLocalReturnStatus = -1.
vcMsgOIAdj = trim(substitute(#T-298'The adjustment-discount (&1) should have the same sign (positive / negative) as the adjustment-amount (&2).':255(71291)T-298#,tOIAdj.tdAdjustmentDiscountAmountTC,tOIAdj.tdAdjustmentAmountTC)) + chr(10) +
trim(substitute(#T-299'Invoice origin: &1.':255(2921)T-299#,tOIAdj.tcInvoiceOrigin)).
<M-297 run SetMessage
(input vcMsgOIAdj (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8672':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
end. /* if (tOIAdj.tdAdjustmentAmountTC > 0 and */
end. /* for each */
/* ====================================================== */
/* Stop in case error occured in the previous code-blocks */
/* ====================================================== */
if viLocalReturnStatus < 0
then Leave VALIDATIONTWOBLOCK.
END. /* VALIDATIONTWOBLOCK */
/* =================== */
/* Exception handling */
/* =================== */
assign oiReturnStatus = viLocalReturnStatus.