| Server IP : 216.92.14.13 / Your IP : 216.73.217.126 Web Server : Apache System : Linux vps4089.pairvps.com 5.15.0-190-generic #200-Ubuntu SMP Fri Aug 7 15:06:04 UTC 2026 x86_64 User : rmlac2fmr ( 1040637) PHP Version : 8.2.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/home/rmlac2fmr/ |
Upload File : |
#!/usr/bin/env python3
"""
Switch ACF (S3) per-diem delivery method from "Through Payroll" to
"On Timecard", in one shot, across every place the value can live:
1. Saved per-diem records db.perDiems[].delivery
2. Per-person overrides db.travelRequests[].bookingDetails.pdDelivery
3. The show's default setting db.shows[S3].pdConfig.delivery
Only entries currently set to "Through Payroll" are changed. Anyone on a
different method (Cash, Check, Separate Check, etc.) is left untouched.
Safety:
- Writes a timestamped backup of db.json before changing anything.
- Matches "Through Payroll" case/space-insensitively; writes exactly
"On Timecard" (the value the dropdown/filter expects).
- Idempotent: safe to run more than once.
- Prints a full report of every record changed.
After running: restart the app, then hard-refresh all open tabs.
Run: python3 ~/switch_acf_perdiem_delivery.py
"""
import json, os, shutil, datetime
DB_PATH = os.path.expanduser("~/public_html/jn.com/ops/data/db.json")
SHOW = "S3" # ACF
FROM = "through payroll" # normalized match
TO = "On Timecard" # exact value written
def norm(v):
return str(v).strip().lower() if v is not None else ""
# --- backup first ---
stamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
backup = f"{DB_PATH}.bak.{stamp}"
shutil.copy2(DB_PATH, backup)
print(f"Backup written: {backup}\n")
with open(DB_PATH, "r", encoding="utf-8") as f:
db = json.load(f)
# Name lookup helpers for the report
persons = {p.get("id"): p for p in db.get("persons", [])}
reqs_by_id = {r.get("id"): r for r in db.get("travelRequests", [])}
def name_for_req(reqId):
r = reqs_by_id.get(reqId) or {}
p = persons.get(r.get("personId")) or {}
nm = f"{(p.get('firstName') or '').strip()} {(p.get('lastName') or '').strip()}".strip()
return nm or reqId or "(unknown)"
changed_pd, changed_bd = [], []
changed_default = False
# 1. Saved per-diem records
for pd in db.get("perDiems", []):
if pd.get("showId") == SHOW and norm(pd.get("delivery")) == FROM:
pd["delivery"] = TO
changed_pd.append((name_for_req(pd.get("reqId")), pd.get("id")))
# 2. Per-person overrides on the travel request
for r in db.get("travelRequests", []):
if r.get("showId") != SHOW:
continue
bd = r.get("bookingDetails")
if isinstance(bd, dict) and norm(bd.get("pdDelivery")) == FROM:
bd["pdDelivery"] = TO
p = persons.get(r.get("personId")) or {}
nm = f"{(p.get('firstName') or '').strip()} {(p.get('lastName') or '').strip()}".strip() or r.get("id")
changed_bd.append((nm, r.get("id")))
# 3. Show default
for s in db.get("shows", []):
if s.get("id") == SHOW:
cfg = s.get("pdConfig")
if isinstance(cfg, dict) and norm(cfg.get("delivery")) == FROM:
cfg["delivery"] = TO
changed_default = True
break
with open(DB_PATH, "w", encoding="utf-8") as f:
json.dump(db, f, indent=2)
# --- report ---
print("=== ACF (S3) per-diem delivery: Through Payroll -> On Timecard ===\n")
print(f"Saved per-diem records changed: {len(changed_pd)}")
for nm, pid in changed_pd:
print(f" {nm} (perDiem {pid})")
print()
print(f"Per-person overrides changed: {len(changed_bd)}")
for nm, rid in changed_bd:
print(f" {nm} (request {rid})")
print()
print(f"Show default changed: {'yes -> On Timecard' if changed_default else 'no (was not Through Payroll)'}")
total = len(changed_pd) + len(changed_bd) + (1 if changed_default else 0)
print(f"\nTotal changes: {total}")
if total == 0:
print("Nothing was set to 'Through Payroll' for ACF — no changes needed.")
print("\nDone. Restart the app, then hard-refresh all open tabs.")