Browse Source

Merge pull request 'fix: upload report image' (#8) from dev-wahyun into staging

Reviewed-on: #8
pull/12/head
farhantock 4 months ago
parent
commit
f0f1b31a0d
  1. 2
      app/Http/Controllers/DashboardBoDController.php
  2. 43
      app/Http/Controllers/ImageController.php

2
app/Http/Controllers/DashboardBoDController.php

@ -275,7 +275,7 @@ class DashboardBoDController extends Controller
return response()->json(['data' => $divisions], 200); return response()->json(['data' => $divisions], 200);
} }
public function getTotalProjectPerBudgetHealth($role_name, $all_project, $hierarchy) public function getTotalProjectPerBudgetHealth($all_project, $hierarchy, $role_name)
{ {
$role = urldecode($role_name); $role = urldecode($role_name);
$replaceHierarchy = preg_replace('/[\[\]]/', '', $hierarchy); $replaceHierarchy = preg_replace('/[\[\]]/', '', $hierarchy);

43
app/Http/Controllers/ImageController.php

@ -25,17 +25,7 @@ class ImageController extends Controller
$extension = $dokumen->extension(); $extension = $dokumen->extension();
$category = $request->category; $category = $request->category;
$name = $ref_id.date("YmdHis").".".$extension; $name = $ref_id.date("YmdHis").".".$extension;
// Limited Storage $destinationPath = $this->setCustomeDirectoryUpload();
$company = Company::where('company_name', $request->company_name)->first();
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$getLimitStorage = $this->setLimitsStorage($company, $dokumen, $destinationPath['pathImage'], $destinationPath);
}
if(isset($getLimitStorage)) {
if($getLimitStorage === false) {
DB::rollBack();
return response()->json(['status' => 'failed', 'message' => 'Limited storage maximum!', 'code' => 500], 500);
}
$data = [ $data = [
'ref_id' => (int)$ref_id, 'ref_id' => (int)$ref_id,
'image' => $name, 'image' => $name,
@ -43,32 +33,6 @@ class ImageController extends Controller
]; ];
$result = Image::create($data); $result = Image::create($data);
$company = Company::find((int)$ref_id);
if($company && $category === 'company_logo_login') {
$dataArray = json_decode($company['logo_login'], true);
if(isset($dataArray['slider'])) {
$jsonImageSlider['login'] = $name;
$jsonImageSlider['slider'] = $dataArray['slider'];
} else {
$jsonImageSlider['login'] = $name;
}
$company->update([
'logo_login' => $jsonImageSlider
]);
}
if($company && $category === 'company_logo_header') {
$company->update([
'logo_header' => array('content' => $name)
]);
}
if($company && $category === 'company_favicon') {
$company->update([
'favicon_image' => array('content' => $name)
]);
}
if($dokumen->move($destinationPath['pathImage'], $name) && $result) { if($dokumen->move($destinationPath['pathImage'], $name) && $result) {
DB::commit(); DB::commit();
return response()->json(['status' => 'success', "name_image" => $name,'message' => 'image upload is successfully!','code' => 200], 200); return response()->json(['status' => 'success', "name_image" => $name,'message' => 'image upload is successfully!','code' => 200], 200);
@ -77,11 +41,6 @@ class ImageController extends Controller
unlink($destinationPath['pathImage'].$name); unlink($destinationPath['pathImage'].$name);
return response()->json(['status' => 'failed','message' => 'image upload is failed!' ,'code' => 400], 400); return response()->json(['status' => 'failed','message' => 'image upload is failed!' ,'code' => 400], 400);
} }
} else {
DB::rollBack();
return response()->json(['status'=>'failed','message'=>'image upload is failed!','code'=>400], 400);
}
} else { } else {
DB::rollBack(); DB::rollBack();
return response()->json(['status'=>'failed','message'=>'image is required!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'image is required!','code'=>400], 400);

Loading…
Cancel
Save