diff --git a/app/Console/Commands/GenerateScaffoldingCommand.php b/app/Console/Commands/GenerateScaffoldingCommand.php new file mode 100644 index 000000000..007acf46d --- /dev/null +++ b/app/Console/Commands/GenerateScaffoldingCommand.php @@ -0,0 +1,111 @@ +module = $this->argument('module').DIRECTORY_SEPARATOR; + $this->name = $this->argument('name'); + + if ($this->option('submodule')) { + $this->submodule = $this->option('submodule').DIRECTORY_SEPARATOR; + } + + Artisan::call('make:model', [ + 'name' => 'Model\\'.$this->module.$this->submodule.$this->name, + '-m' => true, + ]); + + $this->line('created '.$this->name.' model'); + + Artisan::call('make:controller', [ + 'name' => 'Api\\'.$this->module.$this->submodule.$this->name.'Controller', + '-r' => true, + ]); + + $this->line('created '.$this->name.' controller'); + + Artisan::call('make:resource', [ + 'name' => $this->module.$this->submodule.$this->name.'\\'.$this->name.'Resource', + ]); + + $this->line('created '.$this->name.' resource'); + + Artisan::call('make:resource', [ + 'name' => $this->module.$this->submodule.$this->name.'\\'.$this->name.'Collection', + '--collection' => true, + ]); + + $this->line('created '.$this->name.' collection'); + + Artisan::call('make:request', [ + 'name' => $this->module.$this->submodule.$this->name.'\\Store'.$this->name.'Request', + ]); + + $this->line('created '.$this->name.' store request'); + + Artisan::call('make:request', [ + 'name' => $this->module.$this->submodule.$this->name.'\\Update'.$this->name.'Request', + ]); + + $this->line('created '.$this->name.' update request'); + + Artisan::call('make:factory', [ + 'name' => $this->name.'Factory', + ]); + + $this->line('created '.$this->name.' factory'); + + Artisan::call('make:test', [ + 'name' => $this->module.$this->submodule.$this->name.'Test', + ]); + + $this->line('created '.$this->name.' test class'); + + Artisan::call('make:test', [ + 'name' => $this->module.$this->submodule.$this->name.'ValidationTest', + ]); + + $this->line('created '.$this->name.' validation test class'); + } +} diff --git a/app/Console/Commands/ScaffoldingMasterCommand.php b/app/Console/Commands/ScaffoldingMasterCommand.php deleted file mode 100644 index 6e0f7d401..000000000 --- a/app/Console/Commands/ScaffoldingMasterCommand.php +++ /dev/null @@ -1,100 +0,0 @@ -argument('name'); - - Artisan::call('make:model', [ - 'name' => 'Model\\Master\\'.$name, - '-m' => true, - ]); - - $this->info('created '.$name.' model'); - - Artisan::call('make:controller', [ - 'name' => 'Api\\Master\\'.$name.'Controller', - '-r' => true, - ]); - - $this->info('created '.$name.' controller'); - - Artisan::call('make:resource', [ - 'name' => 'Master\\'.$name.'\\'.$name.'Resource', - ]); - - $this->info('created '.$name.' resource'); - - Artisan::call('make:resource', [ - 'name' => 'Master\\'.$name.'\\'.$name.'Collection', - '--collection' => true, - ]); - - $this->info('created '.$name.' collection'); - - Artisan::call('make:request', [ - 'name' => 'Master\\'.$name.'\\Store'.$name.'Request', - ]); - - $this->info('created '.$name.' store request'); - - Artisan::call('make:request', [ - 'name' => 'Master\\'.$name.'\\Update'.$name.'Request', - ]); - - $this->info('created '.$name.' update request'); - - Artisan::call('make:factory', [ - 'name' => $name.'Factory', - ]); - - $this->info('created '.$name.' factory'); - - Artisan::call('make:test', [ - 'name' => 'Master\\'.$name.'RESTTest', - ]); - - $this->info('created '.$name.' REST test class'); - - Artisan::call('make:test', [ - 'name' => 'Master\\'.$name.'ValidationTest', - ]); - - $this->info('created '.$name.' validation test class'); - } -} diff --git a/app/Console/Commands/SeedDummyDatabase.php b/app/Console/Commands/SeedDummyDatabase.php new file mode 100644 index 000000000..c8bc1807c --- /dev/null +++ b/app/Console/Commands/SeedDummyDatabase.php @@ -0,0 +1,57 @@ + 'mysql', + '--class' => 'DummyDatabaseSeeder', + ]); + + $tenantSubdomain = $this->argument('tenant_subdomain'); + + config()->set('database.connections.tenant.database', $tenantSubdomain); + DB::connection('tenant')->reconnect(); + + Artisan::call('db:seed', [ + '--database' => 'tenant', + '--class' => 'DummyTenantDatabaseSeeder', + ]); + } +} diff --git a/app/Console/Commands/SetupTenantDatabase.php b/app/Console/Commands/SetupTenantDatabase.php index f9596083b..f4b52fe25 100644 --- a/app/Console/Commands/SetupTenantDatabase.php +++ b/app/Console/Commands/SetupTenantDatabase.php @@ -3,6 +3,7 @@ namespace App\Console\Commands; use Illuminate\Console\Command; +use Symfony\Component\Process\Process; use Illuminate\Support\Facades\Artisan; class SetupTenantDatabase extends Command @@ -40,6 +41,13 @@ public function handle() { $tenantSubdomain = $this->argument('tenant_subdomain'); + $process = new Process('mysql -u '.env('DB_TENANT_USERNAME').' -p'.env('DB_TENANT_PASSWORD').' -e "drop database if exists '.$tenantSubdomain.'"'); + $process->run(); + + // create new database + $process = new Process('mysql -u '.env('DB_TENANT_USERNAME').' -p'.env('DB_TENANT_PASSWORD').' -e "create database '.$tenantSubdomain.'"'); + $process->run(); + config()->set('database.connections.tenant.database', $tenantSubdomain); Artisan::call('migrate:refresh', [ diff --git a/app/Console/Commands/SetupTenantDatabaseSeeder.php b/app/Console/Commands/SetupTenantDatabaseSeeder.php index 472f2b902..ec8412a5d 100644 --- a/app/Console/Commands/SetupTenantDatabaseSeeder.php +++ b/app/Console/Commands/SetupTenantDatabaseSeeder.php @@ -41,7 +41,7 @@ public function handle() { $tenantSubdomain = $this->argument('tenant_subdomain'); - config()->set('database.connections.tenant.database', 'point_'.$tenantSubdomain); + config()->set('database.connections.tenant.database', $tenantSubdomain); DB::connection('tenant')->reconnect(); Artisan::call('db:seed', [ diff --git a/app/Http/Controllers/Api/HumanResource/Kpi/KpiCategoryController.php b/app/Http/Controllers/Api/HumanResource/Kpi/KpiCategoryController.php new file mode 100644 index 000000000..125be6b87 --- /dev/null +++ b/app/Http/Controllers/Api/HumanResource/Kpi/KpiCategoryController.php @@ -0,0 +1,88 @@ +input('limit') ?? 0; + + return new KpiCategoryCollection(KpiCategory::paginate($limit)); + } + + /** + * Store a newly created resource in storage. + * + * @param \App\Http\Requests\HumanResource\Kpi\KpiCategory\StoreKpiCategoryRequest $request + * + * @return \App\Http\Resources\HumanResource\Kpi\KpiCategory\KpiCategoryResource + */ + public function store(StoreKpiCategoryRequest $request) + { + $kpiCategory = new KpiCategory(); + $kpiCategory->name = $request->input('name'); + $kpiCategory->date = $request->input('date'); + $kpiCategory->person_id = $request->input('person_id'); + $kpiCategory->save(); + + return new KpiCategoryResource($kpiCategory); + } + + /** + * Display the specified resource. + * + * @param int $id + * + * @return \App\Http\Resources\HumanResource\Kpi\KpiCategory\KpiCategoryResource + */ + public function show($id) + { + return new KpiCategoryResource(KpiCategory::findOrFail($id)); + } + + /** + * Update the specified resource in storage. + * + * @param \App\Http\Requests\HumanResource\Kpi\KpiCategory\UpdateKpiCategoryRequest $request + * @param int $id + * + * @return \App\Http\Resources\HumanResource\Kpi\KpiCategory\KpiCategoryResource + */ + public function update(UpdateKpiCategoryRequest $request, $id) + { + $kpiCategory = KpiCategory::findOrFail($id); + $kpiCategory->name = $request->input('name'); + $kpiCategory->date = $request->input('date'); + $kpiCategory->person_id = $request->input('person_id'); + $kpiCategory->save(); + + return new KpiCategoryResource($kpiCategory); + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function destroy($id) + { + KpiCategory::findOrFail($id)->delete(); + + return response(null, 204); + } +} diff --git a/app/Http/Controllers/Api/HumanResource/Kpi/KpiController.php b/app/Http/Controllers/Api/HumanResource/Kpi/KpiController.php new file mode 100644 index 000000000..f3b44b743 --- /dev/null +++ b/app/Http/Controllers/Api/HumanResource/Kpi/KpiController.php @@ -0,0 +1,96 @@ +input('limit') ?? 0; + + return new KpiCollection(Kpi::paginate($limit)); + } + + /** + * Store a newly created resource in storage. + * + * @param \App\Http\Requests\HumanResource\Kpi\Kpi\StoreKpiRequest $request + * + * @return \App\Http\Resources\HumanResource\Kpi\Kpi\KpiResource + */ + public function store(StoreKpiRequest $request) + { + $kpi = new Kpi(); + $kpi->kpi_group_id = $request->input('kpi_group_id'); + $kpi->indicator = $request->input('indicator'); + $kpi->weight = $request->input('weight'); + $kpi->target = $request->input('target'); + $kpi->score = $request->input('score'); + $kpi->score_percentage = $request->input('score_percentage'); + $kpi->save(); + + return new KpiResource($kpi); + } + + /** + * Display the specified resource. + * + * @param int $id + * + * @return \App\Http\Resources\HumanResource\Kpi\Kpi\KpiResource + */ + public function show($id) + { + return new KpiResource(Kpi::findOrFail($id)); + } + + /** + * Update the specified resource in storage. + * + * @param \App\Http\Requests\HumanResource\Kpi\Kpi\UpdateKpiRequest $request + * @param int $id + * + * @return \App\Http\Resources\HumanResource\Kpi\Kpi\KpiResource + */ + public function update(UpdateKpiRequest $request, $id) + { + $kpi = Kpi::findOrFail($id); + $kpi->kpi_group_id = $request->input('kpi_group_id'); + $kpi->indicator = $request->input('indicator'); + $kpi->weight = $request->input('weight'); + $kpi->target = $request->input('target'); + $kpi->score = $request->input('score'); + $kpi->score_percentage = $request->input('score_percentage'); + $kpi->save(); + + return new KpiResource($kpi); + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function destroy($id) + { + Kpi::findOrFail($id)->delete(); + + return response(null, 204); + } +} diff --git a/app/Http/Controllers/Api/HumanResource/Kpi/KpiGroupController.php b/app/Http/Controllers/Api/HumanResource/Kpi/KpiGroupController.php new file mode 100644 index 000000000..2ed4ea74d --- /dev/null +++ b/app/Http/Controllers/Api/HumanResource/Kpi/KpiGroupController.php @@ -0,0 +1,86 @@ +input('limit') ?? 0; + + return new KpiGroupCollection(KpiGroup::paginate($limit)); + } + + /** + * Store a newly created resource in storage. + * + * @param \App\Http\Requests\HumanResource\Kpi\KpiGroup\StoreKpiGroupRequest $request + * + * @return \App\Http\Resources\HumanResource\Kpi\KpiGroup\KpiGroupResource + */ + public function store(StoreKpiGroupRequest $request) + { + $kpiGroup = new KpiGroup(); + $kpiGroup->kpi_category_id = $request->input('kpi_category_id'); + $kpiGroup->name = $request->input('name'); + $kpiGroup->save(); + + return new KpiGroupResource($kpiGroup); + } + + /** + * Display the specified resource. + * + * @param int $id + * + * @return \App\Http\Resources\HumanResource\Kpi\KpiGroup\KpiGroupResource + */ + public function show($id) + { + return new KpiGroupResource(KpiGroup::findOrFail($id)); + } + + /** + * Update the specified resource in storage. + * + * @param \App\Http\Requests\HumanResource\Kpi\KpiGroup\UpdateKpiGroupRequest $request + * @param int $id + * + * @return \App\Http\Resources\HumanResource\Kpi\KpiGroup\KpiGroupResource + */ + public function update(UpdateKpiGroupRequest $request, $id) + { + $kpiGroup = KpiGroup::findOrFail($id); + $kpiGroup->kpi_category_id = $request->input('kpi_category_id'); + $kpiGroup->name = $request->input('name'); + $kpiGroup->save(); + + return new KpiGroupResource($kpiGroup); + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function destroy($id) + { + KpiGroup::findOrFail($id)->delete(); + + return response(null, 204); + } +} diff --git a/app/Http/Controllers/Api/HumanResource/Kpi/KpiResultController.php b/app/Http/Controllers/Api/HumanResource/Kpi/KpiResultController.php new file mode 100644 index 000000000..fb1978a84 --- /dev/null +++ b/app/Http/Controllers/Api/HumanResource/Kpi/KpiResultController.php @@ -0,0 +1,92 @@ +input('limit') ?? 0; + + return new KpiResultCollection(KpiResult::paginate($limit)); + } + + /** + * Store a newly created resource in storage. + * + * @param \App\Http\Requests\HumanResource\Kpi\KpiResult\StoreKpiResultRequest $request + * + * @return \App\Http\Resources\HumanResource\Kpi\KpiResult\KpiResultResource + */ + public function store(StoreKpiResultRequest $request) + { + $kpiResult = new KpiResult(); + $kpiResult->score_min = $request->input('score_min'); + $kpiResult->score_max = $request->input('score_max'); + $kpiResult->criteria = $request->input('criteria'); + $kpiResult->notes = $request->input('notes'); + $kpiResult->save(); + + return new KpiResultResource($kpiResult); + } + + /** + * Display the specified resource. + * + * @param int $id + * + * @return \App\Http\Resources\HumanResource\Kpi\KpiResult\KpiResultResource + */ + public function show($id) + { + return new KpiResultResource(KpiResult::findOrFail($id)); + } + + /** + * Update the specified resource in storage. + * + * @param \App\Http\Requests\HumanResource\Kpi\KpiResult\UpdateKpiResultRequest $request + * @param int $id + * + * @return \App\Http\Resources\HumanResource\Kpi\KpiResult\KpiResultResource + */ + public function update(UpdateKpiResultRequest $request, $id) + { + $kpiResult = KpiResult::findOrFail($id); + $kpiResult->score_min = $request->input('score_min'); + $kpiResult->score_max = $request->input('score_max'); + $kpiResult->criteria = $request->input('criteria'); + $kpiResult->notes = $request->input('notes'); + $kpiResult->save(); + + return new KpiResultResource($kpiResult); + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function destroy($id) + { + KpiResult::findOrFail($id)->delete(); + + return response(null, 204); + } +} diff --git a/app/Http/Controllers/Api/HumanResource/Kpi/KpiScoreController.php b/app/Http/Controllers/Api/HumanResource/Kpi/KpiScoreController.php new file mode 100644 index 000000000..6dcbdde48 --- /dev/null +++ b/app/Http/Controllers/Api/HumanResource/Kpi/KpiScoreController.php @@ -0,0 +1,114 @@ +input('limit') ?? 0; + + return new KpiScoreCollection(KpiScore::paginate($limit)); + } + + /** + * Store a newly created resource in storage. + * + * @param \App\Http\Requests\HumanResource\Kpi\KpiScore\StoreKpiScoreRequest $request + * + * @return \App\Http\Resources\HumanResource\Kpi\KpiScore\KpiScoreResource + */ + public function store(StoreKpiScoreRequest $request) + { + $kpiScore = DB::transaction(function () use ($request) { + $kpiScore = new KpiScore(); + $kpiScore->kpi_template_indicator_id = $request->input('kpi_template_indicator_id'); + $kpiScore->save(); + + for ($i = 0; $i < count($request->get('description')); $i++) { + $kpiScoreDetail = new KpiScoreDetail(); + $kpiScoreDetail->kpi_score_id = $kpiScore->id; + $kpiScoreDetail->description = $request->get('description')[$i]; + $kpiScoreDetail->score = $request->get('score')[$i]; + $kpiScoreDetail->save(); + } + + return $kpiScore; + }); + + return new KpiScoreResource($kpiScore); + } + + /** + * Display the specified resource. + * + * @param int $id + * + * @return \App\Http\Resources\HumanResource\Kpi\KpiScore\KpiScoreResource + */ + public function show($id) + { + return new KpiScoreResource(KpiScore::findOrFail($id)); + } + + /** + * Update the specified resource in storage. + * + * @param \App\Http\Requests\HumanResource\Kpi\KpiScore\UpdateKpiScoreRequest $request + * @param int $id + * + * @return \App\Http\Resources\HumanResource\Kpi\KpiScore\KpiScoreResource + */ + public function update(UpdateKpiScoreRequest $request, $id) + { + $kpiScore = DB::transaction(function () use ($request, $id) { + $kpiScore = KpiScore::findOrFail($id); + $kpiScore->kpi_template_indicator_id = $request->input('kpi_template_indicator_id'); + $kpiScore->save(); + + // update kpi score detail + for ($i = 0; $i < count($request->get('description')); $i++) { + $kpiScoreDetail = KpiScoreDetail::findOrFail($request->get('kpi_score_detail_id')[$i]); + $kpiScoreDetail->kpi_score_id = $kpiScore->id; + $kpiScoreDetail->description = $request->get('description')[$i]; + $kpiScoreDetail->score = $request->get('score')[$i]; + $kpiScoreDetail->save(); + } + + // remove kpi score detail + KpiScoreDetail::whereNotIn('id', $request->get('kpi_score_detail_id'))->delete(); + + return $kpiScore; + }); + + return new KpiScoreResource($kpiScore); + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function destroy($id) + { + KpiScore::findOrFail($id)->delete(); + + return response(null, 204); + } +} diff --git a/app/Http/Controllers/Api/HumanResource/Kpi/KpiTemplateController.php b/app/Http/Controllers/Api/HumanResource/Kpi/KpiTemplateController.php new file mode 100644 index 000000000..69e50c5ad --- /dev/null +++ b/app/Http/Controllers/Api/HumanResource/Kpi/KpiTemplateController.php @@ -0,0 +1,86 @@ +input('limit') ?? 0; + + return new KpiTemplateCollection(KpiTemplate::paginate($limit)); + } + + /** + * Store a newly created resource in storage. + * + * @param \App\Http\Requests\HumanResource\Kpi\KpiTemplate\StoreKpiTemplateRequest $request + * + * @return \App\Http\Resources\HumanResource\Kpi\KpiTemplate\KpiTemplateResource + */ + public function store(StoreKpiTemplateRequest $request) + { + $kpiTemplate = new KpiTemplate(); + $kpiTemplate->name = $request->input('name'); + $kpiTemplate->save(); + + return new KpiTemplateResource($kpiTemplate); + } + + /** + * Display the specified resource. + * + * @param int $id + * + * @return \App\Http\Resources\HumanResource\Kpi\KpiTemplate\KpiTemplateResource + */ + public function show($id) + { + return new KpiTemplateResource(KpiTemplate::findOrFail($id)); + } + + /** + * Update the specified resource in storage. + * + * @param \App\Http\Requests\HumanResource\Kpi\KpiTemplate\UpdateKpiTemplateRequest $request + * @param int $id + * + * @return \App\Http\Resources\HumanResource\Kpi\KpiTemplate\KpiTemplateResource + */ + public function update(UpdateKpiTemplateRequest $request, $id) + { + $kpiTemplate = KpiTemplate::findOrFail($id); + $kpiTemplate->name = $request->input('name'); + $kpiTemplate->save(); + + return new KpiTemplateResource($kpiTemplate); + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function destroy($id) + { + KpiTemplate::findOrFail($id)->delete(); + + return response(null, 204); + } +} diff --git a/app/Http/Controllers/Api/HumanResource/Kpi/KpiTemplateGroupController.php b/app/Http/Controllers/Api/HumanResource/Kpi/KpiTemplateGroupController.php new file mode 100644 index 000000000..43952e098 --- /dev/null +++ b/app/Http/Controllers/Api/HumanResource/Kpi/KpiTemplateGroupController.php @@ -0,0 +1,88 @@ +input('limit') ?? 0; + + return new KpiTemplateGroupCollection(KpiTemplateGroup::paginate($limit)); + } + + /** + * Store a newly created resource in storage. + * + * @param \App\Http\Requests\HumanResource\Kpi\KpiTemplateGroup\StoreKpiTemplateGroupRequest $request + * + * @return \App\Http\Resources\HumanResource\Kpi\KpiTemplateGroup\KpiTemplateGroupResource + */ + public function store(StoreKpiTemplateGroupRequest $request) + { + $kpiTemplateGroup = new KpiTemplateGroup(); + $kpiTemplateGroup->kpi_template_id = $request->input('kpi_template_id'); + $kpiTemplateGroup->name = $request->input('name'); + $kpiTemplateGroup->save(); + + return new KpiTemplateGroupResource($kpiTemplateGroup); + } + + /** + * Display the specified resource. + * + * @param int $id + * + * @return \App\Http\Resources\HumanResource\Kpi\KpiTemplateGroup\KpiTemplateGroupResource + */ + public function show($id) + { + return new KpiTemplateGroupResource(KpiTemplateGroup::findOrFail($id)); + } + + /** + * Update the specified resource in storage. + * + * @param \App\Http\Requests\HumanResource\Kpi\KpiTemplateGroup\UpdateKpiTemplateGroupRequest $request + * @param int $id + * + * @return \App\Http\Resources\HumanResource\Kpi\KpiTemplateGroup\KpiTemplateGroupResource + */ + public function update(UpdateKpiTemplateGroupRequest $request, $id) + { + $kpiTemplateGroup = KpiTemplateGroup::findOrFail($id); + $kpiTemplateGroup->kpi_template_id = $request->input('kpi_template_id'); + $kpiTemplateGroup->name = $request->input('name'); + $kpiTemplateGroup->save(); + + return new KpiTemplateGroupResource($kpiTemplateGroup); + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function destroy($id) + { + KpiTemplateGroup::findOrFail($id)->delete(); + + return response(null, 204); + } +} diff --git a/app/Http/Controllers/Api/HumanResource/Kpi/KpiTemplateIndicatorController.php b/app/Http/Controllers/Api/HumanResource/Kpi/KpiTemplateIndicatorController.php new file mode 100644 index 000000000..ad3002d19 --- /dev/null +++ b/app/Http/Controllers/Api/HumanResource/Kpi/KpiTemplateIndicatorController.php @@ -0,0 +1,92 @@ +input('limit') ?? 0; + + return new KpiTemplateIndicatorCollection(KpiTemplateIndicator::paginate($limit)); + } + + /** + * Store a newly created resource in storage. + * + * @param \App\Http\Requests\HumanResource\Kpi\KpiTemplateIndicator\StoreKpiTemplateIndicatorRequest $request + * + * @return \App\Http\Resources\HumanResource\Kpi\KpiTemplateIndicator\KpiTemplateIndicatorResource + */ + public function store(StoreKpiTemplateIndicatorRequest $request) + { + $kpiTemplateIndicator = new KpiTemplateIndicator(); + $kpiTemplateIndicator->kpi_template_group_id = $request->input('kpi_template_group_id'); + $kpiTemplateIndicator->name = $request->input('name'); + $kpiTemplateIndicator->weight = $request->input('weight'); + $kpiTemplateIndicator->target = $request->input('target'); + $kpiTemplateIndicator->save(); + + return new KpiTemplateIndicatorResource($kpiTemplateIndicator); + } + + /** + * Display the specified resource. + * + * @param int $id + * + * @return \App\Http\Resources\HumanResource\Kpi\KpiTemplateIndicator\KpiTemplateIndicatorResource + */ + public function show($id) + { + return new KpiTemplateIndicatorResource(KpiTemplateIndicator::findOrFail($id)); + } + + /** + * Update the specified resource in storage. + * + * @param \App\Http\Requests\HumanResource\Kpi\KpiTemplateIndicator\UpdateKpiTemplateIndicatorRequest $request + * @param int $id + * + * @return \App\Http\Resources\HumanResource\Kpi\KpiTemplateIndicator\KpiTemplateIndicatorResource + */ + public function update(UpdateKpiTemplateIndicatorRequest $request, $id) + { + $kpiTemplateIndicator = KpiTemplateIndicator::findOrFail($id); + $kpiTemplateIndicator->kpi_template_group_id = $request->input('kpi_template_group_id'); + $kpiTemplateIndicator->name = $request->input('name'); + $kpiTemplateIndicator->weight = $request->input('weight'); + $kpiTemplateIndicator->target = $request->input('target'); + $kpiTemplateIndicator->save(); + + return new KpiTemplateIndicatorResource($kpiTemplateIndicator); + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function destroy($id) + { + KpiTemplateIndicator::findOrFail($id)->delete(); + + return response(null, 204); + } +} diff --git a/app/Http/Controllers/Api/Master/PersonCategoryController.php b/app/Http/Controllers/Api/Master/PersonCategoryController.php index 4658a9fd7..76c180817 100644 --- a/app/Http/Controllers/Api/Master/PersonCategoryController.php +++ b/app/Http/Controllers/Api/Master/PersonCategoryController.php @@ -15,7 +15,9 @@ class PersonCategoryController extends ApiController /** * Display a listing of the resource. * - * @return \Illuminate\Http\Response + * @param \Illuminate\Http\Request $request + * + * @return \App\Http\Resources\Master\PersonCategory\PersonCategoryCollection */ public function index(Request $request) { @@ -28,7 +30,8 @@ public function index(Request $request) * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\Response + * + * @return \App\Http\Resources\Master\PersonCategory\PersonCategoryResource */ public function store(StorePersonCategoryRequest $request) { @@ -44,7 +47,8 @@ public function store(StorePersonCategoryRequest $request) * Display the specified resource. * * @param int $id - * @return \Illuminate\Http\Response + * + * @return \App\Http\Resources\Master\PersonCategory\PersonCategoryResource */ public function show($id) { @@ -56,7 +60,8 @@ public function show($id) * * @param \Illuminate\Http\Request $request * @param int $id - * @return \Illuminate\Http\Response + * + * @return \App\Http\Resources\Master\PersonCategory\PersonCategoryResource */ public function update(UpdatePersonCategoryRequest $request, $id) { diff --git a/app/Http/Controllers/Api/Master/PersonController.php b/app/Http/Controllers/Api/Master/PersonController.php index 6c35918bc..8fb2e5e27 100644 --- a/app/Http/Controllers/Api/Master/PersonController.php +++ b/app/Http/Controllers/Api/Master/PersonController.php @@ -15,7 +15,9 @@ class PersonController extends ApiController /** * Display a listing of the resource. * - * @return \Illuminate\Http\Response + * @param \Illuminate\Http\Request $request + * + * @return \App\Http\Resources\Master\Person\PersonCollection */ public function index(Request $request) { @@ -28,7 +30,8 @@ public function index(Request $request) * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\Response + * + * @return \App\Http\Resources\Master\Person\PersonResource */ public function store(StorePersonRequest $request) { @@ -50,7 +53,8 @@ public function store(StorePersonRequest $request) * Display the specified resource. * * @param int $id - * @return \Illuminate\Http\Response + * + * @return \App\Http\Resources\Master\Person\PersonResource */ public function show($id) { @@ -62,7 +66,8 @@ public function show($id) * * @param \Illuminate\Http\Request $request * @param int $id - * @return \Illuminate\Http\Response + * + * @return \App\Http\Resources\Master\Person\PersonResource */ public function update(UpdatePersonRequest $request, $id) { diff --git a/app/Http/Controllers/Api/Master/PersonGroupController.php b/app/Http/Controllers/Api/Master/PersonGroupController.php index a1b39742d..3bb103a64 100644 --- a/app/Http/Controllers/Api/Master/PersonGroupController.php +++ b/app/Http/Controllers/Api/Master/PersonGroupController.php @@ -15,7 +15,9 @@ class PersonGroupController extends ApiController /** * Display a listing of the resource. * - * @return \Illuminate\Http\Response + * @param \Illuminate\Http\Request $request + * + * @return \App\Http\Resources\Master\PersonGroup\PersonGroupCollection */ public function index(Request $request) { @@ -28,7 +30,8 @@ public function index(Request $request) * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\Response + * + * @return \App\Http\Resources\Master\PersonGroup\PersonGroupResource */ public function store(StorePersonGroupRequest $request) { @@ -44,7 +47,8 @@ public function store(StorePersonGroupRequest $request) * Display the specified resource. * * @param int $id - * @return \Illuminate\Http\Response + * + * @return \App\Http\Resources\Master\PersonGroup\PersonGroupResource */ public function show($id) { @@ -56,7 +60,8 @@ public function show($id) * * @param \Illuminate\Http\Request $request * @param int $id - * @return \Illuminate\Http\Response + * + * @return \App\Http\Resources\Master\PersonGroup\PersonGroupResource */ public function update(UpdatePersonGroupRequest $request, $id) { diff --git a/app/Http/Controllers/Api/Master/UserController.php b/app/Http/Controllers/Api/Master/UserController.php index 40d8e5e40..d6b27c8ce 100644 --- a/app/Http/Controllers/Api/Master/UserController.php +++ b/app/Http/Controllers/Api/Master/UserController.php @@ -16,7 +16,8 @@ class UserController extends ApiController * Display a listing of the resource. * * @param \Illuminate\Http\Request $request - * @return \App\Http\Resources\UserCollection + * + * @return \App\Http\Resources\Master\User\UserCollection */ public function index(Request $request) { @@ -28,8 +29,9 @@ public function index(Request $request) /** * Store a newly created resource in storage. * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\Response + * @param \App\Http\Requests\Master\User\StoreUserRequest $request + * + * @return \App\Http\Resources\Master\User\UserResource */ public function store(StoreUserRequest $request) { @@ -46,7 +48,8 @@ public function store(StoreUserRequest $request) * Display the specified resource. * * @param int $id - * @return \Illuminate\Http\Response + * + * @return \App\Http\Resources\Master\User\UserResource */ public function show($id) { @@ -58,7 +61,8 @@ public function show($id) * * @param \Illuminate\Http\Request $request * @param int $id - * @return \Illuminate\Http\Response + * + * @return \App\Http\Resources\Master\User\UserResource */ public function update(UpdateUserRequest $request, $id) { diff --git a/app/Http/Controllers/Api/Master/WarehouseController.php b/app/Http/Controllers/Api/Master/WarehouseController.php index 8893dcca1..c5eec242a 100644 --- a/app/Http/Controllers/Api/Master/WarehouseController.php +++ b/app/Http/Controllers/Api/Master/WarehouseController.php @@ -15,7 +15,9 @@ class WarehouseController extends Controller /** * Display a listing of the resource. * - * @return \Illuminate\Http\Response + * @param \Illuminate\Http\Request $request + * + * @return \App\Http\Resources\Master\Warehouse\WarehouseCollection */ public function index(Request $request) { @@ -27,8 +29,9 @@ public function index(Request $request) /** * Store a newly created resource in storage. * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\Response + * @param \App\Http\Requests\Master\Warehouse\StoreWarehouseRequest $request + * + * @return \App\Http\Resources\Master\Warehouse\WarehouseResource */ public function store(StoreWarehouseRequest $request) { @@ -45,8 +48,9 @@ public function store(StoreWarehouseRequest $request) /** * Display the specified resource. * - * @param int $id - * @return \Illuminate\Http\Response + * @param int $id + * + * @return \App\Http\Resources\Master\Warehouse\WarehouseResource */ public function show($id) { @@ -58,7 +62,8 @@ public function show($id) * * @param \Illuminate\Http\Request $request * @param int $id - * @return \Illuminate\Http\Response + * + * @return \App\Http\Resources\Master\Warehouse\WarehouseResource */ public function update(UpdateWarehouseRequest $request, $id) { diff --git a/app/Http/Requests/HumanResource/Kpi/Kpi/StoreKpiRequest.php b/app/Http/Requests/HumanResource/Kpi/Kpi/StoreKpiRequest.php new file mode 100644 index 000000000..a82eeb07a --- /dev/null +++ b/app/Http/Requests/HumanResource/Kpi/Kpi/StoreKpiRequest.php @@ -0,0 +1,35 @@ + 'required', + 'indicator' => 'required', + 'weight' => 'required', + 'target' => 'required', + 'score' => 'required', + 'score_percentage' => 'required', + ]; + } +} diff --git a/app/Http/Requests/HumanResource/Kpi/Kpi/UpdateKpiRequest.php b/app/Http/Requests/HumanResource/Kpi/Kpi/UpdateKpiRequest.php new file mode 100644 index 000000000..12aaf7c69 --- /dev/null +++ b/app/Http/Requests/HumanResource/Kpi/Kpi/UpdateKpiRequest.php @@ -0,0 +1,35 @@ + 'required', + 'indicator' => 'required', + 'weight' => 'required', + 'target' => 'required', + 'score' => 'required', + 'score_percentage' => 'required', + ]; + } +} diff --git a/app/Http/Requests/HumanResource/Kpi/KpiCategory/StoreKpiCategoryRequest.php b/app/Http/Requests/HumanResource/Kpi/KpiCategory/StoreKpiCategoryRequest.php new file mode 100644 index 000000000..06ed609e8 --- /dev/null +++ b/app/Http/Requests/HumanResource/Kpi/KpiCategory/StoreKpiCategoryRequest.php @@ -0,0 +1,33 @@ + [ + 'required', + 'unique:kpi_categories,name,NULL,id', + ], + ]; + } +} diff --git a/app/Http/Requests/HumanResource/Kpi/KpiCategory/UpdateKpiCategoryRequest.php b/app/Http/Requests/HumanResource/Kpi/KpiCategory/UpdateKpiCategoryRequest.php new file mode 100644 index 000000000..82ec00aed --- /dev/null +++ b/app/Http/Requests/HumanResource/Kpi/KpiCategory/UpdateKpiCategoryRequest.php @@ -0,0 +1,35 @@ + [ + 'required', + Rule::unique('kpi_categories')->ignore($this->id), + ], + ]; + } +} diff --git a/app/Http/Requests/HumanResource/Kpi/KpiGroup/StoreKpiGroupRequest.php b/app/Http/Requests/HumanResource/Kpi/KpiGroup/StoreKpiGroupRequest.php new file mode 100644 index 000000000..61f4a7a13 --- /dev/null +++ b/app/Http/Requests/HumanResource/Kpi/KpiGroup/StoreKpiGroupRequest.php @@ -0,0 +1,36 @@ + [ + 'required', + 'unique:kpi_groups,name,NULL,id,kpi_category_id,'.$request->get('kpi_category_id'), + ], + ]; + } +} diff --git a/app/Http/Requests/HumanResource/Kpi/KpiGroup/UpdateKpiGroupRequest.php b/app/Http/Requests/HumanResource/Kpi/KpiGroup/UpdateKpiGroupRequest.php new file mode 100644 index 000000000..8a2cfeac0 --- /dev/null +++ b/app/Http/Requests/HumanResource/Kpi/KpiGroup/UpdateKpiGroupRequest.php @@ -0,0 +1,33 @@ +id.',id,kpi_category_id,'.$request->get('kpi_category_id'), + ]; + } +} diff --git a/app/Http/Requests/HumanResource/Kpi/KpiResult/StoreKpiResultRequest.php b/app/Http/Requests/HumanResource/Kpi/KpiResult/StoreKpiResultRequest.php new file mode 100644 index 000000000..b59f5b495 --- /dev/null +++ b/app/Http/Requests/HumanResource/Kpi/KpiResult/StoreKpiResultRequest.php @@ -0,0 +1,42 @@ + [ + 'required', + 'unique:kpi_results,score_min', + ], + 'score_max' => [ + 'required', + 'unique:kpi_results,score_max', + ], + 'criteria' => [ + 'required', + 'unique:kpi_results,criteria', + ], + 'notes' => ['required'], + ]; + } +} diff --git a/app/Http/Requests/HumanResource/Kpi/KpiResult/UpdateKpiResultRequest.php b/app/Http/Requests/HumanResource/Kpi/KpiResult/UpdateKpiResultRequest.php new file mode 100644 index 000000000..9f45b43c2 --- /dev/null +++ b/app/Http/Requests/HumanResource/Kpi/KpiResult/UpdateKpiResultRequest.php @@ -0,0 +1,43 @@ + [ + 'required', + Rule::unique('kpi_results')->ignore($this->id), + ], + 'score_max' => [ + 'required', + Rule::unique('kpi_results')->ignore($this->id), + ], + 'criteria' => [ + 'required', + Rule::unique('kpi_results')->ignore($this->id), + ], + 'notes' => ['required'], + ]; + } +} diff --git a/app/Http/Requests/HumanResource/Kpi/KpiScore/StoreKpiScoreRequest.php b/app/Http/Requests/HumanResource/Kpi/KpiScore/StoreKpiScoreRequest.php new file mode 100644 index 000000000..b28a06ee7 --- /dev/null +++ b/app/Http/Requests/HumanResource/Kpi/KpiScore/StoreKpiScoreRequest.php @@ -0,0 +1,30 @@ + 'required', + ]; + } +} diff --git a/app/Http/Requests/HumanResource/Kpi/KpiScore/UpdateKpiScoreRequest.php b/app/Http/Requests/HumanResource/Kpi/KpiScore/UpdateKpiScoreRequest.php new file mode 100644 index 000000000..83ac7c3c9 --- /dev/null +++ b/app/Http/Requests/HumanResource/Kpi/KpiScore/UpdateKpiScoreRequest.php @@ -0,0 +1,30 @@ + 'required', + ]; + } +} diff --git a/app/Http/Requests/HumanResource/Kpi/KpiTemplate/StoreKpiTemplateRequest.php b/app/Http/Requests/HumanResource/Kpi/KpiTemplate/StoreKpiTemplateRequest.php new file mode 100644 index 000000000..ea82718d6 --- /dev/null +++ b/app/Http/Requests/HumanResource/Kpi/KpiTemplate/StoreKpiTemplateRequest.php @@ -0,0 +1,30 @@ + 'required', + ]; + } +} diff --git a/app/Http/Requests/HumanResource/Kpi/KpiTemplate/UpdateKpiTemplateRequest.php b/app/Http/Requests/HumanResource/Kpi/KpiTemplate/UpdateKpiTemplateRequest.php new file mode 100644 index 000000000..c7287ea21 --- /dev/null +++ b/app/Http/Requests/HumanResource/Kpi/KpiTemplate/UpdateKpiTemplateRequest.php @@ -0,0 +1,30 @@ + 'required', + ]; + } +} diff --git a/app/Http/Requests/HumanResource/Kpi/KpiTemplateGroup/StoreKpiTemplateGroupRequest.php b/app/Http/Requests/HumanResource/Kpi/KpiTemplateGroup/StoreKpiTemplateGroupRequest.php new file mode 100644 index 000000000..1e1e03faf --- /dev/null +++ b/app/Http/Requests/HumanResource/Kpi/KpiTemplateGroup/StoreKpiTemplateGroupRequest.php @@ -0,0 +1,31 @@ + 'required', + 'name' => 'required', + ]; + } +} diff --git a/app/Http/Requests/HumanResource/Kpi/KpiTemplateGroup/UpdateKpiTemplateGroupRequest.php b/app/Http/Requests/HumanResource/Kpi/KpiTemplateGroup/UpdateKpiTemplateGroupRequest.php new file mode 100644 index 000000000..bb85c5557 --- /dev/null +++ b/app/Http/Requests/HumanResource/Kpi/KpiTemplateGroup/UpdateKpiTemplateGroupRequest.php @@ -0,0 +1,31 @@ + 'required', + 'name' => 'required', + ]; + } +} diff --git a/app/Http/Requests/HumanResource/Kpi/KpiTemplateIndicator/StoreKpiTemplateIndicatorRequest.php b/app/Http/Requests/HumanResource/Kpi/KpiTemplateIndicator/StoreKpiTemplateIndicatorRequest.php new file mode 100644 index 000000000..2a09c22ec --- /dev/null +++ b/app/Http/Requests/HumanResource/Kpi/KpiTemplateIndicator/StoreKpiTemplateIndicatorRequest.php @@ -0,0 +1,33 @@ + 'required', + 'name' => 'required', + 'weight' => 'required', + 'target' => 'required', + ]; + } +} diff --git a/app/Http/Requests/HumanResource/Kpi/KpiTemplateIndicator/UpdateKpiTemplateIndicatorRequest.php b/app/Http/Requests/HumanResource/Kpi/KpiTemplateIndicator/UpdateKpiTemplateIndicatorRequest.php new file mode 100644 index 000000000..f27ef30cb --- /dev/null +++ b/app/Http/Requests/HumanResource/Kpi/KpiTemplateIndicator/UpdateKpiTemplateIndicatorRequest.php @@ -0,0 +1,33 @@ + 'required', + 'name' => 'required', + 'weight' => 'required', + 'target' => 'required', + ]; + } +} diff --git a/app/Http/Requests/Master/Person/StorePersonRequest.php b/app/Http/Requests/Master/Person/StorePersonRequest.php index fb53124d3..35a6bf03f 100644 --- a/app/Http/Requests/Master/Person/StorePersonRequest.php +++ b/app/Http/Requests/Master/Person/StorePersonRequest.php @@ -20,6 +20,8 @@ public function authorize() /** * Get the validation rules that apply to the request. * + * @param \Illuminate\Http\Request $request + * * @return array */ public function rules(Request $request) @@ -27,8 +29,7 @@ public function rules(Request $request) return [ 'name' => [ 'required', - 'unique:persons,name,NULL,id' - .',person_category_id,'.$request->get('person_category_id'), + 'unique:persons,name,NULL,id,person_category_id,'.$request->get('person_category_id'), ], 'code' => 'unique:persons,code', 'person_category_id' => 'required', diff --git a/app/Http/Requests/Master/Person/UpdatePersonRequest.php b/app/Http/Requests/Master/Person/UpdatePersonRequest.php index a6d741737..ae9d30976 100644 --- a/app/Http/Requests/Master/Person/UpdatePersonRequest.php +++ b/app/Http/Requests/Master/Person/UpdatePersonRequest.php @@ -20,6 +20,8 @@ public function authorize() /** * Get the validation rules that apply to the request. * + * @param \Illuminate\Http\Request $request + * * @return array */ public function rules(Request $request) @@ -27,8 +29,7 @@ public function rules(Request $request) return [ 'name' => [ 'required', - 'unique:persons,name,'.$this->id.',id' - .',person_category_id,'.$request->get('person_category_id'), + 'unique:persons,name,'.$this->id.',id,person_category_id,'.$request->get('person_category_id'), ], 'code' => 'unique:persons,code,'.$this->id, 'person_category_id' => 'required', diff --git a/app/Http/Resources/HumanResource/Kpi/Kpi/KpiCollection.php b/app/Http/Resources/HumanResource/Kpi/Kpi/KpiCollection.php new file mode 100644 index 000000000..e5ca55b52 --- /dev/null +++ b/app/Http/Resources/HumanResource/Kpi/Kpi/KpiCollection.php @@ -0,0 +1,19 @@ +belongsTo(get_class(new KpiGroup())); + } +} diff --git a/app/Model/HumanResource/Kpi/KpiCategory.php b/app/Model/HumanResource/Kpi/KpiCategory.php new file mode 100644 index 000000000..47063ae34 --- /dev/null +++ b/app/Model/HumanResource/Kpi/KpiCategory.php @@ -0,0 +1,27 @@ +hasMany(get_class(new KpiGroup())); + } + + /** + * Get persons for the kpi category. + */ + public function persons() + { + return $this->hasMany(get_class(new Person())); + } +} diff --git a/app/Model/HumanResource/Kpi/KpiGroup.php b/app/Model/HumanResource/Kpi/KpiGroup.php new file mode 100644 index 000000000..55409dc28 --- /dev/null +++ b/app/Model/HumanResource/Kpi/KpiGroup.php @@ -0,0 +1,26 @@ +hasMany(get_class(new Kpi())); + } + + /** + * Get the kpi category that owns kpi group. + */ + public function category() + { + return $this->belongsTo(get_class(new KpiCategory())); + } +} diff --git a/app/Model/HumanResource/Kpi/KpiResult.php b/app/Model/HumanResource/Kpi/KpiResult.php new file mode 100644 index 000000000..b163dcd86 --- /dev/null +++ b/app/Model/HumanResource/Kpi/KpiResult.php @@ -0,0 +1,10 @@ +hasMany(get_class(new KpiScoreDetail())); + } +} diff --git a/app/Model/HumanResource/Kpi/KpiScoreDetail.php b/app/Model/HumanResource/Kpi/KpiScoreDetail.php new file mode 100644 index 000000000..50b37ff67 --- /dev/null +++ b/app/Model/HumanResource/Kpi/KpiScoreDetail.php @@ -0,0 +1,18 @@ +belongsTo(get_class(new KpiScore())); + } +} diff --git a/app/Model/HumanResource/Kpi/KpiTemplate.php b/app/Model/HumanResource/Kpi/KpiTemplate.php new file mode 100644 index 000000000..7a8b1aa70 --- /dev/null +++ b/app/Model/HumanResource/Kpi/KpiTemplate.php @@ -0,0 +1,18 @@ +hasManyThrough('App\Model\Master\Person', 'App\Model\HumanResource\Kpi\KpiTemplatePerson', 'kpi_template_id', 'id', 'id', 'person_id'); + } +} diff --git a/app/Model/HumanResource/Kpi/KpiTemplateGroup.php b/app/Model/HumanResource/Kpi/KpiTemplateGroup.php new file mode 100644 index 000000000..39e0897be --- /dev/null +++ b/app/Model/HumanResource/Kpi/KpiTemplateGroup.php @@ -0,0 +1,26 @@ +belongsTo(get_class(new KpiTemplate())); + } + + /** + * Get the indicators for the group. + */ + public function indicators() + { + return $this->hasMany(get_class(new KpiTemplateIndicator())); + } +} diff --git a/app/Model/HumanResource/Kpi/KpiTemplateIndicator.php b/app/Model/HumanResource/Kpi/KpiTemplateIndicator.php new file mode 100644 index 000000000..c917ff448 --- /dev/null +++ b/app/Model/HumanResource/Kpi/KpiTemplateIndicator.php @@ -0,0 +1,18 @@ +belongsTo(get_class(new KpiTemplateGroup())); + } +} diff --git a/app/Model/HumanResource/Kpi/KpiTemplatePerson.php b/app/Model/HumanResource/Kpi/KpiTemplatePerson.php new file mode 100644 index 000000000..47e780972 --- /dev/null +++ b/app/Model/HumanResource/Kpi/KpiTemplatePerson.php @@ -0,0 +1,12 @@ +belongsTo('App\Model\Master\PersonGroup', 'person_group_id'); } + + public function kpiTemplate() + { + $kpiTemplatePerson = optional(KpiTemplatePerson::where('person_id', $this->id))->first(); + + return KpiTemplate::find(optional($kpiTemplatePerson)->kpi_template_id); + } } diff --git a/app/Model/Master/User.php b/app/Model/Master/User.php new file mode 100644 index 000000000..925ea4f43 --- /dev/null +++ b/app/Model/Master/User.php @@ -0,0 +1,10 @@ +define(KpiCategory::class, function (Faker $faker) { + return [ + 'person_id' => factory(App\Model\Master\Person::class)->create()->id, + 'date' => $faker->date(), + 'name' => $faker->name, + ]; +}); diff --git a/database/factories/HumanResource/Kpi/KpiFactory.php b/database/factories/HumanResource/Kpi/KpiFactory.php new file mode 100644 index 000000000..b0204da55 --- /dev/null +++ b/database/factories/HumanResource/Kpi/KpiFactory.php @@ -0,0 +1,15 @@ +define(Kpi::class, function (Faker $faker) { + return [ + 'kpi_group_id' => factory(\App\Model\HumanResource\Kpi\KpiGroup::class)->create()->id, + 'indicator' => $faker->name, + 'weight' => 5, + 'target' => 5, + 'score' => $faker->numberBetween($min = 1, $max = 5), + 'score_percentage' => $faker->numberBetween($min = 10, $max = 50), + ]; +}); diff --git a/database/factories/HumanResource/Kpi/KpiGroupFactory.php b/database/factories/HumanResource/Kpi/KpiGroupFactory.php new file mode 100644 index 000000000..94bd8e724 --- /dev/null +++ b/database/factories/HumanResource/Kpi/KpiGroupFactory.php @@ -0,0 +1,11 @@ +define(KpiGroup::class, function (Faker $faker) { + return [ + 'kpi_category_id' => factory(\App\Model\HumanResource\Kpi\KpiCategory::class)->create()->id, + 'name' => $faker->name, + ]; +}); diff --git a/database/factories/HumanResource/Kpi/KpiResultFactory.php b/database/factories/HumanResource/Kpi/KpiResultFactory.php new file mode 100644 index 000000000..bf4bf5e0b --- /dev/null +++ b/database/factories/HumanResource/Kpi/KpiResultFactory.php @@ -0,0 +1,12 @@ +define(\App\Model\HumanResource\Kpi\KpiResult::class, function (Faker $faker) { + return [ + 'score_min' => 0, + 'score_max' => 20, + 'criteria' => $faker->text, + 'notes' => $faker->text, + ]; +}); diff --git a/database/factories/HumanResource/Kpi/KpiScoreDetailFactory.php b/database/factories/HumanResource/Kpi/KpiScoreDetailFactory.php new file mode 100644 index 000000000..74dc6a5eb --- /dev/null +++ b/database/factories/HumanResource/Kpi/KpiScoreDetailFactory.php @@ -0,0 +1,11 @@ +define(\App\Model\HumanResource\Kpi\KpiScoreDetail::class, function (Faker $faker) { + return [ + 'kpi_score_id' => factory(\App\Model\HumanResource\Kpi\KpiScore::class)->create()->id, + 'description' => $faker->text, + 'score' => 1, + ]; +}); diff --git a/database/factories/HumanResource/Kpi/KpiScoreFactory.php b/database/factories/HumanResource/Kpi/KpiScoreFactory.php new file mode 100644 index 000000000..c86f488ca --- /dev/null +++ b/database/factories/HumanResource/Kpi/KpiScoreFactory.php @@ -0,0 +1,9 @@ +define(\App\Model\HumanResource\Kpi\KpiScore::class, function (Faker $faker) { + return [ + 'kpi_template_indicator_id' => factory(\App\Model\HumanResource\Kpi\KpiTemplateIndicator::class)->create()->id, + ]; +}); diff --git a/database/factories/HumanResource/Kpi/KpiTemplateFactory.php b/database/factories/HumanResource/Kpi/KpiTemplateFactory.php new file mode 100644 index 000000000..2899bae35 --- /dev/null +++ b/database/factories/HumanResource/Kpi/KpiTemplateFactory.php @@ -0,0 +1,9 @@ +define(\App\Model\HumanResource\Kpi\KpiTemplate::class, function (Faker $faker) { + return [ + 'name' => $faker->name, + ]; +}); diff --git a/database/factories/HumanResource/Kpi/KpiTemplateGroupFactory.php b/database/factories/HumanResource/Kpi/KpiTemplateGroupFactory.php new file mode 100644 index 000000000..3cd8c5d51 --- /dev/null +++ b/database/factories/HumanResource/Kpi/KpiTemplateGroupFactory.php @@ -0,0 +1,10 @@ +define(\App\Model\HumanResource\Kpi\KpiTemplateGroup::class, function (Faker $faker) { + return [ + 'kpi_template_id' => factory(\App\Model\HumanResource\Kpi\KpiTemplate::class)->create()->id, + 'name' => $faker->name, + ]; +}); diff --git a/database/factories/HumanResource/Kpi/KpiTemplateIndicatorFactory.php b/database/factories/HumanResource/Kpi/KpiTemplateIndicatorFactory.php new file mode 100644 index 000000000..36e9f0f5a --- /dev/null +++ b/database/factories/HumanResource/Kpi/KpiTemplateIndicatorFactory.php @@ -0,0 +1,12 @@ +define(\App\Model\HumanResource\Kpi\KpiTemplateIndicator::class, function (Faker $faker) { + return [ + 'kpi_template_group_id' => factory(\App\Model\HumanResource\Kpi\KpiTemplateGroup::class)->create()->id, + 'name' => $faker->name, + 'weight' => 20, + 'target' => 5, + ]; +}); diff --git a/database/factories/Master/PersonCategoryFactory.php b/database/factories/Master/PersonCategoryFactory.php index d0bb40367..7fb67eb85 100644 --- a/database/factories/Master/PersonCategoryFactory.php +++ b/database/factories/Master/PersonCategoryFactory.php @@ -7,7 +7,7 @@ $factory->define(PersonCategory::class, function (Faker $faker) { return [ - 'code' => $faker->numberBetween($min = 1000, $max = 9999), + 'code' => $faker->numberBetween($min = 10, $max = 999999), 'name' => $faker->name, ]; }); diff --git a/database/factories/Master/PersonFactory.php b/database/factories/Master/PersonFactory.php index ce493f0fd..256ba7db5 100644 --- a/database/factories/Master/PersonFactory.php +++ b/database/factories/Master/PersonFactory.php @@ -7,7 +7,7 @@ $factory->define(Person::class, function (Faker $faker) { return [ - 'code' => $faker->numberBetween($min = 1000, $max = 9999), + 'code' => $faker->numberBetween($min = 10, $max = 999999), 'name' => $faker->name, 'phone' => $faker->phoneNumber, 'email' => $faker->email, diff --git a/database/factories/Master/PersonGroupFactory.php b/database/factories/Master/PersonGroupFactory.php index d2a96243c..d8c7a2152 100644 --- a/database/factories/Master/PersonGroupFactory.php +++ b/database/factories/Master/PersonGroupFactory.php @@ -7,7 +7,7 @@ $factory->define(PersonGroup::class, function (Faker $faker) { return [ - 'code' => $faker->numberBetween($min = 1000, $max = 9999), + 'code' => $faker->numberBetween($min = 10, $max = 999999), 'name' => $faker->name, ]; }); diff --git a/database/factories/Master/UserFactory.php b/database/factories/Master/UserFactory.php index 061d75a2d..27a5c327d 100644 --- a/database/factories/Master/UserFactory.php +++ b/database/factories/Master/UserFactory.php @@ -13,7 +13,7 @@ | */ -$factory->define(App\User::class, function (Faker $faker) { +$factory->define(App\Model\Master\User::class, function (Faker $faker) { static $password; return [ diff --git a/database/factories/WarehouseFactory.php b/database/factories/Master/WarehouseFactory.php similarity index 79% rename from database/factories/WarehouseFactory.php rename to database/factories/Master/WarehouseFactory.php index 35dc82587..268df79be 100644 --- a/database/factories/WarehouseFactory.php +++ b/database/factories/Master/WarehouseFactory.php @@ -7,7 +7,7 @@ $factory->define(Warehouse::class, function (Faker $faker) { return [ - 'code' => $faker->numberBetween($min = 1000, $max = 9999), + 'code' => $faker->numberBetween($min = 10, $max = 999999), 'name' => $faker->name, ]; }); diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php new file mode 100644 index 000000000..061d75a2d --- /dev/null +++ b/database/factories/UserFactory.php @@ -0,0 +1,25 @@ +define(App\User::class, function (Faker $faker) { + static $password; + + return [ + 'name' => $faker->name, + 'email' => $faker->unique()->safeEmail, + 'password' => $password ?: $password = bcrypt('secret'), + 'remember_token' => str_random(10), + ]; +}); diff --git a/database/migrations/tenant/2014_10_12_000000_create_tenant_users_table.php b/database/migrations/tenant/2014_10_12_000000_create_tenant_users_table.php new file mode 100644 index 000000000..24e579abb --- /dev/null +++ b/database/migrations/tenant/2014_10_12_000000_create_tenant_users_table.php @@ -0,0 +1,35 @@ +increments('id'); + $table->string('name'); + $table->string('email')->unique(); + $table->string('password'); + $table->rememberToken(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('users'); + } +} diff --git a/database/migrations/tenant/2018_06_07_191712_create_kpi_templates_table.php b/database/migrations/tenant/2018_06_07_191712_create_kpi_templates_table.php new file mode 100644 index 000000000..3926f859a --- /dev/null +++ b/database/migrations/tenant/2018_06_07_191712_create_kpi_templates_table.php @@ -0,0 +1,32 @@ +increments('id'); + $table->string('name'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('kpi_templates'); + } +} diff --git a/database/migrations/tenant/2018_06_07_191720_create_kpi_template_groups_table.php b/database/migrations/tenant/2018_06_07_191720_create_kpi_template_groups_table.php new file mode 100644 index 000000000..d1dd1195f --- /dev/null +++ b/database/migrations/tenant/2018_06_07_191720_create_kpi_template_groups_table.php @@ -0,0 +1,38 @@ +increments('id'); + $table->unsignedInteger('kpi_template_id')->index(); + $table->string('name'); + $table->timestamps(); + + $table->foreign('kpi_template_id') + ->references('id') + ->on('kpi_templates') + ->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('kpi_template_groups'); + } +} diff --git a/database/migrations/tenant/2018_06_07_191726_create_kpi_template_indicators_table.php b/database/migrations/tenant/2018_06_07_191726_create_kpi_template_indicators_table.php new file mode 100644 index 000000000..82c04fc58 --- /dev/null +++ b/database/migrations/tenant/2018_06_07_191726_create_kpi_template_indicators_table.php @@ -0,0 +1,40 @@ +increments('id'); + $table->unsignedInteger('kpi_template_group_id')->index(); + $table->string('name'); + $table->unsignedInteger('weight'); + $table->unsignedInteger('target'); + $table->timestamps(); + + $table->foreign('kpi_template_group_id') + ->references('id') + ->on('kpi_template_groups') + ->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('kpi_template_indicators'); + } +} diff --git a/database/migrations/tenant/2018_06_07_191807_create_kpi_scores_table.php b/database/migrations/tenant/2018_06_07_191807_create_kpi_scores_table.php new file mode 100644 index 000000000..13f194181 --- /dev/null +++ b/database/migrations/tenant/2018_06_07_191807_create_kpi_scores_table.php @@ -0,0 +1,37 @@ +increments('id'); + $table->unsignedInteger('kpi_template_indicator_id')->index(); + $table->timestamps(); + + $table->foreign('kpi_template_indicator_id') + ->references('id') + ->on('kpi_template_indicators') + ->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('kpi_scores'); + } +} diff --git a/database/migrations/tenant/2018_06_07_191813_create_kpi_score_details_table.php b/database/migrations/tenant/2018_06_07_191813_create_kpi_score_details_table.php new file mode 100644 index 000000000..65998aa21 --- /dev/null +++ b/database/migrations/tenant/2018_06_07_191813_create_kpi_score_details_table.php @@ -0,0 +1,39 @@ +increments('id'); + $table->unsignedInteger('kpi_score_id')->index(); + $table->string('description'); + $table->unsignedInteger('score'); + $table->timestamps(); + + $table->foreign('kpi_score_id') + ->references('id') + ->on('kpi_scores') + ->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('kpi_score_details'); + } +} diff --git a/database/migrations/tenant/2018_06_07_191909_create_kpi_categories_table.php b/database/migrations/tenant/2018_06_07_191909_create_kpi_categories_table.php new file mode 100644 index 000000000..295179ba3 --- /dev/null +++ b/database/migrations/tenant/2018_06_07_191909_create_kpi_categories_table.php @@ -0,0 +1,39 @@ +increments('id'); + $table->unsignedInteger('person_id')->index(); + $table->string('name'); + $table->timestamp('date'); + $table->timestamps(); + + $table->foreign('person_id') + ->references('id') + ->on('persons') + ->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('kpi_categories'); + } +} diff --git a/database/migrations/tenant/2018_06_07_191915_create_kpi_groups_table.php b/database/migrations/tenant/2018_06_07_191915_create_kpi_groups_table.php new file mode 100644 index 000000000..f2bc041a5 --- /dev/null +++ b/database/migrations/tenant/2018_06_07_191915_create_kpi_groups_table.php @@ -0,0 +1,38 @@ +increments('id'); + $table->unsignedInteger('kpi_category_id')->index(); + $table->string('name'); + $table->timestamps(); + + $table->foreign('kpi_category_id') + ->references('id') + ->on('kpi_categories') + ->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('kpi_groups'); + } +} diff --git a/database/migrations/tenant/2018_06_07_191928_create_kpis_table.php b/database/migrations/tenant/2018_06_07_191928_create_kpis_table.php new file mode 100644 index 000000000..b34751e4c --- /dev/null +++ b/database/migrations/tenant/2018_06_07_191928_create_kpis_table.php @@ -0,0 +1,42 @@ +increments('id'); + $table->unsignedInteger('kpi_group_id')->index(); + $table->string('indicator'); + $table->unsignedInteger('weight'); + $table->unsignedInteger('target'); + $table->unsignedInteger('score'); + $table->float('score_percentage'); + $table->timestamps(); + + $table->foreign('kpi_group_id') + ->references('id') + ->on('kpi_groups') + ->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('kpis'); + } +} diff --git a/database/migrations/tenant/2018_06_08_173134_create_kpi_results_table.php b/database/migrations/tenant/2018_06_08_173134_create_kpi_results_table.php new file mode 100644 index 000000000..ed4710260 --- /dev/null +++ b/database/migrations/tenant/2018_06_08_173134_create_kpi_results_table.php @@ -0,0 +1,35 @@ +increments('id'); + $table->unsignedInteger('score_min'); + $table->unsignedInteger('score_max'); + $table->string('criteria'); + $table->string('notes'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('kpi_results'); + } +} diff --git a/database/migrations/tenant/2018_06_08_175659_create_kpi_template_persons_table.php b/database/migrations/tenant/2018_06_08_175659_create_kpi_template_persons_table.php new file mode 100644 index 000000000..0ea0b3b47 --- /dev/null +++ b/database/migrations/tenant/2018_06_08_175659_create_kpi_template_persons_table.php @@ -0,0 +1,42 @@ +unsignedInteger('person_id')->unique(); + $table->unsignedInteger('kpi_template_id'); + $table->timestamps(); + + $table->foreign('kpi_template_id') + ->references('id') + ->on('kpi_templates') + ->onDelete('cascade'); + + $table->foreign('person_id') + ->references('id') + ->on('persons') + ->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('kpi_template_persons'); + } +} diff --git a/database/seeds/DummyTenantDatabaseSeeder.php b/database/seeds/DummyTenantDatabaseSeeder.php index 31e9f942e..362189f2c 100644 --- a/database/seeds/DummyTenantDatabaseSeeder.php +++ b/database/seeds/DummyTenantDatabaseSeeder.php @@ -3,6 +3,11 @@ use App\Model\Master\Person; use App\Model\Master\Warehouse; use Illuminate\Database\Seeder; +use App\Model\HumanResource\Kpi\Kpi; +use App\Model\HumanResource\Kpi\KpiScore; +use App\Model\HumanResource\Kpi\KpiResult; +use App\Model\HumanResource\Kpi\KpiScoreDetail; +use App\Model\HumanResource\Kpi\KpiTemplateIndicator; class DummyTenantDatabaseSeeder extends Seeder { @@ -13,7 +18,21 @@ class DummyTenantDatabaseSeeder extends Seeder */ public function run() { - factory(Warehouse::class, 10)->create(); - factory(Person::class, 10)->create(); + // Master + factory(Warehouse::class, 2)->create(); + factory(Person::class, 2)->create(); + + // Kpi + factory(KpiTemplateIndicator::class, 2)->create(); + factory(KpiResult::class, 1)->create(); + factory(Kpi::class, 2)->create(); + factory(KpiScore::class, 2)->create() + ->each(function ($kpiScore) { + $kpiScore->details()->save(factory(KpiScoreDetail::class)->create(['kpi_score_id' => $kpiScore->id])); + $kpiScore->details()->save(factory(KpiScoreDetail::class)->create(['kpi_score_id' => $kpiScore->id])); + $kpiScore->details()->save(factory(KpiScoreDetail::class)->create(['kpi_score_id' => $kpiScore->id])); + $kpiScore->details()->save(factory(KpiScoreDetail::class)->create(['kpi_score_id' => $kpiScore->id])); + $kpiScore->details()->save(factory(KpiScoreDetail::class)->create(['kpi_score_id' => $kpiScore->id])); + }); } } diff --git a/docs/en/develop/scaffolding.md b/docs/en/develop/scaffolding.md index d25efe618..8614539f8 100644 --- a/docs/en/develop/scaffolding.md +++ b/docs/en/develop/scaffolding.md @@ -8,7 +8,7 @@ With master scaffolding you can create a new master in no time. Just run this command and you will have all the template for your work. ``` -php artisan scaffolding:master Warehouse +php artisan scaffolding:generate Master Warehouse ``` Then register your routes in `routes/api/master.php` diff --git a/routes/api.php b/routes/api.php index b720e73e7..3bbd8a7c1 100644 --- a/routes/api.php +++ b/routes/api.php @@ -20,5 +20,6 @@ Route::prefix('master')->namespace('Master')->group(function () { require base_path('routes/api/master.php'); }); + require base_path('routes/api/human-resource.php'); }); }); diff --git a/routes/api/human-resource.php b/routes/api/human-resource.php new file mode 100644 index 000000000..bb9065b26 --- /dev/null +++ b/routes/api/human-resource.php @@ -0,0 +1,15 @@ +namespace('HumanResource')->group(function () { + Route::prefix('kpi')->namespace('Kpi')->group(function () { + Route::apiResource('templates', 'KpiTemplateController'); + Route::apiResource('template-groups', 'KpiTemplateGroupController'); + Route::apiResource('template-indicators', 'KpiTemplateIndicatorController'); + Route::apiResource('scores', 'KpiScoreController'); + Route::apiResource('score-details', 'KpiController'); + Route::apiResource('results', 'KpiResultController'); + Route::apiResource('categories', 'KpiCategoryController'); + Route::apiResource('groups', 'KpiGroupController'); + Route::apiResource('kpis', 'KpiController'); + }); +}); diff --git a/tests/Feature/HumanResource/Kpi/KpiCategoryTest.php b/tests/Feature/HumanResource/Kpi/KpiCategoryTest.php new file mode 100644 index 000000000..340ced1a5 --- /dev/null +++ b/tests/Feature/HumanResource/Kpi/KpiCategoryTest.php @@ -0,0 +1,100 @@ +signIn(); + } + + /** @test */ + public function an_user_can_create_kpi_category() + { + $data = [ + 'name' => 'name', + 'date' => date('Y-m-d'), + 'person_id' => factory(Person::class)->create()->id, + ]; + + $response = $this->json('POST', 'api/v1/human-resource/kpi/categories', $data, [$this->headers]); + + $response->assertStatus(201); + + $this->assertDatabaseHas('kpi_categories', $data); + } + + /** @test */ + public function an_user_can_read_single_kpi_category() + { + $kpiCategory = factory(KpiCategory::class)->create(); + $response = $this->json('GET', 'api/v1/human-resource/kpi/categories/'.$kpiCategory->id, [], [$this->headers]); + + $response->assertJson([ + 'data' => [ + 'name' => $kpiCategory->name, + ], + ]); + } + + /** @test */ + public function an_user_can_read_all_kpi_category() + { + $kpiCategories = factory(KpiCategory::class, 2)->create(); + + $response = $this->json('GET', 'api/v1/human-resource/kpi/categories', [], [$this->headers]); + + foreach ($kpiCategories as $kpiCategory) { + $this->assertDatabaseHas('kpi_categories', [ + 'name' => $kpiCategory->name, + ]); + } + + $response->assertStatus(200); + } + + /** @test */ + public function an_user_can_update_kpi_category() + { + $kpiCategory = factory(KpiCategory::class)->create(); + + $data = [ + 'id' => $kpiCategory->id, + 'person_id' => $kpiCategory->person_id, + 'date' => $kpiCategory->date, + 'name' => 'another name', + ]; + + $response = $this->json('PUT', 'api/v1/human-resource/kpi/categories/'.$kpiCategory->id, $data, [$this->headers]); + + $response->assertJson(['data' => $data]); + + $this->assertDatabaseHas('kpi_categories', $data); + + $response->assertStatus(200); + } + + /** @test */ + public function an_user_can_delete_kpi_category() + { + $kpiCategory = factory(KpiCategory::class)->create(); + + $response = $this->json('DELETE', 'api/v1/human-resource/kpi/categories/'.$kpiCategory->id, [], [$this->headers]); + + $response->assertStatus(204); + + $this->assertDatabaseMissing('kpi_categories', [ + 'id' => $kpiCategory->id, + ]); + } +} diff --git a/tests/Feature/HumanResource/Kpi/KpiCategoryValidationTest.php b/tests/Feature/HumanResource/Kpi/KpiCategoryValidationTest.php new file mode 100644 index 000000000..30d2b8b75 --- /dev/null +++ b/tests/Feature/HumanResource/Kpi/KpiCategoryValidationTest.php @@ -0,0 +1,56 @@ +signIn(); + } + + /** @test */ + public function a_kpi_category_name_should_be_unique() + { + $kpiCategory = factory(KpiCategory::class)->create(); + + $data = [ + 'name' => $kpiCategory->name, + ]; + + $response = $this->json('POST', 'api/v1/human-resource/kpi/categories', $data, [$this->headers]); + + $response->assertJsonStructure([ + 'error' => [ + 'errors' => ['name'], + ], + ]); + + $response->assertStatus(422); + + $data = [ + 'id' => $kpiCategory->id, + 'name' => $kpiCategory->name, + 'date' => $kpiCategory->date, + 'person_id' => $kpiCategory->person_id, + ]; + + $response = $this->json('PUT', 'api/v1/human-resource/kpi/categories/'.$kpiCategory->id, $data, [$this->headers]); + + $response->assertJsonMissing([ + 'error' => [ + 'errors' => ['name'], + ], + ]); + + $response->assertStatus(200); + } +} diff --git a/tests/Feature/HumanResource/Kpi/KpiGroupTest.php b/tests/Feature/HumanResource/Kpi/KpiGroupTest.php new file mode 100644 index 000000000..1856f2cb7 --- /dev/null +++ b/tests/Feature/HumanResource/Kpi/KpiGroupTest.php @@ -0,0 +1,98 @@ +signIn(); + } + + /** @test */ + public function an_user_can_create_kpi_group() + { + $data = [ + 'name' => 'name', + 'kpi_category_id' => factory(KpiCategory::class)->create()->id, + ]; + + $response = $this->json('POST', 'api/v1/human-resource/kpi/groups', $data, [$this->headers]); + + $response->assertStatus(201); + + $this->assertDatabaseHas('kpi_groups', $data); + } + + /** @test */ + public function an_user_can_read_single_kpi_group() + { + $kpiGroup = factory(KpiGroup::class)->create(); + $response = $this->json('GET', 'api/v1/human-resource/kpi/groups/'.$kpiGroup->id, [], [$this->headers]); + + $response->assertJson([ + 'data' => [ + 'name' => $kpiGroup->name, + ], + ]); + } + + /** @test */ + public function an_user_can_read_all_kpi_group() + { + $kpiGroups = factory(KpiGroup::class, 2)->create(); + + $response = $this->json('GET', 'api/v1/human-resource/kpi/groups', [], [$this->headers]); + + foreach ($kpiGroups as $kpiGroup) { + $this->assertDatabaseHas('kpi_groups', [ + 'name' => $kpiGroup->name, + ]); + } + + $response->assertStatus(200); + } + + /** @test */ + public function an_user_can_update_kpi_group() + { + $kpiGroup = factory(KpiGroup::class)->create(); + + $data = [ + 'id' => $kpiGroup->id, + 'kpi_category_id' => $kpiGroup->kpi_category_id, + 'name' => 'another name', + ]; + + $response = $this->json('PUT', 'api/v1/human-resource/kpi/groups/'.$kpiGroup->id, $data, [$this->headers]); + + $response->assertJson(['data' => $data]); + + $this->assertDatabaseHas('kpi_groups', $data); + + $response->assertStatus(200); + } + + /** @test */ + public function an_user_can_delete_kpi_group() + { + $kpiGroup = factory(KpiGroup::class)->create(); + + $response = $this->json('DELETE', 'api/v1/human-resource/kpi/groups/'.$kpiGroup->id, [], [$this->headers]); + + $response->assertStatus(204); + + $this->assertDatabaseMissing('kpi_groups', [ + 'id' => $kpiGroup->id, + ]); + } +} diff --git a/tests/Feature/HumanResource/Kpi/KpiGroupValidationTest.php b/tests/Feature/HumanResource/Kpi/KpiGroupValidationTest.php new file mode 100644 index 000000000..2128e0fa4 --- /dev/null +++ b/tests/Feature/HumanResource/Kpi/KpiGroupValidationTest.php @@ -0,0 +1,50 @@ +signIn(); + } + + /** @test */ + public function a_kpi_group_name_should_be_unique() + { + $kpiGroup = factory(KpiGroup::class)->create(); + + $data = [ + 'kpi_category_id' => $kpiGroup->kpi_category_id, + 'name' => $kpiGroup->name, + ]; + + $response = $this->json('POST', 'api/v1/human-resource/kpi/groups', $data, [$this->headers]); + + $response->assertJsonStructure([ + 'error' => [ + 'errors' => ['name'], + ], + ]); + + $response->assertStatus(422); + + $response = $this->json('PUT', 'api/v1/human-resource/kpi/groups/'.$kpiGroup->id, $data, [$this->headers]); + + $response->assertJsonMissing([ + 'error' => [ + 'errors' => ['name'], + ], + ]); + + $response->assertStatus(200); + } +} diff --git a/tests/Feature/HumanResource/Kpi/KpiResultTest.php b/tests/Feature/HumanResource/Kpi/KpiResultTest.php new file mode 100644 index 000000000..0d6048d34 --- /dev/null +++ b/tests/Feature/HumanResource/Kpi/KpiResultTest.php @@ -0,0 +1,108 @@ +signIn(); + } + + /** @test */ + public function an_user_can_create_kpi_result() + { + $data = [ + 'score_min' => 85, + 'score_max' => 94, + 'criteria' => 'good', + 'notes' => 'appreciate with reward', + ]; + + $response = $this->json('POST', 'api/v1/human-resource/kpi/results', $data, [$this->headers]); + + $response->assertStatus(201); + + $this->assertDatabaseHas('kpi_results', $data); + } + + /** @test */ + public function an_user_can_read_single_kpi_result() + { + $kpiResult = factory(KpiResult::class)->create(); + $response = $this->json('GET', 'api/v1/human-resource/kpi/results/'.$kpiResult->id, [], [$this->headers]); + + $response->assertJson([ + 'data' => [ + 'score_min' => $kpiResult->score_min, + 'score_max' => $kpiResult->score_max, + 'criteria' => $kpiResult->criteria, + 'notes' => $kpiResult->notes, + ], + ]); + } + + /** @test */ + public function an_user_can_read_all_kpi_result() + { + $kpiCategories = factory(KpiResult::class, 2)->create(); + + $response = $this->json('GET', 'api/v1/human-resource/kpi/results', [], [$this->headers]); + + foreach ($kpiCategories as $kpiResult) { + $this->assertDatabaseHas('kpi_results', [ + 'id' => $kpiResult->id, + 'score_min' => $kpiResult->score_min, + 'score_max' => $kpiResult->score_max, + 'criteria' => $kpiResult->criteria, + 'notes' => $kpiResult->notes, + ]); + } + + $response->assertStatus(200); + } + + /** @test */ + public function an_user_can_update_kpi_result() + { + $kpiResult = factory(KpiResult::class)->create(); + + $data = [ + 'id' => $kpiResult->id, + 'score_min' => $kpiResult->score_min, + 'score_max' => $kpiResult->score_max, + 'criteria' => $kpiResult->criteria, + 'notes' => 'propose new challenge', + ]; + + $response = $this->json('PUT', 'api/v1/human-resource/kpi/results/'.$kpiResult->id, $data, [$this->headers]); + + $response->assertJson(['data' => $data]); + + $this->assertDatabaseHas('kpi_results', $data); + + $response->assertStatus(200); + } + + /** @test */ + public function an_user_can_delete_kpi_result() + { + $kpiResult = factory(KpiResult::class)->create(); + + $response = $this->json('DELETE', 'api/v1/human-resource/kpi/results/'.$kpiResult->id, [], [$this->headers]); + + $response->assertStatus(204); + + $this->assertDatabaseMissing('kpi_results', [ + 'id' => $kpiResult->id, + ]); + } +} diff --git a/tests/Feature/HumanResource/Kpi/KpiResultValidationTest.php b/tests/Feature/HumanResource/Kpi/KpiResultValidationTest.php new file mode 100644 index 000000000..4a84d6490 --- /dev/null +++ b/tests/Feature/HumanResource/Kpi/KpiResultValidationTest.php @@ -0,0 +1,76 @@ +signIn(); + } + + /** @test */ + public function a_kpi_result_name_should_be_unique() + { + $kpiResult = factory(KpiResult::class)->create(); + + $data = [ + 'score_min' => $kpiResult->score_min, + 'score_max' => $kpiResult->score_max, + 'criteria' => $kpiResult->criteria, + ]; + + $response = $this->json('POST', 'api/v1/human-resource/kpi/results', $data, [$this->headers]); + + $response->assertJsonStructure([ + 'error' => [ + 'errors' => ['score_min', 'score_max', 'criteria', 'notes'], + ], + ]); + + $response->assertStatus(422); + + $data = [ + 'id' => $kpiResult->id, + 'score_min' => $kpiResult->score_min, + 'score_max' => $kpiResult->score_max, + 'criteria' => $kpiResult->criteria, + 'notes' => $kpiResult->notes, + ]; + + $response = $this->json('PUT', 'api/v1/human-resource/kpi/results/'.$kpiResult->id, $data, [$this->headers]); + + $response->assertJsonMissing([ + 'error' => [ + 'errors' => ['score_min', 'score_max', 'criteria'], + ], + ]); + + $response->assertStatus(200); + + $data = [ + 'id' => $kpiResult->id, + 'score_min' => $kpiResult->score_min, + 'score_max' => $kpiResult->score_max, + 'criteria' => $kpiResult->criteria, + ]; + + $response = $this->json('PUT', 'api/v1/human-resource/kpi/results/'.$kpiResult->id, $data, [$this->headers]); + + $response->assertJsonStructure([ + 'error' => [ + 'errors' => ['notes'], + ], + ]); + + $response->assertStatus(422); + } +} diff --git a/tests/Feature/HumanResource/Kpi/KpiScoreTest.php b/tests/Feature/HumanResource/Kpi/KpiScoreTest.php new file mode 100644 index 000000000..aa4e6bf47 --- /dev/null +++ b/tests/Feature/HumanResource/Kpi/KpiScoreTest.php @@ -0,0 +1,112 @@ +signIn(); + } + + /** @test */ + public function an_user_can_create_kpi_score() + { + $data = [ + 'kpi_template_indicator_id' => factory(KpiTemplateIndicator::class)->create()->id, + 'description' => ['description', 'description', 'description', 'description', 'description'], + 'score' => [1, 2, 3, 4, 5], + ]; + + $response = $this->json('POST', 'api/v1/human-resource/kpi/scores', $data, [$this->headers]); + + $response->assertStatus(201); + + $this->assertDatabaseHas('kpi_scores', ['kpi_template_indicator_id' => $data['kpi_template_indicator_id']]); + } + + /** @test */ + public function an_user_can_read_single_kpi_score() + { + $kpiScore = factory(KpiScore::class)->create(); + $response = $this->json('GET', 'api/v1/human-resource/kpi/scores/'.$kpiScore->id, [], [$this->headers]); + + $response->assertJson([ + 'data' => [ + 'kpi_template_indicator_id' => $kpiScore->kpi_template_indicator_id, + ], + ]); + } + + /** @test */ + public function an_user_can_read_all_kpi_score() + { + $kpiScores = factory(KpiScore::class, 2)->create(); + + $response = $this->json('GET', 'api/v1/human-resource/kpi/scores', [], [$this->headers]); + + foreach ($kpiScores as $kpiScore) { + $this->assertDatabaseHas('kpi_scores', [ + 'kpi_template_indicator_id' => $kpiScore->kpi_template_indicator_id, + ]); + + $this->assertDatabaseHas('kpi_scores', [ + 'kpi_template_indicator_id' => $kpiScore->kpi_template_indicator_id, + ]); + } + + $response->assertStatus(200); + } + + /** @test */ + public function an_user_can_update_kpi_score() + { + $kpiScore = factory(KpiScore::class)->create(); + + $kpiScore->details()->save(factory(KpiScoreDetail::class)->create(['kpi_score_id' => $kpiScore->id])); + $kpiScore->details()->save(factory(KpiScoreDetail::class)->create(['kpi_score_id' => $kpiScore->id])); + $kpiScore->details()->save(factory(KpiScoreDetail::class)->create(['kpi_score_id' => $kpiScore->id])); + $kpiScore->details()->save(factory(KpiScoreDetail::class)->create(['kpi_score_id' => $kpiScore->id])); + $kpiScore->details()->save(factory(KpiScoreDetail::class)->create(['kpi_score_id' => $kpiScore->id])); + + $data = [ + 'id' => $kpiScore->id, + 'kpi_template_indicator_id' => factory(KpiTemplateIndicator::class)->create()->id, + 'kpi_score_detail_id' => [1, 2, 3, 5], + 'description' => ['description', 'description', 'description', 'description'], + 'score' => [1, 2, 3, 5], + ]; + + $response = $this->json('PUT', 'api/v1/human-resource/kpi/scores/'.$kpiScore->id, $data, [$this->headers]); + + $response->assertJson(['data' => ['kpi_template_indicator_id' => $data['kpi_template_indicator_id']]]); + + $this->assertDatabaseHas('kpi_scores', ['kpi_template_indicator_id' => $data['kpi_template_indicator_id']]); + + $response->assertStatus(200); + } + + /** @test */ + public function an_user_can_delete_kpi_score() + { + $kpiScore = factory(KpiScore::class)->create(); + + $response = $this->json('DELETE', 'api/v1/human-resource/kpi/scores/'.$kpiScore->id, [], [$this->headers]); + + $response->assertStatus(204); + + $this->assertDatabaseMissing('kpi_scores', [ + 'id' => $kpiScore->id, + ]); + } +} diff --git a/tests/Feature/HumanResource/Kpi/KpiScoreValidationTest.php b/tests/Feature/HumanResource/Kpi/KpiScoreValidationTest.php new file mode 100644 index 000000000..c249e4c60 --- /dev/null +++ b/tests/Feature/HumanResource/Kpi/KpiScoreValidationTest.php @@ -0,0 +1,52 @@ +signIn(); + } + + /** @test */ + public function a_kpi_score_name_should_be_unique() + { + $kpiScore = factory(KpiScore::class)->create(); + + $data = []; + + $response = $this->json('POST', 'api/v1/human-resource/kpi/scores', $data, [$this->headers]); + + $response->assertJsonStructure([ + 'error' => [ + 'errors' => ['kpi_template_indicator_id'], + ], + ]); + + $response->assertStatus(422); + + $data = [ + 'id' => $kpiScore->id, + 'kpi_template_indicator_id' => '', + ]; + + $response = $this->json('PUT', 'api/v1/human-resource/kpi/scores/'.$kpiScore->id, $data, [$this->headers]); + + $response->assertJsonMissing([ + 'error' => [ + 'errors' => ['kpi_template_indicator_id'], + ], + ]); + + $response->assertStatus(422); + } +} diff --git a/tests/Feature/HumanResource/Kpi/KpiTemplateGroupTest.php b/tests/Feature/HumanResource/Kpi/KpiTemplateGroupTest.php new file mode 100644 index 000000000..0422800f5 --- /dev/null +++ b/tests/Feature/HumanResource/Kpi/KpiTemplateGroupTest.php @@ -0,0 +1,98 @@ +signIn(); + } + + /** @test */ + public function an_user_can_create_kpi_group() + { + $data = [ + 'name' => 'name', + 'kpi_template_id' => factory(KpiCategory::class)->create()->id, + ]; + + $response = $this->json('POST', 'api/v1/human-resource/kpi/template-groups', $data, [$this->headers]); + + $response->assertStatus(201); + + $this->assertDatabaseHas('kpi_template_groups', $data); + } + + /** @test */ + public function an_user_can_read_single_kpi_group() + { + $kpiTemplateGroup = factory(KpiTemplateGroup::class)->create(); + $response = $this->json('GET', 'api/v1/human-resource/kpi/template-groups/'.$kpiTemplateGroup->id, [], [$this->headers]); + + $response->assertJson([ + 'data' => [ + 'name' => $kpiTemplateGroup->name, + ], + ]); + } + + /** @test */ + public function an_user_can_read_all_kpi_group() + { + $kpiTemplateGroups = factory(KpiTemplateGroup::class, 2)->create(); + + $response = $this->json('GET', 'api/v1/human-resource/kpi/template-groups', [], [$this->headers]); + + foreach ($kpiTemplateGroups as $kpiTemplateGroup) { + $this->assertDatabaseHas('kpi_template_groups', [ + 'name' => $kpiTemplateGroup->name, + ]); + } + + $response->assertStatus(200); + } + + /** @test */ + public function an_user_can_update_kpi_group() + { + $kpiTemplateGroup = factory(KpiTemplateGroup::class)->create(); + + $data = [ + 'id' => $kpiTemplateGroup->id, + 'kpi_template_id' => $kpiTemplateGroup->kpi_template_id, + 'name' => 'another name', + ]; + + $response = $this->json('PUT', 'api/v1/human-resource/kpi/template-groups/'.$kpiTemplateGroup->id, $data, [$this->headers]); + + $response->assertJson(['data' => $data]); + + $this->assertDatabaseHas('kpi_template_groups', $data); + + $response->assertStatus(200); + } + + /** @test */ + public function an_user_can_delete_kpi_group() + { + $kpiTemplateGroup = factory(KpiTemplateGroup::class)->create(); + + $response = $this->json('DELETE', 'api/v1/human-resource/kpi/template-groups/'.$kpiTemplateGroup->id, [], [$this->headers]); + + $response->assertStatus(204); + + $this->assertDatabaseMissing('kpi_template_groups', [ + 'id' => $kpiTemplateGroup->id, + ]); + } +} diff --git a/tests/Feature/HumanResource/Kpi/KpiTemplateGroupValidationTest.php b/tests/Feature/HumanResource/Kpi/KpiTemplateGroupValidationTest.php new file mode 100644 index 000000000..e46c37cac --- /dev/null +++ b/tests/Feature/HumanResource/Kpi/KpiTemplateGroupValidationTest.php @@ -0,0 +1,54 @@ +signIn(); + } + + /** @test */ + public function a_kpi_template_group_name_should_be_unique() + { + $kpiTemplateGroup = factory(KpiTemplateGroup::class)->create(); + + $data = [ + 'name' => 'name', + ]; + + $response = $this->json('POST', 'api/v1/human-resource/kpi/template-groups', $data, [$this->headers]); + + $response->assertJsonStructure([ + 'error' => [ + 'errors' => ['kpi_template_id'], + ], + ]); + + $response->assertStatus(422); + + $data = [ + 'id' => $kpiTemplateGroup->id, + 'kpi_template_id' => '', + ]; + + $response = $this->json('PUT', 'api/v1/human-resource/kpi/template-groups/'.$kpiTemplateGroup->id, $data, [$this->headers]); + + $response->assertJsonMissing([ + 'error' => [ + 'errors' => ['kpi_template_id'], + ], + ]); + + $response->assertStatus(422); + } +} diff --git a/tests/Feature/HumanResource/Kpi/KpiTemplateIndicatorTest.php b/tests/Feature/HumanResource/Kpi/KpiTemplateIndicatorTest.php new file mode 100644 index 000000000..3e80280c1 --- /dev/null +++ b/tests/Feature/HumanResource/Kpi/KpiTemplateIndicatorTest.php @@ -0,0 +1,102 @@ +signIn(); + } + + /** @test */ + public function an_user_can_create_kpi_indicator() + { + $data = [ + 'name' => 'name', + 'kpi_template_group_id' => factory(KpiCategory::class)->create()->id, + 'weight' => 20, + 'target' => 5, + ]; + + $response = $this->json('POST', 'api/v1/human-resource/kpi/template-indicators', $data, [$this->headers]); + + $response->assertStatus(201); + + $this->assertDatabaseHas('kpi_template_indicators', $data); + } + + /** @test */ + public function an_user_can_read_single_kpi_indicator() + { + $kpiTemplateIndicator = factory(KpiTemplateIndicator::class)->create(); + $response = $this->json('GET', 'api/v1/human-resource/kpi/template-indicators/'.$kpiTemplateIndicator->id, [], [$this->headers]); + + $response->assertJson([ + 'data' => [ + 'name' => $kpiTemplateIndicator->name, + ], + ]); + } + + /** @test */ + public function an_user_can_read_all_kpi_indicator() + { + $kpiTemplateIndicators = factory(KpiTemplateIndicator::class, 2)->create(); + + $response = $this->json('GET', 'api/v1/human-resource/kpi/template-indicators', [], [$this->headers]); + + foreach ($kpiTemplateIndicators as $kpiTemplateIndicator) { + $this->assertDatabaseHas('kpi_template_indicators', [ + 'name' => $kpiTemplateIndicator->name, + ]); + } + + $response->assertStatus(200); + } + + /** @test */ + public function an_user_can_update_kpi_indicator() + { + $kpiTemplateIndicator = factory(KpiTemplateIndicator::class)->create(); + + $data = [ + 'id' => $kpiTemplateIndicator->id, + 'kpi_template_group_id' => $kpiTemplateIndicator->kpi_template_group_id, + 'name' => 'another name', + 'weight' => 20, + 'target' => 5, + ]; + + $response = $this->json('PUT', 'api/v1/human-resource/kpi/template-indicators/'.$kpiTemplateIndicator->id, $data, [$this->headers]); + + $response->assertJson(['data' => $data]); + + $this->assertDatabaseHas('kpi_template_indicators', $data); + + $response->assertStatus(200); + } + + /** @test */ + public function an_user_can_delete_kpi_indicator() + { + $kpiTemplateIndicator = factory(KpiTemplateIndicator::class)->create(); + + $response = $this->json('DELETE', 'api/v1/human-resource/kpi/template-indicators/'.$kpiTemplateIndicator->id, [], [$this->headers]); + + $response->assertStatus(204); + + $this->assertDatabaseMissing('kpi_template_indicators', [ + 'id' => $kpiTemplateIndicator->id, + ]); + } +} diff --git a/tests/Feature/HumanResource/Kpi/KpiTemplateIndicatorValidationTest.php b/tests/Feature/HumanResource/Kpi/KpiTemplateIndicatorValidationTest.php new file mode 100644 index 000000000..2b63d82a1 --- /dev/null +++ b/tests/Feature/HumanResource/Kpi/KpiTemplateIndicatorValidationTest.php @@ -0,0 +1,54 @@ +signIn(); + } + + /** @test */ + public function a_kpi_template_indicator_name_should_be_unique() + { + $kpiTemplateIndicator = factory(KpiTemplateIndicator::class)->create(); + + $data = []; + + $response = $this->json('POST', 'api/v1/human-resource/kpi/template-indicators', $data, [$this->headers]); + + $response->assertJsonStructure([ + 'error' => [ + 'errors' => ['name', 'weight', 'target'], + ], + ]); + + $response->assertStatus(422); + + $data = [ + 'id' => $kpiTemplateIndicator->id, + 'name' => 'name', + 'weight' => 20, + 'target' => 5, + ]; + + $response = $this->json('PUT', 'api/v1/human-resource/kpi/template-indicators/'.$kpiTemplateIndicator->id, $data, [$this->headers]); + + $response->assertJsonMissing([ + 'error' => [ + 'errors' => ['name', 'weight', 'target'], + ], + ]); + + $response->assertStatus(422); + } +} diff --git a/tests/Feature/HumanResource/Kpi/KpiTemplateTest.php b/tests/Feature/HumanResource/Kpi/KpiTemplateTest.php new file mode 100644 index 000000000..c08abc5ff --- /dev/null +++ b/tests/Feature/HumanResource/Kpi/KpiTemplateTest.php @@ -0,0 +1,95 @@ +signIn(); + } + + /** @test */ + public function an_user_can_create_kpi_template() + { + $data = [ + 'name' => 'name', + ]; + + $response = $this->json('POST', 'api/v1/human-resource/kpi/templates', $data, [$this->headers]); + + $response->assertStatus(201); + + $this->assertDatabaseHas('kpi_templates', $data); + } + + /** @test */ + public function an_user_can_read_single_kpi_template() + { + $kpiTemplate = factory(KpiTemplate::class)->create(); + $response = $this->json('GET', 'api/v1/human-resource/kpi/templates/'.$kpiTemplate->id, [], [$this->headers]); + + $response->assertJson([ + 'data' => [ + 'name' => $kpiTemplate->name, + ], + ]); + } + + /** @test */ + public function an_user_can_read_all_kpi_template() + { + $kpiCategories = factory(KpiTemplate::class, 2)->create(); + + $response = $this->json('GET', 'api/v1/human-resource/kpi/templates', [], [$this->headers]); + + foreach ($kpiCategories as $kpiTemplate) { + $this->assertDatabaseHas('kpi_templates', [ + 'name' => $kpiTemplate->name, + ]); + } + + $response->assertStatus(200); + } + + /** @test */ + public function an_user_can_update_kpi_template() + { + $kpiTemplate = factory(KpiTemplate::class)->create(); + + $data = [ + 'id' => $kpiTemplate->id, + 'name' => 'another name', + ]; + + $response = $this->json('PUT', 'api/v1/human-resource/kpi/templates/'.$kpiTemplate->id, $data, [$this->headers]); + + $response->assertJson(['data' => $data]); + + $this->assertDatabaseHas('kpi_templates', $data); + + $response->assertStatus(200); + } + + /** @test */ + public function an_user_can_delete_kpi_template() + { + $kpiTemplate = factory(KpiTemplate::class)->create(); + + $response = $this->json('DELETE', 'api/v1/human-resource/kpi/templates/'.$kpiTemplate->id, [], [$this->headers]); + + $response->assertStatus(204); + + $this->assertDatabaseMissing('kpi_templates', [ + 'id' => $kpiTemplate->id, + ]); + } +} diff --git a/tests/Feature/HumanResource/Kpi/KpiTemplateValidationTest.php b/tests/Feature/HumanResource/Kpi/KpiTemplateValidationTest.php new file mode 100644 index 000000000..0b9411346 --- /dev/null +++ b/tests/Feature/HumanResource/Kpi/KpiTemplateValidationTest.php @@ -0,0 +1,54 @@ +signIn(); + } + + /** @test */ + public function a_kpi_template_name_should_be_unique() + { + $kpiTemplate = factory(KpiTemplate::class)->create(); + + $data = [ + 'name' => '', + ]; + + $response = $this->json('POST', 'api/v1/human-resource/kpi/templates', $data, [$this->headers]); + info($response->json()); + $response->assertJsonStructure([ + 'error' => [ + 'errors' => ['name'], + ], + ]); + + $response->assertStatus(422); + + $data = [ + 'id' => $kpiTemplate->id, + 'name' => '', + ]; + + $response = $this->json('PUT', 'api/v1/human-resource/kpi/templates/'.$kpiTemplate->id, $data, [$this->headers]); + + $response->assertJsonMissing([ + 'error' => [ + 'errors' => ['name'], + ], + ]); + + $response->assertStatus(422); + } +} diff --git a/tests/Feature/HumanResource/Kpi/KpiTest.php b/tests/Feature/HumanResource/Kpi/KpiTest.php new file mode 100644 index 000000000..037997403 --- /dev/null +++ b/tests/Feature/HumanResource/Kpi/KpiTest.php @@ -0,0 +1,106 @@ +signIn(); + } + + /** @test */ + public function an_user_can_create_kpi() + { + $data = [ + 'kpi_group_id' => factory(KpiGroup::class)->create()->id, + 'indicator' => 'indicator', + 'weight' => 20, + 'target' => 5, + 'score' => 5, + 'score_percentage' => 5, + ]; + + $response = $this->json('POST', 'api/v1/human-resource/kpi/kpis', $data, [$this->headers]); + + $response->assertStatus(201); + + $this->assertDatabaseHas('kpis', $data); + } + + /** @test */ + public function an_user_can_read_single_kpi() + { + $kpi = factory(Kpi::class)->create(); + $response = $this->json('GET', 'api/v1/human-resource/kpi/kpis/'.$kpi->id, [], [$this->headers]); + + $response->assertJson([ + 'data' => [ + 'indicator' => $kpi->indicator, + ], + ]); + } + + /** @test */ + public function an_user_can_read_all_kpi() + { + $kpis = factory(Kpi::class, 2)->create(); + + $response = $this->json('GET', 'api/v1/human-resource/kpi/kpis', [], [$this->headers]); + + foreach ($kpis as $kpi) { + $this->assertDatabaseHas('kpis', [ + 'indicator' => $kpi->indicator, + ]); + } + + $response->assertStatus(200); + } + + /** @test */ + public function an_user_can_update_kpi() + { + $kpi = factory(Kpi::class)->create(); + + $data = [ + 'id' => $kpi->id, + 'kpi_group_id' => $kpi->kpi_group_id, + 'indicator' => 'another name', + 'weight' => 20, + 'target' => 5, + 'score' => 5, + 'score_percentage' => 5, + ]; + + $response = $this->json('PUT', 'api/v1/human-resource/kpi/kpis/'.$kpi->id, $data, [$this->headers]); + + $response->assertJson(['data' => $data]); + + $this->assertDatabaseHas('kpis', $data); + + $response->assertStatus(200); + } + + /** @test */ + public function an_user_can_delete_kpi() + { + $kpi = factory(Kpi::class)->create(); + + $response = $this->json('DELETE', 'api/v1/human-resource/kpi/kpis/'.$kpi->id, [], [$this->headers]); + + $response->assertStatus(204); + + $this->assertDatabaseMissing('kpis', [ + 'id' => $kpi->id, + ]); + } +} diff --git a/tests/Feature/HumanResource/Kpi/KpiValidationTest.php b/tests/Feature/HumanResource/Kpi/KpiValidationTest.php new file mode 100644 index 000000000..97de83d8e --- /dev/null +++ b/tests/Feature/HumanResource/Kpi/KpiValidationTest.php @@ -0,0 +1,49 @@ +signIn(); + } + + /** @test */ + public function a_kpi_name_should_be_unique() + { + $kpi = factory(Kpi::class)->create(); + + $data = []; + + $response = $this->json('POST', 'api/v1/human-resource/kpi/kpis', $data, [$this->headers]); + + $response->assertJsonStructure([ + 'error' => [ + 'errors' => ['kpi_group_id', 'indicator', 'weight', 'target', 'score', 'score_percentage'], + ], + ]); + + $response->assertStatus(422); + + $data = []; + + $response = $this->json('PUT', 'api/v1/human-resource/kpi/kpis/'.$kpi->id, $data, [$this->headers]); + + $response->assertJsonMissing([ + 'error' => [ + 'errors' => ['kpi_group_id', 'indicator', 'weight', 'target', 'score', 'score_percentage'], + ], + ]); + + $response->assertStatus(422); + } +} diff --git a/tests/Feature/Master/PersonCategoryRESTTest.php b/tests/Feature/Master/PersonCategoryTest.php similarity index 98% rename from tests/Feature/Master/PersonCategoryRESTTest.php rename to tests/Feature/Master/PersonCategoryTest.php index 83a2a364b..ef23cc832 100644 --- a/tests/Feature/Master/PersonCategoryRESTTest.php +++ b/tests/Feature/Master/PersonCategoryTest.php @@ -6,7 +6,7 @@ use App\Model\Master\PersonCategory; use Illuminate\Foundation\Testing\RefreshDatabase; -class PersonCategoryRESTTest extends TestCase +class PersonCategoryTest extends TestCase { use RefreshDatabase; diff --git a/tests/Feature/Master/PersonGroupRESTTest.php b/tests/Feature/Master/PersonGroupTest.php similarity index 98% rename from tests/Feature/Master/PersonGroupRESTTest.php rename to tests/Feature/Master/PersonGroupTest.php index d492b2860..f64586e97 100644 --- a/tests/Feature/Master/PersonGroupRESTTest.php +++ b/tests/Feature/Master/PersonGroupTest.php @@ -6,7 +6,7 @@ use App\Model\Master\PersonGroup; use Illuminate\Foundation\Testing\RefreshDatabase; -class PersonGroupRESTTest extends TestCase +class PersonGroupTest extends TestCase { use RefreshDatabase; diff --git a/tests/Feature/Master/PersonRESTTest.php b/tests/Feature/Master/PersonTest.php similarity index 98% rename from tests/Feature/Master/PersonRESTTest.php rename to tests/Feature/Master/PersonTest.php index 792174581..4e906355b 100644 --- a/tests/Feature/Master/PersonRESTTest.php +++ b/tests/Feature/Master/PersonTest.php @@ -7,7 +7,7 @@ use App\Model\Master\PersonCategory; use Illuminate\Foundation\Testing\RefreshDatabase; -class PersonRESTTest extends TestCase +class PersonTest extends TestCase { use RefreshDatabase; diff --git a/tests/Feature/Master/UserRESTTest.php b/tests/Feature/Master/UserTest.php similarity index 98% rename from tests/Feature/Master/UserRESTTest.php rename to tests/Feature/Master/UserTest.php index 17a643620..3cc3e566d 100644 --- a/tests/Feature/Master/UserRESTTest.php +++ b/tests/Feature/Master/UserTest.php @@ -6,7 +6,7 @@ use Tests\TestCase; use Illuminate\Foundation\Testing\RefreshDatabase; -class UserRESTTest extends TestCase +class UserTest extends TestCase { use RefreshDatabase; diff --git a/tests/Feature/Master/WarehouseRESTTest.php b/tests/Feature/Master/WarehouseTest.php similarity index 98% rename from tests/Feature/Master/WarehouseRESTTest.php rename to tests/Feature/Master/WarehouseTest.php index 9c977ada9..956c94ae5 100644 --- a/tests/Feature/Master/WarehouseRESTTest.php +++ b/tests/Feature/Master/WarehouseTest.php @@ -6,7 +6,7 @@ use App\Model\Master\Warehouse; use Illuminate\Foundation\Testing\RefreshDatabase; -class WarehouseRESTTest extends TestCase +class WarehouseTest extends TestCase { use RefreshDatabase;