Commit iniziale
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user