updated for api bill controller

This commit is contained in:
Yan
2017-06-28 16:56:43 +06:30
54 changed files with 1066 additions and 163 deletions

View 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/

View 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/

View File

@@ -0,0 +1,3 @@
// Place all the styles related to the cash_mgmt controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@@ -0,0 +1,3 @@
// Place all the styles related to the origami/shifts controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@@ -19,7 +19,7 @@ class Api::BillController < Api::ApiController
@sale_id = booking.sale_id
end
end
elsif (params[:order_id])
@sale = Sale.new
@status, @sale_id = @sale.generate_invoice_from_order(params[:order_id], current_login_employee, get_cashier)
@@ -29,6 +29,7 @@ class Api::BillController < Api::ApiController
@sale_items = SaleItem.where("sale_id=?",@sale_id)
unique_code = "ReceiptBillPdf"
#shop detail
shop_details = Shop.find(1)

View File

@@ -2,7 +2,7 @@ class HomeController < ApplicationController
skip_before_action :authenticate, only: [:index, :show, :create, :update, :destroy]
def index
@employees = Employee.all.order("name asc")
@employees = Employee.all_emp_except_waiter.order("name asc")
@login_form = LoginForm.new()
end
@@ -19,7 +19,7 @@ class HomeController < ApplicationController
if @employee != nil
session[:session_token] = @employee.token_session
redirect_to origami_root_path
route_by_role(@employee)
else
render :show, flash[:notice] => "Invalid PIN for Employee. Please try again!"
end
@@ -37,7 +37,7 @@ class HomeController < ApplicationController
redirect_to dashboard_path
elsif @employee.role == "cashier"
session[:session_token] = @employee.token_session
redirect_to origami_root_path
route_by_role(@employee)
elsif @employee.role == "manager"
session[:session_token] = @employee.token_session
redirect_to dashboard_path
@@ -74,4 +74,25 @@ class HomeController < ApplicationController
def settings_home_params
params.require(:login_form).permit(:emp_id, :password)
end
def route_by_role(employee)
if employee.role == "administrator"
redirect_to dashboard_path
elsif employee.role == "cashier"
#check if cashier has existing open cashier
shift = ShiftSale.current_open_shift(employee)
if !shift.nil?
redirect_to origami_root_path
else
redirect_to new_origami_shift_path
end
elsif employee.role == "manager"
redirect_to oqs_root_path
elsif employee.role == "waiter"
redirect_to oqs_root_path
elsif employee.role == "crm"
redirect_to crm_root_path
end
end
end

View File

@@ -0,0 +1,10 @@
class Origami::CashMgmtController < ApplicationController
def index
end
def new
end
def create
end
end

View File

@@ -19,9 +19,9 @@ class Origami::HomeController < BaseOrigamiController
@orders = Order.get_orders()
end
def item_show
selection(params[:booking_id],1)
end
# def item_show
# selection(params[:booking_id],1)
# end
def selection(selected_id, is_ajax)
str = []
@@ -37,8 +37,8 @@ class Origami::HomeController < BaseOrigamiController
@order_details = OrderItem.get_order_items_details(params[:booking_id])
@order_details.each do |ord_detail|
str.push(ord_detail)
end
end
end
end
if is_ajax == 1
render :json => str.to_json

View File

@@ -0,0 +1,21 @@
class Origami::ShiftsController < BaseOrigamiController
def index
end
def show
end
def new
@float = Lookup.where('lookup_type=?','float')
end
def create
opening_balance = params[:opening_balance]
@shift = ShiftSale.new
@shift.create(opening_balance,current_user)
end
def edit
end
end

View File

@@ -25,7 +25,7 @@ class Origami::TableInvoicesController < BaseOrigamiController
else
sale = Sale.find(booking.sale_id)
if sale.sale_status != "completed"
if sale.sale_status != "completed" && sale.sale_status != 'void'
@sale_array.push(sale)
end
end

View File

@@ -9,6 +9,14 @@ class Origami::VoidController < BaseOrigamiController
sale.sale_status = 'void'
sale.save
bookings = sale.bookings
bookings.each do |booking|
orders = booking.orders
orders.each do |order|
# order.status = 'void'
end
end
table_avaliable = true
table = sale.bookings[0].dining_facility
table.bookings.each do |booking|

View File

@@ -0,0 +1,16 @@
class LoginForm
include ActiveModel::Model
include ActiveModel::Validations
attr_accessor :float_amount
validates_presence_of :float_amount
def persisted?
false
end
def initialize(attributes={})
super
end
end

