Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add billing #855

Merged
merged 23 commits into from
Jun 30, 2021
Merged

feat: add billing #855

merged 23 commits into from
Jun 30, 2021

Conversation

djaiss
Copy link
Member

@djaiss djaiss commented May 7, 2021

Billing is a critical feature.

It allows us to bill customers appropriately, thus giving us more resources to work on the product. We need to make sure billing is done well on day 1.

Here is how it works on OfficeLife.

  1. First of all, there is a new .env variable that is enabled by default, which let us have paid plan on the instance. This flag will make sure customers are billed every month.
  2. Every day at midnight (UTC), we calculate the number of maximum active employees in the company's account. This job is called LogDailyMaxNumberOfActiveEmployeesInCompanies. An active employee is an employee who hasn't been locked in the account. This information is stored in a new table, called company_daily_usage_history.
  3. As additional proof, we will also record, for each day, the employee names and emails that were active in the instance. This information is stored in a new table called company_usage_history_details. This table might be huge in the future as we get more customers - we might need to auto-delete the record after a given number of months.
  4. At the end of each company's billing period in the instance, we will get the highest number of maximum active employees in the given time period in the account, and generate an invoice for the company. This information is stored in a new table, called company_invoices. The job is called CreateMonthlyInvoiceForCompany.
  5. Once the invoice is generated, we will manually charge the customer and manually send an invoice.

In an ideal world, charging customers will be automated. For now, we'll charge manually.

Here is a breakdown of all the things we need to do:

  • Make sure the new .env variable is documented
  • Daily job: calculate the number of maximum active employees in the company
  • Daily job: record the names of employees that were in the instance each day
  • Monthly job: create invoice

@sonarcloud
Copy link

sonarcloud bot commented May 13, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

92.3% 92.3% Coverage
0.0% 0.0% Duplication

@djaiss djaiss marked this pull request as ready for review June 30, 2021 01:41
@djaiss djaiss requested a review from a team as a code owner June 30, 2021 01:41
@djaiss djaiss requested review from asbiin and removed request for a team June 30, 2021 01:41
@djaiss
Copy link
Member Author

djaiss commented Jun 30, 2021

@asbiin please review

Copy link
Contributor

@asbiin asbiin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.
Just some consistency changes, because I'm boring.

app/Jobs/Invoicing/CreateMonthlyInvoiceForCompanies.php Outdated Show resolved Hide resolved
database/factories/Company/CompanyInvoiceFactory.php Outdated Show resolved Hide resolved
@@ -37,6 +39,11 @@ protected function schedule(Schedule $schedule)
$schedule->job(new StartRateYourManagerProcess())->lastDayOfMonth('01:00');
$schedule->job(new StopRateYourManagerProcess())->hourly();

$schedule->command('timeoff:calculate '.Carbon::today()->format('Y-m-d'))->daily();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same as the commented line below

djaiss and others added 5 commits June 30, 2021 07:53
@djaiss djaiss merged commit 07901c2 into main Jun 30, 2021
@djaiss djaiss deleted the 2021-05-08-account branch June 30, 2021 13:04
@sonarcloud
Copy link

sonarcloud bot commented Jun 30, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

94.3% 94.3% Coverage
0.0% 0.0% Duplication

@github-actions
Copy link
Contributor

🎉 This PR is included in version 0.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link
Contributor

This pull request has been automatically locked since there
has not been any recent activity after it was closed.
Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants