@rangka-os/create 0.5.0-alpha.13 → 0.5.0-alpha.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/package.json +1 -1
  2. package/template/base/apps/jasa_proyek/app.rk +4 -0
  3. package/template/base/apps/jasa_proyek/dashboards/rekap_absen.rk +1 -1
  4. package/template/base/apps/kasir/skills/rangka-app-kasir/SKILL.md +17 -1
  5. package/template/base/apps/kelas_kursus/app.rk +3 -0
  6. package/template/base/apps/langganan_jasa/app.rk +5 -1
  7. package/template/base/apps/sewa_alat/app.rk +6 -1
  8. package/template/base/connectors/moka/connector.rk +6 -5
  9. package/template/base/modules/catalogue/models/item.rk +9 -0
  10. package/template/base/modules/contacts/models/customer.rk +10 -1
  11. package/template/base/modules/contacts/models/vendor.rk +10 -1
  12. package/template/base/modules/courses/flows/session_attendance_checked.rk +14 -0
  13. package/template/base/modules/courses/flows/session_of_the_day.rk +34 -0
  14. package/template/base/modules/courses/models/course_attendance.rk +2 -0
  15. package/template/base/modules/courses/models/course_session.rk +1 -0
  16. package/template/base/modules/courses/module.rk +1 -1
  17. package/template/base/modules/courses/screens/absen_kelas.rk +17 -0
  18. package/template/base/modules/kitchen/flows/kitchen_ticket_on_sale.rk +26 -8
  19. package/template/base/modules/kitchen/flows/kitchen_ticket_on_update.rk +5 -1
  20. package/template/base/modules/kitchen/flows/kitchen_ticket_on_void.rk +9 -1
  21. package/template/base/modules/kitchen/models/kitchen_guard.rk +5 -0
  22. package/template/base/modules/kitchen/models/kitchen_ticket.rk +5 -0
  23. package/template/base/modules/outlet_sales/flows/moka_api_opened.rk +30 -0
  24. package/template/base/modules/outlet_sales/flows/moka_daily_sales.rk +39 -18
  25. package/template/base/modules/outlet_sales/flows/moka_held_release.rk +35 -0
  26. package/template/base/modules/outlet_sales/flows/moka_line_mapped.rk +26 -2
  27. package/template/base/modules/outlet_sales/flows/moka_transaction_refused.rk +15 -0
  28. package/template/base/modules/outlet_sales/flows/moka_transaction_staged.rk +108 -27
  29. package/template/base/modules/outlet_sales/models/moka_sale_line.rk +15 -2
  30. package/template/base/modules/outlets/models/outlet.rk +13 -1
  31. package/template/base/modules/payroll/flows/payslip_advance_guard.rk +3 -0
  32. package/template/base/modules/payroll/flows/payslip_from_recap.rk +30 -1
  33. package/template/base/modules/payroll/flows/payslip_ytd_guard.rk +18 -1
  34. package/template/base/modules/payroll/flows/payslip_ytd_on_create.rk +28 -1
  35. package/template/base/modules/payroll/models/payslip.rk +19 -1
  36. package/template/base/modules/pos/models/pos_sale.rk +2 -1
  37. package/template/base/modules/pos/models/pos_sale_item.rk +3 -0
  38. package/template/base/modules/pos/screens/kasir.rk +1 -1
  39. package/template/base/modules/projects/flows/attendance_close_on_submit.rk +6 -2
  40. package/template/base/modules/projects/flows/attendance_log_guard_created.rk +3 -1
  41. package/template/base/modules/projects/flows/attendance_log_guard_submitted.rk +8 -4
  42. package/template/base/modules/projects/flows/attendance_log_guard_updated.rk +2 -1
  43. package/template/base/modules/projects/models/assignment.rk +3 -0
  44. package/template/base/modules/projects/models/attendance_close.rk +4 -0
  45. package/template/base/modules/projects/models/attendance_guard.rk +1 -1
  46. package/template/base/modules/projects/models/attendance_log.rk +63 -66
  47. package/template/base/modules/projects/models/work_site.rk +2 -1
  48. package/template/base/modules/projects/module.rk +1 -1
  49. package/template/base/modules/projects/roles/field_worker.rk +2 -0
  50. package/template/base/modules/projects/screens/absen.rk +21 -0
  51. package/template/base/modules/rental/flows/rental_return_on_cancel.rk +5 -3
  52. package/template/base/modules/rental/models/rental_checkout.rk +10 -15
  53. package/template/base/modules/rental/models/rental_return.rk +3 -11
  54. package/template/base/modules/rental/models/rental_schedule.rk +8 -0
  55. package/template/base/modules/rental/models/rental_unit.rk +7 -0
  56. package/template/base/modules/rental/module.rk +1 -1
  57. package/template/base/modules/rental/screens/alat_keluar.rk +19 -0
  58. package/template/base/modules/rental/screens/alat_kembali.rk +19 -0
  59. package/template/base/modules/rental/screens/jadwal_alat.rk +21 -0
  60. package/template/base/modules/subscriptions/models/collection_visit.rk +47 -0
  61. package/template/base/modules/subscriptions/models/subscription.rk +3 -1
  62. package/template/base/modules/subscriptions/module.rk +1 -1
  63. package/template/base/modules/subscriptions/screens/catat_tagih.rk +18 -0
  64. package/template/base/modules/subscriptions/screens/rute_tagih.rk +25 -0
@@ -1,14 +1,38 @@
1
1
  # yaml-language-server: $schema=https://rangka-os.github.io/rangka-os/schema/0.5/flow.json
2
2
  # Head office picked the outlet and the item of an unmapped Moka line: it becomes staged and goes into the next daily
3
- # recap (flow moka_daily_sales).
3
+ # recap (flow moka_daily_sales). The unmapped refund lines of the same Moka checkout (same transaction and checkout,
4
+ # or for a line without checkout the same description) take the same outlet and item and are staged with it, so a
5
+ # sale and its refund go into the recap together. A line dated before the outlet's moka_api_from (or while it is
6
+ # empty) is held instead of staged (the export counts that day); flow moka_api_opened stages it later.
4
7
  name: moka_line_mapped
5
8
  label: {id: Baris Moka yang sudah dipetakan siap direkap}
