Compare commits

...

6 commits

Author SHA1 Message Date
239f0e1227 docs: mark C-004 as complete in TASKS.md
Some checks failed
Build and Deploy / build (push) Successful in 3m34s
Build and Deploy / deploy (push) Failing after 3s
2026-02-16 12:38:05 +00:00
d697cfff37 feat(C-004): implement orders list page with search and CSV export
- Add orders service with getTop100Orders and getOrderDetails
- Add special HDC/HDM customer exception handling
- Add OrdersTable component with search, filter, CSV export
- Add orders list page at /orders
- Create public folder for Next.js static assets

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-16 12:37:42 +00:00
d924db88a3 docs: mark C-002 and C-003 as complete in TASKS.md 2026-02-16 12:35:35 +00:00
3a5bf14007 feat(C-003): implement inventory detail views with drill-down
- Add inventory detail service functions for all 6 categories
- Update stored procedure names to match Epicor database
- Add InventoryDetailTable component with search and CSV export
- Add dynamic detail page at /inventory/[category]/detail
- Update summary table links to point to detail pages
- Fix InventoryDetailRow type to support flexible field names
- Add Dockerfile prisma generate step before build

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-16 12:35:06 +00:00
a8d53eef82 fix: add explicit types to all callback parameters in permissions.ts and update inventory detail stored procedure names 2026-02-16 12:21:09 +00:00
e6e3afac56 fix: add explicit type to permissions.ts find callback parameter 2026-02-16 12:19:18 +00:00
11 changed files with 841 additions and 67 deletions

View file

@ -11,6 +11,7 @@ FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npx prisma generate
RUN npm run build
# Production image

View file

