Skip to content

Commit

Permalink
Instable commit done for technical reasons (always adapting to new cu…
Browse files Browse the repository at this point in the history
…rrency system)
  • Loading branch information
burisu committed Mar 26, 2012
1 parent ede3412 commit 2977cf8
Show file tree
Hide file tree
Showing 111 changed files with 912 additions and 910 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ gem 'rubyzip', :require=>'zip/zip'
gem 'will_paginate', '~> 3.0'
gem "exception_notification"
gem 'state_machine'
gem 'combo_box' #, :path=>'../combo_box'
gem 'combo_box', :path=>'../combo_box'
gem 'formize' #, :path=>'../formize'
gem 'spreet'
gem 'prawn', '>= 0.10.0'
Expand Down
12 changes: 8 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
PATH
remote: ../combo_box
specs:
combo_box (0.0.7)
jquery-rails
rails (~> 3)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -40,9 +47,6 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.2.0)
combo_box (0.0.7)
jquery-rails
rails (~> 3)
erubis (2.7.0)
exception_notification (2.5.2)
actionmailer (>= 3.0.4)
Expand Down Expand Up @@ -140,7 +144,7 @@ DEPENDENCIES
acts_as_list
acts_as_tree
coffee-rails (~> 3.2.1)
combo_box
combo_box!
exception_notification
fastercsv
formize
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ def render_restfully_form(options={})
end


def find_and_check(model, id=nil, options={})
def find_and_check(model=nil, id=nil, options={})
model ||= self.controller_name
model, record, klass = model.to_s, nil, nil
id ||= params[:id]
begin
Expand Down Expand Up @@ -204,9 +205,10 @@ def save_and_redirect(record, options={}, &block)
def t3e(*args)
@title ||= {}
for arg in args
arg = arg.attributes if arg.respond_to?(:attributes)
raise ArgumentError.new("Hash expected, got #{arg.class.name}:#{arg.inspect}") unless arg.is_a? Hash
arg.each do |k,v|
@title[k.to_sym] = if [Date, DateTime, Time].include? v.class
@title[k.to_sym] = if v.respond_to?(:strftime) or v.is_a?(Numeric)
::I18n.localize(v)
else
v.to_s
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/assets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#

class AssetsController < ApplicationController
manage_restfully
manage_restfully :currency=>'@current_company.default_currency', :depreciation_method=>"'linear'"

list(:conditions=>{:company_id=>['@current_company.id']}) do |t|
t.column :name, :url=>true
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/bank_statements_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class BankStatementsController < ApplicationController
t.column :number, :url=>true
t.column :started_on
t.column :stopped_on
t.column :debit
t.column :credit
t.column :debit, :currency=>"RECORD.cash.currency"
t.column :credit, :currency=>"RECORD.cash.currency"
t.action :point
t.action :edit
t.action :destroy, :method=>:delete, :confirm=>:are_you_sure_you_want_to_delete
Expand Down
6 changes: 2 additions & 4 deletions app/controllers/cash_transfers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ class CashTransfersController < ApplicationController

list(:conditions=>["#{CashTransfer.table_name}.company_id = ? ", ['@current_company.id']]) do |t|
t.column :number, :url=>true
t.column :emitter_amount
t.column :name, :through=>:emitter_currency
t.column :emitter_amount, :currency=>"RECORD.emitter_cash.currency"
t.column :name, :through=>:emitter_cash, :url=>true
t.column :receiver_amount
t.column :name, :through=>:receiver_currency
t.column :receiver_amount, :currency=>"RECORD.receiver_cash.currency"
t.column :name, :through=>:receiver_cash, :url=>true
t.column :created_on
t.column :comment
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/cashes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class CashesController < ApplicationController
list(:conditions=>{:company_id=>['@current_company.id']}, :order=>:name) do |t|
t.column :name, :url=>true
t.column :nature_label
t.column :name, :through=>:currency
t.column :currency
t.column :country
t.column :number, :through=>:account, :url=>true
t.column :name, :through=>:journal, :url=>true
t.action :edit
Expand Down Expand Up @@ -63,7 +64,7 @@ def new
render :partial=>'accountancy_form', :locals=>{:nature=>params[:nature]}
return
end
@cash = Cash.new(:mode=>"bban", :nature=>"bank_account", :entity_id=>params[:entity_id]||@current_company.entity_id)
@cash = Cash.new(:mode=>"bban", :currency=>@current_company.default_currency, :nature=>"bank_account", :entity_id=>params[:entity_id]||@current_company.entity_id)
render_restfully_form
end

