openstamanager/modules/fatture/ajax/select.php

166 lines
7.0 KiB
PHP
Raw Normal View History

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';
2024-03-01 11:32:13 +01:00
$query_ordini = "SELECT
`or_ordini`.`id`,
2024-04-18 17:44:05 +02:00
CONCAT('Ordine num. ', IF(`numero_esterno` != '', `numero_esterno`, `numero`), ' del ', DATE_FORMAT(`data`, '%d/%m/%Y'), ' [', `or_statiordine_lang`.`title` , ']') AS text,
2024-03-01 11:32:13 +01:00
'Ordini' AS optgroup,
'ordine' AS tipo,
'uscita' AS dir
FROM
`or_ordini`
INNER JOIN `or_righe_ordini` ON `or_righe_ordini`.`idordine` = `or_ordini`.`id`
INNER JOIN `or_statiordine` ON `or_ordini`.`idstatoordine` = `or_statiordine`.`id`
2024-03-22 15:52:24 +01:00
LEFT JOIN `or_statiordine_lang` ON (`or_statiordine`.`id` = `or_statiordine_lang`.`id_record` AND `or_statiordine_lang`.`id_lang` = ".prepare(Models\Locale::getDefault()->id).')
2024-03-01 11:32:13 +01:00
INNER JOIN `or_tipiordine` ON `or_ordini`.`idtipoordine` = `or_tipiordine`.`id`
WHERE
2024-03-22 15:52:24 +01:00
`idanagrafica` = '.prepare($id_anagrafica)."
2024-04-18 17:44:05 +02:00
AND `title` != 'Fatturato'
2024-03-22 15:52:24 +01:00
AND `dir` = ".prepare($direzione).'
2024-03-01 11:32:13 +01:00
AND |where|
GROUP BY
`or_ordini`.`id`
HAVING
SUM(`or_righe_ordini`.`qta` - `or_righe_ordini`.`qta_evasa`) > 0
ORDER BY
2024-03-22 15:52:24 +01:00
`data` DESC, `numero` DESC';
2020-09-03 11:55:15 +02:00
2024-02-27 12:55:27 +01:00
$query_ddt = "SELECT
2024-03-01 11:32:13 +01:00
`dt_ddt`.`id`,
2024-04-18 17:44:05 +02:00
CONCAT('DDT num. ', IF(`numero_esterno` != '', `numero_esterno`, `numero`), ' del ', DATE_FORMAT(`data`, '%d/%m/%Y'), ' [', `dt_statiddt_lang`.`title`, ']') AS text,
2024-03-01 11:32:13 +01:00
'DDT' AS optgroup,
'ddt' AS tipo,
'uscita' AS dir
FROM `dt_ddt`
INNER JOIN `dt_righe_ddt` ON `dt_righe_ddt`.`idddt` = `dt_ddt`.`id`
INNER JOIN `dt_statiddt` ON `dt_ddt`.`idstato` = `dt_statiddt`.`id`
INNER JOIN `dt_tipiddt` ON `dt_ddt`.`idtipoddt` = `dt_tipiddt`.`id`
2024-03-22 15:52:24 +01:00
LEFT JOIN `dt_statiddt_lang` ON (`dt_statiddt_lang`.`id_record` = `dt_statiddt`.`id` AND `dt_statiddt_lang`.`id_lang` = ".prepare(Models\Locale::getDefault()->id).')
2024-03-01 11:32:13 +01:00
WHERE
2024-03-22 15:52:24 +01:00
`idanagrafica` = '.prepare($id_anagrafica)." AND
2024-04-18 17:44:05 +02:00
`dt_statiddt_lang`.`title` != 'Fatturato' AND
2024-03-01 11:32:13 +01:00
`dt_tipiddt`.`dir`=".prepare($direzione).'AND
|where|
GROUP BY
`dt_ddt`.`id`
HAVING
SUM(`dt_righe_ddt`.`qta` - `dt_righe_ddt`.`qta_evasa`) > 0
ORDER BY
`data` DESC, `numero` DESC';
2020-09-03 11:55:15 +02:00
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;
case 'riferimenti-vendita-fe':
$direzione = 'entrata';
$id_articolo = $superselect['id_articolo'];
if (empty($id_articolo)) {
return [];
}
// 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';
2024-03-01 11:32:13 +01:00
$query_ordini = "SELECT
`or_ordini`.`id`,
2024-04-18 17:44:05 +02:00
CONCAT('Ordine num. ', IF(`numero_esterno` != '', `numero_esterno`, `numero`), ' del ', DATE_FORMAT(data, '%d/%m/%Y'), ' [', `or_statiordine_lang`.`title`, ']') AS text,
2024-03-01 11:32:13 +01:00
'Ordini' AS optgroup,
'ordine' AS tipo,
'entrata' AS dir
FROM `or_ordini`
INNER JOIN `or_righe_ordini` ON `or_righe_ordini`.`idordine` = `or_ordini`.`id`
INNER JOIN `or_statiordine` ON `or_ordini`.`idstatoordine` = `or_statiordine`.`id`
2024-03-22 15:52:24 +01:00
LEFT JOIN `or_statiordine_lang` ON (`or_statiordine_lang`.`id_record` = `or_statiordine`.`id` AND `or_statiordine_lang`.`id_lang` = ".prepare(Models\Locale::getDefault()->id).')
2024-03-01 11:32:13 +01:00
INNER JOIN `or_tipiordine` ON `or_ordini`.`idtipiordine` = `or_tipiordine`.`id`
WHERE
2024-03-22 15:52:24 +01:00
`idarticolo` = '.prepare($id_articolo)."
2024-04-18 17:44:05 +02:00
AND `title` != 'Fatturato'
2024-03-01 11:32:13 +01:00
AND `dir` = ".prepare($direzione).'
AND |where|
GROUP BY
`or_ordini`.`id`
ORDER BY
`data` DESC, `numero` DESC';
2024-02-27 12:55:27 +01:00
$query_ddt = "SELECT
2024-03-01 11:32:13 +01:00
`dt_ddt`.`id`,
2024-04-18 17:44:05 +02:00
CONCAT('DDT num. ', IF(`numero_esterno` != '', `numero_esterno`, `numero`), ' del ', DATE_FORMAT(`data`, '%d/%m/%Y'), ' [', `dt_statiddt_lang`.`title`, ']') AS text,
2024-03-01 11:32:13 +01:00
'DDT' AS optgroup,
'ddt' AS tipo,
'entrata' AS dir
FROM
`dt_ddt`
INNER JOIN `dt_righe_ddt` ON `dt_righe_ddt`.`idddt` = `dt_ddt`.`id`
INNER JOIN `dt_statiddt` ON `dt_ddt`.`idstato` = `dt_statiddt`.`id`
2024-03-22 15:52:24 +01:00
LEFT JOIN `dt_statiddt_lang` ON (`dt_statiddt_lang`.`id_record` = `dt_statiddt`.`id` AND `dt_statiddt_lang`.`id_lang` = ".prepare(Models\Locale::getDefault()->id).')
2024-03-01 11:32:13 +01:00
INNER JOIN `dt_tipiddt` ON `dt_ddt`.`idtipoddt` = `dt_tipiddt`.`id`
WHERE
2024-03-22 15:52:24 +01:00
`idarticolo` = '.prepare($id_articolo)." AND
2024-04-18 17:44:05 +02:00
`dt_stati_lang`.`title` != 'Fatturato' AND
2024-03-01 11:32:13 +01:00
`dt_tipiddt`.`dir`=".prepare($direzione).'AND
|where|
GROUP BY
`dt_ddt`.`id`
HAVING
SUM(`dt_righe_ddt`.`qta` - `dt_righe_ddt`.`qta_evasa`) > 0
ORDER BY
`data` DESC, `numero` DESC';
// Sostituzione per la ricerca
$query_ordini = replace($query_ordini, [
'|where|' => $where,
]);
$query_ddt = replace($query_ddt, [
'|where|' => $where,
]);
$ordini = $database->fetchArray($query_ordini);
$ddt = $database->fetchArray($query_ddt);
$results = array_merge($ordini, $ddt);
break;
2020-09-03 11:55:15 +02:00
}