Bakery POS - Phase 8 Finished Goods / Transfers / Multi-Outlet Inventory

IMPORTANT
=========
This build was created from the exact latest Bakery POS ZIP and SQL export supplied before Phase 8.
The full integrated package preserves the complete existing application, including the current
config/database.php file. No application file from the supplied baseline is intentionally omitted.

LIVE UPGRADE ORDER
==================
1. Back up the current /public_html/bakery/ folder.
2. Back up the engrgolk_bakery database in phpMyAdmin.
3. Import ONLY:

   /sql/009_phase8_finished_goods_inventory.sql

   Import it ONCE into the existing engrgolk_bakery database.

4. Upload the Phase 8 application files.

   Option A - safest when you are already inside /public_html/bakery/:
   Use bakery_full_phase8_DIRECT_EXTRACT.zip and extract it directly there.

   Option B - if uploading from /public_html/:
   Use bakery_full_phase8_updated.zip. It contains the outer bakery/ folder,
   matching the structure of the source ZIP that was supplied.

5. Do NOT import sql/001_master_schema.sql into the existing live database.
   That file is the consolidated clean-install schema only.

6. Login and test in this order:

   Bakery -> Finished Goods
   Bakery -> Transfers -> New Transfer
   Save Draft -> Approve -> Dispatch
   Outlet -> Transfers -> Receive
   Finished Goods / Outlet Stock -> Stock History
   Stock Adjustment
   Physical Count

PHASE 8 BUSINESS FLOW
=====================
Transfer lifecycle:
DRAFT -> APPROVED -> DISPATCHED -> CLOSED
                              \-> RECEIVED -> CLOSED (when there is damage/shortage)

DRAFT:
- No stock effect.

APPROVED:
- Source finished-goods batch quantity is reserved.
- Usable stock = On Hand - Reserved.

DISPATCHED:
- Source on-hand stock is reduced.
- Reservation is released.
- TRANSFER_OUT product-stock ledger movement is recorded.
- Stock remains represented by the transfer as in-transit stock until receipt.

RECEIVED:
- Good received quantity enters the destination batch/lot.
- TRANSFER_IN ledger movement is recorded.
- Damage and shortage are recorded separately and are not added to destination stock.
- No discrepancy: transfer closes automatically.
- Discrepancy: transfer stays RECEIVED until reviewed and manually closed.

Stock adjustment:
- Requires a reason.
- Cannot make stock negative.
- Cannot reduce stock below an approved-transfer reservation.
- Every correction is ledger-backed.

Physical count:
- Creates a snapshot of current positive finished-goods batches.
- Count every row, then post.
- If stock changes after the count starts, posting is blocked and a fresh count is required.
- Variances are posted as ADJUSTMENT ledger movements.

DATABASE CHANGES
================
009_phase8_finished_goods_inventory.sql adds:
- Products: reorder_level_qty
- Finished-product batches: quantity_reserved
- Transfer closure/cancellation fields
- Destination batch / dispatched cost snapshot fields on transfer items
- bpos_stock_counts
- bpos_stock_count_items

No new permission codes are required. The existing stock.view, stock.transfer,
stock.receive, stock.adjust and stock.count permissions are used.

CODE FORMAT
===========
All new/changed Phase 8 PHP, JavaScript, CSS and SQL files are written in a normal
vertically readable structure with indentation and line breaks for easier maintenance.