6
9
  on: moka_sale_line.updated
7
10
  if: event.status == 'unmapped' && event.outlet != '' && event.item != ''
8
11
  steps:
12
+ # the outlet's API gate (outlet.moka_api_from): before it the line is held, the export counts that day
13
+ - find: outlet
14
+ where: "name == event.outlet && moka_api_from != '' && moka_api_from <= event.date"
15
+ as: open_for
9
16
  - find: moka_sale_line
10
17
  where: name == event.name
11
18
  as: rec
12
19
  - update: rec
13
20
  set:
14
- status: "'staged'"
21
+ status: "open_for != null ? 'staged' : 'held'"
22
+ - find_all: moka_sale_line
23
+ if: event.qty > 0
24
+ where: "name != event.name && transaction == event.transaction && qty < 0 && status == 'unmapped' && (event.checkout != '' ? checkout == event.checkout : (checkout == '' && description == 'Retur ' + event.description))"
25
+ as: refunds
26
+ - find: outlet
27
+ if: event.qty > 0
28
+ where: name == event.outlet
29
+ as: outlet_gate
30
+ - for_each: refunds
31
+ if: event.qty > 0
32
+ as: r
33
+ do:
34
+ - update: r
35
+ set:
36
+ outlet: event.outlet
37
+ item: event.item
38
+ status: "outlet_gate != null && outlet_gate.moka_api_from != '' && outlet_gate.moka_api_from <= r.date ? 'staged' : 'held'"
@@ -0,0 +1,15 @@
1
+ # yaml-language-server: $schema=https://rangka-os.github.io/rangka-os/schema/0.5/flow.json
2
+ # A Moka transaction flow moka_transaction_staged does not book, told to head office instead of dropped silently:
3
+ # - no id (transaction_id missing, null or ""): the kernel does not dedupe an empty idempotency key, so a repeated poll
4
+ # would count the sale twice (audit kernel-gelombang1 Delta 2, t_34922edd);
5
+ # - a checkout with quantity or total_price missing or null (audit moka-guard L1): booking a guess is worse than asking.
6
+ # Head office checks it in Moka and books it by hand or through the export. The kernel's event dedupe (hash of the
7
+ # event, 30 days) keeps one notice per distinct event.
8
+ name: moka_transaction_refused
9
+ label: {id: Transaksi Moka yang tidak bisa dicatat diberitahukan}
10
+ on: moka.transaction_created
11
+ if: "!('transaction_id' in event) || event.transaction_id == null || string(event.transaction_id) == '' || ('checkouts' in event && event.checkouts.map(c, 'quantity' in c && c.quantity != null && 'total_price' in c && c.total_price != null ? 0 : 1).sum() > 0)"
12
+ steps:
13
+ - notify: head_office
14
+ channel: email
15
+ template: {id: 'Moka {event.receipt_no} ({event.outlet_name}): transaksi tanpa ID atau jumlah/harga dari Moka tidak dicatat, cek di Moka'}
@@ -1,42 +1,75 @@
1
1
  # yaml-language-server: $schema=https://rangka-os.github.io/rangka-os/schema/0.5/flow.json
2
- # Moka API (connector moka, poll per outlet every 15 minutes): one transaction becomes a moka_transaction and one
3
- # moka_sale_line per item, plus a refund line per refunded quantity. Nothing touches stock here: flow moka_daily_sales
4
- # makes the outlet's daily sales draft from the lines, and stock moves when head office submits it (as with the export).
2
+ # Moka API (connector moka, poll per outlet every 5 minutes of the transactions CHANGED since two days back): the first
3
+ # event of a transaction becomes a moka_transaction and one moka_sale_line per item, plus a refund line per refunded
4
+ # quantity. Nothing touches stock here: flow moka_daily_sales makes the outlet's daily sales draft from the lines, and
5
+ # stock moves when head office submits it (as with the export).
5
6
  # Outlet: Moka's outlet id (outlet.moka_outlet_id), else Moka's outlet name (outlet.moka_name). Item: Moka's SKU = the
6
7
  # item's sku, else Moka's item name = item_name. A line without outlet or item is unmapped and head office is told; it
7
8
  # waits in Baris penjualan Moka until someone picks them (flow moka_line_mapped) and goes into the recap after that,
8
9
  # as its own record for that day if the day was already recapped (an API line is posted exactly once).
9
- # Refunds: a refunded quantity is recorded only if Moka reports it when the transaction is first polled. A refund made
10
- # after that poll is not seen (the poll cursor is the newest created_at and the transaction id is unique); until the
11
- # connector polls refunds, such refunds are booked by head office, or the day comes from the export file instead.
12
- # A transaction delivered twice records nothing: the kernel drops a repeated event, idempotency stops a second run, and
13
- # moka_transaction.transaction_id is unique, so a run racing another rolls back whole.
14
- # The day is the first 10 characters of created_at (Moka answers in the outlet's local time, +07:00).
10
+ # A later event of a known transaction (Moka changed it: a refund made after the sale was polled, or anything else) adds
11
+ # only refund lines for the quantity refunded since, per Moka checkout (moka_sale_line.checkout: the checkout's uuid,
12
+ # else its id), dated the day of the refund (refunded_date), staged for the recap of that day (or unmapped with its
13
+ # sale line, and mapped with it, flow moka_line_mapped); a change without a new refund adds nothing. A checkout without
14
+ # uuid or id is not matched by name (two lines of one item would share a refund): head office is told to book it.
15
+ # A refunded quantity counts at most the line's quantity. A checkout of qty <= 0 or a negative total is not staged:
16
+ # head office is told to check it in Moka.
17
+ # A transaction delivered twice records nothing: the kernel drops a repeated event and a known transaction only adds the
18
+ # refunded quantity not booked yet; moka_transaction.transaction_id is unique, so two runs racing on a new transaction
19
+ # roll the second back whole.
20
+ # Cost: one moka_transaction scan per event (the kernel reads a model whole for find); no moka_sale_line scan for a
21
+ # new transaction (unmapped lines are told about line by line), two per checkout for a refund.
22
+ # The day is the first 10 characters of created_at (Moka answers in the outlet's local time, +07:00); a time in UTC
23
+ # (ending in Z) is taken as WIB (+7 hours) first. The same for refunded_date. To confirm once API access is granted.
24
+ # Idempotency: the transaction and its refunded quantity, so a new refund is a new run and a repeat is not. An event
25
+ # without transaction_id (null or "") is not run: the kernel does not dedupe an empty key, so a repeated poll could book
26
+ # it twice; flow moka_transaction_without_id tells head office instead.
27
+ # Gate (audit sisa-1111 R1): a line of a known outlet whose day is before the outlet's moka_api_from (or while it is
28
+ # empty) is recorded as held, not staged: the export counts that day and the recap leaves it alone. When head office
29
+ # sets moka_api_from, flow moka_api_opened stages the held lines from that day on, so transactions polled before the
30
+ # gate opened are not lost (audit moka-guard H1). A late refund is gated by its own day (a sale counted by the export,
31
+ # refunded after the switch, is booked by the API: M1). Lines of an unknown outlet stay unmapped; mapping them checks
32
+ # the gate (flow moka_line_mapped, rule staged_outlet_api_open). refunded_quantity may be null in a checkout (Moka's
33
+ # spec does not list it): null is 0. A checkout with quantity or total_price null is not booked (flow
34
+ # moka_transaction_refused tells head office).
15
35
  name: moka_transaction_staged
