From e2f3ccd324578bfbc43d2ddc32d5943d139b9ac5 Mon Sep 17 00:00:00 2001 From: mattmcw Date: Thu, 28 Nov 2024 13:54:42 -0500 Subject: [PATCH] BOM script now generates table that links to minimums --- README.md | 35 ++++++++++++++++++----------------- scripts/bom.sh | 14 ++++++++++---- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 28189d1..5c43b50 100644 --- a/README.md +++ b/README.md @@ -39,23 +39,24 @@ Actual price of a full build may be higher. -| Part | Qty | Cost (USD) | -|-------------------------------------|-----|------------| -| M4 hex bolt 40mm | 4 | $2.40 | -| M3 sliding t slot nut | 25 | $1.25 | -| M3 hex cap bolt 8mm | 25 | $2.00 | -| M3 hex cap bolt 6mm | 8 | $0.56 | -| M3 hex cap bolt 12mm | 1 | $0.08 | -| L298N Motor driver module | 1 | $2.87 | -| ESP32 GPIO breakout board | 1 | $5.99 | -| ESP32 Dev board | 1 | $6.66 | -| 608-RS Ball Bearing | 1 | $0.17 | -| 250RPM DC geared motor | 2 | $29.98 | -| 2020 Aluminum extrusion 420mm | 2 | $5.10 | -| 2020 Aluminum extrusion 260mm | 4 | $6.40 | -| 100RPM DC geared motor with encoder | 1 | $16.19 | -|---------|---------------|--------------------------------------------------| -| TOTAL | 76 | $79.65 | +| Part | Qty | Cost (USD) | Minumum | +|-------------------------------------|-----|------------|-------------------------------------------| +| M4 hex bolt 40mm | 4 | $2.40 | [10 for $6.09](https://amzn.to/4ikpYL8) | +| M3 sliding t slot nut | 25 | $1.25 | [105 for $5.99](https://amzn.to/48GRrSU) | +| M3 hex cap bolt 8mm | 25 | $2.00 | [100 for $8.99](https://amzn.to/3YEvWNB) | +| M3 hex cap bolt 6mm | 8 | $0.56 | [100 for $7.26](https://amzn.to/3AwiZxo) | +| M3 hex cap bolt 12mm | 1 | $0.08 | [100 for $8.36](https://amzn.to/48CGa5Y) | +| L298N Motor driver module | 1 | $2.87 | [4 for $11.49](https://amzn.to/4ellssy) | +| ESP32 GPIO breakout board | 1 | $5.99 | [2 for $11.99](https://amzn.to/3UFjpbO) | +| ESP32 Dev board | 1 | $6.66 | [3 for $19.99](https://amzn.to/3NXCvGj) | +| 608-RS Ball Bearing | 1 | $0.17 | [100 for $17.79](https://amzn.to/4fKxDA7) | +| 250RPM DC geared motor | 2 | $29.98 | [1 for $14.99](https://amzn.to/3NWkcRL) | +| 2020 Aluminum extrusion 420mm | 2 | $5.10 | [29 for $73.99](https://amzn.to/418OicC) | +| 2020 Aluminum extrusion 260mm | 4 | $6.40 | [46 for $73.99](https://amzn.to/418OicC) | +| 100RPM DC geared motor with encoder | 1 | $16.19 | [1 for $16.19](https://amzn.to/3UF707G) | +|---------|-----|--------|---------| +| TOTAL | 76 | $79.65 | $277.11 | + diff --git a/scripts/bom.sh b/scripts/bom.sh index d3fa236..51cd605 100644 --- a/scripts/bom.sh +++ b/scripts/bom.sh @@ -54,11 +54,17 @@ echo "quantity,part,part_id,price" > "${TOTAL}" sqlite3 :memory: -cmd '.mode csv' -cmd ".import ${DESTINATION} bom" -cmd ".import ${PRICES} prices"\ 'SELECT SUM(quantity),part,part_id, SUM(quantity) * (COALESCE((SELECT CEIL(prices.price / prices.quantity) 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" -cmd '.mode markdown' \ - "SELECT part as Part, quantity as Qty, printf('$%.2f', CAST(price AS FLOAT) / 100) as 'Cost (USD)' FROM bom ORDER BY part DESC;" +sqlite3 :memory: -cmd '.mode csv' -cmd ".import ${TOTAL} bom" -cmd ".import ${PRICES} prices" -cmd '.mode markdown' \ + "SELECT part as Part, quantity as Qty, \ + printf('$%.2f', CAST(price AS FLOAT) / 100) as 'Cost (USD)', \ + printf( '[%s for $%.2f](%s)', (SELECT prices.quantity FROM prices WHERE prices.part = bom.part), (SELECT CAST(prices.price AS FLOAT) / 100 FROM prices WHERE prices.part = bom.part), (SELECT prices.url FROM prices WHERE prices.part = bom.part)) as 'Minumum' \ + FROM bom ORDER BY part DESC;" -sqlite3 :memory: -cmd '.mode csv' -cmd ".import ${TOTAL} bom" -cmd '.mode markdown' \ - "SELECT 'TOTAL', SUM(quantity), printf('$%.2f', CAST(SUM(price) AS FLOAT) / 100) FROM bom;" | grep -v 'SUM(' +sqlite3 :memory: -cmd '.mode csv' -cmd ".import ${TOTAL} bom" -cmd ".import ${PRICES} prices" -cmd '.mode markdown' \ + "SELECT 'TOTAL', SUM(quantity) AS qty, \ + printf('$%.2f', CAST(SUM(price) AS FLOAT) / 100) as total, \ + printf('$%.2f', ( SELECT CAST( SUM(price) AS FLOAT) / 100 FROM prices WHERE prices.part IN ( SELECT bom.part FROM bom ) ) ) as min \ + FROM bom;" | grep -v 'qty' sqlite3 :memory: -cmd '.mode csv' -cmd ".import ${TOTAL} bom"\ "SELECT SUM(quantity), 'TOTAL', 'N/A', SUM(price) FROM bom;" | tr -d '"' >> "${TOTAL}"