Skip to content
This repository has been archived by the owner on Feb 7, 2025. It is now read-only.

Sfi 2199 subscribe to submitted payment requests #4

Merged
merged 72 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
f8445f6
bumpin version
marctemp Jul 28, 2022
5945a9a
added organisations db tbl
marctemp Jul 28, 2022
02753e1
SFI-2199 Subscribe to submitted payment requests
AbidemiAdio Jul 28, 2022
33075f1
basic db schemas added
marctemp Jul 29, 2022
d963235
adding explicit nullable fks
marctemp Jul 29, 2022
ae7f04b
Added Data Model
AbidemiAdio Aug 1, 2022
9f4eba8
pk-fk setup
marctemp Aug 1, 2022
c6e9f05
added snyk ignores
marctemp Aug 1, 2022
2cbce74
agreementNumber in claim is same as PR, therefore droped in claim table
marctemp Aug 1, 2022
0d543c0
duplicate invoiceNumber, dropped from claims
marctemp Aug 1, 2022
78efaa8
reference is varchar(9), removing comment
marctemp Aug 1, 2022
2f95ca4
schemes renamed to fundings
marctemp Aug 1, 2022
4c7b075
referenceId and correlationId using same UUID datatype
marctemp Aug 1, 2022
2745534
adjusting decimal for areaclaimed to match BPS
marctemp Aug 1, 2022
005c851
adding scheme table
marctemp Aug 1, 2022
c55bf36
split address into distinct gov uk appoved parts
marctemp Aug 1, 2022
bef23a3
added invoiceNumber table
marctemp Aug 2, 2022
7b72ddb
added addressLine3 to org
marctemp Aug 2, 2022
7a5f247
letting John have this one
marctemp Aug 2, 2022
c5406ca
Merge branch 'main' into SFI-2199-subscribe-to-submitted-payment-requ…
marctemp Aug 2, 2022
b87df37
moved sequilze object outside function scope
marctemp Aug 2, 2022
85d6a22
missed db issues
marctemp Aug 2, 2022
f2fe3cb
bumpin version
marctemp Aug 2, 2022
f02d83f
saving progress
marctemp Aug 2, 2022
c9aa039
fixing typo issues
marctemp Aug 2, 2022
feec69d
bumpin version
marctemp Aug 2, 2022
152c52b
Merge branch 'main' into pay-2195-add-constructor-db
marctemp Aug 2, 2022
e7adf42
bumpin version
marctemp Aug 2, 2022
fd4db12
renaming claims to calculations
marctemp Aug 2, 2022
51fa0db
funding to calculations now many to many
marctemp Aug 2, 2022
8373381
Merge branch 'pay-2195-add-constructor-db' into SFI-2199-subscribe-to…
marctemp Aug 2, 2022
8700d3e
fixing typo
marctemp Aug 2, 2022
09388cd
Merge branch 'pay-2195-add-constructor-db' into SFI-2199-subscribe-to…
marctemp Aug 2, 2022
19f4e5b
simple savedown successful
marctemp Aug 2, 2022
79491e6
wip
marctemp Aug 2, 2022
da5ec85
Merge branch 'main' into SFI-2199-subscribe-to-submitted-payment-requ…
marctemp Aug 3, 2022
7cbeb21
renaming process pr to process submit pr
marctemp Aug 3, 2022
140f420
bumpin
marctemp Aug 3, 2022
d40813b
modified areaClaimed to match data
marctemp Aug 3, 2022
ee60119
tests added
marctemp Aug 3, 2022
447008e
added throwing processPaymentRequest test case
marctemp Aug 3, 2022
283e89b
bumpin version
marctemp Aug 3, 2022
6ed9497
Merge branch 'main' into SFI-2199-subscribe-to-submitted-payment-requ…
marctemp Aug 3, 2022
216d401
added placeholder reverseEngineerInvoiceNumber func tests
marctemp Aug 3, 2022
764abc6
fixing changelog typo
marctemp Aug 3, 2022
a16d4b5
fixed standard isssues
marctemp Aug 3, 2022
8d4fdde
removed unness deletion of obj key
marctemp Aug 4, 2022
41c92d6
reverse obj expansion ovverride
marctemp Aug 4, 2022
3559e18
hidious camel naming replaced with kebab
marctemp Aug 4, 2022
066b7da
hidious camel naming replaced with kebab
marctemp Aug 4, 2022
de9f2f8
adding constants and mock constants
marctemp Aug 4, 2022
d1e867f
fixing wrong reverse eng in test descriptions
marctemp Aug 4, 2022
0d5fbdf
resetMock debate resolved
marctemp Aug 4, 2022
101e2d2
fixed internal erro throwing test issue, added for all
marctemp Aug 4, 2022
fd3eac2
added check tht msg not marked as complete if fails to process
marctemp Aug 4, 2022
88b29a6
using sequilize create returning newly created obj
marctemp Aug 4, 2022
e826c2e
added received to allow logic to find most recent of "same" prs
marctemp Aug 4, 2022
df77fa5
renaming schedules to match tech debt names
marctemp Aug 4, 2022
34b1e05
using ref Id rather than invoice number to look for duplicates
marctemp Aug 4, 2022
c8caaee
changes made
marctemp Aug 5, 2022
5118483
added async for processing pr
marctemp Aug 8, 2022
abeaec9
save returning explicit
marctemp Aug 9, 2022
691a31b
forgotten import name change
marctemp Aug 9, 2022
f51d662
added schemes id and name
marctemp Aug 10, 2022
ca5eee8
adding scheme id and scheme code enums to async
marctemp Aug 10, 2022
9e69e1c
mising closing changeset tag
marctemp Aug 10, 2022
c543d54
adding int tests
marctemp Aug 10, 2022
e6fb470
added constants used in mocks
marctemp Aug 10, 2022
1b4233e
adding int tests to ensure all scheme ids are accepted
marctemp Aug 10, 2022
3769200
removing db saved records before int tests
marctemp Aug 10, 2022
ba8fbb7
using status in dup check
marctemp Aug 15, 2022
4ebf1c9
adding missing schemeId to paymentRequests model
marctemp Aug 17, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/constants/account-codes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
SFI_GROSS_VALUE_AP: 'SOS273'
}
3 changes: 3 additions & 0 deletions app/constants/currencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
GBP: 'GBP'
}
3 changes: 3 additions & 0 deletions app/constants/delivery-bodies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
RP00: 'RP00'
}
3 changes: 3 additions & 0 deletions app/constants/descriptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
GROSS_VALUE: 'G00 - Gross value of claim'
}
3 changes: 3 additions & 0 deletions app/constants/fund-codes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
DRD10: 'DRD10'
}
3 changes: 3 additions & 0 deletions app/constants/funding-code-names.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
ARABLE_SOIL_INTRODUCTORY: 'Arable and horticultural soils: Introductory'
}
3 changes: 3 additions & 0 deletions app/constants/funding-codes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
ARABLE_SOIL_INTRODUCTORY: '80001'
}
7 changes: 7 additions & 0 deletions app/constants/funding-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { ARABLE_SOIL_INTRODUCTORY: ARABLE_SOIL_INTRODUCTORY_CODE } = require('./funding-codes')
const { ARABLE_SOIL_INTRODUCTORY } = require('./funding-code-names')

