Skip to content

Commit

Permalink
Merge pull request #66 from iRaySpace/master
Browse files Browse the repository at this point in the history
fix: crashes during table click
  • Loading branch information
iRaySpace authored Jul 16, 2019
2 parents 0ac4782 + 0ce715b commit a7e5138
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/container/SalesContainer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ import {
tailOrderLine,
changeOrderTable,
getOrder,
orderItemToReceiptItem,
} from "../../services/tailorder";

import { currentLanguage } from "../../translations/CurrentLanguage";

const Sound = require("react-native-sound");
Expand Down Expand Up @@ -667,25 +669,14 @@ export default class SalesContainer extends React.Component {

onTableClick = index => {
const { orders, setCurrentTable } = this.props.stateStore;

setCurrentTable(orders[index].id);
const lines = JSON.parse(orders[index].lines);

// Default Receipt
const { defaultReceipt } = this.props.receiptStore;
const { id, items } = orders[index];

// Clear receipts
setCurrentTable(id);
defaultReceipt.clear();

// Add all of the items to the receipt
for (let i = 0; i < lines.length; i++) {
defaultReceipt.add({
item: lines[i].itemCode,
item_name: lines[i].itemName,
price: lines[i].rate,
qty: lines[i].qty,
date: Date.now(),
});
for (let i = 0; i < items.length; i++) {
defaultReceipt.add(orderItemToReceiptItem(items[i]));
}
};

Expand Down
10 changes: 10 additions & 0 deletions src/services/tailorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ exports.tailOrderLine = function(line) {
};
};

exports.orderItemToReceiptItem = function(item) {
return {
item: item.item_code,
item_name: item.item_name,
price: item.rate,
qty: item.qty,
date: item.creation,
};
};

exports.getOrder = function(type, items) {
return { type, items };
};

0 comments on commit a7e5138

Please sign in to comment.