A quote should look like a document from a real company, so this adds the customer details a quote needs, gives every quote a valid-until date, and makes the customer picker usable once there are 20+ of them. Customer details on quotes - The `customers` collection only had a name, so the quote PDF's "Customer Information" block could only ever print a name. Added optional address, VAT number, email and phone fields. - The PDF block now grows to fit whatever is on file and prints the VAT number and contact line, so a filled-in customer produces a professional quote. - The quote details dialog shows the same details. - The customer form gained the new fields, and "Edit customer" now works - it was a menu item that did nothing, so there was no way to add a VAT number to an existing customer. - The customers table shows Address and VAT Number columns. Valid until - Quotes were created with an empty validUntil, so the PDF printed "Valid Until: N/A". The form now defaults it to 30 days after the quote date and keeps it in step when the date moves. The three existing quotes without one were backfilled the same way. Searchable customer picker - The customer dropdown listed every customer in a plain select with no way to add one that was missing. It is now a searchable combobox (by name, address or VAT number) that offers to create the customer when nothing matches, and creates it inline. Sidebar - Settings moved to a gear in the corner next to the app name, and Logs moved into Settings as a tab. The nav is now eight items with no grouping - grouping them would add a layer for no gain at this size. The old /logs link still lands on the logs tab. Also fixes a real PDF bug: item descriptions were cut to 40 characters, which is wider than the description column, so long names printed on top of the SKU column. Descriptions and SKUs are now measured against the real column width and truncated with an ellipsis. Live PocketBase changes (see scripts/add-customer-fields.mjs): - customers update and delete rules were null (superusers only), so a member could not edit the customer they had just added. They now match the other collections.
69 lines
2.3 KiB
JavaScript
69 lines
2.3 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Add the customer fields the quote PDF needs: address, VAT number,
|
|
* email and phone.
|
|
*
|
|
* The `customers` collection only had `comapny_name` and
|
|
* `billing_company`, so the quote PDF's "Customer Information" block
|
|
* could only ever print a name. These four optional fields give it
|
|
* something to print.
|
|
*
|
|
* Existing records are left alone — the fields are optional and can be
|
|
* filled in over time from the Customers screen.
|
|
*
|
|
* Usage:
|
|
* node scripts/add-customer-fields.mjs # dry run (default)
|
|
* node scripts/add-customer-fields.mjs --apply # apply to the instance
|
|
*/
|
|
|
|
import PocketBase from "pocketbase";
|
|
|
|
const PB_URL = process.env.POCKETBASE_URL || "https://pb.jeistk.apphub.co.za";
|
|
const PB_EMAIL = process.env.POCKETBASE_ADMIN_EMAIL || "david@wfsales.co.za";
|
|
const PB_PASSWORD = process.env.POCKETBASE_ADMIN_PASSWORD || "1234567890";
|
|
|
|
const APPLY = process.argv.includes("--apply");
|
|
|
|
const NEW_FIELDS = [
|
|
{ id: "text_cust_address", name: "address", type: "text" },
|
|
{ id: "text_cust_vat", name: "vatNumber", type: "text" },
|
|
{ id: "text_cust_email", name: "email", type: "email" },
|
|
{ id: "text_cust_phone", name: "phone", type: "text" },
|
|
];
|
|
|
|
const pb = new PocketBase(PB_URL);
|
|
pb.autoCancellation(false);
|
|
|
|
await pb.admins.authWithPassword(PB_EMAIL, PB_PASSWORD);
|
|
|
|
const collection = await pb.collections.getOne("customers");
|
|
|
|
const existing = new Set(collection.fields.map((f) => f.name));
|
|
const toAdd = NEW_FIELDS.filter((f) => !existing.has(f.name));
|
|
|
|
console.log("=== BEFORE ===");
|
|
console.log(` fields: ${collection.fields.map((f) => f.name).join(", ")}`);
|
|
console.log(` adding: ${toAdd.length ? toAdd.map((f) => f.name).join(", ") : "(none - already applied)"}`);
|
|
|
|
if (!APPLY) {
|
|
console.log("\nDry run. Re-run with --apply to write these fields to the instance.");
|
|
process.exit(0);
|
|
}
|
|
|
|
for (const field of toAdd) {
|
|
collection.fields.push({
|
|
hidden: false,
|
|
id: field.id,
|
|
name: field.name,
|
|
presentable: false,
|
|
required: false,
|
|
system: false,
|
|
type: field.type,
|
|
});
|
|
}
|
|
|
|
const updated = await pb.collections.update(collection.id, collection);
|
|
|
|
console.log("\n=== AFTER ===");
|
|
console.log(` fields: ${updated.fields.map((f) => f.name).join(", ")}`);
|
|
console.log("\nDone. Fill the new fields in from the Customers screen.");
|