Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save iamsardorbek/08c8043cf4cbd1430939c6f49d7de0e9 to your computer and use it in GitHub Desktop.
Save iamsardorbek/08c8043cf4cbd1430939c6f49d7de0e9 to your computer and use it in GitHub Desktop.
async await order form
async function orderCompliesWithMML() {
let data = {
room_id: d.room_id,
person_id: d.person_id,
currency_id: ctrl.currency_id,
delivery_date: d.delivery_date,
ignore_balance: ctrl.ignore_balance,
price_type_id: priceTypeIds(),
payment_type_id: d.payment_type_id,
inventory_kind: 'G'
};
try {
var result = await page.post(':get_mml_inventory_ids', data);
} catch(e) {
page.alert(e);
}
// filter out the inventories that are banned from the received list
let mml_inventories = _.filter(result.mml_inventories, function(inventory){ return !_.findWhere(d.bans.PRODUCT.items, inventory); });
// take the unique ids, no need for inventory_kind data now
q.mml_inventory_ids = _.uniq(_.map(mml_inventories, inventory_object => inventory_object[0]));
// collect the selected product ids that are in mml
let order_inventory_ids = [];
_.each(ctrl.inventories, function(ik_data) {
_.each(ik_data.items, row => {
let r = _.pick(row, 'product_id', 'is_in_mml');
if (r.is_in_mml == 'Y') order_inventory_ids.push(r.product_id);
});
});
// take unique ones regardless of inventory_kind
order_inventory_ids = _.uniq(order_inventory_ids);
let intersection_mml_and_order = _.intersection(q.mml_inventory_ids, order_inventory_ids);
console.log(intersection_mml_and_order, q.mml_inventory_ids, order_inventory_ids);
if (intersection_mml_and_order.length == q.mml_inventory_ids.length)
return true;
else {
// page.alert(await );
// q.current_step = 1;
return false;
}
}
function radioClass(get){
return get ? 'fa-dot-circle' : 'fa-circle';
}
async function checkedStep(step) {
if (step == 0) {
let valid = page.valid(scope.step0);
if (valid)
getBans();
return valid;
} else if (step == 1) {
if (!q.is_edit && d.compulsory_to_comply_with_mml == 'Y') {
// orderCompliesWithMML();
if (!await orderCompliesWithMML()) {
page.alert('test123');
scope.$digest();
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment