@rangka-os/create 0.5.0-alpha.14 → 0.5.0-alpha.16

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 (94) hide show
  1. package/package.json +1 -1
  2. package/template/base/apps/grosir_distribusi/app.rk +2 -1
  3. package/template/base/apps/jasa_proyek/app.rk +4 -0
  4. package/template/base/apps/jasa_proyek/dashboards/rekap_absen.rk +1 -1
  5. package/template/base/apps/kasir/skills/rangka-app-kasir/SKILL.md +17 -1
  6. package/template/base/apps/kelas_kursus/app.rk +3 -0
  7. package/template/base/apps/langganan_jasa/app.rk +8 -1
  8. package/template/base/apps/produksi_pabrik/dashboards/produksi_overview.rk +1 -1
  9. package/template/base/apps/ritel_cabang/app.rk +3 -0
  10. package/template/base/apps/sewa_alat/app.rk +6 -1
  11. package/template/base/connectors/doku/mock/doku_mock.py +16 -5
  12. package/template/base/connectors/moka/connector.rk +6 -5
  13. package/template/base/connectors/moka/mock/moka_mock.py +210 -0
  14. package/template/base/connectors/xendit/mock/xendit_mock.py +231 -0
  15. package/template/base/modules/bank_statement/flows/bank_transaction_booked.rk +12 -0
  16. package/template/base/modules/bank_statement/flows/bank_transaction_booked_released.rk +11 -0
  17. package/template/base/modules/bank_statement/flows/bank_transaction_claim.rk +11 -1
  18. package/template/base/modules/bank_statement/flows/bank_transaction_confirm.rk +23 -5
  19. package/template/base/modules/bank_statement/flows/bank_transaction_suggest.rk +56 -14
  20. package/template/base/modules/bank_statement/models/bank_transaction.rk +27 -4
  21. package/template/base/modules/bank_statement/models/bank_transaction_claim.rk +1 -1
  22. package/template/base/modules/catalogue/models/item.rk +9 -0
  23. package/template/base/modules/catalogue/models/item_category.rk +2 -0
  24. package/template/base/modules/contacts/models/customer.rk +10 -1
  25. package/template/base/modules/contacts/models/vendor.rk +10 -1
  26. package/template/base/modules/coretax/module.rk +2 -2
  27. package/template/base/modules/coretax/print/coretax_faktur.rk +1 -1
  28. package/template/base/modules/coretax/print/coretax_faktur.xml +13 -7
  29. package/template/base/modules/courses/flows/session_attendance_checked.rk +14 -0
  30. package/template/base/modules/courses/flows/session_of_the_day.rk +34 -0
  31. package/template/base/modules/courses/models/course_attendance.rk +2 -0
  32. package/template/base/modules/courses/models/course_session.rk +1 -0
  33. package/template/base/modules/courses/module.rk +1 -1
  34. package/template/base/modules/courses/screens/absen_kelas.rk +17 -0
  35. package/template/base/modules/delivery/flows/invoice_qty_from_deliveries.rk +1 -1
  36. package/template/base/modules/delivery/module.rk +1 -1
  37. package/template/base/modules/distribution/flows/order_tier_pricing_created.rk +2 -2
  38. package/template/base/modules/distribution/flows/order_tier_pricing_updated.rk +2 -2
  39. package/template/base/modules/distribution/module.rk +1 -1
  40. package/template/base/modules/invoicing/models/sales_invoice.rk +31 -4
  41. package/template/base/modules/invoicing/models/sales_invoice_item.rk +7 -0
  42. package/template/base/modules/invoicing/module.rk +1 -1
  43. package/template/base/modules/invoicing/print/sales_invoice.html +15 -2
  44. package/template/base/modules/orders/models/customer_order.rk +2 -0
  45. package/template/base/modules/orders/models/customer_order_item.rk +10 -0
  46. package/template/base/modules/orders/module.rk +1 -1
  47. package/template/base/modules/outlet_sales/flows/moka_api_opened.rk +30 -0
  48. package/template/base/modules/outlet_sales/flows/moka_held_release.rk +35 -0
  49. package/template/base/modules/outlet_sales/flows/moka_line_mapped.rk +12 -3
  50. package/template/base/modules/outlet_sales/flows/moka_transaction_refused.rk +15 -0
  51. package/template/base/modules/outlet_sales/flows/moka_transaction_staged.rk +31 -11
  52. package/template/base/modules/outlet_sales/models/moka_sale_line.rk +9 -1
  53. package/template/base/modules/outlets/models/outlet.rk +13 -1
  54. package/template/base/modules/payments/flows/payment_refund_from_doku.rk +14 -0
  55. package/template/base/modules/payroll/flows/payroll_close_on_submit.rk +2 -2
  56. package/template/base/modules/payroll/flows/payslip_advance_guard.rk +3 -0
  57. package/template/base/modules/payroll/flows/payslip_from_recap.rk +30 -1
  58. package/template/base/modules/payroll/flows/payslip_ytd_guard.rk +18 -1
  59. package/template/base/modules/payroll/flows/payslip_ytd_on_create.rk +28 -1
  60. package/template/base/modules/payroll/models/payslip.rk +19 -1
  61. package/template/base/modules/payroll/module.rk +2 -2
  62. package/template/base/modules/pos/screens/kasir.rk +1 -1
  63. package/template/base/modules/production/models/production_batch.rk +3 -0
  64. package/template/base/modules/production/module.rk +1 -1
  65. package/template/base/modules/projects/flows/attendance_close_on_submit.rk +6 -2
  66. package/template/base/modules/projects/flows/attendance_log_guard_created.rk +3 -1
  67. package/template/base/modules/projects/flows/attendance_log_guard_submitted.rk +8 -4
  68. package/template/base/modules/projects/flows/attendance_log_guard_updated.rk +2 -1
  69. package/template/base/modules/projects/models/assignment.rk +3 -0
  70. package/template/base/modules/projects/models/attendance_close.rk +4 -0
  71. package/template/base/modules/projects/models/attendance_guard.rk +1 -1
  72. package/template/base/modules/projects/models/attendance_log.rk +63 -66
  73. package/template/base/modules/projects/models/work_site.rk +2 -1
  74. package/template/base/modules/projects/module.rk +1 -1
  75. package/template/base/modules/projects/roles/field_worker.rk +2 -0
  76. package/template/base/modules/projects/screens/absen.rk +21 -0
  77. package/template/base/modules/quotation/models/quotation.rk +14 -4
  78. package/template/base/modules/quotation/models/quotation_item.rk +13 -0
  79. package/template/base/modules/quotation/module.rk +1 -1
  80. package/template/base/modules/quotation/print/quotation.html +16 -2
  81. package/template/base/modules/rental/flows/rental_return_on_cancel.rk +5 -3
  82. package/template/base/modules/rental/models/rental_checkout.rk +10 -15
  83. package/template/base/modules/rental/models/rental_return.rk +3 -11
  84. package/template/base/modules/rental/models/rental_schedule.rk +8 -0
  85. package/template/base/modules/rental/models/rental_unit.rk +7 -0
  86. package/template/base/modules/rental/module.rk +1 -1
  87. package/template/base/modules/rental/screens/alat_keluar.rk +19 -0
  88. package/template/base/modules/rental/screens/alat_kembali.rk +19 -0
  89. package/template/base/modules/rental/screens/jadwal_alat.rk +21 -0
  90. package/template/base/modules/subscriptions/models/collection_visit.rk +47 -0
  91. package/template/base/modules/subscriptions/models/subscription.rk +3 -1
  92. package/template/base/modules/subscriptions/module.rk +1 -1
  93. package/template/base/modules/subscriptions/screens/catat_tagih.rk +18 -0
  94. package/template/base/modules/subscriptions/screens/rute_tagih.rk +25 -0