View File

@@ -0,0 +1,2 @@
module CashMgmtHelper
end

View File

@@ -0,0 +1,2 @@
module Origami::ShiftsHelper
end

View File

@@ -6,6 +6,10 @@ class Employee < ApplicationRecord
validates :emp_id, uniqueness: true, numericality: true, length: {in: 1..4}, allow_blank: true
validates :password, numericality: true, length: {in: 3..9}, allow_blank: true
def self.all_emp_except_waiter
Employee.where('role!=?','waiter')
end
def self.collection
Employee.select("id, name").map { |e| [e.name, e.id] }
end

View File

@@ -0,0 +1,2 @@
class PaymentJournal < ApplicationRecord
end

View File

@@ -270,7 +270,6 @@ class Sale < ApplicationRecord
end
private
def product_get_unit_price(item_code)

View File

@@ -247,6 +247,10 @@ class SalePayment < ApplicationRecord
end
self.sale.sale_status = "completed"
self.sale.save!
shift = ShiftSale.current_open_shift(self.sale.cashier_id)
if shift
shift.update(self.sale)
end
table_update_status(sObj)
rebat(sObj)
end

51
app/models/shift_sale.rb Normal file
View File

@@ -0,0 +1,51 @@
#Description
#total_revenue = sum of all sub-total from sales table
#total_discounts = sum of all discount (overall) from sales tables
#total_taxes = sum of all taxes from sales table (Service + Goverment Tax (commercial_taxes))
#grand_total = total_revenue - total_discounts + total_taxes
#nett_sales = grand_total - commercial_taxes
#cash_sales = cash payment total revenue
#credit_sales = credit payment total revenue
#others_sales = [Sum of each of other payment type --- mpu, jcb, visa,master, rebate, vochure]
#commercial_taxes = Total Goverment tax due
#cash_in = Payment receive
#Cash_out = Payment issues for misc payments
class ShiftSale < ApplicationRecord
belongs_to :cashier_terminal
belongs_to :employee
def self.current_open_shift(current_user)
#if current_user
#find open shift where is open today and is not closed and login by current cashier
today_date = DateTime.now.strftime("%Y-%m-%d")
shift = ShiftSale.where("TO_CHAR(shift_started_at, 'YYYY-MM-DD')=? and shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user.id}",today_date).take
return shift
#end
end
def create(opening_balance,current_user)
self.cashier_terminal_id = CashierTerminal.first.id
self.shift_started_at = DateTime.now
self.employee_id = current_user.id
self.opening_balance = opening_balance
self.save
end
def update(sale)
saleobj = Sale.find(sale)
self.total_revenue = self.total_revenue + saleobj.total_amount
self.total_discounts = self.total_discounts + saleobj.total_discount
self.total_taxes = self.total_taxes + saleobj.total_tax
self.grand_total = self.grand_total + saleobj.grand_total
# self.nett_sales =
# self.cash_sales =
# self.credit_sales =
# self.other_sales =
# self.commercial_taxes =
self.save
end
end

View File

@@ -1,14 +1,24 @@
<style>
.pin_pad {
width:10rem;
height:10rem;
text-align: center;
vertical-align: middle;
line-height: 10rem;
margin:2px;
margin-top:4px;
margin-bottom:4px;
font-size:3rem;
width: 30%;
height:70px;
line-height:70px;
text-align:center;
background:#54A5AF;
font-size:20px;
color:white;
}
.bottom{
margin-bottom: 1px;
}
.left{
margin-left:1px;
}
.orange{
background-color:#FF7F50;
}
.purple {
background-color:#7a62d3;
}
</style>
@@ -23,21 +33,29 @@
<%= f.input :password, label: "Access PIN", required: false, class: "form-control" %>
</div>
</div>
<div class="content" style="margin:10px; margin-top:0px; text-align:center">
<button class="pin_pad" data-value="1">1</button>
<button class="pin_pad" data-value="2">2</button>
<button class="pin_pad" data-value="3">3</button>
<button class="pin_pad" data-value="4">4</button>
<button class="pin_pad" data-value="5">5</button>
<button class="pin_pad" data-value="6">6</button>
<button class="pin_pad" data-value="7">7</button>
<button class="pin_pad" data-value="8">8</button>
<button class="pin_pad" data-value="9">9</button>
<button class="pin_pad" data-value="CLR">CLR</button>
<button class="pin_pad" data-value="8">0</button>
<button class="pin_pad btn-warning" data-value="ENT">ENT</button>
<div class="content row" style="padding-left:10px;margin-left:10px; margin-top:0px; text-align:center">
<div class='col-md-12'>
<div class='row bottom'>
<div class="pin_pad " data-value="1">1</div>
<div class="pin_pad left" data-value="2">2</div>
<div class="pin_pad left" data-value="3">3</div>
</div>
<div class='row bottom'>
<div class="pin_pad" data-value="4">4</div>
<div class="pin_pad left" data-value="5">5</div>
<div class="pin_pad left" data-value="6">6</div>
</div>
<div class='row bottom'>
<div class="pin_pad" data-value="7">7</div>
<div class="pin_pad left" data-value="8">8</div>
<div class="pin_pad left" data-value="9">9</div>
</div>
<div class='row bottom'>
<div class="pin_pad orange" data-value="CLR">CLR</div>
<div class="pin_pad left" data-value="8">0</div>
<div class="pin_pad left purple" data-value="ENT">ENT</div>
</div>
</div>
<div class="footer text-center" style="margin:10px">
</div>

