inventory development
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
class Inventory::InventoryController < BaseInventoryController
|
||||
|
||||
def index
|
||||
|
||||
@products = InventoryDefinition.all.active.order('created_at desc')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,7 +28,7 @@ class Inventory::InventoryDefinitionsController < BaseInventoryController
|
||||
|
||||
respond_to do |format|
|
||||
if @inventory_definition.save
|
||||
format.html { redirect_to @inventory_definition, notice: 'Inventory definition was successfully created.' }
|
||||
format.html { redirect_to inventory_path, notice: 'Inventory definition was successfully created.' }
|
||||
format.json { render :show, status: :created, location: @inventory_definition }
|
||||
else
|
||||
format.html { render :new }
|
||||
@@ -69,6 +69,6 @@ class Inventory::InventoryDefinitionsController < BaseInventoryController
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def inventory_definition_params
|
||||
params.fetch(:inventory_definition, {})
|
||||
params.require(:inventory_definition).permit(:item_code, :min_order_level, :max_stock_level)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class StockChecksController < ApplicationController
|
||||
class Inventory::StockChecksController < BaseInventoryController
|
||||
before_action :set_stock_check, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
# GET /stock_checks
|
||||
|
||||
8
app/jobs/inventory_job.rb
Normal file
8
app/jobs/inventory_job.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class InventoryJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(sale_id)
|
||||
saleObj = Sale.find(sale_id)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,2 +1,39 @@
|
||||
class InventoryDefinition < ApplicationRecord
|
||||
|
||||
scope :active, -> {where(:is_active => true)}
|
||||
|
||||
def calculate_product_count(saleObj)
|
||||
saleObj.sale_items.each do |item|
|
||||
found, inventory_definition = find_product_in_inventory(item)
|
||||
if found
|
||||
check_balance(item,inventory_definition)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.find_product_in_inventory(item)
|
||||
product = InventoryDefinition.find_by_item_code(item.product_code)
|
||||
if product.nil?
|
||||
return false, nil
|
||||
else
|
||||
return true, product
|
||||
end
|
||||
end
|
||||
|
||||
def self.check_balance(item,inventory_definition)
|
||||
stock = StockJournal.where('item_code=?', item.item_code).order('created_at desc').take
|
||||
unless stock.nil?
|
||||
modify_balance(item, stock.balance, inventory_definition)
|
||||
end
|
||||
end
|
||||
|
||||
def self.modify_balance(item, stock_balance, inventory_definition)
|
||||
if stock.balance.to_i >= item.qty
|
||||
puts ">> stock is greater than orde qty"
|
||||
add_to_journal(item, balance, "ok", inventory_definition)
|
||||
else
|
||||
puts " << stock is less than order qty"
|
||||
add_to_journal(item, balance, "out of stock", inventory_definition)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -117,6 +117,7 @@ class Sale < ApplicationRecord
|
||||
create_saleitem_diningcharges(charges, diningprice, booking.dining_facility.name, dining_time)
|
||||
end
|
||||
|
||||
InventoryJob.perform_later(self.id)
|
||||
return true, self.id
|
||||
end
|
||||
|
||||
|
||||
@@ -1,2 +1,24 @@
|
||||
class StockJournal < ApplicationRecord
|
||||
|
||||
SALES_TRANS = "sale"
|
||||
STOCK_CHECK_TRANS = "stock_check"
|
||||
|
||||
def add_to_journal(item, balance, stock_message, inventory_definition)
|
||||
|
||||
balance = calculate_balance(balance, item.qty)
|
||||
|
||||
journal = StockJournal.new
|
||||
journal.item_code = item.item_code
|
||||
journal.inventory_definition_id = inventory_definition.id
|
||||
journal.debit = item.qty
|
||||
journal.balance = balance
|
||||
journal.remark = stock_message
|
||||
journal.trans_ref = item.id
|
||||
journal.trans_type = StockJournal::SALES_TRANS
|
||||
end
|
||||
|
||||
def self.calculate_balance(balance, qty)
|
||||
return balance.to_i - qty.to_i
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="card" id="backend" onclick="location.href='<%= inventory_inventory_path %>'">
|
||||
<div class="card" id="backend" onclick="location.href='<%= inventory_path %>'">
|
||||
<div class="card-content">
|
||||
<span class="card-title">Inventory</span>
|
||||
</div>
|
||||
|
||||
40
app/views/inventory/inventory/_inventory_list.html.erb
Normal file
40
app/views/inventory/inventory/_inventory_list.html.erb
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-8"><h2> Inventoy Product Lists</h2></div>
|
||||
<div class="col-md-4"><button id='new_inventory_product' class='btn btn-primary' style='margin-top:15px;'>New Inventory Product</button></div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Product</th>
|
||||
<th>Min Order</th>
|
||||
<th>Max Stock</th>
|
||||
<th>Created by</th>
|
||||
<th>Created Time</th>
|
||||
</tr>
|
||||
<%
|
||||
count = 0
|
||||
@products.each do |item|
|
||||
count += 1
|
||||
%>
|
||||
<tr>
|
||||
<td><%= count %></td>
|
||||
<td><%= item.item_code rescue ""%></td>
|
||||
<td><%= item.min_order_level %></td>
|
||||
<td><%= item.max_stock_level %></td>
|
||||
<td><%= item.created_by%></td>
|
||||
<td><%= item.created_at%></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$('#new_inventory_product').on('click',function(){
|
||||
window.location.href = '/inventory/inventory_definitions/new';
|
||||
})
|
||||
</script>
|
||||
@@ -1,17 +1,22 @@
|
||||
# Hello Inventory
|
||||
<div class="row">
|
||||
<div class="col-lg-8 col-md-8 col-sm-8">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-10 col-md-10 col-sm-10">
|
||||
<%= render 'inventory_list' %>
|
||||
</div>
|
||||
<div class="col-lg-4 col-md-4 col-sm-4">
|
||||
<button id="refreshbutton" type="button" class="btn btn-block"> Inventory Product Lists</button>
|
||||
<button id="cash_in" type="button" class="btn btn-block btn-primary"> Stock Taking </button>
|
||||
<button id="cash_out" type="button" class="btn btn-block btn-primary"> Stock Check Report</button>
|
||||
|
||||
<div class="col-lg-2 col-md-2 col-sm-2">
|
||||
<%if current_login_employee.role == "administrator" || current_login_employee.role == "manager" %>
|
||||
<button id="back" type="button" class="btn btn-block btn-primary"><i class="fa fa-home fa-lg"></i> Back
|
||||
</button>
|
||||
<button id="back" type="button" class="btn btn-block btn-primary"> Back </button>
|
||||
<%end%>
|
||||
|
||||
<button id="stock_taking" type="button" class="btn btn-block btn-primary"> Stock Taking </button>
|
||||
<button id="stock_check_report" type="button" class="btn btn-block btn-primary"> Stock Check Report</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$('#stock_taking').on('click',function(){
|
||||
window.location.href = '/inventory/stock_checks';
|
||||
})
|
||||
$('#stock_check_report').on('click', function(){
|
||||
window.location.href = '';
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
<%= simple_form_for(@inventory_definition) do |f| %>
|
||||
|
||||
<%= simple_form_for([:inventory,@inventory_definition]) do |f| %>
|
||||
<%= f.error_notification %>
|
||||
|
||||
<div class="form-inputs">
|
||||
<%= f.input :item_code %>
|
||||
<%= f.input :min_order_level %>
|
||||
<%= f.input :max_stock_level %>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<%= f.button :submit %>
|
||||
</div>
|
||||
|
||||
<% end %>
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
<h1>New Inventory Definition</h1>
|
||||
|
||||
<%= render 'form', inventory_definition: @inventory_definition %>
|
||||
|
||||
<%= link_to 'Back', inventory_definitions_path %>
|
||||
<div class="span12">
|
||||
<div class="page-header">
|
||||
<ul class="breadcrumb">
|
||||
<li><a href="<%= root_path %>">Home</a></li>
|
||||
<li><a href="<%= inventory_path %>">Product Inventory</a></li>
|
||||
<li>New</li>
|
||||
</ul>
|
||||
</div>
|
||||
<%= render 'form', inventory: @inventory_definition %>
|
||||
</div>
|
||||
|
||||
@@ -1,25 +1,53 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<button class="btn btn-primary pull-right" style='margin-bottom:2px;'> Finish </button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Product</th>
|
||||
<th>Balance</th>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="row">
|
||||
<div class="col-md-7">
|
||||
<input type='text' class='form-control' placeholder="Product Name"></input>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<input type='text' class='form-control' placeholder="Qty"></input>
|
||||
</div>
|
||||
|
||||
<h1>Stock Checks</h1>
|
||||
<div class="col-md-2">
|
||||
<button class="btn btn-primary"> Save </button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="3"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @stock_checks.each do |stock_check| %>
|
||||
<tr>
|
||||
<td><%= link_to 'Show', stock_check %></td>
|
||||
<td><%= link_to 'Edit', edit_stock_check_path(stock_check) %></td>
|
||||
<td><%= link_to 'Destroy', stock_check, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<br>
|
||||
|
||||
<%= link_to 'New Stock Check', new_stock_check_path %>
|
||||
<div class="col-md-6">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Product</th>
|
||||
<th>Balance</th>
|
||||
<th>Different</th>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<button class="btn btn-primary"> Save to journal</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<title>SmartSales : Restaurant</title>
|
||||
<%= csrf_meta_tags %>
|
||||
|
||||
<%= stylesheet_link_tag 'inventory', media: 'all', 'data-turbolinks-track': 'reload' %>
|
||||
<%= stylesheet_link_tag 'origami', media: 'all', 'data-turbolinks-track': 'reload' %>
|
||||
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
|
||||
<%= stylesheet_link_tag 'jquery-confirm', media: 'all', 'data-turbolinks-track': 'reload' %>
|
||||
<%= javascript_include_tag 'jquery-confirm', 'data-turbolinks-track': 'reload' %>
|
||||
|
||||
@@ -327,7 +327,7 @@ Rails.application.routes.draw do
|
||||
# ----------- Inventory ---------------------------
|
||||
|
||||
namespace :inventory do
|
||||
get 'inventory' => 'inventory#index'
|
||||
get '/' => 'inventory#index'
|
||||
resources :stock_check_items
|
||||
resources :stock_checks
|
||||
resources :stock_journals
|
||||
|
||||
@@ -4,6 +4,8 @@ class CreateInventoryDefinitions < ActiveRecord::Migration[5.1]
|
||||
t.string :item_code
|
||||
t.integer :min_order_level, :default => 0
|
||||
t.integer :max_stock_level, :default => 0
|
||||
t.integer :created_by
|
||||
t.boolean :is_active, :default => true
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user