From 6d1dbe5f63bfb831350a0d50033edd85710393e8 Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Thu, 21 Jan 2021 10:45:59 -0800 Subject: [PATCH] Added multiple labor rates to employees IO-548 --- bodyshop_translations.babel | 42 +++++++ .../employee-search-select.component.jsx | 2 - .../job-costing-modal.component.jsx | 2 +- .../shop-employees-form.component.jsx | 104 ++++++++++++------ .../time-ticket-modal.component.jsx | 44 +++++--- .../time-ticket-modal.container.jsx | 31 ++++-- client/src/graphql/bodyshop.queries.js | 2 +- client/src/graphql/employees.queries.js | 6 +- client/src/graphql/jobs.queries.js | 1 + client/src/translations/en_us/common.json | 4 +- client/src/translations/es/common.json | 4 +- client/src/translations/fr/common.json | 4 +- .../down.yaml | 5 + .../up.yaml | 6 + .../down.yaml | 39 +++++++ .../up.yaml | 38 +++++++ .../down.yaml | 40 +++++++ .../up.yaml | 39 +++++++ .../down.yaml | 39 +++++++ .../up.yaml | 38 +++++++ hasura/migrations/metadata.yaml | 9 +- 21 files changed, 429 insertions(+), 70 deletions(-) create mode 100644 hasura/migrations/1611248235643_alter_table_public_employees_add_column_rates/down.yaml create mode 100644 hasura/migrations/1611248235643_alter_table_public_employees_add_column_rates/up.yaml create mode 100644 hasura/migrations/1611248259535_update_permission_user_public_table_employees/down.yaml create mode 100644 hasura/migrations/1611248259535_update_permission_user_public_table_employees/up.yaml create mode 100644 hasura/migrations/1611248275728_update_permission_user_public_table_employees/down.yaml create mode 100644 hasura/migrations/1611248275728_update_permission_user_public_table_employees/up.yaml create mode 100644 hasura/migrations/1611248283963_update_permission_user_public_table_employees/down.yaml create mode 100644 hasura/migrations/1611248283963_update_permission_user_public_table_employees/up.yaml diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index 6af4875a0..8beee215f 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -9239,6 +9239,27 @@ + + newrate + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + @@ -9522,6 +9543,27 @@ + + rate + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + termination_date false diff --git a/client/src/components/employee-search-select/employee-search-select.component.jsx b/client/src/components/employee-search-select/employee-search-select.component.jsx index 271f59332..6785ee48a 100644 --- a/client/src/components/employee-search-select/employee-search-select.component.jsx +++ b/client/src/components/employee-search-select/employee-search-select.component.jsx @@ -35,11 +35,9 @@ const EmployeeSearchSelect = ( key={o.id} value={o.id} search={`${o.employee_number} ${o.first_name} ${o.last_name}`} - discount={o.discount} > {`${o.employee_number} ${o.first_name} ${o.last_name}`} - {o.cost_center} {o.flat_rate diff --git a/client/src/components/job-costing-modal/job-costing-modal.component.jsx b/client/src/components/job-costing-modal/job-costing-modal.component.jsx index d15d7057a..e109524b4 100644 --- a/client/src/components/job-costing-modal/job-costing-modal.component.jsx +++ b/client/src/components/job-costing-modal/job-costing-modal.component.jsx @@ -87,7 +87,7 @@ export function JobCostingModalComponent({ bodyshop, job }) { ].add( Dinero({ amount: Math.round((ticket_val.rate || 0) * 100), - }).multiply(ticket_val.actualhrs || 0) + }).multiply(ticket_val.actualhrs || ticket_val.productivehrs || 0) ); return ticket_acc; diff --git a/client/src/components/shop-employees/shop-employees-form.component.jsx b/client/src/components/shop-employees/shop-employees-form.component.jsx index 491928f14..387178482 100644 --- a/client/src/components/shop-employees/shop-employees-form.component.jsx +++ b/client/src/components/shop-employees/shop-employees-form.component.jsx @@ -1,4 +1,5 @@ -import { Button, Form, Input, Select, Switch } from "antd"; +import { DeleteFilled } from "@ant-design/icons"; +import { Button, Form, Input, InputNumber, Select, Switch } from "antd"; import moment from "moment"; import React, { useEffect } from "react"; import { useApolloClient } from "react-apollo"; @@ -8,7 +9,8 @@ import { createStructuredSelector } from "reselect"; import { QUERY_USERS_BY_EMAIL } from "../../graphql/employees.queries"; import { selectBodyshop } from "../../redux/user/user.selectors"; import FormDatePicker from "../form-date-picker/form-date-picker.component"; -import CurrencyInput from "../form-items-formatted/currency-form-item.component"; +import FormListMoveArrows from "../form-list-move-arrows/form-list-move-arrows.component"; +import LayoutFormRow from "../layout-form-row/layout-form-row.component"; const mapStateToProps = createStructuredSelector({ bodyshop: selectBodyshop, @@ -131,36 +133,74 @@ export function ShopEmployeesFormComponent({ - - - - - - + + {(fields, { add, remove, move }) => { + return ( +
+ {fields.map((field, index) => ( + + + + + + + + + { + remove(field.name); + }} + /> + + + + ))} + + + +
+ ); + }} +
+ + prev.employeeid !== cur.employeeid} > - + {() => { + const employeeId = form.getFieldValue("employeeid"); + const emps = + employeeAutoCompleteOptions && + employeeAutoCompleteOptions.filter((e) => e.id === employeeId)[0]; + + return ( + + + + ); + }} { + const emps = EmployeeAutoCompleteData.employees.filter( + (e) => e.id === values.employeeid + ); if (timeTicketModal.context.id) { updateTicket({ variables: { timeticketId: timeTicketModal.context.id, - timeticket: values, + timeticket: { + ...values, + rate: + emps.length === 1 + ? emps[0].rates.filter( + (r) => r.cost_center === values.cost_center + )[0].rate + : null, + }, }, }) .then(handleMutationSuccess) .catch(handleMutationError); } else { //Get selected employee rate. - const rate = EmployeeAutoCompleteData.employees.filter( - (i) => i.id === values.employeeid - )[0].base_rate; - insertTicket({ variables: { - timeTicketInput: [{ ...values, rate, bodyshopid: bodyshop.id }], + timeTicketInput: [ + { + ...values, + rate: + emps.length === 1 + ? emps[0].rates.filter( + (r) => r.cost_center === values.cost_center + )[0].rate + : null, + bodyshopid: bodyshop.id, + }, + ], }, }) .then(handleMutationSuccess) @@ -196,7 +214,6 @@ export function TimeTicketModalContainer({ employeeAutoCompleteOptions={ EmployeeAutoCompleteData && EmployeeAutoCompleteData.employees } - responsibilityCenters={bodyshop.md_responsibility_centers || null} loadLineTicketData={loadLineTicketData} lineTicketData={ lineTicketData ? lineTicketData : { joblines: [], timetickets: [] } diff --git a/client/src/graphql/bodyshop.queries.js b/client/src/graphql/bodyshop.queries.js index 8989f5a0b..284d9bbf9 100644 --- a/client/src/graphql/bodyshop.queries.js +++ b/client/src/graphql/bodyshop.queries.js @@ -81,7 +81,7 @@ export const QUERY_BODYSHOP = gql` first_name last_name employee_number - cost_center + rates } } } diff --git a/client/src/graphql/employees.queries.js b/client/src/graphql/employees.queries.js index 658a86810..fbc398ed7 100644 --- a/client/src/graphql/employees.queries.js +++ b/client/src/graphql/employees.queries.js @@ -11,8 +11,7 @@ export const QUERY_EMPLOYEES = gql` termination_date hire_date flat_rate - cost_center - base_rate + rates pin user_email } @@ -41,8 +40,7 @@ export const UPDATE_EMPLOYEE = gql` termination_date hire_date flat_rate - cost_center - base_rate + rates pin user_email } diff --git a/client/src/graphql/jobs.queries.js b/client/src/graphql/jobs.queries.js index 2750f9447..01cdef9f7 100644 --- a/client/src/graphql/jobs.queries.js +++ b/client/src/graphql/jobs.queries.js @@ -302,6 +302,7 @@ export const QUERY_JOB_COSTING_DETAILS = gql` rate cost_center actualhrs + productivehrs } } } diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index be6f35bde..58e3c7e59 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -616,7 +616,8 @@ }, "employees": { "actions": { - "new": "New Employee" + "new": "New Employee", + "newrate": "New Rate" }, "errors": { "delete": "Error encountered while deleting employee. {{message}}", @@ -634,6 +635,7 @@ "hire_date": "Hire Date", "last_name": "Last Name", "pin": "Tech Console PIN", + "rate": "Rate", "termination_date": "Termination Date", "user_email": "User Email" }, diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index 9ef29d1b6..01cdfcd22 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -616,7 +616,8 @@ }, "employees": { "actions": { - "new": "Nuevo empleado" + "new": "Nuevo empleado", + "newrate": "" }, "errors": { "delete": "Se encontró un error al eliminar al empleado. {{message}}", @@ -634,6 +635,7 @@ "hire_date": "Fecha de contratación", "last_name": "Apellido", "pin": "", + "rate": "", "termination_date": "Fecha de conclusión", "user_email": "" }, diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index 9dbd8d97d..736734ffb 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -616,7 +616,8 @@ }, "employees": { "actions": { - "new": "Nouvel employé" + "new": "Nouvel employé", + "newrate": "" }, "errors": { "delete": "Erreur rencontrée lors de la suppression de l'employé. {{message}}", @@ -634,6 +635,7 @@ "hire_date": "Date d'embauche", "last_name": "Nom de famille", "pin": "", + "rate": "", "termination_date": "Date de résiliation", "user_email": "" }, diff --git a/hasura/migrations/1611248235643_alter_table_public_employees_add_column_rates/down.yaml b/hasura/migrations/1611248235643_alter_table_public_employees_add_column_rates/down.yaml new file mode 100644 index 000000000..f0673aa76 --- /dev/null +++ b/hasura/migrations/1611248235643_alter_table_public_employees_add_column_rates/down.yaml @@ -0,0 +1,5 @@ +- args: + cascade: false + read_only: false + sql: ALTER TABLE "public"."employees" DROP COLUMN "rates"; + type: run_sql diff --git a/hasura/migrations/1611248235643_alter_table_public_employees_add_column_rates/up.yaml b/hasura/migrations/1611248235643_alter_table_public_employees_add_column_rates/up.yaml new file mode 100644 index 000000000..8e95f1982 --- /dev/null +++ b/hasura/migrations/1611248235643_alter_table_public_employees_add_column_rates/up.yaml @@ -0,0 +1,6 @@ +- args: + cascade: false + read_only: false + sql: ALTER TABLE "public"."employees" ADD COLUMN "rates" jsonb NOT NULL DEFAULT + jsonb_build_array(); + type: run_sql diff --git a/hasura/migrations/1611248259535_update_permission_user_public_table_employees/down.yaml b/hasura/migrations/1611248259535_update_permission_user_public_table_employees/down.yaml new file mode 100644 index 000000000..71581edc3 --- /dev/null +++ b/hasura/migrations/1611248259535_update_permission_user_public_table_employees/down.yaml @@ -0,0 +1,39 @@ +- args: + role: user + table: + name: employees + schema: public + type: drop_insert_permission +- args: + permission: + check: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + columns: + - active + - base_rate + - cost_center + - created_at + - employee_number + - first_name + - flat_rate + - hire_date + - id + - last_name + - pin + - shopid + - termination_date + - updated_at + - user_email + set: {} + role: user + table: + name: employees + schema: public + type: create_insert_permission diff --git a/hasura/migrations/1611248259535_update_permission_user_public_table_employees/up.yaml b/hasura/migrations/1611248259535_update_permission_user_public_table_employees/up.yaml new file mode 100644 index 000000000..0de1d741b --- /dev/null +++ b/hasura/migrations/1611248259535_update_permission_user_public_table_employees/up.yaml @@ -0,0 +1,38 @@ +- args: + role: user + table: + name: employees + schema: public + type: drop_insert_permission +- args: + permission: + check: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + columns: + - active + - created_at + - employee_number + - first_name + - flat_rate + - hire_date + - id + - last_name + - pin + - rates + - shopid + - termination_date + - updated_at + - user_email + set: {} + role: user + table: + name: employees + schema: public + type: create_insert_permission diff --git a/hasura/migrations/1611248275728_update_permission_user_public_table_employees/down.yaml b/hasura/migrations/1611248275728_update_permission_user_public_table_employees/down.yaml new file mode 100644 index 000000000..8655d5eaf --- /dev/null +++ b/hasura/migrations/1611248275728_update_permission_user_public_table_employees/down.yaml @@ -0,0 +1,40 @@ +- args: + role: user + table: + name: employees + schema: public + type: drop_select_permission +- args: + permission: + allow_aggregations: false + columns: + - active + - base_rate + - cost_center + - created_at + - employee_number + - first_name + - flat_rate + - hire_date + - id + - last_name + - pin + - shopid + - termination_date + - updated_at + - user_email + computed_fields: [] + filter: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + role: user + table: + name: employees + schema: public + type: create_select_permission diff --git a/hasura/migrations/1611248275728_update_permission_user_public_table_employees/up.yaml b/hasura/migrations/1611248275728_update_permission_user_public_table_employees/up.yaml new file mode 100644 index 000000000..dabd89bba --- /dev/null +++ b/hasura/migrations/1611248275728_update_permission_user_public_table_employees/up.yaml @@ -0,0 +1,39 @@ +- args: + role: user + table: + name: employees + schema: public + type: drop_select_permission +- args: + permission: + allow_aggregations: false + columns: + - active + - created_at + - employee_number + - first_name + - flat_rate + - hire_date + - id + - last_name + - pin + - rates + - shopid + - termination_date + - updated_at + - user_email + computed_fields: [] + filter: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + role: user + table: + name: employees + schema: public + type: create_select_permission diff --git a/hasura/migrations/1611248283963_update_permission_user_public_table_employees/down.yaml b/hasura/migrations/1611248283963_update_permission_user_public_table_employees/down.yaml new file mode 100644 index 000000000..e0859b31d --- /dev/null +++ b/hasura/migrations/1611248283963_update_permission_user_public_table_employees/down.yaml @@ -0,0 +1,39 @@ +- args: + role: user + table: + name: employees + schema: public + type: drop_update_permission +- args: + permission: + columns: + - active + - base_rate + - cost_center + - created_at + - employee_number + - first_name + - flat_rate + - hire_date + - id + - last_name + - pin + - shopid + - termination_date + - updated_at + - user_email + filter: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + set: {} + role: user + table: + name: employees + schema: public + type: create_update_permission diff --git a/hasura/migrations/1611248283963_update_permission_user_public_table_employees/up.yaml b/hasura/migrations/1611248283963_update_permission_user_public_table_employees/up.yaml new file mode 100644 index 000000000..5c10dd4b7 --- /dev/null +++ b/hasura/migrations/1611248283963_update_permission_user_public_table_employees/up.yaml @@ -0,0 +1,38 @@ +- args: + role: user + table: + name: employees + schema: public + type: drop_update_permission +- args: + permission: + columns: + - active + - created_at + - employee_number + - first_name + - flat_rate + - hire_date + - id + - last_name + - pin + - rates + - shopid + - termination_date + - updated_at + - user_email + filter: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + set: {} + role: user + table: + name: employees + schema: public + type: create_update_permission diff --git a/hasura/migrations/metadata.yaml b/hasura/migrations/metadata.yaml index cd7148eab..418f4b87f 100644 --- a/hasura/migrations/metadata.yaml +++ b/hasura/migrations/metadata.yaml @@ -1550,8 +1550,6 @@ tables: _eq: true columns: - active - - base_rate - - cost_center - created_at - employee_number - first_name @@ -1560,6 +1558,7 @@ tables: - id - last_name - pin + - rates - shopid - termination_date - updated_at @@ -1569,8 +1568,6 @@ tables: permission: columns: - active - - base_rate - - cost_center - created_at - employee_number - first_name @@ -1579,6 +1576,7 @@ tables: - id - last_name - pin + - rates - shopid - termination_date - updated_at @@ -1597,8 +1595,6 @@ tables: permission: columns: - active - - base_rate - - cost_center - created_at - employee_number - first_name @@ -1607,6 +1603,7 @@ tables: - id - last_name - pin + - rates - shopid - termination_date - updated_at