diff --git a/app/models/book_value_update_event.rb b/app/models/book_value_update_event.rb index 398107f8..e6791125 100644 --- a/app/models/book_value_update_event.rb +++ b/app/models/book_value_update_event.rb @@ -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 @@ -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 diff --git a/app/views/transit_assets/_accounting_funding_form.html.haml b/app/views/transit_assets/_accounting_funding_form.html.haml index dfe9094e..39902ecf 100644 --- a/app/views/transit_assets/_accounting_funding_form.html.haml +++ b/app/views/transit_assets/_accounting_funding_form.html.haml @@ -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, @@ -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 @@ -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({ diff --git a/app/views/transit_assets/_accounting_purchase_form.html.haml b/app/views/transit_assets/_accounting_purchase_form.html.haml index 827eb091..47d52ed1 100644 --- a/app/views/transit_assets/_accounting_purchase_form.html.haml +++ b/app/views/transit_assets/_accounting_purchase_form.html.haml @@ -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 diff --git a/lib/transam_accounting/version.rb b/lib/transam_accounting/version.rb index f4e4b8ca..42058219 100644 --- a/lib/transam_accounting/version.rb +++ b/lib/transam_accounting/version.rb @@ -1,3 +1,3 @@ module TransamAccounting - VERSION = "2.9.1" + VERSION = "2.10.0" end