Browse Source

Merge pull request 'dev-wahyun' (#75) from dev-wahyun into staging

Reviewed-on: ibnu/generic-ospro-backend#75
pull/1/head
farhantock 6 months ago
parent
commit
e745e738f4
  1. 15
      app/Http/Controllers/ReportActivityMaterialController.php
  2. 2
      routes/web.php

15
app/Http/Controllers/ReportActivityMaterialController.php

@ -8,6 +8,8 @@ use Illuminate\Support\Facades\DB;
use App\Models\ReportActivityMaterial; use App\Models\ReportActivityMaterial;
use App\Models\Activity; use App\Models\Activity;
use App\Models\AssignMaterial; use App\Models\AssignMaterial;
use App\Models\Company;
use App\Models\Image;
use Yajra\Datatables\Datatables; use Yajra\Datatables\Datatables;
use DateTime; use DateTime;
@ -100,10 +102,19 @@ class ReportActivityMaterialController extends Controller
} }
} }
public function delete($id) public function delete($id, $company_id)
{ {
if(!ReportActivityMaterial::findOrFail($id)->delete()) $data = ReportActivityMaterial::findOrFail($id);
$company = Company::find($company_id);
$image = Image::where([['ref_id', $id],['category','report_activity']])->first();
if($data && $company && $image) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
unlink($destinationPath['pathImage'].$image['image']);
}
if(!$data->delete()) {
return response()->json(['status'=>'failed','message'=>'Failed to deleted the data!','code'=> 500], 500); return response()->json(['status'=>'failed','message'=>'Failed to deleted the data!','code'=> 500], 500);
}
return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=>200], 200); return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=>200], 200);
} }

2
routes/web.php

@ -431,7 +431,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->post('/report-activity-material/add', 'ReportActivityMaterialController@add'); $router->post('/report-activity-material/add', 'ReportActivityMaterialController@add');
$router->post('/report-activity-material/search', 'ReportActivityMaterialController@search'); $router->post('/report-activity-material/search', 'ReportActivityMaterialController@search');
$router->delete('/report-activity-material/delete/{id}', 'ReportActivityMaterialController@delete'); $router->delete('/report-activity-material/delete/{id}/{company_id}', 'ReportActivityMaterialController@delete');
$router->get('/report-activity-material/list', 'ReportActivityMaterialController@list'); $router->get('/report-activity-material/list', 'ReportActivityMaterialController@list');
$router->get('/report-activity-material/datatables', 'ReportActivityMaterialController@datatables'); $router->get('/report-activity-material/datatables', 'ReportActivityMaterialController@datatables');
$router->post('/report-activity-material/update-status', 'ReportActivityMaterialController@updateStatusStartFinish'); $router->post('/report-activity-material/update-status', 'ReportActivityMaterialController@updateStatusStartFinish');

Loading…
Cancel
Save