lumnik. / scenarios All scenarios · Français

Apprenticeship: an OPCO installment invoiced after the contract was broken

Goal Join every OPCO invoice line to the training centre's contract register, and be told when the invoiced period runs past the contract's rupture, even when the rupture is entered after the invoice.

A business school's apprenticeship training centre (CFA), two CSV exports: 36 apprenticeship contracts, 40 OPCO invoice lines.

contrats.csv
contract_id,apprentice_id,program,opco,start_on,end_on,rupture_on
CTR-26-0001,APP-26-0001,Bachelor 3 alternance,AKTO,2026-09-01,2027-08-31,
CTR-26-0002,APP-26-0002,MSc Supply Chain alternance,OPCO EP,2026-09-01,2027-08-31,
CTR-26-0003,APP-26-0003,PGE M2 alternance,OPCO Commerce,2026-09-01,2027-08-31,
CTR-26-0004,APP-26-0004,Bachelor 3 alternance,Atlas,2026-09-01,2027-08-31,
CTR-26-0005,APP-26-0005,MSc Supply Chain alternance,AKTO,2026-09-01,2027-08-31,
CTR-26-0006,APP-26-0006,PGE M2 alternance,OPCO EP,2026-09-01,2027-08-31,
CTR-26-0007,APP-26-0007,Bachelor 3 alternance,OPCO Commerce,2026-09-01,2027-08-31,
CTR-26-0008,APP-26-0008,MSc Supply Chain alternance,Atlas,2026-09-01,2027-08-31,
CTR-26-0009,APP-26-0009,PGE M2 alternance,AKTO,2026-09-01,2027-08-31,
CTR-26-0010,APP-26-0010,Bachelor 3 alternance,OPCO EP,2026-09-01,2027-08-31,
CTR-26-0011,APP-26-0011,MSc Supply Chain alternance,OPCO Commerce,2026-09-01,2027-08-31,
CTR-26-0012,APP-26-0012,PGE M2 alternance,Atlas,2026-09-01,2027-08-31,
CTR-26-0013,APP-26-0013,Bachelor 3 alternance,AKTO,2026-09-01,2027-08-31,
CTR-26-0014,APP-26-0014,MSc Supply Chain alternance,OPCO EP,2026-09-01,2027-08-31,
CTR-26-0015,APP-26-0015,PGE M2 alternance,OPCO Commerce,2026-09-01,2027-08-31,
CTR-26-0016,APP-26-0016,Bachelor 3 alternance,Atlas,2026-09-01,2027-08-31,
CTR-26-0017,APP-26-0017,MSc Supply Chain alternance,AKTO,2026-09-01,2027-08-31,
CTR-26-0018,APP-26-0018,PGE M2 alternance,OPCO EP,2026-09-01,2027-08-31,
CTR-26-0019,APP-26-0019,Bachelor 3 alternance,OPCO Commerce,2026-09-01,2027-08-31,

… 17 more lines

factures-2026-09.csv
invoice_line,contract_id,opco,installment,period_start,period_end,amount_eur,invoiced_on
F26-09-001,CTR-26-0001,AKTO,1,2026-09-01,2027-03-31,3520.00,2026-09-15
F26-09-002,CTR-26-0002,OPCO EP,1,2026-09-01,2027-03-31,3520.00,2026-09-15
F26-09-003,CTR-26-0003,OPCO Commerce,1,2026-09-01,2027-03-31,3520.00,2026-09-15
F26-09-004,CTR-26-0004,Atlas,1,2026-09-01,2027-03-31,3520.00,2026-09-15
F26-09-005,CTR-26-0005,AKTO,1,2026-09-01,2027-03-31,3520.00,2026-09-15
F26-09-006,CTR-26-0006,OPCO EP,1,2026-09-01,2027-03-31,3520.00,2026-09-15
F26-09-007,CTR-26-0007,OPCO Commerce,1,2026-09-01,2027-03-31,3520.00,2026-09-15
F26-09-008,CTR-26-0008,Atlas,1,2026-09-01,2027-03-31,3520.00,2026-09-15
F26-09-009,CTR-26-0009,AKTO,1,2026-09-01,2027-03-31,3520.00,2026-09-15
F26-09-010,CTR-26-0010,OPCO EP,1,2026-09-01,2027-03-31,3520.00,2026-09-15
F26-09-011,CTR-26-0011,OPCO Commerce,1,2026-09-01,2027-03-31,3520.00,2026-09-15
F26-09-012,CTR-26-0012,Atlas,1,2026-09-01,2027-03-31,3520.00,2026-09-15
F26-09-013,CTR-26-0013,AKTO,1,2026-09-01,2027-03-31,3520.00,2026-09-15
F26-09-014,CTR-26-0014,OPCO EP,1,2026-09-01,2027-03-31,3520.00,2026-09-15
F26-09-015,CTR-26-0015,OPCO Commerce,1,2026-09-01,2027-03-31,3520.00,2026-09-15
F26-09-016,CTR-26-0016,Atlas,1,2026-09-01,2027-03-31,3520.00,2026-09-15
F26-09-017,CTR-26-0017,AKTO,1,2026-09-01,2027-03-31,3520.00,2026-09-15
F26-09-018,CTR-26-0018,OPCO EP,1,2026-09-01,2027-03-31,3520.00,2026-09-15
F26-09-019,CTR-26-0019,OPCO Commerce,1,2026-09-01,2027-03-31,3520.00,2026-09-15

