84 lines
3.3 KiB
JavaScript
84 lines
3.3 KiB
JavaScript
|
|
#!/usr/bin/env node
|
||
|
|
/**
|
||
|
|
* Creates the user's quote exactly as shown in the screenshot.
|
||
|
|
*
|
||
|
|
* Customer : JENTRADEPRO
|
||
|
|
* Quote # : QT-20260914-001
|
||
|
|
* Customer Ref: RFQ;JEI MAGNETIC DRILLING MACHINE PARTS
|
||
|
|
* Quote Date : 2026-09-14
|
||
|
|
* Valid Until : 2026-10-14
|
||
|
|
* Status : Draft
|
||
|
|
*
|
||
|
|
* Items:
|
||
|
|
* 1. PRO132T-B27 - PANEL CONTROL PCB ASSY 110V (BB1) qty 1 R 5518.88
|
||
|
|
* 2. PRO132T-C24 - CARBON BRUSH EACH, PRO152T qty 2 R 438.22
|
||
|
|
* 3. 35708 - MAGNET SWITCH qty 1 R 485.40
|
||
|
|
*/
|
||
|
|
import PocketBase from "pocketbase";
|
||
|
|
|
||
|
|
const PB_URL = "https://pb.jeistk.apphub.co.za";
|
||
|
|
const PB_EMAIL = "david@wfsales.co.za";
|
||
|
|
const PB_PASSWORD = "1234567890";
|
||
|
|
|
||
|
|
const pb = new PocketBase(PB_URL);
|
||
|
|
pb.autoCancellation(false);
|
||
|
|
await pb.admins.authWithPassword(PB_EMAIL, PB_PASSWORD);
|
||
|
|
|
||
|
|
const CUSTOMER_ID = "dgv6gxgcj2f2o14";
|
||
|
|
const QUOTE_NUMBER = "QT-20260914-001";
|
||
|
|
|
||
|
|
const items = [
|
||
|
|
{ id: "oz9zgj5xp72m77s", sku: "PRO132T-B27", qty: 1, price: 5518.88 },
|
||
|
|
{ id: "gfcfv9mkveq95co", sku: "PRO132T-C24", qty: 2, price: 438.22 },
|
||
|
|
{ id: "9lfcwus2w5w9h84", sku: "35708", qty: 1, price: 485.40 },
|
||
|
|
];
|
||
|
|
|
||
|
|
// Clean any prior attempt
|
||
|
|
try {
|
||
|
|
const dup = await pb.collection("quotes").getFirstListItem(`quote_number = "${QUOTE_NUMBER}"`);
|
||
|
|
await pb.collection("quotes").delete(dup.id);
|
||
|
|
console.log(`Removed previous attempt ${dup.id}`);
|
||
|
|
} catch {
|
||
|
|
/* no duplicate */
|
||
|
|
}
|
||
|
|
|
||
|
|
// Create the quote — `items` is a JSON array (schema fix applied earlier)
|
||
|
|
const record = await pb.collection("quotes").create({
|
||
|
|
quote_number: QUOTE_NUMBER,
|
||
|
|
customerName: CUSTOMER_ID,
|
||
|
|
customerRef: "RFQ;JEI MAGNETIC DRILLING MACHINE PARTS",
|
||
|
|
quoteDate: "2026-09-14 00:00:00.000Z",
|
||
|
|
validUntil: "2026-10-14 00:00:00.000Z",
|
||
|
|
notes: "",
|
||
|
|
status: "Draft",
|
||
|
|
items: items.map(i => i.id),
|
||
|
|
quantities: items.map(i => i.qty),
|
||
|
|
unitPrices: items.map(i => i.price),
|
||
|
|
});
|
||
|
|
|
||
|
|
// Verify
|
||
|
|
const stored = await pb.collection("quotes").getOne(record.id, { expand: "customerName" });
|
||
|
|
const customer = stored.expand?.customerName;
|
||
|
|
|
||
|
|
const subtotal = items.reduce((s, i) => s + i.qty * i.price, 0);
|
||
|
|
const vat = subtotal * 0.15;
|
||
|
|
const total = subtotal + vat;
|
||
|
|
|
||
|
|
console.log("\n✅ Quote created on PocketBase");
|
||
|
|
console.log("─────────────────────────────────────");
|
||
|
|
console.log(`ID : ${stored.id}`);
|
||
|
|
console.log(`Quote # : ${stored.quote_number}`);
|
||
|
|
console.log(`Customer : ${customer?.comapny_name ?? "(unknown)"}`);
|
||
|
|
console.log(`Customer Ref: ${stored.customerRef}`);
|
||
|
|
console.log(`Quote Date : ${stored.quoteDate}`);
|
||
|
|
console.log(`Valid Until : ${stored.validUntil}`);
|
||
|
|
console.log(`Status : ${stored.status}`);
|
||
|
|
console.log(`Items stored: ${JSON.stringify(stored.items)}`);
|
||
|
|
console.log(`Quantities : ${JSON.stringify(stored.quantities)}`);
|
||
|
|
console.log(`Unit Prices : ${JSON.stringify(stored.unitPrices)}`);
|
||
|
|
console.log(`Subtotal : R ${subtotal.toFixed(2)}`);
|
||
|
|
console.log(`VAT (15%) : R ${vat.toFixed(2)}`);
|
||
|
|
console.log(`Total : R ${total.toFixed(2)}`);
|
||
|
|
console.log("─────────────────────────────────────");
|
||
|
|
console.log(`Admin URL : https://pb.jeistk.apphub.co.za/_/#/collections?collectionId=pbc_134296766&recordId=${stored.id}`);
|