diff --git a/mirzaev/ebala/system/controllers/market.php b/mirzaev/ebala/system/controllers/market.php index 9141c76..e87ac01 100755 --- a/mirzaev/ebala/system/controllers/market.php +++ b/mirzaev/ebala/system/controllers/market.php @@ -238,6 +238,7 @@ final class market extends core else if (!empty($parameters['account_number']) && strlen($parameters['account_number']) < 11) throw new exception('Несоответствие формату SIM-номера аккаунта представителя'); else if (!empty($parameters['market_mail']) && preg_match('/^.+@.+\.\w+$/', $parameters['market_mail']) === 0) throw new exception('Несоответствие формату почты представителя'); else if (!empty($parameters['account_mail']) && preg_match('/^.+@.+\.\w+$/', $parameters['account_mail']) === 0) throw new exception('Несоответствие формату почты аккаунта представителя'); + else if (!empty($parameters['market_id']) && model::read('d.id == "' . $parameters['market_id'] . '"', errors: $this->errors['account']) instanceof _document) throw new exception('Уже существует магазин с данным идентификатором'); // Универсализация /* $parameters['market_number'] = (int) $parameters['market_number']; */ @@ -277,7 +278,7 @@ final class market extends core } // Инициализация идентификатора магазина - $id = model::id(); + $id = empty($parameters['market_id']) ? model::id() : $parameters['market_id']; // Запись заголовков ответа header('Content-Type: application/json'); @@ -306,30 +307,35 @@ final class market extends core flush(); try { - // Создание магазина - $market = model::create( - data: [ - 'id' => (string) $id, - 'name' => [ - 'first' => $parameters['market_name_first'], - 'second' => $parameters['market_name_second'], - 'last' => $parameters['market_name_last'] + if (isset($account)) { + // Инициализирован аккаунт + + // Создание магазина + $market = model::create( + data: [ + 'id' => (string) $id, + 'name' => [ + 'first' => $parameters['market_name_first'], + 'second' => $parameters['market_name_second'], + 'last' => $parameters['market_name_last'] + ], + 'number' => $parameters['market_number'] === 0 ? '' : $parameters['market_number'], + 'mail' => $parameters['market_mail'], + 'type' => $parameters['market_type'], + 'city' => $parameters['market_city'], + 'district' => $parameters['market_district'], + 'address' => $parameters['market_address'], ], - 'number' => $parameters['market_number'] === 0 ? '' : $parameters['market_number'], - 'mail' => $parameters['market_mail'], - 'type' => $parameters['market_type'], - 'city' => $parameters['market_city'], - 'district' => $parameters['market_district'], - 'address' => $parameters['market_address'], - ], - errors: $this->errors['account'] - ); + errors: $this->errors['account'] + ); - // Проверка существования созданного магазина - if (empty($market)) throw new exception('Не удалось создать магазин'); + // Проверка существования созданного магазина + if (empty($market)) throw new exception('Не удалось создать магазин'); - // Создание ребра: account -> market - account::connect($account, $market, 'market', $this->errors['account']); + // Создание ребра: account -> market + account::connect($account, $market, 'market', $this->errors['account']); + } + throw new exception('Не инициализирован аккаунт'); } catch (exception $e) { // Write to the errors registry $this->errors['account'][] = [ @@ -397,8 +403,8 @@ final class market extends core if (!empty($market)) { // Найден магазин - - // Инициализация параметров (перезапись переданными значениями) + + // Инициализация параметров (перезапись переданными значениями) if ($parameters['name_first'] !== $market->name['first']) $market->name = ['first' => $parameters['name_first']] + $market->name; if ($parameters['name_second'] !== $market->name['second']) $market->name = ['second' => $parameters['name_second']] + $market->name; if ($parameters['name_last'] !== $market->name['last']) $market->name = ['last' => $parameters['name_last']] + $market->name; diff --git a/mirzaev/ebala/system/controllers/worker.php b/mirzaev/ebala/system/controllers/worker.php index 62a5903..88111f1 100755 --- a/mirzaev/ebala/system/controllers/worker.php +++ b/mirzaev/ebala/system/controllers/worker.php @@ -39,7 +39,7 @@ final class worker extends core // Авторизация if ($this->account->status() && ($this->account->type === 'administrator' || $this->account->type === 'operator')) { // Авторизован аккаунт оператора или администратора - + foreach (['active', 'inactive', 'fined', 'decent', 'hided', 'fired'] as $name) { // Перебор фильтров статусов @@ -253,6 +253,7 @@ final class worker extends core else if (!empty($parameters['account_number']) && strlen($parameters['account_number']) < 11) throw new exception('Несоответствие формату SIM-номера аккаунта сотрудника'); else if (!empty($parameters['worker_mail']) && preg_match('/^.+@.+\.\w+$/', $parameters['worker_mail']) === 0) throw new exception('Несоответствие формату почты сотрудника'); else if (!empty($parameters['account_mail']) && preg_match('/^.+@.+\.\w+$/', $parameters['account_mail']) === 0) throw new exception('Несоответствие формату почты аккаунта сотрудника'); + else if (!empty($parameters['worker_id']) && model::read('d.id == "' . $parameters['worker_id'] . '"', errors: $this->errors['account']) instanceof _document) throw new exception('Уже существует сотрудник с данным идентификатором'); // Универсализация /* $parameters['worker_number'] = (int) $parameters['worker_number']; */ @@ -295,6 +296,9 @@ final class worker extends core ]; } + // Инициализация идентификатора сотрудника + $id = empty($parameters['worker_id']) ? model::id() : $parameters['worker_id']; + // Запись заголовков ответа header('Content-Type: application/json'); header('Content-Encoding: none'); @@ -322,41 +326,46 @@ final class worker extends core flush(); try { - // Создание сотрудника - $worker = model::create( - data: [ - 'id' => model::id(), - 'name' => [ - 'first' => $parameters['worker_name_first'], - 'second' => $parameters['worker_name_second'], - 'last' => $parameters['worker_name_last'] - ], - 'number' => $parameters['worker_number'], - 'mail' => $parameters['worker_mail'], - 'birth' => $parameters['worker_birth'], - 'passport' => $parameters['worker_passport'], - 'issued' => $parameters['worker_issued'], - 'department' => [ - 'number' => $parameters['worker_department_number'], - 'address' => $parameters['worker_department_address'] - ], - 'requisites' => $parameters['worker_requisites'], - 'payment' => $parameters['worker_payment'], - 'tax' => $parameters['worker_tax'], - 'city' => $parameters['worker_city'], - 'district' => $parameters['worker_district'], - 'address' => $parameters['worker_address'], - 'hiring' => $parameters['worker_hiring'], - 'rating' => 3 - ], - errors: $this->errors['account'] - ); + if (isset($account)) { + // Инициализирован аккаунт - // Проверка существования созданного сотрудника - if (empty($worker)) throw new exception('Не удалось создать сотрудника'); + // Создание сотрудника + $worker = model::create( + data: [ + 'id' => (string) $id, + 'name' => [ + 'first' => $parameters['worker_name_first'], + 'second' => $parameters['worker_name_second'], + 'last' => $parameters['worker_name_last'] + ], + 'number' => $parameters['worker_number'], + 'mail' => $parameters['worker_mail'], + 'birth' => $parameters['worker_birth'], + 'passport' => $parameters['worker_passport'], + 'issued' => $parameters['worker_issued'], + 'department' => [ + 'number' => $parameters['worker_department_number'], + 'address' => $parameters['worker_department_address'] + ], + 'requisites' => $parameters['worker_requisites'], + 'payment' => $parameters['worker_payment'], + 'tax' => $parameters['worker_tax'], + 'city' => $parameters['worker_city'], + 'district' => $parameters['worker_district'], + 'address' => $parameters['worker_address'], + 'hiring' => $parameters['worker_hiring'], + 'rating' => 3 + ], + errors: $this->errors['account'] + ); - // Создание ребра: account -> worker - account::connect($account, $worker, 'worker', $this->errors['account']); + // Проверка существования созданного сотрудника + if (empty($worker)) throw new exception('Не удалось создать сотрудника'); + + // Создание ребра: account -> worker + account::connect($account, $worker, 'worker', $this->errors['account']); + } + throw new exception('Не инициализирован аккаунт'); } catch (exception $e) { // Write to the errors registry $this->errors['account'][] = [ @@ -424,7 +433,7 @@ final class worker extends core if (!empty($worker)) { // Найден сотрудник - + // Универсализация if (!empty($parameters['birth'])) $parameters['birth'] = DateTime::createFromFormat('Y-m-d', $parameters['birth'])->getTimestamp(); if (!empty($parameters['issued'])) $parameters['issued'] = DateTime::createFromFormat('Y-m-d', $parameters['issued'])->getTimestamp(); diff --git a/mirzaev/ebala/system/models/core.php b/mirzaev/ebala/system/models/core.php index 45f2105..37a73bf 100755 --- a/mirzaev/ebala/system/models/core.php +++ b/mirzaev/ebala/system/models/core.php @@ -171,18 +171,29 @@ class core extends model } /** - * Сгенерировать идентификатор + * Generate identifier * * @param array &$errors Реестр ошибок * - * @return int Свободный идентификатор (подразумевается) + * @return int Идентиикатор (свободный) */ public static function id(array &$errors = []): int { try { - if (collection::init(static::$arangodb->session, static::COLLECTION)) - return static::count(static::COLLECTION, $errors) ?? 0; - else throw new exception('Не удалось инициализировать коллекцию'); + if (collection::init(static::$arangodb->session, static::COLLECTION)) { + // Инициализирована коллекция + + // Exit (success) + return collection::search( + static::$arangodb->session, + sprintf( + <<<'AQL' + RETURN MAX((FOR d in %s RETURN +d.id)) + AQL, + $collection ?? static::COLLECTION + ) + ) + 1; + } else throw new exception('Не удалось инициализировать коллекцию'); } catch (exception $e) { // Запись в реестр ошибок $errors[] = [ @@ -193,10 +204,10 @@ class core extends model ]; } + // Exit (fail) return 0; } - /** * Delete from ArangoDB * diff --git a/mirzaev/ebala/system/models/worker.php b/mirzaev/ebala/system/models/worker.php index 9e152cb..9e976d7 100755 --- a/mirzaev/ebala/system/models/worker.php +++ b/mirzaev/ebala/system/models/worker.php @@ -90,45 +90,6 @@ final class worker extends core return null; } - /** - * Generate identifier - * - * @param array &$errors Реестр ошибок - * - * @return int Идентиикатор (свободный) - */ - public static function id(array &$errors = []): int - { - try { - if (collection::init(static::$arangodb->session, static::COLLECTION)) { - // Инициализирована коллекция - - // Exit (success) - return collection::search( - static::$arangodb->session, - sprintf( - <<<'AQL' - RETURN MAX((FOR d in %s RETURN +d.id)) - AQL, - $collection ?? static::COLLECTION - ) - ); - } else throw new exception('Не удалось инициализировать коллекцию'); - } catch (exception $e) { - // Запись в реестр ошибок - $errors[] = [ - 'text' => $e->getMessage(), - 'file' => $e->getFile(), - 'line' => $e->getLine(), - 'stack' => $e->getTrace() - ]; - } - - // Exit (fail) - return 0; - } - - /** * Записать * diff --git a/mirzaev/ebala/system/public/js/markets.js b/mirzaev/ebala/system/public/js/markets.js index f53b8de..10df418 100644 --- a/mirzaev/ebala/system/public/js/markets.js +++ b/mirzaev/ebala/system/public/js/markets.js @@ -119,6 +119,7 @@ if (typeof window.markets !== "function") { * @param {HTMLElement} market_name_last Отчество представителя магазина * @param {HTMLElement} market_number SIM-номер представителя магазина * @param {HTMLElement} market_mail Почта представителя магазина + * @param {HTMLElement} market_id Идентификатор магазина * @param {HTMLElement} market_type Тип магазина * @param {HTMLElement} market_district Регион магазина @@ -140,6 +141,7 @@ if (typeof window.markets !== "function") { market_name_last, market_number, market_mail, + market_id, market_type, market_city, market_district, @@ -158,6 +160,7 @@ if (typeof window.markets !== "function") { market_name_last.setAttribute("readonly", true); market_number.setAttribute("readonly", true); market_mail.setAttribute("readonly", true); + market_id.setAttribute("readonly", true); market_type.setAttribute("readonly", true); market_city.setAttribute("readonly", true); market_district.setAttribute("readonly", true); @@ -181,6 +184,7 @@ if (typeof window.markets !== "function") { market_name_last, market_number, market_mail, + market_id, market_type, market_city, market_district, @@ -204,6 +208,7 @@ if (typeof window.markets !== "function") { * @param {HTMLElement} market_name_last Отчество представителя магазина * @param {HTMLElement} market_number SIM-номер представителя магазина * @param {HTMLElement} market_mail Почта представителя магазина + * @param {HTMLElement} market_id Идентификатор магазина * @param {HTMLElement} market_type Тип магазина * @param {HTMLElement} market_district Регион магазина @@ -226,6 +231,7 @@ if (typeof window.markets !== "function") { market_name_last, market_number, market_mail, + market_id, market_type, market_city, market_district, @@ -246,6 +252,7 @@ if (typeof window.markets !== "function") { market_name_last.removeAttribute("readonly"); market_number.removeAttribute("readonly"); market_mail.removeAttribute("readonly"); + market_id.removeAttribute("readonly"); market_type.removeAttribute("readonly"); market_city.removeAttribute("readonly"); market_district.removeAttribute("readonly"); @@ -275,7 +282,7 @@ if (typeof window.markets !== "function") { "Content-Type": "application/x-www-form-urlencoded", }, body: - `market_name_first=${market_name_first.value}&market_name_second=${market_name_second.value}&market_name_last=${market_name_last.value}&market_number=${market_number.mask.unmaskedValue}&market_mail=${market_mail.value}&market_type=${market_type.value}&market_city=${market_city.value}&market_district=${market_district.value}&market_address=${market_address.value}&account_name_first=${account_name_first.value}&account_name_second=${account_name_second.value}&account_name_last=${account_name_last.value}&account_number=${account_number.mask.unmaskedValue}&account_mail=${account_mail.value}&account_password=${account_password.value}&account_commentary=${account_commentary.value}`, + `market_name_first=${market_name_first.value}&market_name_second=${market_name_second.value}&market_name_last=${market_name_last.value}&market_number=${market_number.mask.unmaskedValue}&market_mail=${market_mail.value}&market_id=${market_id.value}&market_type=${market_type.value}&market_city=${market_city.value}&market_district=${market_district.value}&market_address=${market_address.value}&account_name_first=${account_name_first.value}&account_name_second=${account_name_second.value}&account_name_last=${account_name_last.value}&account_number=${account_number.mask.unmaskedValue}&account_mail=${account_mail.value}&account_password=${account_password.value}&account_commentary=${account_commentary.value}`, }) .then((response) => response.json()) .then((data) => { @@ -513,6 +520,29 @@ if (typeof window.markets !== "function") { market_mail_input.setAttribute("title", "Почта представителя магазина"); market_mail_input.setAttribute("placeholder", "name@server"); + // Инициализация строки + const market_id = document.createElement("div"); + market_id.classList.add("row", "merged"); + + // Инициализация оболочки для строки + const market_id_label = document.createElement("label"); + market_id_label.setAttribute("id", "market_id"); + + // Инициализация заголовка для поля ввода + const market_id_title = document.createElement("b"); + market_id_title.classList.add("separated", "right", "unselectable"); + market_id_title.innerText = "Идентификатор:"; + + // Инициализация поля ввода + const market_id_input = document.createElement("input"); + market_id_input.classList.add("large"); + market_id_input.setAttribute("name", "id"); + market_id_input.setAttribute("type", "text"); + market_id_input.setAttribute("minlength", "1"); + market_id_input.setAttribute("maxlength", "3"); + market_id_input.setAttribute("title", "Идентификатор магазина"); + market_id_input.setAttribute("placeholder", "000"); + // Инициализация строки const market_type = document.createElement("div"); market_type.classList.add("row", "divided", "merged"); @@ -958,6 +988,11 @@ if (typeof window.markets !== "function") { market_mail.appendChild(market_mail_label); market.appendChild(market_mail); + market_id_label.appendChild(market_id_title); + market_id_label.appendChild(market_id_input); + market_id.appendChild(market_id_label); + market.appendChild(market_id); + market_type_label.appendChild(market_type_title); market_type_select.appendChild(market_type_option_1); market_type_select.appendChild(market_type_option_2); diff --git a/mirzaev/ebala/system/public/js/workers.js b/mirzaev/ebala/system/public/js/workers.js index 340a52a..cdf78c2 100644 --- a/mirzaev/ebala/system/public/js/workers.js +++ b/mirzaev/ebala/system/public/js/workers.js @@ -119,6 +119,7 @@ if (typeof window.workers !== "function") { * @param {HTMLElement} worker_name_last Отчество сотрудника * @param {HTMLElement} worker_number SIM-номер сотрудника * @param {HTMLElement} worker_mail Почта сотрудника + * @param {HTMLElement} worker_id Идентификатор сотрудника * @param {HTMLElement} worker_birth Дата рождения сотрудника * @param {HTMLElement} worker_passport Номер паспорта сотрудника * @param {HTMLElement} worker_issued Дата выдачи паспорта сотрудника @@ -148,6 +149,7 @@ if (typeof window.workers !== "function") { worker_name_last, worker_number, worker_mail, + worker_id, worker_birth, worker_passport, worker_issued, @@ -174,6 +176,7 @@ if (typeof window.workers !== "function") { worker_name_last.setAttribute("readonly", true); worker_number.setAttribute("readonly", true); worker_mail.setAttribute("readonly", true); + worker_id.setAttribute("readonly", true); worker_birth.setAttribute("readonly", true); worker_passport.setAttribute("readonly", true); worker_issued.setAttribute("readonly", true); @@ -205,6 +208,7 @@ if (typeof window.workers !== "function") { worker_name_last, worker_number, worker_mail, + worker_id, worker_birth, worker_passport, worker_issued, @@ -236,6 +240,7 @@ if (typeof window.workers !== "function") { * @param {HTMLElement} worker_name_last Отчество сотрудника * @param {HTMLElement} worker_number SIM-номер сотрудника * @param {HTMLElement} worker_mail Почта сотрудника + * @param {HTMLElement} worker_id Идентификатор сотрудника * @param {HTMLElement} worker_birth Дата рождения сотрудника * @param {HTMLElement} worker_passport Номер паспорта сотрудника * @param {HTMLElement} worker_issued Дата выдачи паспорта сотрудника @@ -266,6 +271,7 @@ if (typeof window.workers !== "function") { worker_name_last, worker_number, worker_mail, + worker_id, worker_birth, worker_passport, worker_issued, @@ -294,6 +300,7 @@ if (typeof window.workers !== "function") { worker_name_last.removeAttribute("readonly"); worker_number.removeAttribute("readonly"); worker_mail.removeAttribute("readonly"); + worker_id.removeAttribute("readonly"); worker_birth.removeAttribute("readonly"); worker_passport.removeAttribute("readonly"); worker_issued.removeAttribute("readonly"); @@ -331,7 +338,7 @@ if (typeof window.workers !== "function") { "Content-Type": "application/x-www-form-urlencoded", }, body: - `worker_name_first=${worker_name_first.value}&worker_name_second=${worker_name_second.value}&worker_name_last=${worker_name_last.value}&worker_number=${worker_number.mask.unmaskedValue}&worker_mail=${worker_mail.value}&worker_birth=${worker_birth.value}&worker_birth=${worker_birth.value}&worker_passport=${worker_passport.value}&worker_issued=${worker_issued.value}&worker_department_number=${worker_department_number.value}&worker_department_address=${worker_department_address.value}&worker_requisites=${worker_requisites.value}&worker_payment=${worker_payment.value}&worker_tax=${worker_tax.value}&worker_city=${worker_city.value}&worker_district=${worker_district.value}&worker_address=${worker_address.value}&worker_hiring=${worker_hiring.value}&account_name_first=${account_name_first.value}&account_name_second=${account_name_second.value}&account_name_last=${account_name_last.value}&account_number=${account_number.mask.unmaskedValue}&account_mail=${account_mail.value}&account_password=${account_password.value}&account_commentary=${account_commentary.value}`, + `worker_name_first=${worker_name_first.value}&worker_name_second=${worker_name_second.value}&worker_name_last=${worker_name_last.value}&worker_number=${worker_number.mask.unmaskedValue}&worker_mail=${worker_mail.value}&worker_id=${worker_id.value}&worker_birth=${worker_birth.value}&worker_birth=${worker_birth.value}&worker_passport=${worker_passport.value}&worker_issued=${worker_issued.value}&worker_department_number=${worker_department_number.value}&worker_department_address=${worker_department_address.value}&worker_requisites=${worker_requisites.value}&worker_payment=${worker_payment.value}&worker_tax=${worker_tax.value}&worker_city=${worker_city.value}&worker_district=${worker_district.value}&worker_address=${worker_address.value}&worker_hiring=${worker_hiring.value}&account_name_first=${account_name_first.value}&account_name_second=${account_name_second.value}&account_name_last=${account_name_last.value}&account_number=${account_number.mask.unmaskedValue}&account_mail=${account_mail.value}&account_password=${account_password.value}&account_commentary=${account_commentary.value}`, }) .then((response) => response.json()) .then((data) => { @@ -561,6 +568,29 @@ if (typeof window.workers !== "function") { worker_mail_input.setAttribute("title", "Почта сотрудника"); worker_mail_input.setAttribute("placeholder", "name@server"); + // Инициализация строки + const worker_id = document.createElement("div"); + worker_id.classList.add("row", "merged"); + + // Инициализация оболочки для строки + const worker_id_label = document.createElement("label"); + worker_id_label.setAttribute("id", "worker_id"); + + // Инициализация заголовка для поля ввода + const worker_id_title = document.createElement("b"); + worker_id_title.classList.add("separated", "right", "unselectable"); + worker_id_title.innerText = "Идентификатор:"; + + // Инициализация поля ввода + const worker_id_input = document.createElement("input"); + worker_id_input.classList.add("large"); + worker_id_input.setAttribute("name", "id"); + worker_id_input.setAttribute("type", "text"); + worker_id_input.setAttribute("minlength", "1"); + worker_id_input.setAttribute("maxlength", "6"); + worker_id_input.setAttribute("title", "Идентификатор сотрудника"); + worker_id_input.setAttribute("placeholder", "000000"); + // Инициализация строки const worker_birth = document.createElement("div"); worker_birth.classList.add("row", "divided"); @@ -1205,6 +1235,11 @@ if (typeof window.workers !== "function") { worker_mail.appendChild(worker_mail_label); worker.appendChild(worker_mail); + worker_id_label.appendChild(worker_id_title); + worker_id_label.appendChild(worker_id_input); + worker_id.appendChild(worker_id_label); + worker.appendChild(worker_id); + worker_birth_label.appendChild(worker_birth_title); worker_birth_label.appendChild(worker_birth_input); worker_birth.appendChild(worker_birth_label);