View File

@@ -0,0 +1,2 @@
<h1>CashMgmt#create</h1>
<p>Find me in app/views/cash_mgmt/create.html.erb</p>

View File

@@ -0,0 +1,2 @@
<h1>CashMgmt#index</h1>
<p>Find me in app/views/cash_mgmt/index.html.erb</p>

View File

@@ -0,0 +1,2 @@
<h1>CashMgmt#new</h1>
<p>Find me in app/views/cash_mgmt/new.html.erb</p>

View File

@@ -27,6 +27,7 @@
<div class="card sales red text-white" data-id = "<%= sale.sale_id %>">
<div class="card-block">
<%= sale.receipt_no %>
<span style="font-size:12px;float:right;line-height:inherit;"><%= sale.sale_status %></span>
</div>
</div>
<% end %>

View File

@@ -27,6 +27,7 @@
<div class="card sales red text-white" data-id = "<%= sale.sale_id %>">
<div class="card-block">
<%= sale.receipt_no %>
<span style="font-size:12px;float:right;line-height:inherit;"><%= sale.sale_status %></span>
</div>
</div>
<% end %>
@@ -289,7 +290,7 @@
<button type="button" class="btn btn-primary btn-block" id='move'>Move</button>
<button type="button" id="request_bills" class="btn btn-primary btn-block">Req.Bill</button>
<button type="button" id="pay" class="btn btn-primary btn-block" disabled>Pay</button>
<button type="button" class="btn btn-primary btn-block" disabled=""> Void </button>
<button type="button" class="btn btn-primary btn-block" disabled> Void </button>
<% else %>
<button type="button" class="btn btn-primary btn-block" disabled>Add Order</button>
<button type="button" class="btn btn-primary btn-block" id='edit'>Edit</button>
@@ -490,9 +491,9 @@ $('#edit').on('click',function(){
})
} else {
}
}
})
})
</script>

View File

@@ -26,7 +26,7 @@
<% @complete.each do |sale| %>
<div class="card sales red text-white" data-id = "<%= sale.sale_id %>">
<div class="card-block">
<%= sale.receipt_no %>
<%= sale.receipt_no %><span style="font-size:12px;float:right;line-height:inherit;"><%= sale.sale_status %></span>
</div>
</div>
<% end %>

View File

