From a269fd3ad85d9b71d70bb7dbe9b9c8ccf6ae3097 Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Wed, 18 Aug 2021 15:39:37 -0700 Subject: [PATCH] IO-1316 Add flat_rate to time tickets & resolve issues in job costing calculations. --- bodyshop_translations.babel | 21 ++++++++++ .../time-ticket-modal.component.jsx | 22 +++++++++- client/src/graphql/jobs-lines.queries.js | 1 + client/src/graphql/jobs.queries.js | 1 + client/src/graphql/timetickets.queries.js | 5 +++ client/src/translations/en_us/common.json | 1 + client/src/translations/es/common.json | 1 + client/src/translations/fr/common.json | 1 + .../down.yaml | 5 +++ .../up.yaml | 6 +++ .../down.yaml | 39 ++++++++++++++++++ .../up.yaml | 40 ++++++++++++++++++ .../down.yaml | 40 ++++++++++++++++++ .../up.yaml | 41 +++++++++++++++++++ .../down.yaml | 39 ++++++++++++++++++ .../up.yaml | 40 ++++++++++++++++++ hasura/migrations/metadata.yaml | 3 ++ server/graphql-client/queries.js | 2 + server/job/job-costing.js | 6 ++- 19 files changed, 311 insertions(+), 3 deletions(-) create mode 100644 hasura/migrations/1629321680242_alter_table_public_timetickets_add_column_flat_rate/down.yaml create mode 100644 hasura/migrations/1629321680242_alter_table_public_timetickets_add_column_flat_rate/up.yaml create mode 100644 hasura/migrations/1629321689733_update_permission_user_public_table_timetickets/down.yaml create mode 100644 hasura/migrations/1629321689733_update_permission_user_public_table_timetickets/up.yaml create mode 100644 hasura/migrations/1629321697271_update_permission_user_public_table_timetickets/down.yaml create mode 100644 hasura/migrations/1629321697271_update_permission_user_public_table_timetickets/up.yaml create mode 100644 hasura/migrations/1629321703175_update_permission_user_public_table_timetickets/down.yaml create mode 100644 hasura/migrations/1629321703175_update_permission_user_public_table_timetickets/up.yaml diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index bb60832a7..ae653bc19 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -35796,6 +35796,27 @@ + + flat_rate + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + memo false diff --git a/client/src/components/time-ticket-modal/time-ticket-modal.component.jsx b/client/src/components/time-ticket-modal/time-ticket-modal.component.jsx index 592447e36..23f4e828b 100644 --- a/client/src/components/time-ticket-modal/time-ticket-modal.component.jsx +++ b/client/src/components/time-ticket-modal/time-ticket-modal.component.jsx @@ -1,5 +1,5 @@ import { useQuery } from "@apollo/client"; -import { Form, Input, InputNumber, Select } from "antd"; +import { Form, Input, InputNumber, Select, Switch } from "antd"; import React from "react"; import { useTranslation } from "react-i18next"; import { connect } from "react-redux"; @@ -113,7 +113,17 @@ export function TimeTicketModalComponent({ }, ]} > - + { + console.log(value); + const emps = + employeeAutoCompleteOptions && + employeeAutoCompleteOptions.filter((e) => e.id === value)[0]; + console.log(emps); + form.setFieldsValue({ flat_rate: emps && emps.flat_rate }); + }} + /> prev.employeeid !== cur.employeeid} @@ -140,6 +150,14 @@ export function TimeTicketModalComponent({ ); }} + + + + diff --git a/client/src/graphql/jobs-lines.queries.js b/client/src/graphql/jobs-lines.queries.js index 82d373942..6aadff627 100644 --- a/client/src/graphql/jobs-lines.queries.js +++ b/client/src/graphql/jobs-lines.queries.js @@ -58,6 +58,7 @@ export const GET_LINE_TICKET_BY_PK = gql` jobid employeeid memo + flat_rate employee { id first_name diff --git a/client/src/graphql/jobs.queries.js b/client/src/graphql/jobs.queries.js index a8d9766ca..80ee3e8ec 100644 --- a/client/src/graphql/jobs.queries.js +++ b/client/src/graphql/jobs.queries.js @@ -318,6 +318,7 @@ export const QUERY_JOB_COSTING_DETAILS = gql` cost_center actualhrs productivehrs + flat_rate } } } diff --git a/client/src/graphql/timetickets.queries.js b/client/src/graphql/timetickets.queries.js index d2af11789..057edc1cb 100644 --- a/client/src/graphql/timetickets.queries.js +++ b/client/src/graphql/timetickets.queries.js @@ -14,6 +14,7 @@ export const QUERY_TICKETS_BY_JOBID = gql` id memo jobid + flat_rate employee { employee_number first_name @@ -42,6 +43,7 @@ export const QUERY_TIME_TICKETS_IN_RANGE = gql` productivehrs memo jobid + flat_rate job { id ro_number @@ -72,6 +74,7 @@ export const INSERT_NEW_TIME_TICKET = gql` ciecacode date memo + flat_rate } } } @@ -98,6 +101,7 @@ export const UPDATE_TIME_TICKET = gql` updated_at jobid date + flat_rate memo } } @@ -121,6 +125,7 @@ export const QUERY_ACTIVE_TIME_TICKETS = gql` clockon memo cost_center + flat_rate jobid job { id diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index e29ff3cbf..2404132da 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -2160,6 +2160,7 @@ "date": "Ticket Date", "efficiency": "Efficiency", "employee": "Employee", + "flat_rate": "Flat Rate?", "memo": "Memo", "productivehrs": "Productive Hours", "ro_number": "Job to Post Against" diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index f40d9dd17..ff5e0383c 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -2160,6 +2160,7 @@ "date": "", "efficiency": "", "employee": "", + "flat_rate": "", "memo": "", "productivehrs": "", "ro_number": "" diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index 54818c3f3..da63a3940 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -2160,6 +2160,7 @@ "date": "", "efficiency": "", "employee": "", + "flat_rate": "", "memo": "", "productivehrs": "", "ro_number": "" diff --git a/hasura/migrations/1629321680242_alter_table_public_timetickets_add_column_flat_rate/down.yaml b/hasura/migrations/1629321680242_alter_table_public_timetickets_add_column_flat_rate/down.yaml new file mode 100644 index 000000000..ee0d34d7f --- /dev/null +++ b/hasura/migrations/1629321680242_alter_table_public_timetickets_add_column_flat_rate/down.yaml @@ -0,0 +1,5 @@ +- args: + cascade: false + read_only: false + sql: ALTER TABLE "public"."timetickets" DROP COLUMN "flat_rate"; + type: run_sql diff --git a/hasura/migrations/1629321680242_alter_table_public_timetickets_add_column_flat_rate/up.yaml b/hasura/migrations/1629321680242_alter_table_public_timetickets_add_column_flat_rate/up.yaml new file mode 100644 index 000000000..acf754c51 --- /dev/null +++ b/hasura/migrations/1629321680242_alter_table_public_timetickets_add_column_flat_rate/up.yaml @@ -0,0 +1,6 @@ +- args: + cascade: false + read_only: false + sql: ALTER TABLE "public"."timetickets" ADD COLUMN "flat_rate" boolean NULL DEFAULT + false; + type: run_sql diff --git a/hasura/migrations/1629321689733_update_permission_user_public_table_timetickets/down.yaml b/hasura/migrations/1629321689733_update_permission_user_public_table_timetickets/down.yaml new file mode 100644 index 000000000..2738367b3 --- /dev/null +++ b/hasura/migrations/1629321689733_update_permission_user_public_table_timetickets/down.yaml @@ -0,0 +1,39 @@ +- args: + role: user + table: + name: timetickets + schema: public + type: drop_insert_permission +- args: + permission: + check: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + columns: + - actualhrs + - bodyshopid + - ciecacode + - clockoff + - clockon + - cost_center + - created_at + - date + - employeeid + - id + - jobid + - memo + - productivehrs + - rate + - updated_at + set: {} + role: user + table: + name: timetickets + schema: public + type: create_insert_permission diff --git a/hasura/migrations/1629321689733_update_permission_user_public_table_timetickets/up.yaml b/hasura/migrations/1629321689733_update_permission_user_public_table_timetickets/up.yaml new file mode 100644 index 000000000..8bab2b4db --- /dev/null +++ b/hasura/migrations/1629321689733_update_permission_user_public_table_timetickets/up.yaml @@ -0,0 +1,40 @@ +- args: + role: user + table: + name: timetickets + schema: public + type: drop_insert_permission +- args: + permission: + check: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + columns: + - actualhrs + - bodyshopid + - ciecacode + - clockoff + - clockon + - cost_center + - created_at + - date + - employeeid + - flat_rate + - id + - jobid + - memo + - productivehrs + - rate + - updated_at + set: {} + role: user + table: + name: timetickets + schema: public + type: create_insert_permission diff --git a/hasura/migrations/1629321697271_update_permission_user_public_table_timetickets/down.yaml b/hasura/migrations/1629321697271_update_permission_user_public_table_timetickets/down.yaml new file mode 100644 index 000000000..9b9382fa6 --- /dev/null +++ b/hasura/migrations/1629321697271_update_permission_user_public_table_timetickets/down.yaml @@ -0,0 +1,40 @@ +- args: + role: user + table: + name: timetickets + schema: public + type: drop_select_permission +- args: + permission: + allow_aggregations: false + columns: + - actualhrs + - bodyshopid + - ciecacode + - clockoff + - clockon + - cost_center + - created_at + - date + - employeeid + - id + - jobid + - memo + - productivehrs + - rate + - updated_at + computed_fields: [] + filter: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + role: user + table: + name: timetickets + schema: public + type: create_select_permission diff --git a/hasura/migrations/1629321697271_update_permission_user_public_table_timetickets/up.yaml b/hasura/migrations/1629321697271_update_permission_user_public_table_timetickets/up.yaml new file mode 100644 index 000000000..98b605f92 --- /dev/null +++ b/hasura/migrations/1629321697271_update_permission_user_public_table_timetickets/up.yaml @@ -0,0 +1,41 @@ +- args: + role: user + table: + name: timetickets + schema: public + type: drop_select_permission +- args: + permission: + allow_aggregations: false + columns: + - actualhrs + - bodyshopid + - ciecacode + - clockoff + - clockon + - cost_center + - created_at + - date + - employeeid + - flat_rate + - id + - jobid + - memo + - productivehrs + - rate + - updated_at + computed_fields: [] + filter: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + role: user + table: + name: timetickets + schema: public + type: create_select_permission diff --git a/hasura/migrations/1629321703175_update_permission_user_public_table_timetickets/down.yaml b/hasura/migrations/1629321703175_update_permission_user_public_table_timetickets/down.yaml new file mode 100644 index 000000000..81b11bf65 --- /dev/null +++ b/hasura/migrations/1629321703175_update_permission_user_public_table_timetickets/down.yaml @@ -0,0 +1,39 @@ +- args: + role: user + table: + name: timetickets + schema: public + type: drop_update_permission +- args: + permission: + columns: + - actualhrs + - bodyshopid + - ciecacode + - clockoff + - clockon + - cost_center + - created_at + - date + - employeeid + - id + - jobid + - memo + - productivehrs + - rate + - updated_at + filter: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + set: {} + role: user + table: + name: timetickets + schema: public + type: create_update_permission diff --git a/hasura/migrations/1629321703175_update_permission_user_public_table_timetickets/up.yaml b/hasura/migrations/1629321703175_update_permission_user_public_table_timetickets/up.yaml new file mode 100644 index 000000000..78f94a6fb --- /dev/null +++ b/hasura/migrations/1629321703175_update_permission_user_public_table_timetickets/up.yaml @@ -0,0 +1,40 @@ +- args: + role: user + table: + name: timetickets + schema: public + type: drop_update_permission +- args: + permission: + columns: + - actualhrs + - bodyshopid + - ciecacode + - clockoff + - clockon + - cost_center + - created_at + - date + - employeeid + - flat_rate + - id + - jobid + - memo + - productivehrs + - rate + - updated_at + filter: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + set: {} + role: user + table: + name: timetickets + schema: public + type: create_update_permission diff --git a/hasura/migrations/metadata.yaml b/hasura/migrations/metadata.yaml index 62d9f434a..6b280e543 100644 --- a/hasura/migrations/metadata.yaml +++ b/hasura/migrations/metadata.yaml @@ -4097,6 +4097,7 @@ tables: - created_at - date - employeeid + - flat_rate - id - jobid - memo @@ -4116,6 +4117,7 @@ tables: - created_at - date - employeeid + - flat_rate - id - jobid - memo @@ -4144,6 +4146,7 @@ tables: - created_at - date - employeeid + - flat_rate - id - jobid - memo diff --git a/server/graphql-client/queries.js b/server/graphql-client/queries.js index 4e8c7b421..0a8b09e33 100644 --- a/server/graphql-client/queries.js +++ b/server/graphql-client/queries.js @@ -791,6 +791,7 @@ exports.QUERY_JOB_COSTING_DETAILS = ` query QUERY_JOB_COSTING_DETAILS($id: uuid! cost_center actualhrs productivehrs + flat_rate } bodyshop{ id @@ -893,6 +894,7 @@ exports.QUERY_JOB_COSTING_DETAILS_MULTI = ` query QUERY_JOB_COSTING_DETAILS_MULT cost_center actualhrs productivehrs + flat_rate } bodyshop { id diff --git a/server/job/job-costing.js b/server/job/job-costing.js index 619c75dd9..6c840ee80 100644 --- a/server/job/job-costing.js +++ b/server/job/job-costing.js @@ -446,7 +446,11 @@ function GenerateCostingData(job) { ].add( Dinero({ amount: Math.round((ticket_val.rate || 0) * 100), - }).multiply(ticket_val.actualhrs || ticket_val.productivehrs || 0) + }).multiply( + ticket_val.flat_rate + ? ticket_val.productivehrs || ticket_val.actualhrs || 0 + : ticket_val.actualhrs || ticket_val.productivehrs || 0 + ) //Should base this on the employee. ); return ticket_acc;