2020-08-06 18:51:56 +02:00
< ? php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager : il software gestionale open source per l ' assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright ( C ) DevCode s . r . l .
2020-09-07 15:04:06 +02:00
*
* 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-08-06 18:51:56 +02:00
namespace Modules\Articoli\Import ;
2020-11-13 10:56:32 +01:00
use Carbon\Carbon ;
2020-08-07 10:14:09 +02:00
use Importer\CSVImporter ;
2021-10-18 10:23:39 +02:00
use Models\Upload ;
2020-12-04 15:40:47 +01:00
use Modules\Anagrafiche\Anagrafica ;
2020-11-13 17:54:58 +01:00
use Modules\Anagrafiche\Sede ;
2023-11-03 11:55:27 +01:00
use Modules\Anagrafiche\Tipo ;
2020-08-07 10:14:09 +02:00
use Modules\Articoli\Articolo ;
use Modules\Articoli\Categoria ;
use Modules\Iva\Aliquota ;
2021-07-28 12:06:29 +02:00
use Plugins\ListinoClienti\DettaglioPrezzo ;
2022-02-16 16:31:26 +01:00
use Plugins\ListinoFornitori\DettaglioFornitore ;
2024-03-05 16:01:45 +01:00
use Models\Module ;
2020-08-06 18:51:56 +02:00
2020-08-07 11:05:08 +02:00
/**
* Struttura per la gestione delle operazioni di importazione ( da CSV ) degli Articoli .
*
* @ since 2.4 . 17
*/
2020-08-07 10:14:09 +02:00
class CSV extends CSVImporter
2020-08-06 18:51:56 +02:00
{
public function getAvailableFields ()
{
return [
[
'field' => 'codice' ,
'label' => 'Codice' ,
'primary_key' => true ,
],
2021-10-15 19:06:26 +02:00
[
'field' => 'immagine' ,
'label' => 'Immagine' ,
'names' => [
'Immagine' ,
'Foto' ,
],
],
2022-02-21 14:46:10 +01:00
[
'field' => 'import_immagine' ,
'label' => 'Import immagine' ,
],
2020-08-06 18:51:56 +02:00
[
'field' => 'descrizione' ,
'label' => 'Descrizione' ,
],
[
'field' => 'qta' ,
'label' => 'Quantità' ,
],
2023-01-24 18:30:45 +01:00
[
'field' => 'data_qta' ,
'label' => 'Data inventario' ,
],
2020-08-06 18:51:56 +02:00
[
'field' => 'um' ,
'label' => 'Unità di misura' ,
'names' => [
'Unità di misura' ,
'Unità misura' ,
'Unit` di misura' ,
'um' ,
],
],
[
'field' => 'prezzo_acquisto' ,
'label' => 'Prezzo acquisto' ,
],
[
'field' => 'prezzo_vendita' ,
'label' => 'Prezzo vendita' ,
],
[
'field' => 'peso_lordo' ,
'label' => 'Peso lordo (KG)' ,
'names' => [
'Peso lordo (KG)' ,
'Peso' ,
],
],
[
'field' => 'volume' ,
'label' => 'Volume (M3)' ,
'names' => [
'Volume (M3)' ,
'Volume' ,
],
],
[
2020-10-02 16:45:09 +02:00
'field' => 'id_categoria' ,
2020-08-06 18:51:56 +02:00
'label' => 'Categoria' ,
'names' => [
'Categoria' ,
2020-08-07 10:14:09 +02:00
'categoria' ,
2020-08-06 18:51:56 +02:00
'idcategoria' ,
],
],
[
2020-10-02 16:45:09 +02:00
'field' => 'id_sottocategoria' ,
2020-08-06 18:51:56 +02:00
'label' => 'Sottocategoria' ,
'names' => [
'Sottocategoria' ,
2020-08-07 10:14:09 +02:00
'sottocategoria' ,
2020-08-06 18:51:56 +02:00
'idsottocategoria' ,
],
],
[
'field' => 'barcode' ,
'label' => 'Barcode' ,
'names' => [
'barcode' ,
'Barcode' ,
'EAN' ,
],
],
[
'field' => 'id_fornitore' ,
2020-12-04 16:16:41 +01:00
'label' => 'Fornitore predefinito' ,
2020-08-06 18:51:56 +02:00
'names' => [
'id_fornitore' ,
'Id Fornitore' ,
'Fornitore' ,
2020-12-04 16:16:41 +01:00
'Fornitore predefinito' ,
2020-08-06 18:51:56 +02:00
],
],
2023-11-03 14:46:17 +01:00
[
'field' => 'p_iva' ,
'label' => 'Partita IVA' ,
'names' => [
'partita iva' ,
'Partita IVA' ,
],
],
2020-08-06 18:51:56 +02:00
[
2020-08-07 10:14:09 +02:00
'field' => 'codice_iva_vendita' ,
2020-08-06 18:51:56 +02:00
'label' => 'Codice IVA vendita' ,
'names' => [
'Codice IVA vendita' ,
2020-08-07 10:14:09 +02:00
'codice_iva_vendita' ,
2020-08-06 18:51:56 +02:00
],
],
[
'field' => 'ubicazione' ,
'label' => 'Ubicazione' ,
],
[
'field' => 'note' ,
'label' => 'Note' ,
],
2020-12-04 16:16:41 +01:00
[
'field' => 'anagrafica_listino' ,
'label' => 'Anagrafica listino' ,
],
2022-02-16 16:31:26 +01:00
[
'field' => 'codice_fornitore' ,
'label' => 'Codice fornitore' ,
],
[
'field' => 'barcode_fornitore' ,
'label' => 'Barcode fornitore' ,
],
[
'field' => 'descrizione_fornitore' ,
'label' => 'Descrizione fornitore' ,
],
2020-12-04 16:16:41 +01:00
[
'field' => 'qta_minima' ,
'label' => 'Qta minima' ,
],
[
'field' => 'qta_massima' ,
'label' => 'Qta massima' ,
],
[
'field' => 'prezzo_listino' ,
'label' => 'Prezzo listino' ,
],
[
'field' => 'sconto_listino' ,
'label' => 'Sconto listino' ,
],
[
'field' => 'dir' ,
'label' => 'Cliente/Fornitore listino' ,
],
2023-02-16 09:32:25 +01:00
[
'field' => 'nome_sede' ,
'label' => 'Sede' ,
],
2020-08-06 18:51:56 +02:00
];
}
2021-02-26 15:47:20 +01:00
/**
* Procedura di inizializzazione per l ' importazione .
* Effettua una rimozione di tutti i dettagli prezzi per le coppie Articolo - Anagrafica presenti nel CSV .
*
* @ return mixed | void
*/
public function init ()
{
$database = database ();
$primary_key = $this -> getPrimaryKey ();
// Count the numbers of rows in a CSV
2022-03-30 17:10:52 +02:00
$number = 0 ;
foreach ( $this -> csv as $row ) {
2023-08-04 14:54:28 +02:00
++ $number ;
2022-03-30 17:10:52 +02:00
}
2021-02-26 15:47:20 +01:00
2023-07-25 17:05:46 +02:00
// Lettura primo record: se non c'è la pulizia listini da fare, esco, altrimenti
// si rischia una lettura di troppi dati insieme
$rows = $this -> getRows ( 0 , 2 );
2021-02-26 15:47:20 +01:00
$first_record = $this -> getRecord ( $rows [ 1 ]);
if ( ! isset ( $first_record [ 'anagrafica_listino' ]) || empty ( $this -> getPrimaryKey ())) {
return ;
}
2021-03-01 09:41:49 +01:00
2023-07-25 17:05:46 +02:00
$rows = $this -> getRows ( 0 , $number );
2021-02-26 15:47:20 +01:00
foreach ( $rows as $row ) {
// Interpretazione secondo la selezione
$record = $this -> getRecord ( $row );
if ( empty ( $record [ 'anagrafica_listino' ])) {
continue ;
}
$articolo = Articolo :: where ( $primary_key , $record [ $primary_key ])
-> first ();
$anagrafica = Anagrafica :: where ( 'ragione_sociale' , $record [ 'anagrafica_listino' ])
-> first ();
if ( empty ( $articolo ) || empty ( $anagrafica )) {
continue ;
}
2022-09-09 16:06:35 +02:00
if ( ! empty ( $record [ 'prezzo_listino' ])) {
$database -> query ( 'DELETE FROM mg_prezzi_articoli WHERE id_articolo = ' . prepare ( $articolo -> id ) . ' AND id_anagrafica = ' . prepare ( $anagrafica -> id ));
}
2022-02-16 16:31:26 +01:00
2022-09-09 16:06:35 +02:00
if ( ! empty ( $record [ 'codice_fornitore' ]) && ! empty ( $record [ 'descrizione_fornitore' ])) {
$database -> query ( 'DELETE FROM mg_fornitore_articolo WHERE id_articolo = ' . prepare ( $articolo -> id ) . ' AND id_fornitore = ' . prepare ( $anagrafica -> id ));
2022-02-16 16:31:26 +01:00
}
2021-02-26 15:47:20 +01:00
}
}
2020-08-06 18:51:56 +02:00
public function import ( $record )
{
$database = database ();
$primary_key = $this -> getPrimaryKey ();
2021-10-15 19:06:26 +02:00
$url = $record [ 'immagine' ];
unset ( $record [ 'immagine' ]);
2020-08-06 18:51:56 +02:00
// Fix per campi con contenuti derivati da query implicite
if ( ! empty ( $record [ 'id_fornitore' ])) {
2023-11-03 11:55:27 +01:00
$dettagli [ 'id_fornitore' ] = $database -> fetchOne ( 'SELECT idanagrafica AS id FROM an_anagrafiche WHERE LOWER(ragione_sociale) = LOWER(' . prepare ( $record [ 'id_fornitore' ]) . ')' )[ 'id' ];
$dettagli [ 'anagrafica_listino' ] = $record [ 'id_fornitore' ];
2023-11-03 14:46:17 +01:00
}
2020-08-06 18:51:56 +02:00
2020-08-07 10:14:09 +02:00
// Gestione categoria e sottocategoria
2021-02-26 15:47:20 +01:00
$categoria = null ;
2021-04-26 09:35:01 +02:00
$sottocategoria = null ;
2020-10-02 16:45:09 +02:00
if ( ! empty ( $record [ 'id_categoria' ])) {
2020-08-07 10:14:09 +02:00
// Categoria
2021-02-26 15:47:20 +01:00
$categoria = Categoria :: where ( 'nome' , strtolower ( $record [ 'id_categoria' ])) -> first ();
2021-01-21 19:13:43 +01:00
2021-02-26 15:47:20 +01:00
if ( empty ( $categoria )) {
$categoria = Categoria :: build ( $record [ 'id_categoria' ]);
2020-08-06 18:51:56 +02:00
}
2020-08-07 10:14:09 +02:00
// Sotto-categoria
2020-10-02 16:45:09 +02:00
if ( ! empty ( $record [ 'id_sottocategoria' ])) {
2021-04-26 09:35:01 +02:00
$sottocategoria = Categoria :: where ( 'nome' , $record [ 'id_sottocategoria' ])
2021-02-26 15:47:20 +01:00
-> where ( 'parent' , $categoria -> id )
2020-08-07 10:14:09 +02:00
-> first ();
if ( empty ( $sottocategoria )) {
2021-04-26 09:35:01 +02:00
$sottocategoria = Categoria :: build ( $record [ 'id_sottocategoria' ]);
$sottocategoria -> parent () -> associate ( $categoria );
$sottocategoria -> save ();
2020-08-07 10:14:09 +02:00
}
2020-08-06 18:51:56 +02:00
}
}
2021-07-07 07:57:10 +02:00
// Gestione um
$um = null ;
if ( ! empty ( $record [ 'um' ])) {
$um = $database -> fetchOne ( 'SELECT id FROM `mg_unitamisura` WHERE `valore`=' . prepare ( $record [ 'um' ]));
if ( empty ( $um )) {
2021-07-06 13:08:24 +02:00
$database -> query ( 'INSERT INTO `mg_unitamisura` (`valore`) VALUES (' . prepare ( $record [ 'um' ]) . ')' );
2021-07-07 07:57:10 +02:00
}
}
2021-07-06 13:08:24 +02:00
2020-08-07 10:14:09 +02:00
// Individuazione articolo e generazione
2021-02-26 15:47:20 +01:00
$articolo = null ;
// Ricerca sulla base della chiave primaria se presente
if ( ! empty ( $primary_key )) {
2021-12-09 15:32:21 +01:00
$articolo = Articolo :: where ( $primary_key , $record [ $primary_key ]) -> withTrashed () -> first ();
2021-02-26 15:47:20 +01:00
}
2020-08-07 10:14:09 +02:00
if ( empty ( $articolo )) {
2024-03-19 18:18:11 +01:00
$articolo = Articolo :: build ( $record [ 'codice' ], $categoria , $sottocategoria );
$articolo -> setTranslation ( 'name' , $record [ 'descrizione' ]);
2021-12-09 15:32:21 +01:00
} else {
$articolo -> restore ();
2020-08-06 18:51:56 +02:00
}
2022-09-09 16:06:35 +02:00
// Individuazione dell'IVA di vendita tramite il relativo Codice
$aliquota = null ;
if ( ! empty ( $record [ 'codice_iva_vendita' ])) {
$aliquota = Aliquota :: where ( 'codice' , $record [ 'codice_iva_vendita' ]) -> first ();
$articolo -> idiva_vendita = $aliquota -> id ;
}
2020-08-07 10:14:09 +02:00
$articolo -> attivo = 1 ;
2020-08-06 18:51:56 +02:00
2020-11-13 10:56:32 +01:00
// Esportazione della quantità indicata
2024-01-15 15:30:45 +01:00
$nuova_qta = ( float ) $record [ 'qta' ];
2020-12-04 16:16:41 +01:00
$nome_sede = $record [ 'nome_sede' ];
2020-11-13 10:56:32 +01:00
2023-11-03 14:46:17 +01:00
if ( ! empty ( $dettagli [ 'id_fornitore' ]) || ! empty ( $dettagli [ 'anagrafica_listino' ] || ! empty ( $dettagli [ 'partita_iva' ]))) {
2023-11-03 11:55:27 +01:00
// Aggiornamento dettaglio prezzi
$dettagli [ 'anagrafica_listino' ] = $dettagli [ 'anagrafica_listino' ] ? : $record [ 'anagrafica_listino' ];
2023-11-03 14:46:17 +01:00
$dettagli [ 'partita_iva' ] = $record [ 'p_iva' ];
2023-11-03 11:55:27 +01:00
$dettagli [ 'qta_minima' ] = $record [ 'qta_minima' ];
$dettagli [ 'qta_massima' ] = $record [ 'qta_massima' ];
$dettagli [ 'prezzo_listino' ] = $record [ 'prezzo_listino' ];
$dettagli [ 'sconto_listino' ] = $record [ 'sconto_listino' ];
$dettagli [ 'dir' ] = $record [ 'dir' ];
$dettagli [ 'codice_fornitore' ] = $record [ 'codice_fornitore' ];
$dettagli [ 'barcode_fornitore' ] = $record [ 'barcode_fornitore' ];
$dettagli [ 'descrizione_fornitore' ] = $record [ 'descrizione_fornitore' ];
$this -> aggiornaDettaglioPrezzi ( $articolo , $dettagli );
}
unset ( $record [ 'anagrafica_listino' ]);
2023-11-03 14:46:17 +01:00
unset ( $record [ 'partita_iva' ]);
2023-11-03 11:55:27 +01:00
unset ( $record [ 'qta_minima' ]);
unset ( $record [ 'qta_massima' ]);
unset ( $record [ 'prezzo_listino' ]);
unset ( $record [ 'sconto_listino' ]);
unset ( $record [ 'dir' ]);
unset ( $record [ 'codice_fornitore' ]);
unset ( $record [ 'barcode_fornitore' ]);
unset ( $record [ 'descrizione_fornitore' ]);
unset ( $record [ 'id_fornitore' ]);
2024-01-15 15:30:45 +01:00
// Gestione immagine
2022-02-21 14:46:10 +01:00
if ( ! empty ( $url ) && ! empty ( $record [ 'import_immagine' ])) {
$file_content = file_get_contents ( $url );
if ( ! empty ( $file_content )) {
if ( $record [ 'import_immagine' ] == 2 || $record [ 'import_immagine' ] == 4 ) {
2024-01-15 15:30:45 +01:00
\Uploads :: deleteLinked ([
2024-03-20 11:13:28 +01:00
'id_module' => ( new Module ()) -> getByField ( 'name' , 'Articoli' ),
2022-02-21 14:46:10 +01:00
'id_record' => $articolo -> id ,
]);
$database -> update ( 'mg_articoli' , [
'immagine' => '' ,
], [
'id' => $articolo -> id ,
]);
}
$name = 'immagine_' . $articolo -> id . '.' . Upload :: getExtensionFromMimeType ( $file_content );
2024-01-15 15:30:45 +01:00
$upload = \Uploads :: upload ( $file_content , [
2022-02-21 14:46:10 +01:00
'name' => 'Immagine' ,
'category' => 'Immagini' ,
'original_name' => $name ,
2024-03-20 11:13:28 +01:00
'id_module' => ( new Module ()) -> getByField ( 'name' , 'Articoli' ),
2022-02-21 14:46:10 +01:00
'id_record' => $articolo -> id ,
], [
'thumbnails' => true ,
]);
$filename = $upload -> filename ;
if ( $record [ 'import_immagine' ] == 1 || $record [ 'import_immagine' ] == 2 ) {
if ( ! empty ( $filename )) {
$database -> update ( 'mg_articoli' , [
'immagine' => $filename ,
], [
'id' => $articolo -> id ,
]);
}
}
}
}
unset ( $record [ 'import_immagine' ]);
2022-02-16 16:31:26 +01:00
2021-02-26 15:47:20 +01:00
// Salvataggio delle informazioni generali
2022-01-27 15:51:01 +01:00
$articolo -> fill ( $record );
2022-01-27 15:55:46 +01:00
$articolo -> fill ([
'id_categoria' => $categoria -> id ? : $articolo [ 'id_categoria' ],
'id_sottocategoria' => $sottocategoria -> id ? : $articolo [ 'id_sottocategoria' ],
]);
2022-02-24 14:53:17 +01:00
// Prezzo di vendita
2022-09-09 16:06:35 +02:00
if ( ! empty ( $record [ 'prezzo_vendita' ])) {
$articolo -> setPrezzoVendita ( $record [ 'prezzo_vendita' ], $aliquota ? $aliquota -> id : setting ( 'Iva predefinita' ));
}
2022-02-24 14:53:17 +01:00
2021-02-26 15:47:20 +01:00
$articolo -> save ();
2020-08-07 10:14:09 +02:00
// Movimentazione della quantità registrata
2021-02-26 15:47:20 +01:00
$anagrafica_azienda = Anagrafica :: find ( setting ( 'Azienda predefinita' ));
2020-11-13 17:54:58 +01:00
$id_sede = 0 ;
if ( ! empty ( $nome_sede )) {
$sede = Sede :: where ( 'nomesede' , $nome_sede )
-> where ( 'idanagrafica' , $anagrafica_azienda -> id )
-> first ();
2023-02-16 09:32:25 +01:00
$id_sede = $sede -> id ? : 0 ;
2020-11-13 17:54:58 +01:00
}
2023-08-04 14:54:28 +02:00
if ( isset ( $record [ 'qta' ])) {
2023-01-24 18:30:45 +01:00
$giacenze = $articolo -> getGiacenze ( $record [ 'data_qta' ]);
$qta_movimento = $nuova_qta - $giacenze [ $id_sede ][ 0 ];
2020-11-13 10:56:32 +01:00
2023-01-24 18:30:45 +01:00
$articolo -> movimenta ( $qta_movimento , tr ( 'Movimento da importazione' ), new Carbon ( $record [ 'data_qta' ]), true , [
2021-12-13 15:48:38 +01:00
'idsede' => $id_sede ,
]);
}
2020-08-06 18:51:56 +02:00
}
public static function getExample ()
{
return [
2023-11-28 11:05:56 +01:00
[ 'Codice' , 'Immagine' , 'Import immagine' , 'Descrizione' , 'Quantità' , 'Data inventario' , 'Unità misura' , 'Prezzo acquisto' , 'Prezzo vendita' , 'Peso' , 'Volume' , 'Categoria' , 'Sottocategoria' , 'Barcode' , 'Fornitore' , 'Partita IVA' , 'Codice IVA vendita' , 'Ubicazione' , 'Note' , 'Anagrafica listino' , 'Codice fornitore' , 'Barcode fornitore' , 'Descrizione fornitore' , 'Qta minima' , 'Qta massima' , 'Prezzo listino' , 'Sconto listino' , 'Cliente/Fornitore listino' , 'Sede' ],
[ '001' , 'https://openstamanager.com/moduli/budget/budget.webp' , '2' , 'Modulo Budget' , '1' , '2023-11-28' , 'PZ' , '180.00' , '180.00' , '' , '' , 'Licenze' , 'Moduli aggiuntivi' , '0001' , 'DevCode s.r.l.' , '05024030289' , '' , '' , '' , '' , 'Budget' , '' , 'Modulo Budget' , '' , '' , '' , '' , 'Fornitore' , 'Sede' ],
2020-08-06 18:51:56 +02:00
];
}
2021-02-26 15:47:20 +01:00
protected function aggiornaDettaglioPrezzi ( Articolo $articolo , $dettagli )
{
// Listini
2023-11-08 11:08:47 +01:00
if ( $dettagli [ 'partita_iva' ]) {
2023-11-03 14:46:17 +01:00
$anagrafica = Anagrafica :: where ( 'piva' , $dettagli [ 'partita_iva' ]) -> first ();
}
2023-11-08 11:08:47 +01:00
2023-12-21 13:03:49 +01:00
if ( empty ( $anagrafica ) && $dettagli [ 'anagrafica_listino' ]) {
$anagrafica = Anagrafica :: where ( 'ragione_sociale' , $dettagli [ 'anagrafica_listino' ]) -> first ();
}
2023-11-03 11:55:27 +01:00
if ( empty ( $anagrafica )) {
$anagrafica = Anagrafica :: build ( $dettagli [ 'anagrafica_listino' ]);
2023-11-03 14:46:17 +01:00
$anagrafica -> piva = $dettagli [ 'partita_iva' ];
$anagrafica -> save ();
2023-11-03 11:55:27 +01:00
}
if ( $dettagli [ 'dir' ]) {
2024-03-20 11:13:28 +01:00
$tipo = ( new Tipo ()) -> getByField ( 'name' , $dettagli [ 'dir' ]);
2024-02-05 17:07:33 +01:00
$tipi = $anagrafica -> tipi -> pluck ( 'id' ) -> toArray ();
2024-02-06 11:36:09 +01:00
$tipi [] = $tipo ;
2023-11-03 14:46:17 +01:00
2023-11-03 11:55:27 +01:00
$anagrafica -> tipologie = $tipi ;
$anagrafica -> save ();
}
2021-02-26 15:47:20 +01:00
$dettagli [ 'dir' ] = strtolower ( $dettagli [ 'dir' ]);
if ( $dettagli [ 'dir' ] == 'fornitore' ) {
$dettagli [ 'dir' ] = 'uscita' ;
} elseif ( $dettagli [ 'dir' ] == 'cliente' ) {
$dettagli [ 'dir' ] = 'entrata' ;
} else {
$dettagli [ 'dir' ] = null ;
}
2022-03-30 17:10:52 +02:00
// Aggiungo Listino
2022-09-09 16:06:35 +02:00
if ( ! empty ( $anagrafica ) && ! empty ( $dettagli [ 'dir' ]) && $dettagli [ 'prezzo_listino' ]) {
2021-02-26 15:47:20 +01:00
$dettaglio_predefinito = DettaglioPrezzo :: build ( $articolo , $anagrafica , $dettagli [ 'dir' ]);
$dettaglio_predefinito -> sconto_percentuale = $dettagli [ 'sconto_listino' ];
$dettaglio_predefinito -> setPrezzoUnitario ( $dettagli [ 'prezzo_listino' ]);
if ( $dettagli [ 'qta_minima' ] !== null && ! empty ( $dettagli [ 'qta_massima' ])) {
$dettaglio_predefinito -> minimo = $dettagli [ 'qta_minima' ];
$dettaglio_predefinito -> massimo = $dettagli [ 'qta_massima' ];
}
$dettaglio_predefinito -> save ();
2022-09-09 16:06:35 +02:00
}
2022-02-16 16:31:26 +01:00
2022-09-09 16:06:35 +02:00
// Aggiungo dettagli fornitore
if ( ! empty ( $anagrafica ) && $dettagli [ 'dir' ] == 'uscita' && ! empty ( $dettagli [ 'codice_fornitore' ]) && ! empty ( $dettagli [ 'descrizione_fornitore' ])) {
$fornitore = DettaglioFornitore :: build ( $anagrafica , $articolo );
$fornitore -> codice_fornitore = $dettagli [ 'codice_fornitore' ];
$fornitore -> barcode_fornitore = $dettagli [ 'barcode_fornitore' ];
$fornitore -> descrizione = $dettagli [ 'descrizione_fornitore' ];
$fornitore -> save ();
2021-02-26 15:47:20 +01:00
}
2022-03-30 17:10:52 +02:00
2023-08-04 14:54:28 +02:00
// Imposto fornitore e prezzo predefinito
2023-11-03 14:46:17 +01:00
$dettagli [ 'id_fornitore' ] = $anagrafica -> id ;
2022-03-30 17:10:52 +02:00
$listino_id_fornitore = DettaglioPrezzo :: dettaglioPredefinito ( $articolo -> id , $dettagli [ 'id_fornitore' ], 'uscita' ) -> first ();
if ( ! empty ( $listino_id_fornitore )) {
2023-08-04 14:54:28 +02:00
$prezzo_acquisto = $listino_id_fornitore -> prezzo_unitario - ( $listino_id_fornitore -> prezzo_unitario * $listino_id_fornitore -> sconto_percentuale ) / 100 ;
2022-03-30 17:10:52 +02:00
$articolo -> prezzo_acquisto = $prezzo_acquisto ;
$articolo -> id_fornitore = $dettagli [ 'id_fornitore' ];
$articolo -> save ();
}
2021-02-26 15:47:20 +01:00
}
2020-08-06 18:51:56 +02:00
}