shop code filter for all reports and transactions

This commit is contained in:
Myat Zin Wai Maw
2019-11-26 12:06:52 +06:30
parent d1ab2c194d
commit 5dd4c6e7b6
26 changed files with 281 additions and 260 deletions

View File

@@ -98,7 +98,7 @@ class Origami::ShiftsController < BaseOrigamiController
other_charges = Sale.get_other_charges() other_charges = Sale.get_other_charges()
@total_other_charges_info = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",@shift) @total_other_charges_info = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",@shift)
end end
@sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='') @sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='').where("sales.shop_code='#{@shop.shop_code}'")
@total_waste = Sale.get_total_waste(shift_id).sum(:grand_total) @total_waste = Sale.get_total_waste(shift_id).sum(:grand_total)
@total_spoile = Sale.get_total_spoile(shift_id).sum(:grand_total) @total_spoile = Sale.get_total_spoile(shift_id).sum(:grand_total)
#other payment details for mpu or visa like card #other payment details for mpu or visa like card
@@ -143,7 +143,7 @@ class Origami::ShiftsController < BaseOrigamiController
if @shift if @shift
#get tax #get tax
shift_obj = ShiftSale.where('id =?',@shift.id) shift_obj = ShiftSale.where('id =?',@shift.id)
@sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='') @sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='').where("sales.shop_code='#{@shop.shop_code}'")
#other payment details for mpu or visa like card #other payment details for mpu or visa like card
@other_payment = ShiftSale.get_by_shift_other_payment(@shift) @other_payment = ShiftSale.get_by_shift_other_payment(@shift)

View File

@@ -2,21 +2,14 @@ class Reports::CommissionController < BaseReportController
# authorize_resource :class => false # authorize_resource :class => false
def index def index
# from_date = DateTime.now.beginning_of_day.utc.getlocal
# to_date = DateTime.now.end_of_day.utc.getlocal
# unless params[:daterange].blank?
# from_date = Date.parse(params[:daterange].split(' - ')[0]).beginning_of_day.utc.getlocal
# to_date = Date.parse(params[:daterange].split(' - ')[1]).end_of_day.utc.getlocal
# @daterange = params[:daterange]
# end
from_date, to_date = get_date_range_from_params from_date, to_date = get_date_range_from_params
commissioner = params[:commissioner].to_i commissioner = params[:commissioner].to_i
@com_id = commissioner @com_id = commissioner
@commissioner = Commissioner.active.all @commissioner = Commissioner.active.where("shop_code='#{@shop.shop_code}'")
@transaction = ProductCommission.get_transaction(from_date, to_date, commissioner) @transaction = ProductCommission.get_transaction(from_date, to_date, commissioner)
@from = from_date @from = from_date
@to = to_date @to = to_date
# get printer info # get printer info
@@ -30,7 +23,7 @@ class Reports::CommissionController < BaseReportController
def show def show
from, to = get_date_range_from_params from, to = get_date_range_from_params
@sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) @sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'")
date_arr = Array.new date_arr = Array.new
@sale_data.each do |sale| @sale_data.each do |sale|
@@ -49,6 +42,5 @@ class Reports::CommissionController < BaseReportController
format.json { render json: out } format.json { render json: out }
end end
end end
end
end

View File

@@ -1,27 +1,27 @@
class Reports::CreditPaymentController < BaseReportController class Reports::CreditPaymentController < BaseReportController
authorize_resource :class => false authorize_resource :class => false
def index def index
@filter_for_credit = [['All',''],['Paid','paid'],['Unpaid','unpaid']] @filter_for_credit = [['All',''],['Paid','paid'],['Unpaid','unpaid']]
@sources = [["All",''], ["Cashier","cashier"],["Quick Service","quick_service"],["Online Order","doemal_order"]] @sources = [["All",''], ["Cashier","cashier"],["Quick Service","quick_service"],["Online Order","doemal_order"]]
from, to = get_date_range_from_params from, to = get_date_range_from_params
@shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'")
@shift = '' @shift = ''
if params[:shift_name].to_i != 0 if params[:shift_name].to_i != 0
shift_sale = ShiftSale.find(params[:shift_name]) shift_sale = ShiftSale.find(params[:shift_name])
if to.blank? if to.blank?
@shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL and shop_code='#{@shop.shop_code}'",shift_sale.shift_started_at)
else else
@shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at = ? and shop_code='#{@shop.shop_code}'",shift_sale.shift_started_at, shift_sale.shift_closed_at)
end end
end end
@filter = params[:filter_check] @filter = params[:filter_check]
@order_source = params[:order_source] @order_source = params[:order_source]
@sale_data = Sale.get_by_shift_sale_credit_payment(@shift_sale_range,@shift,from,to,@filter,@order_source) @sale_data = Sale.get_by_shift_sale_credit_payment(@shift_sale_range,@shift,from,to,@filter,@order_source,@shop.shop_code)
@from = from @from = from
@to = to @to = to
@@ -58,10 +58,10 @@ authorize_resource :class => false
end end
out = {:status => 'ok', :message => date_arr} out = {:status => 'ok', :message => date_arr}
respond_to do |format| respond_to do |format|
format.json { render json: out } format.json { render json: out }
end end
end end
end end

View File

@@ -3,11 +3,11 @@ class Reports::DailysaleController < BaseReportController
def index def index
from, to = get_date_range_from_params from, to = get_date_range_from_params
@sale_data = Sale.daily_sales_list(from,to) @sale_data = Sale.daily_sales_list(from,to,@shop.shop_code)
@tax = SaleTax.get_tax(from,to) @tax = SaleTax.get_tax(from,to,@shop.shop_code)
@from = from @from = from
@to = to @to = to
@payment_methods = PaymentMethodSetting.where("is_active='1'").pluck("payment_method") @payment_methods = PaymentMethodSetting.where("is_active='1' and shop_code='#{@shop.shop_code}'").pluck("payment_method")
# get printer info # get printer info

View File

@@ -2,7 +2,7 @@ class Reports::HourlySaleitemController < BaseReportController
authorize_resource :class => false authorize_resource :class => false
def index def index
@account = Account.all @account = Account.where("shop_code='#{@shop.shop_code}'")
from, to = get_date_range_from_params from, to = get_date_range_from_params
shift_sale_range = '' shift_sale_range = ''
@@ -10,25 +10,25 @@ class Reports::HourlySaleitemController < BaseReportController
shift = '' shift = ''
if params[:shift_name].to_i != 0 if params[:shift_name].to_i != 0
shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'")
shift_sale = ShiftSale.find(params[:shift_name]) shift_sale = ShiftSale.find(params[:shift_name])
if to.blank? if to.blank?
shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL and shop_code='#{@shop.shop_code}'",shift_sale.shift_started_at)
else else
if shift_sale.shift_closed_at.blank? if shift_sale.shift_closed_at.blank?
shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL',shift_sale.shift_started_at) shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL and shop_code='#{@shop.shop_code}'",shift_sale.shift_started_at)
else else
shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) shift = ShiftSale.where("shift_started_at = ? and shift_closed_at = ? and shop_code='#{@shop.shop_code}'",shift_sale.shift_started_at, shift_sale.shift_closed_at)
end end
end end
end end
account_type = params[:account_type] account_type = params[:account_type]
@type = params[:sale_type] @type = params[:sale_type]
@sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_hourly_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type) @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_hourly_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type,@shop.shop_code)
@sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil) @sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil).where("sales.shop_code='#{@shop.shop_code}'")
@account_cate_count = Hash.new {|hash, key| hash[key] = 0} @account_cate_count = Hash.new {|hash, key| hash[key] = 0}
@sale_data.each {|acc_cate| @account_cate_count[acc_cate.account_id] += 1} @sale_data.each {|acc_cate| @account_cate_count[acc_cate.account_id] += 1}
@@ -57,7 +57,7 @@ class Reports::HourlySaleitemController < BaseReportController
# @hourly_total_qty = @sale_data.group_by {|s| s.date_format }.collect{|key,qty| {"date" => key , "total_qty" => qty.sum{|d| d.qty.to_i}}} # @hourly_total_qty = @sale_data.group_by {|s| s.date_format }.collect{|key,qty| {"date" => key , "total_qty" => qty.sum{|d| d.qty.to_i}}}
@hourly_total_qty = @sale_data.group_by(&:date_format).map { |k,v|{"date" => k , "total_qty" => v.count }} @hourly_total_qty = @sale_data.group_by(&:date_format).map { |k,v|{"date" => k , "total_qty" => v.count }}
respond_to do |format| respond_to do |format|
format.html format.html
format.xls format.xls

View File

