diff --git a/templates/contratti/body.php b/templates/contratti/body.php index b82dbae66..859ac30f5 100755 --- a/templates/contratti/body.php +++ b/templates/contratti/body.php @@ -127,39 +127,85 @@ echo ' // Righe documento $righe = $documento->getRighe(); + +if (!setting('Visualizza riferimento su ogni riga in stampa')) { + $riferimenti = []; + $id_rif = []; + + foreach ($righe as $riga) { + $riferimento = ($riga->getOriginalComponent() ? $riga->getOriginalComponent()->getDocument()->getReference() : null); + if (!empty($riferimento)) { + if (!array_key_exists($riferimento, $riferimenti)) { + $riferimenti[$riferimento] = []; + } + + if (!in_array($riga->id, $riferimenti[$riferimento])) { + $id_rif[] = $riga->id; + $riferimenti[$riferimento][] = $riga->id; + } + } + } +} + foreach ($righe as $riga) { $r = $riga->toArray(); $autofill->count($r['descrizione']); echo ' - - - '.nl2br($r['descrizione']); + + '; + $text = ''; + + foreach ($riferimenti as $key => $riferimento) { + if (in_array($riga->id, $riferimento)) { + if ($riga->id === $riferimento[0]) { + $riga_ordine = $database->fetchOne('SELECT numero_cliente, data_cliente FROM or_ordini WHERE id = '.prepare($riga->idordine)); + if (!empty($riga_ordine['numero_cliente']) && !empty($riga_ordine['data_cliente'])) { + $text = $text.'Ordine n. '.$riga_ordine['numero_cliente'].' del '.Translator::dateToLocale($riga_ordine['data_cliente']).'
'; + } + + $text = ''.$key.'
'; + + if ($options['pricing']) { + $text = $text.''; + } + $text = $text.''; + + echo nl2br($text); + } + } + $r['descrizione'] = str_replace('Rif. '.strtolower($key), '', $r['descrizione']); + } + + $source_type = get_class($riga); + + if (!setting('Visualizza riferimento su ogni riga in stampa')) { + echo $r['descrizione']; + } else { + echo nl2br($r['descrizione']); + } if ($riga->isArticolo()) { - // Codice articolo - $text = tr('COD. _COD_', [ - '_COD_' => $riga->codice, - ]); - echo ' -
'.$text.''; - - $autofill->count($text, true); + echo nl2br('
'.$riga->codice.''); + } else { + echo '-'; + } + if ($riga->isArticolo()) { // Seriali $seriali = $riga->serials; if (!empty($seriali)) { $text = tr('SN').': '.implode(', ', $seriali); echo ' -
'.$text.''; + '.$text.''; $autofill->count($text, true); } } echo ' - '; + '; if (!$riga->isDescrizione()) { echo ' diff --git a/templates/ddt/body.php b/templates/ddt/body.php index 3967b8585..eee070f9d 100755 --- a/templates/ddt/body.php +++ b/templates/ddt/body.php @@ -22,7 +22,7 @@ include_once __DIR__.'/../../core.php'; $prezzi_ivati = setting('Utilizza prezzi di vendita comprensivi di IVA'); // Creazione righe fantasma -$autofill = new \Util\Autofill($options['pricing'] ? 7 : 4); +$autofill = new \Util\Autofill($options['pricing'] ? 6 : 3); $rows_per_page = 16; if (!empty($options['last-page-footer'])) { $rows_per_page += 10; @@ -35,7 +35,6 @@ echo " ".tr('#', [], ['upper' => true])." - ".tr('Cod.', [], ['upper' => true])." ".tr('Descrizione', [], ['upper' => true])." ".tr('Q.tà', [], ['upper' => true]).''; @@ -55,6 +54,26 @@ if ($options['pricing']) { // Righe documento $righe = $documento->getRighe(); $num = 0; + +if (!setting('Visualizza riferimento su ogni riga in stampa')) { + $riferimenti = []; + $id_rif = []; + + foreach ($righe as $riga) { + $riferimento = ($riga->getOriginalComponent() ? $riga->getOriginalComponent()->getDocument()->getReference() : null); + if (!empty($riferimento)) { + if (!array_key_exists($riferimento, $riferimenti)) { + $riferimenti[$riferimento] = []; + } + + if (!in_array($riga->id, $riferimenti[$riferimento])) { + $id_rif[] = $riga->id; + $riferimenti[$riferimento][] = $riga->id; + } + } + } +} + foreach ($righe as $riga) { ++$num; $r = $riga->toArray(); @@ -63,74 +82,71 @@ foreach ($righe as $riga) { echo ' - - '.$num.' - + '; - '; + $text = ''; + + foreach ($riferimenti as $key => $riferimento) { + if (in_array($riga->id, $riferimento)) { + if ($riga->id === $riferimento[0]) { + $riga_ordine = $database->fetchOne('SELECT numero_cliente, data_cliente FROM or_ordini WHERE id = '.prepare($riga->idordine)); + if (!empty($riga_ordine['numero_cliente']) && !empty($riga_ordine['data_cliente'])) { + $text = $text.'Ordine n. '.$riga_ordine['numero_cliente'].' del '.Translator::dateToLocale($riga_ordine['data_cliente']).'
'; + } + $r['descrizione'] = str_replace('Rif. '.strtolower($key), '', $r['descrizione']); + preg_match("/Rif\.(.*)/s", $r['descrizione'], $rif2); + $r['descrizione'] = str_replace('Rif.'.strtolower($rif2[1]), '', $r['descrizione']); + if (!empty($rif2)) { + $text .= ''.$rif2[0].''; + } + $text .= ''.$key.''; + + if ($options['pricing']) { + $text .= ''; + } + $text .= ''; + + echo ' + + + + '.nl2br($text); + } + } + $r['descrizione'] = preg_replace("/Rif\.(.*)/s", '', $r['descrizione']); + $autofill->count($r['descrizione']); + } $source_type = get_class($riga); + + if (!setting('Visualizza riferimento su ogni riga in stampa')) { + echo $num.' + + '.$r['descrizione']; + } else { + echo $num.' + + '.nl2br($r['descrizione']); + } + if ($riga->isArticolo()) { - echo $riga->codice; + echo '
'.$riga->codice.''; } else { echo '-'; } - echo ' - - - - '.nl2br($r['descrizione']); - - //Riferimenti ordini/ddt righe - if ($riga->referenceTargets()->count()) { - $source = $source_type::find($riga->id); - $riferimenti = $source->referenceTargets; - - foreach ($riferimenti as $riferimento) { - $documento_riferimento = $riferimento->target->getDocument(); - echo ' -
'.$riferimento->target->descrizione.'
'.tr('Rif. _DOCUMENT_', [ - '_DOCUMENT_' => strtolower($documento_riferimento->getReference()), - ]).'
'; - } - } - if ($riga->isArticolo()) { - // Codice articolo - $text = tr('COD. _COD_', [ - '_COD_' => $riga->codice, - ]); - echo ' -
'.$text.''; - - $autofill->count($text, true); - // Seriali $seriali = $riga->serials; if (!empty($seriali)) { $text = tr('SN').': '.implode(', ', $seriali); echo ' -
'.$text.''; + '.$text.''; $autofill->count($text, true); } } - // Aggiunta dei riferimenti ai documenti - /* - if (setting('Riferimento dei documenti nelle stampe') && $riga->hasOriginal()) { - $ref = $riga->getOriginal()->getDocument()->getReference(); - - if (!empty($ref)) { - echo ' -
'.$ref.''; - - $autofill->count($ref, true); - } - } - */ - echo ' '; diff --git a/templates/fatture/body.php b/templates/fatture/body.php index 7e69387fa..bfad835c5 100755 --- a/templates/fatture/body.php +++ b/templates/fatture/body.php @@ -17,8 +17,6 @@ * along with this program. If not, see . */ -use Modules\Interventi\Intervento; - include_once __DIR__.'/../../core.php'; $v_iva = []; @@ -53,6 +51,26 @@ echo " // Righe documento $righe = $documento->getRighe(); $num = 0; + +if (!setting('Visualizza riferimento su ogni riga in stampa')) { + $riferimenti = []; + $id_rif = []; + + foreach ($righe as $riga) { + $riferimento = ($riga->getOriginalComponent() ? $riga->getOriginalComponent()->getDocument()->getReference() : null); + if (!empty($riferimento)) { + if (!array_key_exists($riferimento, $riferimenti)) { + $riferimenti[$riferimento] = []; + } + + if (!in_array($riga->id, $riferimenti[$riferimento])) { + $id_rif[] = $riga->id; + $riferimenti[$riferimento][] = $riga->id; + } + } + } +} + foreach ($righe as $riga) { ++$num; $r = $riga->toArray(); @@ -62,71 +80,67 @@ foreach ($righe as $riga) { $v_iva[$r['desc_iva']] = sum($v_iva[$r['desc_iva']], $riga->iva); $v_totale[$r['desc_iva']] = sum($v_totale[$r['desc_iva']], $riga->totale_imponibile); - // Descrizione della riga - $descrizione = $riga->descrizione; + echo ' + + '; - // Aggiunta riferimento più profondo per DDT attraverso Interventi - if ($riga->hasOriginalComponent() && $riga->original_document_type == Intervento::class) { - $riga_origine = $riga->getOriginalComponent(); + $text = ''; - if ($riga_origine->hasOriginalComponent()) { - $riferimento = $riga_origine->getOriginalComponent() - ->getDocument()->getReference(); + foreach ($riferimenti as $key => $riferimento) { + if (in_array($riga->id, $riferimento)) { + if ($riga->id === $riferimento[0]) { + $riga_ordine = $database->fetchOne('SELECT numero_cliente, data_cliente FROM or_ordini WHERE id = '.prepare($riga->idordine)); + if (!empty($riga_ordine['numero_cliente']) && !empty($riga_ordine['data_cliente'])) { + $text = $text.'Ordine n. '.$riga_ordine['numero_cliente'].' del '.Translator::dateToLocale($riga_ordine['data_cliente']).'
'; + } + $r['descrizione'] = str_replace('Rif. '.strtolower($key), '', $r['descrizione']); + preg_match("/Rif\.(.*)/s", $r['descrizione'], $rif2); + $r['descrizione'] = str_replace('Rif.'.strtolower($rif2[1]), '', $r['descrizione']); + if (!empty($rif2)) { + $text .= ''.$rif2[0].''; + } + $text .= ''.$key.''; - $descrizione .= "\n".tr('Rif. _DOCUMENT_', [ - '_DOCUMENT_' => strtolower($riferimento), - ]); + echo ' + + + + '.nl2br($text); + } } + $r['descrizione'] = preg_replace("/Rif\.(.*)/s", '', $r['descrizione']); + $autofill->count($r['descrizione']); } - echo ' - '; - - echo ' - - '.$num.' - '; - - echo ' - - '.nl2br(strip_tags($descrizione)); + $source_type = get_class($riga); + if (!setting('Visualizza riferimento su ogni riga in stampa')) { + echo $num.' + + '.$r['descrizione']; + } else { + echo $num.' + + '.nl2br($r['descrizione']); + } if ($riga->isArticolo()) { - // Codice articolo - $text = tr('COD. _COD_', [ - '_COD_' => $riga->codice, - ]); - echo ' -
'.$text.''; - - $autofill->count($text, true); + echo '
'.$riga->codice.''; + } else { + echo '-'; + } + if ($riga->isArticolo()) { // Seriali $seriali = $riga->serials; if (!empty($seriali)) { $text = tr('SN').': '.implode(', ', $seriali); echo ' -
'.$text.''; + '.$text.''; $autofill->count($text, true); } } - // Aggiunta dei riferimenti ai documenti - if (!empty($record['ref_documento'])) { - $data = $dbo->fetchArray("SELECT IF(numero_esterno != '', numero_esterno, numero) AS numero, data FROM co_documenti WHERE id = ".prepare($record['ref_documento'])); - - $text = tr('Rif. fattura _NUM_ del _DATE_', [ - '_NUM_' => $data[0]['numero'], - '_DATE_' => Translator::dateToLocale($data[0]['data']), - ]); - - echo ' -
'.$text.''; - - $autofill->count($text, true); - } - // Informazioni su CIG, CUP, ... if ($riga->hasOriginalComponent()) { $documento_originale = $riga->getOriginalComponent()->getDocument(); @@ -150,7 +164,7 @@ foreach ($righe as $riga) { } echo ' - '; + '; if (!$riga->isDescrizione()) { echo ' diff --git a/templates/interventi/body.php b/templates/interventi/body.php index e09c09671..9d20f98d8 100755 --- a/templates/interventi/body.php +++ b/templates/interventi/body.php @@ -151,6 +151,25 @@ echo ' $righe = $documento->getRighe(); +if (!setting('Visualizza riferimento su ogni riga in stampa')) { + $riferimenti = []; + $id_rif = []; + + foreach ($righe as $riga) { + $riferimento = ($riga->getOriginalComponent() ? $riga->getOriginalComponent()->getDocument()->getReference() : null); + if (!empty($riferimento)) { + if (!array_key_exists($riferimento, $riferimenti)) { + $riferimenti[$riferimento] = []; + } + + if (!in_array($riga->id, $riferimenti[$riferimento])) { + $id_rif[] = $riga->id; + $riferimenti[$riferimento][] = $riga->id; + } + } + } +} + if (!$righe->isEmpty()) { echo ' @@ -194,29 +213,53 @@ if (!$righe->isEmpty()) { } // Articolo echo ' - - + '; + '; // Quantità echo ' diff --git a/templates/ordini/body.php b/templates/ordini/body.php index 814ca79eb..4e199b248 100755 --- a/templates/ordini/body.php +++ b/templates/ordini/body.php @@ -24,6 +24,25 @@ $prezzi_ivati = setting('Utilizza prezzi di vendita comprensivi di IVA'); // Righe documento $righe = $documento->getRighe(); +if (!setting('Visualizza riferimento su ogni riga in stampa')) { + $riferimenti = []; + $id_rif = []; + + foreach ($righe as $riga) { + $riferimento = ($riga->getOriginalComponent() ? $riga->getOriginalComponent()->getDocument()->getReference() : null); + if (!empty($riferimento)) { + if (!array_key_exists($riferimento, $riferimenti)) { + $riferimenti[$riferimento] = []; + } + + if (!in_array($riga->id, $riferimenti[$riferimento])) { + $id_rif[] = $riga->id; + $riferimenti[$riferimento][] = $riga->id; + } + } + } +} + $columns = 7; $has_image = $righe->search(function ($item) { @@ -92,9 +111,54 @@ foreach ($righe as $riga) { echo ' - '; + '; + if ($options['pricing']) { + $text .= ' + + + '; + } + + $text .= ' + + + + '; } - echo ' -
- '.nl2br(strip_tags($riga->descrizione)); +
'; + $text = ''; + + foreach ($riferimenti as $key => $riferimento) { + if (in_array($riga->id, $riferimento)) { + if ($riga->id === $riferimento[0]) { + $riga_ordine = $riga->getOriginalComponent()->getDocument(); + $text = ''.$key.'
'; + + if ($options['pricing']) { + $text = $text.'
'; + } + $text = $text.'
'; + + echo nl2br($text); + } + } + $riga['descrizione'] = str_replace('Rif. '.strtolower($key), '', $riga['descrizione']); + } + + $source_type = get_class($riga); + + if (!setting('Visualizza riferimento su ogni riga in stampa')) { + echo $riga['descrizione']; + } else { + echo nl2br($riga['descrizione']); + } if ($riga->isArticolo()) { - // Codice articolo - $text = tr('COD. _COD_', [ - '_COD_' => $riga->codice, - ]); - echo ' -
'.$text.''; + echo nl2br('
'.$riga->codice.''); + } + if ($riga->isArticolo()) { // Seriali $seriali = $riga->serials; if (!empty($seriali)) { $text = tr('SN').': '.implode(', ', $seriali); echo ' -
'.$text.''; + '.$text.''; + + $autofill->count($text, true); } } echo ' -
- '.$num.' - '; + + $text = ''; + + foreach ($riferimenti as $key => $riferimento) { + if (in_array($riga->id, $riferimento)) { + if ($riga->id === $riferimento[0]) { + $riga_ordine = $database->fetchOne('SELECT numero_cliente, data_cliente FROM or_ordini WHERE id = '.prepare($riga->idordine)); + if (!empty($riga_ordine['numero_cliente']) && !empty($riga_ordine['data_cliente'])) { + $text = $text.'Ordine n. '.$riga_ordine['numero_cliente'].' del '.Translator::dateToLocale($riga_ordine['data_cliente']).'
'; + } + $r['descrizione'] = str_replace('Rif. '.strtolower($key), '', $r['descrizione']); + preg_match("/Rif\.(.*)/s", $r['descrizione'], $rif2); + $r['descrizione'] = str_replace('Rif.'.strtolower($rif2[1]), '', $r['descrizione']); + if (!empty($rif2)) { + $text .= ''.$rif2[0].''; + } + $text .= ''.$key.'
'; + + echo ' + + '.nl2br($text); + } + } + $r['descrizione'] = preg_replace("/Rif\.(.*)/s", '', $r['descrizione']); + $autofill->count($r['descrizione']); + } + + $source_type = get_class($riga); + if (!setting('Visualizza riferimento su ogni riga in stampa')) { + echo $num.' + '.$r['descrizione']; + } else { + echo $num.' + '.nl2br($r['descrizione']); + } if ($has_image) { if ($riga->isArticolo() && !empty($riga->articolo->image)) { @@ -120,10 +184,6 @@ foreach ($righe as $riga) { - '.nl2br($r['descrizione']); - if ($riga->isArticolo()) { if ($documento->direzione == 'entrata' && !$options['hide-item-number']) { // Codice articolo diff --git a/update/2_4_53.php b/update/2_4_53.php new file mode 100644 index 000000000..ded911176 --- /dev/null +++ b/update/2_4_53.php @@ -0,0 +1 @@ +UPDATE `zz_settings` SET `zz_settings`.`nome` = 'Visualizza riferimento su ogni riga in stampa', `help` = 'Se disabilitato, raggruppa il riferimento ai documenti collegati in un\'unica riga, se abilitato riporta i riferimenti ai documenti in ogni riga.' WHERE `zz_settings`.`nome` = "Riferimento dei documenti nelle stampe"; \ No newline at end of file