bottemplates/bots/integration/bling.gbai/bling.gbdialog/sync-inventory.bas
Claude Sonnet 4.5 1ce32959d2 WIP: Template updates from previous session
- Fix TABLE definitions in bling and erp templates
- Update sync scripts for bling integration
- Fix WhatsApp config.csv header

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-08 12:21:12 +00:00

60 lines
1.3 KiB
QBasic

SET SCHEDULE "0 30 23 * * *"
SEND EMAIL admin, "Inventory sync started..."
fullList = FIND ".Produtos"
chunkSize = 100
startIndex = 0
DO WHILE startIndex < ubound(fullList)
list = mid(fullList, startIndex, chunkSize)
prd1 = ""
j = 0
items = NEW ARRAY
DO WHILE j < ubound(list)
produto_id = list[j].id
prd1 = prd1 + "&idsProdutos%5B%5D=" + produto_id
j = j + 1
LOOP
list = null
IF j > 0 THEN
res = GET host + "/estoques/saldos?${prd1}"
WAIT 0.33
items = res.data
res = null
k = 0
DO WHILE k < ubound(items)
depositos = items[k].depositos
pSku = FIND ".Produtos", "id=${items[k].produto.id}"
IF pSku THEN
prdSku = pSku.sku
DELETE ".Depositos", "Sku=" + prdSku
l = 0
DO WHILE l < ubound(depositos)
depositos[l].sku = prdSku
l = l + 1
LOOP
SAVE ".Depositos", depositos
depositos = null
END IF
pSku = null
k = k + 1
LOOP
items = null
END IF
startIndex = startIndex + chunkSize
items = null
LOOP
fullList = null
SEND EMAIL admin, "Inventory sync completed."