@@ -1,25 +1,25 @@
class Reports::IndutyController < BaseReportController class Reports::IndutyController < BaseReportController
authorize_resource :class => false authorize_resource :class => false
def index def index
@commissioners = Commissioner.all #.where("is_active='1'") @commissioners = Commissioner.where("shop_code='#{@shop.shop_code}'") #.where("is_active='1'")
from, to = get_date_range_from_params from, to = get_date_range_from_params
@shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'")
@shift = '' @shift = ''
if params[:shift_name].to_i != 0 if params[:shift_name].to_i != 0
shift_sale = ShiftSale.find(params[:shift_name]) shift_sale = ShiftSale.find(params[:shift_name])
if to.blank? if to.blank?
@shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL and shop_code='#{@shop.shop_code}' ",shift_sale.shift_started_at)
else else
@shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at = ? and shop_code='#{@shop.shop_code}' ",shift_sale.shift_started_at, shift_sale.shift_closed_at)
end end
end end
@commissioner = params[:commissioner] @commissioner = params[:commissioner]
@induty_data = InDuty.get_induty_by_shift(@shift_sale_range,@shift,from,to,@commissioner) @induty_data = InDuty.get_induty_by_shift(@shift_sale_range,@shift,from,to,@commissioner).where("sales.shop_code='#{@shop.shop_code}'")
@from = from @from = from
@to = to @to = to
@@ -43,9 +43,9 @@ class Reports::IndutyController < BaseReportController
def show def show
from, to = get_date_range_from_params from, to = get_date_range_from_params
@induty_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) @induty_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'")
@commissioner = params[:commissioner] @commissioner = params[:commissioner]
date_arr = Array.new date_arr = Array.new
@induty_data.each do |induty| @induty_data.each do |induty|
local_opening_date = induty.opening_date.nil? ? '-' : induty.opening_date.utc.getlocal.strftime("%e %b %I:%M%p") local_opening_date = induty.opening_date.nil? ? '-' : induty.opening_date.utc.getlocal.strftime("%e %b %I:%M%p")
@@ -58,7 +58,7 @@ class Reports::IndutyController < BaseReportController
end end
out = {:status => 'ok', :message => date_arr} out = {:status => 'ok', :message => date_arr}
respond_to do |format| respond_to do |format|
format.json { render json: out } format.json { render json: out }
end end

View File

@@ -1,4 +1,4 @@
class Reports::OrderReservationController < BaseReportController class Reports::OrderReservationController < BaseReportController
# authorize_resource :class => false # authorize_resource :class => false
def index def index
@providers = [["All",''], ["Direct Delivery","direct_delivery"],["Pick-Up","pick_up"],["TURBO","turbo"],["food2u","food2u"], ["ygndoor2door","ygndoor2door"]] @providers = [["All",''], ["Direct Delivery","direct_delivery"],["Pick-Up","pick_up"],["TURBO","turbo"],["food2u","food2u"], ["ygndoor2door","ygndoor2door"]]
@@ -11,23 +11,23 @@ class Reports::OrderReservationController < BaseReportController
@shift = '' @shift = ''
if params[:shift_name].to_i != 0 if params[:shift_name].to_i != 0
@shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'")
shift_sale = ShiftSale.find(params[:shift_name]) shift_sale = ShiftSale.find(params[:shift_name])
if to.blank? if to.blank?
@shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL and shop_code='#{@shop.shop_code}'",shift_sale.shift_started_at)
else else
if shift_sale.shift_closed_at.blank? if shift_sale.shift_closed_at.blank?
@shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL',shift_sale.shift_started_at) @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL and shop_code='#{@shop.shop_code}'",shift_sale.shift_started_at)
else else
@shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at = ? and shop_code='#{@shop.shop_code}'",shift_sale.shift_started_at, shift_sale.shift_closed_at)
end end
end end
end end
provider = params[:provider] provider = params[:provider]
payment_type = params[:payment_type] payment_type = params[:payment_type]
@order_reservation_data = OrderReservation.get_order_reservation_by_shift(@shift_sale_range,@shift,from,to,provider,payment_type) @order_reservation_data = OrderReservation.get_order_reservation_by_shift(@shift_sale_range,@shift,from,to,provider,payment_type).where("sales.shop_code='#{@shop.shop_code}'")
@from = from @from = from
@to = to @to = to
# get printer info # get printer info
@@ -49,7 +49,7 @@ class Reports::OrderReservationController < BaseReportController
def show def show
from, to = get_date_range_from_params from, to = get_date_range_from_params
@sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'")
date_arr = Array.new date_arr = Array.new
@sale_data.each do |sale| @sale_data.each do |sale|
@@ -63,10 +63,10 @@ class Reports::OrderReservationController < BaseReportController
end end
out = {:status => 'ok', :message => date_arr} out = {:status => 'ok', :message => date_arr}
respond_to do |format| respond_to do |format|
format.json { render json: out } format.json { render json: out }
end end
end end
end end

View File

@@ -1,28 +1,28 @@
class Reports::PaymentMethodController < BaseReportController class Reports::PaymentMethodController < BaseReportController
# authorize_resource :class => false # authorize_resource :class => false
def index def index
@payments = [["All Payment",''],["Cash Payment","cash"], ["KBZ Payment", KbzPay::KBZ_PAY], ["Credit Payment","creditnote"], @payments = [["All Payment",''],["Cash Payment","cash"], ["KBZ Payment", KbzPay::KBZ_PAY], ["Credit Payment","creditnote"],
["FOC Payment","foc"], ["MPU Payment","mpu"], ["Visa Payment","visa"], ["FOC Payment","foc"], ["MPU Payment","mpu"], ["Visa Payment","visa"],
["Master Payment","master"], ["JCB Payment","jcb"],["UnionPay Payment","unionpay"], ["Master Payment","master"], ["JCB Payment","jcb"],["UnionPay Payment","unionpay"],
["Alipay Payment","alipay"],["Paymal Payment", "paymal"],["Dinga Payment","dinga"], ["Alipay Payment","alipay"],["Paymal Payment", "paymal"],["Dinga Payment","dinga"],
["JunctionPay","junctionpay"],["Redeem Payment","paypar"],["Gift Voucher","giftvoucher"]] ["JunctionPay","junctionpay"],["Redeem Payment","paypar"],["Gift Voucher","giftvoucher"]]
from, to = get_date_range_from_params from, to = get_date_range_from_params
@shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'")
@shift = '' @shift = ''
if params[:shift_name].to_i != 0 if params[:shift_name].to_i != 0
shift_sale = ShiftSale.find(params[:shift_name]) shift_sale = ShiftSale.find(params[:shift_name])
if to.blank? if to.blank?
@shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL and shop_code='#{@shop.shop_code}'",shift_sale.shift_started_at)
else else
@shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at = ? and shop_code='#{@shop.shop_code}'",shift_sale.shift_started_at, shift_sale.shift_closed_at)
end end
end end
@payment_type = params[:payment_type] @payment_type = params[:payment_type]
@sale_data,@pyament_method = Sale.get_payment_method_by_shift(@shift_sale_range,@shift,from,to,@payment_type) @sale_data,@pyament_method = Sale.get_payment_method_by_shift(@shift_sale_range,@shift,from,to,@payment_type,@shop.shop_code)
@from = from @from = from
@to = to @to = to
# get printer info # get printer info
@@ -44,7 +44,7 @@ class Reports::PaymentMethodController < BaseReportController
def show def show
from, to = get_date_range_from_params from, to = get_date_range_from_params
@sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) @sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'")
date_arr = Array.new date_arr = Array.new
@sale_data.each do |sale| @sale_data.each do |sale|
@@ -58,10 +58,10 @@ class Reports::PaymentMethodController < BaseReportController
end end
out = {:status => 'ok', :message => date_arr} out = {:status => 'ok', :message => date_arr}
respond_to do |format| respond_to do |format|
format.json { render json: out } format.json { render json: out }
end end
end end
end end

View File