16
36
  label: {id: Transaksi Moka masuk jadi baris penjualan}
17
37
  on: moka.transaction_created
18
- if: "'transaction_id' in event && 'created_at' in event && 'checkouts' in event && 'outlet_id' in event"
19
- idempotency: string(event.transaction_id)
38
+ if: "'transaction_id' in event && event.transaction_id != null && string(event.transaction_id) != '' && 'created_at' in event && 'checkouts' in event && 'outlet_id' in event && event.checkouts.map(c, 'quantity' in c && c.quantity != null && 'total_price' in c && c.total_price != null ? 0 : 1).sum() == 0"
39
+ idempotency: "string(event.transaction_id) + ':' + string(event.checkouts.map(c, 'refunded_quantity' in c && c.refunded_quantity != null ? c.refunded_quantity : 0).sum())"
20
40
  steps:
41
+ - find: moka_transaction
42
+ where: transaction_id == string(event.transaction_id)
43
+ as: known
44
+ # a new transaction
21
45
  - find: outlet
46
+ if: known == null
22
47
  where: "moka_outlet_id != '' && moka_outlet_id == string(event.outlet_id)"
23
48
  as: by_id
24
49
  - find: outlet
50
+ if: known == null
25
51
  where: "moka_name != '' && moka_name == ('outlet_name' in event ? event.outlet_name : '')"
26
52
  as: by_name
27
53
  - create: moka_transaction
54
+ if: known == null
28
55
  set:
29
56
  transaction_id: string(event.transaction_id)
30
57
  receipt_no: "'receipt_no' in event ? event.receipt_no : ''"
31
58
  outlet: "by_id != null ? by_id.name : (by_name != null ? by_name.name : '')"
32
59
  moka_outlet: "'outlet_name' in event ? event.outlet_name : string(event.outlet_id)"
33
60
  sold_at: event.created_at
34
- date: event.created_at
61
+ date: "string(event.created_at).matches('Z$') ? event.created_at + duration('7h') : event.created_at"
35
62
  payment_type: "'payment_type' in event ? event.payment_type : ''"
36
63
  total_collected: "'total_collected' in event ? event.total_collected : 0"
37
64
  refunded: "'is_refunded' in event && event.is_refunded == true"
38
65
  as: tx
66
+ # the outlet's gate: open on and after its moka_api_from
67
+ - find: outlet
68
+ if: known == null
69
+ where: "tx.outlet != '' && name == tx.outlet && moka_api_from != '' && moka_api_from <= tx.date"
70
+ as: api_open
39
71
  - for_each: event.checkouts
72
+ if: known == null
40
73
  as: c
41
74
  do:
42
75
  - find: item
@@ -45,12 +78,13 @@ steps:
45
78
  - find: item
46
79
  where: "item_name == c.item_name"
47
80
  as: by_item_name
48
- # a sale line only for a positive quantity, its discount never above its gross (outlet_sales rules
81
+ # a sale line only for a positive quantity and total, its discount never above its gross (outlet_sales rules
49
82
  # qty_not_negative and discount_within_gross refuse anything else, and one refused line would stop the recap)
50
83
  - create: moka_sale_line
51
- if: c.quantity > 0
84
+ if: "c.quantity > 0 && c.total_price >= 0"
52
85
  set:
53
86
  transaction: tx.name
87
+ checkout: "('uuid' in c && c.uuid != null && string(c.uuid) != '' ? string(c.uuid) : ('id' in c && c.id != null ? string(c.id) : ''))"
54
88
  outlet: tx.outlet
55
89
  date: tx.date
56
90
  item: "by_sku != null ? by_sku.name : (by_item_name != null ? by_item_name.name : '')"
@@ -60,31 +94,78 @@ steps:
60
94
  gross: c.total_price
61
95
  discount: "min('discount_amount' in c ? c.discount_amount : 0, c.total_price)"
62
96
  refund: "0"
63
- status: "tx.outlet == '' || (by_sku == null && by_item_name == null) ? 'unmapped' : 'staged'"
97
+ status: "tx.outlet == '' || (by_sku == null && by_item_name == null) ? 'unmapped' : (api_open != null ? 'staged' : 'held')"
64
98
  - create: moka_sale_line
65
99
  # a refund line only when it returns money: a refund of a free item (100% discount) changes nothing and a line of
66
- # qty < 0 without refund is refused by outlet_sales
67
- if: "c.quantity > 0 && 'refunded_quantity' in c && c.refunded_quantity > 0 && round((c.total_price - min('discount_amount' in c ? c.discount_amount : 0, c.total_price)) * c.refunded_quantity / c.quantity) > 0"
100
+ # qty < 0 without refund is refused by outlet_sales; never more than the quantity sold
101
+ if: "c.quantity > 0 && c.total_price >= 0 && 'refunded_quantity' in c && c.refunded_quantity != null && c.refunded_quantity > 0 && round((c.total_price - min('discount_amount' in c ? c.discount_amount : 0, c.total_price)) * min(c.refunded_quantity, c.quantity) / c.quantity) > 0"
68
102
  set:
