2018-05-23 18:05:49 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
include_once __DIR__.'/../../core.php';
|
2018-06-26 09:41:43 +02:00
|
|
|
|
2018-05-23 18:05:49 +02:00
|
|
|
switch (post('op')) {
|
2018-06-22 17:04:37 +02:00
|
|
|
case 'example':
|
|
|
|
|
|
|
|
$module = filter('module');
|
|
|
|
|
|
|
|
$list = [
|
|
|
|
['Codice', 'Descrizione', 'Quantità', 'Unità di misura', 'Prezzo acquisto', 'Prezzo vendita', 'Peso lordo (KG)', 'Volume (M3)', 'Categoria', 'Note'],
|
|
|
|
['00004', 'Articolo', '10', 'Kg', '5,25', '12,72', '10,2', '500', 'Categoria4', 'Articolo di prova'],
|
|
|
|
];
|
|
|
|
|
|
|
|
directory('../../files/'.$module);
|
|
|
|
|
|
|
|
$fp = fopen('../../files/'.$module.'/'.$module.'.csv', 'w');
|
|
|
|
|
|
|
|
foreach ($list as $fields) {
|
|
|
|
fputcsv($fp, $fields, ';');
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose($fp);
|
|
|
|
exit;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'import':
|
2018-05-23 18:05:49 +02:00
|
|
|
|
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
if (!empty($value)) {
|
2018-09-19 15:12:20 +02:00
|
|
|
$qta = $data[$key]['qta'];
|
2018-06-22 17:04:37 +02:00
|
|
|
unset($data[$key]['qta']);
|
|
|
|
|
|
|
|
$data[$key]['attivo'] = 1;
|
2018-11-20 18:18:07 +01:00
|
|
|
if (!empty($data[$key]['prezzo_acquisto'])) {
|
2018-11-30 16:10:15 +01:00
|
|
|
$data[$key]['prezzo_acquisto'] = $data[$key]['prezzo_acquisto'];
|
|
|
|
}
|
|
|
|
if (!empty($data[$key]['prezzo_vendita'])) {
|
|
|
|
$data[$key]['prezzo_vendita'] = $data[$key]['prezzo_vendita'];
|
|
|
|
}
|
|
|
|
if (!empty($data[$key]['peso_lordo'])) {
|
|
|
|
$data[$key]['peso_lordo'] = $data[$key]['peso_lordo'];
|
|
|
|
}
|
|
|
|
if (!empty($data[$key]['volume'])) {
|
|
|
|
$data[$key]['volume'] = $data[$key]['volume'];
|
|
|
|
}
|
2018-06-22 17:04:37 +02:00
|
|
|
|
|
|
|
// Categorie
|
|
|
|
if (!empty($data[$key]['id_categoria'])) {
|
|
|
|
$rs_cat = $dbo->select('mg_categorie', 'id', [
|
|
|
|
'nome' => $data[$key]['id_categoria'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
if (empty($rs_cat[0]['id'])) {
|
|
|
|
$dbo->insert('mg_categorie', [
|
|
|
|
'nome' => $data[$key]['id_categoria'],
|
|
|
|
]);
|
|
|
|
$data[$key]['id_categoria'] = $dbo->lastInsertedID();
|
|
|
|
} else {
|
|
|
|
$data[$key]['id_categoria'] = $rs_cat[0]['id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Um
|
|
|
|
if (!empty($data[$key]['um'])) {
|
|
|
|
$rs_um = $dbo->select('mg_unitamisura', 'id', [
|
|
|
|
'valore' => $data[$key]['um'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
if (empty($rs_um[0]['id'])) {
|
|
|
|
$dbo->insert('mg_unitamisura', [
|
|
|
|
'valore' => $data[$key]['um'],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-23 18:05:49 +02:00
|
|
|
// Insert o update
|
|
|
|
$insert = true;
|
|
|
|
if (!empty($primary_key)) {
|
|
|
|
$rs = $dbo->select('mg_articoli', $primary_key, [
|
|
|
|
$primary_key => $data[$key][$primary_key],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$insert = !in_array($data[$key][$primary_key], $rs[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert
|
|
|
|
if ($insert) {
|
2018-06-22 17:04:37 +02:00
|
|
|
$data[$key]['id_categoria'] = (empty($data[$key]['id_categoria'])) ? 0 : $data[$key]['id_categoria'];
|
2018-05-23 18:05:49 +02:00
|
|
|
$dbo->insert('mg_articoli', $data[$key]);
|
2018-06-22 17:04:37 +02:00
|
|
|
add_movimento_magazzino($dbo->lastInsertedID(), $qta, [], 'Movimento da import', date());
|
2018-05-23 18:05:49 +02:00
|
|
|
}
|
|
|
|
// Update
|
|
|
|
else {
|
|
|
|
$dbo->update('mg_articoli', $data[$key], [$primary_key => $data[$key][$primary_key]]);
|
2018-06-22 17:04:37 +02:00
|
|
|
|
|
|
|
$rs = $dbo->select('mg_articoli', 'id', [
|
|
|
|
$primary_key => $data[$key][$primary_key],
|
|
|
|
]);
|
|
|
|
|
|
|
|
add_movimento_magazzino($rs[0]['id'], $qta, [], 'Movimento da import', date());
|
2018-05-23 18:05:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unset($data[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'field' => 'codice',
|
|
|
|
'label' => 'Codice',
|
|
|
|
'primary_key' => true,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'field' => 'descrizione',
|
|
|
|
'label' => 'Descrizione',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'field' => 'qta',
|
|
|
|
'label' => 'Quantità',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'field' => 'um',
|
2018-06-05 12:55:43 +02:00
|
|
|
'label' => 'Unità di misura',
|
2018-05-23 18:05:49 +02:00
|
|
|
'names' => [
|
|
|
|
'Unità di misura',
|
|
|
|
'Unità misura',
|
2018-06-22 17:04:37 +02:00
|
|
|
'Unit` di misura',
|
|
|
|
'um',
|
2018-05-23 18:05:49 +02:00
|
|
|
],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'field' => 'prezzo_acquisto',
|
|
|
|
'label' => 'Prezzo acquisto',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'field' => 'prezzo_vendita',
|
|
|
|
'label' => 'Prezzo vendita',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'field' => 'peso_lordo',
|
|
|
|
'label' => 'Peso lordo (KG)',
|
2018-06-22 17:04:37 +02:00
|
|
|
'names' => [
|
2018-05-23 18:05:49 +02:00
|
|
|
'Peso lordo (KG)',
|
|
|
|
'Peso',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'field' => 'volume',
|
|
|
|
'label' => 'Volume (M3)',
|
2018-06-22 17:04:37 +02:00
|
|
|
'names' => [
|
2018-05-23 18:05:49 +02:00
|
|
|
'Volume (M3)',
|
2018-09-04 10:03:02 +02:00
|
|
|
'Volume',
|
2018-05-23 18:05:49 +02:00
|
|
|
],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'field' => 'id_categoria',
|
|
|
|
'label' => 'Categoria',
|
|
|
|
'names' => [
|
|
|
|
'Categoria',
|
|
|
|
'id_categoria',
|
|
|
|
'idcategoria',
|
|
|
|
],
|
|
|
|
],
|
2018-06-22 17:04:37 +02:00
|
|
|
[
|
2018-05-23 18:05:49 +02:00
|
|
|
'field' => 'note',
|
|
|
|
'label' => 'Note',
|
2018-06-22 17:04:37 +02:00
|
|
|
],
|
2018-05-23 18:05:49 +02:00
|
|
|
];
|