module.exports = [{
fundingCode: ARABLE_SOIL_INTRODUCTORY_CODE,
name: ARABLE_SOIL_INTRODUCTORY
}]
4 changes: 4 additions & 0 deletions app/constants/ledgers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
AP: 'AP',
AR: 'AR'
}
4 changes: 4 additions & 0 deletions app/constants/payment-request-numbers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
FIRST_PAYMENT: 1,
POST_PAYMENT_ADJUSTMENT: 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably fine for now but may be a limitation if we have tests that cover three payment requests as 3 is still a post payment adjustment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, recognised this myself

}
5 changes: 5 additions & 0 deletions app/constants/schedules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
QUARTERLY: 'Q4',
MONTHLY: 'M12',
THREE_DAY_QUARTERLY: 'T4'
}
7 changes: 7 additions & 0 deletions app/constants/scheme-ids.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
SFI: 1,
SFI_PILOT: 2,
LUMP_SUMS: 3,
LNR: 4,
VET_VISITS: 5
}
7 changes: 7 additions & 0 deletions app/constants/scheme-names.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
LNR: 'LNR',
LUMP_SUMS: 'Lump Sums',
SFI: 'SFI',
SFI_PILOT: 'SFIP',
VET_VISITS: 'Vet Visits'
}
36 changes: 36 additions & 0 deletions app/constants/schemes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const {
LNR: LNR_ID,
LUMP_SUMS: LUMP_SUMS_ID,
SFI: SFI_ID,
SFI_PILOT: SFI_PILOT_ID,
VET_VISITS: VET_VISITS_ID
} = require('./scheme-ids')

