Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/arsinousltd-sudo/Arsinous-V8-Sales/llms.txt

Use this file to discover all available pages before exploring further.

The Arsinous V8 Sales application communicates with a MySQL database entirely through Google Apps Script’s JDBC service. Because no DDL or migration files are included in the repository, the schema documented here is reconstructed from the INSERT, UPDATE, and SELECT statements spread across DB/saveTo.gs, DB/getFrom.gs, invoice/backend.gs, Customer/backend.gs, product/backend.gs, Payment/backend.gs, Discounts.gs, Updates.gs, and SoA.gs. Each table section lists every column that appears in at least one SQL statement, along with its inferred type and purpose.
This schema is inferred from application source code — no DDL or migration files are included in the repository. Column types are approximations based on their usage in prepared statements, string concatenation, and setObject / setString calls. Treat them as a guide rather than a formal contract.
The JDBC connection string in Constants.gs targets MySQL on port 3306. Any MySQL 5.x or later instance reachable at that address is compatible. The connection string also sets useUnicode=yes&characterEncoding=UTF-8, which is required for correct handling of accented characters in customer names and addresses.

customers

Populated and queried by saveCustomerToDb (insert/update) and updateCustomers (SELECT * FROM customers). A new Google Drive sub-folder is created automatically under CUSTOMERS_FOLDER when a customer is inserted without a pre-existing folder value.
ColumnTypeDescription
idINT AUTO_INCREMENTPrimary key.
codeVARCHARShort customer identifier displayed on invoice headers.
nameVARCHARCustomer’s full name. Used in all balance and SoA queries that JOIN to customers.
addressVARCHARStreet address.
municipalityVARCHARMunicipality or district.
cityVARCHARCity.
zipVARCHARPostal / ZIP code.
phoneVARCHARContact phone number.
detailsVARCHARFreeform text written to cell J1 of the generated invoice Google Sheet (invoice header block).
folderVARCHARGoogle Drive folder ID for this customer’s documents. Invoice shortcuts are placed here by createInvoiceSs.
-- Insert (saveCustomerToDb)
INSERT INTO customers
  (code, name, address, municipality, city, zip, phone, details, folder)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);

-- Update (saveCustomerToDb)
UPDATE customers
SET code = '...', name = '...', address = '...', municipality = '...',
    city = '...', zip = '...', phone = '...', details = '...', folder = '...'
WHERE id = <id>;

products

Populated and queried by saveProductToDb (insert/update) and updateProducts (SELECT * FROM products). The vat_code column is a foreign reference to the Vat lookup object defined in Constants.gs.
ColumnTypeDescription
idINT AUTO_INCREMENTPrimary key.
codeVARCHARProduct SKU or short code. Snapshotted into invoices_items.code at the time of sale.
nameVARCHARProduct display name.
catVARCHARProduct category.
vat_codeTINYINTVAT rate identifier: 1 = 0 %, 2 = 5 %, 3 = 19 % (default). See the Vat constant.
costDECIMALPurchase / landed cost. Snapshotted into invoices_items.cost at the time of sale.
priceDECIMALStandard selling price.
retailDECIMALRetail reference price (written to the invoice sheet for comparison).
def_discountVARCHARDefault quantity-break discount pattern, e.g. "6+2,12+6" (buy 6 get 2 free; buy 12 get 6 free).
def_fixed_discountDECIMALDefault flat discount percentage applied before the quantity-break calculation.
-- Insert (saveProductToDb)
INSERT INTO products
  (code, name, cat, vat_code, price, retail, def_discount, def_fixed_discount)
VALUES (?, ?, ?, ?, ?, ?, ?, ?);

-- Update (saveProductToDb)
UPDATE products
SET code = '...', name = '...', cat = '...', vat_code = <n>,
    cost = <n>, price = <n>, retail = <n>,
    def_discount = '...', def_fixed_discount = <n>
WHERE id = <id>;

invoices

The central transaction table. Written by saveInvoice and read by updateInvoices (joined with customers), updateAllBalances, and updateBalanceTab (SoA).
ColumnTypeDescription
idINT AUTO_INCREMENTPrimary key. Returned via RETURN_GENERATED_KEYS immediately after insert so that line items can reference it.
typeVARCHARDocument type: "invoice" or "credit note". Credit notes cause the invoice sheet header cell A11 to read "CREDIT NOTE".
customer_idINTFK → customers.id.
dateDATEInvoice date (YYYY-MM-DD). Used in all date-range filters on the Invoices tab and SoA.
sp_idINTSalesperson ID. FK to a salesperson/sp table (not directly written by the scripts in scope, but referenced in saveInvoice headers and written to invoice sheet cell B8).
nameVARCHARZero-padded 6-digit invoice number, e.g. "000042". Generated from AUTO_INCREMENT via getNextId().
totalDECIMALNet subtotal before VAT.
vatDECIMALVAT amount. total + vat equals the gross invoice value used in balance calculations.
ss_idVARCHARGoogle Sheets file ID of the generated invoice document. Written after createInvoiceSs returns.
commentsVARCHARFree-text comments.
costDECIMALTotal cost of goods on this invoice (sum of invoices_items.cost × qty). Used for margin reporting.
-- Insert (saveInvoice)
INSERT INTO invoices
  (type, customer_id, date, sp_id, name, total, vat, ss_id, comments, cost)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);

-- Update (saveInvoice — edit path)
UPDATE invoices
SET name = '...', customer_id = <n>, date = '...', total = <n>,
    vat = <n>, ss_id = '...', comments = '...', cost = <n>
