MDH Bakery POS — Phase 10 Reports & Finance
==========================================

DEPLOY TO EXISTING LIVE INSTALLATION
1. Back up both the current /public_html/bakery/ files and engrgolk_bakery database.
2. In phpMyAdmin select the EXISTING engrgolk_bakery database.
3. Import ONLY sql/012_phase10_reports_finance.sql once. The migration extends the
   existing bpos_expenses and bpos_report_schedules tables; it does not replace data.
4. Open cPanel File Manager: /public_html/bakery/
5. Upload bakery_phase10_FULL_DIRECT_EXTRACT.zip and Extract/Overwrite in that folder.
   This package has files at the ZIP root: index.php, bakery/index.php, reports/index.php, etc.
   DO NOT extract an outer bakery/ folder inside /public_html/bakery/ again.
6. The existing config/database.php is included byte-for-byte unchanged from your upload.
   Double-check the file before deploying, and keep backups secure.
7. Sign in normally, open Reports & Finance from Bakery/Outlet/Home.
8. Create one sample operating expense and verify Expense History / Financial Report.
9. Try Sales, Daily, Returns, Product, Production, Raw/Finished Stock, Transfer,
   Credit, Outstanding, Purchases, Supplier Payments, Excel, CSV, Print/Save PDF.
10. Verify an Outlet Manager sees ONLY assigned locations and an unauthorized cashier
    cannot access /reports/view.php?report=finance or the expense-management page.

SCHEDULED EMAILS — REQUIRES A REAL cPANEL CRON JOB
Use your actual full hosting home path and the correct PHP CLI binary. Example:
    */15 * * * * /usr/local/bin/php -q /home/YOUR_CPANEL_USER/public_html/bakery/cli/send-reports.php >/dev/null 2>&1
The script refuses browser/HTTP access; DO NOT expose a web-accessible token.
Schedule creation is Super Admin-only and requires reports.email permission.
Times are Asia/Colombo local time, inherited from config/app.php.
Daily sends the previous calendar day; weekly on Monday sends the previous
Mon–Sun; monthly on the 1st sends the previous calendar month.
If mail() is not configured by hosting, scheduled emails cannot deliver until
that mail transport is configured. The UI displays last sent/error status.

REPORT DEFINITIONS / IMPORTANT FINANCIAL RULES
- Gross sales, bill discounts, tax and net amounts come from stored POS snapshots.
- P&L excludes output tax and reverses returned tax proportionally based on original
  sale-item tax snapshots. Returns are attributed to the ORIGINAL SALE period.
- COGS uses original sold batch/unit-cost snapshots. SELLABLE returns reverse COGS;
  damaged/waste/quality-hold returns retain the cost as economic loss.
- Credit collections are cash receipts and do NOT create new sales or profit.
- Supplier payments are cash outflows and do NOT create another operating expense.
- Purchased raw materials are inventory assets until used in production, not OPEX.
- Expense 'ALREADY_IN_PRODUCTION' is visible in the expenses report but excluded
  from OPEX in P&L to prevent double-counting finalized production costs.
- Whole-business (NULL location) expenses only enter an owner/admin all-locations view.
- Stock valuation and low-stock reports display CURRENT quantities, not historical
  as-of quantities. Dates on these pages do not create a historical stock snapshot.
- These are management estimates, not a substitute for a statutory accounting ledger.
- CSV is UTF-8 with a BOM; Excel (.xlsx) uses a portable self-contained writer.
- PDF: choose 'Print / Save as PDF' on the filtered report. It uses A4 landscape CSS.

No other Phase 1–9 methods have been intentionally replaced. All original uploaded
application files remain in the integrated package. The complete outer-wrapper ZIP
is provided separately if your workflow requires a root bakery/ directory.
Do NOT import sql/001_master_schema.sql into an existing live database.
