diff --git a/app/assets/stylesheets/origami.scss b/app/assets/stylesheets/origami.scss index 2ba6fe52..e0a59dc7 100644 --- a/app/assets/stylesheets/origami.scss +++ b/app/assets/stylesheets/origami.scss @@ -72,6 +72,7 @@ } .action-btn { + white-space: normal !important; height: 60px; margin-bottom: 5px; } @@ -168,6 +169,8 @@ background-color: blue } +/* End Colors */ + .left{ margin-left:1px; } @@ -175,6 +178,7 @@ .bottom{ margin-bottom: 1px; } + /*----- Reset -----*/ select.form-control { @@ -197,6 +201,7 @@ tr.discount-item-row:hover { .required abbr{ color: red !important; } + /* Jquery Confirm */ .jconfirm-box-container{ diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index 463f6dc6..79412d60 100644 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -29,7 +29,6 @@ class Origami::DiscountsController < BaseOrigamiController if discount_items.length > 0 #save sale item for discount discount_items.each do |di| - puts di origin_sale_item = SaleItem.find(di["id"]) sale_item = SaleItem.new @@ -53,6 +52,61 @@ class Origami::DiscountsController < BaseOrigamiController render :json => dining.to_json end + # Remove selected discount Items + def remove_discount_items + sale_id = params[:sale_id] + discount_items = JSON.parse(params[:discount_items]) + if Sale.exists?(sale_id) + sale = Sale.find(sale_id) + table_id = sale.bookings[0].dining_facility_id + table_type = DiningFacility.find(table_id).type + + if discount_items.length > 0 + #destroy sale item for discount + discount_items.each do |di| + sale_item = SaleItem.find(di["id"]) + price = (sale_item.price - 0) + sale.total_amount = (sale.total_amount + price) + sale_item.destroy + end + end + + sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax; + sale.save + end + + dining = {:table_id => table_id, :table_type => table_type } + + render :json => dining.to_json + end + + # Remove all discount Items + def remove_all_discount + sale_id = params[:id] + + if Sale.exists?(sale_id) + sale = Sale.find(sale_id) + table_id = sale.bookings[0].dining_facility_id + table_type = DiningFacility.find(table_id).type + + #destroy all discount sale item + sale.sale_items.each do |si| + if si.remark == "Discount" && si.price < 0 + price = (si.price - 0) + sale.total_amount = (sale.total_amount + price) + si.destroy + end + end + + sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax; + sale.save + end + + dining = {:table_id => table_id, :table_type => table_type } + + render :json => dining.to_json + end + #discount for selected order # def create # sale_id = params[:sale_id] diff --git a/app/models/ability.rb b/app/models/ability.rb index 5e5fb4f3..2c110e77 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -40,6 +40,8 @@ class Ability can :index, :discount can :create, :discount + can :remove_discount_items, :discount + can :remove_all_discount, :discount can :show, :payment can :create, :payment @@ -63,6 +65,8 @@ class Ability can :index, :discount can :create, :discount + can :remove_discount_items, :discount + can :remove_all_discount, :discount can :show, :payment can :create, :payment diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index 9979c32f..5e5a3385 100644 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -172,7 +172,7 @@
- +
@@ -187,6 +187,8 @@
+ +
@@ -358,6 +360,55 @@ $(document).ready(function(){ } }); }); + + // Remove selected given discount item + $("#remove-item-discount").on('click', function(e){ + e.preventDefault(); + var sale_id = $('#sale-id').text(); + var discount_items = []; + + // Selected Items + var sale_items = get_selected_sale_items(); + for(var i=0;i < sale_items.length;i++){ + if(sale_items[i].price < 0){ + discount_items.push(sale_items[i]); + } + } + + var params = { 'sale_id': sale_id, 'discount_items': JSON.stringify(discount_items) }; + $.ajax({ + type: "POST", + 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 + } + } + }); + }); + + $("#remove-all").on('click', function(e){ + e.preventDefault(); + var sale_id = $('#sale-id').text(); + $.ajax({ + 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 + } + } + }); + }); }); /* Remove Selection */ diff --git a/config/routes.rb b/config/routes.rb index b6535034..8ca49ba7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -93,6 +93,8 @@ Rails.application.routes.draw do get "/:id/discount" => "discounts#index" post "/:id/discount" => "discounts#create" + get "/:id/remove_all_discount" => "discounts#remove_all_discount" + post "/:id/remove_discount_items" => "discounts#remove_discount_items" post "/:id/request_bills" => "request_bills#print",:as => "request_bill" ,:defaults => { :format => 'json' } get '/:sale_id/reprint' => 'payments#reprint' ,:defaults => { :format => 'json' }