inventory list and stock check
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
<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_by %></td>
|
||||
<td><%= item.created_at%></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
@@ -1,56 +1,83 @@
|
||||
<%= simple_form_for([:inventory, @inventory_definition]) do |f| %>
|
||||
<%= f.error_notification %>
|
||||
|
||||
<%= simple_form_for([:inventory,@inventory_definition]) do |f| %>
|
||||
<%= f.error_notification %>
|
||||
|
||||
<div class="form-inputs">
|
||||
<%= f.input :item_code %>
|
||||
|
||||
<div class="row">
|
||||
<% arr = MenuItem.active.order("name desc").pluck(:name,:item_code) %>
|
||||
<% Product.order("name desc").pluck(:name,:item_code).each do |p| %>
|
||||
<% arr.push(p) %>
|
||||
<% end %>
|
||||
<div class="col-md-3">
|
||||
<label class="control-label"><abbr title="required">*</abbr> Item</label>
|
||||
<select class="form-control item_code_place">
|
||||
<% if !@inventory_definition.item_code.nil? %>
|
||||
<% menuiteminstance = MenuItemInstance.find_by_item_instance_code(@inventory_definition.item_code) %>
|
||||
<% if menuiteminstance.nil?%>
|
||||
<% code = @inventory_definition.item_code %>
|
||||
<% else %>
|
||||
<% code = menuiteminstance.menu_item.item_code %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% arr.each do |a| %>
|
||||
<% if a[1] == code %>
|
||||
<option value="<%= a[1]%>" selected><%= a[0] %></option>
|
||||
<% else %>
|
||||
<option value="<%= a[1]%>"><%= a[0] %></option>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</select>
|
||||
<div class="form-inputs">
|
||||
<div class="row">
|
||||
<% arr = MenuItem.active.order("name desc").pluck(:name, :item_code) %>
|
||||
<% Product.order("name desc").pluck(:name, :item_code).each do |p| %>
|
||||
<% arr.push(p) %>
|
||||
<% end %>
|
||||
<div class="col-md-3">
|
||||
<label class="control-label"><abbr title="required">*</abbr> Item</label>
|
||||
<select class="form-control item_code_place" id="item">
|
||||
<% if !@inventory_definition.item_code.nil? %>
|
||||
<% menuiteminstance = MenuItemInstance.find_by_item_instance_code(@inventory_definition.item_code) %>
|
||||
<% if menuiteminstance.nil? %>
|
||||
<% code = @inventory_definition.item_code %>
|
||||
<% else %>
|
||||
<% code = menuiteminstance.menu_item.item_code %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<option value=""></option>
|
||||
<% arr.each do |a| %>
|
||||
<% if a[1] == code %>
|
||||
<option value="<%= a[1] %>" selected><%= a[0] %></option>
|
||||
<% else %>
|
||||
<option value="<%= a[1] %>"><%= a[0] %></option>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<% sample = [] %>
|
||||
<% if @inventory_definition.item_code.nil? %>
|
||||
<% if !MenuItemInstance.find_by_item_instance_code(@inventory_definition.item_code).nil? %>
|
||||
<% sample = MenuItemInstance.where("item_instance_code=?", @inventory_definition.item_code).pluck(:item_instance_name, :item_instance_code) %>
|
||||
<% else %>
|
||||
<% sample = Product.where("item_code=?", @inventory_definition.item_code).pluck(:name, :item_code) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<div class="col-md-3"><%= f.input :item_code, collection: sample %></div>
|
||||
</div>
|
||||
|
||||
<% sample = [] %>
|
||||
<% if @inventory_definition.item_code.nil? %>
|
||||
<% if !MenuItemInstance.find_by_item_instance_code(@inventory_definition.item_code).nil? %>
|
||||
<% sample = MenuItemInstance.where("item_instance_code=?",@inventory_definition.item_code).pluck(:item_instance_name,:item_instance_code)%>
|
||||
<% else %>
|
||||
<% sample = Product.where("item_code=?",@inventory_definition.item_code).pluck(:name,:item_code)%>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<div class="col-md-3"><%= f.input :item_code, collection: sample %></div>
|
||||
<!-- <div class="col-md-6"><%= f.input :item_code, collection: MenuItemInstance.order("item_instance_name desc").pluck(:item_instance_name,:item_instance_code),input_html: { selected: 2 } %></div> -->
|
||||
<div class="col-md-6"><%= f.input :min_qty %></div>
|
||||
<%= f.input :min_order_level %>
|
||||
<%= f.input :max_stock_level %>
|
||||
</div>
|
||||
|
||||
<%= f.input :min_order_level %>
|
||||
<%= f.input :max_stock_level %>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<%= f.button :submit %>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<%= f.button :submit %>
|
||||
</div>
|
||||
|
||||
<% end %>
|
||||
|
||||
<script>
|
||||
|
||||
$(document).ready(function () {
|
||||
$(".item_code_place").select2({
|
||||
placeholder: 'Select Item'
|
||||
});
|
||||
$("select#inventory_definition_item_code").select2();
|
||||
|
||||
$(".item_code_place").on('change', function (event) {
|
||||
var ajax_url = "<%= settings_find_item_instance_path %>";
|
||||
var item_code = this.value;
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: ajax_url,
|
||||
data: 'item_code=' + item_code,
|
||||
success: function (result) {
|
||||
$("#inventory_definition_item_code").empty();
|
||||
var itemlist;
|
||||
for (var i = 0; i < result.length; i++) {
|
||||
itemlist = "<option value ='" + result[i][1] + "'>" + result[i][0] + "</option>";
|
||||
$("select#inventory_definition_item_code").append(itemlist);
|
||||
}
|
||||
// $("select#inventory_definition_item_code").append(itemlist);
|
||||
$("select#inventory_definition_item_code").select2();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
@@ -7,17 +7,23 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<input type='text' id='stock_check_reason' class='form-control' placeholder="Set Stock Check Reason" value=''></input>
|
||||
</div>
|
||||
<input type='text' id='stock_check_reason' class='form-control' placeholder="Set Stock Check Reason" value=''/>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<div class="row">
|
||||
<div class="col-md-2"></div>
|
||||
<div class="col-md-2">
|
||||
Product
|
||||
Item
|
||||
</div>
|
||||
<div class="col-md-7">
|
||||
<input type='text' class='form-control' placeholder="Product Name" id='product_sku' value=''></input>
|
||||
<select class='form-control' id='product_sku'>
|
||||
<option value="">Select Product</option>
|
||||
<% @inventory_definitions.each do |id| %>
|
||||
<% item_name = MenuItemInstance.find_by_item_instance_code(id.item_code) %>
|
||||
<option value="<%= id.item_code %>"><%= item_name.item_instance_name %></option>
|
||||
<% end %>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
@@ -27,14 +33,14 @@
|
||||
Qty
|
||||
</div>
|
||||
<div class="col-md-7">
|
||||
<input type='text' class='form-control' placeholder="Qty" id='product_qty' value=''></input>
|
||||
<input type='text' class='form-control' placeholder="Qty" id='product_qty' value=''/>
|
||||
</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>
|
||||
<button class="btn btn-primary form-control" id='save_to_stock_check'> Save</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -47,6 +53,7 @@
|
||||
<th>#</th>
|
||||
<th>Product</th>
|
||||
<th>Balance</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
@@ -54,49 +61,58 @@
|
||||
</div>
|
||||
<div class="col-md-1">
|
||||
<div class="row">
|
||||
<button class="btn btn-primary pull-right form-control" style='margin-bottom:2px;' id='finish'> Finish </button>
|
||||
<button class="btn btn-primary pull-right form-control" style='margin-bottom:2px;' id='finish'> Finish</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var count = 0
|
||||
$(document).ready(function () {
|
||||
$('#product_sku').select2({
|
||||
allowClear: true,
|
||||
placeholder: 'Select Product'
|
||||
})
|
||||
});
|
||||
|
||||
$('#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('');
|
||||
var count = 0;
|
||||
|
||||
$('#save_to_stock_check').on('click', function () {
|
||||
count += 1;
|
||||
product_sku = $('#product_sku').val();
|
||||
product_qty = $('#product_qty').val();
|
||||
product_name = $("#product_sku option:selected").text();
|
||||
var tr = '<tr>'
|
||||
+ '<td>' + count + '</td>'
|
||||
+ '<td><input type=hidden value="' + product_sku + '" id="item_sku_' + count + '" name=' + count + '/>'
|
||||
+ '<input type=text value="' + product_name + '" id="item_name_' + count + '" name=' + count + ' disabled/></td>'
|
||||
+ '<td><input type=text value="' + product_qty + '" id="item_qty_' + count + '" name=' + count + '/></td>'
|
||||
+ '<td><input type=button value="Remove" id="item_qty_' + count + '" name=' + count + '/></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 = ''
|
||||
$('#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'];
|
||||
}
|
||||
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) {
|
||||
window.location.href = '/inventory/stock_checks/' + data['stock_id'];
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user