Skip to content

Commit 02dee74

Browse files
committed
WUP Funding App
1 parent 044876a commit 02dee74

File tree

16 files changed

+816
-942
lines changed

16 files changed

+816
-942
lines changed

db/2025_updates.sql

Lines changed: 153 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,156 @@ VALUES(2, 'Approved', 'Approved', 1, 1),
7575
(2, 'Incomplete', 'Incomplete', 1, 3)
7676

7777

78-
ALTER TABLE sfa.status_reason ADD funding_application_type_id INT NULL REFERENCES sfa.funding_application_type(id)
78+
ALTER TABLE sfa.status_reason ADD funding_application_type_id INT NULL REFERENCES sfa.funding_application_type(id)
79+
80+
81+
82+
83+
CREATE FUNCTION [sfa].[fn_financial_coding](@disbursement_id INT)
84+
RETURNS NVARCHAR
85+
AS
86+
BEGIN
87+
DECLARE @coding NVARCHAR = '';
88+
89+
90+
SELECT @coding = CASE
91+
WHEN app.funding_application_type_id = 1 THEN rt.financial_coding
92+
WHEN app.funding_application_type_id = 2 THEN
93+
CASE WHEN CAST(JSON_VALUE(fr.json_data, '$.funding_source') AS nvarchar) = 'WDA' THEN '031-500707-0301-8888'
94+
WHEN CAST(JSON_VALUE(fr.json_data, '$.funding_source') AS nvarchar) = 'LMDA' THEN '031-500708-0301-8888'
95+
END
96+
END
97+
FROM sfa.disbursement d
98+
INNER JOIN sfa.funding_request fr ON fr.id = d.funding_request_id
99+
LEFT OUTER JOIN sfa.application a1 ON a1.id = fr.application_id
100+
LEFT OUTER JOIN sfa.funding_application a2 ON a2.id = fr.funding_application_id
101+
CROSS APPLY (
102+
SELECT
103+
COALESCE(a2.funding_application_type_id, 1) AS funding_application_type_id
104+
) AS app
105+
INNER JOIN sfa.request_type rt ON rt.id = fr.request_type_id
106+
WHERE d.id = @disbursement_id;
107+
108+
RETURN @coding;
109+
END;
110+
111+
112+
ALTER FUNCTION [sfa].[get_records_for_cheque_req_dat_file](
113+
@issue_date_str DATE,
114+
@serial_no INT
115+
)
116+
RETURNS TABLE
117+
AS
118+
RETURN
119+
SELECT
120+
'1' + ( LEFT(LTRIM(ISNULL(CAST(d.financial_batch_id_year AS NVARCHAR(2)), '00')+ '-' + ISNULL(CAST(d.financial_batch_id AS NVARCHAR(10)), '00') ) + REPLICATE(' ', 12) , 12)) +
121+
SPACE(30) + ' ' + '0000000' + '000000000000000' + '0' + FORMAT(CAST(@issue_date_str AS DATE), 'yyyyMMdd') + '0' + '03 ' + 'CAD ' +
122+
'0000000000000' + '0000000000000' + ' ' + '1' + ' ' + '0000000000000' + '0000000000000' + ' ' + ' '
123+
AS record1,
124+
'2'+ LEFT(s.vendor_id + REPLICATE(' ', 12), 12) + '03 ' + '000000000' +
125+
( LEFT(LTRIM(ISNULL(CAST(d.financial_batch_id_year AS NVARCHAR(2)), '00')+ '-' + ISNULL(CAST(d.financial_batch_id AS NVARCHAR(10)), '00') ) + REPLICATE(' ', 12) , 12))+
126+
LEFT(CASE WHEN app.student_number IS NULL THEN 'Yukon Student'
127+
ELSE app.student_number
128+
END + REPLICATE(' ', 22) ,
129+
22) +
130+
'EX'+ 'RE'+ 'CAD '+ ' '+
131+
'0'+ FORMAT(CAST(@issue_date_str AS DATE), 'yyyyMMdd')+ '0'+ '000000000'+ ' '+ ' '+
132+
' '+ '0 '+
133+
RIGHT(REPLICATE('0', 15)+ replace(CONVERT(VARCHAR, ABS(COALESCE(d.disbursed_amount, 0)), 128), '.', ''), 15) +
134+
REPLICATE(' ', 30) + ' '+ '0' + COALESCE(FORMAT(d.due_date, 'yyyyMMdd'), '') + '000000000'+
135+
'000000000000000'+ '0'+ '000000000000000'+ '0'+ '000000000000000'+ '0'+
136+
'000000000000000'+ '0'+ '000000000000000'+ '000000000000000'+ '0'+
137+
-- '0000000000000'+' '+ 'TDCAD '+ ' '+ ' '+ ' '+
138+
'0000000000000'+' '+ ' '+ ' '+ ' '+ ' '+
139+
' '+ ' '
140+
-- + '1' -- change 0 to 1 for sep payment - Lidwien January 2008, Jira SFA 199
141+
+ '1' -- change 1 to 0 for sep payment - Lidwien 2020-08-25 as per Sharon for SFA EFT
142+
+ ' '+ ' '+
143+
--decode(institution_pck.get_institution_code_fct(history_detail.institution_id),'BUAA','G','S')+ -- Changed else condition from ' ' to 'S' Lidwien February 2009, Jira SFA 258
144+
-- 'S'+ -- adjusted special handling code to always be S as per Sheila, 2014-01-29 Lidwien SFA-362
145+
' '+ -- adjusted special handling code to always be space as optional, for NEW EFT no longer required, 2020-08-25 Lidwien
146+
'0000000000000'+ '0000000000000'+ '0000000000000'+ '0000000000000'
147+
-- + 'C' -- change space to C for cheque payment type - Lidwien January 2008, Jira SFA 199
148+
+ ' ' -- change C to space for cheque payment type - for NEW EFT no longer required, 2020-08-25 Lidwien
149+
+'000000000'+ '9990206016050 '+ ' '+
150+
REPLICATE(' ', 22) + '000000000'+ 'CTL-YUKON '+ '0'+ FORMAT(CAST(@issue_date_str AS DATE), 'yyyyMMdd') +
151+
'0'+ FORMAT(CAST(@issue_date_str AS DATE), 'yyyyMMdd')+ '000000000'+ '000000000'+ ' '+ ' '+ '000000000000000'+
152+
'0'+ ' '+ '000000000000000'+ '0'+ ' '+ '000000000000000'+ '0'+
153+
' '+ '000000000000000'+ '0'+ ' '+ '000000000'+ '0'+ FORMAT(CAST(@issue_date_str AS DATE), 'yyyyMMdd')+ '000000000'+
154+
'000000000000000'+ ' '+ '000000000000000'+ '0'+ '1'+ 'N'+ '2'+ '0'+ FORMAT(CAST(@issue_date_str AS DATE), 'yyyyMMdd')+
155+
' '+ ' '+ ' '+ REPLICATE(' ', 25) + ' '+
156+
'0'+ ' '+ ' '
157+
as record2, -- Voucher Header (VOH)
158+
'3'+ LEFT(s.vendor_id + REPLICATE(' ', 12), 12) + '03 '+ '000000000'+
159+
'00001' +( LEFT(LTRIM(ISNULL(CAST(d.financial_batch_id_year AS NVARCHAR(2)), '00')+ '-' + ISNULL(CAST(d.financial_batch_id AS NVARCHAR(10)), '00') ) + REPLICATE(' ', 12) , 12))+
160+
LEFT(
161+
CASE WHEN app.student_number IS NULL THEN 'Yukon Student'
162+
ELSE app.student_number
163+
END + REPLICATE(' ', 22) ,
164+
22)
165+
+ ' ' +
166+
RIGHT(REPLICATE('0', 15)+ replace(CONVERT(VARCHAR, ABS(COALESCE(d.disbursed_amount, 0)), 128), '.', ''), 15) +
167+
RIGHT(REPLICATE('0', 15)+ replace(CONVERT(VARCHAR, ABS(COALESCE(d.disbursed_amount, 0)), 128), '.', ''), 15) +
168+
' ' + REPLICATE(' ', 20) + '000000000000000' + ' ' + '0' + '000000000000000' + '0' +
169+
'000000000000000' + '0' + '000000000000000' + '0' + '000000000000000'+ '0' + '000000000000000' +
170+
' ' + ' ' + ' ' + ' ' + ' ' + ' ' +
171+
' ' + '000' + '00000' + '000000000' + '000000000' + '000000000' + ' ' + ' ' +
172+
' ' + ' ' + ' ' + ' ' + ' '+ ' ' + '000000000000000' + '0' + ' ' + '000000000000000' +
173+
'0' + ' ' + '000000000000000' + '0' + ' ' + '000000000000000' + '0' + ' ' +
174+
' ' + ' ' + ' ' + REPLICATE(' ', 22) + ' ' + '000000000000000' + '0' + ' '+REPLICATE(' ',245)
175+
as record3, -- Voucher Line Record -- (VOL)
176+
'4'+ LEFT(s.vendor_id + REPLICATE(' ', 12), 12) + '03 '+ '000000000'
177+
+'00001' + '00001'
178+
+( LEFT(LTRIM(ISNULL(CAST(d.financial_batch_id_year AS NVARCHAR(2)), '00')+ '-' + ISNULL(CAST(d.financial_batch_id AS NVARCHAR(10)), '00') ) + REPLICATE(' ', 12) , 12))+LEFT(
179+
CASE WHEN app.student_number IS NULL THEN 'Yukon Student'
180+
ELSE app.student_number
181+
END + REPLICATE(' ', 22) ,
182+
22)
183+
+ (LEFT(ISNULL(sfa.fn_financial_coding(d.id), '') + REPLICATE(' ', 45) , 45)) +'03 ' +
184+
RIGHT(REPLICATE('0', 15)+ replace(CONVERT(VARCHAR, ABS(COALESCE(d.disbursed_amount, 0)), 128), '.', ''), 15)
185+
+' ' + ' ' + ' '
186+
+ CASE WHEN d.tax_year IS NULL THEN ''
187+
ELSE (LEFT(LTRIM(d.tax_year) + REPLICATE(' ', 16) , 16))
188+
END
189+
+ '000000000000000'
190+
+' ' + ' ' + ' '+REPLICATE(' ', 573)
191+
as record4,
192+
d.financial_batch_id_year,
193+
d.financial_batch_id,
194+
s.vendor_id
195+
-- Voucher Distribution (VOD)
196+
FROM sfa.request_type rt
197+
INNER JOIN sfa.funding_request fr ON rt.id = fr.request_type_id
198+
INNER JOIN sfa.disbursement d ON fr.id = d.funding_request_id
199+
LEFT JOIN sfa.application a1 ON a1.id = fr.application_id
200+
LEFT JOIN sfa.funding_application a2 ON a2.id = fr.funding_application_id
201+
CROSS APPLY (
202+
SELECT
203+
COALESCE(a1.id, a2.student_id) AS id,
204+
COALESCE(a1.student_id, a2.student_id) AS student_id,
205+
COALESCE(a1.student_number, '') as student_number
206+
-- Add other columns you need from either table
207+
) AS app
208+
INNER JOIN sfa.student s ON s.id = app.student_id
209+
WHERE NOT s.vendor_id IS NULL
210+
AND d.disbursed_amount > 0
211+
AND d.disbursement_type_id = 1
212+
AND NOT d.due_date IS NULL
213+
AND d.financial_batch_run_date = @issue_date_str
214+
AND d.financial_batch_serial_no = @serial_no
215+
AND (
216+
CASE WHEN rt.batch_group_id = 5 THEN
217+
CASE
218+
WHEN fr.yea_request_type = 1 THEN 3
219+
WHEN fr.yea_request_type = 2 THEN 4
220+
ELSE 1
221+
END
222+
WHEN rt.batch_group_id = 1 THEN sfa.get_batch_group_id_fct(fr.id)
223+
ELSE rt.batch_group_id
224+
END
225+
) = 3
226+
-- LOKINGFOR
227+
-- ORDER BY d.financial_batch_id_year, d.financial_batch_id, s.vendor_id;
228+
229+
230+
INSERT INTO sfa.disbursement_type (description, is_active) VALUES ('Cheque - LMDA', 1), ('Cheque - WDA', 1)

