diff --git a/app/controllers/reports/saleitem_controller.rb b/app/controllers/reports/saleitem_controller.rb index c9715fc3..b9f71494 100644 --- a/app/controllers/reports/saleitem_controller.rb +++ b/app/controllers/reports/saleitem_controller.rb @@ -66,226 +66,5 @@ class Reports::SaleitemController < BaseReportController format.json { render json: out } end end - - # def get_date_range_from_params - # period_type = params[:period_type] - # period = params[:period] - # from = params[:from] - # to = params[:to] - # branch = params[:branch] - # report_type = params[:report_type] - - # shift_name = params[:shift_name] - # unless shift_name.nil? - # shift_arr = shift_name.split(' - ') - # shift_from = shift_arr[0] - # shift_to = shift_arr[1] - # end - - # day_ref = Time.now - - # if period_type.to_i == 1 - # ### =>search by from and to - # unless shift_name.nil? - # if shift_name.to_s == '0' - # ### => all shift - # #f_date = DateTime.parse(from) - # #t_date = DateTime.parse(to) - # if params[:from] && params[:to] - # if params[:from] != "" && params[:to] !="" - # f_date = DateTime.strptime(from, "%m/%d/%Y") - # t_date = DateTime.strptime(to, "%m/%d/%Y") - - # f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec) - # t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec) - # from = f_time.beginning_of_day.utc - # to = t_time.end_of_day.utc - # end - # else - # from = day_ref.beginning_of_day.utc - # to = day_ref.end_of_day.utc - # end - # else - # unless shift_from == '-' - # f_date = DateTime.parse(shift_from) - # from = f_date - # else - # from = '' - # end - - # unless shift_to == '-' - # t_date = DateTime.parse(shift_to) - # to = t_date - # else - # to = '' - # end - # end - # else - # # f_date = DateTime.parse(from) - # # t_date = DateTime.parse(to) - # if params[:from] && params[:to] - # if params[:from] != "" && params[:to] !="" - # f_date = DateTime.strptime(from, "%m/%d/%Y") - # t_date = DateTime.strptime(to, "%m/%d/%Y") - # f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec) - # t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec) - # from = f_time.beginning_of_day.utc - # to = t_time.end_of_day.utc - # end - # else - # from = day_ref.beginning_of_day.utc - # to = day_ref.end_of_day.utc - # end - # end - # else - # ### => search by Today or yesterday - # unless shift_name.nil? - # if shift_name.to_s == '0' - # ### => all shift - # case period.to_i - # when PERIOD["today"] - - # from = day_ref.beginning_of_day.utc - # to = day_ref.end_of_day.utc - - # when PERIOD["yesterday"] - # from = (day_ref - 1.day).beginning_of_day.utc - # to = (day_ref - 1.day).end_of_day.utc - - # when PERIOD["this_week"] - # from = Time.now.beginning_of_week.utc - # to = Time.now.utc - # when PERIOD["last_week"] - # from = (day_ref - 7.day).beginning_of_week.utc - # to = (day_ref - 7.day).end_of_week.utc - # when PERIOD["last_7"] - # from = (day_ref - 7.day).utc - # to = Time.now.utc - # when PERIOD["this_month"] - # from = Time.now.beginning_of_month.utc - # to = Time.now.utc - # when PERIOD["last_month"] - # from = (day_ref - 1.month).beginning_of_month.utc - # to = (day_ref - 1.month).end_of_month.utc - # when PERIOD["last_30"] - # from = (day_ref - 30.day).utc - # to = Time.now.utc - # when PERIOD["this_year"] - # from = Time.now.beginning_of_year.utc - # to = Time.now.utc - # when PERIOD["last_year"] - # from = (day_ref - 1.year).beginning_of_year.utc - # to = (day_ref - 1.year).end_of_year.utc - - # end - - # else - # unless shift_from == '-' - # f_date = DateTime.parse(shift_from) - # # f_date = DateTime.strptime(shift_from, "%m/%d/%Y") - # #f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec) - # from = f_date - # else - # from = '' - # end - - # unless shift_to == '-' - # t_date = DateTime.parse(shift_to) - # # t_date = DateTime.strptime(shift_to, "%m/%d/%Y") - - # #t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec) - # to = t_date - # else - # to = '' - # end - # end - # else - # if params[:report_type].to_i != 0 - # r_type = params[:report_type].to_s - - # if r_type == 'shift_item' - - # case period.to_i - # when PERIOD["today"] - - # from = day_ref.beginning_of_day.utc - # to = day_ref.end_of_day.utc - - # when PERIOD["yesterday"] - # from = (day_ref - 1.day).beginning_of_day.utc - # to = (day_ref - 1.day).end_of_day.utc - - # when PERIOD["this_week"] - # from = Time.now.beginning_of_week.utc - # to = Time.now.utc - # when PERIOD["last_week"] - # from = (day_ref - 7.day).beginning_of_week.utc - # to = (day_ref - 7.day).end_of_week.utc - # when PERIOD["last_7"] - # from = (day_ref - 7.day).utc - # to = Time.now.utc - # when PERIOD["this_month"] - # from = Time.now.beginning_of_month.utc - # to = Time.now.utc - # when PERIOD["last_month"] - # from = (day_ref - 1.month).beginning_of_month.utc - # to = (day_ref - 1.month).end_of_month.utc - # when PERIOD["last_30"] - # from = (day_ref - 30.day).utc - # to = Time.now.utc - # when PERIOD["this_year"] - # from = Time.now.beginning_of_year.utc - # to = Time.now.utc - # when PERIOD["last_year"] - # from = (day_ref - 1.year).beginning_of_year.utc - # to = (day_ref - 1.year).end_of_year.utc - - # end - # end - # else - # ### => report not shift - # case period.to_i - # when PERIOD["today"] - # from = day_ref.beginning_of_day.utc - # to = day_ref.end_of_day.utc - - # when PERIOD["yesterday"] - # from = (day_ref - 1.day).beginning_of_day.utc - # to = (day_ref - 1.day).end_of_day.utc - - # when PERIOD["this_week"] - # from = Time.now.beginning_of_week.utc - # to = Time.now.utc - # when PERIOD["last_week"] - # from = (day_ref - 7.day).beginning_of_week.utc - # to = (day_ref - 7.day).end_of_week.utc - # when PERIOD["last_7"] - # from = (day_ref - 7.day).utc - # to = Time.now.utc - # when PERIOD["this_month"] - # from = Time.now.beginning_of_month.utc - # to = Time.now.utc - # when PERIOD["last_month"] - # from = (day_ref - 1.month).beginning_of_month.utc - # to = (day_ref - 1.month).end_of_month.utc - # when PERIOD["last_30"] - # from = (day_ref - 30.day).utc - # to = Time.now.utc - # when PERIOD["this_year"] - # from = Time.now.beginning_of_year.utc - # to = Time.now.utc - # when PERIOD["last_year"] - # from = (day_ref - 1.year).beginning_of_year.utc - # to = (day_ref - 1.year).end_of_year.utc - # end - # end - # end - - - - # end - - # return from, to,report_type - # end - + end diff --git a/app/models/sale.rb b/app/models/sale.rb index 8fa54a7c..4e47f6cd 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -602,14 +602,15 @@ def self.get_shift_sales_by_receipt_no(shift_sale_range,shift,from,to,payment_ty payment_type = " and sale_payments.payment_method = '#{payment_type}'" end end + puts payment_type + query = Sale.all if shift.present? - query = query.where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed' and sales.total_amount != 0", shift.to_a) + query = query.where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed' and sale_payments.payment_amount != 0", shift.to_a) .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") .group("sales.sale_id") - else - query = query .where("sale_status=? #{payment_type} and sales.shift_sale_id in (?)","completed",shift_sale_range.to_a) + query = query .where("sale_status='completed' #{payment_type} and sale_payments.payment_amount != 0 and sales.shift_sale_id in (?)",shift_sale_range.to_a) .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") .group("sales.sale_id") end diff --git a/app/views/reports/saleitem/index.xls.erb b/app/views/reports/saleitem/index.xls.erb index 3773619b..dfdd77dc 100644 --- a/app/views/reports/saleitem/index.xls.erb +++ b/app/views/reports/saleitem/index.xls.erb @@ -1,104 +1,150 @@ - - - - - - - -
-<% unless @sale_data.blank? %> +
+
+
+ - - +
+ - <% if !params[:from].blank?%> - - + <% if !params[:from].blank?%> + + + + <% end %> + <% if @shift_from %> + + <% if @shift_data.employee %> + <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> + <% end %> + + + <% end %> + + + + + + + + + + + + <% unless @sale_data.blank? %> + <% acc_arr = Array.new %> + <% cate_arr = Array.new %> + + <% sub_total = 0.0 %> + <% count = 0%> + <% total_price = 0.0 %> + <% cate_count = 0 %> + <% acc_count = 0%> + <% grand_total = 0%> + <% total_qty = 0%> + <% total_amount = 0 %> + <% discount = 0%> + + <% @sale_data.each do |sale| %> + <% total_qty += sale.total_item %> + + <% if !acc_arr.include?(sale.account_id) %> + + + + + + + <% acc_arr.push(sale.account_id) %> + + <% end %> + + + <% if !cate_arr.include?(sale.menu_category_id) %> + + <% cate_arr.push(sale.menu_category_id) %> + <% else %> + + <% end %> + + + + + + + + + + <% @menu_cate_count.each do |key,value| %> + <% if sale.menu_category_id == key %> + + <% count = count + 1 %> + <% sub_total += sale.grand_total %> + <% if count == value %> + + + + + + + <% sub_total = 0.0%> + <% count = 0%> + <% end %> + <% end %> + <% end %> + + + + <% end %> + + + + + + + + + <% end %> + + + + + - <% end %> - <% if @shift_from %> - <% if @shift_data.employee %> - <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> - <% end %> - - - <% end %> - - - - - - - - - - - - - <% acc_arr = Array.new %> - <% cate_arr = Array.new %> - - <% sub_total = 0.0 %> - <% count = 0%> - <% total_price = 0.0 %> - <% cate_count = 0 %> - <% acc_count = 0%> - <% grand_total = 0%> - <% total_discount = 0.0 %> - - <% @sale_data.order("total_item desc").each do |sale| %> - - - - <% if !cate_arr.include?(sale.menu_category_id) %> - - <% cate_arr.push(sale.menu_category_id) %> - <% else %> - - <% end %> - - <% if @item_table == 'sale' %> - <% if sale.item_remark == 'FOC' %> - - <% elsif sale.item_remark == 'FOC ITEM' %> - - <% elsif sale.item_remark == 'DISCOUNT' %> - - <% else %> - - <% end %> - <% if sale.item_remark == 'DISCOUNT' %> - - - - <% total_price += sale.total_price %> - <% else %> - - - - <% end %> - <% else %> - - - - - <% end %> + + + - - - - - <% grand_total += sale.grand_total%> - <% end %> + + + + + + + + + + + + + + + - + + - +
From Date : <%= params[:from] %> , To Date : <%= params[:to] %>
From Date : <%= params[:from] %> , To Date : <%= params[:to] %>
Shift Name = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
 Menu CategoryCodeProductTotal ItemUnit PriceRevenue
