project QadFinancials > class BBankEntry > method ApiCreateBankEntryFromImport
Description
create unallocated bank state records with line information based on input temp tables
=> it's like APIStdMaintainTT, but there the dataload has the flag keepprevious on false so that gives problems => APIStdMaintainTT is to handle only one record not multiple ...
Parameters
tApiBankState | input | temp-table | Input temp-table holding the bank statement data to be created, updated or deleted. |
tApiBankStateLine | input | temp-table | Input temp-table holding the bank statement lines records linked to the bank statement data to be created, updated or deleted. |
tApiBankAlloc | input | temp-table | Input temp-table holding the allocations records linked to the bank statement data to be created, updated or deleted. |
tApiBankStateAllocColl | input | temp-table | Input temp-table holding the collection allocations records linked to the bank statement data to be created, updated or deleted. |
icAction | input | character | This parameter defines what should happen with the input data : -SAVE: Save the data if there were no errors, -SAVESTORE : Save the data if there were no errors. If there were errors, save as draft. -STORE : Save the data as draft -VALIDATE : Validate the input data, but do no save the data. |
ocLstPrimKey | output | character | Character 4 separated list with the primary keys of the newly created main-table records. The fields of the primary key are separated with Character 2. |
ocLstReturn | output | character | Char 4 separated list with the return status of the newly created main-table records. Zero means not errors occurred. |
ocLstRowId | output | character | Char 4 separated list with the temporarely rowids (negative for new ones) of the newly created main-table records. |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program9/bbankentry.p)
/* ================================================== */
/* Method Info: */
/* BBankEntry will be loaded based on the logical key */
/* ================================================== */
/* ============================================================================ */
/* Clear the instance: */
/* this will also clear the t_s tables that were filled in ApiMaintainByDataset */
/* ============================================================================ */
<M-104 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
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-SAVE} and
icAction <> {&DAEMONACTION-VALIDATE}
then do:
assign vcMessage = trim(subst(#T-111'Bank statement import: the specified action &1 should be in the list &2.':255(286)t-111#,trim(icAction),"{&DAEMONACTION-SAVE},{&DAEMONACTION-VALIDATE}":U))
oiReturnStatus = -1.
<M-99 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-6376':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
return.
end. /* if icAction */
/* ======================== */
/* Count main-table records */
/* ======================== */
for each tApiBankState no-lock :
assign viMainTableRecordCount = viMainTableRecordCount + 1.
end. /* for each */
if viMainTableRecordCount = 0
then do:
assign vcMessage = trim(#T-119'A bank statement integration error occurred. The system could not find main table records (bank state).':255(307)t-119#)
oiReturnStatus = -1.
<M-105 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-6379':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
return.
end. /* if viMainTableRecordCount */
/* ================================ */
/* Start loop on main-table records */
/* ================================ */
for each tApiBankState by tApiBankState.tc_Rowid:
/* ================================== */
/* Initialise and Create new instance */
/* ================================== */
assign vcMessage = "":U
vcNewRowid = "":U
vlWarningsFound = false.
/* ======================================================= */
/* Period company_id should be the same as the viCompanyID */
/* ======================================================= */
if tApiBankState.Company_ID = ? or
tApiBankState.Company_ID = 0
then assign tApiBankState.Company_ID = viCompanyId.
if tApiBankState.Company_ID <> viCompanyId
then do:
assign vcMessage = trim(substitute(#T-120'The entity (ID &1) does not match the current entity.':200(2211)t-120#, trim(string(tApiBankState.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-103 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-6378':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
next.
end.
/* ============================================= */
/* Get the BankEntry_ID based on the logical key */
/* ============================================= */
if (tApiBankState.BankState_ID = ? or
tApiBankState.BankState_ID = 0) and
tApiBankState.BankStateYear <> ? and
tApiBankState.BankStateYear <> 0 and
tApiBankState.BankStateNumber <> ? and
tApiBankState.BankStateNumber <> "":U
then do:
<M-89 run GetBankStateID
(input tApiBankState.Company_ID (iiCompanyID),
input tApiBankState.tcGLCode (icGLCode),
input tApiBankState.BankStateYear (iiBankStateYear),
input tApiBankState.BankStateNumber (icBankStateNumber),
output viBankState_ID (oiBankStateID),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viBankState_ID <> ? and viBankState_ID <> 0
then assign tApiBankState.BankState_ID = viBankState_ID.
end.
/* ====================== */
/* Load/Create BankState */
/* ====================== */
if tApiBankState.BankState_ID = ? or
tApiBankState.BankState_ID = 0
then assign viFcReturnSuper = -4.
else do:
<M-107 run DataLoad
(input '':U (icRowids),
input string(tApiBankState.BankState_ID) (icPkeys),
input '':U (icObjectIds),
input ? (icFreeform),
input true (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
end.
/* INFO: if dataload fails because of invalid ID, -4 is returned and a new record should be created */
if viFcReturnSuper = -4
then do:
assign viFcReturnSuper = 0.
<M-101 run AddDetailLine
(input 'BankState':U (icTable),
input '':U (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper < 0
then assign vcMessage = trim(subst(#T-121'Cannot create a new instance. Error number: &1.':255(308)t-121#, string(viFcReturnSuper))).
end.
else do:
if viFcReturnSuper < 0
then assign vcMessage = trim(subst(#T-122'Cannot load the instance (error number: &1, instance ID: &2).':255(289)t-122#, string(viFcReturnSuper), string(tApiBankState.BankState_ID))).
else do:
find tBankState where
tBankState.BankState_ID = tApiBankState.BankState_ID
no-error.
if not available tBankState
then assign vcMessage = trim(subst(#T-123'Cannot find the instance after it has been loaded (instance ID: &1).':255(290)t-123#, string(tApiBankState.BankState_ID))).
else assign tBankState.tc_Status = "C":U.
end.
end.
/* ================================================================= */
/* Check for errors in the previous block */
/* ================================================================= */
if vcMessage <> "":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.
<M-100 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-6377':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
next.
end. /* if viFcReturnSuper < 0 */
/* get OpeningBalance when it's not yet filled */
assign vhFcComponent = ?.
<M-30 run ApiGetAccountBalance
(input 9999 (iiAccYear),
input 99 (iiAccPeriod),
input tApiBankState.GL_ID (iiGL_ID),
input tApiBankState.tcGLCode (icGLCode),
input tApiBankState.Company_ID (iiCompanyID),
input '':U (icCompanyCode),
output vdDummy (odBalanceLC),
output vdDummy (odBalanceCC),
output tApiBankState.BankStateOpeningBalance (odBalanceTC),
output viFcReturnSuper (oiReturnStatus)) in BGL>
if viFcReturnSuper < 0
then next.
else if viFcReturnSuper > 0
then assign vlWarningsFound = true.
/* =========================================================================================== */
/* Copy all data into the new BankState */
/* =========================================================================================== */
buffer-copy tApiBankState except
BankState_ID
tc_Rowid
tc_ParentRowid
tc_Status
BankStateYear
BankStateNumber
GL_ID
Company_ID
to tBankState.
if tBankState.tc_Status = 'N':U
then do:
/* get BankStateNumber when it's not yet filled */
if tApiBankState.BankStateNumber = '':U or
tApiBankState.BankStateNumber = ?
then do:
<M-31 run GetNewBankStateNumber
(input tApiBankState.Company_ID (iiCompanyID),
input tApiBankState.GL_ID (iiBankGLID),
input tApiBankState.tcGLCode (icBankGLCode),
input tApiBankState.BankStateYear (iiBankStateYear),
output tApiBankState.BankStateNumber (ocNewBankStateNumber),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper < 0
then next.
else if viFcReturnSuper > 0
then assign vlWarningsFound = true.
end. /* if tApiBankState.BankStateNumber = '':U or */
/* Assign fields in instance table from imported table */
assign tBankState.BankStateNumber = tApiBankState.BankStateNumber
tBankState.BankStateYear = tApiBankState.BankStateYear
tBankState.GL_ID = tApiBankState.GL_ID
tBankState.Company_ID = tApiBankState.Company_ID
tBankState.BankStateMovement = 0
tBankState.BankStateClosingBalance = tBankState.BankStateOpeningBalance.
end. /* if tBankState.tc_status = 'N':U */
assign tApiBankState.BankState_ID = tBankState.BankState_ID
vcNewRowid = tBankState.tc_Rowid.
/* =================================================================== */
/* Process other Temp-Tables BankStateLine, Alloc and AlloColl */
/* =================================================================== */
<M-109 run ApiStdMaintainTTSub
(input icAction (icAction),
input-output ocLstReturn (bcLstReturn),
input-output ocLstPrimKey (bcLstPrimKey),
input-output ocLstRowId (bcLstRowid),
input-output vlSaveAsDraft (blSaveAsDraft),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper < 0
then next.
else if viFcReturnSuper > 0
then assign vlWarningsFound = true.
/* =========================================================== */
/* 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(tApiBankState.BankState_ID)
ocLstRowid = ocLstRowid + chr(4) + vcNewRowid.
end. /* for each tApiBankState */
/* ============================================================ */
/* 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-114'A bank statement integration error occurred. An API method returned incomplete information. See other messages for further details.':200(309)t-114#) + chr(10) +
trim(substitute(#T-115'Main table records: &1.':255(310)T-115#,string(viMainTableRecordCount))) + chr(10) +
trim(substitute(#T-116'Return Statuses: &1.':255(311)T-116#,ocLstReturn)) + chr(10) +
trim(substitute(#T-117'Primary keys: &1.':255(312)T-117#,ocLstPrimKey)) + chr(10) +
trim(substitute(#T-118'Row IDs: &1.':255(313)T-118#,ocLstRowid)).
oiReturnStatus = -3.
<M-98 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-6375':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
return.
end. /* if num-entries */
/* if no error found, run validation, addupd, datasave */
/* =============================== */
/* Set Actvity */
/* =============================== */
if vcActivityCode = '':U or
vcActivityCode = ?
then do:
if can-find (first tBankState where
tBankState.tc_Status = "N":U)
then assign vcActivityCode = "Create":U.
else if can-find (first tBankState where
tBankState.tc_Status = "C":U)
then assign vcActivityCode = "Modify":U.
end.
/* ============================================================================== */
/* Validate the data and Perform external updates (can also contain validations). */
/* ============================================================================== */
<M-94 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper <> 0
then do:
if index(ocLstReturn,'-':U) = 0
then assign ocLstReturn = fill(string(viFcReturnSuper) + chr(4),viMainTableRecordCount).
if viFcReturnSuper < 0
then do :
assign oiReturnStatus = viFcReturnSuper.
return.
end. /* viFcReturnSuper < 0 */
end.
/* ================ */
/* External updates */
/* ================ */
<M-95 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper <> 0
then do:
if index(ocLstReturn,'-':U) = 0
then assign ocLstReturn = fill(string(viFcReturnSuper) + chr(4),viMainTableRecordCount).
if viFcReturnSuper < 0
then do :
assign oiReturnStatus = viFcReturnSuper.
return.
end. /* viFcReturnSuper < 0 */
end.
/* ================================================== */
/* Save the data */
/* ================================================== */
if icAction <> {&DAEMONACTION-VALIDATE}
then do :
<M-96 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper <> 0
then do:
if index(ocLstReturn,'-':U) = 0
then assign ocLstReturn = fill(string(viFcReturnSuper) + chr(4),viMainTableRecordCount).
if viFcReturnSuper < 0
then do :
assign oiReturnStatus = viFcReturnSuper.
return.
end. /* viFcReturnSuper < 0 */
end.
end.
/* ===================================================== */
/* 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 vcMessage = trim(#T-112'An error occurred while running the API method. See other error messages for more details.':255(14334)t-112#)
oiReturnStatus = -1.
<M-97 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-6374':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
end.
else do:
assign vcMessage = trim(#T-113'A warning has occurred while running this API method. See other error messages for more details.':255(14089)T-113#)
oiReturnStatus = +1.
<M-106 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-6380':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
end.
end.
Sample code: how to call this method through RPCRequestService (QXtend Inbound)
define temp-table ttContext no-undo
field propertyQualifier as character
field propertyName as character
field propertyValue as character
index entityContext is primary unique
propertyQualifier
propertyName
index propertyQualifier
propertyQualifier.
define dataset dsContext for ttContext.
define variable vhContextDS as handle no-undo.
define variable vhExceptionDS as handle no-undo.
define variable vhServer as handle no-undo.
define variable vhInputDS as handle no-undo.
define variable vhInputOutputDS as handle no-undo.
define variable vhOutputDS as handle no-undo.
define variable vhParameter as handle no-undo.
/* Create context */
create ttContext.
assign ttContext.propertyName = "programName"
ttContext.propertyValue = "BBankEntry".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "ApiCreateBankEntryFromImport".
create ttContext.
assign ttContext.propertyName = "applicationId"
ttContext.propertyValue = "fin".
create ttContext.
assign ttContext.propertyName = "entity"
ttContext.propertyValue = "1000".
create ttContext.
assign ttContext.propertyName = "userName"
ttContext.propertyValue = "mfg".
create ttContext.
assign ttContext.propertyName = "password"
ttContext.propertyValue = "".
/* Create input dataset */
create dataset vhInputDS.
vhInputDS:read-xmlschema("file", "xml/bbankentry.apicreatebankentryfromimport.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icAction = <parameter value>.
vhParameter = vhInputDS:get-buffer-handle("tApiBankState").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
vhParameter::<field-name-2> = <field-value-2>
...
vhParameter = vhInputDS:get-buffer-handle("tApiBankStateLine").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
vhParameter::<field-name-2> = <field-value-2>
...
vhParameter = vhInputDS:get-buffer-handle("tApiBankAlloc").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
vhParameter::<field-name-2> = <field-value-2>
...
vhParameter = vhInputDS:get-buffer-handle("tApiBankStateAllocColl").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
vhParameter::<field-name-2> = <field-value-2>
...
/* Connect the AppServer */
create server vhServer.
vhServer:connect("-URL <appserver-url>").
if not vhServer:connected()
then do:
message "Could not connect AppServer" view-as alert-box error title "Error".
return.
end.
/* Run */
assign vhContextDS = dataset dsContext:handle.
run program/rpcrequestservice.p on vhServer
(input-output dataset-handle vhContextDS by-reference,
output dataset-handle vhExceptionDS,
input dataset-handle vhInputDS by-reference,
input-output dataset-handle vhInputOutputDS by-reference,
output dataset-handle vhOutputDS).
/* Handle output however you want, in this example, we dump it to xml */
if valid-handle(vhExceptionDS)
then vhExceptionDS:write-xml("file", "Exceptions.xml", true).
if valid-handle(vhOutputDS)
then vhOutputDS:write-xml("file", "Output.xml", true).
/* Cleanup */
vhServer:disconnect().
assign vhServer = ?.
if valid-handle(vhInputDS)
then delete object vhInputDS.
if valid-handle(vhOutputDS)
then delete object vhOutputDS.
if valid-handle(vhExceptionDS)
then delete object vhExceptionDS.