Last active
September 21, 2016 22:44
-
-
Save rvgarimrj/55dd8949f976fb51b5208374266f6313 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% if @tipo == "devolucao" %> | |
<div class="nested-fields"> | |
<div class="row listCod" data-cod="<%= f.object.barcode %>"> | |
<%= f.input :id, :as => :hidden, input_html: { class: 'id_detail_ror' } %> | |
<div class="small-6 columns show-for-small-only"> | |
<%= f.input :barcode, label: "Cod Barras", input_html: { class: 'barcode_ror_dev' } %> | |
</div> | |
<%= f.input :order_id, :as => :hidden, input_html: { class: 'order_id_ror_dev' } %> | |
<%= f.input :preco, :as => :hidden,input_html: { class: 'preco_ror_dev' } %> | |
<div class="show-for-medium-up small-2 columns"> | |
<%= f.input :cod_produto, label: "Produto", input_html: { class: 'cod_produto_ror_dev' } %> | |
</div> | |
<%= f.input :desc_produto,:as => :hidden, input_html: { class: 'desc_produto_ror_dev' } %> | |
<%= f.input :cod_cor,:as => :hidden, input_html: { class: 'cod_cor_ror_dev' } %> | |
<div class="small-2 show-for-medium-up columns"> | |
<%= f.input :desc_cor,label: "Cor", input_html: { class: 'desc_cor_ror_dev' } %> | |
</div> | |
<div class="small-2 show-for-medium-up columns"> | |
<%= f.input :desc_tamanho,label: "Tam", input_html: { class: 'desc_tamanho_ror_dev' } %> | |
</div> | |
<div class="small-2 columns"> | |
<%= f.input :quantidade,label: "Qtd Vend.",input_html: { class: 'qtd_ror_vend' } %> | |
</div> | |
<div class="small-3 medium-2 columns"> | |
<%= f.input :quantidade_dev,label: "Qtd Dev", input_html: { class: 'quantidade_ror_dev', id: f.object.barcode } %> | |
</div> | |
<div class="show-for-medium-up medium-2 columns end"> | |
<%= f.input :total_dev,label: "Total Dev",input_html: { class: 'total_ror_dev' } %> | |
</div> | |
<div class="small-1 columns end"> | |
<%= link_to_remove_association "-", f, :class => "button tiny alert remove"%> | |
</div> | |
</div> | |
</div> | |
<% else %> | |
<div class="nested-fields"> | |
<div class="row"> | |
<div class="small-6 medium-2 columns leitor"> | |
<% if !f.object.id.present? %> | |
<form action="#" method="post"> | |
<input id = "barcode" class = "cod_barras" type="text" name="cod_barras" value="" /> | |
</form> | |
<% end %> | |
</div> | |
<div class="small-3 medium-3 columns end"> | |
<% if !f.object.id.present? %> | |
<a id='scanBtn' class="button tiny radius success barcode_btn" type="button" | |
onclick="bridgeit.scan('scanBtn', 'onAfterCaptureScan');">Leitor</a> | |
<% end %> | |
</div> | |
<div class="small-5 columns end not_found"> | |
<span class="not_found">Produto não existe ! <%= link_to 'Cadastrar ?', new_product_path, :target => "_blank", class: "button radius tiny" %></span> | |
</div> | |
</div> | |
<div class="row"> | |
<%= f.input :id, :as => :hidden, input_html: { class: 'id_detail_ror' } %> | |
<div class="small-6 columns show-for-small-only"> | |
<%= f.input :barcode,label: "Cód Barras" ,input_html: { class: 'barcode_ror' } %> | |
</div> | |
<%= f.input :order_id, :as => :hidden, input_html: { class: 'order_id_ror' } %> | |
<div class="show-for-medium-up small-1 columns"> | |
<%= f.input :cod_produto, label: "Produto", input_html: { class: 'cod_produto_ror' } %> | |
</div> | |
<%= f.input :desc_produto,:as => :hidden, input_html: { class: 'desc_produto_ror' } %> | |
<%= f.input :cod_cor,:as => :hidden, input_html: { class: 'cod_cor_ror' } %> | |
<div class="small-2 show-for-medium-up columns"> | |
<%= f.input :desc_cor,label: "Cor", input_html: { class: 'desc_cor_ror' } %> | |
</div> | |
<div class="small-1 show-for-medium-up columns"> | |
<%= f.input :desc_tamanho,label: "Tam", input_html: { class: 'desc_tamanho_ror' } %> | |
</div> | |
<div class="small-2 show-for-medium-up columns"> | |
<%= f.input :preco,label: "Preço",input_html: { class: 'preco_ror' } %> | |
</div> | |
<div class="small-4 medium-1 columns"> | |
<% if !f.object.id.present? %> | |
<%= f.input :quantidade,label: "Qtd", input_html: { class: 'quantidade_ror' } %> | |
<% else %> | |
<%= f.input :quantidade,label: "Qtd", input_html: { class: 'read_only' } %> | |
<% end %> | |
</div> | |
<div class="small-3 medium-2 columns"> | |
<%= f.input :quantidade_dev,label: "Qtd Dev", input_html: { class: 'quantidade_ror_dev', id: f.object.barcode } %> | |
</div> | |
<div class="show-for-medium-up small-2 columns end"> | |
<%= f.input :total,label: "Total",input_html: { class: 'total_ror' } %> | |
</div> | |
<div class="small-1 columns end"> | |
<% if !f.object.id.present? %> | |
<%= link_to_remove_association "-", f, :class => "button tiny alert"%> | |
<% end %> | |
</div> | |
<hr/> | |
</div> | |
</div> | |
<% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% if @tipo == "devolucao" %> | |
<%= simple_form_for(@order) do |f| %> | |
<%= f.error_notification %> | |
<div class="form-inputs"> | |
<%= f.input :customer_id, :as => :hidden %> | |
<%= f.input :tipo, :as => :hidden %> | |
<%= f.input :descontado, :as => :hidden %> | |
<%= f.input :valor_total, :as => :hidden %> | |
<%= f.input :item_total, :as => :hidden %> | |
<%= f.input :order_num, :as => :hidden %> | |
<br/> | |
<div class="row"> | |
<form action="#" method="post"> | |
<div class="small-6 medium-3 columns leitor_dev"> | |
<input id = "inputCod" type="text" /> | |
</div> | |
<div class="small-3 medium-3 columns end"> | |
<a id='scanBtnDev' class="button tiny radius success scan" type="button" | |
onclick="bridgeit.scan('scanBtnDev', 'onAfterCaptureScanDev');">Leitor</a> | |
</div> | |
</form> | |
<div class="small-5 columns end not_found"> | |
<span class="not_found">Produto não existe neste pedido!</span> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="small-12 columns"> | |
<hr/> | |
<div id="details"> | |
<%= f.simple_fields_for :details do |detail| %> | |
<%= render "detail_fields", {:f => detail,:tipo => "devolucao"}%> | |
<% end %> | |
</div> | |
<hr/> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="small-12 columns"> | |
<div class="form-actions container"> | |
<%= link_to_add_association '+ ítens', f, :details, data: {"association-insertion-method" => :before, "association-insertion-node" => ".container " },:class => "button tiny radius add" %> | |
<br /> | |
<br /> | |
<br /> | |
</div> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="small-6 medium-2 columns"> | |
<%= f.button :submit, "Salvar" %> | |
</div> | |
<div class="small-6 medium-2 columns end"> | |
<%= link_to 'Cancelar', orders_path, :class => "button alert"%> | |
</div> | |
</div> | |
<% end %> | |
<% else %> | |
<%= simple_form_for(@order) do |f| %> | |
<%= f.error_notification %> | |
<div class="form-inputs"> | |
<% if !browser.device.mobile? %> | |
<div class="row"> | |
<div class="small-4 columns"> | |
<%= f.association :customer, collection: Customer.order('nome ASC'), label_method: :nome, value_method: :id, include_blank: false, prompt: "Selecione", label: "Cliente:", class: "right inline cliente" %> | |
</div> | |
<div class="small-3 columns end"> | |
<%= f.input :tipo, | |
label: "Escolha:", | |
:collection => Order::TIPO, | |
prompt: "Tipo do pedido", | |
include_blank: false %> | |
</div> | |
<%= f.input :descontado, :as => :hidden %> | |
</div> | |
<% else %> | |
<div class="row collapse"> | |
<div class="small-12 columns end"> | |
<%= f.association :customer, collection: Customer.order('nome ASC'), label_method: :nome, value_method: :id, include_blank: false, prompt: "Selecione", label: "Cliente:", class: "right inline cliente" %> | |
</div> | |
</div> | |
<div class="row collapse"> | |
<div class="small-6 columns end"> | |
<%= f.input :tipo, | |
label: "Escolha:", | |
:collection => Order::TIPO, | |
prompt: "Tipo do pedido", | |
include_blank: false %> | |
</div> | |
</div> | |
<%= f.input :descontado, :as => :hidden %> | |
<% end %> | |
<%= f.input :valor_total, :as => :hidden, input_html: { class: 'valor_total_ror' } %> | |
<%= f.input :item_total, :as => :hidden, input_html: { class: 'item_total_ror' } %> | |
<%= f.input :order_num, :as => :hidden, input_html: { class: 'ordem_num_ror' } %> | |
<div class="row"> | |
<div class="small-12 columns"> | |
<hr/> | |
<div id="details"> | |
<%= f.simple_fields_for :details do |detail| %> | |
<%= render "detail_fields",{ :f => detail , :tipo => "edicao"}%> | |
<% end %> | |
</div> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="small-12 columns"> | |
<div class="form-actions container"> | |
<%= link_to_add_association '+ ítens', f, :details, data: {"association-insertion-method" => :before, "association-insertion-node" => ".container" },:class => "button tiny radius add_itens" %> | |
<br /> | |
<br /> | |
<br /> | |
</div> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="small-6 medium-2 columns"> | |
<%= f.button :submit, "Salvar" %> | |
</div> | |
<div class="small-6 medium-2 columns end"> | |
<%= link_to 'Cancelar', orders_path, :class => "button alert"%> | |
</div> | |
</div> | |
<% end %> | |
<% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DetailsController < ApplicationController | |
before_action :set_detail, only: [:show, :edit, :update, :destroy] | |
# GET /details | |
# GET /details.json | |
def index | |
@details = Detail.select("cod_produto,desc_produto,desc_tamanho,desc_cor,sum (preco) as preco ,sum(quantidade) as quantidade, sum (total) as total,sum(quantidade_dev) as quantidade_dev").group("cod_produto,desc_tamanho,desc_cor").order("cod_produto asc, desc_tamanho asc, desc_cor asc") | |
end | |
# GET /details/1 | |
# GET /details/1.json | |
def show | |
end | |
# GET /details/new | |
def new | |
@detail = Detail.new | |
end | |
# GET /details/1/edit | |
def edit | |
# @detail.order(cod_produto: :asc,desc_cor: :asc, desc_tamanho: :asc) ele nao está ordenando. ver depois | |
end | |
# POST /details | |
# POST /details.json | |
def create | |
@detail = Detail.new(detail_params) | |
respond_to do |format| | |
if @detail.save | |
format.html { redirect_to @detail, notice: 'Detail was successfully created.' } | |
format.json { render :show, status: :created, location: @detail } | |
else | |
format.html { render :new } | |
format.json { render json: @detail.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# PATCH/PUT /details/1 | |
# PATCH/PUT /details/1.json | |
def update | |
respond_to do |format| | |
if @detail.update(detail_params) | |
format.html { redirect_to @detail, notice: 'Detail was successfully updated.' } | |
format.json { render :show, status: :ok, location: @detail } | |
else | |
format.html { render :edit } | |
format.json { render json: @detail.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /details/1 | |
# DELETE /details/1.json | |
def destroy | |
@detail.destroy | |
respond_to do |format| | |
format.html { redirect_to details_url, notice: 'Detail was successfully destroyed.' } | |
format.json { head :no_content } | |
end | |
end | |
private | |
# Use callbacks to share common setup or constraints between actions. | |
def set_detail | |
@detail = Detail.find(params[:id]) | |
end | |
# Never trust parameters from the scary internet, only allow the white list through. | |
def detail_params | |
params.require(:detail).permit(:order_id, :cod_produto, :desc_produto, :cod_cor, :desc_cor, :desc_tamanho, :preco, :quantidade,:total,:quantidade_dev,:total_dev,:barcode) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrdersController < ApplicationController | |
before_action :set_order, only: [:show, :edit, :update, :destroy, :devolucao] | |
require "json" | |
require 'net/http' | |
def consulta_produto | |
@variacao = Variation.find_by(barcode:params[:barcode]) | |
if @variacao.present? | |
hash = {:cod_produto => @variacao.product.cod ,:desc_produto => @variacao.product.descricao,:cod_cor => @variacao.color.cod, :desc_cor => @variacao.color.descricao,:desc_tamanho => @variacao.size.descricao,:preco => @variacao.product.price, :barcode => @variacao.barcode } | |
render :json => { :resultado => hash } | |
else | |
render :json => {:resultado => "error"} | |
end | |
# sql = "select * from friendly_id_slugs where slug = '" + params[:barcode] + "'" | |
# saida = ActiveRecord::Base.connection.execute(sql) | |
# render :json => { :existe => saida } | |
# render :json => { :existe => Empresa.find_by(apelido:params[:apelido])} | |
# render :json => { :existe => Empresa.find_by(apelido:params[:apelido])} | |
end | |
# GET /orders | |
# GET /orders.json | |
def index | |
@orders = Order.all.order(created_at: :desc, customer_id: :desc) | |
end | |
# GET /orders/1 | |
# GET /orders/1.json | |
def barcode | |
@barcode = params[:barcode] | |
render text: 'Thanks for sending a GET request with cURL!' + @barcode | |
uri = URI('http://zxing.appspot.com/scan?'+barcode_path) | |
req = Net::HTTP.get(uri) | |
puts req #show result | |
end | |
def show | |
@detail = Order.find(params[:id]) | |
# @detail = @order.details.select("cod_produto,desc_produto,desc_tamanho,desc_cor,barcode,sum (preco) as preco ,sum(quantidade) as quantidade, sum (total) as total,sum(quantidade_dev) as quantidade_dev, sum(total_dev) as total_dev").group("barcode").order("cod_produto asc, desc_tamanho asc, desc_cor asc").flatten | |
respond_to do |format| | |
format.html | |
format.pdf do | |
pdf = OrderPdf.new(@order,view_context) | |
send_data pdf.render, | |
filename: "order.pdf", | |
type: "application/pdf", | |
disposition: "inline" | |
end | |
end | |
end | |
# GET /orders/new | |
def order_report | |
@order = Order.find(params[:id]) | |
@details = @order.details.select('details.cod_produto as cod_produto, details.desc_produto as desc_produto, details.preco as preco, sum(quantidade) as quantidade, sum(preco) as total').group('cod_produto,desc_produto,preco').order('cod_produto ASC') | |
render 'order_report.pdf.thinreports' | |
end | |
def new | |
@order = Order.new | |
# @variacoes = Variation.order(:barcode).select(:id,:nome) | |
# # ActiveRecord::Base.include_root_in_json = true | |
# gon.clientes = @clientes.to_json | |
end | |
# GET /orders/1/edit | |
def edit | |
@tipo = params[:tipo] | |
end | |
def envia_pedido | |
@order = Order.find(params[:id]) | |
EnviaPedido.envia_pedido(@order,current_user).deliver | |
flash[:success] = "Pedido enviado com sucesso para o cliente #{@order.customer.nome} !" | |
# redirect_to @order | |
redirect_to action: :index | |
end | |
def devolucao | |
# @order = Order.find(params[:id]) | |
end | |
# POST /orders | |
# POST /orders.json | |
def create | |
@order = Order.new(order_params) | |
respond_to do |format| | |
if @order.save | |
format.html { redirect_to @order, notice: 'Order was successfully created.' } | |
format.json { render :show, status: :created, location: @order } | |
else | |
format.html { render :new } | |
format.json { render json: @order.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# PATCH/PUT /orders/1 | |
# PATCH/PUT /orders/1.json | |
def update | |
respond_to do |format| | |
if @order.update(order_params) | |
format.html { redirect_to @order, notice: 'Order was successfully updated.' } | |
format.json { render :show, status: :ok, location: @order } | |
else | |
format.html { render :edit } | |
format.json { render json: @order.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /orders/1 | |
# DELETE /orders/1.json | |
def destroy | |
@order.destroy | |
respond_to do |format| | |
format.html { redirect_to orders_url, notice: 'Order was successfully destroyed.' } | |
format.json { head :no_content } | |
end | |
end | |
private | |
# Use callbacks to share common setup or constraints between actions. | |
def set_order | |
@order = Order.find(params[:id]) | |
end | |
# Never trust parameters from the scary internet, only allow the white list through. | |
def order_params | |
params.require(:order).permit! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment