diff --git a/modules/ddt/actions.php b/modules/ddt/actions.php index f5a633f98..0300afda1 100755 --- a/modules/ddt/actions.php +++ b/modules/ddt/actions.php @@ -413,12 +413,13 @@ switch (filter('op')) { $new_riga = $riga->replicate(); $new_riga->setDocument($ddt); $new_riga->qta_evasa = 0; - $new_riga->save(); if ($new_riga->isArticolo()) { $new_riga->movimenta($new_riga->qta); } + $new_riga->save(); + $riga = null; } @@ -507,12 +508,12 @@ switch (filter('op')) { $copia_riga->original_id = null; $copia_riga->original_type = null; - $copia_riga->save(); - // Movimentazione forzata in direzione del documento if ($copia_riga->isArticolo()) { $copia_riga->movimenta($copia_riga->qta); } + + $copia_riga->save(); } // Salvataggio riferimento @@ -544,11 +545,12 @@ switch (filter('op')) { $new_riga->qta_evasa = 0; $new_riga->idordine = 0; - $new_riga->save(); if ($new_riga->isArticolo()) { $new_riga->movimenta($new_riga->qta); } + + $new_riga->save(); } flash()->info(tr('DDT duplicato correttamente!')); diff --git a/modules/ddt/row-list.php b/modules/ddt/row-list.php index 483f39fd9..b6f802df2 100755 --- a/modules/ddt/row-list.php +++ b/modules/ddt/row-list.php @@ -160,10 +160,12 @@ foreach ($righe as $riga) { $evasione_bar['or_righe_ordini'] = 'success'; foreach ($evasione_bar as $table => $color) { $righe_ev = $dbo->table($table)->where('original_id', $riga->id)->where('original_type', get_class($riga))->get(); - $perc_ev = $righe_ev->sum('qta') * 100 / $riga->qta; - if ($perc_ev > 0) { - echo ' -
'; + if ($righe_ev->count() > 0) { + $perc_ev = $righe_ev->sum('qta') * 100 / $riga->qta; + if ($perc_ev > 0) { + echo ' +
'; + } } } echo ' diff --git a/modules/fatture/actions.php b/modules/fatture/actions.php index 0bd2a4694..6c514c763 100755 --- a/modules/fatture/actions.php +++ b/modules/fatture/actions.php @@ -389,11 +389,12 @@ switch ($op) { $new_riga->idintervento = 0; $new_riga->idddt = 0; $new_riga->idordine = 0; - $new_riga->save(); if ($new_riga->isArticolo()) { $new_riga->movimenta($new_riga->qta); } + + $new_riga->save(); } flash()->info(tr('Fattura duplicata correttamente!')); @@ -694,12 +695,13 @@ switch ($op) { $new_riga = $riga->replicate(); $new_riga->setDocument($fattura); $new_riga->qta_evasa = 0; - $new_riga->save(); if ($new_riga->isArticolo()) { $new_riga->movimenta($new_riga->qta); } + $new_riga->save(); + $riga = null; } diff --git a/modules/interventi/actions.php b/modules/interventi/actions.php index b2e6ffdea..d6bc64994 100644 --- a/modules/interventi/actions.php +++ b/modules/interventi/actions.php @@ -459,12 +459,13 @@ switch (post('op')) { $new_riga = $riga->replicate(); $new_riga->setDocument($intervento); $new_riga->qta_evasa = 0; - $new_riga->save(); if ($new_riga->isArticolo()) { $new_riga->movimenta($new_riga->qta); } + $new_riga->save(); + $riga = null; } @@ -980,11 +981,12 @@ switch (post('op')) { $new_riga->setDocument($new); $new_riga->qta_evasa = 0; - $new_riga->save(); if ($new_riga->isArticolo()) { $new_riga->movimenta($new_riga->qta); } + + $new_riga->save(); } } diff --git a/src/Common/Components/Article.php b/src/Common/Components/Article.php index c81087721..c471d2db4 100755 --- a/src/Common/Components/Article.php +++ b/src/Common/Components/Article.php @@ -308,10 +308,12 @@ abstract class Article extends Accounting ->groupBy('idarticolo') ->sum('qta'); + $qta_modifica = $this->attributes['qta']-$this->original['qta']; + //Se la quantità supera la giacenza in sede allora movimento solo quello che resta if (($qta_sede + $qta_finale) < 0 && $qta_sede >= 0) { $qta_finale = -$qta_sede; - $this->attributes['qta'] = $this->original['qta'] + abs($qta_finale); + $this->attributes['qta'] = $qta_sede + ($qta_modifica != 0 ? $this->original['qta'] : 0); } // Se la quantità sede per qualche motivo è negativa correggo la quantità della riga con la differenza @@ -332,6 +334,7 @@ abstract class Article extends Accounting 'reference_id' => $documento->id, 'idsede' => $id_sede, ]); + } protected static function boot()