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>
This commit is contained in:
Claude Sonnet 4.5 2026-02-08 12:21:12 +00:00
parent dd3d8c74dd
commit 1ce32959d2
17 changed files with 425 additions and 404 deletions

View file

@ -4,11 +4,11 @@ PARAM qtd AS INTEGER LIKE 10 DESCRIPTION "Quantity to add to stock"
DESCRIPTION "Add stock quantity for a product by SKU" DESCRIPTION "Add stock quantity for a product by SKU"
person = FIND "People.xlsx", "id=" + mobile person = FIND "People.xlsx", "id=" + mobile
vendor = FIND "maria.Vendedores", "id=" + person.erpId vendor = FIND ".Vendedores", "id=" + person.erpId
TALK "Olá " + vendor.Contato_Nome + "!" TALK "Olá " + vendor.Contato_Nome + "!"
produto = FIND "maria.Produtos", "sku=" + sku produto = FIND ".Produtos", "sku=" + sku
IF NOT produto THEN IF NOT produto THEN
TALK "Produto não encontrado." TALK "Produto não encontrado."

View file

@ -20,7 +20,7 @@ DO WHILE page > 0 AND page <= pages
itemCount = UBOUND(items) itemCount = UBOUND(items)
IF itemCount > 0 THEN IF itemCount > 0 THEN
MERGE "maria.ContasAReceber" WITH items BY "Id" MERGE ".ContasAReceber" WITH items BY "Id"
totalReceber = totalReceber + itemCount totalReceber = totalReceber + itemCount
page = page + 1 page = page + 1
@ -56,7 +56,7 @@ DO WHILE page > 0 AND page <= pages
itemCount = UBOUND(items) itemCount = UBOUND(items)
IF itemCount > 0 THEN IF itemCount > 0 THEN
MERGE "maria.ContasAPagar" WITH items BY "Id" MERGE ".ContasAPagar" WITH items BY "Id"
totalPagar = totalPagar + itemCount totalPagar = totalPagar + itemCount
page = page + 1 page = page + 1

View file

@ -42,7 +42,7 @@ DO WHILE i > 0 AND i < pages
produto.hierarquia = "s" produto.hierarquia = "s"
END IF END IF
produtoDB = FIND "maria.Produtos", "sku=" + produto.codigo produtoDB = FIND ".Produtos", "sku=" + produto.codigo
IF produtoDB THEN IF produtoDB THEN
IF produtoDB.preco <> produto.preco THEN IF produtoDB.preco <> produto.preco THEN
hist = NEW OBJECT hist = NEW OBJECT
@ -51,7 +51,7 @@ DO WHILE i > 0 AND i < pages
hist.precoAtual = produto.preco hist.precoAtual = produto.preco
hist.produto_id = produto.id hist.produto_id = produto.id
hist.dataModificado = FORMAT today, "yyyy-MM-dd" hist.dataModificado = FORMAT today, "yyyy-MM-dd"
SAVE "maria.HistoricoPreco", hist SAVE ".HistoricoPreco", hist
hist = null hist = null
END IF END IF
END IF END IF
@ -63,7 +63,7 @@ DO WHILE i > 0 AND i < pages
list = null list = null
list = items list = items
MERGE "maria.Produtos" WITH list BY "Id" MERGE ".Produtos" WITH list BY "Id"
list = items list = items
j = 0 j = 0
@ -86,7 +86,7 @@ DO WHILE i > 0 AND i < pages
k = 0 k = 0
DO WHILE k < ubound(listV) DO WHILE k < ubound(listV)
listV[k].hierarquia = 'f' listV[k].hierarquia = 'f'
DELETE "maria.ProdutoImagem", "sku=" + listV[k].sku DELETE ".ProdutoImagem", "sku=" + listV[k].sku
images = listV[k]?.midia?.imagens?.externas images = listV[k]?.midia?.imagens?.externas
l = 0 l = 0
@ -96,16 +96,16 @@ DO WHILE i > 0 AND i < pages
images[l].id = random() images[l].id = random()
l = l + 1 l = l + 1
LOOP LOOP
SAVE "maria.ProdutoImagem", images SAVE ".ProdutoImagem", images
images = null images = null
k = k + 1 k = k + 1
LOOP LOOP
MERGE "maria.Produtos" WITH listV BY "Id" MERGE ".Produtos" WITH listV BY "Id"
END IF END IF
listV = null listV = null
DELETE "maria.ProdutoImagem", "sku=" + list[j].sku DELETE ".ProdutoImagem", "sku=" + list[j].sku
k = 0 k = 0
images = list[j].midia?.imagens?.externas images = list[j].midia?.imagens?.externas
DO WHILE k < ubound(images) DO WHILE k < ubound(images)
@ -114,7 +114,7 @@ DO WHILE i > 0 AND i < pages
images[k].id = random() images[k].id = random()
k = k + 1 k = k + 1
LOOP LOOP
SAVE "maria.ProdutoImagem", images SAVE ".ProdutoImagem", images
j = j + 1 j = j + 1
LOOP LOOP
@ -155,7 +155,7 @@ DO WHILE i > 0 AND i < pages
items[k].custo = items[k].valor / 2 items[k].custo = items[k].valor / 2
k = k + 1 k = k + 1
LOOP LOOP
MERGE "maria.PedidosItem" WITH items BY "Id" MERGE ".PedidosItem" WITH items BY "Id"
items = res.data.parcelas items = res.data.parcelas
k = 0 k = 0
@ -163,14 +163,14 @@ DO WHILE i > 0 AND i < pages
items[k].pedido_id = pedido_id items[k].pedido_id = pedido_id
k = k + 1 k = k + 1
LOOP LOOP
MERGE "maria.Parcela" WITH items BY "Id" MERGE ".Parcela" WITH items BY "Id"
fullList[j] = res.data fullList[j] = res.data
res = null res = null
j = j + 1 j = j + 1
LOOP LOOP
MERGE "maria.Pedidos" WITH fullList BY "Id" MERGE ".Pedidos" WITH fullList BY "Id"
i = i + 1 i = i + 1
IF list?.length < limit THEN IF list?.length < limit THEN
i = 0 i = 0
@ -201,7 +201,7 @@ DO WHILE syncPage > 0 AND syncPage <= pages
syncCount = UBOUND(syncItems) syncCount = UBOUND(syncItems)
IF syncCount > 0 THEN IF syncCount > 0 THEN
MERGE "maria.CategoriaReceita" WITH syncItems BY "Id" MERGE ".CategoriaReceita" WITH syncItems BY "Id"
totalCategoria = totalCategoria + syncCount totalCategoria = totalCategoria + syncCount
syncPage = syncPage + 1 syncPage = syncPage + 1
@ -236,7 +236,7 @@ DO WHILE syncPage > 0 AND syncPage <= pages
syncCount = UBOUND(syncItems) syncCount = UBOUND(syncItems)
IF syncCount > 0 THEN IF syncCount > 0 THEN
MERGE "maria.FormaDePagamento" WITH syncItems BY "Id" MERGE ".FormaDePagamento" WITH syncItems BY "Id"
totalForma = totalForma + syncCount totalForma = totalForma + syncCount
syncPage = syncPage + 1 syncPage = syncPage + 1
@ -275,7 +275,7 @@ DO WHILE i > 0 AND i < pages
j = j + 1 j = j + 1
LOOP LOOP
MERGE "maria.Contatos" WITH items BY "Id" MERGE ".Contatos" WITH items BY "Id"
i = i + 1 i = i + 1
IF list?.length < limit THEN IF list?.length < limit THEN
i = 0 i = 0
@ -305,7 +305,7 @@ DO WHILE i > 0 AND i < pages
j = j + 1 j = j + 1
LOOP LOOP
MERGE "maria.Vendedores" WITH items BY "Id" MERGE ".Vendedores" WITH items BY "Id"
i = i + 1 i = i + 1
IF list?.length < limit THEN IF list?.length < limit THEN
i = 0 i = 0

View file

