我正在尝试计算输出列,它是两个的差异 查询输出中的其他列;第一列是聚合的 库存中的物品,而第二列是物品的集合 被用过。第三列应该是差异的 两个值,这样我就可以输出表中的所有三列。
我想知道以铁路方式进行采购和销售后的剩余库存。
请在下面的屏幕截图中找到参考资料;
对于购买表,
stockings_controller.rb
class StockingsController < ApplicationController
before_action :set_stocking, only: [:show, :edit, :update, :destroy]
# GET /Stockings
# GET /deldetails.json
def index
@stockings = Stocking.all
end
def import
Stocking.import(params[:file])
redirect_to stockings_url, notice: "Stockings imported."
end
# GET /Stockings/1
# GET /Stockings/1.json
def show
end
# GET /Stockings/new
def new
@stocking = Stocking.new
end
# GET /stockings/1/edit
def edit
end
# POST /Stockings
# POST /Stockings.json
def create
@stocking = Stocking.new(stocking_params)
respond_to do |format|
if @stocking.save
format.html { redirect_to @stocking, notice: 'Stocking was successfully created.' }
format.json { render :show, status: :created, location: @stocking }
else
format.html { render :new }
format.json { render json: @stocking.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /Stockings/1
# PATCH/PUT /stockings/1.json
def update
respond_to do |format|
if @stocking.update(stocking_params)
format.html { redirect_to @stocking, notice: 'Stocking was successfully updated.' }
format.json { render :show, status: :ok, location: @stocking }
else
format.html { render :edit }
format.json { render json: @stocking.errors, status: :unprocessable_entity }
end
end
end
# DELETE /stockings/1
# DELETE /stockings/1.json
def destroy
@stocking.destroy
respond_to do |format|
format.html { redirect_to stockings_url, notice: 'Stocking was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_stocking
@stocking = Stocking.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def stocking_params
params.require(:stocking).permit(:slno, :category, :articleno, :description, :color, :quantity, :rprice, :total, :cartonno )
end
end
stocking.rb
类库存&lt;的ActiveRecord ::基
def self.import(file)
CSV.foreach(file.path, headers: true) do |row|
Stocking.create! row.to_hash
end
end
端
index.html.erb
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="table-responsive myTable">
<table class="table listing text-center">
<tr class="tr-head">
<td>SLNO</td>
<td>CATEGORY</td>
<td>ARTICLE NO</td>
<td>DESCRIPTION</td>
<td>COLOR</td>
<td>QUANTITY</td>
<td>RETAIL PRICE</td>
<td>TOTAL</td>
<td>CARTON NO</td>
</tr>
<% @stockings.each do |stocking| %>
<tr class="tr-<%= cycle('odd', 'even') %>">
<td class="col-1">
<%= stocking.slno %>
</td><td class="col-1">
<%= stocking.articleno %>
</td><td class="col-1">
<%= stocking.category %>
</td><td class="col-1">
<%= stocking.description %>
</td><td class="col-1">
<%= stocking.color %>
</td><td class="col-1">
<%= stocking.quantity %>
</td><td class="col-1">
<%= stocking.rprice %>
</td><td class="col-1">
<%= stocking.total %>
</td><td class="col-1">
<%= stocking.cartonno %>
</td>
</tr>
<% end %>
</table>
</div>
</div>
</div>
<br>
<%= link_to 'New stocking', new_stocking_path %>
<!-- |=== HERE -->
<a href="#" class="toggle-form">...</a>
<div id="test">
<h2>Import StOCKS</h2>
<%= form_tag import_stockings_path, multipart: true do %>
<%= file_field_tag :file %>
<%= submit_tag "Import" %>
<% end %>
</div>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$("div#test").hide();
// | === HERE
$("a.toggle-form").click(function(event) {
event.preventDefault();
$("div#test").toggle();
});
});
</script>
我已按上述方式准备购买的桌子,但无法解决处理剩余库存的想法。
我很困惑,我需要为销售等创建相同的东西 或者我选择其他方式。
欢迎任何建议。
提前谢谢。
答案 0 :(得分:0)
我通过以下方式找到剩余库存,剩余库存=购买数量 - 销售数量给客户,指定为cus1,cus2等等,因此我的索引视图如下;
index.html.erb
<td class="col-2"><%= stock = stock.quantity - stock.cus1 - stock.cus2 %></td>
通过这种方式,我获得了实际的剩余库存。