Invoice Number Logic
In the account_warehouse_mapping table:
Add new columns:
invoicePrefix: varchar(10) eg: RAY, CLA , This is fixed for any account_id and warehouse_id mapping.
invoiceSeriesLatestNumber: bigint default value=0 , It will increment for every invoice number generation.
Invoice generation logic:
Run the following query to update the invoiceSeriesLatestNumber in db.
Query: UPDATE account_warehouse_mapping SET invoiceSeriesLatestNumber = (invoiceSeriesLatestNumber +1) WHERE account_id=? AND warehouse_id = ?
We must get an updated record from the above query having updated invoiceSeriesLatestNumber which we will use in our invoice.
Invoice Number = InvoicePrefix + invoiceSeriesLatestNumber
Tax type logic:
Pick the states from shippingAddress state and facility state.
If within state(same state) - CGST/SGST
If different state - IGST
If sold and purchased within Andaman and Nicobar Islands, Lakshadweep, Dadra & Nagar Haveli and Daman & Diu, Ladakh and Chandigarh. - UTGST
For stateCode, Add new column "stateCode" in facility table.