@ -2,7 +2,7 @@ SET SCHEDULE "0 30 23 * * *"
SEND EMAIL admin, "Inventory sync started..." SEND EMAIL admin, "Inventory sync started..."
fullList = FIND "maria.Produtos" fullList = FIND ".Produtos"
chunkSize = 100 chunkSize = 100
startIndex = 0 startIndex = 0
@ -30,11 +30,11 @@ DO WHILE startIndex < ubound(fullList)
k = 0 k = 0
DO WHILE k < ubound(items) DO WHILE k < ubound(items)
depositos = items[k].depositos depositos = items[k].depositos
pSku = FIND "maria.Produtos", "id=${items[k].produto.id}" pSku = FIND ".Produtos", "id=${items[k].produto.id}"
IF pSku THEN IF pSku THEN
prdSku = pSku.sku prdSku = pSku.sku
DELETE "maria.Depositos", "Sku=" + prdSku DELETE ".Depositos", "Sku=" + prdSku
l = 0 l = 0
DO WHILE l < ubound(depositos) DO WHILE l < ubound(depositos)
@ -42,7 +42,7 @@ DO WHILE startIndex < ubound(fullList)
l = l + 1 l = l + 1
LOOP LOOP
SAVE "maria.Depositos", depositos SAVE ".Depositos", depositos
depositos = null depositos = null
END IF END IF

View file

@ -5,7 +5,7 @@ DESCRIPTION "Sync product suppliers from Bling ERP to local database"
SEND EMAIL admin, "Suppliers sync started..." SEND EMAIL admin, "Suppliers sync started..."
FUNCTION SyncProdutoFornecedor(idProduto) FUNCTION SyncProdutoFornecedor(idProduto)
DELETE "maria.ProdutoFornecedor", "Produto_id=" + idProduto DELETE ".ProdutoFornecedor", "Produto_id=" + idProduto
i1 = 1 i1 = 1
DO WHILE i1 > 0 AND i1 < pages DO WHILE i1 > 0 AND i1 < pages
@ -26,7 +26,7 @@ FUNCTION SyncProdutoFornecedor(idProduto)
j1 = j1 + 1 j1 = j1 + 1
LOOP LOOP
SAVE "maria.ProdutoFornecedor", items1 SAVE ".ProdutoFornecedor", items1
items1 = null items1 = null
i1 = i1 + 1 i1 = i1 + 1
@ -38,7 +38,7 @@ FUNCTION SyncProdutoFornecedor(idProduto)
LOOP LOOP
END FUNCTION END FUNCTION
fullList = FIND "maria.Produtos" fullList = FIND ".Produtos"
chunkSize = 100 chunkSize = 100
startIndex = 0 startIndex = 0

View file

@ -1,4 +1,4 @@
TABLE Contatos ON maria TABLE Contatos
Id number key Id number key
Nome string(150) Nome string(150)
Codigo string(50) Codigo string(50)
@ -37,7 +37,7 @@ TABLE Contatos ON maria
Pais_nome string(100) Pais_nome string(100)
END TABLE END TABLE
TABLE Pedidos ON maria TABLE Pedidos
Id number key Id number key
Numero integer Numero integer
NumeroLoja string(15) NumeroLoja string(15)
@ -59,7 +59,7 @@ TABLE Pedidos ON maria
NotaFiscal_id number NotaFiscal_id number
END TABLE END TABLE
TABLE PedidosItem ON maria TABLE PedidosItem
Id number key Id number key
Numero integer Numero integer
Sku string(20) Sku string(20)
@ -75,14 +75,14 @@ TABLE PedidosItem ON maria
Pedido_id number Pedido_id number
END TABLE END TABLE
TABLE ProdutoImagem ON maria TABLE ProdutoImagem
Id number key Id number key
Ordinal number Ordinal number
Sku string(20) Sku string(20)
Link string(250) Link string(250)
END TABLE END TABLE
TABLE Produtos ON maria TABLE Produtos
Id number key Id number key
Nome string(150) Nome string(150)
Sku string(20) Sku string(20)
@ -146,7 +146,7 @@ TABLE Produtos ON maria
Estrutura_componentes_0_produto_Quantidade double Estrutura_componentes_0_produto_Quantidade double
END TABLE END TABLE
TABLE Depositos ON maria TABLE Depositos
Internal_Id number key Internal_Id number key
Id number Id number
Sku string(20) Sku string(20)
@ -154,7 +154,7 @@ TABLE Depositos ON maria
SaldoVirtual double SaldoVirtual double
END TABLE END TABLE
TABLE Vendedores ON maria TABLE Vendedores
Id number key Id number key
DescontoLimite double DescontoLimite double
Loja_Id number Loja_Id number
@ -163,7 +163,7 @@ TABLE Vendedores ON maria
Contato_Situacao string(1) Contato_Situacao string(1)
END TABLE END TABLE
TABLE ProdutoFornecedor ON maria TABLE ProdutoFornecedor
Id number key Id number key
Descricao string(255) Descricao string(255)
Codigo string(50) Codigo string(50)
@ -175,7 +175,7 @@ TABLE ProdutoFornecedor ON maria
Garantia integer Garantia integer
END TABLE END TABLE
TABLE ContasAPagar ON maria TABLE ContasAPagar
Id number key Id number key
Situacao integer Situacao integer
Vencimento date Vencimento date
@ -195,7 +195,7 @@ TABLE ContasAPagar ON maria
Ocorrencia_tipo integer Ocorrencia_tipo integer
END TABLE END TABLE
TABLE ContasAReceber ON maria TABLE ContasAReceber
Id number key Id number key
Situacao integer Situacao integer
Vencimento date Vencimento date
@ -232,7 +232,7 @@ TABLE ContasAReceber ON maria
Ocorrencia_tipo integer Ocorrencia_tipo integer
END TABLE END TABLE
TABLE CategoriaReceita ON maria TABLE CategoriaReceita
Id number key Id number key
IdCategoriaPai number IdCategoriaPai number
Descricao string(255) Descricao string(255)
@ -240,7 +240,7 @@ TABLE CategoriaReceita ON maria
Situacao integer Situacao integer
END TABLE END TABLE
TABLE FormaDePagamento ON maria TABLE FormaDePagamento
Id number key Id number key
Descricao string(255) Descricao string(255)
TipoPagamento integer TipoPagamento integer
@ -258,14 +258,14 @@ TABLE FormaDePagamento ON maria
DadosCartao_cnpjCredenciadora string(16) DadosCartao_cnpjCredenciadora string(16)
END TABLE END TABLE
TABLE NaturezaDeOperacao ON maria TABLE NaturezaDeOperacao
Id number key Id number key
Situacao integer Situacao integer
Padrao integer Padrao integer
Descricao string(255) Descricao string(255)
END TABLE END TABLE
TABLE Parcela ON maria TABLE Parcela
Id number key Id number key
Pedido_id number Pedido_id number
DataVencimento date DataVencimento date
@ -274,7 +274,7 @@ TABLE Parcela ON maria
FormaPagamento_id number FormaPagamento_id number
END TABLE END TABLE
TABLE HistoricoPreco ON maria TABLE HistoricoPreco
Id number key Id number key
Sku string(50) Sku string(50)
PrecoAntigo double PrecoAntigo double

View file

@ -0,0 +1 @@
/bin/bash: line 3: ./target/debug/botserver: No such file or directory

View file

