Skip to content

Commit

Permalink
Merge branch '2.10.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekEdwards committed Apr 24, 2020
2 parents 8c0587f + c46f8cc commit c04ed3d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 30 deletions.
37 changes: 23 additions & 14 deletions app/models/book_value_update_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ def get_update
def can_update?
false # set to false so it doesnt show up in the asset detail page action menu and existing events cannot be updated
end

######## API Serializer ##############
def api_json(options={})
super.merge({
book_value: book_value
})
end

protected

Expand All @@ -59,41 +66,43 @@ def set_defaults
end

def create_depreciation_entry
depr_amount = asset.depreciation_entries.where('event_date <= ?',self.event_date).sum(:book_value) - book_value
asset_instance = self.send(Rails.application.config.asset_base_class_name.underscore)

depr_amount = asset_instance.depreciation_entries.where('event_date <= ?',self.event_date).sum(:book_value) - book_value

asset.depreciation_entries.create!(description: "Manual Adjustment: #{self.comments}", book_value: -depr_amount, event_date: self.event_date)
asset.update_columns(current_depreciation_date: self.event_date)
asset_instance.depreciation_entries.create!(description: "Manual Adjustment: #{self.comments}", book_value: -depr_amount, event_date: self.event_date)
asset_instance.update_columns(current_depreciation_date: self.event_date)

gl_mapping = asset.general_ledger_mapping
gl_mapping = asset_instance.general_ledger_mapping
if gl_mapping.present? # check whether this app records GLAs at all
gl_mapping.accumulated_depr_account.general_ledger_account_entries.create!(event_date: event_date, description: "Manual Adjustment - Accumulated Depreciation: #{asset.asset_path}", amount: -depr_amount, asset: asset)
gl_mapping.accumulated_depr_account.general_ledger_account_entries.create!(event_date: event_date, description: "Manual Adjustment - Accumulated Depreciation: #{asset.asset_path}", amount: -depr_amount, asset: asset_instance)

gl_mapping.depr_expense_account.general_ledger_account_entries.create!(event_date: event_date, description: "Manual Adjustment - Deprectiation Expense: #{asset.asset_path}", amount: depr_amount, asset: asset)
gl_mapping.depr_expense_account.general_ledger_account_entries.create!(event_date: event_date, description: "Manual Adjustment - Deprectiation Expense: #{asset.asset_path}", amount: depr_amount, asset: asset_instance)
end

# destroy any manual adjustments past the depr start
asset.depreciation_entries.manual_adjustments.where('event_date > ?',self.event_date).each do |depr_entry|
asset_instance.depreciation_entries.manual_adjustments.where('event_date > ?',self.event_date).each do |depr_entry|
if gl_mapping.present?
gl_mapping.accumulated_depr_account.general_ledger_account_entries.create!(event_date: event_date, description: "REVERSED Manual Adjustment - Accumulated Depreciation: #{asset.asset_path}", amount: -depr_entry.book_value, asset: asset)
gl_mapping.accumulated_depr_account.general_ledger_account_entries.create!(event_date: event_date, description: "REVERSED Manual Adjustment - Accumulated Depreciation: #{asset.asset_path}", amount: -depr_entry.book_value, asset: asset_instance)

gl_mapping.depr_expense_account.general_ledger_account_entries.create!(event_date: event_date, description: "REVERSED Manual Adjustment - Depreciation Expense: #{asset.asset_path}", amount: depr_entry.book_value, asset: asset)
gl_mapping.depr_expense_account.general_ledger_account_entries.create!(event_date: event_date, description: "REVERSED Manual Adjustment - Depreciation Expense: #{asset.asset_path}", amount: depr_entry.book_value, asset: asset_instance)
end

depr_entry.destroy!
end

asset.depreciation_entries.depreciation_expenses.where('event_date > ?',self.event_date).each do |depr_entry|
asset_instance.depreciation_entries.depreciation_expenses.where('event_date > ?',self.event_date).each do |depr_entry|
if gl_mapping.present?
gl_mapping.accumulated_depr_account.general_ledger_account_entries.create!(event_date: event_date, description: "REVERSED Accumulated Depreciation: #{asset.asset_path}", amount: -depr_entry.book_value, asset: asset)
gl_mapping.accumulated_depr_account.general_ledger_account_entries.create!(event_date: event_date, description: "REVERSED Accumulated Depreciation: #{asset.asset_path}", amount: -depr_entry.book_value, asset: asset_instance)

