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

@@ -1,5 +1,5 @@
class Transactions::CreditNotesController < ApplicationController
before_action :set_transactions_sale, only: [:show, :edit, :update, :destroy]
before_action :check_user
@@ -17,22 +17,22 @@ class Transactions::CreditNotesController < ApplicationController
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)"
@credit_notes = Sale.select("sales.*, #{order_source_query} as source")
.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)
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)
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?
@credit_notes = sale
@credit_notes = sale
@credit_notes = Kaminari.paginate_array(@credit_notes).page(params[:page]).per(20)
else
@credit_notes = 0
end
end
end
end
respond_to do |format|
format.html # index.html.erb
format.json { render json: @credit_notes }
@@ -45,5 +45,5 @@ class Transactions::CreditNotesController < ApplicationController
redirect_to root_path
end
end
end
end

View File

@@ -12,17 +12,17 @@ class Transactions::OrderReservationsController < ApplicationController
if from.nil? && to.nil?
@order_reservations = OrderReservation.select("order_reservations.*, deliveries.provider, deliveries.delivery_fee")
.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_reservations = Kaminari.paginate_array(@order_reservations).page(params[:page]).per(20)
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
@order_reservations = order_reservation
@order_reservations = order_reservation
@order_reservations = Kaminari.paginate_array(@order_reservations).page(params[:page]).per(20)
else
@order_reservations = 0
end
end
end
@from = from
@to = to
@@ -38,7 +38,7 @@ class Transactions::OrderReservationsController < ApplicationController
# GET /transactions/order_reservations/1
# GET /transactions/order_reservations/1.json
def show
@order_reservation = OrderReservation.select("order_reservations.*, deliveries.provider, deliveries.delivery_fee")
.joins(" JOIN deliveries on deliveries.order_reservation_id = order_reservations.order_reservation_id")
.where("order_reservations.order_reservation_id = ?", params[:id])
@@ -73,7 +73,7 @@ class Transactions::OrderReservationsController < ApplicationController
period_type = params[:period_type]
period = params[:period]
from = params[:from]
to = params[:to]
to = params[:to]
day_ref = Time.now.utc.getlocal
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)
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
to = t_time.end_of_day.utc.getlocal
else
case period.to_i
when PERIOD["today"]
from = day_ref.beginning_of_day.utc
@@ -117,10 +117,10 @@ class Transactions::OrderReservationsController < ApplicationController
when PERIOD["last_year"]
from = (day_ref - 1.year).beginning_of_year.utc
to = (day_ref - 1.year).end_of_year.utc
end
end
end
return from, to
return from, to
end
def check_user
@@ -128,7 +128,7 @@ class Transactions::OrderReservationsController < ApplicationController
redirect_to root_path
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_transactions_order_reservation

View File

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

View File

@@ -18,13 +18,13 @@ class Transactions::SalesController < ApplicationController
if receipt_no.nil? && from.nil? && to.nil?
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
@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
@sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20)
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
@sales = sale
@sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20)

View File

@@ -10,16 +10,16 @@ class Transactions::ShiftSalesController < ApplicationController
to = params[:to]
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)
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
@shift_sales = shift_sale
@shift_sales = shift_sale
@shift_sales = Kaminari.paginate_array(@shift_sales).page(params[:page]).per(20)
else
@shift_sales = 0
end
end
end
respond_to do |format|
@@ -32,12 +32,12 @@ class Transactions::ShiftSalesController < ApplicationController
# GET /transactions/shift_sales/1
# GET /transactions/shift_sales/1.json
def show
@shift = ShiftSale.find(params[:id])
#get tax
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 = 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_member_discount = ShiftSale.get_total_member_discount(@shift)
respond_to do |format|
format.html # show.html.erb
@@ -59,7 +59,7 @@ class Transactions::ShiftSalesController < ApplicationController
redirect_to root_path
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_transactions_shift_sale

View File

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