@ -6,86 +6,86 @@
' Items/Products master table ' Items/Products master table
TABLE items TABLE items
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() id UUID KEY
item_code VARCHAR(50) UNIQUE NOT NULL item_code STRING(50)
barcode VARCHAR(50) UNIQUE barcode STRING(50)
name VARCHAR(255) NOT NULL name STRING(255)
description TEXT description TEXT
category VARCHAR(100) category STRING(100)
subcategory VARCHAR(100) subcategory STRING(100)
unit_of_measure VARCHAR(20) DEFAULT 'EACH' unit_of_measure STRING(20)
weight DECIMAL(10,3) weight NUMBER(10,3)
dimensions_length DECIMAL(10,2) dimensions_length NUMBER(10,2)
dimensions_width DECIMAL(10,2) dimensions_width NUMBER(10,2)
dimensions_height DECIMAL(10,2) dimensions_height NUMBER(10,2)
minimum_stock_level INTEGER DEFAULT 0 minimum_stock_level INTEGER
reorder_point INTEGER reorder_point INTEGER
reorder_quantity INTEGER reorder_quantity INTEGER
lead_time_days INTEGER DEFAULT 0 lead_time_days INTEGER
is_active BOOLEAN DEFAULT TRUE is_active BOOLEAN
is_purchasable BOOLEAN DEFAULT TRUE is_purchasable BOOLEAN
is_saleable BOOLEAN DEFAULT TRUE is_saleable BOOLEAN
is_manufactured BOOLEAN DEFAULT FALSE is_manufactured BOOLEAN
standard_cost DECIMAL(15,4) standard_cost NUMBER(15,4)
last_cost DECIMAL(15,4) last_cost NUMBER(15,4)
average_cost DECIMAL(15,4) average_cost NUMBER(15,4)
selling_price DECIMAL(15,4) selling_price NUMBER(15,4)
created_at TIMESTAMP DEFAULT NOW() created_at TIMESTAMP
updated_at TIMESTAMP DEFAULT NOW() updated_at TIMESTAMP
END TABLE END TABLE
' Warehouses table ' Warehouses table
TABLE warehouses TABLE warehouses
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() id UUID KEY
code VARCHAR(20) UNIQUE NOT NULL code STRING(20)
name VARCHAR(100) NOT NULL name STRING(100)
type VARCHAR(50) DEFAULT 'standard' type STRING(50)
address TEXT address TEXT
city VARCHAR(100) city STRING(100)
state VARCHAR(50) state STRING(50)
country VARCHAR(50) country STRING(50)
postal_code VARCHAR(20) postal_code STRING(20)
contact_person VARCHAR(100) contact_person STRING(100)
contact_phone VARCHAR(50) contact_phone STRING(50)
contact_email VARCHAR(100) contact_email STRING(100)
capacity_units INTEGER capacity_units INTEGER
current_occupancy INTEGER DEFAULT 0 current_occupancy INTEGER
is_active BOOLEAN DEFAULT TRUE is_active BOOLEAN DEFAULT TRUE
created_at TIMESTAMP DEFAULT NOW() created_at TIMESTAMP DEFAULT NOW()
END TABLE END TABLE
' Inventory stock levels ' Inventory stock levels
TABLE inventory_stock TABLE inventory_stock
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() id UUID KEY
item_id UUID REFERENCES items(id) item_id UUID
warehouse_id UUID REFERENCES warehouses(id) warehouse_id UUID
location_code VARCHAR(50) location_code STRING(50)
quantity_on_hand DECIMAL(15,3) DEFAULT 0 quantity_on_hand NUMBER(15,3)
quantity_reserved DECIMAL(15,3) DEFAULT 0 quantity_reserved NUMBER(15,3)
quantity_available DECIMAL(15,3) GENERATED ALWAYS AS (quantity_on_hand - quantity_reserved) STORED quantity_available NUMBER(15,3)
quantity_on_order DECIMAL(15,3) DEFAULT 0 quantity_on_order NUMBER(15,3)
last_counted_date DATE last_counted_date DATE
last_movement_date TIMESTAMP last_movement_date TIMESTAMP
created_at TIMESTAMP DEFAULT NOW() created_at TIMESTAMP DEFAULT NOW()
updated_at TIMESTAMP DEFAULT NOW() updated_at TIMESTAMP DEFAULT NOW()
UNIQUE(item_id, warehouse_id, location_code) (item_id, warehouse_id, location_code)
END TABLE END TABLE
' Inventory transactions ' Inventory transactions
TABLE inventory_transactions TABLE inventory_transactions
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() id UUID KEY
transaction_type VARCHAR(50) NOT NULL transaction_type STRING(50)
transaction_number VARCHAR(50) UNIQUE transaction_number STRING(50)
item_id UUID REFERENCES items(id) item_id UUID
warehouse_id UUID REFERENCES warehouses(id) warehouse_id UUID
location_code VARCHAR(50) location_code STRING(50)
quantity DECIMAL(15,3) NOT NULL quantity NUMBER(15,3)
unit_cost DECIMAL(15,4) unit_cost NUMBER(15,4)
total_cost DECIMAL(15,2) total_cost NUMBER(15,2)
reference_type VARCHAR(50) reference_type STRING(50)
reference_id UUID reference_id UUID
notes TEXT notes TEXT
created_by VARCHAR(100) created_by STRING(100)
created_at TIMESTAMP DEFAULT NOW() created_at TIMESTAMP DEFAULT NOW()
END TABLE END TABLE
@ -93,28 +93,28 @@ END TABLE
' Vendors/Suppliers table ' Vendors/Suppliers table
TABLE vendors TABLE vendors
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() id UUID KEY
vendor_code VARCHAR(50) UNIQUE NOT NULL vendor_code STRING(50)
name VARCHAR(255) NOT NULL name STRING(255)
legal_name VARCHAR(255) legal_name STRING(255)
tax_id VARCHAR(50) tax_id STRING(50)
vendor_type VARCHAR(50) vendor_type STRING(50)
status VARCHAR(20) DEFAULT 'active' status STRING(20)
rating INTEGER CHECK (rating >= 1 AND rating <= 5) rating INTEGER
payment_terms VARCHAR(50) payment_terms STRING(50)
credit_limit DECIMAL(15,2) credit_limit NUMBER(15,2)
currency_code VARCHAR(3) DEFAULT 'USD' currency_code STRING(3)
address TEXT address TEXT
city VARCHAR(100) city STRING(100)
state VARCHAR(50) state STRING(50)
country VARCHAR(50) country STRING(50)
postal_code VARCHAR(20) postal_code STRING(20)
phone VARCHAR(50) phone STRING(50)
email VARCHAR(100) email STRING(100)
website VARCHAR(255) website STRING(255)
contact_person VARCHAR(100) contact_person STRING(100)
bank_account_number VARCHAR(50) bank_account_number STRING(50)
bank_name VARCHAR(100) bank_name STRING(100)
notes TEXT notes TEXT
created_at TIMESTAMP DEFAULT NOW() created_at TIMESTAMP DEFAULT NOW()
updated_at TIMESTAMP DEFAULT NOW() updated_at TIMESTAMP DEFAULT NOW()
@ -122,75 +122,75 @@ END TABLE
' Purchase orders ' Purchase orders
TABLE purchase_orders TABLE purchase_orders
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() id UUID KEY
po_number VARCHAR(50) UNIQUE NOT NULL po_number STRING(50)
vendor_id UUID REFERENCES vendors(id) vendor_id UUID
order_date DATE NOT NULL order_date DATE
expected_date DATE expected_date DATE
status VARCHAR(50) DEFAULT 'draft' status STRING(50)
buyer_id VARCHAR(100) buyer_id STRING(100)
ship_to_warehouse_id UUID REFERENCES warehouses(id) ship_to_warehouse_id UUID
shipping_method VARCHAR(50) shipping_method STRING(50)
payment_terms VARCHAR(50) payment_terms STRING(50)
currency_code VARCHAR(3) DEFAULT 'USD' currency_code STRING(3)
exchange_rate DECIMAL(10,6) DEFAULT 1.0 exchange_rate NUMBER(10,6)
subtotal DECIMAL(15,2) subtotal NUMBER(15,2)
tax_amount DECIMAL(15,2) tax_amount NUMBER(15,2)
shipping_cost DECIMAL(15,2) shipping_cost NUMBER(15,2)
total_amount DECIMAL(15,2) total_amount NUMBER(15,2)
notes TEXT notes TEXT
approved_by VARCHAR(100) approved_by STRING(100)
approved_date TIMESTAMP approved_date TIMESTAMP
created_by VARCHAR(100) created_by STRING(100)
created_at TIMESTAMP DEFAULT NOW() created_at TIMESTAMP DEFAULT NOW()
updated_at TIMESTAMP DEFAULT NOW() updated_at TIMESTAMP DEFAULT NOW()
END TABLE END TABLE
' Purchase order lines ' Purchase order lines
TABLE purchase_order_lines TABLE purchase_order_lines
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() id UUID KEY
po_id UUID REFERENCES purchase_orders(id) ON DELETE CASCADE po_id UUID
line_number INTEGER NOT NULL line_number INTEGER
item_id UUID REFERENCES items(id) item_id UUID
description TEXT description TEXT
quantity_ordered DECIMAL(15,3) NOT NULL quantity_ordered NUMBER(15,3)
quantity_received DECIMAL(15,3) DEFAULT 0 quantity_received NUMBER(15,3)
quantity_remaining DECIMAL(15,3) GENERATED ALWAYS AS (quantity_ordered - quantity_received) STORED quantity_remaining NUMBER(15,3)
unit_price DECIMAL(15,4) NOT NULL unit_price NUMBER(15,4)
discount_percent DECIMAL(5,2) DEFAULT 0 discount_percent NUMBER(5,2)
tax_rate DECIMAL(5,2) DEFAULT 0 tax_rate NUMBER(5,2)
line_total DECIMAL(15,2) GENERATED ALWAYS AS (quantity_ordered * unit_price * (1 - discount_percent/100)) STORED line_total NUMBER(15,2)
expected_date DATE expected_date DATE
created_at TIMESTAMP DEFAULT NOW() created_at TIMESTAMP DEFAULT NOW()
UNIQUE(po_id, line_number) (po_id, line_number)
END TABLE END TABLE
' === SALES MODULE === ' === SALES MODULE ===
' Customers table ' Customers table
TABLE customers TABLE customers
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() id UUID KEY
customer_code VARCHAR(50) UNIQUE NOT NULL customer_code STRING(50)
name VARCHAR(255) NOT NULL name STRING(255)
legal_name VARCHAR(255) legal_name STRING(255)
tax_id VARCHAR(50) tax_id STRING(50)
customer_type VARCHAR(50) customer_type STRING(50)
status VARCHAR(20) DEFAULT 'active' status STRING(20)
credit_rating VARCHAR(10) credit_rating STRING(10)
credit_limit DECIMAL(15,2) credit_limit NUMBER(15,2)
payment_terms VARCHAR(50) payment_terms STRING(50)
discount_percent DECIMAL(5,2) DEFAULT 0 discount_percent NUMBER(5,2)
currency_code VARCHAR(3) DEFAULT 'USD' currency_code STRING(3)
billing_address TEXT billing_address TEXT
shipping_address TEXT shipping_address TEXT
city VARCHAR(100) city STRING(100)
state VARCHAR(50) state STRING(50)
country VARCHAR(50) country STRING(50)
postal_code VARCHAR(20) postal_code STRING(20)
phone VARCHAR(50) phone STRING(50)
email VARCHAR(100) email STRING(100)
website VARCHAR(255) website STRING(255)
sales_person_id VARCHAR(100) sales_person_id STRING(100)
notes TEXT notes TEXT
created_at TIMESTAMP DEFAULT NOW() created_at TIMESTAMP DEFAULT NOW()
updated_at TIMESTAMP DEFAULT NOW() updated_at TIMESTAMP DEFAULT NOW()
@ -198,74 +198,74 @@ END TABLE
' Sales orders ' Sales orders
TABLE sales_orders TABLE sales_orders
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() id UUID KEY
order_number VARCHAR(50) UNIQUE NOT NULL order_number STRING(50)
customer_id UUID REFERENCES customers(id) customer_id UUID
order_date DATE NOT NULL order_date DATE
required_date DATE required_date DATE
promised_date DATE promised_date DATE
status VARCHAR(50) DEFAULT 'draft' status STRING(50)
sales_person_id VARCHAR(100) sales_person_id STRING(100)
ship_from_warehouse_id UUID REFERENCES warehouses(id) ship_from_warehouse_id UUID
shipping_method VARCHAR(50) shipping_method STRING(50)
payment_terms VARCHAR(50) payment_terms STRING(50)
payment_method VARCHAR(50) payment_method STRING(50)
currency_code VARCHAR(3) DEFAULT 'USD' currency_code STRING(3)
exchange_rate DECIMAL(10,6) DEFAULT 1.0 exchange_rate NUMBER(10,6)
subtotal DECIMAL(15,2) subtotal NUMBER(15,2)
discount_amount DECIMAL(15,2) DEFAULT 0 discount_amount NUMBER(15,2)
tax_amount DECIMAL(15,2) tax_amount NUMBER(15,2)
shipping_cost DECIMAL(15,2) shipping_cost NUMBER(15,2)
total_amount DECIMAL(15,2) total_amount NUMBER(15,2)
notes TEXT notes TEXT
approved_by VARCHAR(100) approved_by STRING(100)
approved_date TIMESTAMP approved_date TIMESTAMP
created_by VARCHAR(100) created_by STRING(100)
created_at TIMESTAMP DEFAULT NOW() created_at TIMESTAMP DEFAULT NOW()
updated_at TIMESTAMP DEFAULT NOW() updated_at TIMESTAMP DEFAULT NOW()
END TABLE END TABLE
' Sales order lines ' Sales order lines
TABLE sales_order_lines TABLE sales_order_lines
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() id UUID KEY
order_id UUID REFERENCES sales_orders(id) ON DELETE CASCADE order_id UUID
line_number INTEGER NOT NULL line_number INTEGER
item_id UUID REFERENCES items(id) item_id UUID
description TEXT description TEXT
quantity_ordered DECIMAL(15,3) NOT NULL quantity_ordered NUMBER(15,3)
quantity_shipped DECIMAL(15,3) DEFAULT 0 quantity_shipped NUMBER(15,3)
quantity_invoiced DECIMAL(15,3) DEFAULT 0 quantity_invoiced NUMBER(15,3)
unit_price DECIMAL(15,4) NOT NULL unit_price NUMBER(15,4)
discount_percent DECIMAL(5,2) DEFAULT 0 discount_percent NUMBER(5,2)
tax_rate DECIMAL(5,2) DEFAULT 0 tax_rate NUMBER(5,2)
line_total DECIMAL(15,2) GENERATED ALWAYS AS (quantity_ordered * unit_price * (1 - discount_percent/100)) STORED line_total NUMBER(15,2)
cost_of_goods_sold DECIMAL(15,2) cost_of_goods_sold NUMBER(15,2)
margin DECIMAL(15,2) GENERATED ALWAYS AS (line_total - cost_of_goods_sold) STORED margin NUMBER(15,2)
warehouse_id UUID REFERENCES warehouses(id) warehouse_id UUID
promised_date DATE promised_date DATE
created_at TIMESTAMP DEFAULT NOW() created_at TIMESTAMP DEFAULT NOW()
UNIQUE(order_id, line_number) (order_id, line_number)
END TABLE END TABLE
' === MANUFACTURING MODULE === ' === MANUFACTURING MODULE ===
' Bill of Materials (BOM) header ' Bill of Materials (BOM) header
TABLE bill_of_materials TABLE bill_of_materials
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() id UUID KEY
bom_number VARCHAR(50) UNIQUE NOT NULL bom_number STRING(50)
item_id UUID REFERENCES items(id) item_id UUID
revision VARCHAR(20) DEFAULT 'A' revision STRING(20)
description TEXT description TEXT
quantity_per_assembly DECIMAL(15,3) DEFAULT 1 quantity_per_assembly NUMBER(15,3)
unit_of_measure VARCHAR(20) unit_of_measure STRING(20)
status VARCHAR(20) DEFAULT 'active' status STRING(20)
effective_date DATE effective_date DATE
expiration_date DATE expiration_date DATE
total_cost DECIMAL(15,4) total_cost NUMBER(15,4)
labor_cost DECIMAL(15,4) labor_cost NUMBER(15,4)
overhead_cost DECIMAL(15,4) overhead_cost NUMBER(15,4)
created_by VARCHAR(100) created_by STRING(100)
approved_by VARCHAR(100) approved_by STRING(100)
approved_date DATE approved_date DATE
created_at TIMESTAMP DEFAULT NOW() created_at TIMESTAMP DEFAULT NOW()
updated_at TIMESTAMP DEFAULT NOW() updated_at TIMESTAMP DEFAULT NOW()
@ -273,42 +273,42 @@ END TABLE
' BOM components ' BOM components
TABLE bom_components TABLE bom_components
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() id UUID KEY
bom_id UUID REFERENCES bill_of_materials(id) ON DELETE CASCADE bom_id UUID
component_item_id UUID REFERENCES items(id) component_item_id UUID
line_number INTEGER NOT NULL line_number INTEGER
quantity_required DECIMAL(15,6) NOT NULL quantity_required NUMBER(15,6)
unit_of_measure VARCHAR(20) unit_of_measure STRING(20)
scrap_percent DECIMAL(5,2) DEFAULT 0 scrap_percent NUMBER(5,2)
total_quantity DECIMAL(15,6) GENERATED ALWAYS AS (quantity_required * (1 + scrap_percent/100)) STORED total_quantity NUMBER(15,6)
cost_per_unit DECIMAL(15,4) cost_per_unit NUMBER(15,4)
total_cost DECIMAL(15,4) GENERATED ALWAYS AS (total_quantity * cost_per_unit) STORED total_cost NUMBER(15,4)
notes TEXT notes TEXT
created_at TIMESTAMP DEFAULT NOW() created_at TIMESTAMP DEFAULT NOW()
UNIQUE(bom_id, line_number) (bom_id, line_number)
END TABLE END TABLE
' Work orders ' Work orders
TABLE work_orders TABLE work_orders
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() id UUID KEY
wo_number VARCHAR(50) UNIQUE NOT NULL wo_number STRING(50)
item_id UUID REFERENCES items(id) item_id UUID
bom_id UUID REFERENCES bill_of_materials(id) bom_id UUID
quantity_to_produce DECIMAL(15,3) NOT NULL quantity_to_produce NUMBER(15,3)
quantity_completed DECIMAL(15,3) DEFAULT 0 quantity_completed NUMBER(15,3)
quantity_scrapped DECIMAL(15,3) DEFAULT 0 quantity_scrapped NUMBER(15,3)
status VARCHAR(50) DEFAULT 'planned' status STRING(50)
priority VARCHAR(20) DEFAULT 'normal' priority STRING(20)
planned_start_date TIMESTAMP planned_start_date TIMESTAMP
planned_end_date TIMESTAMP planned_end_date TIMESTAMP
actual_start_date TIMESTAMP actual_start_date TIMESTAMP
actual_end_date TIMESTAMP actual_end_date TIMESTAMP
warehouse_id UUID REFERENCES warehouses(id) warehouse_id UUID
work_center VARCHAR(50) work_center STRING(50)
labor_hours_estimated DECIMAL(10,2) labor_hours_estimated NUMBER(10,2)
labor_hours_actual DECIMAL(10,2) labor_hours_actual NUMBER(10,2)
notes TEXT notes TEXT
created_by VARCHAR(100) created_by STRING(100)
created_at TIMESTAMP DEFAULT NOW() created_at TIMESTAMP DEFAULT NOW()
updated_at TIMESTAMP DEFAULT NOW() updated_at TIMESTAMP DEFAULT NOW()
END TABLE END TABLE
@ -317,13 +317,13 @@ END TABLE
' General ledger accounts ' General ledger accounts
TABLE gl_accounts TABLE gl_accounts
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() id UUID KEY
account_number VARCHAR(20) UNIQUE NOT NULL account_number STRING(20)
account_name VARCHAR(100) NOT NULL account_name STRING(100)
account_type VARCHAR(50) NOT NULL account_type STRING(50)
parent_account_id UUID REFERENCES gl_accounts(id) parent_account_id UUID
currency_code VARCHAR(3) DEFAULT 'USD' currency_code STRING(3)
normal_balance VARCHAR(10) CHECK (normal_balance IN ('debit', 'credit')) normal_balance STRING(10)
is_active BOOLEAN DEFAULT TRUE is_active BOOLEAN DEFAULT TRUE
is_control_account BOOLEAN DEFAULT FALSE is_control_account BOOLEAN DEFAULT FALSE
allow_manual_entry BOOLEAN DEFAULT TRUE allow_manual_entry BOOLEAN DEFAULT TRUE
@ -334,65 +334,65 @@ END TABLE
' Journal entries header ' Journal entries header
TABLE journal_entries TABLE journal_entries
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() id UUID KEY
journal_number VARCHAR(50) UNIQUE NOT NULL journal_number STRING(50)
journal_date DATE NOT NULL journal_date DATE
posting_date DATE NOT NULL posting_date DATE
period VARCHAR(20) period STRING(20)
journal_type VARCHAR(50) journal_type STRING(50)
description TEXT description TEXT
reference_type VARCHAR(50) reference_type STRING(50)
reference_number VARCHAR(50) reference_number STRING(50)
status VARCHAR(20) DEFAULT 'draft' status STRING(20)
total_debit DECIMAL(15,2) total_debit NUMBER(15,2)
total_credit DECIMAL(15,2) total_credit NUMBER(15,2)
is_balanced BOOLEAN GENERATED ALWAYS AS (total_debit = total_credit) STORED is_balanced BOOLEAN
posted_by VARCHAR(100) posted_by STRING(100)
posted_at TIMESTAMP posted_at TIMESTAMP
reversed_by_id UUID REFERENCES journal_entries(id) reversed_by_id UUID
created_by VARCHAR(100) created_by STRING(100)
created_at TIMESTAMP DEFAULT NOW() created_at TIMESTAMP DEFAULT NOW()
END TABLE END TABLE
' Journal entry lines ' Journal entry lines
TABLE journal_entry_lines TABLE journal_entry_lines
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() id UUID KEY
journal_entry_id UUID REFERENCES journal_entries(id) ON DELETE CASCADE journal_entry_id UUID
line_number INTEGER NOT NULL line_number INTEGER
account_id UUID REFERENCES gl_accounts(id) account_id UUID
debit_amount DECIMAL(15,2) DEFAULT 0 debit_amount NUMBER(15,2)
credit_amount DECIMAL(15,2) DEFAULT 0 credit_amount NUMBER(15,2)
description TEXT description TEXT
dimension1 VARCHAR(50) dimension1 STRING(50)
dimension2 VARCHAR(50) dimension2 STRING(50)
dimension3 VARCHAR(50) dimension3 STRING(50)
created_at TIMESTAMP DEFAULT NOW() created_at TIMESTAMP DEFAULT NOW()
UNIQUE(journal_entry_id, line_number) (journal_entry_id, line_number)
CHECK (debit_amount = 0 OR credit_amount = 0)
END TABLE END TABLE
' Invoices ' Invoices
TABLE invoices TABLE invoices
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() id UUID KEY
invoice_number VARCHAR(50) UNIQUE NOT NULL invoice_number STRING(50)
invoice_type VARCHAR(20) DEFAULT 'standard' invoice_type STRING(20)
customer_id UUID REFERENCES customers(id) customer_id UUID
vendor_id UUID REFERENCES vendors(id) vendor_id UUID
order_id UUID order_id UUID
invoice_date DATE NOT NULL invoice_date DATE
due_date DATE NOT NULL due_date DATE
status VARCHAR(20) DEFAULT 'draft' status STRING(20)
currency_code VARCHAR(3) DEFAULT 'USD' currency_code STRING(3)
exchange_rate DECIMAL(10,6) DEFAULT 1.0 exchange_rate NUMBER(10,6)
subtotal DECIMAL(15,2) subtotal NUMBER(15,2)
discount_amount DECIMAL(15,2) DEFAULT 0 discount_amount NUMBER(15,2)
tax_amount DECIMAL(15,2) tax_amount NUMBER(15,2)
total_amount DECIMAL(15,2) total_amount NUMBER(15,2)
amount_paid DECIMAL(15,2) DEFAULT 0 amount_paid NUMBER(15,2)
balance_due DECIMAL(15,2) GENERATED ALWAYS AS (total_amount - amount_paid) STORED balance_due NUMBER(15,2)
payment_terms VARCHAR(50) payment_terms STRING(50)
notes TEXT notes TEXT
created_by VARCHAR(100) created_by STRING(100)
created_at TIMESTAMP DEFAULT NOW() created_at TIMESTAMP DEFAULT NOW()
updated_at TIMESTAMP DEFAULT NOW() updated_at TIMESTAMP DEFAULT NOW()
END TABLE END TABLE
@ -401,38 +401,38 @@ END TABLE
' Employees table ' Employees table
TABLE employees TABLE employees
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() id UUID KEY
employee_number VARCHAR(50) UNIQUE NOT NULL employee_number STRING(50)
first_name VARCHAR(100) NOT NULL first_name STRING(100)
last_name VARCHAR(100) NOT NULL last_name STRING(100)
middle_name VARCHAR(100) middle_name STRING(100)
full_name VARCHAR(255) GENERATED ALWAYS AS (first_name || ' ' || COALESCE(middle_name || ' ', '') || last_name) STORED full_name STRING(255)
email VARCHAR(100) UNIQUE email STRING(100)
phone VARCHAR(50) phone STRING(50)
mobile VARCHAR(50) mobile STRING(50)
address TEXT address TEXT
city VARCHAR(100) city STRING(100)
state VARCHAR(50) state STRING(50)
country VARCHAR(50) country STRING(50)
postal_code VARCHAR(20) postal_code STRING(20)
date_of_birth DATE date_of_birth DATE
gender VARCHAR(20) gender STRING(20)
marital_status VARCHAR(20) marital_status STRING(20)
national_id VARCHAR(50) national_id STRING(50)
passport_number VARCHAR(50) passport_number STRING(50)
department_id UUID department_id UUID
position_title VARCHAR(100) position_title STRING(100)
manager_id UUID REFERENCES employees(id) manager_id UUID
hire_date DATE NOT NULL hire_date DATE
employment_status VARCHAR(50) DEFAULT 'active' employment_status STRING(50)
employment_type VARCHAR(50) DEFAULT 'full-time' employment_type STRING(50)'full-time'
salary DECIMAL(15,2) salary NUMBER(15,2)
hourly_rate DECIMAL(10,2) hourly_rate NUMBER(10,2)
commission_percent DECIMAL(5,2) commission_percent NUMBER(5,2)
bank_account_number VARCHAR(50) bank_account_number STRING(50)
bank_name VARCHAR(100) bank_name STRING(100)
emergency_contact_name VARCHAR(100) emergency_contact_name STRING(100)
emergency_contact_phone VARCHAR(50) emergency_contact_phone STRING(50)
notes TEXT notes TEXT
created_at TIMESTAMP DEFAULT NOW() created_at TIMESTAMP DEFAULT NOW()
updated_at TIMESTAMP DEFAULT NOW() updated_at TIMESTAMP DEFAULT NOW()
@ -440,26 +440,26 @@ END TABLE
' Payroll records ' Payroll records
TABLE payroll TABLE payroll
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() id UUID KEY
payroll_number VARCHAR(50) UNIQUE NOT NULL payroll_number STRING(50)
employee_id UUID REFERENCES employees(id) employee_id UUID
pay_period_start DATE NOT NULL pay_period_start DATE
pay_period_end DATE NOT NULL pay_period_end DATE
payment_date DATE NOT NULL payment_date DATE
hours_worked DECIMAL(10,2) hours_worked NUMBER(10,2)
overtime_hours DECIMAL(10,2) overtime_hours NUMBER(10,2)
regular_pay DECIMAL(15,2) regular_pay NUMBER(15,2)
overtime_pay DECIMAL(15,2) overtime_pay NUMBER(15,2)
commission DECIMAL(15,2) commission NUMBER(15,2)
bonus DECIMAL(15,2) bonus NUMBER(15,2)
gross_pay DECIMAL(15,2) gross_pay NUMBER(15,2)
tax_deductions DECIMAL(15,2) tax_deductions NUMBER(15,2)
other_deductions DECIMAL(15,2) other_deductions NUMBER(15,2)
net_pay DECIMAL(15,2) net_pay NUMBER(15,2)
payment_method VARCHAR(50) payment_method STRING(50)
payment_reference VARCHAR(100) payment_reference STRING(100)
status VARCHAR(20) DEFAULT 'pending' status STRING(20)
approved_by VARCHAR(100) approved_by STRING(100)
approved_date TIMESTAMP approved_date TIMESTAMP
created_at TIMESTAMP DEFAULT NOW() created_at TIMESTAMP DEFAULT NOW()
END TABLE END TABLE
@ -468,42 +468,42 @@ END TABLE
' Audit trail ' Audit trail
TABLE erp_audit_log TABLE erp_audit_log
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() id UUID KEY
table_name VARCHAR(50) NOT NULL table_name STRING(50)
record_id UUID NOT NULL record_id UUID
action VARCHAR(20) NOT NULL action STRING(20)
changed_fields JSONB changed_fieldsTEXT
old_values JSONB old_valuesTEXT
new_values JSONB new_valuesTEXT
user_id VARCHAR(100) user_id STRING(100)
user_ip VARCHAR(45) user_ip STRING(45)
user_agent TEXT user_agent TEXT
created_at TIMESTAMP DEFAULT NOW() created_at TIMESTAMP DEFAULT NOW()
END TABLE END TABLE
' System settings ' System settings
TABLE erp_settings TABLE erp_settings
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() id UUID KEY
module VARCHAR(50) NOT NULL module STRING(50)
setting_key VARCHAR(100) NOT NULL setting_key STRING(100)
setting_value TEXT setting_value TEXT
data_type VARCHAR(20) data_type STRING(20)
description TEXT description TEXT
is_encrypted BOOLEAN DEFAULT FALSE is_encrypted BOOLEAN DEFAULT FALSE
created_at TIMESTAMP DEFAULT NOW() created_at TIMESTAMP DEFAULT NOW()
updated_at TIMESTAMP DEFAULT NOW() updated_at TIMESTAMP DEFAULT NOW()
UNIQUE(module, setting_key) (module, setting_key)
END TABLE END TABLE
' Create indexes for performance ' Create indexes for performance
CREATE INDEX idx_inventory_item_warehouse ON inventory_stock(item_id, warehouse_id) 'CREATE INDEX idx_inventory_item_warehouse ON inventory_stock(item_id, warehouse_id)
CREATE INDEX idx_po_vendor ON purchase_orders(vendor_id) 'CREATE INDEX idx_po_vendor ON purchase_orders(vendor_id)
CREATE INDEX idx_po_status ON purchase_orders(status) 'CREATE INDEX idx_po_status ON purchase_orders(status)
CREATE INDEX idx_so_customer ON sales_orders(customer_id) 'CREATE INDEX idx_so_customer ON sales_orders(customer_id)
CREATE INDEX idx_so_status ON sales_orders(status) 'CREATE INDEX idx_so_status ON sales_orders(status)
CREATE INDEX idx_wo_status ON work_orders(status) 'CREATE INDEX idx_wo_status ON work_orders(status)
CREATE INDEX idx_invoice_customer ON invoices(customer_id) 'CREATE INDEX idx_invoice_customer ON invoices(customer_id)
CREATE INDEX idx_invoice_status ON invoices(status) 'CREATE INDEX idx_invoice_status ON invoices(status)
CREATE INDEX idx_employee_manager ON employees(manager_id) 'CREATE INDEX idx_employee_manager ON employees(manager_id)
CREATE INDEX idx_journal_date ON journal_entries(journal_date) 'CREATE INDEX idx_journal_date ON journal_entries(journal_date)
CREATE INDEX idx_audit_table_record ON erp_audit_log(table_name, record_id) 'CREATE INDEX idx_audit_table_record ON erp_audit_log(table_name, record_id)

