From d9beb2597a3ecd29f6045c7815ae4322a51f7da7 Mon Sep 17 00:00:00 2001 From: mac Date: Mon, 6 Jul 2026 15:47:46 +0300 Subject: [PATCH] Fix cancel deal --- ajax/cancelEvent.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ajax/cancelEvent.php b/ajax/cancelEvent.php index 8ccd4fe..05b8ada 100644 --- a/ajax/cancelEvent.php +++ b/ajax/cancelEvent.php @@ -17,6 +17,18 @@ if(isset($_POST['cancelId'])){ // Помечаем сделку как отменённую (status = 2) mysql_query("UPDATE deals SET status = 2 WHERE id = $deal_id"); + // Обнуляем deal_id у связанных заявок + $dealRow = mysql_fetch_assoc(mysql_query("SELECT side_one_requisition_id, side_two_requisition_id FROM deals WHERE id = $deal_id")); + $linkedReqs = array_filter(array_map('intval', [$dealRow['side_one_requisition_id'], $dealRow['side_two_requisition_id']])); + if (!empty($linkedReqs)) { + mysql_query("UPDATE requisitions SET deal_id = NULL WHERE id IN (" . implode(',', $linkedReqs) . ")"); + } + + // Запись в историю сделки — кто отменил + $user_id = $_SESSION['id']; + $cancel_comment = "Сделка отменена. Отменил: " . $_SESSION['fio']; + mysql_query("INSERT INTO user_client_events (user_id, deal_id, type, name, comment, create_date) VALUES ($user_id, $deal_id, 'deal', 'Отмена сделки', '" . addslashes($cancel_comment) . "', NOW())"); + // Помечаем все остальные события этой сделки как отменённые mysql_query("UPDATE user_client_events SET cancel = 1 WHERE deal_id = $deal_id AND cancel = 0"); mysql_query("UPDATE user_object_events SET cancel = 1 WHERE deal_id = $deal_id AND cancel = 0");