@@ -2,7 +2,7 @@ class Reports::ReceiptNoController < BaseReportController
authorize_resource :class => false authorize_resource :class => false
def index def index
@payments = [["All Payment",''], ["Cash Payment","cash"], ["Credit Payment","creditnote"], ["FOC Payment","foc"]] @payments = [["All Payment",''], ["Cash Payment","cash"], ["Credit Payment","creditnote"], ["FOC Payment","foc"]]
@payment_method = PaymentMethodSetting.all @payment_method = PaymentMethodSetting.where("shop_code='#{@shop.shop_code}'")
from, to = get_date_range_from_params from, to = get_date_range_from_params
@shift_sale_range = '' @shift_sale_range = ''
@@ -10,16 +10,16 @@ authorize_resource :class => false
@shift = '' @shift = ''
if params[:shift_name].to_i != 0 if params[:shift_name].to_i != 0
@shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'")
@shift_sale = ShiftSale.find(params[:shift_name]) @shift_sale = ShiftSale.find(params[:shift_name])
if to.blank? if to.blank?
@shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',@shift_sale.shift_started_at) @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL and shop_code='#{@shop.shop_code}'",@shift_sale.shift_started_at)
else else
if @shift_sale.shift_closed_at.blank? if @shift_sale.shift_closed_at.blank?
@shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL',@shift_sale.shift_started_at) @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL and shop_code='#{@shop.shop_code}'",@shift_sale.shift_started_at)
else else
@shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',@shift_sale.shift_started_at, @shift_sale.shift_closed_at) @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at = ? and shop_code='#{@shop.shop_code}' ",@shift_sale.shift_started_at, @shift_sale.shift_closed_at)
end end
end end
end end
@@ -30,9 +30,9 @@ authorize_resource :class => false
end end
payment_type = params[:payment_type] payment_type = params[:payment_type]
@sale_data = Sale.get_shift_sales_by_receipt_no(@shift_sale_range,@shift,from,to,payment_type) @sale_data = Sale.get_shift_sales_by_receipt_no(@shift_sale_range,@shift,from,to,payment_type).where("sales.shop_code='#{@shop.shop_code}'")
@sale_taxes = Sale.get_separate_tax(@shift_sale_range,@shift,from,to,payment_type) @sale_taxes = Sale.get_separate_tax(@shift_sale_range,@shift,from,to,payment_type).where("sales.shop_code='#{@shop.shop_code}'")
@tax_profiles = TaxProfile.group('name').order('order_by asc') #.limit(2) @tax_profiles = TaxProfile.where("shop_code='#{@shop.shop_code}'").group('name').order('order_by asc') #.limit(2)
@from = from @from = from
@to = to @to = to
@@ -55,7 +55,7 @@ authorize_resource :class => false
def show def show
from, to = get_date_range_from_params from, to = get_date_range_from_params
@sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'")
date_arr = Array.new date_arr = Array.new
@sale_data.each do |sale| @sale_data.each do |sale|

View File

@@ -1,8 +1,8 @@
class Reports::ReceiptNoDetailController < BaseReportController class Reports::ReceiptNoDetailController < BaseReportController
authorize_resource :class => false authorize_resource :class => false
def index def index
@payments = [["All Payment",''], ["Cash Payment","cash"], ["Credit Payment","creditnote"], ["FOC Payment","foc"]] @payments = [["All Payment",''], ["Cash Payment","cash"], ["Credit Payment","creditnote"], ["FOC Payment","foc"]]
@payment_method = PaymentMethodSetting.all @payment_method = PaymentMethodSetting.where("shop_code='#{@shop.shop_code}'")
from, to = get_date_range_from_params from, to = get_date_range_from_params
@shift_sale_range = '' @shift_sale_range = ''
@@ -10,22 +10,22 @@ authorize_resource :class => false
@shift = '' @shift = ''
if params[:shift_name].to_i != 0 if params[:shift_name].to_i != 0
@shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'")
@shift_sale = ShiftSale.find(params[:shift_name]) @shift_sale = ShiftSale.find(params[:shift_name])
if to.blank? if to.blank?
@shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',@shift_sale.shift_started_at) @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL and shop_code='#{@shop.shop_code}'",@shift_sale.shift_started_at)
else else
if @shift_sale.shift_closed_at.blank? if @shift_sale.shift_closed_at.blank?
@shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL',@shift_sale.shift_started_at) @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL and shop_code='#{@shop.shop_code}'",@shift_sale.shift_started_at)
else else
@shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',@shift_sale.shift_started_at, @shift_sale.shift_closed_at) @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at = ? and shop_code='#{@shop.shop_code}'",@shift_sale.shift_started_at, @shift_sale.shift_closed_at)
end end
end end
end end
payment_type = params[:payment_type] payment_type = params[:payment_type]
@sale_data = Sale.get_shift_sales_by_receipt_no_detail(@shift_sale_range,@shift,from,to,payment_type) @sale_data = Sale.get_shift_sales_by_receipt_no_detail(@shift_sale_range,@shift,from,to,payment_type).where("sales.shop_code='#{@shop.shop_code}'")
@from = from @from = from
@to = to @to = to
@@ -48,7 +48,7 @@ authorize_resource :class => false
def show def show
from, to = get_date_range_from_params from, to = get_date_range_from_params
@sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'")
date_arr = Array.new date_arr = Array.new
@sale_data.each do |sale| @sale_data.each do |sale|
@@ -62,10 +62,10 @@ authorize_resource :class => false
end end
out = {:status => 'ok', :message => date_arr} out = {:status => 'ok', :message => date_arr}
respond_to do |format| respond_to do |format|
format.json { render json: out } format.json { render json: out }
end end
end end
end end

View File

@@ -2,7 +2,7 @@ class Reports::SaleitemController < BaseReportController
authorize_resource :class => false authorize_resource :class => false
def index def index
@account = Account.all @account = Account.where("shop_code='#{@shop.shop_code}'")
from, to = get_date_range_from_params from, to = get_date_range_from_params
shift_sale_range = '' shift_sale_range = ''
@@ -10,26 +10,25 @@ class Reports::SaleitemController < BaseReportController
shift = '' shift = ''
if params[:shift_name].to_i != 0 if params[:shift_name].to_i != 0
shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'")
shift_sale = ShiftSale.find(params[:shift_name]) shift_sale = ShiftSale.find(params[:shift_name])
if to.blank? if to.blank?
shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL and shop_code='#{@shop.shop_code}' ",shift_sale.shift_started_at)
else else
if shift_sale.shift_closed_at.blank? if shift_sale.shift_closed_at.blank?
shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL',shift_sale.shift_started_at) shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL and shop_code='#{@shop.shop_code}'",shift_sale.shift_started_at)
else else
shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) shift = ShiftSale.where("shift_started_at = ? and shift_closed_at = ? and shop_code='#{@shop.shop_code}'",shift_sale.shift_started_at, shift_sale.shift_closed_at)
end end
end end
end end
account_type = params[:account_type] account_type = params[:account_type]
@type = params[:sale_type] @type = params[:sale_type]
@sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type) @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type,@shop.shop_code)
@sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil)
@sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil).where("sales.shop_code='#{@shop.shop_code}'")
@account_cate_count = Hash.new {|hash, key| hash[key] = 0} @account_cate_count = Hash.new {|hash, key| hash[key] = 0}
@sale_data.each {|acc_cate| @account_cate_count[acc_cate.account_id] += 1} @sale_data.each {|acc_cate| @account_cate_count[acc_cate.account_id] += 1}
@@ -62,7 +61,7 @@ class Reports::SaleitemController < BaseReportController
def show def show
from, to, report_type = get_date_range_from_params from, to, report_type = get_date_range_from_params
@sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'")
date_arr = Array.new date_arr = Array.new
@sale_data.each do |sale| @sale_data.each do |sale|
@@ -94,16 +93,16 @@ class Reports::SaleitemController < BaseReportController
shift_name = 'All Shift' shift_name = 'All Shift'
if params[:shift_name].to_i != 0 if params[:shift_name].to_i != 0
shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'")
shift_sale = ShiftSale.find(params[:shift_name]) shift_sale = ShiftSale.find(params[:shift_name])
if to.blank? if to.blank?
shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL and shop_code='#{@shop.shop_code}'",shift_sale.shift_started_at)
else else
if shift_sale.shift_closed_at.blank? if shift_sale.shift_closed_at.blank?
shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL',shift_sale.shift_started_at) shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL and shop_code='#{@shop.shop_code}'" ,shift_sale.shift_started_at)
else else
shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) shift = ShiftSale.where("shift_started_at = ? and shift_closed_at = ? and shop_code='#{@shop.shop_code}'",shift_sale.shift_started_at, shift_sale.shift_closed_at)
end end
end end
@@ -112,36 +111,30 @@ class Reports::SaleitemController < BaseReportController
shift_name = employee.nil? ? sh_name : "#{sh_name} (#{employee.name})" shift_name = employee.nil? ? sh_name : "#{sh_name} (#{employee.name})"
end end
shop_details = shop_detail
account_type = params[:account_type] account_type = params[:account_type]
@type = params[:period_type] @type = params[:period_type]
period_name = get_period_name(params[:period]) period_name = get_period_name(params[:period])
@sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type) @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type,@shop.shop_code)
other_charges = Sale.get_other_charges() other_charges = Sale.get_other_charges()
if shift.present? if shift.present?
@total_other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) @total_other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed' and sales.shop_code='#{@shop.shop_code}'",shift.to_a)
else else
@total_other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) @total_other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed' and sales.shop_code='#{@shop.shop_code}'",from,to)
end end
# get printer info # get printer info
print_settings = PrintSetting.find_by_unique_code('SaleItemsPdf') # SaleItemsPdf print_settings = PrintSetting.find_by_unique_code_and_shop_code('SaleItemsPdf',@shop.shop_code) # SaleItemsPdf
print_settings_star = PrintSetting.find_by_unique_code('SaleItemsStarPdf') print_settings_star = PrintSetting.find_by_unique_code_and_shop_code('SaleItemsStarPdf',@shop.shop_code)
# if print_settings.nil? && print_settings_star.nil?
# @print_setting = PrintSetting.new(name: "SaleItemsPdf", unique_code: "SaleItemsPdf", template: "",font: "Zawgyi-One", header_font_size: "10", item_font_size: "8", printer_name: "", api_settings: "", brand_name: nil, printer_type: nil, page_width: "210", page_height: "1450", print_copies: "1", precision: "0", delimiter: "0", heading_space: "5" )
# @print_setting.save
# end
if print_settings.nil? if print_settings.nil?
if !print_settings_star.nil? if !print_settings_star.nil?
printer = Printer::CashierStationPrinter.new(print_settings_star) printer = Printer::CashierStationPrinter.new(print_settings_star)
printer.print_sale_items_report(print_settings_star, shop_details, period_name, @type, account_type, from, to, shift_name, @sale_data, @total_other_charges) printer.print_sale_items_report(print_settings_star, @shop, period_name, @type, account_type, from, to, shift_name, @sale_data, @total_other_charges)
end end
else else
printer = Printer::CashierStationPrinter.new(print_settings) printer = Printer::CashierStationPrinter.new(print_settings)
printer.print_sale_items_report(print_settings, shop_details, period_name, @type, account_type, from, to, shift_name, @sale_data, @total_other_charges) printer.print_sale_items_report(print_settings, @shop, period_name, @type, account_type, from, to, shift_name, @sale_data, @total_other_charges)
end end
respond_to do |format| respond_to do |format|

