diff --git a/Modules/CodeTrek/Http/Controllers/CodeTrekController.php b/Modules/CodeTrek/Http/Controllers/CodeTrekController.php index b4ab8224ec..874ad6e2e8 100644 --- a/Modules/CodeTrek/Http/Controllers/CodeTrekController.php +++ b/Modules/CodeTrek/Http/Controllers/CodeTrekController.php @@ -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', [ diff --git a/Modules/Report/Http/Controllers/CodeTrekController.php b/Modules/Report/Http/Controllers/CodeTrekController.php index 7d3ff62c97..add769f5ba 100644 --- a/Modules/Report/Http/Controllers/CodeTrekController.php +++ b/Modules/Report/Http/Controllers/CodeTrekController.php @@ -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 { @@ -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)); } } diff --git a/Modules/Report/Services/CodeTrek/ReportDataService.php b/Modules/Report/Services/CodeTrek/ReportDataService.php new file mode 100644 index 0000000000..1c610807d8 --- /dev/null +++ b/Modules/Report/Services/CodeTrek/ReportDataService.php @@ -0,0 +1,30 @@ +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); + } +} diff --git a/Modules/Report/Services/Finance/ReportDataService.php b/Modules/Report/Services/Finance/ReportDataService.php index a0f5956364..31e51dcb8c 100644 --- a/Modules/Report/Services/Finance/ReportDataService.php +++ b/Modules/Report/Services/Finance/ReportDataService.php @@ -3,7 +3,6 @@ namespace Modules\Report\Services\Finance; use Modules\Client\Entities\Client; -use Modules\CodeTrek\Entities\CodeTrekApplicant; class ReportDataService { @@ -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(); @@ -62,8 +37,7 @@ 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); + $reportData = RevenueReportService::getRevenueReportDataForClient($filters, $client); return [ 'labels' => $reportData['months'], @@ -85,8 +59,7 @@ private function revenueTrend($filters) 'previous_period_end_date' => $defaultPreviousEndDate, ]; $filters = array_merge($defaultFilters, request()->all()); - - $reportData = $this->service->getRevenueGroupedByClient($filters); + $reportData = RevenueReportService::getRevenueGroupedByClient($filters); return [ 'labels' => $reportData['clients_name'], diff --git a/Modules/Report/Services/Finance/RevenueReportService.php b/Modules/Report/Services/Finance/RevenueReportService.php index 8a73cb4edc..804fe06a7e 100644 --- a/Modules/Report/Services/Finance/RevenueReportService.php +++ b/Modules/Report/Services/Finance/RevenueReportService.php @@ -49,7 +49,7 @@ public function getParticularReport(string $particularSlug, array $particular, o return $particular; } - public function getRevenueGroupedByClient($filters) + public static function getRevenueGroupedByClient($filters) { $currentPeriodInvoiceDetails = Invoice::with('client') ->whereBetween('sent_on', [$filters['current_period_start_date'], $filters['current_period_end_date']]) @@ -92,36 +92,36 @@ public function getRevenueGroupedByClient($filters) return $data; } - public function getRevenueReportDataForClient($filters, $client) + public static function getRevenueReportDataForClient($filters, $client) { $amountMonthWise = []; $totalAmount = 0; $clientDepartments = $client->linkedAsDepartment; $clientPartners = $client->linkedAsPartner; - $clientInvoiceDetails = $this->getInvoicesForClient($client, $filters); + $clientInvoiceDetails = self::getInvoicesForClient($client, $filters); foreach ($clientInvoiceDetails as $invoice) { - $data = $this->handleInvoiceDataForClient($invoice, $amountMonthWise); + $data = self::handleInvoiceDataForClient($invoice, $amountMonthWise); $totalAmount += $data['invoiceAmount']; $amountMonthWise = $data['amountMonthWise']; } foreach ($clientDepartments as $department) { - $departmentInvoiceDetails = $this->getInvoicesForClient($department, $filters); + $departmentInvoiceDetails = self::getInvoicesForClient($department, $filters); foreach ($departmentInvoiceDetails as $invoice) { - $data = $this->handleInvoiceDataForClient($invoice, $amountMonthWise); + $data = self::handleInvoiceDataForClient($invoice, $amountMonthWise); $totalAmount += $data['invoiceAmount']; $amountMonthWise = $data['amountMonthWise']; } } foreach ($clientPartners as $partner) { - $partnerInvoiceDetails = $this->getInvoicesForClient($partner, $filters); + $partnerInvoiceDetails = self::getInvoicesForClient($partner, $filters); foreach ($partnerInvoiceDetails as $invoice) { - $data = $this->handleInvoiceDataForClient($invoice, $amountMonthWise); + $data = self::handleInvoiceDataForClient($invoice, $amountMonthWise); $totalAmount += $data['invoiceAmount']; $amountMonthWise = $data['amountMonthWise']; } @@ -277,7 +277,7 @@ private function getAmountsForRevenueProceeds($category, $startDate, $endDate) return $results; } - private function handleInvoiceDataForClient($invoice, $amountMonthWise) + private static function handleInvoiceDataForClient($invoice, $amountMonthWise) { $invoiceAmount = round($invoice->total_amount_in_inr, 2); $amountMonthWise[$invoice->sent_on->format('M-Y')] = ($amountMonthWise[$invoice->sent_on->format('M-Y')] ?? 0) + $invoiceAmount; @@ -288,7 +288,7 @@ private function handleInvoiceDataForClient($invoice, $amountMonthWise) ]; } - private function getInvoicesForClient($client, $filters) + private static function getInvoicesForClient($client, $filters) { return Invoice::where('client_id', $client->id) ->whereBetween('sent_on', [$filters['start_date'], $filters['end_date']])