Fix icon in all clients
This commit is contained in:
parent
fe2860dd0b
commit
de49ff77c3
@ -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();
|
||||
}
|
||||
|
||||
@ -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 = [];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user