project QadFinancials > class BCInvoice > method AdditionalUpdatesAllAllocations
Description
This submethod of AdditionalUpdatesAll holds all program-code regarding the actions for the allocations
Parameters
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program8/bcinvoice.p)
/* ========================= */
/* Set default return status */
/* ========================= */
assign oiReturnStatus = -98.
/* ======================================================================================= */
/* General note: BJournalEntry is already started and opened by the caller-method */
/* ======================================================================================= */
if can-find (first tCInvoiceMovement where
tCInvoiceMovement.tc_Status <> "":U) and
(viBJournalEntryCIID = 0 or
viBJournalEntryCIID = ? or
valid-handle(vhBJournalEntryCIInst) <> true)
then do :
assign vcMessage = trim(#T-17'Internal error: unexpected situation-no communication to the postings available':255(17891)t-17#) + chr(10) +
trim(substitute(#T-18'Instance ID = &1.':255(17892)T-18#,string(viBJournalEntryCIID))) + chr(10) +
trim(substitute(#T-19'Valid handle = &1.':255(17893)T-19#,string(valid-handle(vhBJournalEntryCIInst) = TRUE))) + chr(10) +
trim(substitute(#T-20'Handle value = &1.':255(17894)T-20#,string(vhBJournalEntryCIInst)))
oiReturnStatus = -3.
<M-16 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-4478':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
end. /* if */
assign vlStart1 = false.
/* ======================================================================================= */
/* Go through all un-deleted Invoices, CreditNotes and the corrections on it */
/* Check on status <> "D" otherwise, when you change mf posting from transient to official */
/* the status of the cinvoice is not changed */
/* ======================================================================================= */
for each tCInvoice where
tCInvoice.tc_Status <> "D":U and
tCInvoice.CInvoiceIsLogisticMatching = false and
(tCInvoice.CInvoiceType = {&INVOICETYPE-INVOICE} or
tCInvoice.CInvoiceType = {&INVOICETYPE-CREDITNOTE} or
tCInvoice.CInvoiceType = {&INVOICETYPE-INVOICECORRECTION} or
tCInvoice.CInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION}):
/* =========================================== */
/* Reset data-items to hold CI-Allocation info */
/* =========================================== */
assign vcCIAlloctaionLayerTypeCode = "":U
viCIAlloctaionPostingID = 0.
/* ================================================================================ */
/* Skip validation when you come from opening balance, because you have no mf there */
/* ================================================================================ */
if not can-find(first tCInvoicePosting where
tCInvoicePosting.tc_ParentRowId = tCInvoice.tc_RowId and
tCInvoicePosting.CInvoicePostingType = {&INVOICEPOSTINGTYPE-INITIAL})
then next.
/* =============================================================== */
/* Get the Posting-info (either from the instance, either from db) */
/* =============================================================== */
find first tCInvoicePosting where
tCInvoicePosting.tc_ParentRowId = tCInvoice.tc_RowId and
tCInvoicePosting.CInvoicePostingType = {&INVOICEPOSTINGTYPE-ALLOCATION}
no-error.
if not available tCinvoicePosting
then do:
if not vlStartCIPostingByCIId
then do:
<Q-24 run CInvoicePostingByCInvoiceId (Start) in BCInvoice >
assign vlStartCIPostingByCIId = true.
end.
<Q-1 run CInvoicePostingByCInvoiceId (all) (Read) (NoCache)
(input tCInvoice.CInvoice_ID, (CInvoiceId)
input {&INVOICEPOSTINGTYPE-ALLOCATION}, (PostingType)
output dataset tqCInvoicePostingByCInvoiceId) in BCInvoice >
find first tqCInvoicePostingByCInvoiceId where
tqCInvoicePostingByCInvoiceId.tiCInvoice_ID = tCInvoice.CInvoice_ID and
tqCInvoicePostingByCInvoiceId.tcCInvoicePostingType = {&INVOICEPOSTINGTYPE-ALLOCATION}
no-error.
if available tqCInvoicePostingByCInvoiceId
then assign viCIAlloctaionPostingID = tqCInvoicePostingByCInvoiceId.tiPosting_ID.
end. /* if not available tCinvoicePosting */
else assign viCIAlloctaionPostingID = tCInvoicePosting.Posting_ID.
/* =============================================================== */
/* Get the Layer-Type (either from the instance, either from db) */
/* =============================================================== */
if viCIAlloctaionPostingID <> 0
then do:
/* search in posting instance if there is any */
if available tCInvoicePosting and
viBJournalEntryCIID <> 0 and
viBJournalEntryCIID <> ? and
valid-handle(vhBJournalEntryCIInst) = true
then do :
<M-4 run GetPostingLayerTypeCode (input viCIAlloctaionPostingID (iiPostingId),
output vcCIAlloctaionLayerTypeCode (ocPostingLayerTypeCode),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
end. /* available tCInvoicePosting */
/* search in the db when the previous search failed */
if vcCIAlloctaionLayerTypeCode = "":U
then do:
/* search in db */
if not vlStart1
then do:
<Q-22 run PostingByPostingId (Start) in BPosting >
assign vlStart1 = true.
end.
<Q-21 run PostingByPostingId (all) (Read) (NoCache)
(input ?, (CompanyId)
input viCIAlloctaionPostingID, (PostingId)
input ?, (JournalTypeCode)
output dataset tqPostingByPostingId) in BPosting >
find first tqPostingByPostingId no-error.
assign vcCIAlloctaionLayerTypeCode = if available tqPostingByPostingId
then tqPostingByPostingId.tcLayerTypeCode
else "":U.
end. /* if */
end. /* if available tCInvoicePosting and */
/* ========================================================= */
/* If no posting line record found, so mf is already deleted */
/* ========================================================= */
if vcCIAlloctaionLayerTypeCode = "":U and
available tCInvoicePosting
then delete tCInvoicePosting.
/* ======================================== */
/* Fill allocation status of invoice */
/* If official then allocated */
/* if transient then transient allocation */
/* ======================================== */
assign tCInvoice.CInvoiceAllocationStatus = if vcCIAlloctaionLayerTypeCode = {&LAYERTYPECODE-OFFICIAL}
then {&ALLOCSTATUS-ALLOC}
else if vcCIAlloctaionLayerTypeCode = {&LAYERTYPECODE-TRANSIENT}
then {&ALLOCSTATUS-TRANSALLOC}
else if vcCIAlloctaionLayerTypeCode = "":U
then {&ALLOCSTATUS-NOALLOC}
else "":U
vlError = false.
case tCInvoice.tcReasonAllocationStatus :
when {&ALLOCSTATUS-ALLOC}
then assign vlError = if tCInvoice.CInvoiceAllocationStatus = {&ALLOCSTATUS-NOALLOC} or
tCInvoice.CInvoiceAllocationStatus = "":U
then true
else false.
when {&ALLOCSTATUS-TRANSALLOC}
then assign vlError = if tCInvoice.CInvoiceAllocationStatus = {&ALLOCSTATUS-ALLOC} or
tCInvoice.CInvoiceAllocationStatus = {&ALLOCSTATUS-NOALLOC} or
tCInvoice.CInvoiceAllocationStatus = "":U
then true
else false.
when {&ALLOCSTATUS-NOALLOC}
then assign vlError = if tCInvoice.CInvoiceAllocationStatus = {&ALLOCSTATUS-ALLOC} or
tCInvoice.CInvoiceAllocationStatus = {&ALLOCSTATUS-TRANSALLOC} or
tCInvoice.CInvoiceAllocationStatus = "":U
then true
else false.
end case.
if vlError
then do:
assign vcVoucher = (if vlCIDomainIsConsecutNr = false
then string(tCInvoice.CInvoiceVoucher)
else trim(#T-68'unassigned.':255(278916182)T-68#))
vcMessage = trim(substitute(#T-9'The allocation status (&1) of invoice status code (&2) does not correspond with allocation status on the invoice itself (&3).':255(57148)T-9#, tCInvoice.tcReasonAllocationStatus, tCInvoice.tcReasonCode, tCInvoice.CInvoiceAllocationStatus)) + chr(10) +
trim(substitute(#T-10'Invoice details; GL Calendar Year = &1; GL period = &2; Daybook = &3; Voucher = &4.':255(57147)T-10#,string(tCInvoice.CInvoicePostingYear),string(tCInvoice.CInvoicePostingPeriod), tCInvoice.tcJournalCode, vcVoucher))
oiReturnStatus = -1.
<M-7 run SetMessage (input vcMessage (icMessage),
input '':U (icArguments),
input 'tCInvoice.tcReasonCode':U (icFieldName),
input tCInvoice.tcReasonCode (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input tCInvoice.tc_Rowid (icRowid),
input 'QADFIN-4475':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
end. /* if vlError */
/* =========================================================== */
/* Changing reason code allowed for no allocation */
/* If allocated, you cannot change it */
/* If transient allocated, you can only change it to allocated */
/* =========================================================== */
if tCInvoice.tc_Status = "C":U and
tCInvoice.CInvoiceAllocationStatus <> {&ALLOCSTATUS-NOALLOC}
then do:
find first t_iCInvoice where
t_iCInvoice.tc_Rowid = tCInvoice.tc_Rowid
no-error.
if available t_iCInvoice
then do:
if t_iCInvoice.CInvoiceAllocationStatus <> tCInvoice.CInvoiceAllocationStatus
then do:
if t_iCInvoice.CInvoiceAllocationStatus = {&ALLOCSTATUS-TRANSALLOC} and
tCInvoice.CInvoiceAllocationStatus = {&ALLOCSTATUS-NOALLOC}
then assign vlError = true.
else if t_iCInvoice.CInvoiceAllocationStatus = {&ALLOCSTATUS-ALLOC}
then assign vlError = true.
else assign vlError = false.
end. /* if t_iCInvoice.CInvoiceAllocationStatus <> tCInvoice.CInvoiceAllocationStatus */
if vlError
then do:
assign vcVoucher = (if vlCIDomainIsConsecutNr = false
then string(tCInvoice.CInvoiceVoucher)
else trim(#T-56'unassigned.':255(278916182)T-56#))
vcMessage = trim(substitute(#T-11'You cannot change an invoice status code with allocation status &1 to an invoice status code with allocation status &2.':150(1049)T-11#, t_iCInvoice.CInvoiceAllocationStatus, tCInvoice.CInvoiceAllocationStatus)) + chr(10) +
trim(substitute(#T-12'GL Calendar Year = &1; GL Period = &2; Daybook = &3; Voucher = &4.':255(969)T-12#,string(tCInvoice.CInvoicePostingYear),string(tCInvoice.CInvoicePostingPeriod), tCInvoice.tcJournalCode, vcVoucher))
oiReturnStatus = -1.
<M-8 run SetMessage (input vcMessage (icMessage),
input '':U (icArguments),
input 'tCInvoice.CInvoiceTSMNumber':U (icFieldName),
input tCInvoice.CInvoiceTSMNumber (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input tCInvoice.tc_Rowid (icRowid),
input 'QADFIN-4476':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
end. /* if vlError */
end. /* if available t_iCInvoice */
end. /* if tCInvoice.tc_Status = "C":U and */
end. /* for each tCInvoice where */
if vlStart1
then do:
<Q-23 run PostingByPostingId (Stop) in BPosting >
end.
if vlStartCIPostingByCIId
then do:
<Q-25 run CInvoicePostingByCInvoiceId (Stop) in BCInvoice >
end.
/* ========================= */
/* Set default return status */
/* ========================= */
if oiReturnStatus = -98
then assign oiReturnStatus = 0.