| tApiUpdateDInvoiceOpInfo | input | temp-table | Parameter tiDInvoiceId and tiEntityId is not needed for the input parameters, the program will retrieve these 2 ids by other fields. The other parameters are mandatory. |
| oiReturnStatus | output | integer | Return status of the method. |
MAIN_BLOCK:
do on error undo, throw:
/* check if input temp-table data exists */
find first tApiUpdateDInvoiceOpInfo no-error.
if not available tApiUpdateDInvoiceOpInfo
then do:
assign oiReturnStatus = 0.
leave MAIN_BLOCK.
end.
/**************************************************/
/* get company_id and dinvoice_id info */
/**************************************************/
for each tApiUpdateDInvoiceOpInfo:
assign tApiUpdateDInvoiceOpInfo.tiGTCompanyId = 0
tApiUpdateDInvoiceOpInfo.tiDInvoiceId = 0.
/* get company id */
if tApiUpdateDInvoiceOpInfo.tcGTCompany <> ? and
tApiUpdateDInvoiceOpInfo.tcGTCompany <> "":U
then do:
<Q-53 run CompanyPrim (all) (Read) (NoCache)
(input ?, (LookupCompanyId)
input tApiUpdateDInvoiceOpInfo.tcGTCompany, (CompanyCode)
output dataset tqCompanyPrim) in BCompany>
find first tqCompanyPrim no-error.
if available tqCompanyPrim
then do:
assign tApiUpdateDInvoiceOpInfo.tiGTCompanyId = tqCompanyPrim.tiCompany_ID.
end.
end.
if tApiUpdateDInvoiceOpInfo.tiGTCompanyId = 0
then do:
assign vcMessage = trim(substitute(#T-59'Entity (&1) could not be found.':100(702276637)T-59#, tApiUpdateDInvoiceOpInfo.tcGTCompany))
oiReturnStatus = -1.
<M-74 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'gtih_entity':U (icFieldName),
input tApiUpdateDInvoiceOpInfo.tcGTCompany (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-205599':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end.
/* get invoice id */
if tApiUpdateDInvoiceOpInfo.tcDIText <> "":U and
tApiUpdateDInvoiceOpInfo.tcDIText <> ? and
tApiUpdateDInvoiceOpInfo.tiGTCompanyId <> 0
then do:
<Q-95 run DInvoiceByDITextCompanyID (all) (Read) (NoCache)
(input tApiUpdateDInvoiceOpInfo.tcDIText, (InvoiceNumber)
input tApiUpdateDInvoiceOpInfo.tiGTCompanyId, (CompanyId)
output dataset tqDInvoiceByDITextCompanyID) in BDInvoice>
find first tqDInvoiceByDITextCompanyID no-error.
if available tqDInvoiceByDITextCompanyID
then do:
assign tApiUpdateDInvoiceOpInfo.tiDInvoiceId = tqDInvoiceByDITextCompanyID.tiDInvoice_ID.
end.
end.
if tApiUpdateDInvoiceOpInfo.tiDInvoiceId = 0
then do:
assign vcMessage = trim(substitute(#T-40'Customer invoice (&1,&2) could not be found.':100(433966247)T-40#,
tApiUpdateDInvoiceOpInfo.tcGTCompany,tApiUpdateDInvoiceOpInfo.tcDIText))
oiReturnStatus = -1.
<M-22 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'gtih_hist.gtih_docnbr':U (icFieldName),
input tApiUpdateDInvoiceOpInfo.tcDIText (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-841101':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end.
/* check length of golden tax invoice number */
if length(tApiUpdateDInvoiceOpInfo.tcGTInvNbr,"CHARACTER") > 8
then do:
assign vcMessage = trim(substitute(#T-32'Length of golden tax invoice number (&1) cannot exceed 8 characters.':100(335247428)T-32#,
tApiUpdateDInvoiceOpInfo.tcGTInvNbr))
oiReturnStatus = -1.
<M-16 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tApiUpdateDInvoiceOpInfo.tcGTInvNbr':U (icFieldName),
input tApiUpdateDInvoiceOpInfo.tcGTInvNbr (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-402683':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end.
end. /* for each tApiUpdateDInvoiceOpInfo: */
/* Return when has validation errors */
if oiReturnStatus = -1
then leave MAIN_BLOCK.
<M-93 run UpdateDInvoiceOpInfo
(input tApiUpdateDInvoiceOpInfo (tApiUpdateDInvoiceOpInfo),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then leave MAIN_BLOCK.
/***************************************************************************************************/
/* Validate and commit all the changes */
/***************************************************************************************************/
<M-4 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then
do:
assign oiReturnStatus = viFcReturnSuper.
<M-31 run StopExternalInstances (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
leave MAIN_BLOCK.
end.
<M-44 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then
do:
assign oiReturnStatus = viFcReturnSuper.
<M-82 run StopExternalInstances (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
leave MAIN_BLOCK.
end.
<M-9 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then
do:
assign oiReturnStatus = viFcReturnSuper.
<M-67 run StopExternalInstances (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
leave MAIN_BLOCK.
end.
<M-7 run StopExternalInstances (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end. /* MAIN_BLOCK: */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 = "BDInvoice".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "ApiUpdateDInvoiceOpInfo".
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/bdinvoice.apiupdatedinvoiceopinfo.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tApiUpdateDInvoiceOpInfo").
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.