const {
LNR,
LUMP_SUMS,
SFI,
SFI_PILOT,
VET_VISITS
} = require('./scheme-names')

module.exports = [{
schemeId: LNR_ID,
name: LNR
},
{
schemeId: LUMP_SUMS_ID,
name: LUMP_SUMS
},
{
schemeId: SFI_ID,
name: SFI
},
{
schemeId: SFI_PILOT_ID,
name: SFI_PILOT
},
{
schemeId: VET_VISITS_ID,
name: VET_VISITS
}]
3 changes: 3 additions & 0 deletions app/constants/source-systems.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
SFI: 'SFI'
}
2 changes: 1 addition & 1 deletion app/data/models/payment-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ module.exports = (sequelize, DataTypes) => {
dueDate: DataTypes.STRING,
invoiceNumber: DataTypes.STRING,
marketingYear: DataTypes.INTEGER,
received: DataTypes.DATE,
referenceId: DataTypes.UUID,
schedule: DataTypes.STRING,
sitiAgriInvoiceNumber: DataTypes.STRING,
submitted: DataTypes.DATE,
value: DataTypes.INTEGER
},
Expand Down
13 changes: 13 additions & 0 deletions app/inbound/get-payment-request-by-reference-id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const db = require('../data')

const getPaymentRequestByReferenceId = async (referenceId, transaction) => {
return db.paymentRequest.findOne({
transaction,
lock: true,
where: {
referenceId
}
})
}

module.exports = getPaymentRequestByReferenceId
3 changes: 3 additions & 0 deletions app/inbound/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const processSubmitPaymentRequest = require('./process-submit-payment-request')

module.exports = processSubmitPaymentRequest
27 changes: 27 additions & 0 deletions app/inbound/process-submit-payment-request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const db = require('../data')

const getPaymentRequestByReferenceId = require('./get-payment-request-by-reference-id')
const saveInvoiceNumber = require('./save-invoice-number')
const savePaymentRequest = require('./save-payment-request')
const saveInvoiceLines = require('./save-invoice-lines')

const processSubmitPaymentRequest = async (paymentRequest) => {
const transaction = await db.sequelize.transaction()
try {
const existingPaymentRequest = await getPaymentRequestByReferenceId(paymentRequest.referenceId, transaction)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is still an issue because the reference number will mostly be the same for both the processing and submit messages so whichever got there first would prevent the other being saved.

It's only changed if we need to reprocess a payment request from processing again. ie DAX has rejected it.

What if we included the status of the payment request in the paymentRequest table and used that in the duplicate check?

eg rather than "if this reference exists, it's a duplicate" we have "if this reference exists and it's a submitted payment request" it's a duplicate?

if (existingPaymentRequest) {
console.info(`Duplicate payment request received, skipping ${existingPaymentRequest.referenceId}`)
await transaction.rollback()
} else {
await saveInvoiceNumber(paymentRequest.invoiceNumber, transaction)
const savedPaymentRequest = await savePaymentRequest(paymentRequest, transaction)
await saveInvoiceLines(paymentRequest.invoiceLines, savedPaymentRequest.paymentRequestId, transaction)
await transaction.commit()
}
} catch (error) {
await transaction.rollback()
throw (error)
}
}

module.exports = processSubmitPaymentRequest
11 changes: 11 additions & 0 deletions app/inbound/save-invoice-lines.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const db = require('../data')

const saveInvoiceLines = async (invoiceLines, paymentRequestId, transaction) => {
for (const invoiceLine of invoiceLines) {
delete invoiceLine.invoiceLineId
invoiceLine.fundingCode = invoiceLine.schemeCode
await db.invoiceLine.create({ ...invoiceLine, paymentRequestId }, { transaction })
}
}

module.exports = saveInvoiceLines
13 changes: 13 additions & 0 deletions app/inbound/save-invoice-number.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const db = require('../data')
const reverseEngineerInvoiceNumber = require('../processing/reverse-engineer-invoice-number')

const saveInvoiceNumber = async (invoiceNumber, transaction) => {
await db.invoiceNumber.create({
invoiceNumber,
originalInvoiceNumber: reverseEngineerInvoiceNumber(invoiceNumber)
},
{ transaction }
)
}

