@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
@@ -0,0 +1,231 @@
1
+ #!/usr/bin/env python3
2
+ """A local stand-in for Xendit in test mode (fixed virtual accounts and dynamic QRIS), for demos and tests without a
3
+ Xendit account.
4
+
5
+ XENDIT_MOCK_SECRET_KEY=xnd_development_dummy_demo XENDIT_MOCK_CALLBACK_TOKEN=dummy-cb-demo \
6
+ python3 xendit/mock/xendit_mock.py --port 8902 \
7
+ --va-callback-url http://127.0.0.1:8790/api/xendit/va_paid --qr-callback-url http://127.0.0.1:8790/api/xendit/qr_paid
8
+
9
+ Dummy keys only: the key must start with xnd_development_ and say it is a dummy (a part "dummy" or "test" between
10
+ - _ or .), and the callback token too. Keys come from the environment, never argv (`ps` shows argv). It listens on
11
+ 127.0.0.1 only.
12
+
13
+ Stdlib only. The request and callback shapes follow Xendit's API and the connector `xendit` (connector.rk):
14
+
15
+ - POST /callback_virtual_accounts (Basic auth: secret key, empty password): a fixed VA. A second request with the same
16
+ external_id answers the VA it already made (one VA per invoice), so a retried request makes no second VA.
17
+ - POST /qr_codes (Basic auth): a dynamic QRIS, reference_id = the invoice number.
18
+ - POST /callback_virtual_accounts/external_id=<id>/simulate_payment {amount}: the payer pays the VA (Xendit test
19
+ mode has the same endpoint). The mock sends the VA callback (x-callback-token header) and answers with the callback's
20
+ HTTP status. A closed VA refuses another amount (400 INVALID_AMOUNT).
21
+ - POST /qr_codes/<qr id>/payments/simulate {amount}: the payer pays the QRIS; sends the qr.payment callback.
22
+ - POST /simulate/redeliver/<payment id>[?token=<other>]: sends a callback that was already sent once more (Xendit
23
+ retries a callback that did not get a 2xx), optionally with another token, to test the receiver's idempotency and
24
+ its token check.
25
+ - GET /calls: every request it received (Authorization redacted), for tests. GET /healthz.
26
+ """
27
+ from __future__ import annotations
28
+
29
+ import argparse
30
+ import base64
31
+ import hmac
32
+ import json
33
+ import os
34
+ import re
35
+ import sys
36
+ import threading
37
+ import urllib.error
38
+ import urllib.parse
39
+ import urllib.request
40
+ import uuid
41
+ from datetime import datetime, timedelta, timezone
42
+ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
43
+
44
+ BANKS = {"BCA": "39108", "BNI": "8808", "BRI": "26215", "MANDIRI": "88908", "PERMATA": "8214", "BSI": "6059", "CIMB": "93490"}
45
+
46
+
47
+ def now_iso() -> str:
48
+ return datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.000Z")
49
+
50
+
51
+ class State:
52
+ def __init__(self, secret, token, va_url, qr_url, owner_id="5f0000000000000000000001"):
53
+ self.secret, self.token, self.va_url, self.qr_url, self.owner_id = secret, token, va_url, qr_url, owner_id
54
+ self.vas = {} # external_id -> VA
55
+ self.qrs = {} # qr id -> QR
56
+ self.sent = {} # payment id -> (kind, payload)
57
+ self.calls = []
58
+ self.seq = 0
59
+ self.lock = threading.Lock()
60
+
61
+
62
+ def deliver(state: State, kind: str, payload: dict, token: str | None = None) -> int:
63
+ """POST one callback with the x-callback-token header; the HTTP status, 0 when unreachable."""
64
+ url = state.va_url if kind == "va" else state.qr_url
65
+ if not url:
66
+ return 0
67
+ req = urllib.request.Request(url, data=json.dumps(payload).encode(), method="POST",
68
+ headers={"Content-Type": "application/json", "x-callback-token": token or state.token})
69
+ try:
70
+ with urllib.request.urlopen(req, timeout=15) as r:
71
+ return r.status
72
+ except urllib.error.HTTPError as e:
73
+ return e.code
74
+ except OSError:
75
+ return 0
76
+
77
+
78
+ def handler(state: State):
79
+ class H(BaseHTTPRequestHandler):
80
+ def log_message(self, *a):
81
+ pass
82
+
83
+ def send(self, code, obj):
84
+ raw = json.dumps(obj).encode()
85
+ self.send_response(code)
86
+ self.send_header("Content-Type", "application/json")
87
+ self.send_header("Content-Length", str(len(raw)))
88
+ self.end_headers()
89
+ self.wfile.write(raw)
90
+
91
+ def authed(self) -> bool:
92
+ h = self.headers.get("Authorization", "")
93
+ want = "Basic " + base64.b64encode((state.secret + ":").encode()).decode()
94
+ return hmac.compare_digest(h, want)
95
+
96
+ def json_body(self, raw):
97
+ try:
98
+ return json.loads(raw or b"{}")
99
+ except ValueError:
100
+ return None
101
+
102
+ def do_GET(self):
103
+ path = urllib.parse.urlparse(self.path).path
104
+ if path == "/healthz":
105
+ return self.send(200, {"ok": True})
106
+ if path == "/calls":
107
+ with state.lock:
108
+ return self.send(200, state.calls)
109
+ self.send(404, {"error_code": "NOT_FOUND"})
110
+
111
+ def do_POST(self):
112
+ u = urllib.parse.urlparse(self.path)
113
+ raw = self.rfile.read(int(self.headers.get("Content-Length") or 0))
114
+ with state.lock:
115
+ state.calls.append({"method": "POST", "path": u.path, "body": raw.decode(errors="replace"),
116
+ "headers": {k: ("[redacted]" if k.lower() == "authorization" else v) for k, v in self.headers.items()}})
117
+ body = self.json_body(raw)
118
+ if body is None:
119
+ return self.send(400, {"error_code": "API_VALIDATION_ERROR", "message": "body is not JSON"})
120
+
121
+ if u.path == "/callback_virtual_accounts":
122
+ if not self.authed():
123
+ return self.send(401, {"error_code": "INVALID_API_KEY"})
124
+ ext, bank = str(body.get("external_id") or ""), str(body.get("bank_code") or "")
125
+ if not ext or bank not in BANKS:
126
+ return self.send(400, {"error_code": "API_VALIDATION_ERROR", "message": "external_id and a known bank_code are required"})
127
+ with state.lock:
128
+ va = state.vas.get(ext)
129
+ if va is None:
130
+ state.seq += 1
131
+ amount = int(body.get("expected_amount") or 0)
132
+ va = {"id": uuid.uuid4().hex[:24], "owner_id": state.owner_id, "external_id": ext, "bank_code": bank,
133
+ "merchant_code": BANKS[bank], "name": str(body.get("name") or ""), "account_number": BANKS[bank] + f"{state.seq:011d}",
134
+ "expected_amount": amount, "is_closed": bool(body.get("is_closed", amount > 0)),
135
+ "is_single_use": bool(body.get("is_single_use", False)), "status": "PENDING", "currency": "IDR",
136
+ "expiration_date": body.get("expiration_date") or (datetime.now(timezone.utc) + timedelta(days=31)).strftime("%Y-%m-%dT%H:%M:%S.000Z")}
137
+ state.vas[ext] = va
138
+ return self.send(200, va)
139
+
140
+ if u.path == "/qr_codes":
141
+ if not self.authed():
142
+ return self.send(401, {"error_code": "INVALID_API_KEY"})
143
+ ref, amount = str(body.get("reference_id") or ""), int(body.get("amount") or 0)
144
+ if not ref or amount <= 0:
145
+ return self.send(400, {"error_code": "API_VALIDATION_ERROR", "message": "reference_id and amount are required"})
146
+ qid = "qr_" + uuid.uuid4().hex[:24]
147
+ qr = {"id": qid, "reference_id": ref, "business_id": state.owner_id, "type": "DYNAMIC", "currency": "IDR", "amount": amount,
148
+ "channel_code": "ID_DANA", "status": "ACTIVE", "qr_string": f"00020101021226660014ID.CO.QRIS.WWW0215ID{qid[3:19]}5204599953033605404{amount}5802ID6304MOCK",
149
+ "expires_at": body.get("expires_at") or (datetime.now(timezone.utc) + timedelta(days=2)).strftime("%Y-%m-%dT%H:%M:%S.000Z"), "created": now_iso()}
150
+ with state.lock:
151
+ state.qrs[qid] = qr
152
+ return self.send(201, qr)
153
+
154
+ m = re.fullmatch(r"/callback_virtual_accounts/external_id=([^/]+)/simulate_payment", u.path)
155
+ if m:
156
+ ext = urllib.parse.unquote(m.group(1))
157
+ va = state.vas.get(ext)
158
+ if not va:
159
+ return self.send(404, {"error_code": "CALLBACK_VIRTUAL_ACCOUNT_NOT_FOUND_ERROR"})
160
+ if va["status"] != "PENDING":
161
+ return self.send(400, {"error_code": "INACTIVE_VIRTUAL_ACCOUNT_ERROR", "message": "a single-use VA is paid once"})
162
+ amount = int(body.get("amount") or va["expected_amount"])
163
+ if va["is_closed"] and amount != va["expected_amount"]:
164
+ return self.send(400, {"error_code": "INVALID_AMOUNT", "message": "a closed VA takes exactly its expected amount"})
165
+ pid = uuid.uuid4().hex[:24]
166
+ payload = {"id": uuid.uuid4().hex[:24], "payment_id": pid, "callback_virtual_account_id": va["id"], "owner_id": va["owner_id"],
167
+ "external_id": ext, "account_number": va["account_number"], "bank_code": va["bank_code"], "amount": amount,
168
+ "transaction_timestamp": now_iso(), "merchant_code": va["merchant_code"], "currency": "IDR"}
169
+ with state.lock:
170
+ state.sent[pid] = ("va", payload)
171
+ if va["is_single_use"]:
172
+ va["status"] = "INACTIVE"
173
+ return self.send(200, {"payment_id": pid, "callback_status": deliver(state, "va", payload)})
174
+
175
+ m = re.fullmatch(r"/qr_codes/([^/]+)/payments/simulate", u.path)
176
+ if m:
177
+ qr = state.qrs.get(m.group(1))
178
+ if not qr:
179
+ return self.send(404, {"error_code": "DATA_NOT_FOUND"})
180
+ if qr["status"] != "ACTIVE":
181
+ return self.send(400, {"error_code": "INACTIVE_QR_CODE", "message": "a dynamic QR is paid once"})
182
+ amount = int(body.get("amount") or qr["amount"])
183
+ pid = "qrpy_" + uuid.uuid4().hex[:24]
184
+ payload = {"event": "qr.payment", "business_id": qr["business_id"], "created": now_iso(),
185
+ "data": {"id": pid, "qr_id": qr["id"], "reference_id": qr["reference_id"], "type": "DYNAMIC", "currency": "IDR",
186
+ "amount": amount, "channel_code": qr["channel_code"], "status": "SUCCEEDED", "created": now_iso()}}
187
+ with state.lock:
188
+ state.sent[pid] = ("qr", payload)
189
+ qr["status"] = "INACTIVE"
190
+ return self.send(200, {"payment_id": pid, "callback_status": deliver(state, "qr", payload)})
191
+
192
+ m = re.fullmatch(r"/simulate/redeliver/([^/]+)", u.path)
193
+ if m:
194
+ sent = state.sent.get(m.group(1))
195
+ if not sent:
196
+ return self.send(404, {"error_code": "NOT_FOUND"})
197
+ token = urllib.parse.parse_qs(u.query).get("token", [None])[0]
198
+ return self.send(200, {"callback_status": deliver(state, sent[0], sent[1], token)})
199
+
200
+ self.send(404, {"error_code": "NOT_FOUND"})
201
+ return H
202
+
203
+
204
+ def dummy(value: str) -> bool:
205
+ """True for a value that says it is a dummy (a part dummy or test): a real key or token must never reach the mock."""
206
+ return bool(re.search(r"(^|[-_.])(dummy|test)([-_.]|$)", value, re.IGNORECASE))
207
+
208
+
209
+ def main(argv=None):
210
+ ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
211
+ ap.add_argument("--port", type=int, default=8902)
212
+ ap.add_argument("--va-callback-url", default="", help="where VA callbacks go (the receiver's va_paid hook)")
213
+ ap.add_argument("--qr-callback-url", default="", help="where QRIS callbacks go (the receiver's qr_paid hook)")
214
+ a = ap.parse_args(argv)
215
+ secret = os.environ.get("XENDIT_MOCK_SECRET_KEY", "")
216
+ token = os.environ.get("XENDIT_MOCK_CALLBACK_TOKEN", "")
217
+ if not (secret.startswith("xnd_development_") and dummy(secret)):
218
+ ap.error("set XENDIT_MOCK_SECRET_KEY to a dummy test key (xnd_development_ and a part dummy, e.g. xnd_development_dummy_demo); never a real key")
219
+ if not dummy(token):
220
+ ap.error("set XENDIT_MOCK_CALLBACK_TOKEN to a dummy token (a part dummy or test, e.g. dummy-cb-demo)")
221
+ srv = ThreadingHTTPServer(("127.0.0.1", a.port), handler(State(secret, token, a.va_callback_url, a.qr_callback_url)))
222
+ print(f"xendit mock on http://127.0.0.1:{srv.server_address[1]} (VA callbacks to {a.va_callback_url or '-'}, QRIS to {a.qr_callback_url or '-'})", flush=True)
223
+ try:
224
+ srv.serve_forever()
225
+ except KeyboardInterrupt:
226
+ pass
227
+ return 0
228
+
229
+
230
+ if __name__ == "__main__":
231
+ sys.exit(main())
@@ -0,0 +1,12 @@
1
+ # yaml-language-server: $schema=https://rangka-os.github.io/rangka-os/schema/0.5/flow.json
2
+ # The owner confirms a line that is money already on the books (booked_payment): the line is "Sudah tercatat" against
3
+ # that payment. Nothing is drafted or paid: the money was booked when the payment was submitted (giro received, gateway
4
+ # notification). booked_payment is unique, so one payment is on one line only.
5
+ name: bank_transaction_booked
6
+ label: {id: Mutasi dikonfirmasi sebagai uang yang sudah tercatat}
7
+ on: bank_transaction.updated
8
+ if: event.status == 'confirmed' && event.booked_payment != '' && event.payment == ''
9
+ steps:
10
+ - {find: bank_transaction, where: name == event.name, as: line}
11
+ - update: line
12
+ set: {status: "'booked'", suggested_invoice: "''"}
@@ -0,0 +1,11 @@
1
+ # yaml-language-server: $schema=https://rangka-os.github.io/rangka-os/schema/0.5/flow.json
2
+ # The payment a line was booked against is cancelled (a giro bounced, a gateway payment reversed): the line goes back
3
+ # to unmatched, without the payment, and can be matched again.
4
+ name: bank_transaction_booked_released
5
+ label: {id: Mutasi kembali belum cocok saat pembayaran tercatatnya dibatalkan}
6
+ on: payment.cancelled
7
+ steps:
8
+ - {find: bank_transaction, where: booked_payment == event.name, as: line}
9
+ - update: line
10
+ if: line != null
11
+ set: {status: "'unmatched'", booked_payment: "''"}
@@ -12,8 +12,18 @@ steps:
12
12
  - find: payment