gl_mapping.depr_expense_account.general_ledger_account_entries.create!(event_date: event_date, description: "REVERSED Deprectiation Expense: #{asset.asset_path}", amount: depr_entry.book_value, asset: asset)
gl_mapping.depr_expense_account.general_ledger_account_entries.create!(event_date: event_date, description: "REVERSED Deprectiation Expense: #{asset.asset_path}", amount: depr_entry.book_value, asset: asset_instance)
end

depr_entry.destroy!
end

asset.update_asset_book_value
asset.save(:validate => false)
asset_instance.update_asset_book_value
asset_instance.save(:validate => false)

return true
end
Expand Down
14 changes: 12 additions & 2 deletions app/views/transit_assets/_accounting_funding_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
- funding_pcnt_precision = Rails.application.config.try(:funding_pcnt_decimal_precision) || 2
- if can? :update, asset

- if ['Track', 'PowerSignal', 'Guideway'].include? @asset.class.to_s
%fieldset
%legend{style: 'font-size: medium;'} Funding Programs
%label#funding_sources-error.error
= f.simple_fields_for :funding_source_grant_purchases do |funding_source|
= render 'transit_assets/transit_assets_funding_source_fields', f: funding_source
.links.pull-right
= link_to_add_association f, :funding_source_grant_purchases, partial: 'transit_assets/transit_assets_funding_source_fields', :class => 'asset-subform-action' do
%i.fa.fa-2x.fa-plus-circle
- else
#funding_sources_grant_purchases.asset-subform{style: "width:95%;"}
= simple_form_for(asset.transam_asset,
:as => :asset,
Expand All @@ -12,7 +22,6 @@
:radio_buttons => :vertical_radio_and_checkboxes,
:file => :vertical_file_input,
:boolean => :vertical_boolean}) do |f|

%fieldset
%legend{style: 'font-size: medium;'} Funding Programs
%label#funding_sources-error.error
Expand All @@ -22,6 +31,7 @@
= link_to_add_association f, :funding_source_grant_purchases, partial: 'transit_assets/transit_assets_funding_source_fields', :class => 'asset-subform-action' do
%i.fa.fa-2x.fa-plus-circle


:javascript
$( document ).ready(function() {
$('.funding_sources_grant_purchases_form').validate({
Expand Down
38 changes: 25 additions & 13 deletions app/views/transit_assets/_accounting_purchase_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
:ruby
funding_pcnt_precision = Rails.application.config.try(:funding_pcnt_decimal_precision) || 2
- if can? :update, asset
funding_pcnt_precision = Rails.application.config.try(:funding_pcnt_decimal_precision) || 2#grant_purchase_cost{style: 'display:none;'}= f.object.purchase_cost

- if ['Track', 'PowerSignal', 'Guideway'].include? @asset.class.to_s
#grant_purchase_cost{style: 'display:none;'}= f.object.purchase_cost

%fieldset
%legend{style: 'font-size: medium;'} Grants
%label#grants-error.error
= f.simple_fields_for :grant_grant_purchases do |grant|
= render 'transit_assets/transit_assets_grant_fields', f: grant
.links.pull-right
= link_to_add_association f, :grant_grant_purchases, partial: 'transit_assets/transit_assets_grant_fields', :class => 'asset-subform-action' do
%i.fa.fa-2x.fa-plus-circle
- else
#grants_grant_purchases.asset-subform{style: "width:95%;"}
= simple_form_for(asset.transam_asset,
:as => :asset,
:url => inventory_path(asset.transam_asset),
:method => 'put',
:remote => true,
:html => {:class => 'form-vertical form-section grants_grant_purchases_form'},
:wrapper => :vertical_form,
:wrapper_mappings => {:check_boxes => :vertical_radio_and_checkboxes,
:radio_buttons => :vertical_radio_and_checkboxes,
:file => :vertical_file_input,
:boolean => :vertical_boolean}) do |f|
:as => :asset,
:url => inventory_path(asset.transam_asset),
:method => 'put',
:remote => true,
:html => {:class => 'form-vertical form-section grants_grant_purchases_form'},
:wrapper => :vertical_form,
:wrapper_mappings => {:check_boxes => :vertical_radio_and_checkboxes,
:radio_buttons => :vertical_radio_and_checkboxes,
:file => :vertical_file_input,
:boolean => :vertical_boolean}) do |f|

#grant_purchase_cost{style: 'display:none;'}= asset.purchase_cost
#grant_purchase_cost{style: 'display:none;'}= f.object.purchase_cost

%fieldset
%legend{style: 'font-size: medium;'} Grants
Expand Down
2 changes: 1 addition & 1 deletion lib/transam_accounting/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module TransamAccounting
VERSION = "2.9.1"
VERSION = "2.10.0"
end

0 comments on commit c04ed3d

Please sign in to comment.