diff --git a/modules/anagrafiche/actions.php b/modules/anagrafiche/actions.php index 83b216a72..0d88c2507 100644 --- a/modules/anagrafiche/actions.php +++ b/modules/anagrafiche/actions.php @@ -25,12 +25,17 @@ switch (post('op')) { $sede->email = post('email'); $sede->save(); - + + if (!empty(post('nome')) and !empty(post('cognome')) ){ + $ragione_sociale = post('nome').' '.post('cognome'); + }else{ + $ragione_sociale = post('ragione_sociale'); + } // Informazioni sull'anagrafica $anagrafica->codice = post('codice'); $anagrafica->tipo = post('tipo'); $anagrafica->codice_destinatario = post('codice_destinatario'); - $anagrafica->ragione_sociale = post('ragione_sociale'); + $anagrafica->ragione_sociale = $ragione_sociale; $anagrafica->partita_iva = post('piva'); $anagrafica->codice_fiscale = post('codice_fiscale'); $anagrafica->tipo = post('tipo'); @@ -63,7 +68,8 @@ switch (post('op')) { $anagrafica->idagente = post('idagente'); $anagrafica->idrelazione = post('idrelazione'); $anagrafica->sitoweb = post('sitoweb'); - $anagrafica->nome_cognome = post('nome_cognome'); + $anagrafica->nome = post('nome'); + $anagrafica->cognome = post('cognome'); $anagrafica->iscrizione_tribunale = post('iscrizione_tribunale'); $anagrafica->cciaa = post('cciaa'); $anagrafica->cciaa_citta = post('cciaa_citta'); @@ -121,7 +127,7 @@ switch (post('op')) { case 'add': $idtipoanagrafica = post('idtipoanagrafica'); $ragione_sociale = post('ragione_sociale'); - + $anagrafica = Anagrafica::build($ragione_sociale, $idtipoanagrafica); $id_record = $anagrafica->id; @@ -139,7 +145,9 @@ switch (post('op')) { } $idagente = ($agente_is_logged && in_array($id_cliente, $idtipoanagrafica)) ? $user['idanagrafica'] : 0; - + + $anagrafica->nome = post('nome'); + $anagrafica->cognome = post('cognome'); $anagrafica->partita_iva = post('piva'); $anagrafica->codice_fiscale = post('codice_fiscale'); $anagrafica->indirizzo = post('indirizzo'); diff --git a/modules/anagrafiche/add.php b/modules/anagrafiche/add.php index f17153397..a2c9f2cd7 100644 --- a/modules/anagrafiche/add.php +++ b/modules/anagrafiche/add.php @@ -14,13 +14,24 @@ echo '
- {[ "type": "text", "label": "'.tr('Ragione sociale').'", "name": "ragione_sociale", "required": 1 ]} + {[ "type": "text", "label": "'.tr('Denominazione').'", "name": "ragione_sociale", "required": 1 ]}
{[ "type": "select", "label": "'.tr('Tipo di anagrafica').'", "name": "idtipoanagrafica[]", "multiple": "1", "required": 1, "values": "query=SELECT idtipoanagrafica AS id, descrizione FROM an_tipianagrafiche WHERE idtipoanagrafica NOT IN (SELECT DISTINCT(x.idtipoanagrafica) FROM an_tipianagrafiche_anagrafiche x INNER JOIN an_tipianagrafiche t ON x.idtipoanagrafica = t.idtipoanagrafica INNER JOIN an_anagrafiche ON an_anagrafiche.idanagrafica = x.idanagrafica WHERE t.descrizione = \'Azienda\' AND deleted_at IS NULL) ORDER BY descrizione", "value": "'.(isset($idtipoanagrafica) ? $idtipoanagrafica : null).'", "readonly": '.(!empty($readonly_tipo) ? 1 : 0).' ]}
+
+ +
+
+ {[ "type": "text", "label": "'.tr('Nome').'", "name": "nome", "required": 0 ]} +
+ +
+ {[ "type": "text", "label": "'.tr('Cognome').'", "name": "cognome", "required": 0 ]} +
'; + echo '
diff --git a/modules/anagrafiche/edit.php b/modules/anagrafiche/edit.php index f57c9f882..e7e09943f 100644 --- a/modules/anagrafiche/edit.php +++ b/modules/anagrafiche/edit.php @@ -38,14 +38,34 @@ if (!$cliente) {
-
- {[ "type": "text", "label": "", "name": "ragione_sociale", "required": 1, "value": "$ragione_sociale$" ]} +
+ {[ "type": "text", "label": "", "name": "ragione_sociale", "required": 1, "value": "$ragione_sociale$" ]}
- -
+ +
+ {[ "type": "text", "label": "", "maxlength": 13, "name": "piva", "class": "text-center alphanumeric-mask text-uppercase", "value": "$piva$" ]} +
+ +
{[ "type": "select", "label": "", "name": "tipo", "values": "list=\"\": \"\", \"Azienda\": \"\", \"Privato\": \"\", \"Ente pubblico\": \"\"", "value": "$tipo$" ]}
+ +
+ +
+ {[ "type": "text", "label": "", "name": "nome", "required": 0, "value": "$nome$" ]} +
+ +
+ {[ "type": "text", "label": "", "name": "cognome", "required": 0, "value": "$cognome$" ]} +
+ +
+ {[ "type": "text", "label": "", "maxlength": 16, "name": "codice_fiscale", "class": "text-center alphanumeric-mask text-uppercase", "value": "$codice_fiscale$" ]} +
+ +
-
-
- {[ "type": "text", "label": "", "maxlength": 13, "name": "piva", "class": "text-center alphanumeric-mask text-uppercase", "value": "$piva$" ]} -
- -
- {[ "type": "text", "label": "", "maxlength": 16, "name": "codice_fiscale", "class": "text-center alphanumeric-mask text-uppercase", "value": "$codice_fiscale$" ]} -
-
+
@@ -638,6 +650,42 @@ if (empty($record['deleted_at'])) { $("#lat").val(result.geometry.location.lat()); $("#lng").val(result.geometry.location.lng()); }); + + /* Campo nome e cognome*/ + if ($('#ragione_sociale').val()!='' && $('#ragione_sociale').val() != $('#nome').val()+' '+$('#cognome').val()){ + $('#nome').prop('disabled', true); + $('#cognome').prop('disabled', true); + }; + + if ($('#nome').val()!='' && $('#cognome').val()!=''){ + $('#ragione_sociale').prop('disabled', true); + $("#ragione_sociale").attr('required', false); + }; + + $('#nome, #cognome').keyup(function(){ + if ($('#nome').val() =='' && $('#cognome').val() =='' ){ + $('#ragione_sociale').prop('disabled', false); + $("#ragione_sociale").attr('required', true); + }else{ + + $('#ragione_sociale').prop('disabled', true); + $("#ragione_sociale").attr('required', false); + } + }); + + $('#ragione_sociale').keyup(function(){ + + if ($(this).val()!=''){ + $('#nome').prop('disabled', true); + $('#cognome').prop('disabled', true); + $("#ragione_sociale").attr('required', true); + }else{ + $('#nome').prop('disabled', false); + $('#cognome').prop('disabled', false); + $("#ragione_sociale").attr('required', false); + } + }); + }); diff --git a/plugins/exportFE/edit.php b/plugins/exportFE/edit.php index 71ac16725..c59459fd2 100644 --- a/plugins/exportFE/edit.php +++ b/plugins/exportFE/edit.php @@ -22,7 +22,7 @@ if (!empty($fattura_pa)) { // Campi obbligatori per il pagamento $pagamento = $database->fetchOne('SELECT * FROM `co_pagamenti` WHERE `id` = '.prepare($record['idpagamento'])); $fields = [ - 'codice_modalita_pagamento_fe' => 'Codice di pagamento FE', + 'codice_modalita_pagamento_fe' => 'Codice modalità pagamento FE', ]; $missing = []; @@ -35,7 +35,7 @@ foreach ($fields as $key => $name) { if (!empty($missing) && !$generated) { echo '
-

'.tr('Prima di procedere alla generazione della fattura elettronica completa i seguenti campi del tipo di pagamento: _FIELDS_', [ +

'.tr('Prima di procedere alla generazione della fattura elettronica completa i seguenti campi per il Pagamento: _FIELDS_', [ '_FIELDS_' => ''.implode(', ', $missing).'', ]).'

'; diff --git a/plugins/exportFE/src/FatturaElettronica.php b/plugins/exportFE/src/FatturaElettronica.php index d4c6bba00..ca2237c0f 100644 --- a/plugins/exportFE/src/FatturaElettronica.php +++ b/plugins/exportFE/src/FatturaElettronica.php @@ -621,6 +621,23 @@ class FatturaElettronica return $this->cliente; } + + /** + * Restituisce le informazioni sull'anagrafica dell'intermediario. + * + * @return array + */ + public function getIntermediario() + { + if (empty($this->intermediario)) { + $intermediario = static::getAnagrafica(setting('Terzo intermediario')); + $this->intermediario = $intermediario; + } + + return $this->intermediario; + } + + /** * Restituisce le informazioni riguardanti un anagrafica sulla base dell'identificativo fornito. @@ -823,7 +840,7 @@ class FatturaElettronica public function getFilename($new = false) { $azienda = static::getAzienda(); - $prefix = 'IT'.(empty($azienda['piva']) ? $azienda['codice_fiscale'] : $azienda['piva']); + $prefix = 'IT'.(!empty($azienda['codice_fiscale']) ? $azienda['codice_fiscale'] : $azienda['piva']); if (empty($this->documento['progressivo_invio']) || !empty($new)) { $database = database(); @@ -904,7 +921,7 @@ class FatturaElettronica $result = [ 'IdTrasmittente' => [ 'IdPaese' => $azienda['nazione'], - 'IdCodice' => (!empty($azienda['piva'])) ? $azienda['piva'] : $azienda['codice_fiscale'], + 'IdCodice' => (!empty($azienda['codice_fiscale'])) ? $azienda['codice_fiscale'] : $azienda['piva'], ], 'ProgressivoInvio' => $documento['progressivo_invio'], 'FormatoTrasmissione' => ($cliente['tipo'] == 'Ente pubblico') ? 'FPA12' : 'FPR12', @@ -940,10 +957,12 @@ class FatturaElettronica // Partita IVA (obbligatoria se presente) if (!empty($anagrafica['piva'])) { - $result['IdFiscaleIVA'] = [ - 'IdPaese' => $anagrafica['nazione'], - 'IdCodice' => $anagrafica['piva'], - ]; + + if (!empty($anagrafica['nazione'])) + $result['IdFiscaleIVA']['IdPaese'] = $anagrafica['nazione']; + + $result['IdFiscaleIVA']['IdCodice'] = $anagrafica['piva']; + } // Codice fiscale @@ -1043,7 +1062,7 @@ class FatturaElettronica } /** - * Restituisce l'array responsabile per la generazione del tag CessionarioCommittente. + * Restituisce l'array responsabile per la generazione del tag CessionarioCommittente (1.4). * * @return array */ @@ -1058,6 +1077,24 @@ class FatturaElettronica return $result; } + + + /** + * Restituisce l'array responsabile per la generazione del tag TerzoIntermediarioOSoggettoEmittente (1.5). + * + * @return array + */ + protected static function getTerzoIntermediarioOSoggettoEmittente($fattura) + { + $intermediario = $fattura->getIntermediario(); + + $result = [ + 'DatiAnagrafici' => static::getDatiAnagrafici($intermediario), + ]; + + return $result; + } + /** * Restituisce l'array responsabile per la generazione del tag DatiGeneraliDocumento. @@ -1412,7 +1449,10 @@ class FatturaElettronica } if (empty($percentuale)) { - $dettaglio['Natura'] = $iva['codice_natura_fe']; + //Controllo aggiuntivo codice_natura_fe per evitare che venga riportato il tag vuoto + if (!empty($iva['codice_natura_fe'])){ + $dettaglio['Natura'] = $iva['codice_natura_fe']; + } } if (!empty($riga['riferimento_amministrazione'])) { @@ -1611,6 +1651,12 @@ class FatturaElettronica 'CedentePrestatore' => static::getCedentePrestatore($fattura), 'CessionarioCommittente' => static::getCessionarioCommittente($fattura), ]; + + //Terzo Intermediario o Soggetto Emittente + if (!empty(setting('Terzo intermediario'))){ + $result['TerzoIntermediarioOSoggettoEmittente'] = static::getTerzoIntermediarioOSoggettoEmittente($fattura); + $result['SoggettoEmittente'] = 'TZ'; + } return $result; } diff --git a/update/2_4_5.sql b/update/2_4_5.sql index caf58fe02..8e14cf590 100644 --- a/update/2_4_5.sql +++ b/update/2_4_5.sql @@ -38,4 +38,17 @@ UPDATE `an_sedi` SET `provincia` = UPPER(provincia); -- Colonna Codice Modalità (Pagamenti) -INSERT INTO `zz_views` (`id`, `id_module`, `name`, `query`, `order`, `search`, `slow`, `format`, `search_inside`, `order_by`, `visible`, `summable`, `default` ) VALUES (NULL, (SELECT `id` FROM `zz_modules` WHERE `name` = 'Pagamenti'), 'Codice Modalità', 'codice_modalita_pagamento_fe', 2, 1, 0, 0, NULL, NULL, 1, 0, 0); \ No newline at end of file +INSERT INTO `zz_views` (`id`, `id_module`, `name`, `query`, `order`, `search`, `slow`, `format`, `search_inside`, `order_by`, `visible`, `summable`, `default` ) VALUES (NULL, (SELECT `id` FROM `zz_modules` WHERE `name` = 'Pagamenti'), 'Codice Modalità', 'codice_modalita_pagamento_fe', 2, 1, 0, 0, NULL, NULL, 1, 0, 0); + + +-- Impostazione "Anagrafica del terzo intermediario" +INSERT INTO `zz_settings` (`id`, `nome`, `valore`, `tipo`, `editable`, `sezione`) VALUES (NULL, 'Terzo intermediario', '', 'query=SELECT `an_anagrafiche`.`idanagrafica` AS ''id'', `ragione_sociale` AS ''descrizione'' FROM `an_anagrafiche` INNER JOIN `an_tipianagrafiche_anagrafiche` ON `an_anagrafiche`.`idanagrafica` = `an_tipianagrafiche_anagrafiche`.`idanagrafica` WHERE `idtipoanagrafica` = (SELECT `idtipoanagrafica` FROM `an_tipianagrafiche` WHERE `descrizione` = ''Fornitore'') AND `deleted_at` IS NULL', '1', 'Fatturazione Elettronica'); + +-- Aggiungo campi nome e cognome +ALTER TABLE `an_anagrafiche` CHANGE `nome_cognome` `nome` VARCHAR(255) NOT NULL; +ALTER TABLE `an_anagrafiche` ADD `cognome` VARCHAR(255) NOT NULL AFTER `nome`; + + +-- Colonna Rif. fattura (Prima nota) +INSERT INTO `zz_views` (`id`, `id_module`, `name`, `query`, `order`, `search`, `slow`, `format`, `search_inside`, `order_by`, `visible`, `summable`, `default` ) VALUES (NULL, (SELECT `id` FROM `zz_modules` WHERE `name` = 'Prima nota'), 'Rif. fattura', 'IF((iddocumento != ''),(SELECT numero_esterno FROM co_documenti WHERE id = iddocumento), ''-'')', 2, 1, 0, 0, NULL, NULL, 1, 0, 0); +