IO-1708 Add shop timezone & update server side calculations.
This commit is contained in:
@@ -14,9 +14,10 @@ const { PBS_ENDPOINTS, PBS_CREDENTIALS } = require("./pbs-constants");
|
||||
const CalculateAllocations =
|
||||
require("../../cdk/cdk-calculate-allocations").default;
|
||||
const CdkBase = require("../../web-sockets/web-socket");
|
||||
const moment = require("moment");
|
||||
const moment = require("moment-timezone");
|
||||
const Dinero = require("dinero.js");
|
||||
const axios = AxiosLib.create();
|
||||
|
||||
axios.interceptors.request.use((x) => {
|
||||
const socket = x.socket;
|
||||
|
||||
@@ -553,7 +554,9 @@ async function InsertAccountPostingData(socket) {
|
||||
//Comment: "String",
|
||||
//AdditionalInfo: "String",
|
||||
InvoiceNumber: socket.JobData.ro_number,
|
||||
InvoiceDate: moment(socket.JobData.date_invoiced).toISOString(),
|
||||
InvoiceDate: moment(socket.JobData.date_invoiced)
|
||||
.tz(socket.JobData.bodyshop.timezone)
|
||||
.toISOString(),
|
||||
};
|
||||
wips.push(item);
|
||||
}
|
||||
@@ -567,7 +570,9 @@ async function InsertAccountPostingData(socket) {
|
||||
//Comment: "String",
|
||||
//AdditionalInfo: "String",
|
||||
InvoiceNumber: socket.JobData.ro_number,
|
||||
InvoiceDate: moment(socket.JobData.date_invoiced).toISOString(),
|
||||
InvoiceDate: moment(socket.JobData.date_invoiced)
|
||||
.tz(socket.JobData.bodyshop.timezone)
|
||||
.toISOString(),
|
||||
};
|
||||
wips.push(item);
|
||||
|
||||
@@ -578,7 +583,9 @@ async function InsertAccountPostingData(socket) {
|
||||
//Comment: "String",
|
||||
//AdditionalInfo: "String",
|
||||
InvoiceNumber: socket.JobData.ro_number,
|
||||
InvoiceDate: moment(socket.JobData.date_invoiced).toISOString(),
|
||||
InvoiceDate: moment(socket.JobData.date_invoiced)
|
||||
.tz(socket.JobData.bodyshop.timezone)
|
||||
.toISOString(),
|
||||
};
|
||||
wips.push(itemWip);
|
||||
//Add to the WIP account.
|
||||
@@ -593,7 +600,9 @@ async function InsertAccountPostingData(socket) {
|
||||
//Comment: "String",
|
||||
//AdditionalInfo: "String",
|
||||
InvoiceNumber: socket.JobData.ro_number,
|
||||
InvoiceDate: moment(socket.JobData.date_invoiced).toISOString(),
|
||||
InvoiceDate: moment(socket.JobData.date_invoiced)
|
||||
.tz(socket.JobData.bodyshop.timezone)
|
||||
.toISOString(),
|
||||
};
|
||||
wips.push(item2);
|
||||
}
|
||||
@@ -609,7 +618,9 @@ async function InsertAccountPostingData(socket) {
|
||||
//Comment: "String",
|
||||
//AdditionalInfo: "String",
|
||||
InvoiceNumber: socket.JobData.ro_number,
|
||||
InvoiceDate: moment(socket.JobData.date_invoiced).toISOString(),
|
||||
InvoiceDate: moment(socket.JobData.date_invoiced)
|
||||
.tz(socket.JobData.bodyshop.timezone)
|
||||
.toISOString(),
|
||||
};
|
||||
|
||||
wips.push(item);
|
||||
@@ -622,7 +633,9 @@ async function InsertAccountPostingData(socket) {
|
||||
Posting: {
|
||||
Reference: socket.JobData.ro_number,
|
||||
JournalCode: socket.txEnvelope.journal,
|
||||
TransactionDate: moment(socket.JobData.date_invoiced).toISOString(), //"0001-01-01T00:00:00.0000000Z",
|
||||
TransactionDate: moment(socket.JobData.date_invoiced)
|
||||
.tz(socket.JobData.bodyshop.timezone)
|
||||
.toISOString(), //"0001-01-01T00:00:00.0000000Z",
|
||||
Description: socket.txEnvelope.story,
|
||||
//AdditionalInfo: "String",
|
||||
Source: "ImEX Online",
|
||||
|
||||
@@ -17,7 +17,7 @@ const {
|
||||
setNewRefreshToken,
|
||||
} = require("./qbo-callback");
|
||||
const OAuthClient = require("intuit-oauth");
|
||||
const moment = require("moment");
|
||||
const moment = require("moment-timezone");
|
||||
const GraphQLClient = require("graphql-request").GraphQLClient;
|
||||
const findTaxCode = require("../qb-receivables-lines").findTaxCode;
|
||||
|
||||
@@ -178,7 +178,9 @@ async function InsertBill(oauthClient, qbo_realmId, req, bill, vendor) {
|
||||
VendorRef: {
|
||||
value: vendor.Id,
|
||||
},
|
||||
TxnDate: moment(bill.date).format("YYYY-MM-DD"),
|
||||
TxnDate: moment(bill.date)
|
||||
.tz(bill.job.bodyshop.timezone)
|
||||
.format("YYYY-MM-DD"),
|
||||
//DueDate: bill.due_date && moment(bill.due_date).format("YYYY-MM-DD"),
|
||||
DocNumber: bill.invoice_number,
|
||||
//...(bill.job.class ? { ClassRef: { Id: classes[bill.job.class] } } : {}),
|
||||
|
||||
@@ -15,7 +15,7 @@ const {
|
||||
setNewRefreshToken,
|
||||
} = require("./qbo-callback");
|
||||
const OAuthClient = require("intuit-oauth");
|
||||
const moment = require("moment");
|
||||
const moment = require("moment-timezone");
|
||||
const GraphQLClient = require("graphql-request").GraphQLClient;
|
||||
const {
|
||||
QueryInsuranceCo,
|
||||
@@ -137,14 +137,22 @@ exports.default = async (req, res) => {
|
||||
}
|
||||
|
||||
if (payment.amount > 0) {
|
||||
await InsertPayment(oauthClient, qbo_realmId, req, payment, jobTier);
|
||||
await InsertPayment(
|
||||
oauthClient,
|
||||
qbo_realmId,
|
||||
req,
|
||||
payment,
|
||||
jobTier,
|
||||
bodyshop
|
||||
);
|
||||
} else {
|
||||
await InsertCreditMemo(
|
||||
oauthClient,
|
||||
qbo_realmId,
|
||||
req,
|
||||
payment,
|
||||
jobTier
|
||||
jobTier,
|
||||
bodyshop
|
||||
);
|
||||
}
|
||||
ret.push({ paymentid: payment.id, success: true });
|
||||
@@ -178,7 +186,8 @@ async function InsertPayment(
|
||||
qbo_realmId,
|
||||
req,
|
||||
payment,
|
||||
parentRef
|
||||
parentRef,
|
||||
bodyshop
|
||||
) {
|
||||
const { paymentMethods, invoices } = await QueryMetaData(
|
||||
oauthClient,
|
||||
@@ -198,7 +207,7 @@ async function InsertPayment(
|
||||
CustomerRef: {
|
||||
value: parentRef.Id,
|
||||
},
|
||||
TxnDate: moment(payment.date).format("YYYY-MM-DD"),
|
||||
TxnDate: moment(payment.date).tz(bodyshop.timezone).format("YYYY-MM-DD"),
|
||||
//DueDate: bill.due_date && moment(bill.due_date).format("YYYY-MM-DD"),
|
||||
DocNumber: payment.paymentnum,
|
||||
TotalAmt: Dinero({
|
||||
@@ -362,7 +371,8 @@ async function InsertCreditMemo(
|
||||
qbo_realmId,
|
||||
req,
|
||||
payment,
|
||||
parentRef
|
||||
parentRef,
|
||||
bodyshop
|
||||
) {
|
||||
const { paymentMethods, invoices, items, taxCodes } = await QueryMetaData(
|
||||
oauthClient,
|
||||
@@ -382,7 +392,7 @@ async function InsertCreditMemo(
|
||||
CustomerRef: {
|
||||
value: parentRef.Id,
|
||||
},
|
||||
TxnDate: moment(payment.date).format("YYYY-MM-DD"),
|
||||
TxnDate: moment(payment.date).tz(bodyshop.timezone).format("YYYY-MM-DD"),
|
||||
DocNumber: payment.paymentnum,
|
||||
...(invoices && invoices[0]
|
||||
? { InvoiceRef: { value: invoices[0].Id } }
|
||||
|
||||
@@ -17,7 +17,7 @@ const {
|
||||
} = require("./qbo-callback");
|
||||
const OAuthClient = require("intuit-oauth");
|
||||
const CreateInvoiceLines = require("../qb-receivables-lines").default;
|
||||
const moment = require("moment");
|
||||
const moment = require("moment-timezone");
|
||||
|
||||
const GraphQLClient = require("graphql-request").GraphQLClient;
|
||||
const { generateOwnerTier } = require("../qbxml/qbxml-utils");
|
||||
@@ -440,7 +440,9 @@ async function InsertInvoice(
|
||||
|
||||
const invoiceObj = {
|
||||
Line: InvoiceLineAdd,
|
||||
TxnDate: moment(job.date_invoiced).format("YYYY-MM-DD"),
|
||||
TxnDate: moment(job.date_invoiced)
|
||||
.tz(bodyshop.timezone)
|
||||
.format("YYYY-MM-DD"),
|
||||
DocNumber: job.ro_number,
|
||||
...(job.class ? { ClassRef: { value: classes[job.class] } } : {}),
|
||||
CustomerMemo: {
|
||||
|
||||
@@ -5,7 +5,7 @@ const queries = require("../../graphql-client/queries");
|
||||
const Dinero = require("dinero.js");
|
||||
var builder = require("xmlbuilder2");
|
||||
const QbXmlUtils = require("./qbxml-utils");
|
||||
const moment = require("moment");
|
||||
const moment = require("moment-timezone");
|
||||
const logger = require("../../utils/logger");
|
||||
require("dotenv").config({
|
||||
path: path.resolve(
|
||||
@@ -72,9 +72,14 @@ const generateBill = (bill) => {
|
||||
VendorRef: {
|
||||
FullName: bill.vendor.name,
|
||||
},
|
||||
TxnDate: moment(bill.date).format("YYYY-MM-DD"),
|
||||
TxnDate: moment(bill.date)
|
||||
.tz(bill.job.bodyshop.timezone)
|
||||
.format("YYYY-MM-DD"),
|
||||
DueDate:
|
||||
bill.due_date && moment(bill.due_date).format("YYYY-MM-DD"),
|
||||
bill.due_date &&
|
||||
moment(bill.due_date)
|
||||
.tz(bill.job.bodyshop.timezone)
|
||||
.format("YYYY-MM-DD"),
|
||||
RefNumber: bill.invoice_number,
|
||||
Memo: `RO ${bill.job.ro_number || ""}`,
|
||||
ExpenseLineAdd: bill.billlines.map((il) =>
|
||||
|
||||
@@ -4,7 +4,7 @@ const DineroQbFormat = require("../accounting-constants").DineroQbFormat;
|
||||
const queries = require("../../graphql-client/queries");
|
||||
const Dinero = require("dinero.js");
|
||||
var builder = require("xmlbuilder2");
|
||||
const moment = require("moment");
|
||||
const moment = require("moment-timezone");
|
||||
const QbXmlUtils = require("./qbxml-utils");
|
||||
const QbxmlReceivables = require("./qbxml-receivables");
|
||||
const logger = require("../../utils/logger");
|
||||
@@ -84,7 +84,7 @@ exports.default = async (req, res) => {
|
||||
QbXmlToExecute.push({
|
||||
id: i.id,
|
||||
okStatusCodes: ["0"],
|
||||
qbxml: generatePayment(i, isThreeTier, twoTierPref),
|
||||
qbxml: generatePayment(i, isThreeTier, twoTierPref, bodyshop),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -101,7 +101,7 @@ exports.default = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
const generatePayment = (payment, isThreeTier, twoTierPref) => {
|
||||
const generatePayment = (payment, isThreeTier, twoTierPref, bodyshop) => {
|
||||
let paymentQbxmlObj;
|
||||
if (payment.amount > 0) {
|
||||
paymentQbxmlObj = {
|
||||
@@ -128,7 +128,9 @@ const generatePayment = (payment, isThreeTier, twoTierPref) => {
|
||||
FullName:
|
||||
payment.job.bodyshop.md_responsibility_centers.ar.accountname,
|
||||
},
|
||||
TxnDate: moment(payment.date).format("YYYY-MM-DD"), //Trim String
|
||||
TxnDate: moment(payment.date)
|
||||
.tz(bodyshop.timezone)
|
||||
.format("YYYY-MM-DD"), //Trim String
|
||||
RefNumber: payment.paymentnum || payment.transactionid,
|
||||
TotalAmount: Dinero({
|
||||
amount: Math.round(payment.amount * 100),
|
||||
@@ -172,7 +174,9 @@ const generatePayment = (payment, isThreeTier, twoTierPref) => {
|
||||
FullName:
|
||||
payment.job.bodyshop.md_responsibility_centers.ar.accountname,
|
||||
},
|
||||
TxnDate: moment(payment.date).format("YYYY-MM-DD"), //Trim String
|
||||
TxnDate: moment(payment.date)
|
||||
.tz(bodyshop.timezone)
|
||||
.format("YYYY-MM-DD"), //Trim String
|
||||
RefNumber:
|
||||
payment.paymentnum || payment.stripeid || payment.transactionid,
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ const path = require("path");
|
||||
const DineroQbFormat = require("../accounting-constants").DineroQbFormat;
|
||||
const queries = require("../../graphql-client/queries");
|
||||
const Dinero = require("dinero.js");
|
||||
const moment = require("moment");
|
||||
const moment = require("moment-timezone");
|
||||
var builder = require("xmlbuilder2");
|
||||
const QbXmlUtils = require("./qbxml-utils");
|
||||
const logger = require("../../utils/logger");
|
||||
@@ -254,7 +254,9 @@ const generateInvoiceQbxml = (
|
||||
? { ClassRef: { FullName: jobs_by_pk.class } }
|
||||
: {}),
|
||||
|
||||
TxnDate: moment(jobs_by_pk.date_invoiced).format("YYYY-MM-DD"),
|
||||
TxnDate: moment(jobs_by_pk.date_invoiced)
|
||||
.tz(bodyshop.timezone)
|
||||
.format("YYYY-MM-DD"),
|
||||
RefNumber: jobs_by_pk.ro_number,
|
||||
BillAddress: {
|
||||
Addr1: jobs_by_pk.ownr_co_nm
|
||||
|
||||
@@ -13,7 +13,7 @@ const CdkWsdl = require("./cdk-wsdl").default;
|
||||
const { CDK_CREDENTIALS, CheckCdkResponseForError } = require("./cdk-wsdl");
|
||||
const CalcualteAllocations = require("./cdk-calculate-allocations").default;
|
||||
|
||||
const moment = require("moment");
|
||||
const moment = require("moment-timezone");
|
||||
|
||||
const replaceSpecialRegex = /[^a-zA-Z0-9 .,\n #]+/g;
|
||||
|
||||
@@ -716,6 +716,7 @@ async function InsertDmsVehicle(socket) {
|
||||
dealerNumber: socket.JobData.bodyshop.cdk_dealerid,
|
||||
...(socket.txEnvelope.inservicedate && {
|
||||
inServiceDate: moment(socket.txEnvelope.inservicedate)
|
||||
.tz(socket.JobData.bodyshop.timezone)
|
||||
.startOf("day")
|
||||
.toISOString(),
|
||||
}),
|
||||
@@ -723,7 +724,9 @@ async function InsertDmsVehicle(socket) {
|
||||
},
|
||||
manufacturer: {},
|
||||
vehicle: {
|
||||
deliveryDate: moment().format("YYYYMMDD"),
|
||||
deliveryDate: moment()
|
||||
.tz(socket.JobData.bodyshop.timezone)
|
||||
.format("YYYYMMDD"),
|
||||
licensePlateNo: socket.JobData.plate_no,
|
||||
make: socket.txEnvelope.dms_make,
|
||||
modelAbrev: socket.txEnvelope.dms_model,
|
||||
@@ -850,14 +853,16 @@ async function UpdateDmsVehicle(socket) {
|
||||
inServiceDate: moment(
|
||||
socket.DMSVeh.dealer.inServiceDate ||
|
||||
socket.txEnvelope.inservicedate
|
||||
).toISOString(),
|
||||
)
|
||||
.tz(socket.JobData.bodyshop.timezone)
|
||||
.toISOString(),
|
||||
}),
|
||||
},
|
||||
vehicle: {
|
||||
...socket.DMSVeh.vehicle,
|
||||
deliveryDate: moment(
|
||||
socket.DMSVeh.vehicle.deliveryDate
|
||||
).toISOString(),
|
||||
deliveryDate: moment(socket.DMSVeh.vehicle.deliveryDate)
|
||||
.tz(socket.JobData.bodyshop.timezone)
|
||||
.toISOString(),
|
||||
},
|
||||
owners: ids,
|
||||
},
|
||||
@@ -912,10 +917,18 @@ async function InsertServiceVehicleHistory(socket) {
|
||||
vehID: socket.DMSVid.vehiclesVehId,
|
||||
roNumber: socket.JobData.ro_number.match(/\d+/g),
|
||||
mileage: socket.txEnvelope.kmout,
|
||||
openDate: moment(socket.JobData.actual_in).format("YYYY-MM-DD"),
|
||||
openTime: moment(socket.JobData.actual_in).format("HH:mm:ss"),
|
||||
closeDate: moment(socket.JobData.invoice_date).format("YYYY-MM-DD"),
|
||||
closeTime: moment(socket.JobData.invoice_date).format("HH:mm:ss"),
|
||||
openDate: moment(socket.JobData.actual_in)
|
||||
.tz(socket.JobData.bodyshop.timezone)
|
||||
.format("YYYY-MM-DD"),
|
||||
openTime: moment(socket.JobData.actual_in)
|
||||
.tz(socket.JobData.bodyshop.timezone)
|
||||
.format("HH:mm:ss"),
|
||||
closeDate: moment(socket.JobData.invoice_date)
|
||||
.tz(socket.JobData.bodyshop.timezone)
|
||||
.format("YYYY-MM-DD"),
|
||||
closeTime: moment(socket.JobData.invoice_date)
|
||||
.tz(socket.JobData.bodyshop.timezone)
|
||||
.format("HH:mm:ss"),
|
||||
comments: socket.txEnvelope.story,
|
||||
cashierID: socket.JobData.bodyshop.cdk_configuration.cashierid,
|
||||
},
|
||||
@@ -966,7 +979,9 @@ async function InsertDmsStartWip(socket) {
|
||||
arg0: CDK_CREDENTIALS,
|
||||
arg1: { dealerId: socket.JobData.bodyshop.cdk_dealerid },
|
||||
arg2: {
|
||||
acctgDate: moment().format("YYYY-MM-DD"),
|
||||
acctgDate: moment()
|
||||
.tz(socket.JobData.bodyshop.timezone)
|
||||
.format("YYYY-MM-DD"),
|
||||
//socket.JobData.invoice_date
|
||||
desc:
|
||||
socket.txEnvelope.story &&
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const path = require("path");
|
||||
const queries = require("../graphql-client/queries");
|
||||
const Dinero = require("dinero.js");
|
||||
const moment = require("moment");
|
||||
const moment = require("moment-timezone");
|
||||
const fs = require("fs");
|
||||
|
||||
const _ = require("lodash");
|
||||
@@ -66,24 +66,35 @@ exports.default = async (req, res) => {
|
||||
// },
|
||||
RepairEvent: {
|
||||
CreatedDateTime: (job.date_open
|
||||
? moment(job.date_open)
|
||||
? moment(job.date_open).tz(bodyshop.timezone)
|
||||
: moment()
|
||||
).format(momentFormat),
|
||||
ArrivalDateTime:
|
||||
job.actual_in && moment(job.actual_in).format(momentFormat),
|
||||
job.actual_in &&
|
||||
moment(job.actual_in)
|
||||
.tz(bodyshop.timezone)
|
||||
.format(momentFormat),
|
||||
ArrivalOdometerReading: job.kmin,
|
||||
TargetCompletionDateTime:
|
||||
job.scheduled_completion &&
|
||||
moment(job.scheduled_completion).format(momentFormat),
|
||||
moment(job.scheduled_completion)
|
||||
.tz(bodyshop.timezone)
|
||||
.format(momentFormat),
|
||||
ActualCompletionDateTime:
|
||||
job.actual_completion &&
|
||||
moment(job.actual_completion).format(momentFormat),
|
||||
moment(job.actual_completion)
|
||||
.tz(bodyshop.timezone)
|
||||
.format(momentFormat),
|
||||
ActualPickUpDateTime:
|
||||
job.actual_delivery &&
|
||||
moment(job.actual_delivery).format(momentFormat),
|
||||
moment(job.actual_delivery)
|
||||
.tz(bodyshop.timezone)
|
||||
.format(momentFormat),
|
||||
CloseDateTime:
|
||||
job.date_exported &&
|
||||
moment(job.date_exported).format(momentFormat),
|
||||
moment(job.date_exported)
|
||||
.tz(bodyshop.timezone)
|
||||
.format(momentFormat),
|
||||
},
|
||||
},
|
||||
RepairOrderHeader: {
|
||||
@@ -254,7 +265,8 @@ exports.default = async (req, res) => {
|
||||
//ProductionDate: "2009-10",
|
||||
ModelYear:
|
||||
parseInt(job.v_model_yr) < 1900
|
||||
? parseInt(job.v_model_yr) < moment().format("YY")
|
||||
? parseInt(job.v_model_yr) <
|
||||
moment().tz(bodyshop.timezone).format("YY")
|
||||
? `20${job.v_model_yr}`
|
||||
: `19${job.v_model_yr}`
|
||||
: job.v_model_yr,
|
||||
@@ -288,7 +300,9 @@ exports.default = async (req, res) => {
|
||||
Facts: {
|
||||
LossDateTime:
|
||||
job.loss_date &&
|
||||
moment(job.loss_date).format(momentFormat),
|
||||
moment(job.loss_date)
|
||||
.tz(bodyshop.timezone)
|
||||
.format(momentFormat),
|
||||
LossDescCode: "Collision",
|
||||
PrimaryPOI: {
|
||||
POICode: job.area_of_damage && job.area_of_damage.impact1,
|
||||
@@ -750,13 +764,17 @@ exports.default = async (req, res) => {
|
||||
ProductionStatus: {
|
||||
ProductionStage: {
|
||||
ProductionStageCode: GetProductionStageCode(job, bodyshop),
|
||||
ProductionStageDateTime: moment().format(momentFormat),
|
||||
ProductionStageDateTime: moment()
|
||||
.tz(bodyshop.timezone)
|
||||
.format(momentFormat),
|
||||
// ProductionStageStatusComment:
|
||||
// "Going to be painted this afternoon",
|
||||
},
|
||||
RepairStatus: {
|
||||
RepairStatusCode: GetRepairStatusCode(job),
|
||||
RepairStatusDateTime: moment().format(momentFormat),
|
||||
RepairStatusDateTime: moment()
|
||||
.tz(bodyshop.timezone)
|
||||
.format(momentFormat),
|
||||
// RepairStatusMemo: "Waiting on back ordered parts",
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const path = require("path");
|
||||
const queries = require("../graphql-client/queries");
|
||||
const Dinero = require("dinero.js");
|
||||
const moment = require("moment");
|
||||
const moment = require("moment-timezone");
|
||||
var builder = require("xmlbuilder2");
|
||||
const _ = require("lodash");
|
||||
const logger = require("../utils/logger");
|
||||
@@ -267,27 +267,50 @@ const CreateRepairOrderTag = (job, errorCallback) => {
|
||||
},
|
||||
Dates: {
|
||||
DateofLoss:
|
||||
(job.loss_date && moment(job.loss_date).format(AhDateFormat)) || "",
|
||||
(job.loss_date &&
|
||||
moment(job.loss_date)
|
||||
.tz(job.bodyshop.timezone)
|
||||
.format(AhDateFormat)) ||
|
||||
"",
|
||||
InitialCustomerContactDate: null,
|
||||
FirstFollowUpDate: null,
|
||||
ReferralDate: null,
|
||||
EstimateAppointmentDate: null,
|
||||
SecondFollowUpDate: null,
|
||||
AssignedDate:
|
||||
(job.asgn_date && moment(job.asgn_date).format(AhDateFormat)) || "",
|
||||
(job.asgn_date &&
|
||||
moment(job.asgn_date)
|
||||
.tz(job.bodyshop.timezone)
|
||||
.format(AhDateFormat)) ||
|
||||
"",
|
||||
EstComplete: null,
|
||||
CustomerAuthorizationDate: null,
|
||||
InsuranceAuthorizationDate: null,
|
||||
DateOpened:
|
||||
(job.date_open && moment(job.date_open).format(AhDateFormat)) || "",
|
||||
(job.date_open &&
|
||||
moment(job.date_open)
|
||||
.tz(job.bodyshop.timezone)
|
||||
.format(AhDateFormat)) ||
|
||||
"",
|
||||
ScheduledArrivalDate:
|
||||
(job.scheduled_in && moment(job.scheduled_in).format(AhDateFormat)) ||
|
||||
(job.scheduled_in &&
|
||||
moment(job.scheduled_in)
|
||||
.tz(job.bodyshop.timezone)
|
||||
.format(AhDateFormat)) ||
|
||||
"",
|
||||
CarinShop:
|
||||
(job.actual_in && moment(job.actual_in).format(AhDateFormat)) || "",
|
||||
(job.actual_in &&
|
||||
moment(job.actual_in)
|
||||
.tz(job.bodyshop.timezone)
|
||||
.format(AhDateFormat)) ||
|
||||
"",
|
||||
InsInspDate: null,
|
||||
StartDate:
|
||||
(job.actual_in && moment(job.actual_in).format(AhDateFormat)) || "",
|
||||
(job.actual_in &&
|
||||
moment(job.actual_in)
|
||||
.tz(job.bodyshop.timezone)
|
||||
.format(AhDateFormat)) ||
|
||||
"",
|
||||
PartsOrder: null,
|
||||
TeardownHold: null,
|
||||
SupplementSubmittedDate: null,
|
||||
@@ -303,24 +326,35 @@ const CreateRepairOrderTag = (job, errorCallback) => {
|
||||
//InsuranceTargetOut: null,
|
||||
CarComplete:
|
||||
(job.actual_completion &&
|
||||
moment(job.actual_completion).format(AhDateFormat)) ||
|
||||
moment(job.actual_completion)
|
||||
.tz(job.bodyshop.timezone)
|
||||
.format(AhDateFormat)) ||
|
||||
"",
|
||||
DeliveryAppointmentDate:
|
||||
(job.scheduled_delivery &&
|
||||
moment(job.scheduled_delivery).format(AhDateFormat)) ||
|
||||
moment(job.scheduled_delivery)
|
||||
.tz(job.bodyshop.timezone)
|
||||
.format(AhDateFormat)) ||
|
||||
"",
|
||||
DateClosed:
|
||||
(job.date_invoiced &&
|
||||
moment(job.date_invoiced).format(AhDateFormat)) ||
|
||||
moment(job.date_invoiced)
|
||||
.tz(job.bodyshop.timezone)
|
||||
.format(AhDateFormat)) ||
|
||||
"",
|
||||
CustomerPaidInFullDate: null,
|
||||
InsurancePaidInFullDate: null,
|
||||
CustPickup:
|
||||
(job.actual_delivery &&
|
||||
moment(job.actual_delivery).format(AhDateFormat)) ||
|
||||
moment(job.actual_delivery)
|
||||
.tz(job.bodyshop.timezone)
|
||||
.format(AhDateFormat)) ||
|
||||
"",
|
||||
AccountPostedDate:
|
||||
job.date_exported && moment(job.date_exported).format(AhDateFormat),
|
||||
job.date_exported &&
|
||||
moment(job.date_exported)
|
||||
.tz(job.bodyshop.timezone)
|
||||
.format(AhDateFormat),
|
||||
CSIProcessedDate: null,
|
||||
ThankYouLetterSent: null,
|
||||
AdditionalFollowUpDate: null,
|
||||
@@ -760,9 +794,9 @@ const GenerateDetailLines = (line, statuses) => {
|
||||
MarkUp: null,
|
||||
OrderedOn:
|
||||
(line.parts_order_lines[0] &&
|
||||
moment(line.parts_order_lines[0].parts_order.order_date).format(
|
||||
AhDateFormat
|
||||
)) ||
|
||||
moment(line.parts_order_lines[0].parts_order.order_date)
|
||||
.tz(job.bodyshop.timezone)
|
||||
.format(AhDateFormat)) ||
|
||||
"",
|
||||
OriginalCost: null,
|
||||
OriginalInvoiceNumber: null,
|
||||
@@ -786,7 +820,9 @@ const GenerateDetailLines = (line, statuses) => {
|
||||
ExpectedOn: null,
|
||||
ReceivedOn:
|
||||
line.billlines[0] &&
|
||||
moment(line.billlines[0].bill.date).format(AhDateFormat),
|
||||
moment(line.billlines[0].bill.date)
|
||||
.tz(job.bodyshop.timezone)
|
||||
.format(AhDateFormat),
|
||||
OrderedBy: null,
|
||||
ShipVia: null,
|
||||
VendorContact: null,
|
||||
|
||||
@@ -178,6 +178,7 @@ query QUERY_JOBS_FOR_RECEIVABLES_EXPORT($ids: [uuid!]!) {
|
||||
md_responsibility_centers
|
||||
accountingconfig
|
||||
md_ins_cos
|
||||
timezone
|
||||
}
|
||||
}
|
||||
`;
|
||||
@@ -247,6 +248,7 @@ query QUERY_JOBS_FOR_CDK_EXPORT($id: uuid!) {
|
||||
accountingconfig
|
||||
cdk_dealerid
|
||||
cdk_configuration
|
||||
timezone
|
||||
}
|
||||
owner {
|
||||
accountingid
|
||||
@@ -341,6 +343,7 @@ query QUERY_JOBS_FOR_PBS_EXPORT($id: uuid!) {
|
||||
accountingconfig
|
||||
pbs_serialnumber
|
||||
pbs_configuration
|
||||
timezone
|
||||
}
|
||||
owner {
|
||||
id
|
||||
@@ -385,6 +388,7 @@ query QUERY_BILLS_FOR_PAYABLES_EXPORT($bills: [uuid!]!) {
|
||||
class
|
||||
bodyshop{
|
||||
md_responsibility_centers
|
||||
timezone
|
||||
}
|
||||
}
|
||||
billlines{
|
||||
@@ -411,6 +415,7 @@ exports.QUERY_PAYMENTS_FOR_EXPORT = `
|
||||
id
|
||||
md_responsibility_centers
|
||||
accountingconfig
|
||||
timezone
|
||||
}
|
||||
payments(where: {id: {_in: $payments}}) {
|
||||
id
|
||||
@@ -460,6 +465,7 @@ exports.QUERY_UPCOMING_APPOINTMENTS = `query QUERY_UPCOMING_APPOINTMENTS($now: t
|
||||
ssbuckets
|
||||
target_touchtime
|
||||
workingdays
|
||||
timezone
|
||||
}
|
||||
jobhrs: joblines_aggregate(where: {removed: {_eq: false}}) {
|
||||
aggregate {
|
||||
@@ -558,7 +564,7 @@ exports.AUTOHOUSE_QUERY = `query AUTOHOUSE_EXPORT($start: timestamptz, $bodyshop
|
||||
autohouseid
|
||||
md_responsibility_centers
|
||||
jc_hourly_rates
|
||||
|
||||
timezone
|
||||
}
|
||||
jobs(where: {_and: [{converted: {_eq: true}}, {updated_at: {_gt: $start}}, {shopid: {_eq: $bodyshopid}}]}) {
|
||||
id
|
||||
@@ -1234,6 +1240,7 @@ exports.GET_AUTOHOUSE_SHOPS = `query GET_AUTOHOUSE_SHOPS {
|
||||
md_responsibility_centers
|
||||
jc_hourly_rates
|
||||
imexshopid
|
||||
timezone
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -2,7 +2,7 @@ const GraphQLClient = require("graphql-request").GraphQLClient;
|
||||
const path = require("path");
|
||||
const queries = require("../graphql-client/queries");
|
||||
const Dinero = require("dinero.js");
|
||||
const moment = require("moment");
|
||||
const moment = require("moment-timezone");
|
||||
const logger = require("../utils/logger");
|
||||
const _ = require("lodash");
|
||||
require("dotenv").config({
|
||||
@@ -32,7 +32,7 @@ exports.job = async (req, res) => {
|
||||
});
|
||||
|
||||
const { jobs_by_pk, blockedDays, prodJobs, arrJobs, compJobs } = result;
|
||||
const { ssbuckets, workingdays } = result.jobs_by_pk.bodyshop;
|
||||
const { ssbuckets, workingdays, timezone } = result.jobs_by_pk.bodyshop;
|
||||
const jobHrs = result.jobs_by_pk.jobhrs.aggregate.sum.mod_lb_hrs;
|
||||
|
||||
const JobBucket = ssbuckets.filter(
|
||||
@@ -68,7 +68,9 @@ exports.job = async (req, res) => {
|
||||
);
|
||||
|
||||
filteredArrJobs.forEach((item) => {
|
||||
const itemDate = moment(item.scheduled_in).format("yyyy-MM-DD");
|
||||
const itemDate = moment(item.scheduled_in)
|
||||
.tz(timezone)
|
||||
.format("yyyy-MM-DD");
|
||||
if (!!load[itemDate]) {
|
||||
load[itemDate].hoursIn =
|
||||
(load[itemDate].hoursIn || 0) +
|
||||
@@ -100,18 +102,17 @@ exports.job = async (req, res) => {
|
||||
//Job isn't found in production or coming in.
|
||||
//is it going today or scheduled to go today?
|
||||
if (
|
||||
moment(item.actual_completion || item.scheduled_completion).isSame(
|
||||
moment(),
|
||||
"day"
|
||||
)
|
||||
moment(item.actual_completion || item.scheduled_completion)
|
||||
.tz(timezone)
|
||||
.isSame(moment().tz(timezone), "day")
|
||||
) {
|
||||
console.log("Job is going today anyways, ignore it.", item);
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
moment(item.actual_completion || item.scheduled_completion).isBefore(
|
||||
moment(),
|
||||
moment(item.actual_completion || item.scheduled_completion).tz(timezone).isBefore(
|
||||
moment().tz(timezone),
|
||||
"day"
|
||||
)
|
||||
) {
|
||||
@@ -127,7 +128,7 @@ exports.job = async (req, res) => {
|
||||
} else {
|
||||
const itemDate = moment(
|
||||
item.actual_completion || item.scheduled_completion
|
||||
).format("yyyy-MM-DD");
|
||||
).tz(timezone).format("yyyy-MM-DD");
|
||||
if (!!load[itemDate]) {
|
||||
load[itemDate].hoursOut =
|
||||
(load[itemDate].hoursOut || 0) +
|
||||
@@ -146,20 +147,20 @@ exports.job = async (req, res) => {
|
||||
});
|
||||
|
||||
//Propagate the expected load to each day.
|
||||
const yesterday = moment().subtract(1, "day");
|
||||
const today = moment().startOf("day");
|
||||
const yesterday = moment().tz(timezone).subtract(1, "day");
|
||||
const today = moment().tz(timezone).startOf("day");
|
||||
|
||||
const end = moment.max([
|
||||
...filteredArrJobs.map((a) => moment(a.scheduled_in)),
|
||||
const end = moment.tz(timezone).max([
|
||||
...filteredArrJobs.map((a) => moment(a.scheduled_in).tz(timezone)),
|
||||
...filteredCompJobs
|
||||
.map((p) => moment(p.actual_completion || p.scheduled_completion))
|
||||
.map((p) => moment(p.actual_completion || p.scheduled_completion).tz(timezone))
|
||||
.filter((p) => p.isValid() && p.isAfter(yesterday)),
|
||||
moment().add(5, "days"),
|
||||
moment().tz(timezone).add(5, "days"),
|
||||
]);
|
||||
const range = Math.round(moment.duration(end.diff(today)).asDays());
|
||||
for (var day = 0; day < range; day++) {
|
||||
const current = moment(today).add(day, "days").format("yyyy-MM-DD");
|
||||
const prev = moment(today)
|
||||
const current = moment(today).tz(timezone).add(day, "days").format("yyyy-MM-DD");
|
||||
const prev = moment(today).tz(timezone)
|
||||
.add(day - 1, "days")
|
||||
.format("yyyy-MM-DD");
|
||||
if (!!!load[current]) {
|
||||
@@ -187,7 +188,7 @@ exports.job = async (req, res) => {
|
||||
|
||||
blockedDays.forEach((b) => {
|
||||
//Find it in the load, set it as blocked.
|
||||
const startIsoFormat = moment(b.start).format("YYYY-MM-DD");
|
||||
const startIsoFormat = moment(b.start).tz(timezone).format("YYYY-MM-DD");
|
||||
if (load[startIsoFormat]) load[startIsoFormat].blocked = true;
|
||||
else {
|
||||
load[startIsoFormat] = { blocked: true };
|
||||
@@ -198,12 +199,12 @@ exports.job = async (req, res) => {
|
||||
const possibleDates = [];
|
||||
delete load.productionTotal;
|
||||
const loadKeys = Object.keys(load).sort((a, b) =>
|
||||
moment(a).isAfter(moment(b)) ? 1 : -1
|
||||
moment(a).tz(timezone).isAfter(moment(b).tz(timezone)) ? 1 : -1
|
||||
);
|
||||
|
||||
loadKeys.forEach((loadKey) => {
|
||||
const isShopOpen =
|
||||
(workingdays[dayOfWeekMapper(moment(loadKey).day())] || false) &&
|
||||
(workingdays[dayOfWeekMapper(moment(loadKey).tz(timezone).day())] || false) &&
|
||||
!load[loadKey].blocked;
|
||||
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user