<%= sale.account_name %> Total Price By <%= sale.account_name %> + <% @totalByAccount.each do |account, total| %> + <% if sale.account_id == account %> + <%= total %> + <% grand_total += total %> + <% end %> + <% end %> +
 <%= sale.menu_category_name %> <%= sale.item_code rescue '-' %><%= sale.product_name rescue '-' %><%= sale.total_item rescue '-' %><%= sale.unit_price rescue '-' %><%= sale.grand_total rescue '-' %>
 Sub Total<%= sub_total %>
 Total Item<%= total_qty%>Total Amount<%= grand_total%>
 Cash Received<%= @cash_data - @change_amount %>
Shift Name = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
 Menu CategoryCodeProductTotal ItemUnit PriceRevenue
 <%= sale.menu_category_name %> <%= sale.code rescue '-' %><%= '[PROMO] '.to_s + sale.product_name.to_s rescue '-' %><%= '[DIS:QTY] '.to_s + sale.product_name.to_s rescue '-' %><%= '[DIS:TP] '.to_s + sale.product_name.to_s rescue '-' %><%= sale.product_name.to_s rescue '-' %> - - <%= sale.total_price.abs rescue '-' %><%= sale.total_item.abs rescue '-' %><%= sale.unit_price rescue '-' %><%= sale.grand_total.abs rescue '-' %><%= sale.product_name.to_s rescue '-' %><%= sale.total_item.abs rescue '-' %><%= sale.unit_price rescue '-' %><%= sale.grand_total.abs rescue '-' %> Card Sales<%= @card_data %>
 Credit Sales<%= @credit_data %>
 FOC Sales<%= @foc_data %>
 Discount Amount<%= @discount_data %>
  Grand Total<%= grand_total + total_discount %><%= @grand_total - @change_amount%>
-<% end %>
- - \ No newline at end of file +
+