From eebe7edba8b2be8fb0442be65f377297908846fb Mon Sep 17 00:00:00 2001 From: Allan Carr Date: Fri, 4 Aug 2023 10:36:01 -0700 Subject: [PATCH] IO-2371 Closing period timezone adjustments --- .../bill-form/bill-form.component.jsx | 19 +++++-- .../pages/jobs-close/jobs-close.component.jsx | 56 +++++++++---------- 2 files changed, 43 insertions(+), 32 deletions(-) diff --git a/client/src/components/bill-form/bill-form.component.jsx b/client/src/components/bill-form/bill-form.component.jsx index eb0d3a789..0fa28359a 100644 --- a/client/src/components/bill-form/bill-form.component.jsx +++ b/client/src/components/bill-form/bill-form.component.jsx @@ -12,6 +12,7 @@ import { Switch, Upload, } from "antd"; +import moment from "moment"; import React, { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { MdOpenInNew } from "react-icons/md"; @@ -271,10 +272,20 @@ export function BillFormComponent({ bodyshop.accountingconfig.ClosingPeriod ) { if ( - Date.parse(value).valueOf() >= - Date.parse(bodyshop.accountingconfig.ClosingPeriod[0]).valueOf() && - Date.parse(value).valueOf() <= - Date.parse(bodyshop.accountingconfig.ClosingPeriod[1]).valueOf() + moment(value) + .startOf("day") + .isSameOrAfter( + moment( + bodyshop.accountingconfig.ClosingPeriod[0] + ).startOf("day") + ) && + moment(value) + .startOf("day") + .isSameOrBefore( + moment( + bodyshop.accountingconfig.ClosingPeriod[1] + ).endOf("day") + ) ) { return Promise.resolve(); } else { diff --git a/client/src/pages/jobs-close/jobs-close.component.jsx b/client/src/pages/jobs-close/jobs-close.component.jsx index 840bc8102..91c8c7385 100644 --- a/client/src/pages/jobs-close/jobs-close.component.jsx +++ b/client/src/pages/jobs-close/jobs-close.component.jsx @@ -255,41 +255,41 @@ export function JobsCloseComponent({ job, bodyshop, jobRO }) { }, ({ getFieldValue }) => ({ validator(_, value) { - if (!bodyshop.cdk_dealerid) { + if (!bodyshop.cdk_dealerid) return Promise.resolve(); + if (!value || moment(value).isSameOrAfter(moment(), "day")) { + return Promise.resolve(); + } + return Promise.reject( + new Error(t("jobs.labels.dms.invoicedatefuture")) + ); + }, + }), + ({ getFieldValue }) => ({ + validator(_, value) { + if ( + ClosingPeriod.treatment === "on" && + bodyshop.accountingconfig.ClosingPeriod + ) { if ( - ClosingPeriod.treatment === "on" && - bodyshop.accountingconfig.ClosingPeriod - ) { - if ( - Date.parse(value).valueOf() >= - Date.parse( - bodyshop.accountingconfig.ClosingPeriod[0] - ).valueOf() && - Date.parse(value).valueOf() <= - Date.parse( - bodyshop.accountingconfig.ClosingPeriod[1] - ).valueOf() - ) { - return Promise.resolve(); - } else { - return Promise.reject( - new Error(t("jobs.labels.closingperiod")) - ); - } - } else { - return Promise.resolve(); - } - } else { - if ( - !value || - moment(value).isSameOrAfter(moment(), "day") + moment(value).isSameOrAfter( + moment( + bodyshop.accountingconfig.ClosingPeriod[0] + ).startOf("day") + ) && + moment(value).isSameOrBefore( + moment( + bodyshop.accountingconfig.ClosingPeriod[1] + ).endOf("day") + ) ) { return Promise.resolve(); } else { return Promise.reject( - new Error(t("jobs.labels.dms.invoicedatefuture")) + new Error(t("jobs.labels.closingperiod")) ); } + } else { + return Promise.resolve(); } }, }),