Expand Down
7 changes: 4 additions & 3 deletions app/controllers/deposits_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ class DepositsController < ApplicationController

list(:conditions=>{:company_id=>['@current_company.id']}, :order=>"created_at DESC") do |t|
t.column :number, :url=>true
t.column :amount, :url=>true
t.column :amount, :currency=>"RECORD.cash.currency", :url=>true
t.column :payments_count
t.column :name, :through=>:cash, :url=>true
t.column :label, :through=>:responsible
t.column :created_on
t.column :comment
t.action :show, :url=>{:format=>:pdf}, :image=>:print
t.action :edit, :if=>'RECORD.locked == false'
t.action :destroy, :method=>:delete, :confirm=>:are_you_sure_you_want_to_delete, :if=>'RECORD.locked == false'
Expand All @@ -44,7 +45,7 @@ def index
t.column :account_number
t.column :check_number
t.column :paid_on
t.column :amount, :url=>true
t.column :amount, :currency=>"RECORD.mode.cash.currency", :url=>true
end

# Displays details of one deposit selected with +params[:id]+
Expand All @@ -68,7 +69,7 @@ def show
t.column :check_number
t.column :paid_on
t.column :label, :through=>:responsible
t.column :amount
t.column :amount, :currency=>"RECORD.mode.cash.currency"
t.check_box :to_deposit, :value=>'(RECORD.to_bank_on<=Date.today and (session[:deposit_id].nil? ? (RECORD.responsible.nil? or RECORD.responsible_id==@current_user.id) : (RECORD.deposit_id==session[:deposit_id])))', :label=>tc(:to_deposit)
end

Expand Down
1 change: 1 addition & 0 deletions app/controllers/financial_years_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class FinancialYearsController < ApplicationController
t.column :started_on, :url=>true
t.column :stopped_on, :url=>true
t.column :currency
t.column :currency_precision
t.action :close, :if => '!RECORD.closed and RECORD.closable?'
t.action :edit, :if => '!RECORD.closed'
t.action :destroy, :method=>:delete, :confirm=>:are_you_sure_you_want_to_delete, :if => '!RECORD.closed'
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/incoming_payment_modes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ class IncomingPaymentModesController < ApplicationController

list(:conditions=>{:company_id=>['@current_company.id']}, :order=>:position) do |t|
t.column :name
t.column :with_accounting
t.column :name, :through=>:cash, :url=>true
t.column :with_accounting
t.column :with_deposit
t.column :label, :through=>:depositables_account, :url=>true
t.column :name, :through=>:depositables_journal, :url=>true
t.column :with_commission
t.action :up, :method=>:post, :if=>"!RECORD.first\?"
t.action :down, :method=>:post, :if=>"!RECORD.last\?"
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/incoming_payments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def self.incoming_payments_conditions(options={})
t.column :number, :url=>true
t.column :full_name, :through=>:payer, :url=>true
t.column :paid_on
t.column :amount, :url=>true
t.column :used_amount
t.column :amount, :currency=>"RECORD.mode.cash.currency", :url=>true
t.column :used_amount, :currency=>"RECORD.mode.cash.currency"
t.column :name, :through=>:mode
t.column :check_number
t.column :to_bank_on
Expand Down
9 changes: 4 additions & 5 deletions app/controllers/interfacers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,18 @@ def product_units
search_for(:account, :columns=>["number:X%", :name], :conditions =>{:company_id=>['@current_company.id']})
search_for(:all_contacts, :contacts, :columns=>[:address], :conditions =>["company_id = ? AND deleted_at IS NULL", ['@current_company.id']])
search_for(:attorneys_accounts, :accounts, :columns=>[:number, :name], :conditions=>["company_id=? AND number LIKE ?", ["@current_company.id"], ["@current_company.preferred_third_attorneys_accounts.to_s+'%'"]])
# search_for(:available_prices, :prices, :columns=>["products.code", "products.name", "prices.pretax_amount", "prices.amount"], :joins=>"JOIN #{Product.table_name} AS products ON (product_id=products.id)", :conditions=>["prices.company_id=? AND prices.active=? AND products.active=?", ['@current_company.id'], true, true], :order=>"products.name, prices.amount")
search_for(:available_prices, :prices, :columns=>["product.code", "product.name", :pretax_amount, :amount], :joins=>[:product], :conditions=>["#{Price.table_name}.company_id=? AND #{Price.table_name}.active=? AND #{Product.table_name}.active=?", ['@current_company.id'], true, true], :order=>"products.name, prices.amount")


