Fix incorrect columns in import scripts

This commit is contained in:
2025-02-18 10:46:16 -05:00
parent ca2653ea1a
commit 675a0fc374
7 changed files with 214 additions and 88 deletions

View File

@@ -25,8 +25,8 @@ async function importPurchaseOrders(prodConnection, localConnection, incremental
sku VARCHAR(50),
name VARCHAR(255),
vendor VARCHAR(255),
date DATE,
expected_date DATE,
date TIMESTAMP WITH TIME ZONE,
expected_date TIMESTAMP WITH TIME ZONE,
status INTEGER,
notes TEXT,
ordered INTEGER,
@@ -40,7 +40,7 @@ async function importPurchaseOrders(prodConnection, localConnection, incremental
receiving_id INTEGER NOT NULL,
qty_each INTEGER,
cost_each DECIMAL(10,3),
received_date TIMESTAMP,
received_date TIMESTAMP WITH TIME ZONE,
received_by INTEGER,
received_by_name VARCHAR(255),
is_alt_po INTEGER,
@@ -130,12 +130,12 @@ async function importPurchaseOrders(prodConnection, localConnection, incremental
) as vendor,
CASE
WHEN p.po_id IS NOT NULL THEN
DATE(COALESCE(
COALESCE(
NULLIF(p.date_ordered, '0000-00-00 00:00:00'),
p.date_created
))
)
WHEN r.receiving_id IS NOT NULL THEN
DATE(r.date_created)
r.date_created
END as date,
CASE
WHEN p.date_estin = '0000-00-00' THEN NULL
@@ -213,7 +213,7 @@ async function importPurchaseOrders(prodConnection, localConnection, incremental
pop.pid,
pr.itemnumber as sku,
pr.description as name,
pop.cost_each,
pop.cost_each as cost_price,
pop.qty_each as ordered
FROM po_products pop
USE INDEX (PRIMARY)
@@ -320,7 +320,7 @@ async function importPurchaseOrders(prodConnection, localConnection, incremental
po.status,
po.notes || po.long_note,
product.ordered,
product.cost_each
product.cost_price
);
const offset = idx * 11; // Updated to match 11 fields
@@ -424,6 +424,7 @@ async function importPurchaseOrders(prodConnection, localConnection, incremental
SELECT cost_each
FROM temp_po_receivings r2
WHERE r2.pid = po.pid
AND r2.po_id = po.po_id
AND r2.is_alt_po = 0
AND r2.cost_each > 0
ORDER BY r2.received_date