899 lines
37 KiB
PHP
899 lines
37 KiB
PHP
|
|
<?php
|
||
|
|
date_default_timezone_set('Europe/Moscow');
|
||
|
|
|
||
|
|
class ComplexStatus
|
||
|
|
{
|
||
|
|
public static $db = null;
|
||
|
|
|
||
|
|
public $id;
|
||
|
|
public $name;
|
||
|
|
public $status;
|
||
|
|
public $agency_id;
|
||
|
|
public $color;
|
||
|
|
public $is_archive;
|
||
|
|
|
||
|
|
public static $user_agency_id;
|
||
|
|
public static $user_id;
|
||
|
|
public static $user;
|
||
|
|
public static $client;
|
||
|
|
public static $booking_hour;
|
||
|
|
public static $booking_day;
|
||
|
|
public static $defaulStatus;
|
||
|
|
|
||
|
|
|
||
|
|
public function __construct($id = null, $default = false)
|
||
|
|
{
|
||
|
|
$pdo = new MysqlPdo(hst, ndb, user, pass);
|
||
|
|
$sql = "SET NAMES 'utf8'";
|
||
|
|
$pdo->query($sql);
|
||
|
|
static::$db = $pdo;
|
||
|
|
|
||
|
|
static::$user_agency_id = isset($_SESSION['agency_id']) ? $_SESSION['agency_id'] : 0;
|
||
|
|
static::$user_id = isset($_SESSION['id']) ? $_SESSION['id'] : 0;
|
||
|
|
static::$user = new User;
|
||
|
|
static::$client = new Clients;
|
||
|
|
|
||
|
|
if($default){
|
||
|
|
static::$defaulStatus = $this->getDefaultStatus();
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($id && is_int($id))
|
||
|
|
{
|
||
|
|
$sql = static::$db->query(
|
||
|
|
"SELECT
|
||
|
|
complex_status.*,
|
||
|
|
csr.`booking_hour`,
|
||
|
|
csr.`booking_day`
|
||
|
|
FROM `complex_status`
|
||
|
|
LEFT JOIN complex_status_reservation AS csr ON csr.`complex_status_id` = complex_status.`id`
|
||
|
|
WHERE complex_status.`id` = $id
|
||
|
|
"
|
||
|
|
);
|
||
|
|
$complex_status = static::$db->fetch_assoc($sql);
|
||
|
|
|
||
|
|
if ($complex_status)
|
||
|
|
{
|
||
|
|
$this->id = $complex_status['id'];
|
||
|
|
$this->name = $complex_status['name'];
|
||
|
|
$this->status = $complex_status['status'];
|
||
|
|
$this->agency_id = $complex_status['agency_id'];
|
||
|
|
$this->color = $complex_status['color'];
|
||
|
|
$this->is_archive = $complex_status['is_archive'];
|
||
|
|
$this->booking_hour = $complex_status['booking_hour'];
|
||
|
|
$this->booking_day = $complex_status['booking_day'];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
protected static function addEditReservation($status_id, $reservation)
|
||
|
|
{
|
||
|
|
if (!$reservation) return false;
|
||
|
|
|
||
|
|
$id = $status_id ? $status_id : $reservation->id;
|
||
|
|
|
||
|
|
$can_change_booking_queue = $reservation->can_change_booking_queue ? json_encode($reservation->can_change_booking_queue) : NULL;
|
||
|
|
|
||
|
|
// confirm
|
||
|
|
$managers_of_confirm_reservation_extension = $reservation->managers_of_confirm_reservation_extension ? json_encode($reservation->managers_of_confirm_reservation_extension) : NULL;
|
||
|
|
$employees_not_required_confirmation = $reservation->employees_not_required_confirmation ? json_encode($reservation->employees_not_required_confirmation) : NULL;
|
||
|
|
|
||
|
|
// unconfirm
|
||
|
|
$managers_of_unconfirm_reservation_extension = $reservation->managers_of_unconfirm_reservation_extension ? json_encode($reservation->managers_of_unconfirm_reservation_extension) : NULL;
|
||
|
|
$employees_not_required_unconfirmation = $reservation->employees_not_required_unconfirmation ? json_encode($reservation->employees_not_required_unconfirmation) : NULL;
|
||
|
|
|
||
|
|
if (static::getReservationByComplexStatusId($reservation->id))
|
||
|
|
{
|
||
|
|
$sql = "UPDATE `complex_status_reservation`
|
||
|
|
SET `booking_hour` = '{$reservation->booking_hour}',
|
||
|
|
`booking_day` = '{$reservation->booking_day}',
|
||
|
|
`reminder_hour` = '{$reservation->reminder_hour}',
|
||
|
|
`reminder_day` = '{$reservation->reminder_day}',
|
||
|
|
`booking_type` = '{$reservation->booking_type}',
|
||
|
|
`can_change_booking_queue` = '{$can_change_booking_queue}',
|
||
|
|
`specify_comment_confirm` = '{$reservation->specify_comment_confirm}',
|
||
|
|
`managers_of_confirm_reservation_extension` = '{$managers_of_confirm_reservation_extension}',
|
||
|
|
`employees_not_required_confirmation` = '{$employees_not_required_confirmation}',
|
||
|
|
`specify_comment_unconfirm` = '{$reservation->specify_comment_unconfirm}',
|
||
|
|
`managers_of_unconfirm_reservation_extension` = '{$managers_of_unconfirm_reservation_extension}',
|
||
|
|
`employees_not_required_unconfirmation` = '{$employees_not_required_unconfirmation}',
|
||
|
|
`reservation_extension` = '{$reservation->reservation_extension}'
|
||
|
|
WHERE `complex_status_id` = $id";
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
$sql = "INSERT INTO
|
||
|
|
`complex_status_reservation` (
|
||
|
|
`booking_hour`,
|
||
|
|
`booking_day`,
|
||
|
|
`reminder_hour`,
|
||
|
|
`reminder_day`,
|
||
|
|
`booking_type`,
|
||
|
|
`reservation_extension`,
|
||
|
|
`can_change_booking_queue`,
|
||
|
|
`specify_comment_confirm`,
|
||
|
|
`managers_of_confirm_reservation_extension`,
|
||
|
|
`employees_not_required_confirmation`,
|
||
|
|
`specify_comment_unconfirm`,
|
||
|
|
`managers_of_unconfirm_reservation_extension`,
|
||
|
|
`employees_not_required_unconfirmation`,
|
||
|
|
`complex_status_id`
|
||
|
|
)
|
||
|
|
VALUES (
|
||
|
|
'{$reservation->booking_hour}',
|
||
|
|
'{$reservation->booking_day}',
|
||
|
|
'{$reservation->reminder_hour}',
|
||
|
|
'{$reservation->reminder_day}',
|
||
|
|
'{$reservation->booking_type}',
|
||
|
|
'{$reservation->reservation_extension}',
|
||
|
|
'{$can_change_booking_queue}',
|
||
|
|
'{$reservation->specify_comment_confirm}',
|
||
|
|
'{$managers_of_confirm_reservation_extension}',
|
||
|
|
'{$employees_not_required_confirmation}',
|
||
|
|
'{$reservation->specify_comment_unconfirm}',
|
||
|
|
'{$managers_of_unconfirm_reservation_extension}',
|
||
|
|
'{$employees_not_required_unconfirmation}',
|
||
|
|
$id
|
||
|
|
)";
|
||
|
|
}
|
||
|
|
|
||
|
|
static::$db->query($sql);
|
||
|
|
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function getReservationById($id)
|
||
|
|
{
|
||
|
|
$sql = static::$db->query("SELECT * FROM `complex_status_reservation` WHERE `id` = $id");
|
||
|
|
|
||
|
|
if ($sql)
|
||
|
|
{
|
||
|
|
return static::$db->fetch_assoc($sql);
|
||
|
|
}
|
||
|
|
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function getReservationByComplexStatusId($complex_status_id)
|
||
|
|
{
|
||
|
|
$sql = static::$db->query("SELECT * FROM `complex_status_reservation` WHERE `complex_status_id` = $complex_status_id");
|
||
|
|
|
||
|
|
if ($sql)
|
||
|
|
{
|
||
|
|
return static::$db->fetch_assoc($sql);
|
||
|
|
}
|
||
|
|
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected static function removeReservationByStatusComplexId($complex_status_id)
|
||
|
|
{
|
||
|
|
$sql = "UPDATE `complex_status_reservation`
|
||
|
|
SET `booking_hour` = NULL,
|
||
|
|
`booking_day` = NULL,
|
||
|
|
`reminder_hour` = NULL,
|
||
|
|
`reminder_day` = NULL,
|
||
|
|
`booking_type` = 'constant'
|
||
|
|
WHERE `complex_status_id` = $complex_status_id";
|
||
|
|
|
||
|
|
static::$db->query($sql);
|
||
|
|
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function checkStatusInherit($complex_status_id, $status = '')
|
||
|
|
{
|
||
|
|
if ($complex_status_id) {
|
||
|
|
$statusInherit = static::$db->query("SELECT id FROM `complex_status` WHERE `id` = $complex_status_id AND status = '{$status}'");
|
||
|
|
}
|
||
|
|
|
||
|
|
return $statusInherit ? true : false;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function addEditEventsClinetsExtensionReservation($complex_status_id, $user_id, $client_id, $req_id, $from_id)
|
||
|
|
{
|
||
|
|
$reservation = static::getReservationByComplexStatusId($complex_status_id);
|
||
|
|
$client = static::$client->get($client_id);
|
||
|
|
|
||
|
|
if ((bool)$reservation['reservation_extension'] === false) return false;
|
||
|
|
|
||
|
|
if ($reservation['id'] && $user_id && $client_id && $req_id && $from_id) {
|
||
|
|
$dop_text = "Истекло время бронирования по заявке ID $req_id, " . $client->fio . ". Продлить бронь?";
|
||
|
|
|
||
|
|
$events_cilent = static::$db->fetch_assoc(static::$db->query("SELECT * FROM `events_clients` WHERE `req_id` = $req_id AND `from_id` = $from_id AND `event` = 'extension_reservation_$reservation[id]'"));
|
||
|
|
|
||
|
|
if (!empty($events_cilent)) {
|
||
|
|
$now = new DateTime("now");
|
||
|
|
static::$db->query("UPDATE `events_clients` SET `user_id` = $user_id, `client_id` = $client_id, `req_id` = $req_id, `from_id` = $from_id, `read` = 0, `date_update` = '" . $now->format('Y-m-d H:i:s') . "' WHERE `id` = " . $events_cilent['id']);
|
||
|
|
} else {
|
||
|
|
static::$db->query("INSERT INTO `events_clients` (
|
||
|
|
`user_id`,
|
||
|
|
`client_id`,
|
||
|
|
`req_id`,
|
||
|
|
`from_id`,
|
||
|
|
`event`,
|
||
|
|
`dop_text`
|
||
|
|
)
|
||
|
|
VALUES (
|
||
|
|
$user_id,
|
||
|
|
$client_id,
|
||
|
|
$req_id,
|
||
|
|
$from_id,
|
||
|
|
'extension_reservation_$reservation[id]',
|
||
|
|
'{$dop_text}')
|
||
|
|
");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function extesionReservation($type, $event_id, $comment)
|
||
|
|
{
|
||
|
|
$event_sql = static::$db->query("SELECT * FROM `events_clients` WHERE `id` = $event_id");
|
||
|
|
|
||
|
|
if ($event_sql)
|
||
|
|
{
|
||
|
|
$event = static::$db->fetch_assoc($event_sql);
|
||
|
|
|
||
|
|
$client_id = $event['client_id'];
|
||
|
|
$req_id = $event['req_id'];
|
||
|
|
|
||
|
|
$user_id = static::$user_id;
|
||
|
|
$user = static::$db->fetch_assoc(static::$db->query("SELECT * FROM `users` WHERE `id` = " . $user_id));
|
||
|
|
$fio = trim($user['last_name'] . ' ' . $user['first_name'] );
|
||
|
|
|
||
|
|
$csr_id = (int)explode('extension_reservation_', $event['event'])[1];
|
||
|
|
$reservation = static::$db->fetch_assoc(static::$db->query("SELECT * FROM `complex_status_reservation` WHERE `id` = $csr_id"));
|
||
|
|
$complex_status = static::$db->fetch_assoc(static::$db->query("SELECT * FROM `complex_status` WHERE `id` = " . $reservation['complex_status_id']));
|
||
|
|
|
||
|
|
$requisition = static::$db->fetch_assoc(static::$db->query("SELECT `who_work`, `complex_room_id` FROM `requisitions` WHERE `id` = $req_id"));
|
||
|
|
$m_confirm_re_ids = json_decode($reservation['managers_of_confirm_reservation_extension']);
|
||
|
|
$m_unconfirm_re_ids = json_decode($reservation['managers_of_unconfirm_reservation_extension']);
|
||
|
|
$er_confirmation_ids = json_decode($reservation['employees_not_required_confirmation']);
|
||
|
|
$er_unconfirmation_ids = json_decode($reservation['employees_not_required_unconfirmation']);
|
||
|
|
|
||
|
|
$text = null;
|
||
|
|
$text_telegram = null;
|
||
|
|
$events_clients_list = [];
|
||
|
|
|
||
|
|
static::$db->query("UPDATE `requisitions` SET `er_is_interrupted` = 1 WHERE `id` = $req_id");
|
||
|
|
|
||
|
|
if ($type === 'confirm')
|
||
|
|
{
|
||
|
|
$dop_text = "Сотрудник $fio запросил продление брони: " . $complex_status['name'] . ".";
|
||
|
|
$text = "Сотрудник $fio ";
|
||
|
|
|
||
|
|
if (!in_array($user_id, $er_confirmation_ids) && !in_array($user_id, $m_confirm_re_ids))
|
||
|
|
{
|
||
|
|
$text_telegram = $text . "запросил продление брони по заявке ID $req_id.";
|
||
|
|
$text .= "запросил продление брони. Отправлен запрос на продление.";
|
||
|
|
|
||
|
|
$events_clients_list = $m_confirm_re_ids;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
$new_reservation_date = new DateTime("now");
|
||
|
|
$change_reservation_updated_at = $new_reservation_date->format('Y-m-d H:i:s');
|
||
|
|
|
||
|
|
$format_date = new DateTime("now");
|
||
|
|
$format_date = $format_date->modify('+' . $reservation['booking_day'] . ' day');
|
||
|
|
$format_date = $format_date->modify('+' . $reservation['booking_hour'] . ' hour');
|
||
|
|
$format_date = $format_date->format('d.m.Y H:i:s');
|
||
|
|
|
||
|
|
$text = "Бронь продлена до " . $format_date;
|
||
|
|
$text_telegram = $text . "продлил бронь.";
|
||
|
|
|
||
|
|
static::$db->query("UPDATE `requisitions` SET `reservation_updated_at` = '{$change_reservation_updated_at}', `is_interrupted` = 0, `er_is_interrupted` = 0 WHERE `id` = $req_id");
|
||
|
|
}
|
||
|
|
|
||
|
|
if ((bool)$reservation['specify_comment_confirm'] === true)
|
||
|
|
{
|
||
|
|
$dop_text .= "<br/>Комментарий: " . $comment;
|
||
|
|
$text .= "<br/>Комментарий: " . $comment;
|
||
|
|
$text_telegram .= "<br/>Комментарий: " . $comment;
|
||
|
|
}
|
||
|
|
|
||
|
|
$event_column = 'ext_confirming_res_' . $csr_id;
|
||
|
|
}
|
||
|
|
else if ($type === 'unconfirm')
|
||
|
|
{
|
||
|
|
$dop_text = "Сотрудник $fio запросил отмену брони: " . $complex_status['name'] . ".";
|
||
|
|
$text = "Сотрудник $fio ";
|
||
|
|
|
||
|
|
if (!in_array($user_id, $er_unconfirmation_ids) && !in_array($user_id, $m_unconfirm_re_ids))
|
||
|
|
{
|
||
|
|
$text_telegram = $text . "запросил отмену брони по заявке ID $req_id.";
|
||
|
|
$text .= "запросил отмену брони. Отправлен запрос на отмену брони.";
|
||
|
|
|
||
|
|
$events_clients_list = $m_unconfirm_re_ids;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
$text .= "отменил бронь.";
|
||
|
|
$text_telegram = $text . "отменил бронь.";
|
||
|
|
|
||
|
|
static::updateRoomsStatus(['new_status_id' => 4, 'status_id' => $reservation['complex_status_id'], 'complex_room_id' => $requisition['complex_room_id']], false, false);
|
||
|
|
}
|
||
|
|
|
||
|
|
if ((bool)$reservation['specify_comment_unconfirm'] === true)
|
||
|
|
{
|
||
|
|
$dop_text .= "<br/>Комментарий: " . $comment;
|
||
|
|
$text .= "<br/>Комментарий: " . $comment;
|
||
|
|
$text_telegram .= "<br/>Комментарий: " . $comment;
|
||
|
|
}
|
||
|
|
|
||
|
|
$event_column = 'ext_unconfirming_res_' . $csr_id;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
$dop_text = removeAllWhitespaceIncludingNbsp($dop_text);
|
||
|
|
$text = removeAllWhitespaceIncludingNbsp($text);
|
||
|
|
|
||
|
|
$now = new DateTime("now");
|
||
|
|
$create_date = $now->format('Y-m-d H:i:s');
|
||
|
|
|
||
|
|
if (count($events_clients_list) > 0)
|
||
|
|
{
|
||
|
|
foreach ($events_clients_list as $mre_id)
|
||
|
|
{
|
||
|
|
static::$db->query("INSERT INTO `events_clients` (
|
||
|
|
`user_id`,
|
||
|
|
`client_id`,
|
||
|
|
`req_id`,
|
||
|
|
`from_id`,
|
||
|
|
`event`,
|
||
|
|
`dop_text`,
|
||
|
|
`date`
|
||
|
|
)
|
||
|
|
VALUES (
|
||
|
|
$user_id,
|
||
|
|
$client_id,
|
||
|
|
$req_id,
|
||
|
|
$mre_id,
|
||
|
|
'{$event_column}',
|
||
|
|
'{$dop_text}',
|
||
|
|
'{$create_date}'
|
||
|
|
)");
|
||
|
|
|
||
|
|
$telegramm_chat_id = static::$db->fetch_assoc(static::$db->query("SELECT `telegramm_chat_id` FROM `users` WHERE `id` = $mre_id"))['telegramm_chat_id'];
|
||
|
|
|
||
|
|
if($telegramm_chat_id > 0)
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
$TELEGRAM_TOKEN = '793676666:AAGFo66CjsmO2KxZVRwQbH8pLTvenpsHiHI';
|
||
|
|
|
||
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . "/telegramm/vendor/autoload.php";
|
||
|
|
header('Content-Type: application/json');
|
||
|
|
|
||
|
|
$telegram_bot = new \TelegramBot\Api\Client($TELEGRAM_TOKEN);
|
||
|
|
$telegram_bot->sendMessage($telegramm_chat_id, htmlToTelegramMarkdown($text_telegram), 'markdown');
|
||
|
|
}
|
||
|
|
catch (Exception $e)
|
||
|
|
{
|
||
|
|
(new Logger())->error($e->getMessage());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static::$db->query("INSERT INTO `user_client_events` (
|
||
|
|
`user_id`,
|
||
|
|
`req_id`,
|
||
|
|
`client_id`,
|
||
|
|
`type`,
|
||
|
|
`comment`,
|
||
|
|
`from_id`,
|
||
|
|
`create_date`
|
||
|
|
)
|
||
|
|
VALUES (
|
||
|
|
$user_id,
|
||
|
|
$req_id,
|
||
|
|
$client_id,
|
||
|
|
'comment',
|
||
|
|
'{$text}',
|
||
|
|
$requisition[who_work],
|
||
|
|
'{$create_date}'
|
||
|
|
)
|
||
|
|
");
|
||
|
|
|
||
|
|
static::$db->query("UPDATE `events_clients` SET `read` = 1, `date_update` = '{$create_date}' WHERE `id` = $event_id");
|
||
|
|
|
||
|
|
return [
|
||
|
|
'client_id' => $client_id,
|
||
|
|
'req_id' => $req_id
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function employeeExtesionReservation($type, $event_id, $comment)
|
||
|
|
{
|
||
|
|
$event_sql = static::$db->query("SELECT * FROM `events_clients` WHERE `id` = $event_id");
|
||
|
|
|
||
|
|
if ($event_sql && $type)
|
||
|
|
{
|
||
|
|
$event = static::$db->fetch_assoc($event_sql);
|
||
|
|
$event_type = preg_split("/_res_|ext_/", $event['event']);
|
||
|
|
$event_type_status = (string)$event_type[1];
|
||
|
|
$csr_id = (int)$event_type[2];
|
||
|
|
|
||
|
|
$req_id = $event['req_id'];
|
||
|
|
$client_id = $event['client_id'];
|
||
|
|
$user_id = static::$user_id;
|
||
|
|
|
||
|
|
$reservation = static::$db->fetch_assoc(static::$db->query("SELECT * FROM `complex_status_reservation` WHERE `id` = $csr_id"));
|
||
|
|
$requisition = static::$db->fetch_assoc(static::$db->query("SELECT `who_work`, `complex_room_id` FROM `requisitions` WHERE `id` = $req_id"));
|
||
|
|
|
||
|
|
$m_confirm_re_ids = json_decode($reservation['managers_of_confirm_reservation_extension']);
|
||
|
|
$m_unconfirm_re_ids = json_decode($reservation['managers_of_unconfirm_reservation_extension']);
|
||
|
|
$events_clients_list = ($event_type_status == 'confirming') ? $m_confirm_re_ids : $m_unconfirm_re_ids;
|
||
|
|
|
||
|
|
$user = static::$db->fetch_assoc(static::$db->query("SELECT * FROM `users` WHERE `id` = " . $user_id));
|
||
|
|
$fio = trim($user['last_name'] . ' ' . $user['first_name'] );
|
||
|
|
|
||
|
|
$text = null;
|
||
|
|
$text_telegram = null;
|
||
|
|
|
||
|
|
$new_reservation_date = new DateTime("now");
|
||
|
|
$change_reservation_updated_at = $new_reservation_date->format('Y-m-d H:i:s');
|
||
|
|
|
||
|
|
$format_date = new DateTime("now");
|
||
|
|
$format_date = $format_date->modify('+' . $reservation['booking_day'] . ' day');
|
||
|
|
$format_date = $format_date->modify('+' . $reservation['booking_hour'] . ' hour');
|
||
|
|
$format_date = $format_date->format('d.m.Y H:i:s');
|
||
|
|
|
||
|
|
if ($type == 'confirming')
|
||
|
|
{
|
||
|
|
if ($type == $event_type_status)
|
||
|
|
{
|
||
|
|
$text = "Бронь продлена до " . $format_date;
|
||
|
|
$text_telegram = "Сотрудник $fio подтвердил продление брони по заявке ID $req_id.";
|
||
|
|
|
||
|
|
static::$db->query("UPDATE `requisitions` SET `reservation_updated_at` = '$change_reservation_updated_at', `is_interrupted` = 0, `er_is_interrupted` = 0 WHERE `id` = $req_id");
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
$text = "Бронь не продлена.";
|
||
|
|
$text_telegram = "Сотрудник $fio подтвердил отмену брони по заявке ID $req_id.";
|
||
|
|
|
||
|
|
static::updateRoomsStatus(['new_status_id' => 4, 'status_id' => $reservation['complex_status_id'], 'complex_room_id' => $requisition['complex_room_id']], false, false);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else if ($type == 'unconfirming')
|
||
|
|
{
|
||
|
|
if ($type == $event_type_status)
|
||
|
|
{
|
||
|
|
$text = "Бронь продлена до " . $format_date;
|
||
|
|
$text_telegram = "Сотрудник $fio отказал в отмене брони по заявке ID $req_id.";
|
||
|
|
|
||
|
|
static::$db->query("UPDATE `requisitions` SET `reservation_updated_at` = '$change_reservation_updated_at', `is_interrupted` = 0, `er_is_interrupted` = 0 WHERE `id` = $req_id");
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
$text = "Отказано в продлении брони.";
|
||
|
|
$text_telegram = "Сотрудник $fio отказал продление брони по заявке ID $req_id.";
|
||
|
|
|
||
|
|
static::updateRoomsStatus(['new_status_id' => 4, 'status_id' => $reservation['complex_status_id'], 'complex_room_id' => $requisition['complex_room_id']], false, false);
|
||
|
|
}
|
||
|
|
|
||
|
|
$events_clients_list = $m_unconfirm_re_ids;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
$text_telegram .= $comment ? ("<br/>Комментарий: " . $comment) : '';
|
||
|
|
|
||
|
|
if ($requisition['who_work'])
|
||
|
|
{
|
||
|
|
$telegramm_chat_id = static::$db->fetch_assoc(static::$db->query("SELECT `telegramm_chat_id` FROM `users` WHERE `id` = " . $requisition['who_work']))['telegramm_chat_id'];
|
||
|
|
}
|
||
|
|
|
||
|
|
if($telegramm_chat_id > 0)
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
$TELEGRAM_TOKEN = '793676666:AAGFo66CjsmO2KxZVRwQbH8pLTvenpsHiHI';
|
||
|
|
|
||
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . "/telegramm/vendor/autoload.php";
|
||
|
|
header('Content-Type: application/json');
|
||
|
|
|
||
|
|
$telegram_bot = new \TelegramBot\Api\Client($TELEGRAM_TOKEN);
|
||
|
|
$telegram_bot->sendMessage($telegramm_chat_id, htmlToTelegramMarkdown($text_telegram), 'markdown');
|
||
|
|
}
|
||
|
|
catch (Exception $e)
|
||
|
|
{
|
||
|
|
(new Logger())->error($e->getMessage());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (count($events_clients_list) > 0)
|
||
|
|
{
|
||
|
|
foreach ($events_clients_list as $mre_id)
|
||
|
|
{
|
||
|
|
static::$db->query("UPDATE `events_clients`
|
||
|
|
SET
|
||
|
|
`read` = 1
|
||
|
|
WHERE
|
||
|
|
`req_id` = $req_id
|
||
|
|
AND `from_id` = $mre_id
|
||
|
|
AND `event` = '$event[event]'"
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$text .= $comment ? ("<br/>Комментарий: " . $comment) : '';
|
||
|
|
$text = removeAllWhitespaceIncludingNbsp($text);
|
||
|
|
|
||
|
|
$now = new DateTime("now");
|
||
|
|
$create_date = $now->format('Y-m-d H:i:s');
|
||
|
|
|
||
|
|
static::$db->query("INSERT INTO `user_client_events` (
|
||
|
|
`user_id`,
|
||
|
|
`req_id`,
|
||
|
|
`client_id`,
|
||
|
|
`type`,
|
||
|
|
`comment`,
|
||
|
|
`from_id`,
|
||
|
|
`create_date`
|
||
|
|
)
|
||
|
|
VALUES (
|
||
|
|
$user_id,
|
||
|
|
$req_id,
|
||
|
|
$client_id,
|
||
|
|
'comment',
|
||
|
|
'{$text}',
|
||
|
|
$user_id,
|
||
|
|
'{$create_date}'
|
||
|
|
)
|
||
|
|
");
|
||
|
|
|
||
|
|
return [
|
||
|
|
'client_id' => $client_id,
|
||
|
|
'req_id' => $req_id
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function getComplexStatusReservations($colums = ['*'])
|
||
|
|
{
|
||
|
|
$sql = "SELECT " . implode(',', $colums) . " FROM `complex_status_reservation`";
|
||
|
|
|
||
|
|
if ($res = static::$db->query($sql))
|
||
|
|
{
|
||
|
|
$complex_status_reservation = array();
|
||
|
|
|
||
|
|
while($cs = static::$db->fetch_assoc($res))
|
||
|
|
{
|
||
|
|
$complex_status_reservation[] = $cs;
|
||
|
|
}
|
||
|
|
|
||
|
|
return $complex_status_reservation;
|
||
|
|
}
|
||
|
|
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function getDefaultStatus()
|
||
|
|
{
|
||
|
|
$sql = "SELECT * FROM `complex_status` WHERE `agency_id` IS NULL";
|
||
|
|
|
||
|
|
if ($res = static::$db->query($sql))
|
||
|
|
{
|
||
|
|
$complex_status = array();
|
||
|
|
|
||
|
|
while($cs = static::$db->fetch_assoc($res))
|
||
|
|
{
|
||
|
|
$complex_status[] = $cs;
|
||
|
|
}
|
||
|
|
|
||
|
|
return $complex_status;
|
||
|
|
}
|
||
|
|
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function getDefaultStatusStatus($status_type)
|
||
|
|
{
|
||
|
|
$result = null;
|
||
|
|
$defaultStatus = self::$defaulStatus;
|
||
|
|
|
||
|
|
foreach($defaultStatus as $status){
|
||
|
|
if($status_type == $status['status']){
|
||
|
|
$result = $status;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return $result;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
public static function getAllComplexStatus($is_archive = 0)
|
||
|
|
{
|
||
|
|
$agency_id = static::$user_agency_id;
|
||
|
|
$sql = "SELECT complex_status.*,
|
||
|
|
csr.booking_type,
|
||
|
|
csr.booking_hour,
|
||
|
|
csr.booking_day,
|
||
|
|
csr.reminder_hour,
|
||
|
|
csr.reminder_day,
|
||
|
|
csr.reservation_extension,
|
||
|
|
csr.can_change_booking_queue,
|
||
|
|
csr.specify_comment_confirm,
|
||
|
|
csr.managers_of_confirm_reservation_extension,
|
||
|
|
csr.employees_not_required_confirmation,
|
||
|
|
csr.specify_comment_unconfirm,
|
||
|
|
csr.managers_of_unconfirm_reservation_extension,
|
||
|
|
csr.employees_not_required_unconfirmation
|
||
|
|
FROM complex_status
|
||
|
|
LEFT JOIN complex_status_reservation csr ON complex_status.id = csr.complex_status_id
|
||
|
|
WHERE `agency_id` = $agency_id AND `is_archive` = $is_archive
|
||
|
|
";
|
||
|
|
|
||
|
|
if ($res = static::$db->query($sql))
|
||
|
|
{
|
||
|
|
$complex_status = array();
|
||
|
|
|
||
|
|
while($cs = static::$db->fetch_assoc($res))
|
||
|
|
{
|
||
|
|
$cs['reservation_extension'] = (bool)$cs['reservation_extension'];
|
||
|
|
$cs['specify_comment_confirm'] = (bool)$cs['specify_comment_confirm'];
|
||
|
|
$cs['specify_comment_unconfirm'] = (bool)$cs['specify_comment_unconfirm'];
|
||
|
|
$cs['can_change_booking_queue'] = json_decode($cs['can_change_booking_queue']);
|
||
|
|
$cs['managers_of_confirm_reservation_extension'] = json_decode($cs['managers_of_confirm_reservation_extension']);
|
||
|
|
$cs['employees_not_required_confirmation'] = json_decode($cs['employees_not_required_confirmation']);
|
||
|
|
$cs['managers_of_unconfirm_reservation_extension'] = json_decode($cs['managers_of_unconfirm_reservation_extension']);
|
||
|
|
$cs['employees_not_required_unconfirmation'] = json_decode($cs['employees_not_required_unconfirmation']);
|
||
|
|
|
||
|
|
|
||
|
|
$complex_status[] = $cs;
|
||
|
|
}
|
||
|
|
|
||
|
|
return $complex_status;
|
||
|
|
}
|
||
|
|
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function getAllArchiveComplexStatus()
|
||
|
|
{
|
||
|
|
return static::getAllComplexStatus(1);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function getById($id)
|
||
|
|
{
|
||
|
|
$sql = static::$db->query("SELECT * FROM `complex_status` WHERE `id` = $id");
|
||
|
|
|
||
|
|
if ($sql)
|
||
|
|
{
|
||
|
|
return static::$db->fetch_assoc($sql);
|
||
|
|
}
|
||
|
|
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function getComplexStatus()
|
||
|
|
{
|
||
|
|
if (static::$user_agency_id)
|
||
|
|
{
|
||
|
|
return array_merge(static::getDefaultStatus(), static::getAllComplexStatus());
|
||
|
|
}
|
||
|
|
|
||
|
|
return static::getDefaultStatus();
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function editAdd($status)
|
||
|
|
{
|
||
|
|
$agency_id = static::$user_agency_id;
|
||
|
|
|
||
|
|
if (!$status || !$agency_id) return false;
|
||
|
|
|
||
|
|
if(static::getById($status->id))
|
||
|
|
{
|
||
|
|
$sql = "UPDATE complex_status
|
||
|
|
SET
|
||
|
|
`name` = '{$status->name}',
|
||
|
|
`status` = '{$status->status}',
|
||
|
|
`color` = '{$status->color}'
|
||
|
|
WHERE `id` = $status->id AND `agency_id` = $agency_id";
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
$sql = "INSERT INTO complex_status (`name`, `status`, `color`, `agency_id`)
|
||
|
|
VALUES ('{$status->name}', '{$status->status}', '{$status->color}', $agency_id)";
|
||
|
|
}
|
||
|
|
|
||
|
|
static::$db->query($sql);
|
||
|
|
|
||
|
|
if ($status->booking_type == 'temporary')
|
||
|
|
{
|
||
|
|
static::addEditReservation(static::$db->insert_id(), $status);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
static::removeReservationByStatusComplexId($status->id);
|
||
|
|
}
|
||
|
|
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function updateRoomsStatus($data, $change_req_status_id = true, $complex_status_to_archive = true)
|
||
|
|
{
|
||
|
|
if (!count($data)) return false;
|
||
|
|
|
||
|
|
$data = is_array($data) ? (object)$data : $data;
|
||
|
|
|
||
|
|
$sql = "UPDATE `complex_rooms` SET `complex_status_id` = $data->new_status_id";
|
||
|
|
$sql .= $data->status_id ? " WHERE `complex_status_id` = $data->status_id" : "";
|
||
|
|
|
||
|
|
if ($data->complex_room_id && $data->status_id)
|
||
|
|
{
|
||
|
|
$sql .= " AND `id` = $data->complex_room_id";
|
||
|
|
}
|
||
|
|
else if($data->complex_room_id)
|
||
|
|
{
|
||
|
|
$sql .= " WHERE `id` = $data->complex_room_id";
|
||
|
|
}
|
||
|
|
|
||
|
|
static::$db->query($sql);
|
||
|
|
|
||
|
|
if ($change_req_status_id === true)
|
||
|
|
{
|
||
|
|
$sql = "UPDATE `requisitions` SET `complex_status_id` = $data->new_status_id WHERE `complex_status_id` = $data->status_id";
|
||
|
|
$sql .= $data->complex_room_id ? " AND `complex_room_id` = $data->complex_room_id" : "";
|
||
|
|
static::$db->query($sql);
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($complex_status_to_archive === true)
|
||
|
|
{
|
||
|
|
static::recoverOrToArchive($data->status_id, 1);
|
||
|
|
}
|
||
|
|
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function recoverOrToArchive($status_id, $status)
|
||
|
|
{
|
||
|
|
if (!$status_id || !static::$user_agency_id || !static::getById($status_id)) return false;
|
||
|
|
|
||
|
|
if ($status == 1) {
|
||
|
|
$complex = new Complex();
|
||
|
|
$existedRoomsCount = $complex->getRoomsCountByStatusId($status_id);
|
||
|
|
|
||
|
|
if ($existedRoomsCount['count']) {
|
||
|
|
http_response_code(422);
|
||
|
|
echo json_encode([
|
||
|
|
"status" => false,
|
||
|
|
"error" => [
|
||
|
|
"rooms_count" => $existedRoomsCount['count'],
|
||
|
|
]
|
||
|
|
]);
|
||
|
|
|
||
|
|
exit;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$sql = "UPDATE `complex_status` SET `is_archive` = $status WHERE `id` = $status_id";
|
||
|
|
|
||
|
|
static::$db->query($sql);
|
||
|
|
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function delete($id)
|
||
|
|
{
|
||
|
|
$agency_id = static::$user_agency_id;
|
||
|
|
|
||
|
|
if (!$agency_id) return false;
|
||
|
|
|
||
|
|
$sql = "DELETE FROM `complex_status` WHERE `id` = $id AND `agency_id` = $agency_id";
|
||
|
|
|
||
|
|
static::$db->query($sql);
|
||
|
|
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function getEmployeesAndManagers()
|
||
|
|
{
|
||
|
|
$agency_id = static::$user_agency_id;
|
||
|
|
|
||
|
|
$depClass = new Department();
|
||
|
|
$departments = $depClass->getDepartments();
|
||
|
|
$result = array();
|
||
|
|
static::$user->get($agency_id);
|
||
|
|
$usersArr[] = $agency_id;
|
||
|
|
|
||
|
|
$agency = static::$db->fetch_assoc(static::$db->query("SELECT * FROM `users` WHERE `id` = $agency_id AND `blocked` = 0"));
|
||
|
|
$result[] = array('id' => $agency_id, 'fio' => htmlspecialchars_decode(trim($agency['last_name'] . ' ' . $agency['first_name'] . ' ' . $agency['middle_name']).' (руководитель)'));
|
||
|
|
|
||
|
|
if(static::$user->agency)
|
||
|
|
{
|
||
|
|
$agentsOfAgency = User::getAllAgents(static::$user->agencyId);
|
||
|
|
$agentsOfManager = User::getAllManagers(static::$user->agencyId);
|
||
|
|
}
|
||
|
|
else if (static::$user->manager)
|
||
|
|
{
|
||
|
|
$agentsOfAgency = User::getAllAgents($userId);
|
||
|
|
}
|
||
|
|
else if (static::$user->id_manager)
|
||
|
|
{
|
||
|
|
$agentsOfAgency = User::getAllAgents(static::$user->id_manager);
|
||
|
|
$agentsOfManager = array();
|
||
|
|
while($manager = static::$db->fetch_assoc(static::$db->query("SELECT * FROM `users` WHERE `manager` = 1 AND `id` = " . static::$user->id_manager . " AND `blocked` = 0"))) $agentsOfManager[] = $manager;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
if($agentsOfManager)
|
||
|
|
{
|
||
|
|
foreach($agentsOfManager as $mngr)
|
||
|
|
{
|
||
|
|
if(!in_array($mngr['id'], $usersArr)){
|
||
|
|
$usersArr[] = $mngr['id'];
|
||
|
|
if($mngr['role_id'] > 0){
|
||
|
|
$result[] = array('id' => (int)$mngr['id'], 'fio' => htmlspecialchars_decode(trim($mngr['last_name'] . ' ' . $mngr['first_name'] . ' ' . $mngr['middle_name']).' ('.$departments[$mngr['role_id']]['role_name'].' '.$departments[$mngr['role_id']]['dep_name'].')'));
|
||
|
|
} else {
|
||
|
|
$result[] = array('id' => (int)$mngr['id'], 'fio' => htmlspecialchars_decode(trim($mngr['last_name'] . ' ' . $mngr['first_name'] . ' ' . $mngr['middle_name']).' (менеджер)'));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if((int)$mngr['role_id'] > 0 && (int)$mngr['department_id'] > 0)
|
||
|
|
{
|
||
|
|
$role_user = $depClass->getRole((int)$mngr['role_id']);
|
||
|
|
if($role_user['role'] == 'admin_department')
|
||
|
|
{
|
||
|
|
$menagerDep = static::$user->getDepManagers($role_user['department_id']);
|
||
|
|
|
||
|
|
foreach($menagerDep as $md)
|
||
|
|
{
|
||
|
|
if(!in_array($md['id'], $usersArr))
|
||
|
|
{
|
||
|
|
$usersArr[] = $md['id'];
|
||
|
|
$result[] = array('id' => (int)$md['id'], 'fio' => htmlspecialchars_decode(trim($md['last_name'] . ' ' . $md['first_name'] . ' ' . $md['middle_name']).' ('.$departments[$md['role_id']]['role_name'].' '.$departments[$md['role_id']]['dep_name'].')'));
|
||
|
|
}
|
||
|
|
$thisAgents = static::$user->getAgentsOfAgency($md['id'], true);
|
||
|
|
|
||
|
|
foreach($thisAgents as $da)
|
||
|
|
{
|
||
|
|
if (!in_array($da['id'], $usersArr))
|
||
|
|
{
|
||
|
|
$usersArr[] = $da['id'];
|
||
|
|
$result[] = array('id' => (int)$da['id'], 'fio' => htmlspecialchars_decode(trim($da['last_name'] . ' ' . $da['first_name'] . ' ' . $da['middle_name']).' ('.$departments[$da['role_id']]['role_name'].' '.$departments[$da['role_id']]['dep_name'].')'));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if($agentsOfAgency)
|
||
|
|
{
|
||
|
|
|
||
|
|
foreach($agentsOfAgency as $agent)
|
||
|
|
{
|
||
|
|
if (!in_array($agent['id'], $usersArr))
|
||
|
|
{
|
||
|
|
$usersArr[] = $agent['id'];
|
||
|
|
if($agent['role_id'] > 0){
|
||
|
|
$result[] = array('id' => (int)$agent['id'], 'fio' => htmlspecialchars_decode(trim($agent['last_name'] . ' ' . $agent['first_name'] . ' ' . $agent['middle_name']).' ('.$departments[$agent['role_id']]['role_name'].' '.$departments[$agent['role_id']]['dep_name'].')'));
|
||
|
|
|
||
|
|
} else {
|
||
|
|
$result[] = array('id' => (int)$agent['id'], 'fio' => htmlspecialchars_decode(trim($agent['last_name'] . ' ' . $agent['first_name'] . ' ' . $agent['middle_name']).' (агент)'));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
return $result;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|