tApiPosting | input | temp-table | Input table containing the postings |
tApiPostingLine | input | temp-table | Input table containing the posting-lines |
tApiPostingSaf | input | temp-table | Input table containing the posting-safs of a posting-line |
tApiPostingVat | input | temp-table | Input table containing the PostingVat |
tApiPostingVatDelay | input | temp-table | Input table containing the PostingVatDelay |
icAction | input | character | SAVE SAVESTORE STORE VALIDATE |
ocLstPrimKey | output | character | LstPrimKey Char4 separated list with the primary keys of the newly created main-table records. The fields of a primkey are separated with Char2. E.g. 1<Char2>2002<Char2>100<Char4>1<Char2>2002<Char2>101 |
ocLstReturn | output | character | LstReturn Char4 separated list with the return-status of the newly created main-table records. Zero means no errors occured. E.g. 0<Char4>-1<Char4>-504<Char4>1<Char4>0 |
ocLstRowid | output | character | LstRowid Char4 separated list with the temporarely rowids (negative for new ones) of the newly created main-table records. . E.g. -1<Char2>aox00098001<Char2>-26 |
oiReturnStatus | output | integer | Return status of the method. |
/* ============================================================================ */ /* Clear the instance: */ /* this will also clear the t_s tables that were filled in ApiMaintainByDataSet */ /* ============================================================================ */ <M-56 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BPosting> 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 vcMsgApi = trim(subst(#T-87'Posting integration: the specified action (&1) should be in the list &2.':255(118339802)T-87#,trim(icAction),"{&DAEMONACTION-SAVESTORE},{&DAEMONACTION-SAVE},{&DAEMONACTION-STORE},{&DAEMONACTION-VALIDATE}":U)) oiReturnStatus = -1. <M-64 run SetMessage (input vcMsgApi (icMessage), input '':U (icArguments), input '':U (icFieldName), input '':U (icFieldValue), input 'E':U (icType), input 1 (iiSeverity), input '':U (icRowid), input 'QadFin-7158':U (icFcMsgNumber), input '' (icFcExplanation), input '' (icFcIdentification), input '' (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BPosting> return. end. /* if icAction */ /* ======================== */ /* Count main-table records */ /* ======================== */ for each tApiPosting no-lock : assign viMainTableRecordCount = viMainTableRecordCount + 1. end. /* for each */ if viMainTableRecordCount = 0 then do: assign vcMsgApi = trim(#T-88'Posting integration: no main table records (posting) found.':255(825519009)T-88#) oiReturnStatus = -1. <M-70 run SetMessage (input vcMsgApi (icMessage), input '':U (icArguments), input '':U (icFieldName), input '':U (icFieldValue), input 'E':U (icType), input 1 (iiSeverity), input '':U (icRowid), input 'QadFin-7159':U (icFcMsgNumber), input '' (icFcExplanation), input '' (icFcIdentification), input '' (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BPosting> return. end. /* if viMainTableRecordCount */ /* ============= */ /* Start Queries */ /* ============= */ <Q-73 run VatRuleByVatIDCode (Start) in BVAT > /* ================================ */ /* Start loop on main-table records */ /* ================================ */ for each tApiPosting : /* =========== */ /* Start Block */ /* =========== */ MAINPOSTINGPROCESSINGBLOCK: DO : /* ================================== */ /* Initialise and Create new instance */ /* ================================== */ assign vcMsgApi = "":U vcRowID = "":U vlWarningsFound = false vlSaveAsDraft = (icAction = {&DAEMONACTION-STORE}). /* ========================================================================== */ /* Clear tApiSafFromPosting & Stop a possibly-still existing instance of BSaf */ /* ========================================================================== */ empty temp-table tApiSafFromPosting. if viBSafPostingID <> 0 and viBSafPostingID = ? then do: <I-75 {bFcStopInstance &CLASS = "BSaf"}> end. /* if viBSafPostingID <> 0 and */ /* ==================================================================== */ /* Company_id should belong to current domain, if company is not passed */ /* current company is defaulted */ /* ==================================================================== */ if tApiPosting.Company_ID = ? or tApiPosting.Company_ID = 0 then assign tApiPosting.Company_ID = viCompanyId. else do: <Q-61 assign vlFcQueryRecordsAvailable = CompanyByDomain (NoCache) (input tApiPosting.Company_ID, (CompanyId) input viDomainID, (DomainId) input true, (Active)) in BCompany > if not (vlFcQueryRecordsAvailable = true) then do: assign vcMsgApi = trim(substitute(#T-92'Company ID (&1) does not match the current domain.)':200(915904178)T-92#, trim(string(tApiPosting.Company_ID)) )) ocLstReturn = ocLstReturn + chr(4) + (if viFcReturnSuper = 0 then "-3":U else string(viFcReturnSuper)) ocLstPrimKey = ocLstPrimKey + chr(4) + "*":U ocLstRowid = ocLstRowid + chr(4) + "*":U vlSaveAsDraft = false. <M-62 run SetMessage (input vcMsgApi (icMessage), input '':U (icArguments), input '':U (icFieldName), input '':U (icFieldValue), input 'E':U (icType), input 3 (iiSeverity), input '':U (icRowid), input 'QadFin-7156':U (icFcMsgNumber), input '' (icFcExplanation), input '' (icFcIdentification), input '' (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BPosting> leave MAINPOSTINGPROCESSINGBLOCK. end. end. /* if tApiPosting.Company_ID <> ? and */ /* ============================================ */ /* Create Posting (modification is not allowed) */ /* ============================================ */ <M-71 run DataNew (output viFcReturnSuper (oiReturnStatus)) in BPosting> if viFcReturnSuper >= 0 then do: <M-96 run SetRowidConvert (input tApiPosting.tc_Rowid (icOldRowid), input tPosting.tc_Rowid (icNewRowid), output viFcReturnSuper (oiReturnStatus)) in BPosting> end. if viFcReturnSuper < 0 then assign vcMsgApi = trim(substitute(#T-91'Internal error on the posting integration: unable to create a new instance. Error number: &1.':255(52826970)T-91#,string(viFcReturnSuper))). /* ====================================== */ /* Check for errors in the previous block */ /* ====================================== */ if vcMsgApi <> "":U then do: assign ocLstReturn = ocLstReturn + chr(4) + (if viFcReturnSuper = 0 then "-3":U else string(viFcReturnSuper)) ocLstPrimKey = ocLstPrimKey + chr(4) + "*":U ocLstRowid = ocLstRowid + chr(4) + "*":U vlSaveAsDraft = false. <M-60 run SetMessage (input vcMsgApi (icMessage), input '':U (icArguments), input '':U (icFieldName), input '':U (icFieldValue), input 'E':U (icType), input 3 (iiSeverity), input '':U (icRowid), input 'QadFin-7155':U (icFcMsgNumber), input '' (icFcExplanation), input '' (icFcIdentification), input '' (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BPosting> leave MAINPOSTINGPROCESSINGBLOCK. end. /* if vcMsgApi <> "":U */ /* =========================================================================================== */ /* Copy all data into the new posting */ /* Before continuing, we copy the primary-key-fields of the main table to the input parameters */ /* This is just to hold it there so it can be assigned to ocPrimKey if the save succeeds. This */ /* is done because tPosting is no longer available after the save. We use vcRowID in stead */ /* of tApiPosting.tc_rowid because tApiPosting.tc_rowid is used as by-clause in the for each */ /* and this would result in the fact that a single record is treated multiple times by the */ /* for-each */ /* =========================================================================================== */ buffer-copy tApiPosting except tApiPosting.Posting_ID tApiPosting.tc_ParentRowid tApiPosting.tc_rowid tApiPosting.tc_status tApiPosting.PostingSystemDate to tPosting. assign tApiPosting.Posting_ID = tPosting.Posting_ID /*Needed to set the prim-key after the save*/ vcRowID = tPosting.tc_Rowid. tPosting.PostingOriginIsExternal = (if tPosting.PostingOriginIsExternal = ? then false else tPosting.PostingOriginIsExternal). /* ================= */ /* Get a new Voucher */ /* ================= */ if tPosting.PostingVoucher = 0 or tPosting.PostingVoucher = ? then do: <M-59 run GetPostingNumber (input tPosting.tc_Rowid (ictcRowid), input tPosting.PostingYear (iiYear), input tPosting.tcJournalCode (icJournalCode), output tPosting.PostingVoucher (oiVoucher), output viFcReturnSuper (oiReturnStatus)) in BPosting> if viFcReturnSuper < 0 then do : assign vcMsgApi = trim(substitute(#T-89'Posting integration: an error (&1) occurred while retrieving a new number for the posting.':255(583990505)T-89#,string(viFcReturnSuper))) vlSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE}) ocLstReturn = ocLstReturn + chr(4) + string(viFcReturnSuper) ocLstPrimKey = ocLstPrimKey + chr(4) + "*":U ocLstRowid = ocLstRowid + chr(4) + "*":U. Leave MAINPOSTINGPROCESSINGBLOCK. end. /* if viFcReturnSuper < 0 */ else if viFcReturnSuper > 0 then assign vlWarningsFound = true. if not can-find (tCommitNumber where tCommitNumber.tcNumberType = {&COMMITNUMBERTYPE-POSTINGVOUCHER} and tCommitNumber.tcPostingRowID = tPosting.tc_Rowid) then do : create tCommitNumber. assign tCommitNumber.tcNumberType = {&COMMITNUMBERTYPE-POSTINGVOUCHER} tCommitNumber.tcPostingRowID = tPosting.tc_Rowid. end. end. /* if tPosting.PostingVoucher = 0 */ /* ======================================================================================= */ /* Process posting-lines, posting-safs, posting-vats, posting-vat-delays and posting-xrefs */ /* ======================================================================================= */ <M-95 run StdMaintainTTSub1 (input icAction (icAction), input-output ocLstReturn (bcLstReturn), input-output ocLstPrimKey (bcLstPrimKey), input-output ocLstRowid (bcLstRowid), input-output vlSaveAsDraft (blSaveAsDraft), output viFcReturnSuper (oiReturnStatus)) in BPosting> if viFcReturnSuper < 0 then leave MAINPOSTINGPROCESSINGBLOCK. else if viFcReturnSuper > 0 then assign vlWarningsFound = true. /* =================================================== */ /* This is where it ends if only SaveAsDraft is needed */ /* =================================================== */ if vlSaveAsDraft then do: assign ocLstReturn = ocLstReturn + chr(4) + "-1":U ocLstPrimKey = ocLstPrimKey + chr(4) + "*":U ocLstRowid = ocLstRowid + chr(4) + "*":U. Leave MAINPOSTINGPROCESSINGBLOCK. end. /* vlSaveAsDraft */ /* =================================================== */ /* Create the SAFs based upon tApiSafFromPosting */ /* =================================================== */ if can-find (first tApiSafFromPosting) then do : if viBSafPostingID = ? or viBSafPostingID = 0 then do: <I-76 {bFcStartAndOpenInstance &ADD-TO-TRANSACTION = "false" &CLASS = "BSaf"}> end. else do: <I-77 {bFcOpenInstance &CLASS = "BSaf"}> end. <M-78 run ApiStdMaintainTT (input tApiSafFromPosting (tApiSaf), input icAction (icAction), output vcLstPrimKey (ocLstPrimKey), output vcLstReturn (ocLstReturn), output vcLstRowId (ocLstRowId), output viBSafReturn (oiReturnStatus)) in BSaf> <I-79 {bFcCloseInstance &CLASS = "BSaf"}> assign viFcReturnSuper = viBSafReturn. if viFcReturnSuper < 0 then do : assign ocLstReturn = ocLstReturn + chr(4) + string(viFcReturnSuper) ocLstPrimKey = ocLstPrimKey + chr(4) + "*":U ocLstRowid = ocLstRowid + chr(4) + "*":U vlSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE}). Leave MAINPOSTINGPROCESSINGBLOCK. end. /* viFcReturnSuper < 0 */ else if viFcReturnSuper > 0 then assign vlWarningsFound = true. end. /* if can-find (first tApiSafFromPosting) */ /* =============================== */ /* Set Actvity */ /* =============================== */ if (vcActivityCode = "":U or vcActivityCode = ?) and can-find (first tPosting where tPosting.tc_Status = "N":U) then assign vcActivityCode = "ExternalCreate":U. /* =========================================================== */ /* Indicate the data is saved/stored correctly and set primkey */ /* =========================================================== */ assign ocLstReturn = ocLstReturn + chr(4) + (if vlWarningsFound = true then "1":U else "0":U) ocLstPrimKey = ocLstPrimKey + chr(4) + string(tApiPosting.Posting_ID) ocLstRowid = ocLstRowid + chr(4) + vcRowID. END. /* MAINPOSTINGPROCESSINGBLOCK */ /* ================================================================== */ /* Handle errors: Store if SaveAsDraft is needed */ /* Check: only 1 draft is allowed for a single bus-component instance */ /* ================================================================== */ if vlSaveAsDraft and index(substring(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 vcMsgApi = trim(#T-93'Only one draft instance can be created per method call.':255(13856)T-93#) + chr(10) + trim(#T-94'This second object will not be stored as a draft instance and will thus be considered as an error situation.':255(999890843)T-94#). <M-72 run SetMessage (input vcMsgApi (icMessage), input '':U (icArguments), input '':U (icFieldName), input '':U (icFieldValue), input 'E':U (icType), input 1 (iiSeverity), input '':U (icRowid), input 'QadFin-7160':U (icFcMsgNumber), input '' (icFcExplanation), input '' (icFcIdentification), input '' (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BPosting> next. end. /* if vlDraftInstanceCreated = true */ <M-67 run StoreState (input '(':U + tPosting.PostingInvoiceReferenceTxt + ') ':U + trim(#T-90'Posting created via an API method':200(606057275)T-90#) (icDescription), input ? (icUIClass), output viFcReturnSuper (oiReturnStatus)) in BPosting> assign vlDraftInstanceCreated = true entry(num-entries(ocLstReturn , chr(4)), ocLstReturn , chr(4)) = string(viFcReturnSuper) entry(num-entries(ocLstPrimKey, chr(4)), ocLstPrimKey, chr(4)) = string(tApiPosting.Posting_ID) entry(num-entries(ocLstRowid , chr(4)), ocLstRowid , chr(4)) = vcRowID. end. /* if vlSaveAsDraft and */ end. /* for each tApiPosting */ /* ============= */ /* Stop Queries */ /* ============= */ <Q-74 run VatRuleByVatIDCode (Stop) in BVAT > /* ============================================================ */ /* 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 vcMsgApi = trim(#T-80'Posting integration: incomplete information returned by an API method. See other messages for further details.':200(3206)T-80#) + chr(10) + trim(substitute(#T-81'Main table records: &1.':255(310)T-81#,string(viMainTableRecordCount))) + chr(10) + trim(substitute(#T-82'Return Statuses: &1.':255(311)T-82#,ocLstReturn)) + chr(10) + trim(substitute(#T-83'Primary keys: &1.':255(312)T-83#,ocLstPrimKey)) + chr(10) + trim(substitute(#T-84'Row IDs: &1.':255(313)T-84#,ocLstRowid)). oiReturnStatus = -3. <M-57 run SetMessage (input vcMsgApi (icMessage), input '':U (icArguments), input '':U (icFieldName), input '':U (icFieldValue), input 'E':U (icType), input 1 (iiSeverity), input '':U (icRowid), input 'QadFin-7153':U (icFcMsgNumber), input '' (icFcExplanation), input '' (icFcIdentification), input '' (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BPosting> return. end. /* if num-entries */ /* ===================================================== */ /* Set global return value based on the individual ones: */ /* assign it to zero if all individual ones are zero. */ /* ===================================================== */ 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 oiReturnStatus = -3 vcMsgApi = trim(#T-85'Posting integration: an error has occurred while running this API method. See other error messages for more details.':255(3207)T-85#). <M-58 run SetMessage (input vcMsgApi (icMessage), input '':U (icArguments), input '':U (icFieldName), input '':U (icFieldValue), input 'E':U (icType), input 1 (iiSeverity), input '':U (icRowid), input 'QadFin-7154':U (icFcMsgNumber), input '' (icFcExplanation), input '' (icFcIdentification), input '' (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BPosting> return. end. /* if index(ocLstReturn,"-":U) <> 0 */ else do : assign vcMsgApi = trim(#T-86'Posting integration: a warning has occurred while running this API method. See other error messages for more details.':255(14315)T-86#) oiReturnStatus = +1. <M-63 run SetMessage (input vcMsgApi (icMessage), input '':U (icArguments), input '':U (icFieldName), input '':U (icFieldValue), input 'W':U (icType), input 3 (iiSeverity), input '':U (icRowid), input 'QadFin-7157':U (icFcMsgNumber), input '' (icFcExplanation), input '' (icFcIdentification), input '' (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BPosting> return. end. /* not if lookup */ end. /* Not ocLstReturn = .... */