Skip to content
This repository has been archived by the owner on Jun 22, 2022. It is now read-only.

feat: Department support add into Report #444

Merged
merged 2 commits into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/Http/Controllers/DepartmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Http\Requests\UpdateDepartmentRequest;
use App\Models\Department;
use App\Queries\DepartmentDataTable;
use App\Repositories\ClientRepository;
use App\Repositories\DepartmentRepository;
use DataTables;
use Exception;
Expand Down Expand Up @@ -100,4 +101,17 @@ public function destroy(Department $department)

return $this->sendSuccess('Department deleted successfully.');
}

/**
* @param Request $request
* @param ClientRepository $clientRepository
*
* @return JsonResponse
*/
public function clients(Request $request, ClientRepository $clientRepository)
{
$projects = $clientRepository->getClientList($request->get('department_id', null));

return $this->sendResponse($projects, 'Clients retrieved successfully.');
}
}
26 changes: 18 additions & 8 deletions app/Http/Controllers/ReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Models\User;
use App\Queries\ReportDataTable;
use App\Repositories\ClientRepository;
use App\Repositories\DepartmentRepository;
use App\Repositories\ProjectRepository;
use App\Repositories\ReportRepository;
use App\Repositories\TagRepository;
Expand All @@ -17,11 +18,12 @@
use DataTables;
use Exception;
use Flash;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Redirector;
use Response;
use Illuminate\View\View;

/**
* Class ReportController.
Expand All @@ -43,18 +45,23 @@ class ReportController extends AppBaseController
/** @var ProjectRepository */
private $projectRepo;

/** @var DepartmentRepository */
private $departmentRepo;

public function __construct(
ReportRepository $reportRepo,
UserRepository $userRepository,
ProjectRepository $projectRepository,
ClientRepository $clientRepository,
TagRepository $tagRepository
TagRepository $tagRepository,
DepartmentRepository $departmentRepository
) {
$this->reportRepository = $reportRepo;
$this->userRepo = $userRepository;
$this->clientRepo = $clientRepository;
$this->tagRepo = $tagRepository;
$this->projectRepo = $projectRepository;
$this->departmentRepo = $departmentRepository;
}

/**
Expand All @@ -64,7 +71,7 @@ public function __construct(
*
* @throws Exception
*
* @return Response
* @return Factory|View
*/
public function index(Request $request)
{
Expand All @@ -79,14 +86,15 @@ public function index(Request $request)
/**
* Show the form for creating a new Report.
*
* @return Response
* @return Factory|View
*/
public function create()
{
$data['tags'] = $this->tagRepo->getTagList();
$data['users'] = $this->userRepo->getUserList();
$data['clients'] = $this->clientRepo->getClientList();
$data['projects'] = $this->projectRepo->getProjectsList();
$data['departments'] = $this->departmentRepo->getDepartmentList();

return view('reports.create', $data);
}
Expand All @@ -96,7 +104,7 @@ public function create()
*
* @param CreateReportRequest $request
*
* @return Response
* @return RedirectResponse|Redirector
*/
public function store(CreateReportRequest $request)
{
Expand All @@ -114,7 +122,7 @@ public function store(CreateReportRequest $request)
*
* @param Report $report
*
* @return Response
* @return Factory|View
*/
public function show(Report $report)
{
Expand All @@ -136,7 +144,7 @@ public function show(Report $report)
*
* @param Report $report
*
* @return Response
* @return Factory|View
*/
public function edit(Report $report)
{
Expand All @@ -146,10 +154,12 @@ public function edit(Report $report)
$data['tagIds'] = $this->reportRepository->getTagIds($id);
$data['userIds'] = $this->reportRepository->getUserIds($id);
$data['clientId'] = $this->reportRepository->getClientId($id);
$data['departmentId'] = $this->reportRepository->getDepartmentId($id);
$data['projects'] = $this->projectRepo->getProjectsList($data['clientId']);
$data['users'] = $this->userRepo->getUserList($data['projectIds']);
$data['clients'] = $this->clientRepo->getClientList();
$data['tags'] = $this->tagRepo->getTagList();
$data['departments'] = $this->departmentRepo->getDepartmentList();

return view('reports.edit')->with($data);
}
Expand All @@ -162,7 +172,7 @@ public function edit(Report $report)
*
* @throws Exception
*
* @return Response
* @return RedirectResponse|Redirector
*/
public function update(Report $report, UpdateReportRequest $request)
{
Expand Down
5 changes: 5 additions & 0 deletions app/Models/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
* @method static BuilderAlias|Client whereDeletedBy($value)
* @method static Builder|Client withTrashed()
* @method static Builder|Client withoutTrashed()
*
* @property int|null $department_id
* @property-read \App\Models\Department|null $department
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Client whereDepartmentId($value)
*/
class Client extends Model
{
Expand Down
12 changes: 10 additions & 2 deletions app/Repositories/ClientRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,19 @@ public function model()
/**
* get clients.
*
* @param null $departmentId
*
* @return Collection
*/
public function getClientList()
public function getClientList($departmentId = null)
{
return Client::orderBy('name')->pluck('name', 'id');
$query = Client::orderBy('name');

if (!empty($departmentId)) {
$query->where('department_id', '=', $departmentId);
}

return $query->pluck('name', 'id');
}

/**
Expand Down
15 changes: 15 additions & 0 deletions app/Repositories/DepartmentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Repositories;

use App\Models\Department;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Collection;

/**
* Class DepartmentRepository.
Expand Down Expand Up @@ -35,4 +37,17 @@ public function model()
{
return Department::class;
}

/**
* get Departments.
*
* @return Collection
*/
public function getDepartmentList()
{
/** @var Builder|Department $query */
$query = Department::orderBy('name');

return $query->pluck('name', 'id');
}
}
Loading