@@ -2,15 +2,21 @@
2
2
  {{- /* Element names and order follow the DJP sample "Sample Faktur PK Template v.1.4.xml" (pajak.go.id Coretax
3
3
  templates). Per line: TaxBase = the line's share of the invoice DPP (header discount and down payment spread in
4
4
  proportion, the rounding rest on the last line, so the lines add up to the invoice DPP); TotalDiscount = Price x Qty
5
- - TaxBase; OtherTaxBase = TaxBase x DPP factor; VAT = OtherTaxBase x rate. Amounts in rupiah, at most 2 decimals. */}}
5
+ - TaxBase; OtherTaxBase = TaxBase x DPP factor; VAT = OtherTaxBase x rate. Amounts in rupiah, at most 2 decimals.
6
+ PPN on the fee only (config tax.ppn_fee_only, PMK 83/2012): an invoice whose PPN base is below its DPP was submitted
7
+ that way; its wage lines (ppn_exclude) stay off the faktur pajak and the fee lines share the PPN base instead. */}}
6
8
  <TaxInvoiceBulk xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="TaxInvoice.xsd">
7
9
  <TIN>{{.Doc.seller_tin}}</TIN>
8
10
  <ListOfTaxInvoice>
9
11
  {{- $seller := .Doc.seller_nitku}}
10
12
  {{- range .Related.invoices}}{{$inv := .}}
11
13
  {{- $fx := and .currency (ne .currency "IDR")}}
12
- {{- $s := "0"}}{{range .items}}{{if $fx}}{{$s = add $s .amount_fx_idr}}{{else}}{{$s = add $s .amount}}{{end}}{{end}}
13
- {{- $r := sub $s .dpp}}{{$n := len .items}}{{$acc := "0"}}
14
+ {{- /* an invoice submitted before ppn_base existed has none (the kernel leaves such computes empty on frozen documents):
15
+ its PPN was taken on the whole DPP */}}
16
+ {{- $pb := .dpp}}{{if .ppn_base}}{{$pb = .ppn_base}}{{end}}
17
+ {{- $fee := ne (dec $pb 2) (dec .dpp 2)}}
18
+ {{- $s := "0"}}{{$n := "0"}}{{range .items}}{{if not (and $fee .ppn_exclude)}}{{$n = add $n 1}}{{if $fx}}{{$s = add $s .amount_fx_idr}}{{else}}{{$s = add $s .amount}}{{end}}{{end}}{{end}}
19
+ {{- $r := sub $s $pb}}{{$k := "0"}}{{$acc := "0"}}
14
20
  <TaxInvoice>
15
21
  <TaxInvoiceDate>{{isodate .posting_date}}</TaxInvoiceDate>
16
22
  <TaxInvoiceOpt>Normal</TaxInvoiceOpt>
@@ -18,7 +24,7 @@
18
24
  <AddInfo/>
19
25
  <CustomDoc/>
20
26
  <CustomDocMonthYear/>
21
- <RefDesc>{{.name}}{{if .dp_invoice}}; uang muka {{.dp_invoice}}{{end}}</RefDesc>
27
+ <RefDesc>{{.name}}{{if .dp_invoice}}; uang muka {{.dp_invoice}}{{end}}{{if $fee}}; upah tenaga kerja di luar DPP (PMK 83/2012){{end}}</RefDesc>
22
28
  <FacilityStamp/>
23
29
  <SellerIDTKU>{{$seller}}</SellerIDTKU>
24
30
  <BuyerTin>{{.buyer_tin}}</BuyerTin>
@@ -30,10 +36,10 @@
30
36
  <BuyerEmail>{{.buyer_email}}</BuyerEmail>
31
37
  <BuyerIDTKU>{{.buyer_idtku}}</BuyerIDTKU>
32
38
  <ListOfGoodService>
33
- {{- range $i, $l := .items}}
39
+ {{- range $i, $l := .items}}{{if not (and $fee $l.ppn_exclude)}}{{$k = add $k 1}}
34
40
  {{- $b := $l.amount}}{{$p := $l.rate}}{{if $fx}}{{$b = $l.amount_fx_idr}}{{$p = round (mul $l.rate_fx $inv.exchange_rate) 2}}{{end}}
