BOM script calculates total costs of rows of parts and entire BOM

This commit is contained in:
Matt McWilliams 2024-11-05 20:50:42 -05:00
parent bc71d86ee6
commit e6c65650de
11 changed files with 30 additions and 25 deletions

View File

@ -1,5 +1,5 @@
{
"version": "1.8.144",
"version": "1.8.145",
"ext_port": 1111,
"profiles": {
"mcopy": {

2
app/package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "mcopy-app",
"version": "1.8.144",
"version": "1.8.145",
"lockfileVersion": 2,
"requires": true,
"packages": {

View File

@ -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": {

View File

@ -1,5 +1,5 @@
{
"version": "1.8.144",
"version": "1.8.145",
"ext_port": 1111,
"profiles": {
"mcopy": {

View File

@ -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

1 module c quantity part part_id description
2 front_block 2 M5 hex cap bolt 25mm N/A
3 body 2 M3 hex nut N/A Attach slide_catch to gate
4 body 12 M2.5 hex nut N/A Attach idle_roller and filter_holder and slide_rail to gate

View File

@ -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

1 count quantity part_id part price
2 2 M5 hex nut N/A 0
3 2 M5 hex cap bolt 25mm N/A 0
4 2 M5 hex cap bolt 20mm N/A 0
5 2 M3 hex nut N/A 6
6 13 M2.5 hex nut N/A 0
7 2 M2.5 hex cap bolt 25mm N/A 0
8 6 M2.5 hex cap bolt 15mm N/A 0
9 5 M2.5 hex cap bolt 10mm N/A 0
10 34 N/A TOTALS 6

View File

@ -1 +1,2 @@
part,part_id,price
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/
1 part part_id price url
2 M3 hex nut N/A 3 https://www.amazon.com/ZQZ-M3-0-5mm-Stainless-Hardware-Standard/dp/B0CQJK2R5T/ref=asc_df_B0CQJK2R5T/

4
package-lock.json generated
View File

@ -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",

View File

@ -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": {

View File

@ -1,5 +1,5 @@
{
"version": "1.8.144",
"version": "1.8.145",
"ext_port": 1111,
"profiles": {
"mcopy": {

View File

@ -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}"