Skip to content

Commit

Permalink
Add Some Manual Finance Scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Peyton-McKee committed May 29, 2024
1 parent 1e09de2 commit bf193e6
Showing 1 changed file with 78 additions and 1 deletion.
79 changes: 78 additions & 1 deletion src/backend/src/prisma/manual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
*/

import prisma from './prisma';
import { WBS_Element_Status } from '@prisma/client';
import { Reimbursement_Status_Type, WBS_Element_Status } from '@prisma/client';
import { calculateEndDate } from 'shared';
import { writeFileSync } from 'fs';

/* eslint-disable @typescript-eslint/no-unused-vars */

Expand Down Expand Up @@ -154,6 +155,82 @@ export const migrateToCheckableDescBullets = async () => {
});
};

/**
* Download All Reimbursement Requests with reimbursement status to csv
*/
const downloadReimbursementRequests = async () => {
const rrs = await prisma.reimbursement_Request.findMany({
where: {
dateDeleted: null
},
include: { reimbursementStatuses: true }
});

const csv = rrs
.map(
(rr) =>
`${rr.saboId},${rr.totalCost},${rr.reimbursementStatuses
.map((reimbursementStatus) => reimbursementStatus.type)
.join(',')}`
)
.join('\n');

// if file doesnt exist create it
writeFileSync('./reimbursements.csv', csv, 'utf-8');
};

const getTotalAmountOwedForCashAndBudgetForSubmittedToSaboAndPendingFinanceTeam = async () => {
const reimbursementRequests = await prisma.reimbursement_Request.findMany({
where: {
dateDeleted: null
},
include: {
reimbursementStatuses: true
}
});

const submittedToSabo = reimbursementRequests.filter(
(rr) => rr.reimbursementStatuses[rr.reimbursementStatuses.length - 1].type === Reimbursement_Status_Type.SABO_SUBMITTED
);

const pendingFinance = reimbursementRequests.filter(
(rr) => rr.reimbursementStatuses[rr.reimbursementStatuses.length - 1].type === Reimbursement_Status_Type.PENDING_FINANCE
);

const totalAmountOwedForCashSabo = submittedToSabo.reduce((acc, curr) => {
if (curr.account === 'CASH') {
return acc + curr.totalCost / 100;
}
return 0;
}, 0);

const totalAmountOwedForBudgetSabo = submittedToSabo.reduce((acc, curr) => {
if (curr.account === 'BUDGET') {
return acc + curr.totalCost / 100;
}
return 0;
}, 0);

const totalAmountOwedForCashFinance = pendingFinance.reduce((acc, curr) => {
if (curr.account === 'CASH') {
return acc + curr.totalCost / 100;
}
return 0;
}, 0);

const totalAmountOwedForBudgetFinance = pendingFinance.reduce((acc, curr) => {
if (curr.account === 'BUDGET') {
return acc + curr.totalCost / 100;
}
return 0;
}, 0);

console.log('Total amount owed for cash submitted to SABO:', totalAmountOwedForCashSabo);
console.log('Total amount owed for budget submitted to SABO:', totalAmountOwedForBudgetSabo);
console.log('Total amount owed for cash pending finance team:', totalAmountOwedForCashFinance);
console.log('Total amount owed for budget pending finance team:', totalAmountOwedForBudgetFinance);
};

executeScripts()
.catch((e) => {
console.error(e);
Expand Down

0 comments on commit bf193e6

Please sign in to comment.