[object Object]

← back to Filemaker Mcp

invoice: strip dashes in WC Pattern Number AKA DW SKU; write 'Resale card lookup' (the resale field shown on invoice) so it's no longer blank

f9e757d7b0ba7cc3d8333d013e1b51a33858de6a · 2026-06-29 13:38:07 -0700 · Steve

Files touched

Diff

commit f9e757d7b0ba7cc3d8333d013e1b51a33858de6a
Author: Steve <steve@designerwallcoverings.com>
Date:   Mon Jun 29 13:38:07 2026 -0700

    invoice: strip dashes in WC Pattern Number AKA DW SKU; write 'Resale card lookup' (the resale field shown on invoice) so it's no longer blank
---
 lib/invoice.js | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/invoice.js b/lib/invoice.js
index 014d856..4a5bd95 100644
--- a/lib/invoice.js
+++ b/lib/invoice.js
@@ -21,6 +21,9 @@ const WCPAT_LAYOUT = '1-order detail 1 Copy3'; // exposes "wc pattern"
 // NOT the calc fields "wc pattern no" / "wc pattern no2" / "wc pattern".
 const DWSKU_LAYOUT = '1-order detail 1 Copy3';
 const DWSKU_FIELD = 'WC Pattern Number AKA DW SKU';
+const RESALE_LAYOUT = 'PROFORMA'; // exposes the writable 'Resale card lookup' (the field shown on the invoice)
+// DW SKU value for the WC Pattern Number AKA DW SKU field: base pattern, sample-stripped, DASHES REMOVED (always).
+const dwSku = (sku) => baseSku((sku || '').replace(/-?\s*sample\s*/ig, '').trim()).replace(/-/g, '');
 
 const today = () => { const d = new Date(); return `${String(d.getMonth()+1).padStart(2,'0')}/${String(d.getDate()).padStart(2,'0')}/${d.getFullYear()}`; };
 const stamp = () => new Date().toLocaleString('en-US', { month:'short', day:'numeric', year:'numeric', hour:'numeric', minute:'2-digit' });
@@ -64,7 +67,7 @@ const MAX_LINES = 4; // DETAIL 1 / Q1 / NET 1 family caps at maxRepeat 4
 // billing invoice. Returns the created records.
 export async function createSkuRecords(order, accountNumber, clientName, { commit = true } = {}) {
   const items = order.line_items || [];
-  const skus = items.map((li) => wcPattern(li.sku)); // base DW SKU, sample-stripped
+  const skus = items.map((li) => dwSku(li.sku)); // base DW SKU, sample-stripped, dashes removed
   if (!commit) return { wouldCreate: skus.length, skus };
   const created = [];
   for (const sku of skus) {
@@ -113,6 +116,8 @@ export async function createInvoiceForOrder(order, accountNumber, { commit = tru
   await patch(id, 'SALES PERSON', 'Otto');
   await patch(id, 'BUYER', name);
   await patch(id, 'Resale #', resale(s));
+  // 'Resale card lookup' is the resale field actually shown on the invoice (writable, on PROFORMA)
+  try { await fm.updateRecord('invoice', RESALE_LAYOUT, id, { 'Resale card lookup': resale(s) }, { dryRun: false }); } catch {}
   await patch(id, 'SHIP VIA', shipVia);
   await patch(id, 'SHIPPING  HANDLING', shipping);
   await patch(id, 'SALES TAX YN', orderTax > 0 ? 'Y' : 'N');
@@ -143,7 +148,7 @@ export async function createInvoiceForOrder(order, accountNumber, { commit = tru
   try { await fm.updateRecord('invoice', WCPAT_LAYOUT, id, { 'wc pattern': wcPattern(primarySku) }, { dryRun: false }); } catch {}
   // DW SKU = base pattern SKU of the primary line (e.g. DWCC-112200-Per Yard -> DWCC-112200).
   // Writable Text[4] field; bare name targets repetition 1. Resilient — never aborts the invoice.
-  try { await fm.updateRecord('invoice', DWSKU_LAYOUT, id, { [DWSKU_FIELD]: baseSku(primarySku) }, { dryRun: false }); } catch {}
+  try { await fm.updateRecord('invoice', DWSKU_LAYOUT, id, { [DWSKU_FIELD]: dwSku(primarySku) }, { dryRun: false }); } catch {}
 
   // paid-in-full = computed grand total (rounded to cents) -> Net Due 0
   const grand = r2((await fm.getRecord('invoice', HDR, id))?.fieldData?.['GRAND TOTAL'] || 0);

← ea51d97 sync: every order also creates one no-$ per-SKU tracking rec  ·  back to Filemaker Mcp  ·  remove dead lib/invoice-core.js (orphaned from refactor; lib 1f3eaf8 →