My orders array contains a number of meal plans, each with items inside.
I'm trying to process all orders as paid in the inner loop when I click on place orders. However, the code is only processing some and leaving others behind.
Below is my implementation:
make_delivery_orders(){
let self = this;
var orders = this.deliveryPlans;
swal('This process will place delivery orders! \nAre you sure you want to continue?' ,{
icon: 'info',
buttons: {
secondary:"Cancel",
danger:"Yes & Continue"
},
}).then(async(value) => {
if(value === 'danger'){
orders.map((order,index) => {
if(order.included){
self.post(siteUrl + '/main/sync' , order ,function(o){
if( parseInt(o.result) === 200) {
let r = o.response;
try{
var push = {
data: order,
}
console.log(order)
var url = siteUrl+'/main/print_order_string/';
self.post(url, push,function (res) {
try {
var text = res.response
// to pay the meal in DB
order.details.data[0].cart.map((item,index)=>{
app.mealTopay_array.push(item.meal_id);
setTimeout(function() {
app.pay_selected_meal(item.meal_id, 1)
}, 100);
app.pay_selected_meal(item.meal_id, 1)
console.log(app.mealTopay_array)
})
// to print the receipt
// app.print_text(text, order)
// app.pay_meal_array()
}catch(e){
console.log(e)
}
});
}catch(e){
console.log(e)
}
}
});
}
})
self.make_delivery_by_click('sdj')
}
});
},
pay_selected_meal(id, val){
let self = this;
console.log(id)
console.log(val)
this.post(siteUrl+'/main/updateMealPaid/'+id+'/'+val,'',function (res) {
try {
console.log(res)
// insertLog(log)
}
catch (e) {
console.error(e);
}
self.loading = false;
});
},