-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from liberu-billing/sweep/Implement-Affiliate…
…-Reporting-and-Custom-Commission-Rates Implement Affiliate Reporting and Custom Commission Rates
- Loading branch information
Showing
5 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace App\Services; | ||
|
||
use App\Models\Affiliate; | ||
use Carbon\Carbon; | ||
|
||
class AffiliateReportingService | ||
{ | ||
public function generateReport(Affiliate $affiliate, $startDate, $endDate) | ||
{ | ||
$startDate = Carbon::parse($startDate)->startOfDay(); | ||
$endDate = Carbon::parse($endDate)->endOfDay(); | ||
|
||
$transactions = $affiliate->transactions() | ||
->whereBetween('created_at', [$startDate, $endDate]) | ||
->get(); | ||
|
||
$totalEarnings = $transactions->where('type', 'commission')->sum('amount'); | ||
$totalReferrals = $affiliate->referrals()->whereBetween('created_at', [$startDate, $endDate])->count(); | ||
|
||
return [ | ||
'affiliate' => $affiliate, | ||
'start_date' => $startDate->toDateString(), | ||
'end_date' => $endDate->toDateString(), | ||
'total_earnings' => $totalEarnings, | ||
'total_referrals' => $totalReferrals, | ||
'transactions' => $transactions, | ||
]; | ||
} | ||
} |
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
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