diff --git a/app/controllers/reports/payment_method_controller.rb b/app/controllers/reports/payment_method_controller.rb index 5c440e17..23c256d3 100644 --- a/app/controllers/reports/payment_method_controller.rb +++ b/app/controllers/reports/payment_method_controller.rb @@ -2,7 +2,7 @@ class Reports::PaymentMethodController < BaseReportController # authorize_resource :class => false def index - @payments = [["Cash Payment","cash"], ["Credit Payment","creditnote"], + @payments = [["All Payment",''],["Cash Payment","cash"], ["Credit Payment","creditnote"], ["FOC Payment","foc"], ["MPU Payment","mpu"], ["Visa Payment","visa"], ["Master Payment","master"], ["JCB Payment","jcb"], ["Redeem Payment","paypar"]] @@ -19,9 +19,10 @@ class Reports::PaymentMethodController < BaseReportController @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) end end - payment_type = params[:payment_type] - @sale_data,@pyament_method = Sale.get_payment_method_by_shift(@shift_sale_range,@shift,from,to,payment_type) - + @payment_type = params[:payment_type] + @sale_data,@pyament_method = Sale.get_payment_method_by_shift(@shift_sale_range,@shift,from,to,@payment_type) + puts @pyament_method.to_json + puts "sssssssssssss" @from = from @to = to diff --git a/app/models/sale.rb b/app/models/sale.rb index c6d30e10..ef91fb76 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -793,11 +793,12 @@ def self.get_separate_tax(shift_sale_range=nil,shift,from,to,payment_type) end def self.get_payment_method_by_shift(shift_sale_range,shift,from,to,payment_type) + sale_payment = SalePayment.select("s.receipt_no, sale_payments.*,s.receipt_date as sale_date, s.cashier_name as cashier_name") .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") - payments_total = Sale.select("CAST((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')) AS DATE) as sale_date, + payments_total = SalePayment.select("CAST((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')) AS DATE) as sale_date, SUM(case when (sale_payments.payment_method='mpu') then sale_payments.payment_amount else 0 end) as mpu_amount, SUM(case when (sale_payments.payment_method='master') then sale_payments.payment_amount else 0 end) as master_amount, SUM(case when (sale_payments.payment_method='visa') then sale_payments.payment_amount else 0 end) as visa_amount, @@ -806,26 +807,42 @@ def self.get_payment_method_by_shift(shift_sale_range,shift,from,to,payment_type SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount") - .joins("join (select * from sale_payments group by sale_payments.sale_id, sale_payments.payment_method) sale_payments on sale_payments.sale_id = sales.sale_id") - + .joins("join sales on sales.sale_id = sale_payments.sale_id") if shift.present? - all_total = payments_total.where("sales.shift_sale_id in (?) and sale_status= 'completed' and sale_payments.payment_amount != 0", shift.to_a) - # .group("DATE_FORMAT((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')),'%Y-%m-%d')") + all_total = payments_total.where("sales.shift_sale_id in (?) and sale_status= 'completed' and sale_payments.payment_amount != 0", shift.to_a) + # .group("DATE_FORMAT((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')),'%Y-%m-%d')") + if payment_type.blank? + sale_type = sale_payment.where("s.sale_status = 'completed' and payment_amount != 0 and s.shift_sale_id in (?)",shift.to_a) + .order("payment_method") + else + sale_type = sale_payment.where("payment_method= '#{payment_type}' and payment_amount != 0 and s.sale_status = 'completed' and s.shift_sale_id in (?)",shift.to_a) + end - sale_type = sale_payment.where("payment_method= '#{payment_type}' and s.sale_status = 'completed' and s.shift_sale_id in (?)",shift.to_a) elsif shift_sale_range.present? - all_total = paymessnts_total.where("sales.shift_sale_id in (?) and sale_status= 'completed' and sale_payments.payment_amount != 0", shift_sale_range.to_a) - - sale_type = sale_payment.where("payment_method='#{payment_type}' and s.sale_status = 'completed' and s.shift_sale_id in (?)",shift_sale_range.to_a) + all_total = payments_total.where("sales.shift_sale_id in (?) and sale_status= 'completed' and sale_payments.payment_amount != 0", shift_sale_range.to_a) + # .group("DATE_FORMAT((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')),'%Y-%m-%d')") + if payment_type.blank? + sale_type = sale_payment.where("s.sale_status = 'completed' and payment_amount != 0 and s.shift_sale_id in (?)",shift_sale_range.to_a) + .order("payment_method") + else + sale_type = sale_payment.where("payment_method='#{payment_type}' and payment_amount != 0 and s.sale_status = 'completed' and s.shift_sale_id in (?)",shift_sale_range.to_a) + end + else - all_total = payments_total.where("sales.receipt_date and sale_status= 'completed' and sale_payments.payment_amount != 0", from,to) - - sale_type = sale_payment.where("payment_method='#{payment_type}' and s.sale_status = 'completed' and s.receipt_date between ? and ? ",from,to) + all_total = payments_total.where("sales.receipt_date between ? and ? and sales.sale_status= 'completed' and sale_payments.payment_amount != 0", from,to) + # .group("DATE_FORMAT((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')),'%Y-%m-%d')") + if payment_type.blank? + sale_type = sale_payment.where("s.sale_status = 'completed' and payment_amount != 0 and s.receipt_date between ? and ? ",from,to) + .order("payment_method") + else + sale_type = sale_payment.where("payment_method='#{payment_type}' and payment_amount != 0 and s.sale_status = 'completed' and s.receipt_date between ? and ? ",from,to) + end end + return all_total,sale_type end diff --git a/app/views/layouts/_left_sidebar.html.erb b/app/views/layouts/_left_sidebar.html.erb index d269a3c1..cf9f77c0 100755 --- a/app/views/layouts/_left_sidebar.html.erb +++ b/app/views/layouts/_left_sidebar.html.erb @@ -118,6 +118,9 @@
  • Void Sales
  • +
  • + Payment Method +
  • Commission
  • diff --git a/app/views/reports/credit_payment/index.html.erb b/app/views/reports/credit_payment/index.html.erb index 9b72ba9b..2eed1622 100755 --- a/app/views/reports/credit_payment/index.html.erb +++ b/app/views/reports/credit_payment/index.html.erb @@ -81,11 +81,13 @@ show_shift_name(period,period_type,from,to,'shift_item'); } - $('#from').change(function(){ - search_by_date(); + // OK button is clicked + $('#from').bootstrapMaterialDatePicker().on('beforeChange', function(e, date){ + $('#from').val(date.format("DD-MM-YYYY")) + search_by_date(); }); - - $('#to').change(function(){ + $('#to').bootstrapMaterialDatePicker().on('beforeChange', function(e, date){ + $('#to').val(date.format("DD-MM-YYYY")) search_by_date(); }); diff --git a/app/views/reports/payment_method/_shift_sale_report_filter.html.erb b/app/views/reports/payment_method/_shift_sale_report_filter.html.erb index d791852f..3a7f93c3 100755 --- a/app/views/reports/payment_method/_shift_sale_report_filter.html.erb +++ b/app/views/reports/payment_method/_shift_sale_report_filter.html.erb @@ -27,11 +27,11 @@
    - +
    - +
    diff --git a/app/views/reports/payment_method/index.html.erb b/app/views/reports/payment_method/index.html.erb index 17aceaff..40036a37 100755 --- a/app/views/reports/payment_method/index.html.erb +++ b/app/views/reports/payment_method/index.html.erb @@ -1,7 +1,7 @@ +
    \ No newline at end of file diff --git a/app/views/reports/receipt_no/index.html.erb b/app/views/reports/receipt_no/index.html.erb index 395dd3ce..32d4df12 100755 --- a/app/views/reports/receipt_no/index.html.erb +++ b/app/views/reports/receipt_no/index.html.erb @@ -145,11 +145,13 @@ show_shift_name(period,period_type,from,to,'shift_item'); } - $('#from').change(function(){ - search_by_date(); + // OK button is clicked + $('#from').bootstrapMaterialDatePicker().on('beforeChange', function(e, date){ + $('#from').val(date.format("DD-MM-YYYY")) + search_by_date(); }); - - $('#to').change(function(){ + $('#to').bootstrapMaterialDatePicker().on('beforeChange', function(e, date){ + $('#to').val(date.format("DD-MM-YYYY")) search_by_date(); }); diff --git a/app/views/reports/saleitem/index.html.erb b/app/views/reports/saleitem/index.html.erb index 13b8f598..587d7c52 100755 --- a/app/views/reports/saleitem/index.html.erb +++ b/app/views/reports/saleitem/index.html.erb @@ -209,11 +209,13 @@ show_shift_name(period,period_type,from,to,'shift_item'); } - $('#from').change(function(){ - search_by_date(); + // OK button is clicked + $('#from').bootstrapMaterialDatePicker().on('beforeChange', function(e, date){ + $('#from').val(date.format("DD-MM-YYYY")) + search_by_date(); }); - - $('#to').change(function(){ + $('#to').bootstrapMaterialDatePicker().on('beforeChange', function(e, date){ + $('#to').val(date.format("DD-MM-YYYY")) search_by_date(); }); diff --git a/app/views/reports/shiftsale/index.html.erb b/app/views/reports/shiftsale/index.html.erb index 97330404..54b63caa 100755 --- a/app/views/reports/shiftsale/index.html.erb +++ b/app/views/reports/shiftsale/index.html.erb @@ -143,11 +143,13 @@ show_shift_name(period,period_type,from,to,'shift_item'); } - $('#from').change(function(){ - search_by_date(); + // OK button is clicked + $('#from').bootstrapMaterialDatePicker().on('beforeChange', function(e, date){ + $('#from').val(date.format("DD-MM-YYYY")) + search_by_date(); }); - - $('#to').change(function(){ + $('#to').bootstrapMaterialDatePicker().on('beforeChange', function(e, date){ + $('#to').val(date.format("DD-MM-YYYY")) search_by_date(); }); diff --git a/app/views/reports/void_sale/index.html.erb b/app/views/reports/void_sale/index.html.erb index 649d422e..3b240c2d 100755 --- a/app/views/reports/void_sale/index.html.erb +++ b/app/views/reports/void_sale/index.html.erb @@ -103,13 +103,15 @@ show_shift_name(period,period_type,from,to,'shift_item'); } - $('#from').change(function(){ - search_by_date(); - }); - - $('#to').change(function(){ + // OK button is clicked + $('#from').bootstrapMaterialDatePicker().on('beforeChange', function(e, date){ + $('#from').val(date.format("DD-MM-YYYY")) search_by_date(); - }); + }); + $('#to').bootstrapMaterialDatePicker().on('beforeChange', function(e, date){ + $('#to').val(date.format("DD-MM-YYYY")) + search_by_date(); + }); function search_by_date(){ var from = $('#from').val(); diff --git a/config/locales/en.yml b/config/locales/en.yml index dc020d95..d8780e33 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -411,6 +411,7 @@ en: select_payments: "Select Payments" all_shift: "All Shift" receipt_no_report: "Receipt No Report" + payment_method_report: "Payment Method Report" rnd_adj_sh: "Rounding Adj." shift_sale_report: "Shift Sale Report" cashier_station: "Cashier Station"