From c73cfa4c2da9f35ae698930595cfd4a7b3f9f78e Mon Sep 17 00:00:00 2001 From: Yan Date: Sat, 8 Jul 2017 23:29:31 +0630 Subject: [PATCH] control to req bill and discount ui update --- .../origami/discounts_controller.rb | 27 +-- .../origami/request_bills_controller.rb | 29 +-- app/views/origami/discounts/index.html.erb | 185 +++++++++++++----- app/views/origami/home/show.html.erb | 20 +- .../origami/request_bills/print.json.jbuilder | 8 +- app/views/origami/rooms/show.html.erb | 20 +- 6 files changed, 207 insertions(+), 82 deletions(-) diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index 16590320..ae53c5b3 100644 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -49,11 +49,14 @@ class Origami::DiscountsController < BaseOrigamiController end # Re-calc All Amount in Sale - sale.compute_by_sale_items(sale_id, sale.sale_items, overall_discount.to_f) + sale.compute_by_sale_items(sale_id, sale.sale_items, overall_discount.to_f) + result = {:status=> "Success", :table_id => table_id, :table_type => table_type } + else + result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table_type } end - dining = {:table_id => table_id, :table_type => table_type } - render :json => dining.to_json + + render :json => result.to_json end # Remove selected discount Items @@ -78,11 +81,12 @@ class Origami::DiscountsController < BaseOrigamiController # sale.save # Re-calc All Amount in Sale sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount) - end + result = {:status=> "Success", :table_id => table_id, :table_type => table_type } + else + result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table_type } + end - dining = {:table_id => table_id, :table_type => table_type } - - render :json => dining.to_json + render :json => result.to_json end # Remove all discount Items @@ -108,11 +112,12 @@ class Origami::DiscountsController < BaseOrigamiController # Re-calc All Amount in Sale sale.compute_by_sale_items(sale_id, sale.sale_items, 0) - end + result = {:status=> "Success", :table_id => table_id, :table_type => table_type } + else + result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table_type } + end - dining = {:table_id => table_id, :table_type => table_type } - - render :json => dining.to_json + render :json => result.to_json end #discount for selected order diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index cfea9d37..687c872f 100644 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -5,19 +5,24 @@ class Origami::RequestBillsController < BaseOrigamiController @sale = Sale.new sale_order=SaleOrder.new - order_id = params[:id] # order_id - bk_order = BookingOrder.find_by_order_id(order_id) - check_booking = Booking.find_by_booking_id(bk_order.booking_id) - if check_booking.sale_id.nil? - # Create Sale if it doesn't exist - # puts "current_login_employee" - # puts current_login_employee.name - @status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee, cashier = nil) - @sale_data = Sale.find_by_sale_id(@sale_id) - @sale_items = SaleItem.where("sale_id=?",@sale_id) + if ShiftSale.current_open_shift(current_user.id) + order_id = params[:id] # order_id + bk_order = BookingOrder.find_by_order_id(order_id) + check_booking = Booking.find_by_booking_id(bk_order.booking_id) + if check_booking.sale_id.nil? + # Create Sale if it doesn't exist + # puts "current_login_employee" + # puts current_login_employee.name + @status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee, cashier = nil) + @sale_data = Sale.find_by_sale_id(@sale_id) + @sale_items = SaleItem.where("sale_id=?",@sale_id) + else + @sale_data = Sale.find_by_sale_id(check_booking.sale_id) + @sale_items = SaleItem.where("sale_id=?",@sale_data.sale_id) + end else - @sale_data = Sale.find_by_sale_id(check_booking.sale_id) - @sale_items = SaleItem.where("sale_id=?",@sale_data.sale_id) + @status = false + @error_message = "No Current Open Shift for This Employee" end # Not Use for these printed bill cannot give customer diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index 07d67b84..a75a6dad 100644 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -352,13 +352,24 @@ $(document).ready(function(){ url: ajax_url, data: params, success:function(result){ - alert("Successfully Discount!"); - if(result.table_type == "Table"){ - window.location.href = "/origami/table/" + result.table_id - } - else { - window.location.href = "/origami/room/" + result.table_id - } + $.confirm({ + title: 'Infomation!', + content: result.status, + buttons: { + confirm: { + text: 'Ok', + btnClass: 'btn-green', + action: function(){ + if(result.table_type == "Table"){ + window.location.href = "/origami/table/" + result.table_id + } + else { + window.location.href = "/origami/room/" + result.table_id + } + } + } + } + }); } }); }); @@ -372,8 +383,19 @@ $(document).ready(function(){ // Selected Items var sale_items = get_selected_sale_items(); if(sale_items.length == 0){ - alert("You have no selected item!"); - return; + $.confirm({ + title: 'Infomation!', + content: "You have no selected item!", + buttons: { + confirm: { + text: 'Ok', + btnClass: 'btn-green', + action: function(){ + return; + } + } + } + }); } for(var i=0;i < sale_items.length;i++){ @@ -381,8 +403,19 @@ $(document).ready(function(){ discount_items.push(sale_items[i]); } else { - alert("You have selected no discount item!"); - return; + $.confirm({ + title: 'Infomation!', + content: "You have selected no discount item!!", + buttons: { + confirm: { + text: 'Ok', + btnClass: 'btn-green', + action: function(){ + return; + } + } + } + }); } } @@ -392,13 +425,24 @@ $(document).ready(function(){ url: "/origami/" + sale_id + "/remove_discount_items", data: params, success: function(result){ - alert('Removed Discount'); - if(result.table_type == "Table"){ - window.location.href = "/origami/table/" + result.table_id - } - else { - window.location.href = "/origami/room/" + result.table_id - } + $.confirm({ + title: 'Infomation!', + content: result.status, + buttons: { + confirm: { + text: 'Ok', + btnClass: 'btn-green', + action: function(){ + if(result.table_type == "Table"){ + window.location.href = "/origami/table/" + result.table_id + } + else { + window.location.href = "/origami/room/" + result.table_id + } + } + } + } + }); } }); }); @@ -410,13 +454,24 @@ $(document).ready(function(){ type: "GET", url: "/origami/" + sale_id + "/remove_all_discount", success: function(result){ - alert('Removed All Discount'); - if(result.table_type == "Table"){ - window.location.href = "/origami/table/" + result.table_id - } - else { - window.location.href = "/origami/room/" + result.table_id - } + $.confirm({ + title: 'Infomation!', + content: result.status, + buttons: { + confirm: { + text: 'Ok', + btnClass: 'btn-green', + action: function(){ + if(result.table_type == "Table"){ + window.location.href = "/origami/table/" + result.table_id + } + else { + window.location.href = "/origami/room/" + result.table_id + } + } + } + } + }); } }); }); @@ -540,10 +595,23 @@ function calculate_overall_discount(type, amount){ // For Percentage Pay if(type == 1){ if(amount > 100 ){ - aler("Percentage Value over 100!"); - return; + $.confirm({ + title: 'Infomation!', + content: "Percentage Value over 100!", + buttons: { + confirm: { + text: 'Ok', + btnClass: 'btn-green', + action: function(){ + return; + } + } + } + }); + } + else{ + total_discount = (origin_sub_total * amount)/100; } - total_discount = (origin_sub_total * amount)/100; } $("#order-discount").text(total_discount); @@ -562,7 +630,7 @@ function calculate_item_discount(type, amount, sale_items, account_types){ for(var i=0;i < sale_items.length;i++){ if(account_types.length > 0){ for(var j=0; j < account_types.length; j++){ - if(sale_items[i].account_id != account_types[j].id){ + if(sale_items[i].account_id == account_types[j].id){ // Discount Items var discount_item_row = item_row_template(type, sale_items[i], dis_amount, amount); $("#order-items-table tbody").append(discount_item_row); @@ -604,34 +672,45 @@ function calculate_item_discount(type, amount, sale_items, account_types){ // For Percentage Pay if(type == 1){ if(amount > 100 ){ - aler("Percentage Value over 100!"); - return; + $.confirm({ + title: 'Infomation!', + content: "Percentage Value over 100!", + buttons: { + confirm: { + text: 'Ok', + btnClass: 'btn-green', + action: function(){ + return; + } + } + } + }); } - - // Check sale items exists - if(sale_items.length > 0){ - for(var i=0;i < sale_items.length;i++){ - if(account_types.length > 0){ - for(var j=0; j < account_types.length; j++){ - if(sale_items[i].account_id != account_types[j].id){ - // Discount Items - dis_amount = 0 - ((sale_items[i].price * amount)/100); - var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount); - $("#order-items-table tbody").append(discount_item_row); - total_discount = total_discount + dis_amount; + else{ + // Check sale items exists + if(sale_items.length > 0){ + for(var i=0;i < sale_items.length;i++){ + if(account_types.length > 0){ + for(var j=0; j < account_types.length; j++){ + if(sale_items[i].account_id == account_types[j].id){ + // Discount Items + dis_amount = 0 - ((sale_items[i].price * amount)/100); + var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount); + $("#order-items-table tbody").append(discount_item_row); + total_discount = total_discount + dis_amount; + } } } + else { + dis_amount = 0 - ((sale_items[i].price * amount)/100); + var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount); + $("#order-items-table tbody").append(discount_item_row); + total_discount = total_discount + dis_amount; + } } - else { - dis_amount = 0 - ((sale_items[i].price * amount)/100); - var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount); - $("#order-items-table tbody").append(discount_item_row); - total_discount = total_discount + dis_amount; - - } + sub_total = origin_sub_total + total_discount; } } - // No Needs For Auto Selected // Check account types exists // if(account_types.length > 0){ @@ -653,9 +732,7 @@ function calculate_item_discount(type, amount, sale_items, account_types){ // else { // alert("No Items!"); // } - // } - - sub_total = origin_sub_total + total_discount; + // } } $("#order-sub-total").text(sub_total); diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 8b613409..73959b5b 100644 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -469,8 +469,24 @@ $('#request_bills').click(function() { url: ajax_url, // data: 'order_id='+ order_id, success:function(result){ - - location.reload(); + if(!result.status){ + $.confirm({ + title: 'Infomation!', + content: result.error_message, + buttons: { + confirm: { + text: 'Ok', + btnClass: 'btn-green', + action: function(){ + window.location.href = '/origami'; + } + } + } + }); + } + else { + location.reload(); + } } }); }); diff --git a/app/views/origami/request_bills/print.json.jbuilder b/app/views/origami/request_bills/print.json.jbuilder index 08bf292c..332a9cec 100644 --- a/app/views/origami/request_bills/print.json.jbuilder +++ b/app/views/origami/request_bills/print.json.jbuilder @@ -1 +1,7 @@ -json.status true +if @status == true + #show invoice number and stuff + json.status @status +else + json.status @status + json.error_message @error_message +end diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index 9b681fe1..66a48522 100644 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -457,8 +457,24 @@ $('#request_bills').click(function() { url: ajax_url, // data: 'order_id='+ order_id, success:function(result){ - - location.reload(); + if(!result.status){ + $.confirm({ + title: 'Infomation!', + content: result.error_message, + buttons: { + confirm: { + text: 'Ok', + btnClass: 'btn-green', + action: function(){ + window.location.href = '/origami'; + } + } + } + }); + } + else { + location.reload(); + } } }); });