diff --git a/.travis.yml b/.travis.yml index 4de66914..87737e93 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: ruby rvm: - 2.5.3 +services: + - mysql branches: only: - master diff --git a/Gemfile b/Gemfile index 97ea577a..b9670892 100644 --- a/Gemfile +++ b/Gemfile @@ -7,9 +7,9 @@ source "https://rubygems.org" # To use debugger # gem 'debugger' -gem 'transam_core', git: 'https://github.com/camsys/transam_core', branch: :quarter1 -gem 'transam_reporting', git: 'https://github.com/camsys/transam_reporting', branch: :quarter1 -gem 'transam_transit', git: 'https://github.com/camsys/transam_transit', branch: :quarter1 +gem 'transam_core', git: 'https://github.com/camsys/transam_core', branch: :quarter2 +gem 'transam_reporting', git: 'https://github.com/camsys/transam_reporting', branch: :quarter2 +gem 'transam_transit', git: 'https://github.com/camsys/transam_transit', branch: :quarter2 gem 'mysql2', '~> 0.5.1' # lock gem for dummy app gem "capybara", '2.6.2' # lock gem for old capybara behavior on hidden element xpath diff --git a/app/models/abilities/authorized_accounting_ability.rb b/app/models/abilities/authorized_accounting_ability.rb index 26f9414a..72530bcf 100644 --- a/app/models/abilities/authorized_accounting_ability.rb +++ b/app/models/abilities/authorized_accounting_ability.rb @@ -11,6 +11,26 @@ def initialize(user, organization_ids=[]) cannot :read, Grant + can :create, Comment do |c| + if c.commentable_type == 'Asset' + user.organization_ids.include? c.commentable.organization.id + elsif c.commentable_type == 'FundingSource' + false + else + true + end + end + + can :create, Document do |d| + if d.documentable_type == 'Asset' + user.organization_ids.include? d.documentable.organization.id + elsif d.documentable_type == 'FundingSource' + false + else + true + end + end + end end diff --git a/app/models/abilities/manager_accounting_ability.rb b/app/models/abilities/manager_accounting_ability.rb index fff72a7e..43bdd817 100644 --- a/app/models/abilities/manager_accounting_ability.rb +++ b/app/models/abilities/manager_accounting_ability.rb @@ -9,6 +9,15 @@ def initialize(user) can :manage, FundingSource end + # BPT user can add comments on any asset + can :create, Comment do |c| + if c.commentable_type == 'FundingSource' + false + else + true + end + end + end end end \ No newline at end of file diff --git a/app/models/funding_source.rb b/app/models/funding_source.rb index 36f88d64..dd059ca1 100644 --- a/app/models/funding_source.rb +++ b/app/models/funding_source.rb @@ -19,6 +19,8 @@ class FundingSource < ActiveRecord::Base #------------------------------------------------------------------------------ after_initialize :set_defaults + default_scope { where(funding_source_type: FundingSourceType.active) } + #------------------------------------------------------------------------------ # Associations #------------------------------------------------------------------------------ @@ -40,7 +42,7 @@ class FundingSource < ActiveRecord::Base has_many :grants, :as => :sourceable, :dependent => :destroy has_many :grant_purchases, :as => :sourceable, :dependent => :destroy - has_many :assets, :through => :grant_purchases, :class_name => Rails.application.config.asset_base_class_name + has_many :assets, through: :grant_purchases, source: Rails.application.config.asset_base_class_name.underscore #------------------------------------------------------------------------------ # Validations diff --git a/app/models/funding_source_type.rb b/app/models/funding_source_type.rb index a8140678..1da9b126 100644 --- a/app/models/funding_source_type.rb +++ b/app/models/funding_source_type.rb @@ -11,6 +11,9 @@ class FundingSourceType < ActiveRecord::Base has_many :funding_sources # All types that are available + + default_scope { active } + scope :active, -> { where(:active => true) } scope :funding_program, -> { where("name != 'Agency'") } scope :contributor, -> { where("name IN ('State', 'Agency')") } diff --git a/app/models/grant.rb b/app/models/grant.rb index cfa962c7..7ef9ab1f 100644 --- a/app/models/grant.rb +++ b/app/models/grant.rb @@ -261,7 +261,7 @@ def global_sourceable=(sourceable) # Calculate the anount of the grant that has been spent on assets to date. This calculates # only the federal percentage def spent - GrantPurchase.where(sourceable: self).to_a.sum{ |gp| gp.send(Rails.application.config.asset_base_class_name.underscore).purchase_cost * gp.pcnt_purchase_cost / 100.0 } + GrantPurchase.where(sourceable: self).sum(:amount) end # Returns the balance of the fund. If the account is overdrawn diff --git a/app/models/grant_purchase.rb b/app/models/grant_purchase.rb index 39308919..29de3016 100644 --- a/app/models/grant_purchase.rb +++ b/app/models/grant_purchase.rb @@ -29,7 +29,7 @@ class GrantPurchase < ActiveRecord::Base #------------------------------------------------------------------------------ #validates_presence_of :sourceable validates_presence_of Rails.application.config.asset_base_class_name.underscore.to_sym - validates :pcnt_purchase_cost, :presence => true, :numericality => {:only_integer => true, :greater_than_or_equal_to => 0, :less_than_or_equal_to => 100} + validates :pcnt_purchase_cost, :presence => true, :numericality => {:greater_than_or_equal_to => 0, :less_than_or_equal_to => 100} #------------------------------------------------------------------------------ # Scopes @@ -46,6 +46,7 @@ class GrantPurchase < ActiveRecord::Base :sourceable_id, :other_sourceable, :pcnt_purchase_cost, + :amount, :expense_tag, :_destroy ] diff --git a/app/reports/asset_funding_source_report.rb b/app/reports/asset_funding_source_report.rb index 66abeaad..e2f9ebc8 100644 --- a/app/reports/asset_funding_source_report.rb +++ b/app/reports/asset_funding_source_report.rb @@ -8,7 +8,7 @@ class AssetFundingSourceReport < AbstractReport DETAIL_FORMATS = [:string, :string, :string, :string, :string, :currency] def self.get_detail_data(organization_id_list, params) - query = TransitAsset.unscoped.joins([{transam_asset: [:organization, :asset_subtype]}, :fta_asset_category, :fta_asset_class]) + query = TransitAsset.unscoped.operational.joins([{transam_asset: [:organization, :asset_subtype]}, :fta_asset_category, :fta_asset_class]) .joins('LEFT JOIN fta_vehicle_types ON transit_assets.fta_type_id = fta_vehicle_types.id AND transit_assets.fta_type_type="FtaVehicleType"') .joins('LEFT JOIN fta_equipment_types ON transit_assets.fta_type_id = fta_equipment_types.id AND transit_assets.fta_type_type="FtaEquipmentType"') .joins('LEFT JOIN fta_support_vehicle_types ON transit_assets.fta_type_id = fta_support_vehicle_types.id AND transit_assets.fta_type_type="FtaSupportVehicleType"') @@ -78,8 +78,7 @@ def get_data(organization_id_list, params) labels = [] formats = [] - # Default scope orders by project_id - query = TransamAsset.unscoped.joins(:organization) + query = TransamAsset.unscoped.operational.joins(:organization) .joins('LEFT JOIN grant_purchases ON grant_purchases.transam_asset_id = transam_assets.id AND grant_purchases.sourceable_type="FundingSource"') .joins('LEFT JOIN funding_sources ON grant_purchases.sourceable_id = funding_sources.id') .where(organization_id: organization_id_list) diff --git a/app/views/asset_events/_rehabilitation_update_event_form.html.haml b/app/views/asset_events/_rehabilitation_update_event_form.html.haml index 69c35a4b..52343e51 100644 --- a/app/views/asset_events/_rehabilitation_update_event_form.html.haml +++ b/app/views/asset_events/_rehabilitation_update_event_form.html.haml @@ -1,12 +1,38 @@ +-# This overwrites _rehabilitation_update_event_form in transam_transit and transam_core engine + :ruby - if @asset_event.asset_event_asset_subsystems.empty? - AssetSubsystem.for_type(@asset.asset_type).each do |ss| - @asset_event.asset_event_asset_subsystems.build(asset_subsystem: ss) - end + vehicle_rebuild_types = VehicleRebuildType.active + if ['RevenueVehicle', 'ServiceVehicle'].include?(@asset.fta_asset_class&.class_name) + include_ulm = true + else + vehicle_rebuild_types = VehicleRebuildType.none end = render :layout => "update_event_form" do |f| - = f.input :event_date, :label => 'Date of Report', :wrapper => :vertical_append do + .row + .col-sm-6 + = f.association :vehicle_rebuild_type, :collection => vehicle_rebuild_types, :label => 'Rebuild / Rehab Type', :include_blank => 'Other' + .col-sm-6.other_vehicle_rebuild_type_container + = f.input :other_vehicle_rebuild_type, label: 'Rebuild / Rehab Type (Other)', required: true + = f.input :total_cost, :wrapper => :vertical_prepend, label: 'Cost of Rebuild / Rehabilitation' do + %span.input-group-addon + %i.fa.fa-usd + = f.input_field :total_cost, :class => 'form-control', :required => true, :value => 0, :min => 0, :label => false + %span.input-group-addon + %a.transam-popover{data: {placement: 'auto', toggle: 'popover', html: 'true', content: "This will increase the Cost (Adjusted) of the asset by the amount entered."}, title: 'Cost of Rebuild / Rehabilitation', tabindex: '0'} + %i.fa.fa-info-circle + = f.input :extended_useful_life_months, :wrapper => :vertical_prepend, label: 'Extend Useful Life by (months)' do + = f.input_field :extended_useful_life_months, :class => 'form-control', :required => false, :value => 0, :min => 0, :label => false + %span.input-group-addon + %a.transam-popover{data: {placement: 'auto', toggle: 'popover', html: 'true', content: "- Estimated Service Life (ESL) will be extended by the number of months entered here."}, title: 'Extend Useful Life by (months)', tabindex: '0'} + %i.fa.fa-info-circle + - if include_ulm + = f.input :extended_useful_life_miles, :wrapper => :vertical_prepend, label: 'Extend Useful Life by (miles)' do + = f.input_field :extended_useful_life_miles, :class => 'form-control', :required => false, :value => 0, :min => 0, :label => false + %span.input-group-addon + %a.transam-popover{data: {placement: 'auto', toggle: 'popover', html: 'true', content: "Estimated Service Life (ESL) will be extended by the number of miles entered here."}, title: 'Extend Useful Life by (miles)', tabindex: '0'} + %i.fa.fa-info-circle + = f.input :event_date, :label => 'Date of Rebuild / Rehabilitation', :wrapper => :vertical_append do = f.input_field :event_date, :as => :string, :class => 'form-control datepicker', :data => {'date-container' => "##{format_as_id(@asset_event.asset_event_type.name)}_dialog", 'date-start-date' => "#{format_as_date(start_of_fiscal_year(Organization.get_typed_organization(@asset.organization).first_archivable_fiscal_year))}", @@ -14,46 +40,16 @@ :value => format_as_date(f.object.event_date) %span.input-group-addon %i.fa.fa-calendar - - if AssetSubsystem.active.count > 0 - .row - .col-sm-4.col-sm-offset-8.text-center - .col-sm-6 - .control-label Parts - .col-sm-6 - .control-label Labor - = f.simple_fields_for :asset_event_asset_subsystems do |s| - = s.input :asset_subsystem_id, :as => :hidden - .form-group#costs - %label.control-label.col-sm-8.text-right - = s.object.asset_subsystem - .col-sm-4 - .col-sm-6.form-group - = s.input :parts_cost, :wrapper => :vertical_prepend, :label => false do - %span.input-group-addon - %i.fa.fa-usd - = s.input_field :parts_cost, :class => 'form-control', :label => false - .col-sm-6.form-group - = s.input :labor_cost, :wrapper => :vertical_prepend, label: false do - %span.input-group-addon - %i.fa.fa-usd - = s.input_field :labor_cost, :class => 'form-control', :label => false - .form-group.col-sm-4.col-sm-offset-8 - %label Total Cost - .input-group - %span.input-group-addon - %i.fa.fa-usd - %input#total.form-control{type: "number", disabled: true, val: 0} - - else - = f.input :total_cost, :wrapper => :vertical_prepend, label: 'Total Cost' do - %span.input-group-addon - %i.fa.fa-usd - = f.input_field :total_cost, :class => 'form-control', :required => true, :value => 0, :label => false - = f.input :extended_useful_life_months - = f.input :extended_useful_life_miles if @asset.class.to_s.include? 'Vehicle' - = f.input :comments, :required => true, :input_html => { :rows => 6 }, :placeholder => "Describe work performed...", label: "Notes" + - SystemConfig.transam_module_names.each do |mod| + - view_component = "#{mod}_rehabilitation_update_event_form" + - if lookup_context.template_exists?(view_component, 'asset_events', true) + = render :partial => "asset_events/#{view_component}", :locals => {:f => f} + + = f.input :comments, :required => true, :input_html => { :rows => 6 }, :placeholder => "Describe work performed..." + .form-group - = f.button :submit, "Add Rehabilitation", :class => 'btn btn-primary' + = f.button :submit, "Save", :class => 'btn btn-primary' :javascript @@ -69,33 +65,48 @@ $("#total").val(total_rehab_costs); }); - }); - $('#asset_event_event_date').change(function() { - $.ajax({ - url: '#{get_depreciation_months_left_inventory_path(@asset)}', - data: { - on_date: function() { - return $('#asset_event_event_date').val(); - } - }, - success: function(result){ - if (parseInt(result) == 0) { - $('#asset_event_extended_useful_life_months').rules("add", { - min: 1 - }); - } else { - $('#asset_event_extended_useful_life_months').rules("add", { - min: 0 - }); - } - }, - error: function (xhr, ajaxOptions, thrownError) { - alert("We are sorry but something went wrong. " + xhr.status + " " + thrownError); + function show_hide_other_vehicle_rebuild_type(vehicle_rebuild_type_id) { + if(vehicle_rebuild_type_id) { + $('.other_vehicle_rebuild_type_container').hide(); + $('#asset_event_other_vehicle_rebuild_type').removeAttr('required'); + $('#asset_event_other_vehicle_rebuild_type').val(''); + } else { + $('.other_vehicle_rebuild_type_container').show(); + $('#asset_event_other_vehicle_rebuild_type').attr('required', 'required'); } - }); - }); + } + show_hide_other_vehicle_rebuild_type(#{@asset_event.vehicle_rebuild_type_id || ''}); + + $('#asset_event_vehicle_rebuild_type_id').change(function() { + show_hide_other_vehicle_rebuild_type($(this).val()); + }); + $('#asset_event_event_date').change(function() { + $.ajax({ + url: '#{get_depreciation_months_left_inventory_path(@asset)}', + data: { + on_date: function() { + return $('#asset_event_event_date').val(); + } + }, + success: function(result){ + if (parseInt(result) == 0) { + $('#asset_event_extended_useful_life_months').rules("add", { + min: 1 + }); + } else { + $('#asset_event_extended_useful_life_months').rules("add", { + min: 0 + }); + } + }, + error: function (xhr, ajaxOptions, thrownError) { + alert("We are sorry but something went wrong. " + xhr.status + " " + thrownError); + } + }); + }); + }); diff --git a/app/views/assets/_depreciation_form.html.haml b/app/views/assets/_depreciation_form.html.haml index 4331b5b4..b7e5cdea 100644 --- a/app/views/assets/_depreciation_form.html.haml +++ b/app/views/assets/_depreciation_form.html.haml @@ -28,7 +28,7 @@ %i.fa.fa-calendar .col-xs-4 - = f.input :depreciation_purchase_cost, :wrapper=> :vertical_prepend, :label => "Depreciation Purchase Cost" do + = f.input :depreciation_purchase_cost, :wrapper=> :vertical_prepend, :label => "Depreciation Cost (Purchase)" do %span.input-group-addon %i.fa.fa-usd = f.input_field :depreciation_purchase_cost, :class => "form-control", :disabled => @asset.depreciation_purchase_cost != @asset.book_value diff --git a/app/views/assets/_depreciation_table.html.haml b/app/views/assets/_depreciation_table.html.haml index 4219077e..875c3623 100644 --- a/app/views/assets/_depreciation_table.html.haml +++ b/app/views/assets/_depreciation_table.html.haml @@ -1 +1 @@ -.col-xs-4 = format_field("Purchase Date", format_as_date(@asset.purchase_date) ) = format_field("In Service Date", format_as_date(@asset.in_service_date) ) = format_field("Depreciation Start Date", format_as_date(@asset.depreciation_start_date) ) = format_field("Current Depreciation Date", format_as_date(@asset.current_depreciation_date) ) .col-xs-4 = format_field("Original Useful Life", "#{format_as_integer(@asset.original_depreciation_useful_life_months)} months" ) = format_field("Adjusted Useful Life", "#{format_as_integer(@asset.adjusted_depreciation_useful_life_months)} months" ) = format_field("Original Cost Basis", format_as_currency(@asset.original_cost_basis) ) = format_field("Adjusted Cost Basis", format_as_currency(@asset.adjusted_cost_basis) ) .col-xs-4 = format_field("Salvage Value", format_as_currency(@asset.salvage_value) ) = format_field("Policy Replacement Cost", format_as_currency(@asset.estimated_replacement_cost) ) #depreciation_table_actions.btn-group -#- if can? :update, @asset -# = link_to new_inventory_asset_event_path(@asset, :event_type => BookValueUpdateEvent.asset_event_type.id), :class => 'btn btn-default' do -# %i.fa.fa-fw{:class => BookValueUpdateEvent.asset_event_type.display_icon_name} -# = 'Adjust Book Value' -# -# - if can? :create, Expenditure -# = link_to new_inventory_expenditure_path(@asset), :class => 'btn btn-default' do -# %i.fa.fa-plus.fa-fw -# = " Add CapEx" .col-xs-12 %fieldset %table.table.table-hover#depreciation_table{:data => {:toggle => 'table', :pagination => 'true', :show_pagination_switch => 'true', :page_list => "[5, 10, 20, 50, 100, 200]", :page_size => current_user.num_table_rows, :search => 'false', :toolbar => "#depreciation_table_actions", :export_types => "['csv', 'txt', 'excel']", :show_export => 'true', :show_toggle => 'false', :cookie => 'true', :cookie_id_table => "asset_depreciation_id", :cookie_expire => "1y"}} %thead %tr %th.left Date %th.left Description - if ChartOfAccount.find_by(organization_id: @asset.organization_id) %th.left GL Account %th.right Amount %th.right Net Book Value %tbody - @asset.get_depreciation_table.each do |row| %tr %td.left= format_as_date(row[:on_date]) %td.left= row[:description] - if ChartOfAccount.find_by(organization_id: @asset.organization_id) %td.left= link_to row[:general_ledger_account].account_number, general_ledger_account_path(row[:general_ledger_account]) unless row[:general_ledger_account].blank? %td.right= format_as_currency(row[:amount].to_i) %td.right= format_as_currency(row[:book_value].to_i) :javascript $("#depreciation_table").on('all.bs.table', function(evt, name, args) { $('.fixed-table-container').css('min-height', '300px') transam.make_same_height('.header-part'); }); $(window).load(function() { transam.make_same_height('.header-part'); }); $(window).resize(function() { $("#depreciation_table").bootstrapTable('resetView'); }); \ No newline at end of file +.col-xs-4 = format_field("Purchase Date", format_as_date(@asset.purchase_date) ) = format_field("In Service Date", format_as_date(@asset.in_service_date) ) = format_field("Depreciation Start Date", format_as_date(@asset.depreciation_start_date) ) = format_field("Current Depreciation Date", format_as_date(@asset.current_depreciation_date) ) .col-xs-4 = format_field("Original Useful Life", "#{format_as_integer(@asset.original_depreciation_useful_life_months)} months" ) = format_field("Adjusted Useful Life", "#{format_as_integer(@asset.adjusted_depreciation_useful_life_months)} months" ) = format_field("Original Cost Basis", format_as_currency(@asset.original_cost_basis) ) = format_field("Adjusted Cost Basis", format_as_currency(@asset.adjusted_cost_basis) ) .col-xs-4 = format_field("Salvage Value", format_as_currency(@asset.salvage_value) ) = format_field("Policy Replacement Cost", format_as_currency(@asset.estimated_replacement_cost) ) #depreciation_table_actions.btn-group -#- if can? :update, @asset -# = link_to new_inventory_asset_event_path(@asset, :event_type => BookValueUpdateEvent.asset_event_type.id), :class => 'btn btn-default' do -# %i.fa.fa-fw{:class => BookValueUpdateEvent.asset_event_type.display_icon_name} -# = 'Adjust Book Value' -# -# - if can? :create, Expenditure -# = link_to new_inventory_expenditure_path(@asset), :class => 'btn btn-default' do -# %i.fa.fa-plus.fa-fw -# = " Add CapEx" .col-xs-12 %fieldset %table.table.table-hover#depreciation_table{:data => {:toggle => 'table', :pagination => 'true', :show_pagination_switch => 'false', :page_list => "5, 10, 20, 50, 100, 200, 10000]", :page_size => current_user.num_table_rows, :search => 'false', :toolbar => "#depreciation_table_actions", :export_types => "['csv', 'txt', 'excel']", :show_export => 'true', :show_toggle => 'false', :cookie => 'true', :cookie_id_table => "asset_depreciation_id", :cookie_expire => "1y"}} %thead %tr %th.left Date %th.left Description - if ChartOfAccount.find_by(organization_id: @asset.organization_id) %th.left GL Account %th.right Amount %th.right Net Book Value %tbody - @asset.get_depreciation_table.each do |row| %tr %td.left= format_as_date(row[:on_date]) %td.left= row[:description] - if ChartOfAccount.find_by(organization_id: @asset.organization_id) %td.left= link_to row[:general_ledger_account].account_number, general_ledger_account_path(row[:general_ledger_account]) unless row[:general_ledger_account].blank? %td.right= format_as_currency(row[:amount].to_i) %td.right= format_as_currency(row[:book_value].to_i) :javascript $("#depreciation_table").on('all.bs.table', function(evt, name, args) { $('.fixed-table-container').css('min-height', '300px') transam.make_same_height('.header-part'); }); $(window).load(function() { transam.make_same_height('.header-part'); }); $(window).resize(function() { $("#depreciation_table").bootstrapTable('resetView'); }); \ No newline at end of file diff --git a/app/views/assets/_funding_source_fields.html.haml b/app/views/assets/_funding_source_fields.html.haml index 10168615..720d48b7 100644 --- a/app/views/assets/_funding_source_fields.html.haml +++ b/app/views/assets/_funding_source_fields.html.haml @@ -1,3 +1,4 @@ +- #: This is superceded by transit_assets/transit_assets_funding_source_fields .nested-fields{style: 'border:none;'} .row .col-md-5 diff --git a/app/views/assets/_grant_fields.html.haml b/app/views/assets/_grant_fields.html.haml index b4affce4..815794bf 100644 --- a/app/views/assets/_grant_fields.html.haml +++ b/app/views/assets/_grant_fields.html.haml @@ -1,3 +1,4 @@ +- #: This is superceded by transit_assets/transit_assets_grant_fields - disabled = f.object.sourceable && !f.object.sourceable.open? .nested-fields{style: 'border:none;'} diff --git a/app/views/expenditures/_index_table.html.haml b/app/views/expenditures/_index_table.html.haml index b39643f0..9d734ce2 100755 --- a/app/views/expenditures/_index_table.html.haml +++ b/app/views/expenditures/_index_table.html.haml @@ -3,8 +3,8 @@ %table.table.table-hover{:id => table_dom_id, :data => {:toggle => 'table', :pagination => 'true', - :show_pagination_switch => 'true', - :page_list => "[5, 10, 20, 50, 100, 200]", + :show_pagination_switch => 'false', + :page_list => "5, 10, 20, 50, 100, 200, 10000]", :page_size => current_user.num_table_rows, :search => 'false', :export_types => "['csv', 'txt', 'excel']", diff --git a/app/views/funding_sources/_details.html.haml b/app/views/funding_sources/_details.html.haml index 4126eb55..936e143b 100644 --- a/app/views/funding_sources/_details.html.haml +++ b/app/views/funding_sources/_details.html.haml @@ -21,9 +21,9 @@ .tab-pane.fade#asst .tab-content - if @funding_source.assets.empty? - %p There are no assets associated with this grant. + %p There are no assets associated with this program. - else - = render :partial => 'assets/asset_compact_datatable', :locals => {:assets => @funding_source.assets} + = render :partial => 'assets/asset_compact_datatable', :locals => {:assets => @funding_source.assets.distinct} .tab-pane.fade#docs .tab-content diff --git a/app/views/funding_sources/_index_table.html.haml b/app/views/funding_sources/_index_table.html.haml index 6bb80fe1..ce74b093 100755 --- a/app/views/funding_sources/_index_table.html.haml +++ b/app/views/funding_sources/_index_table.html.haml @@ -9,8 +9,8 @@ .table-responsive %table.table.table-hover{:id => table_dom_id, :data => {:toggle => 'table', :pagination => 'true', - :show_pagination_switch => 'true', - :page_list => "[5, 10, 20, 50, 100, 200]", + :show_pagination_switch => 'false', + :page_list => "5, 10, 20, 50, 100, 200, 10000]", :page_size => current_user.num_table_rows, :search => 'false', :toolbar => "#programs_table_actions", diff --git a/app/views/general_ledger_accounts/_gla_entries.html.haml b/app/views/general_ledger_accounts/_gla_entries.html.haml index fc334799..93c06e44 100644 --- a/app/views/general_ledger_accounts/_gla_entries.html.haml +++ b/app/views/general_ledger_accounts/_gla_entries.html.haml @@ -3,8 +3,8 @@ -else %table.table.table-hover#gla_datatable{:data => {:toggle => 'table', :pagination => 'true', - :show_pagination_switch => 'true', - :page_list => "[5, 10, 20, 50, 100, 200]", + :show_pagination_switch => 'false', + :page_list => "5, 10, 20, 50, 100, 200, 10000]", :page_size => current_user.num_table_rows, :search => 'false', :export_types => "['csv', 'txt', 'excel']", diff --git a/app/views/general_ledger_accounts/_index_table.html.haml b/app/views/general_ledger_accounts/_index_table.html.haml index 82ce6870..a293b840 100644 --- a/app/views/general_ledger_accounts/_index_table.html.haml +++ b/app/views/general_ledger_accounts/_index_table.html.haml @@ -9,9 +9,9 @@ %table.table.table-hover{:id => table_dom_id, :data => {:toggle => 'table', :card_view => "false", :pagination => 'true', - :page_list => "[5, 10, 20, 50, 100, 200]", + :page_list => "5, 10, 20, 50, 100, 200, 10000]", :page_size => current_user.num_table_rows, - :show_pagination_switch => 'true', + :show_pagination_switch => 'false', :search => 'false', :show_columns => 'true', :show_export => 'true', diff --git a/app/views/general_ledger_mappings/_index_table.html.haml b/app/views/general_ledger_mappings/_index_table.html.haml index 660d4ea7..8dc7b5fe 100755 --- a/app/views/general_ledger_mappings/_index_table.html.haml +++ b/app/views/general_ledger_mappings/_index_table.html.haml @@ -11,8 +11,8 @@ %table.table.table-hover{:id => table_dom_id, :data => {:toggle => 'table', :card_view => "false", :pagination => 'true', - :show_pagination_switch => 'true', - :page_list => "[5, 10, 20, 50, 100, 200]", + :show_pagination_switch => 'false', + :page_list => "5, 10, 20, 50, 100, 200, 10000]", :page_size => current_user.num_table_rows, :search => 'false', :toolbar => "#bond_requests_table_actions", diff --git a/app/views/grants/_grant_amendments.html.haml b/app/views/grants/_grant_amendments.html.haml index 3226561b..d4006f12 100644 --- a/app/views/grants/_grant_amendments.html.haml +++ b/app/views/grants/_grant_amendments.html.haml @@ -21,7 +21,7 @@ :side_pagination => 'server', :show_pagination_switch => 'false', :page_number => '1', - :page_list => "[5, 10, 20, 50, 100, 200]", + :page_list => "5, 10, 20, 50, 100, 200, 10000]", :page_size => current_user.num_table_rows, :search => 'false', :show_columns => 'true', diff --git a/app/views/grants/_grant_assets.html.haml b/app/views/grants/_grant_assets.html.haml index fed9c49d..0021a32f 100644 --- a/app/views/grants/_grant_assets.html.haml +++ b/app/views/grants/_grant_assets.html.haml @@ -45,8 +45,8 @@ %th.right{:data => {:sortable => 'true', :order => 'desc', :visible => 'false'}} Scheduled Replacement Cost %tbody - - assets.each do |a| - - a = TransamAsset.get_typed_asset(a) + - grant_purchases.each do |gp| + - a = TransamAsset.get_typed_asset(gp.transam_asset) %tr %td.left= link_to a.asset_tag, inventory_path(a) %td.left= a.external_id @@ -57,7 +57,7 @@ %td.left= a.fta_type_type.classify.constantize.find_by(id: a.fta_type_id).name %td.left= a.asset_subtype %td.right= format_as_currency(a.purchase_cost) - %td.right= format_as_currency(a.purchase_cost * 0.01 * GrantPurchase.find_by(transam_asset_id: a.transam_assetible_id, sourceable_type: "Grant", sourceable_id: grant_id).pcnt_purchase_cost) + %td.right= format_as_currency(a.purchase_cost * 0.01 * gp.pcnt_purchase_cost) %td.left= format_as_decimal(a.reported_condition_rating, 2) %td.left= a.service_status_type.name unless a.service_status_type.nil? %td.left= format_as_date(a.in_service_date) diff --git a/app/views/grants/_history.html.haml b/app/views/grants/_history.html.haml deleted file mode 100644 index c0e2248d..00000000 --- a/app/views/grants/_history.html.haml +++ /dev/null @@ -1,44 +0,0 @@ -:ruby - table_dom_id = SecureRandom.hex - -.table-responsive - %table.table.table-hover{:id => table_dom_id, - :data => {:toggle => 'table', - :card_view => "false", - :pagination => 'true', - :sort_order => 'asc', - :sortable => 'true', - :side_pagination => 'server', - :show_pagination_switch => 'true', - :page_number => '1', - :page_list => "[5, 10, 20, 50, 100, 200]", - :page_size => current_user.num_table_rows, - :search => 'false', - :show_columns => 'true', - :toolbar => "#table_actions", - :row_style => 'row_style', - :click_to_select => 'true', - :show_export => 'true', - :id_field => 'object_key', - :export_types => "['csv', 'txt', 'excel']", - :cookie => 'true', - :cookie_id_table => "grant_history_id", - :cookie_expire => "1y", - :maintain_selected => 'true', - :single_select => 'false'}} - %thead - %tr - %th.center{:data => {:sortable => 'true'}} Event - %th.center{:data => {:sortable => 'true'}} Event Type - %th.center{:data => {:sortable => 'true'}} Comments - %th.center{:data => {:sortable => 'true'}} Event By - %th.center{:data => {:sortable => 'true'}} Date & Time - - %tbody - - @grant.history.each do |evt| - %tr - %td.left= evt[:event] - %td.left= evt[:event_type] - %td.left= evt[:comments] - %td.left= evt[:user] - %td.left= format_as_date_time(evt[:datetime]) \ No newline at end of file diff --git a/app/views/grants/show.html.haml b/app/views/grants/show.html.haml index a103289c..59d8eca4 100755 --- a/app/views/grants/show.html.haml +++ b/app/views/grants/show.html.haml @@ -56,7 +56,7 @@ - if @grant.assets.empty? %p There are no assets associated with this grant. - else - = render :partial => 'grant_assets', :locals => {:assets => @grant.assets, :grant_id => @grant.id} + = render :partial => 'grant_assets', :locals => {:grant_purchases => @grant.grant_purchases} .tab-pane.fade#amendments %legend Amendments .tab-content @@ -64,6 +64,6 @@ .tab-pane.fade#hist %legend History .tab-content - = render 'history' + = render partial: 'shared/papertrail_history', locals: {history: @grant.history} = render 'scripts' diff --git a/app/views/searches/_general_ledger_account_search_results_table.html.haml b/app/views/searches/_general_ledger_account_search_results_table.html.haml index 24ec68a6..d1a0714e 100644 --- a/app/views/searches/_general_ledger_account_search_results_table.html.haml +++ b/app/views/searches/_general_ledger_account_search_results_table.html.haml @@ -7,9 +7,9 @@ :sort_order => 'asc', :sortable => 'true', :side_pagination => 'server', - :show_pagination_switch => 'true', + :show_pagination_switch => 'false', :page_number => '1', - :page_list => "[5, 10, 20, 50, 100, 200]", + :page_list => "5, 10, 20, 50, 100, 200, 10000]", :page_size => current_user.num_table_rows, :search => 'false', :show_columns => 'true', diff --git a/app/views/shared/_financial_nav.html.haml b/app/views/shared/_financial_nav.html.haml index c41286ab..db6bdf79 100644 --- a/app/views/shared/_financial_nav.html.haml +++ b/app/views/shared/_financial_nav.html.haml @@ -67,7 +67,8 @@ %i.fa.fa-fw.fa-book = program - if can? :create, FundingSource - %li.divider + - if FundingSource.all.count > 0 + %li.divider %li = link_to new_funding_source_path do %i.fa.fa-plus.fa-fw diff --git a/app/views/transit_assets/_accounting_funding_form.html.haml b/app/views/transit_assets/_accounting_funding_form.html.haml index e6b86abc..a54f2963 100644 --- a/app/views/transit_assets/_accounting_funding_form.html.haml +++ b/app/views/transit_assets/_accounting_funding_form.html.haml @@ -1,5 +1,6 @@ +- funding_pcnt_precision = Rails.application.config.try(:funding_pcnt_decimal_precision) || 2 - if can? :update, asset - #funding_sources_grant_purchases.well.well-sm{style: "overflow-y:scroll; max-height:250px; width:95%;"} + #funding_sources_grant_purchases.asset-subform{style: "width:95%;"} = simple_form_for(asset.transam_asset, :as => :asset, :url => inventory_path(asset.transam_asset), @@ -13,48 +14,57 @@ :boolean => :vertical_boolean}) do |f| %fieldset - %legend Funding Programs + %legend{style: 'font-size: medium;'} Funding Programs %label#funding_sources-error.error = f.simple_fields_for :funding_source_grant_purchases do |funding_source| - = render 'assets/funding_source_fields', f: 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: 'assets/funding_source_fields', :class => 'btn btn-xs btn-info' do - %i.fa.fa-plus - - = f.button :submit, 'Save', :class => 'btn btn-primary' + = 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({ + ignore: [], submitHandler: function(form) { $('.funding_sources_grant_purchases_form input').prop('disabled', false); // re-enable any disabled fields so they'll submit form.trigger('submit.rails'); // submits form both as HTML or JS as defined in form data-remote } }); - if ($('.funding_sources_grant_purchases_form input.funding-pcnt').length > 0) { - $('.funding_sources_grant_purchases_form input.funding-pcnt').rules( "add", { - pcntSumsHundred_funding_sources: true + + if($('.funding_sources_grant_purchases_form input.purchase_cost_amount').length > 0) { + $('.funding_sources_grant_purchases_form input.purchase_cost_amount').rules( "add", { + pcntSumHundred_funding_sources: true }); } - }); - $('body').on('change', '.funding_sources_grant_purchases_form .funding-pcnt', function() { - $('.funding_sources_grant_purchases_form input.funding-pcnt').rules( "add", { - pcntSumsHundred_funding_sources: true + $('body').on('change', '.funding_sources_grant_purchases_form .purchase_cost_amount', function() { + $('.funding_sources_grant_purchases_form input.purchase_cost_amount').rules( "add", { + pcntSumHundred_funding_sources: true }); $('.funding_sources_grant_purchases_form .funding-pcnt').valid(); - var amount = parseInt($(this).val())*parseInt($('#purchase_cost').editable('getValue')['asset[purchase_cost]'])/100; - var currency_val = parseFloat(amount).toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2}); - $(this).closest('.pcnt-column').next().find('.grant-purchase-amount.display-value').html('$ ' + currency_val); + var pcnt = $(this).val() * 100 / parseInt($('#purchase_cost').editable('getValue')['asset[purchase_cost]']); + + $(this).parents('.funding-source-fields').find('.funding-pcnt').val(pcnt); + $(this).parents('.funding-source-fields').find('.grant-purchase-pcnt.display-value').html(pcnt.toFixed(#{funding_pcnt_precision}) + " %"); }); - $.validator.addMethod("pcntSumsHundred_funding_sources", function(value, element) { + $.validator.addMethod("pcntSumHundred_funding_sources", function(value, element) { + // TDC is counted separately as they're "credits" var sum = 0; + var tdc_sum = 0; + var tdc_funding_programs = JSON.parse('#{FundingSource.where(funding_source_type: FundingSourceType.find_by(name: 'TDC')).map{|f| f.to_global_id.to_s}.to_json.html_safe}') $('.funding_sources_grant_purchases_form .funding-pcnt').each(function() { + var program = $(this).parents('.funding-source-fields').find('.funding-source-global-sourceable').val(); + + if ($.inArray(program, tdc_funding_programs) >= 0){ + tdc_sum += Number($(this).val()); + } else { sum += Number($(this).val()); + } }); - return sum <= 100; - }, "Entries do not sum to 100%."); + return (sum <= 100) && (tdc_sum <= 100); + }, "% Funding do not sum to 100%."); diff --git a/app/views/transit_assets/_accounting_purchase_form.html.haml b/app/views/transit_assets/_accounting_purchase_form.html.haml index cc7f945c..3b772abe 100644 --- a/app/views/transit_assets/_accounting_purchase_form.html.haml +++ b/app/views/transit_assets/_accounting_purchase_form.html.haml @@ -1,5 +1,7 @@ +:ruby + funding_pcnt_precision = Rails.application.config.try(:funding_pcnt_decimal_precision) || 2 - if can? :update, asset - #grants_grant_purchases.well.well-sm{style: "overflow-y:scroll; max-height:250px; width:95%;"} + #grants_grant_purchases.asset-subform{style: "width:95%;"} = simple_form_for(asset.transam_asset, :as => :asset, :url => inventory_path(asset.transam_asset), @@ -13,54 +15,70 @@ :boolean => :vertical_boolean}) do |f| %fieldset - %legend Grants + %legend{style: 'font-size: medium;'} Grants %label#grants-error.error = f.simple_fields_for :grant_grant_purchases do |grant| - = render 'assets/grant_fields', f: grant + = render 'transit_assets/transit_assets_grant_fields', f: grant .links.pull-right - = link_to_add_association f, :grant_grant_purchases, partial: 'assets/grant_fields', :class => 'btn btn-xs btn-info' do - %i.fa.fa-plus - - = f.button :submit, 'Save', :class => 'btn btn-primary' + = 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 :javascript $( document ).ready(function() { $('.grants_grant_purchases_form').validate({ + ignore: [], submitHandler: function(form) { $('.grants_grant_purchases_form input').prop('disabled', false); // re-enable any disabled fields so they'll submit form.trigger('submit.rails'); // submits form both as HTML or JS as defined in form data-remote } }); - if ($('.grants_grant_purchases_form input.funding-pcnt').length > 0) { - $('.grants_grant_purchases_form input.funding-pcnt').rules( "add", { + + if($('.grants_grant_purchases_form input.purchase_cost_amount').length > 0) { + $('.grants_grant_purchases_form input.purchase_cost_amount').rules( "add", { pcntSumsHundred_grants: true }); } - }); - $('body').on('change', '.global-sourceable', function() { - id = $(this).attr('id'); + $('.grants_grant_purchases_form').on('change', '.global-sourceable', function() { + var id = $(this).attr('id'); - $('#' + id.substring(0, id.length-'global_sourceable'.length) + 'other_sourceable').prop('disabled', $(this).val() != ''); + var other_grant_num_field = $('#' + id.substring(0, id.length-'global_sourceable'.length) + 'other_sourceable'); + if($(this).val() != '') { + other_grant_num_field.prop('disabled', true); + other_grant_num_field.val(''); + } else { + other_grant_num_field.prop('disabled', false); + } }); - $('body').on('change', '.grants_grant_purchases_form .funding-pcnt', function() { - $('.grants_grant_purchases_form input.funding-pcnt').rules( "add", { + $('body').on('change', '.grants_grant_purchases_form .purchase_cost_amount', function() { + $('.grants_grant_purchases_form input.purchase_cost_amount').rules( "add", { pcntSumsHundred_grants: true }); $('.grants_grant_purchases_form .funding-pcnt').valid(); - var amount = parseInt($(this).val())*parseInt($('#purchase_cost').editable('getValue')['asset[purchase_cost]'])/100; - var currency_val = parseFloat(amount).toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2}); - $(this).closest('.pcnt-column').next().find('.grant-purchase-amount.display-value').html('$ ' + currency_val); + var pcnt = $(this).val() * 100 / parseInt($('#purchase_cost').editable('getValue')['asset[purchase_cost]']); + + $(this).parents('.grant-fields').find('.funding-pcnt').val(pcnt); + $(this).parents('.grant-fields').find('.grant-purchase-pcnt.display-value').html(pcnt.toFixed(#{funding_pcnt_precision}) + " %"); }); $.validator.addMethod("pcntSumsHundred_grants", function(value, element) { - var sum = 0; + // TDC is counted separately as they're "credits" + var sum = 0; + var tdc_sum = 0; + var tdc_grants = JSON.parse('#{Grant.where(sourceable: FundingSource.where(funding_source_type: FundingSourceType.find_by(name: 'TDC'))).map{|f| f.to_global_id.to_s}.to_json.html_safe}') $('.grants_grant_purchases_form .funding-pcnt').each(function() { + var program = $(this).parents('.grant-fields').find('.global-sourceable').val(); + if ($.inArray(program, tdc_grants) >= 0){ + tdc_sum += Number($(this).val()); + } else { sum += Number($(this).val()); + } }); - return sum <= 100; - }, "Entries do not sum to 100%."); + return (sum <= 100) && (tdc_sum <= 100); + }, "% Funding do not sum to 100%."); + + diff --git a/app/views/transit_assets/_transit_assets_funding_source_fields.html.haml b/app/views/transit_assets/_transit_assets_funding_source_fields.html.haml new file mode 100644 index 00000000..0a87501e --- /dev/null +++ b/app/views/transit_assets/_transit_assets_funding_source_fields.html.haml @@ -0,0 +1,47 @@ +:css + .purchase_cost_amount { + text-align: right; + } + + .right-align-label { + width: 100%; + text-align: right; + } + +.nested-fields.funding-source-fields{style: 'border:none;'} + .row + .asset-subform-action + .col-md-5 + = f.input :global_sourceable, :collection => FundingSource.all.map{|f| [ f.to_s, f.to_global_id ]}, :required => true, :label => 'Program', :input_html => { class: 'funding-source-global-sourceable' } + + .col-md-3.grant-purchase-amount + = f.input :amount, label_html: {class: 'right-align-label'} do + .input-group + %span.input-group-addon + $ + = f.input_field :amount, class: 'form-control purchase_cost_amount', min: 1, step: 1, required: true + .col-md-2.pcnt-column + = f.input :pcnt_purchase_cost, as: :hidden, :input_html => { class: 'funding-pcnt'} + .form-group + %label.control-label.right-align-label % Funding + .grant-purchase-pcnt.display-value{style: "text-align: right; padding: 4px;"}= "#{(format_as_decimal(f.object.pcnt_purchase_cost, Rails.application.config.try(:funding_pcnt_decimal_precision) || 2) || 0)} %" + + .col-md-1.pull-right + = link_to_remove_association f, :class => 'remove_funding_source pull-right' do + %i.fa.fa-2x.fa-minus-circle{style: 'margin-top: 27px;'} + .asset-subform-display{style: 'display: none;'} + .col-md-5 + .form-group + %label.control-label Program + .display-value= f.object.sourceable&.to_s + + .col-md-3 + .form-group + %label.control-label.right-align-label Amount + .display-value{style: 'text-align: right;'}= format_as_currency(f.object.amount) + .col-md-2 + .form-group + %label.control-label.right-align-label % Funding + .grant-purchase-pcnt.display-value{style: "text-align: right; padding: 4px;"}= "#{(format_as_decimal(f.object.pcnt_purchase_cost, Rails.application.config.try(:funding_pcnt_decimal_precision) || 2) || 0)} %" + + diff --git a/app/views/transit_assets/_transit_assets_grant_fields.html.haml b/app/views/transit_assets/_transit_assets_grant_fields.html.haml new file mode 100644 index 00000000..35601a20 --- /dev/null +++ b/app/views/transit_assets/_transit_assets_grant_fields.html.haml @@ -0,0 +1,74 @@ +:css + .purchase_cost_amount { + text-align: right; + } + + .right-align-label { + width: 100%; + text-align: right; + } + +- disabled = f.object.sourceable && !f.object.sourceable.open? + +.nested-fields.grant-fields{style: 'border:none;'} + .row + .asset-subform-action + .col-md-4 + = f.input :sourceable_type, as: :hidden, input_html: {value: 'Grant'} # hidden sourceable type field in case Other set + = f.input :global_sourceable, :collection => Grant.active.open.where(owner_id: @organization_list).or(Grant.where(id: f.object.sourceable_id)).map{|f| [ "#{f.grant_num} : #{format_as_fiscal_year(f.fy_year)} : #{f.owner.short_name} : Primary : #{format_as_currency(f.balance, negative_format: "(%u%n)" )}" , f.to_global_id ]}, :label => 'Grant #', disabled: disabled, include_blank: 'Other', input_html: {class: 'global-sourceable grant-global-sourceable'} + .col-md-2 + = f.input :other_sourceable, label: 'Grant # (Other)', disabled: disabled + + .col-md-2.grant-purchase-amount + + = f.input :amount, label_html: {class: 'right-align-label'} do + .input-group + %span.input-group-addon + $ + = f.input_field :amount, class: 'form-control purchase_cost_amount', min: 1, step: 1, required: true + .col-md-2.pcnt-column + = f.input :pcnt_purchase_cost, as: :hidden, :input_html => { class: 'funding-pcnt'} + .form-group + %label.control-label.right-align-label % Funding + .grant-purchase-pcnt.display-value{style: "text-align: right; padding: 4px;"}= "#{(format_as_decimal(f.object.pcnt_purchase_cost, Rails.application.config.try(:funding_pcnt_decimal_precision) || 2) || 0)} %" + + .col-md-1 + = f.input :expense_tag, label: 'Expense ID', disabled: disabled + + .col-md-1.pull-right + = link_to_remove_association f, :class => 'remove_grant pull-right' do + %i.fa.fa-2x.fa-minus-circle{style: 'margin-top: 27px;'} + + .asset-subform-display{style: 'display: none;'} + .col-md-4 + .form-group + %label.control-label Grant # + - grant = f.object.sourceable + .display-value + - if grant + = "#{grant.grant_num} : #{format_as_fiscal_year(grant.fy_year)} : #{grant.owner.short_name} : Primary : " + %span.grant-balance= "#{format_as_currency(grant.balance, negative_format: "(%u%n)")}" + - else + = "Other" + .col-md-2 + .form-group + %label.control-label Grant # (Other) + .display-value= f.object.other_sourceable + + .col-md-2 + .form-group + %label.control-label.right-align-label Amount + .display-value{style: 'text-align: right;'}= format_as_currency(f.object.amount) + .col-md-2 + .form-group + %label.control-label.right-align-label % Funding + .grant-purchase-pcnt.display-value{style: "text-align: right; padding: 4px;"}= "#{(format_as_decimal(f.object.pcnt_purchase_cost, Rails.application.config.try(:funding_pcnt_decimal_precision) || 2) || 0)} %" + + .col-md-1 + .form-group + %label.control-label Expense ID + .display-value= f.object.expense_tag + + + + diff --git a/config/initializers/transam.rb b/config/initializers/transam.rb index f83264eb..6e3f79c9 100755 --- a/config/initializers/transam.rb +++ b/config/initializers/transam.rb @@ -1 +1 @@ -Rails.application.config.rails_admin_accounting_lookup_tables = ['DepreciationIntervalType', 'ExpenseType'] \ No newline at end of file +Rails.application.config.rails_admin_accounting_lookup_tables = ['DepreciationIntervalType', 'ExpenseType', 'FundingSourceType'] \ No newline at end of file diff --git a/db/data_migrations/20190325185531_add_tdc_funding_source_type.rb b/db/data_migrations/20190325185531_add_tdc_funding_source_type.rb new file mode 100644 index 00000000..909e8c17 --- /dev/null +++ b/db/data_migrations/20190325185531_add_tdc_funding_source_type.rb @@ -0,0 +1,6 @@ +class AddTdcFundingSourceType < ActiveRecord::DataMigration + def up + tdc_type = FundingSourceType.create!(name: 'TDC', description: 'Transportation Development Credits', active: false) + FundingSource.create!(name: 'TDC', description: 'Transportation Development Credits', funding_source_type: tdc_type, match_required: 20, discretionary_fund: true, formula_fund: false) + end +end \ No newline at end of file diff --git a/db/data_migrations/20190523201240_migrate_grant_purchase_amounts.rb b/db/data_migrations/20190523201240_migrate_grant_purchase_amounts.rb new file mode 100644 index 00000000..bb2c5530 --- /dev/null +++ b/db/data_migrations/20190523201240_migrate_grant_purchase_amounts.rb @@ -0,0 +1,9 @@ +class MigrateGrantPurchaseAmounts < ActiveRecord::DataMigration + def up + GrantPurchase.all.each do |gp| + if gp.pcnt_purchase_cost && gp.transam_asset&.purchase_cost + gp.update(amount: (gp.transam_asset&.purchase_cost * gp.pcnt_purchase_cost / 100).to_i) + end + end + end +end \ No newline at end of file diff --git a/db/migrate/20190522024249_change_pcnt_purchase_cost_type.rb b/db/migrate/20190522024249_change_pcnt_purchase_cost_type.rb new file mode 100644 index 00000000..e10e9edf --- /dev/null +++ b/db/migrate/20190522024249_change_pcnt_purchase_cost_type.rb @@ -0,0 +1,5 @@ +class ChangePcntPurchaseCostType < ActiveRecord::Migration[5.2] + def change + change_column :grant_purchases, :pcnt_purchase_cost, :float + end +end diff --git a/db/migrate/20190523200038_add_amount_to_grant_purchase.rb b/db/migrate/20190523200038_add_amount_to_grant_purchase.rb new file mode 100644 index 00000000..b1292150 --- /dev/null +++ b/db/migrate/20190523200038_add_amount_to_grant_purchase.rb @@ -0,0 +1,5 @@ +class AddAmountToGrantPurchase < ActiveRecord::Migration[5.2] + def change + add_column :grant_purchases, :amount, :integer + end +end diff --git a/lib/transam_accounting/version.rb b/lib/transam_accounting/version.rb index e3b9a10b..340fec79 100644 --- a/lib/transam_accounting/version.rb +++ b/lib/transam_accounting/version.rb @@ -1,3 +1,3 @@ module TransamAccounting - VERSION = "2.5.2" + VERSION = "2.6.1" end diff --git a/spec/dummy/config/database.travis.yml b/spec/dummy/config/database.travis.yml index 1b721536..70bcbb46 100644 --- a/spec/dummy/config/database.travis.yml +++ b/spec/dummy/config/database.travis.yml @@ -6,6 +6,8 @@ mysql: &mysql adapter: mysql2 + variables: + sql_mode: traditional username: root password: database: transam_accounting_testing diff --git a/spec/models/grant_purchase_spec.rb b/spec/models/grant_purchase_spec.rb index 04bb900f..8c3d1897 100644 --- a/spec/models/grant_purchase_spec.rb +++ b/spec/models/grant_purchase_spec.rb @@ -32,7 +32,7 @@ end it '#allowable_params' do - expect(GrantPurchase.allowable_params).to eq([:id, :asset_id, :global_sourceable, :sourceable_type, :sourceable_id, :other_sourceable, :pcnt_purchase_cost, :expense_tag, :_destroy]) + expect(GrantPurchase.allowable_params).to eq([:id, :asset_id, :global_sourceable, :sourceable_type, :sourceable_id, :other_sourceable, :pcnt_purchase_cost, :amount, :expense_tag, :_destroy]) end it '.to_s' do