codeunit 50360 "GIO360 Primary Sale Sync"
{
procedure CreateOrder(Receipt: JsonObject): Code[20]
var
SalesHeader: Record "Sales Header";
Distributor: Record Customer;
Token: JsonToken;
begin
Receipt.Get('distributorCode', Token);
Distributor.Get(Token.AsValue().AsCode());
SalesHeader.Init();
SalesHeader."Document Type" := SalesHeader."Document Type"::Order;
SalesHeader.Insert(true);
SalesHeader.Validate("Sell-to Customer No.", Distributor."No.");
SalesHeader.Modify(true);
exit(SalesHeader."No.");
end;
}
{
"event": "secondary_sale.created",
"distributor": "DST-LAG-014",
"retailer": { "name": "Corner store", "area": "Surulere" },
"lines": [
{ "sku": "NDL-70G-40", "qty": 12, "unit": "carton" }
],
"total": { "amount": 186000, "currency": "NGN" },
"vat": { "rate": 7.5, "amount": 13950 },
"synced": true,
"createdAt": "2026-09-24T10:42:18+01:00"
}
$ gio360 sync --target business-central --region lagos
› Authenticating with Business Central … ok
› Pulling confirmed receipts … 214 found
› Creating sales orders … 214/214
› Posting VAT 7.5% and withholding tax … ok
› Updating distributor balances … ok
✓ Sync complete in 4.8s · next run 10:45 WAT