# Café ERP

A working CodeIgniter 4 / MySQL / Bootstrap application for one café: individual login, dashboard, master CRUD, POS, purchasing, production, stock counts, waste, QR ordering and reports.

## Start using it

Canonical folder: `C:/Users/Hp/Herd/cafe-erp`.

The configured `cafe_erp` MySQL database has its schema installed. Open [first-manager setup](http://cafe-erp.test/setup) on a fresh installation, choose your password, currency/precision and payment methods, then sign in. Setup closes after the first account exists. No default account or sample transactions are installed.

The Beydan development database includes optional sample catalog data: 4 categories, 11 menu items, 14 stocked items with sample opening balances, 3 clearly named sample suppliers, 7 drink recipes and 2 batch recipes. Its 12 existing tables were preserved. Prices are USD examples; opening stock was posted through the stock ledger and is labeled as sample in each adjustment reason. Run `php spark db:seed StarterCafeDataSeeder` after creating a manager to add missing sample records on a fresh USD/two-decimal café; rerunning it does not duplicate records or add stock twice. Replace the example prices and reconcile physical quantities before live trading. This seed never creates bills, payments or purchase orders.

To enter your own catalog instead, create categories, inventory and menu items. Add opening stock with **Adjust stock**, save drink recipes and configure disposable serving supplies. In **Point of sale**, search and tap products, choose a serving option per item, then either record payment with the new bill or create a bill for later payment. Preparation and handover remain separate actions on the bill; payment does not use stock.

**Purchases** records orders, partial accepted deliveries and supplier payments. **Batch production** records actual ingredients and portions. **Physical count** reconciles balances; **Waste log** records spoiled inventory. Managers can discard prepared bill items or close unpaid balances from their bills.

Generate printable customer codes from **Tables**. Staff review customer requests in **QR approval queue**. Each acceptance creates a separate bill, including repeat requests at the same table. **Open table bills** shows occupancy. **Expense Management** lets managers define types and record, correct, or void everyday expenses. **Reports** has separate Sales, Income and expenses, Inventory valuation, Suppliers, and Audit log pages with focused filters and Excel/PDF downloads. Income and expenses combines recorded customer payments, supplier payments, refunds and everyday expenses; costs not entered in the system remain excluded.

For a fresh installation:

```powershell
Set-Location C:\Users\Hp\Herd\cafe-erp
composer install
# Copy env to .env; merge env.cafe.example and configure MySQL.
php spark migrate
php spark db:seed CafeSeeder
php spark cafe:qr-key
```

Create the database first. PHP 8.2+ needs MySQLi, Intl, Mbstring, BCMath, GD, Fileinfo and OpenSSL. Herd serves `public/` at `http://cafe-erp.test`. First-manager setup is local/development-only. Keep `.env` private and back up its encryption key with the database.

Phone scanning needs an application URL reachable from the phone. The Herd hostname is local to this computer; configure a suitable network URL before printing codes for café use.

See [production table QR recovery](docs/TABLE-QR-DEPLOYMENT.md) for existing deployments and [receipt printer setup](docs/THERMAL-PRINTING.md) for QZ Tray and ESC/POS.

## Organization and verification

Controllers handle HTTP; named services own validation, transactions and audits; models use bound SQL and explicit fields. Application models never use Query Builder or inherit CI Model. Histories are append-only; master records are archived.

Working Bootstrap views are separated by module. Shared layouts live in `app/Views/layouts`; styles/scripts and Bootstrap live in `public/assets`. Photos are validated and re-encoded into private storage. No frontend build is needed.

Reference-only [previews](http://cafe-erp.test/preview) are isolated and disabled in production.

```powershell
composer test
npm ci
npm run test:browser
```

See [isolated MySQL/browser testing](tests/README.md), [implementation status](docs/IMPLEMENTATION-STATUS.md), [business rules](docs/BUSINESS-RULES.md), [code analysis](docs/PROJECT-ANALYSIS.md) and [routes](docs/WORKING-ROUTES.md).

Active code is in `cafe-erp`. This chat still locks the original `cafe-erp-ci4` working directory. Reopen Codex in the canonical folder before retiring the old copy.