13
13
  where: "event.amended_from != '' && name == event.amended_from && bank_transaction == event.bank_transaction"
14
14
  as: source
15
+ # Checked again at the moment the money is booked (audit rel-uang-e2e r8 H11): another received payment of this amount
16
+ # from the same customer, submitted and held by no statement line, may be this very money (an instalment finance
17
+ # booked after the line was confirmed). Then the submit is refused; the owner sets the line against that payment.
18
+ - {find_all: bank_transaction, where: "status == 'booked'", as: held}
19
+ - find_all: payment
20
+ where: >-
21
+ docstatus == 1 && direction == 'receive' && method != 'sales_return' && amount == event.amount &&
22
+ customer == event.customer && bank_transaction == '' && name != event.name &&
23
+ !(name in held.map(l, l.booked_payment))
24
+ as: same
15
25
  - create: bank_transaction_claim
16
26
  set:
17
27
  bank_transaction: event.bank_transaction
18
28
  payment: event.name
19
- valid: "line != null && line.amount == event.amount && (line.draft_payment == event.before.name || source != null)"
29
+ valid: "line != null && line.amount == event.amount && (line.draft_payment == event.before.name || source != null) && size(same) == 0"
@@ -8,7 +8,7 @@
8
8
  name: bank_transaction_confirm
