1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2025-02-03 17:27:29 +01:00

Aggiunta tabella mg_combinazioni_lang

This commit is contained in:
Pek5892 2024-03-01 09:54:39 +01:00
parent 331fb5094e
commit 6168165bcb
5 changed files with 74 additions and 20 deletions

View File

@ -10,15 +10,13 @@ switch (filter('op')) {
$nome = post('nome');
// Ricerca combinazione con nome indicato
$esistente = Combinazione::where('nome', '=', $nome);
$esistente = (new Combinazione())->getByName($nome)->id_record;
if (isset($combinazione)) {
$esistente = $esistente->where('id', '!=', $combinazione->id);
$esistente = Combinazione::find($esistente)->where('id', '!=', $combinazione->id);
}
$esistente = $esistente->count() !== 0;
if (!$esistente) {
$combinazione = $combinazione ?: Combinazione::build();
$combinazione->nome = $nome;
$combinazione->codice = post('codice');
$combinazione->id_categoria = post('id_categoria');
$combinazione->id_sottocategoria = post('id_sottocategoria');
@ -26,6 +24,8 @@ switch (filter('op')) {
$id_record = $combinazione->id;
$database->query('INSERT INTO `mg_combinazioni_lang` (`id_record`, `id_lang`, `name`) VALUES ('.$id_record.', '.setting('Lingua').', \''.post('nome').'\')');
// Selezione attributi per la combinazione
$combinazione->attributi()->sync((array) post('attributi'));

View File

@ -21,7 +21,7 @@ echo '
</div>
<div class="col-md-6">
{[ "type": "text", "label": "'.tr('Nome').'", "name": "nome", "value": "'.$combinazione->nome.'", "required": 1, "help": "'.tr('Nome univoco della combinazione').'" ]}
{[ "type": "text", "label": "'.tr('Nome').'", "name": "nome", "value": "'.$combinazione->name.'", "required": 1, "help": "'.tr('Nome univoco della combinazione').'" ]}
</div>
</div>

View File

@ -88,7 +88,7 @@ class Combinazione extends Model
if (empty($id_articolo)) {
$articoli = $this->articoli;
if ($articoli->isEmpty()) {
$articolo = Articolo::build($this->nome, $this->nome);
$articolo = Articolo::build($this->codice);
$articolo->id_combinazione = $this->id;
$articolo->id_categoria = $this->id_categoria;
@ -110,8 +110,8 @@ class Combinazione extends Model
$articolo->save();
}
}
$articolo->name = $this->nome.' ['.implode(', ', $variante).']';
$articolo->codice = $this->codice.'-'.implode('|', $variante);
$database->query("INSERT INTO `mg_articoli_lang` (`id_record`, `id_lang`, `name`) VALUES ('" . $articolo->id . "', " . setting('Lingua') . ", '" . implode("', '", $variante) . "')");
$articolo->codice = $this->codice . '-' . implode('|', $variante);
$articolo->save();
}
@ -211,4 +211,35 @@ class Combinazione extends Model
->where('id', $this->id)
->update($combo->toArray());
}
/**
* Ritorna l'attributo name della combinazione.
*
* @return string
*/
public function getNameAttribute()
{
return database()->table($this->table.'_lang')
->select('name')
->where('id_record', '=', $this->id)
->where('id_lang', '=', setting('Lingua'))
->first()->name;
}
/**
* Ritorna l'id della combinazione a partire dal nome.
*
* @param string $name il nome da ricercare
*
* @return \Illuminate\Support\Collection
*/
public function getByName($name)
{
return database()->table($this->table.'_lang')
->select('id_record')
->where('name', '=', $name)
->where('id_lang', '=', setting('Lingua'))
->first();
}
}

View File

@ -1465,18 +1465,6 @@ HAVING
2=2" WHERE `name` = 'Attributi Combinazioni';
UPDATE `zz_views` INNER JOIN `zz_modules` ON `zz_views`.`id_module` = `zz_modules`.`id` SET `zz_views`.`query` = '`mg_attributi_lang`.`name`' WHERE `zz_modules`.`name` = 'Attributi Combinazioni' AND `zz_views`.`name` = 'Nome';
-- Allineamento vista Combinazioni
UPDATE `zz_modules` SET `options` = "
SELECT
|select|
FROM
`mg_combinazioni`
WHERE
1=1 AND
`mg_combinazioni`.`deleted_at` IS NULL
HAVING
2=2" WHERE `name` = 'Combinazioni';
-- Aggiunta tabella mg_categorie_lang
CREATE TABLE IF NOT EXISTS `mg_categorie_lang` (
`id` int NOT NULL,
@ -1596,3 +1584,37 @@ ORDER BY
`mg_movimenti`.`data` DESC,
`mg_movimenti`.`created_at` DESC" WHERE `name` = 'Movimenti';
UPDATE `zz_views` INNER JOIN `zz_modules` ON `zz_views`.`id_module` = `zz_modules`.`id` SET `zz_views`.`query` = 'IF(`mg_articoli_lang`.`name` != "", CONCAT(`mg_articoli`.`codice`, " - ", `mg_articoli_lang`.`name`), `mg_articoli`.`codice`)' WHERE `zz_modules`.`name` = 'Movimenti' AND `zz_views`.`name` = 'Articolo';
-- Aggiunta tabella mg_combinazioni_lang
CREATE TABLE IF NOT EXISTS `mg_combinazioni_lang` (
`id` int NOT NULL,
`id_lang` int NOT NULL,
`id_record` int NOT NULL,
`name` VARCHAR(255) NOT NULL
);
ALTER TABLE `mg_combinazioni_lang`
ADD PRIMARY KEY (`id`);
ALTER TABLE `mg_combinazioni_lang`
MODIFY `id` int NOT NULL AUTO_INCREMENT;
INSERT INTO `mg_combinazioni_lang` (`id`, `id_lang`, `id_record`, `name`) SELECT NULL, (SELECT `id` FROM `zz_langs` WHERE `iso_code` = 'it'), `id`, `nome` FROM `mg_combinazioni`;
ALTER TABLE `mg_combinazioni`
DROP `nome`;
ALTER TABLE `mg_combinazioni_lang` ADD CONSTRAINT `mg_combinazioni_lang_ibfk_1` FOREIGN KEY (`id_record`) REFERENCES `mg_combinazioni`(`id`) ON DELETE CASCADE ON UPDATE RESTRICT;
-- Allineamento vista Combinazioni
UPDATE `zz_modules` SET `options` = "
SELECT
|select|
FROM
`mg_combinazioni`
LEFT JOIN `mg_combinazioni_lang` ON (`mg_combinazioni`.`id` = `mg_combinazioni_lang`.`id_record` AND `mg_combinazioni_lang`.|lang|)
WHERE
1=1 AND
`mg_combinazioni`.`deleted_at` IS NULL
HAVING
2=2" WHERE `name` = 'Combinazioni';
UPDATE `zz_views` INNER JOIN `zz_modules` ON `zz_views`.`id_module` = `zz_modules`.`id` SET `zz_views`.`query` = '`mg_combinazioni_lang`.`name`' WHERE `zz_modules`.`name` = 'Combinazioni' AND `zz_views`.`name` = 'Nome';

View File

@ -141,6 +141,7 @@ return [
'mg_attributi_lang',
'mg_attributo_combinazione',
'mg_combinazioni',
'mg_combinazioni_lang',
'mg_valori_attributi',
'my_impianto_componenti',
'my_componenti',