View file

@ -4,11 +4,11 @@ PARAM qtd AS INTEGER LIKE 10 DESCRIPTION "Quantity to add to stock"
DESCRIPTION "Add stock quantity for a product by SKU" DESCRIPTION "Add stock quantity for a product by SKU"
person = FIND "People.xlsx", "id=" + mobile person = FIND "People.xlsx", "id=" + mobile
vendor = FIND "maria.Vendedores", "id=" + person.erpId vendor = FIND ".Vendedores", "id=" + person.erpId
TALK "Olá " + vendor.Contato_Nome + "!" TALK "Olá " + vendor.Contato_Nome + "!"
produto = FIND "maria.Produtos", "sku=" + sku produto = FIND ".Produtos", "sku=" + sku
IF NOT produto THEN IF NOT produto THEN
TALK "Produto não encontrado." TALK "Produto não encontrado."

View file

@ -20,7 +20,7 @@ DO WHILE page > 0 AND page <= pages
itemCount = UBOUND(items) itemCount = UBOUND(items)
IF itemCount > 0 THEN IF itemCount > 0 THEN
MERGE "maria.ContasAReceber" WITH items BY "Id" MERGE ".ContasAReceber" WITH items BY "Id"
totalReceber = totalReceber + itemCount totalReceber = totalReceber + itemCount
page = page + 1 page = page + 1
@ -56,7 +56,7 @@ DO WHILE page > 0 AND page <= pages
itemCount = UBOUND(items) itemCount = UBOUND(items)
IF itemCount > 0 THEN IF itemCount > 0 THEN
MERGE "maria.ContasAPagar" WITH items BY "Id" MERGE ".ContasAPagar" WITH items BY "Id"
totalPagar = totalPagar + itemCount totalPagar = totalPagar + itemCount
page = page + 1 page = page + 1

