project QadFinancials > class BBill > method ApiGetBillingDueDate
Description
API for getting Bill Date and Billing Due date
Parameters
itInvDate | input | date | |
icBillScheduleCode | input | character | |
iiCompanyId | input | integer | |
itInvDueDate | input | date | |
itFilterRefDateFrom | input | date | |
itFilterRefDateTo | input | date | |
ilCheckHoliday | input | logical | |
ilIsBillDateExisting | input | logical | If BillDate has already existed, it doesn't need to overwrite it. |
olIsRemove | output | logical | |
otBillDate | output | date | |
otBillDueDate | output | date | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program3/bbill.p)
<Q-70 run BillScheduleForDueDate (all) (Read) (NoCache)
(input icBillScheduleCode, (BillScheduleCode)
output dataset tqBillScheduleForDueDate) in BBillSchedule>
for each tqBillScheduleForDueDate:
if tqBillScheduleForDueDate.tcBillScheduleSelectInvBasedOn = {&BILLSCHEDULESELECTINV-INVDATE} then assign vtInputDate = itInvDate.
else assign vtInputDate = itInvDueDate.
if (itFilterRefDateFrom <> ? and vtInputDate > itFilterRefDateTo or vtInputDate < itFilterRefDateFrom)
or (itFilterRefDateFrom = ? and itFilterRefDateTo <> ? and vtInputDate > itFilterRefDateTo)
then do:
olIsRemove = true.
leave.
end.
viDay = DAY(vtInputDate).
viMonth = MONTH(vtInputDate).
viYear = YEAR(vtInputDate).
/* Day in month */
if tqBillScheduleForDueDate.tcBillSchedulePattern = {&BILLSCHEDULEPATTERN-DAYINMTH} then
do:
do while true:
if viDay <= tqBillScheduleForDueDate.tiBillScheduleMthBillDay1 then
do:
if tqBillScheduleForDueDate.tiBillScheduleMthBillDay1 <= 28 then
assign otBillDate = DATE(viMonth, tqBillScheduleForDueDate.tiBillScheduleMthBillDay1, viYear).
else do:
<M-10 run EndOfMonth
(input viMonth (iiMonth),
input viYear (iiYear),
output viEOM (oiEOM),
output oiReturnStatus (oiReturnStatus)) in BBill>
if tqBillScheduleForDueDate.tiBillScheduleMthBillDay1 > viEOM then
assign otBillDate = DATE(viMonth, viEOM, viYear).
else assign otBillDate = DATE(viMonth, tqBillScheduleForDueDate.tiBillScheduleMthBillDay1, viYear).
end.
viDay = tqBillScheduleForDueDate.tiBillScheduleMthDueDay1.
viMonth = viMonth + tqBillScheduleForDueDate.tiBillScheduleMthDelay1.
leave.
end.
else if viDay <= tqBillScheduleForDueDate.tiBillScheduleMthBillDay2 then
do:
if tqBillScheduleForDueDate.tiBillScheduleMthBillDay2 <= 28 then
assign otBillDate = DATE(viMonth, tqBillScheduleForDueDate.tiBillScheduleMthBillDay2, viYear).
else do:
<M-75 run EndOfMonth
(input viMonth (iiMonth),
input viYear (iiYear),
output viEOM (oiEOM),
output oiReturnStatus (oiReturnStatus)) in BBill>
if tqBillScheduleForDueDate.tiBillScheduleMthBillDay2 > viEOM then
assign otBillDate = DATE(viMonth, viEOM, viYear).
else assign otBillDate = DATE(viMonth, tqBillScheduleForDueDate.tiBillScheduleMthBillDay2, viYear).
end.
viDay = tqBillScheduleForDueDate.tiBillScheduleMthDueDay2.
viMonth = viMonth + tqBillScheduleForDueDate.tiBillScheduleMthDelay2.
leave.
end.
else if viDay <= tqBillScheduleForDueDate.tiBillScheduleMthBillDay3 then
do:
if tqBillScheduleForDueDate.tiBillScheduleMthBillDay3 <= 28 then
assign otBillDate = DATE(viMonth, tqBillScheduleForDueDate.tiBillScheduleMthBillDay3, viYear).
else do:
<M-93 run EndOfMonth
(input viMonth (iiMonth),
input viYear (iiYear),
output viEOM (oiEOM),
output oiReturnStatus (oiReturnStatus)) in BBill>
if tqBillScheduleForDueDate.tiBillScheduleMthBillDay3 > viEOM then
assign otBillDate = DATE(viMonth, viEOM, viYear).
else assign otBillDate = DATE(viMonth, tqBillScheduleForDueDate.tiBillScheduleMthBillDay3, viYear).
end.
viDay = tqBillScheduleForDueDate.tiBillScheduleMthDueDay3.
viMonth = viMonth + tqBillScheduleForDueDate.tiBillScheduleMthDelay3.
leave.
end.
else if viDay <= tqBillScheduleForDueDate.tiBillScheduleMthBillDay4 then
do:
if tqBillScheduleForDueDate.tiBillScheduleMthBillDay4 <= 28 then
assign otBillDate = DATE(viMonth, tqBillScheduleForDueDate.tiBillScheduleMthBillDay4, viYear).
else do:
<M-90 run EndOfMonth
(input viMonth (iiMonth),
input viYear (iiYear),
output viEOM (oiEOM),
output oiReturnStatus (oiReturnStatus)) in BBill>
if tqBillScheduleForDueDate.tiBillScheduleMthBillDay4 > viEOM then
assign otBillDate = DATE(viMonth, viEOM, viYear).
else assign otBillDate = DATE(viMonth, tqBillScheduleForDueDate.tiBillScheduleMthBillDay4, viYear).
end.
viDay = tqBillScheduleForDueDate.tiBillScheduleMthDueDay4.
viMonth = viMonth + tqBillScheduleForDueDate.tiBillScheduleMthDelay4.
leave.
end.
else do:
/* Go to next month */
viMonth = viMonth + 1.
viYear = viYear + TRUNCATE((viMonth - 1) / 12, 0).
viMonth = (viMonth - 1 ) mod 12 + 1.
viDay = 0.
end.
end. /* end do while true */
end. /* end Day In Month */
/* Weekly */
else if tqBillScheduleForDueDate.tcBillSchedulePattern = {&BILLSCHEDULEPATTERN-WEEKLY} then
do:
do viLoop = 1 TO 7:
IF TRIM(ENTRY(viLoop, vcDayname)) = tqBillScheduleForDueDate.tcBillScheduleDayInWeek then leave.
end.
viWeekday = viLoop.
do viLoop = 1 TO 5:
if viLoop = 1 and tqBillScheduleForDueDate.tlBillScheduleIsWeek1InMnth = yes then
do:
<M-52 run GetDateOfXthWeekday
(input viYear (iiYear),
input viMonth (iiMonth),
input viLoop (iiNumber),
input viWeekday (iiWeekday),
output viResultDay (oiDay),
output oiReturnStatus (oiReturnStatus)) in BBill>
if viResultDay >= viDay then do:
otBillDate = DATE(viMonth, viResultDay, viYear).
viDay = tqBillScheduleForDueDate.tiBillScheduleMthDueDay1.
viMonth = viMonth + tqBillScheduleForDueDate.tiBillScheduleMthDelay1.
leave.
end.
end.
else if viLoop = 2 and tqBillScheduleForDueDate.tlBillScheduleIsWeek2InMnth = yes then
do:
<M-48 run GetDateOfXthWeekday
(input viYear (iiYear),
input viMonth (iiMonth),
input viLoop (iiNumber),
input viWeekday (iiWeekday),
output viResultDay (oiDay),
output oiReturnStatus (oiReturnStatus)) in BBill>
if viResultDay >= viDay then
do:
otBillDate = DATE(viMonth, viResultDay, viYear).
viDay = tqBillScheduleForDueDate.tiBillScheduleMthDueDay2.
viMonth = viMonth + tqBillScheduleForDueDate.tiBillScheduleMthDelay2.
leave.
end.
end.
else if viLoop = 3 and tqBillScheduleForDueDate.tlBillScheduleIsWeek3InMnth = yes then
do:
<M-87 run GetDateOfXthWeekday
(input viYear (iiYear),
input viMonth (iiMonth),
input viLoop (iiNumber),
input viWeekday (iiWeekday),
output viResultDay (oiDay),
output oiReturnStatus (oiReturnStatus)) in BBill>
if viResultDay >= viDay then do:
otBillDate = DATE(viMonth, viResultDay, viYear).
viDay = tqBillScheduleForDueDate.tiBillScheduleMthDueDay3.
viMonth = viMonth + tqBillScheduleForDueDate.tiBillScheduleMthDelay3.
leave.
end.
end.
else if viLoop = 4 and tqBillScheduleForDueDate.tlBillScheduleIsWeek4InMnth = yes then
do:
<M-66 run GetDateOfXthWeekday
(input viYear (iiYear),
input viMonth (iiMonth),
input viLoop (iiNumber),
input viWeekday (iiWeekday),
output viResultDay (oiDay),
output oiReturnStatus (oiReturnStatus)) in BBill>
if tqBillScheduleForDueDate.tlBillScheduleIsWeek1InMnth = no and tqBillScheduleForDueDate.tlBillScheduleIsWeek2InMnth = no and tqBillScheduleForDueDate.tlBillScheduleIsWeek3InMnth = no then
do:
<M-79 run EndOfMonth
(input viMonth (iiMonth),
input viYear (iiYear),
output viEOM (oiEOM),
output oiReturnStatus (oiReturnStatus)) in BBill>
if viResultDay + 7 <= viEOM then
assign viResultDay = viResultDay + 7.
end.
if viResultDay >= viDay then
do:
otBillDate = DATE(viMonth, viResultDay, viYear).
viDay = tqBillScheduleForDueDate.tiBillScheduleMthDueDay4.
viMonth = viMonth + tqBillScheduleForDueDate.tiBillScheduleMthDelay4.
leave.
end.
end.
/* Check the 5th week while week 4 is singly chosen or all weeks are chosen */
else if viLoop = 5 and tqBillScheduleForDueDate.tlBillScheduleIsWeek4InMnth = yes and
(tqBillScheduleForDueDate.tlBillScheduleIsWeek1InMnth = yes and tqBillScheduleForDueDate.tlBillScheduleIsWeek2InMnth = yes and tqBillScheduleForDueDate.tlBillScheduleIsWeek3InMnth = yes)
then do:
<M-16 run GetDateOfXthWeekday
(input viYear (iiYear),
input viMonth (iiMonth),
input viLoop (iiNumber),
input viWeekday (iiWeekday),
output viResultDay (oiDay),
output oiReturnStatus (oiReturnStatus)) in BBill>
<M-44 run EndOfMonth
(input viMonth (iiMonth),
input viYear (iiYear),
output viEOM (oiEOM),
output oiReturnStatus (oiReturnStatus)) in BBill>
if viResultDay <= viEOM and viResultDay >= viDay then do:
otBillDate = DATE(viMonth, viResultDay, viYear).
viDay = tqBillScheduleForDueDate.tiBillScheduleMthDueDay4.
viMonth = viMonth + tqBillScheduleForDueDate.tiBillScheduleMthDelay4.
leave.
end.
end.
if viLoop = 5 then
do:
/* Go to next month */
viMonth = viMonth + 1.
viYear = viYear + TRUNCATE((viMonth - 1) / 12, 0).
viMonth = (viMonth - 1 ) mod 12 + 1.
viDay = 0.
viLoop = 0.
end.
end. /* end loop 1-5 */
end. /* end Weekly */
viYear = viYear + TRUNCATE((viMonth - 1) / 12, 0).
viMonth = (viMonth - 1 ) mod 12 + 1.
/* Get the number of days in viMonth */
<M-28 run EndOfMonth
(input viMonth (iiMonth),
input viYear (iiYear),
output viEOM (oiEOM),
output oiReturnStatus (oiReturnStatus)) in BBill>
if viDay > viEOM then assign viDay = viEOM.
/* If BillDate has already existed, it doesn't need to be overwrite */
if ilIsBillDateExisting = true
then do:
assign otBillDate = itInvDate.
if itFilterRefDateTo <> ? and otBillDate > itFilterRefDateTo
then do:
assign olIsRemove = true.
end.
end.
/* If Bill Date exceeds FilterRefDateTo, remove it in later process */
else if itFilterRefDateTo <> ? and otBillDate > itFilterRefDateTo then
assign olIsRemove = true.
/* If BillScheduleDueDateCalType = "MTHDELAYDUEDAY", calculate the Billing Due Date */
if tqBillScheduleForDueDate.tcBillScheduleDueDateCalType = {&BILLSCHEDULEDUEDATE-MTHDELAYDUEDAY} then do:
if ilCheckHoliday = yes then do:
<M-62 run NextWorkingDay
(input iiCompanyId (iiCompanyId),
input Date(viMonth, viDay, viYear) (itInputDate),
output otBillDueDate (otOutputDate),
output oiReturnStatus (oiReturnStatus)) in BBill>
end.
else assign otBillDueDate = Date(viMonth, viDay, viYear).
end.
/* If it is "LATESTINVDUEDAY" and itFilterRefDateTo has value, API simply assign Billing Due Date with FilterRefDateTo */
else if itFilterRefDateTo <> ? then assign otBillDueDate = itFilterRefDateTo.
/* If it is "LATESTINVDUEDAY" and itFilterRefDateTo has no value, API simply assign Billing Due Date with input date */
else assign otBillDueDate = vtInputDate.
end. /* end for each tqBillScheduleForDueDate */
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 = "ApiGetBillingDueDate".
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.apigetbillingduedate.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::itInvDate = <parameter value>
vhParameter::icBillScheduleCode = <parameter value>
vhParameter::iiCompanyId = <parameter value>
vhParameter::itInvDueDate = <parameter value>
vhParameter::itFilterRefDateFrom = <parameter value>
vhParameter::itFilterRefDateTo = <parameter value>
vhParameter::ilCheckHoliday = <parameter value>
vhParameter::ilIsBillDateExisting = <parameter value>.
/* 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.