9
9
  label: {id: Mutasi dikonfirmasi jadi pembayaran}
10
10
  on: bank_transaction.updated
11
- if: event.status == 'confirmed' && event.payment == '' && event.suggested_invoice != ''
11
+ if: event.status == 'confirmed' && event.payment == '' && event.suggested_invoice != '' && event.booked_payment == ''
12
12
  steps:
13
13
  - {find: payment, where: "docstatus == 0 && bank_transaction == event.name", as: draft}
14
14
  # a live payment already names the line (it is matched then, or a payment typed by hand carries the line in its
@@ -16,14 +16,32 @@ steps:
16
16
  - {find: payment, where: "docstatus == 1 && direction == 'receive' && (bank_transaction == event.name || reference == event.name)", as: paid}
17
17
  - {find: sales_invoice, where: name == event.suggested_invoice, as: inv}
18
18
  - {find: bank_transaction, where: name == event.name, as: line}
19
+ # Checked again now (audit rel-uang-e2e r7 H10): a payment of this amount from the invoice's customer booked after the
20
+ # suggestion was made, which no statement line holds yet, may be this very money. Then nothing is drafted: a non-cash
21
+ # one becomes the line's Sudah tercatat suggestion, a cash one leaves the line Belum cocok for the owner.
22
+ - {find_all: bank_transaction, where: "status == 'booked'", as: held}
23
+ - {find_all: bank_transaction, where: "booked_payment != '' && name != event.name", as: elsewhere}
24
+ # (a draft finance made for it and has not submitted yet counts too: audit r8 H11 S2)
25
+ - find_all: payment
26
+ where: >-
27
+ inv != null && docstatus != 2 && direction == 'receive' && method != 'sales_return' && amount == event.amount &&
28
+ customer == inv.customer && bank_transaction == '' && !(name in held.map(l, l.booked_payment))
29
+ as: same
30
+ - update: line
31
+ if: "inv != null && size(same) > 0"
32
+ set:
33
+ suggested_invoice: "''"
34
+ booked_payment: "size(same) == 1 && same[0].docstatus == 1 && same[0].method != 'cash' && !(same[0].name in elsewhere.map(l, l.booked_payment)) ? same[0].name : ''"
35
+ draft_payment: "''"
36
+ status: "size(same) == 1 && same[0].docstatus == 1 && same[0].method != 'cash' && !(same[0].name in elsewhere.map(l, l.booked_payment)) ? 'suggested' : 'unmatched'"
19
37
  - update: draft
