From 2f0d3a8393b072012eb6c819124f0ee77346ddef Mon Sep 17 00:00:00 2001 From: Beppe Date: Thu, 16 Jul 2020 10:37:56 +0200 Subject: [PATCH] Controlo completo fatturazione DDT da bulk --- modules/ddt/bulk.php | 61 +++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/modules/ddt/bulk.php b/modules/ddt/bulk.php index 38b9d5e75..bab4f5c01 100755 --- a/modules/ddt/bulk.php +++ b/modules/ddt/bulk.php @@ -50,43 +50,46 @@ switch (post('op')) { $id_anagrafica = $anagrafica->id; // Proseguo solo se i documenti scelti sono fatturabili - $righe = $documento_import->getRighe(); - if (!empty($righe)) { - ++$numero_totale; + if( $documento_import->isImportabile() ){ - // Ricerca fattura per anagrafica tra le registrate - $fattura = $documenti->first(function ($item, $key) use ($id_anagrafica) { - return $item->anagrafica->id == $id_anagrafica; - }); + $righe = $documento_import->getRighe(); + if (!empty($righe)) { + ++$numero_totale; - // Ricerca fattura per anagrafica se l'impostazione di accodamento è selezionata - if (!empty($accodare) && empty($fattura)) { - $fattura = Fattura::where('idanagrafica', $id_anagrafica) - ->where('idstatodocumento', $stato_documenti_accodabili->id) - ->where('idtipodocumento', $tipo_documento->id) - ->first(); + // Ricerca fattura per anagrafica tra le registrate + $fattura = $documenti->first(function ($item, $key) use ($id_anagrafica) { + return $item->anagrafica->id == $id_anagrafica; + }); - if (!empty($fattura)) { + // Ricerca fattura per anagrafica se l'impostazione di accodamento è selezionata + if (!empty($accodare) && empty($fattura)) { + $fattura = Fattura::where('idanagrafica', $id_anagrafica) + ->where('idstatodocumento', $stato_documenti_accodabili->id) + ->where('idtipodocumento', $tipo_documento->id) + ->first(); + + if (!empty($fattura)) { + $documenti->push($fattura); + } + } + + // Creazione fattura per anagrafica + if (empty($fattura)) { + $fattura = Fattura::build($anagrafica, $tipo_documento, $data, $id_segment); $documenti->push($fattura); } - } - // Creazione fattura per anagrafica - if (empty($fattura)) { - $fattura = Fattura::build($anagrafica, $tipo_documento, $data, $id_segment); - $documenti->push($fattura); - } + // Inserimento righe + foreach ($righe as $riga) { + $qta = $riga->qta_rimanente; - // Inserimento righe - foreach ($righe as $riga) { - $qta = $riga->qta_rimanente; + if ($qta > 0) { + $copia = $riga->copiaIn($fattura, $qta); - if ($qta > 0) { - $copia = $riga->copiaIn($fattura, $qta); - - // Aggiornamento seriali dalla riga dell'ordine - if ($copia->isArticolo()) { - $copia->serials = $riga->serials; + // Aggiornamento seriali dalla riga dell'ordine + if ($copia->isArticolo()) { + $copia->serials = $riga->serials; + } } } }