35
41
  {{- $q := round $l.qty 2}}
36
- {{- $tb := round (sub $b (div (mul $r $b) $s)) 2}}{{if eq (add $i 1) (add $n)}}{{$tb = sub $inv.dpp $acc}}{{end}}{{$acc = add $acc $tb}}
42
+ {{- $tb := round (sub $b (div (mul $r $b) $s)) 2}}{{if eq $k $n}}{{$tb = sub $pb $acc}}{{end}}{{$acc = add $acc $tb}}
37
43
  {{- $otb := round (div (mul $tb $inv.dpp_num) $inv.dpp_den) 2}}
38
44
  {{- /* Line amounts are whole rupiah while Price x Qty has 2 decimals, so Price x Qty can fall a few sen under TaxBase:
39
45
  then Price is raised to TaxBase / Qty (rounded up to the sen) and TotalDiscount stays 0 or a few sen, never negative
@@ -54,7 +60,7 @@
54
60
  <STLGRate>0</STLGRate>
55
61
  <STLG>0</STLG>
56
62
  </GoodService>
57
- {{- end}}
63
+ {{- end}}{{end}}
58
64
  </ListOfGoodService>
59
65
  </TaxInvoice>
60
66
  {{- end}}
@@ -0,0 +1,14 @@
1
+ # yaml-language-server: $schema=https://rangka-os.github.io/rangka-os/schema/0.5/flow.json
2
+ name: session_attendance_checked
3
+ label: {id: Absen pertemuan dicek saat pengajar menyimpannya}
4
+ # The instructor's roll screen (screens/absen_kelas.rk) saves the attendance lines and nothing else (contract 0030 §2
5
+ # roll; course_session is not submittable). Saving them is the check: an instructor's save of a session on or before
6
+ # its day ticks attendance_taken, so the meeting leaves "Absen belum dicek" (dashboard kelas_saya). A save that
7
+ # unticks it (before ticked) is left as the instructor wrote it; the course admin's saves tick nothing.
8
+ on: course_session.updated
9
+ if: "event.before != null && !event.before.attendance_taken && !event.attendance_taken && size(event.attendance) > 0 && event.session_date <= today() && 'instructor' in user.roles"
10
+ steps:
11
+ - {find: course_session, where: name == event.name, as: me}
12
+ - update: me
13
+ set:
14
+ attendance_taken: 'true'
@@ -0,0 +1,34 @@
1
+ # yaml-language-server: $schema=https://rangka-os.github.io/rangka-os/schema/0.5/flow.json
2
+ name: session_of_the_day
3
+ label: {id: Pertemuan hari ini dibuka dari jadwal mingguan}
4
+ # Every day at 00:10 (scheduler.timezone), and by the owner from the flow list: each running batch with a class on
5
+ # today's weekday (class_days, the same test as dashboard kelas_saya) and no session dated today gets one, numbered
6
+ # after its last session, with one attendance line per registered or active student marked present. So the
7
+ # instructor's roll screen (screens/absen_kelas.rk) has today's class ready and only the exceptions are marked.
8
+ # A flow-made record runs no other flow, so the lines are filled here as session_fill_attendance does for a session
9
+ # made by hand. session_key (batch|session_no) is unique: a second run the same day makes nothing new.
10
+ # At most 200 batches per run.
11
+ schedule: '10 0 * * *'
12
+ steps:
13
+ - find_all: course_batch
14
+ where: "start_date <= today() && (end_date == '' || end_date >= today()) && class_days.contains(['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'][days_between('2024-01-01', today()) % 7])"
15
+ sort: name
16
+ limit: 200
17
+ as: batches
18
+ - for_each: batches
19
+ as: b
20
+ do:
21
+ - find_all: course_session
22
+ where: batch == b.name
23
+ as: past
24
+ - find_all: enrollment
25
+ where: batch == b.name && (status == 'registered' || status == 'active')
26
+ sort: student
27
+ as: list
28
+ - create: course_session
29
+ if: "past.map(x, x.session_date == today() ? 1 : 0).sum() == 0"
30
+ set:
31
+ batch: b.name
32
+ session_no: "past.size() == 0 ? 1 : max(past.map(x, x.session_no)) + 1"
33
+ session_date: today()
34
+ attendance: "list.map(e, {'enrollment': e.name, 'status': 'present'})"
@@ -9,6 +9,8 @@ fields:
9
9
  required: true
10
10
  - {name: student, type: link, to: student, label: {id: Peserta}, compute: enrollment.student}
11
11
  - {name: batch, type: link, to: course_batch, label: {id: Angkatan}, compute: enrollment.batch}
12
+ # the name the roll screen shows on each line (screens/absen_kelas.rk)
13
+ - {name: student_name, type: data, label: {id: Nama peserta}, compute: enrollment.student.student_name}
12
14
  - name: status
13
15
  type: select
14
16
  label: {id: Kehadiran}
@@ -18,6 +18,7 @@ fields:
18
18
  required: true
19
19
  in_list: true
20
20
  - {name: instructor, type: link, to: user, label: {id: Akun pengajar}, compute: batch.instructor}
21
+ - {name: batch_title, type: data, label: {id: Nama angkatan}, compute: batch.batch_name}
21
22
  - name: session_no
22
23
  type: int
23
24
  label: {id: Pertemuan ke}
@@ -1,6 +1,6 @@
1
1
  # yaml-language-server: $schema=https://rangka-os.github.io/rangka-os/schema/0.5/module.json
2
2
  name: courses
3
- version: 1.1.0
3
+ version: 1.2.0
4
4
  title: {id: Kursus dan pelatihan, en: Courses and training}
5
5
  summary:
6
6
  id: Program kursus, angkatan, peserta, pendaftaran, jadwal pertemuan dan tagihannya.
@@ -0,0 +1,17 @@
1
+ # yaml-language-server: $schema=https://rangka-os.github.io/rangka-os/schema/0.5/screen.json
2
+ name: absen_kelas
3
+ type: roll
4
+ label: {id: Absen kelas, en: Class roll}
5
+ icon: users
6
+ # The instructor marks today's class from the phone (plans/layar-kerja.md §3 #5, contract 0030 §2 roll): every
7
+ # student starts present (flow session_of_the_day or session_fill_attendance), the instructor marks only who is
8
+ # excused, sick or absent, and saves; saving ticks "Absen sudah dicek" (flow session_attendance_checked). The
9
+ # meetings offered are the instructor's own (row scope) up to today whose attendance is not checked yet, newest
10
+ # first; one opens by itself. No submit: course_session is not a submittable document.
11
+ roles: [instructor]
12
+ device: phone
13
+ offline: queue
14
+ roll:
15
+ document: {model: course_session, find: "session_date <= today() && !attendance_taken", sort: "-session_date", title: batch_title, subtitle: session_date}
16
+ rows: {table: attendance, label: student_name, mark: {field: status, values: [present, excused, sick, absent], default: present}, note: note}
17
+ submit: false
@@ -17,4 +17,4 @@ steps:
17
17
  - update: inv
18
18
  if: f != null
19
19
  set:
20
- items: "event.items.filter(l, f.items.map(b, b.item == l.item ? b.delivered_qty - b.invoiced_qty : 0).sum() > 0.0005).map(l, {'name': l.name, 'item': l.item, 'description': l.description, 'uom': l.uom, 'rate': l.rate, 'discount': l.discount, 'pph23_exclude': l.pph23_exclude, 'rate_fx': l.rate_fx, 'qty': min(l.qty, f.items.map(b, b.item == l.item ? b.delivered_qty - b.invoiced_qty : 0).sum())})"
20
+ items: "event.items.filter(l, f.items.map(b, b.item == l.item ? b.delivered_qty - b.invoiced_qty : 0).sum() > 0.0005).map(l, {'name': l.name, 'item': l.item, 'description': l.description, 'uom': l.uom, 'rate': l.rate, 'discount': l.discount, 'pph23_exclude': l.pph23_exclude, 'ppn_exclude': l.ppn_exclude, 'rate_fx': l.rate_fx, 'qty': min(l.qty, f.items.map(b, b.item == l.item ? b.delivered_qty - b.invoiced_qty : 0).sum())})"
@@ -5,7 +5,7 @@
5
5
  # it. order_fulfilment keeps per order what was ordered, delivered, returned and invoiced, because a submitted order
6
6
  # cannot be written (K-p, contract 0022, will move this into the kernel's conversions).
7
7
  name: delivery
8
- version: 1.1.0
8
+ version: 1.1.1
9
9
  title: {id: Pengiriman dan retur, en: Delivery and returns}
10
10
  summary:
11
11
  id: Surat jalan, pemenuhan pesanan dan retur penjualan.
@@ -11,7 +11,7 @@ steps:
11
11
  - {find: customer_order, where: name == event.name, as: so}
12
12
  - update: so
13
13
  set:
14
- items: "event.items.map(i, {'name': i.name, 'item': i.item, 'description': i.description, 'qty': i.qty, 'uom': i.uom, 'rate': i.rate, 'tier_applied': i.tier_applied, 'price_tier': event.price_tier})"
14
+ items: "event.items.map(i, {'name': i.name, 'item': i.item, 'description': i.description, 'qty': i.qty, 'uom': i.uom, 'pph23_exclude': i.pph23_exclude, 'ppn_exclude': i.ppn_exclude, 'rate': i.rate, 'tier_applied': i.tier_applied, 'price_tier': event.price_tier})"
15
15
  - update: so
16
16
  set:
17
- items: "so.items.map(i, {'name': i.name, 'item': i.item, 'description': i.description, 'qty': i.qty, 'uom': i.uom, 'rate': i.tier_applied == i.price_tier ? i.rate : i.list_rate, 'tier_applied': i.price_tier, 'price_tier': i.price_tier})"
17
+ items: "so.items.map(i, {'name': i.name, 'item': i.item, 'description': i.description, 'qty': i.qty, 'uom': i.uom, 'pph23_exclude': i.pph23_exclude, 'ppn_exclude': i.ppn_exclude, 'rate': i.tier_applied == i.price_tier ? i.rate : i.list_rate, 'tier_applied': i.price_tier, 'price_tier': i.price_tier})"
@@ -11,7 +11,7 @@ steps:
11
11
  - {find: customer_order, where: name == event.name, as: so}
12
12
  - update: so
13
13
  set:
14
- items: "event.items.map(i, {'name': i.name, 'item': i.item, 'description': i.description, 'qty': i.qty, 'uom': i.uom, 'rate': i.rate, 'tier_applied': i.tier_applied, 'price_tier': event.price_tier})"
14
+ items: "event.items.map(i, {'name': i.name, 'item': i.item, 'description': i.description, 'qty': i.qty, 'uom': i.uom, 'pph23_exclude': i.pph23_exclude, 'ppn_exclude': i.ppn_exclude, 'rate': i.rate, 'tier_applied': i.tier_applied, 'price_tier': event.price_tier})"
15
15
  - update: so
16
16
  set:
17
- items: "so.items.map(i, {'name': i.name, 'item': i.item, 'description': i.description, 'qty': i.qty, 'uom': i.uom, 'rate': i.tier_applied == i.price_tier ? i.rate : i.list_rate, 'tier_applied': i.price_tier, 'price_tier': i.price_tier})"
17
+ items: "so.items.map(i, {'name': i.name, 'item': i.item, 'description': i.description, 'qty': i.qty, 'uom': i.uom, 'pph23_exclude': i.pph23_exclude, 'ppn_exclude': i.ppn_exclude, 'rate': i.tier_applied == i.price_tier ? i.rate : i.list_rate, 'tier_applied': i.price_tier, 'price_tier': i.price_tier})"
@@ -4,7 +4,7 @@
4
4
  # this module switches on live in their own models (customer, item, customer_order, sales_invoice, payment) behind
5
5
  # app_installed('distribution'); the flows here keep them current.
6
6
  name: distribution
7
- version: 1.0.0
7
+ version: 1.0.1
8
8
  title: {id: Distribusi, en: Distribution}
9
9
  summary:
10
10
  id: Catat giro masuk dari pelanggan grosir sampai cair.
@@ -128,10 +128,32 @@ fields:
128
128
  # Not read_only: a generic amend zeroes read-only fields, and a zero dpp_den would break ppn (kernel follow-up).
129
129
  - {name: dpp_num, type: int, label: {id: DPP nilai lain (pembilang)}, default: 'tax.dpp_num'}
130
130
  - {name: dpp_den, type: int, label: {id: DPP nilai lain (penyebut)}, default: 'tax.dpp_den'}
131
+ # The PPN base: the DPP, or with config tax.ppn_fee_only (kernel contract 0010 §8, default off) the fee part of it:
132
+ # a manpower firm that bills the workers' wages on their own line charges PPN on its fee only (DPP nilai lain, PMK
133
+ # 83/2012 art. 4). Like PPh 23 (pph23_lines_base / pph23_dp_base): the lines not marked ppn_exclude, as a share of
134
+ # subtotal less the header discount, minus the PPN base already taxed on the down-payment invoice this one deducts
135
+ # (that invoice's own ppn_base in proportion to down_payment; its DPP when it predates the field and charged PPN). Foreign documents
136
+ # take the share from the lines' rupiah twins. 'in': a kernel without the setting reads it as off, never as an
137
+ # error that would zero the PPN. Frozen at submit with the setting of that day; the ratio (11/12) and rate still apply.
138
+ - name: ppn_lines_base
139
+ type: currency
140
+ label: {id: Dasar PPN baris}
141
+ hidden: true
142
+ compute: "currency != '' && currency != 'IDR' ? (items.map(i, i.amount_fx_idr).sum() == 0 ? 0 : round((subtotal - discount_amount) * 1.0 * items.map(i, i.ppn_exclude ? 0 : i.amount_fx_idr).sum() / items.map(i, i.amount_fx_idr).sum())) : (subtotal == 0 ? 0 : round((subtotal - discount_amount) * 1.0 * items.map(i, i.ppn_exclude ? 0 : i.amount).sum() / subtotal))"
143
+ - name: ppn_dp_base
144
+ type: currency
145
+ label: {id: Dasar PPN di faktur uang muka}
146
+ hidden: true
147
+ # a DP invoice from before ppn_base existed reads 0 there although it charged PPN: its whole DPP was the base
148
+ compute: "dp_invoice == '' || dp_invoice.dpp == 0 ? 0 : round((dp_invoice.ppn_base == 0 && dp_invoice.ppn != 0 ? dp_invoice.dpp : dp_invoice.ppn_base) * 1.0 * down_payment / dp_invoice.dpp)"
149
+ - name: ppn_base
150
+ type: currency
151
+ label: {id: Dasar PPN}
152
+ compute: "!('ppn_fee_only' in tax && tax.ppn_fee_only) ? dpp : (ppn_lines_base > ppn_dp_base ? ppn_lines_base - ppn_dp_base : 0)"
131
153
  - name: ppn
132
154
  type: currency
133
- label: {id: PPN (DPP x rasio DPP nilai lain x tarif)}
134
- compute: "round(dpp * dpp_num / dpp_den * tax_rate / 100)"
155
+ label: {id: PPN (dasar PPN x rasio DPP nilai lain x tarif)}
156
+ compute: "round(ppn_base * dpp_num / dpp_den * tax_rate / 100)"
135
157
  - name: grand_total
136
158
  type: currency
137
159
  label: {id: Total}
@@ -214,7 +236,7 @@ fields:
214
236
  # Adjustments (discount_amount, down_payment) are entered in rupiah only, also on a foreign document: the ledger, the DP checks
215
237
  # and PPN read the IDR fields. Their foreign twins are derived here (IDR / exchange_rate), never entered.
216
238
  - {name: dpp_fx, type: money, currency_field: currency, rate_field: exchange_rate, label: {id: DPP (valas)}, compute: "currency != '' && currency != 'IDR' ? round(subtotal_fx - (discount_amount + down_payment) / exchange_rate, 2) : 0"}
217
- - {name: ppn_fx, type: money, currency_field: currency, rate_field: exchange_rate, label: {id: PPN (valas)}, compute: "round(dpp_fx * dpp_num / dpp_den * tax_rate / 100, 2)"}
239
+ - {name: ppn_fx, type: money, currency_field: currency, rate_field: exchange_rate, label: {id: PPN (valas)}, compute: "dpp == 0 ? 0 : round(dpp_fx * (ppn_base * 1.0 / dpp) * dpp_num / dpp_den * tax_rate / 100, 2)"}
218
240
  - {name: grand_total_fx, type: money, currency_field: currency, rate_field: exchange_rate, label: {id: Total (valas)}, compute: "dpp_fx + ppn_fx"}
219
241
  - {name: retention_amount_fx, type: money, currency_field: currency, rate_field: exchange_rate, label: {id: Retensi ditahan (valas)}, compute: "round(dpp_fx * retention_percent / 100, 2)"}
220
242
  - {name: pph23_amount_fx, type: money, currency_field: currency, rate_field: exchange_rate, label: {id: PPh 23 dipotong (valas)}, compute: "pph23_applies && dpp != 0 ? round(dpp_fx * (pph23_dpp * 1.0 / dpp * pph23_rate / 100), 2) : 0"}
@@ -378,6 +400,11 @@ rules:
378
400
  on: save
379
401
  check: billing_milestone == '' || billing_milestone.state != 'invoiced' || billing_milestone.sales_invoice == name
380
402
  message: {id: Termin ini sudah ditagih di faktur lain}
403
+ - name: ppn_dp_base_above_lines
404
+ on: save
405
+ level: warn
406
+ check: "!('ppn_fee_only' in tax && tax.ppn_fee_only) || ppn_dp_base <= ppn_lines_base"
407
+ message: {id: 'Dasar PPN di faktur uang muka lebih besar dari dasar PPN baris faktur ini; pisahkan baris upah di faktur uang muka juga'}
381
408
  - name: dp_base_above_lines
382
409
  on: save
383
410
  level: warn
@@ -467,7 +494,7 @@ views:
467
494
  fields: [items]
468
495
  - section: {id: Pajak & potongan}
469
496
  columns:
470
- - [discount_amount, dp_invoice, down_payment, tax_rate, dpp_num, dpp_den, ppn]
497
+ - [discount_amount, dp_invoice, down_payment, tax_rate, dpp_num, dpp_den, ppn_base, ppn]
471
498
  - [pph23_applies, pph23_rate, pph23_amount, retention_percent, retention_of, retention_amount]
472
499
  - section: {id: Ringkasan}
473
500
  columns:
@@ -43,6 +43,13 @@ fields:
43
43
  label: {id: Bukan dasar PPh 23}
44
44
  help: {id: 'Centang untuk baris gaji tenaga kerja yang dirinci terpisah atau penggantian biaya'}
45
45
  default: 'false'
46
+ # The workers' wages billed on their own line: outside the PPN base when the org charges PPN on its fee only
47
+ # (config tax.ppn_fee_only, PMK 83/2012). "Excluded" for the same reason as pph23_exclude: an old line reads false.
48
+ - name: ppn_exclude
49
+ type: check
50
+ label: {id: Upah tenaga kerja (di luar dasar PPN)}
51
+ help: {id: 'Centang untuk baris upah pekerja yang dirinci terpisah; hanya berlaku bila usaha memakai PPN atas fee'}
52
+ default: 'false'
46
53
 
47
54
  - {name: rate_fx, type: money, currency_field: currency, rate_field: exchange_rate, label: {id: Harga (valas)}, default: '0'}
48
55
  - {name: amount_fx, type: money, currency_field: currency, rate_field: exchange_rate, label: {id: Jumlah (valas)}, compute: "round(qty * rate_fx * (1 - discount / 100), 2)"}
@@ -1,6 +1,6 @@
1
1
  # yaml-language-server: $schema=https://rangka-os.github.io/rangka-os/schema/0.5/module.json
2
2
  name: invoicing
3
- version: 1.6.1
3
+ version: 1.7.0
4
4
  title: {id: Faktur, en: Invoicing}
5
5
  summary:
6
6
  id: Buat faktur penjualan, pilih cara bayar termasuk QRIS, dan kirim pengingat tagihan.
@@ -120,8 +120,21 @@
120
120
  <tr><td>Subtotal</td><td class="num">{{rupiah .Doc.subtotal}}</td></tr>
121
121
  {{if .Doc.discount_amount}}<tr><td>Diskon</td><td class="num">-{{rupiah .Doc.discount_amount}}</td></tr>{{end}}
122
122
  {{if .Doc.down_payment}}<tr><td>Uang muka</td><td class="num">-{{rupiah .Doc.down_payment}}</td></tr>{{end}}
123
- {{if taxrate .Doc .Tax}}<tr class="small"><td>DPP</td><td class="num">{{rupiah .Doc.dpp}}</td></tr>{{end}}
124
- {{if taxrate .Doc .Tax}}<tr class="small"><td>PPN {{number (taxrate .Doc .Tax)}}% (DPP nilai lain {{.Doc.dpp_num}}/{{.Doc.dpp_den}})</td><td class="num">{{rupiah .Doc.ppn}}</td></tr>{{end}}
123
+ {{if taxrate .Doc .Tax}}<tr class="small"><td>DPP</td><td class="num">{{rupiah .Doc.dpp}}</td></tr>
124
+ {{- /* As on the faktur pajak (Coretax, PMK 131/2024): the base, then DPP nilai lain, then PPN = rate x DPP nilai lain.
125
+ An invoice of an org with PPN on the fee only (tax.ppn_fee_only, PMK 83/2012) shows the wages left out first; an
126
+ invoice from before ppn_base existed was taxed on its whole DPP. */}}
127
+ {{- /* the DPP only for a document from before ppn_base that charged PPN (as ppn_dp_base reads it); a base of 0 with
128
+ no PPN (wages only, or a settlement whose base the down payment used up) is that 0 */}}
129
+ {{- $pb := .Doc.dpp}}{{if or .Doc.ppn_base (not .Doc.ppn)}}{{$pb = or .Doc.ppn_base 0}}{{end}}
130
+ {{- if ne (dec $pb) (dec .Doc.dpp)}}
131
+ <tr class="small"><td>Upah tenaga kerja di luar dasar PPN (PMK 83/2012)</td><td class="num">-{{rupiah (sub .Doc.dpp $pb)}}</td></tr>
132
+ <tr class="small"><td>Dasar PPN</td><td class="num">{{rupiah $pb}}</td></tr>
133
+ {{- end}}
134
+ {{- if ne .Doc.dpp_num .Doc.dpp_den}}
135
+ <tr class="small"><td>DPP nilai lain {{.Doc.dpp_num}}/{{.Doc.dpp_den}}</td><td class="num">{{rupiah (round (div (mul $pb .Doc.dpp_num) .Doc.dpp_den))}}</td></tr>
136
+ {{- end}}
137
+ <tr class="small"><td>PPN {{number (taxrate .Doc .Tax)}}%</td><td class="num">{{rupiah .Doc.ppn}}</td></tr>{{end}}
125
138
  <tr class="grand"><td>Total</td><td class="num">{{rupiah .Doc.grand_total}}</td></tr>
