Generate Statements API
This functionality adds new billing statements (invoices) in the system, based on API requests received from other FintechOS solutions - such as Policy Admin or from other systems. On the FTOS_PYMT_Statement entity, for the newly generated invoice, the API response populates the following attributes:
-
Statement Id.
-
Statement Reference.
-
Statement Premium Amount.
-
Total Taxes.
-
Statement Amount.
-
Statement Due Date.
-
Payment Type Id.
The system registers a new invoice, containing installments from three different policies.
let policiesData = {
policies: [{
"policyNo": "80000863",
"installmentNo": 7
},
{
"policyNo": "80000862",
"installmentNo": 11
},
{
"policyNo": "80000861",
"installmentNo": 2
}
],
statementDueDate: "2021-10-30"
}
ebs.callActionByNameAsync('FTOS_PYMT_StatementsGenerationAPI', policiesData).then(function(e) {
console.log(e)
});
The following is the list of data parameters included in the request:
Parameter | Description |
---|---|
policies | An array with the policy request details: policyNo and installmentNo . |
statementDueDate | The invoice invariant date, when the payment is due (string). |
The following is an example of a response:
{
UIResult: {
…},
Message: null,
IsSuccess: true,
ClientScript: null,
Serialized: '{"UIResult":{"NavigateToEntityPage":false,"Navigat…ientScript":null,"Serialized":null,"ErrorCode":0}',
…
}
ClientScript: null
ErrorCode: 0
IsSuccess: true
Message: null
Serialized: {
UIResult: {
NavigateToEntityPage: false,
NavigateToEntityPageOnEdit: false,
NavigateToEntityFormName: null,
NavigateToEntityName: null,
NavigateToEntityId: null,
NavigateToEntityInsertDefaults: null,
NavigateToUrl: null,
DownloadFile: null,
ReloadPage: false,
Message: null,
IsSuccess: false,
Data: {
"isSuccess": true,
"result": [{
"statementId": "280f5f20-676c-4f74-b1c4-121d9bd42ec4",
"statementNo": "REF0003383",
"statementPremiumAmount": 10.73,
"totalTaxes": 1.07,
"statementAmount": 10.73,
"paymentTypeId": "180921d6-345a-4d83-a37b-278569008e7c",
"dueDate": {
"invariantDate": "2021-11-11"
}
},
{
"statementId": "0894a6f8-69b0-467c-9991-6b6f22f19d33",
"statementNo": "REF0003384",
"statementPremiumAmount": 10.73,
"totalTaxes": 1.07,
"statementAmount": 10.73,
"paymentTypeId": "180921d6-345a-4d83-a37b-278569008e7c",
"dueDate": {
"invariantDate": "2021-11-11"
}
}
],
"errorMessage": null,
"errorCode": null
},
NavigateToPageNo: null
},
Message: null,
IsSuccess: true,
ClientScript: null,
Serialized: null,
ErrorCode: 0
}
UIResult:
Data: {
isSuccess: null,
errorMessage: null,
errorCode: null,
result: {
…}
}
DownloadFile: null
IsSuccess: false
Message: null
NavigateToEntityFormName: null
NavigateToEntityId: null
NavigateToEntityInsertDefaults: null
NavigateToEntityName: null
NavigateToEntityPage: false
NavigateToEntityPageOnEdit: false
NavigateToPageNo: null
NavigateToUrl: null
ReloadPage: false[[Prototype]]: Object[[Prototype]]: Object
Response description:
Key | Description |
---|---|
errorCode | Error code. |
isSuccess | Marks weather the request is successful or not. |
errorMessage | Error message. |
result | Either null or an array of objects, containing the following:
|
The following are the error messages that can be encountered during the API invoice generation process:
Code | Text | Description |
---|---|---|
ERR.BL.50101 | Invalid request! | No data provided or the policyData doesn’t have the policies property. |
ERR.BL.50102 | Invalid request! PolicyNo or InstallmentNo can not be empty! |
This error appears when the provided data fields are empty. |
ERR.BL.50103 | Invalid request! Policy {0} inserted multiple times! |
This error appears when the same PolicyNo is included multiple times inside the policies array. |
ERR.BL.50104 | Invalid request! One or more policies do not have valid installments! |
A valid policy installment is one that has the installment amount greater than 0, the installment due date not null and the installment business status OnTime. |
ERR.BL.50105 | The policies from the request can not be included in the same statement! | There is a mismatch between one (or some) of the requested policies and the policy grouping rule. For generating a multiple policies invoice, policies need to have the same contractor, payment type, currency, WO product configurations, and due date. |
ERR.BL.50106 | Invalid request! Policy {0} is in {1} status! |
This error appears when the invoice generation API request is made for a policy that does not have a valid status. |
ERR.BL.50107 | The due date of the statement can not be from the past! | This error appears when the provided data field is filled with a past statement due date. |
ERR.BL.50108 | Invalid request! Policy {0} does not exist! |
The requested policy is not registered in the system. |
ERR.BL.50109 | The statement can not be generated for policies that have broker collection as payment type! | The invoice cannot be generated for policies that have broker collection as payment type. |
The FTOS_PYMT_StatementsGenerationAPI endpoint is used to run the FTOS_PYMT_StatementsGenerationAPI server automation script.
FTOS_PYMT_StatementsGenerationAPI - Script called with a data object.
This script executes the following:
-
Validates the request data object.
-
Searches, verifies and returns the policies that are eligible for invoice generation.
-
If all the necessary conditions are met, it uses the details gathered to generate the new invoice.
The script contains the following functions:
This function validates the data object. For example if an invoice due date is provided, it must be greater than the current day. (If the invoice due date is not included in the request, the system assigns to it the installment due date's value.) After checking the payment type for each policy, this function calls the getStatementGenerationRules
function from the FTOS_PYMT_Statements server automation script library in order to identify whether there is any single rule payment type amongst a multiple policies grouping. If a mismatch is found, the system throws an error (see error ERR.BL.50105, above).
Input parameters: policiesData
- The request object.
Output parameters: rez
- The result object.
This function verifies whether the policy is registered in the system, has the installment amount greater than 0, has the installment due date not null, has the installment business status OnTime. Next, the function returns an array of objects with all policies found, that are suitable for invoice generation.
This function also verifies if the request is not duplicated. If it finds that the details of the same policy are duplicated inside the same request, it throws and error.
Input parameters: policiesData
- The request object.
Output parameters: getPolicies
/ rez
- Depending on the query result or validation.
This function verifies whether the policy has a valid status - Proposal, Issued, Enforced or Suspended and returns a result containing the policy Id, policy No, and policy status.
Input parameters: policyNo
(string) - The policy number.
Output parameters: policy
- The query result.
For the case of generating an invoice for more than one policy, this function verifies whether the request complies to the multiple policies inclusion rule - that is the policies need to have the same contractor, same payment type, same currency, same WO product configurations, and the same due date.
Input parameters: policies
- An array of objects containing the policies details.
Output parameters: rez
- An object containing the result.
Based on the single rule name, this function returns all payment types assigned to it.
Input parameters: N/A.
Output parameters: singlePmtTypeArr
- An array with single rule payment types Ids.
This function calls the FTOS_PYMT_StatementsAPI script library and, by using all the gathered data, it generates the billing statement (the invoice) for the selected policy (or policies).
Input parameters:
-
policies
- An array of objects containing details from the policies for which invoices are to be generated. -
statementDate
(string) - The date of the invoice generation.
Output parameters: rez
- An object containing the result of the operation - expected invoice.
The FTOS_PYMT_StatementsAPI library validates and creates new invoices (statements) based on the received data from the FTOS_PYMT_StatementsGenerationAPI script (see above).This function also calls the generateGroupedProducts(sgDay)
and getStatementGenerationRules
functions from FTOS_PYMT_Statements server automation script library in order to validate and generate the invoices.
From this library, the StatementGeneration script is used. This script validates and creates new invoices based on the request object received from the FTOS_PYMT_StatementsGenerationAPI script. This script contains the following functions:
This function prepares the rules for generating invoices, as follows:
-
multiplePolicies - multiple policies are included in the same invoice, based on the same contractor, currency, payment type, product and due date.
-
singlePolicies - only one policy is included in the invoice.
Input parameters:
-
invariantDate
- maxDate. -
accountId
-null
. -
sgDay
(integer) - The number of days in advance before the payment's due date. -
policiesArrAPI
- The array of policies for which invoices are going to be generated. -
statementDueDateAPI
- Thedate
in string format ornull
.
Output parameters: returnArr
- An array of objects with the newly generated invoices, containing:
-
Statement Id,
-
Statement Reference,
-
Statement Premium Amount,
-
Total Taxes,
-
Statement Amount,
-
Statement Due Date,
-
Payment Type Id.
This functions gathers and filters all the installments according to the rules, payment type and grouped products. Next, it creates the new invoice (statement) and invoice details (statement details).
Input parameters:
-
insertStatementObj
- An object containing the following dataruleName
(string),groupByPolicy
(boolean),groupByQuote
(boolean) andpaymentTypeArr
(array of payment types). -
installmentNo
-null
. -
groupedProductsArr
- An array of objects containing the following:minDate
- currentDate,maxDate
- maxDate andproductIds
- [], an empty array. -
nonBroker
-null
.
Output parameters: returnArr
- An array of objects with the newly created invoices.
This function gets the Ids of the payment types, based on each payment type name.
Input parameters: paymentTypeArr
- An array containing the payment type names.
Output parameters: paymentTypeIdArr
- An array containing payment type Ids.
Based on policyNo
and installemntNo
this function makes a query to check if the installment has any invoice details already created. Next, it checks the installment due date period, based on the groupedProducts
or invariantDate
.
Input parameters:
-
policyNo
- The number of the selected policy. -
installmentNo
- The number of the policy installment, that needs to be paid. -
groupedProducts
- Grouping rule. -
invariantDate
- The date when the payment for the installment is due.
Output parameters: groupedProducts
/ false
if query result has values or not.
This function is used to insert a new invoice based on an array returned by query from the getStatementByPaymentType
function.
Input parameters:
-
installmentGroupResult
- array returned by query fromgetStatementByPaymentType
function -
insertStatementObj
- An object containing the following dataruleName
(string),groupByPolicy
(boolean),groupByQuote
(boolean) andpaymentTypeArr
(array of payment types).
Output parameters: returnObj
- The object containing the invoice.
Based on the invoice Id, this function returns the number of the invoice - statementNo
.
Input parameters: statementId
- The Id of the invoice.
Output parameters: statementNo
- The number of the invoice.
This function gets all the installment data necessary for invoice generation. Next, it changes the status of the invoice into Generated.
Input parameters:
-
installmentGroupResult
- An array returned by query fromgetStatementByPaymentType
function. -
insertStatementObj
- An object containing the following dataruleName
(string),groupByPolicy
(boolean),groupByQuote
(boolean) andpaymentTypeArr
(array of payment types). -
statementId
- The Id of the invoice.
Output parameters: N/A.
Based on the installment list, this function can generate a new statementDetail
(invoice). When so, it updates the Statement Due Date, on the installment. Next, this function changes the installment business status into Statement Issued.
Input parameters:
-
installmentsList
- An array of installments objects. -
statementId
- The Id of the invoice.
Output parameters: statementDetailArr
- An array containing the Id of the statementDetail/s.