inventory
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
class StockCheckItemsController < ApplicationController
|
class Inventory::StockCheckItemsController < BaseInventoryController
|
||||||
before_action :set_stock_check_item, only: [:show, :edit, :update, :destroy]
|
before_action :set_stock_check_item, only: [:show, :edit, :update, :destroy]
|
||||||
|
|
||||||
# GET /stock_check_items
|
# GET /stock_check_items
|
||||||
@@ -28,7 +28,7 @@ class StockCheckItemsController < ApplicationController
|
|||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @stock_check_item.save
|
if @stock_check_item.save
|
||||||
format.html { redirect_to @stock_check_item, notice: 'Stock check item was successfully created.' }
|
format.html { redirect_to inventory_stock_checks_path, notice: 'Stock check item was successfully created.' }
|
||||||
format.json { render :show, status: :created, location: @stock_check_item }
|
format.json { render :show, status: :created, location: @stock_check_item }
|
||||||
else
|
else
|
||||||
format.html { render :new }
|
format.html { render :new }
|
||||||
@@ -69,6 +69,6 @@ class StockCheckItemsController < ApplicationController
|
|||||||
|
|
||||||
# Never trust parameters from the scary internet, only allow the white list through.
|
# Never trust parameters from the scary internet, only allow the white list through.
|
||||||
def stock_check_item_params
|
def stock_check_item_params
|
||||||
params.fetch(:stock_check_item, {})
|
params.require(:stock_check_item).permit(:item_code, :stock_count)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,74 +1,98 @@
|
|||||||
class Inventory::StockChecksController < BaseInventoryController
|
class Inventory::StockChecksController < BaseInventoryController
|
||||||
before_action :set_stock_check, only: [:show, :edit, :update, :destroy]
|
|
||||||
|
def index
|
||||||
|
@check = StockCheck.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
item_list = JSON.parse(params[:stock_item])
|
||||||
|
reason = params[:reason]
|
||||||
|
check = StockCheck.new
|
||||||
|
@check = check.create(current_user, reason, item_list)
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
@check = StockCheck.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def save_to_journal
|
||||||
|
check = params[:data]
|
||||||
|
stockCheck = StockCheck.find(check)
|
||||||
|
stockCheck.stock_check_items.each do |item|
|
||||||
|
StockJournal.from_stock_check(item)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# before_action :set_stock_check, only: [:show, :edit, :update, :destroy]
|
||||||
|
|
||||||
# GET /stock_checks
|
# GET /stock_checks
|
||||||
# GET /stock_checks.json
|
# GET /stock_checks.json
|
||||||
def index
|
# def index
|
||||||
@stock_checks = StockCheck.all
|
# @stock_checks = StockCheck.all
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
# GET /stock_checks/1
|
# # GET /stock_checks/1
|
||||||
# GET /stock_checks/1.json
|
# # GET /stock_checks/1.json
|
||||||
def show
|
# def show
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
# GET /stock_checks/new
|
# # GET /stock_checks/new
|
||||||
def new
|
# def new
|
||||||
@stock_check = StockCheck.new
|
# @stock_check = StockCheck.new
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
# GET /stock_checks/1/edit
|
# # GET /stock_checks/1/edit
|
||||||
def edit
|
# def edit
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
# POST /stock_checks
|
# # POST /stock_checks
|
||||||
# POST /stock_checks.json
|
# # POST /stock_checks.json
|
||||||
def create
|
# def create
|
||||||
@stock_check = StockCheck.new(stock_check_params)
|
# @stock_check = StockCheck.new(stock_check_params)
|
||||||
|
#
|
||||||
respond_to do |format|
|
# respond_to do |format|
|
||||||
if @stock_check.save
|
# if @stock_check.save
|
||||||
format.html { redirect_to @stock_check, notice: 'Stock check was successfully created.' }
|
# format.html { redirect_to @stock_check, notice: 'Stock check was successfully created.' }
|
||||||
format.json { render :show, status: :created, location: @stock_check }
|
# format.json { render :show, status: :created, location: @stock_check }
|
||||||
else
|
# else
|
||||||
format.html { render :new }
|
# format.html { render :new }
|
||||||
format.json { render json: @stock_check.errors, status: :unprocessable_entity }
|
# format.json { render json: @stock_check.errors, status: :unprocessable_entity }
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
# PATCH/PUT /stock_checks/1
|
# # PATCH/PUT /stock_checks/1
|
||||||
# PATCH/PUT /stock_checks/1.json
|
# # PATCH/PUT /stock_checks/1.json
|
||||||
def update
|
# def update
|
||||||
respond_to do |format|
|
# respond_to do |format|
|
||||||
if @stock_check.update(stock_check_params)
|
# if @stock_check.update(stock_check_params)
|
||||||
format.html { redirect_to @stock_check, notice: 'Stock check was successfully updated.' }
|
# format.html { redirect_to @stock_check, notice: 'Stock check was successfully updated.' }
|
||||||
format.json { render :show, status: :ok, location: @stock_check }
|
# format.json { render :show, status: :ok, location: @stock_check }
|
||||||
else
|
# else
|
||||||
format.html { render :edit }
|
# format.html { render :edit }
|
||||||
format.json { render json: @stock_check.errors, status: :unprocessable_entity }
|
# format.json { render json: @stock_check.errors, status: :unprocessable_entity }
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
# DELETE /stock_checks/1
|
# # DELETE /stock_checks/1
|
||||||
# DELETE /stock_checks/1.json
|
# # DELETE /stock_checks/1.json
|
||||||
def destroy
|
# def destroy
|
||||||
@stock_check.destroy
|
# @stock_check.destroy
|
||||||
respond_to do |format|
|
# respond_to do |format|
|
||||||
format.html { redirect_to stock_checks_url, notice: 'Stock check was successfully destroyed.' }
|
# format.html { redirect_to stock_checks_url, notice: 'Stock check was successfully destroyed.' }
|
||||||
format.json { head :no_content }
|
# format.json { head :no_content }
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
private
|
# private
|
||||||
# Use callbacks to share common setup or constraints between actions.
|
# # Use callbacks to share common setup or constraints between actions.
|
||||||
def set_stock_check
|
# def set_stock_check
|
||||||
@stock_check = StockCheck.find(params[:id])
|
# @stock_check = StockCheck.find(params[:id])
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
# Never trust parameters from the scary internet, only allow the white list through.
|
# # Never trust parameters from the scary internet, only allow the white list through.
|
||||||
def stock_check_params
|
# def stock_check_params
|
||||||
params.fetch(:stock_check, {})
|
# params.fetch(:stock_check, {})
|
||||||
end
|
# end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ class InventoryJob < ApplicationJob
|
|||||||
|
|
||||||
def perform(sale_id)
|
def perform(sale_id)
|
||||||
saleObj = Sale.find(sale_id)
|
saleObj = Sale.find(sale_id)
|
||||||
|
InventoryDefinition.calculate_product_count(saleObj)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ class InventoryDefinition < ApplicationRecord
|
|||||||
|
|
||||||
scope :active, -> {where(:is_active => true)}
|
scope :active, -> {where(:is_active => true)}
|
||||||
|
|
||||||
def calculate_product_count(saleObj)
|
def self.calculate_product_count(saleObj)
|
||||||
saleObj.sale_items.each do |item|
|
saleObj.sale_items.each do |item|
|
||||||
found, inventory_definition = find_product_in_inventory(item)
|
found, inventory_definition = find_product_in_inventory(item)
|
||||||
if found
|
if found
|
||||||
@@ -20,20 +20,22 @@ class InventoryDefinition < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.check_balance(item,inventory_definition)
|
def self.check_balance(item,inventory_definition) # item => saleItemOBj
|
||||||
stock = StockJournal.where('item_code=?', item.item_code).order('created_at desc').take
|
stock = StockJournal.where('item_code=?', item.product_code).order('created_at desc').take
|
||||||
unless stock.nil?
|
unless stock.nil?
|
||||||
modify_balance(item, stock.balance, inventory_definition)
|
modify_balance(item, stock, inventory_definition)
|
||||||
|
else
|
||||||
|
StockJournal.add_to_journal(item, 0, "out of stock", inventory_definition)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.modify_balance(item, stock_balance, inventory_definition)
|
def self.modify_balance(item, stock, inventory_definition) #saleitemObj
|
||||||
if stock.balance.to_i >= item.qty
|
if stock.balance.to_i >= item.qty
|
||||||
puts ">> stock is greater than orde qty"
|
puts ">> stock is greater than orde qty"
|
||||||
add_to_journal(item, balance, "ok", inventory_definition)
|
StockJournal.add_to_journal(item, stock.balance, "ok", inventory_definition)
|
||||||
else
|
else
|
||||||
puts " << stock is less than order qty"
|
puts " << stock is less than order qty"
|
||||||
add_to_journal(item, balance, "out of stock", inventory_definition)
|
StockJournal.add_to_journal(item, stock.balance, "out of stock", inventory_definition)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -118,7 +118,8 @@ class Sale < ApplicationRecord
|
|||||||
create_saleitem_diningcharges(charges, diningprice, booking.dining_facility.name, dining_time)
|
create_saleitem_diningcharges(charges, diningprice, booking.dining_facility.name, dining_time)
|
||||||
end
|
end
|
||||||
|
|
||||||
InventoryJob.perform_later(self.id)
|
InventoryJob.perform_now(self.id)
|
||||||
|
|
||||||
return true, self.id
|
return true, self.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,17 @@
|
|||||||
class StockCheck < ApplicationRecord
|
class StockCheck < ApplicationRecord
|
||||||
|
|
||||||
|
has_many :stock_check_items
|
||||||
|
|
||||||
|
def create(user, eason, item_list)
|
||||||
|
self.reason = reason
|
||||||
|
self.check_by = user.id
|
||||||
|
self.check_start = Time.now
|
||||||
|
self.check_end = Time.now
|
||||||
|
self.save
|
||||||
|
item_list.each do |item|
|
||||||
|
stockItem = StockCheckItem.new
|
||||||
|
stockItem.create(self.id,item)
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,2 +1,36 @@
|
|||||||
class StockCheckItem < ApplicationRecord
|
class StockCheckItem < ApplicationRecord
|
||||||
|
|
||||||
|
belongs_to :stock_check
|
||||||
|
|
||||||
|
def create(stock_id, item)
|
||||||
|
journal_id, balance = StockCheckItem.find_journal(item['sku'])
|
||||||
|
remark, different = StockCheckItem.stock_different(item['qty'], balance )
|
||||||
|
self.stock_check_id = stock_id
|
||||||
|
self.item_code = item['sku']
|
||||||
|
self.stock_count = item['qty']
|
||||||
|
self.stock_journal_id = journal_id
|
||||||
|
self.stock_balance = balance
|
||||||
|
self.different = different
|
||||||
|
self.remark = remark
|
||||||
|
self.save
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.find_journal(item_code)
|
||||||
|
journal = StockJournal.where('item_code=?', item_code).order('created_at desc').take
|
||||||
|
if journal
|
||||||
|
return journal.id, journal.balance
|
||||||
|
else
|
||||||
|
return nil, 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.stock_different(stock_check_qty, journal_balance)
|
||||||
|
if stock_check_qty.to_i == journal_balance.to_i
|
||||||
|
return 'match', stock_check_qty
|
||||||
|
elsif stock_check_qty.to_i > journal_balance.to_i
|
||||||
|
return 'missing order item', stock_check_qty.to_i - journal_balance.to_i
|
||||||
|
elsif stock_check_qty.to_i < journal_balance.to_i
|
||||||
|
return 'missing stock', stock_check_qty.to_i - journal_balance.to_i
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,22 +3,37 @@ class StockJournal < ApplicationRecord
|
|||||||
SALES_TRANS = "sale"
|
SALES_TRANS = "sale"
|
||||||
STOCK_CHECK_TRANS = "stock_check"
|
STOCK_CHECK_TRANS = "stock_check"
|
||||||
|
|
||||||
def add_to_journal(item, balance, stock_message, inventory_definition)
|
def self.add_to_journal(item, balance, stock_message, inventory_definition) # item => saleObj | balance => Stock journal
|
||||||
|
|
||||||
balance = calculate_balance(balance, item.qty)
|
balance = calculate_balance(balance, item.qty)
|
||||||
|
|
||||||
journal = StockJournal.new
|
journal = StockJournal.new
|
||||||
journal.item_code = item.item_code
|
journal.item_code = item.product_code
|
||||||
journal.inventory_definition_id = inventory_definition.id
|
journal.inventory_definition_id = inventory_definition.id
|
||||||
journal.debit = item.qty
|
journal.debit = item.qty
|
||||||
journal.balance = balance
|
journal.balance = balance
|
||||||
journal.remark = stock_message
|
journal.remark = stock_message
|
||||||
journal.trans_ref = item.id
|
journal.trans_ref = item.id
|
||||||
journal.trans_type = StockJournal::SALES_TRANS
|
journal.trans_type = StockJournal::SALES_TRANS
|
||||||
|
journal.save
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.calculate_balance(balance, qty)
|
def self.calculate_balance(balance, qty)
|
||||||
return balance.to_i - qty.to_i
|
return balance.to_i - qty.to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.from_stock_check(item)
|
||||||
|
definition_id = InventoryDefinition.find_by_item_code(item.item_code)
|
||||||
|
journal = StockJournal.new
|
||||||
|
journal.item_code = item.item_code
|
||||||
|
journal.inventory_definition_id = definition_id.id
|
||||||
|
journal.debit = 0
|
||||||
|
journal.credit = item.stock_count
|
||||||
|
journal.balance = item.stock_count
|
||||||
|
journal.remark = StockJournal::STOCK_CHECK_TRANS
|
||||||
|
journal.trans_ref = item.id
|
||||||
|
journal.trans_type = StockJournal::STOCK_CHECK_TRANS
|
||||||
|
journal.save
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<%if current_login_employee.role == "administrator" || current_login_employee.role == "manager" %>
|
<%if current_login_employee.role == "administrator" || current_login_employee.role == "manager" %>
|
||||||
<button id="back" type="button" class="btn btn-block btn-primary"> Back </button>
|
<button id="back" type="button" class="btn btn-block btn-primary"> Back </button>
|
||||||
<%end%>
|
<%end%>
|
||||||
<button id="stock_taking" type="button" class="btn btn-block btn-primary"> Stock Taking </button>
|
<button id="stock_taking" type="button" class="btn btn-block btn-primary"> New Stock Taking </button>
|
||||||
<button id="stock_check_report" type="button" class="btn btn-block btn-primary"> Stock Check Report</button>
|
<button id="stock_check_report" type="button" class="btn btn-block btn-primary"> Stock Check Report</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
<%= simple_form_for(@stock_check) do |f| %>
|
|
||||||
<%= f.error_notification %>
|
|
||||||
|
|
||||||
<div class="form-inputs">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-actions">
|
|
||||||
<%= f.button :submit %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
json.extract! stock_check, :id, :created_at, :updated_at
|
|
||||||
json.url stock_check_url(stock_check, format: :json)
|
|
||||||
1
app/views/inventory/stock_checks/create.json.jbuilder
Normal file
1
app/views/inventory/stock_checks/create.json.jbuilder
Normal file
@@ -0,0 +1 @@
|
|||||||
|
json.stock_id @check.id
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<h1>Editing Stock Check</h1>
|
|
||||||
|
|
||||||
<%= render 'form', stock_check: @stock_check %>
|
|
||||||
|
|
||||||
<%= link_to 'Show', @stock_check %> |
|
|
||||||
<%= link_to 'Back', stock_checks_path %>
|
|
||||||
@@ -2,52 +2,101 @@
|
|||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<button class="btn btn-primary pull-right" style='margin-bottom:2px;'> Finish </button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<table class="table table-striped">
|
<input type='text' id='stock_check_reason' class='form-control' placeholder="Set Stock Check Reason" value=''></input>
|
||||||
<tr>
|
</div>
|
||||||
<th>#</th>
|
</div>
|
||||||
<th>Product</th>
|
<br>
|
||||||
<th>Balance</th>
|
<div class="row">
|
||||||
</tr>
|
<div class="col-md-2"></div>
|
||||||
</table>
|
<div class="col-md-2">
|
||||||
|
Product
|
||||||
|
</div>
|
||||||
|
<div class="col-md-7">
|
||||||
|
<input type='text' class='form-control' placeholder="Product Name" id='product_sku' value=''></input>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<br>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-7">
|
<div class="col-md-2"></div>
|
||||||
<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>
|
|
||||||
|
|
||||||
<div class="col-md-2">
|
<div class="col-md-2">
|
||||||
<button class="btn btn-primary"> Save </button>
|
Qty
|
||||||
|
</div>
|
||||||
|
<div class="col-md-7">
|
||||||
|
<input type='text' class='form-control' placeholder="Qty" id='product_qty' value=''></input>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4"></div>
|
||||||
|
<div class="col-md-7">
|
||||||
|
<button class="btn btn-primary form-control" id='save_to_stock_check'> Save </button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-6">
|
<div class="col-md-5">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<table class="table table-striped">
|
<table class="table table-striped" id='stock_item'>
|
||||||
<tr>
|
<tr>
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
<th>Product</th>
|
<th>Product</th>
|
||||||
<th>Balance</th>
|
<th>Balance</th>
|
||||||
<th>Different</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-1">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<button class="btn btn-primary pull-right form-control" style='margin-bottom:2px;' id='finish'> Finish </button>
|
||||||
<button class="btn btn-primary"> Save to journal</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
var count = 0
|
||||||
|
|
||||||
|
$('#save_to_stock_check').on('click', function(){
|
||||||
|
count += 1;
|
||||||
|
product_sku = $('#product_sku').val();
|
||||||
|
product_qty = $('#product_qty').val();
|
||||||
|
var tr = '<tr>'
|
||||||
|
+ '<td>'+ count +'</td>'
|
||||||
|
+ '<td><input type=text value="'+ product_sku +'" id="item_sku_'+ count +'" name='+count+'></input></td>'
|
||||||
|
+ '<td><input type=text value="'+ product_qty +'" id="item_qty_'+ count +'" name='+count+'></input></td>'
|
||||||
|
+ '</tr>'
|
||||||
|
$('#stock_item').append(tr)
|
||||||
|
$('#product_sku').val('');
|
||||||
|
$('#product_qty').val('');
|
||||||
|
})
|
||||||
|
|
||||||
|
$('#finish').on('click',function(){
|
||||||
|
var reason = $('#stock_check_reason').val();
|
||||||
|
var arr = [];
|
||||||
|
var jsonStr = ''
|
||||||
|
|
||||||
|
for(var i = 1; i <= count; i++){
|
||||||
|
itemname = $('#item_sku_'+i ).val();
|
||||||
|
itemqty = $('#item_qty_'+i ).val();
|
||||||
|
arr.push({sku:itemname, qty:itemqty})
|
||||||
|
jsonStr = JSON.stringify(arr)
|
||||||
|
}
|
||||||
|
console.log(jsonStr)
|
||||||
|
$.ajax({
|
||||||
|
type: 'Post',
|
||||||
|
url: '<%= inventory_stock_check_save_path %>',
|
||||||
|
data:'stock_item='+ jsonStr + '&reason='+ reason,
|
||||||
|
success:function(data){
|
||||||
|
alert(data['stock_id'])
|
||||||
|
window.location.href = '/inventory/stock_checks/'+ data['stock_id'];
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
json.array! @stock_checks, partial: 'stock_checks/stock_check', as: :stock_check
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<h1>New Stock Check</h1>
|
|
||||||
|
|
||||||
<%= render 'form', stock_check: @stock_check %>
|
|
||||||
|
|
||||||
<%= link_to 'Back', stock_checks_path %>
|
|
||||||
@@ -1,4 +1,74 @@
|
|||||||
<p id="notice"><%= notice %></p>
|
<div class="row">
|
||||||
|
<input type='hidden' id='stock_check_id' value='<%= @check.id %>'/>
|
||||||
|
<div class="col-md-10">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-2">
|
||||||
|
Check by
|
||||||
|
</div>
|
||||||
|
<div class="col-md-8">
|
||||||
|
<%= @check.check_by %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-2">
|
||||||
|
Check At
|
||||||
|
</div>
|
||||||
|
<div class="col-md-8">
|
||||||
|
<%= @check.created_at %></div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-2">
|
||||||
|
Reason
|
||||||
|
</div>
|
||||||
|
<div class="col-md-8">
|
||||||
|
<%= @check.reason %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<div class="row">
|
||||||
|
<table class="table table-striped col-md-12">
|
||||||
|
<tr>
|
||||||
|
<th>#</th>
|
||||||
|
<th>Product</th>
|
||||||
|
<th>Stock Count</th>
|
||||||
|
<th>Stock Balance</th>
|
||||||
|
<th>Different</th>
|
||||||
|
<th>Remark</th>
|
||||||
|
</tr>
|
||||||
|
<%
|
||||||
|
count = 0
|
||||||
|
@check.stock_check_items.each do |item|
|
||||||
|
count += 1
|
||||||
|
%>
|
||||||
|
<tr>
|
||||||
|
<td><%= count %></td>
|
||||||
|
<td><%= item.item_code %></td>
|
||||||
|
<td><%= item.stock_count %></td>
|
||||||
|
<td><%= item.stock_balance %></td>
|
||||||
|
<td><%= item.different %></td>
|
||||||
|
<td><%= item.remark %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-2">
|
||||||
|
<button id="back" type="button" class="btn btn-block btn-primary"> Back </button>
|
||||||
|
<button id="save_to_journal" type="button" class="btn btn-block btn-primary"> Save to Journal </button>
|
||||||
|
<button id="print" type="button" class="btn btn-block btn-primary"> Print </button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<%= link_to 'Edit', edit_stock_check_path(@stock_check) %> |
|
<script>
|
||||||
<%= link_to 'Back', stock_checks_path %>
|
$('#save_to_journal').on('click', function(){
|
||||||
|
check_id = $('#stock_check_id').val();
|
||||||
|
$.ajax({
|
||||||
|
type: 'post',
|
||||||
|
url: '<%= inventory_save_to_journal_path %>',
|
||||||
|
data: 'data='+ check_id,
|
||||||
|
success: function(){
|
||||||
|
alert('success')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
json.partial! "stock_checks/stock_check", stock_check: @stock_check
|
|
||||||
@@ -328,8 +328,11 @@ Rails.application.routes.draw do
|
|||||||
|
|
||||||
namespace :inventory do
|
namespace :inventory do
|
||||||
get '/' => 'inventory#index'
|
get '/' => 'inventory#index'
|
||||||
resources :stock_check_items
|
get '/stock_checks' => 'stock_checks#index'
|
||||||
resources :stock_checks
|
post 'save_stock' => 'stock_checks#create', as:'stock_check_save'
|
||||||
|
get '/stock_checks/:id' => 'stock_checks#show'
|
||||||
|
post 'save_to_journal' => 'stock_checks#save_to_journal', as: 'save_to_journal'
|
||||||
|
# resources :stock_checks
|
||||||
resources :stock_journals
|
resources :stock_journals
|
||||||
resources :inventory_definitions
|
resources :inventory_definitions
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
class CreateStockCheckItems < ActiveRecord::Migration[5.1]
|
class CreateStockCheckItems < ActiveRecord::Migration[5.1]
|
||||||
def change
|
def change
|
||||||
create_table :stock_check_items do |t|
|
create_table :stock_check_items do |t|
|
||||||
t.integer :stock_check_id, :null => false
|
t.integer :stock_check_id
|
||||||
t.string :item_code, :null => false
|
t.string :item_code, :null => false
|
||||||
t.integer :stock_count, :default => 0
|
t.integer :stock_count, :default => 0
|
||||||
t.integer :stock_journal_id
|
t.integer :stock_journal_id
|
||||||
|
|||||||
Reference in New Issue
Block a user