SUBLIBLANKS ORDER SYSTEM - RESULTS & PURCHASE ORDERS UPGRADE
22 November 2026

DEPLOYMENT
1. Back up your current website files and MySQL database first.
2. Upload the files from this ZIP into your existing orders website root (merge; do not create a new parent directory).
3. The site's existing config.php, classes/Shopify.php, one-drive-order-fetch*.php, and original cronjob.php are UNCHANGED.
4. Log in as Admin, open Results & billing and then Purchase orders. The new billing_* tables are created automatically if the existing MySQL user has CREATE TABLE permission. Otherwise run INSTALL_BILLING_TABLES.sql through phpMyAdmin.
5. For live Purchase Order reading, grant the SAME Shopify custom app the additional 'read_inventory_purchase_orders' scope and re-authorize the install to issue access to it. Keep ALL existing scopes. The new reader uses the same existing Shopify store address and access token, using GraphQL Admin API 2026-10. Shopify requires the user to have purchase order viewing permission. 'read_products' is needed for product images/variant matching (often already granted).
6. Click Sync Purchase orders. Initial history imports progressively. Leave the tab open while it runs (up to 600 POs per click) and repeat if needed. It preserves your own refunded/delete flags.
7. To keep Shopify PO history, cancellation statuses and the Google Drive index up-to-date without opening a browser, set up a separate cPanel cron task every 5 minutes:
   /usr/local/bin/php -q /FULL/PATH/TO/WEBSITE/billing-cron.php
   Use your server's actual PHP executable and actual website path. The new cron NEVER touches your existing cronjob.php or Google uploader.
8. Results displays the existing Google Drive file link once files are indexed. The first load automatically checks Google Drive; the Sync Google Drive button retries on demand. This is READ ONLY and does not upload, rename or delete Google files.

WHAT CHANGED
- New responsive left-side navigation and calm navy/teal interface. All prior pages, links and key functionality remain.
- Results shows each dated XLSX, existing Google Drive link, combined file value, distinctly styled Paid/Unpaid labels, and Mark as paid / Mark unpaid.
- Prices for Results come from the saved spreadsheet lines (historic values); original sheets are NEVER modified.
- The main Download icon generates an adjusted billing COPY excluding cancelled orders. The Excel icon downloads the ORIGINAL unchanged sheet. Google Drive links always open the original uploaded file.
- Cancellation checks read Shopify cancellations (not refunds). Only completely cancelled orders are excluded from Results financial totals; item-only refunds do not change totals. Recent orders are checked automatically, and the Check cancellations button allows another pass. A 60-day lookback is used for the first scan, then a two-day overlap per refresh. Historical cancelled orders are backfilled separately in pages (by the Check cancellations button or the new cron). Shopify may require read_all_orders to access orders older than its standard history window.
- A new Purchase orders tab imports native Shopify POs from the public 2026-10 Inventory Purchase Order read API. PO lines show images (when available), product name, Custom SKU, SKU, Custom Price (Orders), quantity, line total and grand total. Items without a price are flagged and NOT silently valued at zero. Products excluded from normal daily order reports are still valued using their saved custom price for PO refunds.
- Local Mark as refunded / Mark as awaiting refund status. Delete hides the local record ONLY and does not delete the PO in Shopify. PDF exports are generated in PHP (no wkhtmltopdf executable required).

IMPORTANT LIMITATIONS / NOTES
- No live Shopify, Google Drive, or MySQL connection was made while building this ZIP. Verify with a small test PO and an already-cancelled order after deployment.
- 'Mark as refunded' is a local reconciliation flag; it does not initiate any Shopify payment or refund.
- Existing uploaded Google files retain their original rows; downloads named -Billing.xlsx reflect cancellation adjustments.
- Actual images require a Shopify product/variant image and permission to read the product; otherwise the PDF displays a blank image placeholder.
- A disconnected Shopify or Google API gives an informative message, but does not affect the legacy upload or connector code.
- Your original ZIP includes live server keys/credentials. Store it securely and rotate any credentials if this ZIP has been shared beyond trusted administrators.
