refactor(quality): added some new options plus cancel button
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
vars {
|
vars {
|
||||||
url: http://localhost:4200
|
url: http://localhost:4200
|
||||||
session_cookie:
|
session_cookie:
|
||||||
urlv2: http://localhost:3000
|
urlv2: http://usmcd1vms036:3000
|
||||||
jwtV2:
|
jwtV2:
|
||||||
userID:
|
userID:
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ export type UserRoles = {
|
|||||||
| "supervisor"
|
| "supervisor"
|
||||||
| "manager"
|
| "manager"
|
||||||
| "admin"
|
| "admin"
|
||||||
| "systemAdmin";
|
| "systemAdmin"
|
||||||
|
| "user";
|
||||||
};
|
};
|
||||||
|
|
||||||
type UserRoleState = {
|
type UserRoleState = {
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ export default function TableNoExpand({
|
|||||||
});
|
});
|
||||||
return (
|
return (
|
||||||
<div className="p-4">
|
<div className="p-4">
|
||||||
<ScrollArea className="w-11/12 rounded-md border whitespace-nowrap">
|
<Table className="table-fixed w-full">
|
||||||
<Table>
|
<ScrollArea className="w-full rounded-md border whitespace-nowrap">
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
{table.getHeaderGroups().map((headerGroup) => (
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
<TableRow key={headerGroup.id}>
|
<TableRow key={headerGroup.id}>
|
||||||
@@ -89,27 +89,28 @@ export default function TableNoExpand({
|
|||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
<ScrollBar orientation="horizontal" />
|
||||||
<div className="flex items-center justify-end space-x-2 py-4">
|
</ScrollArea>
|
||||||
<Button
|
</Table>
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
<div className="flex items-center justify-end space-x-2 py-4">
|
||||||
onClick={() => table.previousPage()}
|
<Button
|
||||||
disabled={!table.getCanPreviousPage()}
|
variant="outline"
|
||||||
>
|
size="sm"
|
||||||
Previous
|
onClick={() => table.previousPage()}
|
||||||
</Button>
|
disabled={!table.getCanPreviousPage()}
|
||||||
<Button
|
>
|
||||||
variant="outline"
|
Previous
|
||||||
size="sm"
|
</Button>
|
||||||
onClick={() => table.nextPage()}
|
<Button
|
||||||
disabled={!table.getCanNextPage()}
|
variant="outline"
|
||||||
>
|
size="sm"
|
||||||
Next
|
onClick={() => table.nextPage()}
|
||||||
</Button>
|
disabled={!table.getCanNextPage()}
|
||||||
</div>
|
>
|
||||||
<ScrollBar orientation="horizontal" />
|
Next
|
||||||
</ScrollArea>
|
</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,16 @@ import { useQuery } from "@tanstack/react-query";
|
|||||||
import { useNavigate, useRouterState } from "@tanstack/react-router";
|
import { useNavigate, useRouterState } from "@tanstack/react-router";
|
||||||
import { createColumnHelper } from "@tanstack/react-table";
|
import { createColumnHelper } from "@tanstack/react-table";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { ArrowDown, ArrowUp } from "lucide-react";
|
import { ArrowDown, ArrowUp, Trash2 } from "lucide-react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
|
SelectGroup,
|
||||||
SelectItem,
|
SelectItem,
|
||||||
|
SelectLabel,
|
||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
} from "@/components/ui/select";
|
} from "@/components/ui/select";
|
||||||
@@ -30,7 +32,6 @@ type Pallets = {
|
|||||||
durationToMove: null;
|
durationToMove: null;
|
||||||
qualityDurationToInspect: number;
|
qualityDurationToInspect: number;
|
||||||
returnDurationToInspect: number;
|
returnDurationToInspect: number;
|
||||||
locationMovesTo: string;
|
|
||||||
locationDropOff: string;
|
locationDropOff: string;
|
||||||
palletStatus: number;
|
palletStatus: number;
|
||||||
palletStatusText: string;
|
palletStatusText: string;
|
||||||
@@ -40,6 +41,8 @@ type Pallets = {
|
|||||||
add_user: string;
|
add_user: string;
|
||||||
upd_date: Date;
|
upd_date: Date;
|
||||||
upd_user: string;
|
upd_user: string;
|
||||||
|
palletComplete: string;
|
||||||
|
canceled: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function QualityRequest() {
|
export default function QualityRequest() {
|
||||||
@@ -50,35 +53,35 @@ export default function QualityRequest() {
|
|||||||
const router = useRouterState();
|
const router = useRouterState();
|
||||||
const currentPath = router.location.href;
|
const currentPath = router.location.href;
|
||||||
|
|
||||||
const palletCompleted = async (e: any) => {
|
// const palletCompleted = async (e: any) => {
|
||||||
if (!session || !session.user) {
|
// if (!session || !session.user) {
|
||||||
toast.error("You are allowed to do this unless you are logged in");
|
// toast.error("You are allowed to do this unless you are logged in");
|
||||||
navigate({ to: "/login", search: { redirect: currentPath } });
|
// navigate({ to: "/login", search: { redirect: currentPath } });
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
const data = {
|
// const data = {
|
||||||
username: session?.user.username,
|
// username: session?.user.username,
|
||||||
runningNr: Number(e.original.runningNr),
|
// runningNr: Number(e.original.runningNr),
|
||||||
palletStatusText: "return",
|
// palletStatusText: "return",
|
||||||
};
|
// };
|
||||||
try {
|
// try {
|
||||||
const res = await axios.post("/lst/old/api/quality/newrequest", data);
|
// const res = await axios.post("/lst/old/api/quality/newrequest", data);
|
||||||
|
|
||||||
//console.log(res.data);
|
// //console.log(res.data);
|
||||||
|
|
||||||
if (res.data.success) {
|
// if (res.data.success) {
|
||||||
toast.success(res.data.message);
|
// toast.success(res.data.message);
|
||||||
refetch();
|
// refetch();
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (!res.data.success) {
|
// if (!res.data.success) {
|
||||||
toast.error(res.data.message);
|
// toast.error(res.data.message);
|
||||||
}
|
// }
|
||||||
} catch (error) {
|
// } catch (error) {
|
||||||
console.log(error);
|
// console.log(error);
|
||||||
toast.error("Encountered and error please try again");
|
// toast.error("Encountered and error please try again");
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
columnHelper.accessor("article", {
|
columnHelper.accessor("article", {
|
||||||
@@ -166,14 +169,14 @@ export default function QualityRequest() {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
columnHelper.accessor("locationMovesTo", {
|
columnHelper.accessor("locationMovedTo", {
|
||||||
header: ({ column }) => {
|
header: ({ column }) => {
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
>
|
>
|
||||||
<span className="flex flex-row gap-2">Location At Request</span>
|
<span className="flex flex-row gap-2">Location Moved to</span>
|
||||||
{column.getIsSorted() === "asc" ? (
|
{column.getIsSorted() === "asc" ? (
|
||||||
<ArrowUp className="ml-2 h-4 w-4" />
|
<ArrowUp className="ml-2 h-4 w-4" />
|
||||||
) : (
|
) : (
|
||||||
@@ -227,7 +230,7 @@ export default function QualityRequest() {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
columnHelper.accessor("palletRequest", {
|
columnHelper.accessor("palletComplete", {
|
||||||
header: ({ column }) => {
|
header: ({ column }) => {
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
@@ -245,15 +248,78 @@ export default function QualityRequest() {
|
|||||||
},
|
},
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
// if pending
|
// if pending
|
||||||
|
|
||||||
|
//const [p, setP] = useState(`${getValue()}`);
|
||||||
const okToCompleteStats = [2, 4, 5];
|
const okToCompleteStats = [2, 4, 5];
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{okToCompleteStats.includes(row.original.palletStatus) ? (
|
{okToCompleteStats.includes(row.original.palletStatus) ? (
|
||||||
<Button variant="outline" onClick={() => palletCompleted(row)}>
|
<Select
|
||||||
Check Complete
|
//value={"return to warehouse"}
|
||||||
</Button>
|
onValueChange={async (value) => {
|
||||||
|
if (!session || !session.user) {
|
||||||
|
toast.error(
|
||||||
|
"You are allowed to do this unless you are logged in",
|
||||||
|
);
|
||||||
|
navigate({
|
||||||
|
to: "/login",
|
||||||
|
search: { redirect: currentPath },
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
username: session?.user.username,
|
||||||
|
runningNr: Number(row.original.runningNr),
|
||||||
|
palletStatusText: value,
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await axios.post(
|
||||||
|
"/lst/old/api/quality/newrequest",
|
||||||
|
data,
|
||||||
|
);
|
||||||
|
|
||||||
|
//console.log(res.data);
|
||||||
|
|
||||||
|
if (res.data.success) {
|
||||||
|
toast.success(res.data.message);
|
||||||
|
refetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!res.data.success) {
|
||||||
|
toast.error(res.data.message);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
toast.error("Encountered and error please try again");
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectTrigger
|
||||||
|
// className={cn(
|
||||||
|
// "w-[100px]",
|
||||||
|
// active
|
||||||
|
// ? "border-green-500 text-green-600"
|
||||||
|
// : "border-gray-400 text-gray-500",
|
||||||
|
// )}
|
||||||
|
>
|
||||||
|
<SelectValue placeholder="Complete Selection" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectGroup>
|
||||||
|
<SelectLabel>Location to drop off</SelectLabel>
|
||||||
|
<SelectItem value="return to warehouse">
|
||||||
|
Return to Warehouse
|
||||||
|
</SelectItem>
|
||||||
|
<SelectItem value="rework">Rework</SelectItem>
|
||||||
|
<SelectItem value="grind">Grind</SelectItem>
|
||||||
|
<SelectItem value="scrap">Scrap</SelectItem>
|
||||||
|
</SelectGroup>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
) : (
|
) : (
|
||||||
<span>Pending to be completed</span>
|
<span>Pending move</span>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
@@ -262,7 +328,9 @@ export default function QualityRequest() {
|
|||||||
];
|
];
|
||||||
|
|
||||||
let adminColumns: any = [];
|
let adminColumns: any = [];
|
||||||
if (userAccess("quality", ["systemAdmin", "admin", "supervisor"])) {
|
if (
|
||||||
|
userAccess("quality", ["systemAdmin", "admin", "supervisor", "manager"])
|
||||||
|
) {
|
||||||
adminColumns = [
|
adminColumns = [
|
||||||
...columns,
|
...columns,
|
||||||
columnHelper.accessor("priority", {
|
columnHelper.accessor("priority", {
|
||||||
@@ -287,7 +355,6 @@ export default function QualityRequest() {
|
|||||||
// if pending
|
// if pending
|
||||||
|
|
||||||
const [p, setP] = useState(`${getValue()}`);
|
const [p, setP] = useState(`${getValue()}`);
|
||||||
console.log(getValue());
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Select
|
<Select
|
||||||
@@ -343,6 +410,78 @@ export default function QualityRequest() {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
columnHelper.accessor("palletComplete", {
|
||||||
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() =>
|
||||||
|
column.toggleSorting(column.getIsSorted() === "asc")
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<span className="flex flex-row gap-2">Cancel</span>
|
||||||
|
{column.getIsSorted() === "asc" ? (
|
||||||
|
<ArrowUp className="ml-2 h-4 w-4" />
|
||||||
|
) : (
|
||||||
|
<ArrowDown className="ml-2 h-4 w-4" />
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
//value={"return to warehouse"}
|
||||||
|
variant="destructive"
|
||||||
|
onClick={async () => {
|
||||||
|
if (!session || !session.user) {
|
||||||
|
toast.error(
|
||||||
|
"You are allowed to do this unless you are logged in",
|
||||||
|
);
|
||||||
|
navigate({
|
||||||
|
to: "/login",
|
||||||
|
search: { redirect: currentPath },
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
username: session?.user.username,
|
||||||
|
runningNr: Number(row.original.runningNr),
|
||||||
|
palletStatusText: "canceled",
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await axios.post(
|
||||||
|
"/lst/old/api/quality/newrequest",
|
||||||
|
data,
|
||||||
|
);
|
||||||
|
|
||||||
|
//console.log(res.data);
|
||||||
|
|
||||||
|
if (res.data.success) {
|
||||||
|
toast.success(
|
||||||
|
`${row.original.runningNr} was just canceled`,
|
||||||
|
);
|
||||||
|
refetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!res.data.success) {
|
||||||
|
toast.error(res.data.message);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
toast.error("Encountered and error please try again");
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Trash2 className="w-[24px] h-[24px]" />
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
}),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ export const Route = createFileRoute("/_old/old/quality/")({
|
|||||||
"admin",
|
"admin",
|
||||||
"manager",
|
"manager",
|
||||||
"supervisor",
|
"supervisor",
|
||||||
|
"user",
|
||||||
],
|
],
|
||||||
moduleName: "quality", // optional
|
moduleName: "quality", // optional
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ export const addNewPallet = async (data: any) => {
|
|||||||
* Post new pallets
|
* Post new pallets
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const returnLabels = ["return to warehouse", "rework", "grind", "scrap"];
|
||||||
|
|
||||||
|
console.log(data, returnLabels.includes(data.palletStatusText));
|
||||||
|
|
||||||
if (parseInt(data.runningNr) <= 0) {
|
if (parseInt(data.runningNr) <= 0) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -40,7 +44,7 @@ export const addNewPallet = async (data: any) => {
|
|||||||
const palletData: any = c;
|
const palletData: any = c;
|
||||||
// if the pallet exist then tell the user to check on it
|
// if the pallet exist then tell the user to check on it
|
||||||
const pStatus = [1, 4, 6];
|
const pStatus = [1, 4, 6];
|
||||||
if (!data.priority) {
|
if (!data.priority && data.palletStatusText !== "canceled") {
|
||||||
if (palletData && pStatus.includes(palletData[0]?.palletStatus)) {
|
if (palletData && pStatus.includes(palletData[0]?.palletStatus)) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -73,22 +77,39 @@ export const addNewPallet = async (data: any) => {
|
|||||||
upd_user: data.user,
|
upd_user: data.user,
|
||||||
upd_date: sql`NOW()`,
|
upd_date: sql`NOW()`,
|
||||||
};
|
};
|
||||||
} else {
|
} else if (data.palletStatusText === "canceled") {
|
||||||
pData = {
|
pData = {
|
||||||
warehouseAtRequest: p[0].warehouseAtRequest,
|
warehouseAtRequest: null,
|
||||||
locationAtRequest: p[0].locationAtRequest,
|
locationAtRequest: null,
|
||||||
warehouseMovedTo: null,
|
warehouseMovedTo: null,
|
||||||
locationMovedTo: null,
|
locationMovedTo: null,
|
||||||
palletStatus: data.palletStatusText === "return" ? 6 : 4,
|
palletStatus: 5,
|
||||||
//durationToMove: 0,
|
//durationToMove: 0,
|
||||||
palletStatusText:
|
palletStatusText: "canceled",
|
||||||
data.palletStatusText === "return" ? "return" : "reactivated",
|
qualityDurationToInspect: 0,
|
||||||
qualityDurationToInspect:
|
locationDropOff: "canceled",
|
||||||
data.palletStatusText === "return"
|
palletRequest: palletData[0].palletStatus + 1,
|
||||||
? differenceInMinutes(new Date(Date.now()), p[0].lastMove)
|
upd_user: data.user,
|
||||||
: 0,
|
upd_date: sql`NOW()`,
|
||||||
locationDropOff:
|
};
|
||||||
data.palletStatusText === "return" ? "Return to warhouse" : "",
|
} else {
|
||||||
|
pData = {
|
||||||
|
warehouseAtRequest: p[0].warehouseAtRequest || "no longer on stock",
|
||||||
|
locationAtRequest: p[0].locationAtRequest || "no longer on stock",
|
||||||
|
warehouseMovedTo: null,
|
||||||
|
locationMovedTo: null,
|
||||||
|
palletStatus: returnLabels.includes(data.palletStatusText) ? 6 : 4,
|
||||||
|
//durationToMove: 0,
|
||||||
|
palletStatusText: returnLabels.includes(data.palletStatusText)
|
||||||
|
? data.palletStatusText
|
||||||
|
: "reactivated",
|
||||||
|
|
||||||
|
qualityDurationToInspect: returnLabels.includes(data.palletStatusText)
|
||||||
|
? differenceInMinutes(new Date(Date.now()), p[0].lastMove)
|
||||||
|
: 0,
|
||||||
|
locationDropOff: returnLabels.includes(data.palletStatusText)
|
||||||
|
? data.palletStatusText
|
||||||
|
: "No location Checked",
|
||||||
palletRequest: palletData[0].palletStatus + 1,
|
palletRequest: palletData[0].palletStatus + 1,
|
||||||
upd_user: data.user,
|
upd_user: data.user,
|
||||||
upd_date: sql`NOW()`,
|
upd_date: sql`NOW()`,
|
||||||
|
|||||||
@@ -71,21 +71,21 @@ export const qualityCycle = async () => {
|
|||||||
const qDataPost = {
|
const qDataPost = {
|
||||||
warehouseMovedTo: prodData[0]?.warehouseAtRequest,
|
warehouseMovedTo: prodData[0]?.warehouseAtRequest,
|
||||||
locationMovedTo: prodData[0]?.locationAtRequest,
|
locationMovedTo: prodData[0]?.locationAtRequest,
|
||||||
// how ling did it take the warhouse to originally move the pallet
|
// how ling did it take the warehouse to originally move the pallet
|
||||||
durationToMove: warehouse.includes(lstQData[i].palletStatus)
|
durationToMove: warehouse.includes(lstQData[i].palletStatus)
|
||||||
? differenceInMinutes(
|
? differenceInMinutes(
|
||||||
new Date(Date.now()),
|
new Date(Date.now()),
|
||||||
lstQData[i].upd_date,
|
lstQData[i].upd_date,
|
||||||
)
|
)
|
||||||
: lstQData[i].durationToMove,
|
: lstQData[i].durationToMove,
|
||||||
// how long did it take warehouse to move the pallet back agian
|
// how long did it take warehouse to move the pallet back again
|
||||||
returnDurationToInspect:
|
returnDurationToInspect:
|
||||||
lstQData[i].palletStatus === 7
|
lstQData[i].palletStatus === 7
|
||||||
? differenceInMinutes(
|
? differenceInMinutes(
|
||||||
new Date(Date.now()),
|
new Date(Date.now()),
|
||||||
lstQData[i].upd_date,
|
lstQData[i].upd_date,
|
||||||
)
|
)
|
||||||
: lstQData[i].qualityDurationToInspect,
|
: lstQData[i].returnDurationToInspect,
|
||||||
palletStatus: 2,
|
palletStatus: 2,
|
||||||
palletStatusText: "moved",
|
palletStatusText: "moved",
|
||||||
upd_date: sql`NOW()`,
|
upd_date: sql`NOW()`,
|
||||||
|
|||||||
Reference in New Issue
Block a user