69
103
  transaction: tx.name
104
+ checkout: "('uuid' in c && c.uuid != null && string(c.uuid) != '' ? string(c.uuid) : ('id' in c && c.id != null ? string(c.id) : ''))"
70
105
  outlet: tx.outlet
71
106
  date: tx.date
72
107
  item: "by_sku != null ? by_sku.name : (by_item_name != null ? by_item_name.name : '')"
73
108
  description: "'Retur ' + c.item_name + ('item_variant_name' in c && c.item_variant_name != '' ? ' ' + c.item_variant_name : '')"
74
109
  sku: "'sku' in c ? c.sku : ''"
75
- qty: -c.refunded_quantity
110
+ qty: -min(c.refunded_quantity, c.quantity)
76
111
  gross: "0"
77
112
  discount: "0"
78
- refund: "round((c.total_price - min('discount_amount' in c ? c.discount_amount : 0, c.total_price)) * c.refunded_quantity / c.quantity)"
79
- status: "tx.outlet == '' || (by_sku == null && by_item_name == null) ? 'unmapped' : 'staged'"
80
- - find_all: moka_sale_line
81
- where: "transaction == tx.name && status == 'unmapped'"
82
- as: unmapped
113
+ refund: "round((c.total_price - min('discount_amount' in c ? c.discount_amount : 0, c.total_price)) * min(c.refunded_quantity, c.quantity) / c.quantity)"
114
+ status: "tx.outlet == '' || (by_sku == null && by_item_name == null) ? 'unmapped' : (api_open != null ? 'staged' : 'held')"
115
+ - notify: head_office
116
+ # an outlet still on the export is not told about items (its lines wait held/unmapped; audit moka-guard D3)
117
+ if: "tx.outlet != '' && api_open != null && c.quantity > 0 && c.total_price >= 0 && by_sku == null && by_item_name == null"
118
+ channel: email
119
+ template: {id: 'Moka {tx.receipt_no} ({tx.moka_outlet}, {tx.date}): barang "{c.item_name}" belum dikenali, petakan di Baris penjualan Moka'}
83
120
  - notify: head_office
84
- if: "event.checkouts.map(c, c.quantity > 0 ? 0 : 1).sum() > 0"
121
+ if: "known == null && (tx.outlet == '' || api_open != null) && event.checkouts.map(c, c.quantity > 0 && c.total_price >= 0 ? 0 : 1).sum() > 0"
85
122
  channel: email
86
- template: {id: 'Moka {tx.receipt_no} ({tx.moka_outlet}, {tx.date}) punya barang dengan qty 0 atau minus, tidak direkap. Cek di Moka'}
123
+ template: {id: 'Moka {tx.receipt_no} ({tx.moka_outlet}, {tx.date}) punya barang dengan qty 0 atau minus, atau total minus, tidak direkap. Cek di Moka'}
87
124
  - notify: head_office
88
- if: size(unmapped) > 0
125
+ if: "known == null && tx.outlet == ''"
89
126
  channel: email
90
- template: {id: 'Moka {tx.receipt_no} ({tx.moka_outlet}, {tx.date}): barang atau outlet belum dikenali, petakan di Baris penjualan Moka'}
127
+ template: {id: 'Moka {tx.receipt_no} ({tx.moka_outlet}, {tx.date}): outlet belum dikenali, petakan barisnya di Baris penjualan Moka'}
128
+ # a known transaction that changed in Moka: refunds made after the first poll, gated by the refund's own day
129
+ - find: outlet
130
+ if: known != null
131
+ where: "known.outlet != '' && name == known.outlet"
132
+ as: ko
133
+ - for_each: event.checkouts
134
+ if: known != null
135
+ as: c
136
+ do:
137
+ - find: moka_sale_line
138
+ where: "('uuid' in c && c.uuid != null && string(c.uuid) != '' ? string(c.uuid) : ('id' in c && c.id != null ? string(c.id) : '')) != '' && transaction == known.name && qty > 0 && checkout == ('uuid' in c && c.uuid != null && string(c.uuid) != '' ? string(c.uuid) : ('id' in c && c.id != null ? string(c.id) : ''))"
139
+ as: sold
140
+ - notify: head_office
141
+ if: "('uuid' in c && c.uuid != null && string(c.uuid) != '' ? string(c.uuid) : ('id' in c && c.id != null ? string(c.id) : '')) == '' && 'refunded_quantity' in c && c.refunded_quantity != null && c.refunded_quantity > 0"
142
+ channel: email
143
+ template: {id: 'Moka {known.receipt_no} ({known.moka_outlet}): retur {c.item_name} tanpa ID baris Moka, catat manual'}
144
+ - find_all: moka_sale_line
145
+ if: sold != null
146
+ where: "transaction == known.name && qty < 0 && checkout == sold.checkout && description == 'Retur ' + sold.description"
147
+ as: returned
148
+ - create: moka_sale_line
149
+ if: "sold != null && 'refunded_quantity' in c && c.refunded_quantity != null && min(c.refunded_quantity, sold.qty) + returned.map(l, l.qty).sum() > 0 && round((sold.gross - sold.discount) * (min(c.refunded_quantity, sold.qty) + returned.map(l, l.qty).sum()) / sold.qty) > 0"
150
+ set:
151
+ transaction: known.name
152
+ checkout: sold.checkout
153
+ outlet: sold.outlet
154
+ date: "'refunded_date' in event && event.refunded_date != null && event.refunded_date != '' ? (string(event.refunded_date).matches('Z$') ? event.refunded_date + duration('7h') : event.refunded_date) : today()"
155
+ item: sold.item
156
+ description: "'Retur ' + sold.description"
157
+ sku: sold.sku
158
+ qty: -(min(c.refunded_quantity, sold.qty) + returned.map(l, l.qty).sum())
159
+ gross: "0"
160
+ discount: "0"
161
+ refund: "round((sold.gross - sold.discount) * (min(c.refunded_quantity, sold.qty) + returned.map(l, l.qty).sum()) / sold.qty)"
162
+ status: "sold.status == 'unmapped' || sold.outlet == '' || sold.item == '' ? 'unmapped' : (ko != null && ko.name == sold.outlet && ko.moka_api_from != '' && ko.moka_api_from <= ('refunded_date' in event && event.refunded_date != null && event.refunded_date != '' ? (string(event.refunded_date).matches('Z$') ? event.refunded_date + duration('7h') : event.refunded_date) : today()) ? 'staged' : 'held')"
163
+ as: late
164
+ - notify: head_office
165
+ if: "sold != null && 'refunded_quantity' in c && c.refunded_quantity != null && min(c.refunded_quantity, sold.qty) + returned.map(l, l.qty).sum() > 0 && round((sold.gross - sold.discount) * (min(c.refunded_quantity, sold.qty) + returned.map(l, l.qty).sum()) / sold.qty) > 0"
166
+ channel: email
167
+ template: {id: 'Moka {known.receipt_no} ({known.moka_outlet}): retur susulan {sold.description} dicatat di Baris penjualan Moka'}
168
+ - update: known
169
+ if: "known != null && 'is_refunded' in event && event.is_refunded == true && !known.refunded"
170
+ set:
171
+ refunded: "true"
@@ -1,9 +1,12 @@
1
1
  # yaml-language-server: $schema=https://rangka-os.github.io/rangka-os/schema/0.5/model.json
