From c6c32330eee0d00ef8a19aa98b176af5605cbd89 Mon Sep 17 00:00:00 2001 From: pek5892 Date: Wed, 22 May 2024 17:11:46 +0200 Subject: [PATCH] Aggiunta file header.php in fatture --- modules/fatture/edit.php | 169 +++++++++--------- modules/fatture/header.php | 351 +++++++++++++++++++++++++++++++++++++ 2 files changed, 436 insertions(+), 84 deletions(-) create mode 100644 modules/fatture/header.php diff --git a/modules/fatture/edit.php b/modules/fatture/edit.php index 352fa5655..2e04a9291 100755 --- a/modules/fatture/edit.php +++ b/modules/fatture/edit.php @@ -42,6 +42,8 @@ $id_stato_parz_pagato = (new StatoFattura())->getByField('title', 'Parzialmente $id_stato_non_valida = (new StatoFattura())->getByField('title', 'Non valida', Models\Locale::getPredefined()->id); $id_stato_annullata = (new StatoFattura())->getByField('title', 'Annullata', Models\Locale::getPredefined()->id); +$id_modulo_anagrafiche = (new Module())->getByField('title', 'Anagrafiche', Models\Locale::getPredefined()->id); + $block_edit = !empty($note_accredito) || in_array($fattura->stato->id, [$id_stato_parz_pagato, $id_stato_pagato, $id_stato_emessa]) || !$abilita_genera; if ($dir == 'entrata') { @@ -258,13 +260,93 @@ if ($righe_vuote) { '; } +$query = 'SELECT `co_statidocumento`.*, `co_statidocumento`.`id` AS id, `colore` AS _bgcolor_, `co_statidocumento_lang`.`title` as descrizione FROM `co_statidocumento` LEFT JOIN `co_statidocumento_lang` ON (`co_statidocumento_lang`.`id_record` = `co_statidocumento`.`id` AND `co_statidocumento_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).')'; +if (empty($record['is_fiscale'])) { + $query .= " WHERE `co_statidocumento`.`id` = '.$id_stato_bozza.'"; + + $plugin = $dbo->fetchArray('SELECT `zz_plugins`.`id` FROM `zz_plugins` LEFT JOIN `zz_plugins_lang` ON (`zz_plugins`.`id` = `zz_plugins_lang`.`id_record` AND `zz_plugins_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).") WHERE `title`='Fatturazione Elettronica' AND `idmodule_to` = ".prepare($id_module)); + echo ''; +} +// Forzo il passaggio della fattura da Bozza ad Emessa per il corretto calcolo del numero. +elseif ($fattura->stato->id == $id_stato_bozza) { + $query .= ' WHERE `co_statidocumento`.`id` IN ('.$id_stato_emessa.', '.$id_stato_bozza.')'; +} + +$query .= ' ORDER BY `title`'; + ?>
- + +
+ +
> + {[ "type": "select", "label": "", "name": "codice_stato_fe", "values": "query=SELECT `codice` as id, CONCAT_WS(' - ',`codice`, `title`) as text FROM `fe_stati_documento` LEFT JOIN `fe_stati_documento_lang` ON (`fe_stati_documento_lang`.`id_record` = `fe_stati_documento`.`codice` AND `fe_stati_documento_lang`.`id_lang` = id); ?>)", "value": "$codice_stato_fe$", "disabled": stato->id == $id_stato_bozza && $abilita_genera)); ?>, "class": "unblockable", "help": "" ]} +
+ + + {[ "type": "select", "label": "'.tr('Stato').'", "name": "idstatodocumento", "required": 1, "values": "query='.$query.'", "value": "'.$fattura->stato->id.'", "class": "'.(($fattura->stato->id != $id_stato_bozza && !$abilita_genera) ? '' : 'unblockable').'", "extra": "onchange=\"return cambiaStato()\"" ]} +
+ + + +
+
+

'.tr('Dati cliente').'

+
+ +
+
+
+ +
+
+ '.Modules::link('Anagrafiche', $record['idanagrafica'], null, null, 'class="pull-right"'); + +if ($dir == 'entrata') { + ?> + {[ "type": "select", "label": "", "name": "idanagrafica", "required": 1, "ajax-source": "clienti", "help": "fetchOne('SELECT `ragione_sociale` FROM `an_anagrafiche` WHERE `idanagrafica` = '.prepare(setting('Azienda predefinita')))['ragione_sociale']); ?>", "value": "$idanagrafica$" ]} + + {[ "type": "select", "label": "", "name": "idanagrafica", "required": 1, "ajax-source": "fornitori", "value": "$idanagrafica$" ]} +'; + +if ($dir == 'entrata') { + echo ' +
'; + if ($record['idagente'] != 0) { + echo Modules::link('Anagrafiche', $record['idagente_fattura'], null, null, 'class="pull-right"'); + } + echo ' + {[ "type": "select", "label": "'.tr('Agente di riferimento').'", "name": "idagente", "ajax-source": "agenti", "select-options": {"idanagrafica": '.$record['idanagrafica'].'}, "value": "$idagente_fattura$" ]} +
'; +} + +echo ' +
'; +if (!empty($record['idreferente'])) { + echo Plugins::link('Referenti', $record['idanagrafica'], null, null, 'class="pull-right"'); +} +$id_modulo_anagrafiche = (new Module())->getByField('title', 'Anagrafiche', Models\Locale::getPredefined()->id); +echo ' + {[ "type": "select", "label": "'.tr('Referente').'", "name": "idreferente", "value": "$idreferente$", "ajax-source": "referenti", "select-options": {"idanagrafica": '.$record['idanagrafica'].', "idsede_destinazione": '.$record['idsede_destinazione'].'}, "icon-after": "add|'.$id_modulo_anagrafiche.'|id_plugin='.(new Plugin())->getByField('title', 'Referenti', Models\Locale::getPredefined()->id).'&id_parent='.$record['idanagrafica'].'||'.(intval($block_edit) ? 'disabled' : '').'" ]} +
+
+
+
'; +?>

@@ -283,14 +365,12 @@ if ($righe_vuote) { {[ "type": "text", "label": "'.tr('Numero fattura/protocollo').'", "required": 1, "name": "numero","class": "text-center alphanumeric-mask", "value": "$numero$" ]}
'; $label = tr('N. fattura del fornitore'); - $size = 2; } else { $label = tr('Numero fattura'); - $size = 4; } ?> -
+
{[ "type": "text", "label": "", "required": "", "name": "numero_esterno", "class": "text-center", "value": "$numero_esterno$", "help": "" ]}
@@ -298,28 +378,6 @@ if ($righe_vuote) { {[ "type": "date", "label": "", "name": "data", "required": 1, "value": "$data$" ]}
-id).')'; -if (empty($record['is_fiscale'])) { - $query .= " WHERE `co_statidocumento`.`id` = '.$id_stato_bozza.'"; - - $plugin = $dbo->fetchArray('SELECT `zz_plugins`.`id` FROM `zz_plugins` LEFT JOIN `zz_plugins_lang` ON (`zz_plugins`.`id` = `zz_plugins_lang`.`id_record` AND `zz_plugins_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).") WHERE `title`='Fatturazione Elettronica' AND `idmodule_to` = ".prepare($id_module)); - echo ''; -} -// Forzo il passaggio della fattura da Bozza ad Emessa per il corretto calcolo del numero. -elseif ($fattura->stato->id == $id_stato_bozza) { - $query .= ' WHERE `co_statidocumento`.`id` IN ('.$id_stato_emessa.', '.$id_stato_bozza.')'; -} - -$query .= ' ORDER BY `title`'; - -?> - -
> {[ "type": "date", "label": "", "name": "data_registrazione", "value": "$data_registrazione$", "help": "" ]}
@@ -329,64 +387,7 @@ $query .= ' ORDER BY `title`'; {[ "type": "date", "class":"unblockable", "label": "", "name": "data_competenza", "required": 1, "value": "$data_competenza$", "min-date": "$data$", "help": "" ]}
- - -
> - {[ "type": "select", "label": "", "name": "codice_stato_fe", "values": "query=SELECT `codice` as id, CONCAT_WS(' - ',`codice`, `title`) as text FROM `fe_stati_documento` LEFT JOIN `fe_stati_documento_lang` ON (`fe_stati_documento_lang`.`id_record` = `fe_stati_documento`.`codice` AND `fe_stati_documento_lang`.`id_lang` = id); ?>)", "value": "$codice_stato_fe$", "disabled": stato->id == $id_stato_bozza && $abilita_genera)); ?>, "class": "unblockable", "help": "" ]} -
- - - {[ "type": "select", "label": "'.tr('Stato').'", "name": "idstatodocumento", "required": 1, "values": "query='.$query.'", "value": "'.$fattura->stato->id.'", "class": "'.(($fattura->stato->id != $id_stato_bozza && !$abilita_genera) ? '' : 'unblockable').'", "extra": "onchange=\"return cambiaStato()\"" ]} -
- - -
-
- '.Modules::link('Anagrafiche', $record['idanagrafica'], null, null, 'class="pull-right"'); - -if ($dir == 'entrata') { - ?> - {[ "type": "select", "label": "", "name": "idanagrafica", "required": 1, "ajax-source": "clienti", "help": "fetchOne('SELECT `ragione_sociale` FROM `an_anagrafiche` WHERE `idanagrafica` = '.prepare(setting('Azienda predefinita')))['ragione_sociale']); ?>", "value": "$idanagrafica$" ]} - - {[ "type": "select", "label": "", "name": "idanagrafica", "required": 1, "ajax-source": "fornitori", "value": "$idanagrafica$" ]} -'; - -if ($dir == 'entrata') { - echo ' -
'; - if ($record['idagente'] != 0) { - echo Modules::link('Anagrafiche', $record['idagente_fattura'], null, null, 'class="pull-right"'); - } - echo ' - {[ "type": "select", "label": "'.tr('Agente di riferimento').'", "name": "idagente", "ajax-source": "agenti", "select-options": {"idanagrafica": '.$record['idanagrafica'].'}, "value": "$idagente_fattura$" ]} -
'; -} - -echo ' -
'; -if (!empty($record['idreferente'])) { - echo Plugins::link('Referenti', $record['idanagrafica'], null, null, 'class="pull-right"'); -} -$id_modulo_anagrafiche = (new Module())->getByField('title', 'Anagrafiche', Models\Locale::getPredefined()->id); -echo ' - {[ "type": "select", "label": "'.tr('Referente').'", "name": "idreferente", "value": "$idreferente$", "ajax-source": "referenti", "select-options": {"idanagrafica": '.$record['idanagrafica'].', "idsede_destinazione": '.$record['idsede_destinazione'].'}, "icon-after": "add|'.$id_modulo_anagrafiche.'|id_plugin='.(new Plugin())->getByField('title', 'Referenti', Models\Locale::getPredefined()->id).'&id_parent='.$record['idanagrafica'].'||'.(intval($block_edit) ? 'disabled' : '').'" ]} -
'; - -echo ' -
-
'; +fetchArray('SELECT `mg_articoli`.`id` FROM ((`mg_articoli` INNER JOIN `co_righe_documenti` ON `mg_articoli`.`id`=`co_righe_documenti`.`idarticolo`) INNER JOIN `co_documenti` ON `co_documenti`.`id`=`co_righe_documenti`.`iddocumento`) WHERE `co_documenti`.`id`='.prepare($id_record)); $id_plugin_sedi = (new Plugin())->getByField('title', 'Sedi', Models\Locale::getPredefined()->id); diff --git a/modules/fatture/header.php b/modules/fatture/header.php new file mode 100644 index 000000000..63e5d8c77 --- /dev/null +++ b/modules/fatture/header.php @@ -0,0 +1,351 @@ +. + */ + +include_once __DIR__.'/../../core.php'; + +use Carbon\Carbon; +use Models\Module; +use Models\Upload; +use Modules\Anagrafiche\Anagrafica; +use Modules\Anagrafiche\Sede; +use Modules\Contratti\Contratto; +use Modules\Interventi\Intervento; +use Modules\Ordini\Ordine; +use Modules\Preventivi\Preventivo; +use Modules\Scadenzario\Scadenza; + +// Anagrafica +$anagrafica = $fattura->anagrafica; + +// Sede +if ($fattura->idsede_destinazione) { + $sede = $dbo->selectOne('an_sedi', '*', ['id' => $fattura->idsede_destinazione]); +} else { + $sede = $anagrafica->toArray(); +} + +// Referente +$referente = null; +if ($fattura->idreferente) { + $referente = $dbo->selectOne('an_referenti', '*', ['id' => $fattura->idreferente]); +} + +// Contratto +$contratto = null; +$ore_erogate = 0; +$ore_previste = 0; +$perc_ore = 0; +$color = 'danger'; +if ($fattura->id_contratto) { + $contratto = Contratto::find($fattura->id_contratto); + $ore_erogate = $contratto->interventi->sum('ore_totali'); + $ore_previste = $contratto->getRighe()->where('um', 'ore')->sum('qta'); + $perc_ore = $ore_previste != 0 ? ($ore_erogate * 100) / $ore_previste : 0; + if ($perc_ore < 75) { + $color = 'success'; + } elseif ($perc_ore <= 100) { + $color = 'warning'; + } +} + +// Preventivo +$preventivo = null; +if ($fattura->id_preventivo) { + $preventivo = Preventivo::find($fattura->id_preventivo); +} + +// Ordine +$ordine = null; +if ($fattura->id_ordine) { + $ordine = Ordine::find($fattura->id_ordine); +} + +// Attività +$interventi_programmati = Intervento::select('in_interventi.*') + ->join('in_statiintervento', 'in_interventi.idstatointervento', '=', 'in_statiintervento.id') + ->where('idanagrafica', $intervento->idanagrafica) + ->where('idsede_destinazione', $intervento->idsede_destinazione) + ->where('is_completato', '!=', 1) + ->where('in_interventi.id', '!=', $id_record) + ->get(); + + +// Insoluti +$insoluti = Scadenza::where('idanagrafica', $fattura->idanagrafica) + ->whereRaw('co_scadenziario.da_pagare > co_scadenziario.pagato') + ->whereRaw('co_scadenziario.scadenza < NOW()') + ->count(); + +// Logo +$logo = Upload::where('id_module', (new Module())->getByField('title', 'Anagrafiche'))->where('id_record', $fattura->idanagrafica)->where('name', 'Logo azienda')->first()->filename; + +$logo = $logo ? base_path().'/files/anagrafiche/'.$logo : App::getPaths()['img'].'/logo_header.png'; + +echo ' +
+
+
+ +
'; + +// Cliente +echo ' +
+

'.$anagrafica->ragione_sociale.'

+ +

+ '.($sede['nomesede'] ? $sede['nomesede'].'
' : '').' + '.$sede['indirizzo'].'
+ '.$sede['cap'].' - '.$sede['citta'].' ('.$sede['provincia'].') +

+ +

+ '.($sede['telefono'] ? ' '.$sede['telefono'].'' : '').' + '.($sede['email'] ? ' '.$sede['email'].'' : '').' + '.($referente['nome'] ? '

'.$referente['nome'].'
' : '').' + '.($referente['telefono'] ? ' '.$referente['telefono'].'' : '').' + '.($referente['email'] ? ' '.$referente['email'].'' : '').' +

+
'; + +// Panoramica +echo ' +
+
+
+

'.tr('Panoramica').'

+
+
+ +

+ '.($insoluti ? tr('Sono presenti insoluti') : tr('Non sono presenti insoluti')).' +

+ +

'.(count($interventi_programmati) == 0 ? tr('Non sono presenti altre attività programmate') : 'Attività aperte:'); +if (count($interventi_programmati) != 0) { + foreach ($interventi_programmati as $fattura_programmato) { + echo ' '.$fattura_programmato->codice.' ('.(new Carbon($fattura_programmato->data_richiesta))->diffForHumans().')'; + } +} +echo ' +

'; +// Contratto +if ($contratto) { + echo ' +

+ '.Modules::link('Contratti', $contratto->id, tr('Contratto num. _NUM_ del _DATA_', ['_NUM_' => $contratto->numero, '_DATA_' => Translator::dateToLocale($contratto->data_bozza)])); + if ($ore_previste > 0) { + echo ' + - '.$ore_erogate.'/'.$ore_previste.' '.tr('ore').'
+ +

+
+
'; + } + echo ' +

'; +} + +// Preventivo +if ($preventivo) { + echo ' +

+ '.Modules::link('Preventivi', $preventivo->id, tr('Preventivo num. _NUM_ del _DATA_', ['_NUM_' => $preventivo->numero, '_DATA_' => Translator::dateToLocale($preventivo->data_bozza)])).' +

'; +} + +// Ordine +if ($ordine) { + echo ' +

+ '.Modules::link('Ordini cliente', $ordine->id, tr('Ordine num. _NUM_ del _DATA_', ['_NUM_' => $ordine->numero, '_DATA_' => Translator::dateToLocale($ordine->data)])).' +

'; +} +echo ' +
+
+
'; + +// Geolocalizzazione +$anagrafica_cliente = $fattura->anagrafica; +$sede_cliente = $anagrafica_cliente->sedeLegale; +if (!empty($fattura->idsede_destinazione)) { + $sede_cliente = Sede::find($fattura->idsede_destinazione); +} + +$anagrafica_azienda = Anagrafica::find(setting('Azienda predefinita')); +$sede_azienda = $anagrafica_azienda->sedeLegale; + +echo ' +
+
+
+

'.tr('Geolocalizzazione').'

+
+
'; + +if (!empty($sede_cliente->gaddress) || (!empty($sede_cliente->lat) && !empty($sede_cliente->lng))) { + echo ' +
+ +
+
+ +
+
'; + // Navigazione diretta verso l'indirizzo + echo ' + + '.tr('Carica mappa').' + +
+ +
'; + // Navigazione diretta verso l'indirizzo + echo ' + + '.tr('Calcola percorso').' + +
+
'; +} else { + echo ' +
+
'; + // Navigazione diretta verso l'indirizzo + echo ' + + '.tr('Calcola percorso').' + +
+ +
'; + // Ricerca diretta su Mappa + echo ' + + '.tr('Cerca su Mappa').' + +
+
'; +} + +echo ' +
+
+
+
+ +';