Guest User

Untitled

a guest
Sep 26th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. async getTotal(){
  2. for(let records of this.records){
  3. await this.selectPresentWeekData(records.weekid,records.croppingid); // asynchronous functions contains query in database
  4. this.loopThroughValues(); // must get the value from the query
  5. this.loopObjectAccess(); // calculates the total using the values from the query
  6. this.pushDataToShow(records.weekid); // push the query data to a new object
  7. }
  8. }
  9.  
  10. selectPresentWeekData(weekid,cropid){
  11. console.log('Collecting input data'+weekid+' cropid '+cropid);
  12. this.sqlite.create({name: 'ionicdb.db',location: 'default'}).then((db: SQLiteObject) => {
  13. const asyncQuery = [
  14. 'SELECT * FROM input_expenses WHERE input_expenses.week_input_rowid = "'+weekid+'" AND input_expenses.input_crop_rowid = "'+cropid+'"',
  15. 'SELECT * FROM labor_expenses WHERE labor_expenses.week_labor_rowid = "'+weekid+'" AND labor_expenses.labor_crop_rowid = "'+cropid+'"',
  16. 'SELECT * FROM food_expenses WHERE food_expenses.week_food_rowid = "'+weekid+'" AND food_expenses.food_crop_rowid = "'+cropid+'"'
  17. ];
  18. Promise.all(asyncQuery.map(asyncQuery =>{
  19. db.executeSql(asyncQuery,{})
  20. })).then(res => {
  21. console.log(res);
  22. }).catch(() => console.log('error'));
  23. }).catch(e => console.log(e.message));
  24. }
Add Comment
Please, Sign In to add comment