diff --git a/ajax/ajax_vue_requisitions.php b/ajax/ajax_vue_requisitions.php index d313246..c549416 100644 --- a/ajax/ajax_vue_requisitions.php +++ b/ajax/ajax_vue_requisitions.php @@ -2310,4 +2310,55 @@ if($request == 'get_deal_by_req'){ exit(); } +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 = []; + if($q && $pdo->num_rows($q) > 0){ + while($r = $pdo->fetch_assoc($q)){ + $deals[] = (int)$r['id']; + } + } + echo json_encode(['deals' => $deals, 'total' => count($deals)]); + exit(); +} + +if($request == 'get_deal_by_object'){ + $object_id = intval($data->object_id); + $sql = "SELECT id FROM deals WHERE status != 2 AND (side_one_object_id = $object_id OR side_two_object_id = $object_id) LIMIT 10"; + $q = $pdo->query($sql); + $deals = []; + if($q && $pdo->num_rows($q) > 0){ + while($r = $pdo->fetch_assoc($q)){ + $deals[] = (int)$r['id']; + } + } + echo json_encode(['deals' => $deals, 'total' => count($deals)]); + exit(); +} + +if($request == 'get_deals_by_objects'){ + $object_ids = isset($data->object_ids) ? $data->object_ids : []; + $object_ids = array_map('intval', $object_ids); + $deals_by_object = []; + if (count($object_ids) > 0) { + $ids_str = implode(',', $object_ids); + $sql = "SELECT side_one_object_id, side_two_object_id, id FROM deals WHERE status != 2 AND (side_one_object_id IN ($ids_str) OR side_two_object_id IN ($ids_str))"; + $q = $pdo->query($sql); + if($q && $pdo->num_rows($q) > 0){ + while($r = $pdo->fetch_assoc($q)){ + if(in_array((int)$r['side_one_object_id'], $object_ids)){ + $deals_by_object[$r['side_one_object_id']] = 1; + } + if(in_array((int)$r['side_two_object_id'], $object_ids)){ + $deals_by_object[$r['side_two_object_id']] = 1; + } + } + } + } + echo json_encode(['deals_by_object' => $deals_by_object]); + exit(); +} + ?> diff --git a/ajax/getClientsView.php b/ajax/getClientsView.php index c447285..e607747 100644 --- a/ajax/getClientsView.php +++ b/ajax/getClientsView.php @@ -2070,6 +2070,17 @@ if (isset($_POST['get_list'])) { } } + //формируем список сделок клиентов + $clientDealsArray = []; + if (count($clientIds) > 0) { + $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']; + } + } + } + $contractsArray = []; $sqlContracts = "SELECT * FROM contracts_client WHERE client_id in (" . implode(", ", $clientIds) .")"; @@ -2598,7 +2609,14 @@ if (isset($_POST['get_list'])) { } ?> -