… 17 more lines

manifests/20-invoice-line.yaml
kind: Entityname: cfa_invoice_amatch: [invoice_line]scopes: [cfa-billing-a]sources:  - table: t_scenario_cfa_invoices_a    map: { invoice_line: invoice_line, contract_id: contract_id, opco: opco, installment: installment,           period_start: period_start, period_end: period_end, amount_eur: amount_eur, invoiced_on: invoiced_on }joins:  - table: t_scenario_cfa_contracts_a    # per contract, not per invoice line    from: contract_id    to: contract_id    map: { apprentice_id: apprentice_id, program: program, start_on: start_on, end_on: end_on, rupture_on: rupture_on }
manifests/30-billed-after-rupture.yaml
apiVersion: apps.lumnik.io/v1kind: Processmetadata:  name: scenario-cfa-billed-after-rupture-aspec:  scope: cfa-billing-a  on: { event: data.row.changed, table: connector.v_cfa_invoice_a }  when:    - "period_end>{rupture_on}"        # the invoiced period runs past the contract's rupture  emit:    type: decision.billed-after-rupture-a    message: "{invoice_line}: {amount_eur} EUR invoiced to {opco} for {period_start} to {period_end}; contract {contract_id} ({apprentice_id}) broken on {rupture_on}"    key: invoice_line
factures-2026-11.csv
invoice_line,contract_id,opco,installment,period_start,period_end,amount_eur,invoiced_on
F26-11-001,CTR-26-0027,OPCO Commerce,2,2026-11-13,2027-02-12,2640.00,2026-11-16
F26-11-002,CTR-26-0028,Atlas,2,2026-11-04,2027-02-03,2640.00,2026-11-16
F26-11-003,CTR-26-0029,AKTO,2,2026-11-15,2027-02-14,2640.00,2026-11-16
F26-11-004,CTR-26-0030,OPCO EP,1,2026-10-05,2027-05-04,3520.00,2026-11-16
$ lm connector run scenario-cfa-contracts-a
run scheduled: 458b4d3c-e774-477f-bb3f-297f6e39fbe9

$ lm run get 458b4d3c-e774-477f-bb3f-297f6e39fbe9
ID        CONNECTOR                 ENDPOINT  STATUS     IN  OUT  SKIPPED  DEAD-LETTERS  STARTED           ENDED             EVALUATED
458b4d3c  scenario-cfa-contracts-a  default   Completed  36  36   0        0             2026-11-11 12:09  2026-11-11 12:09  yes

$ lm inbox --process scenario-cfa-billed-after-rupture-a
ID     WHEN      PROCESS                              MESSAGE                                                                                                                                  ENTITY_KEY
27397  just now  scenario-cfa-billed-after-rupture-a  F26-09-032: 3520.00 EUR invoiced to OPCO Commerce for 2026-09-01 to 2027-03-31; contract CTR-25-0003 (APP-25-0003) broken on 2026-10-30  F26-09-032
27396  just now  scenario-cfa-billed-after-rupture-a  F26-09-007: 3520.00 EUR invoiced to OPCO Commerce for 2026-09-01 to 2027-03-31; contract CTR-26-0007 (APP-26-0007) broken on 2026-10-28  F26-09-007
27391  just now  scenario-cfa-billed-after-rupture-a  F26-11-001: 2640.00 EUR invoiced to OPCO Commerce for 2026-11-13 to 2027-02-12; contract CTR-26-0027 (APP-26-0027) broken on 2026-10-09  F26-11-001

Limits

  • lumnik flags the line; it computes neither the daily prorating nor the amount to repay.
  • The days actually attended, which the completion certificate requires, are not counted.
  • Training continued after the rupture is not told apart: the invoice then falls under a rectifying agreement.
  • Lines already there when the Process is applied are judged only when they or their contract change.
  • Contracts, periods and amounts are synthetic: the real schedule is each OPCO's funding agreement.

School · apprenticeship

An OPCO installment counts only for the days of the contract.

Contracts and invoices live in two tools.

36 contracts, 40 invoice lines, two CSV exports

The problem

CTR-26-0027 is broken on 9 October.

  • In November, its installment goes out anyway.
  • A rupture entered late does not catch the invoices already sent.

What is not changed

The register and the invoicing stay as they are.

  • Their usual CSV exports.
  • No development in either.

What had to be written

joins: [{ table: contracts, from: contract_id }]
when: ["period_end>{rupture_on}"]

One join, one condition between two columns.

  • An Entity: the rupture on every line.
  • A Process: one decision per line.

The rupture arrives late

Two ruptures entered at the end of October.

  • September's invoices come back up.
  • The year 1 balance, closed before, stays silent.

Try it

The scenario replays locally.

Every step is published with its output.

This scenario runs on lumnik Open, free and open source.

Try lumnik Open →