From de49ff77c32b5c0cd02f19e6727b4eed41d7ea82 Mon Sep 17 00:00:00 2001 From: mac Date: Sat, 20 Jun 2026 14:18:56 +0300 Subject: [PATCH] Fix icon in all clients --- ajax/ajax_vue_requisitions.php | 21 +++++++++++++++++++++ ajax/getClientsView.php | 19 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/ajax/ajax_vue_requisitions.php b/ajax/ajax_vue_requisitions.php index c549416..026510a 100644 --- a/ajax/ajax_vue_requisitions.php +++ b/ajax/ajax_vue_requisitions.php @@ -2312,6 +2312,7 @@ if($request == 'get_deal_by_req'){ if($request == 'get_deal_by_client'){ $client_id = intval($data->client_id); + // Через заявки $sql = "SELECT d.id FROM deals d JOIN requisitions r ON (r.id = d.side_one_requisition_id OR r.id = d.side_two_requisition_id) WHERE r.client_id = $client_id AND d.status != 2 GROUP BY d.id LIMIT 10"; $q = $pdo->query($sql); $deals = []; @@ -2320,6 +2321,26 @@ if($request == 'get_deal_by_client'){ $deals[] = (int)$r['id']; } } + // Через side_one_clients / side_two_clients JSON + $sqlJson = "SELECT id, side_one_clients, side_two_clients FROM deals WHERE status != 2"; + $qJson = $pdo->query($sqlJson); + if($qJson && $pdo->num_rows($qJson) > 0){ + while($r = $pdo->fetch_assoc($qJson)){ + $dealId = (int)$r['id']; + if(in_array($dealId, $deals)) continue; + foreach(['side_one_clients', 'side_two_clients'] as $field){ + $clients = json_decode($r[$field], true); + if(is_array($clients)){ + foreach($clients as $c){ + if(isset($c['id']) && (int)$c['id'] === $client_id){ + $deals[] = $dealId; + break 2; + } + } + } + } + } + } echo json_encode(['deals' => $deals, 'total' => count($deals)]); exit(); } diff --git a/ajax/getClientsView.php b/ajax/getClientsView.php index e607747..7a4fc20 100644 --- a/ajax/getClientsView.php +++ b/ajax/getClientsView.php @@ -2073,12 +2073,31 @@ if (isset($_POST['get_list'])) { //формируем список сделок клиентов $clientDealsArray = []; if (count($clientIds) > 0) { + // Основной запрос: клиенты из requisitions $clientDealsRes = mysql_query("SELECT r.client_id, d.id as deal_id FROM deals d JOIN requisitions r ON (r.id = d.side_one_requisition_id OR r.id = d.side_two_requisition_id) WHERE r.client_id IN (" . implode(", ", $clientIds) . ") AND d.status != 2 GROUP BY r.client_id, d.id"); if ($clientDealsRes && mysql_num_rows($clientDealsRes) > 0) { while ($dealRow = mysql_fetch_assoc($clientDealsRes)) { $clientDealsArray[$dealRow['client_id']][] = (int)$dealRow['deal_id']; } } + // Дополнительно: клиенты из side_one_clients / side_two_clients JSON + $jsonDealsRes = mysql_query("SELECT id, side_one_clients, side_two_clients FROM deals WHERE status != 2"); + if ($jsonDealsRes && mysql_num_rows($jsonDealsRes) > 0) { + while ($dealRow = mysql_fetch_assoc($jsonDealsRes)) { + $dealId = (int)$dealRow['id']; + foreach (['side_one_clients', 'side_two_clients'] as $field) { + $clientsJson = json_decode($dealRow[$field], true); + if (is_array($clientsJson)) { + foreach ($clientsJson as $c) { + $cid = isset($c['id']) ? (int)$c['id'] : 0; + if ($cid > 0 && in_array($cid, $clientIds) && !isset($clientDealsArray[$cid])) { + $clientDealsArray[$cid][] = $dealId; + } + } + } + } + } + } } $contractsArray = [];