From ab0f0e0cb0c34af324787008f7088a50c2bc5242 Mon Sep 17 00:00:00 2001 From: Howard Enos Date: Fri, 26 Jun 2026 16:34:46 -0700 Subject: [PATCH] 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 --- .hours_calc.sh | 39 +++++++++++++++++++++++++++++++++++++++ .lab.txt | 0 2 files changed, 39 insertions(+) create mode 100644 .hours_calc.sh create mode 100644 .lab.txt diff --git a/.hours_calc.sh b/.hours_calc.sh new file mode 100644 index 00000000..c57e0c93 --- /dev/null +++ b/.hours_calc.sh @@ -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 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" diff --git a/.lab.txt b/.lab.txt new file mode 100644 index 00000000..e69de29b