126
139
  {{if .Doc.retention_amount}}<tr class="small"><td>Retensi {{number .Doc.retention_percent}}% ditahan</td><td class="num">-{{rupiah .Doc.retention_amount}}</td></tr>{{end}}
127
140
  {{if .Doc.pph23_amount}}<tr class="small"><td>PPh 23 dipotong pelanggan{{if .Doc.pph23_dpp}} (dasar {{rupiah .Doc.pph23_dpp}}){{end}}</td><td class="num">-{{rupiah .Doc.pph23_amount}}</td></tr>{{end}}
@@ -61,6 +61,8 @@ fields:
61
61
  - name: po_date
62
62
  type: date
63
63
  label: {id: Tanggal PO}
64
+ # a salesman takes the order at the shop the same day; a PO from an email is dated by hand
65
+ default: today()
64
66
  required: true
65
67
  - name: work_order
66
68
  type: data
@@ -47,3 +47,13 @@ fields:
47
47
  type: currency
48
48
  label: {id: Jumlah}
49
49
  compute: round(qty * rate)
50
+ # The workers' wages line, carried from the quotation and on to the invoice by the kernel conversions: outside the
51
+ # PPh 23 base and, with config tax.ppn_fee_only, outside the PPN base (PMK 83/2012).
52
+ - name: pph23_exclude
53
+ type: check
54
+ label: {id: Bukan dasar PPh 23}
55
+ default: 'false'
56
+ - name: ppn_exclude
57
+ type: check
58
+ label: {id: Upah tenaga kerja (di luar dasar PPN)}
59
+ default: 'false'
@@ -1,6 +1,6 @@
1
1
  # yaml-language-server: $schema=https://rangka-os.github.io/rangka-os/schema/0.5/module.json
