From eaa591a17bf9ac01b76e0caf136a051c909f9c26 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 27 Sep 2017 13:07:33 +0630 Subject: [PATCH] update addorder --- app/assets/javascripts/addorder.js | 77 +++++++++++++++++++----------- 1 file changed, 48 insertions(+), 29 deletions(-) diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 8edc25b8..dfb94dd4 100644 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -110,6 +110,9 @@ $(function(){ item_sets = $(this).data('item-sets'); for(var field in item_sets) { + + $('.set_order').attr('data-min-qty',item_sets[field]["min_selectable_qty"]); + value = item_sets[field]["instances"]; $(value).each(function(i){ console.log(value); @@ -161,12 +164,15 @@ $(function(){ $(".options-list").empty(); + rowCount = $('.selected-instance'); item_options = $(this).data('option'); + min_qty = $(this).data('min-qty'); max_qty = $(this).data('max-qty'); + code = $(this).data('code'); - if ($('.selected-instance').length+1 <= max_qty) { + if (rowCount.length+1 <= max_qty) { for(var field in item_options) { value = item_options[field]["values"]; type = item_options[field]["type"]; @@ -192,7 +198,7 @@ $(function(){ $(this).removeAttr('data-options'); $('#instance_option').text('') }else { - if ($('.selected-instance').length+1 <= max_qty) { + if (rowCount.length+1 <= max_qty) { sub_total = $('#set_total_price').text(); name = $(this).data('name'); price = $(this).data('price'); @@ -214,36 +220,49 @@ $(function(){ qty = parseInt($('#set_count').val()); item_code = $('#set_item_code').text(); item_name = $('#set_name').text(); + min_qty = $(this).data('min-qty'); var items = $('.selected-instance'); - attribute_arr = [] - option_arr = [] - var rowCount = $('.summary-items tbody tr').length+1; - $(items).each(function(i){ - code = $(items[i]).attr('data-code'); - name = $(items[i]).attr('data-name'); - price = $(items[i]).attr('data-price'); - option = $(items[i]).attr('data-options'); - total = qty * price ; - option_arr.push(option); - row ="" - +''+rowCount+'' - +'' + item_name+ ' ' + name +'' - +'' + qty + '' - +'' - + parseFloat(total).toFixed(2) - +'' - +''; - $(".summary-items tbody").append(row); - rowCount = rowCount + 1; - }); - calculate_sub_total(); + if (items.length >= min_qty) { + attribute_arr = [] + option_arr = [] + var rowCount = $('.summary-items tbody tr').length+1; + $(items).each(function(i){ + code = $(items[i]).attr('data-code'); + name = $(items[i]).attr('data-name'); + price = $(items[i]).attr('data-price'); + option = $(items[i]).attr('data-options'); + total = qty * price ; + option_arr.push(option); + row ="" + +''+rowCount+'' + +'' + item_name+ ' ' + name +'' + +'' + qty + '' + +'' + + parseFloat(total).toFixed(2) + +'' + +''; + $(".summary-items tbody").append(row); + rowCount = rowCount + 1; + }); + calculate_sub_total(); + $(".sx_item_set_detailModal").css({ 'display': "none" }); + }else{ + $(".sx_item_set_detailModal").css({ 'display': "block" }); + $.alert({ + title: 'Alert!', + content: 'Please Select Minimum ' + min_qty + " items", + type: 'red', + typeAnimated: true, + btnClass: 'btn-danger', + }); + } }); //End add order Click