shift open/close

This commit is contained in:
Nweni
2017-06-29 13:35:09 +06:30
parent 45961880c8
commit 618a89472a
20 changed files with 320 additions and 18 deletions

View File

@@ -38,7 +38,7 @@ class Api::BillController < Api::ApiController
item_price_by_accounts = SaleItem.calculate_price_by_accounts(@sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, item_price_by_accounts)
# printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, item_price_by_accounts)
end

View File

@@ -80,7 +80,7 @@ class HomeController < ApplicationController
redirect_to dashboard_path
elsif employee.role == "cashier"
#check if cashier has existing open cashier
shift = ShiftSale.current_open_shift(employee)
shift = ShiftSale.current_open_shift(employee.id)
if !shift.nil?
redirect_to origami_root_path
else

View File

@@ -0,0 +1,15 @@
class Origami::CashInsController < BaseOrigamiController
def new
end
def create
reference = params[:reference]
remark = params[:remark]
amount = params[:amount]
payment_method = params[:payment_method]
payment_method_reference = params[:payment_method_reference]
p_jour = PaymentJournal.new
p_jour.cash_in(reference, remark, amount, payment_method, payment_method_reference, current_user.id)
end
end

View File

@@ -0,0 +1,13 @@
class Origami::CashOutsController < BaseOrigamiController
def new
end
def create
reference = params[:reference]
remark = params[:remark]
amount = params[:amount]
p_jour = PaymentJournal.new
p_jour.cash_out(reference, remark, amount, current_user.id)
end
end

View File

@@ -6,6 +6,7 @@ class Origami::HomeController < BaseOrigamiController
@rooms = Room.all.active.order('status desc')
@complete = Sale.all
@orders = Order.all.order('date desc')
# @shift = ShiftSale.current_open_shift(current_user.id)
end
# origami table detail

View File

@@ -38,7 +38,7 @@ class Origami::RequestBillsController < BaseOrigamiController
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, item_price_by_accounts,member_info,shop_details)
# printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, item_price_by_accounts,member_info,shop_details)
# redirect_to origami_path(@sale_data.sale_id)
end

View File

@@ -4,10 +4,11 @@ class Origami::ShiftsController < BaseOrigamiController
end
def show
@shift = ShiftSale.current_open_shift(current_user.id)
end
def new
@float = Lookup.where('lookup_type=?','float')
@float = Lookup.where('lookup_type=?','float_value')
end
def create
@@ -16,6 +17,14 @@ class Origami::ShiftsController < BaseOrigamiController
@shift.create(opening_balance,current_user)
end
def update_shift
@shift = ShiftSale.current_open_shift(current_user.id)
if @shift
@shift.shift_closed_at = DateTime.now.utc
@shift.save
end
end
def edit
end
end

View File

@@ -1,6 +1,7 @@
class Employee < ApplicationRecord
has_secure_password
has_many :shit_sales
validates_presence_of :name, :role
validates_presence_of :password, :on => [:create]
validates :emp_id, uniqueness: true, numericality: true, length: {in: 1..4}, allow_blank: true

View File

@@ -1,2 +1,22 @@
class PaymentJournal < ApplicationRecord
def cash_in(reference, remark, amount, payment_method, payment_method_reference, current_user)
self.payment_references = reference
self.remark = remark
self.credit_amount = amount
self.payment_method = payment_method
self.payment_status = 'paid'
self.payment_method_references = payment_method_reference
self.created_by = current_user
self.save
end
def cash_out(payment_reference, remark, amount, current_user)
self.payment_references = payment_reference
self.remark = remark
self.debit_amount = amount
self.payment_status = 'paid'
self.created_by = current_user
self.save
end
end

View File

@@ -247,12 +247,14 @@ 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)
shift = ShiftSale.current_open_shift(self.sale.cashier_id)
puts shift
if !shift.nil?
puts ">>>> shift >>>>>>"
shift.update(self.sale)
end
end
end

View File

@@ -14,13 +14,14 @@
class ShiftSale < ApplicationRecord
belongs_to :cashier_terminal
belongs_to :employee
belongs_to :employee, :foreign_key => 'employee_id'
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
puts today_date
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}",today_date).take
return shift
#end
@@ -35,6 +36,7 @@ class ShiftSale < ApplicationRecord
end
def update(sale)
puts ">>>>>> shift sale update"
saleobj = Sale.find(sale)
self.total_revenue = self.total_revenue + saleobj.total_amount
self.total_discounts = self.total_discounts + saleobj.total_discount

View File

