2020-09-03 11:55:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
include_once __DIR__.'/../../../core.php';
|
|
|
|
|
|
|
|
switch ($resource) {
|
|
|
|
/*
|
|
|
|
* Opzioni utilizzate:
|
|
|
|
* - id_anagrafica
|
|
|
|
*/
|
|
|
|
case 'riferimenti-fe':
|
|
|
|
$direzione = 'uscita';
|
|
|
|
$id_anagrafica = $superselect['id_anagrafica'];
|
|
|
|
if (empty($id_anagrafica)) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2020-09-10 17:30:18 +02:00
|
|
|
// Campi di ricerca
|
|
|
|
$search_fields = [];
|
|
|
|
if (!empty($search)) {
|
|
|
|
$search_fields[] = "IF(numero_esterno != '', numero_esterno, numero) LIKE ".prepare('%'.$search.'%');
|
|
|
|
$search_fields[] = "DATE_FORMAT(data, '%d/%m/%Y') LIKE ".prepare('%'.$search.'%');
|
|
|
|
}
|
|
|
|
|
|
|
|
$where = implode(' OR ', $search_fields);
|
|
|
|
$where = $where ? '('.$where.')' : '1=1';
|
|
|
|
|
2020-09-03 11:55:15 +02:00
|
|
|
$query_ordini = "SELECT or_ordini.id,
|
2020-09-10 16:43:28 +02:00
|
|
|
CONCAT('Ordine num. ', IF(numero_esterno != '', numero_esterno, numero), ' del ', DATE_FORMAT(data, '%d/%m/%Y'), ' [', (SELECT descrizione FROM or_statiordine WHERE id = idstatoordine) , ']') AS text,
|
2020-09-03 11:55:15 +02:00
|
|
|
'Ordini' AS optgroup,
|
|
|
|
'ordine' AS tipo
|
|
|
|
FROM or_ordini
|
2020-09-16 09:14:00 +02:00
|
|
|
INNER JOIN or_righe_ordini ON or_righe_ordini.idordine = or_ordini.id
|
2020-09-03 11:55:15 +02:00
|
|
|
WHERE idanagrafica = ".prepare($id_anagrafica)." AND
|
|
|
|
idstatoordine IN (
|
2020-09-10 17:30:18 +02:00
|
|
|
SELECT id FROM or_statiordine WHERE descrizione != 'Fatturato'
|
2020-09-03 11:55:15 +02:00
|
|
|
) AND
|
|
|
|
idtipoordine IN (
|
|
|
|
SELECT id FROM or_tipiordine WHERE dir = ".prepare($direzione).'
|
2020-09-10 17:30:18 +02:00
|
|
|
) AND |where|
|
2020-09-16 09:14:00 +02:00
|
|
|
GROUP BY or_ordini.id
|
|
|
|
HAVING SUM(or_righe_ordini.qta - or_righe_ordini.qta_evasa) > 0
|
2020-09-03 11:55:15 +02:00
|
|
|
ORDER BY data DESC, numero DESC';
|
|
|
|
|
|
|
|
$query_ddt = "SELECT dt_ddt.id,
|
2020-09-10 16:43:28 +02:00
|
|
|
CONCAT('DDT num. ', IF(numero_esterno != '', numero_esterno, numero), ' del ', DATE_FORMAT(data, '%d/%m/%Y'), ' [', (SELECT descrizione FROM dt_statiddt WHERE id = idstatoddt) , ']') AS text,
|
2020-09-03 11:55:15 +02:00
|
|
|
'DDT' AS optgroup,
|
|
|
|
'ddt' AS tipo
|
|
|
|
FROM dt_ddt
|
2020-09-16 09:14:00 +02:00
|
|
|
INNER JOIN dt_righe_ddt ON dt_righe_ddt.idddt = dt_ddt.id
|
2020-09-03 11:55:15 +02:00
|
|
|
WHERE idanagrafica = ".prepare($id_anagrafica)." AND
|
|
|
|
idstatoddt IN (
|
2020-09-10 17:30:18 +02:00
|
|
|
SELECT id FROM dt_statiddt WHERE descrizione != 'Fatturato'
|
2020-09-03 11:55:15 +02:00
|
|
|
) AND
|
|
|
|
idtipoddt IN (
|
|
|
|
SELECT id FROM dt_tipiddt WHERE dir=".prepare($direzione).'
|
2020-09-10 17:30:18 +02:00
|
|
|
) AND |where|
|
2020-09-16 09:14:00 +02:00
|
|
|
GROUP BY dt_ddt.id
|
|
|
|
HAVING SUM(dt_righe_ddt.qta - dt_righe_ddt.qta_evasa) > 0
|
2020-09-03 11:55:15 +02:00
|
|
|
ORDER BY data DESC, numero DESC';
|
|
|
|
|
2020-09-10 17:30:18 +02:00
|
|
|
// Sostituzione per la ricerca
|
|
|
|
$query_ordini = replace($query_ordini, [
|
|
|
|
'|where|' => $where,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$query_ddt = replace($query_ddt, [
|
|
|
|
'|where|' => $where,
|
|
|
|
]);
|
|
|
|
|
2020-09-03 11:55:15 +02:00
|
|
|
$ordini = $database->fetchArray($query_ordini);
|
|
|
|
$ddt = $database->fetchArray($query_ddt);
|
|
|
|
$results = array_merge($ordini, $ddt);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|