/ Cases / Restaurants / Finance

End-to-end cash register and cash control

Chain of custody for cash from the register to the vault: closeouts matched against the point of sale, expenses with photos, signed handoffs and a chained ledger that exposes any tampering.

/ Restaurantes Atitlán/ 2026/ Android tablet app · posts itself to Zoho

≈32

server functions

4

links in the chain of custody

/ The problem

Cash passed through several hands between the register, the pickup route, finance and the vault. When something didn't add up, there was no way to know where it went missing.

/ What we built

  • Shift closeouts matched against what the point of sale says.
  • Cash counts, expenses with a photo of the receipt and a dollar ledger.
  • Handoffs with a numbered slip and a signature every time cash changes hands.
  • A chained ledger: altering an old record breaks the chain and shows up.
  • Everything posts to the books on its own.

/ How it works

  1. 01Register closeout
  2. 02Signed handoff to the route
  3. 03Received by finance
  4. 04Vault
  5. 05Accounting entry

/ By the numbers

Balanced shift closings per week

■ Real production data · counts per week, no amounts or personal data · Current week excluded.

/ Real code

supabase/migrations/20260725034206_control_efectivo_fase01.sqlsql
-- 9.3 Hash encadenado POR CUSTODIO.
-- Por custodio y no global porque con la cola sin señal los movimientos de
-- distintas personas llegan desordenados; dentro de una billetera el orden
-- de inserción sí es único. El lock por custodio evita que dos inserts
-- concurrentes lean el mismo hash previo y bifurquen la cadena.
create or replace function private.cash_encadenar()
returns trigger language plpgsql as $$
declare
  v_prev text;
begin
  perform pg_advisory_xact_lock(hashtext('cash_mov_' || new.custodio_id::text));
  select m.hash into v_prev
    from public.cash_movimientos m
   where m.custodio_id = new.custodio_id
   order by m.seq desc
   limit 1;
  new.hash_prev := v_prev;
  new.hash := encode(sha256(convert_to(
      coalesce(v_prev, '')                                        || '|' ||
      new.custodio_id::text                                       || '|' ||
      to_char(new.monto, 'FM99999999990.00')                      || '|' ||
      new.tipo                                                    || '|' ||
      -- …
      new.idempotency_key::text
    , 'UTF8')), 'hex');
  return new;
end $$;

■ Every cash movement stores the SHA-256 of the previous one; changing an old row breaks the chain and the daily check flags it.

/ Stack

Cloudflare WorkersPostgresCapacitor AndroidImpresión EpsonZoho Books