View File

@@ -8,7 +8,7 @@ class Reports::ShiftsaleController < BaseReportController
if params[:shift_name].to_i != 0 if params[:shift_name].to_i != 0
@shift = ShiftSale.find(params[:shift_name]) @shift = ShiftSale.find(params[:shift_name])
end end
@sale_data = Sale.get_by_shiftsales(from,to,@shift) @sale_data = Sale.get_by_shiftsales(from,to,@shift,@shop.shop_code)
@from = from @from = from
@to = to @to = to
if @shift.present? if @shift.present?
@@ -28,7 +28,7 @@ class Reports::ShiftsaleController < BaseReportController
def show def show
from, to = get_date_range_from_params from, to = get_date_range_from_params
@sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'")
date_arr = Array.new date_arr = Array.new
@sale_data.each do |sale| @sale_data.each do |sale|
@@ -56,7 +56,7 @@ class Reports::ShiftsaleController < BaseReportController
if ENV["SERVER_MODE"] != "cloud" #no print in cloud server if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
close_cashier_pdf = Lookup.collection_of("print_settings") close_cashier_pdf = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of("print_settings")
unique_code = "CloseCashierPdf" unique_code = "CloseCashierPdf"
@@ -75,7 +75,7 @@ class Reports::ShiftsaleController < BaseReportController
shop_details = shop_detail shop_details = shop_detail
cashier_terminal = @shift.cashier_terminal cashier_terminal = @shift.cashier_terminal
@sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='') @sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='').where("sales.shop_code='#{@shop.shop_code}'")
@total_waste = Sale.get_total_waste(shift_id).sum(:grand_total) @total_waste = Sale.get_total_waste(shift_id).sum(:grand_total)
@total_spoile = Sale.get_total_spoile(shift_id).sum(:grand_total) @total_spoile = Sale.get_total_spoile(shift_id).sum(:grand_total)
#other payment details for mpu or visa like card #other payment details for mpu or visa like card
@@ -91,12 +91,12 @@ class Reports::ShiftsaleController < BaseReportController
@total_credit_payments = ShiftSale.get_shift_sales_with_credit_payment(shift_id).total_credit_payments @total_credit_payments = ShiftSale.get_shift_sales_with_credit_payment(shift_id).total_credit_payments
# get printer info # get printer info
print_settings = PrintSetting.find_by_unique_code(unique_code) print_settings = PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code)
printer = Printer::CashierStationPrinter.new(print_settings) printer = Printer::CashierStationPrinter.new(print_settings)
# printer.print_close_cashier(print_settings,cashier_terminal,@shift, nil, shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments) # printer.print_close_cashier(print_settings,cashier_terminal,@shift, nil, shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments)
printer.print_close_cashier(print_settings,cashier_terminal,@shift, @sale_items, @total_other_charges_info, shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments) printer.print_close_cashier(print_settings,cashier_terminal,@shift, @sale_items, @total_other_charges_info, @shop,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments)
respond_to do |format| respond_to do |format|
format.html { redirect_to '/en/reports/shiftsale/', notice: 'Printing Completed.'} format.html { redirect_to '/en/reports/shiftsale/', notice: 'Printing Completed.'}
format format

View File

@@ -2,7 +2,7 @@ class Reports::StaffMealController < BaseReportController
authorize_resource :class => false authorize_resource :class => false
def index def index
@account = Account.all @account = Account.where("shop_code='#{@shop.shop_code}'")
from, to = get_date_range_from_params from, to = get_date_range_from_params
shift_sale_range = '' shift_sale_range = ''
@@ -10,16 +10,16 @@ class Reports::StaffMealController < BaseReportController
shift = '' shift = ''
if params[:shift_name].to_i != 0 if params[:shift_name].to_i != 0
shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'")
shift_sale = ShiftSale.find(params[:shift_name]) shift_sale = ShiftSale.find(params[:shift_name])
if to.blank? if to.blank?
shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL and shop_code='#{@shop.shop_code}'",shift_sale.shift_started_at)
else else
if shift_sale.shift_closed_at.blank? if shift_sale.shift_closed_at.blank?
shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL',shift_sale.shift_started_at) shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL and shop_code='#{@shop.shop_code}'",shift_sale.shift_started_at)
else else
shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) shift = ShiftSale.where("shift_started_at = ? and shift_closed_at = ? and shop_code='#{@shop.shop_code}'",shift_sale.shift_started_at, shift_sale.shift_closed_at)
end end
end end
end end
@@ -32,9 +32,9 @@ class Reports::StaffMealController < BaseReportController
account_type = params[:account_type] account_type = params[:account_type]
@sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_staff_meal_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,account_type,customer_id) @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_staff_meal_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,account_type,customer_id,@shop.shop_code)
@sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil) @sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil).where("sales.shop_code='#{@shop.shop_code}'")
@account_cate_count = Hash.new {|hash, key| hash[key] = 0} @account_cate_count = Hash.new {|hash, key| hash[key] = 0}
@sale_data.each {|acc_cate| @account_cate_count[acc_cate.account_id] += 1} @sale_data.each {|acc_cate| @account_cate_count[acc_cate.account_id] += 1}

View File

@@ -11,9 +11,9 @@ class Reports::StockCheckController < BaseReportController
# end # end
from_date, to_date = get_date_range_from_params from_date, to_date = get_date_range_from_params
@item_code = params[:item_code] @item_code = params[:item_code]
@inventory_definitions = InventoryDefinition.active.all @inventory_definitions = InventoryDefinition.active.where("shop_code='#{@shop.shop_code}'")
@transaction = StockCheckItem.get_transaction(from_date, to_date, @item_code) @transaction = StockCheckItem.where("shop_code='#{@shop.shop_code}'").get_transaction(from_date, to_date, @item_code)
@from = from_date @from = from_date
@to = to_date @to = to_date
# get printer info # get printer info
@@ -27,7 +27,7 @@ class Reports::StockCheckController < BaseReportController
def show def show
from, to = get_date_range_from_params from, to = get_date_range_from_params
@sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) @sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'")
date_arr = Array.new date_arr = Array.new
@sale_data.each do |sale| @sale_data.each do |sale|

View File

