From a91816bb4e77ce49b9c94826e5bf044087919b70 Mon Sep 17 00:00:00 2001 From: Yan Date: Sun, 25 Jun 2017 22:41:26 +0630 Subject: [PATCH] qty edit in oqs --- app/assets/javascripts/OQS.js | 21 ++++++++++- app/controllers/oqs/edit_controller.rb | 18 +++++++++ app/views/layouts/OQS.html.erb | 1 - app/views/oqs/edit/index.html.erb | 27 ++++++++++++++ app/views/oqs/home/index.html.erb | 6 +-- app/views/origami/discounts/index.html.erb | 43 ++++------------------ config/routes.rb | 4 ++ 7 files changed, 79 insertions(+), 41 deletions(-) create mode 100644 app/views/oqs/edit/index.html.erb diff --git a/app/assets/javascripts/OQS.js b/app/assets/javascripts/OQS.js index 0574148b..30a8e264 100644 --- a/app/assets/javascripts/OQS.js +++ b/app/assets/javascripts/OQS.js @@ -68,7 +68,9 @@ $(document).ready(function(){ }); $(".order-item-edit").on('click', function(){ - + var _self = $(this); // To know in ajax return + var assigned_item_id=$(this).attr('id').substr(5); + window.location.href = '/oqs/'+ assigned_item_id + "/edit" }); // complete for queue item @@ -137,4 +139,21 @@ $(document).ready(function(){ success: function(data){ } }); }); + + // Qty update for OQS Edit Controller + $('#qty-update').on('click', function(){ + var qty_weight = $("input[name='qty_weight']").val(); + var remarks = $("textarea[name='remarks']").val(); + var order_items_id = $(this).attr('data-id'); + var params = { 'order_items_id': order_items_id, 'qty_weight': qty_weight, 'remarks': remarks } + $.ajax({ + type: 'POST', + url: '/oqs/' + order_items_id, + data: params, + success: function(result){ + alert("Updated!"); + window.location.href = '/oqs'; + } + }); + }); }); diff --git a/app/controllers/oqs/edit_controller.rb b/app/controllers/oqs/edit_controller.rb index e69de29b..d2236caa 100644 --- a/app/controllers/oqs/edit_controller.rb +++ b/app/controllers/oqs/edit_controller.rb @@ -0,0 +1,18 @@ +class Oqs::EditController < BaseOqsController + def index + assigned_item_id = params[:id] + assigned_item = AssignedOrderItem.find(assigned_item_id) + @order_item = OrderItem.where("order_id='#{ assigned_item.order_id }' AND item_code='#{ assigned_item.item_code }'"); + end + + def update + order_items_id = params[:order_items_id] + qty_weight = params[:qty_weight] + remarks = params[:remarks] + + order_item = OrderItem.find(order_items_id); + order_item.qty = qty_weight + order_item.remark = remarks + order_item.save + end +end diff --git a/app/views/layouts/OQS.html.erb b/app/views/layouts/OQS.html.erb index 9f736336..102edba2 100644 --- a/app/views/layouts/OQS.html.erb +++ b/app/views/layouts/OQS.html.erb @@ -23,7 +23,6 @@ <% end %> <%= yield %> - diff --git a/app/views/oqs/edit/index.html.erb b/app/views/oqs/edit/index.html.erb new file mode 100644 index 00000000..15d48144 --- /dev/null +++ b/app/views/oqs/edit/index.html.erb @@ -0,0 +1,27 @@ +
+
+
+
Update Quantity
+
+
+

<%= @order_item[0].item_name + " - [" + @order_item[0].qty.to_s + "]" %>

+
+ + +
+
+ + +
+
+ + Back + + +
+
+
+
+
+
+ diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb index ce82cbfa..3cc24ce9 100644 --- a/app/views/oqs/home/index.html.erb +++ b/app/views/oqs/home/index.html.erb @@ -29,7 +29,7 @@ -
+
@@ -105,7 +105,7 @@

Order at - <%= qid.created_at.strftime("%Y %m %d") %> + <%= qid.created_at.getlocal.strftime("%Y-%m-%d") %> - <%= qid.item_order_by %> @@ -164,7 +164,7 @@

-
+
diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index 45ab4b2b..5f6b1396 100644 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -199,31 +199,26 @@ $(document).ready(function(){ case 'num': var input_value = $(this).attr("data-value"); if (original_value == "0.0"){ - $('#discount-amount').val(input_value); - // update_balance(); + $('#discount-amount').val(input_value); } else{ - $('#discount-amount').val(original_value + '' + input_value); - // update_balance(); + $('#discount-amount').val(original_value + '' + input_value); } break; case 'add': var input_value = $(this).attr("data-value"); amount = parseInt(input_value); - $('#discount-amount').val(amount); - // update_balance(); + $('#discount-amount').val(amount); break; case 'del' : var discount_text=$('#discount-amount').val(); - $('#discount-amount').val(discount_text.substr(0,discount_text.length-1)); - // update_balance(); + $('#discount-amount').val(discount_text.substr(0,discount_text.length-1)); break; case 'clr': - $('#discount-amount').val("0.0"); - // update_balance(); + $('#discount-amount').val("0.0"); break; } event.handled = true; @@ -332,13 +327,7 @@ $(document).ready(function(){ var sale_id = $('#sale-id').text(); var discount_items = JSON.stringify(get_discount_item_rows()); var overall_discount = $("#order-discount").text(); - var sub_total = $('#order-sub-total').text(); - // var sale_item_id = $('.selected-item').attr('id').substr(0,16); - // var sub_total = $('#order-sub-total').text(); - // var grand_total = $('#order-grand-total').text(); - // var discount_type = $('#discount-type').val(); - // var discount_value = $('#discount-amount').val(); - // var discount_amount = discount_value; + var sub_total = $('#order-sub-total').text(); var ajax_url = "/origami/" + sale_id + "/discount"; var params = { 'sale_id': sale_id, 'sub_total': sub_total, 'discount_items': discount_items, 'overall_discount': overall_discount }; @@ -354,30 +343,12 @@ $(document).ready(function(){ } else { window.location.href = "/origami/room/" + result.table_id - } - - // window.history.back(); + } } }); }); }); -/* For Receipt - Update Balance */ -function update_balance(){ - var discount_amount = $('#discount-amount').val(); - var sub_total = $('#order-sub-total').text(); - var tax = $('#order-Tax').text(); - - // For Percentage Discount - // if(discount_type == 1){ - // discount_amount=(sub_total*discount_amount)/100; - // } - - var total = (parseFloat(sub_total) + parseFloat(tax)) - discount_amount; - $('#order-discount').text(discount_amount); - $('#order-grand-total').text(total); -} - /* Remove Selection */ function selection_remove(){ $(".item-row").removeClass("selected-item"); diff --git a/config/routes.rb b/config/routes.rb index c93beb92..40b14fc4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -143,6 +143,10 @@ Rails.application.routes.draw do post 'update_delivery', to: "home#update_delivery_status" + # qty update + get "/:id/edit", to: "edit#index" + post "/:id", to: "edit#update" + # Pass assigned_order_item_id get 'print/print/:id', to: "print#print" get 'print/print_order_summary/:id', to: "print#print_order_summary"