2
2
  name: orders
3
- version: 1.1.0
3
+ version: 1.2.0
4
4
  title: {id: Pesanan pelanggan, en: Customer orders}
5
5
  summary:
6
6
  id: Catat pesanan pelanggan sebelum dikirim dan ditagih.
@@ -0,0 +1,30 @@
1
+ # yaml-language-server: $schema=https://rangka-os.github.io/rangka-os/schema/0.5/flow.json
2
+ # Head office set (or moved earlier) an outlet's moka_api_from: the outlet's held Moka lines dated on or after it become
3
+ # staged and go into the next daily recap (flow moka_daily_sales). Held lines are what the API polled before the gate
4
+ # opened (audit moka-guard H1): without this they would be counted by neither the API nor the export. Lines dated
5
+ # before the date stay held (the export counts those days). A held line without item (head office emptied it) goes back
6
+ # to unmapped instead of staged, so saving the outlet is never refused by rule staged_has_outlet_and_item (audit
7
+ # moka-guard D2); flow moka_held_release catches held lines this run did not see (D1). Lines of the outlet from the
8
+ # date on that are still unmapped (an unknown item polled while the outlet was on the export, which was not told then:
9
+ # D3) are told to head office now, so the day is not recapped without them unnoticed (audit held-release A2).
10
+ name: moka_api_opened
11
+ label: {id: Baris Moka yang ditahan dilepas saat outlet mulai pakai API}
12
+ on: outlet.updated
13
+ if: "event.moka_api_from != null && event.moka_api_from != ''"
14
+ steps:
15
+ - find_all: moka_sale_line
16
+ where: "outlet == event.name && status == 'held' && date >= event.moka_api_from"
17
+ as: held
18
+ - for_each: held
19
+ as: l
20
+ do:
21
+ - update: l
22
+ set:
23
+ status: "l.item != '' ? 'staged' : 'unmapped'"
24
+ - find_all: moka_sale_line
25
+ where: "outlet == event.name && status == 'unmapped' && date >= event.moka_api_from"
26
+ as: waiting
27
+ - notify: head_office
28
+ if: size(waiting) > 0
29
+ channel: email
30
+ template: {id: '{event.outlet_name} mulai pakai API Moka: {size(waiting)} baris Moka belum dipetakan, petakan di Baris penjualan Moka'}
@@ -0,0 +1,35 @@
1
+ # yaml-language-server: $schema=https://rangka-os.github.io/rangka-os/schema/0.5/flow.json
2
+ # Every hour at :10 (before the recap at :15, flow moka_daily_sales) and from the flow list: held Moka lines whose
3
+ # outlet now counts the API for their day (outlet.moka_api_from set, on or before the line's date) become staged.
4
+ # Flow moka_api_opened does this when head office saves the outlet; this run catches the rest (audit moka-guard D1): a
5
+ # held line head office moved to an outlet already on the API, or a line a poll wrote while the outlet was being
6
+ # saved. A held line without item (head office emptied it) goes back to unmapped instead (rule
7
+ # staged_has_outlet_and_item, D2). Only outlets whose API has started (moka_api_from <= today) are read, and only lines
8
+ # from the earliest of their dates on (audit held-release A1: an outlet with a future date or a long export period
9
+ # must not fill the 2000-line read), and each line against its own outlet's date in the read itself (A1': a held line
10
+ # before a later gate is never released, so it must not take a place in the 2000); if 2000 lines still come back,
11
+ # head office is told and the next runs go on with the rest.
12
+ # A held line without outlet is not read: it waits until head office gives it an outlet.
13
+ name: moka_held_release
14
+ label: {id: Baris Moka yang ditahan dilepas bila outlet sudah pakai API}
15
+ schedule: '10 * * * *'
16
+ steps:
17
+ - find_all: outlet
18
+ where: "moka_api_from != '' && moka_name != '' && moka_api_from <= today()"
19
+ sort: moka_api_from
20
+ as: open
21
+ - find_all: moka_sale_line
22
+ if: size(open) > 0
23
+ where: "status == 'held' && outlet in open.map(o, o.name) && date >= open[0].moka_api_from && open.exists(o, o.name == outlet && o.moka_api_from <= date)"
24
+ limit: 2000
25
+ as: held
26
+ - for_each: "size(open) > 0 ? held : []"
27
+ as: l
28
+ do:
29
+ - update: l
30
+ set:
31
+ status: "l.item != '' ? 'staged' : 'unmapped'"
32
+ - notify: head_office
33
+ if: size(open) > 0 && size(held) >= 2000
34
+ channel: email
35
+ template: {id: 'Lebih dari 2000 baris Moka masih ditahan; dilepas bertahap tiap jam. Cek tanggal Mulai pakai API Moka di outlet'}
@@ -2,22 +2,31 @@
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
3
  # recap (flow moka_daily_sales). The unmapped refund lines of the same Moka checkout (same transaction and checkout,
