add Old Town req:
This commit is contained in:
@@ -62,57 +62,59 @@ class HomeController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def dashboard
|
def dashboard
|
||||||
|
@from, @to = get_date_range_from_params
|
||||||
|
|
||||||
@shop = Shop.first
|
@shop = Shop.first
|
||||||
|
|
||||||
today = DateTime.now.strftime('%Y-%m-%d')
|
today = DateTime.now.strftime('%Y-%m-%d')
|
||||||
@orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count()
|
@orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count()
|
||||||
@sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count()
|
@sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count()
|
||||||
|
|
||||||
@top_products = Sale.top_products(today).sum('i.qty')
|
@top_products = Sale.top_products(today,@from,@to).sum('i.qty')
|
||||||
@bottom_products = Sale.bottom_products(today).sum('i.qty')
|
@bottom_products = Sale.bottom_products(today,@from,@to).sum('i.qty')
|
||||||
@hourly_sales = Sale.hourly_sales(today).sum(:grand_total)
|
@hourly_sales = Sale.hourly_sales(today,@from,@to).sum(:grand_total)
|
||||||
# .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p')
|
# .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p')
|
||||||
# .sum(:grand_total)
|
# .sum(:grand_total)
|
||||||
@employee_sales = Sale.employee_sales(today)
|
@employee_sales = Sale.employee_sales(today,@from,@to)
|
||||||
.sum('(CASE WHEN sp.payment_method="cash" THEN (sp.payment_amount - sales.amount_changed) ELSE sp.payment_amount END)')
|
.sum('(CASE WHEN sp.payment_method="cash" THEN (sp.payment_amount - sales.amount_changed) ELSE sp.payment_amount END)')
|
||||||
@inventories = StockJournal.inventory_balances(today).sum(:balance)
|
@inventories = StockJournal.inventory_balances(today,@from,@to).sum(:balance)
|
||||||
|
|
||||||
@total_sale = Sale.total_sale(today)
|
@total_sale = Sale.total_sale(today,current_user,@from,@to)
|
||||||
@total_count = Sale.total_count(today)
|
@total_count = Sale.total_count(today,current_user,@from,@to)
|
||||||
@total_card = Sale.total_card_sale(today)
|
@total_card = Sale.total_card_sale(today,current_user,@from,@to)
|
||||||
@total_credit = Sale.credit_payment(today)
|
@total_credit = Sale.credit_payment(today,current_user,@from,@to)
|
||||||
|
|
||||||
@sale_data = Array.new
|
@sale_data = Array.new
|
||||||
@total_payment_methods = Sale.total_payment_methods(today)
|
@total_payment_methods = Sale.total_payment_methods(today,current_user,@from,@to)
|
||||||
|
|
||||||
@total_payment_methods.each do |payment|
|
@total_payment_methods.each do |payment|
|
||||||
if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb"
|
if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb"
|
||||||
pay = Sale.payment_sale('card', today)
|
pay = Sale.payment_sale('card', today, current_user,@from,@to)
|
||||||
@sale_data.push({'card' => pay.payment_amount})
|
@sale_data.push({'card' => pay.payment_amount})
|
||||||
else
|
else
|
||||||
pay = Sale.payment_sale(payment.payment_method, today)
|
pay = Sale.payment_sale(payment.payment_method, today, current_user,@from,@to)
|
||||||
@sale_data.push({payment.payment_method => pay.payment_amount})
|
@sale_data.push({payment.payment_method => pay.payment_amount})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@summ_sale = Sale.summary_sale_receipt(today)
|
@summ_sale = Sale.summary_sale_receipt(today,current_user,@from,@to)
|
||||||
@total_customer = Sale.total_customer(today)
|
@total_customer = Sale.total_customer(today,current_user,@from,@to)
|
||||||
@total_dinein = Sale.total_dinein(today)
|
@total_dinein = Sale.total_dinein(today,current_user,@from,@to)
|
||||||
@total_takeaway = Sale.total_takeaway(today)
|
@total_takeaway = Sale.total_takeaway(today,current_user,@from,@to)
|
||||||
@total_other_customer = Sale.total_other_customer(today)
|
@total_other_customer = Sale.total_other_customer(today,current_user,@from,@to)
|
||||||
@total_membership = Sale.total_membership(today)
|
@total_membership = Sale.total_membership(today,current_user,@from,@to)
|
||||||
|
|
||||||
@total_order = Sale.total_order(today)
|
@total_order = Sale.total_order(today,current_user,@from,@to)
|
||||||
@total_accounts = Sale.total_account(today)
|
@total_accounts = Sale.total_account(today,current_user,@from,@to)
|
||||||
@account_data = Array.new
|
@account_data = Array.new
|
||||||
@total_accounts.each do |account|
|
@total_accounts.each do |account|
|
||||||
acc = Sale.account_data(account.account_id, today)
|
acc = Sale.account_data(account.account_id, today,current_user,@from,@to)
|
||||||
if !acc.nil?
|
if !acc.nil?
|
||||||
@account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc})
|
@account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@top_items = Sale.top_items(today)
|
@top_items = Sale.top_items(today,current_user,@from,@to)
|
||||||
@total_foc_items = Sale.total_foc_items(today)
|
@total_foc_items = Sale.total_foc_items(today,current_user,@from,@to)
|
||||||
|
|
||||||
# get printer info
|
# get printer info
|
||||||
@print_settings = PrintSetting.get_precision_delimiter()
|
@print_settings = PrintSetting.get_precision_delimiter()
|
||||||
@@ -162,4 +164,20 @@ class HomeController < ApplicationController
|
|||||||
redirect_to reports_dailysale_index_path
|
redirect_to reports_dailysale_index_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_date_range_from_params
|
||||||
|
from = params[:from]
|
||||||
|
to = params[:to]
|
||||||
|
|
||||||
|
if from.present? && to.present?
|
||||||
|
f_date = DateTime.parse(from)
|
||||||
|
t_date = DateTime.parse(to)
|
||||||
|
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.getlocal
|
||||||
|
to = t_time.end_of_day.utc.getlocal
|
||||||
|
end
|
||||||
|
|
||||||
|
return from, to
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
18
app/controllers/reports/product_sale_controller.rb
Executable file
18
app/controllers/reports/product_sale_controller.rb
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
class Reports::ProductSaleController < BaseReportController
|
||||||
|
authorize_resource :class => false
|
||||||
|
|
||||||
|
def index
|
||||||
|
@order_by = params[:order_by]
|
||||||
|
|
||||||
|
@sale_data = Sale.get_menu_item_query(@order_by)
|
||||||
|
|
||||||
|
# get printer info
|
||||||
|
@print_settings = PrintSetting.get_precision_delimiter()
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html
|
||||||
|
format.json
|
||||||
|
format.xls
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -78,13 +78,28 @@ class Sale < ApplicationRecord
|
|||||||
self.tax_type = "exclusive"
|
self.tax_type = "exclusive"
|
||||||
|
|
||||||
# set cashier
|
# set cashier
|
||||||
if cashier != nil
|
open_cashier = Employee.where("role = 'cashier' AND token_session <> ''")
|
||||||
|
current_shift = ShiftSale.current_shift
|
||||||
|
shift = ShiftSale.current_open_shift(cashier.id)
|
||||||
|
|
||||||
|
# set cashier
|
||||||
|
if shift != nil
|
||||||
self.cashier_id = cashier.id
|
self.cashier_id = cashier.id
|
||||||
self.cashier_name = cashier.name
|
self.cashier_name = cashier.name
|
||||||
|
self.shift_sale_id = shift.id
|
||||||
else
|
else
|
||||||
self.cashier_id = requested_by.id
|
if open_cashier.count>0
|
||||||
self.cashier_name = requested_by.name
|
self.cashier_id = open_cashier[0].id
|
||||||
|
self.cashier_name = open_cashier[0].name
|
||||||
|
shift_id = ShiftSale.current_open_shift(open_cashier[0].id)
|
||||||
|
self.shift_sale_id = current_shift.id
|
||||||
|
else
|
||||||
|
self.cashier_id = current_shift.employee_id
|
||||||
|
self.cashier_name = Employee.find(current_shift.employee_id).name
|
||||||
|
self.shift_sale_id = current_shift.id
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
# set waiter
|
# set waiter
|
||||||
self.requested_by = requested_by.name
|
self.requested_by = requested_by.name
|
||||||
@@ -212,7 +227,7 @@ class Sale < ApplicationRecord
|
|||||||
sale_item.product_name = item.item_name
|
sale_item.product_name = item.item_name
|
||||||
sale_item.product_alt_name = item.alt_name
|
sale_item.product_alt_name = item.alt_name
|
||||||
sale_item.account_id = item.account_id
|
sale_item.account_id = item.account_id
|
||||||
sale_item.remark = item.remark
|
sale_item.status = item.remark
|
||||||
|
|
||||||
sale_item.qty = item.qty
|
sale_item.qty = item.qty
|
||||||
sale_item.unit_price = item.price
|
sale_item.unit_price = item.price
|
||||||
@@ -240,7 +255,7 @@ class Sale < ApplicationRecord
|
|||||||
sale_item.product_name = instance.item_instance_name
|
sale_item.product_name = instance.item_instance_name
|
||||||
sale_item.product_alt_name = menu_item.alt_name
|
sale_item.product_alt_name = menu_item.alt_name
|
||||||
sale_item.account_id = menu_item.account_id
|
sale_item.account_id = menu_item.account_id
|
||||||
sale_item.remark = nil
|
sale_item.status = nil
|
||||||
|
|
||||||
sale_item.qty = item["quantity"]
|
sale_item.qty = item["quantity"]
|
||||||
sale_item.unit_price = item["price"]
|
sale_item.unit_price = item["price"]
|
||||||
@@ -366,7 +381,7 @@ class Sale < ApplicationRecord
|
|||||||
rounding_adjustment = 0
|
rounding_adjustment = 0
|
||||||
|
|
||||||
sales_items.each do |item|
|
sales_items.each do |item|
|
||||||
if item.remark != 'void' && item.remark != 'foc'
|
if item.status != 'void' && item.status != 'foc'
|
||||||
#compute each item and added to total
|
#compute each item and added to total
|
||||||
subtotal_price = subtotal_price + item.price
|
subtotal_price = subtotal_price + item.price
|
||||||
|
|
||||||
@@ -402,6 +417,7 @@ class Sale < ApplicationRecord
|
|||||||
tax_profiles = TaxProfile.all.order("order_by asc")
|
tax_profiles = TaxProfile.all.order("order_by asc")
|
||||||
customer = Customer.find(sale.customer_id)
|
customer = Customer.find(sale.customer_id)
|
||||||
# #Creat new tax records
|
# #Creat new tax records
|
||||||
|
if sale.payment_status != 'foc'
|
||||||
tax_profiles.each do |tax|
|
tax_profiles.each do |tax|
|
||||||
customer.tax_profiles.each do |cus_tax|
|
customer.tax_profiles.each do |cus_tax|
|
||||||
if cus_tax.to_i == tax.id
|
if cus_tax.to_i == tax.id
|
||||||
@@ -430,7 +446,7 @@ class Sale < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
sale.total_tax = total_tax_amount
|
sale.total_tax = total_tax_amount
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -742,8 +758,8 @@ end
|
|||||||
def self.get_item_query()
|
def self.get_item_query()
|
||||||
query = Sale.select("acc.title as account_name,mi.account_id, i.item_instance_code as item_code,i.account_id as account_id, " +
|
query = Sale.select("acc.title as account_name,mi.account_id, 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," +
|
"SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item,i.qty as qty," +
|
||||||
"i.remark as status_type,"+
|
"i.status as status_type,"+
|
||||||
" mii.price as unit_price,i.price as price,i.product_name as product_name, mc.name as" +
|
" i.unit_price,i.price as price,i.product_name as product_name, mc.name as" +
|
||||||
" menu_category_name,mc.id as menu_category_id ")
|
" menu_category_name,mc.id as menu_category_id ")
|
||||||
|
|
||||||
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id" +
|
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id" +
|
||||||
@@ -754,14 +770,14 @@ def self.get_item_query()
|
|||||||
# "JOIN employee_accesses ea ON ea.`employee_id` = sales.cashier_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.joins(" JOIN accounts acc ON acc.id = mi.account_id")
|
||||||
# query = query.where("i.item_instance_code IS NOT NULL")
|
# query = query.where("i.item_instance_code IS NOT NULL")
|
||||||
query = query.group("acc.title,mi.account_id,mi.menu_category_id,i.product_name")
|
query = query.group("acc.title,mi.account_id,mi.menu_category_id,i.product_name,i.unit_price")
|
||||||
.order("acc.title desc, mi.account_id desc, mi.menu_category_id desc, i.unit_price asc")
|
.order("acc.title desc, mi.account_id desc, mi.menu_category_id desc, i.unit_price asc")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_other_charges()
|
def self.get_other_charges()
|
||||||
query = Sale.select("i.account_id as account_id, " +
|
query = Sale.select("i.account_id as account_id, " +
|
||||||
"SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item," +
|
"SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item," +
|
||||||
"i.remark as status_type,"+
|
"i.status as status_type,"+
|
||||||
" i.unit_price as unit_price,i.product_name as product_name")
|
" i.unit_price as unit_price,i.product_name as product_name")
|
||||||
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id")
|
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id")
|
||||||
query = query.where("i.item_instance_code IS NULL AND i.product_code = 'Other Charges'")
|
query = query.where("i.item_instance_code IS NULL AND i.product_code = 'Other Charges'")
|
||||||
@@ -770,7 +786,6 @@ end
|
|||||||
|
|
||||||
def self.get_by_shift_items(shift_sale_range, shift, from, to, status)
|
def self.get_by_shift_items(shift_sale_range, shift, from, to, status)
|
||||||
# date_type_selection = get_sql_function_for_report_type(report_type)
|
# date_type_selection = get_sql_function_for_report_type(report_type)
|
||||||
|
|
||||||
query = self.get_item_query()
|
query = self.get_item_query()
|
||||||
|
|
||||||
discount_query = 0
|
discount_query = 0
|
||||||
@@ -846,6 +861,27 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status)
|
|||||||
return query,other_charges, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount
|
return query,other_charges, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#product sale report query
|
||||||
|
def self.get_menu_item_query(order_by)
|
||||||
|
query = MenuItem.unscoped.select("acc.id as account_id,
|
||||||
|
acc.title as account_name,
|
||||||
|
mii.item_instance_code as item_code, " +
|
||||||
|
"(CASE WHEN si.qty > 0 THEN SUM(si.qty) ELSE 0 END) as total_item," +
|
||||||
|
"(CASE WHEN si.unit_price > 0 THEN si.unit_price ELSE mii.price END) as unit_price," +
|
||||||
|
"(CASE WHEN (si.qty * si.unit_price) > 0 THEN (si.qty * si.unit_price) ELSE 0 END) as grand_total," +
|
||||||
|
"mii.price as unit_price, menu_items.name as product_name,
|
||||||
|
mc.name as" +
|
||||||
|
" menu_category_name,mc.id as menu_category_id, si.remark as status_type, si.price as price ")
|
||||||
|
.joins(" LEFT JOIN menu_item_instances mii ON menu_items.id = mii.menu_item_id" +
|
||||||
|
" LEFT JOIN menu_categories mc ON mc.id = menu_items.menu_category_id" +
|
||||||
|
" LEFT JOIN accounts acc ON acc.id = menu_items.account_id" +
|
||||||
|
" LEFT JOIN sale_items si ON si.item_instance_code = mii.item_instance_code" +
|
||||||
|
" LEFT JOIN sales s ON s.sale_id = si.sale_id")
|
||||||
|
.group("mc.id, menu_items.name, si.qty, (CASE WHEN si.unit_price > 0 THEN si.unit_price ELSE mii.price END)")
|
||||||
|
.order("si.qty #{order_by}, menu_items.menu_category_id #{order_by}")
|
||||||
|
end
|
||||||
|
#product sale report query
|
||||||
|
|
||||||
def self.get_shift_sales_by_receipt_no(shift_sale_range,shift,from,to,payment_type)
|
def self.get_shift_sales_by_receipt_no(shift_sale_range,shift,from,to,payment_type)
|
||||||
## => left join -> show all sales although no orders
|
## => left join -> show all sales although no orders
|
||||||
if payment_type.blank?
|
if payment_type.blank?
|
||||||
@@ -1053,82 +1089,340 @@ end
|
|||||||
return tax
|
return tax
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.top_products(today)
|
def self.top_products(today,from,to)
|
||||||
|
if !from.nil? && !to.nil?
|
||||||
|
query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
|
||||||
|
" i.price as unit_price,mi.name as product_name")
|
||||||
|
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
|
||||||
|
.where("(i.qty > 0 and i.price > 0) and receipt_date between '#{from}' and '#{to}'"+
|
||||||
|
"and payment_status='paid' and sale_status= 'completed'")
|
||||||
|
.group('mi.name')
|
||||||
|
.order("SUM(i.qty) DESC").limit(20)
|
||||||
|
else
|
||||||
query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
|
query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
|
||||||
" i.price as unit_price,mi.name as product_name")
|
" i.price as unit_price,mi.name as product_name")
|
||||||
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
|
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
|
||||||
.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+
|
.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+
|
||||||
"and payment_status='paid' and sale_status= 'completed'")
|
"and payment_status='paid' and sale_status= 'completed'")
|
||||||
.group('mi.name')
|
.group('mi.name')
|
||||||
.order("SUM(i.qty) DESC").limit(10)
|
.order("SUM(i.qty) DESC").limit(20)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.bottom_products(today)
|
def self.bottom_products(today,from,to)
|
||||||
|
if !from.nil? && !to.nil?
|
||||||
|
query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
|
||||||
|
" i.price as unit_price,mi.name as product_name")
|
||||||
|
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
|
||||||
|
.where("(i.qty > 0 and i.price > 0) and receipt_date between '#{from}' and '#{to}'"+
|
||||||
|
"and payment_status='paid' and sale_status= 'completed'")
|
||||||
|
.group('mi.name')
|
||||||
|
.order("SUM(i.qty) ASC").limit(20)
|
||||||
|
else
|
||||||
query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
|
query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
|
||||||
" i.price as unit_price,mi.name as product_name")
|
" i.price as unit_price,mi.name as product_name")
|
||||||
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
|
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
|
||||||
.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+
|
.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+
|
||||||
"and payment_status='paid' and sale_status= 'completed'")
|
"and payment_status='paid' and sale_status= 'completed'")
|
||||||
.group('mi.name')
|
.group('mi.name')
|
||||||
.order("SUM(i.qty) ASC").limit(10)
|
.order("SUM(i.qty) ASC").limit(20)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.hourly_sales(today)
|
def self.hourly_sales(today,from,to)
|
||||||
|
if !from.nil? && !to.nil?
|
||||||
|
query= Sale.select("grand_total")
|
||||||
|
.where('payment_status="paid" and sale_status = "completed" and receipt_date between ? and ?',from,to)
|
||||||
|
.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')")
|
||||||
|
.order('receipt_date')
|
||||||
|
else
|
||||||
query= Sale.select("grand_total")
|
query= Sale.select("grand_total")
|
||||||
.where('payment_status="paid" and sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
|
.where('payment_status="paid" and sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
|
||||||
.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')")
|
.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')")
|
||||||
.order('receipt_date')
|
.order('receipt_date')
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.employee_sales(today)
|
def self.employee_sales(today,from,to)
|
||||||
|
if !from.nil? && !to.nil?
|
||||||
|
query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id")
|
||||||
|
.joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id")
|
||||||
|
.where("sales.payment_status='paid' and sales.sale_status = 'completed' and sales.receipt_date between '#{from}' and '#{to}'")
|
||||||
|
.group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay') THEN 'card' ELSE sp.payment_method END)","e.name")
|
||||||
|
.order("e.name")
|
||||||
|
else
|
||||||
query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id")
|
query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id")
|
||||||
.joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id")
|
.joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id")
|
||||||
.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = '#{today}'")
|
.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = '#{today}'")
|
||||||
.group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay') THEN 'card' ELSE sp.payment_method END)","e.name")
|
.group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay') THEN 'card' ELSE sp.payment_method END)","e.name")
|
||||||
.order("e.name")
|
.order("e.name")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.total_sale(today)
|
def self.total_sale(today,current_user=nil,from,to)
|
||||||
|
if !from.nil? && !to.nil?
|
||||||
|
if current_user.nil?
|
||||||
|
total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).sum("grand_total")
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).sum("grand_total")
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
total = Sale.where('sale_status = "completed" and sales.receipt_date between ? and ? and shift_sale_id=?',from,to,shift.id)
|
||||||
|
.sum("grand_total")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if current_user.nil?
|
||||||
total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).sum("grand_total")
|
total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).sum("grand_total")
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).sum("grand_total")
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
total = Sale.where('sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and shift_sale_id=?',today,shift.id)
|
||||||
|
.sum("grand_total")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.total_count(today)
|
def self.total_count(today,current_user=nil,from,to)
|
||||||
|
if !from.nil? && !to.nil?
|
||||||
|
if current_user.nil?
|
||||||
|
total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).count
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).count
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
total = Sale.where('sale_status = "completed" and receipt_date between ? and ? and shift_sale_id = ?',from,to,shift.id).count
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if current_user.nil?
|
||||||
total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).count
|
total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).count
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).count
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ? and shift_sale_id = ?',today,shift.id).count
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.total_card_sale(today)
|
def self.total_card_sale(today,current_user=nil,from,to)
|
||||||
payment_type = " and payment_method = 'mpu' or payment_method = 'visa' or payment_method = 'master' or payment_method = 'jcb' or payment_method = 'unionpay' "
|
if !from.nil? && !to.nil?
|
||||||
# query = Sale.select("SUM(tax_payable_amount) AS st_amount,tax_name")
|
if current_user.nil?
|
||||||
# .where('sale_status = "completed" #{payment_type} and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
|
query = Sale.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to)
|
||||||
# .joins("join sale_payments on sale_id = sales.sale_id")
|
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
|
||||||
# .group("sales.sale_id")
|
.sum("sp.payment_amount")
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to)
|
||||||
|
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
|
||||||
|
.sum("sp.payment_amount")
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay") and shift_sale_id=?',from,to,shift.id)
|
||||||
|
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
|
||||||
|
.sum("sp.payment_amount")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if current_user.nil?
|
||||||
query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',today)
|
query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',today)
|
||||||
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
|
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
|
||||||
.sum("sp.payment_amount")
|
.sum("sp.payment_amount")
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',today)
|
||||||
|
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
|
||||||
|
.sum("sp.payment_amount")
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay") and shift_sale_id=?',today,shift.id)
|
||||||
|
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
|
||||||
|
.sum("sp.payment_amount")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.credit_payment(today)
|
def self.credit_payment(today,current_user=nil,from,to)
|
||||||
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(s.receipt_date,"%Y-%m-%d") = ?',today)
|
if !from.nil? && !to.nil?
|
||||||
|
if current_user.nil?
|
||||||
|
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and s.receipt_date between ? and ?',from,to)
|
||||||
|
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
||||||
|
.sum("payment_amount")
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and s.receipt_date between ? and ?',from,to)
|
||||||
|
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
||||||
|
.sum("payment_amount")
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and s.receipt_date between ? and ? and s.shift_sale_id=?',from,to,shift.id)
|
||||||
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
||||||
.sum("payment_amount")
|
.sum("payment_amount")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if current_user.nil?
|
||||||
|
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(s.receipt_date,"%Y-%m-%d") = ?',today)
|
||||||
|
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
||||||
|
.sum("payment_amount")
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(s.receipt_date,"%Y-%m-%d") = ?',today)
|
||||||
|
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
||||||
|
.sum("payment_amount")
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(s.receipt_date,"%Y-%m-%d") = ? and s.shift_sale_id=?',today,shift.id)
|
||||||
|
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
||||||
|
.sum("payment_amount")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.summary_sale_receipt(today)
|
def self.summary_sale_receipt(today,current_user=nil,from,to)
|
||||||
|
if !from.nil? && !to.nil?
|
||||||
|
if current_user.nil?
|
||||||
|
query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
|
||||||
|
.where('sale_status = "completed" and receipt_date between ? and ?',from,to)
|
||||||
|
.first()
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
|
||||||
|
.where('sale_status = "completed" and receipt_date between ? and ?',from,to)
|
||||||
|
.first()
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
|
||||||
|
.where('sale_status = "completed" and receipt_date between ? and ? and shift_sale_id=?',from,to,shift.id)
|
||||||
|
.first()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if current_user.nil?
|
||||||
query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
|
query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
|
||||||
.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
|
.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
|
||||||
.first()
|
.first()
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
|
||||||
|
.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
|
||||||
|
.first()
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
|
||||||
|
.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ? and shift_sale_id=?',today,shift.id)
|
||||||
|
.first()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.total_payment_methods(today)
|
def self.total_payment_methods(today,current_user=nil,from,to)
|
||||||
|
if !from.nil? && !to.nil?
|
||||||
|
if current_user.nil?
|
||||||
|
query = Sale.select("distinct sp.payment_method")
|
||||||
|
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to)
|
||||||
|
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.select("distinct sp.payment_method")
|
||||||
|
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to)
|
||||||
|
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.select("distinct sp.payment_method")
|
||||||
|
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and sales.shift_sale_id=?',from,to,shift.id)
|
||||||
|
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if current_user.nil?
|
||||||
query = Sale.select("distinct sp.payment_method")
|
query = Sale.select("distinct sp.payment_method")
|
||||||
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
||||||
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.select("distinct sp.payment_method")
|
||||||
|
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
||||||
|
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.select("distinct sp.payment_method")
|
||||||
|
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id)
|
||||||
|
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.payment_sale(payment_method, today)
|
def self.payment_sale(payment_method, today, current_user=nil,from,to)
|
||||||
|
if !from.nil? && !to.nil?
|
||||||
|
if current_user.nil?
|
||||||
|
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||||
|
if payment_method == 'card'
|
||||||
|
query = query.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to)
|
||||||
|
else
|
||||||
|
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and sales.receipt_date between ? and ?",from,to)
|
||||||
|
end
|
||||||
|
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||||
|
if payment_method == 'card'
|
||||||
|
query = query.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to)
|
||||||
|
else
|
||||||
|
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and sales.receipt_date between ? and ?",from,to)
|
||||||
|
end
|
||||||
|
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||||
|
if payment_method == 'card'
|
||||||
|
query = query.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay") and sales.shift_sale_id=?',from,to,shift.id)
|
||||||
|
else
|
||||||
|
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and sales.receipt_date between ? and ? and sales.shift_sale_id=?",from,to,shift.id)
|
||||||
|
end
|
||||||
|
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if current_user.nil?
|
||||||
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||||
if payment_method == 'card'
|
if payment_method == 'card'
|
||||||
query = query.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',today)
|
query = query.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',today)
|
||||||
@@ -1136,12 +1430,35 @@ end
|
|||||||
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
|
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
|
||||||
end
|
end
|
||||||
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
|
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||||
|
if payment_method == 'card'
|
||||||
|
query = query.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',today)
|
||||||
|
else
|
||||||
|
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
|
||||||
|
end
|
||||||
|
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||||
|
if payment_method == 'card'
|
||||||
|
query = query.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay") and sales.shift_sale_id=?',today,shift.id)
|
||||||
|
else
|
||||||
|
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? and sales.shift_sale_id=?",today,shift.id)
|
||||||
|
end
|
||||||
|
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.total_customer(today)
|
def self.total_customer(today,current_user=nil,from,to)
|
||||||
dinein_cnt = self.total_dinein(today)
|
dinein_cnt = self.total_dinein(today,current_user,from,to)
|
||||||
takeaway_cnt = self.total_takeaway(today)
|
takeaway_cnt = self.total_takeaway(today,current_user,from,to)
|
||||||
membership_cnt = self.total_membership(today)
|
membership_cnt = self.total_membership(today,current_user,from,to)
|
||||||
|
|
||||||
total_cus = 0
|
total_cus = 0
|
||||||
if !dinein_cnt.nil? || !takeaway_cnt.nil? || !membership_cnt.nil?
|
if !dinein_cnt.nil? || !takeaway_cnt.nil? || !membership_cnt.nil?
|
||||||
@@ -1151,69 +1468,448 @@ end
|
|||||||
return total_cus
|
return total_cus
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.total_dinein(today)
|
def self.total_dinein(today,current_user=nil,from,to)
|
||||||
|
if !from.nil? && !to.nil?
|
||||||
|
if current_user.nil?
|
||||||
|
query = Sale.select("count(sales.customer_id) as total_dinein_cus")
|
||||||
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||||
|
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to)
|
||||||
|
.first()
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.select("count(sales.customer_id) as total_dinein_cus")
|
||||||
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||||
|
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to)
|
||||||
|
.first()
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.select("count(sales.customer_id) as total_dinein_cus")
|
||||||
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||||
|
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Dinein" and c.membership_id is null and sales.shift_sale_id=?',from,to,shift.id)
|
||||||
|
.first()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if current_user.nil?
|
||||||
query = Sale.select("count(sales.customer_id) as total_dinein_cus")
|
query = Sale.select("count(sales.customer_id) as total_dinein_cus")
|
||||||
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||||
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null',today)
|
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null',today)
|
||||||
.first()
|
.first()
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.select("count(sales.customer_id) as total_dinein_cus")
|
||||||
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||||
|
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null',today)
|
||||||
|
.first()
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.select("count(sales.customer_id) as total_dinein_cus")
|
||||||
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||||
|
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null and sales.shift_sale_id=?',today,shift.id)
|
||||||
|
.first()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.total_takeaway(today)
|
def self.total_takeaway(today,current_user=nil,from,to)
|
||||||
|
if !from.nil? && !to.nil?
|
||||||
|
if current_user.nil?
|
||||||
|
query = Sale.select("count(sales.customer_id) as total_take_cus")
|
||||||
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||||
|
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to)
|
||||||
|
.first()
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.select("count(sales.customer_id) as total_take_cus")
|
||||||
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||||
|
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to)
|
||||||
|
.first()
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.select("count(sales.customer_id) as total_take_cus")
|
||||||
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||||
|
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null and sales.shift_sale_id=?',from,to,shift.id)
|
||||||
|
.first()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if current_user.nil?
|
||||||
query = Sale.select("count(sales.customer_id) as total_take_cus")
|
query = Sale.select("count(sales.customer_id) as total_take_cus")
|
||||||
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||||
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null',today)
|
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null',today)
|
||||||
.first()
|
.first()
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.select("count(sales.customer_id) as total_take_cus")
|
||||||
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||||
|
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null',today)
|
||||||
|
.first()
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.select("count(sales.customer_id) as total_take_cus")
|
||||||
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||||
|
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null and sales.shift_sale_id=?',today,shift.id)
|
||||||
|
.first()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.total_membership(today)
|
def self.total_membership(today,current_user=nil,from,to)
|
||||||
|
if !from.nil? && !to.nil?
|
||||||
|
if current_user.nil?
|
||||||
|
query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
|
||||||
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||||
|
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',from,to)
|
||||||
|
.first()
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
|
||||||
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||||
|
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',from,to)
|
||||||
|
.first()
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
|
||||||
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||||
|
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null)) and sales.shift_sale_id=?',from,to,shift.id)
|
||||||
|
.first()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if current_user.nil?
|
||||||
query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
|
query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
|
||||||
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||||
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',today)
|
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',today)
|
||||||
.first()
|
.first()
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
|
||||||
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||||
|
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',today)
|
||||||
|
.first()
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
|
||||||
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||||
|
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null)) and sales.shift_sale_id=?',today,shift.id)
|
||||||
|
.first()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.total_other_customer(today)
|
def self.total_other_customer(today,current_user=nil,from,to)
|
||||||
|
if !from.nil? && !to.nil?
|
||||||
|
if current_user.nil?
|
||||||
|
query = Sale.select("count(sales.customer_id) as total_cus")
|
||||||
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||||
|
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type is null and c.membership_id is null',from,to)
|
||||||
|
.first()
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.select("count(sales.customer_id) as total_cus")
|
||||||
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||||
|
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type is null and c.membership_id is null',from,to)
|
||||||
|
.first()
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.select("count(sales.customer_id) as total_cus")
|
||||||
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||||
|
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type is null and c.membership_id is null and sales.shift_sale_id=?',from,to,shift.id)
|
||||||
|
.first()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if current_user.nil?
|
||||||
query = Sale.select("count(sales.customer_id) as total_cus")
|
query = Sale.select("count(sales.customer_id) as total_cus")
|
||||||
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||||
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null',today)
|
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null',today)
|
||||||
.first()
|
.first()
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.select("count(sales.customer_id) as total_cus")
|
||||||
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||||
|
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null',today)
|
||||||
|
.first()
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.select("count(sales.customer_id) as total_cus")
|
||||||
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||||
|
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null and sales.shift_sale_id=?',today,shift.id)
|
||||||
|
.first()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.total_order(today)
|
def self.total_order(today,current_user=nil,from,to)
|
||||||
|
if !from.nil? && !to.nil?
|
||||||
|
if current_user.nil?
|
||||||
|
query = Sale.select("count(distinct a.order_id) as total_order")
|
||||||
|
.joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id")
|
||||||
|
.joins("JOIN orders as b ON b.order_id = a.order_id")
|
||||||
|
.where('b.status = "billed" and sales.receipt_date between ? and ?',from,to)
|
||||||
|
.first()
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.select("count(distinct a.order_id) as total_order")
|
||||||
|
.joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id")
|
||||||
|
.joins("JOIN orders as b ON b.order_id = a.order_id")
|
||||||
|
.where('b.status = "billed" and sales.receipt_date between ? and ?',from,to)
|
||||||
|
.first()
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.select("count(distinct a.order_id) as total_order")
|
||||||
|
.joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id")
|
||||||
|
.joins("JOIN orders as b ON b.order_id = a.order_id")
|
||||||
|
.where('b.status = "billed" and sales.receipt_date between ? and ? and sales.shift_sale_id=?',from,to,shift.id)
|
||||||
|
.first()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if current_user.nil?
|
||||||
query = Sale.select("count(distinct a.order_id) as total_order")
|
query = Sale.select("count(distinct a.order_id) as total_order")
|
||||||
.joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id")
|
.joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id")
|
||||||
.joins("JOIN orders as b ON b.order_id = a.order_id")
|
.joins("JOIN orders as b ON b.order_id = a.order_id")
|
||||||
.where('b.status = "billed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
.where('b.status = "billed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
||||||
.first()
|
.first()
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.select("count(distinct a.order_id) as total_order")
|
||||||
|
.joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id")
|
||||||
|
.joins("JOIN orders as b ON b.order_id = a.order_id")
|
||||||
|
.where('b.status = "billed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
||||||
|
.first()
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.select("count(distinct a.order_id) as total_order")
|
||||||
|
.joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id")
|
||||||
|
.joins("JOIN orders as b ON b.order_id = a.order_id")
|
||||||
|
.where('b.status = "billed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id)
|
||||||
|
.first()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.total_account(today)
|
def self.total_account(today,current_user=nil,from,to)
|
||||||
|
if !from.nil? && !to.nil?
|
||||||
|
if current_user.nil?
|
||||||
|
query = Sale.select("distinct b.id as account_id, b.title as title")
|
||||||
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||||
|
.joins("JOIN accounts as b ON b.id = a.account_id")
|
||||||
|
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to)
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.select("distinct b.id as account_id, b.title as title")
|
||||||
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||||
|
.joins("JOIN accounts as b ON b.id = a.account_id")
|
||||||
|
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to)
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.select("distinct b.id as account_id, b.title as title")
|
||||||
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||||
|
.joins("JOIN accounts as b ON b.id = a.account_id")
|
||||||
|
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and sales.shift_sale_id=?',from,to,shift.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if current_user.nil?
|
||||||
query = Sale.select("distinct b.id as account_id, b.title as title")
|
query = Sale.select("distinct b.id as account_id, b.title as title")
|
||||||
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||||
.joins("JOIN accounts as b ON b.id = a.account_id")
|
.joins("JOIN accounts as b ON b.id = a.account_id")
|
||||||
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.select("distinct b.id as account_id, b.title as title")
|
||||||
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||||
|
.joins("JOIN accounts as b ON b.id = a.account_id")
|
||||||
|
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.select("distinct b.id as account_id, b.title as title")
|
||||||
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||||
|
.joins("JOIN accounts as b ON b.id = a.account_id")
|
||||||
|
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.account_data(account_id, today)
|
def self.account_data(account_id, today, current_user=nil,from,to)
|
||||||
|
if !from.nil? && !to.nil?
|
||||||
|
if current_user.nil?
|
||||||
|
query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc")
|
||||||
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||||
|
.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and sales.receipt_date between ? and ?",from,to)
|
||||||
|
.first()
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc")
|
||||||
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||||
|
.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and sales.receipt_date between ? and ?",from,to)
|
||||||
|
.first()
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc")
|
||||||
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||||
|
.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and sales.receipt_date between ? and ? and sales.shift_sale_id=?",from,to,shift.id)
|
||||||
|
.first()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if current_user.nil?
|
||||||
query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc")
|
query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc")
|
||||||
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||||
.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
|
.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
|
||||||
.first()
|
.first()
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc")
|
||||||
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||||
|
.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
|
||||||
|
.first()
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc")
|
||||||
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||||
|
.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? and sales.shift_sale_id=?",today,shift.id)
|
||||||
|
.first()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.top_items(today)
|
def self.top_items(today,current_user=nil,from,to)
|
||||||
|
if !from.nil? && !to.nil?
|
||||||
|
if current_user.nil?
|
||||||
|
query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price")
|
||||||
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||||
|
.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and sales.receipt_date between ? and ?",from,to)
|
||||||
|
.group("a.product_code")
|
||||||
|
.order("SUM(a.qty) DESC")
|
||||||
|
.first()
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price")
|
||||||
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||||
|
.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and sales.receipt_date between ? and ?",from,to)
|
||||||
|
.group("a.product_code")
|
||||||
|
.order("SUM(a.qty) DESC")
|
||||||
|
.first()
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price")
|
||||||
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||||
|
.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and sales.receipt_date between ? and ? and sales.shift_sale_id=?",from,to,shift.id)
|
||||||
|
.group("a.product_code")
|
||||||
|
.order("SUM(a.qty) DESC")
|
||||||
|
.first()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if current_user.nil?
|
||||||
query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price")
|
query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price")
|
||||||
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||||
.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
|
.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
|
||||||
.group("a.product_code")
|
.group("a.product_code")
|
||||||
.order("SUM(a.qty) DESC")
|
.order("SUM(a.qty) DESC")
|
||||||
.first()
|
.first()
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price")
|
||||||
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||||
|
.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
|
||||||
|
.group("a.product_code")
|
||||||
|
.order("SUM(a.qty) DESC")
|
||||||
|
.first()
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price")
|
||||||
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||||
|
.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? and sales.shift_sale_id=?",today,shift.id)
|
||||||
|
.group("a.product_code")
|
||||||
|
.order("SUM(a.qty) DESC")
|
||||||
|
.first()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.total_foc_items(today)
|
def self.total_foc_items(today,current_user=nil,from,to)
|
||||||
|
if !from.nil? && !to.nil?
|
||||||
|
if current_user.nil?
|
||||||
|
query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||||
|
.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and sales.receipt_date between ? and ?",from,to)
|
||||||
|
.sum("a.qty")
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||||
|
.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and sales.receipt_date between ? and ?",from,to)
|
||||||
|
.sum("a.qty")
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||||
|
.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and sales.receipt_date between ? and ? and sales.shift_sale_id=?",from,to,shift.id)
|
||||||
|
.sum("a.qty")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if current_user.nil?
|
||||||
query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||||
.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
|
.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
|
||||||
.sum("a.qty")
|
.sum("a.qty")
|
||||||
|
else
|
||||||
|
if current_user.role == 'administrator'
|
||||||
|
query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||||
|
.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
|
||||||
|
.sum("a.qty")
|
||||||
|
else
|
||||||
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
|
if !shift.nil?
|
||||||
|
query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||||
|
.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? and sales.shift_sale_id=?",today,shift.id)
|
||||||
|
.sum("a.qty")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#card sale trans data
|
#card sale trans data
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="block-header">
|
<div class="block-header">
|
||||||
<h2><%= t :dashboard %></h2>
|
<!-- <h2><%= t :dashboard %></h2> -->
|
||||||
|
<h2><%= t :date_time %> : <%= Time.zone.now.utc.getlocal.strftime("%Y-%m-%d %I:%M %p") %></h2>
|
||||||
</div>
|
</div>
|
||||||
<% if @print_settings.precision.to_i > 0
|
<% if @print_settings.precision.to_i > 0
|
||||||
precision = @print_settings.precision
|
precision = @print_settings.precision
|
||||||
@@ -65,8 +66,28 @@
|
|||||||
<!-- #END# Widgets -->
|
<!-- #END# Widgets -->
|
||||||
<!-- CPU Usage -->
|
<!-- CPU Usage -->
|
||||||
|
|
||||||
<% if current_user.role == 'administrator' || current_user.role == 'manager' %>
|
<!-- Date range for dashboard -->
|
||||||
|
<div class="row clearfix">
|
||||||
|
<div class="col-lg-4 col-md-4 col-sm-4">
|
||||||
|
<label class="font-14"><%= t("views.right_panel.detail.from") %></label>
|
||||||
|
<input data-behaviour='datepicker' class="form-control datepicker" name="from" id="from" type="text" value="<%= Time.now.utc.strftime('%d-%m-%Y') %>" placeholder="From date" style="height: 35px;">
|
||||||
|
<span id="fromErr" style="color:red;"></span>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-4 col-md-4 col-sm-4">
|
||||||
|
<label class="font-14"><%= t("views.right_panel.detail.to") %></label>
|
||||||
|
<input data-behaviour='datepicker' class="form-control datepicker" name="to" id="to" type="text" value="<%= Time.now.utc.strftime('%d-%m-%Y') %>" placeholder="To date" style="height: 35px;">
|
||||||
|
<span id="toErr" style="color:red;"></span>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-2 col-md-2 col-sm-2">
|
||||||
|
<label></label><br>
|
||||||
|
<input type="button" value="Generate" class='btn btn-primary btn_generate'>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<!-- Date range for dashboard -->
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
<% if current_user.role == 'administrator' || current_user.role == 'manager' %>
|
||||||
<div class="col-xs-8 col-sm-8 col-md-8 col-lg-8">
|
<div class="col-xs-8 col-sm-8 col-md-8 col-lg-8">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
|
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
|
||||||
@@ -122,10 +143,18 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
|
<% end %>
|
||||||
|
<% if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'cashier' %>
|
||||||
<% if !@summ_sale.nil? %>
|
<% if !@summ_sale.nil? %>
|
||||||
|
<% if current_user.role == 'administrator' || current_user.role == 'manager' %>
|
||||||
|
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
|
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
|
||||||
|
<% else %>
|
||||||
|
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
|
||||||
|
<% end %>
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="body">
|
<div class="body">
|
||||||
<h6><%= t :sale %></h6>
|
<h6><%= t :sale %></h6>
|
||||||
@@ -136,19 +165,19 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= t("views.right_panel.detail.total") %> <%= t :sale %> : </td>
|
<td><%= t("views.right_panel.detail.total") %> <%= t :sale %> : </td>
|
||||||
<td align="right"><%= number_with_precision( @summ_sale.total_amount, precision: precision.to_i ,delimiter: delimiter) %></td>
|
<td align="right"><%= number_with_precision( @summ_sale.total_amount, precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.discount") %> : </td>
|
<td><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.discount") %> : </td>
|
||||||
<td align="right"><%= number_with_precision( @summ_sale.total_discount, precision: precision.to_i ,delimiter: delimiter) %></td>
|
<td align="right"><%= number_with_precision( @summ_sale.total_discount, precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %> : </td>
|
<td><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %> : </td>
|
||||||
<td align="right"><%= number_with_precision( @summ_sale.total_tax , precision: precision.to_i ,delimiter: delimiter)%></td>
|
<td align="right"><%= number_with_precision( @summ_sale.total_tax , precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= t("views.right_panel.detail.grand_total") %> : </td>
|
<td><%= t("views.right_panel.detail.grand_total") %> : </td>
|
||||||
<td align="right"><%= number_with_precision( @summ_sale.grand_total , precision: precision.to_i ,delimiter: delimiter)%></td>
|
<td align="right"><%= number_with_precision( @summ_sale.grand_total , precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
@@ -161,7 +190,7 @@
|
|||||||
<td align="right">
|
<td align="right">
|
||||||
<% @sale_data.each do |data| %>
|
<% @sale_data.each do |data| %>
|
||||||
<% pay_mth = payment.payment_method %>
|
<% pay_mth = payment.payment_method %>
|
||||||
<%= data[""+pay_mth+""] %>
|
<%= number_with_precision(data[""+pay_mth+""], precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -174,7 +203,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td><%= t("views.right_panel.detail.card_sale") %> : </td>
|
<td><%= t("views.right_panel.detail.card_sale") %> : </td>
|
||||||
<td align="right">
|
<td align="right">
|
||||||
<%= total_card["card"].to_f %>
|
<%= number_with_precision(total_card["card"], precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -184,11 +213,17 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<% if current_user.role == 'administrator' || current_user.role == 'manager' %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% if current_user.role == 'administrator' || current_user.role == 'manager' %>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
|
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
|
||||||
|
<% else %>
|
||||||
|
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
|
||||||
|
<% end %>
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="body">
|
<div class="body">
|
||||||
<h6><%= t :customer %></h6>
|
<h6><%= t :customer %></h6>
|
||||||
@@ -227,10 +262,16 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<% if current_user.role == 'administrator' || current_user.role == 'manager' %>
|
||||||
</div>
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% if current_user.role == 'administrator' || current_user.role == 'manager' %>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
|
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
|
||||||
|
<% else %>
|
||||||
|
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
|
||||||
|
<% end %>
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="body">
|
<div class="body">
|
||||||
<h6><%= t("views.right_panel.detail.order") %></h6>
|
<h6><%= t("views.right_panel.detail.order") %></h6>
|
||||||
@@ -274,6 +315,41 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(document).ready(function(){
|
||||||
|
var from = '<%= @from.strftime('%d-%m-%Y') rescue '' %>';
|
||||||
|
var to = '<%= @to.strftime('%d-%m-%Y') rescue '' %>';
|
||||||
|
|
||||||
|
if((from!=undefined) && (from != null) && (from != '')){
|
||||||
|
$('#from').val(from);
|
||||||
|
}
|
||||||
|
if((to!=undefined) && (to != null) && (to != '')){
|
||||||
|
$('#to').val(to);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.btn_generate').on('click',function(){
|
||||||
|
var from = $("#from").val();
|
||||||
|
var to = $("#to").val();
|
||||||
|
if((from=='') && (to=='')){
|
||||||
|
$('#fromErr').html("can't be blank");
|
||||||
|
$('#toErr').html("can't be blank");
|
||||||
|
}else if((from!='') && (to=='')){
|
||||||
|
$('#fromErr').html("");
|
||||||
|
$('#toErr').html("can't be blank");
|
||||||
|
}else if((from=='') && (to!='')){
|
||||||
|
$('#fromErr').html("can't be blank");
|
||||||
|
$('#toErr').html("");
|
||||||
|
}else{
|
||||||
|
$('#fromErr').html("");
|
||||||
|
$('#toErr').html("");
|
||||||
|
}
|
||||||
|
if((from!='') && (to!='')){
|
||||||
|
window.location.href = '/dashboard?from='+from+'&to='+to;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
113
app/views/reports/product_sale/index.html.erb
Executable file
113
app/views/reports/product_sale/index.html.erb
Executable file
@@ -0,0 +1,113 @@
|
|||||||
|
<div class="page-header">
|
||||||
|
<ol class="breadcrumb">
|
||||||
|
<li class="breadcrumb-item"><a href="<%= dashboard_path %>"><%= t("views.right_panel.button.home") %></a></li>
|
||||||
|
<li class="breadcrumb-item active"><%= t("views.right_panel.detail.sale_item_report") %></li>
|
||||||
|
<span class="float-right">
|
||||||
|
<%= link_to 'Back', dashboard_path %>
|
||||||
|
</span>
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="text-right">
|
||||||
|
<a href="javascript:export_to('<%=reports_product_sale_index_path%>.xls')" class = "btn btn-info wave-effects "><%= t("views.btn.exp_to_excel") %></a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="margin-top-20">
|
||||||
|
<div class="card">
|
||||||
|
<div class="p-l-20 p-t-20 p-b-20">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label class="font-16" for="order_by">Order by Qty</label>
|
||||||
|
<select name="order_by" id="order_by" class="form-control" style="width:10%">
|
||||||
|
<option value="asc">ASC</option>
|
||||||
|
<option value="desc">DESC</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="table-responsive">
|
||||||
|
<% 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 %>
|
||||||
|
<table class="table table-striped" id="items_table" border="0">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th> </th>
|
||||||
|
<th><%= t("views.right_panel.header.menu_category") %></th>
|
||||||
|
<th><%= t("views.right_panel.detail.code") %></th>
|
||||||
|
<th><%= t("views.right_panel.detail.product") %></th>
|
||||||
|
<th><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %></th>
|
||||||
|
<th><%= t("views.right_panel.detail.unit_price") %></th>
|
||||||
|
<th><%= t("views.right_panel.detail.total") %></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="tbd_data">
|
||||||
|
<% unless @sale_data.blank? %>
|
||||||
|
<% acc_arr = Array.new %>
|
||||||
|
<% cate_arr = Array.new %>
|
||||||
|
|
||||||
|
<% grand_total = 0 %>
|
||||||
|
<% total_qty = 0 %>
|
||||||
|
|
||||||
|
<% @sale_data.each do |sale| %>
|
||||||
|
<% if sale.status_type != "Discount" && sale.status_type != "foc"
|
||||||
|
total_qty += sale.total_item
|
||||||
|
grand_total += sale.grand_total
|
||||||
|
end %>
|
||||||
|
<% if sale.status_type == "foc" && sale.price > 0
|
||||||
|
total_qty += sale.total_item
|
||||||
|
grand_total += sale.grand_total
|
||||||
|
end %>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td> </td>
|
||||||
|
<% if !cate_arr.include?(sale.menu_category_id) %>
|
||||||
|
<td><%= sale.menu_category_name %></td>
|
||||||
|
<% cate_arr.push(sale.menu_category_id) %>
|
||||||
|
<% else %>
|
||||||
|
<td> </td>
|
||||||
|
<% end %>
|
||||||
|
<td><%= sale.item_code rescue '-' %></td>
|
||||||
|
<td><%= sale.product_name rescue '-' %></td>
|
||||||
|
<td><%= sale.total_item rescue '-' %></td>
|
||||||
|
<td><%= number_with_precision(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||||
|
<td><%= number_with_precision(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %></td>
|
||||||
|
</tr>
|
||||||
|
<!-- sub total -->
|
||||||
|
<!-- end sub total -->
|
||||||
|
<% end %>
|
||||||
|
<tr>
|
||||||
|
<td colspan="3"></td>
|
||||||
|
<td><strong>Total</strong></td>
|
||||||
|
<td><strong><%= total_qty %></strong></td>
|
||||||
|
<td></td>
|
||||||
|
<td><strong><%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %></strong></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(function(){
|
||||||
|
$('#order_by').val('<%= @order_by %>');
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#order_by').on('change', function(){
|
||||||
|
var order_by = $("#order_by").val();
|
||||||
|
window.location.href = "?order_by=" + order_by;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
64
app/views/reports/product_sale/index.xls.erb
Executable file
64
app/views/reports/product_sale/index.xls.erb
Executable file
@@ -0,0 +1,64 @@
|
|||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="margin-top-20">
|
||||||
|
<div class="card">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped" id="items_table" border="0">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th> </th>
|
||||||
|
<th><%= t("views.right_panel.header.menu_category") %></th>
|
||||||
|
<th><%= t("views.right_panel.detail.code") %></th>
|
||||||
|
<th><%= t("views.right_panel.detail.product") %></th>
|
||||||
|
<th><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %></th>
|
||||||
|
<th><%= t("views.right_panel.detail.unit_price") %></th>
|
||||||
|
<th><%= t("views.right_panel.detail.total") %></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% unless @sale_data.blank? %>
|
||||||
|
<% acc_arr = Array.new %>
|
||||||
|
<% cate_arr = Array.new %>
|
||||||
|
<% grand_total = 0 %>
|
||||||
|
<% total_qty = 0 %>
|
||||||
|
|
||||||
|
<% @sale_data.each do |sale| %>
|
||||||
|
<% if sale.status_type != "Discount" && sale.status_type != "foc"
|
||||||
|
total_qty += sale.total_item
|
||||||
|
grand_total += sale.grand_total
|
||||||
|
end %>
|
||||||
|
<% if sale.status_type == "foc" && sale.price > 0
|
||||||
|
total_qty += sale.total_item
|
||||||
|
grand_total += sale.grand_total
|
||||||
|
end %>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td> </td>
|
||||||
|
<% if !cate_arr.include?(sale.menu_category_id) %>
|
||||||
|
<td><%= sale.menu_category_name %></td>
|
||||||
|
<% cate_arr.push(sale.menu_category_id) %>
|
||||||
|
<% else %>
|
||||||
|
<td> </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>
|
||||||
|
<% end %>
|
||||||
|
<tr>
|
||||||
|
<td colspan="3"></td>
|
||||||
|
<td><strong>Total</strong></td>
|
||||||
|
<td><strong><%= total_qty %></strong></td>
|
||||||
|
<td></td>
|
||||||
|
<td><strong><%= grand_total rescue '-' %></strong></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -373,6 +373,7 @@ scope "(:locale)", locale: /en|mm/ do
|
|||||||
resources :commission, :only => [:index, :show]
|
resources :commission, :only => [:index, :show]
|
||||||
resources :stock_check, :only => [:index, :show]
|
resources :stock_check, :only => [:index, :show]
|
||||||
resources :payment_method
|
resources :payment_method
|
||||||
|
resources :product_sale, :only => [:index, :show]
|
||||||
|
|
||||||
get "receipt_no/get_shift_by_date", to: "receipt_no#get_shift_by_date", as: "get_shift_by_date"
|
get "receipt_no/get_shift_by_date", to: "receipt_no#get_shift_by_date", as: "get_shift_by_date"
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user