View file

@ -42,7 +42,7 @@ DO WHILE i > 0 AND i < pages
produto.hierarquia = "s" produto.hierarquia = "s"
END IF END IF
produtoDB = FIND "maria.Produtos", "sku=" + produto.codigo produtoDB = FIND ".Produtos", "sku=" + produto.codigo
IF produtoDB THEN IF produtoDB THEN
IF produtoDB.preco <> produto.preco THEN IF produtoDB.preco <> produto.preco THEN
hist = NEW OBJECT hist = NEW OBJECT
@ -51,7 +51,7 @@ DO WHILE i > 0 AND i < pages
hist.precoAtual = produto.preco hist.precoAtual = produto.preco
hist.produto_id = produto.id hist.produto_id = produto.id
hist.dataModificado = FORMAT today, "yyyy-MM-dd" hist.dataModificado = FORMAT today, "yyyy-MM-dd"
SAVE "maria.HistoricoPreco", hist SAVE ".HistoricoPreco", hist
hist = null hist = null
END IF END IF
END IF END IF
@ -63,7 +63,7 @@ DO WHILE i > 0 AND i < pages
list = null list = null
list = items list = items
MERGE "maria.Produtos" WITH list BY "Id" MERGE ".Produtos" WITH list BY "Id"
list = items list = items
j = 0 j = 0
@ -86,7 +86,7 @@ DO WHILE i > 0 AND i < pages
k = 0 k = 0
DO WHILE k < ubound(listV) DO WHILE k < ubound(listV)
listV[k].hierarquia = 'f' listV[k].hierarquia = 'f'
DELETE "maria.ProdutoImagem", "sku=" + listV[k].sku DELETE ".ProdutoImagem", "sku=" + listV[k].sku
images = listV[k]?.midia?.imagens?.externas images = listV[k]?.midia?.imagens?.externas
l = 0 l = 0
@ -96,16 +96,16 @@ DO WHILE i > 0 AND i < pages
images[l].id = random() images[l].id = random()
l = l + 1 l = l + 1
LOOP LOOP
SAVE "maria.ProdutoImagem", images SAVE ".ProdutoImagem", images
images = null images = null
k = k + 1 k = k + 1
LOOP LOOP
MERGE "maria.Produtos" WITH listV BY "Id" MERGE ".Produtos" WITH listV BY "Id"
END IF END IF
listV = null listV = null
DELETE "maria.ProdutoImagem", "sku=" + list[j].sku DELETE ".ProdutoImagem", "sku=" + list[j].sku
k = 0 k = 0
images = list[j].midia?.imagens?.externas images = list[j].midia?.imagens?.externas
DO WHILE k < ubound(images) DO WHILE k < ubound(images)
@ -114,7 +114,7 @@ DO WHILE i > 0 AND i < pages
images[k].id = random() images[k].id = random()
k = k + 1 k = k + 1
LOOP LOOP
SAVE "maria.ProdutoImagem", images SAVE ".ProdutoImagem", images
j = j + 1 j = j + 1
LOOP LOOP
@ -155,7 +155,7 @@ DO WHILE i > 0 AND i < pages
items[k].custo = items[k].valor / 2 items[k].custo = items[k].valor / 2
k = k + 1 k = k + 1
LOOP LOOP
MERGE "maria.PedidosItem" WITH items BY "Id" MERGE ".PedidosItem" WITH items BY "Id"
items = res.data.parcelas items = res.data.parcelas
k = 0 k = 0
@ -163,14 +163,14 @@ DO WHILE i > 0 AND i < pages
items[k].pedido_id = pedido_id items[k].pedido_id = pedido_id
k = k + 1 k = k + 1
LOOP LOOP
MERGE "maria.Parcela" WITH items BY "Id" MERGE ".Parcela" WITH items BY "Id"
fullList[j] = res.data fullList[j] = res.data
res = null res = null
j = j + 1 j = j + 1
LOOP LOOP
MERGE "maria.Pedidos" WITH fullList BY "Id" MERGE ".Pedidos" WITH fullList BY "Id"
i = i + 1 i = i + 1
IF list?.length < limit THEN IF list?.length < limit THEN
i = 0 i = 0
@ -201,7 +201,7 @@ DO WHILE syncPage > 0 AND syncPage <= pages
syncCount = UBOUND(syncItems) syncCount = UBOUND(syncItems)
IF syncCount > 0 THEN IF syncCount > 0 THEN
MERGE "maria.CategoriaReceita" WITH syncItems BY "Id" MERGE ".CategoriaReceita" WITH syncItems BY "Id"
totalCategoria = totalCategoria + syncCount totalCategoria = totalCategoria + syncCount
syncPage = syncPage + 1 syncPage = syncPage + 1
@ -236,7 +236,7 @@ DO WHILE syncPage > 0 AND syncPage <= pages
syncCount = UBOUND(syncItems) syncCount = UBOUND(syncItems)
IF syncCount > 0 THEN IF syncCount > 0 THEN
MERGE "maria.FormaDePagamento" WITH syncItems BY "Id" MERGE ".FormaDePagamento" WITH syncItems BY "Id"
totalForma = totalForma + syncCount totalForma = totalForma + syncCount
syncPage = syncPage + 1 syncPage = syncPage + 1
@ -275,7 +275,7 @@ DO WHILE i > 0 AND i < pages
j = j + 1 j = j + 1
LOOP LOOP
MERGE "maria.Contatos" WITH items BY "Id" MERGE ".Contatos" WITH items BY "Id"
i = i + 1 i = i + 1
IF list?.length < limit THEN IF list?.length < limit THEN
i = 0 i = 0
@ -305,7 +305,7 @@ DO WHILE i > 0 AND i < pages
j = j + 1 j = j + 1
LOOP LOOP
MERGE "maria.Vendedores" WITH items BY "Id" MERGE ".Vendedores" WITH items BY "Id"
i = i + 1 i = i + 1
IF list?.length < limit THEN IF list?.length < limit THEN
i = 0 i = 0

