Skip to content

Commit

Permalink
Completed dashboard page
Browse files Browse the repository at this point in the history
  • Loading branch information
jitendra-webkul committed Aug 20, 2024
1 parent ee80b44 commit 5e163e9
Show file tree
Hide file tree
Showing 30 changed files with 4,185 additions and 3,141 deletions.
1 change: 1 addition & 0 deletions packages/Webkul/Admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@vee-validate/i18n": "^4.9.1",
"@vee-validate/rules": "^4.9.1",
"@vitejs/plugin-vue": "^4.2.3",
"chartjs-chart-funnel": "^4.2.1",
"flatpickr": "^4.6.13",
"mitt": "^3.0.1",
"vee-validate": "^4.9.1",
Expand Down
19 changes: 14 additions & 5 deletions packages/Webkul/Admin/src/Helpers/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ public function getRevenueStats(): array
public function getOverAllStats(): array
{
return [
'total_leads' => $this->leadReporting->getTotalLeadsProgress(),
'average_lead_value' => $this->leadReporting->getAverageLeadValueProgress(),
'total_quotations' => $this->quoteReporting->getTotalQuotesProgress(),
'total_persons' => $this->personReporting->getTotalPersonsProgress(),
'total_organizations' => $this->organizationReporting->getTotalOrganizationsProgress(),
'total_leads' => $this->leadReporting->getTotalLeadsProgress(),
'average_lead_value' => $this->leadReporting->getAverageLeadValueProgress(),
'average_leads_per_day' => $this->leadReporting->getAverageLeadsPerDayProgress(),
'total_quotations' => $this->quoteReporting->getTotalQuotesProgress(),
'total_persons' => $this->personReporting->getTotalPersonsProgress(),
'total_organizations' => $this->organizationReporting->getTotalOrganizationsProgress(),
];
}

Expand Down Expand Up @@ -87,6 +88,14 @@ public function getLeadsStatsByTypes(): mixed
return $this->leadReporting->getTotalWonLeadValueByTypes();
}

/**
* Returns open leads statistics by states.
*/
public function getOpenLeadsByStates(): mixed
{
return $this->leadReporting->getOpenLeadsByStates();
}

/**
* Returns top selling products statistics.
*/
Expand Down
45 changes: 45 additions & 0 deletions packages/Webkul/Admin/src/Helpers/Reporting/Lead.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,31 @@ public function getTotalLeads($startDate, $endDate): int
->count();
}

/**
* Retrieves average leads per day and their progress.
*/
public function getAverageLeadsPerDayProgress(): array
{
return [
'previous' => $previous = $this->getAverageLeadsPerDay($this->lastStartDate, $this->lastEndDate),
'current' => $current = $this->getAverageLeadsPerDay($this->startDate, $this->endDate),
'progress' => $this->getPercentageChange($previous, $current),
];
}

/**
* Retrieves average leads per day
*
* @param \Carbon\Carbon $startDate
* @param \Carbon\Carbon $endDate
*/
public function getAverageLeadsPerDay($startDate, $endDate): float
{
$days = $startDate->diffInDays($endDate);

return $this->getTotalLeads($startDate, $endDate) / $days;
}

/**
* Retrieves total lead value and their progress.
*/
Expand Down Expand Up @@ -249,6 +274,26 @@ public function getTotalWonLeadValueByTypes()
->get();
}

/**
* Retrieves open leads by states.
*/
public function getOpenLeadsByStates()
{
return $this->leadRepository
->resetModel()
->select(
'lead_pipeline_stages.name',
DB::raw('COUNT(lead_value) as total')
)
->leftJoin('lead_pipeline_stages', 'leads.lead_pipeline_stage_id', '=', 'lead_pipeline_stages.id')
->whereNotIn('lead_pipeline_stage_id', $this->wonStageIds)
->whereNotIn('lead_pipeline_stage_id', $this->lostStageIds)
->whereBetween('leads.created_at', [$this->startDate, $this->endDate])
->groupBy('lead_pipeline_stage_id')
->orderByDesc('total')
->get();
}

/**
* Returns over time stats.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class DashboardController extends Controller
'revenue-by-types' => 'getLeadsStatsByTypes',
'top-selling-products' => 'getTopSellingProducts',
'top-persons' => 'getTopPersons',
'open-leads-by-states' => 'getOpenLeadsByStates',
];

/**
Expand Down
Loading

0 comments on commit 5e163e9

Please sign in to comment.