Description
StdMaintainTT; Method that allows the creation of new instances based on the content of the input temp-tables WITHOUT ValidateBC, AddUpd and DataSave
Parameters
Internal usage
QadFinancials
program code (program7/bdinvoice.p)
/* ============================================================================ */
/* Clear the instance: */
/* this will also clear the t_s tables that were filled in ApiMaintainByDataSet */
/* ============================================================================ */
<M-110 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
/* ==================== */
/* Set Default Return */
/* Parameter Validation */
/* ==================== */
assign oiReturnStatus = -98
vlDraftInstanceCreated = false.
if icAction = ? then assign icAction = "":U.
if icAction <> {&DAEMONACTION-SAVESTORE} and
icAction <> {&DAEMONACTION-SAVE} and
icAction <> {&DAEMONACTION-STORE} and
icAction <> {&DAEMONACTION-VALIDATE}
then do:
assign vcMessage = trim(subst(#T-143'A customer invoice integration error occurred. The specified action (&1) is not in the list: &2.':255(49394)t-143#, icAction, "{&DAEMONACTION-SAVESTORE},{&DAEMONACTION-SAVE},{&DAEMONACTION-STORE},{&DAEMONACTION-VALIDATE}":U))
oiReturnStatus = -1.
<M-115 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-7162':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
return.
end. /* if icAction <> {&DAEMONACTION-SAVESTORE} and */
/* ============================================================== */
/* Call method that can extend the tApi-tables with some defaults */
/* ============================================================== */
<M-6 run ApiStdMaintainTTInitialDefaulting (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
/* ======================== */
/* Count main-table records */
/* ======================== */
for each tApiDInvoice:
assign viMainTableRecordCount = viMainTableRecordCount + 1.
end. /* for each tApiDInvoice */
if viMainTableRecordCount = 0
then do:
assign vcMessage = trim(#T-144'A customer invoice integration error occurred. No input record was found. You must define for which records customer invoices must be created.':255(49398)t-144#)
oiReturnStatus = -1.
<M-116 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-7163':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
return.
end. /* if viMainTableRecordCount = 0 */
/* ================================================================================ */
/* Start and open journal entry (in case the caller already set viBJournalEntryCIID */
/* before calling this method, then this will result in just an Open of BJE) */
/* ================================================================================ */
if viBJournalEntryDIID = 0 or viBJournalEntryDIID = ?
then do:
<I-120 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "true"
&CLASS = "BJournalEntry"}>
assign vlBJEIsStartedFromDI = true.
end. /* if viBJournalEntryDIID = 0 or viBJournalEntryDIID = ? */
else do:
<I-112 {bFcOpenInstance
&CLASS = "BJournalEntry"}>
end. /* Not if viBJournalEntryDIID = 0 or viBJournalEntryDIID = ? */
/* ====================================================== */
/* Go through all main-table records */
/* ====================================================== */
for each tApiDInvoice by tApiDInvoice.tc_Rowid :
MAINAPIDINVOICEBLOCK : DO :
/* ========== */
/* Initialize */
/* ========== */
if tApiDInvoice.Debtor_ID = ? then assign tApiDInvoice.Debtor_ID = 0.
if tApiDInvoice.tcDebtorCode = ? then assign tApiDInvoice.tcDebtorCode = "":U.
if tApiDInvoice.DInvoiceType = ? then assign tApiDInvoice.DInvoiceType = "":U.
assign vcMessage = "":U
vcDInvoiceRowId = "":U
vlWarningsFound = false
vlSaveAsDraft = (icAction = {&DAEMONACTION-STORE}).
/* ====================================================== */
/* Delete balance fields, they will be recalculated again */
/* ====================================================== */
assign tApiDInvoice.DInvoiceBalanceDebitTC = 0
tApiDInvoice.DInvoiceBalanceCreditTC = 0
tApiDInvoice.DInvoiceBalanceDebitLC = 0
tApiDInvoice.DInvoiceBalanceCreditLC = 0
tApiDInvoice.DInvoiceBalanceDebitCC = 0
tApiDInvoice.DInvoiceBalanceCreditCC = 0
tApiDInvoice.DInvoiceBalanceTC = 0
tApiDInvoice.DInvoiceBalanceLC = 0
tApiDInvoice.DInvoiceBalanceCC = 0.
/* ================================================= */
/* Check on the link-record between CInvoice-Posting */
/* ================================================= */
find first tApiDInvoicePosting where
tApiDInvoicePosting.tc_ParentRowid = tApiDInvoice.tc_Rowid and
tApiDInvoicePosting.Posting_ID <> 0 and
tApiDInvoicePosting.Posting_ID <> ?
no-error.
if available tApiDInvoicePosting
then do:
/* ======================================================================================== */
/* Amount of invoice must be the same as the sum of the amounts of the posting lines for LC */
/* not for TC because the currency can change for every line of it */
/* ======================================================================================== */
<M-123 run GetPostingHeaderByPostingId (input tApiDInvoicePosting.Posting_ID (iiPostingId),
input ? (icPostingRowID),
output viPostingYear (oiPostingYear),
output viPostingPeriod (oiPostingPeriod),
output vtPostingDate (otPostingDate),
output vcPostingJournalCode (ocPostingJournalCode),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0
then do:
assign ocLstReturn = ocLstReturn + chr(4) + string(viFcReturnSuper)
ocLstPrimKey = ocLstPrimKey + chr(4) + "*":U
ocLstRowid = ocLstRowid + chr(4) + "*":U
vlSaveAsDraft = false.
leave MAINAPIDINVOICEBLOCK.
end. /* if viFcReturnSuper <> 0 */
else if viFcReturnSuper > 0
then assign vlWarningsFound = true.
if tApiDInvoice.DInvoicePostingDate <> vtPostingDate
then do:
assign vcMessage = trim(substitute(#T-140'The posting date of the posting (&1) does not match the posting date of the invoice (&2).':255(13734)T-140#, string(vtPostingDate), string(tApiDInvoice.DInvoicePostingDate))) + chr(10) +
trim(substitute(#T-145'GL Calendar Year = &1; GL Period = &2; Daybook = &3; Voucher = &4.':255(969)T-145#,string(tAPIDInvoice.DInvoicePostingYear),string(tAPIDInvoice.DInvoicePostingPeriod), tAPIDInvoice.tcJournalCode, string(tAPIDInvoice.DInvoiceVoucher)))
ocLstReturn = ocLstReturn + chr(4) + string(-1)
ocLstPrimKey = ocLstPrimKey + chr(4) + "*":U
ocLstRowid = ocLstRowid + chr(4) + "*":U
vlSaveAsDraft = false.
<M-129 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-7170':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
leave MAINAPIDINVOICEBLOCK.
end. /* if tApiDInvoice.DInvoicePostingDate <> vtPostingDate */
if tApiDInvoice.tcJournalCode <> vcPostingJournalCode
then do:
assign vcMessage = trim(substitute(#T-149'The daybook of the posting (&1) does not match daybook of the invoice (&2).':250(13736)t-149#, vcPostingJournalCode, tApiDInvoice.tcJournalCode)) + chr(10) +
trim(substitute(#T-146'GL Calendar Year = &1; GL Period = &2; Daybook = &3; Voucher = &4.':255(969)T-146#,string(tAPIDInvoice.DInvoicePostingYear),string(tAPIDInvoice.DInvoicePostingPeriod), tAPIDInvoice.tcJournalCode, string(tAPIDInvoice.DInvoiceVoucher)))
ocLstReturn = ocLstReturn + chr(4) + string(-1)
ocLstPrimKey = ocLstPrimKey + chr(4) + "*":U
ocLstRowid = ocLstRowid + chr(4) + "*":U
vlSaveAsDraft = false.
<M-111 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-7161':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
leave MAINAPIDINVOICEBLOCK.
end. /* if tApiDInvoice.tcJournalCode <> vcPostingJournalCode */
/* ======================================================== */
/* Check year/period of invoice with year/period of posting */
/* Check single DI-posting for a DI */
/* ======================================================== */
if tApiDInvoice.DInvoicePostingYear <> viPostingYear or
tApiDInvoice.DInvoicePostingPeriod <> viPostingPeriod
then do:
assign vcMessage = trim(substitute(#T-130'The year and GL period of the customer invoice do not match the year (&1) and GL period (&2) of the posting.':255(13738)T-130#, string(viPostingYear), string(viPostingPeriod))) + chr(10) +
trim(substitute(#T-147'GL Calendar Year = &1; GL Period = &2; Daybook = &3; Voucher = &4.':255(969)T-147#,string(tAPIDInvoice.DInvoicePostingYear),string(tAPIDInvoice.DInvoicePostingPeriod), tAPIDInvoice.tcJournalCode, string(tAPIDInvoice.DInvoiceVoucher)))
ocLstReturn = ocLstReturn + chr(4) + string(-1)
ocLstPrimKey = ocLstPrimKey + chr(4) + "*":U
ocLstRowid = ocLstRowid + chr(4) + "*":U
vlSaveAsDraft = false.
<M-121 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-7166':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
Leave MAINAPIDINVOICEBLOCK.
end. /* if tApiDInvoice.DInvoicePostingYear <> viPostingYear or */
find next tApiDInvoicePosting where
tApiDInvoicePosting.tc_ParentRowid = tApiDInvoice.tc_Rowid and
tApiDInvoicePosting.Posting_ID <> 0 and
tApiDInvoicePosting.Posting_ID <> ?
no-error.
if available tApiDInvoicePosting
then do:
assign vcMessage = trim(#T-131'A customer invoice integration error occurred. More than one posting record found for this customer invoice':255(49397)t-131#) + chr(10) +
trim(substitute(#T-148'GL Calendar Year = &1; GL Period = &2; Daybook = &3; Voucher = &4.':255(969)T-148#,string(tAPIDInvoice.DInvoicePostingYear),string(tAPIDInvoice.DInvoicePostingPeriod), tAPIDInvoice.tcJournalCode, string(tAPIDInvoice.DInvoiceVoucher)))
ocLstReturn = ocLstReturn + chr(4) + string(-1)
ocLstPrimKey = ocLstPrimKey + chr(4) + "*":U
ocLstRowid = ocLstRowid + chr(4) + "*":U
vlSaveAsDraft = false.
<M-122 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-7167':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
Leave MAINAPIDINVOICEBLOCK.
end. /* if available tApiDInvoicePosting */
end. /* if available tApiDInvoicePosting after first find */
/* ======================================== */
/* Calculate the lc, cc and balance amounts */
/* ======================================== */
<M-152 run StdMaintainTTCalcAmounts (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0
then do:
assign ocLstReturn = ocLstReturn + chr(4) + string(viFcReturnSuper)
ocLstPrimKey = ocLstPrimKey + chr(4) + "*":U
ocLstRowid = ocLstRowid + chr(4) + "*":U
vlSaveAsDraft = false.
leave MAINAPIDINVOICEBLOCK.
end. /* if viFcReturnSuper <> 0 */
else if viFcReturnSuper > 0
then assign vlWarningsFound = true.
/* ========================================================================================================================= */
/* Call a submethod depending on the fact whether the required postings for the CI are created outside this component or not */
/* ========================================================================================================================= */
if not can-find(first tApiDInvoicePosting where
tApiDInvoicePosting.tc_ParentRowid = tApiDInvoice.tc_Rowid and
tApiDInvoicePosting.Posting_ID <> 0 and
tApiDInvoicePosting.Posting_ID <> ?)
then do:
<M-150 run StdMaintainTTWithIntPost
(input icAction (icAction),
input-output ocLstPrimKey (bcLstPrimKey),
input-output ocLstRowid (bcLstRowId),
input-output ocLstReturn (bcLstReturn),
output vlSaveAsDraft (olSaveAsDraft),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0
then leave MAINAPIDINVOICEBLOCK.
else if viFcReturnSuper > 0
then assign vlWarningsFound = true.
end. /* if not can-find */
else do:
<M-151 run StdMaintainTTWithExtPost
(input icAction (icAction),
input-output ocLstReturn (bcLstReturn),
input-output ocLstPrimKey (bcLstPrimKey),
input-output ocLstRowid (bcLstRowId),
output vlSaveAsDraft (olSaveAsDraft),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0
then leave MAINAPIDINVOICEBLOCK.
else if viFcReturnSuper > 0
then assign vlWarningsFound = true.
end. /* Not if not can-find */
END. /* MAINAPIDINVOICEBLOCK */
/* ================================================================== */
/* Handle errors: Store if SaveAsDraft is needed */
/* Check: only 1 draft is allowed for a single bus-component instance */
/* ================================================================== */
if vlSaveAsDraft and
index(substr(ocLstReturn, r-index(ocLstReturn, chr(4)) + 1,-1,"CHARACTER":U),"-":U) <> 0 /* Negative return-status for this entry */
then do:
if vlDraftInstanceCreated = true
then do :
assign vcMessage = trim(#T-141'Only one draft instance can be created per method call.':255(858)T-141#) + chr(10) + trim(#T-142'This second object will not be stored as a draft instance and so is an error.':255(859)t-142#).
<M-128 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-7169':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
next.
end. /* if vlDraftInstanceCreated = true */
<M-127 run StoreState (input '(':U + tDInvoice.DInvoiceDescription + ') ':U + trim(#T-139'The customer invoice created using an API method.':200(49399)t-139#) (icDescription),
input ? (icUIClass),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
assign vlDraftInstanceCreated = true
entry(num-entries(ocLstReturn , chr(4)), ocLstReturn , chr(4)) = string(viFcReturnSuper)
entry(num-entries(ocLstPrimKey, chr(4)), ocLstPrimKey, chr(4)) = string(tApiDInvoice.DInvoice_ID)
entry(num-entries(ocLstRowid , chr(4)), ocLstRowid , chr(4)) = vcDInvoiceRowId.
end. /* if vlSaveAsDraft and substr */
/*=======================*/
/* LBO - Gunters request */
/*=======================*/
if tApiDInvoice.tiDAVoucher = 0 or
tApiDInvoice.tiDAVoucher = ?
then do:
<M-113 run DefaultValuesDAVoucher (input tApiDInvoice.tcDAJournalCode (icNewDAJournalCode),
input '':U (icOldDAJournalCode),
input tApiDInvoice.DInvoicePostingYear (iiNewPeriodYear),
input 0 (iiOldPeriodYear),
input 0 (iiOldDAVoucher),
output viDAVoucher (oiNewDAVoucher),
input tApiDInvoice.tc_Rowid (icRowId),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
assign tApiDInvoice.tiDAVoucher = viDAVoucher.
end.
end. /* for each tApiDInvoice by tApiDInvoice.tc_Rowid */
/* =================== */
/* Close Journal Entry */
/* =================== */
if vhBJournalEntryDIInst <> ? and /* Can be closed by a subprocedure */
valid-handle(vhBJournalEntryDIInst) = true
then. /* ========================================================================================================= */
/* Normally we would here close BJournalEntry we will not do it for performance */
/* reasons as this way the Commit of the transaction does not have to re-open the instance to commit it. */
/* And in all other scenario's the instance of the class ill be closed by the de-activiate procedure of the */
/* appserver that is executed after each call to the appserver */
/* ========================================================================================================= */
/* ============================================================ */
/* Trim the first character of ocLstReturn and primkey */
/* Check for correct number and format of the return-parameters */
/* ============================================================ */
if length(ocLstReturn,"CHARACTER":U) > 1 then assign ocLstReturn = substring(ocLstReturn,2,-1,"CHARACTER":U).
if length(ocLstPrimKey,"CHARACTER":U) > 1 then assign ocLstPrimKey = substring(ocLstPrimKey,2,-1,"CHARACTER":U).
if length(ocLstRowid,"CHARACTER":U) > 1 then assign ocLstRowid = substring(ocLstRowid,2,-1,"CHARACTER":U).
if num-entries(ocLstReturn,chr(4)) <> viMainTableRecordCount or
num-entries(ocLstPrimKey,chr(4)) <> viMainTableRecordCount or
num-entries(ocLstRowid,chr(4)) <> viMainTableRecordCount
then do :
assign vcMessage = trim(#T-135'A customer invoice/journal entry integration error ocurred. An API method retruned incomplete information. See other messages for further details.':255(49400)t-135#) + chr(10) +
trim(substitute(#T-136'Main table records: &1.':255(310)T-136#,string(viMainTableRecordCount))) + chr(10) +
trim(substitute(#T-137'Return Statuses: &1.':255(311)T-137#,ocLstReturn)) + chr(10) +
trim(substitute(#T-138'Primary keys: &1.':255(312)T-138#,ocLstPrimKey)) + chr(10) +
trim(substitute(#T-132'Row IDs: &1.':255(313)T-132#,ocLstRowid)).
oiReturnStatus = -3.
<M-118 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-7164':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
assign oiReturnStatus = -3.
return.
end. /* if num-entries(ocLstReturn,chr(4)) <> viMainTableRecordCount or */
/* ===================================================== */
/* Set global return status based on the individual ones */
/* ===================================================== */
if ocLstReturn = substring(fill("0":U + CHR(4),viMainTableRecordCount),1,length(ocLstReturn,"CHARACTER":U),"CHARACTER":U)
then assign oiReturnStatus = 0.
else do :
if index(ocLstReturn,"-":U) <> 0
then do :
assign vcMessage = trim(#T-133'An error has occurred while running this API method. See other error messages for more details.':255(301)T-133#)
oiReturnStatus = -1.
<M-119 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-7165':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end. /* index(ocLstReturn,"-":U) <> 0 */
else do :
assign vcMessage = trim(#T-134'A warning occurred when running the API method. See other error messages for more details.':255(14390)t-134#)
oiReturnStatus = +1.
<M-124 run SetMessage (input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'W':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-7168':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end. /* not if lookup */
end. /* not if ocLstReturn */