We want to have a centralized source where any person from the finance team or the product department can find easy and fast the scripts and code related to the tasks from our team.
You will need access to the staging and production consoles, if you are not available to got into this enviroments talk to the Systems Team in #dev-systems Slack channel.
If you want to see the current implementation for this process you can check this Flow Diagram any comment about this process ask in #dev-finance Slack channel.
You can launch the next jobs in order to start the globlal invoicing process for all the agencies, we have different billing periods so check the next snippet :
# For daily billing period
Invoices::GenerateDailyWorker.perform_async
# For weekly billing period
Invoices::GenerateWeeklyWorker.perform_async
# For biweekly billing period
Invoices::GenerateBiweeklyWorker.perform_async
# For Monthly billing period
Invoices::GenerateMonthlyWorker.perform_async
If you need to run the invoicing process for a specific agency in some of the billing periods from the list below you can use the next command:
# Example for agency with monthly billing period
# Script info
agency_id = 'agency_id'
billing_period = :monthly
# Find date limit to fetch pending sales
date_limit = Date.today.prev_month.end_of_month # Date supposed to run the generation
# Trigger workers: this method will trigger one worker per each client with pending sales to generate invoices
Invoices::Generators.new(agency, billing_period, date_limit).start
If you need to run the invoicing process for a specific client in some of the billing periods from the list below you can use the next command:
# Example for client with biweekly billing period
# Script info
client_id = 'client_id'
agency_id = 'agency_id'
generation_date = Date.new(2018,1,16) # Date supposed to run the generation
billing_period = :biweekly
# Find date limit to fetch pending sales
first_fortnight = (1..15)
date_limit = if first_fortnight.include?(generation_date)
Date.today.prev_month.end_of_month
else
Date.today.beginning_of_month + 14.days
end
# Trigger worker
Invoices::Generators::Client.delay(queue: :billing).generate(client_id, agency_id, billing_period, date_limit)
Be careful and take in consideration we use third-party apps and services for some countries, after running some of the commands above you should check the synchronization with this services is working too, a high number of invoices can collapse the rate limit. (For example in Mexico we use Facturama to validate legal documents)
If you want to know more about this workflow you can check the next files in our Ruby repository:
Feel free to contact the channel #dev-finance in Slack if you have any doubt, comment, feedback, suggestion or question.
I'm waiting to update this documentation after the refactor is deployed. Check this PR fore more information.