2
2
  # One item of one Moka transaction, waiting to become a line of the outlet's daily sales (flow moka_daily_sales). A flat
3
3
  # record, not a child table, so the daily flow can read every line of an outlet and day with one find_all.
4
- # status: staged (ready), unmapped (no outlet or no item matched: head office picks them here and the line becomes
4
+ # status: staged (ready), held (the outlet's API gate is closed for its day, see outlet.moka_api_from), unmapped (no outlet or no item matched: head office picks them here and the line becomes
5
5
  # staged, flow moka_line_mapped; head office may still correct them while staged), posted (in outlet_sales `sales`). A refunded quantity is its own line, as in the
6
- # export import: qty < 0, gross 0, refund = the refunded share of the line's net.
6
+ # export import: qty < 0, gross 0, refund = the refunded share of the line's net. A refund Moka reports after the first
7
+ # poll is a refund line of its own, dated the day of the refund (flow moka_transaction_staged).
8
+ # The recap sends a staged line back to unmapped (item or outlet emptied, head office told) when its item or outlet was
9
+ # deleted or the outlet no longer uses Moka, so one such line never stops the recap of other outlets and days.
7
10
  name: moka_sale_line
8
11
  label: {id: Baris penjualan Moka, en: Moka sales line}
9
12
  icon: store
@@ -16,6 +19,8 @@ permissions:
16
19
  - {role: head_office, read: true, export: true}
17
20
  fields:
18
21
  - {name: transaction, type: link, to: moka_transaction, label: {id: Transaksi Moka}, read_only: true, in_list: true}
22
+ # Moka's checkout id: the sale line and its refund lines share it, so a refund made later adds only what is new
23
+ - {name: checkout, type: data, label: {id: ID baris di Moka}, read_only: true}
19
24
  - {name: outlet, type: link, to: outlet, label: {id: Outlet}, in_list: true}
20
25
  - {name: date, type: date, label: {id: Tanggal}, read_only: true, in_list: true}
21
26
  - {name: item, type: link, to: item, label: {id: Barang}, in_list: true}
@@ -36,6 +41,9 @@ fields:
36
41
  - {value: staged, label: {id: Siap direkap}}
37
42
  - {value: unmapped, label: {id: Belum dipetakan}}
38
43
  - {value: posted, label: {id: Sudah direkap}}
44
+ # the outlet does not count Moka API sales for this day yet (outlet.moka_api_from empty or later): the export
45
+ # counts it; flow moka_api_opened stages it once head office opens the outlet's API from this day or earlier
46
+ - {value: held, label: {id: Ditahan (outlet masih ekspor)}}
39
47
  - {name: sales, type: link, to: outlet_sales, label: {id: Penjualan harian}, read_only: true, in_list: true}
40
48
  rules:
41
49
  - name: staged_has_outlet_and_item
@@ -47,6 +55,11 @@ rules:
47
55
  on: save
48
56
  check: status != 'staged' || outlet == '' || outlet.moka_name != ''
49
57
  message: {id: 'Pilih outlet yang memakai Moka (Nama outlet di Moka terisi)'}
58
+ # an API line counts only from the outlet's moka_api_from on: before it the export counts that day (audit R1)
59
+ - name: staged_outlet_api_open
60
+ on: save
61
+ check: status != 'staged' || outlet == '' || (outlet.moka_api_from != '' && outlet.moka_api_from <= date)
62
+ message: {id: 'Outlet ini belum memakai API Moka untuk tanggal baris ini. Isi Mulai pakai API Moka di outlet, atau catat lewat ekspor'}
50
63
  views:
51
64
  list:
52
65
  columns: [date, outlet, description, qty, status, item, sales]
@@ -54,14 +54,26 @@ fields:
54
54
  label: {id: ID outlet di Moka}
55
55
  help: {id: 'Diisi saat Moka tersambung lewat API. Selama connector Moka aktif, outlet juga dicocokkan lewat Nama outlet di Moka'}
56
56
  depends_on: app_installed('outlet_sales') && moka_name != ''
57
+ # The gate from the export to the API (audit sisa-1111 R1): flow moka_transaction_staged books a transaction of this
58
+ # outlet only when its day is on or after this date; before it (or while empty) the outlet's Moka sales come from
59
+ # the Item Details export alone, so a day is never counted from both. Set it to the first day the API should count,
60
+ # after the last exported day. The kernel follows Moka's next_url since rangka-os t_277ba9bf, so the API reads the
61
+ # whole two-day window of every poll.
62
+ - name: moka_api_from
63
+ type: date
64
+ label: {id: Mulai pakai API Moka}
65
+ help: {id: 'Hari pertama penjualan diambil lewat API Moka (sesudah ekspor terakhir). Kosong = tetap ekspor'}
66
+ depends_on: app_installed('outlet_sales') && moka_name != ''
57
67
  # The sales source of an outlet without Moka (moka_name empty): the daily form (default when empty), a file from
58
68
  # another POS in Juragan's template, a Loyverse export, or Juragan's own cashier (module pos). One source per outlet,
