Skip to content

Instantly share code, notes, and snippets.

@renatosousafilho
Created March 31, 2014 12:08
Show Gist options
  • Save renatosousafilho/9890903 to your computer and use it in GitHub Desktop.
Save renatosousafilho/9890903 to your computer and use it in GitHub Desktop.
Módulo de sistema de abertura e fechamento de caixa
class CreateCashes < ActiveRecord::Migration
def change
create_table :cashes do |t|
t.datetime :start_at
t.datetime :end_at
t.decimal :value_open
t.decimal :value_phisic_closed
t.decimal :value_system_closed
t.timestamps
end
end
end
<%= simple_form_for @cash do |f| %>
<div class="form-group">
<%= f.input :value_open, :input_html =>{:class=>"form-control"} %>
</div>
<%= button_tag(type: :submit, :class=>"btn btn-success") do %>
<i class="icon-save"></i> Registar abertura de caixa
<% end %>
<% end %>
class ApplicationController < ActionController::Base
before_filter :authenticate_user!
before_filter :authenticate_cash
def after_sign_in_path_for(resource)
new_cash_path
end
def authenticate_cash
# deve verificar se já foi criado uma abertura de caixa
end
end
class CashesController < ApplicationController
def index
start_at = current_user.current_sign_in_at
@billings = Billing.where("created_at>?",start_at)
end
def new
@cash = Cash.new
end
def create
@cash = Cash.new(cash_params)
@cash.start_at = current_user.current_sign_in_at
if @cash.save
redirect_to root_url
end
end
def cash_params
params.require(:cash).permit(:value_open, :value_phisic_closed, :value_system_closed)
end
end
class Cashing < ActiveRecord::Base
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment