2020-11-11 17:30:53 +01:00
< ? php
2020-11-12 17:11:09 +01:00
use Modules\Contratti\Components\Articolo as ArticoloContratto ;
use Modules\Contratti\Components\Riga as RigaContratto ;
use Modules\DDT\Components\Articolo as ArticoloDDT ;
use Modules\DDT\Components\Riga as RigaDDT ;
use Modules\Ordini\Components\Articolo as ArticoloOrdine ;
use Modules\Ordini\Components\Riga as RigaOrdine ;
use Modules\Preventivi\Components\Articolo as ArticoloPreventivo ;
use Modules\Preventivi\Components\Riga as RigaPreventivo ;
2020-11-11 17:30:53 +01:00
/**
* Procedura per aggiustare alcuni campi di sconto ivato nei documenti prima della fattura
2020-11-12 17:11:09 +01:00
* in quanto veniva calcolato lo sconto ivato erroneamente .
2020-11-11 17:30:53 +01:00
*/
// Fix sconti contratti
$righe = $dbo -> fetchArray ( 'SELECT id, idiva, sconto_percentuale, prezzo_unitario FROM co_righe_contratti WHERE sconto_percentuale != 0 AND tipo_sconto="PRC"' );
2020-11-12 17:11:09 +01:00
foreach ( $righe as $riga ) {
if ( empty ( $riga [ 'idarticolo' ])) {
$this_riga = RigaContratto :: find ( $riga [ 'id' ]);
2020-11-11 17:30:53 +01:00
} else {
2020-11-12 17:11:09 +01:00
$this_riga = ArticoloContratto :: find ( $riga [ 'id' ]);
2020-11-11 17:30:53 +01:00
}
2020-11-12 17:11:09 +01:00
if ( $this_riga !== null ) {
$this_riga -> setPrezzoUnitario ( $riga [ 'prezzo_unitario' ], $riga [ 'idiva' ]);
$this_riga -> setSconto ( $riga [ 'sconto_percentuale' ], 'PRC' );
2020-11-11 17:30:53 +01:00
$this_riga -> save ();
}
}
// Fix sconti preventivi
$righe = $dbo -> fetchArray ( 'SELECT id, idiva, sconto_percentuale, prezzo_unitario FROM co_righe_preventivi WHERE sconto_percentuale != 0 AND tipo_sconto="PRC"' );
2020-11-12 17:11:09 +01:00
foreach ( $righe as $riga ) {
if ( empty ( $riga [ 'idarticolo' ])) {
$this_riga = RigaPreventivo :: find ( $riga [ 'id' ]);
2020-11-11 17:30:53 +01:00
} else {
2020-11-12 17:11:09 +01:00
$this_riga = ArticoloPreventivo :: find ( $riga [ 'id' ]);
2020-11-11 17:30:53 +01:00
}
2020-11-12 17:11:09 +01:00
if ( $this_riga !== null ) {
$this_riga -> setPrezzoUnitario ( $riga [ 'prezzo_unitario' ], $riga [ 'idiva' ]);
$this_riga -> setSconto ( $riga [ 'sconto_percentuale' ], 'PRC' );
2020-11-11 17:30:53 +01:00
$this_riga -> save ();
}
}
// Fix sconti ordini
$righe = $dbo -> fetchArray ( 'SELECT id, idiva, sconto_percentuale, prezzo_unitario FROM or_righe_ordini WHERE sconto_percentuale != 0 AND tipo_sconto="PRC"' );
2020-11-12 17:11:09 +01:00
foreach ( $righe as $riga ) {
if ( empty ( $riga [ 'idarticolo' ])) {
$this_riga = RigaOrdine :: find ( $riga [ 'id' ]);
2020-11-11 17:30:53 +01:00
} else {
2020-11-12 17:11:09 +01:00
$this_riga = ArticoloOrdine :: find ( $riga [ 'id' ]);
2020-11-11 17:30:53 +01:00
}
2020-11-12 17:11:09 +01:00
if ( $this_riga !== null ) {
$this_riga -> setPrezzoUnitario ( $riga [ 'prezzo_unitario' ], $riga [ 'idiva' ]);
$this_riga -> setSconto ( $riga [ 'sconto_percentuale' ], 'PRC' );
2020-11-11 17:30:53 +01:00
$this_riga -> save ();
}
}
// Fix sconti ddt
$righe = $dbo -> fetchArray ( 'SELECT id, idiva, sconto_percentuale, prezzo_unitario FROM dt_righe_ddt WHERE sconto_percentuale != 0 AND tipo_sconto="PRC"' );
2020-11-12 17:11:09 +01:00
foreach ( $righe as $riga ) {
if ( empty ( $riga [ 'idarticolo' ])) {
$this_riga = RigaDDT :: find ( $riga [ 'id' ]);
2020-11-11 17:30:53 +01:00
} else {
2020-11-12 17:11:09 +01:00
$this_riga = ArticoloDDT :: find ( $riga [ 'id' ]);
2020-11-11 17:30:53 +01:00
}
2020-11-12 17:11:09 +01:00
if ( $this_riga !== null ) {
$this_riga -> setPrezzoUnitario ( $riga [ 'prezzo_unitario' ], $riga [ 'idiva' ]);
$this_riga -> setSconto ( $riga [ 'sconto_percentuale' ], 'PRC' );
2020-11-11 17:30:53 +01:00
$this_riga -> save ();
}
2020-11-12 17:11:09 +01:00
}