Add customer name column, fix date format, fix Critical Parts type casting

- Add customer_name via coitem -> cohead -> custinfo join (blank for stock builds)
- Format wo_duedate as YYYY-MM-DD using to_char()
- Fix 'unknown to text' error in UNION by casting MTS/MTO literals to ::text

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-03 13:36:52 -04:00
parent ac93d07e68
commit c3d0cb8ff6
5 changed files with 44 additions and 10 deletions

View File

@@ -17,7 +17,7 @@ WITH fa_wos AS (
), ),
mts_shorts AS ( mts_shorts AS (
SELECT fw.wo_id AS top_wo_id, SELECT fw.wo_id AS top_wo_id,
mi.item_number, mi.item_descrip1, 'MTS' AS shortage_type, mi.item_number, mi.item_descrip1, 'MTS'::text AS shortage_type,
(wm.womatl_qtyreq - wm.womatl_qtyiss) AS qty_needed, (wm.womatl_qtyreq - wm.womatl_qtyiss) AS qty_needed,
qtynetable(mis.itemsite_id, true) AS qty_onhand qtynetable(mis.itemsite_id, true) AS qty_onhand
FROM fa_wos fw FROM fa_wos fw
@@ -32,7 +32,7 @@ mts_shorts AS (
), ),
mto_shorts AS ( mto_shorts AS (
SELECT fw.wo_id AS top_wo_id, SELECT fw.wo_id AS top_wo_id,
mi.item_number, mi.item_descrip1, 'MTO' AS shortage_type, mi.item_number, mi.item_descrip1, 'MTO'::text AS shortage_type,
(sub_wo.wo_qtyord - sub_wo.wo_qtyrcv) AS qty_needed, (sub_wo.wo_qtyord - sub_wo.wo_qtyrcv) AS qty_needed,
NULL::numeric AS qty_onhand NULL::numeric AS qty_onhand
FROM fa_wos fw FROM fa_wos fw

View File

@@ -5,7 +5,7 @@
"pluginType": "DB", "pluginType": "DB",
"unpublishedAction": { "unpublishedAction": {
"actionConfiguration": { "actionConfiguration": {
"body": "WITH fa_wos AS (\n SELECT w.wo_id, w.wo_duedate\n FROM wo w\n JOIN itemsite isite ON w.wo_itemsite_id = isite.itemsite_id\n JOIN item i ON isite.itemsite_item_id = i.item_id\n WHERE w.wo_status IN ('R','E','I')\n AND w.wo_ordtype != 'W'\n AND EXISTS (\n SELECT 1 FROM mpe.itematmdept\n WHERE itematmdept_item_id = i.item_id\n AND 'FA' = ANY(itematmdept_departments)\n )\n AND i.item_id NOT IN (\n SELECT itemgrpitem_item_id FROM itemgrpitem WHERE itemgrpitem_itemgrp_id = 97\n )\n AND w.wo_duedate <= (date_trunc('week', CURRENT_DATE) + interval '11 days')\n),\nmts_shorts AS (\n SELECT fw.wo_id AS top_wo_id,\n mi.item_number, mi.item_descrip1, 'MTS' AS shortage_type,\n (wm.womatl_qtyreq - wm.womatl_qtyiss) AS qty_needed,\n qtynetable(mis.itemsite_id, true) AS qty_onhand\n FROM fa_wos fw\n JOIN mpe.wogrpext wwg ON fw.wo_id = wwg.wogrpext_wo_id\n JOIN mpe.wogrpext rwg ON wwg.wogrpext_root_wo_id = rwg.wogrpext_root_wo_id\n JOIN wo sub_wo ON rwg.wogrpext_wo_id = sub_wo.wo_id\n JOIN womatl wm ON sub_wo.wo_id = wm.womatl_wo_id\n JOIN itemsite mis ON wm.womatl_itemsite_id = mis.itemsite_id\n JOIN item mi ON mis.itemsite_item_id = mi.item_id\n WHERE sub_wo.wo_status IN ('R','I')\n AND wm.womatl_picklist AND wm.womatl_qtyreq > wm.womatl_qtyiss\n),\nmto_shorts AS (\n SELECT fw.wo_id AS top_wo_id,\n mi.item_number, mi.item_descrip1, 'MTO' AS shortage_type,\n (sub_wo.wo_qtyord - sub_wo.wo_qtyrcv) AS qty_needed,\n NULL::numeric AS qty_onhand\n FROM fa_wos fw\n JOIN mpe.wogrpext wwg ON fw.wo_id = wwg.wogrpext_wo_id\n JOIN mpe.wogrpext rwg ON wwg.wogrpext_root_wo_id = rwg.wogrpext_root_wo_id\n JOIN wo sub_wo ON rwg.wogrpext_wo_id = sub_wo.wo_id\n JOIN itemsite mis ON sub_wo.wo_itemsite_id = mis.itemsite_id\n JOIN item mi ON mis.itemsite_item_id = mi.item_id\n WHERE sub_wo.wo_qtyord > sub_wo.wo_qtyrcv\n AND sub_wo.wo_status IN ('R','I')\n AND mi.item_id IN (\n SELECT DISTINCT itemgrpitem_item_id FROM itemgrpitem\n JOIN itemgrp ON itemgrpitem_itemgrp_id = itemgrp_id\n WHERE itemgrp_name IN ('MAGNETIC-TRANSFORMER','MAGNETIC-PLUMBING','SUB-ASSEMBLY','PCB GROUP-WORK','INPUT-BD')\n )\n),\nall_shorts AS (\n SELECT * FROM mts_shorts\n UNION ALL\n SELECT * FROM mto_shorts\n)\nSELECT item_number AS part_number,\n item_descrip1 AS part_description,\n shortage_type,\n COUNT(DISTINCT top_wo_id) AS wos_blocked,\n SUM(qty_needed) AS total_qty_needed,\n MAX(qty_onhand) AS qty_available\nFROM all_shorts\nGROUP BY item_number, item_descrip1, shortage_type\nORDER BY wos_blocked DESC, total_qty_needed DESC;", "body": "WITH fa_wos AS (\n SELECT w.wo_id, w.wo_duedate\n FROM wo w\n JOIN itemsite isite ON w.wo_itemsite_id = isite.itemsite_id\n JOIN item i ON isite.itemsite_item_id = i.item_id\n WHERE w.wo_status IN ('R','E','I')\n AND w.wo_ordtype != 'W'\n AND EXISTS (\n SELECT 1 FROM mpe.itematmdept\n WHERE itematmdept_item_id = i.item_id\n AND 'FA' = ANY(itematmdept_departments)\n )\n AND i.item_id NOT IN (\n SELECT itemgrpitem_item_id FROM itemgrpitem WHERE itemgrpitem_itemgrp_id = 97\n )\n AND w.wo_duedate <= (date_trunc('week', CURRENT_DATE) + interval '11 days')\n),\nmts_shorts AS (\n SELECT fw.wo_id AS top_wo_id,\n mi.item_number, mi.item_descrip1, 'MTS'::text AS shortage_type,\n (wm.womatl_qtyreq - wm.womatl_qtyiss) AS qty_needed,\n qtynetable(mis.itemsite_id, true) AS qty_onhand\n FROM fa_wos fw\n JOIN mpe.wogrpext wwg ON fw.wo_id = wwg.wogrpext_wo_id\n JOIN mpe.wogrpext rwg ON wwg.wogrpext_root_wo_id = rwg.wogrpext_root_wo_id\n JOIN wo sub_wo ON rwg.wogrpext_wo_id = sub_wo.wo_id\n JOIN womatl wm ON sub_wo.wo_id = wm.womatl_wo_id\n JOIN itemsite mis ON wm.womatl_itemsite_id = mis.itemsite_id\n JOIN item mi ON mis.itemsite_item_id = mi.item_id\n WHERE sub_wo.wo_status IN ('R','I')\n AND wm.womatl_picklist AND wm.womatl_qtyreq > wm.womatl_qtyiss\n),\nmto_shorts AS (\n SELECT fw.wo_id AS top_wo_id,\n mi.item_number, mi.item_descrip1, 'MTO'::text AS shortage_type,\n (sub_wo.wo_qtyord - sub_wo.wo_qtyrcv) AS qty_needed,\n NULL::numeric AS qty_onhand\n FROM fa_wos fw\n JOIN mpe.wogrpext wwg ON fw.wo_id = wwg.wogrpext_wo_id\n JOIN mpe.wogrpext rwg ON wwg.wogrpext_root_wo_id = rwg.wogrpext_root_wo_id\n JOIN wo sub_wo ON rwg.wogrpext_wo_id = sub_wo.wo_id\n JOIN itemsite mis ON sub_wo.wo_itemsite_id = mis.itemsite_id\n JOIN item mi ON mis.itemsite_item_id = mi.item_id\n WHERE sub_wo.wo_qtyord > sub_wo.wo_qtyrcv\n AND sub_wo.wo_status IN ('R','I')\n AND mi.item_id IN (\n SELECT DISTINCT itemgrpitem_item_id FROM itemgrpitem\n JOIN itemgrp ON itemgrpitem_itemgrp_id = itemgrp_id\n WHERE itemgrp_name IN ('MAGNETIC-TRANSFORMER','MAGNETIC-PLUMBING','SUB-ASSEMBLY','PCB GROUP-WORK','INPUT-BD')\n )\n),\nall_shorts AS (\n SELECT * FROM mts_shorts\n UNION ALL\n SELECT * FROM mto_shorts\n)\nSELECT item_number AS part_number,\n item_descrip1 AS part_description,\n shortage_type,\n COUNT(DISTINCT top_wo_id) AS wos_blocked,\n SUM(qty_needed) AS total_qty_needed,\n MAX(qty_onhand) AS qty_available\nFROM all_shorts\nGROUP BY item_number, item_descrip1, shortage_type\nORDER BY wos_blocked DESC, total_qty_needed DESC;",
"encodeParamsToggle": true, "encodeParamsToggle": true,
"paginationType": "NONE", "paginationType": "NONE",
"pluginSpecifiedTemplates": [ "pluginSpecifiedTemplates": [

File diff suppressed because one or more lines are too long

View File

@@ -1,9 +1,13 @@
WITH fa_wos AS ( WITH fa_wos AS (
SELECT w.wo_id, w.wo_number, w.wo_subnumber, w.wo_status, w.wo_duedate, SELECT w.wo_id, w.wo_number, w.wo_subnumber, w.wo_status, w.wo_duedate,
w.wo_qtyord, i.item_number AS wo_item, i.item_descrip1 AS wo_descrip w.wo_qtyord, i.item_number AS wo_item, i.item_descrip1 AS wo_descrip,
COALESCE(cust.cust_name, '') AS customer_name
FROM wo w FROM wo w
JOIN itemsite isite ON w.wo_itemsite_id = isite.itemsite_id JOIN itemsite isite ON w.wo_itemsite_id = isite.itemsite_id
JOIN item i ON isite.itemsite_item_id = i.item_id JOIN item i ON isite.itemsite_item_id = i.item_id
LEFT JOIN coitem ci ON w.wo_ordtype = 'S' AND w.wo_ordid = ci.coitem_id
LEFT JOIN cohead ch ON ci.coitem_cohead_id = ch.cohead_id
LEFT JOIN custinfo cust ON ch.cohead_cust_id = cust.cust_id
WHERE w.wo_status IN ('R','E','I') WHERE w.wo_status IN ('R','E','I')
AND w.wo_ordtype != 'W' AND w.wo_ordtype != 'W'
AND EXISTS ( AND EXISTS (
@@ -36,10 +40,11 @@ SELECT
END AS due_group_sort, END AS due_group_sort,
fw.wo_number || '-' || fw.wo_subnumber AS wo_num, fw.wo_number || '-' || fw.wo_subnumber AS wo_num,
fw.wo_status AS wo_status, fw.wo_status AS wo_status,
fw.wo_duedate, to_char(fw.wo_duedate, 'YYYY-MM-DD') AS wo_duedate,
fw.customer_name,
fw.wo_item, fw.wo_item,
fw.wo_descrip, fw.wo_descrip,
'MTS' AS shortage_type, 'MTS'::text AS shortage_type,
formatwonumber(sub_wo.wo_id) AS sub_wo_num, formatwonumber(sub_wo.wo_id) AS sub_wo_num,
mi.item_number AS short_part, mi.item_number AS short_part,
mi.item_descrip1 AS short_part_desc, mi.item_descrip1 AS short_part_desc,
@@ -79,10 +84,11 @@ SELECT
END AS due_group_sort, END AS due_group_sort,
fw.wo_number || '-' || fw.wo_subnumber AS wo_num, fw.wo_number || '-' || fw.wo_subnumber AS wo_num,
fw.wo_status AS wo_status, fw.wo_status AS wo_status,
fw.wo_duedate, to_char(fw.wo_duedate, 'YYYY-MM-DD') AS wo_duedate,
fw.customer_name,
fw.wo_item, fw.wo_item,
fw.wo_descrip, fw.wo_descrip,
'MTO' AS shortage_type, 'MTO'::text AS shortage_type,
formatwonumber(sub_wo.wo_id) AS sub_wo_num, formatwonumber(sub_wo.wo_id) AS sub_wo_num,
mi.item_number AS short_part, mi.item_number AS short_part,
mi.item_descrip1 AS short_part_desc, mi.item_descrip1 AS short_part_desc,

View File

@@ -35,6 +35,7 @@
"wo_num", "wo_num",
"wo_status", "wo_status",
"wo_duedate", "wo_duedate",
"customer_name",
"wo_item", "wo_item",
"wo_descrip", "wo_descrip",
"shortage_type", "shortage_type",
@@ -50,6 +51,7 @@
"wo_num": 100, "wo_num": 100,
"wo_status": 70, "wo_status": 70,
"wo_duedate": 100, "wo_duedate": 100,
"customer_name": 200,
"wo_item": 80, "wo_item": 80,
"shortage_type": 65, "shortage_type": 65,
"sub_wo_num": 110, "sub_wo_num": 110,
@@ -71,6 +73,7 @@
{"key": "primaryColumns.wo_num.computedValue"}, {"key": "primaryColumns.wo_num.computedValue"},
{"key": "primaryColumns.wo_status.computedValue"}, {"key": "primaryColumns.wo_status.computedValue"},
{"key": "primaryColumns.wo_duedate.computedValue"}, {"key": "primaryColumns.wo_duedate.computedValue"},
{"key": "primaryColumns.customer_name.computedValue"},
{"key": "primaryColumns.wo_item.computedValue"}, {"key": "primaryColumns.wo_item.computedValue"},
{"key": "primaryColumns.wo_descrip.computedValue"}, {"key": "primaryColumns.wo_descrip.computedValue"},
{"key": "primaryColumns.shortage_type.computedValue"}, {"key": "primaryColumns.shortage_type.computedValue"},
@@ -183,7 +186,7 @@
"alias": "wo_duedate", "alias": "wo_duedate",
"allowCellWrapping": false, "allowCellWrapping": false,
"allowSameOptionsInNewRow": true, "allowSameOptionsInNewRow": true,
"columnType": "date", "columnType": "text",
"computedValue": "{{(() => { const tableData = ws1tblshort.processedTableData || []; return tableData.length > 0 ? tableData.map((currentRow, currentIndex) => (currentRow[\"wo_duedate\"])) : wo_duedate })()}}", "computedValue": "{{(() => { const tableData = ws1tblshort.processedTableData || []; return tableData.length > 0 ? tableData.map((currentRow, currentIndex) => (currentRow[\"wo_duedate\"])) : wo_duedate })()}}",
"enableFilter": true, "enableFilter": true,
"enableSort": true, "enableSort": true,
@@ -204,6 +207,31 @@
"verticalAlignment": "CENTER", "verticalAlignment": "CENTER",
"width": 150 "width": 150
}, },
"customer_name": {
"alias": "customer_name",
"allowCellWrapping": false,
"allowSameOptionsInNewRow": true,
"columnType": "text",
"computedValue": "{{(() => { const tableData = ws1tblshort.processedTableData || []; return tableData.length > 0 ? tableData.map((currentRow, currentIndex) => (currentRow[\"customer_name\"])) : customer_name })()}}",
"enableFilter": true,
"enableSort": true,
"horizontalAlignment": "LEFT",
"id": "customer_name",
"index": 4,
"isCellEditable": false,
"isCellVisible": true,
"isDerived": false,
"isDisabled": false,
"isEditable": false,
"isVisible": true,
"label": "customer_name",
"originalId": "customer_name",
"sticky": "",
"textSize": "0.775rem",
"validation": {},
"verticalAlignment": "CENTER",
"width": 150
},
"wo_item": { "wo_item": {
"alias": "wo_item", "alias": "wo_item",
"allowCellWrapping": false, "allowCellWrapping": false,