search_for(:available_prices, :prices, :columns=>["product.code", "product.name", {:name=>:pretax_amount, :code=>"I18n.localize(DATUM, :currency=>RECORD.currency)"}, {:name=>:amount, :code=>"I18n.localize(DATUM, :currency=>RECORD.currency)"}], :joins=>[:product], :conditions=>["#{Price.table_name}.company_id=? AND #{Price.table_name}.active=? AND #{Product.table_name}.active=?", ['@current_company.id'], true, true], :order=>"products.name, prices.amount")
# search_for(:available_prices, :prices, :columns=>["product.code", "product.name", :pretax_amount, :amount], :joins=>[:product], :conditions=>["#{Price.table_name}.company_id=? AND #{Price.table_name}.active=? AND #{Product.table_name}.active=?", ['@current_company.id'], true, true], :order=>"products.name, prices.amount")
search_for(:clients_accounts, :accounts, :columns=>[:number, :name], :conditions=>["company_id=? AND number LIKE ?", ["@current_company.id"], ["@current_company.preferred_third_clients_accounts.to_s+'%'"]])
search_for(:client_contacts, :contacts, :columns=>[:address], :conditions=>["company_id = ? AND entity_id = ? AND deleted_at IS NULL", ['@current_company.id'], ['session[:current_entity_id]']])
search_for(:clients, :entities, :columns=>[:code, :full_name], :conditions => {:company_id=>['@current_company.id'], :client=>true})
search_for(:collected_account, :account, :columns=>["number:X%", :name], :conditions => {:company_id=>['@current_company.id']})
# search_for(:contacts, :columns=>[:address], :conditions => { :company_id=>['@current_company.id'], :entity_id=>['@current_company.entity_id']})
search_for(:districts, :columns=>[:name, :code], :conditions=>{:company_id=>['@current_company.id']})
search_for(:entities, :columns=>[:code, :full_name], :conditions => {:company_id=>['@current_company.id']})
# search_for(:incoming_delivery_contacts, :contact, :columns=>['entities.full_name', :address], :conditions =>["#{Contact.table_name}.company_id = ? AND #{Contact.table_name}.deleted_at IS NULL", ['@current_company.id']], :joins=>"JOIN #{Company.table_name} AS companies ON (companies.entity_id=#{Contact.table_name}.entity_id))")
search_for(:incoming_delivery_contacts, :contact, :columns=>['entity.full_name', :address], :conditions =>["#{Contact.table_name}.company_id = ? AND #{Contact.table_name}.deleted_at IS NULL AND #{Contact.table_name}.entity_id = #{Company.table_name}.entity_id", ['@current_company.id']], :joins=>[:company])
search_for(:operation_products, :product, :columns=>[:code, :name], :conditions =>{:company_id=>['@current_company.id'], :active=>true})
# search_for(:operation_out_products, :products, :columns=>[:code, :name], :conditions => {:company_id=>['@current_company.id'], :active=>true, :to_produce=>true})
search_for(:outgoing_deliveries, :columns=>[:planned_on, "contact.address"], :conditions=>["#{OutgoingDelivery.table_name}.company_id = ? AND transport_id IS NULL", ['@current_company.id']], :joins=>[:contact])
search_for(:outgoing_delivery_contacts, :contacts, :columns=>['entity.full_name', :address], :conditions=>["#{Contact.table_name}.company_id = ? AND #{Contact.table_name}.deleted_at IS NULL", ['@current_company.id']], :joins=>[:entity])
search_for(:paid_account, :account, :columns=>["number:X%", :name], :conditions => {:company_id=>['@current_company.id']})
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/journal_entries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class JournalEntriesController < ApplicationController
t.column :number, :through=>:account, :url=>true
t.column :name, :through=>:account, :url=>true
t.column :number, :through=>:bank_statement, :url=>true
t.column :original_debit
t.column :original_credit
t.column :debit
t.column :credit
t.column :original_debit, :currency=>"RECORD.entry.original_currency"
t.column :original_credit, :currency=>"RECORD.entry.original_currency"
t.column :debit, :currency=>"RECORD.entry.financial_year.currency"
t.column :credit, :currency=>"RECORD.entry.financial_year.currency"
end


