Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
jiloysss committed Feb 5, 2019
1 parent fa8b601 commit 5d99bf1
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 79 deletions.
21 changes: 12 additions & 9 deletions src/container/SalesContainer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,15 +542,18 @@ export default class SalesContainer extends React.Component {
quantity.commission_amount
) {
this.props.attendantStore.find(quantity.attendantName).then(result => {
let discountValue =
parseFloat(quantity.discount) > 0
? price * qty - parseFloat(quantity.discount) / 100 * (price * qty)
: price * qty;
line.setCommissionAttendantName(quantity.attendantName);
line.setCommissionRate(result.commission, 10);
line.setCommissionAmount(
parseFloat(result.commission, 10) / 100 * discountValue,
);
if (result) {
let discountValue =
parseFloat(quantity.discount) > 0
? price * qty -
parseFloat(quantity.discount) / 100 * (price * qty)
: price * qty;
line.setCommissionAttendantName(quantity.attendantName);
line.setCommissionRate(result.commission, 10);
line.setCommissionAmount(
parseFloat(result.commission, 10) / 100 * discountValue,
);
}
});
}
// unselect the line
Expand Down
56 changes: 30 additions & 26 deletions src/container/SettingsContainer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import BluetoothSerial from "react-native-bluetooth-serial";
import { observer, inject } from "mobx-react/native";
import { NavigationActions } from "react-navigation";
import { BluetoothStatus } from "react-native-bluetooth-status";
// import { syncObjectValues } from "../../store/PosStore/syncInBackground";
import { syncObjectValues } from "../../store/PosStore/syncInBackground";
import Settings from "@screens/Settings";

import { syncData } from "./sync";
// import { syncData } from "./sync";

