add payment type filter for order reservation

This commit is contained in:
phyusin
2018-07-03 10:34:24 +06:30
parent e94024644d
commit 60a1ef61a4
5 changed files with 57 additions and 26 deletions

View File

@@ -2,6 +2,7 @@ class Reports::OrderReservationController < BaseReportController
# authorize_resource :class => false
def index
@providers = [["All",''], ["Direct Delivery","direct_delivery"],["Pick-Up","pick_up"],["food2u","food2u"], ["ygndoor2door","ygndoor2door"]]
@payment_types = [["All",''], ["COD","cash_on_delivery"],["DINGA","dinga"]]
from, to = get_date_range_from_params
@@ -19,7 +20,8 @@ class Reports::OrderReservationController < BaseReportController
end
provider = params[:provider]
@order_reservation_data = OrderReservation.get_order_reservation_by_shift(@shift_sale_range,@shift,from,to,provider)
payment_type = params[:payment_type]
@order_reservation_data = OrderReservation.get_order_reservation_by_shift(@shift_sale_range,@shift,from,to,provider,payment_type)
@from = from
@to = to
# get printer info

View File

@@ -365,7 +365,7 @@ class OrderReservation < ApplicationRecord
end
end
def self.get_order_reservation_by_shift(shift_sale_range,shift,from,to,provider)
def self.get_order_reservation_by_shift(shift_sale_range,shift,from,to,provider,payment_type)
## => left join -> show all sales although no orders
if provider.blank?
provider = ''
@@ -374,21 +374,28 @@ class OrderReservation < ApplicationRecord
provider = " and deliveries.provider = '#{provider}'"
end
end
if payment_type.blank?
payment_type = ''
else
if payment_type.present?
payment_type = " and order_reservations.payment_type = '#{payment_type}'"
end
end
query = OrderReservation.select("order_reservations.*, deliveries.provider, deliveries.delivery_fee, customers.name, customers.email")
query = OrderReservation.select("order_reservations.*, sales.receipt_date, deliveries.provider, deliveries.delivery_fee, customers.name, customers.email")
.joins(" JOIN deliveries on deliveries.order_reservation_id = order_reservations.order_reservation_id")
.joins(" JOIN customers on customers.customer_id = order_reservations.customer_id")
.joins(" JOIN sales on sales.sale_id = order_reservations.sale_id")
if shift.present?
query = query.where("sales.shift_sale_id in (?) #{provider} and sales.sale_status= 'completed' and sale_payments.payment_amount != 0", shift.to_a)
query = query.where("sales.shift_sale_id in (?) #{provider} #{payment_type} and sales.sale_status= 'completed' and sale_payments.payment_amount != 0", shift.to_a)
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.group("sales.sale_id")
elsif shift_sale_range.present?
query = query.where("sales.sale_status='completed' #{provider} and sale_payments.payment_amount != 0 and sales.shift_sale_id in (?)",shift_sale_range.to_a)
query = query.where("sales.sale_status='completed' #{provider} #{payment_type} and sale_payments.payment_amount != 0 and sales.shift_sale_id in (?)",shift_sale_range.to_a)
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.group("sales.sale_id")
else
query = query.where("sales.sale_status='completed' and sales.receipt_date between ? and ? #{provider} and sale_payments.payment_amount != 0",from,to)
query = query.where("sales.sale_status='completed' and sales.receipt_date between ? and ? #{provider} #{payment_type} and sale_payments.payment_amount != 0",from,to)
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.group("sales.sale_id")
end

View File

@@ -3,7 +3,7 @@
<% if period_type != false %>
<div class="row">
<div class="col-lg-2 col-md-2 col-sm-2">
<label class="font-14"><%= t("views.right_panel.detail.select_period") %></label>
<label class="font-13"><%= t("views.right_panel.detail.select_period") %></label>
<select name="period" id="sel_period" class="form-control">
<option value=""><%= t("views.right_panel.detail.select_period") %></option>
<option value="0">Today</option>
@@ -19,22 +19,28 @@
</select>
</div>
<% if defined? providers %>
<div class="col-lg-2 col-md-2 col-sm-2">
<label class="font-14"><%= t("views.right_panel.detail.select_providers") %></label>
<%= select_tag "provider", options_for_select(@providers, :selected => params[:provider]), :class => "form-control" %>
<div class="col-lg-1 col-md-1 col-sm-1">
<label class="font-13"><%= t("views.right_panel.detail.select_providers") %></label>
<%= select_tag "provider", options_for_select(@providers, :selected => params[:provider]), :class => "form-control", :style => "height: 35px;" %>
</div>
<% end %>
<% if defined? payment_types %>
<div class="col-lg-1 col-md-1 col-sm-1">
<label class="font-13"><%= t("views.right_panel.detail.select_payment") %></label>
<%= select_tag "payment_type", options_for_select(@payment_types, :selected => params[:payment_type]), :class => "form-control", :style => "height: 35px;" %>
</div>
<% end %>
<div class="col-lg-2 col-md-2 col-sm-2">
<!-- <label class="">Select Shift Period</label> -->
<label class="font-14"><%= t("views.right_panel.detail.from") %></label>
<label class="font-13"><%= t("views.right_panel.detail.from") %></label>
<input data-behaviour='datepicker' class="form-control datepicker m-t-3" name="from" id="from" type="text" placeholder="From date" style="height: 32px;">
</div>
<div class="col-lg-2 col-md-2 col-sm-2">
<label class="font-14"><%= t("views.right_panel.detail.to") %></label>
<label class="font-13"><%= t("views.right_panel.detail.to") %></label>
<input data-behaviour='datepicker' class="form-control datepicker m-t-3" name="to" id="to" type="text" placeholder="To date" style="height: 32px;">
</div>
<div class="col-lg-2 col-md-2 col-sm-2">
<label class="font-14"><%= t("views.right_panel.detail.all_shift") %></label>
<label class="font-13"><%= t("views.right_panel.detail.all_shift") %></label>
<select class="form-control select" name="shift_name" id="shift_name" >
</select>
</div>

