From 464e72012bb52cbcb10dc37446980ca51261079c Mon Sep 17 00:00:00 2001 From: Yan Date: Tue, 27 Jun 2017 15:26:02 +0630 Subject: [PATCH 1/8] waiter and cashier in api/bill_controller --- app/controllers/api/api_controller.rb | 7 ++++++- app/controllers/api/bill_controller.rb | 6 +++--- app/models/sale.rb | 23 +++++++++++++++-------- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/app/controllers/api/api_controller.rb b/app/controllers/api/api_controller.rb index c61b5bc2..5b60b5df 100644 --- a/app/controllers/api/api_controller.rb +++ b/app/controllers/api/api_controller.rb @@ -1,6 +1,6 @@ class Api::ApiController < ActionController::API include TokenVerification - helper_method :current_token, :current_login_employee + helper_method :current_token, :current_login_employee, :get_cashier private @@ -13,6 +13,11 @@ class Api::ApiController < ActionController::API end end + # Get current Cashier + def get_cashier + @cashier = Employee.where("role = 'cashier' AND token_session <> ''") + end + def current_login_employee @employee = Employee.find_by_token_session(current_token) end diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index f7a4070d..ab9c56f8 100644 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -13,7 +13,7 @@ class Api::BillController < Api::ApiController if booking if booking.sale_id.nil? @sale = Sale.new - @status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee) + @status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee, get_cashier) else @status = true @sale_id = booking.sale_id @@ -22,7 +22,7 @@ class Api::BillController < Api::ApiController elsif (params[:order_id]) @sale = Sale.new - @status, @sale_id = @sale.generate_invoice_from_order(params[:order_id], current_login_employee) + @status, @sale_id = @sale.generate_invoice_from_order(params[:order_id], current_login_employee, get_cashier) end @sale_data = Sale.find_by_sale_id(@sale_id) @@ -32,7 +32,7 @@ class Api::BillController < Api::ApiController #shop detail shop_details = Shop.find(1) - customer= Customer.where('customer_id=' + @sale_data.customer_id) + customer= Customer.find(@sale_data.customer_id) # get member information member_info = Customer.get_member_account(customer) diff --git a/app/models/sale.rb b/app/models/sale.rb index 8f7f17d8..a214c551 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -25,7 +25,7 @@ class Sale < ApplicationRecord SALE_STATUS_OUTSTANDING = "outstanding" SALE_STATUS_COMPLETED = "completed" - def generate_invoice_from_booking(booking_id, requested_by) + def generate_invoice_from_booking(booking_id, requested_by, cashier) booking = Booking.find(booking_id) status = false Rails.logger.debug "Booking -> " + booking.id.to_s @@ -35,9 +35,9 @@ class Sale < ApplicationRecord booking.booking_orders.each do |order| if booking.sale_id - status, sale_id = generate_invoice_from_order(order.order_id, nil, booking, requested_by) + status, sale_id = generate_invoice_from_order(order.order_id, nil, booking, requested_by, cashier) else - status, sale_id = generate_invoice_from_order(order.order_id, booking.sale_id, booking, requested_by) + status, sale_id = generate_invoice_from_order(order.order_id, booking.sale_id, booking, requested_by, cashier) end booking.sale_id = sale_id end @@ -47,7 +47,7 @@ class Sale < ApplicationRecord end end - def generate_invoice_from_order (order_id, sale_id, booking, requested_by) + def generate_invoice_from_order (order_id, sale_id, booking, requested_by, cashier) taxable = true #if sale_id is exsit and validate #add order to that invoice @@ -66,12 +66,19 @@ class Sale < ApplicationRecord #Default Tax - Values self.tax_type = "exclusive" - # set cashier by current login - self.cashier_id = requested_by.id - self.cashier_name = requested_by.name + # set cashier + if cashier != nil + self.cashier_id = cashier[0].id + self.cashier_name = cashier[0].name + else + self.cashier_id = requested_by.id + self.cashier_name = requested_by.name + end + + # set waiter self.requested_by = requested_by.name - self.requested_at = DateTime.now.utc + self.requested_at = DateTime.now.utc.getlocal Rails.logger.debug "Order -> #{order.id} | order_status -> #{order.status}" if order From 950fff469f1f9fa7b342b3d218ab9d656f3db5a2 Mon Sep 17 00:00:00 2001 From: Yan Date: Tue, 27 Jun 2017 15:28:48 +0630 Subject: [PATCH 2/8] update for req bill by cashier --- app/models/sale.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index a214c551..677dabe4 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -47,7 +47,7 @@ class Sale < ApplicationRecord end end - def generate_invoice_from_order (order_id, sale_id, booking, requested_by, cashier) + def generate_invoice_from_order (order_id, sale_id, booking, requested_by, cashier = nil) taxable = true #if sale_id is exsit and validate #add order to that invoice From 58a8cdec6e210353369e5eece00123e5f784f1ff Mon Sep 17 00:00:00 2001 From: Yan Date: Tue, 27 Jun 2017 18:32:58 +0630 Subject: [PATCH 3/8] still dev dis --- app/assets/stylesheets/origami.scss | 5 ++ .../origami/discounts_controller.rb | 56 ++++++++++++++++++- app/models/ability.rb | 4 ++ app/views/origami/discounts/index.html.erb | 53 +++++++++++++++++- config/routes.rb | 2 + 5 files changed, 118 insertions(+), 2 deletions(-) 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' } From b975d6194f2ed63abf4283976a0459b4c5b236b1 Mon Sep 17 00:00:00 2001 From: Yan Date: Wed, 28 Jun 2017 10:59:03 +0630 Subject: [PATCH 4/8] add remove item and remove all in discount --- app/controllers/origami/discounts_controller.rb | 10 ++++------ app/views/origami/discounts/index.html.erb | 9 +++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index 79412d60..6c76c27a 100644 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -64,9 +64,8 @@ class Origami::DiscountsController < BaseOrigamiController 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 = SaleItem.find(di["id"]) + sale.total_amount = (sale.total_amount + sale_item.price.abs) sale_item.destroy end end @@ -91,9 +90,8 @@ class Origami::DiscountsController < BaseOrigamiController #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) + if si.remark == "Discount" && si.price < 0 + sale.total_amount = (sale.total_amount + si.price.abs) si.destroy end end diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index 5e5a3385..8aaf5c4f 100644 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -369,10 +369,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; + } + for(var i=0;i < sale_items.length;i++){ if(sale_items[i].price < 0){ discount_items.push(sale_items[i]); } + else { + alert("You have selected no discount item!"); + return; + } } var params = { 'sale_id': sale_id, 'discount_items': JSON.stringify(discount_items) }; From ea4ba325fa1216e890c474ebb004d4195e39b88d Mon Sep 17 00:00:00 2001 From: Yan Date: Wed, 28 Jun 2017 14:15:35 +0630 Subject: [PATCH 5/8] text change percentage value --- app/views/origami/discounts/index.html.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index 8aaf5c4f..fbbff065 100644 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -138,7 +138,7 @@
-
20%
+
15%
7
@@ -149,7 +149,7 @@
-
30%
+
20%
0
@@ -160,7 +160,7 @@
-
50%
+
30%
From 879a4b366ca85c28f170710e0c6288cf67c62db7 Mon Sep 17 00:00:00 2001 From: Yan Date: Wed, 28 Jun 2017 14:29:11 +0630 Subject: [PATCH 6/8] print as print copies in printer setting --- app/models/printer/receipt_printer.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index 8e389e79..6aed3ebe 100644 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -71,8 +71,13 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker #Print pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, member_info,rebate_amount,shop_details) - pdf.render_file "tmp/receipt_bill.pdf" - self.print("tmp/receipt_bill.pdf") + # print as print copies in printer setting + count = printer_settings.print_copies + begin + pdf.render_file "tmp/receipt_bill.pdf" + self.print("tmp/receipt_bill.pdf") + count -= 1 + end until count == 0 end #Queue No Print From 5ff75fad7d17697e12ffb3e13bfc2b5d4e7b5b0f Mon Sep 17 00:00:00 2001 From: Yan Date: Wed, 28 Jun 2017 15:40:54 +0630 Subject: [PATCH 7/8] fix for undefied method type in item pdf --- app/controllers/origami/request_bills_controller.rb | 2 +- app/models/printer/order_queue_printer.rb | 4 ++-- app/views/origami/payments/show.html.erb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index 314835a2..bd548253 100644 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -12,7 +12,7 @@ class Origami::RequestBillsController < BaseOrigamiController # 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) + @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 diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index f80ee72d..f946e17b 100644 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -33,13 +33,13 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker order=print_query('order_summary', order_id) # For Print Per Item if oqs.cut_per_item - order_items.each do|odi| + order.each do|odi| filename = "tmp/order_item_#{odi.item_name}" + ".pdf" # For Item Options options = odi.options == "[]"? "" : odi.options # check for item not to show - if odi.price != 0 || odi.price != 10 + if odi.price != 0 pdf = OrderItemPdf.new(odi, print_status, options) # pdf.render_file "tmp/order_item.pdf" pdf.render_file filename diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index cef27145..24ff3844 100644 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -136,13 +136,13 @@ <% if @ppamount != 0.0 %>
-
Paypar
+
Redeem
<%= @ppamount %>
<% else %> <% end %> From d35aa23e3463ef7b9ded78d98d1e4608ac4d035b Mon Sep 17 00:00:00 2001 From: Yan Date: Wed, 28 Jun 2017 16:17:56 +0630 Subject: [PATCH 8/8] still dev to respond code for order --- app/controllers/api/orders_controller.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb index 1eba8c56..2fb61b1f 100644 --- a/app/controllers/api/orders_controller.rb +++ b/app/controllers/api/orders_controller.rb @@ -67,13 +67,19 @@ class Api::OrdersController < Api::ApiController if booking if booking.dining_facility_id.to_i == params[:table_id].to_i && booking.booking_status != 'moved' if !booking.sale_id.nil? - check_order_with_booking(booking) + sale_status = check_order_with_booking(booking) + if sale_status + return false + end else @order.new_booking = false @order.booking_id = params[:booking_id] end else - check_order_with_table(params[:table_id]) + sale_status = check_order_with_table(params[:table_id]) + if sale_status + return false + end end end #booking exists else @@ -90,9 +96,11 @@ class Api::OrdersController < Api::ApiController if booking if booking.sale.sale_status == "completed" || booking.sale.sale_status == "billed" @order.new_booking = true + return true else @order.new_booking = false @order.booking_id = booking.booking_id + return false end end end @@ -101,9 +109,11 @@ class Api::OrdersController < Api::ApiController def check_order_with_booking(booking) if booking.sale.sale_status == "completed" || booking.sale.sale_status == "billed" @order.new_booking = true + return true else @order.new_booking = false @order.booking_id = params[:booking_id] + return false end end # Description