Commit iniziale
This commit is contained in:
24
app/Models/Accessori.php
Normal file
24
app/Models/Accessori.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class Accessori extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public static function saveAccessori($id,$data)
|
||||
{
|
||||
DB::table('accessoris')->insert([
|
||||
'fk_operazione_id'=>$id,
|
||||
'descrizione'=>$data['descrizione'],
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getElementsbyOperazione($data) {
|
||||
return DB::table('accessoris')->where('fk_operazione_id','=',$data)->get();
|
||||
}
|
||||
}
|
||||
11
app/Models/Associazione.php
Normal file
11
app/Models/Associazione.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Associazione extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
||||
81
app/Models/Auto.php
Normal file
81
app/Models/Auto.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class Auto extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public static function getAutoById($id)
|
||||
{
|
||||
return $dettagli=DB::table('autos')->find($id);
|
||||
}
|
||||
|
||||
public static function getAutoList()
|
||||
{
|
||||
// return $lista=DB::table('autos')->select(['targa','marca','modello','id'])->get();
|
||||
return $lista = Auto::all();
|
||||
}
|
||||
|
||||
public static function saveAuto($request)
|
||||
{
|
||||
// TODO: inserire validazione post
|
||||
|
||||
$request->validate([
|
||||
'targa' => 'required|unique:posts|max:7',
|
||||
'marca' => 'required',
|
||||
'modello' => 'required',
|
||||
'cilindrata' => 'requierd',
|
||||
]);
|
||||
|
||||
try {
|
||||
DB::table('autos')->insert([
|
||||
'targa'=>$request['targa'],
|
||||
'marca'=>$request['marca'],
|
||||
'modello'=>$request['modello'],
|
||||
'cilindrata'=>$request['cilindrata'],
|
||||
'cvfiscali'=>$request['cvfiscali'],
|
||||
'alimentazione'=>$request['alimentazione'],
|
||||
'ntelaio'=>$request['ntelaio'],
|
||||
'nmotore'=>$request['nmotore'],
|
||||
'data_acquisto'=>$request['data_acquisto'],
|
||||
'note'=>$request['note'],
|
||||
]);
|
||||
Session::flash('success', 'Auto saved successfully.');
|
||||
} catch (\Exception $e) {
|
||||
Session::flash('error', 'Failed to save auto: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static function delAuto($id)
|
||||
{
|
||||
DB::table('autos')->delete($id['id']);
|
||||
}
|
||||
|
||||
public static function updateAuto($data)
|
||||
{
|
||||
try {
|
||||
DB::table('autos')->where('id','=',$data['id'])->update([
|
||||
'targa'=>$data['targa'],
|
||||
'marca'=>$data['marca'],
|
||||
'modello'=>$data['modello'],
|
||||
'cilindrata'=>$data['cilindrata'],
|
||||
'cvfiscali'=>$data['cvfiscali'],
|
||||
'alimentazione'=>$data['alimentazione'],
|
||||
'ntelaio'=>$data['ntelaio'],
|
||||
'nmotore'=>$data['nmotore'],
|
||||
'data_acquisto'=>$data['data_acquisto'],
|
||||
'note'=>$data['note'],
|
||||
|
||||
]);
|
||||
Session::flash('success', 'Auto updated successfully.');
|
||||
} catch (\Exception $e) {
|
||||
Session::flash('error', 'Failed to update auto: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
55
app/Models/Avviso.php
Normal file
55
app/Models/Avviso.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class Avviso extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable=['avviso','creato_il', 'creato_da', 'urgente'];
|
||||
|
||||
public static function newAvviso($data)
|
||||
{
|
||||
self::create([
|
||||
'avviso'=>$data['avviso'],
|
||||
'creato_da'=>$data['creato_da'],
|
||||
'creato_il'=>date('Y-m-d'),
|
||||
'urgente'=>$data['urgente'],
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getAvvisi()
|
||||
{
|
||||
return self::all();
|
||||
}
|
||||
|
||||
public static function getActualAvvisi()
|
||||
{
|
||||
return self::where('creato_il','>=', now()->subMonth())->get();
|
||||
}
|
||||
|
||||
public static function getHAstatus()
|
||||
{
|
||||
/*$response = Http::withHeaders([
|
||||
'Authorization'=>' Bearer '.env('HA_TOKEN'),
|
||||
'Content-Type'=>' application/json',
|
||||
])->get('https://ha.lavorain.cloud/api/services',['domain']);
|
||||
return $response;
|
||||
// return dd($response);*/
|
||||
}
|
||||
|
||||
public static function getAnsaNews()
|
||||
{
|
||||
/*$xmlstring = Http::get('https://www.ansa.it/trentino/notizie/trentino_rss.xml');
|
||||
$xml_file = simplexml_load_string($xmlstring);
|
||||
$json = json_encode($xml_file );
|
||||
$array = json_decode($json,TRUE);
|
||||
dd($array); // return $array;*/
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
109
app/Models/Categorie.php
Normal file
109
app/Models/Categorie.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
|
||||
protected $fillable = ['cat_name'];
|
||||
|
||||
public function movimenti()
|
||||
{
|
||||
return $this->hasMany(Movimenti::class);
|
||||
}
|
||||
|
||||
public static function getIdCategoriaByName($name)
|
||||
{
|
||||
return DB::table('categories')->where('cat_name',$name)->get('id');
|
||||
}
|
||||
|
||||
public static function list()
|
||||
{
|
||||
return self::all();
|
||||
}
|
||||
public static function listCategorieAPI()
|
||||
{
|
||||
return self::orderBy('cat_name')->get();
|
||||
}
|
||||
public static function listSpesa()
|
||||
{
|
||||
return DB::table('categories')->where('cat_uscita','=',1)->orderBy('cat_name')->get();
|
||||
}
|
||||
|
||||
public static function listEntrata()
|
||||
{
|
||||
return DB::table('categories')->where('cat_entrata','=',1)->orderBy('cat_name')->get();
|
||||
}
|
||||
|
||||
public static function inserisci($request){
|
||||
if ($request['cat_entrata']==='on')
|
||||
{
|
||||
$entrata=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$entrata=0;
|
||||
}
|
||||
|
||||
if ($request['cat_uscita']==='on')
|
||||
{
|
||||
$uscita=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$uscita=0;
|
||||
}
|
||||
|
||||
return DB::table('categories')->insert([
|
||||
'cat_name'=> $request['cat_name'],
|
||||
'cat_entrata'=>$entrata,
|
||||
'cat_uscita'=>$uscita
|
||||
]);
|
||||
}
|
||||
|
||||
public static function deleteById($id){
|
||||
DB::table('categories')
|
||||
->where('id','=', $id)
|
||||
->delete();
|
||||
}
|
||||
|
||||
public static function getById($id) {
|
||||
return DB::table('categories')
|
||||
->where('categories.id','=',$id)
|
||||
->get();
|
||||
}
|
||||
|
||||
public static function updateNameById($request) {
|
||||
if ($request['cat_entrata']==='on')
|
||||
{
|
||||
$entrata=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$entrata=0;
|
||||
}
|
||||
|
||||
if ($request['cat_uscita']==='on')
|
||||
{
|
||||
$uscita=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$uscita=0;
|
||||
}
|
||||
|
||||
DB::table('categories')
|
||||
->where('id','=', $request['id'])
|
||||
->update([
|
||||
'cat_name' => $request['cat_name'],
|
||||
'cat_entrata' => $entrata,
|
||||
'cat_uscita'=>$uscita,
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
74
app/Models/CentralTenant.php
Normal file
74
app/Models/CentralTenant.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\Tenant;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use ZipArchive;
|
||||
|
||||
class CentralTenant extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
||||
public static function listTenants()
|
||||
{
|
||||
return Tenant::all();
|
||||
}
|
||||
|
||||
public static function getTenant($id)
|
||||
{
|
||||
return Tenant::where('id', $id)->get();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function backupTenant($tenantId) {
|
||||
// 1. Identificazione del tenant
|
||||
$tenant = Tenant::find($tenantId);
|
||||
if (!$tenant) {
|
||||
return 'Tenant non trovato.';
|
||||
}
|
||||
|
||||
// 2. Switch al tenant
|
||||
tenancy()->initialize($tenant);
|
||||
|
||||
// 3. Generazione del nome del file zip
|
||||
$fileName = $tenantId . '_' . date('YmdHms') . '.zip';
|
||||
$zipPath = storage_path('app/' . $fileName);
|
||||
|
||||
// 4. Creazione dell'archivio zip
|
||||
$zip = new ZipArchive;
|
||||
if ($zip->open($zipPath, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== true) {
|
||||
return 'Impossibile creare l\'archivio zip.';
|
||||
}
|
||||
|
||||
// 5. Dump del database
|
||||
$databaseName = config('database.connections.tenant.database'); // Assumi 'tenant' come connessione per i tenant
|
||||
$dumpFile = storage_path('app/temp_dump.sql');
|
||||
$command = "mysqldump -u " . config('database.connections.tenant.username') . " -p" . config('database.connections.tenant.password') . " " . $databaseName . " > " . $dumpFile;
|
||||
exec($command);
|
||||
$zip->addFile($dumpFile, 'database.sql');
|
||||
|
||||
// 6. Aggiunta della cartella storage
|
||||
//$storagePath = storage_path('app/tenant/' .$tenantId); // Assumi una struttura di storage separata per tenant
|
||||
$storagePath = storage_path();
|
||||
$files = \File::allFiles($storagePath);
|
||||
foreach ($files as $file) {
|
||||
$relativePath = str_replace($storagePath . '/', '', $file->getPathname());
|
||||
$zip->addFile($file->getPathname(), 'storage/' . $relativePath);
|
||||
}
|
||||
|
||||
// 7. Chiusura dell'archivio zip
|
||||
$zip->close();
|
||||
|
||||
// 8. Download del file
|
||||
// dd($zipPath);
|
||||
return response()->download($zipPath, $fileName, [
|
||||
'Content-Type' => 'application/zip',
|
||||
'Content-Disposition' => 'attachment; filename="' . $fileName . '"',
|
||||
])->deleteFileAfterSend(true); // Cancella il file dopo il download
|
||||
}
|
||||
}
|
||||
30
app/Models/Conto.php
Normal file
30
app/Models/Conto.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Conto extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'nomeConto',
|
||||
'Banca',
|
||||
'IBAN',
|
||||
'saldo_iniziale',
|
||||
'note',
|
||||
];
|
||||
|
||||
public function movimenti()
|
||||
{
|
||||
return $this->hasMany(Movimenti::class);
|
||||
}
|
||||
|
||||
public function saldo()
|
||||
{
|
||||
return $this->saldo_iniziale + $this->movimenti()->sum('importo');
|
||||
}
|
||||
}
|
||||
// Compare this snippet from app/Models/Movimenti.php:
|
||||
43
app/Models/Contratti.php
Normal file
43
app/Models/Contratti.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
|
||||
class Contratti extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable=[
|
||||
'numero',
|
||||
'nome',
|
||||
'datainizio',
|
||||
'datatermine',
|
||||
'fornitore',
|
||||
'tipo',
|
||||
'importo',
|
||||
'scadenzapagamento',
|
||||
'stato',
|
||||
'note',
|
||||
'filename'
|
||||
];
|
||||
|
||||
|
||||
public static function storeContratto(Request $req){
|
||||
/* dd($req); */
|
||||
|
||||
}
|
||||
|
||||
public static function getAllContratto(){
|
||||
return self::all();
|
||||
}
|
||||
|
||||
public static function getContrattoById($id){
|
||||
return DB::table('contrattis')->where('id','=',$id)->get();
|
||||
}
|
||||
|
||||
}
|
||||
74
app/Models/Documenti.php
Normal file
74
app/Models/Documenti.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class Documenti extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
||||
protected $fillable = [
|
||||
'descrizione',
|
||||
'path',
|
||||
];
|
||||
|
||||
public static function countDocument($id){
|
||||
$quanti=DB::table('documentis')
|
||||
->where('movimenti_id','=',$id)
|
||||
->count();
|
||||
return $quanti;
|
||||
}
|
||||
|
||||
// Proposta modifica {issue #5} gitea (generalizzazione del documento)
|
||||
/*
|
||||
public static function countDocument($id,$entity)
|
||||
{
|
||||
return self::where('entita','=',$entity)->where('entita_id','=',$id)->count();
|
||||
}
|
||||
*/
|
||||
|
||||
public static function store($req) {
|
||||
// $movimento_id=$req->input('id');
|
||||
// $filename=$req->file('filename')->store('Documenti');
|
||||
DB::table('documentis')
|
||||
->insert([
|
||||
// 'movimenti_id'=>$movimento_id,
|
||||
'descrizione'=>$req->input('descrizione'),
|
||||
'path'=>$req->input('path'),
|
||||
// 'filename'=>$filename,
|
||||
]);
|
||||
}
|
||||
|
||||
// Proposta modifica {issue #5} gitea (generalizzazione del documento)
|
||||
/*
|
||||
public static function store($req) {
|
||||
$movimento_id=$req->input('id');
|
||||
$filename=$req->file('filename')->store('Documenti');
|
||||
self::create([
|
||||
'entità'=>$req['entita'], // aggiunto per determinare il tipo di entità a cui si riferisce il documento
|
||||
'entita_id'=>$req['entita_id'], // aggiunto per identificare il record al quale associare il documento (al posto di id_movimento)
|
||||
'descrizione'=>$req['descrizione'],
|
||||
'filename'=>$filename
|
||||
]);
|
||||
}
|
||||
*/
|
||||
|
||||
public static function getList($id)
|
||||
{
|
||||
return DB::table('documentis')
|
||||
->where('movimenti_id','=', $id)
|
||||
->get();
|
||||
}
|
||||
|
||||
// Proposta modifica issue {#5 gitea} (generalizzazione del documento)
|
||||
/*
|
||||
public static function getList($id,$entity)
|
||||
{
|
||||
self::where('entita','=',$entity)->where('entita_id','=',$id)->get();
|
||||
}
|
||||
*/
|
||||
}
|
||||
27
app/Models/Event.php
Normal file
27
app/Models/Event.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
|
||||
|
||||
class Event extends Model
|
||||
|
||||
{
|
||||
|
||||
use HasFactory;
|
||||
|
||||
|
||||
|
||||
protected $fillable = [
|
||||
'title','description', 'start', 'end'
|
||||
];
|
||||
|
||||
}
|
||||
61
app/Models/GenDoc.php
Normal file
61
app/Models/GenDoc.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Models\Documenti;
|
||||
|
||||
class GenDoc extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
// DocumentiGenerali
|
||||
|
||||
public static function saveDocument($data){
|
||||
|
||||
$filename=$data->file('filename')->store(self::getEntityFolder($data['entity']));
|
||||
DB::table('gen_docs')
|
||||
->insert([
|
||||
'entity'=>$data['entity'],
|
||||
'entity_id'=>($data['entity_id'] ?? 0 ),
|
||||
'descrizione'=>$data['descrizione'],
|
||||
'filename'=>$filename,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function listDocument($entity,$entity_id = 0)
|
||||
{
|
||||
// Ritorna la lista dei documenti in base all'entità e al rispettivo id
|
||||
return DB::table('gen_docs')->where('entity','=',$entity)->where('entity_id','=',$entity_id)->get(); //nuova funzione
|
||||
// return DB::table('documentis')->where('movimenti_id','=', $entity_id)->get();
|
||||
}
|
||||
|
||||
public static function countDocument($entity,$entity_id = 0){
|
||||
// Conta i documenti inseriti per la determinata entità e id
|
||||
$quanti=DB::table('gen_docs')
|
||||
->where('entity','=',$entity)
|
||||
->where('entity_id','=',$entity_id)
|
||||
->count();
|
||||
return $quanti;
|
||||
}
|
||||
|
||||
private static function getEntityFolder($id)
|
||||
{
|
||||
// Recupera il percorso ('path') dell'entità con l'ID specificato dalla tabella 'Documenti'
|
||||
$entita = Documenti::where('id',$id)->pluck('path');
|
||||
// Restituisce il primo elemento del risultato, che dovrebbe essere il percorso dell'entità
|
||||
return $entita[0];
|
||||
|
||||
}
|
||||
|
||||
public static function delDocument($id){
|
||||
$deleted = GenDoc::where('id',$id)->get();
|
||||
Storage::delete($deleted[0]->filename);
|
||||
$removed = GenDoc::destroy($id);
|
||||
//$removed->detete();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
11
app/Models/Gruppi.php
Normal file
11
app/Models/Gruppi.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Gruppi extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
||||
26
app/Models/HomeAssistantAPI.php
Normal file
26
app/Models/HomeAssistantAPI.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class HomeAssistantAPI extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public static function getSensorState($sensor)
|
||||
{
|
||||
$result=Http::withHeaders(
|
||||
[
|
||||
'Authorization'=>'Bearer '.env('HA_TOKEN'),
|
||||
'Content-Type'=>'application/json',
|
||||
]
|
||||
)->get('https://ha.lavorain.cloud/api/states/'.$sensor);
|
||||
|
||||
return json_decode($result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
11
app/Models/ImportRule.php
Normal file
11
app/Models/ImportRule.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ImportRule extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
||||
24
app/Models/Manutenzione.php
Normal file
24
app/Models/Manutenzione.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class Manutenzione extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public static function saveManutenzione($id,$data)
|
||||
{
|
||||
DB::table('manutenziones')->insert([
|
||||
'fk_operazione_id'=>$id,
|
||||
'descrizione'=>$data['descrizione'],
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getElementsbyOperazione($data) {
|
||||
return DB::table('manutenziones')->where('fk_operazione_id','=',$data)->get();
|
||||
}
|
||||
}
|
||||
398
app/Models/Movimenti.php
Normal file
398
app/Models/Movimenti.php
Normal file
@@ -0,0 +1,398 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Rap2hpoutre\FastExcel\FastExcel;
|
||||
use App\Models\Categorie;
|
||||
use App\Models\Conto;
|
||||
use App\Models\User;
|
||||
|
||||
class Movimenti extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $dates = ['mov_data'];
|
||||
protected $casts = [ 'mov_data'=>'datetime'];
|
||||
|
||||
public static $query= 'SELECT
|
||||
a.id,
|
||||
a.mov_data,
|
||||
a.mov_importo,
|
||||
a.mov_descrizione,
|
||||
c.cat_name,
|
||||
t.tag_name,
|
||||
(SELECT Count(entity_id) as quanti FROM gen_docs WHERE entity=0 AND entity_id = a.id) as quanti
|
||||
FROM movimentis as a
|
||||
JOIN tags as t ON a.mov_fk_tags=t.id
|
||||
JOIN categories as c ON a.mov_fk_categoria=c.id';
|
||||
|
||||
public function Conto()
|
||||
{
|
||||
return $this->belongsTo(Conto::class);
|
||||
}
|
||||
|
||||
public function User()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function Categorie()
|
||||
{
|
||||
return $this->belongsTo(Categorie::class);
|
||||
}
|
||||
|
||||
public function Tags()
|
||||
{
|
||||
return $this->belongsTo(Tags::class);
|
||||
}
|
||||
|
||||
public static function getList() {
|
||||
|
||||
|
||||
$expression=DB::raw(
|
||||
'SELECT
|
||||
a.id,
|
||||
a.mov_data,
|
||||
a.mov_importo,
|
||||
a.mov_descrizione,
|
||||
c.cat_name,
|
||||
t.tag_name,
|
||||
co.nomeConto,
|
||||
(SELECT Count(entity_id) as quanti FROM gen_docs WHERE entity=0 AND entity_id = a.id) as quanti
|
||||
FROM movimentis as a
|
||||
JOIN tags as t ON a.mov_fk_tags=t.id
|
||||
JOIN categories as c ON a.mov_fk_categoria=c.id
|
||||
JOIN contos as co ON a.conto_id=co.id'
|
||||
);
|
||||
|
||||
$query = $expression->getValue(DB::connection()->getQueryGrammar());
|
||||
return DB::select($query);
|
||||
}
|
||||
|
||||
public static function getSaldo($date) {
|
||||
return DB::table('movimentis')->whereYear('mov_data','=',$date)->sum('mov_importo');
|
||||
}
|
||||
|
||||
public static function getSaldoTot() {
|
||||
return DB::table('movimentis')->sum('mov_importo');
|
||||
}
|
||||
|
||||
public static function insSpesa( $request) {
|
||||
DB::table('movimentis')->insert(
|
||||
[
|
||||
'mov_data'=>$request->mov_data,
|
||||
'mov_fk_categoria'=>$request->mov_fk_categoria,
|
||||
'mov_descrizione'=>$request->mov_descrizione,
|
||||
'mov_importo'=>'-'.$request->mov_importo,
|
||||
'mov_fk_tags'=>$request->mov_fk_tags,
|
||||
'mov_inserito_da'=>$request->userid,
|
||||
'conto_id'=>$request->conto_id,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function giroconto($request){
|
||||
|
||||
$requestUscita=$request;
|
||||
$requestEntrata=$request;
|
||||
|
||||
$requestUscita['conto_id']=$requestUscita->daConto;
|
||||
$requestUscita['mov_fk_tags']=1;
|
||||
$rqUscita = $requestUscita;
|
||||
self::insSpesa($rqUscita);
|
||||
|
||||
$requestEntrata['conto_id']=$requestEntrata->aConto;
|
||||
$requestEntrata['mov_fk_tags']=1;
|
||||
$rqEntrata = $requestEntrata;
|
||||
self::insEntrata($rqEntrata);
|
||||
unset($requestUscita['daConto']);
|
||||
unset($requestEntrata['aConto']);
|
||||
|
||||
}
|
||||
|
||||
public static function insEntrata( $request) {
|
||||
DB::table('movimentis')->insert(
|
||||
[
|
||||
'mov_data'=>$request['mov_data'],
|
||||
'mov_fk_categoria'=>$request['mov_fk_categoria'],
|
||||
'mov_descrizione'=>$request['mov_descrizione'],
|
||||
'mov_importo'=>$request['mov_importo'],
|
||||
'mov_fk_tags'=>$request['mov_fk_tags'],
|
||||
'mov_inserito_da'=>$request['userid'],
|
||||
'conto_id'=>$request->conto_id,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function export() {
|
||||
return DB::table('movimentis')
|
||||
->join('categories','movimentis.mov_fk_categoria','=','categories.id')
|
||||
->join('tags','movimentis.mov_fk_tags','=','tags.id')
|
||||
->join('contos','movimentis.conto_id','=','contos.id')
|
||||
->selectRaw('mov_data AS Data,cat_name AS Categoria,tag_name AS Tag,NomeConto AS Conto, mov_descrizione AS Descrizione,mov_importo AS Importo')
|
||||
->orderBy('Data','asc')
|
||||
->get();
|
||||
}
|
||||
|
||||
public static function reportSpesa($year,$month) {
|
||||
return DB::table('movimentis')
|
||||
->selectRaw('ABS(Sum(movimentis.mov_importo)) as resoconto, categories.cat_name,categories.id')
|
||||
->join('categories','movimentis.mov_fk_categoria','=','categories.id')
|
||||
->where('mov_importo','<',0)
|
||||
->whereYear('mov_data',$year)
|
||||
->whereMonth('mov_data',$month)
|
||||
->groupBy('cat_name','categories.id')
|
||||
->get();
|
||||
}
|
||||
|
||||
public static function reportEntrate($year,$month) {
|
||||
return DB::table('movimentis')
|
||||
->selectRaw('ABS(Sum(movimentis.mov_importo)) as resoconto, categories.cat_name,categories.id')
|
||||
->join('categories','movimentis.mov_fk_categoria','=','categories.id')
|
||||
->where('mov_importo','>',0)
|
||||
->whereYear('mov_data',$year)
|
||||
->whereMonth('mov_data',$month)
|
||||
->groupBy('cat_name','categories.id')
|
||||
->get();
|
||||
}
|
||||
|
||||
public static function getMovimentoById($id) {
|
||||
return DB::table('movimentis')
|
||||
->join('categories','movimentis.mov_fk_categoria','=','categories.id')
|
||||
->join('tags','movimentis.mov_fk_tags','=','tags.id')
|
||||
->where('movimentis.id','=',$id)
|
||||
->get();
|
||||
}
|
||||
|
||||
public static function updateMovimenti($request) {
|
||||
DB::table('movimentis')
|
||||
->where('id','=', $request['id'])
|
||||
->update([
|
||||
'mov_data' => $request['mov_data'],
|
||||
'mov_fk_categoria'=>$request['mov_fk_categoria'],
|
||||
'mov_descrizione'=>$request['mov_descrizione'],
|
||||
'mov_importo'=>$request['mov_importo'],
|
||||
'mov_fk_tags'=>$request['mov_fk_tags'],
|
||||
'mov_inserito_da'=>$request['userid'],
|
||||
]);
|
||||
}
|
||||
|
||||
public static function deleteMovimento($id) {
|
||||
DB::table('movimentis')
|
||||
->where('id','=', $id)
|
||||
->delete();
|
||||
}
|
||||
|
||||
public static function listByCatMonth($month,$cat,$year) {
|
||||
|
||||
$expression= DB::raw('SELECT
|
||||
a.id,
|
||||
a.mov_data,
|
||||
a.mov_importo,
|
||||
a.mov_descrizione,
|
||||
c.cat_name,
|
||||
t.tag_name,
|
||||
(SELECT Count(entity_id) as quanti FROM gen_docs WHERE entity=0 AND entity_id = a.id) as quanti
|
||||
FROM movimentis as a
|
||||
JOIN tags as t ON a.mov_fk_tags=t.id
|
||||
JOIN categories as c ON a.mov_fk_categoria=c.id
|
||||
WHERE Month(a.mov_data)='.$month.' AND Year(a.mov_data)='.$year.' AND a.mov_fk_categoria='.$cat
|
||||
);
|
||||
$query = $expression->getValue(DB::connection()->getQueryGrammar());
|
||||
return DB::select($query);
|
||||
|
||||
}
|
||||
|
||||
public static function listByCategory($cat) {
|
||||
|
||||
$expression=DB::raw(' SELECT a.id,
|
||||
a.mov_data,
|
||||
a.mov_importo,
|
||||
a.mov_descrizione,
|
||||
c.cat_name,
|
||||
t.tag_name,
|
||||
(SELECT Count(entity_id) as quanti FROM gen_docs WHERE entity=0 AND entity_id = a.id) as quanti
|
||||
FROM movimentis as a
|
||||
JOIN tags as t ON a.mov_fk_tags=t.id
|
||||
JOIN categories as c ON a.mov_fk_categoria=c.id
|
||||
WHERE a.mov_fk_categoria = '.$cat );
|
||||
|
||||
$query = $expression->getValue(DB::connection()->getQueryGrammar());
|
||||
return DB::select($query);
|
||||
|
||||
}
|
||||
|
||||
public static function getByTag($tag) {
|
||||
$expression=DB::raw('SELECT
|
||||
a.id,
|
||||
a.mov_data,
|
||||
a.mov_importo,
|
||||
a.mov_descrizione,
|
||||
c.cat_name,
|
||||
t.tag_name,
|
||||
(SELECT Count(entity_id) as quanti FROM gen_docs WHERE entity=0 AND entity_id = a.id) as quanti
|
||||
FROM movimentis as a
|
||||
JOIN tags as t ON a.mov_fk_tags=t.id
|
||||
JOIN categories as c ON a.mov_fk_categoria=c.id
|
||||
WHERE a.mov_fk_tags = '.$tag );
|
||||
$query = $expression->getValue(DB::connection()->getQueryGrammar());
|
||||
return DB::select($query);
|
||||
}
|
||||
|
||||
public static function importEstrattoIng($filename)
|
||||
{
|
||||
|
||||
$inputPath='/var/www/html/gestionale_mt/public/storage/tenant'.tenant('id').'/'.$filename;
|
||||
// $outputPath='/var/www/html/gestionale_mt/public/tenant'.tenant('id').'/import/'.$filename.'.csv';
|
||||
$outputPath = $inputPath.'.csv';
|
||||
rename($inputPath,$outputPath);
|
||||
$collection = (new FastExcel)->configureCsv(";")->import($outputPath, function ($line){
|
||||
if($line['DATA VALUTA'])
|
||||
{
|
||||
if($line['ENTRATE']!=null)
|
||||
{
|
||||
$importo = $line['ENTRATE'];
|
||||
} elseif($line['USCITE']!=null)
|
||||
{
|
||||
$importo = $line['USCITE'];
|
||||
}
|
||||
$euro=str_replace(',','.',str_replace('+','',str_replace('.','', $importo)));
|
||||
list($giorno,$mese,$anno) = explode('/',$line['DATA VALUTA']);
|
||||
$data="$anno-$mese-$giorno";
|
||||
self::insEntrata([
|
||||
'mov_data'=>self::dateFormat(0,$line['DATA VALUTA']),
|
||||
'mov_fk_categoria'=>1,
|
||||
'mov_descrizione'=>$line['DESCRIZIONE OPERAZIONE'],
|
||||
'mov_importo'=>$euro,
|
||||
'mov_fk_tags'=>1,
|
||||
'userid'=>1,
|
||||
]);
|
||||
}
|
||||
});
|
||||
unlink($outputPath);
|
||||
|
||||
}
|
||||
|
||||
public static function importEstrattoCR($filename)
|
||||
{
|
||||
$inputPath='/var/www/html/gestionale_mt/public/storage/tenant'.tenant('id').'/'.$filename;
|
||||
// $outputPath='/var/www/html/gestionale_mt/public/'.tenant('id')."/app/".$filename;
|
||||
$outputPath = $inputPath.'.csv';
|
||||
rename($inputPath,$outputPath);
|
||||
|
||||
//$outputPath="/var/www/html/gestionale_mt/storage/tenant".tenant('id')."/app/".$filename;
|
||||
|
||||
$collection = (new FastExcel)->configureCsv(';')->import($outputPath, function ($line){
|
||||
if($line['VALUTA'])
|
||||
{
|
||||
if($line['DARE']<>'')
|
||||
{
|
||||
$dati=[
|
||||
'mov_data'=>self::dateFormat(0,$line['VALUTA']),
|
||||
// date_format(date_create($movimento->mov_data),'d/m/Y'
|
||||
// 'mov_data'=>date_format(date_create($line['VALUTA']),'Y-m-d'),
|
||||
'mov_fk_categoria'=>1,
|
||||
'mov_descrizione'=>$line['DESCRIZIONE OPERAZIONE'],
|
||||
'mov_importo'=>'-'.trim(str_replace(',','.',(str_replace('.','',$line['DARE'])))),
|
||||
'mov_fk_tags'=>1,
|
||||
'userid'=>1,
|
||||
];
|
||||
}
|
||||
if($line['AVERE']<>'')
|
||||
{
|
||||
$dati=[
|
||||
'mov_data'=>self::dateFormat(0,$line['VALUTA']),
|
||||
//'mov_data'=>date_format(date_create($line['VALUTA']),'Y-m-d'),
|
||||
'mov_fk_categoria'=>1,
|
||||
'mov_descrizione'=>$line['DESCRIZIONE OPERAZIONE'],
|
||||
'mov_importo'=>trim(str_replace(',','.',(str_replace('.','',$line['AVERE'])))),
|
||||
'mov_fk_tags'=>1,
|
||||
'userid'=>1,
|
||||
];
|
||||
}
|
||||
self::insEntrata($dati);
|
||||
}
|
||||
});
|
||||
unlink($outputPath);
|
||||
}
|
||||
|
||||
// Test filtri categoria
|
||||
public function mapFieldByName($name)
|
||||
{
|
||||
// definisce lo schema per rigenerare il file CSV secondo standard di importazione
|
||||
$fields = Illuminate\Support\Facade\Schema::getColumnListing('movimentis')->mapFieldByName;
|
||||
foreach ($fields as $field)
|
||||
{
|
||||
echo $column . "\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Test applicazione regole
|
||||
public function setCategoriaMovimento($movimento)
|
||||
{
|
||||
$rules= \App\Models\ImportRule::all();
|
||||
|
||||
foreach ($rules as $role)
|
||||
{
|
||||
if (preg_match("/$role->parola/i","$movimento->descrizione"))
|
||||
{
|
||||
$movimento->catemov_fk_categoria=$role->categoria_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$movimento->catemov_fk_categoria=1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static function getYearsFromMovimenti()
|
||||
{
|
||||
$anni=DB::table('movimentis')->select(DB::raw('DISTINCT YEAR(mov_data) as anno'))->get();
|
||||
// dd($anni); // for test purposes
|
||||
return $anni;
|
||||
}
|
||||
|
||||
|
||||
private static function dateFormat($type,$string)
|
||||
{
|
||||
// $string=(string)$string;
|
||||
if($type)
|
||||
{
|
||||
// $string=$string->format('Y-m-d');
|
||||
list($year,$month,$day) = explode('-',$string);
|
||||
return $day.'/'.$month.'/'.$year;
|
||||
} else {
|
||||
// $string=$string->format('d/m/Y');
|
||||
list($day,$month,$year) =explode('/',$string);
|
||||
return $year.'-'.$month.'-'.$day;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getEntrate($year)
|
||||
{
|
||||
$entrate_anno=DB::table('movimentis')
|
||||
->where('mov_importo','>',0)
|
||||
->whereYear('mov_data', '=' , $year)
|
||||
->sum('mov_importo');
|
||||
//->get();
|
||||
return $entrate_anno;
|
||||
}
|
||||
|
||||
public static function getUscite($year)
|
||||
{
|
||||
$uscite_anno=DB::table('movimentis')
|
||||
->where('mov_importo','<',0)
|
||||
->whereYear('mov_data', '=' , $year)
|
||||
->sum('mov_importo');
|
||||
//->get();
|
||||
return ($uscite_anno);
|
||||
}
|
||||
|
||||
}
|
||||
131
app/Models/Operazione.php
Normal file
131
app/Models/Operazione.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
//use Barryvdh\DomPDF\Facade\Pdf;
|
||||
use Sfneal\ViewExport\Pdf\PdfExportService;
|
||||
|
||||
|
||||
class Operazione extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
// Operazione effettuata sull'auto
|
||||
|
||||
public static function saveOperazione($data)
|
||||
{
|
||||
// inserisce nel database e ritorna l'id
|
||||
$id=DB::table('operaziones')->insertGetId(
|
||||
[
|
||||
'fk_auto_id'=>$data['auto'],
|
||||
'data'=>$data['data'],
|
||||
'km'=>$data['km'],
|
||||
'importo'=>$data['importo'],
|
||||
'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'=>$causale,
|
||||
'mov_importo'=>'-'.$data['importo'],
|
||||
'mov_fk_categoria'=> 1,
|
||||
'mov_inserito_da'=>1,
|
||||
'mov_fk_tags'=>1,
|
||||
|
||||
]);
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
|
||||
public static function getOperazioni($autoId)
|
||||
{
|
||||
// Ritorna la lista delle operazioni effettuate sull'auto
|
||||
$automobile=Auto::getAutoById($autoId);
|
||||
$data=DB::table('operaziones')
|
||||
->where('fk_auto_id','=',$autoId)
|
||||
->orderBy('km')
|
||||
->get();
|
||||
foreach ($data as $dato)
|
||||
{
|
||||
$accessori[$dato->id]=Accessori::getElementsbyOperazione($dato->id);
|
||||
$manutenzione[$dato->id]=Manutenzione::getElementsbyOperazione($dato->id);
|
||||
$revisione[$dato->id]=Revisione::getElementsbyOperazione($dato->id);
|
||||
$rifornimento[$dato->id]=Rifornimento::getElementsbyOperazione($dato->id);
|
||||
if(isset($dato->km))
|
||||
{
|
||||
$km=$dato->km;
|
||||
}else{
|
||||
$km=0;
|
||||
}
|
||||
}
|
||||
// Debug
|
||||
/* dd($rifornimento);*/
|
||||
return view('auto.detail',[
|
||||
'dettagli'=>$automobile,
|
||||
'km'=>$km,
|
||||
|
||||
'operazione'=>$data,
|
||||
'accessori'=>$accessori,
|
||||
'manutenzione'=>$manutenzione,
|
||||
'revisione'=>$revisione,
|
||||
'rifornimento'=>$rifornimento,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function exportPdfOperazioni($autoId)
|
||||
{
|
||||
$automobile=Auto::getAutoById($autoId);
|
||||
$data=DB::table('operaziones')
|
||||
->where('fk_auto_id','=',$autoId)
|
||||
->orderBy('km')
|
||||
->get();
|
||||
foreach ($data as $dato)
|
||||
{
|
||||
$accessori[$dato->id]=Accessori::getElementsbyOperazione($dato->id);
|
||||
$manutenzione[$dato->id]=Manutenzione::getElementsbyOperazione($dato->id);
|
||||
$revisione[$dato->id]=Revisione::getElementsbyOperazione($dato->id);
|
||||
$rifornimento[$dato->id]=Rifornimento::getElementsbyOperazione($dato->id);
|
||||
if(isset($dato->km))
|
||||
{
|
||||
$km=$dato->km;
|
||||
}else{
|
||||
$km=0;
|
||||
}
|
||||
}
|
||||
$view= view('auto.detailpdf',[
|
||||
'dettagli'=>$automobile,
|
||||
'km'=>$km,
|
||||
|
||||
'operazione'=>$data,
|
||||
'accessori'=>$accessori,
|
||||
'manutenzione'=>$manutenzione,
|
||||
'revisione'=>$revisione,
|
||||
'rifornimento'=>$rifornimento,
|
||||
]);
|
||||
return $pdf=PdfExportService::fromView($view)->handle()->download();
|
||||
}
|
||||
}
|
||||
80
app/Models/Progetti.php
Normal file
80
app/Models/Progetti.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class Progetti extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public static function getProgetti() {
|
||||
return DB::table('progettis')
|
||||
->select(
|
||||
'progettis.id as progetto',
|
||||
'users.id as userid',
|
||||
'nome',
|
||||
'name',
|
||||
'descrizione',
|
||||
'data_creazione',
|
||||
'data_fine',
|
||||
'budget',
|
||||
'stato',
|
||||
'note')
|
||||
->join('users','progettis.fk_user','=','users.id')->get();
|
||||
}
|
||||
|
||||
public static function getProgettoById($id){
|
||||
return DB::table('progettis')->
|
||||
join('users','progettis.fk_user','=','users.id')->
|
||||
select('users.id as userid', 'users.name as name', 'progettis.*')->
|
||||
where('progettis.id','=',$id)->
|
||||
get();
|
||||
}
|
||||
|
||||
public static function saveProgetto($progetto){
|
||||
DB::table('progettis')->insert([
|
||||
'nome'=>$progetto['nome'],
|
||||
'descrizione'=>$progetto['descrizione'],
|
||||
'data_creazione'=>date('Y-m-d'),
|
||||
'data_inizio'=>$progetto['data_inizio'],
|
||||
'data_fine'=>$progetto['data_fine'],
|
||||
'fk_user'=>$progetto['coordinatore'],
|
||||
'budget'=>$progetto['budget'],
|
||||
'stato'=>$progetto['stato'],
|
||||
'note'=>$progetto['note']
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public static function delProgetto($progetto_id)
|
||||
{
|
||||
DB::table('progettis')->delete($progetto_id);
|
||||
}
|
||||
|
||||
public static function chiudiProgetto($progetto_id)
|
||||
{
|
||||
// chiude il progetto e lo rende non cancellabile e non più editabile
|
||||
// potrà solo essere esportato in PDF
|
||||
DB::table('progettis')
|
||||
->where('id','=', $progetto_id)
|
||||
->update([
|
||||
'stato'=>'chiuso',
|
||||
'data_fine'=>date('Y-m-d'),
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public static function riapriProgetto($progetto_id)
|
||||
{
|
||||
DB::table('progettis')
|
||||
->where('id','=', $progetto_id)
|
||||
->update([
|
||||
'stato'=>'aperto',
|
||||
'data_fine'=>null,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
27
app/Models/Revisione.php
Normal file
27
app/Models/Revisione.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class Revisione extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public static function saveRevisione($id,$data)
|
||||
{
|
||||
DB::table('revisiones')->insert([
|
||||
'fk_operazione_id'=>$id,
|
||||
'descrizione'=>$data['descrizione'],
|
||||
'centrorevisione'=>$data['centrorevisione'],
|
||||
'superata'=>$data['superata'],
|
||||
'dataproxrevisione'=>$data['dataproxrevisione'],
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getElementsbyOperazione($data) {
|
||||
return DB::table('revisiones')->where('fk_operazione_id','=',$data)->get();
|
||||
}
|
||||
}
|
||||
27
app/Models/Rifornimento.php
Normal file
27
app/Models/Rifornimento.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class Rifornimento extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
// Inserisce i dati di un rifornimento
|
||||
public static function saveRifornimento($id,$data)
|
||||
{
|
||||
DB::table('rifornimentos')->insert([
|
||||
'eurolitro'=>$data['eurolitro'],
|
||||
'litri'=>$data['litri'],
|
||||
'distributore'=>$data['distributore'],
|
||||
'fk_operazione_id'=>$id
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getElementsbyOperazione($data) {
|
||||
return DB::table('rifornimentos')->where('fk_operazione_id','=',$data)->get();
|
||||
}
|
||||
}
|
||||
53
app/Models/RigaProgetto.php
Normal file
53
app/Models/RigaProgetto.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class RigaProgetto extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public static function getRigheProgetto($progetto_id)
|
||||
{
|
||||
return DB::table('riga_progettos')->where('fk_id_progetto','=',$progetto_id)->orderBy('data')->get();
|
||||
}
|
||||
|
||||
public static function saveRiga($args,$id)
|
||||
{
|
||||
DB::table('riga_progettos')->insert([
|
||||
'fk_id_progetto'=>$id,
|
||||
'data'=>$args['data'],
|
||||
'descrizione'=>$args['descrizione'],
|
||||
'prezzo'=>$args['prezzo'],
|
||||
'ore'=>$args['ore'],
|
||||
]);
|
||||
}
|
||||
|
||||
public static function deleteRow($id)
|
||||
{
|
||||
DB::table('riga_progettos')->delete($id);
|
||||
}
|
||||
|
||||
public static function getCostoRighe($id)
|
||||
{
|
||||
return DB::table('riga_progettos')->select(DB::raw('SUM(prezzo) as costo'))->where('fk_id_progetto','=',$id)->get();
|
||||
}
|
||||
|
||||
public static function getRigaById($id)
|
||||
{
|
||||
return DB::table('riga_progettos')->where('id','=',$id)->get();
|
||||
}
|
||||
|
||||
public static function updateRiga($data)
|
||||
{
|
||||
DB::table('riga_progettos')->where('id','=',$data['idriga'])->update([
|
||||
'data'=>$data['data'],
|
||||
'descrizione'=>$data['descrizione'],
|
||||
'prezzo'=>$data['prezzo'],
|
||||
'ore'=>$data['ore'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
11
app/Models/Rivista.php
Normal file
11
app/Models/Rivista.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Rivista extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
||||
50
app/Models/Task.php
Normal file
50
app/Models/Task.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Task extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable=['titolo','descrizione','creato_da','assegnato_a','creato_il','termine_il','chiuso_il','stato'];
|
||||
|
||||
public function getAllTasks()
|
||||
{
|
||||
return self::all();
|
||||
}
|
||||
|
||||
//
|
||||
public static function getTaskAssignedToUser($userid)
|
||||
{
|
||||
return self::where('assegnato_a',$userid)->where('termine_il','>=', now())->get();
|
||||
}
|
||||
|
||||
//
|
||||
public static function getTaskAssignedByUser($userid)
|
||||
{
|
||||
return self::where('creato_da',$userid)->get();
|
||||
}
|
||||
|
||||
public static function saveTask($collection)
|
||||
{
|
||||
self::create(
|
||||
[
|
||||
'titolo' => $collection['titolo'],
|
||||
'descrizione'=>$collection['descrizione'],
|
||||
'creato_da'=>$collection['creato_da'],
|
||||
'assegnato_a'=>$collection['assegnato_a'],
|
||||
'creato_il'=>date('Y-m-d'),
|
||||
'termine_il'=>$collection['termine_il'],
|
||||
'stato'=>'Aperto',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function todolist() {
|
||||
return $this->belongsTo(Todolist::class);
|
||||
}
|
||||
|
||||
}
|
||||
19
app/Models/Todolist.php
Normal file
19
app/Models/Todolist.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Todolist extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public function user() {
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function tasks() {
|
||||
return $this->hasMany(Task::class);
|
||||
}
|
||||
}
|
||||
96
app/Models/User.php
Normal file
96
app/Models/User.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
use Illuminate\Foundation\Auth\Access\Authorizable;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable, HasRoles,Authorizable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
'user_role',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
protected $guard_name = 'web';
|
||||
|
||||
public function movimenti()
|
||||
{
|
||||
return $this->hasMany(Movimenti::class);
|
||||
}
|
||||
|
||||
public function getLdapDomainColumn()
|
||||
{
|
||||
return 'domain';
|
||||
}
|
||||
|
||||
public function getLdapGuidColumn()
|
||||
{
|
||||
return 'guid';
|
||||
}
|
||||
|
||||
public static function addGroup($gruppo)
|
||||
{
|
||||
$user= new User();
|
||||
$user->assignGroup($gruppo);
|
||||
}
|
||||
|
||||
public static function getUserById($id)
|
||||
{
|
||||
return DB::table('users')->where('id','=',$id)->first();
|
||||
}
|
||||
|
||||
public static function getUsers()
|
||||
{
|
||||
return DB::table('users')->orderBy('name')->get();
|
||||
}
|
||||
|
||||
// Aggiunge un utente e assegna un ruolo
|
||||
public static function addUser($params)
|
||||
{
|
||||
self::create([
|
||||
'name'=>$params['name'],
|
||||
'email'=>$params['email'],
|
||||
'password'=>Hash::make($params['password']),
|
||||
])->assignRole($params['role']);
|
||||
|
||||
}
|
||||
|
||||
public function todolists() {
|
||||
return $this->hasMany(Todolist::class);
|
||||
}
|
||||
}
|
||||
38
app/Models/anagrafica.php
Normal file
38
app/Models/anagrafica.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class anagrafica extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public static function inserisci($param) {
|
||||
DB::table('anagraficas')->insert([
|
||||
'ang_cognome'=>$param['ang_cognome'],
|
||||
'ang_nome'=>$param['ang_nome'],
|
||||
'ang_ragioneSociale'=>$param['ang_ragioneSociale'],
|
||||
'ang_codiceFiscale'=>$param['ang_codiceFiscale'],
|
||||
'ang_partitaIva'=>$param['ang_partitaIva'],
|
||||
'ang_indirizzo'=>$param['ang_indirizzo'],
|
||||
'ang_CAP'=>$param['ang_CAP'],
|
||||
'ang_Citta'=>$param['ang_Citta'],
|
||||
'ang_Provincia'=>$param['ang_Provincia'],
|
||||
'ang_telefono'=>$param['ang_telefono'],
|
||||
'ang_note'=>$param['ang_note'],
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getList() {
|
||||
$lista = DB::table('anagraficas')->OrderBy('ang_cognome')->get();
|
||||
return $lista;
|
||||
}
|
||||
|
||||
public static function getById($param) {
|
||||
|
||||
return DB::table('anagraficas')->where('id','=',$param)->get();
|
||||
}
|
||||
}
|
||||
14
app/Models/condominio.php
Normal file
14
app/Models/condominio.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class condominio extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
||||
}
|
||||
|
||||
27
app/Models/contatoreEnEl.php
Normal file
27
app/Models/contatoreEnEl.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class contatoreEnEl extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public static function inserisci($data) {
|
||||
DB::table('contatore_en_els')->insert([
|
||||
'enel_date'=> $data['enel_date'],
|
||||
'enel_A'=> $data['enel_A'],
|
||||
'enel_R'=> $data['enel_R'],
|
||||
'enel_F1'=> $data['enel_F1'],
|
||||
'enel_F2'=> $data['enel_F2'],
|
||||
'enel_F3'=> $data['enel_F3'],
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getList() {
|
||||
return DB::table('contatore_en_els')->orderBy('enel_date','desc')->get();
|
||||
}
|
||||
}
|
||||
24
app/Models/contatoreGas.php
Normal file
24
app/Models/contatoreGas.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class contatoreGas extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public static function getList()
|
||||
{
|
||||
return DB::table('contatore_gases')->orderBy('gas_date','asc')->get();
|
||||
}
|
||||
|
||||
public static function inserisci($data) {
|
||||
DB::table('contatore_gases')->insert([
|
||||
'gas_date'=> $data['gas_date'],
|
||||
'gas_lettura'=> $data['gas_lettura'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
34
app/Models/contatto.php
Normal file
34
app/Models/contatto.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class contatto extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
||||
|
||||
public static function listContactsById($id)
|
||||
{
|
||||
$type=[1=>'Telefono',2=>'Cellulare',3=>'Fax',4=>'Email','Website'];
|
||||
$lista=DB::table('contattos')->where('cnt_fk_anagraficaId','=',$id)->get();
|
||||
return ['tipo'=>$type,'contatti'=>$lista];
|
||||
}
|
||||
|
||||
public static function saveNewContact($param) {
|
||||
DB::table('contattos')->insert([
|
||||
'cnt_tipo'=>$param['cnt_tipo'],
|
||||
'cnt_valore'=>$param['cnt_valore'],
|
||||
'cnt_note'=>$param['cnt_note'],
|
||||
'cnt_fk_anagraficaId'=>$param['cnt_fk_anagraficaId'],
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
48
app/Models/tag.php
Normal file
48
app/Models/tag.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class tag extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public static function getList() {
|
||||
return DB::table('tags')->orderBy('tag_name')->get();
|
||||
}
|
||||
|
||||
public static function getApiList()
|
||||
{
|
||||
return self::orderBy('tag:name')->get();
|
||||
}
|
||||
|
||||
public static function inserisci($param) {
|
||||
DB::table('tags')->insert(['tag_name'=> $param['tag_name']]);
|
||||
}
|
||||
|
||||
public static function getById($param) {
|
||||
return DB::table('tags')
|
||||
->where('tags.id','=',$param)
|
||||
->get();
|
||||
|
||||
}
|
||||
|
||||
public static function updateById($param) {
|
||||
DB::table('tags')
|
||||
->where('id','=', $param['id'])
|
||||
->update([
|
||||
'tag_name' => $param['tag_name'],
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public static function deleteTag($id)
|
||||
{
|
||||
DB::table('tags')
|
||||
//->where('id','=',$id)
|
||||
->delete($id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user