View file

@ -2,7 +2,7 @@ SET SCHEDULE "0 30 23 * * *"
SEND EMAIL admin, "Inventory sync started..." SEND EMAIL admin, "Inventory sync started..."
fullList = FIND "maria.Produtos" fullList = FIND ".Produtos"
chunkSize = 100 chunkSize = 100
startIndex = 0 startIndex = 0
@ -30,11 +30,11 @@ DO WHILE startIndex < ubound(fullList)
k = 0 k = 0
DO WHILE k < ubound(items) DO WHILE k < ubound(items)
depositos = items[k].depositos depositos = items[k].depositos
pSku = FIND "maria.Produtos", "id=${items[k].produto.id}" pSku = FIND ".Produtos", "id=${items[k].produto.id}"
IF pSku THEN IF pSku THEN
prdSku = pSku.sku prdSku = pSku.sku
DELETE "maria.Depositos", "Sku=" + prdSku DELETE ".Depositos", "Sku=" + prdSku
l = 0 l = 0
DO WHILE l < ubound(depositos) DO WHILE l < ubound(depositos)
@ -42,7 +42,7 @@ DO WHILE startIndex < ubound(fullList)
l = l + 1 l = l + 1
LOOP LOOP
SAVE "maria.Depositos", depositos SAVE ".Depositos", depositos
depositos = null depositos = null
END IF END IF

