From 9de4ca04dc8d69964ef21df7609f3839e68d3ed8 Mon Sep 17 00:00:00 2001 From: phyusin Date: Wed, 4 Jul 2018 11:42:19 +0630 Subject: [PATCH 01/11] check query and tax for webview --- app/controllers/origami/home_controller.rb | 2 +- app/controllers/origami/rooms_controller.rb | 4 +-- app/views/origami/home/index.html.erb | 37 +++++++++++++++------ app/views/origami/home/show.html.erb | 4 ++- app/views/origami/rooms/show.html.erb | 36 ++++++++++---------- 5 files changed, 51 insertions(+), 32 deletions(-) diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 773892f3..2d03d298 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -7,7 +7,7 @@ class Origami::HomeController < BaseOrigamiController @tables = Table.unscoped.all.active.order('status desc') @rooms = Room.unscoped.all.active.order('status desc') @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d')) - @orders = Order.where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') + @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @shop = Shop.first # @shift = ShiftSale.current_open_shift(current_user.id) diff --git a/app/controllers/origami/rooms_controller.rb b/app/controllers/origami/rooms_controller.rb index 6877f8aa..49b7ce14 100755 --- a/app/controllers/origami/rooms_controller.rb +++ b/app/controllers/origami/rooms_controller.rb @@ -3,7 +3,7 @@ class Origami::RoomsController < BaseOrigamiController @tables = Table.unscoped.all.active.order('status desc') @rooms = Room.unscoped.all.active.order('status desc') @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d')) - @orders = Order.where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') + @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') # @shift = ShiftSale.current_open_shift(current_user.id) @webview = false if check_mobile @@ -20,7 +20,7 @@ class Origami::RoomsController < BaseOrigamiController @tables = Table.unscoped.all.active.order('status desc') @rooms = Room.unscoped.all.active.order('status desc') @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d')) - @orders = Order.where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') + @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @room = DiningFacility.find(params[:room_id]) diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index 3f9daa9a..3e565ffa 100755 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -50,8 +50,8 @@
<% end %>
- Zone <%= table.zone_id %>
- Table <%= table.name %> ( <%= table.seater %> Seat ) + Table <%= table.name %> ( <%= table.seater %> Seat )
+ Zone <%= table.zone_id %>
<% else %> @@ -61,16 +61,16 @@
<% end %>
- Zone <%= table.zone_id %>
- Table <%= table.name %> ( <%= table.seater %> Seat ) + Table <%= table.name %> ( <%= table.seater %> Seat )
+ Zone <%= table.zone_id %>
<% end %> <% else %>
- Zone <%= table.zone_id %>
- Table <%= table.name %> ( <%= table.seater %> Seat ) + Table <%= table.name %> ( <%= table.seater %> Seat )
+ Zone <%= table.zone_id %>
<% end %> @@ -107,11 +107,26 @@
<% @orders.each do |order| %> -
-
- <%= order.order_id %> -
-
+
text-white" data-id="<%= order.order_id %>"> +
+ <% + order_status = "" + sale_order = order.sale_orders.first + if sale_order + unless sale_order.sale_id.nil? + sale = Sale.find(sale_order.sale_id) + order_status = sale.sale_status + if order_status == 'new' + order_status = order.status + end + end + else + order_status = order.status + end + %> + <%= order.order_id %> <% if !order_status.empty? %>| <%= order_status %> <% end %> +
+
<% end %>
diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 211cc23b..11057247 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -371,7 +371,9 @@ <% else %> No Tax <% end %>
- + <%if !@webview %> + + <% end %> <%= @obj_sale.total_tax rescue 0%> diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index 52c5d108..0f3064f1 100755 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -144,25 +144,25 @@
<% @orders.each do |order| %>
text-white" data-id="<%= order.order_id %>"> -
- <% - order_status = "" - sale_order = SaleOrder.find_by_order_id(order) - if sale_order - unless sale_order.sale_id.nil? - sale = Sale.find(sale_order.sale_id) - order_status = sale.sale_status - if order_status == 'new' - order_status = order.status +
+ <% + order_status = "" + sale_order = order.sale_orders.first + if sale_order + unless sale_order.sale_id.nil? + sale = Sale.find(sale_order.sale_id) + order_status = sale.sale_status + if order_status == 'new' + order_status = order.status + end end + else + order_status = order.status end - else - order_status = order.status - end - %> + %> <%= order.order_id %> <% if !order_status.empty? %>| <%= order_status %> <% end %> -
-
+
+
<% end %> @@ -360,7 +360,9 @@ <% else %> No Tax <% end %>
- + <%if !@webview %> + + <% end %> <%= @obj_sale.total_tax rescue 0%> From 69333505e70dcc01cffb2a3480c7d74eb0c1a8ad Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 4 Jul 2018 14:24:31 +0630 Subject: [PATCH 02/11] update reduce loading --- .../origami/addorders_controller.rb | 4 ++-- app/models/order.rb | 7 +++--- app/models/order_queue_station.rb | 24 ++++++++++++------- app/models/sale_order.rb | 8 +++---- app/models/shift_sale.rb | 4 ++-- .../api/restaurant/zones/index.json.jbuilder | 16 ++++--------- 6 files changed, 31 insertions(+), 32 deletions(-) diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index 220cce6c..1d3bd755 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -96,8 +96,8 @@ class Origami::AddordersController < BaseOrigamiController end def create - Rails.logger.debug "Order Source - " + params[:order_source].to_s - Rails.logger.debug "Table ID - " + params[:table_id].to_s + # Rails.logger.debug "Order Source - " + params[:order_source].to_s + # Rails.logger.debug "Table ID - " + params[:table_id].to_s is_extra_time = false extra_time = '' diff --git a/app/models/order.rb b/app/models/order.rb index 571c549c..01136578 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -44,8 +44,9 @@ class Order < ApplicationRecord if self.table_id.to_i > 0 table = DiningFacility.find(self.table_id) - table.status = "occupied" - table.save + table.update_attributes(status:"occupied") + # table.status = "occupied" + # table.save end else @@ -144,7 +145,7 @@ class Order < ApplicationRecord end #if (!menu_item.nil?) - Rails.logger.debug menu_item + # Rails.logger.debug menu_item set_order_items = Array.new ##If menu Item set item - must add child items to order as well, where price is only take from menu_item if (menu_item[:type] == "SetMenuItem") diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index 9ecd54c0..19bf82be 100755 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -232,12 +232,15 @@ class OrderQueueStation < ApplicationRecord order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) order_queue_printer.print_order_summary(print_settings, oqs,order.order_id, order_items, print_status="") - AssignedOrderItem.where("order_id = '#{ order.order_id }'").find_each do |ai| - # update print status for order items - ai.print_status=true - ai.save - end + assigned =AssignedOrderItem.where("order_id = '#{ order.order_id }'").pluck(:assigned_order_item_id) + AssignedOrderItem.where({ order_id: '#{assigned}'}).update_all(print_status: true) + # assigned_items =AssignedOrderItem.where("order_id = '#{ order.order_id }'") + # assigned_items.each do |ai| + # # update print status for order items + # ai.print_status=true + # ai.save + # end end #Print order_item in 1 slip per item @@ -273,9 +276,12 @@ class OrderQueueStation < ApplicationRecord end end # update print status for completed same order items - AssignedOrderItem.where("order_id = '#{ order.order_id }'").find_each do |ai| - ai.print_status=true - ai.save - end + # AssignedOrderItem.where("order_id = '#{ order.order_id }'").update_all(print_status: true) + # AssignedOrderItem.where("order_id = '#{ order.order_id }'").find_each do |ai| + # ai.print_status=true + # ai.save + # end + assigned =AssignedOrderItem.where("order_id = '#{ order.order_id }'").pluck(:assigned_order_item_id) + AssignedOrderItem.where({ order_id: '#{assigned}'}).update_all(print_status: true) end end diff --git a/app/models/sale_order.rb b/app/models/sale_order.rb index 786054c9..56a64353 100755 --- a/app/models/sale_order.rb +++ b/app/models/sale_order.rb @@ -8,10 +8,10 @@ class SaleOrder < ApplicationRecord belongs_to :order def create_sale_order(sale, order) - self.sale_id = sale - self.order_id = order - self.save - + sale_order = SaleOrder.new + sale_order.sale_id = sale + sale_order.order_id = order + sale_order.save! end private diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index d217a75c..77adf0bd 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -17,8 +17,8 @@ class ShiftSale < ApplicationRecord belongs_to :employee, :foreign_key => 'employee_id' def self.current_shift - today_date = DateTime.now.strftime("%Y-%m-%d") - shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null").take + # today_date = DateTime.now.strftime("%Y-%m-%d") + shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null").first return shift end diff --git a/app/views/api/restaurant/zones/index.json.jbuilder b/app/views/api/restaurant/zones/index.json.jbuilder index e4d09977..4a8666b4 100755 --- a/app/views/api/restaurant/zones/index.json.jbuilder +++ b/app/views/api/restaurant/zones/index.json.jbuilder @@ -6,25 +6,21 @@ if @zones #List all tables json.tables zone.tables do |table| if table.is_active - booking = table.get_current_booking json.id table.id json.name table.name json.status table.status json.zone_id table.zone_id #Add this zone_id to keep data structure consistance - json.current_booking booking.booking_id rescue "" - json.sale_id booking.sale_id rescue "" + json.current_booking table.get_current_booking.booking_id rescue "" end end json.rooms zone.rooms do |room| if room.is_active - booking = room.get_current_booking json.id room.id json.name room.name json.status room.status json.zone_id room.zone_id #Add this zone_id to keep data structure consistance - json.current_booking booking.booking_id rescue "" - json.sale_id booking.sale_id rescue "" + json.current_booking room.get_current_booking.booking_id rescue "" end end end @@ -32,25 +28,21 @@ if @zones else #list all tables and rooms with out zones json.tables @all_tables do |table| if table.is_active - booking = table.get_current_booking json.id table.id json.name table.name json.status table.status json.zone_id table.zone_id #Add this zone_id to keep data structure consistance - json.current_booking booking.booking_id rescue "" - json.sale_id booking.sale_id rescue "" + json.current_booking table.get_current_booking.booking_id rescue "" end end json.rooms @all_rooms do |room| if room.is_active - booking = room.get_current_booking json.id room.id json.name room.name json.status room.status json.zone_id room.zone_id #Add this zone_id to keep data structure consistance - json.current_booking booking.booking_id rescue "" - json.sale_id booking.sale_id rescue "" + json.current_booking room.get_current_booking.booking_id rescue "" end end end From 4f9a4e298499ae46a38af98ecc25a4153755c38f Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 4 Jul 2018 18:08:15 +0630 Subject: [PATCH 03/11] update db index --- app/controllers/origami/home_controller.rb | 4 +- .../origami/payments_controller.rb | 38 ++++++++----------- app/controllers/origami/shifts_controller.rb | 15 +++++--- app/models/order.rb | 18 +++++---- app/models/sale.rb | 4 +- app/models/sale_payment.rb | 15 +++++--- app/pdf/receipt_bill_pdf.rb | 2 +- 7 files changed, 49 insertions(+), 47 deletions(-) diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 2d03d298..1cd6505d 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -8,7 +8,7 @@ class Origami::HomeController < BaseOrigamiController @rooms = Room.unscoped.all.active.order('status desc') @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d')) @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') - @shop = Shop.first + @shop = shop_detail # @shift = ShiftSale.current_open_shift(current_user.id) end @@ -26,7 +26,7 @@ class Origami::HomeController < BaseOrigamiController @status_sale = "" @sale_array = Array.new - @shop = Shop.first + @shop = shop_detail @membership = MembershipSetting::MembershipSetting @payment_methods = PaymentMethodSetting.all @dining_booking = @dining.bookings.active.where("DATE_FORMAT(created_at,'%Y-%m-%d') = '#{DateTime.now.strftime('%Y-%m-%d')}' OR DATE_FORMAT(created_at,'%Y-%m-%d') = '#{Date.today.prev_day}' ") diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 4bd7ff59..2ca8b45a 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -44,11 +44,11 @@ class Origami::PaymentsController < BaseOrigamiController end #shop detail - shop_details = Shop.first + ## shop_detail = Shop.first # customer= Customer.where('customer_id=' +.customer_id) customer = Customer.find(sale_data.customer_id) # rounding adjustment - if shop_details.is_rounding_adj + if shop_detail.is_rounding_adj a = sale_data.grand_total % 25 # Modulus b = sale_data.grand_total / 25 # Division #not calculate rounding if modulus is 0 and division is even @@ -79,7 +79,7 @@ class Origami::PaymentsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) - filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_details, "Frt",current_balance,nil) + filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_detail, "Frt",current_balance,nil) result = { :filepath => filename, @@ -102,9 +102,9 @@ class Origami::PaymentsController < BaseOrigamiController if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) sale_items = SaleItem.get_all_sale_items(sale_id) - shop_details = Shop.first + #shop_detail = Shop.first # rounding adjustment - if shop_details.is_rounding_adj + if shop_detail.is_rounding_adj a = saleObj.grand_total % 25 # Modulus b = saleObj.grand_total / 25 # Division #not calculate rounding if modulus is 0 and division is even @@ -123,16 +123,10 @@ class Origami::PaymentsController < BaseOrigamiController rebate_amount = nil # For Cashier by Zone - bookings = Booking.where("sale_id='#{sale_id}'") - # if bookings.count > 1 - # # for Multiple Booking - # table = DiningFacility.find(bookings[0].dining_facility_id) - # else - # table = DiningFacility.find(bookings[0].dining_facility_id) - # end - - if bookings[0].dining_facility_id.to_i > 0 - table = DiningFacility.find(bookings[0].dining_facility_id) + # bookings = Booking.where("sale_id='#{sale_id}'") + bookings = Booking.find_by_sale_id(sale_id) + if bookings.dining_facility_id.to_i > 0 + table = DiningFacility.find(bookings.dining_facility_id) cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) @@ -216,7 +210,7 @@ class Origami::PaymentsController < BaseOrigamiController discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "Paid",current_balance,card_data) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Paid",current_balance,card_data) render json: JSON.generate({:status => saleObj.rebate_status, :message => "Can't Rebate coz of Sever Error ", :filename => filename, :receipt_no => sale_receipt_no, :printer_name => printer_name}) @@ -255,7 +249,7 @@ class Origami::PaymentsController < BaseOrigamiController if !@lookup_pdf.nil? @pdf_view = @lookup_pdf.value end - @shop = Shop.first #show shop info + @shop = shop_detail #show shop info @customer_lists = Customer.where("customer_id = 'CUS-000000000001' or customer_id = 'CUS-000000000002'") @@ -435,7 +429,7 @@ class Origami::PaymentsController < BaseOrigamiController customer= Customer.find(saleObj.customer_id) #shop detail - shop_details = Shop.first + #shop_detail = Shop.first # get member information rebate = MembershipSetting.find_by_rebate(1) if customer.membership_id != nil && rebate @@ -464,7 +458,7 @@ class Origami::PaymentsController < BaseOrigamiController discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "Re-print",current_balance,card_data) + filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Re-print",current_balance,card_data) result = { :status => true, @@ -539,7 +533,7 @@ class Origami::PaymentsController < BaseOrigamiController customer= Customer.find(saleObj.customer_id) #shop detail - shop_details = Shop.first + #shop_detail = Shop.first # get printer info print_settings=PrintSetting.find_by_unique_code(unique_code) @@ -549,7 +543,7 @@ class Origami::PaymentsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "FOC",nil,nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "FOC",nil,nil) result = { :status => true, :filepath => filename, @@ -579,7 +573,7 @@ class Origami::PaymentsController < BaseOrigamiController def rounding_adj saleObj = Sale.find(params[:sale_id]) - @shop = Shop.find_by_id(1) + @shop = shop_detail if @shop.is_rounding_adj a = saleObj.grand_total % 25 # Modulus diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index 3b2fe081..fd82d474 100755 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -53,12 +53,15 @@ class Origami::ShiftsController < BaseOrigamiController cashier_terminal.save #add shift_sale_id to card_settle_trans - card_settle_trans = CardSettleTran.select('id').where(['shift_sale_id IS NULL and status IS NOT NULL']) + bank_integration = Lookup.find_by_lookup_type('bank_integration') + if !bank_integration.nil? + card_settle_trans = CardSettleTran.select('id').where(['shift_sale_id IS NULL and status IS NOT NULL']) - card_settle_trans.each do |data| - card_sett_trans = CardSettleTran.find(data.id) - card_sett_trans.shift_sale_id = @shift.id - card_sett_trans.save() + card_settle_trans.each do |data| + card_sett_trans = CardSettleTran.find(data.id) + card_sett_trans.shift_sale_id = @shift.id + card_sett_trans.save() + end end if ENV["SERVER_MODE"] != "cloud" #no print in cloud server @@ -77,7 +80,7 @@ class Origami::ShiftsController < BaseOrigamiController end end end - shop_details = Shop.find(1) + shop_details = shop_detail #get tax shift_obj = ShiftSale.where('id =?',@shift.id) @sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='') diff --git a/app/models/order.rb b/app/models/order.rb index 01136578..af5887e6 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -190,16 +190,18 @@ class Order < ApplicationRecord def update_items_status_to_billed(items) if (items.nil?) + OrderItem.where({ order_items_id: '#{self.order_items.pluck(:order_items_id)}'}).update_all(order_item_status: "billed") ##Update the order status to ensure that reflect the stage - self.order_items.each do |item| - item.order_item_status = "billed" - item.save - end + # self.order_items.each do |item| + # item.order_item_status = "billed" + # item.save + # end else - items.each do |item| - item.order_item_status = "billed" - item.save - end + OrderItem.where({ order_items_id: '#{items.pluck(:order_items_id)}'}).update_all(order_item_status: "billed") + # items.each do |item| + # item.order_item_status = "billed" + # item.save + # end end end diff --git a/app/models/sale.rb b/app/models/sale.rb index 33c7f1b6..48dca4d8 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -412,7 +412,7 @@ class Sale < ApplicationRecord # Tax Re-Calculte def compute_tax(sale, total_taxable, total_discount = 0, order_source = nil, tax_type=nil) - shop = Shop.first(); + shop = Shop.first #if tax is not apply create new record SaleTax.where("sale_id='#{sale.sale_id}'").find_each do |existing_tax| @@ -495,7 +495,7 @@ class Sale < ApplicationRecord # Tax Calculate def apply_tax(total_taxable, order_source = nil) - shop = Shop.first(); + shop = Shop.first #if tax is not apply create new record SaleTax.where("sale_id='#{self.sale_id}'").find_each do |existing_tax| diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 782153f2..9b52c248 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -71,10 +71,12 @@ class SalePayment < ApplicationRecord # update complete order items in oqs booking = Booking.find_by_sale_id(sale_id) booking.booking_orders.each do |sodr| - AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").find_each do |aoi| - aoi.delivery_status = 1 - aoi.save - end + assigned =AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").pluck(:assigned_order_item_id) + AssignedOrderItem.where({ order_id: '#{assigned}'}).update_all(print_status: true) + # AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").find_each do |aoi| + # aoi.delivery_status = 1 + # aoi.save + # end end return true, self.save,membership_data @@ -616,8 +618,9 @@ class SalePayment < ApplicationRecord end end if status && sale_count == 0 - table.status = "available" - table.save + table.update_attributes(status: "available") + # table.status = "available" + # table.save end # type = 'payment' diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index e9bf595c..9a1f92b1 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -199,9 +199,9 @@ class ReceiptBillPdf < Prawn::Document move_down line_move sub_total = 0.0 total_qty = 0.0 + show_price = Lookup.find_by_lookup_type("show_price") sale_items.each do |item| # check for item not to show - show_price = Lookup.find_by_lookup_type("show_price") if item.status != 'Discount' && item.qty > 0 if !show_price.nil? && show_price.value.to_i > 0 && item.price == 0 From f0df6a80baa2e5b85b2e8f49a3f26e0589eef8d3 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 5 Jul 2018 12:50:16 +0630 Subject: [PATCH 04/11] update optimzation --- app/controllers/home_controller.rb | 1 + app/models/assigned_order_item.rb | 18 +++++---- app/models/sale.rb | 10 +++-- app/models/sale_order.rb | 12 +++--- app/views/layouts/login_dashboard.html.erb | 45 +++------------------- 5 files changed, 29 insertions(+), 57 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 09d6671e..4e0e89f3 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -20,6 +20,7 @@ class HomeController < ApplicationController def index # @employees = Employee.all_emp_except_waiter.order("name asc") @employees = Employee.all.where("is_active = true").order("name asc") + @roles = Lookup.collection_of("employee_roles") @login_form = LoginForm.new() render "layouts/login_dashboard", layout: false end diff --git a/app/models/assigned_order_item.rb b/app/models/assigned_order_item.rb index ea1b9b39..d5acc98a 100755 --- a/app/models/assigned_order_item.rb +++ b/app/models/assigned_order_item.rb @@ -8,14 +8,16 @@ class AssignedOrderItem < ApplicationRecord belongs_to :order_queue_station def self.assigned_order_item (order, item_code, instance_code, order_queue_station ) - assigned_order_item = AssignedOrderItem.new() - assigned_order_item.order = order - assigned_order_item.item_code = item_code - assigned_order_item.instance_code = instance_code - assigned_order_item.order_queue_station = order_queue_station - assigned_order_item.print_status = false - assigned_order_item.delivery_status = false - assigned_order_item.save + AssignedOrderItem.transaction do + assigned_order_item = AssignedOrderItem.new() + assigned_order_item.order = order + assigned_order_item.item_code = item_code + assigned_order_item.instance_code = instance_code + assigned_order_item.order_queue_station = order_queue_station + assigned_order_item.print_status = false + assigned_order_item.delivery_status = false + assigned_order_item.save! + end end def self.assigned_order_item_by_job(order_id) diff --git a/app/models/sale.rb b/app/models/sale.rb index 48dca4d8..574d303c 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -415,10 +415,12 @@ class Sale < ApplicationRecord shop = Shop.first #if tax is not apply create new record - SaleTax.where("sale_id='#{sale.sale_id}'").find_each do |existing_tax| - #delete existing and create new - existing_tax.delete - end + # SaleTax.where("sale_id='#{sale.sale_id}'").find_each do |existing_tax| + # #delete existing and create new + # existing_tax.delete + # end + taxes = SaleTax.where("sale_id='#{sale.sale_id}'").pluck(:sale_tax_id) + SaleTax.where("sale_tax_id IN (?)", taxes).destroy_all total_tax_amount = 0 tax_incl_exec = "exclusive" diff --git a/app/models/sale_order.rb b/app/models/sale_order.rb index 56a64353..773f2c06 100755 --- a/app/models/sale_order.rb +++ b/app/models/sale_order.rb @@ -7,11 +7,13 @@ class SaleOrder < ApplicationRecord belongs_to :sale belongs_to :order - def create_sale_order(sale, order) - sale_order = SaleOrder.new - sale_order.sale_id = sale - sale_order.order_id = order - sale_order.save! + def create_sale_order(sale, order) + SaleOrder.transaction do + sale_order = SaleOrder.new + sale_order.sale_id = sale + sale_order.order_id = order + sale_order.save! + end end private diff --git a/app/views/layouts/login_dashboard.html.erb b/app/views/layouts/login_dashboard.html.erb index 5db72f79..df2a35c2 100755 --- a/app/views/layouts/login_dashboard.html.erb +++ b/app/views/layouts/login_dashboard.html.erb @@ -112,49 +112,14 @@
From 58eb7ecb000b49d0c39081ac84f8f12f547ac8ab Mon Sep 17 00:00:00 2001 From: Jueli Moon Aung Date: Thu, 5 Jul 2018 10:55:32 +0000 Subject: [PATCH 05/11] .gitignore edited online with Bitbucket --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 239ae203..df5bf8ff 100755 --- a/.gitignore +++ b/.gitignore @@ -42,7 +42,7 @@ pickle-email-*.html /config/initializers/* config/deploy/config/* config/puma.rb -#config/shops.json +config/shops.json !/log/.keep !/tmp/.keep .ruby-version From a5bb0a6746ad34406817e1b7e0aa6c34cbe89534 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 5 Jul 2018 18:19:16 +0630 Subject: [PATCH 06/11] update optimization --- app/assets/javascripts/addorder.js | 11 ++++--- .../origami/addorders_controller.rb | 7 ++++- .../origami/second_display_controller.rb | 31 ++++++++++--------- app/models/assigned_order_item.rb | 2 -- app/models/order_queue_station.rb | 4 +-- app/models/printer/order_queue_printer.rb | 4 +-- app/models/sale_order.rb | 2 -- app/views/origami/addorders/detail.html.erb | 1 + 8 files changed, 34 insertions(+), 28 deletions(-) diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 07af7f41..d7c176ab 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -1,6 +1,7 @@ $(function() { var role = $('#role').val(); - + var second_display_lookup = $("#display_type"); + console.log(second_display_lookup) type = window.location.href.indexOf("quick_service"); modify_order = window.location.href.indexOf("modify_order"); @@ -428,7 +429,7 @@ $(function() { var items = $('.selected-set'); if (items.length >= min_qty) { - if ($('#server_mode').val() != "cloud") { + if ($('#server_mode').val() != "cloud" && second_display_lookup == 2) { item = get_set_item(items); customer_display_view(item,"set_add"); } @@ -756,7 +757,7 @@ $(function() { $('.add_to_order').attr('data-options',JSON.stringify(option_arr)); $('.add_to_order').attr('data-opt',JSON.stringify(option_arr)); var item_data = $(this); - if ($('#server_mode').val() != "cloud") { + if ($('#server_mode').val() != "cloud" && second_display_lookup == 2) { item = get_item(item_data,"add_to_order"); customer_display_view(item,"add"); } @@ -768,7 +769,7 @@ $(function() { // click plus icon for add $(document).on('click', '.add_icon', function(event){ var item_data = $(this); - if ($('#server_mode').val() != "cloud") { + if ($('#server_mode').val() != "cloud" && second_display_lookup == 2) { item = get_item(item_data,"add_icon"); customer_display_view(item,"add"); } @@ -895,7 +896,7 @@ $(function() { window.location.href = "/origami/room/" + table_id } } - if ($('#server_mode').val() != "cloud") { + if ($('#server_mode').val() != "cloud" && second_display_lookup == 2){ customer_display_view(null,"reload"); } } diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index 1d3bd755..025da23c 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -18,7 +18,12 @@ class Origami::AddordersController < BaseOrigamiController if check_mobile @webview = true end - + display_type = Lookup.find_by_lookup_type("display_type") + if !display_type.nil? && display_type.value==2 + @display_type = display_type.value + else + @display_type = nil + end # if params[:menu] == "true" @menus = [] @menu = [] diff --git a/app/controllers/origami/second_display_controller.rb b/app/controllers/origami/second_display_controller.rb index 5f88bdfc..0b1b967b 100644 --- a/app/controllers/origami/second_display_controller.rb +++ b/app/controllers/origami/second_display_controller.rb @@ -8,24 +8,27 @@ class Origami::SecondDisplayController < BaseOrigamiController end def customer_view - if params[:status]!= "billed" - tax_profiles = TaxProfile.all.order("order_by asc") - else - tax_profiles = nil - end - if ENV["SERVER_MODE"] == 'cloud' - from = request.subdomain + "." + request.domain - else - from = "" + display_type = Lookup.find_by_lookup_type("display_type") + if !display_type.nil? && display_type.value==2 + if params[:status]!= "billed" + tax_profiles = TaxProfile.all.order("order_by asc") + else + tax_profiles = nil + end + if ENV["SERVER_MODE"] == 'cloud' + from = request.subdomain + "." + request.domain + else + from = "" + end + ActionCable.server.broadcast "second_display_view_channel",data: params[:data],tax_profiles: tax_profiles,status:params[:status],from:from end - ActionCable.server.broadcast "second_display_view_channel",data: params[:data],tax_profiles: tax_profiles,status:params[:status],from:from # end end #Shop Name in Navbor - helper_method :shop_detail - def shop_detail - @shop = Shop.first - end + # helper_method :shop_detail + # def shop_detail + # @shop = Shop.first + # end end diff --git a/app/models/assigned_order_item.rb b/app/models/assigned_order_item.rb index d5acc98a..64570f7d 100755 --- a/app/models/assigned_order_item.rb +++ b/app/models/assigned_order_item.rb @@ -8,7 +8,6 @@ class AssignedOrderItem < ApplicationRecord belongs_to :order_queue_station def self.assigned_order_item (order, item_code, instance_code, order_queue_station ) - AssignedOrderItem.transaction do assigned_order_item = AssignedOrderItem.new() assigned_order_item.order = order assigned_order_item.item_code = item_code @@ -17,7 +16,6 @@ class AssignedOrderItem < ApplicationRecord assigned_order_item.print_status = false assigned_order_item.delivery_status = false assigned_order_item.save! - end end def self.assigned_order_item_by_job(order_id) diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index 19bf82be..a0372498 100755 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -207,7 +207,7 @@ class OrderQueueStation < ApplicationRecord private #Print order_items in 1 slip def print_slip(oqs, order, order_items) - printer = PrintSetting.all + printer = PrintSetting.all.order("id ASC") unique_code="OrderSummaryPdf" if !printer.empty? @@ -245,7 +245,7 @@ class OrderQueueStation < ApplicationRecord #Print order_item in 1 slip per item def print_slip_item(oqs, order, assigned_items) - printer = PrintSetting.all + printer = PrintSetting.all.order("id ASC") unique_code="OrderItemPdf" if !printer.empty? diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index 03740f82..504dfab2 100755 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -70,7 +70,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker print_settings.save! end - print_setting = PrintSetting.all + print_setting = PrintSetting.all.order("id ASC") order=print_query('order_summary', order_id) # For Print Per Item if oqs.cut_per_item @@ -170,7 +170,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker print_settings.save! end - print_setting = PrintSetting.all + print_setting = PrintSetting.all.order("id ASC") order=print_query('booking_summary', booking_id) # For Print Per Item diff --git a/app/models/sale_order.rb b/app/models/sale_order.rb index 773f2c06..631a5e62 100755 --- a/app/models/sale_order.rb +++ b/app/models/sale_order.rb @@ -8,12 +8,10 @@ class SaleOrder < ApplicationRecord belongs_to :order def create_sale_order(sale, order) - SaleOrder.transaction do sale_order = SaleOrder.new sale_order.sale_id = sale sale_order.order_id = order sale_order.save! - end end private diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb index c20b53e1..bdcc9854 100644 --- a/app/views/origami/addorders/detail.html.erb +++ b/app/views/origami/addorders/detail.html.erb @@ -11,6 +11,7 @@
+