project QadFinancials > class BBill > method CreateBills
Description
Create bills for input invoices.
Parameters
Internal usage
unused
program code (program3/bbill.p)
<M-17 run ClearData (output oiReturnStatus (oiReturnStatus)) in BBill>
empty temp-table tBillToSave.
empty temp-table tDInvoiceToBillForSave.
for each t_sDInvoiceToBillForSave:
create tDInvoiceToBillForSave.
buffer-copy t_sDInvoiceToBillForSave to tDInvoiceToBillForSave.
end.
find first tDInvoiceToBillForSave no-error.
if not available tDInvoiceToBillForSave then
do:
<M-49 run SetMessage
(input trim(#T-73'A bill must contain one or more invoices.':255(352126198)T-73#) (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input ? (icRowid),
input 'qadfin-302485':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBill>
assign oiReturnStatus = -1.
return.
end.
for each tDInvoiceToBillForSave no-lock where tDInvoiceToBillForSave.tlDInvoiceIsSelected = yes
break by tDInvoiceToBillForSave.tcCurrencyCode
by tDInvoiceToBillForSave.ttDInvoiceBillDate
by tDInvoiceToBillForSave.tiCompany_ID
by tDInvoiceToBillForSave.tcDebtorCode
by tDInvoiceToBillForSave.ttDInvoiceDate:
if first-of(tDInvoiceToBillForSave.tcDebtorCode) then
do:
/* create the bill */
<M-81 run AddDetailLine
(input 'Bill':U (icTable),
input '':U (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BBill>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
assign tBill.BillDate = tDInvoiceToBillForSave.ttDInvoiceBillDate
tBill.BillDueDate = tDInvoiceToBillForSave.ttBillDueDate
tBill.BillYear = year(tDInvoiceToBillForSave.ttDInvoiceBillDate)
tBill.BillStatus = {&BILLSTATUS-INITIAL}
tBill.Company_ID = viCompanyId
tBill.tcCurrencyCode = tDInvoiceToBillForSave.tcCurrencyCode
tBill.tcDebtorCode = tDInvoiceToBillForSave.tcDebtorCode
tBill.tcEmployeeCode = tDInvoiceToBillForSave.tcEmployeeCode
tBill.tc_Status = 'N':U.
<Q-30 run CompanyPrim (all) (Read) (NoCache)
(input viCompanyId, (LookupCompanyId)
input ?, (CompanyCode)
output dataset tqCompanyPrim) in BCompany>
find first tqCompanyPrim where tqCompanyPrim.tiCompany_ID = viCompanyId no-error.
if available tqCompanyPrim
then assign tBill.tcCompanyCode = tqCompanyPrim.tcCompanyCode.
assign vhFcComponent = ?.
<M-18 run GetNumber
(input tBill.Company_ID (iiCompanyId),
input tBill.BillYear (iiNumbrYear),
input 'BILLING' (icNumbrType),
output viBillNumber (oiNumber),
input viFcCurrentInstanceId (iiInstanceId),
input vcFcComponentName (icClassName),
output viFcReturnSuper (oiReturnStatus)) in BNumber>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
assign tBill.BillNumber = viBillNumber.
for each bDInvoiceToBillForSave where
bDInvoiceToBillForSave.tlDInvoiceIsSelected = yes and
bDInvoiceToBillForSave.tcDebtorCode = tDInvoiceToBillForSave.tcDebtorCode and
bDInvoiceToBillForSave.tcCurrencyCode = tDInvoiceToBillForSave.tcCurrencyCode and
bDInvoiceToBillForSave.tiCompany_ID = tDInvoiceToBillForSave.tiCompany_ID and
bDInvoiceToBillForSave.ttDInvoiceBillDate = tDInvoiceToBillForSave.ttDInvoiceBillDate:
assign bDInvoiceToBillForSave.tiBill_ID = tBill.Bill_ID.
if bDInvoiceToBillForSave.tlBillScheduleIsUpdInvByBill then
assign bDInvoiceToBillForSave.ttDInvoiceDueDate = bDInvoiceToBillForSave.ttBillDueDate.
end. /* for each bDInvoiceToBillForSave */
end. /* end first-of(tcDebtorCode) */
end. /* end for each tDInvoiceToBillForSave */
<M-9 run ValidateBC (output oiReturnStatus (oiReturnStatus)) in BBill>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0) then
assign
oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then
do:
for each tBill no-lock:
assign vhFcComponent = ?.
<M-21 run ReleaseNumber
(input tBill.Company_ID (iiCompanyId),
input tBill.BillYear (iiNumbrYear),
input 'BILLING' (icNumbrType),
input tBill.BillNumber (iiNumbr),
input viFcCurrentInstanceId (iiInstanceId),
input vcFcComponentName (icClassName),
output viFcReturnSuper (oiReturnStatus)) in BNumber>
end.
return.
end.
<M-28 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BBill>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0) then
assign
oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then
return.
<M-45 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BBill>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0) then
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then
return.
find first tBill where tBill.Bill_id <> 0 no-error.
if available tBill
then do:
create tBillToSave.
buffer-copy tBill to tBillToSave.
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 = "BBill".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "CreateBills".
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/bbill.createbills.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tDInvoiceToBillForSave").
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.