20
- if: inv != null && draft != null
38
+ if: inv != null && draft != null && size(same) == 0
21
39
  set:
22
40
  customer: inv.customer
23
41
  amount: event.amount
24
42
  allocations: "[{'sales_invoice': inv.name, 'amount': min(event.amount, inv.outstanding)}]"
25
43
  - create: payment
26
- if: inv != null && draft == null && paid == null
44
+ if: inv != null && draft == null && paid == null && size(same) == 0
27
45
  set:
28
46
  direction: "'receive'"
29
47
  customer: inv.customer
@@ -36,8 +54,8 @@ steps:
36
54
  notes: "'Dari mutasi ' + event.name + ': ' + event.description"
37
55
  as: pay
38
56
  - update: line
39
- if: inv != null && draft != null && draft.name != event.draft_payment
57
+ if: inv != null && draft != null && draft.name != event.draft_payment && size(same) == 0
40
58
  set: {draft_payment: draft.name}
41
59
  - update: line
42
- if: inv != null && draft == null && paid == null
60
+ if: inv != null && draft == null && paid == null && size(same) == 0
43
61
  set: {draft_payment: pay.name}
@@ -1,8 +1,20 @@
1
1
  # yaml-language-server: $schema=https://rangka-os.github.io/rangka-os/schema/0.5/flow.json