@@ -1,4 +1,4 @@
class Reports::VoidSaleController < BaseReportController class Reports::VoidSaleController < BaseReportController
authorize_resource :class => false authorize_resource :class => false
def index def index
@@ -8,16 +8,16 @@ authorize_resource :class => false
@shift = '' @shift = ''
if params[:shift_name].to_i != 0 if params[:shift_name].to_i != 0
shift_sale = ShiftSale.find(params[:shift_name]) shift_sale = ShiftSale.find(params[:shift_name])
if to.blank? if to.blank?
@shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL and shop_code='#@shop.shop_code' ",shift_sale.shift_started_at)
else else
@shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at = ? and shop_code='#@shop.shop_code' ",shift_sale.shift_started_at, shift_sale.shift_closed_at)
end end
end end
@sale_data = Sale.get_void_sale(@shift,from,to) @sale_data = Sale.get_void_sale(@shift,from,to,@shop.shop_code)
@from = from @from = from
@to = to @to = to
# get printer info # get printer info
@@ -39,7 +39,7 @@ authorize_resource :class => false
def show def show
from, to = get_date_range_from_params from, to = get_date_range_from_params
@sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) @sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'")
date_arr = Array.new date_arr = Array.new
@sale_data.each do |sale| @sale_data.each do |sale|
@@ -53,10 +53,10 @@ authorize_resource :class => false
end end
out = {:status => 'ok', :message => date_arr} out = {:status => 'ok', :message => date_arr}
respond_to do |format| respond_to do |format|
format.json { render json: out } format.json { render json: out }
end end
end end
end end

View File

@@ -1,9 +1,9 @@
class Reports::WasteAndSpoilageController < BaseReportController class Reports::WasteAndSpoilageController < BaseReportController
authorize_resource :class => false authorize_resource :class => false
def index def index
from, to = get_date_range_from_params from, to = get_date_range_from_params
@sale_type = params[:sale_type] @sale_type = params[:sale_type]
@sale_data = Sale.get_wastes_and_spoilages(from,to,@sale_type) @sale_data = Sale.get_wastes_and_spoilages(from,to,@sale_type).where("sales.shop_code='#{@shop.shop_code}'")
@from = from @from = from
@to = to @to = to
# get printer info # get printer info
@@ -15,5 +15,5 @@ authorize_resource :class => false
end end
end end
end end

View File

@@ -1,5 +1,5 @@
class Transactions::CreditNotesController < ApplicationController class Transactions::CreditNotesController < ApplicationController
before_action :set_transactions_sale, only: [:show, :edit, :update, :destroy] before_action :set_transactions_sale, only: [:show, :edit, :update, :destroy]
before_action :check_user before_action :check_user
@@ -17,22 +17,22 @@ class Transactions::CreditNotesController < ApplicationController
if filter.nil? && from.nil? && to.nil? && customer.nil? && order_source.nil? if filter.nil? && from.nil? && to.nil? && customer.nil? && order_source.nil?
order_source_query = "(select orders.source FROM orders JOIN sale_orders so ON so.order_id=orders.order_id WHERE so.sale_id=sales.sale_id GROUP BY so.sale_id)" order_source_query = "(select orders.source FROM orders JOIN sale_orders so ON so.order_id=orders.order_id WHERE so.sale_id=sales.sale_id GROUP BY so.sale_id)"
@credit_notes = Sale.select("sales.*, #{order_source_query} as source") @credit_notes = Sale.select("sales.*, #{order_source_query} as source")
.joins("JOIN sale_payments sp on sp.sale_id = sales.sale_id") .joins("JOIN sale_payments sp on sp.sale_id = sales.sale_id")
.where("(CASE WHEN (sales.grand_total + sales.amount_changed)=(select SUM(sale_payments.payment_amount) .where("(CASE WHEN (sales.grand_total + sales.amount_changed)=(select SUM(sale_payments.payment_amount)
FROM sale_payments WHERE sale_payments.sale_id=sales.sale_id AND sale_payments.payment_method!='creditnote') FROM sale_payments WHERE sale_payments.sale_id=sales.sale_id AND sale_payments.payment_method!='creditnote')
THEN NULL ELSE payment_method='creditnote' END)") THEN NULL ELSE payment_method='creditnote' END) and sales.shop_code='#{@shop.shop_code}'")
@credit_notes = Kaminari.paginate_array(@credit_notes).page(params[:page]).per(20) @credit_notes = Kaminari.paginate_array(@credit_notes).page(params[:page]).per(20)
else else
sale = Sale.search_credit_sales(customer,filter,from,to,order_source) sale = Sale.search_credit_sales(customer,filter,from,to,order_source).where("sales.shop_code='#{@shop.shop_code}'")
if !sale.nil? if !sale.nil?
@credit_notes = sale @credit_notes = sale
@credit_notes = Kaminari.paginate_array(@credit_notes).page(params[:page]).per(20) @credit_notes = Kaminari.paginate_array(@credit_notes).page(params[:page]).per(20)
else else
@credit_notes = 0 @credit_notes = 0
end end
end end
respond_to do |format| respond_to do |format|
format.html # index.html.erb format.html # index.html.erb
format.json { render json: @credit_notes } format.json { render json: @credit_notes }
@@ -45,5 +45,5 @@ class Transactions::CreditNotesController < ApplicationController
redirect_to root_path redirect_to root_path
end end
end end
end end

View File

@@ -12,17 +12,17 @@ class Transactions::OrderReservationsController < ApplicationController
if from.nil? && to.nil? if from.nil? && to.nil?
@order_reservations = OrderReservation.select("order_reservations.*, deliveries.provider, deliveries.delivery_fee") @order_reservations = OrderReservation.select("order_reservations.*, deliveries.provider, deliveries.delivery_fee")
.joins(" JOIN deliveries on deliveries.order_reservation_id = order_reservations.order_reservation_id") .joins(" JOIN deliveries on deliveries.order_reservation_id = order_reservations.order_reservation_id")
.where("NOT order_reservation_status='new'") .where("NOT order_reservation_status='new' and order_reservations.shop_code='#{@shop.shop_code}'")
.order("order_reservation_id desc") .order("order_reservation_id desc")
@order_reservations = Kaminari.paginate_array(@order_reservations).page(params[:page]).per(20) @order_reservations = Kaminari.paginate_array(@order_reservations).page(params[:page]).per(20)
else else
order_reservation = OrderReservation.search(filter,from,to) order_reservation = OrderReservation.search(filter,from,to).where("order_reservations.shop_code='#{@shop.shop_code}'")
if order_reservation.length > 0 if order_reservation.length > 0
@order_reservations = order_reservation @order_reservations = order_reservation
@order_reservations = Kaminari.paginate_array(@order_reservations).page(params[:page]).per(20) @order_reservations = Kaminari.paginate_array(@order_reservations).page(params[:page]).per(20)
else else
@order_reservations = 0 @order_reservations = 0
end end
end end
@from = from @from = from
@to = to @to = to
@@ -38,7 +38,7 @@ class Transactions::OrderReservationsController < ApplicationController
# GET /transactions/order_reservations/1 # GET /transactions/order_reservations/1
# GET /transactions/order_reservations/1.json # GET /transactions/order_reservations/1.json
def show def show
@order_reservation = OrderReservation.select("order_reservations.*, deliveries.provider, deliveries.delivery_fee") @order_reservation = OrderReservation.select("order_reservations.*, deliveries.provider, deliveries.delivery_fee")
.joins(" JOIN deliveries on deliveries.order_reservation_id = order_reservations.order_reservation_id") .joins(" JOIN deliveries on deliveries.order_reservation_id = order_reservations.order_reservation_id")
.where("order_reservations.order_reservation_id = ?", params[:id]) .where("order_reservations.order_reservation_id = ?", params[:id])
@@ -73,7 +73,7 @@ class Transactions::OrderReservationsController < ApplicationController
period_type = params[:period_type] period_type = params[:period_type]
period = params[:period] period = params[:period]
from = params[:from] from = params[:from]
to = params[:to] to = params[:to]
day_ref = Time.now.utc.getlocal day_ref = Time.now.utc.getlocal
if from.present? && to.present? if from.present? && to.present?
@@ -82,8 +82,8 @@ class Transactions::OrderReservationsController < ApplicationController
f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec) 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) 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 from = f_time.beginning_of_day.utc.getlocal
to = t_time.end_of_day.utc.getlocal to = t_time.end_of_day.utc.getlocal
else else
case period.to_i case period.to_i
when PERIOD["today"] when PERIOD["today"]
from = day_ref.beginning_of_day.utc from = day_ref.beginning_of_day.utc
@@ -117,10 +117,10 @@ class Transactions::OrderReservationsController < ApplicationController
when PERIOD["last_year"] when PERIOD["last_year"]
from = (day_ref - 1.year).beginning_of_year.utc from = (day_ref - 1.year).beginning_of_year.utc
to = (day_ref - 1.year).end_of_year.utc to = (day_ref - 1.year).end_of_year.utc
end end
end end
return from, to return from, to
end end
def check_user def check_user
@@ -128,7 +128,7 @@ class Transactions::OrderReservationsController < ApplicationController
redirect_to root_path redirect_to root_path
end end
end end
private private
# Use callbacks to share common setup or constraints between actions. # Use callbacks to share common setup or constraints between actions.
def set_transactions_order_reservation def set_transactions_order_reservation

