From bb1584c1baa1a79739d4436150f4d4ebefc337f2 Mon Sep 17 00:00:00 2001 From: nocode Date: Wed, 17 Jul 2024 11:45:36 +0700 Subject: [PATCH] NEW LIST AGENT FOR USER --- Modules/Agents/Services/AgentService.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Modules/Agents/Services/AgentService.php b/Modules/Agents/Services/AgentService.php index b38cc57..6c2cd07 100644 --- a/Modules/Agents/Services/AgentService.php +++ b/Modules/Agents/Services/AgentService.php @@ -146,7 +146,10 @@ class AgentService $myAgentDown = $this->modelAgentUser->byAgentRoot($agentId)->joinAgent(); if (!empty($input['start_date']) && !empty($input['end_date'])) { - $myAgentDown->betweenDates($input['start_date'], $input['end_date']); + $startDate = Carbon::createFromFormat('Y-m-d', $input['start_date']); + $endDate = Carbon::createFromFormat('Y-m-d', $input['end_date'])->addDay(); + + $myAgentDown->betweenDates($startDate->toDateString(), $endDate->toDateString()); } if (!empty($input['keyword'])) { $myAgentDown->searchAgentName($input['keyword']); @@ -232,21 +235,29 @@ class AgentService } } $agentId = $myAgentInfo->id; + //init query $myAgentDown = $this->modelAgentUser->byParentPath($agentId)->joinAgent(); + //condition startdate & enddate if (!empty($input['start_date']) && !empty($input['end_date'])) { - $myAgentDown->betweenDates($input['start_date'], $input['end_date']); + $startDate = Carbon::createFromFormat('Y-m-d', $input['start_date']); + $endDate = Carbon::createFromFormat('Y-m-d', $input['end_date'])->addDay(); + + $myAgentDown->betweenDates($startDate->toDateString(), $endDate->toDateString()); } + //condition keyword search if (!empty($input['keyword'])) { $myAgentDown->searchAgentName($input['keyword']); } if (!empty($input['grant'])) { $myAgentDown->onlyGrant($input['grant']); } + //execute query get list $listAgentGet = $myAgentDown->get(); $finalData = []; if (!empty($listAgentGet)) { $listAgentById = []; + //array by agent_id and get parent agent foreach ($listAgentGet as $kAgent) { // get parent id by path $kAgent->grant_parent_id = $this->getParentAgent($kAgent->parent_path);