From f7ba12a548f6ab0df948c61e43bdb8257f6a9b4b Mon Sep 17 00:00:00 2001 From: jitendra Date: Mon, 15 Nov 2021 18:05:55 +0530 Subject: [PATCH] Issue #704 fixed --- packages/Webkul/Admin/src/Helpers/Dashboard.php | 4 ++-- packages/Webkul/Lead/src/Models/Lead.php | 12 ------------ .../Webkul/Lead/src/Repositories/LeadRepository.php | 1 + 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/packages/Webkul/Admin/src/Helpers/Dashboard.php b/packages/Webkul/Admin/src/Helpers/Dashboard.php index 5dd804052..73577d87d 100644 --- a/packages/Webkul/Admin/src/Helpers/Dashboard.php +++ b/packages/Webkul/Admin/src/Helpers/Dashboard.php @@ -443,7 +443,7 @@ public function getActivities($startDateFilter, $endDateFilter, $totalWeeks) public function getTopLeads($startDateFilter, $endDateFilter, $totalWeeks) { $topLeads = $this->leadRepository - ->select('leads.*', 'title', 'lead_value as amount', 'leads.created_at', 'status', 'lead_pipeline_stages.name as statusLabel') + ->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') ->whereBetween('leads.created_at', [$startDateFilter, $endDateFilter]) @@ -574,7 +574,7 @@ public function getEmails($startDateFilter, $endDateFilter, $totalWeeks) public function getTopCustomers($startDateFilter, $endDateFilter, $totalWeeks) { $topCustomers = $this->leadRepository - ->select('leads.*', 'persons.id as personId', 'persons.name as label', DB::raw("(COUNT(*)) as count")) + ->select('persons.id as personId', 'persons.name as label', DB::raw("(COUNT(*)) as count")) ->leftJoin('persons', 'leads.person_id', '=', 'persons.id') ->whereBetween('leads.created_at', [$startDateFilter, $endDateFilter]) ->groupBy('person_id') diff --git a/packages/Webkul/Lead/src/Models/Lead.php b/packages/Webkul/Lead/src/Models/Lead.php index 905164407..bbd4c0666 100644 --- a/packages/Webkul/Lead/src/Models/Lead.php +++ b/packages/Webkul/Lead/src/Models/Lead.php @@ -144,16 +144,4 @@ public function getRottenDaysAttribute() return $rottenDate->diffInDays(Carbon::now(), false); } - - /** - * @return array - */ - public function toArray() - { - $array = parent::toArray(); - - $array['rotten_days'] = $this->rotten_days; - - return $array; - } } diff --git a/packages/Webkul/Lead/src/Repositories/LeadRepository.php b/packages/Webkul/Lead/src/Repositories/LeadRepository.php index 19898963a..3d549b10a 100755 --- a/packages/Webkul/Lead/src/Repositories/LeadRepository.php +++ b/packages/Webkul/Lead/src/Repositories/LeadRepository.php @@ -96,6 +96,7 @@ public function getLeads($pipelineId, $term, $createdAtRange) 'lead_pipeline_stages.name as status', 'lead_pipeline_stages.id as lead_pipeline_stage_id' ) + ->addSelect(\DB::raw('DATEDIFF(leads.created_at + INTERVAL lead_pipelines.rotten_days DAY, now()) as rotten_days')) ->leftJoin('persons', 'leads.person_id', '=', 'persons.id') ->leftJoin('lead_pipelines', 'leads.lead_pipeline_id', '=', 'lead_pipelines.id') ->leftJoin('lead_pipeline_stages', 'leads.lead_pipeline_stage_id', '=', 'lead_pipeline_stages.id')