From e6c65650ded7c144ebd12c0cc61ec67d9b5caf0d Mon Sep 17 00:00:00 2001 From: mattmcw Date: Tue, 5 Nov 2024 20:50:42 -0500 Subject: [PATCH] BOM script calculates total costs of rows of parts and entire BOM --- app/data/cfg.json | 2 +- app/package-lock.json | 2 +- app/package.json | 2 +- data/cfg.json | 2 +- hardware/bom/mcopy_gate_BOM.csv | 2 +- hardware/bom/mcopy_gate_BOM_total.csv | 19 ++++++++++--------- hardware/parts/prices.csv | 3 ++- package-lock.json | 4 ++-- package.json | 2 +- processing/mcopy/cfg.json | 2 +- scripts/bom.sh | 15 +++++++++------ 11 files changed, 30 insertions(+), 25 deletions(-) diff --git a/app/data/cfg.json b/app/data/cfg.json index c976129..0f75ff4 100644 --- a/app/data/cfg.json +++ b/app/data/cfg.json @@ -1,5 +1,5 @@ { - "version": "1.8.144", + "version": "1.8.145", "ext_port": 1111, "profiles": { "mcopy": { diff --git a/app/package-lock.json b/app/package-lock.json index e1b7447..9410983 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -1,6 +1,6 @@ { "name": "mcopy-app", - "version": "1.8.144", + "version": "1.8.145", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/app/package.json b/app/package.json index 322d0d1..4d25903 100644 --- a/app/package.json +++ b/app/package.json @@ -1,6 +1,6 @@ { "name": "mcopy-app", - "version": "1.8.144", + "version": "1.8.145", "description": "GUI for the mcopy small gauge film optical printer platform", "main": "main.js", "scripts": { diff --git a/data/cfg.json b/data/cfg.json index c976129..0f75ff4 100644 --- a/data/cfg.json +++ b/data/cfg.json @@ -1,5 +1,5 @@ { - "version": "1.8.144", + "version": "1.8.145", "ext_port": 1111, "profiles": { "mcopy": { diff --git a/hardware/bom/mcopy_gate_BOM.csv b/hardware/bom/mcopy_gate_BOM.csv index 87e3a94..39711df 100644 --- a/hardware/bom/mcopy_gate_BOM.csv +++ b/hardware/bom/mcopy_gate_BOM.csv @@ -1,4 +1,4 @@ -module,c,part,part_id,description +module,quantity,part,part_id,description front_block,2,M5 hex cap bolt 25mm,N/A, body,2,M3 hex nut,N/A,Attach slide_catch to gate body,12,M2.5 hex nut,N/A,Attach idle_roller and filter_holder and slide_rail to gate diff --git a/hardware/bom/mcopy_gate_BOM_total.csv b/hardware/bom/mcopy_gate_BOM_total.csv index 8fc7e4b..b2fa9ea 100644 --- a/hardware/bom/mcopy_gate_BOM_total.csv +++ b/hardware/bom/mcopy_gate_BOM_total.csv @@ -1,9 +1,10 @@ -count,part_id,part,price -2,"M5 hex nut",N/A, -2,"M5 hex cap bolt 25mm",N/A, -2,"M5 hex cap bolt 20mm",N/A, -2,"M3 hex nut",N/A, -13,"M2.5 hex nut",N/A, -2,"M2.5 hex cap bolt 25mm",N/A, -6,"M2.5 hex cap bolt 15mm",N/A, -5,"M2.5 hex cap bolt 10mm",N/A, +quantity,part_id,part,price +2,"M5 hex nut",N/A,0 +2,"M5 hex cap bolt 25mm",N/A,0 +2,"M5 hex cap bolt 20mm",N/A,0 +2,"M3 hex nut",N/A,6 +13,"M2.5 hex nut",N/A,0 +2,"M2.5 hex cap bolt 25mm",N/A,0 +6,"M2.5 hex cap bolt 15mm",N/A,0 +5,"M2.5 hex cap bolt 10mm",N/A,0 +34,N/A,TOTALS,6 diff --git a/hardware/parts/prices.csv b/hardware/parts/prices.csv index 2c74151..2502c28 100644 --- a/hardware/parts/prices.csv +++ b/hardware/parts/prices.csv @@ -1 +1,2 @@ -part,part_id,price \ No newline at end of file +part,part_id,price,url +M3 hex nut,N/A,3,https://www.amazon.com/ZQZ-M3-0-5mm-Stainless-Hardware-Standard/dp/B0CQJK2R5T/ref=asc_df_B0CQJK2R5T/ \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index adb62e7..c669e27 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mcopy", - "version": "1.8.144", + "version": "1.8.145", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "mcopy", - "version": "1.8.144", + "version": "1.8.145", "license": "MIT", "dependencies": { "alert": "file:app/lib/alert", diff --git a/package.json b/package.json index 3edb138..70becd7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mcopy", - "version": "1.8.144", + "version": "1.8.145", "description": "Small gauge film optical printer platform", "main": "build.js", "directories": { diff --git a/processing/mcopy/cfg.json b/processing/mcopy/cfg.json index c976129..0f75ff4 100644 --- a/processing/mcopy/cfg.json +++ b/processing/mcopy/cfg.json @@ -1,5 +1,5 @@ { - "version": "1.8.144", + "version": "1.8.145", "ext_port": 1111, "profiles": { "mcopy": { diff --git a/scripts/bom.sh b/scripts/bom.sh index ae3ea21..4d317c8 100644 --- a/scripts/bom.sh +++ b/scripts/bom.sh @@ -32,7 +32,7 @@ TOTAL=$(realpath "${TOTAL}") PRICES=$(realpath "./hardware/parts/prices.csv") MODULE="" -echo "module,c,part,part_id,description" > "${DESTINATION}" +echo "module,quantity,part,part_id,description" > "${DESTINATION}" tac "${1}" | while read line; do module=$(echo "${line}" | grep 'module') @@ -41,15 +41,18 @@ tac "${1}" | while read line; do fi bom=$(echo "${line}" | grep '//' | grep 'BOM' | awk -F'BOM:' '{print $2}'| xargs) if [[ "${bom}" != "" ]]; then - COUNT=$(echo "${bom}" | awk -F',' '{print $1}' | xargs) + QUANTITY=$(echo "${bom}" | awk -F',' '{print $1}' | xargs) PART=$(echo "${bom}" | awk -F',' '{print $2}' | xargs) ID=$(echo "${bom}" | awk -F',' '{print $3}' | xargs) DESCRIPTION=$(echo "${bom}" | awk -F',' '{print $4}' | xargs) - echo "[${MODULE}] ${COUNT}x ${PART} (${ID})" - echo "${MODULE},${COUNT},${PART},${ID},${DESCRIPTION}" >> "${DESTINATION}" + echo "[${MODULE}] ${QUANTITY}x ${PART} (${ID})" + echo "${MODULE},${QUANTITY},${PART},${ID},${DESCRIPTION}" >> "${DESTINATION}" fi done -echo "count,part_id,part,price" > "${TOTAL}" +echo "quantity,part_id,part,price" > "${TOTAL}" sqlite3 :memory: -cmd '.mode csv' -cmd ".import ${DESTINATION} bom" -cmd ".import ${PRICES} prices"\ - 'SELECT SUM(c),part,part_id, SUM(c) * (SELECT prices.price FROM prices WHERE prices.part = bom.part) as price FROM bom GROUP BY part ORDER BY part DESC;' >> "${TOTAL}" + 'SELECT SUM(quantity),part,part_id, SUM(quantity) * (COALESCE((SELECT prices.price FROM prices WHERE prices.part = bom.part LIMIT 1), 0)) as price FROM bom GROUP BY part ORDER BY part DESC;' >> "${TOTAL}" + +sqlite3 :memory: -cmd '.mode csv' -cmd ".import ${TOTAL} bom"\ + 'SELECT SUM(quantity),"N/A","TOTALS", SUM(price) FROM bom;' >> "${TOTAL}" \ No newline at end of file