2020-05-29 17:12:23 +02:00
< ? php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager : il software gestionale open source per l ' assistenza tecnica e la fatturazione
* Copyright ( C ) DevCode s . n . c .
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < https :// www . gnu . org / licenses />.
*/
2020-05-29 17:12:23 +02:00
include_once __DIR__ . '/../../core.php' ;
2020-07-13 18:24:18 +02:00
use Modules\Articoli\Articolo ;
2020-05-29 17:12:23 +02:00
switch ( post ( 'op' )) {
2020-07-13 18:24:18 +02:00
case 'change_acquisto' :
foreach ( $id_records as $id ) {
$articolo = Articolo :: find ( $id );
$percentuale = post ( 'percentuale' );
2020-07-16 16:49:36 +02:00
$new_prezzo_acquisto = $articolo -> prezzo_acquisto + ( $articolo -> prezzo_acquisto * $percentuale / 100 );
2020-07-13 18:24:18 +02:00
$articolo -> prezzo_acquisto = $new_prezzo_acquisto ;
$articolo -> save ();
}
flash () -> info ( tr ( 'Prezzi di acquisto aggiornati!' ));
2020-07-16 16:49:36 +02:00
2020-07-13 18:24:18 +02:00
break ;
2020-05-29 17:12:23 +02:00
case 'delete-bulk' :
foreach ( $id_records as $id ) {
$elementi = $dbo -> fetchArray ( 'SELECT `co_documenti`.`id`, `co_documenti`.`data`, `co_documenti`.`numero`, `co_documenti`.`numero_esterno`, `co_tipidocumento`.`descrizione` AS tipo_documento, `co_tipidocumento`.`dir` FROM `co_documenti` JOIN `co_tipidocumento` ON `co_tipidocumento`.`id` = `co_documenti`.`idtipodocumento` WHERE `co_documenti`.`id` IN (SELECT `iddocumento` FROM `co_righe_documenti` WHERE `idarticolo` = ' . prepare ( $id ) . ' )
UNION SELECT `dt_ddt` . `id` , `dt_ddt` . `data` , `dt_ddt` . `numero` , `dt_ddt` . `numero_esterno` , `dt_tipiddt` . `descrizione` AS tipo_documento , `dt_tipiddt` . `dir` FROM `dt_ddt` JOIN `dt_tipiddt` ON `dt_tipiddt` . `id` = `dt_ddt` . `idtipoddt` WHERE `dt_ddt` . `id` IN ( SELECT `idddt` FROM `dt_righe_ddt` WHERE `idarticolo` = '.prepare($id).' )
UNION SELECT `co_preventivi` . `id` , `co_preventivi` . `data_bozza` , `co_preventivi` . `numero` , 0 AS numero_esterno , " Preventivo " AS tipo_documento , 0 AS dir FROM `co_preventivi` WHERE `co_preventivi` . `id` IN ( SELECT `idpreventivo` FROM `co_righe_preventivi` WHERE `idarticolo` = '.prepare($id).' ) ORDER BY `data` ' );
if ( ! empty ( $elementi )) {
$dbo -> query ( 'UPDATE mg_articoli SET deleted_at = NOW() WHERE id = ' . prepare ( $id ) . Modules :: getAdditionalsQuery ( $id_module ));
2020-06-09 16:59:26 +02:00
} else {
2020-05-29 17:12:23 +02:00
$dbo -> query ( 'DELETE FROM `mg_articoli` WHERE id = ' . prepare ( $id ) . Modules :: getAdditionalsQuery ( $id_module ));
}
}
flash () -> info ( tr ( 'Articoli eliminati!' ));
break ;
}
if ( App :: debug ()) {
$operations [ 'delete-bulk' ] = [
'text' => '<span><i class="fa fa-trash"></i> ' . tr ( 'Elimina selezionati' ) . '</span>' ,
'data' => [
'msg' => tr ( 'Vuoi davvero eliminare gli articoli selezionati?' ),
'button' => tr ( 'Procedi' ),
'class' => 'btn btn-lg btn-danger' ,
],
];
}
2020-07-13 18:24:18 +02:00
$operations [ 'change_acquisto' ] = [
'text' => tr ( 'Aggiorna prezzo di acquisto' ),
'data' => [
'title' => tr ( 'Aggiornare il prezzo di acquisto per gli articoli selezionati?' ),
'msg' => 'Per indicare uno sconto inserire la percentuale con il segno meno, al contrario per un rincaro inserire la percentuale senza segno.<br><br>{[ "type": "number", "label": "' . tr ( 'Percentuale sconto/rincaro' ) . '", "name": "percentuale", "required": 1, "icon-after": "%" ]}' ,
'button' => tr ( 'Procedi' ),
'class' => 'btn btn-lg btn-warning' ,
'blank' => false ,
],
];
2020-05-29 17:12:23 +02:00
return $operations ;