Skip to content

Commit d72015d

Browse files
authored
Merge pull request #399 from icefoganalytics/test
WUP Fixes
2 parents 9e8409e + ca5b5f6 commit d72015d

File tree

7 files changed

+239
-103
lines changed

7 files changed

+239
-103
lines changed

db/2025_updates.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,5 @@ VALUES (2, 'Cancelled', 'Cancelled', 1, 4),
247247
INSERT INTO sfa.registered_trade (name) VALUES
248248
('Electrical'), ('Plumbing')
249249

250-
update sfa.status set funding_application_type_id = 1 where funding_application_type_id is null
250+
update sfa.status set funding_application_type_id = 1 where funding_application_type_id is null
251+
update sfa.status_reason set funding_application_type_id = 1 where funding_application_type_id is null

src/api/models/application.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,15 +815,26 @@ export function cleanNumberOptional(input: any): number | null {
815815

816816
export function cleanNumber(input: any): number {
817817
let isNegative = false;
818-
input = (`${input}` ?? "0").trim();
818+
input = `${input ?? "0"}`.trim().toLowerCase();
819819

820820
if (input.indexOf("(") >= 0 || input.indexOf("-") == 0) {
821821
isNegative = true;
822822
input = input.replace("(", "").replace(")", "").trim();
823823
}
824824

825825
let num = Math.min(
826-
Number(Number(input.replace("$", "").replace(/,/g, "").replace(/-/g, "").trim()).toFixed(2)),
826+
Number(
827+
Number(
828+
input
829+
.replace("$", "")
830+
.replace("cad", "")
831+
.replace("usd", "")
832+
.replace("ca", "")
833+
.replace(/,/g, "")
834+
.replace(/-/g, "")
835+
.trim()
836+
).toFixed(2)
837+
),
827838
SQL_MAXVALUE
828839
);
829840

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

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ export class ChequeReqList extends BaseRepository {
103103
`SELECT
104104
s.id AS student_id,
105105
app.id AS application_id,
106-
rt.description AS funding_type,
106+
CASE WHEN d.disbursement_type_id = 11 THEN CONCAT(rt.description, ' (WDA)')
107+
WHEN d.disbursement_type_id = 10 THEN CONCAT(rt.description, ' (LMDA)')
108+
ELSE rt.description END AS funding_type,
107109
d.financial_batch_id_year,
108110
d.financial_batch_id,
109111
CASE
@@ -181,9 +183,11 @@ export class ChequeReqList extends BaseRepository {
181183
);
182184

183185
if (pdfData.length) {
184-
const groupByBatchId = _.groupBy(pdfData, "financial_batch_id");
185-
186-
return Object.values(groupByBatchId);
186+
// Sort by financial_batch_id and financial_coding, then group by composite key
187+
const sorted = _.orderBy(pdfData, ['financial_batch_id', 'financial_coding']);
188+
return Object.values(
189+
_.groupBy(sorted, (item) => `${item.financial_batch_id}_${item.financial_coding}`)
190+
);
187191
} else {
188192
return [];
189193
}
@@ -199,37 +203,47 @@ export class ChequeReqList extends BaseRepository {
199203
isSigned: boolean
200204
): Promise<any> {
201205
try {
202-
const batchTotal = await this.mainDb
203-
.select(
204-
"d.financial_batch_id",
205-
this.mainDb.raw(`FORMAT(SUM(d.disbursed_amount), 'C') as total`)
206-
)
207-
.from("sfa.funding_request AS fr")
208-
.join("sfa.request_type AS rt", "rt.id", "=", "fr.request_type_id")
209-
.join("sfa.disbursement AS d", "fr.id", "=", "d.funding_request_id")
210-
.join("sfa.application AS app", "fr.application_id", "=", "app.id")
211-
.join("sfa.student AS s", "app.student_id", "=", "s.id")
212-
.join("SFA.person AS p", "s.person_id", "=", "p.id")
213-
.where("d.financial_batch_run_date", "=", issueDate)
214-
.where("d.financial_batch_serial_no", "=", serialNo)
215-
.whereNotNull("d.due_date")
216-
.andWhere(
217-
isSigned
218-
? this.mainDb.raw(`
219-
(
220-
CASE WHEN rt.batch_group_id = 5 THEN
221-
CASE
222-
WHEN fr.yea_request_type = 1 THEN 3
223-
WHEN fr.yea_request_type = 2 THEN 4
224-
ELSE 1
225-
END
226-
WHEN rt.batch_group_id = 1 THEN sfa.get_batch_group_id_fct(fr.id)
227-
ELSE rt.batch_group_id
228-
END
229-
) = 3`)
230-
: this.mainDb.raw("1 = 1")
231-
)
232-
.groupBy("d.financial_batch_id");
206+
const batchTotal = await this.mainDb.raw(
207+
`
208+
SELECT
209+
d.financial_batch_id,
210+
sfa.fn_financial_coding(d.id) AS financial_coding,
211+
FORMAT(SUM(d.disbursed_amount), 'C') as total
212+
FROM sfa.funding_request AS fr
213+
JOIN sfa.request_type AS rt ON rt.id = fr.request_type_id
214+
JOIN sfa.disbursement AS d ON fr.id = d.funding_request_id
215+
LEFT JOIN sfa.application a1 ON a1.id = fr.application_id
216+
LEFT JOIN sfa.funding_application a2 ON a2.id = fr.funding_application_id
217+
CROSS APPLY (
218+
SELECT
219+
COALESCE(a1.id, a2.student_id) AS id,
220+
COALESCE(a1.student_id, a2.student_id) AS student_id,
221+
COALESCE(a1.student_number, '') as student_number
222+
) AS app
223+
JOIN sfa.student AS s ON app.student_id = s.id
224+
JOIN sfa.person AS p ON s.person_id = p.id
225+
WHERE d.financial_batch_run_date = ?
226+
AND d.financial_batch_serial_no = ?
227+
AND d.due_date IS NOT NULL
228+
AND (
229+
? = 0 OR
230+
(
231+
CASE WHEN rt.batch_group_id = 5 THEN
232+
CASE
233+
WHEN fr.yea_request_type = 1 THEN 3
234+
WHEN fr.yea_request_type = 2 THEN 4
235+
ELSE 1
236+
END
237+
WHEN rt.batch_group_id = 1 THEN sfa.get_batch_group_id_fct(fr.id)
238+
ELSE rt.batch_group_id
239+
END
240+
) = 3
241+
)
242+
GROUP BY d.financial_batch_id, sfa.fn_financial_coding(d.id)
243+
ORDER BY 1, 2;
244+
`,
245+
[issueDate, serialNo, isSigned ? 1 : 0]
246+
);
233247

234248
return batchTotal || [];
235249
} catch (error) {

src/api/services/admin/assessments/wup-skills-for-success-service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class WUPSkillForSuccessService {
2727
this.parent.assessment.student_contribution_review = "NO";
2828
this.parent.assessment.spouse_contribution_review = "NO";
2929
this.parent.assessment.parent_contribution_review = "NO";
30-
30+
3131
if (reload) {
3232
this.parent.assessment.classes_start_date =
3333
this.parent.fundingRequest.json_data.classes_start_date;
@@ -40,11 +40,11 @@ export class WUPSkillForSuccessService {
4040

4141
let tuition =
4242
cleanNumber(
43-
this.parent.fundingRequest.json_data.approved_tuition_amount
43+
this.parent.assessment.json_data.approved_tuition_amount
4444
) ?? 0;
4545
let textbook =
4646
cleanNumber(
47-
this.parent.fundingRequest.json_data.approved_textbook_amount
47+
this.parent.assessment.json_data.approved_textbook_amount
4848
) ?? 0;
4949

5050
// previous disbursements are for the current academic year

src/web/src/components/application/assessments/views/WUP-Apprenticeship.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,9 @@ export default {
396396
Number(
397397
input
398398
.replace("$", "")
399+
.replace("cad", "")
400+
.replace("usd", "")
401+
.replace("ca", "")
399402
.replace(/,/g, "")
400403
.replace(/-/g, "")
401404
.trim()

0 commit comments

Comments
 (0)