View File

@@ -12,7 +12,7 @@
<!-- <div class="container"> -->
<%= render :partial=>'shift_sale_report_filter',
:locals=>{ :period_type => true, :shift_name => true,:providers => true, :report_path =>reports_order_reservation_index_path} %>
:locals=>{ :period_type => true, :shift_name => true, :providers => true, :payment_types => true, :report_path =>reports_order_reservation_index_path} %>
<hr />
<!-- </div> -->
@@ -41,9 +41,10 @@
<% end %>
<tr>
<th><%= t("views.right_panel.detail.receipt_date") %></th>
<th><%= t :reference_number %></th>
<th><%= t :customer %></th>
<th><%= t("views.right_panel.detail.type") %></th>
<th><%= t("views.right_panel.detail.requested_time") %></th>
<!-- <th><%= t("views.right_panel.detail.type") %></th> -->
<th><%= t("views.right_panel.detail.provider") %></th>
<th><%= t :payment_method %></th>
<th><%= t :payment %> <%= t("views.right_panel.detail.status")%></th>
@@ -124,13 +125,20 @@
else
provider = order_reservation.provider
end
payment_type = ""
if order_reservation.payment_type == "cash_on_delivery"
payment_type = "COD"
elsif order_reservation.payment_type == "dinga"
payment_type = "DINGA"
end
%>
<tr>
<td><%= order_reservation.receipt_date.utc.getlocal.strftime("%Y-%m-%d") %></td>
<td><%= order_reservation.transaction_ref %></td>
<td><%= order_reservation.name %></td>
<td><%= order_reservation.order_reservation_type %></td>
<td><%= order_reservation.requested_time.utc.getlocal.strftime("%Y-%m-%d %I:%M %p") %></td>
<!-- <td><%= order_reservation.order_reservation_type %></td> -->
<td><%= provider%></td>
<td><%= order_reservation.payment_type%></td>
<td><%= payment_type%></td>
<td><%= order_reservation.payment_status%></td>
<td><%= number_with_precision(order_reservation.total_amount, precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></td>
<td><%= number_with_precision(discount_amount , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></td>
@@ -146,7 +154,7 @@
end %>
<tr>
<td colspan="6"></td>
<td colspan="6"><b>Total</b></td>
<td><b><%= number_with_precision(total_amount , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></b></td>
<td><b><%= number_with_precision(total_discount_amount , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></b></td>
<td><b><%= number_with_precision(total_delivery_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></b></td>

View File

@@ -24,9 +24,10 @@
<% end %>
<tr>
<th><%= t("views.right_panel.detail.receipt_date") %></th>
<th><%= t :reference_number %></th>
<th><%= t :customer %></th>
<th><%= t("views.right_panel.detail.type") %></th>
<th><%= t("views.right_panel.detail.requested_time") %></th>
<!-- <th><%= t("views.right_panel.detail.type") %></th> -->
<th><%= t("views.right_panel.detail.provider") %></th>
<th><%= t :payment_method %></th>
<th><%= t :payment %> <%= t("views.right_panel.detail.status")%></th>
@@ -98,13 +99,20 @@
else
provider = order_reservation.provider
end
payment_type = ""
if order_reservation.payment_type == "cash_on_delivery"
payment_type = "COD"
elsif order_reservation.payment_type == "dinga"
payment_type = "DINGA"
end
%>
<tr>
<td><%= order_reservation.receipt_date.utc.getlocal.strftime("%Y-%m-%d") %></td>
<td><%= order_reservation.transaction_ref %></td>
<td><%= order_reservation.name %></td>
<td><%= order_reservation.order_reservation_type %></td>
<td><%= order_reservation.requested_time.utc.getlocal.strftime("%Y-%m-%d %I:%M %p") %></td>
<!-- <td><%= order_reservation.order_reservation_type %></td> -->
<td><%= provider%></td>
<td><%= order_reservation.payment_type%></td>
<td><%= payment_type%></td>
<td><%= order_reservation.payment_status%></td>
<td><%= order_reservation.total_amount rescue '0.0'%></td>
<td><%= discount_amount rescue '0.0'%></td>
@@ -120,7 +128,7 @@
end %>
<tr>
<td colspan="6"></td>
<td colspan="6"><b>Total</b></td>
<td><b><%= total_amount rescue '0.0'%></b></td>
<td><b><%= total_discount_amount rescue '0.0'%></b></td>
<td><b><%= total_delivery_fee rescue '0.0'%></b></td>