Add CB payment in transactions and reports
This commit is contained in:
138
app/controllers/reports/card_sale_tran_controller.rb
Normal file
138
app/controllers/reports/card_sale_tran_controller.rb
Normal file
@@ -0,0 +1,138 @@
|
||||
class Reports::CardSaleTranController < BaseReportController
|
||||
authorize_resource :class => false
|
||||
|
||||
# GET /transactions/sales
|
||||
# GET /transactions/sales.json
|
||||
def index
|
||||
@payment_method = [["All Payments",''],["MPU Payment","mpu"], ["Visa Payment","visa"],
|
||||
["Master Payment","master"], ["JCB Payment","jcb"],["UnionPay Payment","unionpay"],
|
||||
["Alipay Payment","alipay"]]
|
||||
@sales = Sale.all
|
||||
# byebug
|
||||
payment_type = params[:payment_type]
|
||||
|
||||
# from = params[:from]
|
||||
# to = params[:to]
|
||||
from, to = get_date_range_from_params
|
||||
status = 'Approved'
|
||||
@shift_sale_range = ''
|
||||
@shift = ''
|
||||
|
||||
if params[:shift_name].to_i != 0
|
||||
|
||||
@shift_sale_range = CardSaleTran.get_by_shift_sale_by_card(from,to,status)
|
||||
|
||||
@shift_sale = ShiftSale.find(params[:shift_name])
|
||||
if to.blank?
|
||||
@shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',@shift_sale.shift_started_at)
|
||||
else
|
||||
if @shift_sale.shift_closed_at.blank?
|
||||
@shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL',@shift_sale.shift_started_at)
|
||||
else
|
||||
@shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',@shift_sale.shift_started_at, @shift_sale.shift_closed_at)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if from.nil? && to.nil? && payment_method.nil? && @shift.nil?
|
||||
|
||||
@cardSales = CardSaleTran.where("status = 'Approved'").order("sale_id desc")
|
||||
|
||||
@cardSales = Kaminari.paginate_array(@cardSales).page(params[:page]).per(20)
|
||||
else
|
||||
cardSale = CardSaleTran.searchReport(from,to,payment_type,@shift_sale_range,@shift)
|
||||
if cardSale.count > 0
|
||||
@cardSales = cardSale
|
||||
@cardSales = Kaminari.paginate_array(@cardSales).page(params[:page]).per(20)
|
||||
else
|
||||
@cardSales = 0
|
||||
end
|
||||
end
|
||||
|
||||
@from = from
|
||||
@to = to
|
||||
# get printer info
|
||||
@print_settings = PrintSetting.get_precision_delimiter()
|
||||
if @shift.present?
|
||||
@shift.each do |sh|
|
||||
@shift_from = sh.shift_started_at.nil? ? '-' : sh.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p")
|
||||
@shift_to = sh.shift_closed_at.nil? ? '-' : sh.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p")
|
||||
@shift_data = sh
|
||||
end
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xls
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# date range
|
||||
PERIOD = {
|
||||
"today" => 0,
|
||||
"yesterday" => 1,
|
||||
"this_week" => 2,
|
||||
"last_week" => 3,
|
||||
"last_7" => 4,
|
||||
"this_month" => 5,
|
||||
"last_month" => 6,
|
||||
"last_30" => 7,
|
||||
"this_year" => 8,
|
||||
"last_year" => 9
|
||||
}
|
||||
|
||||
def get_date_range_from_params
|
||||
period_type = params[:period_type]
|
||||
period = params[:period]
|
||||
from = params[:from]
|
||||
to = params[:to]
|
||||
day_ref = Time.now.utc.getlocal
|
||||
if from.present? && to.present?
|
||||
f_date = DateTime.parse(from)
|
||||
t_date = DateTime.parse(to)
|
||||
f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec)
|
||||
t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec)
|
||||
from = f_time.beginning_of_day.utc.getlocal
|
||||
to = t_time.end_of_day.utc.getlocal
|
||||
else
|
||||
case period.to_i
|
||||
when PERIOD["today"]
|
||||
from = day_ref.beginning_of_day.utc
|
||||
to = day_ref.end_of_day.utc
|
||||
|
||||
when PERIOD["yesterday"]
|
||||
from = (day_ref - 1.day).beginning_of_day.utc
|
||||
to = (day_ref - 1.day).end_of_day.utc
|
||||
|
||||
when PERIOD["this_week"]
|
||||
from = Time.now.beginning_of_week.utc
|
||||
to = Time.now.utc
|
||||
when PERIOD["last_week"]
|
||||
from = (day_ref - 7.day).beginning_of_week.utc
|
||||
to = (day_ref - 7.day).end_of_week.utc
|
||||
when PERIOD["last_7"]
|
||||
from = (day_ref - 7.day).utc
|
||||
to = Time.now.utc
|
||||
when PERIOD["this_month"]
|
||||
from = Time.now.beginning_of_month.utc
|
||||
to = Time.now.utc
|
||||
when PERIOD["last_month"]
|
||||
from = (day_ref - 1.month).beginning_of_month.utc
|
||||
to = (day_ref - 1.month).end_of_month.utc
|
||||
when PERIOD["last_30"]
|
||||
from = (day_ref - 30.day).utc
|
||||
to = Time.now.utc
|
||||
when PERIOD["this_year"]
|
||||
from = Time.now.beginning_of_year.utc
|
||||
to = Time.now.utc
|
||||
when PERIOD["last_year"]
|
||||
from = (day_ref - 1.year).beginning_of_year.utc
|
||||
to = (day_ref - 1.year).end_of_year.utc
|
||||
end
|
||||
end
|
||||
|
||||
return from, to
|
||||
end
|
||||
|
||||
end
|
||||
105
app/controllers/transactions/card_sale_trans_controller.rb
Normal file
105
app/controllers/transactions/card_sale_trans_controller.rb
Normal file
@@ -0,0 +1,105 @@
|
||||
class Transactions::CardSaleTransController < ApplicationController
|
||||
authorize_resource :class => false
|
||||
|
||||
# GET /transactions/sales
|
||||
# GET /transactions/sales.json
|
||||
def index
|
||||
@status = [["All Status",''], ["Approved","Approved"], ["Declined","Declined"]]
|
||||
@payment_method = [["All Payments",''],["MPU Payment","mpu"], ["Visa Payment","visa"],
|
||||
["Master Payment","master"], ["JCB Payment","jcb"],["UnionPay Payment","unionpay"],
|
||||
["Alipay Payment","alipay"]]
|
||||
@sales = Sale.all
|
||||
# byebug
|
||||
payment_type = params[:payment_type]
|
||||
sale_id = params[:sale_id]
|
||||
status_type = params[:status_type]
|
||||
|
||||
# from = params[:from]
|
||||
# to = params[:to]
|
||||
from, to = get_date_range_from_params
|
||||
|
||||
if sale_id.nil? && from.nil? && to.nil? && payment_method.nil? && status_type.nil?
|
||||
|
||||
@cardSales = CardSaleTran.where("status IS NOT NULL").order("sale_id desc")
|
||||
|
||||
@cardSales = Kaminari.paginate_array(@cardSales).page(params[:page]).per(20)
|
||||
else
|
||||
cardSale = CardSaleTran.search(sale_id,from,to,payment_type,status_type)
|
||||
if cardSale.count > 0
|
||||
@cardSales = cardSale
|
||||
@cardSales = Kaminari.paginate_array(@cardSales).page(params[:page]).per(20)
|
||||
else
|
||||
@cardSales = 0
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# date range
|
||||
PERIOD = {
|
||||
"today" => 0,
|
||||
"yesterday" => 1,
|
||||
"this_week" => 2,
|
||||
"last_week" => 3,
|
||||
"last_7" => 4,
|
||||
"this_month" => 5,
|
||||
"last_month" => 6,
|
||||
"last_30" => 7,
|
||||
"this_year" => 8,
|
||||
"last_year" => 9
|
||||
}
|
||||
|
||||
def get_date_range_from_params
|
||||
period_type = params[:period_type]
|
||||
period = params[:period]
|
||||
from = params[:from]
|
||||
to = params[:to]
|
||||
day_ref = Time.now.utc.getlocal
|
||||
if from.present? && to.present?
|
||||
f_date = DateTime.parse(from)
|
||||
t_date = DateTime.parse(to)
|
||||
f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec)
|
||||
t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec)
|
||||
from = f_time.beginning_of_day.utc.getlocal
|
||||
to = t_time.end_of_day.utc.getlocal
|
||||
else
|
||||
case period.to_i
|
||||
when PERIOD["today"]
|
||||
from = day_ref.beginning_of_day.utc
|
||||
to = day_ref.end_of_day.utc
|
||||
|
||||
when PERIOD["yesterday"]
|
||||
from = (day_ref - 1.day).beginning_of_day.utc
|
||||
to = (day_ref - 1.day).end_of_day.utc
|
||||
|
||||
when PERIOD["this_week"]
|
||||
from = Time.now.beginning_of_week.utc
|
||||
to = Time.now.utc
|
||||
when PERIOD["last_week"]
|
||||
from = (day_ref - 7.day).beginning_of_week.utc
|
||||
to = (day_ref - 7.day).end_of_week.utc
|
||||
when PERIOD["last_7"]
|
||||
from = (day_ref - 7.day).utc
|
||||
to = Time.now.utc
|
||||
when PERIOD["this_month"]
|
||||
from = Time.now.beginning_of_month.utc
|
||||
to = Time.now.utc
|
||||
when PERIOD["last_month"]
|
||||
from = (day_ref - 1.month).beginning_of_month.utc
|
||||
to = (day_ref - 1.month).end_of_month.utc
|
||||
when PERIOD["last_30"]
|
||||
from = (day_ref - 30.day).utc
|
||||
to = Time.now.utc
|
||||
when PERIOD["this_year"]
|
||||
from = Time.now.beginning_of_year.utc
|
||||
to = Time.now.utc
|
||||
when PERIOD["last_year"]
|
||||
from = (day_ref - 1.year).beginning_of_year.utc
|
||||
to = (day_ref - 1.year).end_of_year.utc
|
||||
end
|
||||
end
|
||||
|
||||
return from, to
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user