@@ -0,0 +1,79 @@
<div class='row'>
<div class="col-lg-11 col-md-11 col-sm-11">
<h2> Payment Credit </h2>
<br>
<table class='table table-striped'>
<tr>
<td> Payment Reference
</td>
<td><input type='text' id='reference'/></td>
</tr>
<tr>
<td> Remark
</td>
<td><input type="text" id='remark'/></td>
</tr>
<tr>
<td> Payment Method
</td>
<td>
<button class='btn btn-primary payment-type' data-id='cash' id='cash'>CASH</button>
<button class='btn btn-primary payment-type' data-id='mpu' id='mpu'>MPU</button>
<button class='btn btn-primary payment-type' data-id='visa' id='visa'>VISA</button>
<button class='btn btn-primary payment-type' data-id='jcb' id='jcb'>JCB</button>
</td>
</tr>
</table>
<div class='row'>
<div class='col-md-2'></div>
<div class='col-md-2'>Reference Number </div>
<div class='col-md-4'><input type='text' id='payment_method_reference'/> </div>
</div>
<br>
<div class='row'>
<div class='col-md-2'></div>
<div class='col-md-2'>Amount</div>
<div class='col-md-4'><input type='text' id='amount'/></div>
</div>
<br><br>
<div class='row'>
<div class='col-md-3'></div>
<div class='col-md-4'><button class='btn btn-primary btn-lg' id='cash_in' style='width:200px;'> Cash In</button></div>
</div>
</div>
<div class="col-lg-1 col-md-1 col-sm-1">
<button class='btn btn-primary ' id='cash_in' style='width:100px;'> Back </button>
</div>
</div>
<script>
var payment_method = "";
$('.payment-type').on('click',function(){
$('.payment-type').css("background-color","#7a62d3")
$(this).css("background-color","green");
var type = $(this).attr('data-id')
if(type == 'cash'){
payment_method = 'cash';
}else if(type == 'mpu'){
payment_method = "mpu";
}else if(type == 'visa'){
payment_method = "visa";
}else if(type == 'jcb'){
payment_method = "jcb";
}
})
$('#cash_in').on('click',function(){
var reference = $('#reference').val();
var remark = $('#remark').val();
var amount = $('#amount').val();
var payment_method_reference = $('#payment_method_reference').val();
$.ajax({type: "POST",
url: "<%= origami_cash_ins_path %>",
data: "reference="+ reference + "&remark=" + remark + "&amount="+ amount + "&payment_method="+payment_method + "&payment_method_reference="+ payment_method_reference,
success:function(result){
window.location.href = '/origami';
}
});
})
</script>

View File

@@ -0,0 +1,44 @@
<h2>Payment Debit</h2>
<div class='row'>
<div class='col-md-9'>
<table class='table table-striped'>
<tr>
<td> Payment Reference
</td>
<td><input id='reference' type='text' value=''/></td>
</tr>
<tr>
<td> Remark
</td>
<td><input id='remark' type="text" value=''/></td>
</tr>
<tr>
<td> Amount
</td>
<td><input id='amount' type="text" value=''/></td>
</tr>
</table>
</div>
</div>
<br><br>
<div class='row'>
<div class='col-md-3'></div>
<div class='col-md-4'><button class='btn btn-primary btn-lg' id='cash_out'> Cash Out</button></div>
</div>
<script>
$('#cash_out').on('click',function(){
var reference = $('#reference').val();
var remark = $('#remark').val();
var amount = $('#amount').val();
$.ajax({type: "POST",
url: "<%= origami_cash_outs_path %>",
data: "reference="+ reference + "&remark=" + remark + "&amount="+ amount,
success:function(result){
window.location.href = '/origami';
}
});
})
</script>

View File

@@ -1,6 +1,6 @@
<div class="row">
<!-- Column One -->
<div class="col-lg-11 col-md-11 col-sm-11">
<div class="col-lg-10 col-md-10 col-sm-10">
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
@@ -103,8 +103,11 @@
</div>
<!-- tabs - End -->
</div>
<div class="col-lg-1 col-md-1 col-sm-1">
<div class="col-lg-2 col-md-2 col-sm-2">
<button id="refreshbutton" type="button" class="btn btn-block" style="border-radius:5px;color:#fff;background-color:red;"> Refresh off </button>
<button id="cash_in" type="button" class="btn btn-block btn-primary" style="border-radius:5px;color:#fff;"> Cash In </button>
<button id="cash_out" type="button" class="btn btn-block btn-primary" style="border-radius:5px;color:#fff;"> Cash Out </button>
<button id="close_cashier" type="button" class="btn btn-block btn-primary" style="border-radius:5px;color:#fff;"> Close Cashier </button>
</div>
</div>
<!-- Column One -->
@@ -193,4 +196,16 @@ $(function() {
}
}
});
$('#cash_in').on('click',function(){
window.location.href = '/origami/cash_ins/new';
})
$('#cash_out').on('click',function(){
window.location.href = '/origami/cash_outs/new';
})
$('#close_cashier').on('click',function(){
window.location.href = '/origami/shift/close';
})
</script>

View File

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

View File

