project QadFinancials > class BBankImport > method ApiEDIImportBankImport
Description
This method is invoked by EDI to store dataset into DB.
Parameters
| izProdsBankImport | input | dataset-handle | |
| oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program3/bbankimport.p)
/* ================================================================= */
/* API method invoked By EDI Program */
/* This method parses the dataset passed by EDI and stores data */
/* in dataset to database */
/* ================================================================= */
/* Initialization. Read data from the dataset */
assign oiReturnStatus = -98
vhBankImport = izProdsBankImport:get-buffer-handle(1)
vhBankImportLine = izProdsBankImport:get-buffer-handle(2)
vhBankImpBuf = temp-table tBankImp:default-buffer-handle.
if viBBankImportLineID = 0 or viBBankImportLineID = ?
then do:
<I-14 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "true"
&CLASS = "BBankImportLine"}>
end. /* if viBBankImportLineID = 0 or viBBankImportLineID = ? */
else do:
<I-21 {bFcOpenInstance
&CLASS = "BBankImportLine"}>
end. /* if else if viBBankImportLineID = 0 or viBBankImportLineID = ? */
/* Go through the dataset */
create query vhQuery in widget-pool "non-persistent".
vhQuery:add-buffer(vhBankImport).
vhQuery:query-prepare("for each ":U + vhBankImport:table).
vhQuery:query-open().
vhQuery:get-first(no-lock).
create query vhQueryLines in widget-pool "non-persistent".
vhQueryLines:add-buffer(vhBankImportLine).
/* Copy the data from EDI dataset to component tables */
repeat while not vhQuery:Query-Off-End:
vcBankFileName = vhBankImport:buffer-field("BankImpFileName":U):buffer-value.
/* FIN-1994 Validation on the bank file name, the bank file name can not be duplicated in half year */
<Q-30 run BankImpByBankFileName (all) (Read) (NoCache)
(input vcBankFileName, (BankFileName)
input today - 180, (LoadedDate)
output dataset tqBankImpByBankFileName) in BBankImport >
find first tqBankImpByBankFileName no-error.
if available tqBankImpByBankFileName
then do:
assign vcMessage = trim(substitute(#T-29'A bank file with the same name &1 was already imported on &2.':150(733721742)T-29#,
vcBankFileName,
string(tqBankImpByBankFileName.ttBankImpLoadedDate)))
oiReturnStatus = -1.
<I-32 {bFcCloseInstance
&CLASS = "BBankImportLine"}>
<M-31 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-9662':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankImport>
return.
end.
<M-6 run AddDetailLine
(input 'BankImp':U (icTable),
input '':U (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BBankImport>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
<I-23 {bFcCloseInstance
&CLASS = "BBankImportLine"}>
return.
end.
vhBankImpBuf:find-by-rowid(rowid(tBankImp)).
vhBankImpBuf:buffer-copy(vhBankImport, 'tc_Rowid,tc_Status,BankImp_ID,BankImpLoadedDate,BankImpLoadedTime':U).
assign tBankImp.BankImpLoadedDate = today
tBankImp.BankImpLoadedTime = time.
/* We have to put a pause here to comply the unique index on the field BankImpLoadedTime */
pause 1 no-message.
vhQueryLines:query-prepare("for each " + vhBankImportLine:table +
" where BankImp_ID = " + vhBankImport:buffer-field("BankImp_ID":U):buffer-value).
vhQueryLines:query-open().
vhQueryLines:get-first(no-lock).
/* Update information data of the detail import lines */
repeat while not vhQueryLines:Query-Off-End:
assign vhBankImportLine:buffer-field("BankImp_ID":U):buffer-value = tBankImp.BankImp_ID.
vhQueryLines:get-next(no-lock).
end.
assign vcRowid = tBankImp.tc_Rowid
viBankImpID = tBankImp.BankImp_ID.
vhQuery:get-next(no-lock).
end.
vhQuery:Query-close().
vhQueryLines:Query-close().
delete object vhQuery.
delete object vhQueryLines.
delete object vhBankImpBuf.
/* Copy the detail line information to component table */
<M-9 run UpdateBankImportLine
(input vhBankImportLine:handle (ihBankImportLines),
input vcRowid (icParentRowid),
input viBankImpID (iiBankImpID),
output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
<I-24 {bFcCloseInstance
&CLASS = "BBankImportLine"}>
return.
end.
<M-19 run ValidateBCAndAdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
<I-25 {bFcCloseInstance
&CLASS = "BBankImportLine"}>
return.
end.
/* Finalization */
<M-2 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BBankImport>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
<I-26 {bFcCloseInstance
&CLASS = "BBankImportLine"}>
return.
end.
<M-3 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BBankImport>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
<I-27 {bFcCloseInstance
&CLASS = "BBankImportLine"}>
return.
end.
<M-4 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BBankImport>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
<I-28 {bFcCloseInstance
&CLASS = "BBankImportLine"}>
return.
end.
if vhBBankImportLineInst <> ? and /* Can be closed by a subprocedure */
valid-handle(vhBBankImportLineInst) = true
then do:
<I-22 {bFcCloseInstance
&CLASS = "BBankImportLine"}>
end. /* if vhBBankImportLineInst <> ? and */
if oiReturnStatus = -98 then assign oiReturnStatus = 0.