# Barcode Scanning and Supplier Return Credits

## Selling and receiving

- Retail and wholesale: scan into the product search field. An exact barcode adds the item immediately on Enter, or after a short pause for scanners without an Enter suffix.
- Save & Print now uses F12, replacing F5. Save remains F4. Cash is F2; M-Pesa is F3; quantity is F1.
- New purchases and Edit / Add Items support direct barcode addition. Quantity can be changed on the added line. Product VAT settings are retained.
- Repeated selling scans follow the existing duplicate-product setting.

## Damaged stock and supplier credits

Open Damaged Products, then Add Damaged Product. Select the branch and date, then search or scan products into the item list. Add multiple rows, edit each quantity, remove unwanted rows, and save the whole batch together. Supplier selection remains visible and is optional for ordinary write-offs.

Choose either:

- Write off damaged stock: removes stock and posts an inventory loss, without changing any supplier balance.
- Return to supplier for credit: select the supplier and outstanding invoice to credit, enter the agreed credit including VAT, VAT from the supplier's credit note (zero when none), and the supplier credit/return reference.

Save deducts stock once, records the return, applies the credit to that invoice's outstanding balance, and posts the accounting journal in one database transaction. A failure on any row rolls back the entire batch. Use Print Return Note on any recorded return row for one Goods Return Note containing all items from that batch. Enter agreed credit and VAT separately on each return line.

The credited invoice need not contain the returned product: it may be a later invoice from the same supplier and branch. Only purchases visible to the user's own/all purchase permissions are offered. Credits cannot exceed the outstanding invoice balance; this workflow does not create unallocated supplier credits or record cash refunds.

Example: invoice total 1,000, M-Pesa payment 800, supplier return credit 200, balance zero. The invoice remains 1,000; actual payments remain 800. The separate Supplier Return Credit column and purchase details show the other 200 and its reference. Supplier outstanding balances use the remaining invoice balance.

Input VAT reductions use the explicitly entered supplier credit VAT and the return date; the selected settlement invoice's VAT is not copied onto unrelated returned items. The VAT report lists these adjustments separately. Differences between stock cost and supplier credit excluding VAT post to Inventory Loss And Wastage.

Invoices carrying credits cannot be deleted or processed through the older invoice-total-reducing purchase return action. Additional credits use Damaged Products. Products with damage/return history must be made inactive rather than deleted.

## Permissions

Damaged Products has a new **Apply Supplier Return Credit** checkbox (`damaged_products.supplier_credit`). Creating records also requires Add Damaged Product. Existing roles with Purchase Return authority received the new credit permission during migration. Both module access and branch restrictions still apply. This does not grant licence issuing authority.

## Existing installations

Back up the destination database, copy the changed application files without overwriting its `.env`, and apply pending migrations through the normal controlled upgrade procedure. The new migrations are `2026_10_16_160000_add_supplier_damage_credits.php` and `2026_10_16_170000_add_damage_batch_reference.php`. They add columns and a permission; they do not replace business data or change licence activation.

Earlier database exports and client ZIPs are not automatically rebuilt by these source edits.

## Verification

PHPUnit: `SupplierDamageCreditTest`, `PurchasePaymentPermissionsTest`, `PurchaseTaxRoundingTest`.

Browser fixtures: run the feature tests, then `node tools/verify-scanners-and-supplier-credits.cjs`. These simulate scanner keystrokes and test the F12 action at desktop and mobile widths. Real scanner hardware and client printers still need an on-site check.
