← back to Filemaker Mcp
scripts/test-dummy-invoice.mjs
96 lines
// TEST: create a dummy client + dummy invoice so Steve can eyeball the
// two-line retail/discount layout, then delete both by hand.
// Usage:
// node scripts/test-dummy-invoice.mjs fields <db> — list layout fields
// node scripts/test-dummy-invoice.mjs create — create client + invoice, print readback
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';
const __dir = dirname(fileURLToPath(import.meta.url));
for (const line of readFileSync(join(__dir, '..', '.env'), 'utf8').split('\n')) {
const m = line.match(/^([A-Z_]+)=(.*)$/);
if (m && !process.env[m[1]]) process.env[m[1]] = m[2];
}
const fm = await import('../src/fm-client.js');
const [cmd, arg] = process.argv.slice(2);
if (cmd === 'fields') {
const meta = await fm.fieldMetadata(arg || 'Clients');
console.log(JSON.stringify((meta.fieldMetaData || []).map((f) => f.name), null, 1));
process.exit(0);
}
if (cmd !== 'create') { console.error('usage: fields <db> | create'); process.exit(2); }
// ---- 1. dummy client (Clients file) ----
const clientFields = {
'Account Number': '9999999',
'Company': 'TEST — DELETE ME (Claude layout demo)',
'Name': 'Testy McTestface',
'Address': '123 Dummy Lane',
'City': 'Los Angeles',
'State': 'CA',
'Zip': '90001',
'Phone': '+13105550000',
'Email address': 'test-delete-me@example.com',
};
// client 57431 already created on first run
// ---- 2. dummy invoice (invoice file / Order Detail) ----
const TEST_TAG = 'TEST — DELETE ME (Claude layout demo)';
const invoiceFields = {
'Invoice': '999999',
'Date': '07/01/2026',
'Account #': '9999999',
'SOLD NAME': 'Testy McTestface',
'SOLD COMPANY': TEST_TAG,
'SOLD ADDRESS': '123 Dummy Lane',
'SOLD CITY': 'Houston',
'SOLD STATE': 'TX',
'SOLD ZIP': '77008',
'BUYER': 'Testy McTestface',
'SHIP COMAPNY': TEST_TAG,
'SHIP ADDRESS': '123 Dummy Lane',
'SHIP CITY': 'Houston',
'SHIP STATE': 'TX',
'SHIP ZIP': '77008',
'SHIP VIA': 'UPS® Ground',
'Cust PO': 'TEST-0000',
// line 1: retail
'Q1(1)': 4,
'Unit 1(1)': 'S/R',
'DETAIL 1(1)': 'DWTT80707 - 27" x 4.5yds (TEST)',
'NET 1(1)': 131.95,
// line 2: discount
'Q1(2)': 4,
'Unit 1(2)': 'S/R',
'DETAIL 1(2)': 'Discount at 15%',
'NET 1(2)': -19.79,
'SHIPPING HANDLING': 44.5,
'PAID ON ACCOUNT': 493.14,
'check Number': 'TEST',
'SALES TAX YN(1)': 'N',
'Resale #': 'Out of State',
'Notes': TEST_TAG,
};
const created = await fm.createRecord('invoice', 'Order Detail', invoiceFields, { dryRun: false });
console.log('CREATED invoice record:', JSON.stringify(created));
const recordId = created.recordId || created.response?.recordId || created;
const rec = await fm.getRecord('invoice', 'Order Detail', recordId);
const f = rec.fieldData;
console.log('READBACK (calcs included):', JSON.stringify({
recordId,
Invoice: f['Invoice'],
'SOLD NAME': f['SOLD NAME'],
'Q1(1)': f['Q1(1)'], 'Unit 1(1)': f['Unit 1(1)'], 'DETAIL 1(1)': f['DETAIL 1(1)'], 'NET 1(1)': f['NET 1(1)'], 'TOTAL 1(1)': f['TOTAL 1(1)'],
'Q1(2)': f['Q1(2)'], 'Unit 1(2)': f['Unit 1(2)'], 'DETAIL 1(2)': f['DETAIL 1(2)'], 'NET 1(2)': f['NET 1(2)'], 'TOTAL 1(2)': f['TOTAL 1(2)'],
'MERCHANDISE TOTAL': f['MERCHANDISE TOTAL(1)'] ?? f['MERCHANDISE TOTAL'],
'SHIPPING HANDLING': f['SHIPPING HANDLING'],
'PAID ON ACCOUNT': f['PAID ON ACCOUNT'],
'NET DUE 2': f['NET DUE 2'],
}, null, 1));