From f33f11df64d0db6c23e47434cbb7dece54c8f389 Mon Sep 17 00:00:00 2001 From: Yan Date: Sun, 18 Jun 2017 03:20:19 +0630 Subject: [PATCH] rescue member call and update oqs and js route bug --- app/assets/javascripts/origami.js | 13 ++--- app/controllers/api/bill_controller.rb | 21 +++++++- app/controllers/oqs/home_controller.rb | 48 +++++++++++++------ app/controllers/origami/home_controller.rb | 1 + .../origami/payments_controller.rb | 2 +- app/models/customer.rb | 7 ++- app/models/order.rb | 2 +- app/models/sale.rb | 36 +++++++------- app/models/sale_item.rb | 2 + app/models/sale_payment.rb | 9 +++- app/pdf/receipt_bill_pdf.rb | 8 ++-- app/views/origami/home/index.html.erb | 4 +- 12 files changed, 102 insertions(+), 51 deletions(-) diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index 6149a2bc..78a21c3b 100644 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -121,7 +121,7 @@ $(document).ready(function(){ // Bill Request $('#request_bills').click(function() { - var order_id=$(".selected-item").find(".orders-id").text(); + var order_id=$(".selected-item").find(".orders-id").text().substr(0,16); if(order_id!=""){ window.location.href = '/origami/' + order_id + '/request_bills' } @@ -133,7 +133,8 @@ $(document).ready(function(){ // Discount for Payment $('#discount').click(function() { - var order_id=$(".selected-item").find(".orders-id").text(); + var order_id=$(".selected-item").find(".orders-id").text().substr(0,16); + if(order_id!=""){ window.location.href = '/origami/' + order_id + '/discount' } @@ -148,7 +149,7 @@ $(document).ready(function(){ $("#pay-discount").on('click', function(e){ e.preventDefault(); var sale_id = $('#sale-id').text(); - var sale_item_id = $('.selected-item').attr('id'); + var sale_item_id = $('.selected-item').attr('id').substr(0,16); var sub_total = $('#order-sub-total').text(); var grand_total = $('#order-grand-total').text(); var discount_type = $('#discount-type').val(); @@ -178,7 +179,7 @@ $(document).ready(function(){ // Payment for Bill $('#pay-bill').click(function() { - var sale_id=$(".selected-item").find(".orders-id").text(); + var sale_id=$(".selected-item").find(".orders-id").text().substr(0,16); if(sale_id!=""){ window.location.href = '/origami/sale/'+ sale_id + "/payment" } @@ -190,7 +191,7 @@ $(document).ready(function(){ }); $('#customer').click(function() { - var sale = $(".selected-item").find(".orders-id").text(); + var sale = $(".selected-item").find(".orders-id").text().substr(0,16); if (sale.substring(0, 3)=="SAL") { var sale_id = sale }else{ @@ -202,7 +203,7 @@ $(document).ready(function(){ }); $('#re-print').click(function() { - var sale_id = $(".selected-item").find(".orders-id").text(); + var sale_id = $(".selected-item").find(".orders-id").text().substr(0,16); window.location.href = '/origami/'+ sale_id + "/reprint" diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index 6b1fb225..75d412e7 100644 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -15,13 +15,32 @@ class Api::BillController < Api::ApiController @status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee) else @status = true + @sale_id = booking.sale_id end end elsif (params[:order_id]) @sale = Sale.new @status, @sale_id = @sale.generate_invoice_from_order(params[:order_id], current_login_employee) - end + + @sale_data = Sale.find_by_sale_id(@sale_id) + @sale_items = SaleItem.where("sale_id=?",@sale_id) + + unique_code = "ReceiptBillPdf" + customer= Customer.where('customer_id=' + @sale_data.customer_id) + + # get printer info + print_settings=PrintSetting.find_by_unique_code(unique_code) + + # find order id by sale id + # sale_order = SaleOrder.find_by_sale_id(@sale_data.sale_id) + + # Calculate Food and Beverage Total + food_total, beverage_total = SaleItem.calculate_food_beverage(@sale_items) + + printer = Printer::ReceiptPrinter.new(print_settings) + printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, food_total, beverage_total) + redirect_to origami_path(@sale_data.sale_id) end diff --git a/app/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb index a6898e85..979c5b88 100644 --- a/app/controllers/oqs/home_controller.rb +++ b/app/controllers/oqs/home_controller.rb @@ -28,16 +28,24 @@ class Oqs::HomeController < BaseOqsController table_name = params[:table_id] status = params[:status] dining = DiningFacility.find_by_name(table_name); - oqpz = OrderQueueProcessByZone.find_by_zone_id(dining.zone_id) - if status == "" - AssignedOrderItem.where("order_queue_station_id=#{ oqpz.order_queue_station_id } AND delivery_status=0").find_each do |aoi| - oi = OrderItem.find_by_item_code(aoi.item_code) - items.push(oi) - end - else - AssignedOrderItem.where("order_queue_station_id=#{ oqpz.order_queue_station_id } AND delivery_status=1").find_each do |aoi| - oi = OrderItem.find_by_item_code(aoi.item_code) - items.push(oi) + # oqpz = OrderQueueProcessByZone.find_by_zone_id(dining.zone_id) + # if status == "" + # AssignedOrderItem.where("order_queue_station_id=#{ oqpz.order_queue_station_id } AND delivery_status=0").find_each do |aoi| + # oi = OrderItem.find_by_item_code(aoi.item_code) + # items.push(oi) + # end + # else + # AssignedOrderItem.where("order_queue_station_id=#{ oqpz.order_queue_station_id } AND delivery_status=1").find_each do |aoi| + # oi = OrderItem.find_by_item_code(aoi.item_code) + # items.push(oi) + # end + # end + + booking = Booking.find_by_dining_facility_id(dining.id) + BookingOrder.where("booking_id='#{ booking.booking_id }'").find_each do |bo| + order=Order.find(bo.order_id) + order.order_items.each do |oi| + items.push(oi) end end @@ -73,16 +81,26 @@ class Oqs::HomeController < BaseOqsController # Query for OQS with status def queue_items_query(status) + # AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.station_name, oqs.is_active, df.name as zone, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, cus.name as customer_name, odt.created_at") + # .joins(" left join order_queue_process_by_zones as oqpz ON oqpz.order_queue_station_id = assigned_order_items.order_queue_station_id + # left join dining_facilities as df on df.zone_id = oqpz.zone_id + # left join order_queue_stations as oqs ON oqs.id = assigned_order_items.order_queue_station_id + # left join orders as od ON od.order_id = assigned_order_items.order_id + # left join order_items as odt ON odt.item_code = assigned_order_items.item_code + # left join customers as cus ON cus.customer_id = od.customer_id") + # .where("assigned_order_items.delivery_status = #{status}") + # .group("assigned_order_items.assigned_order_item_id") + # .order("odt.item_name DESC") AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.station_name, oqs.is_active, df.name as zone, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, cus.name as customer_name, odt.created_at") - .joins(" left join order_queue_process_by_zones as oqpz ON oqpz.order_queue_station_id = assigned_order_items.order_queue_station_id - left join dining_facilities as df on df.zone_id = oqpz.zone_id - left join order_queue_stations as oqs ON oqs.id = assigned_order_items.order_queue_station_id + .joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id left join orders as od ON od.order_id = assigned_order_items.order_id left join order_items as odt ON odt.item_code = assigned_order_items.item_code - left join customers as cus ON cus.customer_id = od.customer_id") + left join customers as cus ON cus.customer_id = od.customer_id + left join booking_orders as bo on bo.order_id = assigned_order_items.order_id + left join bookings as bk on bk.booking_id = bo.booking_id + left join dining_facilities as df on df.id = bk.dining_facility_id") .where("assigned_order_items.delivery_status = #{status}") .group("assigned_order_items.assigned_order_item_id") - .order("odt.item_name DESC") end end diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index dbde3293..49ad4806 100644 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -39,6 +39,7 @@ class Origami::HomeController < BaseOrigamiController str.push(ord_detail) end end + if is_ajax == 1 render :json => str.to_json else diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index ca497b81..2cb218da 100644 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -48,7 +48,7 @@ class Origami::PaymentsController < BaseOrigamiController @balance = 0.00 @accountable_type = '' - if response["data"]==true + if response["status"]==true response["data"].each do |res| if res["accountable_type"] == "RebateAccount" @balance = res["balance"] diff --git a/app/models/customer.rb b/app/models/customer.rb index 0cbf8d58..0fda2bb9 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -39,12 +39,17 @@ class Customer < ApplicationRecord auth_token = memberaction.auth_token.to_s url = membership.gateway_url.to_s + memberaction.gateway_url.to_s + begin response = HTTParty.get(url, :body => { membership_id: customer.membership_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' - } + }, + :timeout => 10 ) + rescue Net::OpenTimeout + response = { status: false } + end return response; diff --git a/app/models/order.rb b/app/models/order.rb index 2ea76a98..a4328d76 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -246,7 +246,7 @@ class Order < ApplicationRecord .joins("left join orders on orders.order_id = booking_orders.order_id") .joins("left join sales on sales.sale_id = bookings.sale_id") .where("sales.sale_status='completed'") - .group("sales.sale_id,bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id") + .group("sales.sale_id") # For PG #bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id end diff --git a/app/models/sale.rb b/app/models/sale.rb index 9683c2b2..1edd835e 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -195,28 +195,28 @@ class Sale < ApplicationRecord existing_tax.delete end - total_tax_amount = 0 - #tax_profile - list by order_by - tax_profiles = TaxProfile.all.order("order_by asc") + # total_tax_amount = 0 + # #tax_profile - list by order_by + # tax_profiles = TaxProfile.all.order("order_by asc") - #Creat new tax records - tax_profiles.each do |tax| - sale_tax = SaleTax.new(:sale => self) - sale_tax.tax_name = tax.name - sale_tax.tax_rate = tax.rate - #include or execulive - # sale_tax.tax_payable_amount = total_taxable * tax.rate - sale_tax.tax_payable_amount = total_taxable * tax.rate / 100 - #new taxable amount - total_taxable = total_taxable + sale_tax.tax_payable_amount + # #Creat new tax records + # tax_profiles.each do |tax| + # sale_tax = SaleTax.new(:sale => self) + # sale_tax.tax_name = tax.name + # sale_tax.tax_rate = tax.rate + # #include or execulive + # # sale_tax.tax_payable_amount = total_taxable * tax.rate + # sale_tax.tax_payable_amount = total_taxable * tax.rate / 100 + # #new taxable amount + # total_taxable = total_taxable + sale_tax.tax_payable_amount - sale_tax.inclusive = tax.inclusive - sale_tax.save + # sale_tax.inclusive = tax.inclusive + # sale_tax.save - total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount - end + # total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount + # end - self.total_tax = total_tax_amount + # self.total_tax = total_tax_amount end diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index ef852bbd..71373f2d 100644 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -30,6 +30,7 @@ class SaleItem < ApplicationRecord # end end + # Calculate food total and beverage total def self.calculate_food_beverage(sale_items) food_prices=0 beverage_prices=0 @@ -43,6 +44,7 @@ class SaleItem < ApplicationRecord return food_prices, beverage_prices end + # get food price or beverage price for item def self.get_price(sale_item_id) food_price=0 beverage_price=0 diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 731fa321..2b0035f3 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -260,12 +260,17 @@ class SalePayment < ApplicationRecord campaign_type_id = memberaction.additional_parameter["campaign_type_id"] auth_token = memberaction.auth_token.to_s url = membership.gateway_url.to_s + memberaction.gateway_url.to_s - response = HTTParty.post(url, :body => { generic_customer_id:generic_customer_id ,merchant_uid:merchant_uid,total_amount: total_amount,campaign_type_id: campaign_type_id, + + begin + response = HTTParty.post(url, :body => { generic_customer_id:generic_customer_id ,merchant_uid:merchant_uid,total_amount: total_amount,campaign_type_id: campaign_type_id, receipt_no: receipt_no,auth_token:auth_token}.to_json, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' - }) + }, :timeout => 10) + rescue Net::OpenTimeout + response = { status: false } + end puts response.to_json end diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 524ee7e5..b04d85ce 100644 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -121,9 +121,9 @@ class ReceiptBillPdf < Prawn::Document pad_top(15) { text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :overflow => :shrink_to_fix, :size => self.item_font_size, :overflow => :shrink_to_fix - text_box "#{price.to_i}", :at =>[self.item_width,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - text_box "#{qty.to_i}", :at =>[item_name_width,y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{total_price.to_i}", :at =>[(item_name_width),y_position], :width =>self.total_width+5, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{price}", :at =>[self.item_width,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{qty}", :at =>[item_name_width,y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{total_price}", :at =>[(item_name_width),y_position], :width =>self.total_width+5, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix } move_down 3 end @@ -174,7 +174,7 @@ class ReceiptBillPdf < Prawn::Document text "#{ st.tax_name }", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "( " +"#{ st.tax_payable_amount }" +" )" , :size => self.item_font_size,:align => :right + text "#{ st.tax_payable_amount }" , :size => self.item_font_size,:align => :right end end else diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index 66d65aea..607f24b2 100644 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -354,14 +354,14 @@ Discount: (<%=@selected_item.total_discount rescue 0%>) - +