openstamanager/modules/contratti/ajax/select.php

48 lines
2.1 KiB
PHP
Raw Normal View History

<?php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright (C) DevCode s.r.l.
2020-09-07 15:04:06 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
include_once __DIR__.'/../../../core.php';
switch ($resource) {
/*
2020-08-17 10:57:51 +02:00
* Opzioni utilizzate:
2020-08-17 16:25:01 +02:00
* - idanagrafica
* - stato
2020-08-17 16:25:01 +02:00
*/
case 'contratti':
2019-01-10 18:41:25 +01:00
$query = 'SELECT co_contratti.id AS id, CONCAT("Contratto ", numero, " del ", DATE_FORMAT(data_bozza, "%d/%m/%Y"), " - ", co_contratti.nome, " [", (SELECT `descrizione` FROM `co_staticontratti` WHERE `co_staticontratti`.`id` = `idstato`) , "]") AS descrizione, (SELECT SUM(subtotale) FROM co_righe_contratti WHERE idcontratto=co_contratti.id) AS totale, (SELECT SUM(sconto) FROM co_righe_contratti WHERE idcontratto=co_contratti.id) AS sconto, (SELECT COUNT(id) FROM co_righe_contratti WHERE idcontratto=co_contratti.id) AS n_righe FROM co_contratti INNER JOIN an_anagrafiche ON co_contratti.idanagrafica=an_anagrafiche.idanagrafica |where| ORDER BY id';
foreach ($elements as $element) {
$filter[] = 'id='.prepare($element);
}
2019-02-14 17:49:58 +01:00
if (empty($elements)) {
$where[] = 'an_anagrafiche.idanagrafica='.prepare($superselect['idanagrafica']);
$stato = !empty($superselect['stato']) ? $superselect['stato'] : 'is_pianificabile';
2019-03-20 14:56:11 +01:00
$where[] = 'idstato IN (SELECT `id` FROM `co_staticontratti` WHERE '.$stato.' = 1)';
}
if (!empty($search)) {
2019-05-24 18:47:54 +02:00
$search_fields[] = 'co_contratti.nome LIKE '.prepare('%'.$search.'%');
}
break;
}