4
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.
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.
6
7
  name: moka_line_mapped
7
8
  label: {id: Baris Moka yang sudah dipetakan siap direkap}
8
9
  on: moka_sale_line.updated
9
10
  if: event.status == 'unmapped' && event.outlet != '' && event.item != ''
10
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
11
16
  - find: moka_sale_line
12
17
  where: name == event.name
13
18
  as: rec
14
19
  - update: rec
15
20
  set:
16
- status: "'staged'"
21
+ status: "open_for != null ? 'staged' : 'held'"
17
22
  - find_all: moka_sale_line
18
23
  if: event.qty > 0
19
24
  where: "name != event.name && transaction == event.transaction && qty < 0 && status == 'unmapped' && (event.checkout != '' ? checkout == event.checkout : (checkout == '' && description == 'Retur ' + event.description))"
20
25
  as: refunds
26
+ - find: outlet
27
+ if: event.qty > 0
28
+ where: name == event.outlet
29
+ as: outlet_gate
21
30
  - for_each: refunds
22
31
  if: event.qty > 0
23
32
  as: r
@@ -26,4 +35,4 @@ steps:
26
35
  set:
27
36
  outlet: event.outlet
28
37
  item: event.item
29
- status: "'staged'"
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'}
@@ -21,11 +21,21 @@
21
21
  # new transaction (unmapped lines are told about line by line), two per checkout for a refund.
