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

Fix/sync master and release #3344

Merged
merged 19 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions Modules/CodeTrek/Http/Controllers/CodeTrekController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,14 @@ public function index(Request $request)
// $this->authorize('view', $applicant); There are some issues in the production, which is why these lines are commented out.

$centres = OfficeLocation::all();

$mentors = User::all();
$applicantData = $this->service->getCodeTrekApplicants($request->all());
$applicants = $applicantData['applicants'];
$statusCounts = $applicantData['statusCounts'];
$start_date = Carbon::parse($request->application_start_date) ?? today()->subYear();
$end_date = Carbon::parse($request->application_end_date) ?? today();
$reportApplicationCounts = CodeTrekApplicant::select(\DB::Raw('DATE(start_date) as date, COUNT(*) as count'))
->whereDate('start_date', '>=', $start_date)
->whereDate('start_date', '<=', $end_date)
$startDate = Carbon::parse($request->input('application_start_date', today()->subYear()));
$endDate = Carbon::parse($request->input('application_end_date', today()));
$reportApplicationCounts = CodeTrekApplicant::whereDate('start_date', '>=', $startDate)
->whereDate('start_date', '<=', $endDate)
->count();

return view('codetrek::index', [
Expand Down
4 changes: 2 additions & 2 deletions Modules/Report/Http/Controllers/CodeTrekController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Modules\Report\Services\Finance\ReportDataService;
use Modules\Report\Services\CodeTrek\ReportDataService;

class CodeTrekController extends Controller
{
Expand All @@ -20,6 +20,6 @@ public function getApplicantData(Request $request)
$type = $request->type;
$filters = $request->filters;

return $this->service->getDataForDailyCodeTrekApplications($type, json_decode($filters, true), $request);
return $this->service->getDataForDailyCodeTrekApplications($type, json_decode($filters, true));
}
}
29 changes: 29 additions & 0 deletions Modules/Report/Services/CodeTrek/ReportDataService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Modules\Report\Services\CodeTrek;

use Modules\CodeTrek\Entities\CodeTrekApplicant;

class ReportDataService
{
public function getDataForDailyCodeTrekApplications($type, $filters)
{
if ($type == 'codetrek-application') {
GauravGusain98 marked this conversation as resolved.
Show resolved Hide resolved
$filterStartDate = empty($filters['start_date']) ? today()->subYear() : $filters['start_date'];
$filterEndDate = empty($filters['end_date']) ? today() : $filters['end_date'];
$applicantChartData = CodeTrekApplicant::select(\DB::Raw('DATE(start_date) as date, COUNT(*) as count'))
->whereDate('start_date', '>=', $filterStartDate)
->whereDate('start_date', '<=', $filterEndDate)
->groupBy('date');

$dates = $applicantChartData->pluck('date')->toArray();
$counts = $applicantChartData->pluck('count')->toArray();
$chartData = [
'dates' => $dates,
'counts' => $counts,
];

return json_encode($chartData);
}
}
}
33 changes: 4 additions & 29 deletions Modules/Report/Services/Finance/ReportDataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Modules\Report\Services\Finance;

use Modules\Client\Entities\Client;
use Modules\CodeTrek\Entities\CodeTrekApplicant;

class ReportDataService
{
Expand All @@ -20,30 +19,6 @@ public function getData($type, $filters)
return $filters;
}

public function getDataForDailyCodeTrekApplications($type, $filters)
{
if ($type == 'codetrek-application') {
$applicants = CodeTrekApplicant::find('start_date');
$defaultStartDate = $applicants->created_at ?? today()->subYear();
$defaultEndDate = today();
$filters['start_date'] = empty($filters['start_date']) ? $defaultStartDate : $filters['start_date'];
$filters['end_date'] = empty($filters['end_date']) ? $defaultEndDate : $filters['end_date'];
$applicantChartData = CodeTrekApplicant::select(\DB::Raw('DATE(start_date) as date, COUNT(*) as count'))
->whereDate('start_date', '>=', $filters['start_date'])
->whereDate('start_date', '<=', $filters['end_date'])
->groupBy('date');

$dates = $applicantChartData->pluck('date')->toArray();
$counts = $applicantChartData->pluck('count')->toArray();
$chartData = [
'dates' => $dates,
'counts' => $counts,
];

return json_encode($chartData);
}
}

public function getDataForClientRevenueReportPage(array $data)
{
$selectedClient = isset($data['client_id']) ? Client::find($data['client_id']) : Client::orderBy('name')->first();
Expand All @@ -62,8 +37,8 @@ private function revenueTrendForClient($filters)

$filters['start_date'] = empty($filters['start_date']) ? $defaultStartDate : $filters['start_date'];
$filters['end_date'] = empty($filters['end_date']) ? $defaultEndDate : $filters['end_date'];

$reportData = $this->service->getRevenueReportDataForClient($filters, $client);
$revenueReportService = new RevenueReportService;
$reportData = $revenueReportService->getRevenueReportDataForClient($filters, $client);
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be easier if we make these static functions and then can directly call these like:

$reportData = RevenueReportService::getRevenueReportDataForClient($filters, $client);


return [
'labels' => $reportData['months'],
Expand All @@ -85,8 +60,8 @@ private function revenueTrend($filters)
'previous_period_end_date' => $defaultPreviousEndDate,
];
$filters = array_merge($defaultFilters, request()->all());

$reportData = $this->service->getRevenueGroupedByClient($filters);
$revenueReportService = new RevenueReportService;
$reportData = $revenueReportService->getRevenueGroupedByClient($filters);
Copy link
Member

Choose a reason for hiding this comment

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

same feedback for this. Can be used as a static function.


return [
'labels' => $reportData['clients_name'],
Expand Down