update report

This commit is contained in:
Aung Myo
2017-07-10 14:32:57 +06:30
parent 292c8ff563
commit b1b9b5a93f
10 changed files with 1097 additions and 154 deletions

View File

@@ -0,0 +1,19 @@
class Reports::SaleitemController < BaseReportController
authorize_resource :class => false
def index
from, to, report_type = get_date_range_from_params
@sale_data = Sale.get_by_range_by_saleitems(from,to,Sale::SALE_STATUS_COMPLETED,report_type)
respond_to do |format|
format.html
format.xls
end
end
def show
end
end

View File

@@ -5,9 +5,7 @@ class Reports::DailysaleController < BaseReportController
from, to ,report_type = get_date_range_from_params
@sale_data = Sale.daily_sales_list(from,to)
@tax = SaleTax.get_tax(from,to)
puts from
puts to
puts "sssssssss"
respond_to do |format|
format.html
format.xls

View File

@@ -2,16 +2,6 @@ class Reports::ReceiptNoController < BaseReportController
authorize_resource :class => false
def index
from, to, report_type = get_date_range_from_params
# if to.blank?
# @shift = ShiftSale.where('shift_started_at <= ? and shift_closed_at is NULL',from).take
# else
# @shift = ShiftSale.where("(shift_started_at between ? and ? OR shift_closed_at between ? and ? )", from, to, from, to).take
# end
# puts "2017-07-07T10:46:09.000Z - 2017-07-07T11:12:51.000Z"
# puts "2017-06-25 17:30:00 UTC 2017-07-02 17:29:59 UTC"
# puts params[:shift_name]
# puts from.utc
# puts to.utc
if params[:shift_name].to_i != 0
@shift = ShiftSale.where('shift_started_at >= ? and shift_closed_at <= ?',from,to).take
@@ -40,29 +30,23 @@ authorize_resource :class => false
def show
from, to, report_type = get_date_range_from_params
@sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED)
puts "hhhhhhhhhhhhhhhhhhhhh"
puts @sale_data.to_json
puts from
puts to
puts report_type
puts params[:shift_name]
@sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED)
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
str = { :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date}
date_arr.push(str)
end
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
str = { :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date}
date_arr.push(str)
end
out = {:status => 'ok', :message => date_arr}
respond_to do |format|
format.json { render json: out }
end
out = {:status => 'ok', :message => date_arr}
respond_to do |format|
format.json { render json: out }
end
end

View File

@@ -2,9 +2,38 @@ class Reports::SaleitemController < BaseReportController
authorize_resource :class => false
def index
from, to, report_type = get_date_range_from_params
from, to, report_type = get_date_range_from_params
shift_sale_range = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED)
@sale_data = Sale.get_by_range_by_saleitems(from,to,Sale::SALE_STATUS_COMPLETED,report_type)
shift = ''
if to.blank?
shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',from)
else
shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',from, to)
end
@sale_data, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED, report_type)
@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.menu_category_id] += 1}
@totalByAccount = Hash.new {|hash, key| hash[key] = 0}
@sale_data.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total}
if !shift.nil?
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
@@ -13,7 +42,246 @@ class Reports::SaleitemController < BaseReportController
end
def show
from, to, report_type = get_date_range_from_params
@sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED)
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
str = { :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date}
date_arr.push(str)
end
out = {:status => 'ok', :message => date_arr}
respond_to do |format|
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

View File

