Skip to content

Commit

Permalink
Merge pull request #3344 from ColoredCow/fix/sync-master-and-release
Browse files Browse the repository at this point in the history
Fix/sync master and release
  • Loading branch information
Satendra-SR authored Sep 15, 2023
2 parents 6192c3b + 85d24ec commit 6bfd410
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 47 deletions.
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));
}
}
30 changes: 30 additions & 0 deletions Modules/Report/Services/CodeTrek/ReportDataService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Modules\Report\Services\CodeTrek;

use Modules\CodeTrek\Entities\CodeTrekApplicant;

class ReportDataService
{
public function getDataForDailyCodeTrekApplications($type, $filters)
{
$chartData = [];
if ($type == 'codetrek-application') {
$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);
}
}
31 changes: 2 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,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'],
Expand All @@ -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'],
Expand Down
20 changes: 10 additions & 10 deletions Modules/Report/Services/Finance/RevenueReportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']])
Expand Down Expand Up @@ -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'];
}
Expand Down Expand Up @@ -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;
Expand All @@ -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']])
Expand Down

0 comments on commit 6bfd410

Please sign in to comment.