@rangka-os/create 0.5.0-alpha.33 → 0.5.0-alpha.35
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.
- package/package.json +1 -1
- package/template/base/apps/faktur_piutang/app.rk +4 -0
- package/template/base/apps/faktur_piutang/skills/rangka-app-faktur-piutang/SKILL.md +35 -0
- package/template/base/apps/fnb_cabang/app.rk +7 -0
- package/template/base/apps/fnb_cabang/skills/rangka-app-fnb-cabang/SKILL.md +43 -0
- package/template/base/apps/jasa_proyek/app.rk +11 -1
- package/template/base/apps/jasa_proyek/skills/rangka-app-jasa-proyek/SKILL.md +51 -0
- package/template/base/apps/karyawan_gaji/app.rk +2 -0
- package/template/base/apps/kasir/app.rk +2 -0
- package/template/base/apps/kasir/skills/rangka-app-kasir/SKILL.md +1 -1
- package/template/base/apps/pembelian_pemasok/app.rk +8 -0
- package/template/base/apps/pembelian_pemasok/skills/rangka-app-pembelian-pemasok/SKILL.md +43 -0
- package/template/base/apps/pesanan_whatsapp/app.rk +28 -0
- package/template/base/apps/ritel_cabang/app.rk +7 -0
- package/template/base/apps/ritel_cabang/dashboards/ritel_overview.rk +16 -0
- package/template/base/apps/ritel_cabang/dashboards/ritel_stock.rk +13 -0
- package/template/base/apps/ritel_cabang/skills/rangka-app-ritel-cabang/SKILL.md +43 -0
- package/template/base/apps/sewa_alat/skills/rangka-app-sewa-alat/SKILL.md +3 -3
- package/template/base/connectors/rangka_whatsapp/README.md +3 -2
- package/template/base/connectors/rangka_whatsapp/connector.rk +12 -4
- package/template/base/connectors/rangka_whatsapp/fixtures/expect.json +3 -2
- package/template/base/connectors/rangka_whatsapp/fixtures/message_received.json +1 -1
- package/template/base/connectors/rangka_whatsapp/fixtures/message_received_order.json +1 -0
- package/template/base/connectors/rangka_whatsapp/mock/rangka_whatsapp_mock.py +9 -4
- package/template/base/modules/accounting/flows/financial_report_compute.rk +1 -1
- package/template/base/modules/accounting/flows/financial_report_recompute.rk +1 -1
- package/template/base/modules/accounting/flows/gl_pos_sale_post.rk +38 -2
- package/template/base/modules/accounting/models/gl_entry.rk +3 -0
- package/template/base/modules/attendance/module.rk +4 -4
- package/template/base/modules/attendance/screens/absen_outlet.rk +3 -0
- package/template/base/modules/catalogue/defaults/uom.rk +19 -0
- package/template/base/modules/catalogue/models/item.rk +12 -0
- package/template/base/modules/kitchen/flows/kitchen_ticket_on_draft.rk +44 -0
- package/template/base/modules/kitchen/flows/kitchen_ticket_on_sale.rk +6 -5
- package/template/base/modules/loyalty/flows/loyalty_on_sale.rk +6 -5
- package/template/base/modules/loyalty/flows/loyalty_on_sale_cancel.rk +2 -2
- package/template/base/modules/outlet_sales/models/outlet_sales_line.rk +1 -0
- package/template/base/modules/outlets/models/outlet.rk +48 -0
- package/template/base/modules/outlets/module.rk +1 -1
- package/template/base/modules/payroll/flows/pph21_annual_on_slip_cancel.rk +28 -0
- package/template/base/modules/payroll/flows/pph21_annual_on_slip_submit.rk +84 -0
- package/template/base/modules/payroll/models/payslip.rk +4 -0
- package/template/base/modules/payroll/models/pph21_annual.rk +84 -0
- package/template/base/modules/payroll/models/pph21_period.rk +77 -0
- package/template/base/modules/payroll/module.rk +3 -2
- package/template/base/modules/payroll/print/bukti_potong_a1.html +53 -0
- package/template/base/modules/payroll/print/bukti_potong_a1.rk +9 -0
- package/template/base/modules/payroll/print/coretax_bp21.rk +44 -0
- package/template/base/modules/payroll/print/coretax_bp21.xml +36 -0
- package/template/base/modules/payroll/print/coretax_bpa1.rk +21 -0
- package/template/base/modules/payroll/print/coretax_bpa1.xml +46 -0
- package/template/base/modules/payroll/print/coretax_bpmp.rk +23 -0
- package/template/base/modules/payroll/print/coretax_bpmp.xml +31 -0
- package/template/base/modules/pos/flows/pos_sale_merge.rk +34 -0
- package/template/base/modules/pos/flows/pos_sale_on_cancel.rk +3 -0
- package/template/base/modules/pos/flows/pos_sale_on_submit.rk +28 -1
- package/template/base/modules/pos/flows/pos_sale_split.rk +37 -0
- package/template/base/modules/pos/flows/pos_shift_on_create.rk +9 -1
- package/template/base/modules/pos/flows/pos_table_guard_on_create.rk +24 -0
- package/template/base/modules/pos/flows/pos_table_guard_on_update.rk +23 -0
- package/template/base/modules/pos/models/dining_area.rk +23 -0
- package/template/base/modules/pos/models/dining_table.rk +38 -0
- package/template/base/modules/pos/models/pos_guard.rk +39 -0
- package/template/base/modules/pos/models/pos_payment.rk +2 -0
- package/template/base/modules/pos/models/pos_sale.rk +153 -7
- package/template/base/modules/pos/models/pos_sale_item.rk +4 -0
- package/template/base/modules/pos/models/pos_shift.rk +11 -1
- package/template/base/modules/pos/module.rk +9 -4
- package/template/base/modules/pos/print/pos_receipt.html +5 -2
- package/template/base/modules/pos/print/pos_receipt_part.html +30 -0
- package/template/base/modules/pos/print/pos_receipt_part.rk +8 -0
- package/template/base/modules/pos/screens/kasir.rk +6 -3
- package/template/base/modules/pos/screens/kasir_meja.rk +62 -0
- package/template/base/modules/reimbursement/models/expense_claim.rk +1 -1
- package/template/base/modules/shifts/module.rk +1 -1
- package/template/base/modules/stock/flows/stock_balance_variant_group.rk +26 -0
- package/template/base/modules/stock/models/stock_balance.rk +1 -0
- package/template/base/modules/stock/models/stock_move.rk +1 -0
- package/template/base/modules/users/flows/summary_daily.rk +3 -1
- package/template/base/modules/users/flows/summary_monthly.rk +3 -1
- package/template/base/modules/users/flows/summary_weekly.rk +3 -1
- package/template/base/modules/whatsapp/models/whatsapp_message.rk +2 -0
- package/template/base/modules/whatsapp/module.rk +2 -2
- package/template/base/modules/whatsapp_order/README.md +44 -0
- package/template/base/modules/whatsapp_order/flows/whatsapp_order_intake.rk +118 -0
- package/template/base/modules/whatsapp_order/flows/whatsapp_order_locked.rk +12 -0
- package/template/base/modules/whatsapp_order/flows/whatsapp_order_on_update.rk +124 -0
- package/template/base/modules/whatsapp_order/models/whatsapp_inbound.rk +62 -0
- package/template/base/modules/whatsapp_order/models/whatsapp_order.rk +164 -0
- package/template/base/modules/whatsapp_order/models/whatsapp_order_guard.rk +46 -0
- package/template/base/modules/whatsapp_order/models/whatsapp_order_line.rk +45 -0
- package/template/base/modules/whatsapp_order/module.rk +42 -0
- package/template/base/modules/whatsapp_order/screens/pesanan_wa.rk +22 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# yaml-language-server: $schema=https://rangka-os.github.io/rangka-os/schema/0.5/flow.json
|
|
2
|
+
# stock_balance.variant_group is a compute through item, stored when the balance is written (rangka-os#267). An item
|
|
3
|
+
# grouped or regrouped after its balances exist keeps the old value on them until its next move, so the "Stok per
|
|
4
|
+
# produk" roll-up would miss it. A scheduled flow runs as the system (a flow on item.updated would run with the
|
|
5
|
+
# permissions of the person saving the item, and no role but the owner may write stock_balance). Every run rewrites up
|
|
6
|
+
# to 50 stale balances with nothing changed, which recomputes the field; a balance already right is not touched.
|
|
7
|
+
# Items whose group was cleared are left until their next stock move. Stock moves already posted keep the group they
|
|
8
|
+
# had when posted.
|
|
9
|
+
name: stock_balance_variant_group
|
|
10
|
+
label: {id: Perbarui grup varian di saldo stok}
|
|
11
|
+
description: {id: 'Tiap 10 menit, saldo stok yang grup variannya belum sama dengan data barang diperbarui, 50 baris sekali jalan.'}
|
|
12
|
+
schedule: "*/10 * * * *"
|
|
13
|
+
steps:
|
|
14
|
+
- find_all: item
|
|
15
|
+
where: "variant_group != ''"
|
|
16
|
+
limit: 2000
|
|
17
|
+
as: grouped
|
|
18
|
+
- find_all: stock_balance
|
|
19
|
+
where: "grouped.exists(i, i.name == item && i.variant_group != variant_group)"
|
|
20
|
+
limit: 50
|
|
21
|
+
as: stale
|
|
22
|
+
- for_each: stale
|
|
23
|
+
as: b
|
|
24
|
+
do:
|
|
25
|
+
- update: b
|
|
26
|
+
set: {last_move: b.last_move}
|
|
@@ -33,6 +33,7 @@ fields:
|
|
|
33
33
|
- {value: vehicle, label: {id: Mobil kanvas}}
|
|
34
34
|
- {value: quarantine, label: {id: Barang rusak / karantina}}
|
|
35
35
|
- {value: production, label: {id: Ruang produksi}}
|
|
36
|
+
- {name: variant_group, type: data, label: {id: Grup varian}, hidden: true, compute: item.variant_group}
|
|
36
37
|
- {name: last_sale_date, type: date, label: {id: Terakhir terjual}, read_only: true, in_list: true}
|
|
37
38
|
views:
|
|
38
39
|
list:
|
|
@@ -14,6 +14,7 @@ fields:
|
|
|
14
14
|
- {name: posting_date, type: date, label: {id: Tanggal}, read_only: true, in_list: true}
|
|
15
15
|
- {name: outlet, type: link, to: outlet, label: {id: Lokasi}, required: true, read_only: true, in_list: true}
|
|
16
16
|
- {name: item, type: link, to: item, label: {id: Barang}, required: true, read_only: true, in_list: true}
|
|
17
|
+
- {name: variant_group, type: data, label: {id: Grup varian}, hidden: true, compute: item.variant_group}
|
|
17
18
|
- {name: qty, type: float, label: {id: 'Qty (+ masuk, - keluar)'}, read_only: true, in_list: true}
|
|
18
19
|
- {name: unit_cost, type: currency, label: {id: Biaya per satuan}, read_only: true, hidden_for: [outlet_staff, cashier, warehouse_staff]}
|
|
19
20
|
- {name: value, type: currency, label: {id: Nilai}, read_only: true, in_list: true, hidden_for: [outlet_staff, cashier, warehouse_staff]}
|
|
@@ -64,7 +64,9 @@ steps:
|
|
|
64
64
|
date_to: "('as_of' in event ? event.as_of : today()) - duration(1)"
|
|
65
65
|
summary_key: "'daily|' + string(('as_of' in event ? event.as_of : today()) - duration(1))"
|
|
66
66
|
setting: cfg.name
|
|
67
|
-
|
|
67
|
+
# POS sales on the net before service charge, PBJT and rounding (audit F6): PBJT is owed to the region, service and
|
|
68
|
+
# rounding sit in their own accounts; cash_in below still counts the whole receipt
|
|
69
|
+
sales_total: "(app_installed('invoicing') ? inv.map(i, i.grand_total).sum() : 0) + (app_installed('pos') ? receipts.map(i, i.grand_total - i.service_charge - i.pbjt - i.rounding).sum() : 0) + (app_installed('outlet_sales') ? daily.map(i, i.net_total).sum() : 0)"
|
|
68
70
|
sales_count: "(app_installed('invoicing') ? size(inv) : 0) + (app_installed('pos') ? size(receipts) : 0) + (app_installed('outlet_sales') ? size(daily) : 0)"
|
|
69
71
|
cash_in: "(app_installed('payments') ? paid.map(i, i.amount).sum() : 0) + (app_installed('pos') ? receipts.map(i, i.grand_total).sum() : 0) + (app_installed('outlet_sales') ? takings.map(i, i.received_total).sum() : 0)"
|
|
70
72
|
due_count: "app_installed('invoicing') ? owed.filter(i, i.due_date >= ('as_of' in event ? event.as_of : today())).size() : 0"
|
|
@@ -64,7 +64,9 @@ steps:
|
|
|
64
64
|
date_to: "('as_of' in event ? event.as_of : today()) - duration(1)"
|
|
65
65
|
summary_key: "'monthly|' + string(('as_of' in event ? event.as_of : today()) - duration(1))"
|
|
66
66
|
setting: cfg.name
|
|
67
|
-
|
|
67
|
+
# POS sales on the net before service charge, PBJT and rounding (audit F6): PBJT is owed to the region, service and
|
|
68
|
+
# rounding sit in their own accounts; cash_in below still counts the whole receipt
|
|
69
|
+
sales_total: "(app_installed('invoicing') ? inv.map(i, i.grand_total).sum() : 0) + (app_installed('pos') ? receipts.map(i, i.grand_total - i.service_charge - i.pbjt - i.rounding).sum() : 0) + (app_installed('outlet_sales') ? daily.map(i, i.net_total).sum() : 0)"
|
|
68
70
|
sales_count: "(app_installed('invoicing') ? size(inv) : 0) + (app_installed('pos') ? size(receipts) : 0) + (app_installed('outlet_sales') ? size(daily) : 0)"
|
|
69
71
|
cash_in: "(app_installed('payments') ? paid.map(i, i.amount).sum() : 0) + (app_installed('pos') ? receipts.map(i, i.grand_total).sum() : 0) + (app_installed('outlet_sales') ? takings.map(i, i.received_total).sum() : 0)"
|
|
70
72
|
due_count: "app_installed('invoicing') ? owed.filter(i, i.due_date >= ('as_of' in event ? event.as_of : today())).size() : 0"
|
|
@@ -64,7 +64,9 @@ steps:
|
|
|
64
64
|
date_to: "('as_of' in event ? event.as_of : today()) - duration(1)"
|
|
65
65
|
summary_key: "'weekly|' + string(('as_of' in event ? event.as_of : today()) - duration(1))"
|
|
66
66
|
setting: cfg.name
|
|
67
|
-
|
|
67
|
+
# POS sales on the net before service charge, PBJT and rounding (audit F6): PBJT is owed to the region, service and
|
|
68
|
+
# rounding sit in their own accounts; cash_in below still counts the whole receipt
|
|
69
|
+
sales_total: "(app_installed('invoicing') ? inv.map(i, i.grand_total).sum() : 0) + (app_installed('pos') ? receipts.map(i, i.grand_total - i.service_charge - i.pbjt - i.rounding).sum() : 0) + (app_installed('outlet_sales') ? daily.map(i, i.net_total).sum() : 0)"
|
|
68
70
|
sales_count: "(app_installed('invoicing') ? size(inv) : 0) + (app_installed('pos') ? size(receipts) : 0) + (app_installed('outlet_sales') ? size(daily) : 0)"
|
|
69
71
|
cash_in: "(app_installed('payments') ? paid.map(i, i.amount).sum() : 0) + (app_installed('pos') ? receipts.map(i, i.grand_total).sum() : 0) + (app_installed('outlet_sales') ? takings.map(i, i.received_total).sum() : 0)"
|
|
70
72
|
due_count: "app_installed('invoicing') ? owed.filter(i, i.due_date >= ('as_of' in event ? event.as_of : today())).size() : 0"
|
|
@@ -40,6 +40,8 @@ fields:
|
|
|
40
40
|
- {value: reminder, label: {id: Pengingat tagihan}}
|
|
41
41
|
- {value: order_ready, label: {id: Kabar pesanan siap}}
|
|
42
42
|
- {value: appointment, label: {id: Pengingat janji}}
|
|
43
|
+
# module whatsapp_order: the reply after staff confirm an order the customer wrote on WhatsApp
|
|
44
|
+
- {value: order_reply, label: {id: Balasan pesanan WA}}
|
|
43
45
|
- {name: template, type: data, label: {id: Template}, read_only: true}
|
|
44
46
|
- {name: document, type: data, label: {id: Dokumen}, read_only: true, in_list: true}
|
|
45
47
|
- {name: customer, type: link, to: customer, label: {id: Pelanggan}, read_only: true, in_list: true}
|
|
@@ -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: whatsapp
|
|
3
|
-
version: 1.
|
|
3
|
+
version: 1.1.0
|
|
4
4
|
title: {id: WhatsApp ke pelanggan, en: WhatsApp to customers}
|
|
5
5
|
summary:
|
|
6
6
|
id: Catatan pesan WhatsApp ke pelanggan (terkirim, dibaca, gagal) dan daftar pelanggan yang tidak mau dikirimi WA.
|
|
@@ -8,7 +8,7 @@ summary:
|
|
|
8
8
|
category: sales
|
|
9
9
|
icon: send-plane-line
|
|
10
10
|
# The shared part of the WhatsApp message types (whatsapp_receipt, whatsapp_reminder, whatsapp_order_ready,
|
|
11
|
-
# whatsapp_booking): each of those is its own module, so switching one type on or off is a change set the owner
|
|
11
|
+
# whatsapp_booking, whatsapp_order): each of those is its own module, so switching one type on or off is a change set the owner
|
|
12
12
|
# approves (config.modules). Messages go out through connector rangka_whatsapp (Rangka Cloud's relay, contract 0063
|
|
13
13
|
# §7): the relay checks the opt-out list, the kill switch, the template's approval and the caps before every send,
|
|
14
14
|
# and sends a key once. This module keeps what the business sees:
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# whatsapp_order: orders customers write on WhatsApp
|
|
2
|
+
|
|
3
|
+
A customer writes to the business's WhatsApp number ("pesan 2 kopi susu, 1 roti"). The order becomes a draft, priced
|
|
4
|
+
from the business's own item records. Staff confirm it with one tap on the work screen **Pesanan dari WhatsApp**
|
|
5
|
+
(`pesanan_wa`, app `pesanan_whatsapp`). Confirming creates the customer when needed and a draft `pos_sale` on the
|
|
6
|
+
cashier's open shift, then replies to the customer with the items and the total (template `pesanan_diterima`).
|
|
7
|
+
Nothing becomes an order without a person's confirm. The rules are in `module.rk` and the comments of each flow.
|
|
8
|
+
|
|
9
|
+
## Two steps, one path
|
|
10
|
+
|
|
11
|
+
1. **Message into lines.** For a text, Rangka Cloud does this (`rangka-cloud internal/whatsapp/orderparse`):
|
|
12
|
+
deterministic, no catalogue, no LLM. It gives `lines: [{qty, name, note, text, …}]`, `notes` and `order_signal`
|
|
13
|
+
on the connector trigger `rangka_whatsapp.message_received`.
|
|
14
|
+
2. **Lines into a priced draft.** Flow `whatsapp_order_intake` does this for any line:
|
|
15
|
+
- a line with `sku` is matched by `item.sku` only;
|
|
16
|
+
- a line with `name` is matched by the same name, part of the name, or the spelling skeleton. One candidate fills
|
|
17
|
+
the line, several make a choice for staff, none leaves an unknown line flagged as a note;
|
|
18
|
+
- a `price` on a line is kept as `quoted_rate` and only compared. The charged price is always the item's rate, and
|
|
19
|
+
a difference puts the order in "Perlu dicek".
|
|
20
|
+
|
|
21
|
+
The draft records its `source` (`whatsapp_text` today). Each message is kept once in `whatsapp_inbound`, with its
|
|
22
|
+
raw text, its Meta message type (`kind`) and the lines read from it, for audit and for a later shared inbox
|
|
23
|
+
(rangka-apps#130).
|
|
24
|
+
|
|
25
|
+
Names stay neutral (order, line, item, customer), so the same path fits a reseller re-ordering stock or a course
|
|
26
|
+
registration, not only a café.
|
|
27
|
+
|
|
28
|
+
## Next: A1b (interactive messages and catalogue carts)
|
|
29
|
+
|
|
30
|
+
Not built here. How it plugs in:
|
|
31
|
+
|
|
32
|
+
- **Catalogue cart** (Meta webhook message type `order`: `product_retailer_id`, `quantity`, `item_price`). Rangka
|
|
33
|
+
Cloud's intake maps each product to a line `{qty: quantity, sku: product_retailer_id, price: item_price, text}` and
|
|
34
|
+
sends `source: whatsapp_cart` and `order_signal: true`. The connector `rangka_whatsapp` adds `source` to its
|
|
35
|
+
`message_received` emit. The order then follows the same path: SKU match, price from the item, mismatch flagged,
|
|
36
|
+
one-tap confirm, the same reply. It needs catalogue sync to Meta (item SKU = retailer id). That is a separate piece
|
|
37
|
+
of work and costs money once real Meta is used.
|
|
38
|
+
- **Reply buttons and list messages** (`interactive` replies). The intake turns a picked row into one line with
|
|
39
|
+
`sku`, or into a staff note. A button that confirms an order still only records the customer's yes; a person
|
|
40
|
+
confirms the order.
|
|
41
|
+
- **WhatsApp Flows forms** (for example a course registration). Same idea: the form's answer becomes lines or notes
|
|
42
|
+
on a draft, never a confirmed document by itself.
|
|
43
|
+
- Sending interactive messages needs a new relay action in Rangka Cloud. Templates stay the only path outside the
|
|
44
|
+
24-hour window.
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# yaml-language-server: $schema=https://rangka-os.github.io/rangka-os/schema/0.5/flow.json
|
|
2
|
+
# A customer wrote to the business's WhatsApp number (connector rangka_whatsapp, trigger message_received; module
|
|
3
|
+
# doc). Runs once per Meta message id (idempotency, and whatsapp_inbound.message_id is unique), as the system.
|
|
4
|
+
# Two steps, kept apart so other sources can feed the second (module doc "Next: A1b"): reading a message into lines
|
|
5
|
+
# (Rangka Cloud's text parser today: name, qty, note) and matching lines to a priced draft (here). A line that names a
|
|
6
|
+
# product by reference (`sku`, as a WhatsApp catalogue cart will) is matched by item.sku only, never by name; a price
|
|
7
|
+
# a line carries (`price`) is kept as quoted_rate and only compared, the price is always the item's.
|
|
8
|
+
# 1. The message is kept (whatsapp_inbound, with its text and source) with its lines matched against the items in one
|
|
9
|
+
# pass (the expression in `lines` below), so the order steps copy rows that are already matched:
|
|
10
|
+
# - names are compared in one form: lower case, punctuation as a space, single spaces (Rangka Cloud's
|
|
11
|
+
# orderparse.Normalize; vectors in tests/day_one_whatsapp_order.py NORMALIZE_VECTORS);
|
|
12
|
+
# - candidates, first that has any: the same name (e); names holding the customer's words as whole words (p);
|
|
13
|
+
# the longest names the customer's words hold (rl: "kopi susu gula aren" holds "kopi susu", the rest becomes
|
|
14
|
+
# the note); the same spelling skeleton (t: no spaces and vowels, c/q as k, v as f, z as j, a doubled letter as
|
|
15
|
+
# one; only names of six or more letters, with the same first letter and word count);
|
|
16
|
+
# - one candidate fills the item; several make the line a choice (match pilih, candidates in choices); none leaves
|
|
17
|
+
# it tak_dikenal. The price is never set here: the line reads the item's rate.
|
|
18
|
+
# Only active items for sale with a price are candidates (kind not material, rate above 0).
|
|
19
|
+
# 2. A draft order: the customer's open one (state new) when its last message is at most 30 minutes from this one,
|
|
20
|
+
# else a new one, but only when Rangka Cloud read an order in the text (order_signal) or, for the open one, at least
|
|
21
|
+
# one line matched. Rows are appended; the window moves with each message. An order holds at most 60 lines: a
|
|
22
|
+
# message that would pass it is kept (result order_full) and not added.
|
|
23
|
+
# Candidates are the first 5001 items read; a catalogue past 5000 marks the draft catalogue_capped, which keeps it
|
|
24
|
+
# in "Perlu dicek" (a single candidate may not be the only one).
|
|
25
|
+
# 3. The customer: the one whose WhatsApp number this is, else the profile name as free text (created on confirm).
|
|
26
|
+
# The outlet: the store ticked "Terima pesanan WhatsApp" (outlet.wa_orders), else the only store, else empty (head
|
|
27
|
+
# office sets it).
|
|
28
|
+
name: whatsapp_order_intake
|
|
29
|
+
label: {id: 'Pesan WhatsApp masuk: jadi draf pesanan'}
|
|
30
|
+
description: {id: 'Pesanan yang ditulis pelanggan di WhatsApp jadi draf dengan harga dari data barang. Baris yang tidak dikenali atau punya beberapa pilihan ditandai untuk dicek staf. Tidak ada yang jadi pesanan sebelum staf mengonfirmasi.'}
|
|
31
|
+
on: rangka_whatsapp.message_received
|
|
32
|
+
if: "'message_id' in event && event.message_id != ''"
|
|
33
|
+
idempotency: event.message_id
|
|
34
|
+
steps:
|
|
35
|
+
- {find: whatsapp_inbound, where: message_id == event.message_id, as: seen}
|
|
36
|
+
- find_all: whatsapp_order
|
|
37
|
+
where: "wa_number == event.from.replace('+', '') && state == 'new'"
|
|
38
|
+
sort: -last_epoch
|
|
39
|
+
limit: 1
|
|
40
|
+
as: opens
|
|
41
|
+
- find: customer
|
|
42
|
+
where: "wa_number == event.from.replace('+', '')"
|
|
43
|
+
as: cust
|
|
44
|
+
- find_all: item
|
|
45
|
+
where: "kind != 'material' && active != false && rate > 0"
|
|
46
|
+
limit: 5001
|
|
47
|
+
as: menu
|
|
48
|
+
- find_all: outlet
|
|
49
|
+
if: "app_installed('outlets')"
|
|
50
|
+
where: "(location_type == '' || location_type == 'store') && active != false"
|
|
51
|
+
sort: -wa_orders
|
|
52
|
+
limit: 2
|
|
53
|
+
as: stores
|
|
54
|
+
- create: whatsapp_inbound
|
|
55
|
+
if: seen == null
|
|
56
|
+
set:
|
|
57
|
+
message_id: event.message_id
|
|
58
|
+
source: "'source' in event && event.source != '' ? event.source : 'whatsapp_text'"
|
|
59
|
+
kind: "'kind' in event ? event.kind : ''"
|
|
60
|
+
sender: "cust != null ? cust.customer_name : ('profile_name' in event && event.profile_name != '' ? event.profile_name : 'Pelanggan WhatsApp')"
|
|
61
|
+
phone: event.from
|
|
62
|
+
wa_number: event.from.replace('+', '')
|
|
63
|
+
text: "'text' in event ? event.text : ''"
|
|
64
|
+
received_at: event.at
|
|
65
|
+
lines_read: "'lines' in event ? event.lines.size() : 0"
|
|
66
|
+
catalogue_capped: menu.size() > 5000
|
|
67
|
+
outlet: "app_installed('outlets') && opens.size() > 0 ? opens[0].outlet : (app_installed('outlets') && ((stores.size() > 0 && stores[0].wa_orders) || stores.size() == 1) ? stores[0].name : '')"
|
|
68
|
+
lines: >-
|
|
69
|
+
!('lines' in event) || event.lines.size() == 0 ? [] : [menu.map(i, {'id': i.name, 'title': i.item_name, 'sku': i.sku, 'n': i.item_name.lowerAscii().replace('(', ' ').replace(')', ' ').replace('[', ' ').replace(']', ' ').replace('{', ' ').replace('}', ' ').replace('-', ' ').replace('/', ' ').replace('.', ' ').replace(',', ' ').replace(';', ' ').replace(':', ' ').replace('&', ' ').replace('+', ' ').replace('_', ' ').replace('#', ' ').replace('*', ' ').replace('!', ' ').replace('?', ' ').replace('~', ' ').replace("'", ' ').replace('"', ' ').replace(' ', ' ').replace(' ', ' ').replace(' ', ' ').trim()}).map(x, {'id': x.id, 'title': x.title, 'sku': x.sku, 'n': x.n, 'k': x.n.replace(' ', '').replace('a', '').replace('e', '').replace('i', '').replace('o', '').replace('u', '').replace('c', 'k').replace('q', 'k').replace('v', 'f').replace('z', 'j').replace('bb', 'b').replace('dd', 'd').replace('ff', 'f').replace('gg', 'g').replace('hh', 'h').replace('jj', 'j').replace('kk', 'k').replace('ll', 'l').replace('mm', 'm').replace('nn', 'n').replace('pp', 'p').replace('rr', 'r').replace('ss', 's').replace('tt', 't').replace('ww', 'w').replace('xx', 'x').replace('yy', 'y'), 'w': (size(x.n) - size(x.n.replace(' ', '')))})].map(mm, event.lines.map(l, {'l': l, 'n': ('name' in l ? string(l.name) : '').lowerAscii().replace('(', ' ').replace(')', ' ').replace('[', ' ').replace(']', ' ').replace('{', ' ').replace('}', ' ').replace('-', ' ').replace('/', ' ').replace('.', ' ').replace(',', ' ').replace(';', ' ').replace(':', ' ').replace('&', ' ').replace('+', ' ').replace('_', ' ').replace('#', ' ').replace('*', ' ').replace('!', ' ').replace('?', ' ').replace('~', ' ').replace("'", ' ').replace('"', ' ').replace(' ', ' ').replace(' ', ' ').replace(' ', ' ').trim(), 'ref': 'sku' in l ? string(l.sku) : ''}).map(c, {'l': c.l, 'n': c.n, 'ref': c.ref, 'k': c.n.replace(' ', '').replace('a', '').replace('e', '').replace('i', '').replace('o', '').replace('u', '').replace('c', 'k').replace('q', 'k').replace('v', 'f').replace('z', 'j').replace('bb', 'b').replace('dd', 'd').replace('ff', 'f').replace('gg', 'g').replace('hh', 'h').replace('jj', 'j').replace('kk', 'k').replace('ll', 'l').replace('mm', 'm').replace('nn', 'n').replace('pp', 'p').replace('rr', 'r').replace('ss', 's').replace('tt', 't').replace('ww', 'w').replace('xx', 'x').replace('yy', 'y'), 'w': (size(c.n) - size(c.n.replace(' ', ''))), 'e': c.ref != '' ? mm.filter(x, x.sku == c.ref) : mm.filter(x, x.n == c.n), 'p': c.ref != '' || c.n == '' ? [] : mm.filter(x, (' ' + x.n + ' ').contains(' ' + c.n + ' ')), 'r': c.ref != '' || c.n == '' ? [] : mm.filter(x, (' ' + c.n + ' ').contains(' ' + x.n + ' '))}).map(c, {'l': c.l, 'n': c.n, 'e': c.e, 'p': c.p, 'rl': c.r.size() == 0 ? [] : c.r.filter(x, size(x.n) == max(c.r.map(y, size(y.n)))), 't': c.n == '' || c.ref != '' ? [] : mm.filter(x, size(x.n) >= 6 && x.k == c.k && x.w == c.w && truncate(x.n, 1) == truncate(c.n, 1))}).map(c, {'l': c.l, 'n': c.n, 'cand': c.e.size() > 0 ? c.e : (c.p.size() > 0 ? c.p : (c.rl.size() > 0 ? c.rl : c.t)), 'how': c.e.size() > 0 ? 'sama' : (c.p.size() > 0 ? 'sebagian' : (c.rl.size() > 0 ? 'sebagian' : (c.t.size() > 0 ? 'ejaan' : 'tak_dikenal'))), 'rest': c.e.size() == 0 && c.p.size() == 0 && c.rl.size() == 1 ? c.n.replace(c.rl[0].n, '').replace(' ', ' ').trim() : ''}).map(c, {'text': 'text' in c.l ? string(c.l.text) : '', 'qty': int(c.l.qty) > 0 ? int(c.l.qty) : 1, 'unit': 'unit' in c.l ? string(c.l.unit) : '', 'quoted_rate': 'price' in c.l ? int(c.l.price) : 0, 'item': c.cand.size() == 1 ? c.cand[0].id : '', 'match': c.cand.size() > 1 ? 'pilih' : c.how, 'choices': c.cand.size() > 1 ? truncate(c.cand.map(x, x.title).join(' / '), 240) : '', 'note': ['note' in c.l ? string(c.l.note) : '', c.rest].filter(s, s != '').join('; ')}))[0]
|
|
70
|
+
as: inb
|
|
71
|
+
- create: whatsapp_order
|
|
72
|
+
if: >-
|
|
73
|
+
seen == null && inb.lines.size() > 0 && event.order_signal == true && !(opens.size() > 0 && epoch(event.at) - opens[0].last_epoch <= 1800 && opens[0].last_epoch - epoch(event.at) <= 1800)
|
|
74
|
+
set:
|
|
75
|
+
customer_name: "cust != null ? cust.customer_name : ('profile_name' in event && event.profile_name.trim() != '' ? event.profile_name.trim() : 'Pelanggan WhatsApp')"
|
|
76
|
+
customer: "cust != null ? cust.name : ''"
|
|
77
|
+
source: inb.source
|
|
78
|
+
catalogue_capped: inb.catalogue_capped
|
|
79
|
+
phone: event.from
|
|
80
|
+
wa_number: event.from.replace('+', '')
|
|
81
|
+
outlet: "app_installed('outlets') && ((stores.size() > 0 && stores[0].wa_orders) || stores.size() == 1) ? stores[0].name : ''"
|
|
82
|
+
lines: >-
|
|
83
|
+
inb.lines.map(l, {'text': l.text, 'item': l.item, 'qty': l.qty, 'unit': l.unit, 'note': l.note, 'match': l.match, 'choices': l.choices, 'quoted_rate': l.quoted_rate})
|
|
84
|
+
notes: "'notes' in event ? event.notes.join('; ') : ''"
|
|
85
|
+
messages: '1'
|
|
86
|
+
first_message_at: event.at
|
|
87
|
+
last_message_at: event.at
|
|
88
|
+
last_epoch: epoch(event.at)
|
|
89
|
+
as: fresh
|
|
90
|
+
# a flow find leaves table rows out: an empty update loads them before rows are appended
|
|
91
|
+
- find: whatsapp_order
|
|
92
|
+
if: >-
|
|
93
|
+
seen == null && inb.lines.size() > 0 && (opens.size() > 0 && epoch(event.at) - opens[0].last_epoch <= 1800 && opens[0].last_epoch - epoch(event.at) <= 1800) && opens[0].line_count + inb.lines.size() <= 60 && (event.order_signal == true || inb.lines.map(l, l.item != '' || l.match == 'pilih' ? 1 : 0).sum() > 0)
|
|
94
|
+
where: name == opens[0].name
|
|
95
|
+
as: o
|
|
96
|
+
- update: o
|
|
97
|
+
if: >-
|
|
98
|
+
seen == null && inb.lines.size() > 0 && (opens.size() > 0 && epoch(event.at) - opens[0].last_epoch <= 1800 && opens[0].last_epoch - epoch(event.at) <= 1800) && opens[0].line_count + inb.lines.size() <= 60 && (event.order_signal == true || inb.lines.map(l, l.item != '' || l.match == 'pilih' ? 1 : 0).sum() > 0)
|
|
99
|
+
set: {}
|
|
100
|
+
- update: o
|
|
101
|
+
if: >-
|
|
102
|
+
seen == null && inb.lines.size() > 0 && (opens.size() > 0 && epoch(event.at) - opens[0].last_epoch <= 1800 && opens[0].last_epoch - epoch(event.at) <= 1800) && opens[0].line_count + inb.lines.size() <= 60 && (event.order_signal == true || inb.lines.map(l, l.item != '' || l.match == 'pilih' ? 1 : 0).sum() > 0)
|
|
103
|
+
set:
|
|
104
|
+
lines: >-
|
|
105
|
+
o.lines.map(l, {'text': l.text, 'item': l.item, 'qty': l.qty, 'unit': l.unit, 'note': l.note, 'match': l.match, 'choices': l.choices, 'quoted_rate': l.quoted_rate}) + inb.lines.map(l, {'text': l.text, 'item': l.item, 'qty': l.qty, 'unit': l.unit, 'note': l.note, 'match': l.match, 'choices': l.choices, 'quoted_rate': l.quoted_rate})
|
|
106
|
+
notes: "'notes' in event && event.notes.size() > 0 ? (o.notes != '' ? o.notes + '; ' : '') + event.notes.join('; ') : o.notes"
|
|
107
|
+
messages: o.messages + 1
|
|
108
|
+
catalogue_capped: o.catalogue_capped || inb.catalogue_capped
|
|
109
|
+
last_message_at: "epoch(event.at) > o.last_epoch ? event.at : o.last_message_at"
|
|
110
|
+
last_epoch: max(o.last_epoch, epoch(event.at))
|
|
111
|
+
- update: inb
|
|
112
|
+
if: seen == null
|
|
113
|
+
set:
|
|
114
|
+
result: >-
|
|
115
|
+
seen == null && inb.lines.size() > 0 && event.order_signal == true && !(opens.size() > 0 && epoch(event.at) - opens[0].last_epoch <= 1800 && opens[0].last_epoch - epoch(event.at) <= 1800) ? 'order_new' : (seen == null && inb.lines.size() > 0 && (opens.size() > 0 && epoch(event.at) - opens[0].last_epoch <= 1800 && opens[0].last_epoch - epoch(event.at) <= 1800) && opens[0].line_count + inb.lines.size() <= 60 && (event.order_signal == true || inb.lines.map(l, l.item != '' || l.match == 'pilih' ? 1 : 0).sum() > 0) ? 'order_added' : (seen == null && inb.lines.size() > 0 && (opens.size() > 0 && epoch(event.at) - opens[0].last_epoch <= 1800 && opens[0].last_epoch - epoch(event.at) <= 1800) && opens[0].line_count + inb.lines.size() > 60 ? 'order_full' : 'not_order'))
|
|
116
|
+
order: >-
|
|
117
|
+
seen == null && inb.lines.size() > 0 && event.order_signal == true && !(opens.size() > 0 && epoch(event.at) - opens[0].last_epoch <= 1800 && opens[0].last_epoch - epoch(event.at) <= 1800) ? fresh.name : (seen == null && inb.lines.size() > 0 && (opens.size() > 0 && epoch(event.at) - opens[0].last_epoch <= 1800 && opens[0].last_epoch - epoch(event.at) <= 1800) && opens[0].line_count + inb.lines.size() <= 60 && (event.order_signal == true || inb.lines.map(l, l.item != '' || l.match == 'pilih' ? 1 : 0).sum() > 0) ? o.name : '')
|
|
118
|
+
lines_matched: "inb.lines.map(l, l.item != '' || l.match == 'pilih' ? 1 : 0).sum()"
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# yaml-language-server: $schema=https://rangka-os.github.io/rangka-os/schema/0.5/flow.json
|
|
2
|
+
# A confirmed WhatsApp order is final (audit 2026-11-21 finding 2): its sale and its reply were made from these lines,
|
|
3
|
+
# so a person's later edit of the order (lines, quantities, customer, outlet) is refused. Changes go on the sale at
|
|
4
|
+
# the kasir. Writes by flows start no flow, so the confirm's own write of the sale and the reply is not seen here.
|
|
5
|
+
name: whatsapp_order_locked
|
|
6
|
+
label: {id: 'Pesanan WhatsApp yang sudah dikonfirmasi tidak bisa diubah'}
|
|
7
|
+
description: {id: 'Setelah dikonfirmasi, isi pesanan WhatsApp tetap seperti yang dibalas ke pelanggan. Perubahan dilakukan di transaksi kasirnya.'}
|
|
8
|
+
on: whatsapp_order.updated
|
|
9
|
+
if: event.before != null && event.before.state == 'confirmed' && event.state == 'confirmed'
|
|
10
|
+
steps:
|
|
11
|
+
- create: whatsapp_order_guard
|
|
12
|
+
set: {reason: "'locked'", document: event.name}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# yaml-language-server: $schema=https://rangka-os.github.io/rangka-os/schema/0.5/flow.json
|
|
2
|
+
# Staff confirm or turn down a WhatsApp order (state, one tap on the work screen pesanan_wa or the form). Runs inside
|
|
3
|
+
# that write, as the person (writes by flows start no flow, so the intake's appends are not seen here). Allowed moves:
|
|
4
|
+
# new -> confirmed, new -> rejected, rejected -> new; a confirmed order is final (its sale is voided at the kasir like
|
|
5
|
+
# any sale). The model's rules have already refused a confirm with no item line or an open choice.
|
|
6
|
+
# Confirm:
|
|
7
|
+
# 1. The customer: the order's link, else the customer with this WhatsApp number, else a new customer with the name on
|
|
8
|
+
# the order (free text the staff could correct) and the number.
|
|
9
|
+
# 2. The order the business works with: a draft pos_sale (module pos) on the confirming person's open shift (at the
|
|
10
|
+
# order's outlet when it has one); head office or the owner without a shift of their own use an open shift of that
|
|
11
|
+
# outlet. The sale prices its lines from the item (and its promos), so paying it at the counter is a sale like any
|
|
12
|
+
# other: stock, receipt (with module whatsapp_receipt the WhatsApp receipt and the order-ready message too) and
|
|
13
|
+
# reports. The buyer is "<name> (WAO-…)" so the counter shows where it came from. An order without an outlet is
|
|
14
|
+
# confirmed only on one's own shift (its outlet is then written on the order); otherwise refused (no_outlet).
|
|
15
|
+
# The reply lists the items up to 120 characters (Meta's 512-byte parameter limit, any script), else "N jenis barang". Without module pos: refused
|
|
16
|
+
# (no_target; a customer_order path for businesses without a kasir is a later step). No open shift: refused
|
|
17
|
+
# (no_shift), nothing kept.
|
|
18
|
+
# 3. The reply: one whatsapp_message (key <order>:order_reply:1) and the template pesanan_diterima through Rangka Cloud,
|
|
19
|
+
# with the items and the document's total; skipped for a number on the opt-out list. A template may go out in and
|
|
20
|
+
# outside Meta's 24-hour window (module doc), so no free text is ever sent.
|
|
21
|
+
name: whatsapp_order_on_update
|
|
22
|
+
label: {id: 'Pesanan WhatsApp dikonfirmasi: buat transaksi dan balas pelanggan'}
|
|
23
|
+
description: {id: 'Saat staf mengonfirmasi pesanan WhatsApp, pelanggan baru dicatat, draf transaksi kasir (atau pesanan pelanggan) dibuat dengan harga dari data barang, lalu pelanggan dibalas rincian dan totalnya lewat WhatsApp.'}
|
|
24
|
+
on: whatsapp_order.updated
|
|
25
|
+
if: event.before != null && event.before.state != event.state
|
|
26
|
+
steps:
|
|
27
|
+
- create: whatsapp_order_guard
|
|
28
|
+
if: "!((event.before.state + '>' + event.state) in ['new>confirmed', 'new>rejected', 'rejected>new'])"
|
|
29
|
+
set: {reason: "'bad_step'", document: event.name}
|
|
30
|
+
- create: whatsapp_order_guard
|
|
31
|
+
if: "event.state == 'confirmed' && !app_installed('pos')"
|
|
32
|
+
set: {reason: "'no_target'", document: event.name}
|
|
33
|
+
# 1. the customer
|
|
34
|
+
- find: customer
|
|
35
|
+
if: event.state == 'confirmed' && event.customer == ''
|
|
36
|
+
where: "event.wa_number != '' && wa_number == event.wa_number"
|
|
37
|
+
as: known
|
|
38
|
+
- create: customer
|
|
39
|
+
if: event.state == 'confirmed' && event.customer == '' && known == null
|
|
40
|
+
set:
|
|
41
|
+
customer_name: event.customer_name.trim()
|
|
42
|
+
phone: event.phone
|
|
43
|
+
as: added
|
|
44
|
+
# 2. the cashier's draft sale: an open shift of the confirming person, else, for head office or the owner, an open
|
|
45
|
+
# shift of the order's outlet
|
|
46
|
+
- find: pos_shift
|
|
47
|
+
if: event.state == 'confirmed' && app_installed('pos')
|
|
48
|
+
where: "cashier == user.email && state == 'open' && (event.outlet == '' || outlet == event.outlet)"
|
|
49
|
+
as: own
|
|
50
|
+
- find_all: pos_shift
|
|
51
|
+
if: event.state == 'confirmed' && app_installed('pos')
|
|
52
|
+
where: "event.outlet != '' && state == 'open' && outlet == event.outlet"
|
|
53
|
+
sort: -opening_date
|
|
54
|
+
limit: 1
|
|
55
|
+
as: open_shifts
|
|
56
|
+
- create: whatsapp_order_guard
|
|
57
|
+
if: >-
|
|
58
|
+
event.state == 'confirmed' && app_installed('pos') && own == null
|
|
59
|
+
&& event.outlet != '' && (open_shifts.size() == 0 || !('head_office' in user.roles || 'owner' in user.roles))
|
|
60
|
+
set: {reason: "'no_shift'", document: event.name}
|
|
61
|
+
# without an outlet and without a shift of one's own, the order's outlet must be chosen first (never the shift that
|
|
62
|
+
# happens to be open somewhere)
|
|
63
|
+
- create: whatsapp_order_guard
|
|
64
|
+
if: event.state == 'confirmed' && app_installed('pos') && own == null && event.outlet == ''
|
|
65
|
+
set: {reason: "'no_outlet'", document: event.name}
|
|
66
|
+
- create: pos_sale
|
|
67
|
+
if: event.state == 'confirmed' && app_installed('pos')
|
|
68
|
+
set:
|
|
69
|
+
shift: "own != null ? own.name : open_shifts[0].name"
|
|
70
|
+
buyer: "truncate(event.customer_name.trim(), 100) + ' (' + event.name + ')'"
|
|
71
|
+
customer: "event.customer != '' ? event.customer : (known != null ? known.name : added.name)"
|
|
72
|
+
items: >-
|
|
73
|
+
event.lines.filter(l, l.item != '').map(l, {'item': l.item, 'qty': l.qty, 'packing': '', 'discount_pct': 0,
|
|
74
|
+
'note': l.note, 'is_gift': false})
|
|
75
|
+
wa_phone: "app_installed('whatsapp_receipt') ? event.phone : ''"
|
|
76
|
+
wa_receipt: "app_installed('whatsapp_receipt') && event.phone != ''"
|
|
77
|
+
as: sale
|
|
78
|
+
# 3. the reply, with the sale's total (its promos applied)
|
|
79
|
+
- {find: whatsapp_message, if: "event.state == 'confirmed'", where: "key == event.name + ':order_reply:1'", as: done}
|
|
80
|
+
- {find: whatsapp_opt_out, if: "event.state == 'confirmed'", where: number == event.wa_number, as: out}
|
|
81
|
+
- {find: outlet, if: "event.state == 'confirmed' && app_installed('pos')", where: name == sale.outlet, as: o}
|
|
82
|
+
- create: whatsapp_message
|
|
83
|
+
if: event.state == 'confirmed' && app_installed('pos') && done == null && event.wa_number != ''
|
|
84
|
+
set:
|
|
85
|
+
key: event.name + ':order_reply:1'
|
|
86
|
+
message_type: "'order_reply'"
|
|
87
|
+
template: "'pesanan_diterima'"
|
|
88
|
+
document: event.name
|
|
89
|
+
customer: "event.customer != '' ? event.customer : (known != null ? known.name : added.name)"
|
|
90
|
+
number_tail: "'…' + event.wa_number.replace(truncate(event.wa_number, size(event.wa_number) - 4), '')"
|
|
91
|
+
amount: sale.grand_total
|
|
92
|
+
status: "out != null ? 'skipped' : 'queued'"
|
|
93
|
+
error: "out != null ? 'opted_out' : ''"
|
|
94
|
+
status_at: now()
|
|
95
|
+
as: msg
|
|
96
|
+
- call: rangka_whatsapp.send_template
|
|
97
|
+
if: event.state == 'confirmed' && app_installed('pos') && done == null && event.wa_number != '' && out == null
|
|
98
|
+
with:
|
|
99
|
+
to: "'+' + event.wa_number"
|
|
100
|
+
template: "'pesanan_diterima'"
|
|
101
|
+
type: "'order_reply'"
|
|
102
|
+
idempotency_key: event.name + ':order_reply:1'
|
|
103
|
+
components: >-
|
|
104
|
+
[{'type': 'body', 'parameters': [
|
|
105
|
+
{'type': 'text', 'text': truncate(event.customer_name.trim(), 60)},
|
|
106
|
+
{'type': 'text', 'text': event.name},
|
|
107
|
+
{'type': 'text', 'text': o != null ? o.outlet_name : org.legal_name},
|
|
108
|
+
{'type': 'text', 'text': size(event.summary) <= 120 ? event.summary : string(event.item_lines) + ' jenis barang'},
|
|
109
|
+
{'type': 'text', 'text': msg.amount_text}]}]
|
|
110
|
+
- {find: whatsapp_order, if: "event.state == 'confirmed'", where: name == event.name, as: me}
|
|
111
|
+
- update: me
|
|
112
|
+
if: event.state == 'confirmed'
|
|
113
|
+
set:
|
|
114
|
+
customer: "event.customer != '' ? event.customer : (known != null ? known.name : added.name)"
|
|
115
|
+
confirmed_by: user.name
|
|
116
|
+
confirmed_at: now()
|
|
117
|
+
confirmed_date: today()
|
|
118
|
+
- update: me
|
|
119
|
+
if: event.state == 'confirmed' && app_installed('pos')
|
|
120
|
+
set:
|
|
121
|
+
sale: sale.name
|
|
122
|
+
outlet: "app_installed('outlets') ? sale.outlet : ''"
|
|
123
|
+
reply_total: "done == null && event.wa_number != '' ? msg.amount : 0"
|
|
124
|
+
reply: "done == null && event.wa_number != '' ? msg.name : ''"
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# yaml-language-server: $schema=https://rangka-os.github.io/rangka-os/schema/0.5/model.json
|
|
2
|
+
# One message a customer wrote to the business's WhatsApp number, kept once by Meta's message id (unique; the flow's
|
|
3
|
+
# idempotency key is the same id, so a webhook delivered twice makes one row and one draft). Written by flow
|
|
4
|
+
# whatsapp_order_intake only. It says what the message did: started an order, added to one, or was no order. A later
|
|
5
|
+
# shared inbox (rangka-apps#130) can read these rows instead of keeping its own copy.
|
|
6
|
+
name: whatsapp_inbound
|
|
7
|
+
label: {id: Pesan WhatsApp masuk, en: Incoming WhatsApp message}
|
|
8
|
+
icon: chat-download-line
|
|
9
|
+
naming: WAIN-{YY}{MM}-{######}
|
|
10
|
+
title_field: sender
|
|
11
|
+
permissions:
|
|
12
|
+
- {role: head_office, read: true, export: true}
|
|
13
|
+
- {role: sales_manager, read: true}
|
|
14
|
+
- {role: cashier, read: true}
|
|
15
|
+
fields:
|
|
16
|
+
- {name: message_id, type: data, label: {id: ID pesan WhatsApp}, required: true, unique: true, read_only: true, hidden: true}
|
|
17
|
+
# where the order came from: the text a customer wrote (Rangka Cloud reads it into lines); whatsapp_cart (a WhatsApp
|
|
18
|
+
# catalogue cart with product references) is the next source, fed into the same matching (module doc "Next: A1b")
|
|
19
|
+
- name: source
|
|
20
|
+
type: select
|
|
21
|
+
label: {id: Sumber}
|
|
22
|
+
default: "'whatsapp_text'"
|
|
23
|
+
read_only: true
|
|
24
|
+
in_filter: true
|
|
25
|
+
options:
|
|
26
|
+
- {value: whatsapp_text, label: {id: Chat WhatsApp}}
|
|
27
|
+
- {value: whatsapp_cart, label: {id: Keranjang katalog WhatsApp}}
|
|
28
|
+
# Meta's message type (text, image, order, …): the raw text is kept in `text` for audit
|
|
29
|
+
- {name: kind, type: data, label: {id: Jenis pesan}, read_only: true}
|
|
30
|
+
- {name: sender, type: data, label: {id: Pengirim}, read_only: true, in_list: true}
|
|
31
|
+
- {name: phone, type: phone, label: {id: Nomor WhatsApp}, read_only: true}
|
|
32
|
+
- {name: wa_number, type: data, label: {id: Nomor WhatsApp (seragam)}, read_only: true, hidden: true, index: true}
|
|
33
|
+
- {name: text, type: text, label: {id: Isi pesan}, read_only: true}
|
|
34
|
+
- {name: received_at, type: datetime, label: {id: Diterima}, read_only: true, in_list: true}
|
|
35
|
+
- name: result
|
|
36
|
+
type: select
|
|
37
|
+
label: {id: Hasil}
|
|
38
|
+
read_only: true
|
|
39
|
+
in_list: true
|
|
40
|
+
in_filter: true
|
|
41
|
+
chip: true
|
|
42
|
+
options:
|
|
43
|
+
- {value: order_new, label: {id: Pesanan baru}}
|
|
44
|
+
- {value: order_added, label: {id: Ditambahkan ke pesanan}}
|
|
45
|
+
- {value: order_full, label: {id: 'Tidak ditambahkan, pesanan sudah 60 baris'}}
|
|
46
|
+
- {value: not_order, label: {id: Bukan pesanan}}
|
|
47
|
+
- {name: order, type: link, to: whatsapp_order, label: {id: Pesanan WhatsApp}, read_only: true, in_list: true}
|
|
48
|
+
# the lines Rangka Cloud read in this message, matched against the items (flow whatsapp_order_intake): the order
|
|
49
|
+
# copies them, and they stay here as what this one message said
|
|
50
|
+
- {name: lines, type: table, of: whatsapp_order_line, label: {id: Baris terbaca}, read_only: true}
|
|
51
|
+
# how many lines were read and how many of them matched an item (or are a choice)
|
|
52
|
+
# more items for sale than the intake reads (5000): a line's single candidate may not be the only one, so the order
|
|
53
|
+
# waits for a look ("Perlu dicek")
|
|
54
|
+
- {name: catalogue_capped, type: check, label: {id: Katalog terlalu besar untuk dicocokkan penuh}, read_only: true, default: 'false'}
|
|
55
|
+
- {name: lines_read, type: int, label: {id: Baris terbaca}, read_only: true, default: '0'}
|
|
56
|
+
- {name: lines_matched, type: int, label: {id: Baris cocok dengan barang}, read_only: true, default: '0'}
|
|
57
|
+
# the outlet scopes the rows for the cashier (role scope outlet), the same outlet as the order's
|
|
58
|
+
- {name: outlet, type: link, to: outlet, label: {id: Outlet}, read_only: true, depends_on: app_installed('outlets')}
|
|
59
|
+
views:
|
|
60
|
+
list:
|
|
61
|
+
columns: [name, sender, received_at, result, order]
|
|
62
|
+
sort: -received_at
|