Browse Source

company mangement

pull/3/head
farhan048 1 year ago
parent
commit
79e044fbd5
  1. 139
      app/Http/Controllers/CompanyController.php
  2. 2
      app/Models/Company.php
  3. 26
      routes/web.php

139
app/Http/Controllers/CompanyController.php

@ -7,79 +7,104 @@ use Illuminate\Http\Request;
class CompanyController extends Controller class CompanyController extends Controller
{ {
/** public function add(Request $request)
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{ {
// $this->validate($request, [
} 'name' => 'required',
'description' => 'required'
]);
/** $data = $request->all();
* Show the form for creating a new resource.
* $data['created_by'] = $this->currentName;
* @return \Illuminate\Http\Response
*/ $result = Company::create($data);
public function create()
{ if ($result) {
// return response()->json(['status' => 'success', 'message' => 'add Company successfully!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'add data Company failed!', 'code' => 400], 400);
}
} }
/** public function edit($id)
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{ {
// if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
die();
}
$result = Company::find($id);
if ($result) {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'failed get data Company, please try again later!', 'code' => 400], 400);
}
} }
/** public function update(Request $request, $id)
* Display the specified resource.
*
* @param \App\Company $company
* @return \Illuminate\Http\Response
*/
public function show(Company $company)
{ {
// if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
}
$data = Company::find($id);
if ($data) {
$result = $data->update($request->all());
} else {
return response()->json(['status' => 'failed', 'message' => 'data Company not found!', 'code' => 400], 400);
die();
}
if ($result) {
return response()->json(['status' => 'success', 'message' => 'data Company successfully updated!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'data Company failed updated!', 'code' => 400], 400);
}
} }
/** public function delete($id)
* Show the form for editing the specified resource.
*
* @param \App\Company $company
* @return \Illuminate\Http\Response
*/
public function edit(Company $company)
{ {
// $data = Company::find($id);
if ($data) {
$delete = $data->delete();
} else {
return response()->json(['status' => 'failed', 'message' => 'data Company not found!', 'code' => 400], 400);
die();
}
if ($delete) {
return response()->json(['status' => 'success', 'message' => 'data Company successfully deleted!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'data Company failed deleted!', 'code' => 400], 400);
}
} }
/** public function search(Request $request)
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Company $company
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Company $company)
{ {
// $payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_company');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200);
} }
/** public function list()
* Remove the specified resource from storage.
*
* @param \App\Company $company
* @return \Illuminate\Http\Response
*/
public function destroy(Company $company)
{ {
// $data = Company::all();
$countData = $data->count();
if ($data) {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'failed get list Company, please try again later!', 'code' => 400], 400);
}
} }
} }

2
app/Models/Company.php

@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model;
class Company extends Model class Company extends Model
{ {
protected $table = 'm_divisi'; protected $table = 'm_company';
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';

26
routes/web.php

@ -1,10 +1,10 @@
<?php <?php
$router->get('/', function () use ($router) { $router->get('/', function () use ($router) {
return $router->app->version(); return $router->app->version();
}); });
$router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($router) { $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($router) {
$router->post('/login', 'AuthController@login'); $router->post('/login', 'AuthController@login');
$router->post('/menu/add', 'MenuController@add'); $router->post('/menu/add', 'MenuController@add');
@ -53,7 +53,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->post('/document-activity/search', 'ActivityDokumenController@searchDocProject'); $router->post('/document-activity/search', 'ActivityDokumenController@searchDocProject');
$router->get('/document-activity/download/{id}', 'ActivityDokumenController@downloadDokumen'); $router->get('/document-activity/download/{id}', 'ActivityDokumenController@downloadDokumen');
$router->get('/project-by-customer/{id}','ProjectController@getByUser'); $router->get('/project-by-customer/{id}', 'ProjectController@getByUser');
$router->post('/project/search', 'ProjectController@search'); $router->post('/project/search', 'ProjectController@search');
$router->post('/project/add', 'ProjectController@add'); $router->post('/project/add', 'ProjectController@add');
$router->put('/project/update/{id}', 'ProjectController@update'); $router->put('/project/update/{id}', 'ProjectController@update');
@ -207,11 +207,11 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->get('/activity/{id}/{proyek_id}/get', 'ActivityController@getByGanttId'); $router->get('/activity/{id}/{proyek_id}/get', 'ActivityController@getByGanttId');
$router->post('/activity/search', 'ActivityController@search'); $router->post('/activity/search', 'ActivityController@search');
$router->post('/activity/search-analysis', 'ActivityController@searchAnalysis'); $router->post('/activity/search-analysis', 'ActivityController@searchAnalysis');
$router->post('/activity/import', 'ActivityController@import'); $router->post('/activity/import', 'ActivityController@import');
$router->post('/activity/import-update', 'ActivityController@importUpdate'); $router->post('/activity/import-update', 'ActivityController@importUpdate');
$router->post('/activity/import-old', 'ActivityController@importOld'); $router->post('/activity/import-old', 'ActivityController@importOld');
$router->post('/activity/batch-update/{ganttId}', 'ActivityController@batchUpdate'); $router->post('/activity/batch-update/{ganttId}', 'ActivityController@batchUpdate');
$router->get('/activity/update-schedule/{ganttId}', 'ActivityController@updateSchedule'); $router->get('/activity/update-schedule/{ganttId}', 'ActivityController@updateSchedule');
$router->post('/task', 'ActivityController@add'); $router->post('/task', 'ActivityController@add');
$router->get('/task/edit/{id}', 'ActivityController@edit'); $router->get('/task/edit/{id}', 'ActivityController@edit');
$router->put('/task/{id}', 'ActivityController@update'); $router->put('/task/{id}', 'ActivityController@update');
@ -411,7 +411,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->get('/report-k3-detail/list', 'ReportK3DetailController@list'); $router->get('/report-k3-detail/list', 'ReportK3DetailController@list');
$router->post('/user-to-proyek/add', 'UserToProyekController@add'); $router->post('/user-to-proyek/add', 'UserToProyekController@add');
$router->post('/user-to-proyek/add-multiple', 'UserToProyekController@addMultiple'); $router->post('/user-to-proyek/add-multiple', 'UserToProyekController@addMultiple');
$router->get('/user-to-proyek/edit/{id}', 'UserToProyekController@edit'); $router->get('/user-to-proyek/edit/{id}', 'UserToProyekController@edit');
$router->put('/user-to-proyek/update/{id}', 'UserToProyekController@update'); $router->put('/user-to-proyek/update/{id}', 'UserToProyekController@update');
$router->post('/user-to-proyek/search', 'UserToProyekController@search'); $router->post('/user-to-proyek/search', 'UserToProyekController@search');
@ -496,6 +496,12 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->post('/broadcast/search', 'BroadcastController@search'); $router->post('/broadcast/search', 'BroadcastController@search');
$router->delete('/broadcast/delete/{id}', 'BroadcastController@delete'); $router->delete('/broadcast/delete/{id}', 'BroadcastController@delete');
$router->get('/broadcast/list', 'BroadcastController@list'); $router->get('/broadcast/list', 'BroadcastController@list');
});
$router->post('/company-management/add', 'CompanyController@add');
$router->get('/company-management/edit/{id}', 'CompanyController@edit');
$router->put('/company-management/update/{id}', 'CompanyController@update');
$router->post('/company-management/search', 'CompanyController@search');
$router->delete('/company-management/delete/{id}', 'CompanyController@delete');
$router->get('/company-management/list', 'CompanyController@list');
});
}); });

Loading…
Cancel
Save