Skip to content

Commit

Permalink
Issue krayin#801 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
shagun2405 committed Aug 23, 2022
1 parent 5d7ad0e commit bec5c91
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 51 deletions.
13 changes: 8 additions & 5 deletions packages/Webkul/Admin/src/Helpers/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ public function getActivities($startDateFilter, $endDateFilter, $totalWeeks)
*/
public function getTopLeads($startDateFilter, $endDateFilter, $totalWeeks)
{
$topLeads = $this->leadRepository
if (bouncer()->hasPermission('leads.view')) {
$topLeads = $this->leadRepository
->select('leads.id', 'title', 'lead_value as amount', 'leads.created_at', 'status', 'lead_pipeline_stages.name as statusLabel')
->leftJoin('lead_pipeline_stages', 'leads.lead_pipeline_stage_id', '=', 'lead_pipeline_stages.id')
->orderBy('lead_value', 'desc')
Expand All @@ -461,11 +462,13 @@ public function getTopLeads($startDateFilter, $endDateFilter, $totalWeeks)
->limit(3)
->get();

$cardData = [
"data" => $topLeads
];
$cardData = [
"data" => $topLeads,
];

return $cardData;
return $cardData;
}

}

/**
Expand Down
94 changes: 48 additions & 46 deletions packages/Webkul/Admin/src/Http/Controllers/Lead/LeadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,76 +79,78 @@ public function index()
*/
public function get()
{
if (request('view_type')) {
return app(\Webkul\Admin\DataGrids\Lead\LeadDataGrid::class)->toJson();
} else {
$createdAt = request('created_at') ?? null;

if ($createdAt && isset($createdAt["bw"])) {
$createdAt = explode(",", $createdAt["bw"]);

$createdAt[0] .= ' 00:01';

$createdAt[1] = $createdAt[1]
? $createdAt[1] . ' 23:59'
: Carbon::now()->format('Y-m-d 23:59');
if (bouncer()->hasPermission('leads.view')) {
if (request('view_type')) {
return app(\Webkul\Admin\DataGrids\Lead\LeadDataGrid::class)->toJson();
} else {
$createdAt = null;
}
$createdAt = request('created_at') ?? null;

if (request('pipeline_id')) {
$pipeline = $this->pipelineRepository->find(request('pipeline_id'));
} else {
$pipeline = $this->pipelineRepository->getDefaultPipeline();
}
if ($createdAt && isset($createdAt["bw"])) {
$createdAt = explode(",", $createdAt["bw"]);

$data = [];
$createdAt[0] .= ' 00:01';

if ($stageId = request('pipeline_stage_id')) {
$query = $this->leadRepository->getLeadsQuery($pipeline->id, $stageId, request('search') ?? '', $createdAt);
$createdAt[1] = $createdAt[1]
? $createdAt[1] . ' 23:59'
: Carbon::now()->format('Y-m-d 23:59');
} else {
$createdAt = null;
}

$paginator = $query->paginate(10);
if (request('pipeline_id')) {
$pipeline = $this->pipelineRepository->find(request('pipeline_id'));
} else {
$pipeline = $this->pipelineRepository->getDefaultPipeline();
}

$data[$stageId] = [
'leads' => [],
'pagination' => [
'current' => $current = $paginator->currentPage(),
'last' => $last = $paginator->lastPage(),
'next' => $current < $last ? $current + 1 : null,
],
'total' => core()->formatBasePrice($query->paginate(request('page') ? request('page') * 10 : 10, ['*'], 'page', 1)->sum('lead_value')),
];
$data = [];

foreach ($paginator as $lead) {
$data[$stageId]['leads'][] = array_merge($lead->toArray(), [
'lead_value' => core()->formatBasePrice($lead->lead_value),
]);
}
} else {
foreach ($pipeline->stages as $stage) {
$query = $this->leadRepository->getLeadsQuery($pipeline->id, $stage->id, request('search') ?? '', $createdAt);
if ($stageId = request('pipeline_stage_id')) {
$query = $this->leadRepository->getLeadsQuery($pipeline->id, $stageId, request('search') ?? '', $createdAt);

$paginator = $query->paginate(10);

$data[$stage->id] = [
$data[$stageId] = [
'leads' => [],
'pagination' => [
'current' => $current = $paginator->currentPage(),
'last' => $last = $paginator->lastPage(),
'next' => $current < $last ? $current + 1 : null,
],
'total' => core()->formatBasePrice($query->paginate(10)->sum('lead_value')),
'total' => core()->formatBasePrice($query->paginate(request('page') ? request('page') * 10 : 10, ['*'], 'page', 1)->sum('lead_value')),
];

foreach ($paginator as $lead) {
$data[$stage->id]['leads'][] = array_merge($lead->toArray(), [
$data[$stageId]['leads'][] = array_merge($lead->toArray(), [
'lead_value' => core()->formatBasePrice($lead->lead_value),
]);
}
} else {
foreach ($pipeline->stages as $stage) {
$query = $this->leadRepository->getLeadsQuery($pipeline->id, $stage->id, request('search') ?? '', $createdAt);

$paginator = $query->paginate(10);

$data[$stage->id] = [
'leads' => [],
'pagination' => [
'current' => $current = $paginator->currentPage(),
'last' => $last = $paginator->lastPage(),
'next' => $current < $last ? $current + 1 : null,
],
'total' => core()->formatBasePrice($query->paginate(10)->sum('lead_value')),
];

foreach ($paginator as $lead) {
$data[$stage->id]['leads'][] = array_merge($lead->toArray(), [
'lead_value' => core()->formatBasePrice($lead->lead_value),
]);
}
}
}
}

return response()->json($data);
return response()->json($data);
}
}
}

Expand Down

0 comments on commit bec5c91

Please sign in to comment.