Merge remote-tracking branch 'origin/staging' into origin/production
This commit is contained in:
@@ -133,12 +133,46 @@ class ClaimReportController extends Controller
|
||||
)
|
||||
->get();
|
||||
$results['request_files'] = $request_files;
|
||||
|
||||
// Jika path kosong, kembalikan null
|
||||
if (!$row->path) {
|
||||
return null;
|
||||
}
|
||||
// $documents = DB::table('files')
|
||||
// ->where('fileable_type', 'App\Models\ClaimRequest')
|
||||
// ->where('fileable_id', $claimRequestId)
|
||||
// ->select('original_name', \DB::raw("CONCAT('" . env('APP_URL') . "/storage/', path) as path"), 'type')
|
||||
// ->orderBy('id', 'desc')
|
||||
// ->get();
|
||||
|
||||
$documents = DB::table('files')
|
||||
->where('fileable_type', 'App\Models\ClaimRequest')
|
||||
->where('fileable_id', $claimRequestId)
|
||||
->select('original_name', \DB::raw("CONCAT('" . env('APP_URL') . "/storage/', path) as path"), 'type')
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
->where('fileable_type', 'App\Models\ClaimRequest')
|
||||
->where('fileable_id', $claimRequestId)
|
||||
->select('id', 'original_name', 'path', 'source', 'type')
|
||||
->orderBy('id', 'desc')
|
||||
->get()
|
||||
->map(function ($row) {
|
||||
// default null kalau tidak ada path
|
||||
if (!$row->path) {
|
||||
$row->path = null; // atau bisa $row->url = null
|
||||
return $row;
|
||||
}
|
||||
|
||||
if ($row->source === 's3') {
|
||||
try {
|
||||
$row->path = Storage::disk('s3')->temporaryUrl(
|
||||
$row->path,
|
||||
now()->addMinutes(60)
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$row->path = Storage::disk('s3')->url($row->path);
|
||||
}
|
||||
} else {
|
||||
$row->path = Storage::disk('public')->url($row->path);
|
||||
}
|
||||
|
||||
return $row;
|
||||
});
|
||||
$results['documents'] = $documents;
|
||||
|
||||
return Helper::responseJson($results);
|
||||
@@ -149,15 +183,16 @@ class ClaimReportController extends Controller
|
||||
$claim_id = Crypt::decrypt($claim_id);
|
||||
if ($request->hasFile('fileDiagnosis')) {
|
||||
foreach ($request->fileDiagnosis as $file) {
|
||||
$pathFile = File::storeFile('claim-diagnosis', $claim_id, $file);
|
||||
$fileData = File::storeFile('claim-diagnosis', $claim_id, $file);
|
||||
File::updateOrCreate([
|
||||
'fileable_type'=>'App\Models\ClaimRequest',
|
||||
'fileable_id' => $claim_id,
|
||||
'type' => 'claim-diagnosis',
|
||||
'name' => File::getFileName('claim-diagnosis', $claim_id, $file),
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'path' => $pathFile,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
@@ -166,15 +201,16 @@ class ClaimReportController extends Controller
|
||||
|
||||
if ($request->hasFile('fileKondisis')) {
|
||||
foreach ($request->fileKondisis as $file) {
|
||||
$pathFile = File::storeFile('claim-kondisi', $claim_id, $file);
|
||||
$fileData = File::storeFile('claim-kondisi', $claim_id, $file);
|
||||
File::updateOrCreate([
|
||||
'fileable_type'=>'App\Models\ClaimRequest',
|
||||
'fileable_id' => $claim_id,
|
||||
'type' => 'claim-kondisi',
|
||||
'name' => File::getFileName('claim-kondisi', $claim_id, $file),
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'path' => $pathFile,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
@@ -188,10 +224,11 @@ class ClaimReportController extends Controller
|
||||
'fileable_type'=>'App\Models\ClaimRequest',
|
||||
'fileable_id' => $claim_id,
|
||||
'type' => 'claim-result',
|
||||
'name' => File::getFileName('claim-result', $claim_id, $file),
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'path' => $pathFile,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
@@ -109,6 +109,7 @@ class ClaimRequestController extends Controller
|
||||
'name' => $new_file_name,
|
||||
'original_name' => $full_path,
|
||||
'extension' => $ekstension,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $pathFile,
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
@@ -134,6 +135,7 @@ class ClaimRequestController extends Controller
|
||||
'name' => $new_file_name,
|
||||
'original_name' => $full_path,
|
||||
'extension' => $ekstension,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $pathFile,
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
@@ -159,6 +161,7 @@ class ClaimRequestController extends Controller
|
||||
'name' => $new_file_name,
|
||||
'original_name' => $full_path,
|
||||
'extension' => $ekstension,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $pathFile,
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
|
||||
@@ -70,6 +70,7 @@ class CorporateCurrentController extends Controller
|
||||
'type' => 'avatar',
|
||||
'name' => File::getFileName('avatar', $corporate->id, $request->file('logo')),
|
||||
'extension' => $request->file('logo')->getClientOriginalExtension(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $pathFileAvatar,
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
|
||||
@@ -5,6 +5,7 @@ use App\Helpers\Helper;
|
||||
use App\Models\DailyMonitoring;
|
||||
use App\Models\RequestDailyMonitoring;
|
||||
use App\Models\MedicalPlan;
|
||||
use App\Models\File;
|
||||
use DB;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -12,7 +13,6 @@ use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\File as Files;
|
||||
use Modules\Internal\Transformers\DailyMonitoringResource;
|
||||
use App\Models\File;
|
||||
use Carbon\Carbon;
|
||||
|
||||
|
||||
@@ -281,19 +281,18 @@ class DailyMonitoringController extends Controller
|
||||
// }
|
||||
// }
|
||||
foreach ($request->confirmation_medical_leter as $file) {
|
||||
$name = 'labresult-' . uniqid();
|
||||
$extension= $file->getClientOriginalExtension();
|
||||
$fileName = $name . '.' . $extension;
|
||||
$orignalName = $file->getClientOriginalName();
|
||||
$path = $file->storeAs($this->path_for_store, $fileName);
|
||||
$fileData = File::storeFile('confirmation-medical-letter', $request->id, $file);
|
||||
File::create([
|
||||
'fileable_type' => 'App\Models\LaboratoriumResult',
|
||||
'fileable_id' => $request->id,
|
||||
'type' => 'confirmation-medical-letter',
|
||||
'name' => $name,
|
||||
'original_name' => $orignalName,
|
||||
'extension' => $extension,
|
||||
'path' => $path,
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
}
|
||||
@@ -312,19 +311,18 @@ class DailyMonitoringController extends Controller
|
||||
// }
|
||||
// }
|
||||
foreach ($request->medical_action_letter as $file) {
|
||||
$name = 'labresult-' . uniqid();
|
||||
$extension= $file->getClientOriginalExtension();
|
||||
$fileName = $name . '.' . $extension;
|
||||
$orignalName = $file->getClientOriginalName();
|
||||
$path = $file->storeAs($this->path_for_store, $fileName);
|
||||
$fileData = File::storeFile('medical-action-letter', $request->id, $file);
|
||||
File::create([
|
||||
'fileable_type' => 'App\Models\LaboratoriumResult',
|
||||
'fileable_id' => $request->id,
|
||||
'type' => 'medical-action-letter',
|
||||
'name' => $name,
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $orignalName,
|
||||
'extension' => $extension,
|
||||
'path' => $path,
|
||||
'extension' => $file->getClientOriginalName(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
// $file->storeAs($this->path_for_store, $fileName);
|
||||
}
|
||||
@@ -343,19 +341,18 @@ class DailyMonitoringController extends Controller
|
||||
// }
|
||||
// }
|
||||
foreach ($request->result as $file) {
|
||||
$name = 'labresult-' . uniqid();
|
||||
$extension= $file->getClientOriginalExtension();
|
||||
$orignalName = $file->getClientOriginalName();
|
||||
$fileName = $name . '.' . $extension;
|
||||
$path = $file->storeAs($this->path_for_store, $fileName);
|
||||
$fileData = File::storeFile('laboratorium-result', $request->id, $file);
|
||||
File::create([
|
||||
'fileable_type' => 'App\Models\LaboratoriumResult',
|
||||
'fileable_id' => $request->id,
|
||||
'type' => 'laboratorium-result',
|
||||
'name' => $name,
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $orignalName,
|
||||
'extension' => $extension,
|
||||
'path' => $path,
|
||||
'extension' => $file->getClientOriginalName(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
// $file->storeAs($this->path_for_store, $fileName);
|
||||
@@ -577,38 +574,36 @@ class DailyMonitoringController extends Controller
|
||||
// insert file result
|
||||
if ($request->confirmation_medical_leter){
|
||||
foreach ($request->confirmation_medical_leter as $file) {
|
||||
$name = 'labresult-' . uniqid();
|
||||
$extension= $file->getClientOriginalExtension();
|
||||
$fileName = $name . '.' . $extension;
|
||||
$orignalName = $file->getClientOriginalName();
|
||||
$path = $file->storeAs($this->path_for_store, $fileName);
|
||||
$fileData = File::storeFile('confirmation-medical-letter', $db_response->id, $file);
|
||||
File::create([
|
||||
'fileable_type' => 'App\Models\LaboratoriumResult',
|
||||
'fileable_id' => $db_response->id,
|
||||
'type' => 'confirmation-medical-letter',
|
||||
'name' => $name,
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $orignalName,
|
||||
'extension' => $extension,
|
||||
'path' => $path,
|
||||
'extension' => $file->getClientOriginalName(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
if ($request->medical_action_letter){
|
||||
foreach ($request->medical_action_letter as $file) {
|
||||
$name = 'labresult-' . uniqid();
|
||||
$extension= $file->getClientOriginalExtension();
|
||||
$fileName = $name . '.' . $extension;
|
||||
$orignalName = $file->getClientOriginalName();
|
||||
$path = $file->storeAs($this->path_for_store, $fileName);
|
||||
$fileData = File::storeFile('medical-action-letter', $db_response->id, $file);
|
||||
File::create([
|
||||
'fileable_type' => 'App\Models\LaboratoriumResult',
|
||||
'fileable_id' => $db_response->id,
|
||||
'type' => 'medical-action-letter',
|
||||
'name' => $name,
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $orignalName,
|
||||
'extension' => $extension,
|
||||
'path' => $path,
|
||||
'extension' => $file->getClientOriginalName(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
// $file->storeAs($this->path_for_store, $fileName);
|
||||
@@ -616,19 +611,18 @@ class DailyMonitoringController extends Controller
|
||||
}
|
||||
if ($request->result){
|
||||
foreach ($request->result as $file) {
|
||||
$name = 'labresult-' . uniqid();
|
||||
$extension= $file->getClientOriginalExtension();
|
||||
$orignalName = $file->getClientOriginalName();
|
||||
$fileName = $name . '.' . $extension;
|
||||
$path = $file->storeAs($this->path_for_store, $fileName);
|
||||
$fileData = File::storeFile('laboratorium-result', $db_response->id, $file);
|
||||
File::create([
|
||||
'fileable_type' => 'App\Models\LaboratoriumResult',
|
||||
'fileable_id' => $db_response->id,
|
||||
'type' => 'laboratorium-result',
|
||||
'name' => $name,
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $orignalName,
|
||||
'extension' => $extension,
|
||||
'path' => $path,
|
||||
'extension' => $file->getClientOriginalName(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
// $file->storeAs($this->path_for_store, $fileName);
|
||||
@@ -752,38 +746,36 @@ class DailyMonitoringController extends Controller
|
||||
// insert file result
|
||||
if ($request->confirmation_medical_leter){
|
||||
foreach ($request->confirmation_medical_leter as $file) {
|
||||
$name = 'labresult-' . uniqid();
|
||||
$extension= $file->getClientOriginalExtension();
|
||||
$fileName = $name . '.' . $extension;
|
||||
$orignalName = $file->getClientOriginalName();
|
||||
$path = $file->storeAs($this->path_for_store, $fileName);
|
||||
$fileData = File::storeFile('confirmation-medical-letter', $db_response->id, $file);
|
||||
File::create([
|
||||
'fileable_type' => 'App\Models\LaboratoriumResult',
|
||||
'fileable_id' => $db_response->id,
|
||||
'type' => 'confirmation-medical-letter',
|
||||
'name' => $name,
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $orignalName,
|
||||
'extension' => $extension,
|
||||
'path' => $path,
|
||||
'extension' => $file->getClientOriginalName(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
if ($request->medical_action_letter){
|
||||
foreach ($request->medical_action_letter as $file) {
|
||||
$name = 'labresult-' . uniqid();
|
||||
$extension= $file->getClientOriginalExtension();
|
||||
$fileName = $name . '.' . $extension;
|
||||
$orignalName = $file->getClientOriginalName();
|
||||
$path = $file->storeAs($this->path_for_store, $fileName);
|
||||
$fileData = File::storeFile('medical-action-letter', $db_response->id, $file);
|
||||
File::create([
|
||||
'fileable_type' => 'App\Models\LaboratoriumResult',
|
||||
'fileable_id' => $db_response->id,
|
||||
'type' => 'medical-action-letter',
|
||||
'name' => $name,
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $orignalName,
|
||||
'extension' => $extension,
|
||||
'path' => $path,
|
||||
'extension' => $file->getClientOriginalName(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
// $file->storeAs($this->path_for_store, $fileName);
|
||||
@@ -791,19 +783,19 @@ class DailyMonitoringController extends Controller
|
||||
}
|
||||
if ($request->result){
|
||||
foreach ($request->result as $file) {
|
||||
$name = 'labresult-' . uniqid();
|
||||
$extension= $file->getClientOriginalExtension();
|
||||
$orignalName = $file->getClientOriginalName();
|
||||
$fileName = $name . '.' . $extension;
|
||||
$path = $file->storeAs($this->path_for_store, $fileName);
|
||||
$fileData = File::storeFile('laboratorium-result', $db_response->id, $file);
|
||||
File::create([
|
||||
'fileable_type' => 'App\Models\LaboratoriumResult',
|
||||
'fileable_id' => $db_response->id,
|
||||
'type' => 'laboratorium-result',
|
||||
'name' => $name,
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $orignalName,
|
||||
'extension' => $extension,
|
||||
'path' => $path,
|
||||
'extension' => $file->getClientOriginalName(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
|
||||
]);
|
||||
|
||||
// $file->storeAs($this->path_for_store, $fileName);
|
||||
|
||||
@@ -130,8 +130,27 @@ class DataServiceMonitoring extends JsonResource
|
||||
->get();
|
||||
if ($document){
|
||||
foreach($document as $d){
|
||||
// Jika path kosong, kembalikan null
|
||||
if (!$row->path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Cek nilai 'source'. Jika 's3', gunakan disk S3.
|
||||
// Selain itu (termasuk null atau 'local'), gunakan disk 'public'.
|
||||
if ($row->source === 's3') {
|
||||
try {
|
||||
$path = Storage::disk('s3')->temporaryUrl(
|
||||
$row->path,
|
||||
now()->addMinutes(60) // expired 1 jam
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$path = Storage::disk('s3')->url($row->path); // fallback kalau public
|
||||
}
|
||||
} else {
|
||||
$path = Storage::disk('public')->url($row->path);
|
||||
}
|
||||
$arr_document[]= [
|
||||
'path' => env('APP_URL') . '/storage/lab_result/' . $d->name . '.' . $d->extension,
|
||||
'path' => $path,
|
||||
'type' => $d->type,
|
||||
'original_name' => $d->original_name,
|
||||
'name' => $d->name,
|
||||
@@ -194,8 +213,28 @@ class DataServiceMonitoring extends JsonResource
|
||||
->get();
|
||||
if ($document){
|
||||
foreach($document as $d){
|
||||
// Jika path kosong, kembalikan null
|
||||
if (!$row->path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Cek nilai 'source'. Jika 's3', gunakan disk S3.
|
||||
// Selain itu (termasuk null atau 'local'), gunakan disk 'public'.
|
||||
if ($row->source === 's3') {
|
||||
try {
|
||||
$path = Storage::disk('s3')->temporaryUrl(
|
||||
$row->path,
|
||||
now()->addMinutes(60) // expired 1 jam
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$path = Storage::disk('s3')->url($row->path); // fallback kalau public
|
||||
}
|
||||
} else {
|
||||
$path = Storage::disk('public')->url($row->path);
|
||||
}
|
||||
|
||||
$arr_document[]= [
|
||||
'path' => env('APP_URL') . '/storage/lab_result/' . $d->name . '.' . $d->extension,
|
||||
'path' => $path,
|
||||
'type' => $d->type,
|
||||
'original_name' => $d->original_name,
|
||||
'name' => $d->name,
|
||||
|
||||
@@ -133,7 +133,7 @@ class ClaimRequestController extends Controller
|
||||
|
||||
if ($request->hasFile('additional_files')) {
|
||||
foreach ($request->additional_files as $file) {
|
||||
$pathFile = File::storeFile('additional-files', $request->request_logs_id, $file);
|
||||
$fileData = File::storeFile('additional-files', $request->request_logs_id, $file);
|
||||
// $newClaimRequest->files()->updateOrCreate([
|
||||
// 'type' => 'additional-files',
|
||||
// 'name' => File::getFileName('additional-files', $newClaimRequest->id, $file),
|
||||
@@ -147,10 +147,11 @@ class ClaimRequestController extends Controller
|
||||
'fileable_type' => 'App\Models\RequestLog',
|
||||
'fileable_id' => $request->request_logs_id,
|
||||
'type' => 'additional-files',
|
||||
'name' => File::getFileName('additional-files', $request->request_logs_id, $file),
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'path' => $pathFile,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
@@ -444,15 +445,16 @@ class ClaimRequestController extends Controller
|
||||
|
||||
if ($request->hasFile('fileDiagnosis')) {
|
||||
foreach ($request->fileDiagnosis as $file) {
|
||||
$pathFile = File::storeFile('claim-diagnosis', $claim_id, $file);
|
||||
$fileData = File::storeFile('claim-diagnosis', $claim_id, $file);
|
||||
File::updateOrCreate([
|
||||
'fileable_type'=>'App\Models\ClaimRequest',
|
||||
'fileable_id' => $claim_id,
|
||||
'type' => 'claim-diagnosis',
|
||||
'name' => File::getFileName('claim-diagnosis', $claim_id, $file),
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'path' => $pathFile,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
@@ -461,12 +463,12 @@ class ClaimRequestController extends Controller
|
||||
|
||||
if ($request->hasFile('fileKondisis')) {
|
||||
foreach ($request->fileKondisis as $file) {
|
||||
$pathFile = File::storeFile('claim-kondisi', $claim_id, $file);
|
||||
$fileData = File::storeFile('claim-kondisi', $claim_id, $file);
|
||||
File::updateOrCreate([
|
||||
'fileable_type'=>'App\Models\ClaimRequest',
|
||||
'fileable_id' => $claim_id,
|
||||
'type' => 'claim-kondisi',
|
||||
'name' => File::getFileName('claim-kondisi', $claim_id, $file),
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'path' => $pathFile,
|
||||
@@ -478,15 +480,16 @@ class ClaimRequestController extends Controller
|
||||
|
||||
if ($request->hasFile('fileResults')) {
|
||||
foreach ($request->fileResults as $file) {
|
||||
$pathFile = File::storeFile('claim-result', $claim_id, $file);
|
||||
$fileData = File::storeFile('claim-result', $claim_id, $file);
|
||||
File::updateOrCreate([
|
||||
'fileable_type'=>'App\Models\ClaimRequest',
|
||||
'fileable_id' => $claim_id,
|
||||
'type' => 'claim-result',
|
||||
'name' => File::getFileName('claim-result', $claim_id, $file),
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'path' => $pathFile,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
@@ -378,15 +378,16 @@ class RequestLogController extends Controller
|
||||
]);
|
||||
if ($request->hasFile('result_files')) {
|
||||
foreach ($request->result_files as $file) {
|
||||
$pathFile = File::storeFile('final-log-result', $request->request_logs_id, $file);
|
||||
$fileData = File::storeFile('final-log-result', $request->request_logs_id, $file);
|
||||
File::updateOrCreate([
|
||||
'fileable_type' => 'App\Models\RequestLog',
|
||||
'fileable_id' => $request->request_logs_id,
|
||||
'type' => 'final-log-result',
|
||||
'name' => File::getFileName('final-log-result', $request->request_logs_id, $file),
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'path' => $pathFile,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
@@ -394,15 +395,16 @@ class RequestLogController extends Controller
|
||||
}
|
||||
if ($request->hasFile('diagnosa_files')) {
|
||||
foreach ($request->diagnosa_files as $file) {
|
||||
$pathFile = File::storeFile('final-log-diagnosis', $request->request_logs_id, $file);
|
||||
$fileData = File::storeFile('final-log-diagnosis', $request->request_logs_id, $file);
|
||||
File::updateOrCreate([
|
||||
'fileable_type' => 'App\Models\RequestLog',
|
||||
'fileable_id' => $request->request_logs_id,
|
||||
'type' => 'final-log-diagnosis',
|
||||
'name' => File::getFileName('final-log-diagnosis', $request->request_logs_id, $file),
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'path' => $pathFile,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
@@ -410,7 +412,7 @@ class RequestLogController extends Controller
|
||||
}
|
||||
if ($request->hasFile('kondisi_files')) {
|
||||
foreach ($request->kondisi_files as $file) {
|
||||
$pathFile = File::storeFile('final-log-kondisi', $request->request_logs_id, $file);
|
||||
$fileData = File::storeFile('final-log-kondisi', $request->request_logs_id, $file);
|
||||
File::updateOrCreate([
|
||||
'fileable_type' => 'App\Models\RequestLog',
|
||||
'fileable_id' => $request->request_logs_id,
|
||||
@@ -418,7 +420,8 @@ class RequestLogController extends Controller
|
||||
'name' => File::getFileName('final-log-kondisi', $request->request_logs_id, $file),
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'path' => $pathFile,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
@@ -195,7 +195,10 @@ class ClaimController extends Controller
|
||||
$limit = $request->has('per_page') ? $request->input('per_page') : 50;
|
||||
$results = DB::table('request_logs')
|
||||
->leftJoin('members', 'request_logs.member_id', '=', 'members.id')
|
||||
->join('files', 'request_logs.id', '=', 'files.fileable_id')
|
||||
->join('files', function ($join) {
|
||||
$join->on('request_logs.id', '=', 'files.fileable_id')
|
||||
->whereNull('files.deleted_at');
|
||||
})
|
||||
// ->leftJoin('member_plans', 'member_plans.member_id', '=', 'members.id')
|
||||
->when($request->input('search'), function ($query, $search) {
|
||||
$query->where(function ($query) use ($search) {
|
||||
@@ -239,46 +242,82 @@ class ClaimController extends Controller
|
||||
(SELECT organizations.name FROM organizations WHERE organizations.id = request_logs.organization_id LIMIT 1) AS provider
|
||||
'),
|
||||
'request_logs.status_final_log as status',
|
||||
DB::raw("CONCAT('" . env('APP_URL') . "/storage/', path) as path")
|
||||
'files.path',
|
||||
'files.source'
|
||||
)
|
||||
->paginate($limit);
|
||||
|
||||
$results->getCollection()->transform(function ($row) {
|
||||
if (!$row->path) {
|
||||
$row->path = null;
|
||||
return $row;
|
||||
}
|
||||
|
||||
if ($row->source === 's3') {
|
||||
try {
|
||||
$row->path = Storage::disk('s3')->temporaryUrl(
|
||||
$row->path,
|
||||
now()->addMinutes(60)
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$row->path = Storage::disk('s3')->url($row->path);
|
||||
}
|
||||
} else {
|
||||
$row->path = Storage::disk('public')->url($row->path);
|
||||
}
|
||||
|
||||
return $row;
|
||||
});
|
||||
|
||||
return response()->json(Helper::paginateResources($results));
|
||||
}
|
||||
|
||||
public function downloadZip(Request $request)
|
||||
{
|
||||
$selectedRows = $request->selectedRows; // asumsi $selectedRows berisi array ID file yang dipilih
|
||||
$files = [];
|
||||
$selectedRows = $request->selectedRows; // array ID file
|
||||
$files = [];
|
||||
|
||||
// Ambil path file dari database atau sumber lain sesuai dengan $selectedRows
|
||||
$data = DB::table('files')
|
||||
->whereIn('id', $selectedRows)
|
||||
->select('path')
|
||||
->get();
|
||||
// Ambil path dan source
|
||||
$data = DB::table('files')
|
||||
->whereIn('id', $selectedRows)
|
||||
->select('path', 'source', 'original_name')
|
||||
->get();
|
||||
|
||||
foreach ($data as $value) {
|
||||
$files[] = storage_path('app/public/' . $value->path);
|
||||
}
|
||||
$zipFileName = 'downloaded_files_' . time() . '.zip';
|
||||
$zipPath = storage_path('app/public/' . $zipFileName);
|
||||
|
||||
$zipFileName = 'downloaded_files.zip';
|
||||
$zip = new ZipArchive();
|
||||
$zip = new ZipArchive();
|
||||
if ($zip->open($zipPath, ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
|
||||
foreach ($data as $value) {
|
||||
$localPath = null;
|
||||
|
||||
if ($zip->open(storage_path('app/public/' . $zipFileName), ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
|
||||
foreach ($files as $file) {
|
||||
$zip->addFile($file, basename($file));
|
||||
if ($value->source === 's3') {
|
||||
// download file dari S3 ke temporary file
|
||||
$tmpFile = tempnam(sys_get_temp_dir(), 's3file_');
|
||||
$stream = Storage::disk('s3')->get($value->path);
|
||||
file_put_contents($tmpFile, $stream);
|
||||
$localPath = $tmpFile;
|
||||
} else {
|
||||
// ambil file dari local storage
|
||||
$localPath = storage_path('app/public/' . $value->path);
|
||||
}
|
||||
|
||||
if ($localPath && file_exists($localPath)) {
|
||||
$zip->addFile($localPath, $value->original_name ?? basename($value->path));
|
||||
}
|
||||
}
|
||||
|
||||
$zip->close();
|
||||
|
||||
// return URL ke file zip
|
||||
return response()->json([
|
||||
'file_url' => env('APP_URL') . Storage::url($zipFileName)
|
||||
], 200);
|
||||
}
|
||||
|
||||
$zip->close();
|
||||
|
||||
// Mengembalikan response berupa URL file zip
|
||||
return response()->json(['file_url' => env('APP_URL').Storage::url($zipFileName)], 200);
|
||||
} else {
|
||||
return response()->json(['message' => 'Gagal membuat file ZIP.'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function downloadTemplate()
|
||||
{
|
||||
@@ -1295,9 +1334,31 @@ class ClaimController extends Controller
|
||||
$documents = DB::table('files')
|
||||
->where('fileable_type', 'App\Models\ClaimRequest')
|
||||
->where('fileable_id', $claim_id)
|
||||
->select('original_name', \DB::raw("CONCAT('" . env('APP_URL') . "/storage/', path) as path"), 'type')
|
||||
->select('id', 'original_name', 'path', 'source', 'type')
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
->get()
|
||||
->map(function ($row) {
|
||||
if (!$row->path) {
|
||||
$row->path = null;
|
||||
return $row;
|
||||
}
|
||||
|
||||
if ($row->source === 's3') {
|
||||
try {
|
||||
$row->path = Storage::disk('s3')->temporaryUrl(
|
||||
$row->path,
|
||||
now()->addMinutes(60)
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$row->path = Storage::disk('s3')->url($row->path);
|
||||
}
|
||||
} else {
|
||||
$row->path = Storage::disk('public')->url($row->path);
|
||||
}
|
||||
|
||||
return $row;
|
||||
});
|
||||
|
||||
$results['documents'] = $documents;
|
||||
|
||||
$request_documents = DB::table('claim_request_files')
|
||||
|
||||
@@ -162,6 +162,7 @@ class ClaimRequestController extends Controller
|
||||
'name' => $new_file_name,
|
||||
'original_name' => $full_path,
|
||||
'extension' => $ekstension,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $pathFile,
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
@@ -187,6 +188,7 @@ class ClaimRequestController extends Controller
|
||||
'name' => $new_file_name,
|
||||
'original_name' => $full_path,
|
||||
'extension' => $ekstension,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $pathFile,
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
@@ -212,6 +214,7 @@ class ClaimRequestController extends Controller
|
||||
'name' => $new_file_name,
|
||||
'original_name' => $full_path,
|
||||
'extension' => $ekstension,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $pathFile,
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
@@ -303,6 +306,7 @@ class ClaimRequestController extends Controller
|
||||
'name' => File::getFileName('claim-result', $id, $file),
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $pathFile,
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
@@ -318,6 +322,7 @@ class ClaimRequestController extends Controller
|
||||
'name' => File::getFileName('claim-diagnosis', $id, $file),
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $pathFile,
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
@@ -333,6 +338,7 @@ class ClaimRequestController extends Controller
|
||||
'name' => File::getFileName('claim-kondisi', $id, $file),
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $pathFile,
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
@@ -553,15 +559,16 @@ class ClaimRequestController extends Controller
|
||||
{
|
||||
if ($request->hasFile('invoice_files')) {
|
||||
foreach ($request->invoice_files as $file) {
|
||||
$pathFile = File::storeFile('claim-invoice', $claim_id, $file);
|
||||
$fileData = File::storeFile('claim-invoice', $claim_id, $file);
|
||||
File::updateOrCreate([
|
||||
'fileable_type'=>'App\Models\ClaimRequest',
|
||||
'fileable_id' => $claim_id,
|
||||
'type' => 'claim-invoice',
|
||||
'name' => File::getFileName('claim-invoice', $claim_id, $file),
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'path' => $pathFile,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
@@ -674,15 +681,16 @@ class ClaimRequestController extends Controller
|
||||
|
||||
if ($request->hasFile('fileDiagnosis')) {
|
||||
foreach ($request->fileDiagnosis as $file) {
|
||||
$pathFile = File::storeFile('claim-diagnosis', $claim_id, $file);
|
||||
$fileData = File::storeFile('claim-diagnosis', $claim_id, $file);
|
||||
File::updateOrCreate([
|
||||
'fileable_type'=>'App\Models\ClaimRequest',
|
||||
'fileable_id' => $claim_id,
|
||||
'type' => 'claim-diagnosis',
|
||||
'name' => File::getFileName('claim-diagnosis', $claim_id, $file),
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'path' => $pathFile,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
@@ -691,15 +699,16 @@ class ClaimRequestController extends Controller
|
||||
|
||||
if ($request->hasFile('fileKondisis')) {
|
||||
foreach ($request->fileKondisis as $file) {
|
||||
$pathFile = File::storeFile('claim-kondisi', $claim_id, $file);
|
||||
$fileData = File::storeFile('claim-kondisi', $claim_id, $file);
|
||||
File::updateOrCreate([
|
||||
'fileable_type'=>'App\Models\ClaimRequest',
|
||||
'fileable_id' => $claim_id,
|
||||
'type' => 'claim-kondisi',
|
||||
'name' => File::getFileName('claim-kondisi', $claim_id, $file),
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'path' => $pathFile,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
@@ -708,15 +717,16 @@ class ClaimRequestController extends Controller
|
||||
|
||||
if ($request->hasFile('fileResults')) {
|
||||
foreach ($request->fileResults as $file) {
|
||||
$pathFile = File::storeFile('claim-result', $claim_id, $file);
|
||||
$fileData = File::storeFile('claim-result', $claim_id, $file);
|
||||
File::updateOrCreate([
|
||||
'fileable_type'=>'App\Models\ClaimRequest',
|
||||
'fileable_id' => $claim_id,
|
||||
'type' => 'claim-result',
|
||||
'name' => File::getFileName('claim-result', $claim_id, $file),
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'path' => $pathFile,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
@@ -239,6 +239,7 @@ class CorporateController extends Controller
|
||||
'type' => 'avatar',
|
||||
'name' => File::getFileName('avatar', $newCorporate->id, $request->file('logo')),
|
||||
'extension' => $request->file('logo')->getClientOriginalExtension(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $pathFileAvatar,
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
@@ -353,6 +354,7 @@ class CorporateController extends Controller
|
||||
'type' => 'avatar',
|
||||
'name' => File::getFileName('avatar', $corporate->id, $request->file('logo')),
|
||||
'extension' => $request->file('logo')->getClientOriginalExtension(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $pathFileAvatar,
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
@@ -405,10 +407,13 @@ class CorporateController extends Controller
|
||||
'file' => 'required|file|mimes:xls,xlsx,csv,txt',
|
||||
]);
|
||||
$file_name = now()->getPreciseTimestamp(3) . '-' . $request->file('file')->getClientOriginalName();
|
||||
$file = $request->file('file')->storeAs('temp', $file_name);
|
||||
|
||||
// 🚀 Paksa simpan ke local/public
|
||||
$file = $request->file('file')->storeAs('temp', $file_name, 'public');
|
||||
$corporate = Corporate::with(['plans'])->findOrFail($corporate_id);
|
||||
$fileWrite = Storage::disk('public')->path('temp/result-' . $file_name);
|
||||
$fileRead = Storage::path('temp/' . $file_name);
|
||||
$fileRead = Storage::disk('public')->path('temp/' . $file_name);
|
||||
|
||||
$import = new ImportService();
|
||||
$import->read($fileRead);
|
||||
$import->write($fileWrite, 'xsls');
|
||||
|
||||
@@ -210,7 +210,7 @@ class CorporateFormulariumController extends Controller
|
||||
]);
|
||||
// dd($request->toArray());
|
||||
$file_name = now()->getPreciseTimestamp(3).'-'.$request->file('file')->getClientOriginalName();
|
||||
$file = $request->file('file')->storeAs('temp', $file_name);
|
||||
$file = $request->file('file')->storeAs('temp', $file_name, 'public'); // 🚀 Paksa simpan ke local/public
|
||||
|
||||
// $importLog = $corporate->importLogs()->create([
|
||||
// 'type' => 'diagnosis-exclusions',
|
||||
@@ -220,7 +220,7 @@ class CorporateFormulariumController extends Controller
|
||||
// ]);
|
||||
|
||||
$import = new ImportService();
|
||||
$import->read(Storage::path('temp/'.$file_name));
|
||||
$import->read(Storage::disk('public')->path('temp/'.$file_name));
|
||||
$import->write(Storage::disk('public')->path('temp/result-'.$file_name), 'xsls');
|
||||
foreach ($import->sheetsIterator() as $sheetIndex => $sheet) {
|
||||
$doc_headers_indexes = [];
|
||||
|
||||
@@ -192,10 +192,10 @@ class CorporateMemberController extends Controller
|
||||
$corporate = Corporate::findOrFail($corporate_id)->load('currentPolicy');
|
||||
|
||||
$file_name = now()->getPreciseTimestamp(3) . '-' . $request->file('file')->getClientOriginalName();
|
||||
$file = $request->file('file')->storeAs('temp', $file_name);
|
||||
$file = $request->file('file')->storeAs('temp', $file_name, 'public');
|
||||
|
||||
$reader = ReaderEntityFactory::createXLSXReader(Storage::path('temp/' . $file_name));
|
||||
$reader->open(Storage::path('temp/' . $file_name));
|
||||
$reader->open(Storage::disk('public')->path('temp/' . $file_name));
|
||||
|
||||
$writer = WriterEntityFactory::createXLSXWriter();
|
||||
$writer->openToFile(Storage::disk('public')->path('temp/result-' . $file_name));
|
||||
|
||||
@@ -280,19 +280,18 @@ class DailyMonitoringController extends Controller
|
||||
// }
|
||||
// }
|
||||
foreach ($request->confirmation_medical_leter as $file) {
|
||||
$name = 'labresult-' . uniqid();
|
||||
$extension= $file->getClientOriginalExtension();
|
||||
$fileName = $name . '.' . $extension;
|
||||
$orignalName = $file->getClientOriginalName();
|
||||
$path = $file->storeAs($this->path_for_store, $fileName);
|
||||
$fileData = File::storeFile('confirmation-medical-letter', $request->id, $file);
|
||||
File::create([
|
||||
'fileable_type' => 'App\Models\LaboratoriumResult',
|
||||
'fileable_id' => $request->id,
|
||||
'type' => 'confirmation-medical-letter',
|
||||
'name' => $name,
|
||||
'original_name' => $orignalName,
|
||||
'extension' => $extension,
|
||||
'path' => $path,
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
}
|
||||
@@ -311,19 +310,18 @@ class DailyMonitoringController extends Controller
|
||||
// }
|
||||
// }
|
||||
foreach ($request->medical_action_letter as $file) {
|
||||
$name = 'labresult-' . uniqid();
|
||||
$extension= $file->getClientOriginalExtension();
|
||||
$fileName = $name . '.' . $extension;
|
||||
$orignalName = $file->getClientOriginalName();
|
||||
$path = $file->storeAs($this->path_for_store, $fileName);
|
||||
$fileData = File::storeFile('confirmation-medical-letter', $db_response->id, $file);
|
||||
File::create([
|
||||
'fileable_type' => 'App\Models\LaboratoriumResult',
|
||||
'fileable_id' => $request->id,
|
||||
'type' => 'medical-action-letter',
|
||||
'name' => $name,
|
||||
'original_name' => $orignalName,
|
||||
'extension' => $extension,
|
||||
'path' => $path,
|
||||
'type' => 'confirmation-medical-letter',
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
// $file->storeAs($this->path_for_store, $fileName);
|
||||
}
|
||||
@@ -342,19 +340,18 @@ class DailyMonitoringController extends Controller
|
||||
// }
|
||||
// }
|
||||
foreach ($request->result as $file) {
|
||||
$name = 'labresult-' . uniqid();
|
||||
$extension= $file->getClientOriginalExtension();
|
||||
$orignalName = $file->getClientOriginalName();
|
||||
$fileName = $name . '.' . $extension;
|
||||
$path = $file->storeAs($this->path_for_store, $fileName);
|
||||
$fileData = File::storeFile('laboratorium-result', $db_response->id, $file);
|
||||
File::create([
|
||||
'fileable_type' => 'App\Models\LaboratoriumResult',
|
||||
'fileable_id' => $request->id,
|
||||
'type' => 'laboratorium-result',
|
||||
'name' => $name,
|
||||
'original_name' => $orignalName,
|
||||
'extension' => $extension,
|
||||
'path' => $path,
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
// $file->storeAs($this->path_for_store, $fileName);
|
||||
@@ -576,38 +573,36 @@ class DailyMonitoringController extends Controller
|
||||
// insert file result
|
||||
if ($request->confirmation_medical_leter){
|
||||
foreach ($request->confirmation_medical_leter as $file) {
|
||||
$name = 'labresult-' . uniqid();
|
||||
$extension= $file->getClientOriginalExtension();
|
||||
$fileName = $name . '.' . $extension;
|
||||
$orignalName = $file->getClientOriginalName();
|
||||
$path = $file->storeAs($this->path_for_store, $fileName);
|
||||
$fileData = File::storeFile('confirmation-medical-letter', $db_response->id, $file);
|
||||
File::create([
|
||||
'fileable_type' => 'App\Models\LaboratoriumResult',
|
||||
'fileable_id' => $db_response->id,
|
||||
'type' => 'confirmation-medical-letter',
|
||||
'name' => $name,
|
||||
'original_name' => $orignalName,
|
||||
'extension' => $extension,
|
||||
'path' => $path,
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
if ($request->medical_action_letter){
|
||||
foreach ($request->medical_action_letter as $file) {
|
||||
$name = 'labresult-' . uniqid();
|
||||
$extension= $file->getClientOriginalExtension();
|
||||
$fileName = $name . '.' . $extension;
|
||||
$orignalName = $file->getClientOriginalName();
|
||||
$path = $file->storeAs($this->path_for_store, $fileName);
|
||||
$fileData = File::storeFile('medical-action-letter', $db_response->id, $file);
|
||||
File::create([
|
||||
'fileable_type' => 'App\Models\LaboratoriumResult',
|
||||
'fileable_id' => $db_response->id,
|
||||
'type' => 'medical-action-letter',
|
||||
'name' => $name,
|
||||
'original_name' => $orignalName,
|
||||
'extension' => $extension,
|
||||
'path' => $path,
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
// $file->storeAs($this->path_for_store, $fileName);
|
||||
@@ -615,19 +610,18 @@ class DailyMonitoringController extends Controller
|
||||
}
|
||||
if ($request->result){
|
||||
foreach ($request->result as $file) {
|
||||
$name = 'labresult-' . uniqid();
|
||||
$extension= $file->getClientOriginalExtension();
|
||||
$orignalName = $file->getClientOriginalName();
|
||||
$fileName = $name . '.' . $extension;
|
||||
$path = $file->storeAs($this->path_for_store, $fileName);
|
||||
$fileData = File::storeFile('laboratorium-result', $db_response->id, $file);
|
||||
File::create([
|
||||
'fileable_type' => 'App\Models\LaboratoriumResult',
|
||||
'fileable_id' => $db_response->id,
|
||||
'type' => 'laboratorium-result',
|
||||
'name' => $name,
|
||||
'original_name' => $orignalName,
|
||||
'extension' => $extension,
|
||||
'path' => $path,
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
// $file->storeAs($this->path_for_store, $fileName);
|
||||
@@ -751,38 +745,36 @@ class DailyMonitoringController extends Controller
|
||||
// insert file result
|
||||
if ($request->confirmation_medical_leter){
|
||||
foreach ($request->confirmation_medical_leter as $file) {
|
||||
$name = 'labresult-' . uniqid();
|
||||
$extension= $file->getClientOriginalExtension();
|
||||
$fileName = $name . '.' . $extension;
|
||||
$orignalName = $file->getClientOriginalName();
|
||||
$path = $file->storeAs($this->path_for_store, $fileName);
|
||||
$fileData = File::storeFile('confirmation-medical-letter', $db_response->id, $file);
|
||||
File::create([
|
||||
'fileable_type' => 'App\Models\LaboratoriumResult',
|
||||
'fileable_id' => $db_response->id,
|
||||
'type' => 'confirmation-medical-letter',
|
||||
'name' => $name,
|
||||
'original_name' => $orignalName,
|
||||
'extension' => $extension,
|
||||
'path' => $path,
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
if ($request->medical_action_letter){
|
||||
foreach ($request->medical_action_letter as $file) {
|
||||
$name = 'labresult-' . uniqid();
|
||||
$extension= $file->getClientOriginalExtension();
|
||||
$fileName = $name . '.' . $extension;
|
||||
$orignalName = $file->getClientOriginalName();
|
||||
$path = $file->storeAs($this->path_for_store, $fileName);
|
||||
$fileData = File::storeFile('medical-action-letter', $db_response->id, $file);
|
||||
File::create([
|
||||
'fileable_type' => 'App\Models\LaboratoriumResult',
|
||||
'fileable_id' => $db_response->id,
|
||||
'type' => 'medical-action-letter',
|
||||
'name' => $name,
|
||||
'original_name' => $orignalName,
|
||||
'extension' => $extension,
|
||||
'path' => $path,
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
// $file->storeAs($this->path_for_store, $fileName);
|
||||
@@ -790,19 +782,18 @@ class DailyMonitoringController extends Controller
|
||||
}
|
||||
if ($request->result){
|
||||
foreach ($request->result as $file) {
|
||||
$name = 'labresult-' . uniqid();
|
||||
$extension= $file->getClientOriginalExtension();
|
||||
$orignalName = $file->getClientOriginalName();
|
||||
$fileName = $name . '.' . $extension;
|
||||
$path = $file->storeAs($this->path_for_store, $fileName);
|
||||
$fileData = File::storeFile('laboratorium-result', $db_response->id, $file);
|
||||
File::create([
|
||||
'fileable_type' => 'App\Models\LaboratoriumResult',
|
||||
'fileable_id' => $db_response->id,
|
||||
'type' => 'laboratorium-result',
|
||||
'name' => $name,
|
||||
'original_name' => $orignalName,
|
||||
'extension' => $extension,
|
||||
'path' => $path,
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
// $file->storeAs($this->path_for_store, $fileName);
|
||||
|
||||
@@ -114,10 +114,10 @@ class DiagnosisController extends Controller
|
||||
'file' => 'required|file|mimes:xls,xlsx,csv,txt',
|
||||
]);
|
||||
$file_name = now()->getPreciseTimestamp(3).'-'.$request->file('file')->getClientOriginalName();
|
||||
$file = $request->file('file')->storeAs('temp', $file_name);
|
||||
$file = $request->file('file')->storeAs('temp', $file_name, 'public'); // 🚀 Paksa simpan ke local/public
|
||||
|
||||
$import = new ImportService();
|
||||
$import->read(Storage::path('temp/'.$file_name));
|
||||
$import->read(Storage::disk('public')->path('temp/'.$file_name));
|
||||
$import->write(Storage::disk('public')->path('temp/result-'.$file_name), 'xsls');
|
||||
|
||||
$imported_icd_data = 0;
|
||||
|
||||
@@ -123,7 +123,7 @@ class FormulariumController extends Controller
|
||||
]);
|
||||
// dd($request->toArray());
|
||||
$file_name = now()->getPreciseTimestamp(3).'-'.$request->file('file')->getClientOriginalName();
|
||||
$file = $request->file('file')->storeAs('temp', $file_name);
|
||||
$file = $request->file('file')->storeAs('temp', $file_name, 'public'); // 🚀 Paksa simpan ke local/public
|
||||
|
||||
// $importLog = $corporate->importLogs()->create([
|
||||
// 'type' => 'diagnosis-exclusions',
|
||||
@@ -133,7 +133,7 @@ class FormulariumController extends Controller
|
||||
// ]);
|
||||
|
||||
$import = new ImportService();
|
||||
$import->read(Storage::path('temp/'.$file_name));
|
||||
$import->read(Storage::disk('public')->path('temp/'.$file_name));
|
||||
$import->write(Storage::disk('public')->path('temp/result-'.$file_name), 'xsls');
|
||||
foreach ($import->sheetsIterator() as $sheetIndex => $sheet) {
|
||||
$doc_headers_indexes = [];
|
||||
|
||||
@@ -241,11 +241,34 @@ class InvoicePaymentController extends Controller
|
||||
'files.id as file_id',
|
||||
'invoice_payments.amount_paid',
|
||||
'invoice_payments.payment_number',
|
||||
DB::raw("CONCAT('" . env('APP_URL') . "/storage/', files.path) as path"),
|
||||
'files.path',
|
||||
'files.source',
|
||||
'files.original_name'
|
||||
)
|
||||
->orderBy('invoice_payments.payment_number', 'asc')
|
||||
->get();
|
||||
->get()
|
||||
->map(function ($row) {
|
||||
// default null kalau tidak ada path
|
||||
if (!$row->path) {
|
||||
$row->path = null; // atau bisa $row->url = null
|
||||
return $row;
|
||||
}
|
||||
|
||||
if ($row->source === 's3') {
|
||||
try {
|
||||
$row->path = Storage::disk('s3')->temporaryUrl(
|
||||
$row->path,
|
||||
now()->addMinutes(60)
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$row->path = Storage::disk('s3')->url($row->path);
|
||||
}
|
||||
} else {
|
||||
$row->path = Storage::disk('public')->url($row->path);
|
||||
}
|
||||
|
||||
return $row;
|
||||
});
|
||||
|
||||
$invoice['files'] = $payments->groupBy('payment_number')->map(function ($group) {
|
||||
return [
|
||||
@@ -350,15 +373,16 @@ class InvoicePaymentController extends Controller
|
||||
}
|
||||
if (!empty($valuePayments['files']) && is_array($valuePayments['files'])) {
|
||||
foreach ($valuePayments['files'] as $file) {
|
||||
$pathFile = File::storeFile('files-proof-payment', $lastInsertedId, $file);
|
||||
$fileData = File::storeFile('files-proof-payment', $lastInsertedId, $file);
|
||||
File::updateOrCreate([
|
||||
'fileable_type' => 'App\Models\InvoicePayment',
|
||||
'fileable_id' => $lastInsertedId,
|
||||
'type' => 'files-proof-payment',
|
||||
'name' => File::getFileName('files-proof-payment', $lastInsertedId, $file),
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'path' => $pathFile,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
@@ -444,15 +468,16 @@ class InvoicePaymentController extends Controller
|
||||
//File New
|
||||
if (!empty($valuePayments['files']) && is_array($valuePayments['files'])) {
|
||||
foreach ($valuePayments['files'] as $file) {
|
||||
$pathFile = File::storeFile('files-proof-payment', $invoicePaymentId, $file);
|
||||
$fileData = File::storeFile('files-proof-payment', $invoicePaymentId, $file);
|
||||
File::updateOrCreate([
|
||||
'fileable_type' => 'App\Models\InvoicePayment',
|
||||
'fileable_id' => $invoicePaymentId,
|
||||
'type' => 'files-proof-payment',
|
||||
'name' => File::getFileName('files-proof-payment', $invoicePaymentId, $file),
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'path' => $pathFile,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
@@ -110,18 +110,19 @@ class LaboratoriumResultController extends Controller
|
||||
|
||||
// insert file result
|
||||
foreach ($request->lab_result_file as $file) {
|
||||
$name = 'labresult-' . uniqid();
|
||||
$extension= $file->getClientOriginalExtension();
|
||||
$fileName = $name . '.' . $extension;
|
||||
|
||||
$fileData = File::storeFile('laboratorium-result', $db_response->id, $file);
|
||||
File::create([
|
||||
'fileable_type' => 'App\Models\LaboratoriumResult',
|
||||
'fileable_id' => $db_response->id,
|
||||
'type' => 'laboratorium-result',
|
||||
'name' => $name,
|
||||
'original_name' => $fileName,
|
||||
'extension' => $extension,
|
||||
'path' => '',
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $orignalName,
|
||||
'extension' => $file->getClientOriginalName(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
|
||||
]);
|
||||
|
||||
$file->storeAs($this->path_for_store, $fileName);
|
||||
|
||||
@@ -542,6 +542,7 @@ class RequestLogController extends Controller
|
||||
'name' => File::getFileName('final-log-result', $id, $file),
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $pathFile,
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
@@ -558,6 +559,7 @@ class RequestLogController extends Controller
|
||||
'name' => File::getFileName('final-log-diagnosis', $id, $file),
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $pathFile,
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
@@ -573,6 +575,7 @@ class RequestLogController extends Controller
|
||||
'name' => File::getFileName('final-log-kondisi', $id, $file),
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $pathFile,
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
@@ -987,9 +990,31 @@ class RequestLogController extends Controller
|
||||
$documents = DB::table('files')
|
||||
->where('fileable_type', 'App\Models\RequestLog')
|
||||
->where('fileable_id', $claimRequestId)
|
||||
->select('original_name', \DB::raw("CONCAT('" . env('APP_URL') . "/storage/', path) as path"), 'type')
|
||||
->select('original_name', 'path', 'source','type')
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
->get()
|
||||
->map(function ($row) {
|
||||
// default null kalau tidak ada path
|
||||
if (!$row->path) {
|
||||
$row->path = null; // atau bisa $row->url = null
|
||||
return $row;
|
||||
}
|
||||
|
||||
if ($row->source === 's3') {
|
||||
try {
|
||||
$row->path = Storage::disk('s3')->temporaryUrl(
|
||||
$row->path,
|
||||
now()->addMinutes(60)
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$row->path = Storage::disk('s3')->url($row->path);
|
||||
}
|
||||
} else {
|
||||
$row->path = Storage::disk('public')->url($row->path);
|
||||
}
|
||||
|
||||
return $row;
|
||||
});
|
||||
$results['documents'] = $documents;
|
||||
$dialog_submits = DB::table('claim_requests')
|
||||
->leftJoin('members', 'claim_requests.member_id','=', 'members.id')
|
||||
@@ -1005,15 +1030,16 @@ class RequestLogController extends Controller
|
||||
{
|
||||
if ($request->hasFile('invoice_files')) {
|
||||
foreach ($request->invoice_files as $file) {
|
||||
$pathFile = File::storeFile('claim-invoice', $claim_id, $file);
|
||||
$fileData = File::storeFile('claim-invoice', $claim_id, $file);
|
||||
File::updateOrCreate([
|
||||
'fileable_type'=>'App\Models\RequestLog',
|
||||
'fileable_id' => $claim_id,
|
||||
'type' => 'claim-invoice',
|
||||
'name' => File::getFileName('claim-invoice', $claim_id, $file),
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'path' => $pathFile,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
@@ -1150,13 +1176,14 @@ class RequestLogController extends Controller
|
||||
$requestLog = RequestLog::findOrFail($id);
|
||||
if ($request->hasFile('result_files')) {
|
||||
foreach ($request->result_files as $file) {
|
||||
$pathFile = File::storeFile('final-log-result', $id, $file);
|
||||
$fileData = File::storeFile('final-log-result', $id, $file);
|
||||
$requestLog->files()->updateOrCreate([
|
||||
'type' => 'final-log-result',
|
||||
'name' => File::getFileName('final-log-result', $id, $file),
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'path' => $pathFile,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
'reason' => $request->reason,
|
||||
@@ -1166,13 +1193,14 @@ class RequestLogController extends Controller
|
||||
|
||||
if ($request->hasFile('diagnosa_files')) {
|
||||
foreach ($request->diagnosa_files as $file) {
|
||||
$pathFile = File::storeFile('final-log-diagnosis', $id, $file);
|
||||
$fileData = File::storeFile('final-log-diagnosis', $id, $file);
|
||||
$requestLog->files()->updateOrCreate([
|
||||
'type' => 'final-log-diagnosis',
|
||||
'name' => File::getFileName('final-log-diagnosis', $id, $file),
|
||||
'type' => 'final-log-result',
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'path' => $pathFile,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
'reason' => $request->reason,
|
||||
@@ -1182,13 +1210,14 @@ class RequestLogController extends Controller
|
||||
|
||||
if ($request->hasFile('kondisi_files')) {
|
||||
foreach ($request->kondisi_files as $file) {
|
||||
$pathFile = File::storeFile('final-log-kondisi', $id, $file);
|
||||
$fileData = File::storeFile('final-log-kondisi', $id, $file);
|
||||
$requestLog->files()->updateOrCreate([
|
||||
'type' => 'final-log-kondisi',
|
||||
'name' => File::getFileName('final-log-kondisi', $id, $file),
|
||||
'type' => 'final-log-result',
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'path' => $pathFile,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
'reason' => $request->reason,
|
||||
@@ -1199,29 +1228,96 @@ class RequestLogController extends Controller
|
||||
return Helper::responseJson(data: $request->toArray(), message: 'File Success Uploaded');
|
||||
}
|
||||
|
||||
// public function requestFiles(Request $request, $id)
|
||||
// {
|
||||
// Helper::setCustomPHPIniSettings();
|
||||
// $requestLog = RequestLog::findOrFail($id);
|
||||
|
||||
// // Daftar file yang akan diproses
|
||||
// $fileTypes = [
|
||||
// 'result_files' => 'final-log-result',
|
||||
// 'diagnosa_files' => 'final-log-diagnosis',
|
||||
// 'kondisi_files' => 'final-log-kondisi',
|
||||
// ];
|
||||
|
||||
// foreach ($fileTypes as $inputName => $fileType) {
|
||||
// if ($request->hasFile($inputName)) {
|
||||
// foreach ($request->file($inputName) as $file) {
|
||||
// // 1. Panggil method storeFile yang sudah diperbaiki
|
||||
// $fileData = File::storeFile($fileType, $id, $file);
|
||||
// dd($fileData);
|
||||
// // 2. Perbaiki panggilan updateOrCreate
|
||||
// $requestLog->files()->updateOrCreate(
|
||||
// [
|
||||
// 'original_name' => $file->getClientOriginalName(),
|
||||
// ],
|
||||
// [
|
||||
// // Array 2: Data untuk di-update atau di-create
|
||||
// 'name' => $fileData['name'],
|
||||
// 'original_name' => $file->getClientOriginalName(),
|
||||
// 'extension' => $file->getClientOriginalExtension(),
|
||||
// 'source' => 's3', // Langsung set ke 's3' untuk file baru
|
||||
// 'path' => $fileData['path'],
|
||||
// 'created_by' => auth()->id(),
|
||||
// 'updated_by' => auth()->id(),
|
||||
// 'reason' => $request->reason,
|
||||
// ]
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// return Helper::responseJson(data: $requestLog->files, message: 'File Success Uploaded');
|
||||
// }
|
||||
|
||||
public function deleteFiles(Request $request, $id)
|
||||
{
|
||||
// Path file yang akan dihapus
|
||||
$path = 'public/' . $request->path;
|
||||
// Ambil data file dari database
|
||||
$file = File::where('path', $request->path)->first();
|
||||
|
||||
// Tentukan disk berdasarkan source
|
||||
$disk = $file->source === 's3' ? 's3' : 'local';
|
||||
|
||||
// Menghapus file dari penyimpanan
|
||||
if (Storage::exists($path)) {
|
||||
Storage::delete($path);
|
||||
// Path file sesuai yang disimpan di DB
|
||||
$path = $file->path;
|
||||
|
||||
// Update entri file dari basis data
|
||||
File::where('path', $request->path)->update([
|
||||
'deleted_at' => Carbon::now(), // Gunakan Carbon untuk mendapatkan tanggal dan waktu saat ini
|
||||
'deleted_by' => auth()->user()->id,
|
||||
'reason' => $request->reason
|
||||
// Hapus file dari storage (cek dulu ada atau tidak)
|
||||
if (Storage::disk($disk)->exists($path)) {
|
||||
Storage::disk($disk)->delete($path);
|
||||
|
||||
// Update status file di DB (soft delete + reason)
|
||||
$file->update([
|
||||
'deleted_at' => Carbon::now(),
|
||||
'deleted_by' => auth()->id(),
|
||||
'reason' => $request->reason,
|
||||
]);
|
||||
// Mengembalikan respons JSON sukses
|
||||
return Helper::responseJson(data: $request->toArray(), message: 'File successfully deleted');
|
||||
|
||||
return Helper::responseJson(
|
||||
data: $file->toArray(),
|
||||
message: 'File successfully deleted'
|
||||
);
|
||||
} else {
|
||||
// Update status file di DB (soft delete + reason)
|
||||
$file->update([
|
||||
'deleted_at' => Carbon::now(),
|
||||
'deleted_by' => auth()->id(),
|
||||
'reason' => $request->reason,
|
||||
]);
|
||||
|
||||
return Helper::responseJson(
|
||||
data: $file->toArray(),
|
||||
message: 'File successfully deleted'
|
||||
);
|
||||
}
|
||||
|
||||
// Jika file tidak ditemukan di penyimpanan, kirim respons JSON gagal
|
||||
return Helper::responseJson(data: $request->toArray(), message: 'File deletion failed');
|
||||
// Jika file tidak ditemukan
|
||||
return Helper::responseJson(
|
||||
data: $file->toArray(),
|
||||
message: 'File deletion failed'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function cekphp(){
|
||||
phpinfo();
|
||||
}
|
||||
|
||||
@@ -128,15 +128,16 @@ class ChatController extends Controller
|
||||
$pathFile = null;
|
||||
if ($request->hasFile('file_chat')) {
|
||||
foreach ($request->file_chat as $file) {
|
||||
$pathFile = File::storeFile('chat', $message->id, $file);
|
||||
$fileData = File::storeFile('chat', $message->id, $file);
|
||||
File::updateOrCreate([
|
||||
'fileable_type'=>'App\Models\Message',
|
||||
'fileable_id' => $message->id,
|
||||
'type' => 'chat',
|
||||
'name' => File::getFileName('chat', $message->id, $file),
|
||||
'name' => $fileData['name'],
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'path' => $pathFile,
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $fileData['path'],
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
@@ -129,6 +129,7 @@ class PersonController extends Controller
|
||||
'type' => 'avatar',
|
||||
'name' => File::getFileName('avatar', $family->id, $request->file('user_avatar')),
|
||||
'extension' => $request->file('user_avatar')->getClientOriginalExtension(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $pathFileAvatar,
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
@@ -141,6 +142,7 @@ class PersonController extends Controller
|
||||
'type' => 'dataDiri',
|
||||
'name' => File::getFileName('dataDiri', $family->id, $request->file('verification_file')),
|
||||
'extension' => $request->file('verification_file')->getClientOriginalExtension(),
|
||||
'source' => env('FILESYSTEM_DISK'),
|
||||
'path' => $pathFileVerification,
|
||||
'created_by' => auth()->user()->id,
|
||||
'updated_by' => auth()->user()->id,
|
||||
|
||||
@@ -18,16 +18,18 @@ class File extends Model
|
||||
'name',
|
||||
'original_name',
|
||||
'extension',
|
||||
'source',
|
||||
'path',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_at',
|
||||
'reason'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
// 'deleted_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
@@ -78,20 +80,64 @@ class File extends Model
|
||||
|
||||
public function getUrlAttribute()
|
||||
{
|
||||
return url(Storage::url($this->path));
|
||||
// Jika path kosong, kembalikan null
|
||||
if (!$this->path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Cek nilai 'source'. Jika 's3', gunakan disk S3.
|
||||
// Selain itu (termasuk null atau 'local'), gunakan disk 'public'.
|
||||
if ($this->source === 's3') {
|
||||
try {
|
||||
return Storage::disk('s3')->temporaryUrl(
|
||||
$this->path,
|
||||
now()->addMinutes(60) // expired 1 jam
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
return Storage::disk('s3')->url($this->path); // fallback kalau public
|
||||
}
|
||||
}
|
||||
return Storage::disk('public')->url($this->path);
|
||||
}
|
||||
|
||||
// public static function storeFile($type, $id, $file)
|
||||
// {
|
||||
// // $fileName = self::getFileName($type, $id);
|
||||
// $fileName = $file->getClientOriginalName();
|
||||
// $directory = self::getDirectory($type);
|
||||
// $extension = $file->getClientOriginalExtension();
|
||||
// $path = $directory . $fileName . '.' . $extension;
|
||||
// $file->storeAs('public/' . $directory, $fileName);
|
||||
// return $path;
|
||||
// }
|
||||
|
||||
public static function storeFile($type, $id, $file)
|
||||
{
|
||||
// $fileName = self::getFileName($type, $id);
|
||||
$fileName = $file->getClientOriginalName();
|
||||
$directory = self::getDirectory($type);
|
||||
// Pastikan directory tidak punya trailing slash
|
||||
$directory = rtrim(self::getDirectory($type), '/');
|
||||
|
||||
// Buat nama file yang unik dan aman
|
||||
$originalName = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME);
|
||||
$extension = $file->getClientOriginalExtension();
|
||||
$path = $directory . $fileName . '.' . $extension;
|
||||
$file->storeAs('public/' . $directory, $fileName . '.' . $extension);
|
||||
return $path;
|
||||
$safeName = Str::slug($originalName);
|
||||
$uniqueName = $safeName . '-' . uniqid() . '.' . $extension;
|
||||
|
||||
// Upload file ke disk 's3' dengan visibility 'public'
|
||||
$path = Storage::disk('s3')->putFileAs(
|
||||
$directory,
|
||||
$file,
|
||||
$uniqueName,
|
||||
'public'
|
||||
);
|
||||
|
||||
// Kembalikan path dan nama unik agar bisa digunakan di controller
|
||||
return [
|
||||
'path' => $directory . '/' . $uniqueName, // hasil konsisten
|
||||
'name' => $uniqueName,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public static function storeFileChat($type, $id, $file)
|
||||
{
|
||||
// $fileName = self::getFileName($type, $id);
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use DB;
|
||||
|
||||
@@ -111,16 +112,38 @@ class RequestDailyMonitoring extends Model
|
||||
'fileable_id' => $this->attributes['id'],
|
||||
'deleted_at' => null,
|
||||
])->get();
|
||||
|
||||
|
||||
foreach ($document as $row) {
|
||||
// Jika path kosong, kembalikan null
|
||||
if (!$row->path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Cek nilai 'source'. Jika 's3', gunakan disk S3.
|
||||
// Selain itu (termasuk null atau 'local'), gunakan disk 'public'.
|
||||
if ($row->source === 's3') {
|
||||
try {
|
||||
$path = Storage::disk('s3')->temporaryUrl(
|
||||
$row->path,
|
||||
now()->addMinutes(60) // expired 1 jam
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$path = Storage::disk('s3')->url($row->path); // fallback kalau public
|
||||
}
|
||||
} else {
|
||||
// pastikan path tidak double "public/"
|
||||
$pathInDisk = str_replace('public/', '', $row->path);
|
||||
$path = Storage::disk('public')->url($pathInDisk);
|
||||
}
|
||||
|
||||
$arr_document[] = [
|
||||
'id' => $row->id,
|
||||
'file_name' => $row->original_name,
|
||||
'path' => env('APP_URL') . '/storage/lab_result/' . $row->name .'.'. $row->extension,
|
||||
// 'path' => env('APP_URL') . '/storage/lab_result/' . $row->name .'.'. $row->extension,
|
||||
'path' => $path,
|
||||
'type' => $row->type,
|
||||
];
|
||||
}
|
||||
|
||||
return $arr_document;
|
||||
}
|
||||
|
||||
@@ -139,9 +162,29 @@ class RequestDailyMonitoring extends Model
|
||||
])->get();
|
||||
|
||||
foreach ($document as $row) {
|
||||
// Jika path kosong, kembalikan null
|
||||
if (!$row->path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Cek nilai 'source'. Jika 's3', gunakan disk S3.
|
||||
// Selain itu (termasuk null atau 'local'), gunakan disk 'public'.
|
||||
if ($row->source === 's3') {
|
||||
try {
|
||||
$path = Storage::disk('s3')->temporaryUrl(
|
||||
$row->path,
|
||||
now()->addMinutes(60) // expired 1 jam
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$path = Storage::disk('s3')->url($row->path); // fallback kalau public
|
||||
}
|
||||
} else {
|
||||
$path = Storage::disk('public')->url($row->path);
|
||||
}
|
||||
$arr_document[] = [
|
||||
'name' => $row->original_name,
|
||||
'path' => env('APP_URL') . '/storage/lab_result/' . $row->name .'.'. $row->extension,
|
||||
// 'path' => env('APP_URL') . '/storage/lab_result/' . $row->name .'.'. $row->extension,
|
||||
'path' => $path,
|
||||
'type' => $row->type,
|
||||
];
|
||||
}
|
||||
@@ -158,9 +201,29 @@ class RequestDailyMonitoring extends Model
|
||||
])->get();
|
||||
|
||||
foreach ($document as $row) {
|
||||
// Jika path kosong, kembalikan null
|
||||
if (!$row->path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Cek nilai 'source'. Jika 's3', gunakan disk S3.
|
||||
// Selain itu (termasuk null atau 'local'), gunakan disk 'public'.
|
||||
if ($row->source === 's3') {
|
||||
try {
|
||||
$path = Storage::disk('s3')->temporaryUrl(
|
||||
$row->path,
|
||||
now()->addMinutes(60) // expired 1 jam
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$path = Storage::disk('s3')->url($row->path); // fallback kalau public
|
||||
}
|
||||
} else {
|
||||
$path = Storage::disk('public')->url($row->path);
|
||||
}
|
||||
$arr_document[] = [
|
||||
'name' => $row->original_name,
|
||||
'path' => env('APP_URL') . '/storage/lab_result/' . $row->name .'.'. $row->extension,
|
||||
// 'path' => env('APP_URL') . '/storage/lab_result/' . $row->name .'.'. $row->extension,
|
||||
'path' => $path,
|
||||
'type' => $row->type,
|
||||
];
|
||||
}
|
||||
@@ -177,9 +240,30 @@ class RequestDailyMonitoring extends Model
|
||||
])->get();
|
||||
|
||||
foreach ($document as $row) {
|
||||
// Jika path kosong, kembalikan null
|
||||
if (!$row->path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Cek nilai 'source'. Jika 's3', gunakan disk S3.
|
||||
// Selain itu (termasuk null atau 'local'), gunakan disk 'public'.
|
||||
if ($row->source === 's3') {
|
||||
try {
|
||||
$path = Storage::disk('s3')->temporaryUrl(
|
||||
$row->path,
|
||||
now()->addMinutes(60) // expired 1 jam
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$path = Storage::disk('s3')->url($row->path); // fallback kalau public
|
||||
}
|
||||
} else {
|
||||
$path = Storage::disk('public')->url($row->path);
|
||||
}
|
||||
|
||||
$arr_document[] = [
|
||||
'name' => $row->original_name,
|
||||
'path' => env('APP_URL') . '/storage/lab_result/' . $row->name .'.'. $row->extension,
|
||||
// 'path' => env('APP_URL') . '/storage/lab_result/' . $row->name .'.'. $row->extension,
|
||||
'path' => $path,
|
||||
'type' => $row->type,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ return [
|
||||
'driver' => 's3',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION'),
|
||||
'region' => env('AWS_DEFAULT_REGION', 'ap-southeast-1'),
|
||||
'bucket' => env('AWS_BUCKET'),
|
||||
'url' => env('AWS_URL'),
|
||||
'endpoint' => env('AWS_ENDPOINT'),
|
||||
|
||||
Reference in New Issue
Block a user