================================================================================
  OKHES — MANUFACTURING V2 DEPLOYMENT PACKAGE
  Site:   okhes.averycaregroupltd.com
  Folder: okhes  (NOT "CRM")
  Date:   September 2026
================================================================================

WHAT THIS PACKAGE DOES
----------------------
Replaces the old "recipe per bag size" manufacturing model with the correct
four-stage flow:

  1. Purchase  → raw ingredients + packaging (bags) into separate stock
  2. Production → one recipe per feed type → bulk stock (kg)
  3. Packing    → bulk + bags → bag-size sellable products
  4. Sale       → deducts packed stock only; blocks if insufficient

Also includes: transaction reversals, backdated sales, tax-in/out report,
gross/net profit report, purchase-line tax (recoverable vs non-recoverable).


BEFORE YOU UPLOAD — BACK UP
---------------------------
1. Back up your live database in phpMyAdmin (Export).
2. Back up your current okhes files:
   public_html/okhes/src/
   public_html/okhes/public/
   public_html/okhes/config/   (do not overwrite db.local.php)


YOUR SERVER FOLDER LAYOUT (okhes — not CRM)
-------------------------------------------
The live app lives under the folder name  okhes :

  public_html/
    okhes/
      config/       app.php, db.php, db.local.php  ← keep db.local.php as-is
      src/            auth.php, stock.php, manufacturing.php, ...
      public/         login.php, dashboard.php, css/, includes/, store/
      database/       migrate_*.sql, schema_cpanel.sql

Login URL (typical):
  https://okhes.averycaregroupltd.com/okhes/public/login.php

If your subdomain document root is set to  public_html/okhes/public  then:
  https://okhes.averycaregroupltd.com/login.php
  and config/app.php should have:  define('APP_BASE_URL', '');


STEP 1 — UPLOAD FILES
---------------------
1. cPanel → File Manager → go to  public_html/
2. Upload  OKHES-Manufacturing-v2-cPanel-Upload.zip
3. Extract the ZIP.

   The ZIP contains a top-level  okhes/  folder. After extract you should see:

     public_html/okhes/src/...
     public_html/okhes/public/...
     public_html/okhes/database/...
     public_html/okhes/DEPLOY_README.txt

4. If you already have  public_html/okhes/  — choose  Merge / Overwrite  when
   prompted so updated files replace old ones.

   DO NOT overwrite:
     okhes/config/db.local.php   (your live database password)
     okhes/config/db.php         (unless you manage credentials separately)

5. Confirm  okhes/public/migrate_okhes_data.php  exists (one-time migration tool).


STEP 2 — RUN DATABASE MIGRATION (REQUIRED, ONCE)
------------------------------------------------
1. cPanel → phpMyAdmin → select your Okhes database
   (e.g. bgmxghks_averycrm or your okhes database name).
2. SQL tab → open  okhes/database/migrate_manufacturing_v2.sql
3. Copy all contents → Paste → Go.

Creates: feed_types, packaging_materials, packing_runs, new columns, permissions.


STEP 3 — MIGRATE EXISTING LIVE DATA (RECOMMENDED)
-------------------------------------------------
Log in as Admin, then visit ONE of:

  Browser:
    https://okhes.averycaregroupltd.com/okhes/public/migrate_okhes_data.php
    — or — if document root = okhes/public:
    https://okhes.averycaregroupltd.com/migrate_okhes_data.php

  SSH:
    cd ~/public_html/okhes
    php database/migrate_okhes_data.php

Converts old bag-ingredients → packaging, links products to feed types,
consolidates duplicate recipes to one formula per feed (per kg).

DELETE  public/migrate_okhes_data.php  from the server after running.


STEP 4 — CONFIG CHECK (okhes folder)
------------------------------------
On the server, open  okhes/config/app.php  and set APP_BASE_URL for your setup:

  Document root = public_html (default subdomain to okhes folder):
    define('APP_BASE_URL', '/okhes/public');

  Document root = public_html/okhes/public:
    define('APP_BASE_URL', '');

Database credentials stay in  okhes/config/db.local.php  (server only).


STEP 5 — SET UP MANUFACTURING
-----------------------------
Log in as Admin:

  1. Manufacturing → Feed Types
  2. Recipes (one per feed; quantities = per 1 kg output)
  3. Manufacturing → Packaging → Receive stock for bags
  4. Products (each bag-size SKU: feed type + bag weight + packaging)
  5. Test: Production → Packing → Sale


STEP 6 — VERIFY PERMISSIONS
---------------------------
Admin → Users → Roles & Permissions. New permissions:

  feed_types, packaging, packing, transactions.reverse,
  sales.backdate, reports.tax, reports.profit


FILE PLACEMENT MAP
------------------

  SERVER (okhes)                              THIS PACKAGE
  ----------------                            ------------
  okhes/src/manufacturing.php            ←    okhes/src/manufacturing.php
  okhes/src/stock.php                    ←    okhes/src/stock.php
  okhes/public/production.php            ←    okhes/public/production.php
  okhes/public/feed_types.php            ←    okhes/public/feed_types.php
  okhes/public/includes/nav_sidebar.php  ←    okhes/public/includes/nav_sidebar.php
  okhes/public/store/checkout.php        ←    okhes/public/store/checkout.php
  okhes/database/migrate_manufacturing_v2.sql ← okhes/database/...


TROUBLESHOOTING
---------------
- 404 errors: wrong APP_BASE_URL — use /okhes/public or '' per Step 4.
- Uploaded to CRM/ by mistake: move or re-extract into public_html/okhes/.
- Permission denied on menus: re-run migrate_manufacturing_v2.sql; log in as Admin.
- Production "No recipe": recipe must link to Feed Type, not a bag-size product.


ACCEPTANCE CHECKLIST
--------------------
 [ ] Files are under public_html/okhes/ (not public_html/CRM/)
 [ ] Feed types + one recipe each
 [ ] Bags under Packaging (not Ingredients)
 [ ] Production → bulk kg; Packing → bag products
 [ ] Sales blocked when stock insufficient
 [ ] Reversals work (production / packing / sale)
 [ ] Tax In/Out and Profit reports load

================================================================================
  End of deployment instructions — folder name on server: okhes
================================================================================