WHERE id = <id>;

invoices_items

One row per line item on an invoice. Written in batch by saveInvoice after the parent invoices row is committed. When an invoice is edited, all existing line items are deleted and re-inserted.
ColumnTypeDescription
idINT AUTO_INCREMENTPrimary key.
invoice_idINTFK → invoices.id.
product_idINTFK → products.id.
lot_idINTFK → irs_items.id. The specific inventory lot from which stock is deducted.
qtyDECIMALQuantity sold. Added to (or subtracted from) irs_items.in_stock atomically with the invoice save.
priceDECIMALUnit selling price at the time of the sale.
discountVARCHARQuantity-break discount string applied on this line (e.g. "6+2").
fixed_discountDECIMALFixed percentage discount applied before the quantity-break calculation.
manual_discountVARCHARAny discount entered manually by the user at the time of invoicing.
codeVARCHARSnapshot of products.code at the time of sale, preserved for historical accuracy.
costDECIMALSnapshot of products.cost (or irs_items.cost) at the time of sale.
priceAfterDiscountDECIMALFinal unit price after all discount tiers have been applied.
-- Insert (saveInvoice — batch)
INSERT INTO invoices_items
  (invoice_id, product_id, lot_id, qty, price, discount,
   fixed_discount, manual_discount, code, cost, priceAfterDiscount)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);

customers_payments

Records cash receipts and bank transfers against a customer. Written by saveCustomerPaymentToDb and queried by updateCustomersPayments (P&D tab) and the SoA / balance scripts. Payments are stored as positive amounts; the balance queries negate them when computing the outstanding balance.
ColumnTypeDescription
idINT AUTO_INCREMENTPrimary key.
customer_idINTFK → customers.id.
typeVARCHARPayment method label, e.g. "Cash", "Bank Transfer".
dateDATEDate the payment was received (YYYY-MM-DD).
amountDECIMALPayment amount. Stored as a positive value; subtracted from the running balance in all aggregate queries.
commentsVARCHARFree-text notes.
numVARCHARPayment reference number (e.g. cheque number, transfer reference).
deposit_dateDATEDate the payment was physically deposited to the bank account. NULL until deposited. Used by the “Payments w/o Deposits” filter on the P&D tab.
deposit_numVARCHARDeposit slip reference number.
-- Insert (saveCustomerPaymentToDb)
INSERT INTO customers_payments
  (customer_id, type, date, amount, comments, num, deposit_date, deposit_num)
VALUES (?, ?, ?, ?, ?, ?, ?, ?);

-- Update (saveCustomerPaymentToDb)
UPDATE customers_payments
SET customer_id = '...', type = '...', date = '...', amount = '...',
    comments = '...', num = '...', deposit_date = <date|NULL>, deposit_num = '...'
WHERE id = <id>;

discounts

Per-customer discount overrides for individual products. The entire set for a given customer is deleted and re-inserted atomically by saveDiscounts. When getDiscounts fetches the Discounts tab it LEFT JOINs this table against products, so products without a customer override still appear with their default discount values.
ColumnTypeDescription
product_idINTFK → products.id. Part of the composite primary key.
customer_idINTFK → customers.id. Part of the composite primary key.
discountVARCHARCustomer-specific quantity-break discount override string (replaces products.def_discount for this customer).
fixed_discountDECIMALCustomer-specific flat discount override percentage (replaces products.def_fixed_discount for this customer).
-- Overwrite all discounts for a customer (saveDiscounts)
DELETE FROM discounts WHERE customer_id = <id>;

INSERT INTO discounts (product_id, customer_id, discount, fixed_discount)
VALUES (?, ?, ?, ?);

irs_items

The inventory lot table. Each row represents a discrete purchase lot (batch) for a product, with its own expiry date and cost. The in_stock column is decremented when an invoice is saved and incremented when an invoice is deleted, always within the same JDBC transaction.
ColumnTypeDescription
idINT AUTO_INCREMENTPrimary key. Referenced as lot_id in invoices_items.
product_idINTFK → products.id.
lotVARCHARLot / batch identifier (e.g. manufacturer batch number). Shown in the Inventory sheet alongside the expiry date.
exp_dateDATEExpiry date of this lot. Written to the invoice Google Sheet in the line-item rows.
in_stockDECIMALCurrent quantity available in this lot. Filtered with WHERE in_stock > 0 in updateInventory.
costDECIMALPurchase cost for this lot.
final_costDECIMALFinal landed cost after any additional charges (freight, duties, etc.).
-- Deduct stock on invoice save (saveInvoice — batch)
UPDATE irs_items SET in_stock = in_stock - ? WHERE id = ?;

-- Restore stock on invoice delete (deleteInvoice — batch)
UPDATE irs_items SET in_stock = in_stock + ? WHERE id = ?;

-- Read for Inventory tab (updateInventory)
SELECT * FROM irs_items WHERE in_stock > 0;

pos_items

Purchase-order items representing stock that has been ordered but not yet received. Used exclusively by updateInventory to populate the “ordered (PO)” column on the Inventory sheet.
ColumnTypeDescription
idINT AUTO_INCREMENTPrimary key.
product_idINTFK → products.id.
quantityDECIMALQuantity on open purchase order. Filtered with WHERE quantity > 0 in updateInventory.
-- Read for Inventory tab (updateInventory)
SELECT * FROM pos_items WHERE quantity > 0;

Build docs developers (and LLMs) love