View File

@@ -9,11 +9,11 @@ class Transactions::OrdersController < ApplicationController
to = params[:to] to = params[:to]
if filter.nil? && from.nil? && to.nil? if filter.nil? && from.nil? && to.nil?
orders = Order.order("order_id desc") orders = Order.where("shop_code='#{@shop.shop_code}'").order("order_id desc")
else else
orders = Order.search(filter,from,to) orders = Order.search(filter,from,to).where("orders.shop_code='#{@shop.shop_code}'")
end end
if !orders.nil? if !orders.nil?
@orders = Kaminari.paginate_array(orders).page(params[:page]).per(20) @orders = Kaminari.paginate_array(orders).page(params[:page]).per(20)
else else
@@ -23,14 +23,14 @@ class Transactions::OrdersController < ApplicationController
@receipt_no = filter @receipt_no = filter
@from = from @from = from
@to = to @to = to
respond_to do |format| respond_to do |format|
format.html format.html
format.json { render json: @orders } format.json { render json: @orders }
# format.csv { send_data OrdersCsvExport.generate } # format.csv { send_data OrdersCsvExport.generate }
end end
end end
def show def show
@order = Order.find(params[:id]) @order = Order.find(params[:id])

View File

@@ -18,13 +18,13 @@ class Transactions::SalesController < ApplicationController
if receipt_no.nil? && from.nil? && to.nil? if receipt_no.nil? && from.nil? && to.nil?
if @shift.blank? if @shift.blank?
@sales = Sale.where("NOT sale_status='new'").order("sale_id desc") @sales = Sale.where("NOT sale_status='new' and shop_code='#{@shop.shop_code}'").order("sale_id desc")
else else
@sales = Sale.where("NOT sale_status='new' and shift_sale_id ='#{@shift.id}'").order("sale_id desc") @sales = Sale.where("NOT sale_status='new' and shift_sale_id ='#{@shift.id}' and shop_code='#{@shop.shop_code}'").order("sale_id desc")
end end
@sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20) @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20)
else else
sale = Sale.search(receipt_no,from,to,@shift) sale = Sale.search(receipt_no,from,to,@shift).where("sales.shop_code='#{@shop.shop_code}'")
if sale.count > 0 if sale.count > 0
@sales = sale @sales = sale
@sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20) @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20)

View File

@@ -10,16 +10,16 @@ class Transactions::ShiftSalesController < ApplicationController
to = params[:to] to = params[:to]
if filter.nil? && from.nil? && to.nil? if filter.nil? && from.nil? && to.nil?
@shift_sales = ShiftSale.all.order("id desc") @shift_sales = ShiftSale.where("shop_code='#{@shop.shop_code}'").order("id desc")
@shift_sales = Kaminari.paginate_array(@shift_sales).page(params[:page]).per(20) @shift_sales = Kaminari.paginate_array(@shift_sales).page(params[:page]).per(20)
else else
shift_sale = ShiftSale.search(filter,from,to) shift_sale = ShiftSale.search(filter,from,to).where("shift_sales.shop_code='#{@shop.shop_code}'")
if shift_sale.count > 0 if shift_sale.count > 0
@shift_sales = shift_sale @shift_sales = shift_sale
@shift_sales = Kaminari.paginate_array(@shift_sales).page(params[:page]).per(20) @shift_sales = Kaminari.paginate_array(@shift_sales).page(params[:page]).per(20)
else else
@shift_sales = 0 @shift_sales = 0
end end
end end
respond_to do |format| respond_to do |format|
@@ -32,12 +32,12 @@ class Transactions::ShiftSalesController < ApplicationController
# GET /transactions/shift_sales/1 # GET /transactions/shift_sales/1
# GET /transactions/shift_sales/1.json # GET /transactions/shift_sales/1.json
def show def show
@shift = ShiftSale.find(params[:id]) @shift = ShiftSale.find(params[:id])
#get tax #get tax
shift_obj = ShiftSale.where('id =?',@shift.id) shift_obj = ShiftSale.where('id =?',@shift.id)
@sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='') @sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='').where("sales.shop_code='#{@shop.shop_code}'")
#other payment details for mpu or visa like card #other payment details for mpu or visa like card
@other_payment = ShiftSale.get_by_shift_other_payment(@shift) @other_payment = ShiftSale.get_by_shift_other_payment(@shift)
@@ -46,7 +46,7 @@ class Transactions::ShiftSalesController < ApplicationController
@total_discount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'discount') @total_discount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'discount')
@total_member_discount = ShiftSale.get_total_member_discount(@shift) @total_member_discount = ShiftSale.get_total_member_discount(@shift)
respond_to do |format| respond_to do |format|
format.html # show.html.erb format.html # show.html.erb
@@ -59,7 +59,7 @@ class Transactions::ShiftSalesController < ApplicationController
redirect_to root_path redirect_to root_path
end end
end end
private private
# Use callbacks to share common setup or constraints between actions. # Use callbacks to share common setup or constraints between actions.
def set_transactions_shift_sale def set_transactions_shift_sale

View File

@@ -5,15 +5,15 @@ class Transactions::SurveysController < ApplicationController
to = params[:to] to = params[:to]
if filter.nil? && from.nil? && to.nil? if filter.nil? && from.nil? && to.nil?
@surveys = Survey.all @surveys = Survey.where("shop_code='#{@shop.shop_code}'")
else else
@surveys = Survey.search(filter,from,to) @surveys = Survey.search(filter,from,to).where("shop_code='#{@shop.shop_code}'")
end end
@filter = filter @filter = filter
@from = from @from = from
@to = to @to = to
respond_to do |format| respond_to do |format|
format.html # index.html.erb format.html # index.html.erb
format.xls format.xls

View File