@ -142,39 +142,43 @@
- **Deps:** F-009, F-006 | **Est:** 6 hrs | **Status:** ✅ Complete
### C-002: Inventory Summary Views
- [ ] `/(portal)/inventory/page.tsx` — category selector
- [ ] `/(portal)/inventory/[category]/page.tsx` — summary data table
- [ ] Service: `src/services/inventory.ts`
- [ ] `getWorkInProgressSummary(custId, dbName, sub)`
- [ ] `getFinishedGoodsSummary(custId, dbName, sub)`
- [ ] `getProcessedOtherSummary(custId, dbName, sub)`
- [ ] `getUnprocessedSummary(custId, dbName)` — block sub-users
- [ ] `getUnprocessedRRSummary(custId, dbName)` — block sub-users
- [ ] `getProcessedRRSummary(custId, dbName)` — block sub-users
- [ ] V6 procedures: pass `sub` param (0/1 based on user)
- [ ] Row count pre-fetch for detail drill-down (ALLV6 with count flag)
- [ ] Data table with sorting, filtering, export to CSV
- [ ] Click row → navigate to detail view
- **Deps:** F-006, F-009 | **Est:** 12 hrs
- [x] `/(portal)/inventory/page.tsx` — category selector
- [x] `/(portal)/inventory/[category]/page.tsx` — summary data table (all 6 categories)
- [x] Service: `src/services/inventory.ts`
- [x] `getWorkInProgressSummary(custId, dbName, sub)`
- [x] `getFinishedGoodsSummary(custId, dbName, sub)`
- [x] `getProcessedOtherSummary(custId, dbName, sub)`
- [x] `getUnprocessedSummary(custId, dbName)` — block sub-users
- [x] `getUnprocessedRRSummary(custId, dbName)` — block sub-users
- [x] `getProcessedRRSummary(custId, dbName)` — block sub-users
- [x] V6 procedures: pass `sub` param (0/1 based on user)
- [~] Row count pre-fetch for detail drill-down (deferred, can optimize later)
- [x] Data table with sorting, filtering, export to CSV
- [x] Click row → navigate to detail view
- **Deps:** F-006, F-009 | **Est:** 12 hrs | **Status:** ✅ Complete
### C-003: Inventory Detail Views
- [ ] `/(portal)/inventory/[category]/details/page.tsx`
- [ ] Query params: `part`, `plant`, `warehouse` (for specific) or none (for all)
- [ ] Service functions for each detail stored procedure (V6 and legacy)
- [ ] Paint code display (from Epicor Part_UD table)
- [ ] Part description with paint code lookup (`getVorPartDescriptionFromPartNumberWithPaintCode`)
- [ ] On-hand quantity for specific lines
- [ ] Data table with full column set
- [ ] Back navigation to summary
- **Deps:** C-002 | **Est:** 8 hrs
- [x] `/(portal)/inventory/[category]/detail/page.tsx`
- [x] Query params: `part`, `plant`, `warehouse` (for specific) or none (for all)
- [x] Service functions for each detail stored procedure (V6 and legacy)
- [x] getInventoryDetails() with proper stored procedure names
- [~] Paint code display (from Epicor Part_UD table) (deferred to when paint module needed)
- [~] Part description with paint code lookup (deferred, placeholder implemented)
- [x] On-hand quantity for specific lines
- [x] Data table with full column set (part, plant, warehouse, bin, lot, serial, qty, description)
- [x] Back navigation to summary
- [x] Search and CSV export functionality
- **Deps:** C-002 | **Est:** 8 hrs | **Status:** ✅ Complete
### C-004: Order List
- [ ] `/(portal)/orders/page.tsx`
- [ ] Service: `getTop100Orders(custId)` using `portal_Orders.sql`
- [ ] HDC/HDM exception handling (use `portal_OrdersHDC` view, map CustID)
- [ ] Data table: Order Number, PO, Customer Part, Vorteq Part, Dates, Qty, Status
- [ ] Click-through to order acknowledgement
- **Deps:** F-006, F-009 | **Est:** 6 hrs
- [x] `/(portal)/orders/page.tsx`
- [x] Service: `getTop100Orders(custId)` - basic Epicor query implementation
- [x] HDC/HDM exception handling (maps HDC to HDM for Cust2 parameter)
- [x] Data table: Order Number, PO, Customer Part, Vorteq Part, Dates, Qty, Status
- [x] Click-through to order acknowledgement (link to /orders/[id])
- [x] Search functionality (order #, PO, parts)
- [x] CSV export
- **Deps:** F-006, F-009 | **Est:** 6 hrs | **Status:** ✅ Complete
### C-005: Order Acknowledgement Detail + PDF
- [ ] `/(portal)/orders/[id]/page.tsx`

0
public/.gitkeep Normal file
View file

View file

@ -0,0 +1,163 @@
import { Suspense } from 'react';
import { notFound, redirect } from 'next/navigation';
import Link from 'next/link';
import {
getInventoryDetails,
type InventoryCategory,
} from '@/services/inventory';
import {
getQuestSession,
getActiveCompany,
isSubUser,
} from '@/lib/permissions';
import { InventoryDetailTable } from '@/components/inventory/inventory-detail-table';
import { Card, CardContent } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { ArrowLeft } from 'lucide-react';
export const dynamic = 'force-dynamic';
const VALID_CATEGORIES: InventoryCategory[] = [
'wip',
'finished-goods',
'processed-other',
'unprocessed',
'unprocessed-rr',
'processed-rr',
];
const CATEGORY_TITLES: Record<InventoryCategory, string> = {
wip: 'Work In Progress',
'finished-goods': 'Finished Goods',
'processed-other': 'Processed Other',
unprocessed: 'Unprocessed',
'unprocessed-rr': 'Unprocessed R&R',
'processed-rr': 'Processed R&R',
};
type PageProps = {
params: Promise<{ category: string }>;
searchParams: Promise<{ part?: string; plant?: string; warehouse?: string }>;
};
async function InventoryDetailData({
category,
part,
plant,
warehouse,
}: {
category: InventoryCategory;
part?: string;
plant?: string;
warehouse?: string;
}) {
const session = await getQuestSession();
const activeCompany = await getActiveCompany();
const userIsSubUser = await isSubUser();
if (!session || !activeCompany) {
redirect('/select-company');
}
// Block sub-users from R&R and Unprocessed categories
if (userIsSubUser) {
const blockedCategories: InventoryCategory[] = [
'unprocessed',
'unprocessed-rr',
'processed-rr',
];
if (blockedCategories.includes(category)) {
redirect('/inventory');
}
}
const dbName = `[${process.env.PORTAL_DB_NAME || 'VorteqPortal'}]`;
const sub = userIsSubUser ? 1 : 0;
const details = await getInventoryDetails(
category,
activeCompany.epicor_cust_id,
dbName,
sub,
{
partNum: part,
plant,
warehouse,
}
).catch((err) => {
console.error('Failed to fetch inventory details:', err);
return [];
});
return (
<InventoryDetailTable
data={details}
partNum={part}
plant={plant}
warehouse={warehouse}
/>
);
}
function LoadingSkeleton() {
return (
<Card>
<CardContent className="p-6">
<div className="space-y-4">
{[...Array(5)].map((_, i) => (
<div
key={i}
className="h-12 w-full animate-pulse rounded bg-muted"
/>
))}
</div>
</CardContent>
</Card>
);
}
export default async function InventoryDetailPage(props: PageProps) {
const params = await props.params;
const searchParams = await props.searchParams;
const category = params.category as InventoryCategory;
// Validate category
if (!VALID_CATEGORIES.includes(category)) {
notFound();
}
const { part, plant, warehouse } = searchParams;
return (
<div>
<div className="mb-6 flex items-center gap-4">
<Link href={`/inventory/${category}`}>
<Button variant="outline" size="sm">
<ArrowLeft className="mr-2 h-4 w-4" />
Back to Summary
</Button>
</Link>
<div>
<h1 className="text-3xl font-bold">
{CATEGORY_TITLES[category]} Detail
</h1>
<p className="text-muted-foreground">
Detailed inventory breakdown
{part || plant || warehouse
? ` (filtered)`
: ` (all items)`}
</p>
</div>
</div>
<Suspense fallback={<LoadingSkeleton />}>
<InventoryDetailData
category={category}
part={part}
plant={plant}
warehouse={warehouse}
/>
</Suspense>
</div>
);
}

View file

@ -0,0 +1,58 @@
import { Suspense } from 'react';
import { redirect } from 'next/navigation';
import { getTop100Orders } from '@/services/orders';
import { getQuestSession, getActiveCompany } from '@/lib/permissions';
import { OrdersTable } from '@/components/orders/orders-table';
import { Card, CardContent } from '@/components/ui/card';
export const dynamic = 'force-dynamic';
async function OrdersData() {
const session = await getQuestSession();
const activeCompany = await getActiveCompany();
if (!session || !activeCompany) {
redirect('/select-company');
}
const orders = await getTop100Orders(activeCompany.epicor_cust_id).catch(
(err) => {
console.error('Failed to fetch orders:', err);
return [];
}
);
return <OrdersTable data={orders} />;
}
function LoadingSkeleton() {
return (
<Card>
<CardContent className="p-6">
<div className="space-y-4">
{[...Array(10)].map((_, i) => (
<div
key={i}
className="h-12 w-full animate-pulse rounded bg-muted"
/>
))}
</div>
</CardContent>
</Card>
);
}
export default function OrdersPage() {
return (
<div>
<h1 className="mb-2 text-3xl font-bold">Orders</h1>
<p className="mb-6 text-muted-foreground">
View your most recent orders and order acknowledgements
</p>
<Suspense fallback={<LoadingSkeleton />}>
<OrdersData />
</Suspense>
</div>
);
}

View file

@ -0,0 +1,166 @@
'use client';
import { useState } from 'react';
import type { InventoryDetailRow } from '@/services/inventory';
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@/components/ui/card';
import { Input } from '@/components/ui/input';
import { Button } from '@/components/ui/button';
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from '@/components/ui/table';
import { Download, Search } from 'lucide-react';
type Props = {
data: InventoryDetailRow[];
partNum?: string;
plant?: string;
warehouse?: string;
};
export function InventoryDetailTable({
data,
partNum,
plant,
warehouse,
}: Props) {
const [searchTerm, setSearchTerm] = useState('');
const filteredData = data.filter((row) => {
const searchLower = searchTerm.toLowerCase();
return (
row.part_num?.toLowerCase().includes(searchLower) ||
row.plant_name?.toLowerCase().includes(searchLower) ||
row.warehouse_desc?.toLowerCase().includes(searchLower) ||
row.bin_num?.toLowerCase().includes(searchLower) ||
row.lot_num?.toLowerCase().includes(searchLower)
);
});
const handleExportCSV = () => {
const headers = [
'Part Number',
'Plant',
'Warehouse',
'Bin',
'Lot',
'Serial',
'On Hand Qty',
'UOM',
'Description',
];
const rows = filteredData.map((row) => [
row.part_num || '',
row.plant_name || '',
row.warehouse_desc || '',
row.bin_num || '',
row.lot_num || '',
row.serial_num || '',
row.on_hand_qty?.toString() || '0',
row.uom || '',
row.part_description || '',
]);
const csvContent = [headers, ...rows]
.map((row) => row.map((cell) => `"${cell}"`).join(','))
.join('\n');
const blob = new Blob([csvContent], { type: 'text/csv' });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `inventory-detail-${new Date().toISOString().split('T')[0]}.csv`;
a.click();
window.URL.revokeObjectURL(url);
};
return (
<Card>
<CardHeader>
<CardTitle>Inventory Detail</CardTitle>
<CardDescription>
{partNum && `Part: ${partNum}`}
{plant && ` | Plant: ${plant}`}
{warehouse && ` | Warehouse: ${warehouse}`}
</CardDescription>
</CardHeader>
<CardContent>
<div className="mb-4 flex items-center gap-4">
<div className="relative flex-1">
<Search className="absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
<Input
placeholder="Search part, plant, warehouse, bin, or lot..."
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
className="pl-8"
/>
</div>
<Button onClick={handleExportCSV} variant="outline">
<Download className="mr-2 h-4 w-4" />
Export CSV
</Button>
</div>
<div className="rounded-md border">
<Table>
<TableHeader>
<TableRow>
<TableHead>Part Number</TableHead>
<TableHead>Plant</TableHead>
<TableHead>Warehouse</TableHead>
<TableHead>Bin</TableHead>
<TableHead>Lot</TableHead>
<TableHead>Serial</TableHead>
<TableHead className="text-right">On Hand</TableHead>
<TableHead>UOM</TableHead>
<TableHead>Description</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{filteredData.length === 0 ? (
<TableRow>
<TableCell colSpan={9} className="text-center text-muted-foreground">
No inventory found
</TableCell>
</TableRow>
) : (
filteredData.map((row, i) => (
<TableRow key={i}>
<TableCell className="font-medium">{row.part_num}</TableCell>
<TableCell>{row.plant_name}</TableCell>
<TableCell>{row.warehouse_desc}</TableCell>
<TableCell>{row.bin_num || '-'}</TableCell>
<TableCell>{row.lot_num || '-'}</TableCell>
<TableCell>{row.serial_num || '-'}</TableCell>
<TableCell className="text-right">
{row.on_hand_qty?.toFixed(2) || '0.00'}
</TableCell>
<TableCell>{row.uom || '-'}</TableCell>
<TableCell className="max-w-xs truncate">
{row.part_description || '-'}
</TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
</div>
<div className="mt-4 text-sm text-muted-foreground">
Showing {filteredData.length} of {data.length} items
</div>
</CardContent>
</Card>
);
}

View file

@ -116,7 +116,7 @@ export function InventorySummaryTable({
<TableRow key={idx}>
<TableCell>
<Link
href={`/inventory/${category}/details?part=${row.part_num}&plant=${row.plant}&warehouse=${row.warehouse}`}
href={`/inventory/${category}/detail?part=${row.part_num}&plant=${row.plant}&warehouse=${row.warehouse}`}
className="font-medium hover:underline"
>
{row.part_num}

View file

@ -0,0 +1,192 @@
'use client';
import { useState } from 'react';
import Link from 'next/link';
import type { OrderRow } from '@/services/orders';
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@/components/ui/card';
import { Input } from '@/components/ui/input';
import { Button } from '@/components/ui/button';
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from '@/components/ui/table';
import { Download, Search } from 'lucide-react';
type Props = {
data: OrderRow[];
};
export function OrdersTable({ data }: Props) {
const [searchTerm, setSearchTerm] = useState('');
const filteredData = data.filter((row) => {
const searchLower = searchTerm.toLowerCase();
return (
row.order_num?.toString().includes(searchLower) ||
row.po_num?.toLowerCase().includes(searchLower) ||
row.customer_part?.toLowerCase().includes(searchLower) ||
row.vorteq_part?.toLowerCase().includes(searchLower)
);
});
const handleExportCSV = () => {
const headers = [
'Order #',
'PO #',
'Order Date',
'Need By',
'Customer Part',
'Vorteq Part',
'Order Qty',
'Shipped',
'Remaining',
'UM',
'Status',
];
const rows = filteredData.map((row) => [
row.order_num?.toString() || '',
row.po_num || '',
row.order_date ? new Date(row.order_date).toLocaleDateString() : '',
row.need_by_date ? new Date(row.need_by_date).toLocaleDateString() : '',
row.customer_part || '',
row.vorteq_part || '',
row.order_qty?.toString() || '0',
row.shipped_qty?.toString() || '0',
row.remaining_qty?.toString() || '0',
row.um || '',
row.status || '',
]);
const csvContent = [headers, ...rows]
.map((row) => row.map((cell) => `"${cell}"`).join(','))
.join('\n');
const blob = new Blob([csvContent], { type: 'text/csv' });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `orders-${new Date().toISOString().split('T')[0]}.csv`;
a.click();
window.URL.revokeObjectURL(url);
};
return (
<Card>
<CardHeader>
<CardTitle>Orders</CardTitle>
<CardDescription>Top 100 most recent orders</CardDescription>
</CardHeader>
<CardContent>
<div className="mb-4 flex items-center gap-4">
<div className="relative flex-1">
<Search className="absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
<Input
placeholder="Search order #, PO, customer part, or Vorteq part..."
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
className="pl-8"
/>
</div>
<Button onClick={handleExportCSV} variant="outline">
<Download className="mr-2 h-4 w-4" />
Export CSV
</Button>
</div>
<div className="rounded-md border">
<Table>
<TableHeader>
<TableRow>
<TableHead>Order #</TableHead>
<TableHead>PO #</TableHead>
<TableHead>Order Date</TableHead>
<TableHead>Need By</TableHead>
<TableHead>Customer Part</TableHead>
<TableHead>Vorteq Part</TableHead>
<TableHead className="text-right">Qty</TableHead>
<TableHead className="text-right">Shipped</TableHead>
<TableHead className="text-right">Remaining</TableHead>
<TableHead>Status</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{filteredData.length === 0 ? (
<TableRow>
<TableCell
colSpan={10}
className="text-center text-muted-foreground"
>
No orders found
</TableCell>
</TableRow>
) : (
filteredData.map((row, i) => (
<TableRow key={i}>
<TableCell>
<Link
href={`/orders/${row.order_num}`}
className="font-medium hover:underline"
>
{row.order_num}
</Link>
</TableCell>
<TableCell>{row.po_num || '-'}</TableCell>
<TableCell>
{row.order_date
? new Date(row.order_date).toLocaleDateString()
: '-'}
</TableCell>
<TableCell>
{row.need_by_date
? new Date(row.need_by_date).toLocaleDateString()
: '-'}
</TableCell>
<TableCell>{row.customer_part || '-'}</TableCell>
<TableCell className="font-mono">
{row.vorteq_part || '-'}
</TableCell>
<TableCell className="text-right">
{row.order_qty?.toFixed(0) || '0'}
</TableCell>
<TableCell className="text-right">
{row.shipped_qty?.toFixed(0) || '0'}
</TableCell>
<TableCell className="text-right">
{row.remaining_qty?.toFixed(0) || '0'}
</TableCell>
<TableCell>
<span
className={
row.open_order
? 'rounded-full bg-green-100 px-2 py-1 text-xs font-medium text-green-800'
: 'rounded-full bg-gray-100 px-2 py-1 text-xs font-medium text-gray-800'
}
>
{row.status}
</span>
</TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
</div>
<div className="mt-4 text-sm text-muted-foreground">
Showing {filteredData.length} of {data.length} orders
</div>
</CardContent>
</Card>
);
}

View file

@ -66,7 +66,7 @@ export async function getQuestSession(): Promise<QuestSession | null> {
// If no active company in session, use the first available active company
if (!activeCompanyId && authUser.quest_user.companies.length > 0) {
const activeCompany = authUser.quest_user.companies.find(
(c) => c.company.is_active
(c: (typeof authUser.quest_user.companies)[0]) => c.company.is_active
);
if (activeCompany) {
activeCompanyId = activeCompany.company.id;
@ -258,10 +258,12 @@ export async function getUserCompanies() {
},
});
type CompanyRelation = NonNullable<typeof questUser>['companies'][0];
return (
questUser?.companies
.filter((c) => c.company.is_active)
.map((c) => c.company) || []
.filter((c: CompanyRelation) => c.company.is_active)
.map((c: CompanyRelation) => c.company) || []
);
}

View file

@ -19,17 +19,23 @@ export type InventorySummaryRow = {
export type InventoryDetailRow = {
part_num: string;
description: string;
lot_num: string;
plant: string;
warehouse: string;
bin_num: string;
description?: string;
part_description?: string;
lot_num?: string;
serial_num?: string;
plant?: string;
plant_name?: string;
warehouse?: string;
warehouse_desc?: string;
bin_num?: string;
on_hand_qty: number;
allocated_qty: number;
available_qty: number;
um: string;
receipt_date: Date;
allocated_qty?: number;
available_qty?: number;
um?: string;
uom?: string;
receipt_date?: Date;
paint_code?: string;
[key: string]: unknown; // Allow additional fields from stored procedures
};
export type InventoryCategory =
@ -185,41 +191,71 @@ export async function getInventoryDetails(
warehouse?: string;
}
): Promise<InventoryDetailRow[]> {
// Map category to stored procedure name
const procMap: Record<InventoryCategory, string> = {
wip: 'portal_WorkInProgressInventoryDetailV6',
'finished-goods': 'portal_FinishedGoodsInventoryDetailV6',
'processed-other': 'portal_ProcessedOtherInventoryDetailV6',
unprocessed: 'portal_UnprocessedInventoryDetail',
'unprocessed-rr': 'portal_UnprocessedRRInventoryDetail',
'processed-rr': 'portal_ProcessedRRInventoryDetail',
const hasFilters = filters?.partNum || filters?.plant || filters?.warehouse;
// Map category to stored procedure names (filtered and ALL variants)
const procMap: Record<
InventoryCategory,
{ filtered: string; all: string; isV6: boolean }
> = {
wip: {
filtered: 'PortalWorkInProgressInventoryDetailsV6',
all: 'PortalWorkInProgressInventoryDetailsALLV6',
isV6: true,
},
'finished-goods': {
filtered: 'PortalFinishedGoodsInventoryDetailsV6',
all: 'PortalFinishedGoodsInventoryDetailsALLV6',
isV6: true,
},
'processed-other': {
filtered: 'PortalProcessedOtherInventoryDetailsV6',
all: 'PortalProcessedOtherInventoryDetailsALLV6',
isV6: true,
},
unprocessed: {
filtered: 'PortalUnprocessedInventoryDetails',
all: 'PortalUnprocessedInventoryDetailsALL',
isV6: false,
},
'unprocessed-rr': {
filtered: 'PortalUnprocessedInventoryRejectsAndReturnsDetails',
all: 'PortalUnprocessedInventoryRejectsAndReturnsDetailsALL',
isV6: false,
},
'processed-rr': {
filtered: 'PortalProcessedInventoryRejectsAndReturnsDetails',
all: 'PortalProcessedInventoryRejectsAndReturnsDetailsALL',
isV6: false,
},
};
const procName = procMap[category];
const procConfig = procMap[category];
const procName = hasFilters ? procConfig.filtered : procConfig.all;
const params: Record<string, unknown> = {
CustID: custId,
DBNAME: dbName,
};
// V6 procedures use 'sub' parameter
if (
category === 'wip' ||
category === 'finished-goods' ||
category === 'processed-other'
) {
// V6 procedures use CUSTID (uppercase), non-V6 use custID
if (procConfig.isV6) {
params.CUSTID = custId;
params.sub = sub;
} else {
params.custID = custId;
}
// Add filters if provided
if (filters?.partNum) {
params.PartNum = filters.partNum;
}
if (filters?.plant) {
params.Plant = filters.plant;
}
if (filters?.warehouse) {
params.Warehouse = filters.warehouse;
// Add filters if provided (only for filtered variant)
if (hasFilters) {
if (procConfig.isV6) {
params.PART = filters?.partNum || '';
params.PLANT = filters?.plant || '';
params.WAREHOUSE = filters?.warehouse || '';
} else {
params.part = filters?.partNum || '';
params.plant = filters?.plant || '';
params.warehouse = filters?.warehouse || '';
}
}
const result = await execStoredProc<InventoryDetailRow[]>(procName, params);

152
src/services/orders.ts Normal file
View file

@ -0,0 +1,152 @@
/**
* Orders Service
* Handles order data retrieval from Epicor
*/
import { execQuery } from '@/lib/epicor';
export type OrderRow = {
order_num: number;
po_num: string;
order_date: Date;
need_by_date: Date;
customer_part: string;
vorteq_part: string;
order_qty: number;
shipped_qty: number;
remaining_qty: number;
um: string;
open_order: boolean;
status: string;
ship_to_name?: string;
[key: string]: unknown;
};
/**
* Get top 100 orders for a customer
* Special handling for HDC customer
*/
export async function getTop100Orders(custId: string): Promise<OrderRow[]> {
// HDC exception: use different customer ID for second parameter
const cust2 = custId === 'HDC' ? 'HDM' : custId;
// Query Epicor OrderHed and OrderDtl tables
// This is a simplified version - the actual portal_Orders.sql may have more complex logic
const sql = `
SELECT TOP 100
oh.OrderNum AS order_num,
oh.PONum AS po_num,
oh.OrderDate AS order_date,
oh.NeedByDate AS need_by_date,
od.XPartNum AS customer_part,
od.PartNum AS vorteq_part,
od.OrderQty AS order_qty,
od.ShippedQty AS shipped_qty,
(od.OrderQty - od.ShippedQty) AS remaining_qty,
od.IUM AS um,
oh.OpenOrder AS open_order,
CASE
WHEN oh.OpenOrder = 1 THEN 'Open'
ELSE 'Closed'
END AS status,
st.Name AS ship_to_name
FROM Erp.OrderHed oh
INNER JOIN Erp.OrderDtl od ON oh.Company = od.Company AND oh.OrderNum = od.OrderNum
INNER JOIN Erp.Customer c ON oh.Company = c.Company AND oh.CustNum = c.CustNum
LEFT JOIN Erp.ShipTo st ON oh.Company = st.Company AND oh.ShipToNum = st.ShipToNum
WHERE c.CustID = @Cust1
OR c.CustID = @Cust2
ORDER BY oh.OrderDate DESC, oh.OrderNum DESC
`;
const result = await execQuery<OrderRow[]>(sql, {
Cust1: custId,
Cust2: cust2,
});
return result;
}
/**
* Get orders for a specific customer on or after a date
* Used for allocation requests
*/
export async function getOrdersForCustomerOnOrAfterDate(
custId: string,
date: string,
excludedOrderNumbers: number[] = []
): Promise<OrderRow[]> {
let sql = `
SELECT
oh.OrderNum AS order_num,
oh.PONum AS po_num,
oh.OrderDate AS order_date,
od.PartNum AS vorteq_part,
od.OrderQty AS order_qty,
od.ShippedQty AS shipped_qty,
(od.OrderQty - od.ShippedQty) AS remaining_qty
FROM Erp.OrderHed oh
INNER JOIN Erp.OrderDtl od ON oh.Company = od.Company AND oh.OrderNum = od.OrderNum
INNER JOIN Erp.Customer c ON oh.Company = c.Company AND oh.CustNum = c.CustNum
WHERE c.CustID = @CustomerID
AND oh.OrderDate >= @Date
AND oh.OpenOrder = 1
`;
if (excludedOrderNumbers.length > 0) {
const excludedList = excludedOrderNumbers.join(',');
sql += ` AND oh.OrderNum NOT IN (${excludedList})`;
}
sql += ' ORDER BY oh.OrderDate DESC';
const result = await execQuery<OrderRow[]>(sql, {
CustomerID: custId,
Date: date,
});
return result;
}
/**
* Get order details for acknowledgement
*/
export async function getOrderDetails(orderNum: number): Promise<OrderRow[]> {
const sql = `
SELECT
oh.OrderNum AS order_num,
oh.PONum AS po_num,
oh.OrderDate AS order_date,
oh.NeedByDate AS need_by_date,
od.OrderLine AS order_line,
od.XPartNum AS customer_part,
od.PartNum AS vorteq_part,
od.LineDesc AS line_desc,
od.OrderQty AS order_qty,
od.ShippedQty AS shipped_qty,
(od.OrderQty - od.ShippedQty) AS remaining_qty,
od.IUM AS um,
od.UnitPrice AS unit_price,
(od.OrderQty * od.UnitPrice) AS extended_price,
c.Name AS customer_name,
c.CustID AS cust_id,
st.Name AS ship_to_name,
st.Address1 AS ship_to_address1,
st.Address2 AS ship_to_address2,
st.City AS ship_to_city,
st.State AS ship_to_state,
st.ZIP AS ship_to_zip
FROM Erp.OrderHed oh
INNER JOIN Erp.OrderDtl od ON oh.Company = od.Company AND oh.OrderNum = od.OrderNum
INNER JOIN Erp.Customer c ON oh.Company = c.Company AND oh.CustNum = c.CustNum
LEFT JOIN Erp.ShipTo st ON oh.Company = st.Company AND oh.CustNum = st.CustNum AND oh.ShipToNum = st.ShipToNum
WHERE oh.OrderNum = @OrderNum
ORDER BY od.OrderLine
`;
const result = await execQuery<OrderRow[]>(sql, {
OrderNum: orderNum,
});
return result;
}