59
- # so a day is never counted twice.
69
+ # so a day is never counted twice. With module pos installed a new outlet without Moka starts on the cashier (a site
70
+ # built with app kasir next to an outlet_sales app can ring up at once); head office switches it per outlet.
60
71
  - name: sales_source
61
72
  type: select
62
73
  label: {id: Sumber penjualan}
63
74
  help: {id: 'Untuk outlet yang tidak pakai Moka. Kosong berarti formulir harian'}
64
75
  depends_on: app_installed('outlet_sales') && moka_name == ''
76
+ default: "app_installed('pos') && moka_name == '' ? 'kasir' : ''"
65
77
  options:
66
78
  - {value: form, label: {id: Formulir harian}}
67
79
  - {value: file, label: {id: File POS (template Juragan)}}
@@ -3,6 +3,9 @@ name: payslip_advance_guard
3
3
  label: {id: Potongan kasbon tidak melebihi kasbonnya}
4
4
  # Inside a payslip submit: the live slips that repay one kasbon (this one included) never deduct more than the kasbon
5
5
  # (audit gelombang 3 F5). The kasbon's own cancel is refused while one of them is submitted (cash_advance_cancel_guard).
6
+ # Two slips repaying one kasbon submitted at the same moment run one after the other: the find steps take the flow
7
+ # read locks of cash_advance and payslip (contract 0025), so the second one reads the first one's deduction and is
8
+ # refused (audit gelombang 3 r2 R3; day_one scenario_payroll_advance_race).
6
9
  on: payslip.submitted
7
10
  steps:
8
11
  - if: event.cash_advance != ''
@@ -27,10 +27,38 @@ steps:
27
27
  set:
28
28
  reason: "'second_slip'"
29
29
  document: other.name
30
+ - if: prof != null && run != null
31
+ find_all: cash_advance
32
+ where: worker == event.worker && docstatus == 1
33
+ sort: advance_date
34
+ as: kas
35
+ # A permanent employment that ended earlier this year (a submitted last_month slip) and was followed by casual months
36
+ # paid per day starts a new period of work: only the slips after it count (audit gelombang 3 r2 R2). A last_month
37
+ # ticked without a casual month after it (a mistake, the worker stayed) does not cut the year (audit apps-low F1).
38
+ - if: prof != null && run != null
39
+ find_all: payslip
40
+ where: worker == event.worker && tax_year == run.tax_year && tax_month < run.tax_month && docstatus == 1 && employment == 'casual' && pay_basis == 'daily'
41
+ sort: -tax_month
42
+ limit: 1
43
+ as: lastcas
30
44
  - if: prof != null && run != null
31
45
  find_all: payslip
32
- where: worker == event.worker && tax_year == run.tax_year && tax_month < run.tax_month && docstatus == 1 && !(employment == 'casual' && pay_basis == 'daily')
46
+ where: >-
47
+ worker == event.worker && tax_year == run.tax_year && tax_month < run.tax_month && docstatus == 1 && last_month && !(employment == 'casual' && pay_basis == 'daily')
48
+ && tax_month < (size(lastcas) > 0 ? lastcas[0].tax_month : 0)
49
+ sort: -tax_month
50
+ limit: 1
51
+ as: ended
52
+ - if: prof != null && run != null
53
+ find_all: payslip
54
+ where: >-
55
+ worker == event.worker && tax_year == run.tax_year && tax_month < run.tax_month && docstatus == 1 && !(employment == 'casual' && pay_basis == 'daily')
56
+ && tax_month > (size(ended) > 0 ? ended[0].tax_month : 0)
33
57
  as: prev
58
+ - if: prof != null && run != null
59
+ find_all: payslip
60
+ where: worker == event.worker && cash_advance != '' && docstatus == 1
61
+ as: repaid
34
62
  - if: prof != null && run != null
35
63
  create: payslip
36
64
  set:
@@ -45,3 +73,4 @@ steps:
45
73
  ytd_pph21: "prev.map(p, p.pph21).sum()"
46
74
  ytd_pension: "prev.map(p, p.jht_employee + p.jp_employee).sum()"
47
75
  ytd_months: "size(prev)"