@@ -753,7 +753,7 @@ class Sale < ApplicationRecord
return num return num
end end
def self.daily_sales_list(from,to) def self.daily_sales_list(from,to,shop_code)
sales = select(" sales = select("
sales.*, sales.*,
SUM(case when (sale_payments.payment_method='KBZPay') then sale_payments.payment_amount else 0 end) as kbzpay_amount, SUM(case when (sale_payments.payment_method='KBZPay') then sale_payments.payment_amount else 0 end) as kbzpay_amount,
@@ -774,7 +774,7 @@ def self.daily_sales_list(from,to)
SUM(case when (sale_payments.payment_method='giftvoucher') then sale_payments.payment_amount else 0 end) as giftvoucher_amount, SUM(case when (sale_payments.payment_method='giftvoucher') then sale_payments.payment_amount else 0 end) as giftvoucher_amount,
SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount") SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount")
.along_with_sale_payments_except_void .along_with_sale_payments_except_void
.where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to) .where("shop_code='#{shop_code}' and (sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to)
.group("sale_id").to_sql .group("sale_id").to_sql
daily_total = connection.select_all("SELECT daily_total = connection.select_all("SELECT
@@ -826,11 +826,11 @@ def self.get_by_range_by_saleitems(from,to,status,report_type)
query = query.where("(receipt_date between ? and ? and sale_status=?) AND i.unit_price <> 0",from,to,status) query = query.where("(receipt_date between ? and ? and sale_status=?) AND i.unit_price <> 0",from,to,status)
end end
def self.get_by_shiftsales(from,to,shift) def self.get_by_shiftsales(from,to,shift,shop_code)
if !shift.blank? if !shift.blank?
query = ShiftSale.where("shift_sales.id =?",shift.id) query = ShiftSale.where("shift_sales.id =? and shop_code='#{shop_code}'",shift.id)
else else
query = ShiftSale.where("(shift_started_at between ? and ? OR shift_closed_at between ? and ? )", from, to, from, to) query = ShiftSale.where("(shift_started_at between ? and ? OR shift_closed_at between ? and ? ) and shop_code='#{shop_code}'", from, to, from, to)
end end
shift_sale_data = Hash.new shift_sale_data = Hash.new
@@ -951,7 +951,7 @@ def self.get_other_charges()
query = query.group("i.sale_item_id") query = query.group("i.sale_item_id")
end end
def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,account_type) def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,account_type,shop_code)
# date_type_selection = get_sql_function_for_report_type(report_type) # date_type_selection = get_sql_function_for_report_type(report_type)
if account_type.blank? if account_type.blank?
account_type = '' account_type = ''
@@ -974,19 +974,19 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou
product = self.get_product_sale() product = self.get_product_sale()
if shift.present? if shift.present?
query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift.to_a) query = query.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift.to_a)
if type.nil? || type == 'all' || type == "other" if type.nil? || type == 'all' || type == "other"
other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) other_charges = other_charges.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a)
end end
product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) product = product.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a)
discount_query = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount) discount_query = Sale.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount)
change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed) change_amount = Sale.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed)
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount,
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id") .joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.to_a) .where("sales.shop_code='#{shop_code}' and sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.to_a)
sale_cash.each do |s_c| sale_cash.each do |s_c|
total_cash_amount += s_c.cash_amount.to_f total_cash_amount += s_c.cash_amount.to_f
total_card_amount += s_c.card_amount.to_f total_card_amount += s_c.card_amount.to_f
@@ -997,19 +997,19 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou
### => get all sales range in shift_sales ### => get all sales range in shift_sales
elsif shift_sale_range.present? elsif shift_sale_range.present?
query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift_sale_range.to_a) query = query.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift_sale_range.to_a)
if type.nil? || type == 'all' || type == "other" if type.nil? || type == 'all' || type == "other"
other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) other_charges = other_charges.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a)
end end
product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) product = product.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a)
discount_query = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount) discount_query = Sale.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount)
change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed) change_amount = Sale.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed)
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount,
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id") .joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift_sale_range.to_a) .where("sales.shop_code='#{shop_code}' and sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift_sale_range.to_a)
sale_cash.each do |s_c| sale_cash.each do |s_c|
total_cash_amount += s_c.cash_amount.to_f total_cash_amount += s_c.cash_amount.to_f
total_card_amount += s_c.card_amount.to_f total_card_amount += s_c.card_amount.to_f
@@ -1020,20 +1020,20 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou
total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
else else
query = query.where("sales.receipt_date between ? and ? #{account_type} and sale_status='completed'",from,to) query = query.where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? #{account_type} and sale_status='completed'",from,to)
if type.nil? || type == 'all' || type == "other" if type.nil? || type == 'all' || type == "other"
other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) other_charges = other_charges.where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? and sale_status='completed'",from,to)
end end
product = product.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) product = product.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to)
discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount) discount_query = Sale.where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount)
change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed) change_amount = Sale.where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed)
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount,
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id") .joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.where("sales.receipt_date between ? and ? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", from,to) .where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", from,to)
sale_cash.each do |s_c| sale_cash.each do |s_c|
total_cash_amount += s_c.cash_amount.to_f total_cash_amount += s_c.cash_amount.to_f
total_card_amount += s_c.card_amount.to_f total_card_amount += s_c.card_amount.to_f
@@ -1047,7 +1047,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou
return query,other_charges, product, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount return query,other_charges, product, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount
end end
def self.get_staff_meal_items(shift_sale_range, shift, from, to, status,account_type,customer_id) def self.get_staff_meal_items(shift_sale_range, shift, from, to, status,account_type,customer_id,shop_code)
# date_type_selection = get_sql_function_for_report_type(report_type) # date_type_selection = get_sql_function_for_report_type(report_type)
if account_type.blank? if account_type.blank?
account_type = '' account_type = ''
@@ -1079,19 +1079,19 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status,account_
product = self.get_product_sale() product = self.get_product_sale()
if shift.present? if shift.present?
query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",shift.to_a) query = query.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",shift.to_a)
# if type.nil? || type == 'all' || type == "other" # if type.nil? || type == 'all' || type == "other"
# other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) # other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a)
# end # end
product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) product = product.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a)
discount_query = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount) discount_query = Sale.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount)
change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed) change_amount = Sale.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed)
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount,
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id") .joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.to_a) .where("sales.shop_code='#{shop_code}' and sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.to_a)
sale_cash.each do |s_c| sale_cash.each do |s_c|
total_cash_amount += s_c.cash_amount.to_f total_cash_amount += s_c.cash_amount.to_f
total_card_amount += s_c.card_amount.to_f total_card_amount += s_c.card_amount.to_f
@@ -1102,19 +1102,19 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status,account_
### => get all sales range in shift_sales ### => get all sales range in shift_sales
elsif shift_sale_range.present? elsif shift_sale_range.present?
query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",shift_sale_range.to_a) query = query.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",shift_sale_range.to_a)
# if type.nil? || type == 'all' || type == "other" # if type.nil? || type == 'all' || type == "other"
# other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) # other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a)
# end # end
product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) product = product.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a)
discount_query = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount) discount_query = Sale.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount)
change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed) change_amount = Sale.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed)
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount,
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id") .joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift_sale_range.to_a) .where("sales.shop_code='#{shop_code}' and sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift_sale_range.to_a)
sale_cash.each do |s_c| sale_cash.each do |s_c|
total_cash_amount += s_c.cash_amount.to_f total_cash_amount += s_c.cash_amount.to_f
total_card_amount += s_c.card_amount.to_f total_card_amount += s_c.card_amount.to_f
@@ -1125,20 +1125,20 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status,account_
total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
else else
query = query.where("sales.receipt_date between ? and ? #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",from,to) query = query.where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",from,to)
# if type.nil? || type == 'all' || type == "other" # if type.nil? || type == 'all' || type == "other"
# other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) # other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to)
# end # end
product = product.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) product = product.where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? and sale_status='completed'",from,to)
discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount) discount_query = Sale.where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount)
change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed) change_amount = Sale.where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed)
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount,
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id") .joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.where("sales.receipt_date between ? and ? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", from,to) .where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", from,to)
sale_cash.each do |s_c| sale_cash.each do |s_c|
total_cash_amount += s_c.cash_amount.to_f total_cash_amount += s_c.cash_amount.to_f
total_card_amount += s_c.card_amount.to_f total_card_amount += s_c.card_amount.to_f
@@ -1233,7 +1233,7 @@ def self.get_shift_sales_by_receipt_no_detail(shift_sale_range,shift,from,to,pay
return query return query
end end
def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to,filter,order_source) def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to,filter,order_source,shop_code)
payments_for_credits = SalePayment.select(" payments_for_credits = SalePayment.select("
sales.sale_id, sales.sale_id,
DATE_FORMAT(CONVERT_TZ(sale_payments.created_at,'+00:00','+06:30'),'%d %b %y %h:%i%p') as credit_payment_receipt_date, DATE_FORMAT(CONVERT_TZ(sale_payments.created_at,'+00:00','+06:30'),'%d %b %y %h:%i%p') as credit_payment_receipt_date,
@@ -1242,7 +1242,8 @@ def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to,filter,
CONCAT(DATE_FORMAT(CONVERT_TZ(shift_sales.shift_started_at,'+00:00','+06:30'),'%d %b %y %h:%i%p'),' - ',DATE_FORMAT(CONVERT_TZ(shift_sales.shift_closed_at,'+00:00','+06:30'),'%d %b %y %h:%i%p')) as credit_payment_shift_name") CONCAT(DATE_FORMAT(CONVERT_TZ(shift_sales.shift_started_at,'+00:00','+06:30'),'%d %b %y %h:%i%p'),' - ',DATE_FORMAT(CONVERT_TZ(shift_sales.shift_closed_at,'+00:00','+06:30'),'%d %b %y %h:%i%p')) as credit_payment_shift_name")
.joins(:sale_audit) .joins(:sale_audit)
.joins(:sale => :shift_sale) .joins(:sale => :shift_sale)
.joins(:sale => :cashier).to_sql .joins(:sale => :cashier)
.where("sales.shop_code='#{shop_code}'").to_sql
credits = SalePayment.select(" credits = SalePayment.select("
sale_payments.sale_payment_id, sale_payments.sale_payment_id,
@@ -1289,10 +1290,11 @@ def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to,filter,
credits = credits.group("sale_payments.sale_payment_id, sales_sale_payments.sale_id") credits = credits.group("sale_payments.sale_payment_id, sales_sale_payments.sale_id")
end end
def self.get_void_sale(shift,from,to) def self.get_void_sale(shift,from,to,shop_code)
sale_arr = Array.new sale_arr = Array.new
query = Sale.select("sales.receipt_no,sales.receipt_date, sales.payment_status, sales.sale_status,sales.total_amount,sales.grand_total, sales.rounding_adjustment") query = Sale.select("sales.receipt_no,sales.receipt_date, sales.payment_status, sales.sale_status,sales.total_amount,sales.grand_total, sales.rounding_adjustment")
.where("sales.shop_code='#{shop_code}'")
# .joins("INNER JOIN shift_sales sh ON sh.id = sales.shift_sale_id") # .joins("INNER JOIN shift_sales sh ON sh.id = sales.shift_sale_id")
# .where("sales.sale_status = 'void' and (sh.shift_started_at between ? and ? # .where("sales.sale_status = 'void' and (sh.shift_started_at between ? and ?
# OR sh.shift_closed_at between ? and ? )", from ,to, from, to) # OR sh.shift_closed_at between ? and ? )", from ,to, from, to)
@@ -1342,13 +1344,13 @@ def self.get_separate_tax(shift_sale_range=nil,shift,from,to,payment_type)
end end
end end
def self.get_payment_method_by_shift(shift_sale_range,shift,from,to,payment_type) def self.get_payment_method_by_shift(shift_sale_range,shift,from,to,payment_type,shop_code)
sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) ELSE 0 END) sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) ELSE 0 END)
FROM sale_payments FROM sale_payments
INNER JOIN sale_audits sa INNER JOIN sale_audits sa
ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id
INNER JOIN sales ON sa.sale_id = sales.sale_id INNER JOIN sales ON sa.sale_id = sales.sale_id
WHERE sales.sale_status='completed' " WHERE sales.sale_status='completed' and sales.shop_code='#{shop_code}'"
if shift.present? if shift.present?
shift_ids = shift.map(&:id).join(",") shift_ids = shift.map(&:id).join(",")
@@ -1374,7 +1376,7 @@ def self.get_payment_method_by_shift(shift_sale_range,shift,from,to,payment_type
sale_payment = SalePayment.select("s.amount_changed as change_amount,s.receipt_no, sale_payments.*,s.receipt_date as sale_date, sale_payment = SalePayment.select("s.amount_changed as change_amount,s.receipt_no, sale_payments.*,s.receipt_date as sale_date,
s.cashier_name as cashier_name") s.cashier_name as cashier_name")
.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")
.where("(#{sub_query1}) ") .where("(#{sub_query1}) and s.shop_code='#{shop_code}'")
.order('s.receipt_no DESC') .order('s.receipt_no DESC')
payments_total = SalePayment.select("CAST((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')) AS DATE) as sale_date, payments_total = SalePayment.select("CAST((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')) AS DATE) as sale_date,
@@ -1395,6 +1397,7 @@ def self.get_payment_method_by_shift(shift_sale_range,shift,from,to,payment_type
SUM(case when (sale_payments.payment_method='giftvoucher') then sale_payments.payment_amount else 0 end) as giftvoucher_amount, SUM(case when (sale_payments.payment_method='giftvoucher') then sale_payments.payment_amount else 0 end) as giftvoucher_amount,
SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount") SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount")
.joins("join sales on sales.sale_id = sale_payments.sale_id") .joins("join sales on sales.sale_id = sale_payments.sale_id")
.where("sales.shop_code='#{shop_code}'")
if shift.present? if shift.present?
@@ -2170,7 +2173,7 @@ def self.employee_sale(shop,today,shift=nil,from=nil,to=nil,from_time=nil,to_tim
end end
# Start hourly sale item report # Start hourly sale item report
def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,account_type) def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,account_type,shop_code)
# date_type_selection = get_sql_function_for_report_type(report_type) # date_type_selection = get_sql_function_for_report_type(report_type)
if account_type.blank? if account_type.blank?
account_type = '' account_type = ''
@@ -2193,19 +2196,19 @@ def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,acco
product = self.get_product_sale() product = self.get_product_sale()
if shift.present? if shift.present?
query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift.to_a) query = query.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift.to_a)
if type.nil? || type == 'all' || type == "other" if type.nil? || type == 'all' || type == "other"
other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) other_charges = other_charges.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a)
end end
product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) product = product.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a)
discount_query = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount) discount_query = Sale.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount)
change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed) change_amount = Sale.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed)
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount,
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id") .joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.to_a) .where("sales.shop_code='#{shop_code}' and sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.to_a)
sale_cash.each do |s_c| sale_cash.each do |s_c|
total_cash_amount += s_c.cash_amount.to_f total_cash_amount += s_c.cash_amount.to_f
total_card_amount += s_c.card_amount.to_f total_card_amount += s_c.card_amount.to_f
@@ -2216,19 +2219,19 @@ def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,acco
### => get all sales range in shift_sales ### => get all sales range in shift_sales
elsif shift_sale_range.present? elsif shift_sale_range.present?
query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift_sale_range.to_a) query = query.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift_sale_range.to_a)
if type.nil? || type == 'all' || type == "other" if type.nil? || type == 'all' || type == "other"
other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) other_charges = other_charges.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a)
end end
product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) product = product.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a)
discount_query = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount) discount_query = Sale.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount)
change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed) change_amount = Sale.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed)
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount,
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id") .joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift_sale_range.to_a) .where("sales.shop_code='#{shop_code}' and sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift_sale_range.to_a)
sale_cash.each do |s_c| sale_cash.each do |s_c|
total_cash_amount += s_c.cash_amount.to_f total_cash_amount += s_c.cash_amount.to_f
total_card_amount += s_c.card_amount.to_f total_card_amount += s_c.card_amount.to_f
@@ -2239,20 +2242,20 @@ def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,acco
total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
else else
query = query.where("sales.receipt_date between ? and ? #{account_type} and sale_status='completed'",from,to) query = query.where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? #{account_type} and sale_status='completed'",from,to)
if type.nil? || type == 'all' || type == "other" if type.nil? || type == 'all' || type == "other"
other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) other_charges = other_charges.where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? and sale_status='completed'",from,to)
end end
product = product.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) product = product.where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? and sale_status='completed'",from,to)
discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount) discount_query = Sale.where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount)
change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed) change_amount = Sale.where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed)
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount,
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id") .joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.where("sales.receipt_date between ? and ? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", from,to) .where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", from,to)
sale_cash.each do |s_c| sale_cash.each do |s_c|
total_cash_amount += s_c.cash_amount.to_f total_cash_amount += s_c.cash_amount.to_f
total_card_amount += s_c.card_amount.to_f total_card_amount += s_c.card_amount.to_f

