@alizadefaig/pos-server 1.2.27 → 1.2.28

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.
@@ -42,11 +42,42 @@ const teamResource = (team, {currencySymbol = null, languageCode = null, urls =
42
42
  };
43
43
  };
44
44
 
45
+ const OFFLINE_MODES = ['off', 'standalone', 'hall'];
46
+
47
+ /**
48
+ * Порт OfflineSetupService::forTerminal (Laravel): офлайн-режим кассы из суперадминки — то, что
49
+ * касса записывает в секцию offline своего config.json. null — заведение офлайном не управляет.
50
+ * Правила меняются в обоих местах сразу.
51
+ *
52
+ * @param {object} terminal строка terminals
53
+ * @param {?object} company строка companies (offline_mode, offline_master_terminal_id, offline_lan_key, offline_lan_front)
54
+ */
55
+ const offlineConfig = (terminal, company) => {
56
+ const mode = company ? company.offline_mode : null;
57
+ if (!OFFLINE_MODES.includes(mode)) {
58
+ return null;
59
+ }
60
+ if (mode === 'off') {
61
+ return {enabled: false};
62
+ }
63
+ if (mode === 'hall' && company.offline_master_terminal_id && company.offline_lan_key) {
64
+ const isMaster = company.offline_master_terminal_id === terminal.id;
65
+ return {
66
+ enabled: true,
67
+ role: isMaster ? 'master' : 'follower',
68
+ master_url: isMaster ? null : 'auto',
69
+ lan_front: isMaster && Boolean(nullableBool(company.offline_lan_front)),
70
+ lan_key: company.offline_lan_key,
71
+ };
72
+ }
73
+ return {enabled: true, role: 'standalone', master_url: null, lan_front: false};
74
+ };
75
+
45
76
  /**
46
77
  * @param {object} terminal строка terminals
47
- * @param {{companyName: ?string, workshops: Array<{id, name}>, posMode: object}} rel
78
+ * @param {{companyName: ?string, workshops: Array<{id, name}>, posMode: object, company: ?object}} rel
48
79
  */
49
- const terminalResource = (terminal, {companyName = null, workshops = [], posMode}) => ({
80
+ const terminalResource = (terminal, {companyName = null, workshops = [], posMode, company = null}) => ({
50
81
  id: terminal.id,
51
82
  name: terminal.name,
52
83
  is_active: nullableBool(terminal.is_active),
@@ -58,6 +89,7 @@ const terminalResource = (terminal, {companyName = null, workshops = [], posMode
58
89
  // Каст 'array', `?? []`.
59
90
  settings: phpArray(terminal.settings) ?? [],
60
91
  pos_mode: posMode,
92
+ offline: offlineConfig(terminal, company),
61
93
  });
62
94
 
63
95
  /**
@@ -82,4 +114,4 @@ const teamUserResource = (member, {user = null, role = null, scopes = {}, cashSh
82
114
  shift: shiftResource(workShift),
83
115
  });
84
116
 
85
- module.exports = {teamResource, terminalResource, teamUserResource};
117
+ module.exports = {teamResource, terminalResource, teamUserResource, offlineConfig};
@@ -106,7 +106,7 @@ class InitService {
106
106
  ? this.db.get(`SELECT code FROM languages WHERE id = ?${this.alive()}`, [team.language_id])
107
107
  : null,
108
108
  terminal.company_id
109
- ? this.db.get(`SELECT name FROM companies WHERE id = ?${this.alive()}`, [terminal.company_id])
109
+ ? this.db.get(`SELECT * FROM companies WHERE id = ?${this.alive()}`, [terminal.company_id])
110
110
  : null,
111
111
  this.db.all(
112
112
  `SELECT pw.id, pw.name FROM product_workshops pw
@@ -129,6 +129,8 @@ class InitService {
129
129
  companyName: company ? company.name : null,
130
130
  workshops: terminalWorkshops,
131
131
  posMode: mode,
132
+ // SELECT * выше: офлайн-колонок (offline_*) в локальной схеме кассы нет.
133
+ company,
132
134
  }),
133
135
  };
134
136
  }
@@ -235,7 +235,7 @@ class OrderProductService {
235
235
 
236
236
  async updateModifiers({orderProductId, modifiers}) {
237
237
  const orderProduct = await this.findMutable(orderProductId, 'orderProducts.updateModifiers');
238
- const [sets, , hash] = await OrderService.collectModifierSets(this.snapshot, modifiers);
238
+ const [sets, , hash] = await OrderService.collectModifierSets(this.snapshot, modifiers, this.context.locale());
239
239
 
240
240
  await this.orderProducts.update(orderProductId, {modifications_sets_hash: hash});
241
241
  await this.orderProducts.deleteModifierSets(orderProductId);
@@ -15,6 +15,7 @@ const {businessDay} = require('../support/tz');
15
15
  const {uuid, isUuid} = require('../support/ids');
16
16
  const {htmlspecialchars, md5, phpJsonEncode} = require('../support/str');
17
17
  const {castRow} = require('../support/db');
18
+ const {translated} = require('../support/lang');
18
19
  const {assertOrderMutable} = require('../guard');
19
20
  const {withLock} = require('../support/lock');
20
21
 
@@ -239,7 +240,7 @@ class OrderService {
239
240
  throw notFound('Product not found');
240
241
  }
241
242
 
242
- const [sets, , hash] = await OrderService.collectModifierSets(this.snapshot, modifierSets);
243
+ const [sets, , hash] = await OrderService.collectModifierSets(this.snapshot, modifierSets, this.context.locale());
243
244
 
244
245
  // Повременная позиция уникальна по времени старта — её нельзя доливать в существующую.
245
246
  const hasTimerModifier = await this.snapshot.hasTimerModifier(product.id);
@@ -861,11 +862,17 @@ class OrderService {
861
862
  * Порядок ключей в элементе важен: хэш считается от json_encode этого массива и служит
862
863
  * ключом склейки строк чека — переставь поля, и одинаковые позиции перестанут склеиваться.
863
864
  */
864
- static async collectModifierSets(snapshot, modifierSets) {
865
+ static async collectModifierSets(snapshot, modifierSets, locale) {
865
866
  let totalPrice = 0;
866
867
  const data = [];
867
868
 
868
- for (const modifier of modifierSets || []) {
869
+ // Фронт шлёт modifier_sets_form как есть — объект по id модификатора (так его отдаёт и
870
+ // ProductResource). PHP-шный foreach обходит его как массив, for..of — нет.
871
+ const items = Array.isArray(modifierSets)
872
+ ? modifierSets
873
+ : (modifierSets && typeof modifierSets === 'object' ? Object.values(modifierSets) : []);
874
+
875
+ for (const modifier of items) {
869
876
  const modifierSet = await snapshot.findModifierSet(modifier.modifier_set_id);
870
877
  if (!modifierSet) {
871
878
  throw notFound('Modifier set not found');
@@ -884,7 +891,8 @@ class OrderService {
884
891
 
885
892
  data.push({
886
893
  modifier_set_type: modifierSet.type,
887
- modifier_set_title: productModifierSet.title,
894
+ // title переводимый (Spatie): PHP отдаёт строку локали, а не JSON из колонки.
895
+ modifier_set_title: translated(productModifierSet.title, locale),
888
896
  name: modifier.name,
889
897
  total,
890
898
  price,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alizadefaig/pos-server",
3
- "version": "1.2.27",
3
+ "version": "1.2.28",
4
4
  "description": "Server in express js with Proxy to Main server if need and will work with Electron JS",
5
5
  "homepage": "https://gitlab.com/faigalizade/pos-server#readme",
6
6
  "bugs": {