From a9c8eb4e93a775b8bddcab462e933dfdcce812af Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 19 Mar 2018 11:35:43 +0630 Subject: [PATCH 1/5] check tax profile --- .../origami/addorders_controller.rb | 8 +-- .../origami/payments_controller.rb | 3 +- .../origami/request_bills_controller.rb | 2 +- .../origami/sale_edit_controller.rb | 18 +++++-- app/controllers/origami/void_controller.rb | 3 +- app/models/sale.rb | 52 +++++++++++-------- app/views/origami/home/show.html.erb | 2 +- app/views/origami/payments/show.html.erb | 4 +- app/views/origami/rooms/show.html.erb | 2 +- app/views/origami/sale_edit/edit.html.erb | 4 +- .../origami/table_invoices/show.html.erb | 4 +- config/routes.rb | 4 +- 12 files changed, 61 insertions(+), 45 deletions(-) diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index 3a8dea9b..f5bb7d37 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -103,11 +103,11 @@ class Origami::AddordersController < BaseOrigamiController } # begin - if params[:order_source] == "quick_service" - customer_id = "CUS-000000000002" # for no customer id from mobile - else + # if params[:order_source] == "quick_service" + # customer_id = "CUS-000000000002" # for no customer id from mobile + # else customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile - end + # end @order = Order.new @order.source = params[:order_source] @order.order_type = params[:order_type] diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 49320273..00ad4e4d 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -402,12 +402,13 @@ class Origami::PaymentsController < BaseOrigamiController member_info = nil rebate_amount = nil current_balance = nil + order_source = params[:type] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) if saleObj.discount_type == "member_discount" saleObj.update_attributes(rounding_adjustment: 0) - saleObj.compute_by_sale_items(sale_id, saleObj.sale_items,0) + saleObj.compute_by_sale_items(sale_id, saleObj.sale_items,0,order_source) end saleObj.update_attributes(rounding_adjustment: 0) diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index aa145b4f..adfe35a6 100755 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -13,7 +13,7 @@ class Origami::RequestBillsController < ApplicationController if check_booking.sale_id.nil? # Create Sale if it doesn't exist - @status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee, current_user) + @status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee, current_user, order.source) @sale_data = Sale.find_by_sale_id(@sale_id) @sale_items = SaleItem.where("sale_id=?",@sale_id) else diff --git a/app/controllers/origami/sale_edit_controller.rb b/app/controllers/origami/sale_edit_controller.rb index 72df82ac..1743f881 100755 --- a/app/controllers/origami/sale_edit_controller.rb +++ b/app/controllers/origami/sale_edit_controller.rb @@ -76,11 +76,14 @@ class Origami::SaleEditController < BaseOrigamiController # re-calc tax saleObj = Sale.find(saleitemObj.sale_id) + order_id = SaleOrder.find_by_sale_id(saleitemObj.sale_id).order_id + order = Order.find(order_id) + action_by = current_user.id remark = "FOC Sale Item ID #{saleitemObj.sale_item_id} | Receipt No #{saleObj.receipt_no} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}Receipt No #{saleObj.receipt_no}" sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,saleObj.cashier_id, action_by,remark,"SALEITEMFOC" ) - saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount) + saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount,order.source) ProductCommission.create_product_commission(@newsaleitem, saleitemObj) end @@ -141,7 +144,7 @@ class Origami::SaleEditController < BaseOrigamiController end end - saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount) + saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount,order.source) ProductCommission.edit_product_commission(saleitemObj) end @@ -162,17 +165,21 @@ class Origami::SaleEditController < BaseOrigamiController # re-calc tax saleObj = Sale.find(saleitemObj.sale_id) + order_id = SaleOrder.find_by_sale_id(saleitemObj.sale_id).order_id + order = Order.find(order_id) + action_by = current_user.id remark = "Cancle Void Sale Item ID #{saleitemObj.sale_item_id} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}|Receipt No #{saleObj.receipt_no}" sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,saleObj.cashier_id, action_by,remark,"ITEMCANCELVOID" ) - saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount) + saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount, order.source) ProductCommission.remove_product_commission(saleitemObj) end # remove all void items def cancel_all_void sale_id = params[:sale_id] + order_source = params[:type] saleObj = Sale.find(sale_id) saleObj.sale_items.each do |item| if item.qty.to_i < 0 @@ -185,13 +192,14 @@ class Origami::SaleEditController < BaseOrigamiController end # re-calc tax - saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount) + saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount,order_source) end def apply_void sale_id = params[:sale_id] + order_source = params[:type] saleObj = Sale.find(sale_id) - saleObj.compute_without_void + saleObj.compute_without_void(order_source) saleObj.sale_items.each do |item| ProductCommission.remove_product_commission(item) end diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index 33ff0d76..00f9d76b 100755 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -4,12 +4,13 @@ class Origami::VoidController < BaseOrigamiController sale_id = params[:sale_id] remark = params[:remark] + order_source = params[:type] #tax profile source if Sale.exists?(sale_id) sale = Sale.find_by_sale_id(sale_id) if sale.discount_type == "member_discount" sale.update_attributes(total_discount: 0) - sale.compute_by_sale_items(sale_id, sale.sale_items,0) + sale.compute_by_sale_items(sale_id, sale.sale_items,0,order_source) end # update count for shift sale diff --git a/app/models/sale.rb b/app/models/sale.rb index 5d46aafc..11ddd296 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -26,7 +26,7 @@ class Sale < ApplicationRecord SALE_STATUS_OUTSTANDING = "outstanding" SALE_STATUS_COMPLETED = "completed" - def generate_invoice_from_booking(booking_id, requested_by, cashier) + def generate_invoice_from_booking(booking_id, requested_by, cashier, order_source = nil) booking = Booking.find(booking_id) status = false Rails.logger.debug "Booking -> " + booking.id.to_s @@ -36,9 +36,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, cashier) + status, sale_id = generate_invoice_from_order(order.order_id, nil, booking, requested_by, cashier, order_source) else - status, sale_id = generate_invoice_from_order(order.order_id, booking.sale_id, booking, requested_by, cashier) + status, sale_id = generate_invoice_from_order(order.order_id, booking.sale_id, booking, requested_by, cashier, order_source) end booking.sale_id = sale_id end @@ -58,7 +58,7 @@ class Sale < ApplicationRecord end end - def generate_invoice_from_order (order_id, sale_id, booking, requested_by, cashier = nil) + def generate_invoice_from_order (order_id, sale_id, booking, requested_by, cashier = nil, order_source = nil) taxable = true #if sale_id is exsit and validate #add order to that invoice @@ -128,7 +128,7 @@ class Sale < ApplicationRecord self.save! #compute sales summary - compute + compute(order_source) #Update the order items that is billed order.update_items_status_to_billed(nil) @@ -172,7 +172,7 @@ class Sale < ApplicationRecord # 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,current_user) + @status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee,current_user,order.source) @sale_data = Sale.find_by_sale_id(@sale_id) @sale_items = SaleItem.where("sale_id=?",@sale_id) else @@ -310,7 +310,7 @@ class Sale < ApplicationRecord end #compute - invoice total - def compute + def compute(order_source = nil) sales_items = self.sale_items #Computation Fields @@ -329,7 +329,7 @@ class Sale < ApplicationRecord # total_taxable = total_taxable + (item.taxable_price * item.qty) end - apply_tax (total_taxable) + apply_tax(total_taxable, order_source) self.total_amount = subtotal_price self.total_discount = total_discount @@ -342,7 +342,7 @@ class Sale < ApplicationRecord end #compute - invoice total - def compute_by_sale_items(sale_id, sale_itemss, total_discount,discount_type=nil) + def compute_by_sale_items(sale_id, sale_itemss, total_discount,discount_type=nil,order_source=nil) sale = Sale.find(sale_id) sales_items = sale_itemss @@ -362,7 +362,7 @@ class Sale < ApplicationRecord end end - compute_tax(sale, total_taxable, total_discount) + compute_tax(sale, total_taxable, total_discount, order_source) sale.total_amount = subtotal_price sale.total_discount = total_discount sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax @@ -376,7 +376,7 @@ class Sale < ApplicationRecord end # No Use too many wrong - def compute_without_void + def compute_without_void(order_source = nil) sales_items = self.sale_items #Computation Fields @@ -396,7 +396,7 @@ class Sale < ApplicationRecord end end - apply_tax (total_taxable) + apply_tax(total_taxable, order_source) self.total_amount = subtotal_price self.total_discount = total_discount self.grand_total = (self.total_amount - self.total_discount) + self.total_tax @@ -407,7 +407,7 @@ class Sale < ApplicationRecord end # Tax Re-Calculte - def compute_tax(sale, total_taxable, total_discount = 0) + def compute_tax(sale, total_taxable, total_discount = 0, order_source = nil) shop = Shop.first(); #if tax is not apply create new record @@ -423,8 +423,9 @@ class Sale < ApplicationRecord # #Creat new tax records if sale.payment_status != 'foc' tax_profiles.each do |tax| - customer.tax_profiles.each do |cus_tax| - if cus_tax.to_i == tax.id + # customer.tax_profiles.each do |cus_tax| + # if cus_tax.to_i == tax.id + if tax.group_type.to_s == order_source.to_s sale_tax = SaleTax.new(:sale => sale) sale_tax.tax_name = tax.name sale_tax.tax_rate = tax.rate @@ -447,15 +448,16 @@ class Sale < ApplicationRecord sale_tax.inclusive = tax.inclusive sale_tax.save - end end + # end + # end end end sale.total_tax = total_tax_amount end # Tax Calculate - def apply_tax(total_taxable) + def apply_tax(total_taxable, order_source = nil) shop = Shop.first(); #if tax is not apply create new record @@ -469,11 +471,14 @@ class Sale < ApplicationRecord tax_profiles = TaxProfile.all.order("order_by asc") customer = Customer.find(self.customer_id) - + if order_source.to_s == "emenu" + order_source = "cashier" + end #Create new tax records tax_profiles.each do |tax| - customer.tax_profiles.each do |cus_tax| - if cus_tax.to_i == tax.id + # customer.tax_profiles.each do |cus_tax| + # if cus_tax.to_i == tax.id + if tax.group_type.to_s == order_source.to_s sale_tax = SaleTax.new(:sale => self) sale_tax.tax_name = tax.name sale_tax.tax_rate = tax.rate @@ -497,8 +502,9 @@ class Sale < ApplicationRecord sale_tax.inclusive = tax.inclusive sale_tax.save - end end + # end + # end end self.total_tax = total_tax_amount end @@ -1963,7 +1969,7 @@ end end # Re-compute for add - saleobj.compute + saleobj.compute(order.source) saleobj.save order.save booking.save @@ -1993,7 +1999,7 @@ end end # Re-compute for add - saleobj.compute + saleobj.compute(order.source) saleobj.save order.save booking.save diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 54b0e956..ffbf1e4c 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -905,7 +905,7 @@ }, function (isConfirm) { if (isConfirm) { var sale_id = "<%= @obj_sale.sale_id rescue "" %>" - var ajax_url = "/origami/sale/" + sale_id + '/void'; + var ajax_url = "/origami/sale/" + sale_id + '/cashier/void'; var remark = $("#remark").val(); $.ajax({ diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 2deb9c0c..a5449d35 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -691,7 +691,7 @@ var customer_name = "<%= @customer.name %>"; if (isConfirm) { var sale_id = $('#sale_id').text(); var remark = $("#remark").val(); - var ajax_url = "/origami/sale/" + sale_id + '/void'; + var ajax_url = "/origami/sale/" + sale_id +'/'+cashier_type+ '/void'; $.ajax({ type: 'POST', url: ajax_url, @@ -897,7 +897,7 @@ var customer_name = "<%= @customer.name %>"; if (isConfirm) { $.ajax({ type: "POST", - url: "<%= origami_payment_foc_path %>", + url: "/origami/payment/"+cashier_type+"/foc", data: params, success:function(result){ customer_display_view(null,"reload"); diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index d98a3fe2..758a5273 100755 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -889,7 +889,7 @@ $('#add_invoice').on('click',function(){ var sure = confirm("Are you sure want to Void"); if (sure == true) { var sale_id = $('#sale_id').val(); - var ajax_url = "/origami/sale/" + sale_id + '/void'; + var ajax_url = "/origami/sale/" + sale_id + '/cashier/void'; $.ajax({ type: 'POST', url: ajax_url, diff --git a/app/views/origami/sale_edit/edit.html.erb b/app/views/origami/sale_edit/edit.html.erb index 745286d3..ff203657 100755 --- a/app/views/origami/sale_edit/edit.html.erb +++ b/app/views/origami/sale_edit/edit.html.erb @@ -331,7 +331,7 @@ var cashier_type = "<%= @cashier_type %>"; $.ajax({ type: "POST", url: ajax_url, - data: 'sale_id=' + sale_id, + data: 'sale_id=' + sale_id +'&type='+cashier_type, success: function (result) { location.reload(); } @@ -345,7 +345,7 @@ var cashier_type = "<%= @cashier_type %>"; $.ajax({ type: "POST", url: ajax_url, - data: 'sale_id=' + sale_id, + data: 'sale_id=' + sale_id+'&type='+cashier_type, success: function (result) { if (cashier_type=="quick_service") { window.location.href = '/origami/sale/'+sale_id+'/'+cashier_type+'/payment/'; diff --git a/app/views/origami/table_invoices/show.html.erb b/app/views/origami/table_invoices/show.html.erb index 515973f1..216e5eea 100644 --- a/app/views/origami/table_invoices/show.html.erb +++ b/app/views/origami/table_invoices/show.html.erb @@ -261,7 +261,7 @@ $('#void').on('click',function () { if (isConfirm) { var sale_id = $('#sale_id').val(); var remark = $("#remark").val(); - var ajax_url = "/origami/sale/" + sale_id + '/void'; + var ajax_url = "/origami/sale/" + sale_id + '/cashier/void'; $.ajax({ type: 'POST', url: ajax_url, @@ -291,7 +291,7 @@ $('#foc').click(function() { if ($(this).attr('active')=== "true") { $.ajax({ type: "POST", - url: "<%= origami_payment_foc_path %>", + url: "/origami/payment/cashier/foc", data: params, success:function(result){ if (cash >= 0) { diff --git a/config/routes.rb b/config/routes.rb index b51baca3..34020dee 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -170,7 +170,7 @@ scope "(:locale)", locale: /en|mm/ do get 'sale/:sale_id/:type/payment' => 'payments#show' post 'sale/:sale_id/:type/payment/print' => 'payments#print' #route for print receipt - post 'payment/foc' => 'payments#foc', :defaults => {:format => 'json'} + post 'payment/:type/foc' => 'payments#foc', :defaults => {:format => 'json'} post 'payment/cash' => 'payments#create' post 'payment/mpu' => "mpu#create" post 'payment/jcb' => "jcb#create" @@ -192,7 +192,7 @@ scope "(:locale)", locale: /en|mm/ do get 'sale/:sale_id/:type/payment/others_payment/Voucher' => "voucher#index" #---------Void --------------# - post 'sale/:sale_id/void' => 'void#overall_void' + post 'sale/:sale_id/:type/void' => 'void#overall_void' #---------Multiple Invoices --------------# get 'table/:table_id/table_invoices' => "table_invoices#index", :as => "table_invoice_index" From ca817197d917b017674a20f310741be6b2dd8c03 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 19 Mar 2018 18:13:38 +0630 Subject: [PATCH 2/5] update menu import and export --- Gemfile | 5 +- Gemfile.lock | 18 +++- app/controllers/settings/menus_controller.rb | 11 +-- app/models/menu.rb | 42 ++++++++- app/views/settings/menus/index.html.erb | 5 +- app/views/settings/menus/index.xlsx.axlsx | 86 +++++++++++++++++++ config/application.rb | 2 + config/initializers/mime_types.rb | 1 + out.xls | Bin 0 -> 3584 bytes 9 files changed, 155 insertions(+), 15 deletions(-) create mode 100644 app/views/settings/menus/index.xlsx.axlsx create mode 100644 out.xls diff --git a/Gemfile b/Gemfile index 4ca47865..c20dec66 100755 --- a/Gemfile +++ b/Gemfile @@ -46,8 +46,11 @@ gem 'mini_magick' gem 'cups' gem 'prawn' gem 'prawn-table' -gem 'spreadsheet' gem 'to_xls-rails' +gem 'rubyzip', '= 1.0.0' +gem 'axlsx', '= 2.0.1' +gem 'axlsx_rails' +gem 'roo' #Reporting gem #gem 'compendium' #gem "cancan" diff --git a/Gemfile.lock b/Gemfile.lock index 1c7e6534..254ff760 100755 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -50,6 +50,13 @@ GEM airbrussh (1.3.0) sshkit (>= 1.6.1, != 1.7.0) arel (8.0.0) + axlsx (2.0.1) + htmlentities (~> 4.3.1) + nokogiri (>= 1.4.1) + rubyzip (~> 1.0.0) + axlsx_rails (0.5.1) + actionpack (>= 3.1) + axlsx (>= 2.0.1) bcrypt (3.1.11) bindex (0.5.0) builder (3.2.3) @@ -100,6 +107,7 @@ GEM railties (>= 3.2, < 5.2) globalid (0.4.1) activesupport (>= 4.2.0) + htmlentities (4.3.4) httparty (0.15.6) multi_xml (>= 0.5.2) i18n (0.9.1) @@ -197,6 +205,10 @@ GEM rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) redis (3.3.5) + roo (1.13.2) + nokogiri + rubyzip + spreadsheet (> 0.6.4) rspec-core (3.7.0) rspec-support (~> 3.7.0) rspec-expectations (3.7.0) @@ -215,6 +227,7 @@ GEM rspec-support (~> 3.7.0) rspec-support (3.7.0) ruby-ole (1.2.12.1) + rubyzip (1.0.0) sass (3.5.3) sass-listen (~> 4.0.0) sass-listen (4.0.0) @@ -286,6 +299,8 @@ PLATFORMS DEPENDENCIES aescrypt + axlsx (= 2.0.1) + axlsx_rails bcrypt (~> 3.1.7) byebug cancancan (~> 1.10) @@ -320,13 +335,14 @@ DEPENDENCIES rack-cors rails (~> 5.1.0) redis (~> 3.0) + roo rspec-rails (~> 3.5) + rubyzip (= 1.0.0) sass-rails (~> 5.0) schema_to_scaffold shoulda-matchers (~> 3.1) sidekiq simple_form - spreadsheet spring spring-watcher-listen (~> 2.0.0) tether-rails diff --git a/app/controllers/settings/menus_controller.rb b/app/controllers/settings/menus_controller.rb index 0a6d87c7..8fed1e97 100755 --- a/app/controllers/settings/menus_controller.rb +++ b/app/controllers/settings/menus_controller.rb @@ -7,12 +7,9 @@ class Settings::MenusController < ApplicationController def index @settings_menus = Menu.all.page(params[:page]).per(10) respond_to do |format| - format.html - # format.csv { send_data MenuCsvExport.generate } - -format.csv { send_data Menu.to_csv } -# format.csv { send_data MenuCategory.to_csv } - end + format.html + format.xlsx + end end # GET /settings/menus/1 @@ -76,7 +73,7 @@ format.csv { send_data Menu.to_csv } def import Menu.import(params[:file]) - redirect_to settings_menu_path, notice: "imported" + redirect_to settings_menus_path, notice: "imported" end private diff --git a/app/models/menu.rb b/app/models/menu.rb index 12784eea..09e36928 100755 --- a/app/models/menu.rb +++ b/app/models/menu.rb @@ -1,4 +1,6 @@ class Menu < ApplicationRecord + + require 'spreadsheet' has_many :menu_categories, dependent: :destroy validates_presence_of :name, :valid_days, :valid_time_from, :valid_time_to @@ -34,7 +36,7 @@ class Menu < ApplicationRecord def self.to_csv m_attributes = %w{name is_active valid_days valid_time_from valid_time_to created_by created_at updated_at} - CSV.generate(headers: true) do |csv| + CSV.generate(headers: true, row_sep: "\r\n") do |csv| csv << m_attributes menu = Menu.all menu.each do |user| @@ -44,9 +46,41 @@ class Menu < ApplicationRecord end def self.import(file) - CSV.foreach(file.path, headers:true) do |row| - Menu.create! row.to_hash - end + spreadsheet = Roo::Spreadsheet.open(file.path) + puts spreadsheet.info + + spreadsheet = Roo::Excelx.new(file.path) + puts spreadsheet.info + + # Use the extension option if the extension is ambiguous. + spreadsheet = Roo::Spreadsheet.open(file.path, extension: :xlsx) + + puts spreadsheet.info + + header = spreadsheet.row(1) + + (2..spreadsheet.last_row).each do |i| + + row = Hash[[header,spreadsheet.row(i)].transpose] + + menu = Menu.new + menu.name = row["name"] + menu.is_active = row["is_active"] + menu.valid_days = row["valid_days"] + menu.valid_time_from = row["valid_time_from"] + menu.valid_time_to = row["valid_time_to"] + menu.created_by = row["created_by"] + menu.save + end + end + + def self.open_spreadsheet(file) + case File.extname(file.original_filename) + when ".csv" then Roo::CSV.new(file.path,nil,:ignore) + when ".xls" then Roo::Excel.new(file.path,nil,:ignore) + when ".xlsx" then Roo::Excelx.new(file.path,nil,:ignore) + else raise "Unknown File type: #{original_filename}" + end end end \ No newline at end of file diff --git a/app/views/settings/menus/index.html.erb b/app/views/settings/menus/index.html.erb index ed215031..11ae575f 100755 --- a/app/views/settings/menus/index.html.erb +++ b/app/views/settings/menus/index.html.erb @@ -7,11 +7,12 @@ - +<%end%> +<%= link_to "Export users as spreadsheet", settings_menus_path(format: "xlsx") %>