View file

@ -5,7 +5,7 @@ DESCRIPTION "Sync product suppliers from Bling ERP to local database"
SEND EMAIL admin, "Suppliers sync started..." SEND EMAIL admin, "Suppliers sync started..."
FUNCTION SyncProdutoFornecedor(idProduto) FUNCTION SyncProdutoFornecedor(idProduto)
DELETE "maria.ProdutoFornecedor", "Produto_id=" + idProduto DELETE ".ProdutoFornecedor", "Produto_id=" + idProduto
i1 = 1 i1 = 1
DO WHILE i1 > 0 AND i1 < pages DO WHILE i1 > 0 AND i1 < pages
@ -26,7 +26,7 @@ FUNCTION SyncProdutoFornecedor(idProduto)
j1 = j1 + 1 j1 = j1 + 1
LOOP LOOP
SAVE "maria.ProdutoFornecedor", items1 SAVE ".ProdutoFornecedor", items1
items1 = null items1 = null
i1 = i1 + 1 i1 = i1 + 1
@ -38,7 +38,7 @@ FUNCTION SyncProdutoFornecedor(idProduto)
LOOP LOOP
END FUNCTION END FUNCTION
fullList = FIND "maria.Produtos" fullList = FIND ".Produtos"
chunkSize = 100 chunkSize = 100
startIndex = 0 startIndex = 0