@@ -534,25 +534,25 @@ end
# .joins("join shift_sales sh on sh.id = sales.shift_sale_id")
# .where('sales.sale_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"')
# cash = all_total.select('sr.payment_method')
# .where('sr.payment_method = "cash"')
# .sum(:amount)
# credit = all_total.where('sr.payment_type = "creditnote"')
# credit = all_total.where('sr.payment_method = "creditnote"')
# .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 = "creditnote"')
# .where('sr.payment_method = "creditnote"')
# .sum(:amout)
# foc = all_total.where('sales.payment_type = "foc" and sales.sale_status = "completed"')
# foc = all_total.where('sales.payment_method = "foc" and sales.sale_status = "completed"')
# .sum(:grand_total)
# card = all_total.select('payment_type')
# .where('sr.payment_type = "card"')
# card = all_total.select('payment_method')
# .where('sr.payment_method = "card"')
# .sum(:amount).to_f
# rounding_adj = all_total.sum(:rounding_adjustment)
@@ -586,10 +586,96 @@ def self.get_by_shift_sale(from,to,status)
return query = query.where("shift_sales.shift_started_at >= ?" + " AND shift_sales.shift_closed_at <= ?", from,to)
end
def self.get_separate_tax(from,to,payment_type=nil)
def self.get_item_query()
query = Sale.select("acc.title as account_name,mi.account_id, mi.item_code as item_code, " +
"(SUM(i.qty * i.unit_price)) as grand_total,SUM(i.qty) as total_item," +
" i.unit_price as unit_price,mi.name as product_name, mc.name as" +
" menu_category_name,mc.id as menu_category_id ")
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code" +
" JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id JOIN menu_categories mc ON mc.id = mi.menu_category_id ")
# "JOIN employee_accesses ea ON ea.`employee_id` = sales.cashier_id ")
query = query.joins(" JOIN accounts acc ON acc.id = mi.account_id")
query = query.group('i.product_code ').order("mi.account_id, mi.menu_category_id")
end
def self.get_by_shift_items(shift_sale_range, shift, from, to, status, report_type)
# date_type_selection = get_sql_function_for_report_type(report_type)
query = self.get_item_query()
discount_query = 0
total_card_amount = 0
total_cash_amount = 0
total_credit_amount = 0
total_foc_amount = 0
total_grand_total = 0
if shift == '[]'
### => get all sales range in shift_sales
query = query.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)
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') then (sale_ - sales.amount_changed) 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' ", 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
elsif shift_sale_range == '[]'
query = query.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)
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') 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' ", 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
else
query = query.where("receipt_date between ? and ? and sale_status=?",from,to,'completed')
sale_cash = Sale.select("sales.total_discount as total_discount,
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') 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' ", 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
discount_query = s_c.total_discount.to_f
end
total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
end
return query, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total
end
def self.get_separate_tax(from,to,payment_method=nil)
query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name")
.joins("INNER JOIN sales ON sales.id = sale_taxes.sale_id")
.joins("INNER JOIN sales ON sales.sale_id = sale_taxes.sale_id")
.group("sale_taxes.tax_name")
return query = query.where("sale_status=? and receipt_date between ? and ?","completed",from,to)

View File

@@ -0,0 +1,194 @@
<div class="row">
<div class="col-md-12">
<%= form_tag report_path, :method => :get, :id=>"frm_report", :class => "form" do %>
<% if period_type != false %>
<div class="row">
<div class="form-group col-md-2">
<label>Select Period</label>
<select name="period" id="sel_period" class="form-control">
<option value="0">Today</option>
<option value="1">Yesterday</option>
<option value="2">This week</option>
<option value="3">Last week</option>
<option value="4">Last 7 days</option>
<option value="5">This month</option>
<option value="6">Last month</option>
<option value="7">Last 30 days</option>
<option value="8">This year</option>
<option value="9">Last year</option>
</select>
</div>
<input type="hidden" name="report_type" value="sale_item" id="sel_sale_type">
<!-- <div class="form-group col-md-2">
<label>Select Type</label>
<select name="sale_type" id="sel_sale_type" class="form-control">
<option value="0">All Sale Type</option>
<option value="1">Revenue Only</option>
<option value="2">Discount Only</option>
<option value="3">Void Only</option>
<option value="4">Taxes Only</option>
<option value="5">Other Amount Only</option>
</select>
</div> -->
<div class="form-group col-md-3">
<!-- <label class="">Select Shift Period</label> -->
<label class="">From</label>
<input data-behaviour='datepicker' class="form-control" name="from" id="from" type="text" placeholder="From date">
</div>
<div class="form-group col-md-3">
<label class="">To</label>
<input data-behaviour='datepicker' class="form-control" name="to" id="to" type="text" placeholder="To date">
</div>
<div class="form-group col-md-2 margin-top-20">
<input type="submit" value="Generate Report" class='btn btn-primary'>
</div>
</div>
<% end %>
<!-- <div class="row">
<% if defined? show_monthly %>
<div class="span3" style="margin-bottom:10px;">
<input type="hidden" id="report_type" name="report_type" value="0">
<div class="btn-group" data-toggle="buttons-radio">
<button id="btn_report_type_1" onclick="$('#report_type').val(1)" type="button" class="btn btn-inverse">Monthly</button>
<button id="btn_report_type_2" onclick="$('#report_type').val(2)" type="button" class="btn btn-inverse">Yearly</button>
</div>
</div>
<% end %>
</div> -->
<div class="row">
<div class="form-group">
<% if defined? promotions %>
<%= select_tag "promotion", options_for_select(@promotions, :selected => params[:promotion_type]), :class => "form-control" %>
<% end %>
<% if defined? menu_types %>
<%= select_tag "menu_type", options_for_select(@menu_types, :selected => params[:menu_type]), :class => "form-control" %>
<% end %>
<% if defined? payments %>
<%= select_tag "payment_type", options_for_select(@payments, :selected => params[:payment_type]), :class => "form-control" %>
<% end %>
<% if defined? shift_name %>
<!-- Temporary no needs
<select name="shift_name" id="shift_name"></select>
-->
<% end %>
<% if defined? cashiers %>
<%= select_tag "cashier", options_from_collection_for_select(@cashiers,"id","name"),:prompt => "All Cashier Stations", :class => "form-control" %>
<% end %>
<% if defined? singer %>
<%= select_tag "singer", options_from_collection_for_select(singer,"id","name"),:prompt => "All Vocal List", :class => "form-control" %>
<% end %>
<% if defined? bsm %>
<%= select_tag "singer", options_from_collection_for_select(bsm,"id","name"),:prompt => "All BSM List", :class => "form-control" %>
<% end %>
<% if defined? guest_role %>
<%= select_tag "guest_role", options_from_collection_for_select(@guest_role,"id","name"),:prompt => "Vocal/BSM List", :class => "form-control" %>
<% end %>
<% if defined? list_by_payment_type %> <!-- for report detail by credit and foc -->
<%= select_tag "payment_type_list", options_for_select(@payment_list, :selected => params[:payment_type_list]), :class => "form-control" %>
<% end %>
<% if defined? products %>
<%= select_tag "product", options_from_collection_for_select(@products,"id","name"),:prompt => "All Products", :class => "form-control" %>
<% end %>
<% if defined? items %>
<%= select_tag "item", options_for_select(@items, :selected => params[:item_type]), :class => "form-control" %>
<% end %>
</div>
</div>
<!-- <div class="row">
<div class="col-md-12">
<input type="submit" value="Generate Report" class='btn btn-primary'>
</div>
</div> -->
<% end %>
</div>
</div>
<script type="text/javascript">
$(function(){
$('#custom_excel').hide();
$('#custom_excel').click(function(){
var url = $('#custom_excel').attr('data-url');
$('#frm_report').attr('action',url)
$('#frm_report').submit();
// window.location = url;
});
var item = $('#item').val();
var payment_type = $('#payment_type');
if(item == 'order'){
$('#cashier').hide();
$('#waiter').show();
if(payment_type){
$('#payment_type').hide();
}
}
else if(item == 'sale'){
$('#waiter').hide();
$('#cashier').show();
}
else{
$('#waiter').hide();
$('#cashier').show();
$("#item").val('sale');
}
});
//Reset the form to pervious values
$("#branch").val(<%=params[:branch]%>);
$("#waiter").val("<%=params[:waiter]%>");
$("#cashier").val(<%=params[:cashier]%>);
$("#product").val(<%=params[:product]%>);
$("#singer").val(<%=params[:singer]%>);
$("#item").val('<%=params[:item]%>');
$("#guest_role").val('<%=params[:guest_role]%>');
$("#from").val("<%=params[:from]%>");
$("#to").val("<%=params[:to]%>");
$("#sel_period").val(<%=params[:period]%>);
$("#sel_sale_type").val(<%=params[:sale_type]%>);
<% if params[:period_type] == 1 || params[:period_type] == "1" %>
$("#rd_period_type_1").attr("checked","checked");
<% else %>
$("#rd_period_type_0").attr("checked","checked");
<% end %>
$(".btn-group button").removeClass("active");
<% report_type = params[:report_type].blank? ? "0" : params[:report_type] %>
$("#btn_report_type_<%= report_type %>").addClass("active");
$('#item').change(function(){
var item = $('#item').val();
var payment_type = $('#payment_type');
if(item == 'sale'){
$('#waiter').hide();
$('#cashier').show();
if(payment_type){
$('#payment_type').show();
}
}
else{
$('#cashier').hide();
$('#waiter').show();
if(payment_type){
$('#payment_type').hide();
}
}
});
</script>

View File

@@ -0,0 +1,141 @@
<div class="page-header">
<ul class="breadcrumb">
<li><a href="<%= dashboard_path %>">Home</a></li>
<li>Daily Sale Report</li>
</ul>
</div>
<div class="container">
<%= render :partial=>'shift_sale_report_filter',
:locals=>{ :period_type => true, :shift_name => false, :report_path =>reports_saleitem_index_path} %>
<hr />
</div>
<div class="container">
<div class="row">
<div class="col-md-12 text-right">
<a href="javascript:export_to('<%=reports_saleitem_index_path%>.xls')" class = "btn btn-default">Export to Excel</a>
</div>
</div>
</div>
<div class="container margin-top-20">
<div class="card row">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Date</th>
<th id="date"></th>
</tr>
<tr>
<th>Menu Category</th>
<th>Code</th>
<th>Product</th>
<th>Total Item</th>
<th>Unit Price</th>
<th>Revenue</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
<script type="text/javascript">
$(function(){
var cate = [];
var y;
var count = 0;
var sub_total = 0;
var sub_total_arr = [];
<% @sale_data.each do |result| %>
count = count + 1;
if(count == 1)
$('#date').append('<%= result.date_name rescue '-'%>');
y = $.inArray(<%= result.menu_category_id %>, cate);
if(y == -1){
//add sub total row
sub_total_arr.push(sub_total);
var total_row = '<tr><td colspan="4"></td>'+
'<td > Sub Total</td> ' +
'<td><span class="underline">'+ sub_total +'</span></td>'+
'</tr>';
if(count != 1){
$('.table').append(total_row);
sub_total = 0;
}
cate.push(<%= result.menu_category_id %>);
var th = '<tr><td colspan="6"><%= result.menu_category_name rescue '-'%></td></tr>';
var tr = '<tr>'+
'<td></td>'+
'<td><%= result.code rescue '-'%></td>' +
'<td><%= result.product_name rescue '-'%></td>' +
'<td><%= result.total_item.to_i rescue '-'%></td>' +
'<td><%= number_with_precision(result.unit_price, :precision => 0) rescue '-'%></td>'+
'<td><%= number_with_precision(result.grand_total, :precision => 0) rescue '-'%>'+
'</td>'+
'</tr>';
$('.table').append(th);
$('.table').append(tr);
sub_total = parseInt(sub_total) + parseInt(<%= result.grand_total rescue '-'%>);
}
else{
var tr = '<tr>'+
'<td></td>'+
'<td><%= result.code rescue '-'%></td>' +
'<td><%= result.product_name rescue '-'%></td>' +
'<td><%= result.total_item.to_i rescue '-'%></td>' +
'<td><%= number_with_precision(result.unit_price, :precision => 0) rescue '-'%></td>'+
'<td><%= number_with_precision(result.grand_total, :precision => 0) rescue '-'%></td></tr>';
$('.table').append(tr);
sub_total = parseInt(sub_total) + parseInt(<%= result.grand_total rescue '-'%>);
}
<% end %>
last_line_subtotal(sub_total);
sub_total_arr.push(parseInt(sub_total));
grand_total(sub_total_arr);
})
function last_line_subtotal(sub_total){
var total_row = '<tr><td colspan="4"></td>'+
'<td > Sub Total</td> ' +
'<td><span class="underline">'+ sub_total +'</span></td>'+
'</tr>';
$('.table').append(total_row);
}
function grand_total(sub_total_arr){
var total = 0;
for(var i=0; i< sub_total_arr.length; i++){
//total_1 = (total_1) + (sub_total_arr[i]);
total = parseInt(total) + parseInt(sub_total_arr[i]);
}
var row = '<tr><td colspan="4"></td>'+
'<td > Grand Total</td> ' +
'<td><span class="double_underline">'+ total +'</span></td>'+
'</tr>';
$('.table').append(row);
}
</script>

View File

@@ -0,0 +1,104 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-type" content="application/vnd.ms-excel; charset=UTF-8">
</head>
<body>
<div class="span12">
<% unless @sale_data.blank? %>
<table class="table table-striped" id="items_table" border="0">
<thead>
<% if !params[:from].blank?%>
<tr>
<th colspan="7">From Date : <%= params[:from] %> , To Date : <%= params[:to] %></th>
</tr>
<% end %>
<% if @shift_from %>
<tr>
<% if @shift_data.employee %>
<% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %>
<% end %>
<th colspan="7">Shift Name = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )</th>
</tr>
<% end %>
<tr>
<th>&nbsp;</th>
<th>Menu Category</th>
<th>Code</th>
<th>Product</th>
<th>Total Item</th>
<th>Unit Price</th>
<th>Revenue</th>
</tr>
</thead>
<tbody>
<% 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| %>
<tr>
<td>&nbsp;</td>
<% if !cate_arr.include?(sale.menu_category_id) %>
<td><%= sale.menu_category_name %></td>
<% cate_arr.push(sale.menu_category_id) %>
<% else %>
<td>&nbsp;</td>
<% end %>
<td><%= sale.code rescue '-' %></td>
<% if @item_table == 'sale' %>
<% if sale.item_remark == 'FOC' %>
<td><%= '[PROMO] '.to_s + sale.product_name.to_s rescue '-' %></td>
<% elsif sale.item_remark == 'FOC ITEM' %>
<td><%= '[DIS:QTY] '.to_s + sale.product_name.to_s rescue '-' %></td>
<% elsif sale.item_remark == 'DISCOUNT' %>
<td><%= '[DIS:TP] '.to_s + sale.product_name.to_s rescue '-' %></td>
<% else %>
<td><%= sale.product_name.to_s rescue '-' %></td>
<% end %>
<% if sale.item_remark == 'DISCOUNT' %>
<td> - </td>
<td> - </td>
<td><%= sale.total_price.abs rescue '-' %></td>
<% total_price += sale.total_price %>
<% else %>
<td><%= sale.total_item.abs rescue '-' %></td>
<td><%= sale.unit_price rescue '-' %></td>
<td><%= sale.grand_total.abs rescue '-' %></td>
<% end %>
<% else %>
<td><%= sale.product_name.to_s rescue '-' %></td>
<td><%= sale.total_item.abs rescue '-' %></td>
<td><%= sale.unit_price rescue '-' %></td>
<td><%= sale.grand_total.abs rescue '-' %></td>
<% end %>
</tr>
<!-- sub total -->
<!-- end sub total -->
<% grand_total += sale.grand_total%>
<% end %>
<tr>
<td colspan="5">&nbsp;</td>
<td>Grand Total</td>
<td><span class="double_underline"><%= grand_total + total_discount %></span></td>
</tr>
</tbody>
</table>
<% end %>
</div>
</body>
</html>

