feat: tables and orders in the manager on v2 (platform-v2 step 6.9)
- manager: new pages/orders/ (Tables page cards + quick actions, order page with
lines, multi-select pay/discount/cancel/tab, staff + customer, price changes,
history, the menu + cart beside it); a free table opens a new order on first
Send; v1 TablesPage, OrderDetailPage, DesktopOrderingTab, ManagerOrderDrawer
and PaymentMethodModal removed
- ordering by line id like the phones: GET /api/orders/menu (the counter's
product shape, in-store prices); the product dialog, cart rules and quote hook
move to packages/ordering (@xenia/ordering), shared by counter, menu tablet,
manager
- close follows orders.close_with_unpaid (pay first, or write off after saying
so) on the order page and the overview's quick view; paying asks cash or card
- a confirmed booking can keep its table ahead (manager, phones, counter):
POST /api/connect/bookings/{id}/table, reservations create/PATCH; refused with
reservation.table_kept within 2 h of another booking
- tests: test_manager_ordering.py, online bookings +2, manager orders.test.mjs,
@xenia/ordering, e2e manager.mjs (take, change, pay-first close, RESERVED)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -117,5 +117,18 @@
|
||||
"paid": "Πληρωμένο",
|
||||
"reserved": "Κράτηση σύντομα"
|
||||
}
|
||||
},
|
||||
"ordering": {
|
||||
"dialog": {
|
||||
"close": "Κλείσιμο",
|
||||
"add": "Στο καλάθι",
|
||||
"pickOne": "επιλέξτε ένα",
|
||||
"quick": "Προσθήκες",
|
||||
"extras": "Έξτρα",
|
||||
"without": "Χωρίς",
|
||||
"note": "Σημείωση για την κουζίνα",
|
||||
"quantity": "Ποσότητα",
|
||||
"missing": "Μένει να επιλέξετε: {{list}}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +157,8 @@
|
||||
"not_found": "Η κράτηση {{reservation_id}} δεν βρέθηκε.",
|
||||
"status_changed": "Η κράτηση άλλαξε από άλλη οθόνη στο μεταξύ (τώρα είναι {{current}}).",
|
||||
"table_unknown": "Το τραπέζι {{table_id}} δεν βρέθηκε.",
|
||||
"table_busy": "Αυτό το τραπέζι έχει ήδη ανοιχτή παραγγελία. Διαλέξτε άλλο τραπέζι ή κλείστε πρώτα εκείνη την παραγγελία."
|
||||
"table_busy": "Αυτό το τραπέζι έχει ήδη ανοιχτή παραγγελία. Διαλέξτε άλλο τραπέζι ή κλείστε πρώτα εκείνη την παραγγελία.",
|
||||
"table_kept": "Αυτό το τραπέζι είναι ήδη κρατημένο για {{name}} στις {{time}}."
|
||||
},
|
||||
"display": {
|
||||
"qr_url_missing": "Γράψτε τον σύνδεσμο που ανοίγει ο QR κωδικός.",
|
||||
|
||||
@@ -2182,5 +2182,177 @@
|
||||
"rotateRight": "Στροφή δεξιά 15°",
|
||||
"takeOff": "Βγάλτε το από την κάτοψη",
|
||||
"removeThing": "Αφαίρεση"
|
||||
},
|
||||
"orders": {
|
||||
"back": "Πίσω",
|
||||
"toTables": "Τραπέζια",
|
||||
"title": "Τραπέζι {{table}}",
|
||||
"titleNoTable": "Παραγγελία #{{id}}",
|
||||
"newTitle": "Τραπέζι {{table}}: νέα παραγγελία",
|
||||
"newHint": "Επιλέξτε τι παραγγέλνουν και στείλτε το: η παραγγελία ανοίγει με την πρώτη αποστολή.",
|
||||
"notFound": "Η παραγγελία δεν βρέθηκε.",
|
||||
"total": "Σύνολο",
|
||||
"paid": "Πληρώθηκαν",
|
||||
"due": "Μένουν",
|
||||
"tabs": {
|
||||
"order": "Παραγγελία",
|
||||
"prices": "Αλλαγές τιμών",
|
||||
"history": "Ιστορικό"
|
||||
},
|
||||
"payAll": "Πληρωμή όλων",
|
||||
"close": "Κλείσιμο",
|
||||
"cancel": "Ακύρωση παραγγελίας",
|
||||
"closed": "Η παραγγελία έκλεισε",
|
||||
"cancelled": "Η παραγγελία ακυρώθηκε",
|
||||
"confirmClose": "Κλείσιμο παραγγελίας;",
|
||||
"writeOffTitle": "Κλείσιμο με απλήρωτα;",
|
||||
"writeOffBody_one": "{{count}} γραμμή ({{amount}}) δεν έχει πληρωθεί. Με το κλείσιμο διαγράφεται: μετράει ως απλήρωτη στις αναφορές.",
|
||||
"writeOffBody_other": "{{count}} γραμμές ({{amount}}) δεν έχουν πληρωθεί. Με το κλείσιμο διαγράφονται: μετράνε ως απλήρωτες στις αναφορές.",
|
||||
"writeOff": "Κλείσιμο χωρίς πληρωμή",
|
||||
"payAndClose": "Πληρωμή και κλείσιμο",
|
||||
"cancelTitle": "Ακύρωση όλης της παραγγελίας;",
|
||||
"cancelBody": "Ακυρώνεται κάθε απλήρωτη γραμμή. Να τυπωθεί δελτίο ακύρωσης για την κουζίνα;",
|
||||
"printer": "Εκτυπωτής…",
|
||||
"print": "Εκτύπωση",
|
||||
"printing": "Στάλθηκε στον εκτυπωτή…",
|
||||
"pay": {
|
||||
"title_one": "Πληρωμή {{count}} γραμμής",
|
||||
"title_other": "Πληρωμή {{count}} γραμμών",
|
||||
"closeTitle": "Πληρωμή υπολοίπου και κλείσιμο",
|
||||
"closeBody": "Σε αυτό το κατάστημα η πληρωμή γίνεται πριν κλείσει η παραγγελία (Ρυθμίσεις: κλείσιμο με απλήρωτα).",
|
||||
"cash": "Μετρητά",
|
||||
"card": "Κάρτα",
|
||||
"noCard": "Το κατάστημα δεν δέχεται κάρτες (Ρυθμίσεις).",
|
||||
"done": "Πληρώθηκε",
|
||||
"method": {
|
||||
"cash": "Μετρητά",
|
||||
"card": "Κάρτα",
|
||||
"transfer": "Τραπεζική",
|
||||
"treat": "Κεράστηκε",
|
||||
"comp": "Κεράστηκε",
|
||||
"other": "Άλλο"
|
||||
}
|
||||
},
|
||||
"lines": {
|
||||
"none": "Δεν έχει παραγγελθεί τίποτα ακόμη.",
|
||||
"pick": "Επιλογή {{name}}",
|
||||
"free": "ΔΩΡΕΑΝ",
|
||||
"notPrinted": "Δεν τυπώθηκε",
|
||||
"status": {
|
||||
"paid": "Πληρώθηκε",
|
||||
"cancelled": "Ακυρώθηκε",
|
||||
"tabbed": "Στην καρτέλα",
|
||||
"closed": "Απλήρωτο"
|
||||
},
|
||||
"without": "Χωρίς {{list}}",
|
||||
"added": "{{time}} · {{name}}",
|
||||
"paidBy": "πλήρωσε: {{name}}",
|
||||
"each": "{{price}} το ένα",
|
||||
"picked_one": "{{count}} γραμμή · {{amount}}",
|
||||
"picked_other": "{{count}} γραμμές · {{amount}}",
|
||||
"clear": "Καθαρισμός",
|
||||
"toTab": "Στην καρτέλα",
|
||||
"tabbed": "Πέρασε στην καρτέλα του πελάτη",
|
||||
"discount": "Έκπτωση",
|
||||
"cancel": "Ακύρωση",
|
||||
"pay": "Πληρωμή",
|
||||
"cancelTitle_one": "Ακύρωση {{count}} γραμμής;",
|
||||
"cancelTitle_other": "Ακύρωση {{count}} γραμμών;",
|
||||
"cancelBody": "Να τυπωθεί δελτίο ακύρωσης για την κουζίνα;",
|
||||
"cancelNoPrint": "Ακύρωση χωρίς δελτίο",
|
||||
"cancelPrint": "Ακύρωση και εκτύπωση",
|
||||
"cancelled_one": "Ακυρώθηκε {{count}} γραμμή",
|
||||
"cancelled_other": "Ακυρώθηκαν {{count}} γραμμές"
|
||||
},
|
||||
"discount": {
|
||||
"title_one": "Έκπτωση σε {{count}} γραμμή",
|
||||
"title_other": "Έκπτωση σε {{count}} γραμμές",
|
||||
"body": "Ποσοστό έκπτωσης· η νέα τιμή στρογγυλεύει στα 0,10. Ισχύουν τα όριά σας.",
|
||||
"pct": "Έκπτωση (%)",
|
||||
"about": "Περίπου {{amount}}",
|
||||
"note": "Αιτία (προαιρετικά)",
|
||||
"apply": "Εφαρμογή",
|
||||
"done": "Η έκπτωση εφαρμόστηκε"
|
||||
},
|
||||
"people": {
|
||||
"staff": "Προσωπικό",
|
||||
"noStaff": "Κανείς ακόμη.",
|
||||
"add": "Προσθήκη…",
|
||||
"remove": "Αφαίρεση {{name}}",
|
||||
"customer": "Πελάτης",
|
||||
"noCustomer": "Χωρίς πελάτη.",
|
||||
"customerAdd": "Ανάθεση πελάτη",
|
||||
"customerSearch": "Αναζήτηση με όνομα ή τηλέφωνο…",
|
||||
"customerNone": "Δεν βρέθηκαν πελάτες.",
|
||||
"customerRemove": "Αφαίρεση πελάτη"
|
||||
},
|
||||
"history": {
|
||||
"none": "Δεν υπάρχουν εγγραφές.",
|
||||
"noPrices": "Καμία αλλαγή τιμής σε αυτή την παραγγελία.",
|
||||
"duplicate": "ΔΙΠΛΗ",
|
||||
"offline": "offline",
|
||||
"by": "από {{name}}",
|
||||
"event": {
|
||||
"ORDER_OPENED": "Άνοιγμα",
|
||||
"ITEMS_ADDED": "Προσθήκη",
|
||||
"PAYMENT": "Πληρωμή",
|
||||
"PAYMENT_OFFLINE": "Πληρωμή (offline)",
|
||||
"ORDER_CLOSED": "Κλείσιμο",
|
||||
"ORDER_CANCELLED": "Ακύρωση",
|
||||
"ITEM_CANCELLED": "Ακύρωση γραμμής"
|
||||
},
|
||||
"price": {
|
||||
"modifier_applied": "Κανόνας τιμής",
|
||||
"deal_triggered": "Προσφορά",
|
||||
"deal_offer_shown": "Προσφορά (εμφανίστηκε)",
|
||||
"deal_offer_accepted": "Προσφορά (αποδεκτή)",
|
||||
"deal_offer_dismissed": "Προσφορά (απορρίφθηκε)",
|
||||
"waiter_discount": "Έκπτωση",
|
||||
"free_item_added": "Δωρεάν προϊόν"
|
||||
}
|
||||
},
|
||||
"add": {
|
||||
"search": "Αναζήτηση στο μενού…",
|
||||
"all": "Όλα",
|
||||
"service": "Σέρβις",
|
||||
"nothing": "Τίποτα εδώ.",
|
||||
"soldOut": "Εξαντλήθηκε",
|
||||
"toSend": "Για αποστολή",
|
||||
"empty": "Πατήστε ένα προϊόν για να το προσθέσετε.",
|
||||
"less": "Ένα λιγότερο",
|
||||
"more": "Ένα ακόμη",
|
||||
"note": "Σημείωση για όλη την παραγγελία (προαιρετικά)",
|
||||
"clear": "Καθαρισμός",
|
||||
"send": "Αποστολή",
|
||||
"sent": "Στάλθηκε στην κουζίνα",
|
||||
"notPrinted": "Στάλθηκε, αλλά δεν τυπώθηκε σε: {{printers}}"
|
||||
},
|
||||
"tables": {
|
||||
"zone": "Ζώνη",
|
||||
"allZones": "Όλες οι ζώνες",
|
||||
"noZone": "Χωρίς ζώνη",
|
||||
"none": "Δεν βρέθηκαν τραπέζια.",
|
||||
"open": "Τραπέζι {{table}}, {{state}}",
|
||||
"notPrinted": "Δεν τυπώθηκε",
|
||||
"reserved": "Κράτηση {{time}} · {{name}}",
|
||||
"time": "Χρόνος",
|
||||
"seats_one": "{{count}} θέση",
|
||||
"seats_other": "{{count}} θέσεις",
|
||||
"noWaiter": "Χωρίς σερβιτόρο",
|
||||
"view": "Άνοιγμα",
|
||||
"take": "Νέα παραγγελία"
|
||||
},
|
||||
"quick": {
|
||||
"title": "Τραπέζι {{table}}: γρήγορες ενέργειες",
|
||||
"flags": "Σημαίες",
|
||||
"noFlags": "Δεν υπάρχουν σημαίες ακόμη (Ρυθμίσεις).",
|
||||
"notify": "Ειδοποίηση σερβιτόρων",
|
||||
"message": "Ή γράψτε μήνυμα…",
|
||||
"toAll": "Σε όλους",
|
||||
"toTable": "Στους σερβιτόρους του τραπεζιού",
|
||||
"save": "Αποθήκευση",
|
||||
"saved": "Οι σημαίες αποθηκεύτηκαν",
|
||||
"sent": "Σημαίες αποθηκεύτηκαν και το μήνυμα στάλθηκε"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,17 +183,6 @@
|
||||
"less": "Ένα λιγότερο",
|
||||
"more": "Ένα ακόμη",
|
||||
"each": "{{price}} το ένα",
|
||||
"dialog": {
|
||||
"close": "Κλείσιμο",
|
||||
"add": "Στο καλάθι",
|
||||
"pickOne": "επιλέξτε ένα",
|
||||
"quick": "Προσθήκες",
|
||||
"extras": "Έξτρα",
|
||||
"without": "Χωρίς",
|
||||
"note": "Σημείωση για την κουζίνα",
|
||||
"quantity": "Ποσότητα",
|
||||
"missing": "Μένει να επιλέξετε: {{list}}"
|
||||
},
|
||||
"gate": {
|
||||
"dayClosed": "Η ημέρα εργασίας δεν έχει ανοίξει",
|
||||
"dayOpeners": "Ζητήστε από κάποιον που μπορεί να την ανοίξει: {{names}}.",
|
||||
@@ -463,7 +452,10 @@
|
||||
"noTable": "Χωρίς τραπέζι ακόμα",
|
||||
"arrive": "Ήρθαν: καθίστε τους",
|
||||
"cancel": "Ακύρωση",
|
||||
"noShow": "Δεν ήρθαν"
|
||||
"noShow": "Δεν ήρθαν",
|
||||
"keep": "Κράτηση αυτού του τραπεζιού",
|
||||
"release": "Χωρίς κρατημένο τραπέζι",
|
||||
"busyNow": "πιασμένο τώρα"
|
||||
},
|
||||
"call": {
|
||||
"title": "Εισερχόμενη κλήση",
|
||||
@@ -471,6 +463,9 @@
|
||||
"takeaway": "Νέα πώληση για παραλαβή",
|
||||
"visits_one": "{{count}} επίσκεψη · {{spent}}",
|
||||
"visits_other": "{{count}} επισκέψεις · {{spent}}"
|
||||
},
|
||||
"dialog": {
|
||||
"close": "Κλείσιμο"
|
||||
}
|
||||
},
|
||||
"display": {
|
||||
|
||||
@@ -841,7 +841,10 @@
|
||||
"closed": "Είμαστε κλειστά τότε",
|
||||
"party": "Ιδιωτική εκδήλωση",
|
||||
"other": "Άλλος λόγος"
|
||||
}
|
||||
},
|
||||
"keep": "Κράτηση αυτού του τραπεζιού",
|
||||
"release": "Χωρίς κρατημένο τραπέζι",
|
||||
"busyNow": "πιασμένο τώρα"
|
||||
},
|
||||
"tabletOrder": {
|
||||
"title": "Παραγγελία από το tablet",
|
||||
|
||||
@@ -117,5 +117,18 @@
|
||||
"paid": "Paid",
|
||||
"reserved": "Booked soon"
|
||||
}
|
||||
},
|
||||
"ordering": {
|
||||
"dialog": {
|
||||
"close": "Close",
|
||||
"add": "Add to cart",
|
||||
"pickOne": "choose one",
|
||||
"quick": "Add-ons",
|
||||
"extras": "Extras",
|
||||
"without": "Without",
|
||||
"note": "Note for the kitchen",
|
||||
"quantity": "Quantity",
|
||||
"missing": "Still to choose: {{list}}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +157,8 @@
|
||||
"not_found": "Booking {{reservation_id}} not found.",
|
||||
"status_changed": "This booking was changed on another screen in the meantime (it is now {{current}}).",
|
||||
"table_unknown": "Table {{table_id}} not found.",
|
||||
"table_busy": "That table already has an open order. Pick another table, or close that order first."
|
||||
"table_busy": "That table already has an open order. Pick another table, or close that order first.",
|
||||
"table_kept": "That table is already kept for {{name}} at {{time}}."
|
||||
},
|
||||
"display": {
|
||||
"qr_url_missing": "Enter the link the QR code opens.",
|
||||
|
||||
@@ -2182,5 +2182,177 @@
|
||||
"rotateRight": "Turn right 15°",
|
||||
"takeOff": "Take it off the plan",
|
||||
"removeThing": "Remove"
|
||||
},
|
||||
"orders": {
|
||||
"back": "Back",
|
||||
"toTables": "Tables",
|
||||
"title": "Table {{table}}",
|
||||
"titleNoTable": "Order #{{id}}",
|
||||
"newTitle": "Table {{table}}: new order",
|
||||
"newHint": "Pick what they order and send it: the order opens with the first send.",
|
||||
"notFound": "This order can't be found.",
|
||||
"total": "Total",
|
||||
"paid": "Paid",
|
||||
"due": "Still to pay",
|
||||
"tabs": {
|
||||
"order": "Order",
|
||||
"prices": "Price changes",
|
||||
"history": "History"
|
||||
},
|
||||
"payAll": "Pay everything",
|
||||
"close": "Close",
|
||||
"cancel": "Cancel order",
|
||||
"closed": "Order closed",
|
||||
"cancelled": "Order cancelled",
|
||||
"confirmClose": "Close the order?",
|
||||
"writeOffTitle": "Close with unpaid items?",
|
||||
"writeOffBody_one": "{{count}} line ({{amount}}) is not paid. Closing writes it off: it counts as not paid in the reports.",
|
||||
"writeOffBody_other": "{{count}} lines ({{amount}}) are not paid. Closing writes them off: they count as not paid in the reports.",
|
||||
"writeOff": "Close without paying",
|
||||
"payAndClose": "Take the payment and close",
|
||||
"cancelTitle": "Cancel the whole order?",
|
||||
"cancelBody": "Every line not paid is cancelled. Should the kitchen get a cancellation ticket?",
|
||||
"printer": "Printer…",
|
||||
"print": "Print",
|
||||
"printing": "Sent to the printer…",
|
||||
"pay": {
|
||||
"title_one": "Pay {{count}} line",
|
||||
"title_other": "Pay {{count}} lines",
|
||||
"closeTitle": "Pay the rest and close",
|
||||
"closeBody": "This venue takes the payment before an order closes (Settings: close with unpaid items).",
|
||||
"cash": "Cash",
|
||||
"card": "Card",
|
||||
"noCard": "The venue doesn't take cards (Settings).",
|
||||
"done": "Paid",
|
||||
"method": {
|
||||
"cash": "Cash",
|
||||
"card": "Card",
|
||||
"transfer": "Transfer",
|
||||
"treat": "On the house",
|
||||
"comp": "On the house",
|
||||
"other": "Other"
|
||||
}
|
||||
},
|
||||
"lines": {
|
||||
"none": "Nothing ordered yet.",
|
||||
"pick": "Pick {{name}}",
|
||||
"free": "FREE",
|
||||
"notPrinted": "Not printed",
|
||||
"status": {
|
||||
"paid": "Paid",
|
||||
"cancelled": "Cancelled",
|
||||
"tabbed": "On the tab",
|
||||
"closed": "Written off"
|
||||
},
|
||||
"without": "Without {{list}}",
|
||||
"added": "{{time}} · {{name}}",
|
||||
"paidBy": "paid by {{name}}",
|
||||
"each": "{{price}} each",
|
||||
"picked_one": "{{count}} line picked · {{amount}}",
|
||||
"picked_other": "{{count}} lines picked · {{amount}}",
|
||||
"clear": "Clear",
|
||||
"toTab": "On the tab",
|
||||
"tabbed": "Put on the customer's tab",
|
||||
"discount": "Discount",
|
||||
"cancel": "Cancel",
|
||||
"pay": "Pay",
|
||||
"cancelTitle_one": "Cancel {{count}} line?",
|
||||
"cancelTitle_other": "Cancel {{count}} lines?",
|
||||
"cancelBody": "Should the kitchen get a cancellation ticket?",
|
||||
"cancelNoPrint": "Cancel, no ticket",
|
||||
"cancelPrint": "Cancel and print",
|
||||
"cancelled_one": "{{count}} line cancelled",
|
||||
"cancelled_other": "{{count}} lines cancelled"
|
||||
},
|
||||
"discount": {
|
||||
"title_one": "Discount on {{count}} line",
|
||||
"title_other": "Discount on {{count}} lines",
|
||||
"body": "A percentage off; the new price rounds to the nearest 0.10. Your discount limits apply.",
|
||||
"pct": "Discount (%)",
|
||||
"about": "About {{amount}}",
|
||||
"note": "Why (optional)",
|
||||
"apply": "Apply",
|
||||
"done": "Discount applied"
|
||||
},
|
||||
"people": {
|
||||
"staff": "Staff",
|
||||
"noStaff": "No one yet.",
|
||||
"add": "Add someone…",
|
||||
"remove": "Take {{name}} off",
|
||||
"customer": "Customer",
|
||||
"noCustomer": "No customer.",
|
||||
"customerAdd": "Add a customer",
|
||||
"customerSearch": "Search by name or phone…",
|
||||
"customerNone": "No customers found.",
|
||||
"customerRemove": "Take the customer off"
|
||||
},
|
||||
"history": {
|
||||
"none": "Nothing recorded.",
|
||||
"noPrices": "No price changes on this order.",
|
||||
"duplicate": "COUNTED TWICE",
|
||||
"offline": "offline",
|
||||
"by": "by {{name}}",
|
||||
"event": {
|
||||
"ORDER_OPENED": "Opened",
|
||||
"ITEMS_ADDED": "Added",
|
||||
"PAYMENT": "Payment",
|
||||
"PAYMENT_OFFLINE": "Payment (offline)",
|
||||
"ORDER_CLOSED": "Closed",
|
||||
"ORDER_CANCELLED": "Cancelled",
|
||||
"ITEM_CANCELLED": "Line cancelled"
|
||||
},
|
||||
"price": {
|
||||
"modifier_applied": "Price rule",
|
||||
"deal_triggered": "Deal",
|
||||
"deal_offer_shown": "Deal offered",
|
||||
"deal_offer_accepted": "Deal accepted",
|
||||
"deal_offer_dismissed": "Deal declined",
|
||||
"waiter_discount": "Discount",
|
||||
"free_item_added": "Free item"
|
||||
}
|
||||
},
|
||||
"add": {
|
||||
"search": "Search the menu…",
|
||||
"all": "All",
|
||||
"service": "Service",
|
||||
"nothing": "Nothing here.",
|
||||
"soldOut": "Sold out",
|
||||
"toSend": "To send",
|
||||
"empty": "Tap a product to add it.",
|
||||
"less": "One less",
|
||||
"more": "One more",
|
||||
"note": "Note for the whole order (optional)",
|
||||
"clear": "Clear",
|
||||
"send": "Send",
|
||||
"sent": "Sent to the kitchen",
|
||||
"notPrinted": "Sent, but not printed on: {{printers}}"
|
||||
},
|
||||
"tables": {
|
||||
"zone": "Zone",
|
||||
"allZones": "All zones",
|
||||
"noZone": "No zone",
|
||||
"none": "No tables match.",
|
||||
"open": "Table {{table}}, {{state}}",
|
||||
"notPrinted": "Not printed",
|
||||
"reserved": "Booked {{time}} · {{name}}",
|
||||
"time": "Time",
|
||||
"seats_one": "{{count}} seat",
|
||||
"seats_other": "{{count}} seats",
|
||||
"noWaiter": "No waiter",
|
||||
"view": "Open",
|
||||
"take": "Take an order"
|
||||
},
|
||||
"quick": {
|
||||
"title": "Table {{table}}: quick actions",
|
||||
"flags": "Flags",
|
||||
"noFlags": "No flags yet (Settings).",
|
||||
"notify": "Tell the waiters",
|
||||
"message": "Or type a message…",
|
||||
"toAll": "To everyone",
|
||||
"toTable": "To this table's waiters",
|
||||
"save": "Save",
|
||||
"saved": "Flags saved",
|
||||
"sent": "Flags saved and message sent"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,17 +183,6 @@
|
||||
"less": "One less",
|
||||
"more": "One more",
|
||||
"each": "{{price}} each",
|
||||
"dialog": {
|
||||
"close": "Close",
|
||||
"add": "Add to cart",
|
||||
"pickOne": "choose one",
|
||||
"quick": "Add-ons",
|
||||
"extras": "Extras",
|
||||
"without": "Without",
|
||||
"note": "Note for the kitchen",
|
||||
"quantity": "Quantity",
|
||||
"missing": "Still to choose: {{list}}"
|
||||
},
|
||||
"gate": {
|
||||
"dayClosed": "The business day isn't open",
|
||||
"dayOpeners": "Ask someone who can open it: {{names}}.",
|
||||
@@ -463,7 +452,10 @@
|
||||
"noTable": "No table yet",
|
||||
"arrive": "They're here: seat them",
|
||||
"cancel": "Cancel",
|
||||
"noShow": "No-show"
|
||||
"noShow": "No-show",
|
||||
"keep": "Keep this table for them",
|
||||
"release": "Don't keep a table",
|
||||
"busyNow": "busy now"
|
||||
},
|
||||
"call": {
|
||||
"title": "Incoming call",
|
||||
@@ -471,6 +463,9 @@
|
||||
"takeaway": "New takeaway sale",
|
||||
"visits_one": "{{count}} visit · {{spent}}",
|
||||
"visits_other": "{{count}} visits · {{spent}}"
|
||||
},
|
||||
"dialog": {
|
||||
"close": "Close"
|
||||
}
|
||||
},
|
||||
"display": {
|
||||
|
||||
@@ -841,7 +841,10 @@
|
||||
"closed": "We're closed then",
|
||||
"party": "Private event",
|
||||
"other": "Other reason"
|
||||
}
|
||||
},
|
||||
"keep": "Keep this table for them",
|
||||
"release": "Don't keep a table",
|
||||
"busyNow": "busy now"
|
||||
},
|
||||
"tabletOrder": {
|
||||
"title": "Ordered from the tablet",
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "@xenia/ordering",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"description": "A product's choices and the cart's rules as lines the server prices (plan steps 3.3a, 6.9): the product dialog, the quote hook and the pure cart rules, shared by the counter POS, the menu tablet and the manager.",
|
||||
"main": "src/index.js",
|
||||
"exports": {
|
||||
".": "./src/index.js",
|
||||
"./cart": "./src/cart.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@xenia/access": "^0.0.0",
|
||||
"@xenia/i18n": "^0.0.0",
|
||||
"@xenia/ui": "^0.0.0",
|
||||
"lucide-react": "^1.73.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node --test \"tests/*.test.mjs\""
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^19.0.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
// A product's choices and price in one dialog (plan step 3.3a; shared since 6.9): the counter POS,
|
||||
// the menu tablet and the manager's ordering. "Check price" opens it without adding anything; a
|
||||
// product with preferences to pick opens it on tap. The price shown is the backend's (the menu
|
||||
// price, then the app's quote endpoint through `fetchQuote(lines)`), never added up here.
|
||||
// `product` is the counter's product shape (routers/pos._product_out).
|
||||
import { useMemo, useState } from 'react'
|
||||
import { Minus, Plus } from 'lucide-react'
|
||||
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dialog, Input, Stepper } from '@xenia/ui'
|
||||
import { Allergens } from '@xenia/access'
|
||||
import {
|
||||
defaultSelection, missingChoices, pickChoice, pickChoiceSub, pickOptionSub, pickShared, setChoiceQty, setOptionQty,
|
||||
setQuick, toLine, toggleOption, toggleRemoved, unitOf,
|
||||
} from './cart.js'
|
||||
import { useQuote } from './useQuote.js'
|
||||
|
||||
const chip = on => `min-h-[var(--x-control-md)] px-3 rounded-control border-2 text-body text-left flex items-center gap-2 transition-colors duration-fast
|
||||
${on ? 'border-accent bg-accent-soft text-accent-ink font-medium' : 'border-line bg-surface-2 text-ink hover:bg-surface-3'}`
|
||||
|
||||
function Section({ title, hint, children }) {
|
||||
return (
|
||||
<section className="grid gap-2">
|
||||
<h3 className="text-label font-semibold text-ink-2 uppercase tracking-wide">{title}{hint && <span className="ml-2 normal-case font-normal text-warning-ink">{hint}</span>}</h3>
|
||||
<div className="flex flex-wrap gap-2">{children}</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
function Price({ value }) {
|
||||
const { formatMoney } = useFormat()
|
||||
return value ? <span className="text-ink-2 text-label">{value > 0 ? '+' : ''}{formatMoney(value)}</span> : null
|
||||
}
|
||||
|
||||
// fetchQuote(lines) → the server's quote ({lines, total}); each app its endpoint (the menu tablet's
|
||||
// has in-store prices and no discounts, 6.6)
|
||||
export function ProductDialog({ product, onAdd, onClose, fetchQuote, addLabel }) {
|
||||
const { t } = useTranslation('common')
|
||||
const { formatMoney } = useFormat()
|
||||
const unit = unitOf(product)
|
||||
const [sel, setSel] = useState(() => defaultSelection(product))
|
||||
const [qty, setQty] = useState(unit ? unit.start : 1)
|
||||
const missing = missingChoices(product, sel)
|
||||
const line = useMemo(() => toLine(product, sel, qty), [product, sel, qty])
|
||||
const { quote, pending } = useQuote(fetchQuote, missing.length ? [] : [line])
|
||||
const priced = quote?.lines?.[0]
|
||||
|
||||
const add = () => { onAdd(line); onClose() }
|
||||
|
||||
return (
|
||||
<Dialog open onClose={onClose} size="lg" title={product.name} description={product.description || undefined}
|
||||
footer={<>
|
||||
<Button variant="secondary" size="lg" onClick={onClose}>{t('ordering.dialog.close')}</Button>
|
||||
<Button size="lg" disabled={missing.length > 0} onClick={add} data-testid="dialog-add">
|
||||
{(addLabel ?? t('ordering.dialog.add'))}{priced && !pending ? ` · ${formatMoney(priced.total)}` : ''}
|
||||
</Button>
|
||||
</>}>
|
||||
<div className="grid gap-5" data-testid="product-dialog" data-product={product.id}>
|
||||
<div className="flex gap-4 items-start">
|
||||
{product.image_url && <img src={product.image_url} alt="" className="size-28 rounded-card object-cover shrink-0 bg-surface-2" />}
|
||||
<div className="grid gap-1">
|
||||
<div className="text-display font-semibold text-ink" data-testid="dialog-price">
|
||||
{formatMoney(priced ? priced.unit_price : product.price)}
|
||||
{unit && <span className="text-body text-ink-2"> / {unit.label}</span>}
|
||||
</div>
|
||||
{product.price !== product.base_price && !priced && (
|
||||
<div className="text-label text-ink-3 line-through">{formatMoney(product.base_price)}</div>
|
||||
)}
|
||||
{priced?.adjustments?.map(a => (
|
||||
<div key={a.label} className="text-label text-success-ink">{a.label} {a.delta > 0 ? '+' : ''}{formatMoney(a.delta)}</div>
|
||||
))}
|
||||
{product.tags?.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1 mt-1">
|
||||
{product.tags.map(tag => <span key={tag} className="px-2 py-0.5 rounded-full bg-surface-2 text-caption text-ink-2">{tag}</span>)}
|
||||
</div>
|
||||
)}
|
||||
<Allergens allergens={product.allergens} style={{ marginTop: 4 }} />
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{product.prefs.map(ps => {
|
||||
const picked = sel.prefs[ps.id]?.choices ?? []
|
||||
const one = !ps.multi && picked[0] ? ps.choices.find(c => c.id === picked[0].id) : null
|
||||
const need = missing.find(m => m.kind === 'pref' && m.name === ps.name)
|
||||
return (
|
||||
<div key={ps.id} className="grid gap-3" data-pref={ps.id}>
|
||||
<Section title={ps.name} hint={need ? t('ordering.dialog.pickOne') : null}>
|
||||
{ps.choices.map(c => {
|
||||
const p = picked.find(x => x.id === c.id)
|
||||
return (
|
||||
<span key={c.id} className="flex items-center gap-1">
|
||||
<button type="button" className={chip(!!p)} onClick={() => setSel(s => pickChoice(product, s, ps.id, c.id))} data-choice={c.id}>
|
||||
{c.name} <Price value={c.price} />
|
||||
</button>
|
||||
{ps.multi && p && (
|
||||
<Stepper value={p.qty} min={1} max={99} onChange={v => setSel(s => setChoiceQty(s, ps.id, c.id, v))} label={c.name} />
|
||||
)}
|
||||
</span>
|
||||
)
|
||||
})}
|
||||
</Section>
|
||||
{one?.subs?.length > 0 && (
|
||||
<Section title={one.name}>
|
||||
{one.subs.map(s => (
|
||||
<button key={s.name} type="button" className={chip(picked[0].sub === s.name)} onClick={() => setSel(x => pickChoiceSub(x, ps.id, s.name))}>
|
||||
{s.name} <Price value={s.price} />
|
||||
</button>
|
||||
))}
|
||||
</Section>
|
||||
)}
|
||||
{ps.shared && one && !one.disables_shared && (
|
||||
<Section title={ps.shared.name}>
|
||||
{ps.shared.subs.map(s => (
|
||||
<button key={s.name} type="button" className={chip(sel.prefs[ps.id]?.shared === s.name)} onClick={() => setSel(x => pickShared(x, ps.id, s.name))}>
|
||||
{s.name} <Price value={s.price} />
|
||||
</button>
|
||||
))}
|
||||
</Section>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
|
||||
{product.quick.length > 0 && (
|
||||
<Section title={t('ordering.dialog.quick')}>
|
||||
{product.quick.map(q => {
|
||||
const n = sel.quick[q.id] ?? 0
|
||||
return (
|
||||
<span key={q.id} className="flex items-center gap-1">
|
||||
<button type="button" className={chip(n > 0)} onClick={() => setSel(s => setQuick(s, q.id, n > 0 ? 0 : 1))} data-quick={q.id}>
|
||||
{q.name} <Price value={q.price} />
|
||||
</button>
|
||||
{q.allow_multiple && n > 0 && (
|
||||
<Stepper value={n} min={1} max={99} onChange={v => setSel(s => setQuick(s, q.id, v))} label={q.name} />
|
||||
)}
|
||||
</span>
|
||||
)
|
||||
})}
|
||||
</Section>
|
||||
)}
|
||||
|
||||
{product.options.length > 0 && (
|
||||
<Section title={t('ordering.dialog.extras')}>
|
||||
{product.options.map(o => {
|
||||
const s = sel.options[o.id]
|
||||
return (
|
||||
<span key={o.id} className="grid gap-2">
|
||||
<span className="flex items-center gap-1">
|
||||
<button type="button" className={chip(!!s)} onClick={() => setSel(x => toggleOption(product, x, o.id))} data-option={o.id}>
|
||||
{o.name} <Price value={o.price} />
|
||||
</button>
|
||||
{o.allow_multiple && s && <Stepper value={s.qty} min={1} max={99} onChange={v => setSel(x => setOptionQty(x, o.id, v))} label={o.name} />}
|
||||
</span>
|
||||
{s && o.subs.length > 0 && (
|
||||
<span className="flex flex-wrap gap-1 pl-3">
|
||||
{o.subs.map(sub => (
|
||||
<button key={sub.name} type="button" className={chip(s.subs.includes(sub.name))} onClick={() => setSel(x => pickOptionSub(product, x, o.id, sub.name))}>
|
||||
{sub.name} <Price value={sub.price} />
|
||||
</button>
|
||||
))}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
)
|
||||
})}
|
||||
</Section>
|
||||
)}
|
||||
|
||||
{product.ingredients.length > 0 && (
|
||||
<Section title={t('ordering.dialog.without')}>
|
||||
{product.ingredients.map(i => (
|
||||
<button key={i.id} type="button" className={chip(sel.removed.includes(i.id))} onClick={() => setSel(s => toggleRemoved(s, i.id))} data-ingredient={i.id}>
|
||||
{sel.removed.includes(i.id) ? <Minus size={14} /> : <Plus size={14} className="opacity-40" />}{i.name}
|
||||
</button>
|
||||
))}
|
||||
</Section>
|
||||
)}
|
||||
|
||||
<div className="grid sm:grid-cols-[1fr_auto] gap-3 items-end">
|
||||
<label className="grid gap-1 text-label text-ink-2">
|
||||
{t('ordering.dialog.note')}
|
||||
<Input value={sel.notes} onChange={e => setSel(s => ({ ...s, notes: e.target.value }))} maxLength={200} />
|
||||
</label>
|
||||
<div className="grid gap-1 text-label text-ink-2">
|
||||
{t('ordering.dialog.quantity')}
|
||||
<Stepper value={qty} min={unit ? unit.step : 1} max={unit ? 999 : 99} step={unit ? unit.step : 1}
|
||||
format={v => (unit ? `${Number(v).toFixed(unit.step < 1 ? 1 : 0)} ${unit.label}` : String(v))}
|
||||
onChange={v => setQty(Math.round(v * 1000) / 1000)} label={t('ordering.dialog.quantity')} data-testid="dialog-qty" />
|
||||
</div>
|
||||
</div>
|
||||
{missing.length > 0 && (
|
||||
<p className="text-label text-warning-ink" data-testid="dialog-missing">{t('ordering.dialog.missing', { list: missing.map(m => m.name).join(', ') })}</p>
|
||||
)}
|
||||
</div>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
// The counter POS's menu and cart, without prices (plan step 3.3a). Prices always come from
|
||||
// the backend: the menu's `price` and POST /api/pos/quote (services/pos_cart.py). This file
|
||||
// only knows what was chosen; the rules for a complete choice mirror the backend's, so the
|
||||
// screen can say what's missing before asking. Pure: unit-tested in Node (tests/pos.test.mjs).
|
||||
|
||||
// ── menu ────────────────────────────────────────────────────────────────────
|
||||
|
||||
/** Lower case, accents and Greek tonos removed: "Φρέντο" matches "φρεντο". */
|
||||
export function fold(text) {
|
||||
return String(text ?? '').normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase().trim()
|
||||
}
|
||||
|
||||
/** Products in a category (a product listed in several shows in each), in that category's
|
||||
* order; categoryId null = all products (each once). */
|
||||
export function productsIn(products, categoryId) {
|
||||
if (categoryId == null) return products
|
||||
const pos = p => p.categories.find(c => c.category_id === categoryId)
|
||||
return products.filter(pos).sort((a, b) => pos(a).sort_order - pos(b).sort_order || a.name.localeCompare(b.name))
|
||||
}
|
||||
|
||||
/** Search by name (any word order, accents ignored), each product once whatever its
|
||||
* categories. */
|
||||
export function searchProducts(products, query) {
|
||||
const words = fold(query).split(/\s+/).filter(Boolean)
|
||||
if (!words.length) return []
|
||||
return products.filter(p => { const name = fold(p.name); return words.every(w => name.includes(w)) })
|
||||
}
|
||||
|
||||
/** Categories that have products, in their order (top level first, then by sort order). */
|
||||
export function categoriesWithProducts(categories, products) {
|
||||
const used = new Set(products.flatMap(p => p.categories.map(c => c.category_id)))
|
||||
return categories.filter(c => used.has(c.id))
|
||||
}
|
||||
|
||||
// ── one product's choices ───────────────────────────────────────────────────
|
||||
|
||||
const defaultSub = subs => (subs?.length ? (subs.find(s => s.is_default) ?? subs[0]).name : null)
|
||||
|
||||
/** The choices a product starts with: default preference choices (+ their default subs and
|
||||
* the set's default shared sub), nothing else. */
|
||||
export function defaultSelection(product) {
|
||||
const prefs = {}
|
||||
for (const ps of product.prefs ?? []) {
|
||||
const def = ps.choices.find(c => c.id === ps.default_choice_id)
|
||||
prefs[ps.id] = def
|
||||
? { choices: [{ id: def.id, qty: 1, sub: ps.multi ? null : defaultSub(def.subs) }], shared: ps.shared && !def.disables_shared ? defaultSub(ps.shared.subs) : null }
|
||||
: { choices: [], shared: null }
|
||||
}
|
||||
return { quick: {}, options: {}, prefs, removed: [], notes: '' }
|
||||
}
|
||||
|
||||
/** Does the product need the options dialog (a preference to pick)? Otherwise a tap adds it. */
|
||||
export function needsChoices(product) {
|
||||
return (product.prefs ?? []).length > 0
|
||||
}
|
||||
|
||||
/** What's still missing: [{ kind: 'pref' | 'sub' | 'option_sub', name }] (empty = complete). */
|
||||
export function missingChoices(product, sel) {
|
||||
const out = []
|
||||
for (const ps of product.prefs ?? []) {
|
||||
const picked = sel.prefs[ps.id]?.choices ?? []
|
||||
if (!picked.length) { out.push({ kind: 'pref', name: ps.name }); continue }
|
||||
if (ps.multi) continue
|
||||
const c = ps.choices.find(x => x.id === picked[0].id)
|
||||
if (c?.subs?.length && !picked[0].sub) out.push({ kind: 'sub', name: c.name })
|
||||
if (ps.shared && c && !c.disables_shared && !sel.prefs[ps.id]?.shared) out.push({ kind: 'sub', name: ps.shared.name })
|
||||
}
|
||||
for (const o of product.options ?? []) {
|
||||
const s = sel.options[o.id]
|
||||
if (s && o.subs?.length && !(s.subs?.length)) out.push({ kind: 'option_sub', name: o.name })
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** Pick a single-choice preference (its default sub and the set's shared sub come with it). */
|
||||
export function pickChoice(product, sel, setId, choiceId) {
|
||||
const ps = product.prefs.find(p => p.id === setId)
|
||||
const c = ps.choices.find(x => x.id === choiceId)
|
||||
const prev = sel.prefs[setId] ?? { choices: [], shared: null }
|
||||
if (ps.multi) {
|
||||
const has = prev.choices.some(x => x.id === choiceId)
|
||||
const choices = has ? prev.choices.filter(x => x.id !== choiceId) : [...prev.choices, { id: choiceId, qty: 1, sub: null }]
|
||||
return { ...sel, prefs: { ...sel.prefs, [setId]: { ...prev, choices } } }
|
||||
}
|
||||
const shared = ps.shared && !c.disables_shared ? (prev.shared ?? defaultSub(ps.shared.subs)) : null
|
||||
return { ...sel, prefs: { ...sel.prefs, [setId]: { choices: [{ id: choiceId, qty: 1, sub: defaultSub(c.subs) }], shared } } }
|
||||
}
|
||||
|
||||
export function setChoiceQty(sel, setId, choiceId, qty) {
|
||||
const prev = sel.prefs[setId]
|
||||
return { ...sel, prefs: { ...sel.prefs, [setId]: { ...prev, choices: prev.choices.map(x => (x.id === choiceId ? { ...x, qty: Math.max(1, qty) } : x)) } } }
|
||||
}
|
||||
|
||||
export function pickChoiceSub(sel, setId, sub) {
|
||||
const prev = sel.prefs[setId]
|
||||
return { ...sel, prefs: { ...sel.prefs, [setId]: { ...prev, choices: prev.choices.map((x, i) => (i === 0 ? { ...x, sub } : x)) } } }
|
||||
}
|
||||
|
||||
export function pickShared(sel, setId, shared) {
|
||||
return { ...sel, prefs: { ...sel.prefs, [setId]: { ...sel.prefs[setId], shared } } }
|
||||
}
|
||||
|
||||
/** Toggle an extra (with its default sub). */
|
||||
export function toggleOption(product, sel, optionId) {
|
||||
const options = { ...sel.options }
|
||||
if (options[optionId]) delete options[optionId]
|
||||
else {
|
||||
const o = product.options.find(x => x.id === optionId)
|
||||
const sub = defaultSub(o.subs)
|
||||
options[optionId] = { qty: 1, subs: sub ? [sub] : [] }
|
||||
}
|
||||
return { ...sel, options }
|
||||
}
|
||||
|
||||
export function pickOptionSub(product, sel, optionId, name) {
|
||||
const o = product.options.find(x => x.id === optionId)
|
||||
const cur = sel.options[optionId]?.subs ?? []
|
||||
const subs = o.multi_select ? (cur.includes(name) ? cur.filter(n => n !== name) : [...cur, name]) : [name]
|
||||
return { ...sel, options: { ...sel.options, [optionId]: { ...sel.options[optionId], subs } } }
|
||||
}
|
||||
|
||||
export function setOptionQty(sel, optionId, qty) {
|
||||
return { ...sel, options: { ...sel.options, [optionId]: { ...sel.options[optionId], qty: Math.max(1, qty) } } }
|
||||
}
|
||||
|
||||
/** Quick add-ons: qty 0 removes it. */
|
||||
export function setQuick(sel, quickId, qty) {
|
||||
const quick = { ...sel.quick }
|
||||
if (qty > 0) quick[quickId] = qty
|
||||
else delete quick[quickId]
|
||||
return { ...sel, quick }
|
||||
}
|
||||
|
||||
export function toggleRemoved(sel, ingredientId) {
|
||||
const removed = sel.removed.includes(ingredientId) ? sel.removed.filter(i => i !== ingredientId) : [...sel.removed, ingredientId]
|
||||
return { ...sel, removed }
|
||||
}
|
||||
|
||||
/** The cart line POST /api/pos/quote (and 3.3b's sale) takes. */
|
||||
export function toLine(product, sel, quantity) {
|
||||
const line = { product_id: product.id, quantity }
|
||||
const quick = Object.entries(sel.quick).map(([id, qty]) => ({ id: Number(id), qty }))
|
||||
const options = Object.entries(sel.options).map(([id, o]) => ({ id: Number(id), qty: o.qty, subs: o.subs }))
|
||||
const prefs = Object.entries(sel.prefs).filter(([, p]) => p.choices.length)
|
||||
.map(([id, p]) => ({ set_id: Number(id), choices: p.choices.map(c => ({ id: c.id, qty: c.qty, sub: c.sub })), shared: p.shared }))
|
||||
if (quick.length) line.quick = quick
|
||||
if (options.length) line.options = options
|
||||
if (prefs.length) line.prefs = prefs
|
||||
if (sel.removed.length) line.removed = [...sel.removed]
|
||||
if (sel.notes?.trim()) line.notes = sel.notes.trim()
|
||||
return line
|
||||
}
|
||||
|
||||
// ── the cart ────────────────────────────────────────────────────────────────
|
||||
|
||||
/** Two lines are the same sale when everything but the quantity is the same. */
|
||||
export function lineKey(line) {
|
||||
const { quantity, ...rest } = line // eslint-disable-line no-unused-vars
|
||||
return stable(rest)
|
||||
}
|
||||
|
||||
const stable = v => (Array.isArray(v) ? `[${v.map(stable).join(',')}]`
|
||||
: v && typeof v === 'object' ? `{${Object.keys(v).sort().map(k => `${k}:${stable(v[k])}`).join(',')}}`
|
||||
: JSON.stringify(v))
|
||||
|
||||
/** Add a line; the same product with the same choices adds to its quantity. */
|
||||
export function addLine(cart, line) {
|
||||
const key = lineKey(line)
|
||||
const i = cart.findIndex(l => lineKey(l) === key)
|
||||
if (i < 0) return [...cart, line]
|
||||
return cart.map((l, j) => (j === i ? { ...l, quantity: round(l.quantity + line.quantity) } : l))
|
||||
}
|
||||
|
||||
export function setLineQty(cart, index, quantity) {
|
||||
if (quantity <= 0) return cart.filter((_, i) => i !== index)
|
||||
return cart.map((l, i) => (i === index ? { ...l, quantity: round(quantity) } : l))
|
||||
}
|
||||
|
||||
const round = n => Math.round(n * 1000) / 1000
|
||||
|
||||
// Weighed products (kg, L, g, mL): step and starting amount (the waiter app's)
|
||||
export const UNITS = {
|
||||
kg: { step: 0.1, start: 0.5, label: 'kg' },
|
||||
liter: { step: 0.1, start: 0.5, label: 'L' },
|
||||
gram: { step: 10, start: 100, label: 'g' },
|
||||
ml: { step: 5, start: 100, label: 'mL' },
|
||||
}
|
||||
|
||||
export const unitOf = product => UNITS[product.unit_type] ?? null
|
||||
|
||||
// ── paying (3.3b) ───────────────────────────────────────────────────────────
|
||||
|
||||
/** Amounts a customer typically hands over for `total`: the exact amount, then the next
|
||||
* round amounts above it (notes of 5, 10, 20, 50, 100), at most five. */
|
||||
export function quickAmounts(total) {
|
||||
const out = [round2(total)]
|
||||
for (const step of [5, 10, 20, 50, 100]) {
|
||||
const v = Math.ceil((total + 0.0001) / step) * step
|
||||
if (v > total + 0.004 && !out.includes(v)) out.push(v)
|
||||
}
|
||||
return out.slice(0, 5)
|
||||
}
|
||||
|
||||
/** Change to give back (null when not enough was given). */
|
||||
export function changeFor(given, due) {
|
||||
if (given == null || Number.isNaN(given)) return null
|
||||
const c = round2(given - due)
|
||||
return c < 0 ? null : c
|
||||
}
|
||||
|
||||
/** Cash and card parts of a split: methods[i] is 'cash' | 'card' for line i, totals from the
|
||||
* quote. → { cash, card, payments } (payments as POST /api/pos/sales takes them). */
|
||||
export function splitPayments(methods, totals) {
|
||||
const lines = { cash: [], card: [] }
|
||||
methods.forEach((m, i) => lines[m].push(i))
|
||||
const sum = idx => round2(idx.reduce((s, i) => s + (totals[i] ?? 0), 0))
|
||||
const payments = ['card', 'cash'].filter(m => lines[m].length).map(m => ({ method: m, lines: lines[m] }))
|
||||
return { cash: sum(lines.cash), card: sum(lines.card), payments }
|
||||
}
|
||||
|
||||
export const DISCOUNTS = [0, 5, 10, 15, 20, 25, 50, 100]
|
||||
|
||||
const round2 = n => Math.round(n * 100) / 100
|
||||
|
||||
/** The counter's sales point for an order type (phase 3S; backend pos_cart.point_for). */
|
||||
export function salesPointFor(orderType) {
|
||||
return orderType === 'takeaway' ? 'in_store_takeaway' : 'in_store'
|
||||
}
|
||||
|
||||
/** The menu's products sold at a sales point, each with that sales point's price (GET
|
||||
* /api/pos/menu sends `sold_at` and `prices`; older answers: everything, `price`). */
|
||||
export function forSalesPoint(products, point) {
|
||||
return products
|
||||
.filter(p => !p.sold_at || p.sold_at.includes(point))
|
||||
.map(p => (p.prices?.[point] != null ? { ...p, price: p.prices[point] } : p))
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// @xenia/ordering (plan step 6.9): what a person chooses for a product and how it becomes a line
|
||||
// the server prices (line ids, 4.4), one implementation for the counter POS, the menu tablet and
|
||||
// the manager's ordering. Pure rules in ./cart (Node-testable); the dialog and the quote hook.
|
||||
export * from './cart.js'
|
||||
export { ProductDialog } from './ProductDialog.jsx'
|
||||
export { useQuote } from './useQuote.js'
|
||||
@@ -0,0 +1,29 @@
|
||||
// The server's price for a cart, asked again shortly after it changes (plan steps 3.3a, 6.9).
|
||||
// `fetchQuote(lines)` is the app's call (the counter: /api/pos/quote; the manager and the phones:
|
||||
// /api/orders/quote; the menu tablet: its own). Only the latest answer counts.
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
|
||||
const QUOTE_DELAY_MS = 120
|
||||
|
||||
export function useQuote(fetchQuote, lines, extraKey = '') {
|
||||
const [state, setState] = useState({ quote: null, pending: false, error: null })
|
||||
const seq = useRef(0)
|
||||
const fn = useRef(fetchQuote)
|
||||
useEffect(() => { fn.current = fetchQuote })
|
||||
const key = JSON.stringify([lines, extraKey])
|
||||
useEffect(() => {
|
||||
const mine = ++seq.current
|
||||
if (!lines.length) { setState({ quote: { lines: [], total: 0 }, pending: false, error: null }); return undefined } // eslint-disable-line react-hooks/set-state-in-effect
|
||||
setState(s => ({ ...s, pending: true }))
|
||||
const id = setTimeout(async () => {
|
||||
try {
|
||||
const data = await fn.current(lines)
|
||||
if (mine === seq.current) setState({ quote: data, pending: false, error: null })
|
||||
} catch (err) {
|
||||
if (mine === seq.current) setState(s => ({ ...s, pending: false, error: err }))
|
||||
}
|
||||
}, QUOTE_DELAY_MS)
|
||||
return () => clearTimeout(id)
|
||||
}, [key]) // eslint-disable-line react-hooks/exhaustive-deps -- `key` is the lines + the caller's extra key
|
||||
return state
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// The shared cart rules (plan step 6.9); the counter's own cases are in terminal/tests/pos.test.mjs.
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { defaultSelection, missingChoices, needsChoices, toLine } from '../src/cart.js'
|
||||
|
||||
const burger = {
|
||||
id: 1, unit_type: 'piece', quick: [{ id: 5, name: 'Cheese', price: 1 }], options: [], ingredients: [{ id: 9, name: 'Onion' }],
|
||||
prefs: [{ id: 3, name: 'Cooking', default_choice_id: null, multi: false, shared: null, choices: [{ id: 7, name: 'Rare', subs: [] }] }],
|
||||
}
|
||||
|
||||
test('a product with a preference to pick needs the dialog; the line holds ids only', () => {
|
||||
assert.equal(needsChoices(burger), true)
|
||||
const sel = defaultSelection(burger)
|
||||
assert.deepEqual(missingChoices(burger, sel).map(m => m.name), ['Cooking'])
|
||||
sel.prefs[3] = { choices: [{ id: 7, qty: 1 }] }
|
||||
sel.quick[5] = 2
|
||||
sel.removed = [9]
|
||||
assert.deepEqual(missingChoices(burger, sel), [])
|
||||
const line = toLine(burger, sel, 1)
|
||||
assert.equal(line.product_id, 1)
|
||||
assert.equal('unit_price' in line, false)
|
||||
assert.deepEqual(line.removed, [9])
|
||||
})
|
||||
Reference in New Issue
Block a user