update report and view

This commit is contained in:
Aung Myo
2017-07-28 17:07:16 +06:30
parent 24fd399c17
commit 98c04f21d8
14 changed files with 815 additions and 29 deletions

View File

@@ -15,7 +15,7 @@ class Origami::HomeController < BaseOrigamiController
@rooms = Room.all.active.order('status desc')
@complete = Sale.where("sale_status != 'new'")
@orders = Order.all.order('date desc')
@shop = Shop.find_by_id(1)
@status_order = ""
@status_sale = ""
@sale_array = Array.new

View File

@@ -166,7 +166,14 @@ class Origami::PaymentsController < BaseOrigamiController
def rounding_adj
saleObj = Sale.find(params[:sale_id])
new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
@shop = Shop.find_by_id(1)
if @shop.is_rounding_adj
new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
else
new_total = saleObj.grand_total
end
rounding_adj = new_total-saleObj.grand_total
saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj)

View File

@@ -0,0 +1,61 @@
class Reports::CreditPaymentController < BaseReportController
authorize_resource :class => false
def index
from, to = get_date_range_from_params
@shift_sale_range = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED)
@shift = ''
if params[:shift_name].to_i != 0
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
@shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at)
end
end
@sale_data = Sale.get_by_shift_sale_credit_payment(@shift_sale_range,@shift,from,to)
@from = from
@to = to
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
def show
from, to = get_date_range_from_params
@sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED)
date_arr = Array.new
@sale_data.each do |sale|
local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p")
local_closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc.getlocal.strftime("%e %b %I:%M%p")
opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc
closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc
shift_id = sale.id.nil? ? '-' : sale.id
str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date}
date_arr.push(str)
end
out = {:status => 'ok', :message => date_arr}
respond_to do |format|
format.json { render json: out }
end
end
end

View File

@@ -0,0 +1,60 @@
class Reports::VoidSaleController < BaseReportController
authorize_resource :class => false
def index
from, to = get_date_range_from_params
# @shift_sale_range = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED)
@shift = ''
if params[:shift_name].to_i != 0
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
@shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at)
end
end
@sale_data = Sale.get_void_sale(@shift,from,to)
@from = from
@to = to
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
def show
from, to = get_date_range_from_params
@sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED)
date_arr = Array.new
@sale_data.each do |sale|
local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p")
local_closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc.getlocal.strftime("%e %b %I:%M%p")
opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc
closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc
shift_id = sale.id.nil? ? '-' : sale.id
str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date}
date_arr.push(str)
end
out = {:status => 'ok', :message => date_arr}
respond_to do |format|
format.json { render json: out }
end
end
end

View File

@@ -68,7 +68,7 @@ class Ability
can :overall_void, :void
elsif user.role == "cashier"
can :overall_void, :void
can :read, Order
can :update, Order

View File