22
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
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.
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).
25
35
  name: moka_transaction_staged
26
36
  label: {id: Transaksi Moka masuk jadi baris penjualan}
27
37
  on: moka.transaction_created
28
- if: "'transaction_id' in event && 'created_at' in event && 'checkouts' in event && 'outlet_id' in event"
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"
29
39
  idempotency: "string(event.transaction_id) + ':' + string(event.checkouts.map(c, 'refunded_quantity' in c && c.refunded_quantity != null ? c.refunded_quantity : 0).sum())"
30
40
  steps:
31
41
  - find: moka_transaction
@@ -53,6 +63,11 @@ steps:
53
63
  total_collected: "'total_collected' in event ? event.total_collected : 0"
54
64
  refunded: "'is_refunded' in event && event.is_refunded == true"
55
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
56
71
  - for_each: event.checkouts
57
72
  if: known == null
58
73
  as: c
@@ -79,11 +94,11 @@ steps:
79
94
  gross: c.total_price
80
95
  discount: "min('discount_amount' in c ? c.discount_amount : 0, c.total_price)"
81
96
  refund: "0"
82
- 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')"
83
98
  - create: moka_sale_line
84
99
  # a refund line only when it returns money: a refund of a free item (100% discount) changes nothing and a line of
85
100
  # qty < 0 without refund is refused by outlet_sales; never more than the quantity sold
