From e443c5431ec87edd7c6abe1fed68210d92ba3091 Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Mon, 19 Aug 2019 10:45:50 +0630 Subject: [PATCH 1/2] hourly sale items report --- .../reports/hourly_saleitem_controller.bk.rb | 200 +++++++++ .../reports/hourly_saleitem_controller.rb | 12 +- app/models/sale.rb | 140 ++++++- app/views/layouts/_left_sidebar.html.erb | 3 + .../_shift_sale_report_filter.html.erb | 4 +- .../reports/hourly_saleitem/index.bk.html.erb | 121 ++++++ .../reports/hourly_saleitem/index.html.erb | 229 ++++++++-- .../reports/hourly_saleitem/index.xls.erb | 394 ++++++------------ 8 files changed, 801 insertions(+), 302 deletions(-) create mode 100644 app/controllers/reports/hourly_saleitem_controller.bk.rb create mode 100644 app/views/reports/hourly_saleitem/index.bk.html.erb diff --git a/app/controllers/reports/hourly_saleitem_controller.bk.rb b/app/controllers/reports/hourly_saleitem_controller.bk.rb new file mode 100644 index 00000000..88a61335 --- /dev/null +++ b/app/controllers/reports/hourly_saleitem_controller.bk.rb @@ -0,0 +1,200 @@ +class Reports::HourlySaleitemController < BaseReportController + authorize_resource :class => false + def index + + @account = Account.all + from, to = get_date_range_from_params + + shift_sale_range = '' + + shift = '' + if params[:shift_name].to_i != 0 + + shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) + + shift_sale = ShiftSale.find(params[:shift_name]) + if to.blank? + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) + else + if shift_sale.shift_closed_at.blank? + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL',shift_sale.shift_started_at) + else + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) + end + end + end + + account_type = params[:account_type] + @type = params[:sale_type] + @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type) + logger.debug 'product>>>>>>>>>>>>>>>>>>>>>>>>>>' + # logger.debug @sale_data.group_by {|s| s.date_format }.collect{|key,qty| {"Date" =>key , "total_qty" => qty.sum{|d| d.qty.to_i}}} + + @hourly_total_qty = @sale_data.group_by {|s| s.date_format }.collect{|key,qty| {"date" => key , "total_qty" => qty.sum{|d| d.qty.to_i}}} + logger.debug @hourly_total_qty + + @sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil) + + @account_cate_count = Hash.new {|hash, key| hash[key] = 0} + @sale_data.each {|acc_cate| @account_cate_count[acc_cate.account_id] += 1} + + + @menu_cate_count = Hash.new {|hash, key| hash[key] = 0} + @sale_data.each {|cate| @menu_cate_count[cate.account_id] += 1} + + + @totalByAccount = Hash.new {|hash, key| hash[key] = 0} + @sale_data.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total} + + @from = from + @to = to + + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() + + if shift.present? + shift.each do |sh| + @shift_from = sh.shift_started_at.nil? ? '-' : sh.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_to = sh.shift_closed_at.nil? ? '-' : sh.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_data = sh + end + end + + respond_to do |format| + format.html + format.xls + end + end + + def show + from, to, report_type = get_date_range_from_params + @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) + sale_data = @sale_data + date_arr = Array.new + @sale_data.each do |sale| + local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p") + local_closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc.getlocal.strftime("%e %b %I:%M%p") + opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc + closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc + shift_id = sale.id.nil? ? '-' : sale.id + str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date} + date_arr.push(str) + logger.debug 'show date arr####################' + logger.debug date_arr + end + + # @totalByAccount = Hash.new {|hash, key| hash[key] = 0} + # @sale_data.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total} + + out = {:status => 'ok', :message => date_arr} + + respond_to do |format| + format.json { render json: out } + end + end + + def print_sale_items + from, to = get_date_range_from_params + + shift_sale_range = '' + + shift = '' + shift_name = 'All Shift' + if params[:shift_name].to_i != 0 + + shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) + + shift_sale = ShiftSale.find(params[:shift_name]) + if to.blank? + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) + else + if shift_sale.shift_closed_at.blank? + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL',shift_sale.shift_started_at) + else + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) + end + end + + sh_name = "#{shift_sale.shift_started_at.utc.getlocal.strftime('%d %B %l:%M%p')} - #{shift_sale.shift_closed_at.utc.getlocal.strftime('%d %B %l:%M%p')}" + employee = Employee.find(shift_sale.employee_id) + shift_name = employee.nil? ? sh_name : "#{sh_name} (#{employee.name})" + end + + shop_details = shop_detail + account_type = params[:account_type] + @type = params[:period_type] + period_name = get_period_name(params[:period]) + + @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type) + other_charges = Sale.get_other_charges() + if shift.present? + @total_other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) + else + @total_other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) + end + + # get printer info + print_settings = PrintSetting.find_by_unique_code('SaleItemsPdf') # SaleItemsPdf + print_settings_star = PrintSetting.find_by_unique_code('SaleItemsStarPdf') + + # if print_settings.nil? && print_settings_star.nil? + # @print_setting = PrintSetting.new(name: "SaleItemsPdf", unique_code: "SaleItemsPdf", template: "",font: "Zawgyi-One", header_font_size: "10", item_font_size: "8", printer_name: "", api_settings: "", brand_name: nil, printer_type: nil, page_width: "210", page_height: "1450", print_copies: "1", precision: "0", delimiter: "0", heading_space: "5" ) + # @print_setting.save + # end + + if print_settings.nil? + if !print_settings_star.nil? + printer = Printer::CashierStationPrinter.new(print_settings_star) + printer.print_sale_items_report(print_settings_star, shop_details, period_name, @type, account_type, from, to, shift_name, @sale_data, @total_other_charges) + end + else + printer = Printer::CashierStationPrinter.new(print_settings) + printer.print_sale_items_report(print_settings, shop_details, period_name, @type, account_type, from, to, shift_name, @sale_data, @total_other_charges) + end + + respond_to do |format| + format.html { redirect_to '/en/reports/saleitem/', notice: 'Printing Completed.'} + format + end + end + + def get_period_name(period) + period_name = '-' + unless period.nil? or period.blank? + case period.to_i + when PERIOD["today"] + period_name = "Today" + + when PERIOD["yesterday"] + period_name = "Yesterday" + + when PERIOD["this_week"] + period_name = "This Week" + + when PERIOD["last_week"] + period_name = "Last Week" + + when PERIOD["last_7"] + period_name = "Last 7 days" + + when PERIOD["this_month"] + period_name = "This Month" + + when PERIOD["last_month"] + period_name = "Last Month" + + when PERIOD["last_30"] + period_name = "Last 30 Days" + + when PERIOD["this_year"] + period_name = "This Year" + + when PERIOD["last_year"] + period_name = "Last Year" + + end + end + return period_name + end + +end diff --git a/app/controllers/reports/hourly_saleitem_controller.rb b/app/controllers/reports/hourly_saleitem_controller.rb index 68883c68..019af7a1 100644 --- a/app/controllers/reports/hourly_saleitem_controller.rb +++ b/app/controllers/reports/hourly_saleitem_controller.rb @@ -26,9 +26,9 @@ class Reports::HourlySaleitemController < BaseReportController account_type = params[:account_type] @type = params[:sale_type] - @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type) - logger.debug 'product>>>>>>>>>>>>>>>>>>>>>>>>>>' - logger.debug @sale_data.group(:date_format) + @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_hourly_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type) + # logger.debug 'product>>>>>>>>>>>>>>>>>>>>>>>>>>' + # logger.debug @sale_data.group(:date_format) @sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil) @@ -56,6 +56,8 @@ class Reports::HourlySaleitemController < BaseReportController @shift_data = sh end end + # @hourly_total_qty = @sale_data.group_by {|s| s.date_format }.collect{|key,qty| {"date" => key , "total_qty" => qty.sum{|d| d.qty.to_i}}} + @hourly_total_qty = @sale_data.group_by(&:date_format).map { |k,v|{"date" => k , "total_qty" => v.count }} respond_to do |format| format.html @@ -76,8 +78,6 @@ class Reports::HourlySaleitemController < BaseReportController shift_id = sale.id.nil? ? '-' : sale.id str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date} date_arr.push(str) - logger.debug 'show date arr####################' - logger.debug date_arr end # @totalByAccount = Hash.new {|hash, key| hash[key] = 0} @@ -122,7 +122,7 @@ class Reports::HourlySaleitemController < BaseReportController @type = params[:period_type] period_name = get_period_name(params[:period]) - @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type) + @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_hourly_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type) other_charges = Sale.get_other_charges() if shift.present? @total_other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) diff --git a/app/models/sale.rb b/app/models/sale.rb index acbb25b7..ed469667 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1184,8 +1184,6 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou else query = query.where("sales.receipt_date between ? and ? #{account_type} and sale_status='completed'",from,to) - logger.debug 'get_by_shift_items??????????????????????????????????????' - logger.debug query.to_json if type.nil? || type == 'all' || type == "other" other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) end @@ -2785,8 +2783,6 @@ def self.hourly_sale_data(today,shift=nil,from=nil,to=nil,from_time=nil,to_time= end query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')") .order('receipt_date') - logger.debug 'sales data>>>>>>>>>>>>>>>>>>>>>>>' - logger.debug query.to_json end return query @@ -2816,6 +2812,142 @@ def self.employee_sale(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil return query end +# Start hourly sale item report +def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,account_type) + # date_type_selection = get_sql_function_for_report_type(report_type) + if account_type.blank? + account_type = '' + else + account_type = " and acc.title = '#{account_type}'" + end + + query = self.get_hourly_item_query(type) + + discount_query = 0 + total_card_amount = 0 + total_cash_amount = 0 + total_credit_amount = 0 + total_foc_amount = 0 + total_grand_total = 0 + + if type.nil? || type == 'all' || type == "other" + other_charges = self.get_other_charges() + end + product = self.get_product_sale() + + if shift.present? + query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift.to_a) + if type.nil? || type == 'all' || type == "other" + other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) + end + product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) + discount_query = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount) + change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed) + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, + 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 sale_payments on sale_payments.sale_id = sales.sale_id") + .where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.to_a) + sale_cash.each do |s_c| + total_cash_amount += s_c.cash_amount.to_f + total_card_amount += s_c.card_amount.to_f + total_credit_amount += s_c.credit_amount.to_f + total_foc_amount += s_c.foc_amount.to_f + end + total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f + + ### => get all sales range in shift_sales + elsif shift_sale_range.present? + query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift_sale_range.to_a) + if type.nil? || type == 'all' || type == "other" + other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) + end + product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) + discount_query = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount) + change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed) + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, + 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 sale_payments on sale_payments.sale_id = sales.sale_id") + .where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift_sale_range.to_a) + sale_cash.each do |s_c| + total_cash_amount += s_c.cash_amount.to_f + total_card_amount += s_c.card_amount.to_f + total_credit_amount += s_c.credit_amount.to_f + total_foc_amount += s_c.foc_amount.to_f + end + + total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f + + else + query = query.where("sales.receipt_date between ? and ? #{account_type} and sale_status='completed'",from,to) + if type.nil? || type == 'all' || type == "other" + other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) + end + product = product.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) + + discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount) + change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed) + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, + 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 sale_payments on sale_payments.sale_id = sales.sale_id") + .where("sales.receipt_date between ? and ? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", from,to) + sale_cash.each do |s_c| + total_cash_amount += s_c.cash_amount.to_f + total_card_amount += s_c.card_amount.to_f + total_credit_amount += s_c.credit_amount.to_f + total_foc_amount += s_c.foc_amount.to_f + end + total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f + + end + + return query,other_charges, product, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount +end + +def self.get_hourly_item_query(type) + check_product = "i.menu_category_name != 'product'" + if type == "revenue" + sale_type = "i.qty > 0 and status IS NULL" + elsif type == "all" || type.nil? + sale_type = "#{check_product}" + elsif type == "discount" + sale_type = "#{check_product} and i.status = 'Discount'" + elsif type == "foc" + sale_type = "#{check_product} and i.status = 'foc' and i.item_instance_code IS NOT NULL and i.qty > 0" + elsif type == "void" + sale_type = "#{check_product} and i.status = 'void' and i.item_instance_code IS NOT NULL and i.qty > 0" + elsif type == "other" + sale_type = "#{check_product} and i.item_instance_code IS NULL" + elsif type == "promotion" + sale_type = "#{check_product} and i.status = 'promotion'" + end + query = Sale.select("sales.sale_id,acc.title as account_name, + i.item_instance_code as item_code,i.account_id as account_id, " + + "SUM(i.qty * i.unit_price) as grand_total, + SUM(i.qty) as total_item,i.qty as qty," + + "i.status as status_type,i.remark as remark,"+ + "i.unit_price,i.price as price,i.product_name as product_name, " + + "i.menu_category_name,i.menu_category_code as menu_category_id, " + + "date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p') + as date_format") + + query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id" + + " JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id") + # "JOIN employee_accesses ea ON ea.`employee_id` = sales.cashier_id ") + query = query.joins(" JOIN accounts acc ON acc.id = i.account_id") + query = query.where("#{sale_type}") + query = query.group("acc.title,i.account_id,i.menu_category_code,i.item_instance_code,i.product_name,i.unit_price") + .order("date_format asc") + # query = query.order("i.menu_category_name asc, SUM(i.qty) desc") +end + +# End hourly sale item report + private def generate_custom_id diff --git a/app/views/layouts/_left_sidebar.html.erb b/app/views/layouts/_left_sidebar.html.erb index d9f12423..4fee71b1 100644 --- a/app/views/layouts/_left_sidebar.html.erb +++ b/app/views/layouts/_left_sidebar.html.erb @@ -285,6 +285,9 @@
  • Sale Items +
  • +
  • + Hourly Sale Items
  • Product Sale diff --git a/app/views/reports/hourly_saleitem/_shift_sale_report_filter.html.erb b/app/views/reports/hourly_saleitem/_shift_sale_report_filter.html.erb index fab1ad38..4ca6ccf9 100644 --- a/app/views/reports/hourly_saleitem/_shift_sale_report_filter.html.erb +++ b/app/views/reports/hourly_saleitem/_shift_sale_report_filter.html.erb @@ -32,7 +32,7 @@ -
    +
    diff --git a/app/views/reports/hourly_saleitem/index.bk.html.erb b/app/views/reports/hourly_saleitem/index.bk.html.erb new file mode 100644 index 00000000..5992d5cd --- /dev/null +++ b/app/views/reports/hourly_saleitem/index.bk.html.erb @@ -0,0 +1,121 @@ +
    + +
    +
    + <%= render :partial=>'shift_sale_report_filter', + :locals=>{ :period_type => true, :shift_name => true,:payments => true, :report_path =>reports_waste_and_spoilage_index_path} %> +
    + +
    +
    + + + <% time_arr = Array.new %> + <% menu_cat_arr = Array.new %> + <% footer_arr = Array.new %> + <% count = 0 %> + <% waste_and_spoil_item_count = 0%> + <% total_qty = 0 %> + <% time_count = 0 %> + <% @sale_data.each do |sale| %> + <% if !time_arr.include?(sale.date_format) %> + <% time_count = time_count + 1 %> + + + + + + + + + + + + + + + + + + <% time_arr.push(sale.date_format) %> + <% menu_cat_arr.clear %> + <% count = 0 %> + <% end %> + + + <% if sale.status_type != "Discount" && sale.status_type != "foc" && sale.status_type != "promotion" + total_qty += sale.total_item + end %> + <% if sale.status_type == "foc" && sale.price > 0 + total_qty += sale.total_item + end %> + <% if sale.status_type == "Discount" + total_qty += sale.total_item*(-1) + end %> + <% if sale.status_type =="promotion" && @type == "promotion" + total_qty += sale.total_item*(-1) + end %> + + <% if !sale.item_code.nil?%> + <% waste_and_spoil_item_count += sale.qty.to_i %> + + <% if !menu_cat_arr.include?(sale.menu_category_name) %> + + <% menu_cat_arr.push(sale.menu_category_name) %> + <% else %> + + <% end %> + + + + + + + + <% end %> + + + + + <% @hourly_total_qty.each do |qty| %> + <% qty_count = qty["total_qty"] %> + <% logger.debug ' qty count+++++++++++++++++++++++++' %> + <% logger.debug qty_count %> + <% #logger.debug ' normal count+++++++++++++++++++++++++' %> + <% #logger.debug sale.sale_items.count %> + <% end %> + + <% count = count + 1 %> + <% logger.debug 'count ------------------------------------' %> + <% logger.debug count %> + <% if sale.sale_items.count == count %> + + + + + + + + <% footer_arr.push(sale.sale_id) %> + <% end %> + + <% end %> + +
     
    + Time :<%= sale.date_format %> + Date :
    Menu CategoryItem CodeItem NameQtyPriceTotal Price
    <%= sale.menu_category_name %> <%= sale.item_code %><%= sale.product_name %><%= sale.total_item.to_i %><%= sale.unit_price %><%= sale.price %><%= sale.date_format %>
     Total Qty:<%= total_qty%>Grand Total:
    +
    +
    +
    +
    +
    diff --git a/app/views/reports/hourly_saleitem/index.html.erb b/app/views/reports/hourly_saleitem/index.html.erb index f5491203..a51ebe98 100644 --- a/app/views/reports/hourly_saleitem/index.html.erb +++ b/app/views/reports/hourly_saleitem/index.html.erb @@ -2,7 +2,7 @@ + + diff --git a/app/views/reports/hourly_saleitem/index.xls.erb b/app/views/reports/hourly_saleitem/index.xls.erb index 8f326e27..df37f29e 100644 --- a/app/views/reports/hourly_saleitem/index.xls.erb +++ b/app/views/reports/hourly_saleitem/index.xls.erb @@ -9,274 +9,138 @@
    -
    - - - - - - <% if @shift_from %> - - <% if @shift_data.employee %> - <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> - <% end %> - - - <% end %> - - - - - - - - - - - - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %> - <% acc_arr = Array.new %> - <% cate_arr = Array.new %> - <% p_qty = 0 %> - <% sub_qty = 0 %> - <% sub_total = 0 %> - <% other_sub_total = 0 %> - <% product_sub_total = 0 %> - <% count = 0 %> - <% total_price = 0 %> - <% cate_count = 0 %> - <% acc_count = 0 %> - <% grand_total = 0 %> - <% total_qty = 0 %> - <% total_amount = 0 %> - <% discount = 0 %> - <% total_item_foc = 0 %> - <% total_item_dis = 0.0 %> - <% total_tax = 0 %> - <% unless @sale_data.blank? %> - <% @sale_data.each do |sale| %> - - - <% if sale.status_type != "Discount" && sale.status_type != "foc" && sale.status_type != "promotion" - total_qty += sale.total_item - end %> - <% if sale.status_type == "foc" && sale.price > 0 - total_qty += sale.total_item - end %> - <% if sale.status_type == "Discount" - total_qty += sale.total_item*(-1) - end %> - <% if sale.remark =="promotion" - total_qty += sale.total_item - end %> - - - <% if sale.status_type == "foc" && sale.grand_total < 0 - total_item_foc += sale.grand_total*(-1) - end %> +
    +
    +
    - <% if sale.status_type == "Discount" && sale.grand_total < 0 - total_item_dis += sale.grand_total*(-1) - end %> - - <% 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 %> - - - <% if sale.status_type != "Discount" %> - - <%else%> - - <% end %> - - - - - +
    <%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%>
    <%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
     <%= t("views.right_panel.header.menu_category") %><%= t("views.right_panel.detail.code") %><%= t("views.right_panel.detail.product") %><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= t("views.right_panel.detail.unit_price") %><%= t("views.right_panel.detail.revenue") %>
    <%= sale.account_name %> <%= t("views.right_panel.detail.total_price_by") %> <%= sale.account_name %> - <% @totalByAccount.each do |account, total| %> - <% if sale.account_id == account %> - <%= number_with_precision(total, precision:precision.to_i,delimiter:delimiter) %> - <% grand_total += total %> - <% end %> - <% end %> -
     <%= sale.menu_category_name %> <%= sale.item_code rescue '-' %><%= sale.product_name rescue '-' %><%= sale.total_item rescue '-' %><%= sale.total_item*(-1) rescue '-' %><%= number_with_precision(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_with_precision(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
    + <% time_arr = Array.new %> + <% acc_arr = Array.new %> + <% sale_item_count =0 %> + <% menu_cat_arr = Array.new %> + <% footer_arr = Array.new %> + <% count = 0 %> + <% waste_and_spoil_item_count = 0%> + <% total_qty = 0 %> + <% time_count = 0 %> + <% grand_total = 0 %> + <% @sale_data.each do |sale| %> + <% if !time_arr.include?(sale.date_format) %> + <% sale_item_count =1 %> + <% time_count = time_count + 1 %> + + + + + + + + + + + + + + + + + + <% time_arr.push(sale.date_format) %> + <% menu_cat_arr.clear %> + <% count = 0 %> + <% else %> + <% sale_item_count =sale_item_count +1 %> + <% end %> + + <% if @print_settings.precision.to_i > 0 + precision = @print_settings.precision + else + precision = 0 + end + #check delimiter + if @print_settings.delimiter + delimiter = "," + else + delimiter = "" + end + %> + + <% if sale.status_type != "Discount" && sale.status_type != "foc" && sale.status_type != "promotion" + total_qty += sale.total_item + end %> + <% if sale.status_type == "foc" && sale.price > 0 + total_qty += sale.total_item + end %> + <% if sale.status_type == "Discount" + total_qty += sale.total_item*(-1) + end %> + <% if sale.status_type =="promotion" && @type == "promotion" + total_qty += sale.total_item*(-1) + end %> - <% @menu_cate_count.each do |key,value| %> - <% if sale.account_id == key %> - <% count = count + 1 %> - <% sub_total += sale.grand_total %> - <% #sub_qty += sale.total_item %> - <% if sale.status_type !="Discount" && (!sale.product_name.include? "FOC") && sale.status_type != "promotion" - sub_qty += sale.total_item - end %> - <% if sale.status_type =="Discount" - sub_qty += sale.total_item*(-1) - end %> + + <% if sale.status_type == "foc" && sale.grand_total < 0 + grand_total += sale.grand_total*(-1) + end %> - <% if sale.remark == "promotion" - sub_qty += sale.total_item - end %> - <% if count == value %> - - - - - - - - <% sub_total = 0.0%> - <% sub_qty = 0 %> - <% count = 0%> - <% end %> - <% end %> - <% end %> - - <% end %> - - <% if @product.present?%> - - - - - - - <% @product.each do |product| %> - <% if product.total_item > 0 - total_qty += product.total_item - end %> - <% grand_total +=product.grand_total - p_qty += product.total_item%> - - - - - - - - - - - - <% product_sub_total += product.grand_total %> - - <% end %> - - - - + <% if sale.status_type == "Discount" && sale.grand_total < 0 + grand_total += sale.grand_total*(-1) + end %> - - - - <%end%> - + <% if sale.status_type == "promotion" && sale.grand_total < 0 + grand_total += sale.grand_total*(-1) + end %> - - <% if @type == "other" || @other_charges.present?%> - - - - - - - <% @other_charges.each do |other| %> - <% if other.total_item > 0 - total_qty += other.total_item - end %> - <% grand_total +=other.grand_total%> - - - - - - - - - - - - <% other_sub_total += other.grand_total %> - - <% end %> - - - - - - <%end%> - - - - - - - - - <% end %> - <% if @type == "other"%> - - - - - - - <% @other_charges.each do |other| %> - <% if other.total_item > 0 - total_qty += other.total_item - end %> - <% grand_total +=other.grand_total%> - - - - - - - - - - - - <% other_sub_total += other.grand_total %> - - <% end %> - - - - - - <%end%> - -
     
    + Time :<%= sale.date_format %> +
    Menu CategoryItem CodeItem NameQtyPriceTotal Price
     Total <%= sale.account_name %> Qty <%= sub_qty %><%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(sub_total , precision:precision.to_i,delimiter:delimiter)%>
    Product 
     Product<%= product.product_code rescue '-' %><%= product.product_name rescue '-' %><%= product.total_item rescue '-' %> <%= number_with_precision(product.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(product.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
     Total Product Qty <%= p_qty %><%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(product_sub_total , precision:precision.to_i,delimiter:delimiter)%>
    Other Charges 
     Other Charges<%= other.item_code rescue '-' %><%= other.product_name rescue '-' %><%= other.total_item rescue '-' %> <%= number_with_precision(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
     <%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(other_sub_total , precision:precision.to_i,delimiter:delimiter)%>
     <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= total_qty%><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter)%>
    Other Charges 
     Other Charges<%= other.item_code rescue '-' %><%= other.product_name rescue '-' %><%= other.total_item rescue '-' %> <%= number_with_precision(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
     <%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(other_sub_total , precision:precision.to_i,delimiter:delimiter)%>
    -
    -
    -
    -
    -
    + <% grand_total += sale.grand_total %> + + <% if !sale.item_code.nil?%> + <% waste_and_spoil_item_count += sale.qty.to_i %> + + <% if !menu_cat_arr.include?(sale.menu_category_name) %> + <%= sale.menu_category_name %> + <% menu_cat_arr.push(sale.menu_category_name) %> + <% else %> +   + <% end %> + <%= sale.item_code %> + <%= sale.product_name %> + <%= sale.total_item.to_i %> + <%= sale.unit_price.to_i %> + <%= sale.grand_total.to_i %> + <%= sale.date_format %> + + <% end %> + + <% count = count + 1 %> + <% @hourly_total_qty.each do |hr| %> + <% if hr["date"].to_s == sale.date_format.to_s && hr["total_qty"].to_i ==sale_item_count%> + + + Total Qty: + + + <%= total_qty.to_i %> + <% total_qty = 0%> + + Grand Total: + + + <%= grand_total.to_i %> + <% grand_total = 0 %> + + + + <% footer_arr.push(sale.sale_id) %> + <% else %> + <% end %> + <% end %> + + <% end %> + +
    + + - \ No newline at end of file + From 919e6f61b3fc5e0913aa9d471b173b6fccba18ac Mon Sep 17 00:00:00 2001 From: Git Code2lab Date: Wed, 28 Aug 2019 11:57:33 +0000 Subject: [PATCH 2/2] Update puma.rb --- config/puma.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/puma.rb b/config/puma.rb index fd89392f..dcc85b12 100755 --- a/config/puma.rb +++ b/config/puma.rb @@ -8,3 +8,4 @@ stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/ port ENV.fetch("PORT") { 62158 } workers 2 preload_app! +threads 1,1 \ No newline at end of file