From 9c1a324effb96602988fa266f4775de4938c8799 Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 30 Jun 2017 13:29:55 +0630 Subject: [PATCH] add other charges --- app/controllers/api/orders_controller.rb | 20 +- .../origami/other_charges_controller.rb | 48 +++ app/models/ability.rb | 2 + app/views/origami/home/show.html.erb | 24 +- .../origami/other_charges/index.html.erb | 331 ++++++++++++++++++ config/routes.rb | 5 + 6 files changed, 418 insertions(+), 12 deletions(-) create mode 100644 app/controllers/origami/other_charges_controller.rb create mode 100644 app/views/origami/other_charges/index.html.erb diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb index 817c7eea..3a7dacc3 100644 --- a/app/controllers/api/orders_controller.rb +++ b/app/controllers/api/orders_controller.rb @@ -68,8 +68,8 @@ class Api::OrdersController < Api::ApiController if booking.dining_facility_id.to_i == params[:table_id].to_i && booking.booking_status != 'moved' if !booking.sale_id.nil? sale_status = check_order_with_booking(booking) - puts "WWwwWWWWWWww" - puts sale_status + # puts "WWwwWWWWWWww" + # puts sale_status if sale_status return return_json_status_with_code(400, "bill requested") end @@ -79,8 +79,8 @@ class Api::OrdersController < Api::ApiController end else sale_status = check_order_with_table(params[:table_id]) - puts "OOOOOOOOO" - puts sale_status + # puts "OOOOOOOOO" + # puts sale_status if sale_status return return_json_status_with_code(400, "bill requested") end @@ -88,8 +88,8 @@ class Api::OrdersController < Api::ApiController end #booking exists else sale_status = check_order_with_table(params[:table_id]) - puts "MMMMMMMM" - puts sale_status + # puts "MMMMMMMM" + # puts sale_status if sale_status # return false , @message = "bill requested" return return_json_status_with_code(400, "bill requested") @@ -109,13 +109,13 @@ class Api::OrdersController < Api::ApiController def check_order_with_table(table_id) table = DiningFacility.find(table_id) if table - booking = table.get_moved_booking - puts booking + booking = table.get_current_booking + # puts booking if booking if !booking.sale_id.nil? if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new" @order.new_booking = true - return true + return false end else @order.new_booking = false @@ -130,7 +130,7 @@ class Api::OrdersController < Api::ApiController def check_order_with_booking(booking) if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new" @order.new_booking = true - return true + return false else @order.new_booking = false @order.booking_id = params[:booking_id] diff --git a/app/controllers/origami/other_charges_controller.rb b/app/controllers/origami/other_charges_controller.rb new file mode 100644 index 00000000..654f539a --- /dev/null +++ b/app/controllers/origami/other_charges_controller.rb @@ -0,0 +1,48 @@ +class Origami::OtherChargesController < BaseOrigamiController + authorize_resource :class => false + + def index + sale_id = params[:sale_id] + if Sale.exists?(sale_id) + @sale_data = Sale.find(sale_id) + end + end + + def create + sale_id = params[:sale_id] + other_charges_items = JSON.parse(params[:other_charges_items]) + sub_total = params[:sub_total] + + 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 + sale.total_amount = sub_total.to_f + sale.grand_total = sub_total.to_f + sale.total_tax; + sale.save + if other_charges_items.length > 0 + #save sale item for discount + other_charges_items.each do |di| + # origin_sale_item = SaleItem.find(di["id"]) + sale_item = SaleItem.new + + sale_item.sale_id = sale_id + sale_item.product_code = "Other Charges" + sale_item.product_name = di["name"] + sale_item.remark = "Other Charges" + + sale_item.qty = 1 + sale_item.unit_price = di["price"] + sale_item.taxable_price = di["price"] + sale_item.is_taxable = 0 + + sale_item.price = di["price"] + sale_item.save + end + end + end + + dining = {:table_id => table_id, :table_type => table_type } + render :json => dining.to_json + end +end \ No newline at end of file diff --git a/app/models/ability.rb b/app/models/ability.rb index 87371392..0d54d030 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -40,6 +40,8 @@ class Ability can :add_customer, Customer can :update_sale_by_customer, Customer + can :index, :other_charges + can :create, :other_charges can :index, :discount can :create, :discount can :remove_discount_items, :discount diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index dde68c48..f89560f3 100644 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -303,7 +303,8 @@ <% if @status_order == 'order' && @status_sale != 'sale' %> - + + @@ -313,6 +314,7 @@ + @@ -390,6 +392,25 @@ $(document).ready(function(){ return false; }); + // Add Other Charges + $('#other-charges').click(function() { + var sale = $('#sale_id').val(); + if (sale!="") { + var sale_id = sale + }else{ + var sale_id = $('#save_order_id').attr('data-order'); + } + + if(sale_id!=""){ + window.location.href = '/origami/' + sale_id + '/other_charges' + } + else { + alert("Please select an table!"); + } + + return false; + }); + // Discount for Payment $('#discount').click(function() { var sale = $('#sale_id').val(); @@ -408,7 +429,6 @@ $(document).ready(function(){ return false; }); - }); // Print for first bill diff --git a/app/views/origami/other_charges/index.html.erb b/app/views/origami/other_charges/index.html.erb new file mode 100644 index 00000000..129aa0e0 --- /dev/null +++ b/app/views/origami/other_charges/index.html.erb @@ -0,0 +1,331 @@ +
+ +
+ +
+ +
+
+
+ +

Receipt No: <%=@sale_data.receipt_no rescue ' '%>

+ +
+
+

Date: <%=@sale_data.receipt_date.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%>

+
+
+
+ + + + + + + + <% sub_total = 0 %> + <% @sale_data.sale_items.each do |sale_item| %> + <% + sub_total += sale_item.qty*sale_item.unit_price + unless sale_item.price == 0 + %> + > + + + + + <% + end + end + %> + +
ItemsQTY + Price +
+ + <%=sale_item.product_name%>@<%=sale_item.unit_price%> + + <%=sale_item.qty%> + + <%=(sale_item.qty*sale_item.unit_price)%> +
+
+ +
+
+
+ + + +
+ +
+
+
Other Charges Control
+
+
+
+
+
+
+ +
+
+ +
+
+
+
+ +
+ +
+
+
+
+
3000
+
+
+
1
+
2
+
3
+
+
+ +
+
+
5000
+
+
+
4
+
5
+
6
+
+
+ +
+
+
10000
+
+
+
7
+
8
+
9
+
+
+ +
+
+
15000
+
+
+
0
+
.
+
00
+
+
+ +
+
+
20000
+
+
+
+
DEL
+
CLR
+
+
+
+ +
+
+ + +
+
+
+
+
+
+ + +
+ +
+ + +
+
+
+ + diff --git a/config/routes.rb b/config/routes.rb index dd38914d..10ee5a05 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -93,6 +93,11 @@ Rails.application.routes.draw do # post '/:booking_id' => 'home#item_show' + # Other Charges + get "/:sale_id/other_charges" => "other_charges#index" + post "/:sale_id/other_charges" => "other_charges#create" + + # Discount get "/:id/discount" => "discounts#index" post "/:id/discount" => "discounts#create" get "/:id/remove_all_discount" => "discounts#remove_all_discount"