Expand Down
2 changes: 1 addition & 1 deletion app/controllers/outgoing_payment_modes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class OutgoingPaymentModesController < ApplicationController

list(:conditions=>{:company_id=>['@current_company.id']}, :order=>:position) do |t|
t.column :name
t.column :with_accounting
t.column :name, :through=>:cash, :url=>true
t.column :with_accounting
t.action :up, :method=>:post, :if=>"!RECORD.first\?"
t.action :down, :method=>:post, :if=>"!RECORD.last\?"
t.action :edit
Expand Down
22 changes: 15 additions & 7 deletions app/controllers/sale_natures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@
#

class SaleNaturesController < ApplicationController
manage_restfully
manage_restfully :currency=>"@current_company.default_currency"

list(:conditions=>{:company_id=>['@current_company.id']}) do |t|
t.column :name
t.column :name, :url=>true
t.column :active
t.column :name, :through=>:expiration, :url=>true
t.column :name, :through=>:payment_delay, :url=>true
t.column :currency
# t.column :name, :through=>:expiration, :url=>true
# t.column :name, :through=>:payment_delay, :url=>true
t.column :downpayment
t.column :downpayment_minimum
t.column :downpayment_rate
t.column :comment
# t.column :downpayment_minimum
# t.column :downpayment_rate
t.column :with_accounting
t.column :name, :through=>:journal, :url=>true
#t.column :comment
t.action :edit
t.action :destroy, :method=>:delete, :confirm=>:are_you_sure_you_want_to_delete
end
Expand All @@ -37,4 +40,9 @@ class SaleNaturesController < ApplicationController
def index
end

def show
@sale_nature = find_and_check
t3e @sale_nature
end

end
14 changes: 7 additions & 7 deletions app/controllers/sales_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def self.sales_conditions
t.column :label, :through=>:responsible
t.column :comment
t.column :state_label
t.column :paid_amount
t.column :amount
t.column :paid_amount, :currency=>true
t.column :amount, :currency=>true
t.action :show, :url=>{:format=>:pdf}, :image=>:print
t.action :edit, :if=>'RECORD.draft? '
t.action :cancel, :if=>'RECORD.cancelable? '
Expand All @@ -72,8 +72,8 @@ def index
t.column :number, :url=>true, :children=>:designation
t.column :full_name, :through=>:client, :children=>false
t.column :created_on, :children=>false
t.column :pretax_amount
t.column :amount
t.column :pretax_amount, :currency=>true
t.column :amount, :currency=>true
end

list(:deliveries, :model=>:outgoing_deliveries, :children=>:lines, :conditions=>{:company_id=>['@current_company.id'], :sale_id=>['session[:current_sale_id]']}) do |t|
Expand Down Expand Up @@ -131,9 +131,9 @@ def index
t.column :serial, :through=>:tracking, :url=>true
t.column :quantity
t.column :label, :through=>:unit
t.column :pretax_amount, :through=>:price, :label=>"unit_price_amount"
t.column :pretax_amount
t.column :amount
t.column :pretax_amount, :through=>:price, :label=>"unit_price_amount", :currency=>true
t.column :pretax_amount, :currency=>"RECORD.sale.currency"
t.column :amount, :currency=>"RECORD.sale.currency"
t.action :edit, :if=>'RECORD.sale.draft? and RECORD.reduction_origin_id.nil? '
t.action :destroy, :method=>:delete, :confirm=>:are_you_sure_you_want_to_delete, :if=>'RECORD.sale.draft? and RECORD.reduction_origin_id.nil? '
end
Expand Down
71 changes: 11 additions & 60 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ def number_to_management(value)
number_to_currency(number, :precision=>2, :format=>'%n', :delimiter=>'&nbsp;', :separator=>',')
end

