samedi 19 décembre 2015

Calculate Price x quantity Ruby on Rails

I need your support with ruby on rails. I'm trying to calculate the result of price and quantity in the light of new and edit.En view show if it works. I'm using Simple_form, calculate input quantity and price. automatically and must leave the result. sending the code.

<%= simple_form_for(@ticket) do |f| %>
  <%= f.error_notification %>
    <div class="form-inputs">
    <%= f.input :fecha %>
    <%= f.input :impuesto, :input_html => { value: '18.00'} %>
    <%= f.association :customer, label_method: "#{:nombre}", value_method: :id, prompt: "Debes buscar la empresa" %>
    <%= f.association :status %>
    <div>

    <table id="items">
          <tr>
            <th class="text-center" width="60px">ITEM</th>
            <th class="text-center" width="160px">CODIGO</th>
            <th class="text-center" width="225px">DESCRIPCION</th>
            <th class="text-center" width="100px">CANTIDAD</th>
            <th class="text-center" width="110px">PRECIO</th> 
            <th class="text-center" width="150px">TOTAL <%= @empresa.moneda1 %></th>
            <th></th>
          </tr>
    </table>    
<%= simple_nested_form_for @ticket, :wrapper => false do |g| %>
    <table id="detail_tickets">
    <%= g.simple_fields_for :detail_tickets do |p| %>
    <tr class="fields">
        <th align="center" width="60px" class="text-center"><%= p.input :item, label: false %></th>
        <th align="center" width="160px"><%= p.input :code, label: false %></th>
        <th align="center" width="225px" class="description"><%= p.input :description, label: false, :input_html => {:rows => 3} %></th>
        <th align="center" width="100px" class="text-center"><%= p.input :cantidad, label: false %></th>
        <th align="center" width="110px" class="text-right"><%= p.input :price, label: false %></th>
        <% @total_price = params[:cantidad].to_s.to_d * params[:price].to_s.to_d %> 
        <th align="right" width="150px" class="text-right"><%= @total_price %></th>
        <th align="center" width="63px" class="text-center"><%= p.link_to_remove "", class: "btn btn-danger fa fa-trash" %></th>
    </tr>
    <% end %>
    </table>

    <table id="items">
        <tr>
            <th width="700px"></th>
            <th class="text-center" width="110px">VALOR DE VENTA : </th> 
            <th class="text-center" width="150px"></th> 
        </tr>

        <tr>
            <th width="700px"></th>
            <th class="text-center" width="110px">I.G.V. : </th> 
            <th class="text-center" width="150px"></th> 
        </tr>

        <tr>
            <th width="700px"></th>
            <th class="text-center" width="110px">TOTAL : </th> 
            <th class="text-center" width="150px"></th> 
        </tr>
    </table>
    <br>
    <br>
    <p><%= g.link_to_add "Adicionar Producto", :detail_tickets, :data => { :target => "#detail_tickets" }, class: "btn btn-primary" %></p>
  <div class="form-actions">
    <%= f.button :submit %>
  </div>
<% end %>
<% end %>

Aucun commentaire:

Enregistrer un commentaire