Browse Source

Merge pull request 'staging' (#52) from staging into master

Reviewed-on: ibnu/generic-ospro-backend#52
pull/1/head
farhantock 9 months ago
parent
commit
e56e82fb57
  1. 81
      app/Http/Controllers/RefferalCodeController.php
  2. 37
      app/Http/Controllers/RoleMenuController.php
  3. 29
      app/Models/RefferalCode.php
  4. 7
      routes/web.php

81
app/Http/Controllers/RefferalCodeController.php

@ -0,0 +1,81 @@
<?php
namespace App\Http\Controllers;
use App\Models\RefferalCode;
use Illuminate\Http\Request;
class RefferalCodeController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'code' => 'required|unique:refferal_code,code',
'exp' => 'nullable',
'type' => 'nullable',
'allocation' => 'nullable'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = RefferalCode::create($data);
if($result){
return response()->json(['status'=>'success','message'=>'Add refferal code successfully!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'Add refferal Code failed!','code'=>400], 400);
}
}
public function edit($id)
{
if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'Id is required!', 'code' => 400], 400);
die();
}
$result = RefferalCode::find($id);
if ($result) {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'Failed get refferal code, please try again later!', 'code' => 400], 400);
}
}
public function update(Request $request, $id)
{
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400);
}
$data = RefferalCode::find($id);
if($data){
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'Refferal code not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'Refferal code successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'Refferal code failed updated!','code'=>400], 400);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'refferal_code');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200);
}
}

37
app/Http/Controllers/RoleMenuController.php

@ -28,6 +28,43 @@ class RoleMenuController extends Controller
}
}
public function addMultiple(Request $request)
{
$menus = $request->all();
if (is_array($menus) && count($menus) > 0 && isset($menus[0]['menu_id'])) {
$countRes = 0;
foreach ($menus as $menu) {
$dataInsert = array(
"menu_id" => $menu['menu_id'],
"role_id" => $menu['role_id'],
);
$result = RoleMenu::create($dataInsert);
if ($result) {
$countRes++;
} else {
$countRes--;
}
}
if ($countRes > 0) {
return response()->json(['status' => 'success', 'message' => 'Add data menu role successfully!', 'code' => 200]);
} else {
return response()->json(['status' => 'failed', 'message' => 'Add data menu role failed created!', 'code' => 500]);
}
} else {
if(isset($data))
{
return response()->json(['status' => 'success', 'message' => 'Add data menu role successfully!', 'code' => 200]);
}else{
return response()->json(['status' => 'failed', 'message' => 'Add data menu role failed created!', 'code' => 500]);
}
}
}
public function update(Request $request, $id)
{
if(!$id || (int) $id < 0 || $id==""){

29
app/Models/RefferalCode.php

@ -0,0 +1,29 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class RefferalCode extends Model
{
protected $table = 'refferal_code';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'id',
'code',
'amount',
'exp',
'type',
'allocation',
'description',
'created_at',
'created_by',
'updated_at',
'updated_by',
'deleted_at',
'deleted_by'
];
}

7
routes/web.php

@ -16,6 +16,8 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->post('/demo-management-user/add', 'DemoController@add');
$router->post('/role-user/add', 'RoleController@add');
$router->post('/menu-company-user/add-multiple', 'MenuCompanyController@addMultiple');
$router->post('/role-menu-user/add-multiple', 'RoleMenuController@addMultiple');
$router->post('/refferal-code/search', 'RefferalCodeController@search');
$router->post('/menu/add', 'MenuController@add');
$router->get('/menu/edit/{id}', 'MenuController@edit');
@ -133,6 +135,11 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->post('/human-resource/check-old-password/{id}', 'HumanResourceController@checkOldPassword');
$router->get('/human-resource/sync', 'HumanResourceController@sync');
$router->post('/refferal-code/search', 'RefferalCodeController@search');
$router->post('/refferal-code/add', 'RefferalCodeController@add');
$router->get('/refferal-code/edit/{id}', 'RefferalCodeController@edit');
$router->put('/refferal-code/update/{id}', 'RefferalCodeController@update');
$router->post('/project-role/search', 'ProjectRoleController@search');
$router->post('/project-role/add', 'ProjectRoleController@add');
$router->get('/project-role/edit/{id}', 'ProjectRoleController@edit');

Loading…
Cancel
Save