2
- # A new statement line with money in looks for the invoice it pays. First choice: an open invoice whose number is in
3
- # the transfer note (written loosely, see below). Otherwise: exactly one open invoice whose remaining amount equals
4
- # the line. Two candidates of the same amount -> no suggestion (the owner picks). It only suggests; the payment comes after the owner confirms.
5
- # outstanding is already net of PPh 23, so a customer who withheld tax still matches.
2
+ # A new statement line with money in looks for what it is. It only suggests; nothing is paid before the owner confirms.
3
+ # 1. Money already on the books (booked_payment): a submitted non-cash payment of the same amount that no statement line
4
+ # holds yet, whose reference (giro number, gateway reference) is in the note -> that payment. A giro is booked to the
5
+ # bank when it is received and a QRIS or VA through a gateway when the gateway reports it, so their clearing or
6
+ # settlement line must not pay an invoice again (audit rel-uang-e2e H1: a clearing line of one giro was suggested to
7
+ # another open invoice of the same amount and paid it twice).
8
+ # 2. An open invoice whose number is in the transfer note (written loosely, see below), only when no received payment
9
+ # of the line's amount (cash too) waits for its line and the note is not a cash deposit (SETOR, TUNAI, CRM, CDM).
10
+ # 3. Never an invoice by the amount alone (audit rel-uang-e2e r1-r5 H1, H3, H4, H6, H7, M2): money reaches the bank
11
+ # from too many places that carry no invoice (a giro or gateway payment already booked, a shop's takings settled in
12
+ # sums of the bank's own, cash collected and deposited, a transfer between the business's own accounts), and an
13
+ # amount can never tell them from a customer's transfer. A wrong suggestion, once confirmed, pays an invoice nobody
14
+ # paid. The owner picks the invoice of such a line by hand.
15
+ # 4. Else exactly one booked payment of that amount waiting for its line -> that payment.
16
+ # Anything else: no suggestion (the owner picks). outstanding is already net of PPh 23, so a customer who withheld tax
17
+ # still matches.
6
18
  name: bank_transaction_suggest
7
19
  label: {id: Usulan cocok mutasi ke faktur}
8
20
  on: bank_transaction.created