diff --git a/app/views/settings/menus/index.xlsx.axlsx b/app/views/settings/menus/index.xlsx.axlsx new file mode 100644 index 00000000..977e9782 --- /dev/null +++ b/app/views/settings/menus/index.xlsx.axlsx @@ -0,0 +1,86 @@ +wb = xlsx_package.workbook +wb.styles do |s| + date = s.add_style(:format_code => "yyyy-mm-dd", :border => Axlsx::STYLE_THIN_BORDER) + wrap_text = s.add_style :sz => 11, + :alignment => { :horizontal => :left,:vertical => :center , + :wrap_text => true} + header_text = s.add_style :fg_color=> "FFFFFF", + :b => true, + :bg_color => "004586", + :sz => 12, + :border => { :style => :thin, :color => "00" }, + :alignment => { :horizontal => :left, + :vertical => :center , + :header_text => true} + + wb.add_worksheet(name: "Menu") do |sheet| + sheet.add_row %w( name is_active valid_days valid_time_from valid_time_to created_by ), :style=>header_text + @settings_menus.each do |menu| + sheet.add_row [ menu.name, menu.is_active, menu.valid_days, menu.valid_time_from,menu.valid_time_to, menu.created_by], :style=>[date,wrap_text] + end + end + + wb.add_worksheet(name: "Menu Category") do |sheet| + sheet.add_row %w(menu_id code name alt_name order_by created_by menu_category_id is_available created_at updated_at), :style=>header_text + MenuCategory.all.each do |mc| + sheet.add_row [mc.menu_id, mc.code, mc.name, mc.alt_name, mc.order_by, mc.created_by, mc.menu_category_id, mc.is_available, mc.created_at, mc.updated_at], :style=>wrap_text + end + end + + wb.add_worksheet(name: "Menu Item") do |sheet| + sheet.add_row %w(item_code name alt_name image_path description information unit type menu_category_id item_attributes item_options account_id _qty taxable is_sub_item is_available created_by created_at updated_at), :style=>header_text + MenuItem.all.each do |mi| + sheet.add_row [mi.item_code, mi.name, mi.alt_name, mi.image_path, mi.description, mi.information, mi.unit, mi.type, mi.menu_category_id, mi.item_attributes, mi.item_options, mi.account_id, mi.min_qty, mi.taxable, mi.is_sub_item, mi.is_available, mi.created_by, mi.created_at, mi.updated_at], :style=>wrap_text + end + end + + wb.add_worksheet(name: "Menu Item Instance") do |sheet| + sheet.add_row %w(menu_item_id item_instance_code item_instance_name item_attributes price is_on_promotion promotion_price is_available is_default created_at updated_at), :style=>header_text + MenuItemInstance.all.each do |mii| + sheet.add_row [mii.menu_item_id, mii.item_instance_code, mii.item_instance_name, mii.item_attributes, mii.price, mii.is_on_promotion, mii.promotion_price, mii.is_available, mii.is_default, mii.created_at, mii.updated_at], :style=>wrap_text + end + end + + wb.add_worksheet(name: "Menu Options") do |sheet| + sheet.add_row %w(option_type name value created_at updated_at), :style=>header_text + MenuItemOption.all.each do |option| + sheet.add_row [option.option_type, option.name, option.value, option.created_at, option.updated_at], :style=>wrap_text + end + end + + wb.add_worksheet(name: "Item Attributes") do |sheet| + sheet.add_row %w(attribute_type name value created_at updated_at), :style=>header_text + MenuItemAttribute.all.each do |attr| + sheet.add_row [ attr.attribute_type,attr.name,attr.value,attr.created_at,attr.updated_at], :style=>wrap_text + end + end + + wb.add_worksheet(name: "Account") do |sheet| + sheet.add_row %w(title account_type discount point bonus rebate created_at updated_at), :style=>header_text + Account.all.each do |acc| + sheet.add_row [acc.title,acc.account_type,acc.discount,acc.point,acc.bonus,acc.rebate,acc.created_at,acc.updated_at], :style=>wrap_text + end + end + + wb.add_worksheet(name: "Item Set") do |sheet| + sheet.add_row %w(name alt_name min_selectable_qty max_selectable_qty created_at updated_at), :style=>header_text + ItemSet.all.each do |set| + sheet.add_row [set.name, set.alt_name, set.min_selectable_qty, set.max_selectable_qty, set.created_at, set.updated_at], :style=>wrap_text + end + end + + wb.add_worksheet(name: "Menu Instance Item Set") do |sheet| + sheet.add_row %w(item_set_id menu_item_instance_id created_at updated_at), :style=>header_text + MenuInstanceItemSet.all.each do |miis| + sheet.add_row [miis.item_set_id, miis.menu_item_instance_id, miis.created_at, miis.updated_at], :style=>wrap_text + end + end + + wb.add_worksheet(name: "Menu Item Set") do |sheet| + sheet.add_row %w(item_set_id menu_item_id created_at updated_at), :style=>header_text + MenuItemSet.all.each do |mis| + sheet.add_row [mis.item_set_id, mis.menu_item_id, mis.created_at, mis.updated_at], :style=>wrap_text + end + end + +end diff --git a/config/application.rb b/config/application.rb index e9a4e634..5e672414 100755 --- a/config/application.rb +++ b/config/application.rb @@ -2,6 +2,8 @@ require_relative 'boot' require 'csv' require 'rails/all' +require 'creek' +# require 'iconv' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index 3859c754..3e0fb279 100755 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -3,3 +3,4 @@ # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf Mime::Type.register 'application/vnd.ms-excel', :xls +Mime::Type.register "application/xlsx", :xlsx diff --git a/out.xls b/out.xls new file mode 100644 index 0000000000000000000000000000000000000000..ffe4b922dd3da5584007d3d2209613a7f913243e GIT binary patch literal 3584 zcmeHJy=xRv5dXc+UcA%G*Ckpg$P(}i(#SS~#53YyqZTKUQlhyK zGLV13Mhgqi&SD{ooz*D_mO(5v&)>}59x+^D1dAg(yYpt=yf^dS&b*m@?>DD9>o1Oe z#x6LI5p25xMt8^!`H{3g3Haniw(Xn~agInfgCX)jAb>V6UGaTQ*4;KJ@^M2m<&<-;B|M7!5d4QjH%b$Bp^BC?KzMva!o^EKq z_Zmrlm5_-+=ru8EEFCiKcAF%IwGK9nSSAuAoFDOVlp|t45rbSx9%0p+y2qT9uNhs%RK}(EiKC)=FTHpkPmV%Hk(JE3FQkQ}!IEKqwQCgkuP!*A?-?9qr<+5Qf8jB%>)&Kc>)v?Jeo8KQCA`$!OeI3snQ;ZKAa)Ej=gges7ok&5sln;~ez(de z`~0`^sU7^8KEG9#ugPFPd7z30pH)`e3RXy)SliR*A3@Hfzq{T6{44#E9DTwfS8t+@ z+q#c>SGb3kf2RKWvX6nPA2w$nzWHd7Qcg2_Gqm&QM%!{>oC{&I&;@z?NuMz-UB^uTWm^ Date: Mon, 19 Mar 2018 18:22:15 +0630 Subject: [PATCH 3/5] update addorder sytle --- app/assets/javascripts/addorder.js | 2 +- app/models/menu.rb | 2 -- config/application.rb | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index f6365db0..d3723026 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -196,7 +196,7 @@ $(function() { +add+ '' +'
' +'
' - +"
Date: Mon, 19 Mar 2018 19:34:34 +0630 Subject: [PATCH 4/5] SQA feedback --- app/assets/javascripts/origami.js | 4 +- app/controllers/oqs/edit_controller.rb | 2 +- app/controllers/origami/jcb_controller.rb | 61 +++++++++------ app/controllers/origami/master_controller.rb | 60 +++++++++------ app/controllers/origami/mpu_controller.rb | 63 ++++++++++------ .../origami/payments_controller.rb | 5 +- .../origami/unionpay_controller.rb | 59 +++++++++------ app/controllers/origami/visa_controller.rb | 59 +++++++++------ app/models/order.rb | 10 +-- app/models/order_queue_station.rb | 74 +++++++++++++++++++ app/models/sale_payment.rb | 13 +++- .../origami/pending_order/index.html.erb | 0 app/views/origami/pending_order/show.html.erb | 8 +- 13 files changed, 289 insertions(+), 129 deletions(-) mode change 100755 => 100644 app/controllers/origami/jcb_controller.rb mode change 100755 => 100644 app/controllers/origami/master_controller.rb mode change 100755 => 100644 app/controllers/origami/mpu_controller.rb mode change 100755 => 100644 app/controllers/origami/visa_controller.rb mode change 100755 => 100644 app/views/origami/pending_order/index.html.erb diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index 418b6ebe..7388529b 100755 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -249,7 +249,7 @@ function setCommPorts(comPortLists) { closeOnCancel: false, allowOutsideClick: false }, function () { - window.location.href = '/origami/sale/'+ sale_id + "/payment/others_payment"; + window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type+"/payment/others_payment"; }); } } @@ -342,6 +342,8 @@ function resCBPay(resMsg,card_sale_trans_id,cmd_type,payment_type,bnk_bill_amoun }else{ if(payment_type!="master"){ payment_type = payment_type.toUpperCase(); + }else{ + payment_type = "Master"; } swal({ title: 'Oops', diff --git a/app/controllers/oqs/edit_controller.rb b/app/controllers/oqs/edit_controller.rb index 94ba5842..98ec1d63 100644 --- a/app/controllers/oqs/edit_controller.rb +++ b/app/controllers/oqs/edit_controller.rb @@ -6,7 +6,7 @@ class Oqs::EditController < BaseOqsController if params[:type] == 'oqs' assigned_item = AssignedOrderItem.find(assigned_item_id) @order_item = OrderItem.where("order_id='#{ assigned_item.order_id }' AND item_instance_code='#{ assigned_item.instance_code }'") - elsif + elsif params[:type] == "pending" assigned_item = OrderItem.find(assigned_item_id) @booking = Booking.joins(" JOIN booking_orders as bko on bko.booking_id = bookings.booking_id") .where("bko.order_id = '#{assigned_item.order_id}'").first() diff --git a/app/controllers/origami/jcb_controller.rb b/app/controllers/origami/jcb_controller.rb old mode 100755 new mode 100644 index 06ee6087..5c06f9fe --- a/app/controllers/origami/jcb_controller.rb +++ b/app/controllers/origami/jcb_controller.rb @@ -5,33 +5,43 @@ class Origami::JcbController < BaseOrigamiController @cashier_type = params[:type] # limit jcb_amount sale_data = Sale.find_by_sale_id(@sale_id) - total = sale_data.grand_total + total = 0 @jcbcount = 0 - others = 0 + @shop = Shop::ShopDetail + @rounding_adj = 0 + @can_jcb = 0 + @member_discount= 0 + @sub_total = 0 + @membership_id = nil + @receipt_no = nil + if !sale_data.nil? + total = sale_data.grand_total + + others = 0 + + if @shop.is_rounding_adj + new_total = Sale.get_rounding_adjustment(sale_data.grand_total) + else + new_total = sale_data.grand_total + end + @rounding_adj = new_total-sale_data.grand_total + + sale_data.sale_payments.each do |sale_payment| + if sale_payment.payment_method == "jcb" + @jcbcount = @jcbcount + sale_payment.payment_amount + else + others = others + sale_payment.payment_amount + end + end + @can_jcb = total - @jcbcount - others - @payment_method_setting_nav = PaymentMethodSetting.all - @shop = Shop::ShopDetail - if @shop.is_rounding_adj - new_total = Sale.get_rounding_adjustment(sale_data.grand_total) - else - new_total = sale_data.grand_total + @member_discount = MembershipSetting.find_by_discount(1) + @sub_total = sale_data.total_amount + @membership_id = sale_data.customer.membership_id + #for bank integration + @receipt_no = sale_data.receipt_no end - @rounding_adj = new_total-sale_data.grand_total - - sale_data.sale_payments.each do |sale_payment| - if sale_payment.payment_method == "jcb" - @jcbcount = @jcbcount + sale_payment.payment_amount - else - others = others + sale_payment.payment_amount - end - end - @can_jcb = total - @jcbcount - others - @member_discount = MembershipSetting.find_by_discount(1) - @sub_total = sale_data.total_amount - @membership_id = sale_data.customer.membership_id - #for bank integration - @receipt_no = sale_data.receipt_no bank_integration = Lookup.collection_of('bank_integration') @bank_integration = 0 if !bank_integration[0].nil? @@ -59,4 +69,9 @@ class Origami::JcbController < BaseOrigamiController end end + #Shop Name in Navbor + helper_method :shop_detail + def shop_detail + @shop = Shop.first + end end diff --git a/app/controllers/origami/master_controller.rb b/app/controllers/origami/master_controller.rb old mode 100755 new mode 100644 index 77ae99d2..858d0125 --- a/app/controllers/origami/master_controller.rb +++ b/app/controllers/origami/master_controller.rb @@ -5,32 +5,41 @@ class Origami::MasterController < BaseOrigamiController @cashier_type = params[:type] # limit master_amount sale_data = Sale.find_by_sale_id(@sale_id) - total = sale_data.grand_total + total = 0 @mastercount = 0 - others = 0 - - @payment_method_setting_nav = PaymentMethodSetting.all - @shop = Shop::ShopDetail - if @shop.is_rounding_adj - new_total = Sale.get_rounding_adjustment(sale_data.grand_total) - else - new_total = sale_data.grand_total - end - @rounding_adj = new_total-sale_data.grand_total + @shop = Shop::ShopDetail + @rounding_adj = 0 + @can_master = 0 + @member_discount = 0 + @sub_total = 0 + @membership_id = nil + @receipt_no = nil + if !sale_data.nil? + total = sale_data.grand_total + + others = 0 + + if @shop.is_rounding_adj + new_total = Sale.get_rounding_adjustment(sale_data.grand_total) + else + new_total = sale_data.grand_total + end + @rounding_adj = new_total-sale_data.grand_total - sale_data.sale_payments.each do |sale_payment| - if sale_payment.payment_method == "master" - @mastercount = @mastercount + sale_payment.payment_amount - else - others = others + sale_payment.payment_amount - end + sale_data.sale_payments.each do |sale_payment| + if sale_payment.payment_method == "master" + @mastercount = @mastercount + sale_payment.payment_amount + else + others = others + sale_payment.payment_amount + end + end + @can_master = total - @mastercount - others + @member_discount = MembershipSetting.find_by_discount(1) + @sub_total = sale_data.total_amount + @membership_id = sale_data.customer.membership_id + #for bank integration + @receipt_no = sale_data.receipt_no end - @can_master = total - @mastercount - others - @member_discount = MembershipSetting.find_by_discount(1) - @sub_total = sale_data.total_amount - @membership_id = sale_data.customer.membership_id - #for bank integration - @receipt_no = sale_data.receipt_no bank_integration = Lookup.collection_of('bank_integration') @bank_integration = 0 if !bank_integration[0].nil? @@ -58,4 +67,9 @@ class Origami::MasterController < BaseOrigamiController end end + #Shop Name in Navbor + helper_method :shop_detail + def shop_detail + @shop = Shop.first + end end diff --git a/app/controllers/origami/mpu_controller.rb b/app/controllers/origami/mpu_controller.rb old mode 100755 new mode 100644 index c3f74133..1b125bda --- a/app/controllers/origami/mpu_controller.rb +++ b/app/controllers/origami/mpu_controller.rb @@ -4,33 +4,43 @@ class Origami::MpuController < BaseOrigamiController @cashier_type = params[:type] # limit mpu_amount sale_data = Sale.find_by_sale_id(@sale_id) - total = sale_data.grand_total + total = 0 @mpucount = 0 - others = 0 - - @payment_method_setting_nav = PaymentMethodSetting.all @shop = Shop::ShopDetail - if @shop.is_rounding_adj - new_total = Sale.get_rounding_adjustment(sale_data.grand_total) - else - new_total = sale_data.grand_total - end - @rounding_adj = new_total-sale_data.grand_total - - sale_data.sale_payments.each do |sale_payment| - if sale_payment.payment_method == "mpu" - @mpucount = @mpucount + sale_payment.payment_amount - else - others = others + sale_payment.payment_amount - end - end - @can_mpu = total - @mpucount - others + @rounding_adj = 0 + @can_mpu = 0 + @member_discount = 0 + @sub_total = 0 + @membership_id = nil + @receipt_no = nil + if !sale_data.nil? + total = sale_data.grand_total + + others = 0 + + if @shop.is_rounding_adj + new_total = Sale.get_rounding_adjustment(sale_data.grand_total) + else + new_total = sale_data.grand_total + end + @rounding_adj = new_total-sale_data.grand_total + + sale_data.sale_payments.each do |sale_payment| + if sale_payment.payment_method == "mpu" + @mpucount = @mpucount + sale_payment.payment_amount + else + others = others + sale_payment.payment_amount + end + end + @can_mpu = total - @mpucount - others + + @member_discount = MembershipSetting.find_by_discount(1) + @sub_total = sale_data.total_amount + @membership_id = sale_data.customer.membership_id + #for bank integration + @receipt_no = sale_data.receipt_no + end - @member_discount = MembershipSetting.find_by_discount(1) - @sub_total = sale_data.total_amount - @membership_id = sale_data.customer.membership_id - #for bank integration - @receipt_no = sale_data.receipt_no bank_integration = Lookup.collection_of('bank_integration') @bank_integration = 0 if !bank_integration[0].nil? @@ -58,4 +68,9 @@ class Origami::MpuController < BaseOrigamiController end end + #Shop Name in Navbor + helper_method :shop_detail + def shop_detail + @shop = Shop.first + end end diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index f9aaa51c..edee8a03 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -177,8 +177,11 @@ class Origami::PaymentsController < BaseOrigamiController end booking.booking_orders.each do |order| - Order.pay_process_order_queue(order.order_id,table_id) + # Order.pay_process_order_queue(order.order_id, table_id) + oqs = OrderQueueStation.new + oqs.pay_process_order_queue(order.order_id, table_id) end + end #for card sale data diff --git a/app/controllers/origami/unionpay_controller.rb b/app/controllers/origami/unionpay_controller.rb index 707a1022..7213af6d 100644 --- a/app/controllers/origami/unionpay_controller.rb +++ b/app/controllers/origami/unionpay_controller.rb @@ -4,32 +4,40 @@ class Origami::UnionpayController < BaseOrigamiController @cashier_type = params[:type] # limit unionpay_amount sale_data = Sale.find_by_sale_id(@sale_id) - total = sale_data.grand_total + total = 0 @unionpaycount = 0 - others = 0 - - @payment_method_setting_nav = PaymentMethodSetting.all @shop = Shop::ShopDetail - if @shop.is_rounding_adj - new_total = Sale.get_rounding_adjustment(sale_data.grand_total) - else - new_total = sale_data.grand_total + @rounding_adj = 0 + @can_unionpay = 0 + @member_discount = 0 + @sub_total = 0 + @membership_id = nil + @receipt_no = nil + if !sale_data.nil? + total = sale_data.grand_total + others = 0 + + if @shop.is_rounding_adj + new_total = Sale.get_rounding_adjustment(sale_data.grand_total) + else + new_total = sale_data.grand_total + end + @rounding_adj = new_total-sale_data.grand_total + + sale_data.sale_payments.each do |sale_payment| + if sale_payment.payment_method == "unionpay" + @unionpaycount = @unionpaycount + sale_payment.payment_amount + else + others = others + sale_payment.payment_amount + end + end + @can_unionpay = total - @unionpaycount - others + @member_discount = MembershipSetting.find_by_discount(1) + @sub_total = sale_data.total_amount + @membership_id = sale_data.customer.membership_id + #for bank integration + @receipt_no = sale_data.receipt_no end - @rounding_adj = new_total-sale_data.grand_total - - sale_data.sale_payments.each do |sale_payment| - if sale_payment.payment_method == "unionpay" - @unionpaycount = @unionpaycount + sale_payment.payment_amount - else - others = others + sale_payment.payment_amount - end - end - @can_unionpay = total - @unionpaycount - others - @member_discount = MembershipSetting.find_by_discount(1) - @sub_total = sale_data.total_amount - @membership_id = sale_data.customer.membership_id - #for bank integration - @receipt_no = sale_data.receipt_no bank_integration = Lookup.collection_of('bank_integration') @bank_integration = 0 if !bank_integration[0].nil? @@ -58,4 +66,9 @@ class Origami::UnionpayController < BaseOrigamiController end end + #Shop Name in Navbor + helper_method :shop_detail + def shop_detail + @shop = Shop.first + end end diff --git a/app/controllers/origami/visa_controller.rb b/app/controllers/origami/visa_controller.rb old mode 100755 new mode 100644 index 788704eb..346b66d1 --- a/app/controllers/origami/visa_controller.rb +++ b/app/controllers/origami/visa_controller.rb @@ -4,32 +4,40 @@ class Origami::VisaController < BaseOrigamiController @cashier_type = params[:type] # limit visa_amount sale_data = Sale.find_by_sale_id(@sale_id) - total = sale_data.grand_total + total = 0 @visacount = 0 - others = 0 - - @payment_method_setting_nav = PaymentMethodSetting.all @shop = Shop::ShopDetail - if @shop.is_rounding_adj - new_total = Sale.get_rounding_adjustment(sale_data.grand_total) - else - new_total = sale_data.grand_total + @rounding_adj = 0 + @can_visa = 0 + @member_discount = 0 + @sub_total = 0 + @membership_id = nil + @receipt_no = nil + if !sale_data.nil? + total = sale_data.grand_total + others = 0 + + if @shop.is_rounding_adj + new_total = Sale.get_rounding_adjustment(sale_data.grand_total) + else + new_total = sale_data.grand_total + end + @rounding_adj = new_total-sale_data.grand_total + + sale_data.sale_payments.each do |sale_payment| + if sale_payment.payment_method == "visa" + @visacount = @visacount + sale_payment.payment_amount + else + others = others + sale_payment.payment_amount + end + end + @can_visa = total - @visacount - others + @member_discount = MembershipSetting.find_by_discount(1) + @sub_total = sale_data.total_amount + @membership_id = sale_data.customer.membership_id + #for bank integration + @receipt_no = sale_data.receipt_no end - @rounding_adj = new_total-sale_data.grand_total - - sale_data.sale_payments.each do |sale_payment| - if sale_payment.payment_method == "visa" - @visacount = @visacount + sale_payment.payment_amount - else - others = others + sale_payment.payment_amount - end - end - @can_visa = total - @visacount - others - @member_discount = MembershipSetting.find_by_discount(1) - @sub_total = sale_data.total_amount - @membership_id = sale_data.customer.membership_id - #for bank integration - @receipt_no = sale_data.receipt_no bank_integration = Lookup.collection_of('bank_integration') @bank_integration = 0 if !bank_integration[0].nil? @@ -58,4 +66,9 @@ class Origami::VisaController < BaseOrigamiController end end + #Shop Name in Navbor + helper_method :shop_detail + def shop_detail + @shop = Shop.first + end end diff --git a/app/models/order.rb b/app/models/order.rb index 25c5db4a..fcc8b6c2 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -71,9 +71,9 @@ class Order < ApplicationRecord BookingOrder.create({:booking_id => booking.booking_id, :order => self}) #Send order to queue one it done! - if self.source != "quick_service" + # if self.source != "quick_service" process_order_queue - end + # end #send order to broadcast job send_order_broadcast(booking) @@ -297,7 +297,7 @@ class Order < ApplicationRecord else if order oqs = OrderQueueStation.new - oqs.process_order(order, self.table_id) + oqs.process_order(order, self.table_id, self.source) end assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id) ActionCable.server.broadcast "order_queue_station_channel",order: assign_order @@ -313,7 +313,7 @@ class Order < ApplicationRecord else if order oqs = OrderQueueStation.new - oqs.process_order(order, self.table_id) + oqs.process_order(order, self.table_id, self.source) end assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id) ActionCable.server.broadcast "order_queue_station_channel",order: assign_order @@ -326,7 +326,7 @@ class Order < ApplicationRecord else if order oqs = OrderQueueStation.new - oqs.process_order(order, self.table_id) + oqs.process_order(order, self.table_id, self.source) end assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id) ActionCable.server.broadcast "order_queue_station_channel",order: assign_order diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index af544ce5..3380f244 100755 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -101,6 +101,80 @@ class OrderQueueStation < ApplicationRecord end #end else end + def pay_process_order_queue (order_id, table_id) + + oqs_stations = OrderQueueStation.active + + order = Order.find(order_id) + order_items = order.order_items + + if table_id.to_i > 0 + # get dining + dining = DiningFacility.find(table_id) + oqs_by_zones = OrderQueueProcessByZone.where("zone_id=#{dining.zone_id}") + booking = Booking.find_by_dining_facility_id(dining.id) + + # ToDo per item per printer + + oqs_by_zones.each do |oqpbz| + oqs = OrderQueueStation.find(oqpbz.order_queue_station_id) + is_auto_printed = false + oqs_order_items = [] + + if oqs.is_active + #Get List of items - + pq_items = JSON.parse(oqs.processing_items) + #Loop through the processing items + pq_items.each do |pq_item| + #Processing through the looping items + order_items.each do |order_item| + if (pq_item == order_item.item_code) + if (order_item.qty > 0) + oqs_order_items.push(order_item) + end + end + end + end + + if oqs.auto_print + if oqs_order_items.length > 0 + print_slip(oqs, order, oqs_order_items) + is_auto_printed = true + end + end + end + end + else + oqs_stations.each do |oqs| + is_auto_printed = false + oqs_order_items = [] + + if oqs.is_active + #Get List of items - + pq_items = JSON.parse(oqs.processing_items) + #Loop through the processing items + pq_items.each do |pq_item| + #Processing through the looping items + order_items.each do |order_item| + if (pq_item == order_item.item_code) + if (order_item.qty > 0) + oqs_order_items.push(order_item) + end + end + end + end + + if oqs.auto_print + if oqs_order_items.length > 0 + print_slip(oqs, order, oqs_order_items) + is_auto_printed = true + end + end + end + end + end #end else + end + private #Print order_items in 1 slip def print_slip(oqs, order, order_items) diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index b82cbf18..91a4db1e 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -325,6 +325,7 @@ class SalePayment < ApplicationRecord sObj = Sale.find(self.sale_id) is_credit = 0 is_foc = 0 + is_cash = false sObj.sale_payments.each do |spay| all_received_amount += spay.payment_amount.to_f if spay.payment_method == "creditnote" @@ -333,8 +334,12 @@ class SalePayment < ApplicationRecord if spay.payment_method == "foc" is_foc = 1 end + if spay.payment_method.to_s == "cash" + is_cash = true + end end - if (self.sale.grand_total <= all_received_amount) + + if (self.sale.grand_total <= all_received_amount) && is_cash if is_credit == 0 self.sale.payment_status = "paid" else @@ -374,11 +379,15 @@ class SalePayment < ApplicationRecord end self.sale.save! - table_update_status(sObj) if check_foc + table_update_status(sObj) update_shift elsif paid_amount.to_f > 0 #|| paid_amount != "0.0" + table_update_status(sObj) + update_shift + elsif is_cash && paid_amount.to_f == 0 + table_update_status(sObj) update_shift end end diff --git a/app/views/origami/pending_order/index.html.erb b/app/views/origami/pending_order/index.html.erb old mode 100755 new mode 100644 diff --git a/app/views/origami/pending_order/show.html.erb b/app/views/origami/pending_order/show.html.erb index a7ade0a4..19750c4d 100644 --- a/app/views/origami/pending_order/show.html.erb +++ b/app/views/origami/pending_order/show.html.erb @@ -97,13 +97,15 @@ <% end%> <% else%> <% sub_total = 0 + total = 0 @order_items.each do |order_item| - sub_total = sub_total + order_item.price %> + total = order_item.qty * order_item.price + sub_total = sub_total + total %> <%= order_item.item_name %> <%= order_item.qty %> - <%= order_item.price %> + <%= total %> <% end%> <% end%> @@ -210,7 +212,7 @@ $(document).ready(function(){ swal("Information!", result.error_message); } else { - location.reload(); + window.location.href = '/origami/quick_service/pending_order'; } } }); From 27a3026c2a8642e826a66898149708fdef6887e0 Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 19 Mar 2018 19:41:32 +0630 Subject: [PATCH 5/5] oqs edit --- app/models/order_queue_station.rb | 6 +++--- app/views/oqs/edit/index.html.erb | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index 3380f244..889491ed 100755 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -13,7 +13,7 @@ class OrderQueueStation < ApplicationRecord # validations validates_presence_of :station_name, :printer_name - def process_order (order, table_id) + def process_order (order, table_id, order_source = nil) oqs_stations = OrderQueueStation.active @@ -55,7 +55,7 @@ class OrderQueueStation < ApplicationRecord end end - if oqs.auto_print + if oqs.auto_print && order_source != "quick_service" if oqs_order_items.length > 0 print_slip(oqs, order, oqs_order_items) is_auto_printed = true @@ -90,7 +90,7 @@ class OrderQueueStation < ApplicationRecord end end - if oqs.auto_print + if oqs.auto_print && order_source != "quick_service" if oqs_order_items.length > 0 print_slip(oqs, order, oqs_order_items) is_auto_printed = true diff --git a/app/views/oqs/edit/index.html.erb b/app/views/oqs/edit/index.html.erb index 7a1eebab..70e9a0ff 100644 --- a/app/views/oqs/edit/index.html.erb +++ b/app/views/oqs/edit/index.html.erb @@ -144,9 +144,12 @@ $(document).ready(function(){ }); $('#back').on('click', function () { + var booking_id = '<%= @booking.booking_id %>'; <% if !@link_type.nil? %> <% if @link_type == 'oqs' %> window.location.href = '/oqs'; + <% elsif @link_type == 'pending' %> + window.location.href = '/origami/quick_service/pending_order/'+booking_id; <% else %> <% if !@dining_type.nil? %> <% if @dining_type == 'Table' %>