module.exports = saveInvoiceNumber
8 changes: 8 additions & 0 deletions app/inbound/save-payment-request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const db = require('../data')

const savePaymentRequest = async (paymentRequest, transaction) => {
delete paymentRequest.paymentRequestId
return db.paymentRequest.create({ ...paymentRequest, received: new Date() }, { transaction })
}

module.exports = savePaymentRequest
6 changes: 6 additions & 0 deletions app/messaging/process-submit-message.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const util = require('util')
const processSubmitPaymentRequest = require('../inbound')

const processSubmitMessage = async (message, receiver) => {
try {
const paymentRequest = message.body
console.log('Payment request submitted:', util.inspect(paymentRequest, false, null, true))
await processSubmitPaymentRequest(paymentRequest)
await receiver.completeMessage(message)
} catch (err) {
console.error('Unable to process submit message:', err)
Expand Down
5 changes: 5 additions & 0 deletions app/processing/reverse-engineer-invoice-number.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const reverseEngineerInvoiceNumber = (invoiceNumber) => {
return `original${invoiceNumber.slice(0, 5)}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is just a placeholder so this isn't a suggestion for change, more just a snippet of wisdom.

Because we're subscribing to all submitted payments, we're going to pass Vets, Lump Sums, Pilot and SFI through this. All the Siti Agri ones we'll be able to reverse engineer back to the SITI invoice to match to DWH but with slightly different values for what you have as original. Vets doesn't have an original invoice number as they don't provide us with one. We create it for them.

}

module.exports = reverseEngineerInvoiceNumber
64 changes: 64 additions & 0 deletions changelog/db.changelog-1.2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-3.9.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.9.xsd">
<changeSet author="Marc Templeton" id="1">
<tagDatabase tag="v1.1.0" />
</changeSet>
<changeSet author="Marc Templeton" id="2">
<modifyDataType tableName="fundings" columnName="areaClaimed" newDataType="DECIMAL(11,4)" />
<rollback>
<modifyDataType tableName="fundings" columnName="areaClaimed" newDataType="DECIMAL(19,4)" />
</rollback>
</changeSet>
<changeSet author="Marc Templeton" id="3">
<insert tableName="schemes">
<column name="schemeId" value="1" />
<column name="name" value="SFI" />
</insert>
</changeSet>
<changeSet author="Marc Templeton" id="4">
<insert tableName="schemes">
<column name="schemeId" value="2" />
<column name="name" value="SFI Pilot" />
</insert>
</changeSet>
<changeSet author="Marc Templeton" id="5">
<insert tableName="schemes">
<column name="schemeId" value="3" />
<column name="name" value="Lump Sums" />
</insert>
</changeSet>
<changeSet author="Marc Templeton" id="6">
<insert tableName="schemes">
<column name="schemeId" value="4" />
<column name="name" value="LNR" />
</insert>
</changeSet>
<changeSet author="Marc Templeton" id="7">
<insert tableName="schemes">
<column name="schemeId" value="5" />
<column name="name" value="Vet Visits" />
</insert>
</changeSet>
<changeSet author="Marc Templeton" id="8">
<modifyDataType tableName="fundingOptions" columnName="name" newDataType="VARCHAR(60)" />
<rollback>
<modifyDataType tableName="fundingOptions" columnName="name" newDataType="VARCHAR(30)" />
</rollback>
</changeSet>
<changeSet author="Marc Templeton" id="9">
<insert tableName="fundingOptions">
<column name="fundingCode" value="80001" />
<column name="name" value="Arable and horticultural soils: Introductory" />
</insert>
</changeSet>
<changeSet author="Marc Templeton" id="10">
<addColumn tableName="paymentRequests">
<column afterColumn="marketingYear" name="received" type="TIMESTAMP" />
</addColumn>
</changeSet>
<changeSet author="Marc Templeton" id="11">
<dropColumn tableName="paymentRequests">
<column name="sitiAgriInvoiceNumber" />
</dropColumn>
</changeSet>
</databaseChangeLog>
1 change: 1 addition & 0 deletions changelog/db.changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
<include file="changelog/db.changelog-1.0.xml"/>
<include file="changelog/db.changelog-1.1.xml"/>
<include file="changelog/db.changelog-1.2.xml"/>
</databaseChangeLog>
Loading