diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 254a9a0f..77dd5821 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -207,7 +207,7 @@ class Origami::PaymentsController < BaseOrigamiController end printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, printed_status,current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,Shop.current_shop, printed_status,current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil) # if !saleObj.nil? # InventoryJob.perform_now(self.id) # InventoryDefinition.calculate_product_count(saleObj) diff --git a/app/controllers/reports/customer_controller.rb b/app/controllers/reports/customer_controller.rb index b623d1e0..8cd25e73 100644 --- a/app/controllers/reports/customer_controller.rb +++ b/app/controllers/reports/customer_controller.rb @@ -34,7 +34,7 @@ class Reports::CustomerController < BaseReportController membership_type = params[:membership_type] end @sale_data = Sale.get_shift_sales_by_customer(@shift_sale_range, @shift, from, to, membership_type, customer_filter) - @sale_taxes = Sale.get_separate_tax(@shift_sale_range, @shift, from, to, nil) + @sale_taxes = Sale.get_separate_tax_by_customer(@shift_sale_range, @shift, from, to, nil, customer_filter, membership_type) @tax_profiles = TaxProfile.group('name').order('order_by asc') #.limit(2) @from = from diff --git a/app/controllers/reports/receipt_no_controller.rb b/app/controllers/reports/receipt_no_controller.rb index d01bfe64..e20f0793 100755 --- a/app/controllers/reports/receipt_no_controller.rb +++ b/app/controllers/reports/receipt_no_controller.rb @@ -32,7 +32,7 @@ authorize_resource :class => false payment_type = params[:payment_type] @sale_data = Sale.get_shift_sales_by_receipt_no(@shift_sale_range, @shift, from, to, payment_type, customer_filter) - @sale_taxes = Sale.get_separate_tax(@shift_sale_range, @shift, from, to, payment_type) + @sale_taxes = Sale.get_separate_tax_by_customer(@shift_sale_range, @shift, from, to, payment_type, customer_filter) @tax_profiles = TaxProfile.group('name').order('order_by asc') #.limit(2) @from = from diff --git a/app/models/sale.rb b/app/models/sale.rb index 981bf2ac..abef0d42 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1225,7 +1225,7 @@ def self.get_shift_sales_by_receipt_no(shift_sale_range, shift, from, to, paymen if payment_type.blank? payment_type = '' else - payment_type = " and sale_payments.payment_method = '#{payment_type}'" + payment_type = "sale_payments.payment_method = '#{payment_type}'" end query = Sale.includes(:sale_items).select("sales.*, sale_payments.*") @@ -1235,7 +1235,9 @@ def self.get_shift_sales_by_receipt_no(shift_sale_range, shift, from, to, paymen .joins("LEFT JOIN dining_facilities ON dining_facilities.id = bookings.dining_facility_id") .completed.where.not(total_amount: 0) .group("sales.sale_id") - + if payment_type != '' + query = query.where("#{payment_type} and sale_payments.payment_amount!=0") + end if customer_filter.present? query = query.joins(sanitize_sql_array(["INNER JOIN customers ON customers.customer_id = sales.customer_id AND " + "customers.name LIKE :filter", filter: "%#{customer_filter}%"])) @@ -1440,6 +1442,31 @@ def self.get_separate_tax(shift_sale_range=nil,shift,from,to,payment_type) end end +def self.get_separate_tax_by_customer(shift_sale_range, shift, from, to, payment_type,customer_filter, membership_type=nil) + + query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name") + .where("sale_status= 'completed'") + .joins("LEFT JOIN sales ON sales.sale_id = sale_taxes.sale_id") + .group("sale_taxes.tax_name") + .order("sale_taxes.tax_name desc") + if payment_type.present? + query = query.joins("JOIN sale_payments ON sale_payments.sale_id = sale_taxes.sale_id AND sale_payments.payment_method = '#{payment_type}' and sale_payments.payment_amount!=0") + end + + query = query.joins("INNER JOIN customers ON customers.customer_id = sales.customer_id + #{sanitize_sql_array(['AND customers.name LIKE :filter', filter: "%#{customer_filter}%"]) if customer_filter.present?} + #{sanitize_sql_array(['AND customers.membership_type = :type', type: membership_type]) if membership_type.present?}") + + if shift.present? + query = query.where("sales.shift_sale_id in (?) ", shift.to_a) + elsif shift_sale_range.present? + query = query.where("sales.shift_sale_id in (?) ", shift_sale_range.to_a) + else + query = query.where("sales.receipt_date between ? and ? ", from,to) + end + +end + def self.get_payment_method_by_shift(shift,from,to,payment_type) payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index d1a8f7a2..593c3a27 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -165,13 +165,7 @@ $("#member_acc_no").on('click', function(e){ localStorage.setItem("member_card",true); $("#sxModal").show(); -<<<<<<< HEAD - setTimeout(function(){ - getCardNo(); - },100); -======= getCardNo(); ->>>>>>> r-1902001-01 }); // QR Code Reader diff --git a/app/views/reports/customer/_shift_sale_report_filter.html.erb b/app/views/reports/customer/_shift_sale_report_filter.html.erb index 35819152..44fa908c 100755 --- a/app/views/reports/customer/_shift_sale_report_filter.html.erb +++ b/app/views/reports/customer/_shift_sale_report_filter.html.erb @@ -31,7 +31,7 @@ diff --git a/app/views/settings/lookups/_form.html.erb b/app/views/settings/lookups/_form.html.erb index 92ec53a8..5712300c 100755 --- a/app/views/settings/lookups/_form.html.erb +++ b/app/views/settings/lookups/_form.html.erb @@ -1,5 +1,3 @@ -<% breadcrumb_add 'LookUp', settings_lookups_path, settings_lookups_path, t("views.btn.#{action_name}") %> -