-
Notifications
You must be signed in to change notification settings - Fork 0
Sfi 2199 subscribe to submitted payment requests #4
Changes from 70 commits
f8445f6
5945a9a
02753e1
33075f1
d963235
ae7f04b
9f4eba8
c6e9f05
2cbce74
0d543c0
78efaa8
2f95ca4
4c7b075
2745534
005c851
c55bf36
bef23a3
7b72ddb
7a5f247
c5406ca
b87df37
85d6a22
f2fe3cb
f02d83f
c9aa039
feec69d
152c52b
e7adf42
fd4db12
51fa0db
8373381
8700d3e
09388cd
19f4e5b
79491e6
da5ec85
7cbeb21
140f420
d40813b
ee60119
447008e
283e89b
6ed9497
216d401
764abc6
a16d4b5
8d4fdde
41c92d6
3559e18
066b7da
de9f2f8
d1e867f
0d5fbdf
101e2d2
fd3eac2
88b29a6
e826c2e
df77fa5
34b1e05
c8caaee
5118483
abeaec9
691a31b
f51d662
ca5eee8
9e69e1c
c543d54
e6fb470
1b4233e
3769200
ba8fbb7
4ebf1c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
SFI_GROSS_VALUE_AP: 'SOS273' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
GBP: 'GBP' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
RP00: 'RP00' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
GROSS_VALUE: 'G00 - Gross value of claim' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
DRD10: 'DRD10' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
ARABLE_SOIL_INTRODUCTORY: 'Arable and horticultural soils: Introductory' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
ARABLE_SOIL_INTRODUCTORY: '80001' | ||
} |
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 | ||
}] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
AP: 'AP', | ||
AR: 'AR' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
FIRST_PAYMENT: 1, | ||
POST_PAYMENT_ADJUSTMENT: 2 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
QUARTERLY: 'Q4', | ||
MONTHLY: 'M12', | ||
THREE_DAY_QUARTERLY: 'T4' | ||
} |
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 | ||
} |
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' | ||
} |
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 | ||
}] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
SFI: 'SFI' | ||
} |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const processSubmitPaymentRequest = require('./process-submit-payment-request') | ||
|
||
module.exports = processSubmitPaymentRequest |
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is still an issue because the 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 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) { | ||
marctemp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 |
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 |
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 |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const reverseEngineerInvoiceNumber = (invoiceNumber) => { | ||
return `original${invoiceNumber.slice(0, 5)}` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
|
||
module.exports = reverseEngineerInvoiceNumber |
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> |
There was a problem hiding this comment.
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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, recognised this myself