unslopkit

Components / Code blocks

Terminal mid-run

A dark terminal caught mid-command: a progress bar, a result per item with warnings and failures marked, and a spinner on the step still going.

halden sync~/crews/reyes
$ halden sync --since monday
Syncing 38 job sheets for Reyes Framing
31/38
✓JS-2207Alder St refit22.5 h
✓JS-2211Garage roof, Pier Ln14.0 h
!JS-2214Bathroom, Mill Lnno sign-off
✗JS-2216Back deck rebuildupload failed
 Uploading receipts, 4 of 9
Drawn in your kit, Plain.Change the look

The code

Plain HTML and CSS on your kit's variables. Put it next to tokens/variables.css from your kit's files and it draws in your look.

<div class="ukc-code-terminal-run">
<div class="tw">
  <div class="tt"><span class="nm"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 7l5 5-5 5M12 18h7"/></svg>halden sync</span><span class="cwd">~/crews/reyes</span></div>
  <pre class="body"><samp><span class="l"><span class="pr">$</span> <kbd>halden sync --since monday</kbd></span>
<span class="l"><span class="dim">Syncing 38 job sheets for Reyes Framing</span></span>
<span class="l"><span class="meter"><span class="track" role="progressbar" aria-label="Job sheets synced" aria-valuemin="0" aria-valuemax="38" aria-valuenow="31"><span class="fill"></span></span><span>31/38</span></span></span>
<span class="l"><span class="row"><span class="mk">✓</span><span>JS-2207</span><span class="nm">Alder St refit</span><span class="rt">22.5 h</span></span></span>
<span class="l"><span class="row"><span class="mk">✓</span><span>JS-2211</span><span class="nm">Garage roof, Pier Ln</span><span class="rt">14.0 h</span></span></span>
<span class="l"><span class="row warn"><span class="mk">!</span><span>JS-2214</span><span class="nm">Bathroom, Mill Ln</span><span class="rt">no sign-off</span></span></span>
<span class="l"><span class="row fail"><span class="mk">✗</span><span>JS-2216</span><span class="nm">Back deck rebuild</span><span class="rt">upload failed</span></span></span>
<span class="l"><span class="dim"><span class="spin" aria-hidden="true"></span> Uploading receipts, 4 of 9</span></span></samp></pre>
</div>
</div>

More code blocks

All 24
  • src/totals.ts +4−1
    @@ -12,3 +12,5 @@ function lineTotal
     export function lineTotal(l: Line) {
    −  return l.qty * l.rate * (1 + TAX);
    +  const net = round(l.qty * l.rate);
    +  const tax = round(net * l.taxRate);
    +  return { net, tax, total: net + tax };
     }
    @@ -24,2 +26,3 @@
     export const round = (n: number) =>
    +  // To the cent, half away from zero
       Math.round(n * 100) / 100;

    Unified diff

  • .halden.yml+4−3
    Changes to .halden.yml. Version 3.1 on the left, version 3.2 on the right.
    v3.1v3.2
    1invoices:1invoices:
    2 prefix: INV2 prefix: INV
    3− due_days: 143+ due_days: 30
    4 rounding: line4 rounding: line
    5− tax: 0.08255+ tax:
    6+ rate: 0.0825
    7+ labor: false
    6− legacy_pdf: true
    7 reminders: on8 reminders: on

    Side-by-side diff

  • export default {
      crew: "reyes-framing",
      currency: "USD",
      rounding: "line",
      reminders: [7, 14, 30],
      // Sync offline sheets
      sync: { every: "15m" },
    };

    TypeScriptLn 5, Col 25

    File tree and editor

  • POST/v2/invoicesCreate an invoice from a signed-off job sheet.

    Request

    Authorization: Bearer $HALDEN_KEY
    Content-Type: application/json
     
    {
      "job": "JS-2207",
      "due_days": 30,
      "send": true
    }

    Response

    {
      "id": "inv_0418",
      "number": "INV-0418",
      "status": "sent",
      "total": 2140.00,
      "currency": "USD",
      "pdf": "/v2/invoices/inv_0418.pdf"
    }
    {
      "error": "job_not_signed_off",
      "message": "JS-2207 has no sign-off yet",
      "field": "job"
    }

    201 Created · 184 ms422 Unprocessable · 61 ms

    Request and response

  • job-sheet.json1.2 kB
    { 7 keys }
    "id": "JS-2207",
    "site": "14 Alder St",
    "signed_off": true,
    "crew": [ 2 items ],
    "Ines Ortega",
    "Dana Whitfield"
    ],
    "hours": { 3 keys },
    "labor": 22.5,
    "travel": 1.5,
    "overtime": 0
    },
    "materials": [ 2 items ],
    { 3 keys },
    "sku": "OAK-WT-30",
    "qty": 1,
    "unit_cost": 41800
    },
    { 3 keys }
    "sku": "2x6-PT-12",
    "qty": 40,
    "unit_cost": 1145
    }
    ],
    "invoice": null
    }

    Path$.materials[1].qty

    Collapsible JSON

  • Step 3Handle the webhook

    export async function POST(req: Request) {
      const raw = await req.text();
      const event = verify(raw, req.headers); (note 1)
     
      if (event.type === "invoice.paid") { (note 2)
        await markPaid(event.invoice);
      }
      return new Response(null, { status: 204 }); (note 3)
    }
    1. Note 1: verify throws if the signature or timestamp is off, so a forged call never reaches your code.

    2. Note 2: Check the type first. New event types get added, so skip the ones you don't handle.

    3. Note 3: Answer within 10 seconds. Slow or failed deliveries are retried for three days.

    Annotated snippet