feat(eom): all endpoints created for the eom template to run in all plants
This commit is contained in:
@@ -3,8 +3,12 @@ import { db } from "../../../../database/dbclient.js";
|
||||
import { invHistoricalData } from "../../../../database/schema/historicalINV.js";
|
||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||
import { format } from "date-fns";
|
||||
import { settings } from "../../../../database/schema/settings.js";
|
||||
|
||||
export const historicalInvByDate = async (date: string) => {
|
||||
export const historicalInvByDate = async (
|
||||
date: string,
|
||||
includePlantToken: boolean = false
|
||||
) => {
|
||||
const histDate = new Date(date);
|
||||
|
||||
const { data, error } = (await tryCatch(
|
||||
@@ -24,9 +28,28 @@ export const historicalInvByDate = async (date: string) => {
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `Historical inventory for ${date}`,
|
||||
data: data,
|
||||
};
|
||||
if (includePlantToken) {
|
||||
const { data: s, error: se } = (await tryCatch(
|
||||
db.select().from(settings).where(eq(settings.name, "plantToken"))
|
||||
)) as any;
|
||||
|
||||
if (se) {
|
||||
console.log("Error getting articles");
|
||||
return data;
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `Historical inventory for ${date}`,
|
||||
data: data.map((n: any) => {
|
||||
return { plantToken: s[0].value, ...n };
|
||||
}),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: true,
|
||||
message: `Historical inventory for ${date}`,
|
||||
data: data,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2,8 +2,11 @@ import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||
import { format } from "date-fns";
|
||||
import { query } from "../../sqlServer/prodSqlServer.js";
|
||||
import { lastPurchasePrice } from "../../sqlServer/querys/eom/lstPurchasePrice.js";
|
||||
import { db } from "../../../../database/dbclient.js";
|
||||
import { settings } from "../../../../database/schema/settings.js";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
export const lastPurchase = async () => {
|
||||
export const lastPurchase = async (includePlantToken: boolean = false) => {
|
||||
const { data, error } = (await tryCatch(
|
||||
query(lastPurchasePrice, "Last purchase price")
|
||||
)) as any;
|
||||
@@ -16,9 +19,28 @@ export const lastPurchase = async () => {
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `Last purchase price for all av in the last 5 years`,
|
||||
data: data.data,
|
||||
};
|
||||
if (includePlantToken) {
|
||||
const { data: s, error: se } = (await tryCatch(
|
||||
db.select().from(settings).where(eq(settings.name, "plantToken"))
|
||||
)) as any;
|
||||
|
||||
if (se) {
|
||||
console.log("Error getting articles");
|
||||
return data.data;
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `Last purchase price for all av in the last 5 years`,
|
||||
data: data.data.map((n: any) => {
|
||||
return { plantToken: s[0].value, ...n };
|
||||
}),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: true,
|
||||
message: `Last purchase price for all av in the last 5 years`,
|
||||
data: data.data,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
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 { lastSalesPriceCheck } from "../../sqlServer/querys/eom/lastSalesprice.js";
|
||||
import { format } from "date-fns-tz";
|
||||
|
||||
export const lastSales = async (date: string) => {
|
||||
export const lastSales = async (
|
||||
date: string,
|
||||
includePlantToken: boolean = false
|
||||
) => {
|
||||
const { data, error } = (await tryCatch(
|
||||
query(lastSalesPriceCheck.replace("[date]", date), "Last sales price")
|
||||
)) as any;
|
||||
@@ -15,9 +22,34 @@ export const lastSales = async (date: string) => {
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `Last sales price for all av in the last 5 years`,
|
||||
data: data.data,
|
||||
};
|
||||
if (includePlantToken) {
|
||||
const { data: s, error: se } = (await tryCatch(
|
||||
db.select().from(settings).where(eq(settings.name, "plantToken"))
|
||||
)) as any;
|
||||
|
||||
if (se) {
|
||||
console.log("Error getting articles");
|
||||
return data.data;
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `Historical inventory for ${date}`,
|
||||
data: data.data.map((n: any) => {
|
||||
return {
|
||||
plantToken: s[0].value,
|
||||
...n,
|
||||
validDate: format(n.validDate, "M/d/yyyy"),
|
||||
};
|
||||
}),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: true,
|
||||
message: `Last sales price for all av in the last 5 years`,
|
||||
data: data.data.map((n: any) => {
|
||||
return { ...n, validDate: format(n.validDate, "M/d/yyyy") };
|
||||
}),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
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 { lastSalesPriceCheck } from "../../sqlServer/querys/eom/lastSalesprice.js";
|
||||
import { consumptionCheck } from "../../sqlServer/querys/eom/consumptionCheck.js";
|
||||
import { format } from "date-fns-tz";
|
||||
|
||||
type Consumption = {
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
includePlantToken: boolean;
|
||||
};
|
||||
|
||||
export const getProductionConsumption = async (consumption: Consumption) => {
|
||||
const { data, error } = (await tryCatch(
|
||||
query(
|
||||
consumptionCheck
|
||||
.replace("[startDate]", consumption.startDate)
|
||||
.replace("[endDate]", consumption.endDate),
|
||||
"Last sales price"
|
||||
)
|
||||
)) as any;
|
||||
|
||||
if (error) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Error getting the last sales price",
|
||||
data: error,
|
||||
};
|
||||
}
|
||||
|
||||
if (consumption.includePlantToken) {
|
||||
const { data: s, error: se } = (await tryCatch(
|
||||
db.select().from(settings).where(eq(settings.name, "plantToken"))
|
||||
)) as any;
|
||||
|
||||
if (se) {
|
||||
console.log("Error getting articles");
|
||||
return data.data;
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `consumption data`,
|
||||
data: data.data.map((n: any) => {
|
||||
return {
|
||||
plantToken: s[0].value,
|
||||
...n,
|
||||
Prod_Date: format(n.Prod_Date, "M/d/yyyy"),
|
||||
};
|
||||
}),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: true,
|
||||
message: `consumption data`,
|
||||
data: data.data.map((n: any) => {
|
||||
return {
|
||||
...n,
|
||||
Prod_Date: format(n.Prod_Date, "M/d/yyyy"),
|
||||
};
|
||||
}),
|
||||
};
|
||||
}
|
||||
};
|
||||
66
lstV2/server/services/eom/controller/getPurchased.ts
Normal file
66
lstV2/server/services/eom/controller/getPurchased.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 { format } from "date-fns-tz";
|
||||
import { purchased } from "../../sqlServer/querys/eom/purchased.js";
|
||||
|
||||
type Consumption = {
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
includePlantToken: boolean;
|
||||
};
|
||||
|
||||
export const getPurchased = async (consumption: Consumption) => {
|
||||
const { data, error } = (await tryCatch(
|
||||
query(
|
||||
purchased
|
||||
.replace("[startDate]", consumption.startDate)
|
||||
.replace("[endDate]", consumption.endDate),
|
||||
"Last sales price"
|
||||
)
|
||||
)) as any;
|
||||
|
||||
if (error) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Error getting the last sales price",
|
||||
data: error,
|
||||
};
|
||||
}
|
||||
|
||||
if (consumption.includePlantToken) {
|
||||
const { data: s, error: se } = (await tryCatch(
|
||||
db.select().from(settings).where(eq(settings.name, "plantToken"))
|
||||
)) as any;
|
||||
|
||||
if (se) {
|
||||
console.log("Error getting articles");
|
||||
return data.data;
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `consumption data`,
|
||||
data: data.data.map((n: any) => {
|
||||
return {
|
||||
plantToken: s[0].value,
|
||||
...n,
|
||||
Received_Date: format(n.Received_Date, "M/d/yyyy"),
|
||||
};
|
||||
}),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: true,
|
||||
message: `consumption data`,
|
||||
data: data.data.map((n: any) => {
|
||||
return {
|
||||
...n,
|
||||
Received_Date: format(n.Received_Date, "M/d/yyyy"),
|
||||
};
|
||||
}),
|
||||
};
|
||||
}
|
||||
};
|
||||
68
lstV2/server/services/eom/controller/getSoldItems.ts
Normal file
68
lstV2/server/services/eom/controller/getSoldItems.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
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 { format } from "date-fns-tz";
|
||||
|
||||
import { soldOutItems } from "../../sqlServer/querys/eom/soldOut.js";
|
||||
|
||||
type Consumption = {
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
includePlantToken: boolean;
|
||||
};
|
||||
|
||||
export const getSoldItems = async (consumption: Consumption) => {
|
||||
const { data, error } = (await tryCatch(
|
||||
query(
|
||||
soldOutItems
|
||||
.replace("[startDate]", consumption.startDate)
|
||||
.replace("[endDate]", consumption.endDate),
|
||||
"Last sales price"
|
||||
)
|
||||
)) as any;
|
||||
|
||||
if (error) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Error getting the last sales price",
|
||||
data: error,
|
||||
};
|
||||
}
|
||||
|
||||
if (consumption.includePlantToken) {
|
||||
const { data: s, error: se } = (await tryCatch(
|
||||
db.select().from(settings).where(eq(settings.name, "plantToken"))
|
||||
)) as any;
|
||||
|
||||
if (se) {
|
||||
console.log("Error getting articles");
|
||||
return data.data;
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `consumption data`,
|
||||
data: data.data.map((n: any) => {
|
||||
return {
|
||||
plantToken: s[0].value,
|
||||
...n,
|
||||
DeliveryDate: format(n.DeliveryDate, "M/d/yyyy"),
|
||||
};
|
||||
}),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: true,
|
||||
message: `consumption data`,
|
||||
data: data.data.map((n: any) => {
|
||||
return {
|
||||
...n,
|
||||
DeliveryDate: format(n.DeliveryDate, "M/d/yyyy"),
|
||||
};
|
||||
}),
|
||||
};
|
||||
}
|
||||
};
|
||||
68
lstV2/server/services/eom/controller/getregrind.ts
Normal file
68
lstV2/server/services/eom/controller/getregrind.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
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 { lastSalesPriceCheck } from "../../sqlServer/querys/eom/lastSalesprice.js";
|
||||
import { consumptionCheck } from "../../sqlServer/querys/eom/consumptionCheck.js";
|
||||
import { format } from "date-fns-tz";
|
||||
import { regrindCheck } from "../../sqlServer/querys/eom/regrind.js";
|
||||
|
||||
type Consumption = {
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
includePlantToken: boolean;
|
||||
};
|
||||
|
||||
export const getRegrind = async (consumption: Consumption) => {
|
||||
const { data, error } = (await tryCatch(
|
||||
query(
|
||||
regrindCheck
|
||||
.replace("[startDate]", consumption.startDate)
|
||||
.replace("[endDate]", consumption.endDate),
|
||||
"Last sales price"
|
||||
)
|
||||
)) as any;
|
||||
|
||||
if (error) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Error getting the last sales price",
|
||||
data: error,
|
||||
};
|
||||
}
|
||||
|
||||
if (consumption.includePlantToken) {
|
||||
const { data: s, error: se } = (await tryCatch(
|
||||
db.select().from(settings).where(eq(settings.name, "plantToken"))
|
||||
)) as any;
|
||||
|
||||
if (se) {
|
||||
console.log("Error getting articles");
|
||||
return data.data;
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `consumption data`,
|
||||
data: data.data.map((n: any) => {
|
||||
return {
|
||||
plantToken: s[0].value,
|
||||
...n,
|
||||
Buchungsdatum: format(n.Buchungsdatum, "M/d/yyyy"),
|
||||
};
|
||||
}),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: true,
|
||||
message: `consumption data`,
|
||||
data: data.data.map((n: any) => {
|
||||
return {
|
||||
...n,
|
||||
Buchungsdatum: format(n.Buchungsdatum, "M/d/yyyy"),
|
||||
};
|
||||
}),
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user