diff --git a/client/src/components/jobs-detail-header-actions/jobs-detail-header-actions.component.jsx b/client/src/components/jobs-detail-header-actions/jobs-detail-header-actions.component.jsx index f602d3d98..78a08b021 100644 --- a/client/src/components/jobs-detail-header-actions/jobs-detail-header-actions.component.jsx +++ b/client/src/components/jobs-detail-header-actions/jobs-detail-header-actions.component.jsx @@ -54,7 +54,23 @@ const mapDispatchToProps = (dispatch) => ({ setMessage: (text) => dispatch(setMessage(text)), }); -export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, setScheduleContext, setBillEnterContext, setPaymentContext, setJobCostingContext, jobRO, setTimeTicketContext, setCardPaymentContext, insertAuditTrail, setEmailOptions, openChatByPhone, setMessage }) { +export function JobsDetailHeaderActions({ + job, + bodyshop, + currentUser, + refetch, + setScheduleContext, + setBillEnterContext, + setPaymentContext, + setJobCostingContext, + jobRO, + setTimeTicketContext, + setCardPaymentContext, + insertAuditTrail, + setEmailOptions, + openChatByPhone, + setMessage + }) { const {t} = useTranslation(); const client = useApolloClient(); const history = useNavigate(); @@ -81,6 +97,33 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se ); }, [job.status, bodyshop.md_ro_statuses.post_production_statuses]); + const handleDuplicate =() => + DuplicateJob( + client, + job.id, + {defaultOpenStatus: bodyshop.md_ro_statuses.default_imported}, + (newJobId) => { + history(`/manage/jobs/${newJobId}`); + notification["success"]({ + message: t("jobs.successes.duplicated"), + }); + }, + true + ); + + const handleDuplicateConfirm = () => + DuplicateJob( + client, + job.id, + {defaultOpenStatus: bodyshop.md_ro_statuses.default_imported}, + (newJobId) => { + history(`/manage/jobs/${newJobId}`); + notification["success"]({ + message: t("jobs.successes.duplicated"), + }); + } + ); + const handleFinish = async (values) => { logImEXEvent("schedule_manual_event"); @@ -88,7 +131,7 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se try { insertAppointment({ variables: { - apt: { ...values, isintake: false, jobid: job.id, bodyshopid: bodyshop.id }, + apt: {...values, isintake: false, jobid: job.id, bodyshopid: bodyshop.id}, }, refetchQueries: ["QUERY_ALL_ACTIVE_APPOINTMENTS"], }); @@ -104,6 +147,25 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se } }; + const handleDeleteJob = async () => { + //delete the job. + const result = await deleteJob({variables: {id: job.id}}); + + if (!!!result.errors) { + notification["success"]({ + message: t("jobs.successes.delete"), + }); + //go back to jobs list. + history(`/manage/`); + } else { + notification["error"]({ + message: t("jobs.errors.deleted", { + error: JSON.stringify(result.errors), + }), + }); + } + }; + const handleCreateCsi = async (e) => { logImEXEvent("job_create_csi"); @@ -199,8 +261,7 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se message: t("csi.errors.notconfigured"), }); } - } - else { + } else { if (e.key === "email") setEmailOptions({ jobid: job.id, @@ -242,6 +303,45 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se } }; + const handleVoidJob = async () => { + //delete the job. + const result = await voidJob({ + variables: { + jobId: job.id, + job: { + status: bodyshop.md_ro_statuses.default_void, + voided: true, + scheduled_in: null, + scheduled_completion: null, + inproduction: false, + date_void: new Date(), + }, + note: [ + { + jobid: job.id, + created_by: currentUser.email, + audit: true, + text: t("jobs.labels.voidnote"), + }, + ], + }, + }); + + if (!!!result.errors) { + notification["success"]({ + message: t("jobs.successes.voided"), + }); + //go back to jobs list. + history(`/manage/`); + } else { + notification["error"]({ + message: t("jobs.errors.voiding", { + error: JSON.stringify(result.errors), + }), + }); + } + }; + const handleExportCustData = async (e) => { logImEXEvent("job_export_cust_data"); let PartnerResponse; @@ -350,6 +450,33 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se }); }; + const handleLostSaleFinish = async ({lost_sale_reason}) => { + const jobUpdate = await cancelAllAppointments({ + variables: { + jobid: job.id, + job: { + date_scheduled: null, + scheduled_in: null, + scheduled_completion: null, + lost_sale_reason, + date_lost_sale: new Date(), + status: bodyshop.md_ro_statuses.default_imported, + }, + }, + }); + if (!jobUpdate.errors) { + notification["success"]({ + message: t("appointments.successes.canceled"), + }); + insertAuditTrail({ + jobid: job.id, + operation: + AuditTrailMapping.appointmentcancel(lost_sale_reason), + }); + + } + }; + const handleSuspend = (e) => { logImEXEvent("production_toggle_alert"); //e.stopPropagation(); @@ -363,7 +490,7 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se }); }; - const overlay = ( + const popOverContent = (
@@ -377,10 +504,10 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se }, ]} > - + - + { const start = form.getFieldValue("start"); - form.setFieldsValue({ end: start.add(30, "minutes") }); + form.setFieldsValue({end: start.add(30, "minutes")}); }} /> @@ -407,10 +534,10 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se required: true, //message: t("general.validation.required"), }, - ({ getFieldValue }) => ({ + ({getFieldValue}) => ({ async validator(rule, value) { if (value) { - const { start } = form.getFieldsValue(); + const {start} = form.getFieldsValue(); if (dayjs(start).isAfter(dayjs(value))) { return Promise.reject( t("employees.labels.endmustbeafterstart") @@ -425,7 +552,7 @@ export function JobsDetailHeaderActions({job, bodyshop, currentUser, refetch, se }), ]} > - +