Last active
August 29, 2015 14:20
-
-
Save robcole/c69550a5c5faed3a2c1c to your computer and use it in GitHub Desktop.
Revisions
-
robcole revised this gist
Apr 30, 2015 . 2 changed files with 7 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ def apply_current_grant! current_grant = project.current_grant current_grant.apply_to_donation(self) end @@ -9,18 +9,18 @@ def grant_can_be_applied? def apply_multiple_grants if grants.current.remaining_amount >= total_amount apply_current_grant! else while grant_can_be_applied? apply_current_grant! end end end def apply_grant! grant_count = project.grants.active.count if grant_count == 1 apply_current_grant! elsif grant_count > 1 apply_multiple_grants else This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ def apply_to_donation(donation) if active? amount_to_apply = donation.project_amount donation.grant_amount ||= 0 if remaining_amount >= amount_to_apply # Case: There is enough remaining to match the gift donation.grant_amount += amount_to_apply self.remaining_amount -= amount_to_apply @@ -11,6 +11,7 @@ def apply_to_donation(donation) donation.grant_amount += amount_remaining self.remaining_amount -= amount_remaining end donation.grants.push(self) donation.save! self.save! end -
robcole revised this gist
Apr 30, 2015 . 1 changed file with 17 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ def apply_to_donation(donation) if active? amount_to_apply = donation.project_amount donation.grant_amount ||= 0 if amount_remaining >= amount_to_apply # Case: There is enough remaining to match the gift donation.grant_amount += amount_to_apply self.remaining_amount -= amount_to_apply else # Case: There is NOT enough remaining to match the gift donation.grant_amount += amount_remaining self.remaining_amount -= amount_remaining end donation.save! self.save! end end -
robcole renamed this gist
Apr 30, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
robcole created this gist
Apr 30, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ def apply_grant current_grant = project.grants.current current_grant.apply_to_donation(self) end def grant_can_be_applied? grants.current.present? && (total_amount <= grant_amount) end def apply_multiple_grants if grants.current.remaining_amount >= total_amount apply_grant else while grant_can_be_applied? apply_grant end end end def apply_grant! grant_count = project.grants.active.count if grant_count == 1 apply_grant elsif grant_count > 1 apply_multiple_grants else end end