From ec2b20bc22a9f5080fabea0348058567b73cd844 Mon Sep 17 00:00:00 2001 From: jiloysss Date: Tue, 23 Jul 2019 12:01:33 +0800 Subject: [PATCH] Fix: Tax Issue Refactor: None Feat: None --- src/boot/setup.js | 1 + src/services/tailorder.js | 1 - src/store/PosStore/DbFunctions.js | 84 ++++++++++--------- src/store/PosStore/ReceiptStore.js | 3 - .../components/ConfirmOrderModalComponent.js | 2 +- 5 files changed, 48 insertions(+), 43 deletions(-) diff --git a/src/boot/setup.js b/src/boot/setup.js index 033193a..d777d2e 100755 --- a/src/boot/setup.js +++ b/src/boot/setup.js @@ -11,6 +11,7 @@ import getTheme from "../theme/components"; import variables from "../theme/variables/platform"; const stores2 = config(); +BackgroundJob.cancel({jobKey: "AutomaticSync"}); const backgroundJob = { jobKey: "myJob", job: () => syncObjectValues("sync", stores2, true), diff --git a/src/services/tailorder.js b/src/services/tailorder.js index 70beb47..17f84c4 100644 --- a/src/services/tailorder.js +++ b/src/services/tailorder.js @@ -5,7 +5,6 @@ exports.sendOrder = function(origin, order) { method: "POST", body: JSON.stringify(order), }; - return fetch(url, fetchData).then(response => response.json()); }; diff --git a/src/store/PosStore/DbFunctions.js b/src/store/PosStore/DbFunctions.js index c9d08da..236bc66 100644 --- a/src/store/PosStore/DbFunctions.js +++ b/src/store/PosStore/DbFunctions.js @@ -6,6 +6,7 @@ import { unformat } from "accounting-js"; import FrappeFetch from "react-native-frappe-fetch"; import { Toast } from "native-base"; var validUrl = require("valid-url"); +import BackgroundJob from "react-native-background-job"; export function openAndSyncDB(dbName, withSync = false) { const SQLiteAdapter = SQLiteAdapterFactory(SQLite); @@ -37,49 +38,56 @@ export function sync( store, ) { // if (credentials.url !== undefined && credentials.user_name !== undefined && credentials.password !== undefined) { - if (validUrl.isWebUri(credentials.url.toLowerCase())) { - return FrappeFetch.createClient({ - url: credentials.url.toLowerCase(), - username: credentials.user_name, - password: credentials.password, - }) + if (credentials.url) { - .then(responseLog => { - const { Client } = FrappeFetch; - return Client.postApi( - "tailpos_sync.sync_pos.sync_data", - // "frappe.handler.ping", - { - tailposData: JSON.parse(jsonObject), - trashObject: JSON.parse(trashObj), - deviceId: credentials.deviceId, - typeOfSync: type, - }, - ); - }) - .catch(error => { - store.stateStore.setIsNotSyncing(); + if (validUrl.isWebUri(credentials.url.toLowerCase())) { + return FrappeFetch.createClient({ + url: credentials.url.toLowerCase(), + username: credentials.user_name, + password: credentials.password, + }) - if (!jobStatus) { + .then(responseLog => { + const {Client} = FrappeFetch; + return Client.postApi( + "tailpos_sync.sync_pos.sync_data", + // "frappe.handler.ping", + { + tailposData: JSON.parse(jsonObject), + trashObject: JSON.parse(trashObj), + deviceId: credentials.deviceId, + typeOfSync: type, + }, + ); + }) + .catch(error => { + store.stateStore.setIsNotSyncing(); + BackgroundJob.cancel({ jobKey: "AutomaticSync" }); + if (!jobStatus) { + Toast.show({ + text: "Unable to sync", + type: "danger", + duration: 5000, + }); + + } + }) + + .then(response => response.json()) + .then(responseJson => { + return responseJson.message.data; + }); + } else { + store.stateStore.setIsNotSyncing(); Toast.show({ - text: "Unable to sync", - type: "danger", - duration: 5000, + text: "Invalid URL", + type: "danger", + duration: 5000, }); - } - }) - - .then(response => response.json()) - .then(responseJson => { - return responseJson.message.data; - }); + BackgroundJob.cancel({ jobKey: "AutomaticSync" }); + } } else { - store.stateStore.setIsNotSyncing(); - Toast.show({ - text: "Invalid URL", - type: "danger", - duration: 5000, - }); + BackgroundJob.cancel({ jobKey: "AutomaticSync" }); } } diff --git a/src/store/PosStore/ReceiptStore.js b/src/store/PosStore/ReceiptStore.js index d0953b3..d084b85 100644 --- a/src/store/PosStore/ReceiptStore.js +++ b/src/store/PosStore/ReceiptStore.js @@ -297,9 +297,6 @@ export const Receipt = types ReceiptStore.delete(self); // Reference }, clear() { - self.discount = ""; - self.discountValue = 0; - self.taxesValue = "0"; // Yay! self.lines.splice(0, self.lines.length); diff --git a/src/stories/components/ConfirmOrderModalComponent.js b/src/stories/components/ConfirmOrderModalComponent.js index 5c37abb..b8b0f42 100644 --- a/src/stories/components/ConfirmOrderModalComponent.js +++ b/src/stories/components/ConfirmOrderModalComponent.js @@ -61,9 +61,9 @@ export default class ConfirmOrderModalComponent extends React.Component { + -