shift
This commit is contained in:
@@ -19,10 +19,6 @@ class HomeController < ApplicationController
|
||||
|
||||
if @employee != nil
|
||||
session[:session_token] = @employee.token_session
|
||||
|
||||
#if cashier => already opening cahshier?
|
||||
|
||||
redirect_to origami_root_path
|
||||
route_by_role(@employee)
|
||||
else
|
||||
render :show, flash[:notice] => "Invalid PIN for Employee. Please try again!"
|
||||
@@ -41,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
|
||||
@@ -84,13 +80,13 @@ class HomeController < ApplicationController
|
||||
redirect_to dashboard_path
|
||||
elsif employee.role == "cashier"
|
||||
#check if cashier has existing open cashier
|
||||
|
||||
# if !ShiftSale.current_open_shift(employee).nil?
|
||||
# redirect_to origami_root_path
|
||||
# else
|
||||
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 == "checker"
|
||||
end
|
||||
elsif employee.role == "manager"
|
||||
redirect_to oqs_root_path
|
||||
elsif employee.role == "waiter"
|
||||
redirect_to oqs_root_path
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class Origami::ShiftsController < ApplicationController
|
||||
class Origami::ShiftsController < BaseOrigamiController
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
@@ -6,6 +7,13 @@ class Origami::ShiftsController < ApplicationController
|
||||
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
|
||||
|
||||
@@ -263,7 +263,6 @@ class Sale < ApplicationRecord
|
||||
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def product_get_unit_price(item_code)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -19,7 +19,33 @@ class ShiftSale < ApplicationRecord
|
||||
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
|
||||
@shift = ShiftSale.where("cast(shift_started_at as date) = #{DateTime.now.to_date} and shift_started_at is null and employee_id = #{current_user.id}").limit(1)
|
||||
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
|
||||
|
||||
1
app/views/origami/shifts/create.json.jbuilder
Normal file
1
app/views/origami/shifts/create.json.jbuilder
Normal file
@@ -0,0 +1 @@
|
||||
json.status true
|
||||
@@ -1,2 +1,46 @@
|
||||
<h1>Origami::Shifts#new</h1>
|
||||
<p>Find me in app/views/origami/shifts/new.html.erb</p>
|
||||
<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>
|
||||
|
||||
@@ -89,7 +89,7 @@ Rails.application.routes.draw do
|
||||
get 'room/:room_id' => 'rooms#show'
|
||||
get 'order/:order_id' => "orders#show"
|
||||
|
||||
post '/:booking_id' => 'home#item_show'
|
||||
# post '/:booking_id' => 'home#item_show'
|
||||
|
||||
get "/:id/discount" => "discounts#index"
|
||||
post "/:id/discount" => "discounts#create"
|
||||
|
||||
Reference in New Issue
Block a user