@@ -642,10 +642,36 @@ def self.get_shift_sales_by_receipt_no(shift_sale_range,shift,from,to,payment_ty
query = query.where("sale_status='completed' and sales.receipt_date between ? and ? #{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
end
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")
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
end
def self.get_void_sale(shift,from,to)
sale_arr = Array.new
account= Sale.select("sales.receipt_no,sales.receipt_date, sales.payment_status, sales.sale_status,sales.total_amount,sales.grand_total, sales.rounding_adjustment")
.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 ?
OR sh.shift_closed_at between ? and ? )", from ,to, from, to)
out = {:items => account}
sale_arr.push(out)
return sale_arr
end
def self.get_separate_tax(shift_sale_range=nil,shift,from,to,payment_type)
if payment_type.blank?
@@ -680,18 +706,6 @@ def self.get_separate_tax(shift_sale_range=nil,shift,from,to,payment_type)
.group("sale_taxes.tax_name")
.order("sale_taxes.sale_tax_id asc")
end
# query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name")
# .joins("INNER JOIN sales ON sales.sale_id = sale_taxes.sale_id")
# .joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
# .group("sale_taxes.tax_name")
# .order("sale_taxes.sale_tax_id asc")
# if shift.present?
# query = query.where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed'", shift.to_a)
# else
# query = query.where("sales.receipt_date between ? and ? #{payment_type} and sale_status= 'completed' ",from,to)
# end
end
# def self.get_separate_tax(from,to,payment_method=nil)

View File

@@ -20,7 +20,6 @@
</li>
</ul>
<!-- Nav tabs - End -->
<input type="hidden" id="rounding_adj" value="<%= @shop.is_rounding_adj %>">
<div class="tab-content">
<!--- Panel 0 - Completed Orders -->
@@ -452,9 +451,7 @@ $("#first_bill").on('click', function(){
$('#pay').on('click',function() {
var sale_id = $('#sale_id').val();
var rounding_adj = $('#rounding_adj').val();
if(rounding_adj == "true"){
var url = '/origami/sale/'+ sale_id + "/rounding_adj" ;
$.ajax({
type: "POST",
@@ -463,9 +460,7 @@ $('#pay').on('click',function() {
window.location.href = '/origami/sale/'+ sale_id + "/payment";
}
});
}else{
window.location.href = '/origami/sale/'+ sale_id + "/payment";
}
});

View File

@@ -0,0 +1,125 @@
<div class="row">
<div class="col-md-12">
<%= form_tag report_path, :method => :get, :id=>"frm_report", :class => "form" do %>
<% if period_type != false %>
<div class="row">
<div class="form-group col-md-2">
<label>Select Period</label>
<select name="period" id="sel_period" class="form-control">
<option value="">Select Period</option>
<option value="0">Today</option>
<option value="1">Yesterday</option>
<option value="2">This week</option>
<option value="3">Last week</option>
<option value="4">Last 7 days</option>
<option value="5">This month</option>
<option value="6">Last month</option>
<option value="7">Last 30 days</option>
<option value="8">This year</option>
<option value="9">Last year</option>
</select>
</div>
<div class="form-group col-md-2">
<!-- <label class="">Select Shift Period</label> -->
<label class="">From</label>
<input data-behaviour='datepicker' class="form-control" name="from" id="from" type="text" placeholder="From date">
</div>
<div class="form-group col-md-2">
<label class="">To</label>
<input data-behaviour='datepicker' class="form-control" name="to" id="to" type="text" placeholder="To date">
</div>
<div class="form-group col-md-3">
<label class="">All Shift</label>
<select class="form-control select" name="shift_name" id="shift_name" >
</select>
</div>
<div class="form-group col-md-1 margin-top-20">
<input type="submit" value="Generate Report" class='btn btn-primary'>
</div>
</div>
<% end %>
<% end %>
</div>
</div>
<script type="text/javascript">
$(function(){
$('#custom_excel').hide();
$('#custom_excel').click(function(){
var url = $('#custom_excel').attr('data-url');
$('#frm_report').attr('action',url)
$('#frm_report').submit();
// window.location = url;
});
var item = $('#item').val();
var payment_type = $('#payment_type');
if(item == 'order'){
$('#cashier').hide();
$('#waiter').show();
if(payment_type){
$('#payment_type').hide();
}
}
else if(item == 'sale'){
$('#waiter').hide();
$('#cashier').show();
}
else{
$('#waiter').hide();
$('#cashier').show();
$("#item").val('sale');
}
});
<% if params[:shift_name].to_i > 0%>
shift_id = '<%= params[:shift_name] %>'
local_date = '<%= @shift_from %> - <%= @shift_to %> '
var shift = $('#shift_name');
str = '<option value="'+ shift_id +'" '+ 'selected = "selected"' +'>' + local_date + '</option>';
shift.append(str);
<% end %>
$("#from").val("<%=params[:from] rescue '-'%>");
$("#to").val("<%=params[:to] rescue '-'%>");
$("#sel_period").val(<%=params[:period] rescue '-'%>);
$("#sel_sale_type").val(<%=params[:sale_type] rescue '-'%>);
// shift = $(".shift-id").text()
// if (shift.length>0) {
// $('.shift_name > option[value="'+shift+'"]').attr('selected','selected');
// }
<% if params[:period_type] == 1 || params[:period_type] == "1" %>
$("#rd_period_type_1").attr("checked","checked");
<% else %>
$("#rd_period_type_0").attr("checked","checked");
<% end %>
$(".btn-group button").removeClass("active");
<% report_type = params[:report_type].blank? ? "0" : params[:report_type] %>
$("#btn_report_type_<%= report_type %>").addClass("active");
$('#item').change(function(){
var item = $('#item').val();
var payment_type = $('#payment_type');
if(item == 'sale'){
$('#waiter').hide();
$('#cashier').show();
if(payment_type){
$('#payment_type').show();
}
}
else{
$('#cashier').hide();
$('#waiter').show();
if(payment_type){
$('#payment_type').hide();
}
}
});
</script>

View File

@@ -0,0 +1,150 @@
<div class="page-header">
<ul class="breadcrumb">
<li><a href="<%= dashboard_path %>">Home</a></li>
<li>Credit Payment List Report</li>
</ul>
</div>
<div class="container">
<%= render :partial=>'shift_sale_report_filter',
:locals=>{ :period_type => true, :shift_name => true, :report_path =>reports_credit_payment_index_path} %>
<hr />
</div>
<div class="container">
<div class="row">
<div class="col-md-12 text-right">
<a href="javascript:export_to('<%=reports_credit_payment_index_path%>.xls')" class = "btn btn-default">Export to Excel</a>
</div>
</div>
</div>
<div class="container margin-top-20">
<div class="card row">
<% unless @sale_data.blank? %>
<table class="table table-striped" border="0">
<thead>
<% if !params[:from].blank?%>
<tr>
<th colspan="7">From Date : <%= params[:from] rescue '-'%> , To Date : <%= params[:to] rescue '-'%></th>
</tr>
<% end %>
<tr>
<th> Shift Name </th>
<th> Receive No</th>
<th> Cashier Name</th>
<th> Customer Name</th>
<th> Credit Amount </th>
</tr>
</thead>
<tbody>
<% @sale_data.each do |credit| %>
<tr>
<% if @shift_from.nil? && @shift_to.nil? %>
<td><%= credit.sale_date.utc.getlocal.strftime("%e %b %I:%M%p") rescue '-'%></td>
<% else %>
<td><%= @shift_from rescue '-'%> - <%= @shift_to rescue '-'%></td>
<% end %>
<td><%= credit.receipt_no rescue '-' %></td>
<td><%= credit.cashier_name rescue '-' %></td>
<td><%= credit.sale.customer.name rescue '-' %></td>
<td><%= credit.payment_amount rescue '-' %></td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
</div>
</div>
<script>
$(function(){
var check_arr = [];
$('#sel_period').change(function(){
search_by_period();
});
function search_by_period(){
var period = $('#sel_period').val();
var period_type = 0;
var from = "";
var to = "";
show_shift_name(period,period_type,from,to,'shift_item');
}
$('#from').change(function(){
search_by_date();
});
$('#to').change(function(){
search_by_date();
});
function search_by_date(){
var from = $('#from').val();
var to = $('#to').val();
var period = 0;
var period_type = 1;
if(to != '' && from != ''){
shift_name = from + ',' + to;
check_arr.push(to);
console.log(check_arr.length)
if(check_arr.length == 1){
show_shift_name(period,period_type,from,to,'shift_item');
}
if(check_arr.length == 3){
check_arr = [];
}
}
}
function show_shift_name(period,period_type,from,to,shift_item){
var shift = $('#shift_name');
shift.empty();
var str = '';
var param_shift = '';
var param_shift = '<%= params[:shift_name] rescue '-'%>';
url = '<%= reports_get_shift_by_date_path %>';
$.get(url, {period :period, period_type :period_type, from :from, to :to, report_type :shift_item} , function(data){
str = '<option value="0">--- All Shift ---</option>';
$(data.message).each(function(index){
var local_date = data.message[index].local_opening_date + ' - ' + data.message[index].local_closing_date;
var sh_date = data.message[index].opening_date + ' - ' + data.message[index].closing_date;
var shift_id = data.message[index].shift_id ;
if(param_shift != ''){
if(shift_id == param_shift){
selected = 'selected = "selected"';
}
else{
selected = '';
}
}else{
selected = '';
}
str += '<option value="'+ shift_id +'" '+ selected +'>' + local_date + '</option>';
// console.log(sh_date)
})
shift.append(str);
});
}
});
</script>

View File

@@ -0,0 +1,39 @@
<div class="container margin-top-20">
<div class="card row">
<% unless @sale_data.blank? %>
<table class="table table-striped" border="0">
<thead>
<% if !params[:from].blank?%>
<tr>
<th colspan="7">From Date : <%= params[:from] rescue '-'%> , To Date : <%= params[:to] rescue '-'%></th>
</tr>
<% end %>
<tr>
<th> Shift Name </th>
<th> Receive No</th>
<th> Cashier Name</th>
<th> Customer Name</th>
<th> Credit Amount </th>
</tr>
</thead>
<tbody>
<% @sale_data.each do |credit| %>
<tr>
<% if @shift_from.nil? && @shift_to.nil? %>
<td><%= credit.sale_date.utc.getlocal.strftime("%e %b %I:%M%p") rescue '-'%></td>
<% else %>
<td><%= @shift_from rescue '-'%> - <%= @shift_to rescue '-'%></td>
<% end %>
<td><%= credit.receipt_no rescue '-' %></td>
<td><%= credit.cashier_name rescue '-' %></td>
<td><%= credit.sale.customer.name rescue '-' %></td>
<td><%= credit.payment_amount rescue '-' %></td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
</div>
</div>

View File

@@ -0,0 +1,125 @@
<div class="row">
<div class="col-md-12">
<%= form_tag report_path, :method => :get, :id=>"frm_report", :class => "form" do %>
<% if period_type != false %>
<div class="row">
<div class="form-group col-md-2">
<label>Select Period</label>
<select name="period" id="sel_period" class="form-control">
<option value="">Select Period</option>
<option value="0">Today</option>
<option value="1">Yesterday</option>
<option value="2">This week</option>
<option value="3">Last week</option>
<option value="4">Last 7 days</option>
<option value="5">This month</option>
<option value="6">Last month</option>
<option value="7">Last 30 days</option>
<option value="8">This year</option>
<option value="9">Last year</option>
</select>
</div>
<div class="form-group col-md-2">
<!-- <label class="">Select Shift Period</label> -->
<label class="">From</label>
<input data-behaviour='datepicker' class="form-control" name="from" id="from" type="text" placeholder="From date">
</div>
<div class="form-group col-md-2">
<label class="">To</label>
<input data-behaviour='datepicker' class="form-control" name="to" id="to" type="text" placeholder="To date">
</div>
<div class="form-group col-md-3">
<label class="">All Shift</label>
<select class="form-control select" name="shift_name" id="shift_name" >
</select>
</div>
<div class="form-group col-md-1 margin-top-20">
<input type="submit" value="Generate Report" class='btn btn-primary'>
</div>
</div>
<% end %>
<% end %>
</div>
</div>
<script type="text/javascript">
$(function(){
$('#custom_excel').hide();
$('#custom_excel').click(function(){
var url = $('#custom_excel').attr('data-url');
$('#frm_report').attr('action',url)
$('#frm_report').submit();
// window.location = url;
});
var item = $('#item').val();
var payment_type = $('#payment_type');
if(item == 'order'){
$('#cashier').hide();
$('#waiter').show();
if(payment_type){
$('#payment_type').hide();
}
}
else if(item == 'sale'){
$('#waiter').hide();
$('#cashier').show();
}
else{
$('#waiter').hide();
$('#cashier').show();
$("#item").val('sale');
}
});
<% if params[:shift_name].to_i > 0%>
shift_id = '<%= params[:shift_name] %>'
local_date = '<%= @shift_from %> - <%= @shift_to %> '
var shift = $('#shift_name');
str = '<option value="'+ shift_id +'" '+ 'selected = "selected"' +'>' + local_date + '</option>';
shift.append(str);
<% end %>
$("#from").val("<%=params[:from] rescue '-'%>");
$("#to").val("<%=params[:to] rescue '-'%>");
$("#sel_period").val(<%=params[:period] rescue '-'%>);
$("#sel_sale_type").val(<%=params[:sale_type] rescue '-'%>);
// shift = $(".shift-id").text()
// if (shift.length>0) {
// $('.shift_name > option[value="'+shift+'"]').attr('selected','selected');
// }
<% if params[:period_type] == 1 || params[:period_type] == "1" %>
$("#rd_period_type_1").attr("checked","checked");
<% else %>
$("#rd_period_type_0").attr("checked","checked");
<% end %>
$(".btn-group button").removeClass("active");
<% report_type = params[:report_type].blank? ? "0" : params[:report_type] %>
$("#btn_report_type_<%= report_type %>").addClass("active");
$('#item').change(function(){
var item = $('#item').val();
var payment_type = $('#payment_type');
if(item == 'sale'){
$('#waiter').hide();
$('#cashier').show();
if(payment_type){
$('#payment_type').show();
}
}
else{
$('#cashier').hide();
$('#waiter').show();
if(payment_type){
$('#payment_type').hide();
}
}
});
</script>

View File

@@ -0,0 +1,175 @@
<div class="page-header">
<ul class="breadcrumb">
<li><a href="<%= dashboard_path %>">Home</a></li>
<li>Credit Payment List Report</li>
</ul>
</div>
<div class="container">
<%= render :partial=>'shift_sale_report_filter',
:locals=>{ :period_type => true, :shift_name => true, :report_path =>reports_void_sale_index_path} %>
<hr />
</div>
<div class="container">
<div class="row">
<div class="col-md-12 text-right">
<a href="javascript:export_to('<%=reports_void_sale_index_path%>.xls')" class = "btn btn-default">Export to Excel</a>
</div>
</div>
</div>
<div class="container margin-top-20">
<div class="card row">
<% if @sale_data.count > 0 %>
<table class="table table-striped" border="0">
<thead>
<% if !params[:from].blank?%>
<tr>
<th colspan="7">From Date : <%= params[:from] rescue '-'%> , To Date : <%= params[:to] rescue '-'%></th>
</tr>
<% end %>
<% if @shift_from %>
<tr>
<% if @shift.cashier_id %>
<% cashier_name = !@shift.nil? ? @shift.employee.name : '-' %>
<% end %>
<th colspan="3">Shift Name = <%= @shift_from rescue '-'%> - <%= @shift_to rescue '-'%> ( <%= cashier_name rescue '-'%> )</th>
</tr>
<% end %>
<tr>
<th>Receipt No</th>
<th>Sale Date</th>
<th>Total Amount</th>
<th>Grand Total</th>
<th>Rounding Adj.</th>
<th>Grand Total + <br/>Rounding Adj.</th>
<th>Sale Status</th>
<th>Remarks</th>
</tr>
</thead>
<tbody>
<% total_amount = 0.0 %>
<% grand_total = 0.0 %>
<% rounding_adjustment = 0.0 %>
<% grand_rounding_adjustment = 0.0 %>
<% @sale_data.each do |result| %>
<% result[:items].each do |item| %>
<tr>
<td><%= item.receipt_no rescue '-' %> </td>
<td><%= item.date.utc.getlocal.strftime("%e %b %I:%M%p") rescue '-' %></td>
<td><%= item.total_amount.to_f rescue '-'%> </td>
<td><%= item.grand_total.to_f rescue '-'%> </td>
<td><%= item.rounding_adjustment.to_f rescue '-' %></td>
<td><%= item.grand_total.to_f + item.rounding_adjustment.to_f rescue '-'%> </td>
<td><%= item.sales_status rescue '-' %> </td>
<td><%= item.remarks rescue '-' %> </td>
</tr>
<% total_amount = total_amount.to_f + item.total_amount.to_f %>
<% grand_total = grand_total.to_f + item.grand_total.to_f %>
<% rounding_adjustment = rounding_adjustment.to_f + item.rounding_adjustment.to_f %>
<% grand_rounding_adjustment = grand_rounding_adjustment.to_f + item.grand_total.to_f + item.rounding_adjustment.to_f %>
<% end %>
<% end %>
<tr style="border-top:4px double #666;font-weight:600;">
<td colspan="2" style="text-align:center;">Total Void Amount :</td>
<td><%= total_amount rescue '-' %></td>
<td><%= grand_total rescue '-' %></td>
<td><%= rounding_adjustment rescue '-'%></td>
<td colspan="3"><%= grand_rounding_adjustment rescue '-'%></td>
</tr>
</tbody>
</table>
<% end %>
</div>
</div>
<script>
$(function(){
var check_arr = [];
$('#sel_period').change(function(){
search_by_period();
});
function search_by_period(){
var period = $('#sel_period').val();
var period_type = 0;
var from = "";
var to = "";
show_shift_name(period,period_type,from,to,'shift_item');
}
$('#from').change(function(){
search_by_date();
});
$('#to').change(function(){
search_by_date();
});
function search_by_date(){
var from = $('#from').val();
var to = $('#to').val();
var period = 0;
var period_type = 1;
if(to != '' && from != ''){
shift_name = from + ',' + to;
check_arr.push(to);
console.log(check_arr.length)
if(check_arr.length == 1){
show_shift_name(period,period_type,from,to,'shift_item');
}
if(check_arr.length == 3){
check_arr = [];
}
}
}
function show_shift_name(period,period_type,from,to,shift_item){
var shift = $('#shift_name');
shift.empty();
var str = '';
var param_shift = '';
var param_shift = '<%= params[:shift_name] rescue '-'%>';
url = '<%= reports_get_shift_by_date_path %>';
$.get(url, {period :period, period_type :period_type, from :from, to :to, report_type :shift_item} , function(data){
str = '<option value="0">--- All Shift ---</option>';
$(data.message).each(function(index){
var local_date = data.message[index].local_opening_date + ' - ' + data.message[index].local_closing_date;
var sh_date = data.message[index].opening_date + ' - ' + data.message[index].closing_date;
var shift_id = data.message[index].shift_id ;
if(param_shift != ''){
if(shift_id == param_shift){
selected = 'selected = "selected"';
}
else{
selected = '';
}
}else{
selected = '';
}
str += '<option value="'+ shift_id +'" '+ selected +'>' + local_date + '</option>';
// console.log(sh_date)
})
shift.append(str);
});
}
});
</script>

View File

@@ -0,0 +1,39 @@
<div class="container margin-top-20">
<div class="card row">
<% unless @sale_data.blank? %>
<table class="table table-striped" border="0">
<thead>
<% if !params[:from].blank?%>
<tr>
<th colspan="7">From Date : <%= params[:from] rescue '-'%> , To Date : <%= params[:to] rescue '-'%></th>
</tr>
<% end %>
<tr>
<th> Shift Name </th>
<th> Receive No</th>
<th> Cashier Name</th>
<th> Customer Name</th>
<th> Credit Amount </th>
</tr>
</thead>
<tbody>
<% @sale_data.each do |credit| %>
<tr>
<% if @shift_from.nil? && @shift_to.nil? %>
<td><%= credit.sale_date.utc.getlocal.strftime("%e %b %I:%M%p") rescue '-'%></td>
<% else %>
<td><%= @shift_from rescue '-'%> - <%= @shift_to rescue '-'%></td>
<% end %>
<td><%= credit.receipt_no rescue '-' %></td>
<td><%= credit.cashier_name rescue '-' %></td>
<td><%= credit.sale.customer.name rescue '-' %></td>
<td><%= credit.payment_amount rescue '-' %></td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
</div>
</div>

View File

@@ -276,14 +276,10 @@ Rails.application.routes.draw do
resources :dailysale, :only => [:index, :show]
resources :saleitem, :only => [:index, :show]
resources :shiftsale, :only => [:index, :show]
resources :credit_payment, :only => [:index, :show]
resources :void_sale, :only => [:index, :show]
get "receipt_no/get_shift_by_date", to: "receipt_no#get_shift_by_date", as: "get_shift_by_date"
# resources :sales, :only => [:index, :show]
# resources :orders, :only => [:index, :show]
# resources :customers, :only => [:index, :show]
# resources :products, :only => [:index, :show]
# resources :inventory, :only => [:index, :show]
# resources :employees, :only => [:index, :show]
end
#mount_compendium at: '/report' #, controller: 'reports'