Invoice Generation
Scheduled Job
The FTOS_PYMT_InsertStatement invoice statement generation job is scheduled to run every day at 3:00 AM. This job finds the installments that are eligible for the generation of new statements. This job calls the FTOS_PYMT_InsertStatementDueDate
endpoint.
Server Automation Scripts
The FTOS_PYMT_InsertStatementDueDate server side script uses the following functions:
Based on the imported library, insertStatement(maxDate,null)
is the function that handles the generation of statements.
Input parameters:
-
maxDate
: It is obtained by adjoining theinvariantDate
of the current date to thedaysBeforePolicyScheduleDueDate
parameter. This variable represents the maximum date until the policies are filtered based on installments. -
null
: accountId.
Output parameters: N/A.
Variables:
-
libFlowParameter
: import from the FTOS_PA_FlowParameter library. -
daysBeforePolicyScheduleDueDate
: based on the imported library, through thegetNoOfDaysInAdvance
function, this variable receives an integer value that is set as the SGDAY flow parameter . -
statementGenerationLib
: import from the FTOS_PYMT_Statements library.
Server Automation Script Libraries
From the FTOS_PYMT_Statements server automation script library, the following functions are used:
This function gets a JSON object from the FTOS_DFP_ProcessorSettings entity. The object contains the settings for statement processing and has the following structure:
{
"StatementsRules": {
"rulesArr": [
"multiplePolicies",
"singlePolicies",
"multiplePoliciesByQuoteMultipleNext",
"multipleFirstPoliciesByQuoteSingleNext"
],
"OP": 0,
"PayU": 0,
"PayU-on Time": 1,
"brokerCollection": 0
}
}
This function returns an array of payment types based on each Rule Name Key, from the FTOS_PYMT_StatementProcessor parameter.
This function returns an array of payment types based on each Rule Name Key for processing statements, from the FTOS_DFP_ProcessorSettings entity.
The function is used for filtering installments by payment types based on rule names (rulesArr
).
Input parameters: value
- The rule name key. For example: 0, 1, 2, ...
Output parameters: An array
of strings with the Payment Types. For example:
-
For
multiplePolicies
, an output example is ["OP", "PayU", "brokerCollection"]. -
For
singlePolicies
, an output example is ["PayU-on Time"]. -
For
multiplePoliciesByQuoteMultipleNext
andmultipleFirstPoliciesByQuoteSingleNext
, an output example is an empty array [].
This function returns an object with invariant dates: the firstDay
of last month and the lastDay
of last month, in order to help filtering the installments with brokerCollection
Payment Type .
Input parameters: N/A,
Output parameters: An object that contains the invariant values as following:
lastMonthObj = {
"firstDay": firstDay,
"lastDay": lastDay
}
This function gets the option set item Id from the months option set, based on the month number and, next, returns an object with the month Id and month name.
Input parameters: monthNo
- The month number; it can take values from 1 to 12.
Output parameters: An object that contains monthId
and monthName
.
This function returns the FTOS_PYMT_StatementMonthid primary key attribute, from the FTOS_PYMT_StatementMonth entity, based on a query that searches for the monthId
and year
. If the fetch is empty, this function inserts the current search values into the FTOS_PYMT_StatementMonth entity.
Input parameters: maxDate
- The invariant date for the statement.
Output parameters: statementMonthId
- The Id of the statement month.
This function compares objects.
Input parameters:
object1
- An object containing the specified details.
object2
- An object containing the specified details.
Output parameters: boolean.
This function compares arrays.
Input parameters:
-
a
- An array containing the specified data. -
b
- An array containing the specified data.
Output parameters: boolean.
This function gets the position of a specified array element from inside the array.
Input parameters:
-
elem
- The element to compare. -
arrEleme
- The array.
Output parameters: The element position, if found - else, null
.
This function gets the position of an array element from an array object.
Input parameters:
-
elem
- The element to compare. -
arr
- The array.
Output parameters: The element position, if found - else, null
.
This function gets the maximum date for the payment - such as the SGDAY or the last day of the month. The maximum date variable represents the maximum date until the policies are filtered based on installments.
Input parameters: days
- The maximum date for a payment.
Output parameters: InvariantDate
- The invariant date.
This function compares dates in an array of dates.
Input parameters:
-
arr
- The array of the specified dates. -
day
- The invariant date.
Output parameters: The product Id
, if the days match - else, it returns false
.
This function compares dates.
Input parameters:
-
day1
- The invariant date. -
day2
- The invariant date.
Output parameters:
The product Id
, if the days match - else, it returns false
.
This function gets all the products that are in VWDraft, VWVersion Draft and VWVersion Unapproved status and also with the writeOffId
attribute set to NoWriteOff, GenericWriteOff, or SpecificWriteOff, at the product level. Next, it filters all found products by start date and end date.
Input parameters: sgDay
- The SGDAY parameter (integer) from the processor.
Output parameters: obj
- An object containing the requested data.
This function filters for products with Specific WriteOff settings, based on their writeOffId
attibute.
Input parameters: productsArr
- An array of products.
Output parameters: productsResultArr
- An array of products that satisfy the request.
This function gets all products filtered by date and WriteOff type.
Input parameters: resultGroupedProducts
- An array containing the products.
Output parameters: resultGroupedProducts
- An array containing the products found by the fetch.
This function prepares the rules for generating the invoices, by using a loop of conditions.
Based on the chosen parameter, from the FTOS_PYMT_StatementProcessor entity, the function can trigger four types of statement generation flows:
-
multiplePolicies
: where multiple policies are included, based on the Contractor, Currency, Payment Type, Product and Due Date; -
singlePolicies
: where a single policy is included; -
multiplePoliciesByQuoteMultipleNext
: for first installments - where multiple policies are generated by the same quote or for next installments - where multiple policies are included, based on the Contractor, Currency, Payment Type and Due Date; -
multipleFirstPoliciesByQuoteSingleNext
: for first installments - where multiple policies are generated by the same quote or for next installments - where a single policy is included.
Input parameters:
-
maxDate
: The invariant date values for the statement. -
accountId
: Null.
Output parameters: N/A.
Variables:
-
rulesArr
- An array of rule names. For example: [multiplePolicies
,singlePolicies
,multiplePoliciesByQuoteMultipleNext
,multipleFirstPoliciesByQuoteSingleNext
] -
ruleName
- A string, for each rule name. For example:multiplePolicies
. -
groupByPolicy
- A boolean (true, false) value, used to group by policy. -
groupByQuote
- A boolean (true, false) value, used to group by quote. -
paymentTypeArr
- An array of payment types. For example: [OP
,PayU
,brokerCollection
]. -
groupedProducts
- An array of products.
insertStatementByPaymentType(invariantDate, accountId, ruleName, groupByPolicy, groupByQuote, paymentTypeArr, 1)
Input parameters:
-
invariantDate
- The invariant date of the statement. -
accountId
- The Id of the account. -
ruleName
- The name of the rule. -
groupByPolicy
- The boolean for grouping by policy. -
groupByQuote
- The boolean for grouping by quote. -
paymentTypeArr
- The array containing the payment types. -
installmentNo
- The installment number variable. It can take the following values:null
- for a filter without installment number,1
- for the first installment,2
- for all other installments except the first.
Output parameters: N/A.
Variables:
-
currentDate
- The current day, with the following hour format 00:00:00.000. This variable is used in statement generation for filling in theinstallmentsStartDate
andstatementDate
attributes. -
lastMonth
- An object containing the first day of last month and the last day of last month, returned by thegetLastMonth
function. -
statementMonthId
- The statementMonthid attribute from FTOS_PYMT_StatementMonth entity, returned by thegetStatementMonthId(invariantDate)
function. This variable is used in statement generation for filling in thestatementMonthId
attribute. -
libParameter
- For importing the FTOS_PA_FlowParameter library. -
brokerScope
- based on the FTOS_PA_FlowParameter imported library, this variable receives a string value from the option set item that is set as theBKSCOPE
flow parameter. -
businessStatusPolicyProposal
- The Id of Proposal status from the FTOS_INSPA_Policy entity. -
businessStatusPolicyIssued
- The Id of Issued status from the FTOS_INSPA_Policy entity. -
businessStatusPolicyEnforced
- The Id of Enforced status from the FTOS_INSPA_Policy entity. -
businessStatusPolicySuspended
- The Id of Suspended status from the FTOS_INSPA_Policy entity. -
policyPaymentTypeOPOptionSetValue
- The Id of the OP option set item from the FTOS_INSPA_PolicyPaymentType option set. -
policyPaymentTypePayUOptionSetValue
- The Id of the PayU option set item from the FTOS_INSPA_PolicyPaymentType option set. -
policyPaymentTypePayUOnTimeOptionSetValue
- The Id of the PayU-on time option set item from the FTOS_INSPA_PolicyPaymentType option set. -
policyPaymentTypeBrokerCollection
- The Id of the brokerCollection option set item from the FTOS_INSPA_PolicyPaymentType option set. -
fetchInstallmentGroup
- This fetch executes the following actions:Gets all the payment schedules (installments) from FTOS_INSQB_PaymentSchedule entity, for policies that have currency -
currencyId
is not null.Adds attributes needed for filtering from the FTOS_INSQB_PaymentScheduleDetail - the installments entity and also from the FTOS_INSPA_Policy entity.
Calculates the sum out of the following installments attributes:
installmentAmount
,paidAmount
,commissionAmount
,taxAmount
,netPremium
, from the FTOS_INSQB_PaymentScheduleDetail entity, based on the rules conditions. -
fetchInstallments
- This fetch executes the following:
Gets each filtered payment schedule found in thefetchInstallmentGroup
fetch.
Generates the statement detail according to rules and inserts the required values in the FTOS_PYMT_StatementDetail entity.
Calculates and updates the statement DueDate attribute from the FTOS_INSQB_PaymentScheduleDetail entity.
Changes the installment status in StatementIssued.
Filtering Configurations
The following are examples about how to define the filtering for the fetch needed to generate statements:
For the fetchInstallmentGroup
function, you can define the filtering for the fetch based on the following attributes:
Attributes | Conditions | Entity |
---|---|---|
accountId | Is not null. | FTOS_INSPA_Policy |
businessStatusId | Is in Proposal, Enforced, Issued or Suspended status. | FTOS_INSPA_Policy |
currencyId | Is not null. | FTOS_INSQB_PaymentSchedule |
dueDate | Is not null. | FTOS_INSQB_PaymentScheduleDetail |
hasStatementDetail | Is null or is equal with false. | FTOS_INSQB_PaymentScheduleDetail |
installmentAmount | Is grater than or equal with 0. | FTOS_INSQB_PaymentScheduleDetail |
installmentId | Is in On time status. | FTOS_PYMT_StatementDetail |
insuranceProductId | Is not null. | FTOS_INSPA_Policy |
policyPaymentTypeId | Is not an empty array. Can take one of the following values: Bank Transfer, PayU, PayU-On Time or Broker Collection. | FTOS_INSPA_Policy |
The following are the types of push rules for fetching the needed data for generating statements:
Fetch Type | Specific Conditions | Description |
---|---|---|
multiplePolicies | insuranceBroker is null | The statement is generated based on the accountId, currency, payment type and due date. Do not apply additional conditions. |
singlePolicies | group by policy | The statement is generated based on the FTOS_INSPA_Policyid attribute. |
multiplePoliciesByQuoteMultipleNext - first installment | group by quote number | The statement is generated for the multiple policies logic based on the quote number. |
multiplePoliciesByQuoteMultipleNext - next installments | insuranceBroker is null | The statement is generated based on the accountId, currency, payment type and due date. |
multipleFirstPoliciesByQuoteSingleNext - first installment | group by quote number | The statement is generated for the single policies logic based on the quote number. |
multipleFirstPoliciesByQuoteSingleNext - next installments | group by policy | The statement is generated based on the FTOS_INSPA_Policyid attribute. |
brokerConditionRules.notBrokerCollectionRules | InsuranceBrokerId is not null. The Policy Payment Type is: Bank Transfer, PayU or PayU-On Time |
The statement is generated for a Broker policy based on the InsuranceBrokerId attribute. |
brokerConditionRules.BrokerCollectionRules | InsuranceBrokerId is not null. Due Date is in the previous month. Policy Payment Type takes the Broker Collection value. |
The statement is generated for a Broker policy based on the InsuranceBrokerId attribute, on the date set by the Broker_Billing_Day_Statment_Generation parameter. |
The following is an example of an object aimed at filtering for Broker policies that do not have the Payment Type set to Broker Collection:
if (brokerConditionRulesObj.notBrokerCollectionRules == true) {
fetchInstallmentGroup.entity.join[0].entity.attributelist.push({
"name": "dueDate"
});
fetchInstallmentGroup.entity.join[0].entity.join[1].entity.attributelist.push({
"name": "AccountId"
});
if (brokerConditionRulesObj.brokerScopeDueInstallments = true) {
fetchInstallmentGroup.where.expressionlist.push({
"type": "and",
"conditionlist": [{
"first": "e.policyPaymentTypeId",
"type": "notequals",
"second": "val(" + policyPaymentTypeBrokerCollection + ")"
}]
});
}
fetchInstallmentGroup.where.expressionlist.push({
"type": "and",
"conditionlist": [{
"first": "b.dueDate",
"type": "lte",
"second": "val(" + invariantDate + ")"
}]
});
}
if (brokerConditionRulesObj.pushInsuranceBroker == true) {
fetchInstallmentGroup.entity.join[0].entity.join[1].entity.attributelist.push({
"name": "insuranceBrokerId"
});
}
After defining the structure of the fetch object, use it as a parameter for the function responsible for getting the results. Next, store the result in a variable:
var installmentGroupResult = getByQuery(fetchInstallmentGroup)
For each installment of installmentGroupResult
, take the values needed and store them into statementInsertOb
j object in order to generate the statement:
var statementId = insert('FTOS_PYMT_Statement', statementInsertObj)
Based on the statementId
, this changes the business status into Generated.