Azure D365 Portal - Sales Orders module
======================================

This package adds a second module after Customers: Sales Orders.

Main idea
---------
1. D365 F&O exports the Sales Order Header entity to Azure SQL BYOD.
2. Azure API Bridge exposes /sales-orders and returns SELECT * from the sales order BYOD table.
3. cPanel PHP sync stores important default fields in Azure_D365_Sales_Orders and stores the full original BYOD row in raw_json.
4. The Sales Orders page shows only useful default columns first. Users can click Columns and select additional BYOD fields from the full raw_json data.

Files added/changed
-------------------
- public_html/d365_portal/sales_orders.php
- public_html/d365_portal/assets/js/sales_orders.js
- public_html/d365_portal/api/sales_orders.php
- public_html/d365_portal/api/export_sales_orders.php
- public_html/d365_portal/api/sync_sales_orders.php
- public_html/d365_portal/api/debug_sales_orders.php
- public_html/d365_portal/layout.php
- public_html/d365_portal/index.php
- public_html/d365_portal/sync_status.php
- sql/Azure_D365_sales_orders_update.sql
- azure_api_bridge_nodejs/server.js

Important Azure App Service settings
------------------------------------
Add these in App Service > Environment variables:

BYOD_SALES_ORDER_TABLE = dbo.SalesOrderHeaderV2Staging
BYOD_SALES_ORDER_SYNC_COLUMN = SYNCSTARTDATETIME
BYOD_SALES_ORDER_ORDER_COLUMN = SALESORDERNUMBER
SQL_CONNECTION_TIMEOUT = 120000
SQL_REQUEST_TIMEOUT = 120000

You must confirm the exact BYOD table name in Azure SQL after publishing the D365 entity.
If your actual table is different, update BYOD_SALES_ORDER_TABLE.
If your order number column is different, update BYOD_SALES_ORDER_ORDER_COLUMN.

Quick test URLs
---------------
Azure API Bridge test:
https://YOUR-AZURE-APP.azurewebsites.net/sales-orders?pageSize=5
Use x-api-key header.

Portal sync:
https://yourdomain.com/d365_portal/api/sync_sales_orders.php?mode=full
https://yourdomain.com/d365_portal/api/sync_sales_orders.php?mode=incremental

Portal pages:
https://yourdomain.com/d365_portal/sales_orders.php
https://yourdomain.com/d365_portal/api/debug_sales_orders.php
https://yourdomain.com/d365_portal/api/sales_orders.php?page=1&pageSize=10
