Allineamento add stati documento

This commit is contained in:
Pek5892 2024-03-07 09:37:01 +01:00
parent 0294d0aa87
commit 49083abc6a
7 changed files with 57 additions and 20 deletions

View File

@ -76,7 +76,9 @@ class Tipo extends Model
*/ */
public function setNameAttribute($value) public function setNameAttribute($value)
{ {
$translated = database()->table($this->table.'_lang') $table = database()->table($this->table.'_lang');
$translated = $table
->where('id_record', '=', $this->id) ->where('id_record', '=', $this->id)
->where('id_lang', '=', setting('Lingua')); ->where('id_lang', '=', setting('Lingua'));
@ -85,7 +87,7 @@ class Tipo extends Model
'name' => $value 'name' => $value
]); ]);
} else { } else {
$translated->insert([ $table->insert([
'id_record' => $this->id, 'id_record' => $this->id,
'id_lang' => setting('Lingua'), 'id_lang' => setting('Lingua'),
'name' => $value 'name' => $value

View File

@ -66,7 +66,9 @@ class Stato extends Model
*/ */
public function setNameAttribute($value) public function setNameAttribute($value)
{ {
$translated = database()->table($this->table.'_lang') $table = database()->table($this->table.'_lang');
$translated = $table
->where('id_record', '=', $this->id) ->where('id_record', '=', $this->id)
->where('id_lang', '=', setting('Lingua')); ->where('id_lang', '=', setting('Lingua'));
@ -75,7 +77,7 @@ class Stato extends Model
'name' => $value 'name' => $value
]); ]);
} else { } else {
$translated->insert([ $table->insert([
'id_record' => $this->id, 'id_record' => $this->id,
'id_lang' => setting('Lingua'), 'id_lang' => setting('Lingua'),
'name' => $value 'name' => $value

View File

@ -47,6 +47,31 @@ class Stato extends Model
->first()->name; ->first()->name;
} }
/**
* Imposta l'attributo name dell'articolo.
*/
public function setNameAttribute($value)
{
$table = database()->table($this->table.'_lang');
$translated = $table
->where('id_record', '=', $this->id)
->where('id_lang', '=', setting('Lingua'));
if ($translated->count() > 0) {
$translated->update([
'name' => $value
]);
} else {
$table->insert([
'id_record' => $this->id,
'id_lang' => setting('Lingua'),
'name' => $value
]);
}
}
/** /**
* Ritorna l'id dello stato fattura a partire dal nome. * Ritorna l'id dello stato fattura a partire dal nome.
* *

View File

@ -79,7 +79,9 @@ class Aliquota extends Model
*/ */
public function setNameAttribute($value) public function setNameAttribute($value)
{ {
$translated = database()->table($this->table.'_lang') $table = database()->table($this->table.'_lang');
$translated = $table
->where('id_record', '=', $this->id) ->where('id_record', '=', $this->id)
->where('id_lang', '=', setting('Lingua')); ->where('id_lang', '=', setting('Lingua'));
@ -88,7 +90,7 @@ class Aliquota extends Model
'name' => $value 'name' => $value
]); ]);
} else { } else {
$translated->insert([ $table->insert([
'id_record' => $this->id, 'id_record' => $this->id,
'id_lang' => setting('Lingua'), 'id_lang' => setting('Lingua'),
'name' => $value 'name' => $value

View File

@ -185,7 +185,9 @@ class Pagamento extends Model
*/ */
public function setNameAttribute($value) public function setNameAttribute($value)
{ {
$translated = database()->table($this->table.'_lang') $table = database()->table($this->table.'_lang');
$translated = $table
->where('id_record', '=', $this->id) ->where('id_record', '=', $this->id)
->where('id_lang', '=', setting('Lingua')); ->where('id_lang', '=', setting('Lingua'));
@ -194,7 +196,7 @@ class Pagamento extends Model
'name' => $value 'name' => $value
]); ]);
} else { } else {
$translated->insert([ $table->insert([
'id_record' => $this->id, 'id_record' => $this->id,
'id_lang' => setting('Lingua'), 'id_lang' => setting('Lingua'),
'name' => $value 'name' => $value

View File

@ -18,19 +18,20 @@
*/ */
include_once __DIR__.'/../../core.php'; include_once __DIR__.'/../../core.php';
use Modules\Fatture\Stato;
switch (post('op')) { switch (post('op')) {
case 'update': case 'update':
$dbo->update('co_statidocumento', [ $descrizione = post('descrizione');
'icona' => post('icona'), $stato_new = Stato::find((new Stato())->getByName($descrizione)->id_record);
'colore' => post('colore'),
], ['id' => $id_record]);
$dbo->update('co_statidocumento_lang', [
'name' => post('descrizione'),
], ['id_record' => $id_record]);
flash()->info(tr('Informazioni salvate correttamente.'));
if ($stato_new) {
flash()->error(tr('Questo nome è già stato utilizzato per un altro stato.'));
} else {
$stato->icona = post('icona');
$stato->colore = post('colore');
$stato->name = $descrizione;
$stato->save();
break; break;
}
} }

View File

@ -18,7 +18,10 @@
*/ */
include_once __DIR__.'/../../core.php'; include_once __DIR__.'/../../core.php';
use Modules\Fatture\Stato;
if (isset($id_record)) { if (isset($id_record)) {
$record = $dbo->fetchOne('SELECT * FROM `co_statidocumento` LEFT JOIN (`co_statidocumento_lang`) ON (`co_statidocumento_lang`.`id_record` = `co_statidocumento`.`id` AND `co_statidocumento_lang`.`id_lang` = '.prepare(setting('Lingua')).') WHERE `co_statidocumento`.`id`='.prepare($id_record)); $record = $dbo->fetchOne('SELECT * FROM `co_statidocumento` LEFT JOIN (`co_statidocumento_lang`) ON (`co_statidocumento_lang`.`id_record` = `co_statidocumento`.`id` AND `co_statidocumento_lang`.`id_lang` = '.prepare(setting('Lingua')).') WHERE `co_statidocumento`.`id`='.prepare($id_record));
$stato = Stato::find($id_record);
} }