This repository has been archived by the owner on Feb 7, 2025. It is now read-only.
generated from DEFRA/ffc-template-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PAY-2318 Aggregate, map and build statement constructor object (#22)
* PAY-2318 Aggregate, map and build statement constructor object * Added all statement component * Implemented all PR feedback * Changes IRO PR round-1 * added getStatement unit * schedule tests added * finalised getStatement unit * added sendStatement tests * more updates IRO PR * funding code fix added * utility tests added * moving payment constants * using trunc in tests * dueDate formatted to DD/MM/YYYY * Added schema to Organisation for DWH compactibility * Remove all logs comment * Fixed ConnectionAcquireTimeoutError * Reduced splice of reversedInvoiceNumber for settlement and calculation to 7 from 8 IRO DWH data * modified for insert into schedule table * Added Total-aggregate as fundings item * Modify organisation schema to correspond with statement-data structure * Modify organisation schema to correspond with statement-data structure Co-authored-by: Marc Templeton <marcte@kainos.com>
- Loading branch information
1 parent
959a4f9
commit 0a22f80
Showing
77 changed files
with
1,641 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
const Joi = require('joi') | ||
|
||
module.exports = Joi.object({ | ||
sbi: Joi.number().integer().required(), | ||
calculationDate: Joi.date().required() | ||
calculationId: Joi.number().integer().required(), | ||
calculationDate: Joi.date().required(), | ||
invoiceNumber: Joi.string().required(), | ||
paymentRequestId: Joi.number().integer().required(), | ||
sbi: Joi.number().integer().required() | ||
}).required() |
20 changes: 20 additions & 0 deletions
20
app/processing/calculation/get-calculation-by-invoice-number.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const db = require('../../data') | ||
|
||
const getCalculationByInvoiceNumber = async (invoiceNumber, transaction) => { | ||
return db.calculation.findOne({ | ||
transaction, | ||
attributes: [ | ||
'calculationId', | ||
'calculationDate', | ||
'invoiceNumber', | ||
'paymentRequestId', | ||
'sbi' | ||
], | ||
where: { | ||
invoiceNumber | ||
}, | ||
raw: true | ||
}) | ||
} | ||
|
||
module.exports = getCalculationByInvoiceNumber |
10 changes: 7 additions & 3 deletions
10
app/processing/calculation/get-calculation-by-payment-request-id.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
app/processing/calculation/get-completed-payment-request-by-reversed-invoice-number.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const db = require('../../data') | ||
|
||
const { COMPLETED } = require('../../constants/statuses') | ||
|
||
const getCompletedPaymentRequestByReversedInvoiceNumber = async (reversedInvoiceNumber, transaction) => { | ||
return db.paymentRequest.findOne({ | ||
transaction, | ||
where: { | ||
reversedInvoiceNumber, | ||
status: COMPLETED | ||
} | ||
}) | ||
} | ||
|
||
module.exports = getCompletedPaymentRequestByReversedInvoiceNumber |
24 changes: 24 additions & 0 deletions
24
app/processing/calculation/update-calculation-payment-request-id.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const db = require('../../data') | ||
const getCalculationByInvoiceNumber = require('./get-calculation-by-invoice-number') | ||
const { reverseEngineerInvoiceNumber } = require('../../utility') | ||
|
||
const updateCalculationPaymentRequestId = async (invoiceNumber, paymentRequestId, transaction) => { | ||
const reversedInvoiceNumber = reverseEngineerInvoiceNumber(invoiceNumber) | ||
const calculation = await getCalculationByInvoiceNumber(reversedInvoiceNumber, transaction) | ||
|
||
if (calculation) { | ||
await db.calculation.update({ paymentRequestId }, { | ||
transaction, | ||
lock: true, | ||
where: { | ||
invoiceNumber: reversedInvoiceNumber | ||
} | ||
}) | ||
|
||
calculation.paymentRequestId = paymentRequestId | ||
} | ||
|
||
return calculation | ||
} | ||
|
||
module.exports = updateCalculationPaymentRequestId |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const getFundings = require('./get-fundings') | ||
|
||
module.exports = getFundings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...ocessing/invoice-line/get-positive-invoice-line-by-funding-code-and-payment-request-id.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const db = require('../../data') | ||
|
||
const getPositiveInvoiceLineByFundingCodeAndPaymentRequestId = async (fundingCode, paymentRequestId, transaction) => { | ||
return db.invoiceLine.findOne({ | ||
transaction, | ||
attributes: [ | ||
'value' | ||
], | ||
where: { | ||
paymentRequestId, | ||
fundingCode, | ||
value: { [db.Sequelize.Op.gte]: 0 } | ||
}, | ||
raw: true | ||
}) | ||
} | ||
|
||
module.exports = getPositiveInvoiceLineByFundingCodeAndPaymentRequestId |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const schema = require('./invoice-line-schema') | ||
|
||
const getPositiveInvoiceLineByFundingCodeAndPaymentRequestId = require('./get-positive-invoice-line-by-funding-code-and-payment-request-id') | ||
|
||
const QUARTER = 0.25 | ||
const MIN_PAYMENT_VALUE = 0 | ||
const DEFAULT_REDUCTION_VALUE = 0 | ||
|
||
const getPositiveInvoiceLine = async (fundingCode, paymentRequestId) => { | ||
const invoiceLine = await getPositiveInvoiceLineByFundingCodeAndPaymentRequestId(fundingCode, paymentRequestId) | ||
const result = schema.validate(invoiceLine, { | ||
abortEarly: false | ||
}) | ||
|
||
if (result.error) { | ||
throw new Error(`Payment request with paymentRequestId: ${paymentRequestId} does not have the required invoice-line data for funding code ${fundingCode} : ${result.error.message}`) | ||
} | ||
|
||
const annualValue = invoiceLine.value | ||
const quarterlyValue = annualValue > MIN_PAYMENT_VALUE ? Math.trunc(annualValue * QUARTER) : MIN_PAYMENT_VALUE | ||
const quarterlyReduction = DEFAULT_REDUCTION_VALUE | ||
const quarterlyPayment = quarterlyValue - quarterlyReduction | ||
const reductions = [] | ||
|
||
return { | ||
annualValue, | ||
quarterlyValue, | ||
quarterlyReduction, | ||
quarterlyPayment, | ||
reductions | ||
} | ||
} | ||
|
||
module.exports = getPositiveInvoiceLine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const getPositiveInvoiceLine = require('./get-positive-invoice-line') | ||
|
||
module.exports = getPositiveInvoiceLine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const Joi = require('joi') | ||
|
||
module.exports = Joi.object({ | ||
value: Joi.number().integer().min(0).required() | ||
}).required() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const db = require('../../data') | ||
|
||
const getOrganisationBySbi = async (sbi, transaction) => { | ||
return db.organisation.findOne({ | ||
transaction, | ||
attributes: [ | ||
'sbi', | ||
'addressLine1', | ||
'addressLine2', | ||
'addressLine3', | ||
'city', | ||
'county', | ||
'emailAddress', | ||
'frn', | ||
'name', | ||
'postcode' | ||
], | ||
where: { | ||
sbi | ||
}, | ||
raw: true | ||
}) | ||
} | ||
|
||
module.exports = getOrganisationBySbi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const schema = require('./organisation-schema') | ||
const getOrganisationBySbi = require('./get-organisation-by-sbi') | ||
|
||
const getOrganisation = async (sbi, transaction) => { | ||
const organisation = await getOrganisationBySbi(sbi, transaction) | ||
|
||
const result = schema.validate(organisation, { | ||
abortEarly: false | ||
}) | ||
|
||
if (result.error) { | ||
throw new Error(`Organisation with the sbi: ${sbi} does not have the required details data: ${result.error.message}`) | ||
} | ||
|
||
return { | ||
line1: organisation.addressLine1, | ||
line2: organisation.addressLine2, | ||
line3: organisation.addressLine3, | ||
line4: organisation.city, | ||
line5: organisation.county, | ||
postcode: organisation.postcode, | ||
businessName: organisation.name, | ||
email: organisation.emailAddress, | ||
frn: organisation.frn, | ||
sbi: organisation.sbi | ||
} | ||
} | ||
|
||
module.exports = getOrganisation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const getOrganisation = require('./get-organisation') | ||
|
||
module.exports = getOrganisation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const Joi = require('joi') | ||
|
||
module.exports = Joi.object({ | ||
sbi: Joi.number().integer().min(105000000).max(999999999).required(), | ||
addressLine1: Joi.string().optional(), | ||
addressLine2: Joi.string().optional(), | ||
addressLine3: Joi.string().optional(), | ||
city: Joi.string().optional(), | ||
county: Joi.string().optional(), | ||
emailAddress: Joi.string().email().required(), | ||
frn: Joi.number().integer().min(1000000000).max(9999999999).required(), | ||
name: Joi.string().required(), | ||
postcode: Joi.string().required() | ||
}).required() |
Oops, something went wrong.