update shift sale
This commit is contained in:
3
app/assets/javascripts/reports/shiftsale.coffee
Normal file
3
app/assets/javascripts/reports/shiftsale.coffee
Normal file
@@ -0,0 +1,3 @@
|
||||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||
3
app/assets/stylesheets/reports/shiftsale.scss
Normal file
3
app/assets/stylesheets/reports/shiftsale.scss
Normal file
@@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the reports/shiftsale controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
@@ -9,7 +9,12 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
sale_data = Sale.find_by_sale_id(sale_id)
|
||||
sale_items = SaleItem.where("sale_id=?",sale_id)
|
||||
|
||||
new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
|
||||
rounding_adj = sale_data.grand_total - new_total
|
||||
|
||||
sale_data.update_attributes(grand_total: new_total,rounding_adjustment:rounding_adj)
|
||||
# Print for First Bill to Customer
|
||||
|
||||
unique_code = "ReceiptBillPdf"
|
||||
#shop detail
|
||||
shop_details = Shop.find(1)
|
||||
|
||||
18
app/controllers/reports/shiftsale_controller.rb
Normal file
18
app/controllers/reports/shiftsale_controller.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
class Reports::ShiftsaleController < ApplicationController
|
||||
# authorize_resource :class => false
|
||||
|
||||
def index
|
||||
|
||||
from, to, report_type = get_date_range_from_params
|
||||
@sale_data = Sale.get_by_shiftsales(from,to)
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xls
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
2
app/helpers/reports/shiftsale_helper.rb
Normal file
2
app/helpers/reports/shiftsale_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module Reports::ShiftsaleHelper
|
||||
end
|
||||
@@ -45,6 +45,7 @@ class Ability
|
||||
can :remove_discount_items, :discount
|
||||
can :remove_all_discount, :discount
|
||||
|
||||
can :first_bill, :payment
|
||||
can :show, :payment
|
||||
can :create, :payment
|
||||
can :reprint, :payment
|
||||
|
||||
@@ -322,6 +322,41 @@ class Sale < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.get_rounding_adjustment(num)
|
||||
## 0 -- 25 -- 50 -- 75 -- 100
|
||||
# if get_rounded_amt == true
|
||||
value = 0
|
||||
|
||||
num = num.to_f.round
|
||||
get_last_no = num.to_s.last(2).to_f
|
||||
if get_last_no.between?(0,25)
|
||||
## down to 0
|
||||
num -= get_last_no
|
||||
else
|
||||
if get_last_no.between?(26,50)
|
||||
## up to 50
|
||||
value = 50 - get_last_no.to_f
|
||||
num += value
|
||||
puts 'up to 50'
|
||||
else
|
||||
if get_last_no.between?(51, 75)
|
||||
## down to 50
|
||||
value = get_last_no.to_f - 50
|
||||
num -= value
|
||||
puts 'down to 50'
|
||||
else
|
||||
## up to 100
|
||||
value = 100 - get_last_no.to_f
|
||||
num += value
|
||||
puts 'up to 100'
|
||||
end
|
||||
end
|
||||
end
|
||||
# end
|
||||
return num
|
||||
end
|
||||
|
||||
|
||||
def self.daily_sales_list(from,to)
|
||||
payments_total = Sale.select("CAST((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')) AS DATE) as sale_date,
|
||||
SUM(case when (sale_payments.payment_method='mpu') then sale_payments.payment_amount else 0 end) as mpu_amount,
|
||||
@@ -387,13 +422,13 @@ def self.get_by_range_by_saleitems(from,to,status,report_type)
|
||||
.group('mi.id')
|
||||
.order("mi.menu_category_id")
|
||||
|
||||
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id
|
||||
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id
|
||||
JOIN menu_items mi ON i.product_code = mi.item_code" +
|
||||
" JOIN menu_categories mc ON mc.id = mi.menu_category_id
|
||||
JOIN employees ea ON ea.id = sales.cashier_id")
|
||||
|
||||
|
||||
query = query.where("receipt_date between ? and ? and sale_status=?",from,to,status)
|
||||
query = query.where("receipt_date between ? and ? and sale_status=?",from,to,status)
|
||||
|
||||
|
||||
|
||||
@@ -409,6 +444,10 @@ def self.get_by_range_by_saleitems(from,to,status,report_type)
|
||||
|
||||
end
|
||||
|
||||
def self.get_by_shiftsales(from,to)
|
||||
return ShiftSale.where("(shift_started_at between ? and ? OR shift_closed_at between ? and ? )", from, to, from, to)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_custom_id
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
<li><%= link_to "Daily Sale Report", reports_dailysale_index_path, :tabindex =>"-1" %></li>
|
||||
<li><%= link_to "Sales Item Report", reports_saleitem_index_path, :tabindex =>"-1" %></li>
|
||||
<li><%= link_to "Receipt Report", reports_receipt_no_index_path, :tabindex =>"-1" %></li>
|
||||
<!-- <li><%= link_to "Shift Sale Report", reports_shiftsale_index_path, :tabindex =>"-1" %></li> -->
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
127
app/views/reports/shiftsale/_shift_sale_report_filter.html.erb
Normal file
127
app/views/reports/shiftsale/_shift_sale_report_filter.html.erb
Normal file
@@ -0,0 +1,127 @@
|
||||
<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="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>
|
||||
<!-- <input type="hidden" name="report_type" value="daily_sale" id="sel_sale_type"> -->
|
||||
<!-- <div class="form-group col-md-2">
|
||||
<label>Select Type</label>
|
||||
<select name="sale_type" id="sel_sale_type" class="form-control">
|
||||
<option value="0">All Sale Type</option>
|
||||
<option value="1">Revenue Only</option>
|
||||
<option value="2">Discount Only</option>
|
||||
<option value="3">Void Only</option>
|
||||
<option value="4">Taxes Only</option>
|
||||
<option value="5">Other Amount Only</option>
|
||||
</select>
|
||||
</div> -->
|
||||
<div class="form-group col-md-3">
|
||||
<!-- <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-3">
|
||||
<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-2 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');
|
||||
}
|
||||
});
|
||||
|
||||
//Reset the form to pervious values
|
||||
$("#branch").val(<%=params[:branch]%>);
|
||||
$("#waiter").val("<%=params[:waiter]%>");
|
||||
$("#cashier").val(<%=params[:cashier]%>);
|
||||
$("#product").val(<%=params[:product]%>);
|
||||
$("#singer").val(<%=params[:singer]%>);
|
||||
$("#item").val('<%=params[:item]%>');
|
||||
$("#guest_role").val('<%=params[:guest_role]%>');
|
||||
|
||||
|
||||
$("#from").val("<%=params[:from]%>");
|
||||
$("#to").val("<%=params[:to]%>");
|
||||
$("#sel_period").val(<%=params[:period]%>);
|
||||
$("#sel_sale_type").val(<%=params[:sale_type]%>);
|
||||
|
||||
<% 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>
|
||||
160
app/views/reports/shiftsale/index.html.erb
Normal file
160
app/views/reports/shiftsale/index.html.erb
Normal file
@@ -0,0 +1,160 @@
|
||||
<div class="page-header">
|
||||
<ul class="breadcrumb">
|
||||
<li><a href="<%= dashboard_path %>">Home</a></li>
|
||||
<li>Shift Sale Report</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<%= render :partial=>'shift_sale_report_filter',
|
||||
:locals=>{ :period_type => true, :shift_name => false, :report_path =>reports_shiftsale_index_path} %>
|
||||
<hr />
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-12 text-right">
|
||||
<a href="javascript:export_to('<%=reports_shiftsale_index_path%>.xls')" class = "btn btn-default">Export to Excel</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container margin-top-20">
|
||||
<!-- <div class="span11">
|
||||
<div id="report_container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
|
||||
</div> -->
|
||||
<div class="card row">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<% if params[:from]%>
|
||||
<tr>
|
||||
<th colspan="7">From Date : <%= params[:from] rescue '-'%> ,To Date : <%= params[:to] rescue '-'%></th>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
<tr>
|
||||
<th>Cashier Station</th>
|
||||
<th>Shift Name</th>
|
||||
<th>Void Amount</th>
|
||||
<th>Cash Payment</th>
|
||||
<th>Credit Charges</th>
|
||||
<th>Credit Payment</th>
|
||||
<th>FOC Payment</th>
|
||||
<th>Card Payment</th>
|
||||
<th>Grand Total +
|
||||
<br/>Rounding Adj</th>
|
||||
<th>Rounding Adj</th>
|
||||
<th>Grand Total</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% void = 0%>
|
||||
<% cash = 0%>
|
||||
<% credit = 0%>
|
||||
<% accept_credit = 0%>
|
||||
<% foc = 0%>
|
||||
<% card = 0%>
|
||||
<% total = 0%>
|
||||
<% rounding_adj = 0%>
|
||||
<% g_total = 0 %>
|
||||
|
||||
<% @sale_data.each do |result| %>
|
||||
<tr>
|
||||
<td>
|
||||
<%= result[:cashier_station_name] rescue '-'%>
|
||||
</td>
|
||||
<td><%= result[:shift_started_at].strftime("%e %b %I:%M%p") rescue '-' %> -
|
||||
<%= result[:shift_closed_at].strftime("%e %b %I:%M%p") rescue '-' %>
|
||||
</td>
|
||||
<!-- <td style='color:red;'>(<%= sprintf "%.2f",result[:void_amount].to_f.to_d rescue '-'%>)</td> -->
|
||||
<td><%= sprintf "%.2f",result[:cash_amount].to_f.to_d rescue '-'%></td>
|
||||
<td><%= sprintf "%.2f",result[:credit_amount].to_f.to_d rescue '-'%></td>
|
||||
<td><%= sprintf "%.2f",result[:accept_credit_amount].to_f.to_d rescue '-'%></td>
|
||||
<td><%= sprintf "%.2f",result[:foc_amount].to_f.to_d rescue '-'%></td>
|
||||
<td><%= sprintf "%.2f",result[:card_amount].to_f.to_d rescue '-'%></td>
|
||||
<td><%= sprintf "%.2f",result[:grand_total].to_f.to_d rescue '-'%></td>
|
||||
<td><%= sprintf "%.2f",result[:rounding_adj].to_f.to_d rescue '-'%></td>
|
||||
<% grand_total = result[:grand_total].to_f - result[:rounding_adj].to_f %>
|
||||
<td><%= sprintf "%.2f",grand_total.to_f.to_d rescue '-'%></td>
|
||||
</tr>
|
||||
<% void += result[:void_amount].to_f %>
|
||||
<% cash += result[:cash_amount].to_f %>
|
||||
<% credit += result[:credit_amount].to_f %>
|
||||
<% accept_credit += result[:accept_credit_amount].to_f %>
|
||||
<% foc += result[:foc_amount].to_f %>
|
||||
<% card += result[:card_amount].to_f %>
|
||||
<% total += result[:grand_total].to_f %>
|
||||
<% rounding_adj += result[:rounding_adj].to_f %>
|
||||
<% g_total += grand_total.to_f %>
|
||||
|
||||
<% end %>
|
||||
|
||||
<tr style="border-top: 3px solid grey;">
|
||||
<td colspan="2"></td>
|
||||
<td style='color:red;'><b>(<%= sprintf("%.2f",void) rescue '-'%>)</b></td>
|
||||
<td><b><%= sprintf("%.2f",cash) rescue '-'%></b></td>
|
||||
<td><b><%= sprintf("%.2f",credit) rescue '-'%></b></td>
|
||||
<td><b><%= sprintf("%.2f",accept_credit) rescue '-'%></b></td>
|
||||
<td><b><%= sprintf("%.2f",foc) rescue '-'%></b></td>
|
||||
<td><b><%= sprintf("%.2f",card) rescue '-'%></b></td>
|
||||
<td><b><%= sprintf("%.2f",total) rescue '-'%></b></td>
|
||||
<td><b><%= sprintf("%.2f",rounding_adj) rescue '-'%></b></td>
|
||||
<td><b><%= sprintf("%.2f",g_total) rescue '-'%></b></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
$(function(){
|
||||
var check_arr = [];
|
||||
var search = '<%= params[:period_type] %>';
|
||||
if(search){
|
||||
if(parseInt(search) == 0){
|
||||
search_by_period();
|
||||
}
|
||||
else{
|
||||
search_by_date();
|
||||
}
|
||||
}else{
|
||||
search_by_period();
|
||||
}
|
||||
$('#sel_period').change(function(){
|
||||
search_by_period();
|
||||
});
|
||||
function search_by_period(){
|
||||
var period = $('#sel_period').val();
|
||||
var period_type = 0;
|
||||
var from = "";
|
||||
var to = "";
|
||||
}
|
||||
|
||||
$('#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){
|
||||
}
|
||||
if(check_arr.length == 3){
|
||||
check_arr = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@@ -1,26 +1,4 @@
|
||||
<div class="page-header">
|
||||
<ul class="breadcrumb">
|
||||
<li><a href="<%= dashboard_path %>">Home</a></li>
|
||||
<li>Daily Sale Report</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<%= render :partial=>'shift_sale_report_filter',
|
||||
:locals=>{ :period_type => true, :shift_name => false, :report_path =>reports_daily_sales_path} %>
|
||||
<hr />
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-12 text-right">
|
||||
<a href="javascript:export_to('<%=reports_daily_sales_path%>.xls')" class = "btn btn-default">Export to Excel</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container margin-top-20">
|
||||
<div class="card row">
|
||||
<div class="card row">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered">
|
||||
<thead>
|
||||
@@ -136,55 +114,3 @@
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
$(function(){
|
||||
var check_arr = [];
|
||||
var search = '<%= params[:period_type] %>';
|
||||
if(search){
|
||||
if(parseInt(search) == 0){
|
||||
search_by_period();
|
||||
}
|
||||
else{
|
||||
search_by_date();
|
||||
}
|
||||
}else{
|
||||
search_by_period();
|
||||
}
|
||||
$('#sel_period').change(function(){
|
||||
search_by_period();
|
||||
});
|
||||
function search_by_period(){
|
||||
var period = $('#sel_period').val();
|
||||
var period_type = 0;
|
||||
var from = "";
|
||||
var to = "";
|
||||
}
|
||||
|
||||
$('#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){
|
||||
}
|
||||
if(check_arr.length == 3){
|
||||
check_arr = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@@ -264,6 +264,7 @@ Rails.application.routes.draw do
|
||||
resources :receipt_no, :only => [:index, :show]
|
||||
resources :dailysale, :only => [:index, :show]
|
||||
resources :saleitem, :only => [:index, :show]
|
||||
resources :shiftsale, :only => [:index, :show]
|
||||
# resources :sales, :only => [:index, :show]
|
||||
# resources :orders, :only => [:index, :show]
|
||||
# resources :customers, :only => [:index, :show]
|
||||
|
||||
5
spec/controllers/reports/shiftsale_controller_spec.rb
Normal file
5
spec/controllers/reports/shiftsale_controller_spec.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Reports::ShiftsaleController, type: :controller do
|
||||
|
||||
end
|
||||
15
spec/helpers/reports/shiftsale_helper_spec.rb
Normal file
15
spec/helpers/reports/shiftsale_helper_spec.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
require 'rails_helper'
|
||||
|
||||
# Specs in this file have access to a helper object that includes
|
||||
# the Reports::ShiftsaleHelper. For example:
|
||||
#
|
||||
# describe Reports::ShiftsaleHelper do
|
||||
# describe "string concat" do
|
||||
# it "concats two strings with spaces" do
|
||||
# expect(helper.concat_strings("this","that")).to eq("this that")
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
RSpec.describe Reports::ShiftsaleHelper, type: :helper do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
Reference in New Issue
Block a user