waste and spoil report

This commit is contained in:
NyanLinHtut
2019-08-09 14:21:24 +06:30
parent 3f08f99bf4
commit 5e344dc4a6
12 changed files with 1044 additions and 189 deletions

View File

@@ -1,11 +1,11 @@
class HomeController < ApplicationController
class HomeController < ApplicationController
# layout "application", except: [:index, :show]
# skip_before_action :authenticate, only: [:index, :show, :create, :update, :destroy]
# skip_before_action :authenticate, only: [:index, :show, :create, :update, :destroy]
before_action :check_user, only: :dashboard
# Special check for only dashboard
def check_user
def check_user
if current_user.nil?
redirect_to root_path
end
@@ -42,8 +42,8 @@ class HomeController < ApplicationController
route_by_role(@employee)
else
flash[:notice] ="Invalid PIN for Employee. Please try again!"
render :show
end
render :show
end
end
def create
@@ -117,7 +117,8 @@ class HomeController < ApplicationController
@hourly_sales = Sale.hourly_sales(today,current_user,@from,@to,@from_time,@to_time).sum(:grand_total)
# .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p')
# .sum(:grand_total)
logger.debug 'hourly_sales<>><><><<<<<<>><<<><><><><><><><><><<>><'
logger.debug @hourly_sales.to_json
employee_sales = Sale.employee_sales(today,current_user,@from,@to,@from_time,@to_time)
# .sum("(CASE WHEN sp.payment_method='cash' THEN ((sp.payment_amount) - (sales.amount_changed)) ELSE (sp.payment_amount) END)")
@employee_sales = []
@@ -145,7 +146,7 @@ class HomeController < ApplicationController
if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" || payment.payment_method == "unionpay" || payment.payment_method == "alipay"
pay = Sale.payment_sale('card', today, current_user,@from,@to,@from_time,@to_time)
@sale_data.push({'card' => pay.payment_amount})
else
else
pay = Sale.payment_sale(payment.payment_method, today, current_user,@from,@to,@from_time,@to_time)
@sale_data.push({payment.payment_method => pay.payment_amount})
end
@@ -154,7 +155,7 @@ class HomeController < ApplicationController
@summ_sale = Sale.summary_sale_receipt(today,current_user,@from,@to,@from_time,@to_time)
@total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(today,current_user,@from,@to,@from_time,@to_time)
# @total_other_customer = Sale.total_other_customer(today,current_user)
@total_order = Sale.total_order(today,current_user,@from,@to,@from_time,@to_time)
@total_accounts = Sale.total_account(today,current_user,@from,@to,@from_time,@to_time)
@account_data = Array.new
@@ -168,7 +169,7 @@ class HomeController < ApplicationController
end
@top_items = Sale.top_items(today,current_user,@from,@to,@from_time,@to_time)
@total_foc_items = Sale.total_foc_items(today,current_user,@from,@to,@from_time,@to_time)
@total_foc_items = Sale.total_foc_items(today,current_user,@from,@to,@from_time,@to_time)
# get printer info
@print_settings = PrintSetting.get_precision_delimiter()
@@ -231,7 +232,7 @@ class HomeController < ApplicationController
def get_date_range_from_params
from = params[:from]
to = params[:to]
to = params[:to]
from_time = params[:from_time]
to_time = params[:to_time]
@@ -243,8 +244,8 @@ class HomeController < ApplicationController
# from = f_time.beginning_of_day.utc.getlocal
# to = t_time.end_of_day.utc.getlocal
from = DateTime.parse(from).utc.getlocal.strftime('%Y-%m-%d')
to = DateTime.parse(to).utc.getlocal.strftime('%Y-%m-%d')
from = DateTime.parse(from).utc.getlocal.strftime('%Y-%m-%d')
to = DateTime.parse(to).utc.getlocal.strftime('%Y-%m-%d')
end
return from, to, from_time, to_time

View File

@@ -0,0 +1,197 @@
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(:date_format)
@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

View File

@@ -64,7 +64,7 @@ class Reports::SaleitemController < BaseReportController
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")