Skip to content

Commit

Permalink
merge takeover
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth committed Oct 1, 2011
2 parents 1e16d3c + b265fd2 commit ae9d3d1
Show file tree
Hide file tree
Showing 98 changed files with 19,819 additions and 231 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
doc/transaction_event_logs/
.rvmrc
.DS_Store
log/*
Expand Down
30 changes: 6 additions & 24 deletions app/controllers/accounts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,6 @@ class Accounts < Application
# provides :xml, :yaml, :js
before :get_context

# TODO the recursive functions need to be debugged and have to be used a display fully nested accounting selection box
# def hash_creation(account, hash_list)
# if account.children
# hash_list[account]||={}
# account.children.each{|c|
# hash_creation(c, hash_list[c])
# }
# else
# hash_list[account] = account.children
# end
# end

# def list_creation(account, list)
# if account.children
# account.children.each{|c|
# list_creation(c, list)
# }
# else
# list << account.children
# end
# end

def index
if params[:branch_id] and not params[:branch_id].blank?
@branch = Branch.get(params[:branch_id])
Expand All @@ -33,7 +11,11 @@ def index
end
@accounts = Account.tree((params[:branch_id] and not params[:branch_id].blank?) ? params[:branch_id].to_i : nil )
if params[:account_type_id] and (not params[:account_type_id].blank?)
@accounts = @accounts.delete(AccountType.get(params[:account_type_id])).to_hash
# bizarre result from to_hash compels me to take the scenic route - svs
at = AccountType.get(params[:account_type_id])
na = {}
na[at] = @accounts[at]
@accounts = na
end
template = request.xhr? ? 'accounts/select' : 'accounts/index'
display @accounts, template, :layout => layout?
Expand Down Expand Up @@ -153,7 +135,7 @@ def book
private
def get_context
@branches_list = Branch.all.map{ |x| [x.id, x.name]}
@branches_list.unshift([0, 'Head Office Accounts'])
@branches_list.unshift([nil, 'Head Office Accounts'])
@branch = Branch.get(params[:branch_id]) if params.key?(:branch_id)
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def delete
# if flag is still set to true delete the object
if flag == true and obj.destroy
# delete all the loan history
LoanHistory.all(:loan_id => obj.id).destroy if model == Loan or model.superclass == Loan or model.superclass.superclass == Loan
LoanHistory.all(:loan_id => obj.id).destroy if obj.is_a?(Loan)
Attendance.all(:client_id => obj.id).destroy if model == Client
PortfolioLoan.all(:portfolio_id => obj.id).destroy if model == Portfolio
Posting.all(:journal_id => obj.id).destroy if model == Journal
Expand All @@ -118,7 +118,7 @@ def delete
end
else
if model == ApplicableFee
obj.destroy #skip validations. they fail on the duplicate one
obj.destroy
redirect(params[:return], :message => {:notice => "Deleted #{model} #{model.respond_to?(:name) ? model.name : ''} (id: #{id})"})
end

Expand Down
7 changes: 7 additions & 0 deletions app/controllers/loan_purposes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class LoanPurposes < Application
# provides :xml, :yaml, :js

before :all_loan_purposes, :only => [:new, :create, :update]
def index
@loan_purposes = LoanPurpose.all
display @loan_purposes
Expand All @@ -21,12 +22,14 @@ def new
def edit(id)
only_provides :html
@loan_purpose = LoanPurpose.get(id)
@parents = LoanPurpose.all(:conditions => ['id != ?', id])
raise NotFound unless @loan_purpose
display @loan_purpose
end

def create(loan_purpose)
@loan_purpose = LoanPurpose.new(loan_purpose)
@loan_purpose.parent_id = 0 if @loan_purpose.parent_id.blank?
if @loan_purpose.save
redirect resource(@loan_purpose), :message => {:notice => "LoanPurpose was successfully created"}
else
Expand All @@ -37,6 +40,7 @@ def create(loan_purpose)

def update(id, loan_purpose)
@loan_purpose = LoanPurpose.get(id)
loan_purpose['parent_id'] = 0 if loan_purpose['parent_id'].blank?
raise NotFound unless @loan_purpose
if @loan_purpose.update(loan_purpose)
redirect resource(@loan_purpose)
Expand All @@ -55,4 +59,7 @@ def destroy(id)
end
end

def all_loan_purposes
@parents = LoanPurpose.all
end
end # LoanPurposes
1 change: 0 additions & 1 deletion app/controllers/loans.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ def reverse_write_off(id)
else
msg = {:error => "Loan could not be reversed because #{@loan.errors.values.join(',')}"}
end
debugger
redirect(resource(@branch, @center, @client, @loan) + "#misc", :message => msg)
end

Expand Down
14 changes: 14 additions & 0 deletions app/controllers/model_event_logs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class ModelEventLogs < Application
provides :xml, :yaml, :js

def index
render
end

def show(id)
@model_event_log = ModelEventLog.get(id)
raise NotFound unless @model_event_log
display @model_event_log
end

end
20 changes: 20 additions & 0 deletions app/controllers/organizations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Organizations < Application
provides :xml, :yaml, :js

def index
@organizations = Organization.all
display @organizations
end

def show(id)
@organization = Organization.get(id)
raise NotFound unless @organization
@domains = @organization.domains
if params[:format] and API_SUPPORT_FORMAT.include?(params[:format])
display [@organization, @domains]
else
display [@organization, @domains], 'domains/index', :layout => layout?
end
end

end
6 changes: 3 additions & 3 deletions app/controllers/staff_members.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def day_sheet(id)
file = @staff_member.generate_collection_pdf(@date)
filename = File.join(Merb.root, "doc", "pdfs", "staff", @staff_member.name, "collection_sheets", "collection_#{@staff_member.id}_#{@date.strftime('%Y_%m_%d')}.pdf")
if file
send_data(File.read(filename), :filename => filename)
send_data(File.read(filename), :filename => filename, :type => "application/pdf")
else
redirect resource(@staff_member), :message => {:notice => "No centers for collection today"}
end
Expand All @@ -103,7 +103,7 @@ def disbursement_sheet(id)
file = @staff_member.generate_disbursement_pdf(@date)
filename = File.join(Merb.root, "doc", "pdfs", "staff", @staff_member.name, "disbursement_sheets", "disbursement_#{@staff_member.id}_#{@date.strftime('%Y_%m_%d')}.pdf")
if file
send_data(File.read(filename), :filename => filename)
send_data(File.read(filename), :filename => filename, :type => "application/pdf")
else
redirect resource(@staff_member), :message => {:notice => "No centers for collection today"}
end
Expand Down Expand Up @@ -175,7 +175,7 @@ def display_sheets(id)
end

def send_sheet(filename)
send_data(File.read(filename), :filename => filename)
send_data(File.read(filename), :filename => filename, :type => "application/pdf")
end

# this redirects to the proper url, used from the router
Expand Down
13 changes: 13 additions & 0 deletions app/controllers/transaction_logs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class TransactionLogs < Application
provides :xml, :yaml, :js

def index
render
end

def show(id)
@transaction_log = TransactionLog.get(id)
raise NotFound unless @transaction_log
display @transaction_log
end
end
34 changes: 16 additions & 18 deletions app/helpers/accounts_helper.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
module Merb
module AccountsHelper
def show_accounts(accounts, depth = 0, tag = 'ul')
def show_accounts(accounts, depth = 0, tag = 'ul', selected = nil)
subtag = tag == 'ul' ? 'li' : 'option'

if accounts.is_a?(Array)
return if accounts.length == 0
first_account, rest_accounts = accounts[0], accounts[1..-1]||[]
rv = ((first_account.is_a?(Account) ? output_li(first_account, depth, tag, false) : show_accounts(first_account, depth, tag)) + rest_accounts.map{|account|
if account.is_a?(Account)
output_li(account, depth, tag)
elsif account.is_a?(Array) and account.length == 1 and account.first.is_a?(Account)
output_li(account.first, depth, tag)
elsif account.is_a?(Array) and account.length > 0
if tag == 'ul'
"<ul>#{show_accounts(account, depth + 1, tag)}</ul>"
else
show_accounts(account, depth + 1, tag)
end
end
}.join)
if account.is_a?(Account)
output_li(account, depth, tag, selected)
elsif account.is_a?(Array) and account.length == 1 and account.first.is_a?(Account)
output_li(account.first, depth, tag, selected)
elsif account.is_a?(Array) and account.length > 0
if tag == 'ul'
"<ul>#{show_accounts(account, depth + 1, tag)}</ul>"
else
show_accounts(account, depth + 1, tag, selected)
end
end
}.join)
rv = (rv + "</li>").gsub("<ul></li></ul>", "") if tag == 'ul'
else
rv = output_li(accounts, depth, tag)
rv = output_li(accounts, depth, tag, selected)
end
return rv
end

private

def output_select(account, depth, emit_closing=true)
end

def output_li(account, depth, tag, emit_closing=true)
def output_li(account, depth, tag, emit_closing=true, selected = nil)
if tag == 'ul'
return ( (account.branch_edge) ? "<li>#{link_to(account.name, resource(account))}#{"<span class=\"branchName\">" + account.branch.name + '</span>' if account.branch}#{emit_closing ? '</li>' : ''}" : "")
else
Expand Down
5 changes: 5 additions & 0 deletions app/helpers/model_event_logs_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Merb
module ModelEventLogsHelper

end
end # Merb
5 changes: 5 additions & 0 deletions app/helpers/organizations_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Merb
module OrganizationsHelper

end
end # Merb
5 changes: 5 additions & 0 deletions app/helpers/transaction_logs_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Merb
module TransactionLogsHelper

end
end # Merb
54 changes: 47 additions & 7 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ def is_bank_account?
@account_category ? @account_category.eql?('Bank') : false
end





def opening_and_closing_balances_as_of(for_date = Date.today)
return [nil, nil] if for_date > Date.today
opening_balance_on_date = opening_balance_as_of for_date
Expand Down Expand Up @@ -90,6 +86,7 @@ def change_closing_over_opening_balance_for_period(for_date = Date.today)
end

def opening_balance_as_of(for_date = Date.today)
debugger
return nil if for_date > Date.today
datum_balance = 0.0; datum = nil
check_past_period = true
Expand All @@ -113,7 +110,7 @@ def opening_balance_as_of(for_date = Date.today)

return nil if (datum_balance.nil? && balance_from_postings.nil?)
datum_balance ||= 0.0; balance_from_postings ||= 0.0
return datum_balance + balance_from_postings
return datum_balance.to_f + balance_from_postings.to_f
end

def balance_as_of_now
Expand Down Expand Up @@ -172,7 +169,7 @@ def self.tree(branch_id = nil)
data = {}
Account.all(:order => [:account_type_id.asc], :parent_id => nil).group_by{|account| account.account_type}.each{|account_type, accounts|
accounts.each{|account|
account.branch_edge = (account.branch_id == branch_id)
account.branch_edge = (account.branch_id == branch_id || account.branch_id == nil)
}
# recurse the tree: climb
data[account_type] = climb(accounts, branch_id)
Expand All @@ -184,10 +181,53 @@ def self.tree(branch_id = nil)
data
end

def self.put_tree(accounts)
rv = ""
if accounts
accounts.sort_by{|account_type, accounts| account_type.name}.each do |account_type, as|
if as
puts "------------------------------------ #{account_type.name}------------------------------"
as.each do |account|
rv += show_accounts(account, 0)
end
end
end
end
return rv
end

def self.show_accounts(accounts, depth)
if accounts.is_a?(Array)
return if accounts.length == 0
first_account, rest_accounts = accounts[0], accounts[1..-1]||[]
rv = ((first_account.is_a?(Account) ? output_li(first_account, depth) : show_accounts(first_account, depth)) + rest_accounts.map{|account|
if account.is_a?(Account)
output_li(account, depth)
elsif account.is_a?(Array) and account.length == 1 and account.first.is_a?(Account)
output_li(account.first, depth)
elsif account.is_a?(Array) and account.length > 0
show_accounts(account, depth + 1)
end
}.join)
else
rv = output_li(accounts, depth)
end
return rv
end

def self.output_li(account, depth)
# debugger if account.id == 32
puts "#{account.id} : #{account.name} : #{account.branch_id}"
prefix = (0..(depth*4)).map{|d| "-"}.join
return (account.branch_edge ? "#{prefix}#{account.id} : #{account.name} Branch: #{account.branch.name if account.branch} Parent: #{account.parent_id} #{Account.get(account.parent_id).name if account.parent_id}\n" : "(#{account.branch_id} #{account.name})\n")
end

private
def self.climb(accounts, branch_id)
# mark branch edges
accounts.each{|account| account.branch_edge = (account.branch_id == branch_id)}
accounts.each{|account|
account.branch_edge = (account.branch_id == branch_id || account.branch_id == nil)
}
#make tree
accounts.map{|account|
account.children.length>0 ? [account, climb(account.children, branch_id)] : [account]
Expand Down
5 changes: 4 additions & 1 deletion app/models/accounting_period.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class AccountingPeriod

has n, :account_balances
has n, :accounts, :through => :account_balances


belongs_to :organization
property :organization_id, Integer, :nullable => true

validates_with_method :cannot_overlap
validates_with_method :closing_done_sequentially
validates_with_method :all_account_balances_are_verified_before_closing_accounting_period
Expand Down
8 changes: 7 additions & 1 deletion app/models/branch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ class Branch
include DataMapper::Resource
include Comparable
extend Reporting::BranchReports
include Mostfit::Caching

before :save, :convert_blank_to_nil

Expand All @@ -23,6 +22,13 @@ class Branch
has n, :accounts
has n, :api_accesses

belongs_to :organization, :parent_key => [:org_guid], :child_key => [:parent_org_guid], :required => false

property :parent_org_guid, String, :nullable => true

belongs_to :domain, :parent_key => [:domain_guid], :child_key => [:parent_domain_guid], :required => false
property :parent_domain_guid, String, :nullable => true

validates_is_unique :code
validates_length :code, :min => 1, :max => 10

Expand Down
Loading

0 comments on commit ae9d3d1

Please sign in to comment.