86
- if: "c.quantity > 0 && c.total_price >= 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)) * min(c.refunded_quantity, c.quantity) / c.quantity) > 0"
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"
87
102
  set:
88
103
  transaction: tx.name
89
104
  checkout: "('uuid' in c && c.uuid != null && string(c.uuid) != '' ? string(c.uuid) : ('id' in c && c.id != null ? string(c.id) : ''))"
@@ -96,20 +111,25 @@ steps:
96
111
  gross: "0"
97
112
  discount: "0"
98
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)"
99
- status: "tx.outlet == '' || (by_sku == null && by_item_name == null) ? 'unmapped' : 'staged'"
114
+ status: "tx.outlet == '' || (by_sku == null && by_item_name == null) ? 'unmapped' : (api_open != null ? 'staged' : 'held')"
100
115
  - notify: head_office
101
- if: "tx.outlet != '' && c.quantity > 0 && c.total_price >= 0 && by_sku == null && by_item_name == null"
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"
102
118
  channel: email
103
119
  template: {id: 'Moka {tx.receipt_no} ({tx.moka_outlet}, {tx.date}): barang "{c.item_name}" belum dikenali, petakan di Baris penjualan Moka'}
104
120
  - notify: head_office
105
- if: "known == null && event.checkouts.map(c, c.quantity > 0 && c.total_price >= 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"
106
122
  channel: email
107
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'}
108
124
  - notify: head_office
109
125
  if: "known == null && tx.outlet == ''"
110
126
  channel: email
111
127
  template: {id: 'Moka {tx.receipt_no} ({tx.moka_outlet}, {tx.date}): outlet belum dikenali, petakan barisnya di Baris penjualan Moka'}
112
- # a known transaction that changed in Moka: refunds made after the first poll
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
113
133
  - for_each: event.checkouts
114
134
  if: known != null
115
135
  as: c
@@ -126,7 +146,7 @@ steps:
126
146
  where: "transaction == known.name && qty < 0 && checkout == sold.checkout && description == 'Retur ' + sold.description"
127
147
  as: returned
128
148
  - create: moka_sale_line
129
- if: "sold != null && 'refunded_quantity' in c && 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"
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"
130
150
  set:
131
151
  transaction: known.name
132
152
  checkout: sold.checkout
@@ -139,10 +159,10 @@ steps:
139
159
  gross: "0"
140
160
  discount: "0"
141
161
  refund: "round((sold.gross - sold.discount) * (min(c.refunded_quantity, sold.qty) + returned.map(l, l.qty).sum()) / sold.qty)"
142
- status: "sold.status == 'unmapped' || sold.outlet == '' || sold.item == '' ? 'unmapped' : 'staged'"
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')"
143
163
  as: late
144
164
  - notify: head_office
145
- if: "sold != null && 'refunded_quantity' in c && 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"
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"
146
166
  channel: email
147
167
  template: {id: 'Moka {known.receipt_no} ({known.moka_outlet}): retur susulan {sold.description} dicatat di Baris penjualan Moka'}
148
168
  - update: known