Jelajahi Sumber

Merge branch 'master' of 192.168.0.20:/home/pi/git/grocery_transactions

Daniel Sheffield 3 tahun lalu
induk
melakukan
6f691886f6
1 mengubah file dengan 22 tambahan dan 22 penghapusan
  1. 22 22
      grocery_transactions.sh

+ 22 - 22
grocery_transactions.sh

@@ -9,6 +9,27 @@ set -euo pipefail
 ENDKW=ROLLBACK
 DATE="$(date +%Y-%m-%d)"
 STORE=" IS NOT NULL"
+usage(){
+    cat <<EOF
+Usage: ./${0##*/} [ -d DATE ] [ -s STORE ] [ -r | -c ] < transactions.txn
+ 
+Companion script for grocery_transactions.py
+
+Reads transactions from stdin.
+ROLLBACK (-r) is enabled by default
+Date is optional and by default is set to current day.
+Date and store only affect the display of the transactions.
+If store is not set, then all stores are shown for that day.
+
+Example:
+    # load generated transactions with ROLLBACK
+    ./${0##*/} -d DATE -s STORE < transactions.txn
+    ./${0##*/} -d DATE -s STORE -r < transactions.txn
+    
+    # load generated transactions with COMMIT
+    ./${0##*/} -d DATE -s STORE -c < transactions.txn
+EOF
+}
 while getopts ":crd:s:" options; do
   case "${options}" in         
     c)                          
@@ -31,27 +52,6 @@ while getopts ":crd:s:" options; do
   esac
 done
 
-usage(){
-    cat <<EOF
-Usage: ./${0##*/} [ -d DATE ] [ -s STORE ] [ -r | -c ] < transactions.txn
- 
-Companion script for grocery_transactions.py
-
-Reads transactions from stdin.
-ROLLBACK (-r) is enabled by default
-Date is optional and by default is set to current day.
-Date and store only affect the display of the transactions.
-If store is not set, then all stores are shown for that day.
-
-Example:
-    # load generated transactions with ROLLBACK
-    ./${0##*/} -d DATE -s STORE < transactions.txn
-    ./${0##*/} -d DATE -s STORE -r < transactions.txn
-    
-    # load generated transactions with COMMIT
-    ./${0##*/} -d DATE -s STORE -c < transactions.txn
-EOF
-}
 if [[ -t 0 ]]
 then
     usage 1>&2
@@ -62,7 +62,7 @@ BEGIN;
 $(cat - )
 SELECT
   date_part('day',ts)||'/'||date_part('month',ts)||' '||date_part('hour',ts)::int%12 AS ts,
-  substr(store,1,4) AS shop,
+  code AS shop,
   substr(description,1,32) AS description,
   quantity AS volume,
   substr(unit,1,4) AS unit,