# Take an extra argument which will translate
def number_to_money(amount, currency, options={})
return unless amount and currency
return Numisma[currency].localize(amount, options)
end



def preference(name)
# name = self.controller.controller_name.to_s << name.to_s if name.to_s.match(/^\./)
Expand Down Expand Up @@ -258,7 +265,10 @@ def attribute_item(object, attribute, options={})
end
if [TrueClass, FalseClass].include? value.class
value = content_tag(:div, "", :class=>"checkbox-#{value}")
elsif ["Date", "Time", "DateTime"].include? value.class.name
elsif options[:currency] and value.is_a?(Numeric)
value = ::I18n.localize(value, :currency=>options[:currency])
value = link_to(value.to_s, options[:url]) if options[:url]
elsif value.respond_to?(:strftime) or value.is_a?(Numeric)
value = ::I18n.localize(value)
value = link_to(value.to_s, options[:url]) if options[:url]
elsif options[:duration]
Expand Down Expand Up @@ -1447,64 +1457,5 @@ def condition_label(condition)




# Take an extra argument which will translate
def number_to_money(amount, currency, options={})
return unless amount and currency

options.symbolize_keys!

defaults = I18n.translate('number.format'.to_sym, :locale => options[:locale], :default => {})
defaultt = I18n.translate('number.currency.format'.to_sym, :locale => options[:locale], :default => {})
defaultt[:negative_format] ||= "-" + defaultt[:format] if defaultt[:format]
formatcy = I18n.translate("number.currency.formats.#{currency}".to_sym, :locale => options[:locale], :default => {})
formatcy[:negative_format] ||= "-" + formatcy[:format] if formatcy[:format]

prec = {}
prec[:separator] = formatcy[:separator] || defaultt[:separator] || defaults[:separator]
prec[:delimiter] = formatcy[:delimiter] || defaultt[:delimiter] || defaults[:delimiter]
prec[:precision] = formatcy[:precision] || Numisma[currency].precision || defaultt[:precision]
format = formatcy[:format] || defaultt[:format] || defaults[:format]
negative_format = formatcy[:negative_format] || defaultt[:negative_format] || defaults[:negative_format] || "-" + format
unit = formatcy[:unit] || Numisma[currency].unit || currency

# defaults = {}.merge(defaults).merge!(formatcy)
# defaults.merge!(defaultt)
# defaults.merge!(formatcy)
# defaults[:negative_format] = "-" + options[:format] if options[:format]
# options = defaults.merge!(options)

# unit = formatcy[:unit] || Numisma[currency].unit || currency
# format = options.delete(:format)

# options[:precision] ||= Numisma[currency].precision

# raise [amount, currency, prec, unit, format, negative_format].inspect

if amount.to_f < 0
format = negative_format # options.delete(:negative_format)
amount = amount.respond_to?("abs") ? amount.abs : amount.sub(/^-/, '')
end

#begin
# value = number_with_precision(amount, prec.merge(:raise => true))
value = amount.to_s
integers, decimals = value.split(/\./)
# TODO: Find a better way to delimite thousands
decimals = decimals.gsub(/0+$/, '').ljust(prec[:precision], '0').reverse.split(/(?=\d{3})/).reverse.collect{|x| x.reverse}.join(prec[:delimiter])
value = integers.gsub(/^0+[1-9]+/, '').gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{prec[:delimiter]}")
value += prec[:separator] + decimals unless decimals.blank?
format.gsub(/%n/, value).gsub(/%u/, unit).gsub(/%s/, '&nbsp;').html_safe
# rescue InvalidNumberError => e
# if options[:raise]
# raise
# else
# formatted_number = format.gsub(/%n/, e.number).gsub(/%u/, unit).gsub(/%s/, '&nbsp;')
# e.number.to_s.html_safe? ? formatted_number.html_safe : formatted_number
# end
# end
end


end

2 changes: 1 addition & 1 deletion app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Account < CompanyRecord
self.label = tc(:label, :number=>self.number.to_s, :name=>self.name.to_s)
end

protect_on_destroy do
protect(:on => :destroy) do
dependencies = 0
for k, v in self.class.reflections.select{|k, v| v.macro == :has_many}
dependencies += self.send(k).size
Expand Down

0 comments on commit 2977cf8

Please sign in to comment.