NEW LIST AGENT FOR USER

main
nocode 1 year ago
parent 9dd104246f
commit bb1584c1ba
  1. 15
      Modules/Agents/Services/AgentService.php

@ -146,7 +146,10 @@ class AgentService
$myAgentDown = $this->modelAgentUser->byAgentRoot($agentId)->joinAgent(); $myAgentDown = $this->modelAgentUser->byAgentRoot($agentId)->joinAgent();
if (!empty($input['start_date']) && !empty($input['end_date'])) { 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'])) { if (!empty($input['keyword'])) {
$myAgentDown->searchAgentName($input['keyword']); $myAgentDown->searchAgentName($input['keyword']);
@ -232,21 +235,29 @@ class AgentService
} }
} }
$agentId = $myAgentInfo->id; $agentId = $myAgentInfo->id;
//init query
$myAgentDown = $this->modelAgentUser->byParentPath($agentId)->joinAgent(); $myAgentDown = $this->modelAgentUser->byParentPath($agentId)->joinAgent();
//condition startdate & enddate
if (!empty($input['start_date']) && !empty($input['end_date'])) { 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'])) { if (!empty($input['keyword'])) {
$myAgentDown->searchAgentName($input['keyword']); $myAgentDown->searchAgentName($input['keyword']);
} }
if (!empty($input['grant'])) { if (!empty($input['grant'])) {
$myAgentDown->onlyGrant($input['grant']); $myAgentDown->onlyGrant($input['grant']);
} }
//execute query get list
$listAgentGet = $myAgentDown->get(); $listAgentGet = $myAgentDown->get();
$finalData = []; $finalData = [];
if (!empty($listAgentGet)) { if (!empty($listAgentGet)) {
$listAgentById = []; $listAgentById = [];
//array by agent_id and get parent agent
foreach ($listAgentGet as $kAgent) { foreach ($listAgentGet as $kAgent) {
// get parent id by path // get parent id by path
$kAgent->grant_parent_id = $this->getParentAgent($kAgent->parent_path); $kAgent->grant_parent_id = $this->getParentAgent($kAgent->parent_path);

Loading…
Cancel
Save