diff --git a/src/container/SalesContainer/index.js b/src/container/SalesContainer/index.js index 0479ed0..086876f 100644 --- a/src/container/SalesContainer/index.js +++ b/src/container/SalesContainer/index.js @@ -36,7 +36,9 @@ import { tailOrderLine, changeOrderTable, getOrder, + orderItemToReceiptItem, } from "../../services/tailorder"; + import { currentLanguage } from "../../translations/CurrentLanguage"; const Sound = require("react-native-sound"); @@ -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])); } }; diff --git a/src/services/tailorder.js b/src/services/tailorder.js index 1085ee6..70beb47 100644 --- a/src/services/tailorder.js +++ b/src/services/tailorder.js @@ -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 }; };