Skip to content

Commit

Permalink
Merge pull request #94 from hebron-george/tampa_house_lease
Browse files Browse the repository at this point in the history
Tampa house lease
  • Loading branch information
hebron-george authored Aug 4, 2019
2 parents 1d831b0 + e096962 commit 4201421
Show file tree
Hide file tree
Showing 13 changed files with 526 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@import "custom";
@import "bootstrap";
@import "leases";
3 changes: 3 additions & 0 deletions app/assets/stylesheets/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ $gray-darker: #343a40;
//}
//
/* footer */
.navbar {
margin-bottom: 3pt;
}

footer {
margin-top: 45px;
Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/leases.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Place all the styles related to the leases controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

.renew_section {
margin-bottom: 10pt;
}
12 changes: 12 additions & 0 deletions app/controllers/leases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ def update
end
end

def renew
property = set_property
new_lease = property.property_interface.renew_lease!

respond_to do |format|
if new_lease
format.html { redirect_to [@property, new_lease], notice: 'New Lease created!' }
format.json { render :show, status: :ok, location: [@property, new_lease] }
end
end
end

# DELETE /properties/:property_id/leases/1
# DELETE /properties/:property_id/leases/1.json
def destroy
Expand Down
8 changes: 8 additions & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true

def self.newest
order(:created_at => :desc).first
end

def self.oldest
order(:created_at => :desc).last
end
end
18 changes: 18 additions & 0 deletions app/models/lease.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ class Lease < ApplicationRecord
# https://semaphoreci.com/blog/2017/08/09/faster-rails-eliminating-n-plus-one-queries.html
scope :with_eager_loaded_contract, -> { eager_load(contract_attachment: :blob) }

def self.build_lease!(property, lease_details, lease_pdf)
l = build_lease(property, lease_details, lease_pdf)
l.save!
l
end

def self.build_lease(property, lease_details, lease_pdf)
l = Lease.new
l.property = property
l.tenants = lease_details[:tenants]
l.start_date = lease_details[:starting_date]
l.amount = lease_details[:rent_amount]
l.end_date = lease_details[:ending_date]
l.lease_frequency_id = 1 # hardcoding just to get it working for now, I was having some weird error pop up
l.contract.attach(io: StringIO.new(lease_pdf), filename: "lease_#{l.start_date}_#{Date.current}", content_type: "application/pdf")
l
end

def expired?(date=nil)
date = date || DateTime.now
return unless self.end_date
Expand Down
2 changes: 1 addition & 1 deletion app/views/leases/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<% if @leases.present? %>
<% @leases.sort_by(&:start_date).each do |lease| %>
<tr>
<td><%= link_to(lease.contract.blob.filename, [@property, lease]) %></td>
<td><%= link_to(lease&.contract&.blob&.filename, [@property, lease]) %></td>
<td><%= lease.start_date&.to_s(:long) %></td>
<td><%= lease.end_date&.to_s(:long) %></td>
<td>
Expand Down
8 changes: 7 additions & 1 deletion app/views/leases/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<h2>Lease Details</h2>
<!--<h2>Lease Details</h2>-->
<% if @lease.expiring_soon? %>
<div class="renew_section">
<h2>Expiring Soon... </h2>
<%= link_to "Renew Lease", property_lease_renew_current_lease_path(@property.id, @lease.id, id: @lease.id), id: @lease.id , class: 'btn btn-danger'%>
</div>
<% end %>

<table class="table table-striped table-hover table-bordered">
<thead class="thead-dark">
Expand Down
Loading

0 comments on commit 4201421

Please sign in to comment.