change credit payment query
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
class Reports::CreditPaymentController < BaseReportController
|
||||
authorize_resource :class => false
|
||||
def index
|
||||
|
||||
@filter_for_credit = [['All',''],['Paid','paid'],['Unpaid','unpaid']]
|
||||
from, to = get_date_range_from_params
|
||||
|
||||
@shift_sale_range = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED)
|
||||
@@ -17,10 +17,12 @@ authorize_resource :class => false
|
||||
end
|
||||
end
|
||||
|
||||
@sale_data = Sale.get_by_shift_sale_credit_payment(@shift_sale_range,@shift,from,to)
|
||||
@filter = params[:filter_check]
|
||||
@sale_data = Sale.get_by_shift_sale_credit_payment(@shift_sale_range,@shift,from,to,@filter)
|
||||
|
||||
@from = from
|
||||
@to = to
|
||||
|
||||
# get printer info
|
||||
@print_settings = PrintSetting.get_precision_delimiter()
|
||||
if @shift.present?
|
||||
|
||||
@@ -1099,18 +1099,56 @@ def self.get_shift_sales_by_receipt_no_detail(shift_sale_range,shift,from,to,pay
|
||||
return query
|
||||
end
|
||||
|
||||
def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to)
|
||||
query = SalePayment.select("s.receipt_no, sale_payments.*,s.receipt_date as sale_date,
|
||||
s.cashier_name as cashier_name")
|
||||
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
||||
def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to,filter)
|
||||
puts "filter"
|
||||
puts filter
|
||||
sub_query = "SELECT (CASE WHEN SUM(payment_amount) > 0
|
||||
THEN DATE_FORMAT(CONVERT_TZ(sale_payments.created_at,'+00:00','+06:30'),'%d %b %y %h:%i%p') ELSE '-' END)
|
||||
FROM SXRestaurants_development.`sale_payments`
|
||||
INNER JOIN SXRestaurants_development.sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
|
||||
WHERE sale_audits.sale_id = s.sale_id"
|
||||
|
||||
if shift.present?
|
||||
query = query.where("payment_method= 'creditnote' and s.sale_status = 'completed' and s.shift_sale_id in (?)",shift.to_a)
|
||||
elsif shift_sale_range.present?
|
||||
query = query.where("payment_method='creditnote' and s.sale_status = 'completed' and s.shift_sale_id in (?)",shift_sale_range.to_a)
|
||||
else
|
||||
query = query.where("payment_method='creditnote' and s.sale_status = 'completed' and s.receipt_date between ? and ? ",from,to)
|
||||
end
|
||||
sub_query1 = "SELECT (CASE WHEN SUM(payment_amount) > 0 THEN SUM(payment_amount) ELSE 0 END)
|
||||
FROM SXRestaurants_development.`sale_payments`
|
||||
INNER JOIN SXRestaurants_development.sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
|
||||
WHERE sale_audits.sale_id = s.sale_id"
|
||||
|
||||
sub_query2 = "SELECT (CASE WHEN shift_closed_at IS NOT NULL AND credit_payment > 0
|
||||
THEN CONCAT(DATE_FORMAT(CONVERT_TZ(shift_started_at,'+00:00','+06:30'),'%d %b %y %h:%i%p'),' - ',DATE_FORMAT(CONVERT_TZ(shift_closed_at,'+00:00','+06:30'),'%d %b %y %h:%i%p'))
|
||||
ELSE '-' END)
|
||||
FROM SXRestaurants_development.shift_sales
|
||||
WHERE shift_sales.id = s.shift_sale_id"
|
||||
|
||||
sub_query3 = "SELECT (CASE WHEN shift_closed_at IS NOT NULL AND credit_payment > 0
|
||||
THEN employees.name ELSE '-' END)
|
||||
FROM SXRestaurants_development.shift_sales
|
||||
INNER JOIN SXRestaurants_development.employees ON employees.id=shift_sales.employee_id
|
||||
WHERE shift_sales.id = s.shift_sale_id"
|
||||
|
||||
filter_check = ""
|
||||
if filter == 'paid'
|
||||
filter_check = " AND ss.credit_sales = 0"
|
||||
elsif filter == 'unpaid'
|
||||
filter_check = " AND ss.credit_sales > 0"
|
||||
end
|
||||
|
||||
query = SalePayment.select("s.receipt_no, sale_payments.*,s.receipt_date as sale_date,
|
||||
s.cashier_name as cashier_name,
|
||||
(#{sub_query}) as credit_payment_receipt_date,
|
||||
(#{sub_query1}) as credit_payment,
|
||||
(#{sub_query3}) as credit_payment_cashier_name,
|
||||
(#{sub_query2}) as credit_payment_shift_name")
|
||||
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
||||
.joins("INNER JOIN shift_sales ss ON ss.id = s.shift_sale_id")
|
||||
|
||||
if shift.present?
|
||||
query = query.where("sale_payments.payment_method= 'creditnote' and s.sale_status = 'completed' #{filter_check} and s.shift_sale_id in (?)",shift.to_a)
|
||||
elsif shift_sale_range.present?
|
||||
query = query.where("sale_payments.payment_method='creditnote' and s.sale_status = 'completed' #{filter_check} and s.shift_sale_id in (?)",shift_sale_range.to_a)
|
||||
else
|
||||
query = query.where("sale_payments.payment_method='creditnote' and s.sale_status = 'completed' #{filter_check} and s.receipt_date between ? and ? ",from,to)
|
||||
end
|
||||
query = query.group("sale_payments.sale_payment_id")
|
||||
end
|
||||
|
||||
def self.get_void_sale(shift,from,to)
|
||||
|
||||
@@ -18,7 +18,12 @@
|
||||
<option value="9">Last year</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<% if defined? filter_for_credit %>
|
||||
<div class="form-group col-md-2">
|
||||
<label class="font-20">Select Paid/ Unpaid</label>
|
||||
<%= select_tag "filter_check", options_for_select(@filter_for_credit, :selected => params[:filter_check]), :class => "form-control", :style => "height: 37px;" %>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="form-group col-md-2">
|
||||
<!-- <label class="">Select Shift Period</label> -->
|
||||
<label class="font-20">From</label>
|
||||
@@ -28,7 +33,7 @@
|
||||
<label class="font-20">To</label>
|
||||
<input data-behaviour='datepicker' class="form-control datepicker m-t-3" name="to" id="to" type="text" placeholder="To date" style="height: 34px;">
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<div class="form-group col-md-2">
|
||||
<label class="font-20">All Shift</label>
|
||||
<select class="form-control select" name="shift_name" id="shift_name" style="height: 37px;">
|
||||
</select>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
</div>
|
||||
<!-- <div class="container"> -->
|
||||
<%= render :partial=>'shift_sale_report_filter',
|
||||
:locals=>{ :period_type => true, :shift_name => true, :report_path =>reports_credit_payment_index_path} %>
|
||||
:locals=>{ :period_type => true, :filter_for_credit => true, :shift_name => true, :report_path =>reports_credit_payment_index_path} %>
|
||||
<hr />
|
||||
<!-- </div> -->
|
||||
|
||||
@@ -48,13 +48,21 @@
|
||||
<th> <%= t("views.right_panel.detail.shift_name") %> </th>
|
||||
<th> <%= t("views.right_panel.detail.receipt_no") %></th>
|
||||
<th> <%= t :cashier %> <%= t("views.right_panel.detail.name") %></th>
|
||||
<th> <%= t :customer %> <%= t("views.right_panel.detail.name") %></th>
|
||||
<th> <%= t :customer %> <%= t("views.right_panel.detail.name") %></th>
|
||||
<th> <%= t("views.right_panel.detail.credit_amount") %> </th>
|
||||
<th> <%= t :credit %> <%= t :payment %> <br>
|
||||
<%= t("views.right_panel.detail.shift_name") %></th>
|
||||
<th> <%= t :credit %> <%= t("views.right_panel.detail.receipt_date") %></th>
|
||||
<th> <%= t :credit %> <%= t :payment %> <br> <%= t :cashier_name %></th>
|
||||
<th> <%= t :credit %> <%= t :payment %> <%= t("views.right_panel.detail.amount") %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% total_credit_amount = 0
|
||||
total_credit_payment = 0 %>
|
||||
<% @sale_data.each do |credit| %>
|
||||
|
||||
<% total_credit_amount += credit.payment_amount %>
|
||||
<% total_credit_payment += credit.credit_payment %>
|
||||
<tr>
|
||||
<% if @shift_from.nil? && @shift_to.nil? %>
|
||||
<td><%= credit.sale_date.utc.getlocal.strftime("%e %b %I:%M%p") rescue '-'%></td>
|
||||
@@ -65,8 +73,17 @@
|
||||
<td><%= credit.cashier_name rescue '-' %></td>
|
||||
<td><%= credit.sale.customer.name rescue '-' %></td>
|
||||
<td><%= number_with_precision(credit.payment_amount, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
|
||||
<td><%= credit.credit_payment_shift_name rescue '-' %></td>
|
||||
<td><%= credit.credit_payment_receipt_date rescue '-' %></td>
|
||||
<td><%= credit.credit_payment_cashier_name rescue '-' %></td>
|
||||
<td><%= number_with_precision(credit.credit_payment, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<tr>
|
||||
<td colspan="4"><b>Total</b></td>
|
||||
<td colspan="4"><b><%= number_with_precision(total_credit_amount, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></b></td>
|
||||
<td><b><%= number_with_precision(total_credit_payment, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></b></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<% end %>
|
||||
|
||||
@@ -20,13 +20,21 @@
|
||||
<th> <%= t("views.right_panel.detail.shift_name") %> </th>
|
||||
<th> <%= t("views.right_panel.detail.receipt_no") %></th>
|
||||
<th> <%= t :cashier %> <%= t("views.right_panel.detail.name") %></th>
|
||||
<th> <%= t :customer %> <%= t("views.right_panel.detail.name") %></th>
|
||||
<th> <%= t :customer %> <%= t("views.right_panel.detail.name") %></th>
|
||||
<th> <%= t("views.right_panel.detail.credit_amount") %> </th>
|
||||
<th> <%= t :credit %> <%= t :payment %> <br>
|
||||
<%= t("views.right_panel.detail.shift_name") %></th>
|
||||
<th> <%= t :credit %> <%= t("views.right_panel.detail.receipt_date") %></th>
|
||||
<th> <%= t :credit %> <%= t :payment %> <br> <%= t :cashier_name %></th>
|
||||
<th> <%= t :credit %> <%= t :payment %> <%= t("views.right_panel.detail.amount") %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% total_credit_amount = 0
|
||||
total_credit_payment = 0 %>
|
||||
<% @sale_data.each do |credit| %>
|
||||
|
||||
<% total_credit_amount += credit.payment_amount
|
||||
total_credit_payment += credit.credit_payment %>
|
||||
<tr>
|
||||
<% if @shift_from.nil? && @shift_to.nil? %>
|
||||
<td><%= credit.sale_date.utc.getlocal.strftime("%e %b %I:%M%p") rescue '-'%></td>
|
||||
@@ -37,8 +45,17 @@
|
||||
<td><%= credit.cashier_name rescue '-' %></td>
|
||||
<td><%= credit.sale.customer.name rescue '-' %></td>
|
||||
<td><%= credit.payment_amount rescue '-' %></td>
|
||||
<td><%= credit.credit_payment_shift_name rescue '-' %></td>
|
||||
<td><%= credit.credit_payment_receipt_date rescue '-' %></td>
|
||||
<td><%= credit.credit_payment_cashier_name rescue '-' %></td>
|
||||
<td><%= credit.credit_payment rescue '-' %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<tr>
|
||||
<td colspan="4"><b>Total</b></td>
|
||||
<td colspan="4"><b><%= total_credit_amount rescue '-' %></b></td>
|
||||
<td><b><%= total_credit_payment rescue '-' %></b></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user