@@ -11,7 +11,7 @@
</tr>
<tr>
<td><strong>Table No</strong> <% if @sale_data%>- <%=@sale_data.receipt_no%><% end %></td>
<td><strong>Sale Id</strong> </span><span id="sale_id"><% if @sale_data %><%=@sale_data.sale_id %><% end %></td>
<td><strong>Sale Id</strong> <span id="sale_id"><% if @sale_data %><%=@sale_data.sale_id %><% end %></span></td>
</tr>
<tr>
<td><strong>Customer :</strong> <%= @sale_data.customer.name%></td>
@@ -244,7 +244,7 @@
<button type="button" class="btn btn-primary btn-block" onclick="localStorage.removeItem('cash');window.location.href = '/origami';"> Back </button>
<button type="button" class="btn btn-primary btn-block"> FOC </button>
<button type="button" class="btn btn-primary btn-block"> Void </button>
<button type="button" class="btn btn-primary btn-block" id="void"> Void </button>
</div>
</div>
@@ -354,6 +354,23 @@ $( document ).ready(function() {
}
});
$('#void').on('click',function () {
var sure = confirm("Are you sure want to Void");
if (sure == true) {
var sale_id = $('#sale_id').text();
var ajax_url = "/origami/sale/" + sale_id + '/void';
$.ajax({
type: 'POST',
url: ajax_url,
success: function () {
window.location.href = '/origami/';
}
})
} else {
}
});
});
function update_balance(){
@@ -369,4 +386,5 @@ function update_balance(){
var result = amount_due - total;
$('#balance').text(result.toFixed(2));
}
</script>

View File

@@ -26,7 +26,7 @@
<% @complete.each do |sale| %>
<div class="card sales red text-white" data-id = "<%= sale.sale_id %>">
<div class="card-block">
<%= sale.receipt_no %>
<%= sale.receipt_no %><span style="font-size:12px;float:right;line-height:inherit;"><%= sale.sale_status %></span>
</div>
</div>
<% end %>

View File

@@ -26,7 +26,7 @@
<% @complete.each do |sale| %>
<div class="card sales red text-white" data-id = "<%= sale.sale_id %>">
<div class="card-block">
<%= sale.receipt_no %>
<%= sale.receipt_no %><span style="font-size:12px;float:right;line-height:inherit;"><%= sale.sale_status %></span>
</div>
</div>
<% end %>
@@ -185,7 +185,9 @@
<!-- Column Three -->
<div class="col-lg-1 col-md-1 col-sm-1">
<button type="button" class="btn btn-primary btn-block" id='back'>Back</button>
<button type="button" id="void" class="btn btn-primary btn-block">VOID</button>
<% if @sale.sale_status != 'void' %>
<button type="button" id="void" class="btn btn-primary btn-block">VOID</button>
<% end %>
<button type="button" id="re-print" class="btn btn-primary btn-block">Re.Print</button>
</div>
</div>

View File

@@ -0,0 +1 @@
json.status true

View File

@@ -0,0 +1,2 @@
<h1>Origami::Shifts#edit</h1>
<p>Find me in app/views/origami/shifts/edit.html.erb</p>

View File

@@ -0,0 +1,2 @@
<h1>Origami::Shifts#index</h1>
<p>Find me in app/views/origami/shifts/index.html.erb</p>

View File

@@ -0,0 +1,46 @@
<h1>Open Cashier</h1>
<br>
<div class="row">
<div class="col-md-4">
<table class='table table-striped'>
<% @float.each do |float| %>
<tr>
<th><%= float.name %></th>
<th><input class='float-value' type='text' data-value ="<%= float.value %>" value='' /></th>
</tr>
<% end %>
<tr>
<th>Total</th>
<th><div id='total'></div></th>
</tr>
</table>
<div class="row">
<div class='col-md-4'></div>
<div class='col-md-2'>
<button class='btn btn-primary' id='open_cashier'>Open Cashier</button>
</div>
</div>
</div>
</div>
<script>
var total = 0
$(document).on('focusout', '.float-value', function(event){
var input_type = $(this).attr("data-value");
var count = $(this).val();
total += input_type * count
$('#total').text(total)
})
$('#open_cashier').on('click',function(){
var amount = $('#total').text();
$.ajax({type: "POST",
url: "<%= origami_shifts_path %>",
data: "opening_balance=" + amount,
success:function(result){
if(result){
window.location.href = '/origami';
}
}
});
})
</script>

View File

@@ -0,0 +1,2 @@
<h1>Origami::Shifts#show</h1>
<p>Find me in app/views/origami/shifts/show.html.erb</p>

View File

@@ -128,6 +128,7 @@
<div class="col-lg-1 col-md-1 col-sm-1">
<button type="button" class="btn btn-primary btn-block" id='back'>Back</button>
<button type="button" id="pay" class="btn btn-primary btn-block">Pay</button>
<button type="button" id="void" class="btn btn-primary btn-block"> Void </button>
</div>
</div>
<script>
@@ -143,5 +144,21 @@ $('#pay').on('click',function() {
});
$('#back').on('click',function(){
window.location.href = '/origami/table/<%= @table.id %>';
})
});
$('#void').on('click',function () {
var sure = confirm("Are you sure want to Void");
if (sure == true) {
var sale_id = $('#sale_id').val();
var ajax_url = "/origami/sale/" + sale_id + '/void';
$.ajax({
type: 'POST',
url: ajax_url,
success: function () {
window.location.href = '/origami/';
}
})
} else {
}
});
</script>