View File

@@ -18,7 +18,7 @@
<option value="9">Last year</option>
</select>
</div>
<input type="hidden" name="report_type" value="sale_item" id="sel_sale_type">
<!-- <input type="hidden" name="report_type" value="sale_item" id="sel_sale_type"> -->
<!-- <div class="form-group col-md-2">
<label>Select Type</label>
<select name="sale_type" id="sel_sale_type" class="form-control">
@@ -39,6 +39,10 @@
<label class="">To</label>
<input data-behaviour='datepicker' class="form-control" name="to" id="to" type="text" placeholder="To date">
</div>
<div class="form-group col-md-2">
<label class="">All Shift</label>
<select name="shift_name" id="shift_name" class="form-control"></select>
</div>
<div class="form-group col-md-2 margin-top-20">
<input type="submit" value="Generate Report" class='btn btn-primary'>
</div>

View File

@@ -1,13 +1,14 @@
<div class="page-header">
<ul class="breadcrumb">
<li><a href="<%= dashboard_path %>">Home</a></li>
<li>Daily Sale Report</li>
</ul>
<ul class="breadcrumb">
<li><a href="<%= dashboard_path %>">Home</a></li>
<li>Daily Sale Report</li>
</ul>
</div>
<div class="container">
<%= render :partial=>'shift_sale_report_filter',
:locals=>{ :period_type => true, :shift_name => false, :report_path =>reports_saleitem_index_path} %>
<%= render :partial=>'shift_sale_report_filter',
:locals=>{ :period_type => true, :shift_name => true, :report_path =>reports_saleitem_index_path} %>
<hr />
</div>
@@ -21,121 +22,265 @@
<div class="container margin-top-20">
<div class="card row">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Date</th>
<th id="date"></th>
</tr>
<tr>
<th>Menu Category</th>
<th>Code</th>
<th>Product</th>
<th>Total Item</th>
<th>Unit Price</th>
<th>Revenue</th>
</tr>
</thead>
<tbody>
<div class="table-responsive">
</tbody>
</table>
</div>
</div>
<table class="table table-striped" id="items_table" border="0">
<thead>
<% if !params[:from].blank?%>
<tr>
<th colspan="7">From Date : <%= params[:from] %> , To Date : <%= params[:to] %></th>
</tr>
<% end %>
<% if @shift_from %>
<tr>
<% if @shift_data.employee %>
<% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %>
<% end %>
<th colspan="7">Shift Name = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )</th>
</tr>
<% end %>
<tr>
<th>&nbsp;</th>
<th>Menu Category</th>
<th>Code</th>
<th>Product</th>
<th>Total Item</th>
<th>Unit Price</th>
<th>Revenue</th>
</tr>
</thead>
<tbody>
<% 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) %>
<tr>
<td><b><%= sale.account_name %></b></td>
<td colspan="4">&nbsp;</td>
<td>Total Price By <%= sale.account_name %></td>
<td>
<% @totalByAccount.each do |account, total| %>
<% if sale.account_id == account %>
<b><%= total %></b>
<% grand_total += total %>
<% end %>
<% end %>
</td>
</tr>
<% acc_arr.push(sale.account_id) %>
<% end %>
<tr>
<td>&nbsp;</td>
<% if !cate_arr.include?(sale.menu_category_id) %>
<td><%= sale.menu_category_name %></td>
<% cate_arr.push(sale.menu_category_id) %>
<% else %>
<td>&nbsp;</td>
<% end %>
<td><%= sale.item_code rescue '-' %></td>
<td><%= sale.product_name rescue '-' %></td>
<td><%= sale.total_item rescue '-' %></td>
<td><%= sale.unit_price rescue '-' %></td>
<td><%= sale.grand_total rescue '-' %></td>
</tr>
<!-- sub total -->
<% @menu_cate_count.each do |key,value| %>
<% if sale.menu_category_id == key %>
<% count = count + 1 %>
<% sub_total += sale.grand_total %>
<% if count == value %>
<tr>
<td colspan="5">&nbsp;</td>
<td>Sub Total</td>
<td ><span class="underline"><%= sub_total %></span></td>
</tr>
<% sub_total = 0.0%>
<% count = 0%>
<% end %>
<% end %>
<% end %>
<!-- end sub total -->
<% end %>
<tr style="border-top:2px solid grey;">
<td colspan="3">&nbsp;</td>
<td>Total Item</td>
<td><span><%= total_qty%></span></td>
<td>Total Amount</td>
<td><span><%= grand_total%></span></td>
</tr>
<% end %>
<!-- <tr style="border-top:2px solid grey;">
<td colspan="5">&nbsp;</td>
<td>Total Amount</td>
<td><span><%= grand_total%></span></td>
</tr> -->
<!-- <tr>
<td colspan="5">&nbsp;</td>
<td>Cash Received</td>
<td><span><%= @cash_data %></span></td>
</tr>
<tr>
<td colspan="5">&nbsp;</td>
<td>Card Sales</td>
<td><span><%= @card_data %></span></td>
</tr>
<tr>
<td colspan="5">&nbsp;</td>
<td>Credit Sales</td>
<td><span><%= @credit_data %></span></td>
</tr>
<tr>
<td colspan="5">&nbsp;</td>
<td>FOC Sales</td>
<td><span><%= @foc_data %></span></td>
</tr>
<tr>
<td colspan="5">&nbsp;</td>
<td>Discount Amount</td>
<td><span><%= @discount_data %></span></td>
</tr>
<tr>
<td colspan="5">&nbsp;</td>
<td>Grand Total</td>
<!-- <td><span class="double_underline"><%= grand_total.to_f - @discount_data.to_f%></span></td> -->
<!-- <td><span class="double_underline"><%= @grand_total%></span></td>
</tr> -->
</tbody>
</table>
</div>
</div>
</div>
<script type="text/javascript">
$(function(){
var cate = [];
var y;
var count = 0;
var sub_total = 0;
var sub_total_arr = [];
<% @sale_data.each do |result| %>
count = count + 1;
if(count == 1)
$('#date').append('<%= result.date_name rescue '-'%>');
y = $.inArray(<%= result.menu_category_id %>, cate);
if(y == -1){
//add sub total row
sub_total_arr.push(sub_total);
var total_row = '<tr><td colspan="4"></td>'+
'<td > Sub Total</td> ' +
'<td><span class="underline">'+ sub_total +'</span></td>'+
'</tr>';
<script>
$(function(){
if(count != 1){
$('.table').append(total_row);
sub_total = 0;
var check_arr = [];
var search = '<%= params[:period_type] %>';
if(search){
if(parseInt(search) == 0){
search_by_period();
}
else{
search_by_date();
}
}else{
search_by_period();
}
$('#sel_period').change(function(){
search_by_period();
});
function search_by_period(){
var period = $('#sel_period').val();
var period_type = 0;
var from = "";
var to = "";
show_shift_name(period,period_type,from,to,'shift_item');
}
$('#from').change(function(){
search_by_date();
});
$('#to').change(function(){
search_by_date();
});
function search_by_date(){
var from = $('#from').val();
var to = $('#to').val();
var period = 0;
var period_type = 1;
if(to != '' && from != ''){
shift_name = from + ',' + to;
check_arr.push(to);
console.log(check_arr.length)
if(check_arr.length == 1){
show_shift_name(period,period_type,from,to,'shift_item');
}
if(check_arr.length == 3){
check_arr = [];
}
}
cate.push(<%= result.menu_category_id %>);
var th = '<tr><td colspan="6"><%= result.menu_category_name rescue '-'%></td></tr>';
var tr = '<tr>'+
'<td></td>'+
'<td><%= result.code rescue '-'%></td>' +
'<td><%= result.product_name rescue '-'%></td>' +
'<td><%= result.total_item.to_i rescue '-'%></td>' +
'<td><%= number_with_precision(result.unit_price, :precision => 0) rescue '-'%></td>'+
'<td><%= number_with_precision(result.grand_total, :precision => 0) rescue '-'%>'+
'</td>'+
'</tr>';
$('.table').append(th);
$('.table').append(tr);
sub_total = parseInt(sub_total) + parseInt(<%= result.grand_total rescue '-'%>);
}
else{
var tr = '<tr>'+
'<td></td>'+
'<td><%= result.code rescue '-'%></td>' +
'<td><%= result.product_name rescue '-'%></td>' +
'<td><%= result.total_item.to_i rescue '-'%></td>' +
'<td><%= number_with_precision(result.unit_price, :precision => 0) rescue '-'%></td>'+
'<td><%= number_with_precision(result.grand_total, :precision => 0) rescue '-'%></td></tr>';
$('.table').append(tr);
sub_total = parseInt(sub_total) + parseInt(<%= result.grand_total rescue '-'%>);
}
<% end %>
function show_shift_name(period,period_type,from,to,shift_item){
var shift = $('#shift_name');
last_line_subtotal(sub_total);
sub_total_arr.push(parseInt(sub_total));
grand_total(sub_total_arr);
})
shift.empty();
var selected = '';
var str = '';
var param_shift = '<%= params[:shift_name]%>';
function last_line_subtotal(sub_total){
var total_row = '<tr><td colspan="4"></td>'+
'<td > Sub Total</td> ' +
'<td><span class="underline">'+ sub_total +'</span></td>'+
'</tr>';
url = '<%= reports_get_shift_by_date_path %>';
$.get(url, {period :period, period_type :period_type, from :from, to :to, report_type :shift_item} , function(data){
console.log(data)
$('.table').append(total_row);
}
str = '<option value="0">--- All Shift ---</option>';
$(data.message).each(function(index){
function grand_total(sub_total_arr){
var local_date = data.message[index].local_opening_date + ' - ' + data.message[index].local_closing_date;
var sh_date = data.message[index].opening_date + ' - ' + data.message[index].closing_date;
var total = 0;
for(var i=0; i< sub_total_arr.length; i++){
//total_1 = (total_1) + (sub_total_arr[i]);
total = parseInt(total) + parseInt(sub_total_arr[i]);
}
var row = '<tr><td colspan="4"></td>'+
'<td > Grand Total</td> ' +
'<td><span class="double_underline">'+ total +'</span></td>'+
'</tr>';
$('.table').append(row);
}
if(param_shift != ''){
if(sh_date == param_shift){
selected = 'selected = "selected"';
}
else{
selected = '';
}
}
else{
selected = '';
}
str += '<option value="'+ sh_date +'" '+ selected +'>' + local_date + '</option>';
// console.log(sh_date)
})
shift.append(str);
});
}
//total price by account
$('#items_table tr').each(function(i){
});
});
</script>