Skip to content

Commit 5f2b1ac

Browse files
jiloysssjiloysss
authored andcommitted
Fix: None
Refactor: None Feat: Categories in shift report if hasTailPos equals true
1 parent d3d4387 commit 5f2b1ac

File tree

9 files changed

+180
-170
lines changed

9 files changed

+180
-170
lines changed

src/container/PaymentContainer/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,14 @@ export default class PaymentContainer extends React.Component {
218218
parseInt(totalAmountDue, 10) +
219219
parseInt(val.price.toFixed(2), 10) *
220220
parseInt(val.qty.toFixed(2), 10);
221-
if (val.category){
222-
this.props.shiftStore.defaultShift.categoriesAmounts({
223-
name: val.category,
224-
total_amount: parseInt(val.price.toFixed(2), 10) * parseInt(val.qty.toFixed(2), 10)
225-
});
226-
}
221+
if (val.category) {
222+
this.props.shiftStore.defaultShift.categoriesAmounts({
223+
name: val.category,
224+
total_amount:
225+
parseInt(val.price.toFixed(2), 10) *
226+
parseInt(val.qty.toFixed(2), 10),
227+
});
228+
}
227229
});
228230
if (
229231
this.props.receiptStore.defaultReceipt.orderType !== "None"

src/container/SalesContainer/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export default class SalesContainer extends React.Component {
110110
const { setReceiptLine } = this.props.receiptStore;
111111
const { defaultReceipt } = this.props.receiptStore;
112112
const { isStackItem } = this.props.stateStore;
113-
const categoryObj = this.props.categoryStore.find(item.category);
113+
const categoryObj = this.props.categoryStore.find(item.category);
114114

115115
const line = createReceiptLine(item, categoryObj._55.name);
116116
setReceiptLine(line);
@@ -140,7 +140,9 @@ export default class SalesContainer extends React.Component {
140140
beep.play();
141141

142142
searchByBarcode(barcodeValue).then(resultItem => {
143-
const categoryObj = this.props.categoryStore.find(resultItem.category);
143+
const categoryObj = this.props.categoryStore.find(
144+
resultItem.category,
145+
);
144146
if (resultItem) {
145147
const line = ReceiptLine.create({
146148
item: resultItem._id,
@@ -270,13 +272,13 @@ export default class SalesContainer extends React.Component {
270272

271273
changeValue("barcodeScannerInput", "", "Sales");
272274
searchByBarcode(barcodeValue).then(result => {
273-
const categoryObj = this.props.categoryStore.find(result.category);
275+
const categoryObj = this.props.categoryStore.find(result.category);
274276

275-
if (result) {
277+
if (result) {
276278
const line = ReceiptLine.create({
277279
item: result._id,
278280
item_name: result.name,
279-
category: categoryObj.name,
281+
category: categoryObj.name,
280282

281283
qty: parseInt(1, 10),
282284
price: parseFloat(result.price),

src/container/ShiftInfoContainer/index.js

Lines changed: 80 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ let strings = new LocalizedStrings(translation);
2020
"itemStore",
2121
"shiftReportsStore",
2222
"stateStore",
23-
"categoryStore",
24-
"shiftStore"
23+
"categoryStore",
24+
"shiftStore",
2525
)
2626
@observer
2727
export default class ShiftInfoContainer extends React.Component {
2828
onPrintReport(report) {
29-
3029
BluetoothSerial.isConnected().then(res => {
3130
if (res) {
3231
const writePromises = [];
@@ -304,70 +303,92 @@ export default class ShiftInfoContainer extends React.Component {
304303
),
305304
);
306305
if (this.props.stateStore.hasTailOrder) {
307-
let orderTypes = ["Dine-in", "Takeaway", "Delivery", "Online", "Family"];
308-
orderTypes.map(val => {
309-
let orderString = "" + val;
310-
let valueString = "";
311-
if (val === "Dine-in"){
312-
valueString = formatNumber(parseFloat(report.getOrderTypesTotal.dineInTotal,10)).toString();
313-
} else if (val === "Takeaway"){
314-
valueString = formatNumber(parseFloat(report.getOrderTypesTotal.takeawayTotal,10)).toString();
315-
316-
} else if (val === "Delivery"){
317-
valueString = formatNumber(parseFloat(report.getOrderTypesTotal.deliveryTotal,10)).toString();
318-
319-
} else if (val === "Online"){
320-
valueString = formatNumber(parseFloat(report.getOrderTypesTotal.onlineTotal,10)).toString();
321-
322-
} else if (val === "Family"){
323-
valueString = formatNumber(parseFloat(report.getOrderTypesTotal.familyTotal,10)).toString();
306+
let orderTypes = [
307+
"Dine-in",
308+
"Takeaway",
309+
"Delivery",
310+
"Online",
311+
"Family",
312+
];
313+
orderTypes.map(val => {
314+
let orderString = "" + val;
315+
let valueString = "";
316+
if (val === "Dine-in") {
317+
valueString = formatNumber(
318+
parseFloat(report.getOrderTypesTotal.dineInTotal, 10),
319+
).toString();
320+
} else if (val === "Takeaway") {
321+
valueString = formatNumber(
322+
parseFloat(report.getOrderTypesTotal.takeawayTotal, 10),
323+
).toString();
324+
} else if (val === "Delivery") {
325+
valueString = formatNumber(
326+
parseFloat(report.getOrderTypesTotal.deliveryTotal, 10),
327+
).toString();
328+
} else if (val === "Online") {
329+
valueString = formatNumber(
330+
parseFloat(report.getOrderTypesTotal.onlineTotal, 10),
331+
).toString();
332+
} else if (val === "Family") {
333+
valueString = formatNumber(
334+
parseFloat(report.getOrderTypesTotal.familyTotal, 10),
335+
).toString();
336+
}
337+
let totalLength = orderString.length + valueString.length;
324338

325-
}
326-
let totalLength = orderString.length + valueString.length;
327-
328-
for (let i = 0; i < 32 - totalLength; i += 1) {
329-
orderString += " ";
330-
}
331-
orderString += valueString;
332-
writePromises.push(
333-
BluetoothSerial.write(
334-
TinyPOS.bufferedText(`${orderString}`, {size: "normal"}, true),
335-
),
336-
);
337-
});
339+
for (let i = 0; i < 32 - totalLength; i += 1) {
340+
orderString += " ";
341+
}
342+
orderString += valueString;
338343
writePromises.push(
339-
BluetoothSerial.write(
340-
TinyPOS.bufferedText(
341-
"================================",
342-
{size: "normal"},
343-
true,
344-
),
344+
BluetoothSerial.write(
345+
TinyPOS.bufferedText(
346+
`${orderString}`,
347+
{ size: "normal" },
348+
true,
345349
),
350+
),
346351
);
347-
JSON.parse(report.categories_total_amounts).map(val => {
348-
let categoryString = "" + val.name;
349-
let valueString = formatNumber(parseFloat(val.total_amount, 10)).toString();
350-
let totalLength = categoryString.length + valueString.length;
352+
});
353+
writePromises.push(
354+
BluetoothSerial.write(
355+
TinyPOS.bufferedText(
356+
"================================",
357+
{ size: "normal" },
358+
true,
359+
),
360+
),
361+
);
362+
JSON.parse(report.categories_total_amounts).map(val => {
363+
let categoryString = "" + val.name;
364+
let valueString = formatNumber(
365+
parseFloat(val.total_amount, 10),
366+
).toString();
367+
let totalLength = categoryString.length + valueString.length;
351368

352-
for (let i = 0; i < 32 - totalLength; i += 1) {
353-
categoryString += " ";
354-
}
355-
categoryString += valueString;
356-
writePromises.push(
357-
BluetoothSerial.write(
358-
TinyPOS.bufferedText(`${categoryString}`, {size: "normal"}, true),
359-
),
360-
);
361-
});
369+
for (let i = 0; i < 32 - totalLength; i += 1) {
370+
categoryString += " ";
371+
}
372+
categoryString += valueString;
362373
writePromises.push(
363-
BluetoothSerial.write(
364-
TinyPOS.bufferedText(
365-
"================================",
366-
{size: "normal"},
367-
true,
368-
),
374+
BluetoothSerial.write(
375+
TinyPOS.bufferedText(
376+
`${categoryString}`,
377+
{ size: "normal" },
378+
true,
369379
),
380+
),
370381
);
382+
});
383+
writePromises.push(
384+
BluetoothSerial.write(
385+
TinyPOS.bufferedText(
386+
"================================",
387+
{ size: "normal" },
388+
true,
389+
),
390+
),
391+
);
371392
}
372393
const datePrinted = new Date();
373394
writePromises.push(

src/store/PosStore/CategoryStore.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -191,28 +191,27 @@ const Store = types
191191
});
192192
});
193193
},
194-
addCategoriesAmounts(obj){
195-
let categories_amounts = JSON.parse(self.categories_total_amounts);
196-
categories_amounts.push(obj);
197-
self.categories_total_amounts = JSON.stringify(categories_amounts);
198-
},
194+
addCategoriesAmounts(obj) {
195+
let categories_amounts = JSON.parse(self.categories_total_amounts);
196+
categories_amounts.push(obj);
197+
self.categories_total_amounts = JSON.stringify(categories_amounts);
198+
},
199199
categoriesAmounts(obj) {
200-
201-
let categories_amounts = JSON.parse(self.categories_total_amounts);
202-
let amounts = false;
203-
if (categories_amounts.length > 0){
204-
for (let i = 0; i < categories_amounts.length; i += 1){
205-
if (obj.name === categories_amounts[i].name){
200+
let categories_amounts = JSON.parse(self.categories_total_amounts);
201+
let amounts = false;
202+
if (categories_amounts.length > 0) {
203+
for (let i = 0; i < categories_amounts.length; i += 1) {
204+
if (obj.name === categories_amounts[i].name) {
206205
categories_amounts[i].total_amount += obj.total_amount;
207206
amounts = true;
208207
}
209208
}
210209
}
211-
if (!amounts){
212-
self.addCategoriesAmounts(obj);
213-
} else {
214-
self.categories_total_amounts = JSON.stringify(categories_amounts);
215-
}
210+
if (!amounts) {
211+
self.addCategoriesAmounts(obj);
212+
} else {
213+
self.categories_total_amounts = JSON.stringify(categories_amounts);
214+
}
216215
},
217216
}));
218217

src/store/PosStore/ItemStore.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,7 @@ const Store = types
223223
});
224224
}
225225
},
226-
findName(name, price) {
227-
226+
findName(name, price) {
228227
return new Promise(function(resolve, reject) {
229228
self.filtered = true;
230229
db
@@ -240,7 +239,6 @@ const Store = types
240239
},
241240
})
242241
.then(result => {
243-
244242
const categoryItemsReplacement = result.docs.map(item =>
245243
JSON.parse(JSON.stringify(item)),
246244
);

src/store/PosStore/ShiftStore.js

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ export const Shift = types
4747
reportType: types.optional(types.string, "XReading"),
4848
dateUpdated: types.optional(types.Date, Date.now),
4949
syncStatus: types.optional(types.boolean, false),
50-
categories_total_amounts: types.optional(types.string, "[]"),
51-
50+
categories_total_amounts: types.optional(types.string, "[]"),
5251
})
5352
.preProcessSnapshot(snapshot => assignUUID(snapshot, "Shift"))
5453
.views(self => ({
@@ -214,29 +213,28 @@ export const Shift = types
214213
self.commissions = self.commissions + commission;
215214
self.ending_cash = self.ending_cash - commission;
216215
},
217-
addCategoriesAmounts(obj){
218-
let categories_amounts = JSON.parse(self.categories_total_amounts);
219-
categories_amounts.push(obj);
220-
self.categories_total_amounts = JSON.stringify(categories_amounts);
221-
},
222-
categoriesAmounts(obj) {
223-
224-
let categories_amounts = JSON.parse(self.categories_total_amounts);
225-
let amounts = false;
226-
if (categories_amounts.length > 0){
227-
for (let i = 0; i < categories_amounts.length; i += 1){
228-
if (obj.name === categories_amounts[i].name){
229-
categories_amounts[i].total_amount += obj.total_amount;
230-
amounts = true;
231-
}
232-
}
233-
}
234-
if (!amounts){
235-
self.addCategoriesAmounts(obj);
236-
} else {
237-
self.categories_total_amounts = JSON.stringify(categories_amounts);
216+
addCategoriesAmounts(obj) {
217+
let categories_amounts = JSON.parse(self.categories_total_amounts);
218+
categories_amounts.push(obj);
219+
self.categories_total_amounts = JSON.stringify(categories_amounts);
220+
},
221+
categoriesAmounts(obj) {
222+
let categories_amounts = JSON.parse(self.categories_total_amounts);
223+
let amounts = false;
224+
if (categories_amounts.length > 0) {
225+
for (let i = 0; i < categories_amounts.length; i += 1) {
226+
if (obj.name === categories_amounts[i].name) {
227+
categories_amounts[i].total_amount += obj.total_amount;
228+
amounts = true;
238229
}
239-
},
230+
}
231+
}
232+
if (!amounts) {
233+
self.addCategoriesAmounts(obj);
234+
} else {
235+
self.categories_total_amounts = JSON.stringify(categories_amounts);
236+
}
237+
},
240238
}));
241239

242240
const ShiftStore = types
@@ -348,7 +346,7 @@ const ShiftStore = types
348346
total_taxes: doc.total_taxes,
349347
status: doc.status,
350348
reportType: doc.reportType,
351-
categories_total_amounts: doc.categories_total_amounts,
349+
categories_total_amounts: doc.categories_total_amounts,
352350
dateUpdated: Date.now(),
353351
syncStatus: false,
354352
});
@@ -380,7 +378,8 @@ const ShiftStore = types
380378
total_taxes: entries.rows[i].doc.total_taxes,
381379
status: entries.rows[i].doc.status,
382380
reportType: entries.rows[i].doc.reportType,
383-
categories_total_amounts: entries.rows[i].doc.categories_total_amounts,
381+
categories_total_amounts:
382+
entries.rows[i].doc.categories_total_amounts,
384383
dateUpdated: Date.now(),
385384
syncStatus: false,
386385
});
@@ -425,7 +424,7 @@ const ShiftStore = types
425424
total_taxes: report.total_taxes,
426425
attendant: report.attendant,
427426
status: report.status,
428-
categories_total_amounts: report.categories_total_amounts,
427+
categories_total_amounts: report.categories_total_amounts,
429428

430429
commissions: report.commissions,
431430
reportType: report.reportType,

src/store/PosStore/syncInBackground.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ export function syncObjectValues(status, store, jobStatus) {
2727
if (resLength > 0 || trashLength > 0) {
2828
const protocol = store.stateStore.isHttps ? "https://" : "http://";
2929

30-
const syncInfo = {
31-
deviceId: store.stateStore.deviceId,
32-
url: protocol + store.printerStore.sync[0].url,
33-
user_name: store.printerStore.sync[0].user_name,
34-
password: store.printerStore.sync[0].password,
35-
};
30+
const syncInfo = {
31+
deviceId: store.stateStore.deviceId,
32+
url: protocol + store.printerStore.sync[0].url,
33+
user_name: store.printerStore.sync[0].user_name,
34+
password: store.printerStore.sync[0].password,
35+
};
3636

3737
store.syncStore
3838
.syncNow(result, status, syncInfo, jobStatus, store)

0 commit comments

Comments
 (0)