@@ -12,20 +24,50 @@ steps:
12
24
  # "INV-2026-00012", "inv 2026 00012", "INV202600012", "INV/2026/00012" all match, compared without case, spaces,
13
25
  # dashes, slashes and dots on both sides. The number decides only when the line fits what the invoice still owes
14
26
  # (a part payment fits, an overpayment does not): "0004 2" typed for invoice 00042 must not pull a larger line
15
- # to invoice 0004; such a line falls back to the amount match.
27
+ # to invoice 0004; such a line gets no invoice suggestion.
16
28
  - find_all: sales_invoice
17
29
  where: >-
18
30
  docstatus == 1 && outstanding >= event.amount && (event.description.contains(name) ||
19
31
  event.description.upperAscii().replace(' ', '').replace('-', '').replace('/', '').replace('.', '')
20
32
  .contains(name.upperAscii().replace(' ', '').replace('-', '').replace('/', '').replace('.', '')))
21
33
  as: by_number
22
- - {find_all: sales_invoice, where: "docstatus == 1 && outstanding == event.amount", as: by_amount}
34
+ # held: lines with a booked payment, suggested or confirmed (a payment is suggested on one line at a time, booked_payment
35
+ # is unique); done: lines whose booking the owner confirmed. Money counts as waiting for its line until a line is
36
+ # confirmed against it: a suggestion alone, maybe wrong, does not free the invoice named in another line (audit r9 H12).
37
+ - {find_all: bank_transaction, where: "booked_payment != ''", as: held}
38
+ - {find_all: bank_transaction, where: "status == 'booked'", as: done}
39
+ - find_all: payment
40
+ where: >-
41
+ docstatus == 1 && direction == 'receive' && method != 'cash' && method != 'sales_return' && amount == event.amount &&
42
+ bank_transaction == '' && !(name in held.map(l, l.booked_payment))
43
+ as: booked
44
+ - find_all: payment
45
+ where: >-
46
+ docstatus == 1 && direction == 'receive' && method != 'cash' && method != 'sales_return' && amount == event.amount &&
47
+ bank_transaction == '' && !(name in held.map(l, l.booked_payment)) && reference != '' &&
48
+ event.description.upperAscii().contains(reference.upperAscii())
49
+ as: booked_ref
50
+ # Any received payment of this amount (cash too) no line holds yet: the line may be that money reaching the bank
51
+ # (an instalment by transfer or giro booked without a reference, cash collected and deposited). Then the invoice
52
+ # named in the note is not suggested (audit rel-uang-e2e r6 H8, H9): a booked non-cash payment is suggested as Sudah
53
+ # tercatat instead (step 3), a cash one leaves the line to the owner.
54
+ - find_all: payment
55
+ where: >-
56
+ docstatus == 1 && direction == 'receive' && method != 'sales_return' && amount == event.amount &&
57
+ bank_transaction == '' && !(name in done.map(l, l.booked_payment))
58
+ as: same
23
59
  - {find: bank_transaction, where: name == event.name, as: line}
24
- - if: size(by_number) == 1
25
- then:
26
- - update: line
27
- set: {suggested_invoice: "by_number[0].name", status: "'suggested'"}
28
- else:
29
- - update: line
30
- if: size(by_amount) == 1
31
- set: {suggested_invoice: "by_amount[0].name", status: "'suggested'"}
60
+ - update: line
61
+ if: size(booked_ref) == 1
62
+ set: {booked_payment: "booked_ref[0].name", status: "'suggested'"}
63
+ # a cash deposit names no customer's transfer, whatever number it carries
64
+ - update: line
65
+ if: >-
66
+ size(booked_ref) != 1 && size(by_number) == 1 && size(same) == 0 &&
67
+ ['SETOR', 'TUNAI', 'CRM', 'CDM', 'CASH DEP', 'CASH IN', 'DEP CASH'].map(w, event.description.upperAscii().contains(w) ? 1 : 0).sum() == 0
68
+ set: {suggested_invoice: "by_number[0].name", status: "'suggested'"}
69
+ - update: line
70
+ if: >-
71
+ size(booked_ref) != 1 && size(booked) == 1 && !(size(by_number) == 1 && size(same) == 0 &&
72
+ ['SETOR', 'TUNAI', 'CRM', 'CDM', 'CASH DEP', 'CASH IN', 'DEP CASH'].map(w, event.description.upperAscii().contains(w) ? 1 : 0).sum() == 0)
73
+ set: {booked_payment: "booked[0].name", status: "'suggested'"}
@@ -68,6 +68,7 @@ fields:
68
68
  - {value: suggested, label: {id: Ada usulan}}
69
69
  - {value: confirmed, label: {id: Dikonfirmasi}}
