Last active
January 8, 2018 15:25
-
-
Save avidas/3b1389e6025cd180e6d989e0844feeb2 to your computer and use it in GitHub Desktop.
This file contains 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 characters
begin | |
TenantService.switch_to_rest_of_world_tenant | |
account = Account.find_by_short_code("DYD9GC") | |
location = Location.find_by_code("LON11") | |
# Get billing period | |
start_of_two_months_ago = Date.today.last_month.last_month.beginning_of_month | |
end_of_two_months_ago = Date.today.last_month.last_month.end_of_month | |
two_months_ago_range = start_of_two_months_ago..end_of_two_months_ago | |
billing_period = two_months_ago_range # Invoice for December covers Nov 1 - Nov 30th | |
# Mid month refunds created during November | |
# prevents December invoice to be generated | |
# We need to archive them | |
Reservation. | |
where(account: account). | |
where(ended_on: billing_period). | |
select{ |r| r.reservable.name == "Mid-Month Move Out Refund" }. | |
map(&:archive!) | |
# Regenerate December invoice | |
# We are going to generate the active invoice for December | |
# and let billing finalize it. | |
Invoices::InvoiceManager.new.update!(account, location, two_months_ago_range) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