fix(datamart): added some fixed some
This commit is contained in:
29
server/services/dataMart/controller/getCustomerInventory.ts
Normal file
29
server/services/dataMart/controller/getCustomerInventory.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { query } from "../../sqlServer/prodSqlServer.js";
|
||||
import { customerInvNoHold } from "../../sqlServer/querys/dataMart/customerInventoryQuerys.js";
|
||||
|
||||
export const getCurrentCustomerInv = async (customer: any | null) => {
|
||||
let updatedQuery = customerInvNoHold;
|
||||
|
||||
if (customer) {
|
||||
//console.log(data.customer);
|
||||
updatedQuery = customerInvNoHold.replaceAll(
|
||||
"--and IdAdressen",
|
||||
`and IdAdressen = ${customer}`
|
||||
);
|
||||
}
|
||||
try {
|
||||
const inventory = await query(updatedQuery, "Get active inventory");
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "All customer inventory minus holds",
|
||||
data: inventory,
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
message: "There was an error getting the inventory",
|
||||
data: error,
|
||||
};
|
||||
}
|
||||
};
|
||||
66
server/services/dataMart/controller/getOpenOrders.ts
Normal file
66
server/services/dataMart/controller/getOpenOrders.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../../../../database/dbclient.js";
|
||||
import { settings } from "../../../../database/schema/settings.js";
|
||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||
import { query } from "../../sqlServer/prodSqlServer.js";
|
||||
import { openOrders } from "../../sqlServer/querys/dataMart/openOrders.js";
|
||||
|
||||
export const getOpenOrders = async (data: any | null) => {
|
||||
const { data: plantToken, error: plantError } = await tryCatch(
|
||||
db.select().from(settings).where(eq(settings.name, "plantToken"))
|
||||
);
|
||||
if (plantError) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Error getting Settings",
|
||||
data: plantError,
|
||||
};
|
||||
}
|
||||
let orders = [];
|
||||
|
||||
let updatedQuery = openOrders;
|
||||
|
||||
// start days can be sent over
|
||||
if (data?.sDay) {
|
||||
updatedQuery = updatedQuery.replaceAll("[sDay]", data.sDay[0]);
|
||||
} else {
|
||||
updatedQuery = updatedQuery.replaceAll("[sDay]", "15");
|
||||
}
|
||||
|
||||
// end days can be sent over
|
||||
if (data?.eDay) {
|
||||
updatedQuery = updatedQuery.replaceAll("[eDay]", data.eDay[0]);
|
||||
} else {
|
||||
updatedQuery = updatedQuery.replaceAll("[eDay]", "5");
|
||||
}
|
||||
|
||||
try {
|
||||
orders = await query(updatedQuery, "Get active openorders");
|
||||
} catch (error) {
|
||||
return { success: false, message: "Current open orders", data: orders };
|
||||
}
|
||||
|
||||
// add plant token in
|
||||
const pOrders = orders.map((item: any) => {
|
||||
// const dateCon = new Date(item.loadingDate).toLocaleString("en-US", {
|
||||
// month: "numeric",
|
||||
// day: "numeric",
|
||||
// year: "numeric",
|
||||
// hour: "2-digit",
|
||||
// minute: "2-digit",
|
||||
// hour12: false,
|
||||
// });
|
||||
|
||||
//const dateCon = new Date(item.loadingDate).toISOString().replace("T", " ").split(".")[0];
|
||||
const dateCon = new Date(item.loadingDate).toISOString().split("T")[0];
|
||||
//const delDate = new Date(item.deliveryDate).toISOString().replace("T", " ").split(".")[0];
|
||||
const delDate = new Date(item.deliveryDate).toISOString().split("T")[0];
|
||||
return {
|
||||
plantToken: plantToken[0].value,
|
||||
...item,
|
||||
loadingDate: dateCon,
|
||||
deliveryDate: delDate,
|
||||
};
|
||||
});
|
||||
return { success: true, message: "Current open orders", data: pOrders };
|
||||
};
|
||||
@@ -1,14 +1,25 @@
|
||||
import { createLog } from "../../logger/logger.js";
|
||||
import { query } from "../../sqlServer/prodSqlServer.js";
|
||||
import {
|
||||
totalInvNoRn,
|
||||
totalInvRn,
|
||||
} from "../../sqlServer/querys/dataMart/totalINV.js";
|
||||
|
||||
export const getINV = async () => {
|
||||
export const getINV = async (rn: boolean) => {
|
||||
let inventory: any = [];
|
||||
|
||||
let updatedQuery = totalInvNoRn;
|
||||
|
||||
if (rn) {
|
||||
createLog(
|
||||
"info",
|
||||
"datamart",
|
||||
"datamart",
|
||||
"The user requested the running numbers this could take a while."
|
||||
);
|
||||
updatedQuery = totalInvRn;
|
||||
}
|
||||
|
||||
try {
|
||||
inventory = await query(updatedQuery, "Gets Curruent inv");
|
||||
return { success: true, message: "Current inv", data: inventory };
|
||||
|
||||
Reference in New Issue
Block a user