sync: auto-sync from HOWARD-HOME at 2026-06-26 16:34:14

Author: Howard Enos
Machine: HOWARD-HOME
Timestamp: 2026-06-26 16:34:14
This commit is contained in:
2026-06-26 16:34:46 -07:00
parent 6f7c8443f9
commit ab0f0e0cb0
2 changed files with 39 additions and 0 deletions

39
.hours_calc.sh Normal file
View File

@@ -0,0 +1,39 @@
#!/usr/bin/env bash
BASE="https://computerguru.syncromsp.com/api/v1"
API_KEY="Tde5174a6e9e312d14-02fd5bfe0f0ee40c87d027507c680e18"
gj() { # resilient GET that retries until JSON parses (handles 429)
local url="$1" tries=0 R
while [ $tries -lt 8 ]; do
R=$(curl -s "$url" </dev/null | tr -d '\000-\037')
if echo "$R" | jq -e . >/dev/null 2>&1; then printf '%s' "$R"; return 0; fi
tries=$((tries+1)); sleep 3
done
return 1
}
IDS=()
for page in 1 2 3 4 5 6; do
P=$(gj "${BASE}/invoices?per_page=100&page=${page}&api_key=${API_KEY}")
while read -r x; do [ -n "$x" ] && IDS+=("$x"); done < <(echo "$P" | jq -r --arg s "2026-06-01" --arg e "2026-06-12" '.invoices[] | select(.date>=$s and .date<=$e) | .id')
sleep 1
done
echo "in-range invoices: ${#IDS[@]}"
: > ./.lab.txt; OK=0; FAIL=0
for id in "${IDS[@]}"; do
if R=$(gj "${BASE}/invoices/${id}?api_key=${API_KEY}"); then
OK=$((OK+1))
echo "$R" | jq -r '.invoice as $i | $i.line_items[]? | select(.item|test("labor";"i")) | "\($i.date)\t\(.quantity)\t\(.user_id)\t\(.item)\t#\($i.number)"' >> ./.lab.txt
else
FAIL=$((FAIL+1)); echo "FAILED id=$id"
fi
sleep 1
done
echo "fetched OK=$OK failed=$FAIL"
echo "=== labor hours in window by tech ==="
awk -F'\t' '{h[$3]+=$2;n[$3]++} END{for(k in h) printf " user_id %-6s : %7.2f h (%d lines)\n",k,h[k],n[k]}' ./.lab.txt
echo "=== HOWARD (1750) lines 06-01..06-12 ==="
awk -F'\t' '$3=="1750"' ./.lab.txt | sort
echo "-----"
awk -F'\t' '$3=="1750"{s+=$2;n++} END{printf "HOWARD billed hours 2026-06-01..2026-06-12: %.2f h (%d lines)\n",s,n}' ./.lab.txt
echo "=== Howard by labor type ==="
awk -F'\t' '$3=="1750"{h[$4]+=$2} END{for(k in h) printf " %-42s %.2f h\n",k,h[k]}' ./.lab.txt
echo "DONE"

0
.lab.txt Normal file
View File