src/api/repositories/cheque_req_list/cheque-req-list-repository.ts

Lines changed: 80 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export class ChequeReqList extends BaseRepository {
4949
records =
5050
(await this.getInfoFileDAT(issueDate, serial_no_p || 0)) ?? []; //cheque_req_export;
5151
pdfData = await this.getPDFData(issueDate, serial_no_p || 0, false);
52+
5253
batchTotal = await this.getBatchTotal(
5354
issueDate,
5455
serial_no_p || 0,
@@ -98,94 +99,86 @@ export class ChequeReqList extends BaseRepository {
9899
isSigned: boolean
99100
): Promise<any> {
100101
try {
101-
const pdfData = await this.mainDb
102-
.select(
103-
"s.id AS student_id",
104-
"app.id AS application_id",
105-
"rt.description AS funding_type",
106-
"d.financial_batch_id_year",
107-
"d.financial_batch_id",
108-
this.mainDb.raw(`
109-
CASE
110-
WHEN rt.batch_group_id = 5 THEN
111-
CASE
112-
WHEN fr.yea_request_type = 1 THEN 3
113-
WHEN fr.yea_request_type = 2 THEN 4
114-
ELSE 1
115-
END
116-
WHEN rt.batch_group_id = 1 THEN
117-
sfa.get_batch_group_id_fct(fr.id)
118-
ELSE rt.batch_group_id
119-
END AS bg_id
120-
`),
121-
this.mainDb.raw(`
122-
REPLACE(
123-
ISNULL(
124-
CAST(rt.batch_group_id AS VARCHAR(10)),
125-
ISNULL(
126-
CAST(CASE WHEN fr.yea_request_type = 1 THEN 3
127-
WHEN fr.yea_request_type = 2 THEN 4
128-
ELSE 1
129-
END AS VARCHAR(10)),
130-
CAST(sfa.get_batch_group_id_fct(fr.id) AS VARCHAR(10))
131-
)
132-
) + RIGHT('0000' +
133-
CAST(d.financial_batch_id_year AS VARCHAR(4)), 2) + '-' +
134-
CAST(d.financial_batch_id AS VARCHAR(10)),
135-
' ',
136-
''
137-
) AS batch_id
138-
`),
139-
"fr.request_type_id",
140-
"rt.financial_coding",
141-
this.mainDb.raw(
142-
`COALESCE(p.first_name , '') + ' ' + COALESCE(p.last_name, '') AS name`
143-
),
144-
"s.vendor_id",
145-
this.mainDb.raw("FORMAT(disbursed_amount, 'C') AS disbursed_amount"),
146-
this.mainDb.raw(
147-
`CASE WHEN app.student_number IS NULL THEN 'Yukon Student' ELSE app.student_number END AS invoice_id`
148-
),
149-
this.mainDb.raw(
150-
"UPPER(FORMAT(d.due_date, 'yyyy MMM dd')) AS due_date"
151-
),
152-
"app.id",
153-
this.mainDb.raw("'S' as SPEC_HAND"),
154-
"d.tax_year",
155-
this.mainDb.raw(
156-
"UPPER(FORMAT(d.financial_batch_run_date, 'yyyy MMM dd')) AS invoice_date"
102+
const pdfData = await this.mainDb.raw(
103+
`SELECT
104+
s.id AS student_id,
105+
app.id AS application_id,
106+
rt.description AS funding_type,
107+
d.financial_batch_id_year,
108+
d.financial_batch_id,
109+
CASE
110+
WHEN rt.batch_group_id = 5 THEN
111+
CASE
112+
WHEN fr.yea_request_type = 1 THEN 3
113+
WHEN fr.yea_request_type = 2 THEN 4
114+
ELSE 1
115+
END
116+
WHEN rt.batch_group_id = 1 THEN
117+
sfa.get_batch_group_id_fct(fr.id)
118+
ELSE rt.batch_group_id
119+
END AS bg_id,
120+
REPLACE(
121+
ISNULL(
122+
CAST(rt.batch_group_id AS VARCHAR(10)),
123+
ISNULL(
124+
CAST(CASE WHEN fr.yea_request_type = 1 THEN 3
125+
WHEN fr.yea_request_type = 2 THEN 4
126+
ELSE 1
127+
END AS VARCHAR(10)),
128+
CAST(sfa.get_batch_group_id_fct(fr.id) AS VARCHAR(10))
129+
)
130+
) + RIGHT('0000' +
131+
CAST(d.financial_batch_id_year AS VARCHAR(4)), 2) + '-' +
132+
CAST(d.financial_batch_id AS VARCHAR(10)),
133+
' ',
134+
''
135+
) AS batch_id,
136+
fr.request_type_id,
137+
sfa.fn_financial_coding(d.id) AS financial_coding,
138+
COALESCE(p.first_name, '') + ' ' + COALESCE(p.last_name, '') AS name,
139+
s.vendor_id,
140+
FORMAT(d.disbursed_amount, 'C') AS disbursed_amount,
141+
CASE WHEN app.student_number IS NULL THEN 'Yukon Student' ELSE app.student_number END AS invoice_id,
142+
UPPER(FORMAT(d.due_date, 'yyyy MMM dd')) AS due_date,
143+
app.id,
144+
'S' as SPEC_HAND,
145+
d.tax_year,
146+
UPPER(FORMAT(d.financial_batch_run_date, 'yyyy MMM dd')) AS invoice_date
147+
FROM sfa.funding_request AS fr
148+
JOIN sfa.request_type AS rt ON rt.id = fr.request_type_id
149+
JOIN sfa.disbursement AS d ON fr.id = d.funding_request_id
150+
LEFT JOIN sfa.application a1 ON a1.id = fr.application_id
151+
LEFT JOIN sfa.funding_application a2 ON a2.id = fr.funding_application_id
152+
CROSS APPLY (
153+
SELECT
154+
COALESCE(a1.id, a2.student_id) AS id,
155+
COALESCE(a1.student_id, a2.student_id) AS student_id,
156+
COALESCE(a1.student_number, '') as student_number
157+
-- Add other columns you need from either table
158+
) AS app
159+
JOIN sfa.student AS s ON app.student_id = s.id
160+
JOIN sfa.person AS p ON s.person_id = p.id
161+
WHERE d.financial_batch_run_date = ?
162+
AND d.financial_batch_serial_no = ?
163+
AND d.due_date IS NOT NULL
164+
AND (
165+
? = 0 OR
166+
(
167+
CASE WHEN rt.batch_group_id = 5 THEN
168+
CASE
169+
WHEN fr.yea_request_type = 1 THEN 3
170+
WHEN fr.yea_request_type = 2 THEN 4
171+
ELSE 1
172+
END
173+
WHEN rt.batch_group_id = 1 THEN sfa.get_batch_group_id_fct(fr.id)
174+
ELSE rt.batch_group_id
175+
END
176+
) = 3
157177
)
158-
)
159-
.from("sfa.funding_request AS fr")
160-
.join("sfa.request_type AS rt", "rt.id", "=", "fr.request_type_id")
161-
.join("sfa.disbursement AS d", "fr.id", "=", "d.funding_request_id")
162-
.join("sfa.application AS app", "fr.application_id", "=", "app.id")
163-
.join("sfa.student AS s", "app.student_id", "=", "s.id")
164-
.join("SFA.person AS p", "s.person_id", "=", "p.id")
165-
.where("d.financial_batch_run_date", "=", issueDate)
166-
.where("d.financial_batch_serial_no", "=", serialNo)
167-
.whereNotNull("d.due_date")
168-
.andWhere(
169-
isSigned
170-
? this.mainDb.raw(`
171-
(
172-
CASE WHEN rt.batch_group_id = 5 THEN
173-
CASE
174-
WHEN fr.yea_request_type = 1 THEN 3
175-
WHEN fr.yea_request_type = 2 THEN 4
176-
ELSE 1
177-
END
178-
WHEN rt.batch_group_id = 1 THEN sfa.get_batch_group_id_fct(fr.id)
179-
ELSE rt.batch_group_id
180-
END
181-
) = 3`)
182-
: this.mainDb.raw("1 = 1")
183-
)
184-
.orderBy("s.vendor_id")
185-
.orderBy("p.last_name")
186-
.orderBy("d.financial_batch_id_year")
187-
.orderBy("d.financial_batch_id")
188-
.orderBy("p.first_name");
178+
ORDER BY s.vendor_id, p.last_name, d.financial_batch_id_year, d.financial_batch_id, p.first_name;
179+
`,
180+
[issueDate, serialNo, isSigned ? 1 : 0]
181+
);
189182

190183
if (pdfData.length) {
191184
const groupByBatchId = _.groupBy(pdfData, "financial_batch_id");
@@ -435,7 +428,6 @@ export class ChequeReqList extends BaseRepository {
435428
SELECT * FROM sfa.get_records_for_cheque_req_dat_file('${issueDate}', ${serial_no}) AS t1
436429
ORDER BY t1.financial_batch_id_year, t1.financial_batch_id, t1.vendor_id;
437430
`); //recordsForDATFile
438-
439431
return records;
440432
} catch (error) {
441433
console.log(error);

src/api/routes/admin/funding-application/funding-application-router.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,6 @@ fundingApplicationRouter.put(
157157
.where({ id: parseInt(id) })
158158
.first();
159159

160-
console.log("Updating funding application ID:", id, "with data:", body);
161-
162160
if (fundingApp) {
163161
let application_data = fundingApp.application_data ?? "{}";
164162
let dataObj = JSON.parse(application_data);
@@ -174,8 +172,6 @@ fundingApplicationRouter.put(
174172
}
175173
}
176174

177-
console.log("Existing", dataObj);
178-
179175
// Merge existing application_data with new data
180176
dataObj = { ...dataObj, ...body.application_data };
181177
body.application_data = JSON.stringify(dataObj);
@@ -186,12 +182,6 @@ fundingApplicationRouter.put(
186182
updated_at: new Date(),
187183
};
188184

189-
console.log(
190-
"Final updated data for funding application ID:",
191-
id,
192-
updatedData
193-
);
194-
195185
await db("sfa.funding_application")
196186
.where({ id: parseInt(id) })
197187
.update(updatedData);

0 commit comments

Comments
 (0)