shift sale

This commit is contained in:
Nweni
2017-07-01 09:46:14 +06:30
parent 18094f5a71
commit c589f11758
6 changed files with 29 additions and 17 deletions

View File

@@ -4,7 +4,6 @@ class Origami::ShiftsController < BaseOrigamiController
end end
def show def show
puts current_user.id
@shift = ShiftSale.current_open_shift(current_user.id) @shift = ShiftSale.current_open_shift(current_user.id)
end end
@@ -15,8 +14,9 @@ class Origami::ShiftsController < BaseOrigamiController
def create def create
opening_balance = params[:opening_balance] opening_balance = params[:opening_balance]
cashier_terminal = params[:cashier_terminal]
@shift = ShiftSale.new @shift = ShiftSale.new
@shift.create(opening_balance,current_user) @shift.create(opening_balance,cashier_terminal, current_user)
end end
def update_shift def update_shift
@@ -30,7 +30,7 @@ class Origami::ShiftsController < BaseOrigamiController
end end
end end
def edit def edit
end end
end end

View File

@@ -479,11 +479,12 @@ end
def get_commerical_tax def get_commerical_tax
tax = 0.0 tax = 0.0
self.sale_taxes.each do |tax| self.sale_taxes.each do |taxobj|
if tax.tax_name == "Commerical Tax" if taxobj.tax_name == "Commerical Tax"
tax += tax.tax_payable_amount tax += taxobj.tax_payable_amount
end end
end end
return tax
end end

View File

@@ -266,6 +266,8 @@ class SalePayment < ApplicationRecord
shift = ShiftSale.current_open_shift(self.sale.cashier_id) shift = ShiftSale.current_open_shift(self.sale.cashier_id)
if !shift.nil? if !shift.nil?
shift.update(self.sale) shift.update(self.sale)
self.sale.shift_sale_id = shift.id
self.sale.save
end end
end end

View File

@@ -27,8 +27,8 @@ class ShiftSale < ApplicationRecord
#end #end
end end
def create(opening_balance,current_user) def create(opening_balance,cashier_terminal, current_user)
self.cashier_terminal_id = CashierTerminal.first.id self.cashier_terminal_id = cashier_terminal
self.shift_started_at = DateTime.now self.shift_started_at = DateTime.now
self.employee_id = current_user.id self.employee_id = current_user.id
self.opening_balance = opening_balance self.opening_balance = opening_balance

View File

@@ -1,12 +1,19 @@
<h1>Open Cashier</h1> <h1>Open Cashier</h1>
<br> <br>
<div class="row">
<div class="col-md-12">
</div>
</div>
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
<table class='table table-striped'> <table class='table table-striped'>
<tr>
<th>Cashier Terminal</th>
<th>
<select class='form-control' id='cashier_terminal'>
<% @terminal.each do |ter| %>
<option value="<%= ter.id %>"><%= ter.name %></option>
<% end %>
</select>
</th>
</tr>
<% @float.each do |float| %> <% @float.each do |float| %>
<tr> <tr>
<th><%= float.name %></th> <th><%= float.name %></th>
@@ -69,10 +76,12 @@ $(document).on('focusout', '.float-value', function(event){
}) })
$('#open_cashier').on('click',function(){ $('#open_cashier').on('click',function(){
var cashier_terminal = $('#cashier_terminal').val();
alert(cashier_terminal)
var amount = $('#total').text(); var amount = $('#total').text();
$.ajax({type: "POST", $.ajax({type: "POST",
url: "<%= origami_shifts_path %>", url: "<%= origami_shifts_path %>",
data: "opening_balance=" + amount, data: "opening_balance=" + amount + "&cashier_terminal="+ cashier_terminal,
success:function(result){ success:function(result){
if(result){ if(result){
window.location.href = '/origami'; window.location.href = '/origami';

View File

@@ -20,7 +20,7 @@ class CreateSales < ActiveRecord::Migration[5.1]
t.decimal :rounding_adjustment, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.decimal :rounding_adjustment, :precision => 10, :scale => 2, :null => false, :default => 0.00
t.decimal :amount_received, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.decimal :amount_received, :precision => 10, :scale => 2, :null => false, :default => 0.00
t.decimal :amount_changed, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.decimal :amount_changed, :precision => 10, :scale => 2, :null => false, :default => 0.00
t.integer :shift_sale_id, :null => false t.integer :shift_sale_id
t.timestamps t.timestamps
end end
end end