2018-02-03 16:29:53 +01:00
< ? 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 />.
*/
2018-02-03 16:29:53 +01:00
include_once __DIR__ . '/../../../core.php' ;
switch ( $resource ) {
case 'get_sedi' :
$idanagrafica = get ( 'idanagrafica' );
$q = " SELECT id, CONCAT_WS( ' - ', nomesede, citta ) AS descrizione FROM an_sedi WHERE idanagrafica=' " . $idanagrafica . " ' " . Modules :: getAdditionalsQuery ( 'Anagrafiche' ) . ' ORDER BY id' ;
$rs = $dbo -> fetchArray ( $q );
$n = sizeof ( $rs );
for ( $i = 0 ; $i < $n ; ++ $i ) {
echo html_entity_decode ( $rs [ $i ][ 'id' ] . ':' . $rs [ $i ][ 'descrizione' ]);
if (( $i + 1 ) < $n ) {
echo '|' ;
}
}
break ;
2024-01-15 15:30:45 +01:00
// Elenco sedi con <option>
2018-02-03 16:29:53 +01:00
case 'get_sedi_select' :
$idanagrafica = get ( 'idanagrafica' );
$q = " SELECT id, CONCAT_WS( ' - ', nomesede, citta ) AS descrizione FROM an_sedi WHERE idanagrafica=' " . $idanagrafica . " ' " . Modules :: getAdditionalsQuery ( 'Anagrafiche' ) . ' ORDER BY id' ;
$rs = $dbo -> fetchArray ( $q );
$n = sizeof ( $rs );
echo " <option value= \" -1 \" >- Nessuna -</option> \n " ;
echo " <option value= \" 0 \" >Sede legale</option> \n " ;
for ( $i = 0 ; $i < $n ; ++ $i ) {
echo '<option value="' . $rs [ $i ][ 'id' ] . '">' . $rs [ $i ][ 'descrizione' ] . " </option> \n " ;
}
break ;
2018-11-09 11:34:27 +01:00
2024-01-15 15:30:45 +01:00
// Elenco e-mail
2018-11-09 11:34:27 +01:00
case 'get_email' :
$id_anagrafica = get ( 'id_anagrafica' );
if ( ! empty ( $id_anagrafica )) {
$where = 'AND idanagrafica = ' . prepare ( $id_anagrafica );
}
$results = [];
// Tutti i referenti per questo cliente
2022-02-07 17:45:28 +01:00
$q = " SELECT DISTINCT(email), (SELECT nomesede FROM an_sedi WHERE an_sedi.id=an_referenti.idsede) AS sede, idanagrafica, nome AS ragione_sociale FROM an_referenti WHERE email != '' " . $where . ' ORDER BY idanagrafica' ;
2018-11-09 11:34:27 +01:00
$rs = $dbo -> fetchArray ( $q );
foreach ( $rs as $r ) {
$results [] = [
'value' => $r [ 'email' ],
2023-08-04 14:54:28 +02:00
'label' => $r [ 'ragione_sociale' ] . ( $r [ 'sede' ] != '' ? ' (' . $r [ 'sede' ] . ')' : '' ) . ' <' . $r [ 'email' ] . '>' ,
2018-11-09 11:34:27 +01:00
];
}
2024-01-15 15:30:45 +01:00
// Tutti le sedi per questo cliente
$q = " SELECT DISTINCT(email), id AS idanagrafica, nomesede AS ragione_sociale FROM an_sedi WHERE email != '' " . $where . ' ORDER BY id' ;
2020-01-22 10:49:44 +01:00
2024-01-15 15:30:45 +01:00
$rs = $dbo -> fetchArray ( $q );
foreach ( $rs as $r ) {
$results [] = [
'value' => $r [ 'email' ],
'label' => $r [ 'ragione_sociale' ] . ' <' . $r [ 'email' ] . '>' ,
];
}
2020-01-22 10:49:44 +01:00
2022-09-29 16:06:05 +02:00
// Tutti gli agenti del cliente
2023-08-04 14:54:28 +02:00
$q = " SELECT DISTINCT(email), ragione_sociale, idanagrafica FROM an_anagrafiche WHERE email != '' AND (idanagrafica=(SELECT idagente FROM an_anagrafiche AS agenti WHERE 1=1 " . $where . ') OR idanagrafica IN (SELECT idagente FROM an_anagrafiche_agenti WHERE 1=1 ' . $where . '))' ;
2018-11-09 11:34:27 +01:00
$rs = $dbo -> fetchArray ( $q );
foreach ( $rs as $r ) {
$results [] = [
'value' => $r [ 'email' ],
'label' => $r [ 'ragione_sociale' ] . ' <' . $r [ 'email' ] . '>' ,
];
}
// Email del cliente
2018-11-12 18:32:46 +01:00
$query = " SELECT DISTINCT(email) AS email, ragione_sociale, idanagrafica FROM an_anagrafiche WHERE email != '' " . $where ;
2018-11-30 16:10:15 +01:00
// Se type pec, propongo anche la pec
if ( get ( 'type' ) == 'pec' ) {
2022-09-29 16:06:05 +02:00
$query .= " UNION SELECT DISTINCT(pec), ragione_sociale, idanagrafica FROM an_anagrafiche WHERE pec != '' " . $where ;
2018-11-09 11:34:27 +01:00
}
$query .= ' ORDER BY idanagrafica' ;
$rs = $dbo -> fetchArray ( $query );
foreach ( $rs as $r ) {
$results [] = [
'value' => $r [ 'email' ],
'label' => $r [ 'ragione_sociale' ] . ' <' . $r [ 'email' ] . '>' ,
];
}
echo json_encode ( $results );
break ;
2018-02-03 16:29:53 +01:00
}