@@ -1,2 +1,92 @@
<h1>Origami::Shifts#show</h1>
<p>Find me in app/views/origami/shifts/show.html.erb</p>
<div class='row'>
<div class='col-md-10'>
<h1>Close Cashier</h1>
<br>
<table class='table table-striped'>
<tr>
<td>Shift Started At</td>
<td><%= @shift.shift_started_at.utc.getlocal.strftime("%d/%m/%Y - %I:%M %p") rescue '-' %></td>
</tr>
<tr>
<td>Cashier Name</td>
<td><%= @shift.employee.name rescue ''%></td>
</tr>
<tr>
<td>Opening Balance</td>
<td><%= @shift.opening_balance rescue ''%></td>
</tr>
<tr>
<td>Total Revenue</td>
<td><%= @shift.total_revenue rescue ''%></td>
</tr>
<tr>
<td>Total Discount</td>
<td><%= @shift.total_discounts rescue ''%></td>
</tr>
<tr>
<td>Total Tax</td>
<td><%= @shift.total_taxes rescue ''%></td>
</tr>
<tr>
<td>Grand Total</td>
<td><%= @shift.grand_total rescue ''%></td>
</tr>
<tr>
<td>Nett Sale</td>
<td><%= @shift.nett_sales rescue ''%></td>
</tr>
<tr>
<td>Cash Sale</td>
<td><%= @shift.cash_sales rescue ''%></td>
</tr>
<tr>
<td>Credit Sale</td>
<td><%= @shift.credit_sales rescue ''%></td>
</tr>
<tr>
<td>Other Sale</td>
<td><%= @shift.other_sales rescue ''%></td>
</tr>
<tr>
<td>Commercial Tax</td>
<td><%= @shift.commercial_taxes rescue ''%></td>
</tr>
<tr>
<td>Cash In</td>
<td><%= @shift.cash_in rescue ''%></td>
</tr>
<tr>
<td>Cash Out</td>
<td><%= @shift.cash_out rescue ''%></td>
</tr>
</table>
<hr>
<div class='row'>
<div class='col-md-5'>
<span style='font-size:20px;'><b>Closing Balance</b></span>
</div>
<div class='col-md-6'>
<span style='font-size:20px;padding-left:18px;'><b><%= @shift.closing_balance rescue ''%></b></span>
</div>
</div>
</div>
<div class="col-lg-2 col-md-2 col-sm-2">
<button type="button" class="btn btn-primary btn-block" id='back'> Back </button>
<button type="button" class="btn btn-primary btn-block green" id='close_cashier'> Close Cashier </button>
</div>
</div>
<script>
$('#close_cashier').on('click',function(){
$.ajax({type: "POST",
url: "<%= origami_close_shift_path %>",
success:function(result){
console.log(result)
window.location.href = '/';
}
});
})
$('#back').on('click',function(){
window.location.href = '/origami';
})
</script>

View File

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

View File

@@ -70,6 +70,8 @@ Rails.application.routes.draw do
#--------- Cashier ------------#
namespace :origami do
resources :cash_ins, only:[:new, :create]
resources :cash_outs, only:[:new, :create]
root "home#index"
get "table/:dining_id" => "home#show" do #origami/:booking_id will show
# resources :discounts, only: [:index,:new, :create ] #add discount type
@@ -98,7 +100,9 @@ Rails.application.routes.draw do
get '/:sale_id/reprint' => 'payments#reprint' ,:defaults => { :format => 'json' }
#---------Shift ---------------#
resources :shifts, only: [:index, :show, :new, :create, :edit, :update]
resources :shifts, only: [:index, :new, :create, :edit]
post 'close_shift' => 'shifts#update_shift'
get 'shift/close' => 'shifts#show'
#shift - index (open/close shift landing page)
#shift - show (sales summary display)
#shift - new (open shift)

View File

@@ -8,7 +8,7 @@ class CreatePaymentJournals < ActiveRecord::Migration[5.1]
t.string :payment_method,:null => false, :default => "CASH"
t.string :payment_status,:null => false, :default => "NEW"
t.string :payment_method_references
t.integer :created_by, :null => false
t.timestamps
end
end

View File

@@ -82,6 +82,12 @@ void_reason = Lookup.create([{lookup_type:'void_reason', name: 'Approve By Manag
{lookup_type:'void_reason', name: 'Cashier Mistake', value: 'Cashier Mistake'},
{lookup_type:'void_reason', name: 'Waiter Mistake', value: 'Waiter Mistake'}])
# sale void reason
float_value = Lookup.create([{lookup_type:'float_value', name: '500', value: '500'},
{lookup_type:'float_value', name: '1000', value: '1000'},
{lookup_type:'float_value', name: '5000', value: '5000'},
{lookup_type:'float_value', name: '10000', value: '10000'}])
#WALK CUSTOMER - Default CUSTOMER (take key 1)
customer = Customer.create({name:"WALK-IN", email: "cus1@customer.com", contact_no:"000000000",card_no:"000"})
customer2 = Customer.create({name:"TAKEAWAY", email: "cus2@customer.com", contact_no:"111111111",card_no:"111"})
@@ -173,4 +179,5 @@ payment_methods = PaymentMethodSetting.create({payment_method:"JCB",gateway_url:
payment_methods = PaymentMethodSetting.create({payment_method:"Master",gateway_url: "http://192.168.1.47:3006"})
payment_methods = PaymentMethodSetting.create({payment_method:"Redeem",gateway_url: "http://192.168.1.47:3006",merchant_account_id:"vWSsseoZCzxd6xcNf_uS"})
cashier_terminal = CashierTerminal.create({name:"Terminal 1"})
puts " Finished System Default Set Up Data "