fix(po-number): floor at 9000, imported POs keep original PO number
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
6763a60421
commit
ccc93d40f3
3 changed files with 11 additions and 3 deletions
|
|
@ -12,6 +12,9 @@ export type ImportPoInput = {
|
||||||
vesselId: string;
|
vesselId: string;
|
||||||
accountId: string;
|
accountId: string;
|
||||||
companyId?: string;
|
companyId?: string;
|
||||||
|
/** Original PO number from the imported Excel — preserved as-is on the PO record.
|
||||||
|
* If absent, a new structured number is generated. */
|
||||||
|
originalPoNumber?: string;
|
||||||
/** vendorId of an existing vendor, if pre-matched in the UI */
|
/** vendorId of an existing vendor, if pre-matched in the UI */
|
||||||
vendorId?: string;
|
vendorId?: string;
|
||||||
/** Raw vendor name from the Excel — used to auto-create if no vendorId matched */
|
/** Raw vendor name from the Excel — used to auto-create if no vendorId matched */
|
||||||
|
|
@ -119,8 +122,10 @@ export async function importPo(
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
|
|
||||||
// ── 4. Generate structured PO number ─────────────────────────────────────
|
// ── 4. Determine PO number ────────────────────────────────────────────────
|
||||||
const poNumber = await generatePoNumber(input.vesselId, input.companyId);
|
// Preserve the original PO number from the imported document when available;
|
||||||
|
// otherwise generate a new structured number starting from 9000+.
|
||||||
|
const poNumber = input.originalPoNumber?.trim() || await generatePoNumber(input.vesselId, input.companyId);
|
||||||
|
|
||||||
// ── 5. Create PO in CLOSED state ──────────────────────────────────────────
|
// ── 5. Create PO in CLOSED state ──────────────────────────────────────────
|
||||||
// Imported POs bypass the approval workflow — they are historical records.
|
// Imported POs bypass the approval workflow — they are historical records.
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,7 @@ export function ImportForm({ vessels, accounts, vendors, companies }: Props) {
|
||||||
vesselId: preview.vesselId,
|
vesselId: preview.vesselId,
|
||||||
companyId: preview.companyId || undefined,
|
companyId: preview.companyId || undefined,
|
||||||
accountId: preview.accountId,
|
accountId: preview.accountId,
|
||||||
|
originalPoNumber: preview.parsed.poNumber || undefined,
|
||||||
vendorId: preview.vendorId || undefined,
|
vendorId: preview.vendorId || undefined,
|
||||||
parsedVendorName: preview.parsed.vendorName || undefined,
|
parsedVendorName: preview.parsed.vendorName || undefined,
|
||||||
parsedVendorAddress: preview.parsed.vendorAddress || undefined,
|
parsedVendorAddress: preview.parsed.vendorAddress || undefined,
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,9 @@ function currentFY(): string {
|
||||||
/** Find the next sequential PO ID (min 200) by scanning existing structured PO numbers. */
|
/** Find the next sequential PO ID (min 200) by scanning existing structured PO numbers. */
|
||||||
async function nextPoId(): Promise<number> {
|
async function nextPoId(): Promise<number> {
|
||||||
const pos = await db.purchaseOrder.findMany({ select: { poNumber: true } });
|
const pos = await db.purchaseOrder.findMany({ select: { poNumber: true } });
|
||||||
let maxId = 199;
|
// Floor at 8999 so the first generated ID is 9000, avoiding clashes with
|
||||||
|
// imported POs that retain their original IDs (which typically start from 1).
|
||||||
|
let maxId = 8999;
|
||||||
for (const { poNumber } of pos) {
|
for (const { poNumber } of pos) {
|
||||||
const parts = poNumber.split("/");
|
const parts = poNumber.split("/");
|
||||||
if (parts.length === 4) {
|
if (parts.length === 4) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue