Files
bodyshop/client/src/graphql/jobs-lines.queries.js
2021-09-21 15:56:07 -07:00

229 lines
4.1 KiB
JavaScript

import { gql } from "@apollo/client";
export const GET_ALL_JOBLINES_BY_PK = gql`
query GET_ALL_JOBLINES_BY_PK($id: uuid!) {
joblines(where: { jobid: { _eq: $id } }, order_by: { line_no: asc }) {
id
line_no
unq_seq
line_ind
line_desc
part_type
oem_partno
db_price
act_price
part_qty
mod_lbr_ty
db_hrs
mod_lb_hrs
lbr_op
lbr_amt
op_code_desc
status
notes
location
tax_part
}
}
`;
export const GET_LINE_TICKET_BY_PK = gql`
query GET_LINE_TICKET_BY_PK($id: uuid!) {
jobs_by_pk(id: $id) {
id
lbr_adjustments
converted
}
joblines(where: { jobid: { _eq: $id }, removed: { _eq: false } }) {
id
line_desc
part_type
oem_partno
db_price
act_price
part_qty
mod_lbr_ty
db_hrs
mod_lb_hrs
lbr_op
lbr_amt
op_code_desc
}
timetickets(where: { jobid: { _eq: $id } }) {
actualhrs
ciecacode
cost_center
date
id
jobid
employeeid
memo
flat_rate
employee {
id
first_name
last_name
employee_number
}
productivehrs
}
}
`;
export const UPDATE_JOB_LINE_STATUS = gql`
mutation UPDATE_JOB_LINE_STATUS(
$ids: [uuid!]!
$status: String!
$location: String
) {
update_joblines(
where: { id: { _in: $ids } }
_set: { status: $status, location: $location }
) {
affected_rows
returning {
id
status
location
}
}
}
`;
export const INSERT_NEW_JOB_LINE = gql`
mutation INSERT_NEW_JOB_LINE($lineInput: [joblines_insert_input!]!) {
insert_joblines(objects: $lineInput) {
returning {
id
}
}
}
`;
export const RECEIVE_PARTS_LINE = gql`
mutation RECEIVE_PARTS_LINE(
$lineId: uuid!
$line: joblines_set_input!
$orderLineId: uuid!
$orderLine: parts_order_lines_set_input!
) {
update_joblines(where: { id: { _eq: $lineId } }, _set: $line) {
returning {
id
notes
mod_lbr_ty
part_qty
db_price
act_price
line_desc
oem_partno
notes
location
status
removed
}
}
update_parts_order_lines_by_pk(
pk_columns: { id: $orderLineId }
_set: $orderLine
) {
id
line_desc
backordered_on
backordered_eta
status
}
}
`;
export const UPDATE_JOB_LINE = gql`
mutation UPDATE_JOB_LINE($lineId: uuid!, $line: joblines_set_input!) {
update_joblines(where: { id: { _eq: $lineId } }, _set: $line) {
returning {
id
notes
mod_lbr_ty
part_qty
db_price
act_price
line_desc
line_no
oem_partno
notes
location
status
removed
}
}
}
`;
export const GET_JOB_LINES_TO_ENTER_BILL = gql`
query GET_JOB_LINES_TO_ENTER_BILL($id: uuid!) {
joblines(where: { jobid: { _eq: $id } }) {
removed
id
line_desc
part_type
oem_partno
db_price
act_price
part_qty
mod_lbr_ty
db_hrs
mod_lb_hrs
lbr_op
lbr_amt
op_code_desc
}
jobs_by_pk(id: $id) {
id
status
}
}
`;
// oem_partno: {
// _neq: "";
// }
// act_price: {
// _gt: "0";
// }
export const generateJobLinesUpdatesForInvoicing = (joblines) => {
const updates = joblines.reduce((acc, jl, idx) => {
return (
acc +
`a${idx}:update_joblines(where: {id: {_eq: "${
jl.id
}"}}, _set: {profitcenter_labor: "${
jl.profitcenter_labor || ""
}", profitcenter_part: "${jl.profitcenter_part || ""}"}) {
returning {
line_desc
profitcenter_part
profitcenter_labor
id
}
}`
);
}, "");
return gql`
mutation UPDATE_JOBLINES_FOR_INVOICING{
${updates}
}
`;
};
export const DELETE_JOB_LINE_BY_PK = gql`
mutation DELETE_JOB_LINE_BY_PK($joblineId: uuid!) {
update_joblines_by_pk(
pk_columns: { id: $joblineId }
_set: { removed: true }
) {
removed
id
}
}
`;