Fix import impianti
This commit is contained in:
parent
88ba7311b3
commit
529cf6f5c5
|
@ -21,7 +21,7 @@ include_once __DIR__.'/../../core.php';
|
||||||
use Modules\Impianti\Categoria;
|
use Modules\Impianti\Categoria;
|
||||||
|
|
||||||
if (isset($id_record)) {
|
if (isset($id_record)) {
|
||||||
$record = $dbo->fetchOne('SELECT * FROM `my_impianti_categorie` LEFT JOIN `my_impianti_categorie_lang` ON (`my_impianti_categorie`.`id`=`my_impianti_categorie_lang`.`id_record` AND `my_impianti_categorie_lang`.`id_lang` = '.prepare(\Models\Locale::getDefault()->id).' WHERE `my_impianti_categorie`.`id`='.prepare($id_record));
|
$record = $dbo->fetchOne('SELECT * FROM `my_impianti_categorie` LEFT JOIN `my_impianti_categorie_lang` ON (`my_impianti_categorie`.`id`=`my_impianti_categorie_lang`.`id_record` AND `my_impianti_categorie_lang`.`id_lang` = '.prepare(\Models\Locale::getDefault()->id).') WHERE `my_impianti_categorie`.`id`='.prepare($id_record));
|
||||||
|
|
||||||
$categoria = Categoria::find($id_record);
|
$categoria = Categoria::find($id_record);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,19 +18,20 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
include_once __DIR__.'/../../core.php';
|
include_once __DIR__.'/../../core.php';
|
||||||
|
use Modules\Impianti\Categoria;
|
||||||
|
|
||||||
$subcategorie = $dbo->fetchArray('SELECT `my_impianti_categorie`.*, `my_impianti_categorie_lang`.`name` FROM `my_impianti_categorie` LEFT JOIN `my_impianti_categorie_lang` ON (`my_impianti_categorie`.`id`=`my_impianti_categorie_lang`.`id_record` AND `my_impianti_categorie_lang`.`id_lang` = '.prepare(\Models\Locale::getDefault()->id).') WHERE `parent`='.prepare($id_record).' ORDER BY `name` ASC ');
|
$subcategorie = Categoria::where('parent', '=', $id_record)->get();
|
||||||
|
|
||||||
foreach ($subcategorie as $sub) {
|
foreach ($subcategorie as $sub) {
|
||||||
$n_impianti = $dbo->fetchNum('SELECT * FROM `my_impianti` WHERE `id_sottocategoria`='.prepare($sub['id']).' AND deleted_at IS NULL');
|
$n_impianti = $dbo->fetchNum('SELECT * FROM `my_impianti` WHERE `id_sottocategoria`='.prepare($sub->id).' AND deleted_at IS NULL');
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td>'.$sub['nome'].'</td>
|
<td>'.$sub->getTranslation('name').'</td>
|
||||||
<td>'.$sub['colore'].'</td>
|
<td>'.$sub->colore.'</td>
|
||||||
<td>'.$sub['nota'].'</td>
|
<td>'.$sub->nota.'</td>
|
||||||
<td>
|
<td>
|
||||||
<a class="btn btn-warning btn-sm" title="Modifica riga" onclick="launch_modal(\''.tr('Modifica sottocategoria').'\', \''.base_path().'/add.php?id_module='.$id_module.'&id_record='.$sub['id'].'&id_original='.$id_record.'\');"><i class="fa fa-edit"></i></a>
|
<a class="btn btn-warning btn-sm" title="Modifica riga" onclick="launch_modal(\''.tr('Modifica sottocategoria').'\', \''.base_path().'/add.php?id_module='.$id_module.'&id_record='.$sub->id.'&id_original='.$id_record.'\');"><i class="fa fa-edit"></i></a>
|
||||||
<a class="btn btn-sm btn-danger ask '.(($n_impianti > 0) ? 'disabled tip' : '').'" data-backto="record-edit" data-id="'.$sub['id'].'" title="'.(($n_impianti > 0) ? 'Sottocategoria collegata a '.$n_impianti.' articoli' : '').'">
|
<a class="btn btn-sm btn-danger ask '.(($n_impianti > 0) ? 'disabled tip' : '').'" data-backto="record-edit" data-id="'.$sub->id.'" title="'.(($n_impianti > 0) ? 'Sottocategoria collegata a '.$n_impianti.' articoli' : '').'">
|
||||||
<i class="fa fa-trash"></i>
|
<i class="fa fa-trash"></i>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -67,11 +67,11 @@ class CSV extends CSVImporter
|
||||||
'label' => 'Telefono',
|
'label' => 'Telefono',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'field' => 'id_categoria',
|
'field' => 'categoria',
|
||||||
'label' => 'Categoria',
|
'label' => 'Categoria',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'field' => 'id_sottocategoria',
|
'field' => 'sottocategoria',
|
||||||
'label' => 'Sottocategoria',
|
'label' => 'Sottocategoria',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
@ -105,27 +105,26 @@ class CSV extends CSVImporter
|
||||||
// Gestione categoria e sottocategoria
|
// Gestione categoria e sottocategoria
|
||||||
$categoria = null;
|
$categoria = null;
|
||||||
$sottocategoria = null;
|
$sottocategoria = null;
|
||||||
|
if (!empty($record['categoria'])) {
|
||||||
|
// Categoria
|
||||||
|
$categoria = Categoria::where('id', '=', (new Categoria())->getByField('name', strtolower($record['categoria'])))->first();
|
||||||
|
|
||||||
if (empty($record['id_categoria'])) {
|
if (empty($categoria)) {
|
||||||
$record['id_categoria'] = 'Nessuna';
|
$categoria = Categoria::build();
|
||||||
}
|
$categoria->setTranslation('name', $record['categoria']);
|
||||||
// Categoria
|
$categoria->save();
|
||||||
$categoria = Categoria::where('nome', strtolower($record['id_categoria']))->first();
|
}
|
||||||
|
|
||||||
if (empty($categoria)) {
|
// Sotto-categoria
|
||||||
$categoria = Categoria::build($record['id_categoria']);
|
if (!empty($record['sottocategoria'])) {
|
||||||
}
|
$sottocategoria = Categoria::where('id', '=', (new Categoria())->getByField('name', strtolower($record['sottocategoria'])))->first();
|
||||||
|
|
||||||
// Sotto-categoria
|
if (empty($sottocategoria)) {
|
||||||
if (!empty($record['id_sottocategoria'])) {
|
$sottocategoria = Categoria::build();
|
||||||
$sottocategoria = Categoria::where('nome', $record['id_sottocategoria'])
|
$sottocategoria->setTranslation('name', $record['sottocategoria']);
|
||||||
->where('parent', $categoria->id)
|
$sottocategoria->parent()->associate($categoria);
|
||||||
->first();
|
$sottocategoria->save();
|
||||||
|
}
|
||||||
if (empty($sottocategoria)) {
|
|
||||||
$sottocategoria = Categoria::build($record['id_sottocategoria']);
|
|
||||||
$sottocategoria->parent()->associate($categoria);
|
|
||||||
$sottocategoria->save();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +144,6 @@ class CSV extends CSVImporter
|
||||||
$impianto->save();
|
$impianto->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
$impianto->id_sottocategoria = $sottocategoria['id'];
|
|
||||||
$impianto->idanagrafica = $anagrafica->idanagrafica;
|
$impianto->idanagrafica = $anagrafica->idanagrafica;
|
||||||
$impianto->save();
|
$impianto->save();
|
||||||
|
|
||||||
|
|
|
@ -124,9 +124,9 @@ class CSV extends CSVImporter
|
||||||
unset($record['tipo']);
|
unset($record['tipo']);
|
||||||
|
|
||||||
if (empty($record['stato'])) {
|
if (empty($record['stato'])) {
|
||||||
$stato = (new Stato())->getByField('name', 'Completato');
|
$stato = Stato::find((new Stato())->getByField('name', 'Completato'));
|
||||||
} else {
|
} else {
|
||||||
$stato = (new Stato())->getByField('name', $record['stato']);
|
$stato = Stato::find((new Stato())->getByField('name', $record['stato']));
|
||||||
}
|
}
|
||||||
unset($record['stato']);
|
unset($record['stato']);
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ class CSV extends CSVImporter
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
['Codice', 'Telefono', 'Data', 'Data richiesta', 'Ora inizio', 'Ora fine', 'Tecnico', 'Tipo', 'Note', 'Impianto', 'Richiesta', 'Descrizione', 'Stato'],
|
['Codice', 'Telefono', 'Data', 'Data richiesta', 'Ora inizio', 'Ora fine', 'Tecnico', 'Tipo', 'Note', 'Impianto', 'Richiesta', 'Descrizione', 'Stato'],
|
||||||
['00001/2024', '+39 0429 60 25 12', '07/11/2024', '03/11/2024', '8:30', '9:30', 'Stefano Bianchi', '', '', '12345-85A22', 'Manutenzione ordinaria', 'eseguito intervento di manutenzione', 'Bozza'],
|
['00001/2024', '+39 0429 60 25 12', '07/11/2024', '03/11/2024', '8:30', '9:30', 'Stefano Bianchi', '', '', '12345-85A22', 'Manutenzione ordinaria', 'eseguito intervento di manutenzione', 'Da programmare'],
|
||||||
['0002/2024', '+39 0429 60 25 12', '08/11/2024', '04/11/2024', '11:20', '', 'Stefano Bianchi', '', '', '12345-85B23', 'Manutenzione ordinaria', 'eseguito intervento di manutenzione', ''],
|
['0002/2024', '+39 0429 60 25 12', '08/11/2024', '04/11/2024', '11:20', '', 'Stefano Bianchi', '', '', '12345-85B23', 'Manutenzione ordinaria', 'eseguito intervento di manutenzione', ''],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ class Stato extends Model
|
||||||
|
|
||||||
public function getModuleAttribute()
|
public function getModuleAttribute()
|
||||||
{
|
{
|
||||||
return 'Stato dei contratti';
|
return 'Stati di attività';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getTranslatedFields()
|
public static function getTranslatedFields()
|
||||||
|
|
|
@ -153,7 +153,7 @@ class Upload extends Model
|
||||||
{
|
{
|
||||||
$parent = $this->plugin ?: $this->module;
|
$parent = $this->plugin ?: $this->module;
|
||||||
|
|
||||||
return strtolower($parent->getTranslation('name'));
|
return strtolower($parent ? $parent->getTranslation('name') : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2455,4 +2455,7 @@ INSERT INTO `zz_api_resources` (`id`, `version`, `type`, `resource`, `class`, `e
|
||||||
(NULL, 'app-v1', 'retrieve', 'pagamento', 'API\\App\\v1\\Pagamenti', '1');
|
(NULL, 'app-v1', 'retrieve', 'pagamento', 'API\\App\\v1\\Pagamenti', '1');
|
||||||
|
|
||||||
ALTER TABLE `mg_categorie` CHANGE `nota` `nota` VARCHAR(1000) NULL;
|
ALTER TABLE `mg_categorie` CHANGE `nota` `nota` VARCHAR(1000) NULL;
|
||||||
ALTER TABLE `mg_categorie` CHANGE `colore` `colore` VARCHAR(255) NULL;
|
ALTER TABLE `mg_categorie` CHANGE `colore` `colore` VARCHAR(255) NULL;
|
||||||
|
|
||||||
|
ALTER TABLE `my_impianti_categorie` CHANGE `nota` `nota` VARCHAR(1000) NULL;
|
||||||
|
ALTER TABLE `my_impianti_categorie` CHANGE `colore` `colore` VARCHAR(255) NULL;
|
Loading…
Reference in New Issue