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)
{
$translated = database()->table($this->table.'_lang')
$table = database()->table($this->table.'_lang');
$translated = $table
->where('id_record', '=', $this->id)
->where('id_lang', '=', setting('Lingua'));
@ -85,7 +87,7 @@ class Tipo extends Model
'name' => $value
]);
} else {
$translated->insert([
$table->insert([
'id_record' => $this->id,
'id_lang' => setting('Lingua'),
'name' => $value

View File

@ -66,7 +66,9 @@ class Stato extends Model
*/
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_lang', '=', setting('Lingua'));
@ -75,7 +77,7 @@ class Stato extends Model
'name' => $value
]);
} else {
$translated->insert([
$table->insert([
'id_record' => $this->id,
'id_lang' => setting('Lingua'),
'name' => $value

View File

@ -47,6 +47,31 @@ class Stato extends Model
->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.
*

View File

@ -79,7 +79,9 @@ class Aliquota extends Model
*/
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_lang', '=', setting('Lingua'));
@ -88,7 +90,7 @@ class Aliquota extends Model
'name' => $value
]);
} else {
$translated->insert([
$table->insert([
'id_record' => $this->id,
'id_lang' => setting('Lingua'),
'name' => $value

View File

@ -185,7 +185,9 @@ class Pagamento extends Model
*/
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_lang', '=', setting('Lingua'));
@ -194,7 +196,7 @@ class Pagamento extends Model
'name' => $value
]);
} else {
$translated->insert([
$table->insert([
'id_record' => $this->id,
'id_lang' => setting('Lingua'),
'name' => $value

View File

@ -18,19 +18,20 @@
*/
include_once __DIR__.'/../../core.php';
use Modules\Fatture\Stato;
switch (post('op')) {
case 'update':
$dbo->update('co_statidocumento', [
'icona' => post('icona'),
'colore' => post('colore'),
], ['id' => $id_record]);
$dbo->update('co_statidocumento_lang', [
'name' => post('descrizione'),
], ['id_record' => $id_record]);
flash()->info(tr('Informazioni salvate correttamente.'));
$descrizione = post('descrizione');
$stato_new = Stato::find((new Stato())->getByName($descrizione)->id_record);
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;
}
}

View File

@ -18,7 +18,10 @@
*/
include_once __DIR__.'/../../core.php';
use Modules\Fatture\Stato;
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));
$stato = Stato::find($id_record);
}