# Markazia Central Costing ERP — Full Documentation (`llms-full.txt`) > Production Host: https://markzia.araamo.com/ > OpenAPI Spec: https://markzia.araamo.com/openapi.json > Summary Index: https://markzia.araamo.com/llms.txt ## 1. Platform Purpose & Scope **Markazia Central Costing ERP** (`مركز التكاليف المركزي — شركة المتخصصة المركزية للمطاعم واللحوم`) is an enterprise F&B costing, kitchen production, carcass butchery, inter-branch logistics, and financial reconciliation web platform. It unifies live Odoo 19 ERP accounting and purchasing data with Supabase PostgreSQL cloud state. Supported operational branches: - `خلدا` (Khalda Branch — `khalda`) - `المدينة` (Gardens / Al-Madina Branch — `gardens`) - `المشغل المركزي` (Central Kitchen / Meat Workshop — `workshop`) - `المزرعة` (Farm — `mazraa`) - `غير موزع تحليلياً` (Unallocated General Accounting — `general`) --- ## 2. Technical Architecture ### Backend (`src/worker.ts` on Cloudflare Workers) - Runs at the Cloudflare Edge under Worker `markzia-costing`. - Serves static SPA bundles from `./web_react/dist` via `ASSETS` binding with extension-safe SPA routing (`!url.pathname.slice(1).includes('.')`). - Handles `/api/*` REST endpoints for Supabase state sync, password & Cloudflare Zero Trust authentication, RBAC management, and Odoo 19 JSON-RPC calls. - Communicates with Odoo 19 (`jsonrpc` 2.0) over raw Cloudflare TLS sockets (`cloudflare:sockets`) with automatic HTTPS endpoint fallbacks and `Cache-Control: no-store`. ### Frontend (`web_react/` React 19 + TypeScript + Vite SPA) - Bilingual Arabic (default RTL) and English (LTR) UI with Light & Obsidian Dark themes. - Uses `SmartNumberInput` for clean precision handling (supports Eastern Arabic numerals `٠-٩`, trims insignificant trailing zeros such as `1000.00 -> 1000`, preserves precision `< 0.01`). - Protected by role-based access control (`super_admin`, `costing_manager`, `kitchen_chef`, `cost_auditor`, `viewer`, `custom`) with strict hiding of costs (`can_view_costs`) and selling prices (`can_view_selling_price`) for kitchen-only roles. - Every state mutation emits an audit entry to `public.audit_logs` via `AuditLogService`. --- ## 3. Official Short Routes Reference | Module | Official URL | Internal Route Key | | --- | --- | --- | | Semi-Finished Mixes (`SF`) | `https://markzia.araamo.com/smf` | `sf` | | Finished Meals (`FP`) | `https://markzia.araamo.com/fp` | `fp` | | Combos (`CB`) | `https://markzia.araamo.com/cb` | `cb` | | Meat Workshop (`MW`) | `https://markzia.araamo.com/mw` | `meat_workshop` | | Drinks (`DRK`) | `https://markzia.araamo.com/drk` | `drinks` | | Butchery & Carcass (`BTC`) | `https://markzia.araamo.com/btc` | `butchery` | | Yield Formulas (`YLD`) | `https://markzia.araamo.com/yld` | `yields` | | Odoo Warehouse (`WH`) | `https://markzia.araamo.com/wh` | `odoo` | | Odoo COGS Entry (`COGS`) | `https://markzia.araamo.com/cogs` | `odoo_cogs` | | Delivery App Prices (`APP`) | `https://markzia.araamo.com/app` | `apps` | | Branch Sales & P&L (`PNL`) | `https://markzia.araamo.com/pnl` | `facilitations` | | Branch Transfers (`TRF`) | `https://markzia.araamo.com/trf` | `transfers` | | Standalone Chef Portal (`CHF`) | `https://markzia.araamo.com/chf` | `chef_model` | | Chef Requests (`REQ`) | `https://markzia.araamo.com/req` | `chef_requests` | | Global Audit Log (`LOG`) | `https://markzia.araamo.com/log` | `global_audit` | | Recipe Audit Center (`AUD`) | `https://markzia.araamo.com/aud` | `audit` | | Voucher Gallery (`VCH`) | `https://markzia.araamo.com/vch` | `vouchers` | | Under Review (`REV`) | `https://markzia.araamo.com/rev` | `under_review` | | Archive Log (`ARC`) | `https://markzia.araamo.com/arc` | `archived` | | Trash Bin (`DEL`) | `https://markzia.araamo.com/del` | `trash` | --- ## 4. Data Persistence Model (Supabase PostgreSQL) - `public.app_kv_store`: Canonical versioned JSONB state keyed by `recipes_state_v1`, `chef_submissions_v1`, `yield_formulas_v1`, `deleted_yield_codes_v1`, `branch_transfers_v1`, and `rbac_users`. - `public.yield_formulas`: Normalized raw material trimming/peeling yield percentages, drained weights, net kg costs, and piece-count rules. - `public.branch_transfers`: Dual-written inter-branch transfer & return records with route (`from_branch`, `to_branch`) and full line-item `transfer_data`. - `public.audit_logs`: Indexed immutable activity ledger recording timestamp, actor metadata (`user_name`, `user_email`, `user_role`), `action_type`, `entity_type`, `entity_id`, `page_context`, `description`, and JSONB field diffs. --- ## 5. Worker API Endpoints Summary (See `/openapi.json`) ### Identity & Auth - `GET /api/access/identity` — Resolves Cloudflare Zero Trust (`Cf-Access-Authenticated-User-Email` / `CF_Authorization`) session & RBAC user profile. - `POST /api/auth/login-password` — Authenticates username/email + password against `rbac_users`. - `POST /api/auth/logout` — Expires session cookie. ### Cloud Sync & Audit - `GET | POST | PUT /api/recipes/state` — Reads or saves `recipes_state_v1`. - `GET | POST | PUT /api/chef/submissions` — Reads or merges `chef_submissions_v1` with tombstone protection. - `GET | POST | PUT /api/yield/formulas` — Reads/writes structured `yield_formulas` table + deleted tombstones. - `GET | POST /api/audit/logs` — Filters (`entity_id`, `entity_type`, `page_context`, `action_type`, `user_email`, `search`, `limit`, `offset`) or appends entries to `audit_logs`. - `GET | POST | PUT | DELETE /api/admin/users` — Manages RBAC users (`?lite=1` omits large base64 documents). - `POST /api/admin/sync-access-policy` — Adds or removes user emails in the Cloudflare Zero Trust policy. ### Odoo 19 ERP Bridge - `POST /api/odoo/test-connection` — Validates Odoo RPC version & user authentication. - `POST /api/odoo/lookup` — Lists Odoo `account.journal` and `account.account` records. - `POST /api/odoo/cogs-entry` — Creates a balanced COGS journal entry (`account.move`, draft by default). - `POST /api/odoo/delete-entry` — Unlinks a draft `account.move` by `move_id`. - `POST /api/odoo/webhook-sales` — Handles Odoo sales webhook events. - `POST /api/odoo/sales-summary` — Unlimited-scan period sales + recipe COGS aggregation. - `POST /api/odoo/full-sales-lines` — Unlimited `account.move` / `account.move.line` dataset for audit & Excel export. - `GET | POST /api/odoo/monthly-daily-sales` — Daily net sales, discounts, returns, branch P&L breakdown, unposted moves, missing analytic moves, and open POS sessions. - `GET | POST /api/odoo/purchases` — Live `purchase.order.line` & `product.product` standard, monthly avg, annual avg, and latest purchase prices by `default_code`. - `GET | POST /api/odoo/product-channel-prices` — Live pricelist lookup for a product `code` across Direct, Talabat, Careem, Ashyaee, and Meis (`net` & `gross` 16% VAT).