70
70
  - {value: matched, label: {id: Cocok, en: Matched}}
71
+ - {value: booked, label: {id: Sudah tercatat, en: Already booked}}
71
72
  - {value: ignored, label: {id: Abaikan}}
72
73
  - name: suggested_invoice
73
74
  type: link
@@ -87,6 +88,16 @@ fields:
87
88
  to: payment
88
89
  label: {id: Pembayaran}
89
90
  read_only: true
91
+ # Money that is already on the books before it shows on the statement: a giro (booked to the bank when received),
92
+ # a QRIS or VA paid through a gateway, a QRIS settlement. Its line is "Sudah tercatat" against that payment and never
93
+ # becomes a second payment of an invoice. unique: one payment is on one statement line only.
94
+ - name: booked_payment
95
+ type: link
96
+ to: payment
97
+ label: {id: Pembayaran yang sudah tercatat}
98
+ help: {id: 'Uang yang sudah dicatat sebelum muncul di mutasi (giro, QRIS, VA, gateway). Baris ini tidak membuat pembayaran baru.'}
99
+ unique: true
100
+ peek: [customer, method, reference, amount]
90
101
  rules:
91
102
  - name: one_side_only
92
103
  on: save
@@ -94,8 +105,20 @@ rules:
94
105
  message: {id: 'Isi Masuk atau Keluar saja, tidak boleh negatif'}
95
106
  - name: confirm_needs_invoice
96
107
  on: save
97
- check: status != 'confirmed' || suggested_invoice != ''
98
- message: {id: Pilih faktur sebelum konfirmasi}
108
+ check: status != 'confirmed' || suggested_invoice != '' || booked_payment != ''
109
+ message: {id: Pilih faktur (atau pembayaran yang sudah tercatat) sebelum konfirmasi}
110
+ - name: invoice_or_booked
111
+ on: save
112
+ check: suggested_invoice == '' || booked_payment == ''
113
+ message: {id: 'Pilih salah satu: faktur yang dibayar, atau pembayaran yang sudah tercatat'}
114
+ - name: booked_needs_payment
115
+ on: save
116
+ check: status != 'booked' || booked_payment != ''
117
+ message: {id: Pilih pembayaran yang sudah tercatat}
118
+ - name: booked_payment_fits
119
+ on: save
120
+ check: "booked_payment == '' || (booked_payment.docstatus == 1 && booked_payment.direction == 'receive' && booked_payment.method != 'cash' && booked_payment.method != 'sales_return' && booked_payment.amount == amount && booked_payment.bank_transaction == '')"
121
+ message: {id: 'Pembayaran yang sudah tercatat harus pembayaran masuk non-tunai yang diajukan, sebesar baris ini, dan belum dicocokkan ke mutasi lain'}
99
122
  - name: confirm_only_money_in
100
123
  on: save
101
124
  check: status != 'confirmed' || amount > 0
@@ -110,7 +133,7 @@ rules:
110
133
  message: {id: Urutan mulai dari 1}
111
134
  views:
112
135
  list:
113
- columns: [date, description, amount, status, suggested_invoice, payment]
136
+ columns: [date, description, amount, status, suggested_invoice, payment, booked_payment]
114
137
  sort: -date
115
138
  form:
116
139
  layout:
@@ -120,5 +143,5 @@ views:
120
143
  - [credit, debit, amount, balance]
121
144
  - section: {id: Pencocokan}
122
145
  columns:
123
- - [status, suggested_invoice]
146
+ - [status, suggested_invoice, booked_payment]
124
147
  - [draft_payment, payment]
@@ -43,7 +43,7 @@ rules:
43
43
  - name: own_payment_only
44
44
  on: save
45
45
  check: valid
46
- message: {id: 'Mutasi bank hanya bisa dibayar oleh draf dari mutasi itu (atau amend-nya) sebesar nilai mutasi, dan tidak bisa diubah'}
46
+ message: {id: 'Mutasi ini hanya dibayar oleh drafnya sendiri sebesar nilainya. Kalau pembayaran pelanggan ini sudah tercatat, pilih Sudah tercatat.'}
47
47
  views:
48
48
  list:
49
49
  columns: [bank_transaction, payment, released_line]
@@ -122,6 +122,15 @@ fields:
122
122
  label: {id: Kode barang/jasa Coretax}
123
123
  help: {id: '6 angka dari referensi kode barang/jasa Coretax. Kosongkan bila tidak tahu (000000)'}
124
124
  depends_on: app_installed('coretax')
