From 43b9bdc168d6c53997d9655ec400a5e76b2aa45f Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 30 Jun 2017 14:15:04 +0630 Subject: [PATCH 1/3] update shiftsale --- .../reports/shiftsale_controller.rb | 2 +- app/models/sale.rb | 57 +++++++++++++++ app/views/layouts/_header.html.erb | 2 +- app/views/reports/shiftsale/index.html.erb | 69 ++++++++++--------- 4 files changed, 95 insertions(+), 35 deletions(-) diff --git a/app/controllers/reports/shiftsale_controller.rb b/app/controllers/reports/shiftsale_controller.rb index 5f13857d..6d8df8c6 100644 --- a/app/controllers/reports/shiftsale_controller.rb +++ b/app/controllers/reports/shiftsale_controller.rb @@ -1,4 +1,4 @@ -class Reports::ShiftsaleController < ApplicationController +class Reports::ShiftsaleController < BaseReportController # authorize_resource :class => false def index diff --git a/app/models/sale.rb b/app/models/sale.rb index 9c3aea00..313a6f80 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -448,6 +448,63 @@ def self.get_by_shiftsales(from,to) return ShiftSale.where("(shift_started_at between ? and ? OR shift_closed_at between ? and ? )", from, to, from, to) end +# def self.get_by_shiftsales(employee,from,to) +# shift_sales = ShiftSale.select('shift_sales.id, cs.name as cashier_station_name, shift_sales.shift_started_at as opening_date, shift_sales.shift_closeed_at as closing_date') +# .joins(" INNER JOIN cashier_terminals cs ON cs.id = shift_sales.cashier_terminal_id") +# .where("shift_sales.employee_id = ? and (shift_sales.shift_started_at between ? and ? OR shift_sales.shift_closeed_at between ? and ? )", employee, from, to, from, to) +# .order("shift_sales.id DESC") + +# sale_arr = Array.new +# shift_sales.each do |shift| +# all_total= Sale.select("grand_total,sr.payment_method, sr.payment_amount, rounding_adjustment") +# .joins("join employees e on sales.cashier_id = e.id join shift_sales sh on sh.id = sales.shift_sale_id") +# .joins("INNER JOIN (select * from sale_payments group by sale_payments.sale_id, sale_payments.payment_method) sr ON sr.sale_id = sales.sale_id") +# .where("sales.shift_sale_id =? and sales.sale_status = 'completed' and sales.total_amount != 0",shift.id) + +# void = Sale.select("SUM(sales.grand_total) AS grand_total") +# .joins("join shift_sales sh on sh.id = sales.shift_sale_id") +# .where('sales.sales_status = "void" and sales.total_amount != 0 and sales.shift_sale_id = ?', shift.id) +# .sum(:grand_total) +# cash = all_total.select('sr.payment_type') +# .where('sr.payment_type = "cash"') +# .sum(:amount) + +# credit = all_total.where('sr.payment_type = "credit"') +# .sum(:amount) + +# accept_credit = all_total.select('ci.amout') +# .joins("INNER JOIN credit_items ci ON ci.sale_id = sales.id") +# .where('sr.payment_type = "credit"') +# .sum(:amout) + + + +# foc = all_total.where('sales.payment_type = "foc" and sales.sales_status = "completed"') +# .sum(:grand_total) + +# card = all_total.select('payment_type') +# .where('sr.payment_type = "card"') +# .sum(:amount).to_f + +# rounding_adj = all_total.sum(:rounding_adjustment) + +# discount = all_total.sum(:discount_amount) +# void = void.nil? ? 0 : void +# cash = cash.nil? ? 0 : cash +# credit = credit.nil? ? 0 : credit +# foc = foc.nil? ? 0 : foc +# card = card.nil? ? 0 : card +# accept_credit = accept_credit.nil? ? 0 : accept_credit +# # all_payments = void.to_d + cash.to_d + credit.to_d + foc.to_d + card.to_d + accept_credit.to_d +# all_payments = cash.to_d + credit.to_d + foc.to_d + card.to_d + accept_credit.to_d +# payments = { void_amount: void, cash_amount: cash, credit_amount: credit,accept_credit_amount: accept_credit, foc_amount: foc, card_amount: card, grand_total: all_payments , cashier_station_name: shift.cashier_station_name, opening_date: shift.opening_date, closing_date: shift.closing_date, rounding_adj: rounding_adj } + +# sale_arr.push(payments) +# end + +# return sale_arr +# end + private def generate_custom_id diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 558d35dd..ca16298c 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -42,7 +42,7 @@
  • <%= link_to "Daily Sale Report", reports_dailysale_index_path, :tabindex =>"-1" %>
  • <%= link_to "Sales Item Report", reports_saleitem_index_path, :tabindex =>"-1" %>
  • <%= link_to "Receipt Report", reports_receipt_no_index_path, :tabindex =>"-1" %>
  • - +
  • <%= link_to "Shift Sale Report", reports_shiftsale_index_path, :tabindex =>"-1" %>
  • diff --git a/app/views/reports/shiftsale/index.html.erb b/app/views/reports/shiftsale/index.html.erb index 8582a578..a2732834 100644 --- a/app/views/reports/shiftsale/index.html.erb +++ b/app/views/reports/shiftsale/index.html.erb @@ -35,16 +35,17 @@ Cashier Station + Cashier Name Shift Name - Void Amount + Cash Payment - Credit Charges + Credit Payment - FOC Payment + Card Payment Grand Total + -
    Rounding Adj - Rounding Adj + + Grand Total @@ -58,48 +59,50 @@ <% total = 0%> <% rounding_adj = 0%> <% g_total = 0 %> - - <% @sale_data.each do |result| %> + + <% @sale_data.each do |result|%> - <%= result[:cashier_station_name] rescue '-'%> + <%= result.cashier_terminal.name rescue '-'%> - <%= result[:shift_started_at].strftime("%e %b %I:%M%p") rescue '-' %> - - <%= result[:shift_closed_at].strftime("%e %b %I:%M%p") rescue '-' %> + + <%= result.employee.name rescue '-'%> + + <%= result.shift_started_at.strftime("%e %b %I:%M%p") rescue '-' %> - + <%= result.shift_closed_at.strftime("%e %b %I:%M%p") rescue '-' %> - - <%= sprintf "%.2f",result[:cash_amount].to_f.to_d rescue '-'%> - <%= sprintf "%.2f",result[:credit_amount].to_f.to_d rescue '-'%> - <%= sprintf "%.2f",result[:accept_credit_amount].to_f.to_d rescue '-'%> - <%= sprintf "%.2f",result[:foc_amount].to_f.to_d rescue '-'%> - <%= sprintf "%.2f",result[:card_amount].to_f.to_d rescue '-'%> - <%= sprintf "%.2f",result[:grand_total].to_f.to_d rescue '-'%> - <%= sprintf "%.2f",result[:rounding_adj].to_f.to_d rescue '-'%> - <% grand_total = result[:grand_total].to_f - result[:rounding_adj].to_f %> - <%= sprintf "%.2f",grand_total.to_f.to_d rescue '-'%> + + <%= sprintf "%.2f",result.cash_sales.to_f.to_d rescue '-'%> + <%= sprintf "%.2f",result.credit_sales.to_f.to_d rescue '-'%> + + + <%= sprintf "%.2f",result.other_sales.to_f.to_d rescue '-'%> + <%= sprintf "%.2f",result.grand_total.to_f.to_d rescue '-'%> + + + <% grand_total = result.grand_total.to_f %> + <%= sprintf "%.2f",grand_tota.to_f.to_d rescue '-'%> - <% void += result[:void_amount].to_f %> - <% cash += result[:cash_amount].to_f %> - <% credit += result[:credit_amount].to_f %> - <% accept_credit += result[:accept_credit_amount].to_f %> - <% foc += result[:foc_amount].to_f %> - <% card += result[:card_amount].to_f %> - <% total += result[:grand_total].to_f %> - <% rounding_adj += result[:rounding_adj].to_f %> + <% cash += result.cash_sales.to_f %> + <% credit += result.credit_sales.to_f %> + <% card += result.other_sales.to_f %> + + <% total += result.grand_total.to_f %> <% g_total += grand_total.to_f %> <% end %> - - (<%= sprintf("%.2f",void) rescue '-'%>) + + <%= sprintf("%.2f",cash) rescue '-'%> <%= sprintf("%.2f",credit) rescue '-'%> - <%= sprintf("%.2f",accept_credit) rescue '-'%> - <%= sprintf("%.2f",foc) rescue '-'%> + + <%= sprintf("%.2f",card) rescue '-'%> <%= sprintf("%.2f",total) rescue '-'%> - <%= sprintf("%.2f",rounding_adj) rescue '-'%> + <%= sprintf("%.2f",g_total) rescue '-'%> From 155e1a5ba3c9d95901ec448a90e5d63dc3d9a62b Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 30 Jun 2017 14:16:05 +0630 Subject: [PATCH 2/3] hide shiftsale in header --- app/views/layouts/_header.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index ca16298c..558d35dd 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -42,7 +42,7 @@
  • <%= link_to "Daily Sale Report", reports_dailysale_index_path, :tabindex =>"-1" %>
  • <%= link_to "Sales Item Report", reports_saleitem_index_path, :tabindex =>"-1" %>
  • <%= link_to "Receipt Report", reports_receipt_no_index_path, :tabindex =>"-1" %>
  • -
  • <%= link_to "Shift Sale Report", reports_shiftsale_index_path, :tabindex =>"-1" %>
  • + From 45c69ab53605e239ba195e233c772fa407da5bc1 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 30 Jun 2017 15:53:25 +0630 Subject: [PATCH 3/3] update sale ability and shipt slae --- app/models/ability.rb | 5 +++++ app/models/shift_sale.rb | 2 +- app/views/layouts/_header.html.erb | 2 +- app/views/reports/shiftsale/index.html.erb | 8 ++++---- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index 066311af..624fa76a 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -89,6 +89,11 @@ class Ability can :moving, :movetable can :move_dining, :moveroom + + can :first_bill, :payment + can :show, :payment + can :create, :payment + can :reprint, :payment elsif user.role == "accountant" diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index a897de2b..aa4c565f 100644 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -21,7 +21,7 @@ class ShiftSale < ApplicationRecord #find open shift where is open today and is not closed and login by current cashier today_date = DateTime.now.strftime("%Y-%m-%d") puts today_date - shift = ShiftSale.where("TO_CHAR(shift_started_at, 'YYYY-MM-DD')=? and shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}", today_date).take + shift = ShiftSale.where("DATE(shift_started_at)= #{ today_date } and shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}").take return shift #end diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 558d35dd..fd951d6c 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -42,7 +42,7 @@
  • <%= link_to "Daily Sale Report", reports_dailysale_index_path, :tabindex =>"-1" %>
  • <%= link_to "Sales Item Report", reports_saleitem_index_path, :tabindex =>"-1" %>
  • <%= link_to "Receipt Report", reports_receipt_no_index_path, :tabindex =>"-1" %>
  • - +
  • <%= link_to "Shift Sale Report", reports_shiftsale_index_path, :tabindex =>"-1" %>
  • diff --git a/app/views/reports/shiftsale/index.html.erb b/app/views/reports/shiftsale/index.html.erb index 6a1d69c2..714a8328 100644 --- a/app/views/reports/shiftsale/index.html.erb +++ b/app/views/reports/shiftsale/index.html.erb @@ -42,9 +42,9 @@ Credit Payment - Card Payment - Grand Total + - + Other Payment + Grand Total @@ -101,7 +101,7 @@ <%= sprintf("%.2f",card) rescue '-'%> - <%= sprintf("%.2f",total) rescue '-'%> + <%= sprintf("%.2f",g_total) rescue '-'%>