diff --git a/Admin/Install/db.json b/Admin/Install/db.json index b3c8a55..d670e68 100644 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -15,32 +15,6 @@ "null": false, "foreignTable": "account", "foreignKey": "account_id" - }, - "hr_staff_unit": { - "name": "hr_staff_unit", - "type": "INT", - "null": false, - "foreignTable": "organization_unit", - "foreignKey": "organization_unit_id" - }, - "hr_staff_department": { - "name": "hr_staff_department", - "type": "INT", - "null": false, - "foreignTable": "organization_department", - "foreignKey": "organization_department_id" - }, - "hr_staff_position": { - "name": "hr_staff_position", - "type": "INT", - "null": false, - "foreignTable": "organization_position", - "foreignKey": "organization_position_id" - }, - "hr_staff_active": { - "name": "hr_staff_active", - "type": "TINYINT", - "null": false } } }, @@ -90,7 +64,8 @@ "hr_staff_history_end": { "name": "hr_staff_history_end", "type": "DATETIME", - "null": false + "null": true, + "default": null } } } diff --git a/Admin/Routes/Web/Api.php b/Admin/Routes/Web/Api.php new file mode 100644 index 0000000..fab8df7 --- /dev/null +++ b/Admin/Routes/Web/Api.php @@ -0,0 +1,20 @@ + [ + [ + 'dest' => '\Modules\HumanResourceManagement\Controller\ApiController:apiEmployeeFromAccountCreate', + 'verb' => RouteVerb::PUT, + 'permission' => [ + 'module' => ApiController::MODULE_NAME, + 'type' => PermissionType::CREATE, + 'state' => PermissionState::HR, + ], + ], + ], +]; \ No newline at end of file diff --git a/Admin/Routes/Web/Backend.php b/Admin/Routes/Web/Backend.php index c56f14d..adc7b73 100644 --- a/Admin/Routes/Web/Backend.php +++ b/Admin/Routes/Web/Backend.php @@ -6,7 +6,7 @@ use phpOMS\Account\PermissionType; use phpOMS\Router\RouteVerb; return [ - '^.*/hr/staff/list.*$' => [ + '^.*/humanresource/staff/list.*$' => [ [ 'dest' => '\Modules\HumanResourceManagement\Controller\BackendController:viewHrStaffList', 'verb' => RouteVerb::GET, @@ -17,7 +17,7 @@ return [ ], ], ], - '^.*/hr/staff/profile.*$' => [ + '^.*/humanresource/staff/profile.*$' => [ [ 'dest' => '\Modules\HumanResourceManagement\Controller\BackendController:viewHrStaffProfile', 'verb' => RouteVerb::GET, @@ -28,7 +28,7 @@ return [ ], ], ], - '^.*/hr/staff/create.*$' => [ + '^.*/humanresource/staff/create.*$' => [ [ 'dest' => '\Modules\HumanResourceManagement\Controller\BackendController:viewHrStaffCreate', 'verb' => RouteVerb::GET, @@ -39,7 +39,7 @@ return [ ], ], ], - '^.*/hr/department/list.*$' => [ + '^.*/humanresource/department/list.*$' => [ [ 'dest' => '\Modules\HumanResourceManagement\Controller\BackendController:viewHrDepartmentList', 'verb' => RouteVerb::GET, diff --git a/Controller/ApiController.php b/Controller/ApiController.php new file mode 100644 index 0000000..310d90b --- /dev/null +++ b/Controller/ApiController.php @@ -0,0 +1,177 @@ +validateEmployeeFromAccountCreate($request))) { + $response->set('employee_create', new FormValidation($val)); + + return; + } + + $employee = $this->createEmployeeFromAccountFromRequest($request); + $this->createModel($request->getHeader()->getAccount(), $employee, EmployeeMapper::class, 'employee'); + $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Employee', 'Employee successfully created', $employee); + } + + /** + * Validate employee from account create request + * + * @param RequestAbstract $request Request + * + * @return array + * + * @since 1.0.0 + */ + private function validateEmployeeFromAccountCreate(RequestAbstract $request) : array + { + $val = []; + if (($val['account'] = empty($request->getData('account'))) + ) { + return $val; + } + + return []; + } + + /** + * Method to create employee from account from request. + * + * @param RequestAbstract $request Request + * + * @return Employee + * + * @since 1.0.0 + */ + private function createEmployeeFromAccountFromRequest(RequestAbstract $request) : Employee + { + $employee = new Employee(); + $employee->setAccount((int) ($request->getData('account') ?? 0)); + + return $employee; + } + + /** + * Api method to create an employee history + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiEmployeeHistoryCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void + { + if (!empty($val = $this->validateEmployeeHistoryCreate($request))) { + $response->set('history_create', new FormValidation($val)); + + return; + } + + $history = $this->createEmployeeHistoryFromRequest($request); + $this->createModel($request->getHeader()->getAccount(), $history, EmployeeHistoryMapper::class, 'history'); + $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'History', 'History successfully created', $history); + } + + /** + * Validate employee history + * + * @param RequestAbstract $request Request + * + * @return array + * + * @since 1.0.0 + */ + private function validateEmployeeHistoryCreate(RequestAbstract $request) : array + { + $val = []; + if (($val['employee'] = empty($request->getData('employee'))) + || ($val['start'] = empty($request->getData('start'))) + || ($val['unit'] = empty($request->getData('unit'))) + || ($val['department'] = empty($request->getData('department'))) + || ($val['position'] = empty($request->getData('position'))) + ) { + return $val; + } + + return []; + } + + /** + * Method to create employee history from request. + * + * @param RequestAbstract $request Request + * + * @return EmployeeHistory + * + * @since 1.0.0 + */ + private function createEmployeeHistoryFromRequest(RequestAbstract $request) : EmployeeHistory + { + $history = new EmployeeHistory(); + $history->setEmployee((int) ($request->getData('employee') ?? 0)); + $history->setUnit((int) ($request->getData('unit') ?? 0)); + $history->setDepartment((int) ($request->getData('department') ?? 0)); + $history->setPosition((int) ($request->getData('position') ?? 0)); + $history->setStart(new \DateTime($request->getData('start') ?? 'now')); + + if (!empty($request->getData('end'))) { + $history->setEnd(new \DateTime($request->getData('end'))); + } + + return $history; + } +} diff --git a/Controller/BackendController.php b/Controller/BackendController.php index fd09acd..4344c84 100644 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -70,6 +70,9 @@ final class BackendController extends Controller $view->setTemplate('/Modules/HumanResourceManagement/Theme/Backend/staff-create'); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1002402001, $request, $response)); + $accSelector = new \Modules\Profile\Theme\Backend\Components\AccountGroupSelector\BaseView($this->app, $request, $response); + $view->addData('accSelector', $accSelector); + return $view; } diff --git a/Models/Employee.php b/Models/Employee.php index 2f1affb..2e49241 100644 --- a/Models/Employee.php +++ b/Models/Employee.php @@ -14,7 +14,7 @@ declare(strict_types=1); namespace Modules\HumanResourceManagement\Models; -use Modules\Admin\Models\Account; +use phpOMS\Contract\ArrayableInterface; /** * Employee class. @@ -24,7 +24,7 @@ use Modules\Admin\Models\Account; * @link https://orange-management.org * @since 1.0.0 */ -class Employee +class Employee implements ArrayableInterface, \JsonSerializable { /** @@ -37,68 +37,18 @@ class Employee private $account = null; - private $unit = null; - - private $department = null; - - private $position = null; - - private $isActive = true; - private $history = []; - private $status = []; - - public function setAccount(Account $account) : void + public function setAccount($account) : void { $this->account = $account; } - public function getAccount() : Account + public function getAccount() { return $this->account; } - public function setActivity(bool $active) : void - { - $this->isActive = $active; - } - - public function isActive() : bool - { - return $this->isActive; - } - - public function setUnit($unit) : void - { - $this->unit = $unit; - } - - public function getUnit() - { - return $this->unit; - } - - public function setDepartment($department) : void - { - $this->department = $department; - } - - public function getDepartment() - { - return $this->department; - } - - public function setPosition($position) : void - { - $this->position = $position; - } - - public function getPosition() - { - return $this->position; - } - public function getId() : int { return $this->id; @@ -106,11 +56,38 @@ class Employee public function getHistory() : array { - return []; + return $this->history; } - public function getNewestHistory() : void + public function getNewestHistory() : EmployeeHistory { + return empty($this->history) ? new NullEmployeeHistory : end($this->history); + } + /** + * {@inheritdoc} + */ + public function toArray() : array + { + return [ + 'id' => $this->id, + 'account' => $this->account, + ]; + } + + /** + * {@inheritdoc} + */ + public function __toString() + { + return (string) \json_encode($this->toArray()); + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() + { + return $this->toArray(); } } diff --git a/Models/EmployeeHistory.php b/Models/EmployeeHistory.php index 711a902..62f43d4 100644 --- a/Models/EmployeeHistory.php +++ b/Models/EmployeeHistory.php @@ -14,6 +14,15 @@ declare(strict_types=1); namespace Modules\HumanResourceManagement\Models; +use Modules\Organization\Models\Position; +use Modules\Organization\Models\NullPosition; +use Modules\Organization\Models\Unit; +use Modules\Organization\Models\NullUnit; +use Modules\Organization\Models\Department; +use Modules\Organization\Models\NullDepartment; + +use phpOMS\Contract\ArrayableInterface; + /** * Employee class. * @@ -22,7 +31,116 @@ namespace Modules\HumanResourceManagement\Models; * @link https://orange-management.org * @since 1.0.0 */ -class EmployeeHistory +class EmployeeHistory implements ArrayableInterface, \JsonSerializable { + private $id = 0; + private $employee = null; + + private $unit = null; + + private $department = null; + + private $position = null; + + private $start = null; + + private $end = null; + + public function getId() : int + { + return $this->id; + } + + public function getEmployee() + { + return $this->employee ?? new NullEmployee(); + } + + public function setEmployee($employee) : void + { + $this->employee = $employee; + } + + public function getPosition() : Position + { + return $this->position ?? new NullPosition(); + } + + public function setPosition($position) : void + { + $this->position = $position; + } + + public function getUnit() : Unit + { + return $this->unit ?? new NullUnit(); + } + + public function setUnit($unit) : void + { + $this->unit = $unit; + } + + public function getDepartment() : Department + { + return $this->department ?? new NullDepartment(); + } + + public function setDepartment($department) : void + { + $this->department = $department; + } + + public function getStart() : ?\DateTime + { + return $this->start; + } + + public function setStart(\DateTime $start) : void + { + $this->start = $start; + } + + public function getEnd() : ?\DateTime + { + return $this->end; + } + + public function setEnd(\DateTime $end) : void + { + $this->end = $end; + } + + /** + * {@inheritdoc} + */ + public function toArray() : array + { + return [ + 'id' => $this->id, + 'employee' => !\is_int($this->employee) ? $this->employee->getId() : $this->employee, + 'unit' => $this->unit, + 'department' => $this->department, + 'position' => $this->position, + 'start' => $this->start->format('Y-m-d H:i:s'), + 'end' => $this->end === null ? null : $this->end->format('Y-m-d H:i:s'), + ]; + } + + /** + * {@inheritdoc} + */ + public function __toString() + { + return (string) \json_encode($this->toArray()); + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() + { + return $this->toArray(); + } } diff --git a/Models/EmployeeHistoryMapper.php b/Models/EmployeeHistoryMapper.php index 639136c..b3d441a 100644 --- a/Models/EmployeeHistoryMapper.php +++ b/Models/EmployeeHistoryMapper.php @@ -15,9 +15,49 @@ declare(strict_types=1); namespace Modules\HumanResourceManagement\Models; use phpOMS\DataStorage\Database\DataMapperAbstract; +use Modules\Organization\Models\DepartmentMapper; +use Modules\Organization\Models\PositionMapper; +use Modules\Organization\Models\UnitMapper; final class EmployeeHistoryMapper extends DataMapperAbstract { + /** + * Columns. + * + * @var array> + * @since 1.0.0 + */ + protected static $columns = [ + 'hr_staff_history_id' => ['name' => 'hr_staff_history_id', 'type' => 'int', 'internal' => 'id'], + 'hr_staff_history_staff' => ['name' => 'hr_staff_history_staff', 'type' => 'int', 'internal' => 'employee'], + 'hr_staff_history_unit' => ['name' => 'hr_staff_history_unit', 'type' => 'int', 'internal' => 'unit'], + 'hr_staff_history_department' => ['name' => 'hr_staff_history_department', 'type' => 'int', 'internal' => 'department'], + 'hr_staff_history_position' => ['name' => 'hr_staff_history_position', 'type' => 'int', 'internal' => 'position'], + 'hr_staff_history_start' => ['name' => 'hr_staff_history_start', 'type' => 'DateTime', 'internal' => 'start'], + 'hr_staff_history_end' => ['name' => 'hr_staff_history_end', 'type' => 'DateTime', 'internal' => 'end'], + ]; + + /** + * Belongs to. + * + * @var array> + * @since 1.0.0 + */ + protected static $belongsTo = [ + 'unit' => [ + 'mapper' => UnitMapper::class, + 'src' => 'hr_staff_history_unit', + ], + 'department' => [ + 'mapper' => DepartmentMapper::class, + 'src' => 'hr_staff_history_department', + ], + 'position' => [ + 'mapper' => PositionMapper::class, + 'src' => 'hr_staff_history_position', + ], + ]; + /** * Primary field name. * diff --git a/Models/EmployeeMapper.php b/Models/EmployeeMapper.php index 4e93e86..95d099e 100644 --- a/Models/EmployeeMapper.php +++ b/Models/EmployeeMapper.php @@ -15,9 +15,6 @@ declare(strict_types=1); namespace Modules\HumanResourceManagement\Models; use Modules\Admin\Models\AccountMapper; -use Modules\Organization\Models\DepartmentMapper; -use Modules\Organization\Models\PositionMapper; -use Modules\Organization\Models\UnitMapper; use phpOMS\DataStorage\Database\DataMapperAbstract; final class EmployeeMapper extends DataMapperAbstract @@ -32,10 +29,6 @@ final class EmployeeMapper extends DataMapperAbstract protected static $columns = [ 'hr_staff_id' => ['name' => 'hr_staff_id', 'type' => 'int', 'internal' => 'id'], 'hr_staff_account' => ['name' => 'hr_staff_account', 'type' => 'int', 'internal' => 'account'], - 'hr_staff_unit' => ['name' => 'hr_staff_unit', 'type' => 'int', 'internal' => 'unit'], - 'hr_staff_department' => ['name' => 'hr_staff_department', 'type' => 'int', 'internal' => 'department'], - 'hr_staff_position' => ['name' => 'hr_staff_position', 'type' => 'int', 'internal' => 'position'], - 'hr_staff_active' => ['name' => 'hr_staff_active', 'type' => 'bool', 'internal' => 'isActive'], ]; /** @@ -49,17 +42,20 @@ final class EmployeeMapper extends DataMapperAbstract 'mapper' => AccountMapper::class, 'src' => 'hr_staff_account', ], - 'unit' => [ - 'mapper' => UnitMapper::class, - 'src' => 'hr_staff_unit', - ], - 'department' => [ - 'mapper' => DepartmentMapper::class, - 'src' => 'hr_staff_department', - ], - 'position' => [ - 'mapper' => PositionMapper::class, - 'src' => 'hr_staff_position', + ]; + + /** + * Has many relation. + * + * @var array> + * @since 1.0.0 + */ + protected static $hasMany = [ + 'history' => [ + 'mapper' => EmployeeHistoryMapper::class, + 'table' => 'hr_staff_history', + 'dst' => 'hr_staff_history_staff', + 'src' => null, ], ]; diff --git a/Models/NullEmployee.php b/Models/NullEmployee.php new file mode 100644 index 0000000..19ecb6e --- /dev/null +++ b/Models/NullEmployee.php @@ -0,0 +1,27 @@ +getData('nav')->render(); +?> + +
+
+
+

getHtml('Account'); ?>

+
+
+ + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+

getHtml('CreateFromExistingAccount'); ?>

+
+
+ + +
+
getData('accSelector')->render('iAccount', 'account', true); ?> +
+
+
+
+
+
diff --git a/Theme/Backend/staff-list.tpl.php b/Theme/Backend/staff-list.tpl.php index 0f388d5..00136d2 100644 --- a/Theme/Backend/staff-list.tpl.php +++ b/Theme/Backend/staff-list.tpl.php @@ -14,13 +14,6 @@ * @var \phpOMS\Views\View $this */ -$footerView = new \phpOMS\Views\PaginationView($this->app, $this->request, $this->response); -$footerView->setTemplate('/Web/Templates/Lists/Footer/PaginationBig'); - -$footerView->setPages(25); -$footerView->setPage(1); -$footerView->setResults(1); - $employees = $this->getData('employees'); echo $this->getData('nav')->render(); ?> @@ -42,14 +35,10 @@ echo $this->getData('nav')->render(); ?> $value) : ++$c; - $url = \phpOMS\Uri\UriFactory::build('{/prefix}hr/staff/profile?{?}&id=' . $value->getId()); ?> + $url = \phpOMS\Uri\UriFactory::build('{/prefix}humanresource/staff/profile?{?}&id=' . $value->getId()); ?> printHtml($value->getId()); ?> printHtml($value->getAccount()->getName1()); ?> - printHtml($value->getUnit()->getName()); ?> - printHtml($value->getDepartment()->getName()); ?> - printHtml($value->getPosition()->getName()); ?> - printHtml($value->getPosition()->getName()); ?> getHtml('Empty', '0', '0'); ?> @@ -58,4 +47,3 @@ echo $this->getData('nav')->render(); ?> - diff --git a/Theme/Backend/staff-single.tpl.php b/Theme/Backend/staff-single.tpl.php index 7c478fd..b85da3d 100644 --- a/Theme/Backend/staff-single.tpl.php +++ b/Theme/Backend/staff-single.tpl.php @@ -12,6 +12,8 @@ */ $employee = $this->getData('employee'); +$history = $employee->getHistorY(); +$recentHistory = $employee->getNewestHistory(); echo $this->getData('nav')->render(); ?> @@ -24,13 +26,13 @@ echo $this->getData('nav')->render(); ?>
getHtml('Position') ?> - printHtml($employee->getPosition()->getName()); ?> + printHtml($recentHistory->getPosition()->getName()); ?>
getHtml('Department') ?> - printHtml($employee->getDepartment()->getName()); ?> + printHtml($recentHistory->getDepartment()->getName()); ?>
getHtml('Unit') ?> - printHtml($employee->getUnit()->getName()); ?> + printHtml($recentHistory->getUnit()->getName()); ?>
getHtml('Birthday') ?> 06.09.1934 @@ -86,10 +88,25 @@ echo $this->getData('nav')->render(); ?>
-
-

getHtml('History') ?>

-
-
-
+
+ + + + + + +
getHtml('History') ?>
getHtml('Start') ?> + getHtml('End') ?> + getHtml('Unit') ?> + getHtml('Department') ?> + getHtml('Position') ?> +
getStart()->format('Y-m-d'); ?> + getEnd() === null ? '' : $hist->getEnd()->format('Y-m-d'); ?> + printHtml($hist->getUnit()->getName()); ?> + printHtml($hist->getDepartment()->getName()); ?> + printHtml($hist->getPosition()->getName()); ?> + +
+
- \ No newline at end of file + diff --git a/info.json b/info.json index f91f893..2760d0e 100644 --- a/info.json +++ b/info.json @@ -26,7 +26,8 @@ "load": [ { "pid": [ - "/humanresource" + "/humanresource/staff", + "/humanresource/department" ], "type": 4, "for": 0,