@inject(
"printerStore",
Expand Down Expand Up @@ -605,31 +605,35 @@ export default class SettingsContainer extends React.Component {
}

syncAll(status) {
const { url, user_name, password } = this.props.printerStore.sync[0];
// console.log("SYYYYYYNC")
// const { url, user_name, password } = this.props.printerStore.sync[0];
//
// syncData(url, {
// username: user_name,
// password: password,
// })
// .then(res => {
// if (res.uptodate) {
// Toast.show({
// text: "Already up-to-date",
// buttonText: "Okay",
// });
// } else {
// if (res.items) {
// this.props.itemStore.addBulk(res.items);
// }
// }
// })
// .catch(err => {
// Toast.show({
// type: "danger",
// text: err.toString(),
// buttonText: "Okay",
// });
// });

syncData(url, {
username: user_name,
password: password,
})
.then(res => {
if (res.uptodate) {
Toast.show({
text: "Already up-to-date",
buttonText: "Okay",
});
} else {
if (res.items) {
this.props.itemStore.addBulk(res.items);
}
}
})
.catch(err => {
Toast.show({
type: "danger",
text: err.toString(),
buttonText: "Okay",
});
});
const storeProps = this.props;
syncObjectValues(status, storeProps, false);
}

onSyncSave() {
Expand Down
24 changes: 20 additions & 4 deletions src/container/SettingsContainer/sync.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import Frappe from "react-native-frappe-fetch";
var validUrl = require("valid-url");
import { Toast } from "native-base";

module.exports.syncData = function(url, credentials) {
const { username, password } = credentials;

return Frappe.createClient({ url, username, password })
.then(res => Frappe.Client.postApi("tailpos_sync.sync"))
.then(res => res.json())
.then(res => res.message);
if (validUrl.isWebUri(url.toLowerCase())) {
return Frappe.createClient({ url, username, password })
.then(res => {
Frappe.Client.postApi("tailpos_sync.sync");
})
.then(res => {
res.json();
})
.then(res => {
res.message;
});
} else {
Toast.show({
text: "Invalid URL",
type: "danger",
duration: 5000,
});
}
};
28 changes: 24 additions & 4 deletions src/store/PosStore/AttendantStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,31 @@ const AttendantStore = types
if (obj) {
return obj;
} else {
await db.get(id).then(doc => {
return Attendant.create(JSON.parse(JSON.stringify(doc)));
});
// await db.get(id).then(doc => {
// if(doc){
// return Attendant.create(JSON.parse(JSON.stringify(doc)));
//
// } else {
// return null;
// }
// });
db
.find({
selector: {
_id: { $regex: `.*${id}.*` },
},
})
.then(result => {
const { docs } = result;
if (docs.length > 0) {
return Attendant.create(
JSON.parse(JSON.stringify(result.docs[0])),
);
} else {
return null;
}
});
}
return null;
},
getData() {
return new Promise(function(resolve, reject) {
Expand Down
34 changes: 29 additions & 5 deletions src/store/PosStore/CategoryStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,40 @@ const Store = types
if (!obj && id !== "No Category") {
// If category is found in the databaseeeeee
db
.get(id)
.then(doc =>
resolve(Category.create(JSON.parse(JSON.stringify(doc)))),
);
.find({
selector: {
_id: { $regex: `.*${id}.*` },
},
})
.then(result => {
const { docs } = result;
if (docs.length > 0) {
resolve(
Category.create(JSON.parse(JSON.stringify(result.docs[0]))),
);
} else {
resolve(null);
}
});
// db
// .get(id)
// .then(doc =>{
// console.log(doc)
// if(doc){
// console.log("TRUUUE")
// } else {
// console.log("NULL")
// resolve(null);
// }
// }).catch(e => {
// throw e
// })
// resolve(null);
} else if (obj) {
resolve(obj); // if found object
}

// If no object found
resolve(null);
});
},
setCategory(category) {
Expand Down
27 changes: 23 additions & 4 deletions src/store/PosStore/CustomerStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,30 @@ const Store = types
if (obj) {
return obj;
} else {
await db.get(id).then(doc => {
return Customer.create(JSON.parse(JSON.stringify(doc)));
});
db
.find({
selector: {
_id: { $regex: `.*${id}.*` },
},
})
.then(result => {
const { docs } = result;
if (docs.length > 0) {
return Customer.create(
JSON.parse(JSON.stringify(result.docs[0])),
);
} else {
return null;
}
});
// await db.get(id).then(doc => {
// if(doc){
// return Customer.create(JSON.parse(JSON.stringify(doc)));
// } else {
// return null;
// }
// });
}
return null;
},
delete(data) {
destroy(data);
Expand Down
21 changes: 16 additions & 5 deletions src/store/PosStore/DiscountStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,23 @@ const Store = types
if (obj) {
return obj;
} else {
db.get(id).then(doc => {
return Discount.create(JSON.parse(JSON.stringify(doc)));
});
db
.find({
selector: {
_id: { $regex: `.*${id}.*` },
},
})
.then(result => {
const { docs } = result;
if (docs.length > 0) {
return Discount.create(
JSON.parse(JSON.stringify(result.docs[0])),
);
} else {
return null;
}
});
}

return null;
},
findFromRows(id) {
for (var i = 0; i < self.rows.length; i++) {
Expand Down
38 changes: 31 additions & 7 deletions src/store/PosStore/ItemStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,22 @@ const Store = types
updateLengthObjects(obj) {
if (obj) {
let objectLength = JSON.parse(self.categoryLengths);

var length = false;
for (let i = 0; i < objectLength.length; i += 1) {
if (obj === objectLength[i].categoryId) {
objectLength[i].categoryId = obj;
objectLength[i].categoryLength += 1;
length = true;
}
}

self.categoryLengths = JSON.stringify(objectLength);
if (!length) {
self.addCategoryLength({
categoryId: obj,
categoryLength: 1,
});
} else {
self.categoryLengths = JSON.stringify(objectLength);
}
}
},
updateLengthObjectsDelete(obj) {
Expand All @@ -186,11 +193,28 @@ const Store = types
if (obj) {
return obj;
} else {
db.get(id).then(doc => {
return Item.create(JSON.parse(JSON.stringify(doc)));
});
// db.get(id).then(doc => {
// if(doc){
// return Item.create(JSON.parse(JSON.stringify(doc)));
// } else {
// return null;
// }
// });
db
.find({
selector: {
_id: { $regex: `.*${id}.*` },
},
})
.then(result => {
const { docs } = result;
if (docs.length > 0) {
return Item.create(JSON.parse(JSON.stringify(result.docs[0])));
} else {
return null;
}
});
}
return null;
},
findName(name, price) {
return new Promise(function(resolve, reject) {
Expand Down
Loading

0 comments on commit 5d99bf1

Please sign in to comment.