From 7dc1606379bc174df3ceef260c4f4684192e06cb Mon Sep 17 00:00:00 2001 From: Harin Date: Tue, 25 Jul 2023 22:43:26 -0700 Subject: [PATCH] Billing PDF modifications and bug fixes --- backend/src/controllers/costCentreController.js | 1 + backend/src/models/costCentre.js | 3 ++- database/init/cost_centers.sql | 1 + database/procedures/billableProc.sql | 6 ++++-- database/procedures/costCenterProc.sql | 4 ++++ frontend/src/components/CostCenterTable/index.js | 10 +++++++++- .../GenerateInvoice/InvoiceTemplate/index.js | 15 +++++++-------- frontend/src/components/InvoiceTable/index.js | 4 ++-- frontend/src/redux/api/costcenterApi.js | 1 + frontend/src/redux/saga/costCenterSaga.js | 10 +++++++++- frontend/src/screens/invoice/invoice-preview.js | 6 +++++- frontend/src/screens/login-form/index.js | 4 ++-- frontend/src/screens/signup-form/index.js | 2 +- 13 files changed, 48 insertions(+), 19 deletions(-) diff --git a/backend/src/controllers/costCentreController.js b/backend/src/controllers/costCentreController.js index 59571ce2..b911dd46 100644 --- a/backend/src/controllers/costCentreController.js +++ b/backend/src/controllers/costCentreController.js @@ -33,6 +33,7 @@ export default class CostCentreController { const costCenterData = { cost_center_id: req.body.cost_center_id, cost_center_name: req.body.cost_center_name, + cost_center_client_name: req.body.cost_center_client_name, cost_center_investigator: req.body.cost_center_investigator, cost_center_contact: req.body.cost_center_contact, cost_center_email: req.body.cost_center_email, diff --git a/backend/src/models/costCentre.js b/backend/src/models/costCentre.js index 7260b604..554afc89 100644 --- a/backend/src/models/costCentre.js +++ b/backend/src/models/costCentre.js @@ -55,10 +55,11 @@ export class CostCentre { insertCostCentre(newCostCentre, result) { con.query( - "CALL save_cost_center(?, ?, ?, ?, ?, ?, ?)", + "CALL save_cost_center(?, ?, ?, ?, ?, ?, ?, ?)", [ newCostCentre.cost_center_id, newCostCentre.cost_center_name, + newCostCentre.cost_center_client_name, newCostCentre.cost_center_investigator, newCostCentre.cost_center_contact, newCostCentre.cost_center_email, diff --git a/database/init/cost_centers.sql b/database/init/cost_centers.sql index 514f2868..2e630cb3 100644 --- a/database/init/cost_centers.sql +++ b/database/init/cost_centers.sql @@ -11,6 +11,7 @@ BEGIN CREATE TABLE `cost_centers` ( cost_center_id VARCHAR(50) NOT NULL, cost_center_name VARCHAR(50), + cost_center_client_name VARCHAR(255), cost_center_investigator VARCHAR(255), cost_center_contact VARCHAR(255), cost_center_email VARCHAR(255), diff --git a/database/procedures/billableProc.sql b/database/procedures/billableProc.sql index 060bddde..a68a02c1 100644 --- a/database/procedures/billableProc.sql +++ b/database/procedures/billableProc.sql @@ -76,11 +76,12 @@ END $$ CREATE PROCEDURE `load_billable` () BEGIN - SELECT billable.*, u.username, o.organization_name, t.task_id, st.fk_task_id, st.subtask_id, t.task_state, st.subtask_state FROM billable + SELECT billable.*, u.username, o.organization_name, p.project_name, t.task_id, st.fk_task_id, st.subtask_id, t.task_state, st.subtask_state FROM billable LEFT JOIN tasks t on t.task_uuid = billable.task_uuid LEFT JOIN subtasks st on st.subtask_uuid = billable.task_uuid LEFT JOIN users u on u.user_id = billable.created_by LEFT JOIN organizations o on o.organization_id = u.fk_organization_id + LEFT JOIN projects p on p.project_id = billable.fk_project_id WHERE billable.billed = 0 AND (t.task_state != "archived" OR t.task_state IS NULL) AND (st.subtask_state != "archived" OR st.subtask_state IS NULL); @@ -100,13 +101,14 @@ CREATE PROCEDURE `load_billable_with_filter` ( ) BEGIN - SELECT billable.*, u.username, o.organization_name, t.task_id, st.fk_task_id, st.subtask_id, t.task_state, st.subtask_state FROM billable + SELECT billable.*, u.username, o.organization_name, p.project_name, t.task_id, st.fk_task_id, st.subtask_id, t.task_state, st.subtask_state FROM billable LEFT JOIN tasks t on t.task_uuid = billable.task_uuid LEFT JOIN subtasks st on st.subtask_uuid = billable.task_uuid LEFT JOIN costcenter_assignments ca on ca.fk_project_id = billable.fk_project_id LEFT JOIN project_assignments pa on pa.fk_project_id = billable.fk_project_id LEFT JOIN users u on u.user_id = billable.created_by LEFT JOIN organizations o on o.organization_id = u.fk_organization_id + LEFT JOIN projects p on p.project_id = billable.fk_project_id WHERE (name = _service_name OR _service_name IS NULL OR _service_name = '') AND (ca.fk_cost_center_id = _costcenter_id OR _costcenter_id IS NULL OR _costcenter_id = '') AND (billable.fk_project_id = _project_id OR _project_id IS NULL OR _project_id = '') diff --git a/database/procedures/costCenterProc.sql b/database/procedures/costCenterProc.sql index a421893c..c7bfa35b 100644 --- a/database/procedures/costCenterProc.sql +++ b/database/procedures/costCenterProc.sql @@ -9,6 +9,7 @@ DELIMITER $$ CREATE PROCEDURE `save_cost_center` ( IN `_cost_center_id` VARCHAR(50), IN `_cost_center_name` VARCHAR(50), + IN `_cost_center_client_name` VARCHAR(255), IN `_cost_center_investigator` VARCHAR(255), IN `_cost_center_contact` VARCHAR(255), IN `_cost_center_email` VARCHAR(255), @@ -18,6 +19,7 @@ CREATE PROCEDURE `save_cost_center` ( INSERT INTO `cost_centers` ( `cost_center_id`, `cost_center_name`, + `cost_center_client_name`, `cost_center_investigator`, `cost_center_contact`, `cost_center_email`, @@ -28,6 +30,7 @@ VALUES ( `_cost_center_id`, `_cost_center_name`, + `_cost_center_client_name`, `_cost_center_investigator`, `_cost_center_contact`, `_cost_center_email`, @@ -36,6 +39,7 @@ VALUES ) ON DUPLICATE KEY UPDATE cost_centers.cost_center_id=_cost_center_id, cost_centers.cost_center_name=_cost_center_name, + cost_centers.cost_center_client_name=_cost_center_client_name, cost_centers.cost_center_investigator=_cost_center_investigator, cost_centers.cost_center_contact=_cost_center_contact, cost_centers.cost_center_email=_cost_center_email, diff --git a/frontend/src/components/CostCenterTable/index.js b/frontend/src/components/CostCenterTable/index.js index a141c84f..4a578425 100644 --- a/frontend/src/components/CostCenterTable/index.js +++ b/frontend/src/components/CostCenterTable/index.js @@ -21,7 +21,14 @@ const CostCenterTable = () => { dataIndex: "cost_center_name", key: "cost_center_name", editable: true, - width: "20%", + width: "15%", + }, + { + title: "Client Name", + dataIndex: "cost_center_client_name", + key: "cost_center_client_name", + editable: true, + width: "10%", }, { title: "Principal Investigator", @@ -114,6 +121,7 @@ const CostCenterTable = () => { const newData = { cost_center_id: uuid(), cost_center_name: "New Cost Center", + cost_center_client_name: "New Client", cost_center_investigator: "New Investigator", cost_center_contact: "New Contact", cost_center_email: "New Email", diff --git a/frontend/src/components/GenerateInvoice/InvoiceTemplate/index.js b/frontend/src/components/GenerateInvoice/InvoiceTemplate/index.js index e07b7dc3..7ed07a68 100644 --- a/frontend/src/components/GenerateInvoice/InvoiceTemplate/index.js +++ b/frontend/src/components/GenerateInvoice/InvoiceTemplate/index.js @@ -54,12 +54,11 @@ const InvoiceTemplate = ({ customer, costcenterMap, invoicNum }) => {

Billed to:

- Client Name: {customer.cost_center_name} -
- Client Address: {customer.cost_center_address}
- Contact: {customer.cost_center_contact}
- Department: {customer.cost_center_type}
- Worktag/Email: {customer.cost_center_email}
+ Client Name: {customer.cost_center_client_name}
+ Address/Department: {customer.cost_center_address}
+ Billing Contact: {customer.cost_center_contact}
+ Email: {customer.cost_center_email}
+ Cost Center/Worktag: {customer.cost_center_name}

@@ -74,6 +73,7 @@ const InvoiceTemplate = ({ customer, costcenterMap, invoicNum }) => {

Project Details:

Project ID: {customer.fk_project_id}
+ Project Name: {customer.project_name}
Principal Investigator: {customer.cost_center_investigator}

@@ -87,7 +87,7 @@ const InvoiceTemplate = ({ customer, costcenterMap, invoicNum }) => { return costcenterMap[billable.fk_project_id] === customer.cost_center_id })} /> - +
@@ -155,7 +155,6 @@ function InvoiceDetails({ billingData }) { {billingData.map((invoiceItem, index) => { - console.log(invoiceItem); return ( diff --git a/frontend/src/components/InvoiceTable/index.js b/frontend/src/components/InvoiceTable/index.js index f8a2b14c..996ddfd6 100644 --- a/frontend/src/components/InvoiceTable/index.js +++ b/frontend/src/components/InvoiceTable/index.js @@ -34,8 +34,8 @@ const InvoiceTable = () => { }, { title: "Project", - dataIndex: "fk_project_id", - key: "fk_project_id", + dataIndex: "project_name", + key: "project_name", editable: false, }, { diff --git a/frontend/src/redux/api/costcenterApi.js b/frontend/src/redux/api/costcenterApi.js index cacac84f..20f4b220 100644 --- a/frontend/src/redux/api/costcenterApi.js +++ b/frontend/src/redux/api/costcenterApi.js @@ -83,6 +83,7 @@ export const postCostCenterApi = async (payload) => { var data = JSON.stringify({ cost_center_id: payload.cost_center_id, cost_center_name: payload.cost_center_name, + cost_center_client_name: payload.cost_center_client_name, cost_center_investigator: payload.cost_center_investigator, cost_center_contact: payload.cost_center_contact, cost_center_email: payload.cost_center_email, diff --git a/frontend/src/redux/saga/costCenterSaga.js b/frontend/src/redux/saga/costCenterSaga.js index a553879f..2f58386a 100644 --- a/frontend/src/redux/saga/costCenterSaga.js +++ b/frontend/src/redux/saga/costCenterSaga.js @@ -17,7 +17,15 @@ import { loadProjectSaga } from "./projectSaga"; export function* loadCostCenterSaga() { const costCenterList = yield call(getCostcenterApi); - yield put({ type: SET_COSTCENTER, payload: costCenterList.data }); + const ccd = costCenterList.data; + const costCenterData = ccd.map((costCenter) => { + return { + ...costCenter, + cost_center_investigator: costCenter.cost_center_investigator ?? "New Investigator", + cost_center_client_name: costCenter.cost_center_client_name ?? "New Client", + } + }) + yield put({ type: SET_COSTCENTER, payload: costCenterData }); } export function* updateProjectAssignment({ payload }) { diff --git a/frontend/src/screens/invoice/invoice-preview.js b/frontend/src/screens/invoice/invoice-preview.js index 98a1999d..26441c95 100644 --- a/frontend/src/screens/invoice/invoice-preview.js +++ b/frontend/src/screens/invoice/invoice-preview.js @@ -44,7 +44,11 @@ function InvoicePreview() { const billableProject = invoice.fk_project_id; const billableProjectFilter = projectList.find((project) => project.project_id === billableProject); const billableCostCenterList = billableProjectFilter.costcenter; - const costcenter = billableCostCenterList[0] ?? "No Cost Center"; + const cc = billableCostCenterList[0] ?? "No Cost Center"; + const costcenter = { + ...cc, + project_name: invoice.project_name, + } if (customers.filter((customer) => customer.cost_center_id === costcenter.cost_center_id).length === 0) { customers.push(costcenter); } diff --git a/frontend/src/screens/login-form/index.js b/frontend/src/screens/login-form/index.js index c111e53a..16b75365 100644 --- a/frontend/src/screens/login-form/index.js +++ b/frontend/src/screens/login-form/index.js @@ -25,7 +25,7 @@ function LoginForm({ from }) { dispatch({ type: AUTHENTICATE_USER, payload: { - email: email, + email: email.toLowerCase(), password: password, }, }); @@ -44,7 +44,7 @@ function LoginForm({ from }) { dispatch({ type: REQUEST_RESET, payload: { - email: email, + email: email.toLowerCase(), }, }); }; diff --git a/frontend/src/screens/signup-form/index.js b/frontend/src/screens/signup-form/index.js index 410be142..92d4b11e 100644 --- a/frontend/src/screens/signup-form/index.js +++ b/frontend/src/screens/signup-form/index.js @@ -53,7 +53,7 @@ function SignUpForm() { user_id: uuid(), fk_organization_id: null, username: firstName + " " + lastName, - email: email, + email: email.toLowerCase(), employee: false, password: password, navTo: () => navigate("/"),