125
+ # Records already linked by documents cannot be deleted (kernel: 409 linked); one no longer used is switched off
126
+ # instead and kept for its history. Hiding it from link pickers is a kernel follow-up (web).
127
+ - name: active
128
+ type: check
129
+ label: {id: Aktif}
130
+ help: {id: 'Matikan bila barang tidak dijual atau dibeli lagi. Barang yang sudah dipakai transaksi tidak bisa dihapus'}
131
+ default: 'true'
132
+ in_list: true
133
+ in_filter: true
125
134
  rules:
126
135
  - name: coretax_code_6
127
136
  on: save
@@ -15,6 +15,8 @@ permissions:
15
15
  - {role: outlet_staff, read: true}
16
16
  - {role: sales_rep, read: true}
17
17
  - {role: field_sales, read: true}
18
+ # the cashier's catalogue groups by category: without read the tabs show codes (KTG-001), not names
19
+ - {role: cashier, read: true}
18
20
  fields:
19
21
  - name: category_name
20
22
  type: data
@@ -140,6 +140,15 @@ fields:
140
140
  type: table
141
141
  of: contact_person
142
142
  label: {id: Kontak person}
143
+ # Records already linked by documents cannot be deleted (kernel: 409 linked); one no longer used is switched off
144
+ # instead and kept for its history. Hiding it from link pickers is a kernel follow-up (web).
145
+ - name: active
146
+ type: check
147
+ label: {id: Aktif}
148
+ help: {id: 'Matikan bila pelanggan tidak aktif lagi. Pelanggan yang sudah punya transaksi tidak bisa dihapus'}
149
+ default: 'true'
150
+ in_list: true
151
+ in_filter: true
143
152
  rules:
144
153
  - name: npwp_16
145
154
  on: save
@@ -162,7 +171,7 @@ views:
162
171
  layout:
163
172
  - section: {id: Identitas}
164
173
  columns:
165
- - [customer_name, city, address]
174
+ - [customer_name, city, address, active]
166
175
  - [npwp, phone, email]
167
176
  - section: {id: Data pajak (e-Faktur)}
168
177
  columns:
@@ -68,6 +68,15 @@ fields:
68
68
  type: table
69
69
  of: contact_person
70
70
  label: {id: Kontak person}
71
+ # Records already linked by documents cannot be deleted (kernel: 409 linked); one no longer used is switched off
72
+ # instead and kept for its history. Hiding it from link pickers is a kernel follow-up (web).
73
+ - name: active
74
+ type: check
75
+ label: {id: Aktif}
76
+ help: {id: 'Matikan bila pemasok tidak dipakai lagi. Pemasok yang sudah punya transaksi tidak bisa dihapus'}
77
+ default: 'true'
78
+ in_list: true
79
+ in_filter: true
71
80
  rules:
72
81
  - name: npwp_16
73
82
  on: save
@@ -90,7 +99,7 @@ views:
90
99
  layout:
91
100
  - section: {id: Identitas}
92
101
  columns:
93
- - [vendor_name, city, address]
102
+ - [vendor_name, city, address, active]
94
103
  - [npwp, phone, email]
95
104
  - section: {id: Data pajak (bukti potong)}
96
105
  columns:
@@ -3,11 +3,11 @@
3
3
  # (TaxInvoiceBulk) and the unified withholding slips the firm issues (BPPU, BpuBulk), checked before download.
4
4
  # Decisions and sources: reports/keputusan-riset/09-pajak-coretax.md in the project folder.
5
5
  name: coretax
6
- version: 1.0.1
6
+ version: 1.1.0
7
7
  title: {id: Lapor pajak Coretax, en: Coretax tax filing}
8
8
  summary:
9
9
  id: Siapkan masa pajak dan berkas unduhan untuk lapor di Coretax.
10
10
  en: Prepare tax periods and the files to report in Coretax.
11
11
  category: tax
12
12
  icon: file-list-3-line
13
- requires: {rangka: '>=0.5', users: ^1.0, contacts: ^1.2, catalogue: ^1.2, invoicing: ^1.5, procurement: ^1.1, payments: ^1.4}
13
+ requires: {rangka: '>=0.5', users: ^1.0, contacts: ^1.2, catalogue: ^1.2, invoicing: ^1.7, procurement: ^1.1, payments: ^1.4}
@@ -11,7 +11,7 @@ related:
11
11
  invoices:
12
12
  model: sales_invoice
13
13
  range: {posting_date: [period_start, period_end]}
14
- filter: docstatus == 1 && tax_rate > 0 && kind != 'retention'
14
+ filter: docstatus == 1 && tax_rate > 0 && ppn > 0 && kind != 'retention'
15
15
  sort: name
16
16
  children: true
17
17
  limit: 1000