Aggiunta impostazione per raggruppare i riferimenti riga in fase di stampa

This commit is contained in:
Pek5892 2023-12-13 17:33:24 +01:00
parent e6e8ed58da
commit ea49c110d4
6 changed files with 311 additions and 131 deletions

View File

@ -127,39 +127,85 @@ echo '
// Righe documento // Righe documento
$righe = $documento->getRighe(); $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) { foreach ($righe as $riga) {
$r = $riga->toArray(); $r = $riga->toArray();
$autofill->count($r['descrizione']); $autofill->count($r['descrizione']);
echo ' echo '
<tr> <tr>
<td> <td>';
'.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.'<b>Ordine n. '.$riga_ordine['numero_cliente'].' del '.Translator::dateToLocale($riga_ordine['data_cliente']).'</b><br>';
}
$text = '<b>'.$key.'</b><br>';
if ($options['pricing']) {
$text = $text.'<td></td><td></td>';
}
$text = $text.'</td><td></td></tr><tr><td>';
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()) { if ($riga->isArticolo()) {
// Codice articolo echo nl2br('<br><small>'.$riga->codice.'</small>');
$text = tr('COD. _COD_', [ } else {
'_COD_' => $riga->codice, echo '-';
]); }
echo '
<br><small>'.$text.'</small>';
$autofill->count($text, true);
if ($riga->isArticolo()) {
// Seriali // Seriali
$seriali = $riga->serials; $seriali = $riga->serials;
if (!empty($seriali)) { if (!empty($seriali)) {
$text = tr('SN').': '.implode(', ', $seriali); $text = tr('SN').': '.implode(', ', $seriali);
echo ' echo '
<br><small>'.$text.'</small>'; <small>'.$text.'</small>';
$autofill->count($text, true); $autofill->count($text, true);
} }
} }
echo ' echo '
</td>'; </td>';
if (!$riga->isDescrizione()) { if (!$riga->isDescrizione()) {
echo ' echo '

View File

@ -22,7 +22,7 @@ include_once __DIR__.'/../../core.php';
$prezzi_ivati = setting('Utilizza prezzi di vendita comprensivi di IVA'); $prezzi_ivati = setting('Utilizza prezzi di vendita comprensivi di IVA');
// Creazione righe fantasma // Creazione righe fantasma
$autofill = new \Util\Autofill($options['pricing'] ? 7 : 4); $autofill = new \Util\Autofill($options['pricing'] ? 6 : 3);
$rows_per_page = 16; $rows_per_page = 16;
if (!empty($options['last-page-footer'])) { if (!empty($options['last-page-footer'])) {
$rows_per_page += 10; $rows_per_page += 10;
@ -35,7 +35,6 @@ echo "
<thead> <thead>
<tr> <tr>
<th class='text-center' style='width:5%'>".tr('#', [], ['upper' => true])."</th> <th class='text-center' style='width:5%'>".tr('#', [], ['upper' => true])."</th>
<th class='text-center'>".tr('Cod.', [], ['upper' => true])."</th>
<th class='text-center'>".tr('Descrizione', [], ['upper' => true])."</th> <th class='text-center'>".tr('Descrizione', [], ['upper' => true])."</th>
<th class='text-center'>".tr('Q.tà', [], ['upper' => true]).'</th>'; <th class='text-center'>".tr('Q.tà', [], ['upper' => true]).'</th>';
@ -55,6 +54,26 @@ if ($options['pricing']) {
// Righe documento // Righe documento
$righe = $documento->getRighe(); $righe = $documento->getRighe();
$num = 0; $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) { foreach ($righe as $riga) {
++$num; ++$num;
$r = $riga->toArray(); $r = $riga->toArray();
@ -63,74 +82,71 @@ foreach ($righe as $riga) {
echo ' echo '
<tr> <tr>
<td class="text-center" style="vertical-align: middle"> <td class="text-center" style="vertical-align: middle">';
'.$num.'
</td>
<td class="text-center" nowrap="nowrap" style="vertical-align: middle">'; $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.'<b>Ordine n. '.$riga_ordine['numero_cliente'].' del '.Translator::dateToLocale($riga_ordine['data_cliente']).'</b><br>';
}
$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 .= '<b>'.$rif2[0].'</b>';
}
$text .= '<b>'.$key.'</b>';
if ($options['pricing']) {
$text .= '</td><td></td><td></td><td>';
}
$text .= '</td><td></td></tr><tr><td class="text-center" nowrap="nowrap" style="vertical-align: middle">';
echo '
</td>
<td>
'.nl2br($text);
}
}
$r['descrizione'] = preg_replace("/Rif\.(.*)/s", '', $r['descrizione']);
$autofill->count($r['descrizione']);
}
$source_type = get_class($riga); $source_type = get_class($riga);
if (!setting('Visualizza riferimento su ogni riga in stampa')) {
echo $num.'
</td>
<td>'.$r['descrizione'];
} else {
echo $num.'
</td>
<td>'.nl2br($r['descrizione']);
}
if ($riga->isArticolo()) { if ($riga->isArticolo()) {
echo $riga->codice; echo '<br><small>'.$riga->codice.'</small>';
} else { } else {
echo '-'; echo '-';
} }
echo '
</td>
<td>
'.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 '
<br><small>'.$riferimento->target->descrizione.'<br>'.tr('Rif. _DOCUMENT_', [
'_DOCUMENT_' => strtolower($documento_riferimento->getReference()),
]).'</small>';
}
}
if ($riga->isArticolo()) { if ($riga->isArticolo()) {
// Codice articolo
$text = tr('COD. _COD_', [
'_COD_' => $riga->codice,
]);
echo '
<br><small>'.$text.'</small>';
$autofill->count($text, true);
// Seriali // Seriali
$seriali = $riga->serials; $seriali = $riga->serials;
if (!empty($seriali)) { if (!empty($seriali)) {
$text = tr('SN').': '.implode(', ', $seriali); $text = tr('SN').': '.implode(', ', $seriali);
echo ' echo '
<br><small>'.$text.'</small>'; <small>'.$text.'</small>';
$autofill->count($text, true); $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 '
<br><small>'.$ref.'</small>';
$autofill->count($ref, true);
}
}
*/
echo ' echo '
</td>'; </td>';

View File

@ -17,8 +17,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
use Modules\Interventi\Intervento;
include_once __DIR__.'/../../core.php'; include_once __DIR__.'/../../core.php';
$v_iva = []; $v_iva = [];
@ -53,6 +51,26 @@ echo "
// Righe documento // Righe documento
$righe = $documento->getRighe(); $righe = $documento->getRighe();
$num = 0; $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) { foreach ($righe as $riga) {
++$num; ++$num;
$r = $riga->toArray(); $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_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); $v_totale[$r['desc_iva']] = sum($v_totale[$r['desc_iva']], $riga->totale_imponibile);
// Descrizione della riga echo '
$descrizione = $riga->descrizione; <tr>
<td class="text-center" style="vertical-align: middle">';
// Aggiunta riferimento più profondo per DDT attraverso Interventi $text = '';
if ($riga->hasOriginalComponent() && $riga->original_document_type == Intervento::class) {
$riga_origine = $riga->getOriginalComponent();
if ($riga_origine->hasOriginalComponent()) { foreach ($riferimenti as $key => $riferimento) {
$riferimento = $riga_origine->getOriginalComponent() if (in_array($riga->id, $riferimento)) {
->getDocument()->getReference(); 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.'<b>Ordine n. '.$riga_ordine['numero_cliente'].' del '.Translator::dateToLocale($riga_ordine['data_cliente']).'</b><br>';
}
$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 .= '<b>'.$rif2[0].'</b>';
}
$text .= '<b>'.$key.'</b></td><td></td><td></td><td></td><td></td></tr><tr><td class="text-center" nowrap="nowrap" style="vertical-align: middle">';
$descrizione .= "\n".tr('Rif. _DOCUMENT_', [ echo '
'_DOCUMENT_' => strtolower($riferimento), </td>
]);
<td>
'.nl2br($text);
}
} }
$r['descrizione'] = preg_replace("/Rif\.(.*)/s", '', $r['descrizione']);
$autofill->count($r['descrizione']);
} }
echo ' $source_type = get_class($riga);
<tr>'; if (!setting('Visualizza riferimento su ogni riga in stampa')) {
echo $num.'
echo ' </td>
<td class="text-center" style="vertical-align: middle"> <td>'.$r['descrizione'];
'.$num.' } else {
</td>'; echo $num.'
</td>
echo ' <td>'.nl2br($r['descrizione']);
<td> }
'.nl2br(strip_tags($descrizione));
if ($riga->isArticolo()) { if ($riga->isArticolo()) {
// Codice articolo echo '<br><small>'.$riga->codice.'</small>';
$text = tr('COD. _COD_', [ } else {
'_COD_' => $riga->codice, echo '-';
]); }
echo '
<br><small>'.$text.'</small>';
$autofill->count($text, true);
if ($riga->isArticolo()) {
// Seriali // Seriali
$seriali = $riga->serials; $seriali = $riga->serials;
if (!empty($seriali)) { if (!empty($seriali)) {
$text = tr('SN').': '.implode(', ', $seriali); $text = tr('SN').': '.implode(', ', $seriali);
echo ' echo '
<br><small>'.$text.'</small>'; <small>'.$text.'</small>';
$autofill->count($text, true); $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 '
<br><small>'.$text.'</small>';
$autofill->count($text, true);
}
// Informazioni su CIG, CUP, ... // Informazioni su CIG, CUP, ...
if ($riga->hasOriginalComponent()) { if ($riga->hasOriginalComponent()) {
$documento_originale = $riga->getOriginalComponent()->getDocument(); $documento_originale = $riga->getOriginalComponent()->getDocument();
@ -150,7 +164,7 @@ foreach ($righe as $riga) {
} }
echo ' echo '
</td>'; </td>';
if (!$riga->isDescrizione()) { if (!$riga->isDescrizione()) {
echo ' echo '

View File

@ -151,6 +151,25 @@ echo '
$righe = $documento->getRighe(); $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()) { if (!$righe->isEmpty()) {
echo ' echo '
<table class="table table-bordered"> <table class="table table-bordered">
@ -194,29 +213,53 @@ if (!$righe->isEmpty()) {
} }
// Articolo // Articolo
echo ' echo '
<tr> <tr>
<td> <td>';
'.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 = '<b>'.$key.'</b><br>';
if ($options['pricing']) {
$text = $text.'</td><td></td><td>';
}
$text = $text.'</td><td></td></tr><tr><td>';
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()) { if ($riga->isArticolo()) {
// Codice articolo echo nl2br('<br><small>'.$riga->codice.'</small>');
$text = tr('COD. _COD_', [ }
'_COD_' => $riga->codice,
]);
echo '
<br><small>'.$text.'</small>';
if ($riga->isArticolo()) {
// Seriali // Seriali
$seriali = $riga->serials; $seriali = $riga->serials;
if (!empty($seriali)) { if (!empty($seriali)) {
$text = tr('SN').': '.implode(', ', $seriali); $text = tr('SN').': '.implode(', ', $seriali);
echo ' echo '
<br><small>'.$text.'</small>'; <small>'.$text.'</small>';
$autofill->count($text, true);
} }
} }
echo ' echo '
</td>'; </td>';
// Quantità // Quantità
echo ' echo '

View File

@ -24,6 +24,25 @@ $prezzi_ivati = setting('Utilizza prezzi di vendita comprensivi di IVA');
// Righe documento // Righe documento
$righe = $documento->getRighe(); $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; $columns = 7;
$has_image = $righe->search(function ($item) { $has_image = $righe->search(function ($item) {
@ -92,9 +111,54 @@ foreach ($righe as $riga) {
echo ' echo '
<tr> <tr>
<td class="text-center" style="vertical-align: middle"> <td class="text-center" style="vertical-align: middle">';
'.$num.'
</td>'; $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.'<b>Ordine n. '.$riga_ordine['numero_cliente'].' del '.Translator::dateToLocale($riga_ordine['data_cliente']).'</b><br>';
}
$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 .= '<b>'.$rif2[0].'</b>';
}
$text .= '<b>'.$key.'</b></td>';
if ($options['pricing']) {
$text .= '
<td></td>
<td></td>
<td></td>';
}
$text .= '<td></td><td></td></tr><tr><td class="text-center" nowrap="nowrap" style="vertical-align: middle">';
echo '
</td>
<td>
'.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.'
</td>
<td>'.$r['descrizione'];
} else {
echo $num.'
</td>
<td>'.nl2br($r['descrizione']);
}
if ($has_image) { if ($has_image) {
if ($riga->isArticolo() && !empty($riga->articolo->image)) { if ($riga->isArticolo() && !empty($riga->articolo->image)) {
@ -120,10 +184,6 @@ foreach ($righe as $riga) {
</td>'; </td>';
} }
echo '
<td>
'.nl2br($r['descrizione']);
if ($riga->isArticolo()) { if ($riga->isArticolo()) {
if ($documento->direzione == 'entrata' && !$options['hide-item-number']) { if ($documento->direzione == 'entrata' && !$options['hide-item-number']) {
// Codice articolo // Codice articolo

1
update/2_4_53.php Normal file
View File

@ -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";