Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Harin329 committed Jul 22, 2023
2 parents c85b61f + a090ccc commit 71a2580
Show file tree
Hide file tree
Showing 32 changed files with 497 additions and 59 deletions.
20 changes: 18 additions & 2 deletions backend/src/controllers/taskController.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ export default class TaskController {
return new Promise((resolve, reject) => {
if (
!req.body.task_title ||
!req.body.task_state ||
!req.body.task_description
!req.body.task_state
) {
return reject({ error: "Error with request body." });
}
Expand Down Expand Up @@ -90,6 +89,23 @@ export default class TaskController {
});
}

updateTaskProject(req) {
return new Promise((resolve, reject) => {
const TaskModel = new Task();
TaskModel.updateTaskProject(
req.params.taskId,
req.body.project_id,
(err, result) => {
if (err) {
reject({ error: err });
}
this.isTaskLoaded = false;
resolve(result);
}
);
});
}

//add subtask given taskID
saveSubtaskByTask(req) {
return new Promise((resolve, reject) => {
Expand Down
19 changes: 18 additions & 1 deletion backend/src/models/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,24 @@ export class Task {
result(error, null);
} else {
result(null, {
result: `Task of ${taskId} Saved Successfully for Task ID: ${taskDescription}`,
result: `Task of ${taskId} Saved Successfully for Task ID: ${taskId}`,
});
}
}
);
}

updateTaskProject(taskId, taskProject, result) {
con.query(
"CALL update_task_project(?, ?)",
[taskId, taskProject],
function (error, _) {
if (error) {
console.log("error: ", error);
result(error, null);
} else {
result(null, {
result: `Task of ${taskId} Saved Successfully for Task ID: ${taskId}`,
});
}
}
Expand Down
11 changes: 11 additions & 0 deletions backend/src/routes/taskRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ router.post("/description/:taskId", authorize(), (req, res) => {
});
});

router.post("/project/:taskId", authorize(), (req, res) => {
taskController
.updateTaskProject(req)
.then((response) => {
res.status(200).json(response);
})
.catch((err) => {
res.status(404).json(err);
});
});

//add subtask given task_id
router.post("/addsubtask/:taskId", authorize(), (req, res) => {
if (!req.body) {
Expand Down
12 changes: 12 additions & 0 deletions backend/src/routes/userRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ router.post("/resetpassword", (req, res) => {
}
});

router.post("/adminReset", authorize(true), (req, res) => {
// Reset Password
userController
.updateUserPassword(req, req.body.email)
.then((response) => {
res.status(200).json(response);
})
.catch((err) => {
res.status(404).json(err);
});
});

router.delete("/:userId", authorize(), (req, res) => {
userController
.deleteUser(req.params.userId)
Expand Down
8 changes: 6 additions & 2 deletions database/procedures/billableProc.sql
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ END $$
CREATE PROCEDURE `load_billable` ()

BEGIN
SELECT billable.*, 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, 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
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);
Expand All @@ -98,11 +100,13 @@ CREATE PROCEDURE `load_billable_with_filter` (
)

BEGIN
SELECT billable.*, 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, 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
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 = '')
Expand Down
11 changes: 11 additions & 0 deletions database/procedures/ticketManagement/saveProcedures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ DROP procedure IF EXISTS `save_subtask`;
DROP procedure IF EXISTS `update_task_status`;
DROP procedure IF EXISTS `update_task_title`;
DROP procedure IF EXISTS `update_task_description`;
DROP procedure IF EXISTS `update_task_project`;
DROP procedure IF EXISTS `update_subtask_status`;

DELIMITER $$
Expand Down Expand Up @@ -74,6 +75,16 @@ UPDATE `subtasks` SET `subtask_description`=`_task_description`, `subtask_update

END $$

CREATE PROCEDURE `update_task_project` (
IN `_task_uuid` VARCHAR(50),
IN `_task_project` VARCHAR(250)

) BEGIN
UPDATE `tasks` SET `fk_project_id`=`_task_project`, `task_updated` = NOW() WHERE `task_uuid`=`_task_uuid`;
UPDATE `billable` SET `fk_project_id`=`_task_project` WHERE `task_uuid`=`_task_uuid`;

END $$

CREATE PROCEDURE `save_subtask` (
IN `_subtask_uuid` VARCHAR(50),
IN `_subtask_title` VARCHAR(100),
Expand Down
4 changes: 3 additions & 1 deletion frontend/.example.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
REACT_APP_S3_ACCESS_KEY_ID = REPLACE_VALUE_WITH_NO_QUOTATIONS
REACT_APP_S3_SECRET_ACCESS_KEY = REPLACE_VALUE_WITH_NO_QUOTATIONS
REACT_APP_S3_BUCKET = REPLACE_VALUE_WITH_NO_QUOTATIONS
REACT_APP_BACKEND = REPLACE_VALUE_WITH_NO_QUOTATIONS
REACT_APP_BACKEND = REPLACE_VALUE_WITH_NO_QUOTATIONS
REACT_APP_FRONTEND = REPLACE_VALUE_WITH_NO_QUOTATIONS
REACT_APP_SUMMARY_FORMAT = png
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"date-fns": "^2.29.3",
"html2canvas": "^1.4.1",
"html2pdf.js": "^0.10.1",
"jspdf": "^2.5.1",
"react": "^18.2.0",
"react-apexcharts": "^1.4.0",
"react-beautiful-dnd": "^13.1.1",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/CostEstimate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const CostEstimateFull = () => {

<div className="CostEstimates">
{formResponses.map((response) => {
if (!costEstimateMap) {
if (!costEstimateMap || costEstimateMap.length === 0) {
return null;
}
const cost = costEstimateMap.get(response.response) ?? 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#invoice-template {
color: #000;
margin: 10px auto;
border: 1px solid #ddd;
padding: 10px;
}
#invoice-header {
font-size: 12px;
Expand Down
13 changes: 7 additions & 6 deletions frontend/src/components/GenerateInvoice/InvoiceTemplate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const InvoiceTemplate = ({ customer, costcenterMap, invoicNum }) => {
/>
</div>

<div className="signer">
{/* <div className="signer">
<div className="signer-form signer-item">
<label htmlFor="date">Date:</label>
<input
Expand All @@ -127,7 +127,7 @@ const InvoiceTemplate = ({ customer, costcenterMap, invoicNum }) => {
onChange={handleChange}
/>
</div>
</div>
</div> */}
</div>
</div>
</div>
Expand All @@ -147,17 +147,22 @@ function InvoiceDetails({ billingData }) {
<tbody>
<tr className="heading">
<td>Description</td>
<td>SOW</td>
<td>User</td>
<td>Quantity</td>
<td>Unit Price</td>
<td>Total(CAD)</td>
</tr>

{billingData.map((invoiceItem, index) => {
console.log(invoiceItem);
return (
<tr className="item" key={invoiceItem.billable_id}>
<td>
{index + 1}. {invoiceItem.name}
</td>
<td>{`SOW-${invoiceItem.task_id ?? (invoiceItem.subtask_id ?? "?")}`}</td>
<td>{invoiceItem.username}</td>
<td>{invoiceItem.quantity}</td>
<td>${(invoiceItem.cost / invoiceItem.quantity).toFixed(2)}</td>
<td>${invoiceItem.cost}</td>
Expand All @@ -175,10 +180,6 @@ function InvoiceDetails({ billingData }) {
<td>Total Due: </td>
<td>${subtotal}</td>
</tr>
<tr className="item total">
<td>Amount Paid:</td>
<td>$0</td>
</tr>
</tbody>
</table>
</div>
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/components/InvoiceTable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ const InvoiceTable = () => {
key: "fk_project_id",
editable: false,
},
{
title: "Organization",
dataIndex: "organization_name",
key: "organization_name",
editable: false,
},
{
title: "User",
dataIndex: "username",
key: "username",
editable: false,
},
{
title: "Created Date",
dataIndex: "createdDate",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function ProjectSelectorEditor({ question }) {
useEffect(() => {
console.log(question);
setQuestionNum(`Q${question.position_index}`);
setTitle("User will select a project here...");
setTitle(question.question ?? "");
setNote(question.question_note);
}, [question]);

Expand Down
20 changes: 17 additions & 3 deletions frontend/src/components/ProjectSelector/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import {
REMOVE_PROJECT_RESPONSE,
} from "../../redux/actions/formActions";
import { GET_PROJECT } from "../../redux/actions/billingActions";
import { LOAD_QUESTION } from "../../redux/actions/questionActions";

function ProjectSelector({ question }) {
const dispatch = useDispatch();
const projectList = useSelector((state) => state.projectReducer.projectList);
const currentUser = useSelector((state) => state.userReducer.currentUser);
const draftList = useSelector((state) => state.formReducer.draftList);
const formResponses = useSelector((state) => state.formReducer.formResponses);
const [selectedValue, setSelectedValue] = useState(null);
const [draftDone, setDraftDone] = useState(false);

const handleChange = (event) => {
const selected = JSON.parse(event.target.value);
Expand All @@ -34,7 +37,6 @@ function ProjectSelector({ question }) {
question_info: question,
},
});
setSelectedValue(selected);

const draftObj = {
draft_id: question.question_id + "_" + currentUser.user_id,
Expand All @@ -47,6 +49,9 @@ function ProjectSelector({ question }) {
type: ADD_DRAFT,
payload: draftObj,
});
setDraftDone(true);
dispatch({ type: LOAD_QUESTION, payload: question.fk_form_id });
setSelectedValue(selected);
};

useEffect(() => {
Expand All @@ -63,7 +68,6 @@ function ProjectSelector({ question }) {
(option) => option.project_id === draft.answer
);
if (value) {
setSelectedValue(value);
dispatch({
type: ADD_RESPONSE,
payload: {
Expand All @@ -73,10 +77,20 @@ function ProjectSelector({ question }) {
question_info: question,
},
});
setSelectedValue(value);
setDraftDone(true);
}
}
}, [dispatch, draftList, projectList, question]);

useEffect(() => {
dispatch({ type: LOAD_QUESTION, payload: question.fk_form_id });
}, [dispatch, question.fk_form_id, draftDone]);

useEffect(() => {
const project = formResponses.find((response) => response?.question_info?.question_type === "project");
setSelectedValue(project?.question);
}, [formResponses, question]);

return (
<div className="GlobalCustomerQuestionContainer">
Expand All @@ -86,7 +100,7 @@ function ProjectSelector({ question }) {
</div>
<div className="GlobalQuestionSubtitle">{question.question_note}</div>
<select className="select" onChange={handleChange}>
{selectedValue === null && <option key={"Default"} value={""} />}
{!selectedValue && <option key={"Default"} value={""} />}
{projectList.map((option) => (
<option key={option.project_id} value={JSON.stringify(option)} selected={selectedValue && option.project_id === selectedValue.project_id}>
{option.project_name}
Expand Down
Loading

0 comments on commit 71a2580

Please sign in to comment.