resolved #96, resolved #79, resolved #65

This commit is contained in:
Arsen Mirzaev Tatyano-Muradovich 2024-04-07 04:22:40 +07:00
parent 03391a1269
commit efb85a2609
4 changed files with 166 additions and 51 deletions

View File

@ -11,6 +11,7 @@ use mirzaev\ebala\controllers\core,
mirzaev\ebala\models\account,
mirzaev\ebala\models\worker,
mirzaev\ebala\models\market,
mirzaev\ebala\models\payments,
mirzaev\ebala\models\core as _core;
// Библиотека для ArangoDB
@ -577,7 +578,7 @@ final class task extends core
throw new exception('Запрещено редактировать заявку за менее 16 часов до её начала');
}
// Запись в ресстре последних обновивших
// Запись в реестре последних обновивших
$task->updates = [$this->account->type => match ($this->account->type) {
'worker', 'market' => account::{$this->account->type}($this->account->getId())?->id,
default => $this->account->getKey()
@ -1207,7 +1208,7 @@ final class task extends core
// Изменение статуса подтверждения
$task->confirmed = !$task->confirmed;
// Запись в ресстре последних обновивших
// Запись в реестре последних обновивших
$task->updates = [$this->account->type => match ($this->account->type) {
'worker', 'market' => account::{$this->account->type}($this->account->getId())?->id,
default => $this->account->getKey()
@ -1332,7 +1333,7 @@ final class task extends core
}
}
// Запись в ресстре последних обновивших
// Запись в реестре последних обновивших
$task->updates = [$this->account->type => match ($this->account->type) {
'worker', 'market' => account::{$this->account->type}($this->account->getId())?->id,
default => $this->account->getKey()
@ -1453,7 +1454,7 @@ final class task extends core
else {
// Получена оценка
// Запись оценики
// Запись оценки
$task->rating = $parameters['rating'];
if (!empty($parameters['review'])) {
@ -1468,9 +1469,38 @@ final class task extends core
// Снятие с публикации
$task->published = false;
// Иниализация сотрудника
$worker = worker::read('d.id == "' . $task->worker . '"');
// Инициализация магазина
$market = market::read('d.id == "' . $task->market . '"');
// Подсчёт часов работы
$hours = model::hours($task->start, $task->end, $this->errors);
// Инициализация цены работы за 1 час
$hour = payments::hour($market->city, $task->work);
// Подсчёт оплаты за работу
$payment = $hour * $hours;
// Инициализация штрафа
$penalty = payments::penalty($task->rating ?? null);
// Инициализация премии
$bonus = payments::bonus($task->rating ?? null);
// Инициализация транзакции к оплате сотруднику
model::transaction(
$task->getId(),
$worker->getId(),
$payment - ($penalty === null ? $payment : -$penalty) + $bonus,
$this->errors
);
}
// Запись в ресстре последних обновивших
// Запись в реcстре последних обновивших
$task->updates = [$this->account->type => match ($this->account->type) {
'worker', 'market' => account::{$this->account->type}($this->account->getId())?->id,
default => $this->account->getKey()
@ -1567,7 +1597,7 @@ final class task extends core
// Изменение статуса скрытия
$task->hided = !$task->hided;
// Запись в ресстре последних обновивших
// Запись в реестре последних обновивших
$task->updates = [$this->account->type => match ($this->account->type) {
'worker', 'market' => account::{$this->account->type}($this->account->getId())?->id,
default => $this->account->getKey()
@ -1705,7 +1735,7 @@ final class task extends core
// Изменение статуса
$task->status = 'deleted';
// Запись в ресстре последних обновивших
// Запись в реестре последних обновивших
$task->updates = [$this->account->type => match ($this->account->type) {
'worker', 'market' => account::{$this->account->type}($this->account->getId())?->id,
default => $this->account->getKey()
@ -2075,7 +2105,7 @@ final class task extends core
default => 'Кассир'
};
// Запись в ресстре последних обновивших
// Запись в реестре последних обновивших
$task->updates = [$this->account->type => match ($this->account->type) {
'worker', 'market' => account::{$this->account->type}($this->account->getId())?->id,
default => $this->account->getKey()
@ -2197,7 +2227,7 @@ final class task extends core
// Изменение статуса
$task->description = $parameters['description'];
// Запись в ресстре последних обновивших
// Запись в реестре последних обновивших
$task->updates = [$this->account->type => match ($this->account->type) {
'worker', 'market' => account::{$this->account->type}($this->account->getId())?->id,
default => $this->account->getKey()
@ -2314,7 +2344,7 @@ final class task extends core
if (!empty($parameters['start'])) $task->start = $parameters['start'];
if (!empty($parameters['end'])) $task->end = $parameters['end'];
// Запись в ресстре последних обновивших
// Запись в реестре последних обновивших
$task->updates = [$this->account->type => match ($this->account->type) {
'worker', 'market' => account::{$this->account->type}($this->account->getId())?->id,
default => $this->account->getKey()
@ -2407,7 +2437,7 @@ final class task extends core
// Запись комментария
$task->commentary = $parameters['commentary'];
// Запись в ресстре последних обновивших
// Запись в реестре последних обновивших
$task->updates = [$this->account->type => match ($this->account->type) {
'worker', 'market' => account::{$this->account->type}($this->account->getId())?->id,
default => $this->account->getKey()
@ -2500,7 +2530,7 @@ final class task extends core
// Запись статуса о публикации
$task->published = true;
// Запись в ресстре последних обновивших
// Запись в реестре последних обновивших
$task->updates = [$this->account->type => match ($this->account->type) {
'worker', 'market' => account::{$this->account->type}($this->account->getId())?->id,
default => $this->account->getKey()
@ -2593,7 +2623,7 @@ final class task extends core
// Запись статуса о публикации
$task->published = false;
// Запись в ресстре последних обновивших
// Запись в реестре последних обновивших
$task->updates = [$this->account->type => match ($this->account->type) {
'worker', 'market' => account::{$this->account->type}($this->account->getId())?->id,
default => $this->account->getKey()
@ -2948,7 +2978,7 @@ final class task extends core
$task->problematic = false;
}
// Запись в ресстре последних обновивших
// Запись в реестре последних обновивших
$task->updates = [$this->account->type => match ($this->account->type) {
'worker', 'market' => account::{$this->account->type}($this->account->getId())?->id,
default => $this->account->getKey()
@ -3026,7 +3056,7 @@ final class task extends core
$task->problematic = false;
}
// Запись в ресстре последних обновивших
// Запись в реестре последних обновивших
$task->updates = [$this->account->type => match ($this->account->type) {
'worker', 'market' => account::{$this->account->type}($this->account->getId())?->id,
default => $this->account->getKey()

View File

@ -206,7 +206,7 @@ final class payments extends core
->setCellValue("K$row", $task->rating ?? 'Отсутствует')
->setCellValue("L$row", $task->review ?? '')
->setCellValue("M$row", $worker->name['second'] . ' ' . $worker->name['first'] . ' ' . $worker->name['last'])
->setCellValue("N$row", $hour = static::hour($market->city, $task->work))
->setCellValue("N$row", $hour = static::hour('worker', $market->city, $task->work))
->setCellValue("O$row", $payment = $hour * $hours)
->setCellValue("P$row", ($penalty = static::penalty($task->rating ?? null)) === null ? $payment : $penalty)
->setCellValue("Q$row", $bonus = static::bonus($task->rating ?? null))
@ -465,7 +465,7 @@ final class payments extends core
->setCellValue("E$row", $work)
->setCellValue("F$row", $task['workers'])
->setCellValue("G$row", $task['hours'])
->setCellValue("H$row", $hour = static::hour($market->city, $work))
->setCellValue("H$row", $hour = static::hour('market', $market->city, $work))
->setCellValue("I$row", $payment = $hour * $task['hours'])
->setCellValue("J$row", $payment);
@ -533,15 +533,18 @@ final class payments extends core
/**
* Determine tariff
*
* @param string $type Type of tariffs (market, worker)
* @param string $city City in which the place of work is located
* @param string $work Type of work
*
* @return int|float Cost of work per hour (rubles)
*/
public static function hour(string $city, string $work): int|float
public static function hour(string $type, string $city, string $work): int|float
{
return match ($city) {
'Красноярск' => match (mb_strtolower($work)) {
return
match (mb_strtolower($type)) {
'market', 'магазин' => match (mb_strtolower($city)) {
'красноярск' => match (mb_strtolower($work)) {
'cashiers', 'cashier', 'кассиры', 'кассир' => 257.07,
'displayers', 'displayer', 'выкладчики', 'выкладчик' => 257.07,
'gastronomes', 'gastronome', 'гастрономы', 'гастроном' => 257.07,
@ -551,7 +554,7 @@ final class payments extends core
'universals_mobile', 'universal_mobile', 'мобильные универсалы', 'мобильный универсал' => 305,
default => 0
},
'Железногорск', 'Сосновоборск', 'Тыва' => match (mb_strtolower($work)) {
'железногорск', 'сосновоборск', ыва' => match (mb_strtolower($work)) {
'cashiers', 'cashier', 'кассиры', 'кассир' => 263.34,
'displayers', 'displayer', 'выкладчики', 'выкладчик' => 263.34,
'gastronomes', 'gastronome', 'гастрономы', 'гастроном' => 263.34,
@ -561,7 +564,7 @@ final class payments extends core
'universals_mobile', 'universal_mobile', 'мобильные универсалы', 'мобильный универсал' => 305,
default => 0
},
'Хакасия', ркутск' => match (mb_strtolower($work)) {
'хакасия', ркутск' => match (mb_strtolower($work)) {
'cashiers', 'cashier', 'кассиры', 'кассир' => 245.385,
'displayers', 'displayer', 'выкладчики', 'выкладчик' => 245.385,
'gastronomes', 'gastronome', 'гастрономы', 'гастроном' => 245.385,
@ -572,6 +575,41 @@ final class payments extends core
default => 0
},
default => 0
},
'worker', 'сотрудник' => match (mb_strtolower($city)) {
'красноярск' => match (mb_strtolower($work)) {
'cashiers', 'cashier', 'кассиры', 'кассир' => 190.91,
'displayers', 'displayer', 'выкладчики', 'выкладчик' => 190.91,
'gastronomes', 'gastronome', 'гастрономы', 'гастроном' => 190.91,
'brigadiers', 'brigadier', 'бригадиры', 'бригадир' => 250,
'loaders', 'loader', 'грузчики', 'грузчик' => 177.27,
'loaders_mobile', 'loader_mobile', 'мобильные грузчики', 'мобильный грузчик' => 250,
'universals_mobile', 'universal_mobile', 'мобильные универсалы', 'мобильный универсал' => 250,
default => 0
},
'железногорск', 'сосновоборск', 'тыва' => match (mb_strtolower($work)) {
'cashiers', 'cashier', 'кассиры', 'кассир' => 190.91,
'displayers', 'displayer', 'выкладчики', 'выкладчик' => 190.91,
'gastronomes', 'gastronome', 'гастрономы', 'гастроном' => 190.91,
'brigadiers', 'brigadier', 'бригадиры', 'бригадир' => 250,
'loaders', 'loader', 'грузчики', 'грузчик' => 177.27,
'loaders_mobile', 'loader_mobile', 'мобильные грузчики', 'мобильный грузчик' => 250,
'universals_mobile', 'universal_mobile', 'мобильные универсалы', 'мобильный универсал' => 250,
default => 0
},
'хакасия', 'иркутск' => match (mb_strtolower($work)) {
'cashiers', 'cashier', 'кассиры', 'кассир' => 181.82,
'displayers', 'displayer', 'выкладчики', 'выкладчик' => 181.82,
'gastronomes', 'gastronome', 'гастрономы', 'гастроном' => 181.82,
'brigadiers', 'brigadier', 'бригадиры', 'бригадир' => 250,
'loaders', 'loader', 'грузчики', 'грузчик' => 168.18,
'loaders_mobile', 'loader_mobile', 'мобильные грузчики', 'мобильный грузчик' => 250,
'universals_mobile', 'universal_mobile', 'мобильные универсалы', 'мобильный универсал' => 250,
default => 0
},
default => 0
},
default => 0
};
}

View File

@ -245,4 +245,51 @@ final class task extends core
default => $work
};
}
/**
* Create a transaction for work on a task
*
* @param string $task
* @param string $worker
* @param int $amount
* @param array $errors
*
* @return ?string Identificator of instance of ArangoDB
*/
public static function transaction(
string $task,
string $worker,
int $amount = 0,
array &$errors = []
): ?string {
try {
if (
collection::init(static::$arangodb->session, self::COLLECTION)
&& collection::init(static::$arangodb->session, worker::COLLECTION)
&& collection::init(static::$arangodb->session, 'transaction', true)
) {
// Инициализированы коллекции
// Запись документа в базу данны и возврат (успех)
return document::write(static::$arangodb->session, 'transaction', [
'_from' => $task,
'_to' => $worker,
'amount' => $amount,
'processed' => 0,
]);
} else throw new exception('Не удалось инициализировать коллекции');
} catch (exception $e) {
// Write to the errors registry
$errors[] = [
'text' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'stack' => $e->getTrace()
];
}
// Exit (fail)
return null;
}
}

View File

@ -2273,7 +2273,7 @@ if (typeof window.tasks !== "function") {
complete.innerText = "Завершить";
complete.setAttribute(
"onclick",
`tasks.complete(this, this.parentElement.previousElementSibling.previousElementSibling.children[0], this.parentElement.previousElementSibling, document.getElementById('${task}'))`
`tasks.complete(this, this.parentElement.previousElementSibling.previousElementSibling.previousElementSibling.children[0], this.parentElement.previousElementSibling.previousElementSibling, document.getElementById('${task}'))`
);
// Инициализация окна с ошибками