Skip to content

Commit

Permalink
Merge pull request #65 from camsys/quarter2
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mathmerized authored Jun 13, 2019
2 parents dc2b1c7 + f8a08de commit 47cde52
Show file tree
Hide file tree
Showing 38 changed files with 369 additions and 187 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
language: ruby
rvm:
- 2.5.3
services:
- mysql
branches:
only:
- master
Expand Down
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 20 additions & 0 deletions app/models/abilities/authorized_accounting_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions app/models/abilities/manager_accounting_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion app/models/funding_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class FundingSource < ActiveRecord::Base
#------------------------------------------------------------------------------
after_initialize :set_defaults

default_scope { where(funding_source_type: FundingSourceType.active) }

#------------------------------------------------------------------------------
# Associations
#------------------------------------------------------------------------------
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions app/models/funding_source_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')") }
Expand Down
2 changes: 1 addition & 1 deletion app/models/grant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/models/grant_purchase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,6 +46,7 @@ class GrantPurchase < ActiveRecord::Base
:sourceable_id,
:other_sourceable,
:pcnt_purchase_cost,
:amount,
:expense_tag,
:_destroy
]
Expand Down
5 changes: 2 additions & 3 deletions app/reports/asset_funding_source_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"')
Expand Down Expand Up @@ -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)
Expand Down
145 changes: 78 additions & 67 deletions app/views/asset_events/_rehabilitation_update_event_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,59 +1,55 @@
-# 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))}",
'date-end-date' => "#{format_as_date(@asset.policy_analyzer.get_depreciation_date(Date.today)-1.day)}"},
: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

Expand All @@ -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);
}
});
});

});

2 changes: 1 addition & 1 deletion app/views/assets/_depreciation_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 47cde52

Please sign in to comment.