BUB-7 Automobili: Inserito possibilità a livello Model Operazione, di integrare le spese se inMovimenti viene inviato nel post
This commit is contained in:
parent
9f0ee469c8
commit
afc4ac70e6
@ -4,8 +4,14 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class Categorie extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public static function getIdCategoriaByName($name)
|
||||
{
|
||||
return DB::table('categories')->where('cat_name',$name)->get('id');
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\Auto;
|
||||
use App\Models\Categorie;
|
||||
|
||||
class Operazione extends Model
|
||||
{
|
||||
@ -24,6 +26,41 @@ class Operazione extends Model
|
||||
'type'=>$data['type']
|
||||
]
|
||||
);
|
||||
if (isset($data['inMovimenti']))
|
||||
{
|
||||
|
||||
$automobile=Auto::getAutoById($data['auto']);
|
||||
$auto=' '.$automobile['marca'].' '.$automobile['modello'].' '.$automobile['targa'];
|
||||
$categoria=Categorie::getIdCategoriaByName('Automobili');
|
||||
$causale="Automobili: ".strtoUpper($data['type']).' ';
|
||||
|
||||
if(isset($data['descrizione']))
|
||||
{
|
||||
$causale.=$data['descrizione'].$auto;
|
||||
}
|
||||
if(isset($data['centrorevisione']))
|
||||
{
|
||||
$causale.= $data['centrorevisione'].$auto;
|
||||
}
|
||||
if(isset($data['litri']))
|
||||
{
|
||||
$causale.=$auto.' litri:'.$data['litri'].' Euro/litro:'.$data['eurolitro'];
|
||||
}
|
||||
|
||||
DB::table('movimentis')->insert([
|
||||
'mov_data'=>$data['data'],
|
||||
'mov_descrizione'=>'Automobili: '.strtoUpper($data['type']).' '.$auto,
|
||||
'mov_importo'=>'-'.$data['importo'],
|
||||
'mov_fk_categoria'=> $categoria,
|
||||
|
||||
]);
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
|
||||
public static function getOperazioni($autoId)
|
||||
{
|
||||
// Ritorna la lista delle operazioni effettuate sull'auto
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user