76
+ open_advance: "kas.exists(k, repaid.map(p, p.cash_advance == k.name ? p.other_deduction : 0).sum() < k.amount) ? kas.filter(k, repaid.map(p, p.cash_advance == k.name ? p.other_deduction : 0).sum() < k.amount)[0].name : ''"
@@ -8,8 +8,25 @@ label: {id: Slip gaji dengan penghasilan sebelumnya yang basi tidak bisa diajuka
8
8
  # months as a permanent employee only (PMK 168/2023; audit gelombang 3 F1).
9
9
  on: payslip.submitted
10
10
  steps:
11
+ # A permanent employment that ended earlier this year (a submitted last_month slip) and was followed by casual months
12
+ # paid per day starts a new period of work: only the slips after it count (audit gelombang 3 r2 R2). A last_month
13
+ # ticked without a casual month after it (a mistake, the worker stayed) does not cut the year (audit apps-low F1).
11
14
  - find_all: payslip
12
- where: worker == event.worker && tax_year == event.tax_year && tax_month < event.tax_month && docstatus == 1 && !(employment == 'casual' && pay_basis == 'daily')
15
+ where: worker == event.worker && tax_year == event.tax_year && tax_month < event.tax_month && docstatus == 1 && employment == 'casual' && pay_basis == 'daily'
16
+ sort: -tax_month
17
+ limit: 1
18
+ as: lastcas
19
+ - find_all: payslip
20
+ where: >-
21
+ worker == event.worker && tax_year == event.tax_year && tax_month < event.tax_month && docstatus == 1 && last_month && !(employment == 'casual' && pay_basis == 'daily')
22
+ && tax_month < (size(lastcas) > 0 ? lastcas[0].tax_month : 0)
23
+ sort: -tax_month
24
+ limit: 1
25
+ as: ended
26
+ - find_all: payslip
27
+ where: >-
28
+ worker == event.worker && tax_year == event.tax_year && tax_month < event.tax_month && docstatus == 1 && !(employment == 'casual' && pay_basis == 'daily')
29
+ && tax_month > (size(ended) > 0 ? ended[0].tax_month : 0)
13
30
  as: prev
14
31
  - if: size(prev) != event.ytd_months || prev.map(p, p.gross_taxable).sum() != event.ytd_gross || prev.map(p, p.pph21).sum() != event.ytd_pph21 || prev.map(p, p.jht_employee + p.jp_employee).sum() != event.ytd_pension
15
32
  create: payroll_guard
@@ -7,10 +7,36 @@ label: {id: Slip gaji membaca penghasilan sebelumnya tahun ini}
7
7
  # Slips under the daily TER (casual, paid per day) are not part of the year: the December recomputation covers the
8
8
  # months as a permanent employee only (PMK 168/2023; audit gelombang 3 F1).
9
9
  on: payslip.created
10
+ # It also notes a kasbon of the worker not yet repaid in full (open_advance; warned at submit when the deduction does not
11
+ # link it). Reads cash_advance before payslip, like payslip_advance_guard.
10
12
  steps:
13
+ - find_all: cash_advance
14
+ where: worker == event.worker && docstatus == 1
15
+ sort: advance_date
16
+ as: kas
17
+ # A permanent employment that ended earlier this year (a submitted last_month slip) and was followed by casual months
18
+ # paid per day starts a new period of work: only the slips after it count (audit gelombang 3 r2 R2). A last_month
19
+ # ticked without a casual month after it (a mistake, the worker stayed) does not cut the year (audit apps-low F1).
11
20
  - find_all: payslip
12
- where: worker == event.worker && tax_year == event.tax_year && tax_month < event.tax_month && docstatus == 1 && !(employment == 'casual' && pay_basis == 'daily')
21
+ where: worker == event.worker && tax_year == event.tax_year && tax_month < event.tax_month && docstatus == 1 && employment == 'casual' && pay_basis == 'daily'
22
+ sort: -tax_month
23
+ limit: 1
24
+ as: lastcas
25
+ - find_all: payslip
26
+ where: >-
27
+ worker == event.worker && tax_year == event.tax_year && tax_month < event.tax_month && docstatus == 1 && last_month && !(employment == 'casual' && pay_basis == 'daily')
28
+ && tax_month < (size(lastcas) > 0 ? lastcas[0].tax_month : 0)
29
+ sort: -tax_month
30
+ limit: 1
31
+ as: ended
32
+ - find_all: payslip
33
+ where: >-
34
+ worker == event.worker && tax_year == event.tax_year && tax_month < event.tax_month && docstatus == 1 && !(employment == 'casual' && pay_basis == 'daily')
35
+ && tax_month > (size(ended) > 0 ? ended[0].tax_month : 0)
13
36
  as: prev
37
+ - find_all: payslip
38
+ where: worker == event.worker && cash_advance != '' && docstatus == 1
39
+ as: repaid
14
40
  - find: payslip
15
41
  where: name == event.name
16
42
  as: me
@@ -20,3 +46,4 @@ steps:
20
46
  ytd_pph21: "prev.map(p, p.pph21).sum()"
21
47
  ytd_pension: "prev.map(p, p.jht_employee + p.jp_employee).sum()"
22
48
  ytd_months: "size(prev)"
49
+ open_advance: "kas.exists(k, repaid.map(p, p.cash_advance == k.name ? p.other_deduction : 0).sum() < k.amount) ? kas.filter(k, repaid.map(p, p.cash_advance == k.name ? p.other_deduction : 0).sum() < k.amount)[0].name : ''"
@@ -96,6 +96,10 @@ fields:
96
96
  # The kasbon this deduction repays (cash_advance of the same worker, submitted): its cancel is then refused, and the
97
97
  # live slips linking it never deduct more than it (payslip_advance_guard, audit gelombang 3 F5).
98
98
  - {name: cash_advance, type: link, to: cash_advance, label: {id: Kasbon yang dipotong}}
99
+ # A kasbon of this worker not yet repaid in full by the submitted slips linking it, found when the slip is made
100
+ # (payslip_ytd_on_create, payslip_from_recap). A deduction without a link while one is open is warned at submit
101
+ # (audit gelombang 3 r2 R1): linked, the kasbon cannot be cancelled after its repayment.
102
+ - {name: open_advance, type: link, to: cash_advance, label: {id: Kasbon belum lunas}, read_only: true}
99
103
  - name: ptkp_status
100
104
  type: select
101
105
  label: {id: Status PTKP}
@@ -291,6 +295,15 @@ rules:
291
295
  && holiday_hours_2x <= holiday_overtime_days * (payroll_run.workdays_per_week == 5 ? 8 : 7)
292
296
  && holiday_hours_3x <= holiday_overtime_days && holiday_hours_4x <= holiday_overtime_days * 3
293
297
  message: {id: 'Hari 0 sampai 31, jam hari libur per tarif tidak melebihi batas per hari (2x: 7 atau 8, 3x: 1, 4x: 3), tidak negatif'}
298
+ # Rest-day hours climb the tiers in order (PP 35/2021 Pasal 31; audit gelombang 3 r2 R4): an hour at 3x only after a
299
+ # full day at 2x (at least 5 hours, the shortest day of a six-day week; 8 hours in a five-day week), hours at 4x only
300
+ # after the hour at 3x (at most 3 per day that had one).
301
+ - name: holiday_tiers_in_order
302
+ on: save
303
+ check: >-
304
+ holiday_hours_2x >= holiday_hours_3x * (payroll_run.workdays_per_week == 5 ? 8 : 5)
305
+ && holiday_hours_4x <= holiday_hours_3x * 3
306
+ message: {id: 'Jam hari libur 3x baru setelah jam 2x penuh, dan 4x baru setelah jam 3x'}
294
307
  - name: pay_entered
295
308
  on: submit
296
309
  check: "pay_basis == 'monthly' ? monthly_salary > 0 : (days > 0 && day_rate > 0)"
@@ -311,6 +324,11 @@ rules:
311
324
  on: submit
312
325
  check: net_pay >= 0
313
326
  message: {id: 'Gaji bersih minus: kurangi potongan lain'}
327
+ - name: deduction_not_linked
328
+ on: submit
329
+ level: warn
330
+ check: other_deduction == 0 || cash_advance != '' || open_advance == ''
331
+ message: {id: 'Pekerja ini punya kasbon belum lunas, tapi potongannya tidak ditautkan ke kasbon itu'}
314
332
  - name: umk_warning
315
333
  on: submit
316
334
  level: warn
@@ -329,7 +347,7 @@ views:
329
347
  - section: {id: Kehadiran dan upah}
330
348
  columns:
331
349
  - [pay_basis, employment, days, day_rate, monthly_salary, fixed_allowance, daily_allowance]
332
- - [overtime_hours, overtime_days, overtime_rate, thr_tenure_months, other_income, other_deduction, cash_advance]
350
+ - [overtime_hours, overtime_days, overtime_rate, thr_tenure_months, other_income, other_deduction, cash_advance, open_advance]
333
351
  - section: {id: Hari libur masuk kerja}
334
352
  columns:
335
353
  - [holiday_overtime_days]
@@ -13,8 +13,9 @@ name: pos_sale
13
13
  label: {id: Transaksi kasir, en: Cashier sale}
14
14
  icon: receipt
15
15
  is_submittable: true
16
+ # No title_field: a receipt's title is its number (STRK-...), so a link to it (a kitchen ticket, a daily sales check)
17
+ # shows the number and never the total to a role that may not read the receipt.
16
18
  naming: STRK-{outlet.code}-{YY}{MM}-{#####}
17
- title_field: grand_total
18
19
  on_submit: [stock.post_moves]
19
20
  on_cancel: [stock.reverse_moves]
20
21
  permissions:
@@ -7,6 +7,9 @@ name: pos_sale_item
7
7
  is_child: true
8
8
  fields:
9
9
  - {name: item, type: link, to: item, label: {id: Barang atau menu}, required: true, peek: [rate, stock_uom]}
10
+ # the item's category when the line was saved: the kitchen routes a paid line by it (module kitchen) without reading
11
+ # the whole catalogue during the payment
12
+ - {name: category, type: link, to: item_category, label: {id: Kategori}, hidden: true, compute: item.category}
10
13
  - {name: description, type: text, label: {id: Uraian}, default: item.item_name}
11
14
  - name: packing
12
15
  type: link
@@ -12,7 +12,7 @@ offline: queue
12
12
  counter:
13
13
  catalogue:
14
14
  model: item
15
- filter: "kind != 'material'"
15
+ filter: "kind != 'material' && active != false"
16
16
  title: item_name
17
17
  search: [item_name, sku, barcode]
18
18
  group_by: category
@@ -52,9 +52,13 @@ steps:
52
52
  set:
53
53
  project: event.project
54
54
  worker: a.worker
55
- # An hourly assignment's rates are per hour: its per-day recap takes the worker's day rates instead (no
56
- # assignment), as an imported recap does (audit r2 R2-1).
55
+ # An hourly assignment's cost rate is per hour: its per-day recap keeps the worker's day pay (no assignment,
56
+ # audit r2 R2-1) and takes the assignment's day and overtime rates, as an imported recap does (audit r3 R3-1).
57
57
  assignment: "a.rate_basis == 'hour' ? '' : a.name"
58
+ day_rate: a.day_rate
59
+ hour_rate: a.hour_rate
60
+ overtime_rate: a.overtime_rate
61
+ overtime_cost_rate: a.overtime_cost_rate
58
62
  work_date: event.period_from
59
63
  period_to: event.period_to
60
64
  rate_basis: "'day'"
@@ -4,9 +4,11 @@ label: {id: Satu absen per orang per hari (baru)}
4
4
  # A second live log of the same worker and day would count the day twice in the recap. The read takes the flow lock of
5
5
  # contract 0025, so two clock-ins sent at the same moment run one after the other and the second is refused.
6
6
  on: attendance_log.created
7
+ # A draft left without its clock-in time (the clock screen's second write failed) does not hold the day: the next
8
+ # clock-in may go ahead (audit 2026-11-12 F2). The submit guard still allows one counted log per day.
7
9
  steps:
8
10
  - find: attendance_log
9
- where: day_key == event.day_key && name != event.name && docstatus != 2
11
+ where: day_key == event.day_key && name != event.name && docstatus != 2 && (docstatus == 1 || clock_in != '')
10
12
  as: other
11
13
  - if: other != null
12
14
  create: attendance_guard
@@ -15,17 +15,21 @@ steps:
15
15
  reason: "'period_closed'"
16
16
  document: closed.name
17
17
  - find: attendance_log
18
- where: day_key == event.day_key && name != event.name && docstatus != 2
18
+ where: day_key == event.day_key && name != event.name && docstatus != 2 && (docstatus == 1 || clock_in != '')
19
19
  as: other
20
20
  - if: other != null
21
21
  create: attendance_guard
22
22
  set:
23
23
  reason: "'second_log'"
24
24
  document: other.name
25
- # One photo, one day (audit r2 R2-3): a clock-in photo already used by another live log is refused. That the photo
26
- # was uploaded to this very log is checked by the kernel only from WS6 (image fields).
25
+ # One photo, one day (audit r2 R2-3, r3 R3-2): a photo of this log already used as the clock-in or clock-out photo of
26
+ # another live log is refused. That the photo was uploaded to this very log is checked by the kernel only from WS6
27
+ # (image fields).
27
28
  - find: attendance_log
28
- where: in_photo == event.in_photo && name != event.name && docstatus != 2
29
+ where: >-
30
+ name != event.name && docstatus != 2 && (
31
+ in_photo == event.in_photo || out_photo == event.in_photo
32
+ || (event.out_photo != '' && (in_photo == event.out_photo || out_photo == event.out_photo)))
29
33
  as: same_photo
30
34
  - if: same_photo != null
31
35
  create: attendance_guard
@@ -3,9 +3,10 @@ name: attendance_log_guard_updated
3
3
  label: {id: Satu absen per orang per hari (diubah)}
4
4
  # The same check when the worker or the date of a draft changes.
5
5
  on: attendance_log.updated
6
+ # Drafts without a clock-in time do not hold the day (audit 2026-11-12 F2).
6
7
  steps:
7
8
  - find: attendance_log
8
- where: day_key == event.day_key && name != event.name && docstatus != 2
9
+ where: day_key == event.day_key && name != event.name && docstatus != 2 && (docstatus == 1 || clock_in != '')
9
10
  as: other
10
11
  - if: other != null
11
12
  create: attendance_guard