View File

@@ -27,10 +27,10 @@ class SaleTax < ApplicationRecord
end end
end end
def self.get_tax(from,to) def self.get_tax(from,to,shop_code)
query = SaleTax.select("sale_taxes.tax_name,SUM(sale_taxes.tax_payable_amount) as tax_amount") query = SaleTax.select("sale_taxes.tax_name,SUM(sale_taxes.tax_payable_amount) as tax_amount")
.joins("join sales on sales.sale_id = sale_taxes.sale_id") .joins("join sales on sales.sale_id = sale_taxes.sale_id")
.where("sale_status = ? AND sales.receipt_date between ? and ? AND total_amount != 0 AND inclusive = 0", 'completed', from, to) .where("sales.shop_code='#{shop_code}' and sale_status = ? AND sales.receipt_date between ? and ? AND total_amount != 0 AND inclusive = 0", 'completed', from, to)
.group("sale_taxes.tax_name") .group("sale_taxes.tax_name")
end end

View File

@@ -1,11 +1,11 @@
# application_path="#{File.expand_path("../..", __FILE__)}" application_path="#{File.expand_path("../..", __FILE__)}"
# directory application_path directory application_path
# #environment ENV.fetch("RAILS_ENV") { "production" } #environment ENV.fetch("RAILS_ENV") { "production" }
# environment "production" environment "production"
# pidfile "#{application_path}/tmp/puma/pid" pidfile "#{application_path}/tmp/puma/pid"
# state_path "#{application_path}/tmp/puma/state" state_path "#{application_path}/tmp/puma/state"
# stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log" stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log"
# port ENV.fetch("PORT") { 62158 } port ENV.fetch("PORT") { 62158 }
# workers 2 workers 2
# preload_app! preload_app!
# threads 1,1 threads 1,1

View File

@@ -0,0 +1,33 @@
class Removeshopid < ActiveRecord::Migration[5.1]
def change
remove_column :accounts, :shop_id
remove_column :bookings, :shop_id
remove_column :cashier_terminals, :shop_id
remove_column :commissioners, :shop_id
remove_column :commissions, :shop_id
remove_column :customers, :shop_id
remove_column :dining_facilities, :shop_id
remove_column :dining_queues, :shop_id
remove_column :employees, :shop_id
remove_column :inventory_definitions, :shop_id
remove_column :item_sets, :shop_id
remove_column :lookups, :shop_id
remove_column :membership_settings, :shop_id
remove_column :menus, :shop_id
remove_column :order_queue_stations, :shop_id
remove_column :orders, :shop_id
remove_column :payment_journals, :shop_id
remove_column :payment_method_settings, :shop_id
remove_column :print_settings, :shop_id
remove_column :sales, :shop_id
remove_column :products, :shop_id
remove_column :promotions, :shop_id
remove_column :seed_generators, :shop_id
remove_column :shift_sales, :shop_id
remove_column :stock_checks, :shop_id
remove_column :stock_journals, :shop_id
remove_column :surveys, :shop_id
remove_column :tax_profiles, :shop_id
remove_column :zones, :shop_id
end
end