|
|
|
@ -2,9 +2,12 @@
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers; |
|
|
|
|
|
|
|
|
|
use App\Models\Company; |
|
|
|
|
use Illuminate\Http\Request; |
|
|
|
|
use App\Models\FolderDocumentProyek; |
|
|
|
|
use App\Models\DokumenProject; |
|
|
|
|
use App\Models\FolderDocumentProyek; |
|
|
|
|
use Illuminate\Support\Facades\DB; |
|
|
|
|
use Illuminate\Support\Facades\Log; |
|
|
|
|
|
|
|
|
|
class FolderDocumentProyekController extends Controller |
|
|
|
|
{ |
|
|
|
@ -44,23 +47,31 @@ class FolderDocumentProyekController extends Controller
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function delete($id) |
|
|
|
|
public function delete($id, $company_id) |
|
|
|
|
{ |
|
|
|
|
DB::beginTransaction(); |
|
|
|
|
$data = FolderDocumentProyek::find($id); |
|
|
|
|
|
|
|
|
|
if($data){ |
|
|
|
|
$delete = $data->delete(); |
|
|
|
|
}else{ |
|
|
|
|
return response()->json(['status'=>'failed','message'=>'data Folder Document Proyek not found!','code'=>400], 400); |
|
|
|
|
die(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($delete){ |
|
|
|
|
$company = Company::find($company_id); |
|
|
|
|
if($data && $company) { |
|
|
|
|
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); |
|
|
|
|
$dir = $destinationPath['pathDocument']; |
|
|
|
|
$dataFile = DokumenProject::where([['type_dokumen', 'project-document-in-folder'],['ref_id', $data['id']]])->orderByRaw('id ASC')->get(); |
|
|
|
|
if (is_dir($dir)) { |
|
|
|
|
foreach ($dataFile as $file) { |
|
|
|
|
unlink($dir.$file['file']); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if($data->delete()) { |
|
|
|
|
DB::commit(); |
|
|
|
|
return response()->json(['status'=>'success','message'=>'Folder Document Proyek successfully deleted!','code'=>200], 200); |
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
DB::rollBack(); |
|
|
|
|
return response()->json(['status'=>'failed','message'=>'Folder Document Proyek failed deleted!','code'=>400], 400); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
DB::rollBack(); |
|
|
|
|
return response()->json(['status'=>'failed','message'=>'Data Folder Document Proyek not found!','code'=>400], 400); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function search(Request $request) |
|
|
|
@ -85,6 +96,7 @@ class FolderDocumentProyekController extends Controller
|
|
|
|
|
return response()->json(['status'=>'failed','message'=>'failed get list tools request, please try again later!','code'=>400], 400); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function getTree($id) |
|
|
|
|
{ |
|
|
|
|
$data = FolderDocumentProyek::where('proyek_id', $id)->whereNull('parent_id')->orderByRaw('id ASC')->get(); |
|
|
|
@ -100,7 +112,7 @@ class FolderDocumentProyekController extends Controller
|
|
|
|
|
foreach($dataFile as $objRowFile) { |
|
|
|
|
$objRowFile->key = rand(1, 1000); |
|
|
|
|
$objRowFile->isDir = false; |
|
|
|
|
$objRowFile->proyek_id = $id; |
|
|
|
|
$objRowFile->proyek_id = (int)$id; |
|
|
|
|
$finalData[] = $objRowFile; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -122,7 +134,7 @@ class FolderDocumentProyekController extends Controller
|
|
|
|
|
foreach($dataFile as $objRowFile) { |
|
|
|
|
$objRowFile->key = rand(1, 1000); |
|
|
|
|
$objRowFile->isDir = false; |
|
|
|
|
$objRowFile->proyek_id = $proyek_id; |
|
|
|
|
$objRowFile->proyek_id = (int)$proyek_id; |
|
|
|
|
$finalData[] = $objRowFile; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|