View file

@ -1,4 +1,4 @@
TABLE Contatos ON maria TABLE Contatos
Id number key Id number key
Nome string(150) Nome string(150)
Codigo string(50) Codigo string(50)
@ -37,7 +37,7 @@ TABLE Contatos ON maria
Pais_nome string(100) Pais_nome string(100)
END TABLE END TABLE
TABLE Pedidos ON maria TABLE Pedidos
Id number key Id number key
Numero integer Numero integer
NumeroLoja string(15) NumeroLoja string(15)
@ -59,7 +59,7 @@ TABLE Pedidos ON maria
NotaFiscal_id number NotaFiscal_id number
END TABLE END TABLE
TABLE PedidosItem ON maria TABLE PedidosItem
Id number key Id number key
Numero integer Numero integer
Sku string(20) Sku string(20)
@ -75,14 +75,14 @@ TABLE PedidosItem ON maria
Pedido_id number Pedido_id number
END TABLE END TABLE
TABLE ProdutoImagem ON maria TABLE ProdutoImagem
Id number key Id number key
Ordinal number Ordinal number
Sku string(20) Sku string(20)
Link string(250) Link string(250)
END TABLE END TABLE
TABLE Produtos ON maria TABLE Produtos
Id number key Id number key
Nome string(150) Nome string(150)
Sku string(20) Sku string(20)
@ -146,7 +146,7 @@ TABLE Produtos ON maria
Estrutura_componentes_0_produto_Quantidade double Estrutura_componentes_0_produto_Quantidade double
END TABLE END TABLE
TABLE Depositos ON maria TABLE Depositos
Internal_Id number key Internal_Id number key
Id number Id number
Sku string(20) Sku string(20)
@ -154,7 +154,7 @@ TABLE Depositos ON maria
SaldoVirtual double SaldoVirtual double
END TABLE END TABLE
TABLE Vendedores ON maria TABLE Vendedores
Id number key Id number key
DescontoLimite double DescontoLimite double
Loja_Id number Loja_Id number
@ -163,7 +163,7 @@ TABLE Vendedores ON maria
Contato_Situacao string(1) Contato_Situacao string(1)
END TABLE END TABLE
TABLE ProdutoFornecedor ON maria TABLE ProdutoFornecedor
Id number key Id number key
Descricao string(255) Descricao string(255)
Codigo string(50) Codigo string(50)
@ -175,7 +175,7 @@ TABLE ProdutoFornecedor ON maria
Garantia integer Garantia integer
END TABLE END TABLE
TABLE ContasAPagar ON maria TABLE ContasAPagar
Id number key Id number key
Situacao integer Situacao integer
Vencimento date Vencimento date
@ -195,7 +195,7 @@ TABLE ContasAPagar ON maria
Ocorrencia_tipo integer Ocorrencia_tipo integer
END TABLE END TABLE
TABLE ContasAReceber ON maria TABLE ContasAReceber
Id number key Id number key
Situacao integer Situacao integer
Vencimento date Vencimento date
@ -232,7 +232,7 @@ TABLE ContasAReceber ON maria
Ocorrencia_tipo integer Ocorrencia_tipo integer
END TABLE END TABLE
TABLE CategoriaReceita ON maria TABLE CategoriaReceita
Id number key Id number key
IdCategoriaPai number IdCategoriaPai number
Descricao string(255) Descricao string(255)
@ -240,7 +240,7 @@ TABLE CategoriaReceita ON maria
Situacao integer Situacao integer
END TABLE END TABLE
TABLE FormaDePagamento ON maria TABLE FormaDePagamento
Id number key Id number key
Descricao string(255) Descricao string(255)
TipoPagamento integer TipoPagamento integer
@ -258,14 +258,14 @@ TABLE FormaDePagamento ON maria
DadosCartao_cnpjCredenciadora string(16) DadosCartao_cnpjCredenciadora string(16)
END TABLE END TABLE
TABLE NaturezaDeOperacao ON maria TABLE NaturezaDeOperacao
Id number key Id number key
Situacao integer Situacao integer
Padrao integer Padrao integer
Descricao string(255) Descricao string(255)
END TABLE END TABLE
TABLE Parcela ON maria TABLE Parcela
Id number key Id number key
Pedido_id number Pedido_id number
DataVencimento date DataVencimento date
@ -274,7 +274,7 @@ TABLE Parcela ON maria
FormaPagamento_id number FormaPagamento_id number
END TABLE END TABLE
TABLE HistoricoPreco ON maria TABLE HistoricoPreco
Id number key Id number key
Sku string(50) Sku string(50)
PrecoAntigo double PrecoAntigo double

1
botserver.log Normal file
View file

@ -0,0 +1 @@
/home/rodriguez/gb/restart.sh: line 19: ./target/debug/botserver: No such file or directory

1
botui.log Normal file
View file

@ -0,0 +1 @@
/home/rodriguez/gb/restart.sh: line 23: ./target/debug/botui: No such file or directory

View file

@ -1 +1,19 @@
Meta Challenge, name,value
,
bot-name,WhatsApp Integration
bot-description,WhatsApp messaging integration
,
param-whatsappPhoneNumber,
param-whatsappBusinessAccountID,
param-whatsappAccessToken,
param-whatsappWebhookURL,
param-whatsappVerifyToken,
,
llm-model,gpt-4o-mini
llm-temperature,0.3
,
sync-interval,60
auto-reply,true
,
param-admin1,admin@yourdomain.com
param-admin2,admin2@yourdomain.com

1 Meta Challenge name value
2
3 bot-name WhatsApp Integration
4 bot-description WhatsApp messaging integration
5
6 param-whatsappPhoneNumber
7 param-whatsappBusinessAccountID
8 param-whatsappAccessToken
9 param-whatsappWebhookURL
10 param-whatsappVerifyToken
11
12 llm-model gpt-4o-mini
13 llm-temperature 0.3
14
15 sync-interval 60
16 auto-reply true
17
18 param-admin1 admin@yourdomain.com
19 param-admin2 admin2@yourdomain.com