2017-08-04 16:28:16 +02: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 />.
*/
2017-08-04 16:28:16 +02:00
2023-06-13 14:47:19 +02:00
use Modules\Anagrafiche\Nazione ;
2024-03-28 09:16:13 +01:00
use Modules\Anagrafiche\Tipo ;
2023-06-13 14:47:19 +02:00
2017-08-04 16:28:16 +02:00
include_once __DIR__ . '/../../core.php' ;
2024-06-11 17:26:05 +02:00
$id_nazione_italia = ( new Nazione ()) -> getByField ( 'title' , 'Italia' , Models\Locale :: getPredefined () -> id );
2024-03-28 09:16:13 +01:00
2024-11-27 11:56:46 +01:00
if ( $idtipoanagrafica ) {
$tipo = Tipo :: where ( 'name' , $idtipoanagrafica ) -> first () -> id ;
} else {
$tipo = get ( 'tipoanagrafica' );
2017-08-04 16:28:16 +02:00
}
2024-11-27 11:56:46 +01:00
$id_tipo_azienda = Tipo :: where ( 'name' , 'Azienda' ) -> first () -> id ;
2017-08-04 16:28:16 +02:00
echo '
2018-02-23 16:04:50 +01:00
< form action = " " method = " post " id = " add-form " >
2017-08-04 16:28:16 +02:00
< input type = " hidden " name = " op " value = " add " >
< input type = " hidden " name = " backto " value = " record-edit " >
< div class = " row " >
< div class = " col-md-6 " >
2020-07-03 15:18:57 +02:00
{[ " type " : " text " , " label " : " '.tr('Denominazione').' " , " name " : " ragione_sociale " , " id " : " ragione_sociale_add " , " required " : 1 ]}
2017-08-04 16:28:16 +02:00
</ div >
< div class = " col-md-6 " >
2024-04-18 17:44:05 +02:00
{[ " type " : " select " , " label " : " '.tr('Tipo di anagrafica').' " , " name " : " idtipoanagrafica[] " , " id " : " idtipoanagrafica_add " , " multiple " : " 1 " , " required " : 1 , " values " : " query=SELECT `an_tipianagrafiche`.`id`, `title` as descrizione FROM `an_tipianagrafiche` LEFT JOIN `an_tipianagrafiche_lang` ON (`an_tipianagrafiche`.`id` = `an_tipianagrafiche_lang`.`id_record` AND `an_tipianagrafiche_lang`.`id_lang` = '.prepare(Models \ Locale::getDefault()->id).') WHERE `an_tipianagrafiche`.`id` NOT IN (SELECT DISTINCT(`x`.`idtipoanagrafica`) FROM `an_tipianagrafiche_anagrafiche` x INNER JOIN `an_tipianagrafiche` t ON `x`.`idtipoanagrafica` = `t`.`id` LEFT JOIN `an_tipianagrafiche_lang` ON (`t`.`id` = `an_tipianagrafiche_lang`.`id_record` AND `an_tipianagrafiche_lang`.`id_lang` = '.prepare(Models \ Locale::getDefault()->id).') INNER JOIN `an_anagrafiche` ON `an_anagrafiche`.`idanagrafica` = `x`.`idanagrafica` WHERE `an_tipianagrafiche`.`id` = '.prepare( $id_tipo_azienda ).' AND `deleted_at` IS NULL) ORDER BY `title` " , " value " : " '.( $idtipoanagrafica ?? null).' " , " readonly " : '.(!empty(get(' readonly_tipo ')) ? 1 : 0).' ]}
2017-08-04 16:28:16 +02:00
</ div >
2019-01-04 19:23:28 +01:00
</ div >
2019-01-05 09:53:17 +01:00
2019-01-04 19:23:28 +01:00
< div class = " row " >
< div class = " col-md-6 " >
2021-02-23 15:47:25 +01:00
{[ " type " : " text " , " label " : " '.tr('Cognome').' " , " name " : " cognome " , " id " : " cognome_add " ]}
2019-01-04 19:23:28 +01:00
</ div >
2020-02-17 18:43:49 +01:00
2019-01-04 19:23:28 +01:00
< div class = " col-md-6 " >
2021-02-23 15:47:25 +01:00
{[ " type " : " text " , " label " : " '.tr('Nome').' " , " name " : " nome " , " id " : " nome_add " ]}
2019-01-04 19:23:28 +01:00
</ div >
2018-04-17 23:41:56 +02:00
</ div > ' ;
2019-01-05 09:53:17 +01:00
2018-07-03 11:12:32 +02:00
echo '
2024-05-20 11:13:08 +02:00
< br >
2024-05-16 18:02:50 +02:00
< div class = " card card-info collapsed-card " >
< div class = " card-header " >
< h3 class = " card-title " > '.tr(' Dati anagrafici ').' </ h3 >
< div class = " card-tools pull-right " >
< button type = " button " class = " btn btn-tool " data - card - widget = " collapse " >
< i class = " fa fa-plus " ></ i >
</ button >
</ div >
</ div >
< div class = " card-body collapse " >
2018-04-17 23:41:56 +02:00
< div class = " row " >
< div class = " col-md-4 " >
2023-06-13 14:47:19 +02:00
{[ " type " : " text " , " label " : " '.tr('Partita IVA').' " , " maxlength " : 16 , " name " : " piva " , " id " : " piva_add " , " class " : " text-center alphanumeric-mask " , " validation " : " partita_iva " ]}
2018-04-17 23:41:56 +02:00
</ div >
< div class = " col-md-4 " >
2019-07-05 12:28:19 +02:00
{[ " type " : " text " , " label " : " '.tr('Codice fiscale').' " , " maxlength " : 16 , " name " : " codice_fiscale " , " class " : " text-center alphanumeric-mask " , " validation " : " codice_fiscale " ]}
2018-04-17 23:41:56 +02:00
</ div >
2020-02-17 18:43:49 +01:00
2018-04-17 23:41:56 +02:00
< div class = " col-md-4 " >
2024-02-25 11:24:18 +01:00
{[ " type " : " select " , " label " : " '.tr('Tipologia').' " , " name " : " tipo " , " id " : " tipo_add " , " values " : " list= \" Azienda \" : \" '.tr('Azienda').' \" , \" Ente pubblico \" : \" '.tr('Ente pubblico').' \" , \" Privato \" : \" '.tr('Privato').' \" " , " placeholder " : " '.tr('Non specificato').' " ]}
2018-04-17 23:41:56 +02:00
</ div >
</ div >
< div class = " row " >
< div class = " col-md-4 " >
2018-07-03 12:28:38 +02:00
{[ " type " : " text " , " label " : " '.tr('Indirizzo').' " , " name " : " indirizzo " ]}
2018-04-17 23:41:56 +02:00
</ div >
< div class = " col-md-2 " >
2021-02-01 12:07:38 +01:00
{[ " type " : " text " , " label " : " '.tr('C.A.P.').' " , " name " : " cap " , " maxlength " : 6 , " class " : " text-center " ]}
2018-04-17 23:41:56 +02:00
</ div >
< div class = " col-md-4 " >
2018-07-03 12:28:38 +02:00
{[ " type " : " text " , " label " : " '.tr('Città').' " , " name " : " citta " , " class " : " text-center " ]}
2018-04-17 23:41:56 +02:00
</ div >
< div class = " col-md-2 " >
2018-11-29 14:46:31 +01:00
{[ " type " : " text " , " label " : " '.tr('Provincia').' " , " name " : " provincia " , " maxlength " : 2 , " class " : " text-center " , " extra " : " onkeyup= \" this.value = this.value.toUpperCase(); \" " ]}
2018-04-17 23:41:56 +02:00
</ div >
</ div >
< div class = " row " >
2020-02-17 18:43:49 +01:00
2019-03-21 11:39:33 +01:00
< div class = " col-md-4 " >
2024-04-18 17:44:05 +02:00
{[ " type " : " select " , " label " : " '.tr('Nazione').' " , " name " : " id_nazione " , " id " : " id_nazione_add " , " values " : " query=SELECT `an_nazioni`.`id` AS id, CONCAT_WS( \ ' - \ ', `iso2`, `an_nazioni_lang`.`title`) AS descrizione, `iso2` FROM `an_nazioni` LEFT JOIN `an_nazioni_lang` ON (`an_nazioni`.`id` = `an_nazioni_lang`.`id_record` AND `an_nazioni_lang`.`id_lang` = '.prepare(Models \ Locale::getDefault()->id).') ORDER BY CASE WHEN `iso2`= \ 'IT \ ' THEN -1 ELSE `iso2` END " , " value " : " '. $id_nazione_italia .' " ]}
2019-03-21 11:39:33 +01:00
</ div >
2020-02-17 18:43:49 +01:00
2018-04-17 23:41:56 +02:00
< div class = " col-md-4 " >
2023-10-06 12:44:54 +02:00
{[ " type " : " telefono " , " label " : " '.tr('Telefono').' " , " name " : " telefono " , " class " : " text-center " ]}
2018-04-17 23:41:56 +02:00
</ div >
< div class = " col-md-4 " >
2023-10-06 12:44:54 +02:00
{[ " type " : " telefono " , " label " : " '.tr('Cellulare').' " , " name " : " cellulare " , " class " : " text-center " ]}
2018-04-17 23:41:56 +02:00
</ div >
2019-03-21 11:39:33 +01:00
</ div >
2020-02-17 18:43:49 +01:00
2019-03-21 11:39:33 +01:00
< div class = " row " >
2020-02-17 18:43:49 +01:00
2018-04-17 23:41:56 +02:00
< div class = " col-md-4 " >
2024-10-30 12:16:43 +01:00
{[ " type " : " email " , " label " : " '.tr('Email').' " , " name " : " email " , " placeholder " : " casella@dominio.ext " , " validation " : " email " ]}
2018-04-17 23:41:56 +02:00
</ div >
2020-02-17 18:43:49 +01:00
2019-03-21 11:39:33 +01:00
< div class = " col-md-4 " >
2024-10-30 12:16:43 +01:00
{[ " type " : " email " , " label " : " '.tr('PEC').' " , " name " : " pec " , " placeholder " : " pec@dominio.ext " ]}
2019-03-21 11:39:33 +01:00
</ div > ' ;
2019-04-04 17:30:58 +02:00
2024-02-25 11:24:18 +01:00
$help_codice_destinatario = tr ( " Per impostare il codice specificare prima '<b>Tipologia</b>' e '<b>Nazione</b>' dell'anagrafica " ) . ':<br><br><ul><li>' . tr ( 'Azienda (B2B) - Codice Destinatario, 7 caratteri' ) . '</li><li>' . tr ( 'Ente pubblico (B2G/PA) - Codice Univoco Ufficio (www.indicepa.gov.it), 6 caratteri' ) . '</li><li>' . tr ( 'Privato (B2C) - viene utilizzato il Codice Fiscale' ) . '</li></ul>Se non si conosce il codice destinatario lasciare vuoto il campo. Verrà applicato in automatico quello previsto di default dal sistema (\'0000000\', \'999999\', \'XXXXXXX\').' ;
2019-04-04 17:30:58 +02:00
2019-03-21 11:39:33 +01:00
echo '
< div class = " col-md-4 " >
2021-02-23 15:47:25 +01:00
{[ " type " : " text " , " label " : " '.tr('Codice destinatario').' " , " name " : " codice_destinatario " , " class " : " text-center text-uppercase alphanumeric-mask " , " maxlength " : " 7 " , " extra " : " " , " help " : " '.tr( $help_codice_destinatario ).' " , " readonly " : " 1 " ]}
2019-03-21 11:39:33 +01:00
</ div >
</ div >
2018-04-17 23:41:56 +02:00
</ div >
</ div > ' ;
2020-02-17 18:43:49 +01:00
echo '
< div class = " row " >
2017-08-04 16:28:16 +02:00
< div class = " col-md-12 text-right " >
2018-02-18 19:53:23 +01:00
< button type = " submit " class = " btn btn-primary " >< i class = " fa fa-plus " ></ i > '.tr(' Aggiungi ').' </ button >
2017-08-04 16:28:16 +02:00
</ div >
</ div >
</ form > ' ;
2019-01-05 09:53:17 +01:00
?>
< script >
2021-02-23 15:47:25 +01:00
var nome = input ( " nome " );
var cognome = input ( " cognome " );
var ragione_sociale = input ( " ragione_sociale " );
var id_nazione = input ( " id_nazione " );
2020-07-03 15:18:57 +02:00
2019-01-05 09:53:17 +01:00
// Abilito solo ragione sociale oppure solo nome-cognome in base a cosa compilo
2021-02-23 15:47:25 +01:00
nome . on ( " keyup " , function () {
if ( nome . get ()) {
ragione_sociale . disable ();
} else if ( ! cognome . get ()) {
ragione_sociale . enable ();
2019-01-05 09:53:17 +01:00
}
});
2021-02-23 15:47:25 +01:00
cognome . on ( " keyup " , function () {
if ( cognome . get ()) {
ragione_sociale . disable ();
} else if ( ! nome . get ()) {
ragione_sociale . enable ();
2020-07-03 15:18:57 +02:00
}
});
2021-02-23 15:47:25 +01:00
ragione_sociale . on ( " keyup " , function () {
let disable = ragione_sociale . get () !== " " ;
nome . setDisabled ( disable );
cognome . setDisabled ( disable );
2019-01-05 09:53:17 +01:00
});
2019-10-04 13:26:47 +02:00
2021-02-23 15:47:25 +01:00
id_nazione . change ( function () {
2023-06-13 14:47:19 +02:00
if ( id_nazione . get () !== null ) {
if (( id_nazione . getData () . iso2 === 'IT' ) || ( id_nazione . getData () . iso2 === 'SM' )) {
input ( " codice_destinatario " ) . enable ();
} else {
input ( " codice_destinatario " ) . disable ();
}
// Aggiunta nazione come parametro aggiuntivo per la validazione partita iva
$ ( " #piva_add " ) . data ( " additional " , $ ( this ) . selectData () . iso2 );
2019-10-04 13:26:47 +02:00
}
});
2023-06-13 14:47:19 +02:00
$ ( document ) . ready ( function (){
id_nazione . trigger ( 'change' );
});
2019-04-09 17:58:42 +02:00
</ script >