Browse Source

Merge branch 'staging' of https://git.oslog.id/ibnu/generic-ospro-backend into dev-wahyun

pull/1/head
wahyun 10 months ago
parent
commit
851e13f064
  1. 147
      app/Http/Controllers/AssignMaterialController.php
  2. 80
      app/Http/Controllers/AuthController.php
  3. 114
      app/Http/Controllers/DemoController.php
  4. 1
      app/Models/Demo.php
  5. 12
      routes/web.php

147
app/Http/Controllers/AssignMaterialController.php

@ -12,13 +12,15 @@ use Datatables;
class AssignMaterialController extends Controller class AssignMaterialController extends Controller
{ {
private function sanitizeDecimal($number) { private function sanitizeDecimal($number)
$number = str_replace(".","",$number); {
$number = str_replace(",",".",$number); $number = str_replace(".", "", $number);
$number = str_replace(",", ".", $number);
return $number; return $number;
} }
public function add(Request $request){ public function add(Request $request)
{
$this->validate($request, [ $this->validate($request, [
'activity_id' => 'required', 'activity_id' => 'required',
'material_id' => 'required', 'material_id' => 'required',
@ -29,8 +31,8 @@ class AssignMaterialController extends Controller
$checkStock = RequestMaterial::where("id", $request->material_id)->first(); $checkStock = RequestMaterial::where("id", $request->material_id)->first();
$currentStock = $checkStock->qty; $currentStock = $checkStock->qty;
if((int)$currentStock < (int)$request->qty_planning){ if ((int)$currentStock < (int)$request->qty_planning) {
return response()->json(['status'=>'failed','message'=>'Stock is not enough!','code'=> 500]); return response()->json(['status' => 'failed', 'message' => 'Stock is not enough!', 'code' => 500]);
} }
$start_date = $activity->start_date; $start_date = $activity->start_date;
@ -43,56 +45,58 @@ class AssignMaterialController extends Controller
$data['budget'] = $checkStock->price; $data['budget'] = $checkStock->price;
$data['qty_planning'] = $this->sanitizeDecimal($data['qty_planning']); $data['qty_planning'] = $this->sanitizeDecimal($data['qty_planning']);
if ($planDate >= $startDate) { if ($planDate >= $startDate) {
$result = AssignMaterial::create($data); $result = AssignMaterial::create($data);
return response()->json(['status'=>'success','message'=>'Data added!', 'code'=>200], 200); return response()->json(['status' => 'success', 'message' => 'Data added!', 'code' => 200], 200);
}else{ } else {
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 400], 400); return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 400], 400);
} }
} }
public function update(Request $request, $id){ public function update(Request $request, $id)
if(empty($id) || !is_int((int)$id)) {
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); if (empty($id) || !is_int((int)$id))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$data = AssignMaterial::find($id); $data = AssignMaterial::find($id);
if(!$data) if (!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
$result = $data->update($request->all()); $result = $data->update($request->all());
if($result) if ($result)
return response()->json(['status'=>'success','message'=> 'Data updated!','code'=> 200], 200); return response()->json(['status' => 'success', 'message' => 'Data updated!', 'code' => 200], 200);
return response()->json(['status'=>'failed','message'=>'Failed to update!','code'=> 500], 500); return response()->json(['status' => 'failed', 'message' => 'Failed to update!', 'code' => 500], 500);
} }
public function delete($id) public function delete($id)
{ {
$data = AssignMaterial::where('id', $id)->first(); $data = AssignMaterial::where('id', $id)->first();
$reports = ReportActivityMaterial::where('assign_material_id', $data->id)->get(); $reports = ReportActivityMaterial::where('assign_material_id', $data->id)->get();
if (isset($reports)) { if (isset($reports)) {
foreach ($reports as $report) { foreach ($reports as $report) {
$report->delete(); $report->delete();
} }
} }
if($data->delete()) if ($data->delete())
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=> 200], 200); return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200);
return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500); return response()->json(['status' => 'failed', 'message' => 'Failed to delete!', 'code' => 500], 500);
} }
public function edit($id){ public function edit($id)
if(empty($id) || !is_int((int)$id)) {
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); if (empty($id) || !is_int((int)$id))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$result = AssignMaterial::find($id); $result = AssignMaterial::find($id);
if($result) if ($result)
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
} }
public function search(Request $request) public function search(Request $request)
@ -103,7 +107,7 @@ class AssignMaterialController extends Controller
$countBuilder = $dataBuilder['count']; $countBuilder = $dataBuilder['count'];
$dataGet = $builder->get(); $dataGet = $builder->get();
$totalRecord = $countBuilder->count(); $totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200);
} }
public function list() public function list()
@ -111,18 +115,21 @@ class AssignMaterialController extends Controller
$data = AssignMaterial::all(); $data = AssignMaterial::all();
$countData = $data->count(); $countData = $data->count();
if($data) if ($data)
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200);
return response()->json(['status'=>'failed','message'=>'Failed to get the data!','code'=> 500], 500); return response()->json(['status' => 'failed', 'message' => 'Failed to get the data!', 'code' => 500], 500);
} }
public function datatables(Request $request){ public function datatables(Request $request)
{
$id_activity = $request->query('idact'); $id_activity = $request->query('idact');
$type = $request->query('type') ?? "material"; $type = $request->query('type') ?? "material";
$data = AssignMaterial::select( $data = AssignMaterial::select(
"assign_material_to_activity.*","m.description as material_name", "m.uom as uom" "assign_material_to_activity.*",
) "m.description as material_name",
"m.uom as uom"
)
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('assign_material_to_activity.activity_id', $id_activity) ->where('assign_material_to_activity.activity_id', $id_activity)
->where('assign_material_to_activity.type', $type) ->where('assign_material_to_activity.type', $type)
@ -130,28 +137,33 @@ class AssignMaterialController extends Controller
->get(); ->get();
return Datatables::of($data) return Datatables::of($data)
->addIndexColumn() ->addIndexColumn()
->addColumn('action', function($row){ ->addColumn('action', function ($row) {
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-material-delete"><i class="fa fa-trash"></i></a>'; $actionBtn = '<a href="javascript:void(0)" data-id="' . $row->id . '" class="delete btn btn-danger btn-sm btn-material-delete"><i class="fa fa-trash"></i></a>';
return $actionBtn; return $actionBtn;
}) })
->rawColumns(['action'])->make(true); ->rawColumns(['action'])->make(true);
} }
public function datatablesForReportActivity(Request $request){ public function datatablesForReportActivity(Request $request)
{
$id_activity = $request->query('idact'); $id_activity = $request->query('idact');
$data = $query = AssignMaterial::select(
AssignMaterial::select( DB::raw('(SELECT SUM(assign_material_to_activity.qty_planning) FROM assign_material_to_activity WHERE assign_material_to_activity.activity_id = ram.activity_id) as qty_planning'),
DB::raw('(SELECT SUM(assign_material_to_activity.qty_planning) FROM assign_material_to_activity WHERE assign_material_to_activity.activity_id = ram.activity_id) as qty_planning'), DB::raw('SUM(ram.qty) as qty_sum'),
DB::raw('SUM(ram.qty) as qty_sum'), "m.description as material_name",
"m.description as material_name", "assign_material_to_activity.activity_id"
"assign_material_to_activity.activity_id", )
) ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id");
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") if (!AssignMaterial::join("report_activity_material as ram", "ram.assign_material_id", "=", "assign_material_to_activity.id")->where("assign_material_to_activity.activity_id", $id_activity)->exists()) {
->join("report_activity_material as ram", "ram.assign_material_id", "=", "assign_material_to_activity.id") $query->leftJoin("report_activity_material as ram", "ram.assign_material_id", "=", "assign_material_to_activity.id");
->groupBy("m.description") } else {
$query->join("report_activity_material as ram", "ram.assign_material_id", "=", "assign_material_to_activity.id");
}
$data = $query->groupBy("m.description")
->groupBy("ram.activity_id") ->groupBy("ram.activity_id")
->groupBy("assign_material_to_activity.activity_id") ->groupBy("assign_material_to_activity.activity_id")
->where("assign_material_to_activity.activity_id", $id_activity)->get(); ->where("assign_material_to_activity.activity_id", $id_activity)
->get();
return Datatables::of($data) return Datatables::of($data)
->addIndexColumn() ->addIndexColumn()
// ->addColumn('qty_planning', function($row){ // ->addColumn('qty_planning', function($row){
@ -164,60 +176,61 @@ class AssignMaterialController extends Controller
// ->where("ram.activity_id", $row->activity_id)->first(); // ->where("ram.activity_id", $row->activity_id)->first();
// return $val_qty_act ? $val_qty_act->qty_sum : '-'; // return $val_qty_act ? $val_qty_act->qty_sum : '-';
// }) // })
->addColumn('status_activity', function($row){ ->addColumn('status_activity', function ($row) {
$val_status = AssignMaterial::select("status_activity") $val_status = AssignMaterial::select("status_activity")
->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id') ->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id')
->where('m.description', '=', $row->material_name) ->where('m.description', '=', $row->material_name)
->where("assign_material_to_activity.activity_id", $row->activity_id)->first(); ->where("assign_material_to_activity.activity_id", $row->activity_id)->first();
return $val_status ? $val_status->status_activity : null; return $val_status ? $val_status->status_activity : null;
}) })
->addColumn('start_activity', function($row){ ->addColumn('start_activity', function ($row) {
$val_start = AssignMaterial::select("start_activity") $val_start = AssignMaterial::select("start_activity")
->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id') ->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id')
->where('m.description', '=', $row->material_name) ->where('m.description', '=', $row->material_name)
->where("assign_material_to_activity.activity_id", $row->activity_id)->first(); ->where("assign_material_to_activity.activity_id", $row->activity_id)->first();
return $val_start ? $val_start->start_activity : null; return $val_start ? $val_start->start_activity : null;
}) })
->addColumn('finish_activity', function($row){ ->addColumn('finish_activity', function ($row) {
$val_finish = AssignMaterial::select("finish_activity") $val_finish = AssignMaterial::select("finish_activity")
->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id') ->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id')
->where('m.description', '=', $row->material_name) ->where('m.description', '=', $row->material_name)
->where("assign_material_to_activity.activity_id", $row->activity_id)->first(); ->where("assign_material_to_activity.activity_id", $row->activity_id)->first();
return $val_finish ? $val_finish->finish_activity : null; return $val_finish ? $val_finish->finish_activity : null;
}) })
->addColumn('uom', function($row){ ->addColumn('uom', function ($row) {
$val_uom = RequestMaterial::select("uom") $val_uom = RequestMaterial::select("uom")
->where('description', '=', $row->material_name)->first(); ->where('description', '=', $row->material_name)->first();
return $val_uom ? $val_uom->uom : null; return $val_uom ? $val_uom->uom : null;
}) })
->addColumn('assign_material_id', function($row){ ->addColumn('assign_material_id', function ($row) {
$assignMaterial =AssignMaterial::select('assign_material_to_activity.id')->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") $assignMaterial = AssignMaterial::select('assign_material_to_activity.id')->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('activity_id', $row->activity_id)->where('m.description', $row->material_name)->first(); ->where('activity_id', $row->activity_id)->where('m.description', $row->material_name)->first();
return $assignMaterial ? $assignMaterial->id : null; return $assignMaterial ? $assignMaterial->id : null;
}) })
->addColumn('action', function($row){ ->addColumn('action', function ($row) {
$dataPlan = AssignMaterial::select('assign_material_to_activity.id')->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") $dataPlan = AssignMaterial::select('assign_material_to_activity.id')->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('activity_id', $row->activity_id)->where('m.description', $row->material_name)->first(); ->where('activity_id', $row->activity_id)->where('m.description', $row->material_name)->first();
$actionBtn = '<a href="javascript:void(0)" data-id="'.$dataPlan->id.'" data-activity_id="'.$row->activity_id.'" data-material-id="'.$row->material_id.'" data-material-name="'.$row->material_name.'" class="primary btn btn-primary btn-sm btn-lihat-plan" data-toggle="tooltip" title="Lihat Plan" data-placement="top"><i class="fa fa-align-justify"></i></a>'; $actionBtn = '<a href="javascript:void(0)" data-id="' . $dataPlan->id . '" data-activity_id="' . $row->activity_id . '" data-material-id="' . $row->material_id . '" data-material-name="' . $row->material_name . '" class="primary btn btn-primary btn-sm btn-lihat-plan" data-toggle="tooltip" title="Lihat Plan" data-placement="top"><i class="fa fa-align-justify"></i></a>';
$actionBtn .= '<a href="javascript:void(0)" data-id="'.$dataPlan->id.'" data-activity_id="'.$row->activity_id.'" data-material-id="'.$row->material_id.'" data-material-name="'.$row->material_name.'" class="warning btn btn-warning btn-sm btn-lihat-actual" data-toggle="tooltip" title="Input Progress" data-placement="top"><i class="fa fa-edit" aria-hidden="true"></i></a>'; $actionBtn .= '<a href="javascript:void(0)" data-id="' . $dataPlan->id . '" data-activity_id="' . $row->activity_id . '" data-material-id="' . $row->material_id . '" data-material-name="' . $row->material_name . '" class="warning btn btn-warning btn-sm btn-lihat-actual" data-toggle="tooltip" title="Input Progress" data-placement="top"><i class="fa fa-edit" aria-hidden="true"></i></a>';
return $actionBtn; return $actionBtn;
}) })
->rawColumns(['action'])->make(true); ->rawColumns(['action'])->make(true);
} }
public function ForReportActivityByMaterial(Request $request){ public function ForReportActivityByMaterial(Request $request)
{
$id_activity = $request->idact; $id_activity = $request->idact;
$data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom") $data = AssignMaterial::select("assign_material_to_activity.*", "m.description as material_name", "m.uom as uom")
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('assign_material_to_activity.activity_id', $id_activity)->get(); ->where('assign_material_to_activity.activity_id', $id_activity)->get();
foreach ($data as $key) { foreach ($data as $key) {
$val_qty_sum = ReportActivityMaterial::where('assign_material_id', '=', $key->id)->sum("qty"); $val_qty_sum = ReportActivityMaterial::where('assign_material_id', '=', $key->id)->sum("qty");
} }
$countData = $data->count(); $countData = $data->count();
if($data){ if ($data) {
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200);
}else{ } else {
return response()->json(['status'=>'failed','message'=>'failed get Assign material, please try again later!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'failed get Assign material, please try again later!', 'code' => 400], 400);
} }
} }
} }

80
app/Http/Controllers/AuthController.php

@ -13,7 +13,7 @@ use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Password; use Illuminate\Support\Facades\Password;
use Illuminate\Validation\ValidationException; use Illuminate\Validation\ValidationException;
const URL_EMAIL = 'https://notifapp.odm-iu.com/service-mail/notif_mail.php';
class AuthController extends Controller class AuthController extends Controller
{ {
public function __construct() public function __construct()
@ -24,25 +24,24 @@ class AuthController extends Controller
public function login(Request $request) public function login(Request $request)
{ {
$username = $request->username; $username = $request->username;
$email = $request->email;
$password = $request->password; $password = $request->password;
$remember = $request->remember; $remember = $request->remember;
$is_mobile = $request->is_mobile; $is_mobile = $request->is_mobile;
if (empty($email) && empty($username) || empty($password)) if (empty($username) || empty($password))
return response()->json(['status' => 'error', 'message' => 'You must fill all the fields'], 400); return response()->json(['status' => 'error', 'message' => 'You must fill all the fields'], 400);
$usernameCheck = false; $usernameCheck = false;
$passwordCheck = false; $passwordCheck = false;
if (User::where('username', $username)->orWhere('email', $email)->exists()) if (User::where('username', $username)->exists())
$usernameCheck = true; $usernameCheck = true;
if (User::where('password', md5($password))->exists()) if (User::where('password', md5($password))->exists())
$passwordCheck = true; $passwordCheck = true;
if ($usernameCheck & $passwordCheck) { if ($usernameCheck & $passwordCheck) {
$user = User::where('username', $username)->where('password', md5($password))->orWhere('email', $email)->first(); $user = User::where('username', $username)->where('password', md5($password))->first();
if ($is_mobile) { if ($is_mobile) {
$fcm_token = $request->fcm_token; $fcm_token = $request->fcm_token;
@ -62,6 +61,14 @@ class AuthController extends Controller
$dataRole = Role::find($user->role_id); $dataRole = Role::find($user->role_id);
$dataHierarchy = $this->getDataHierarchy($user->divisi_id, $user->id); $dataHierarchy = $this->getDataHierarchy($user->divisi_id, $user->id);
$configApp = Company::where('id', $user->company_id)->first(); $configApp = Company::where('id', $user->company_id)->first();
if ($configApp) {
$logoLogin = json_decode($configApp->logo_login, true);
$favicon = json_decode($configApp->favicon_image, true);
$logoHeader = json_decode($configApp->logo_header, true);
$configApp->logo_login = $logoLogin;
$configApp->favicon_image = $favicon;
$configApp->logo_header = $logoHeader;
}
if ($configApp) if ($configApp)
$user->configApp = $configApp; $user->configApp = $configApp;
@ -101,4 +108,67 @@ class AuthController extends Controller
return response()->json(['code' => 201, 'message' => "username doesn't match"], 201); return response()->json(['code' => 201, 'message' => "username doesn't match"], 201);
} }
} }
public function sendEmail(Request $request)
{
$hashed = Str::random(15);
$email = $request->email;
$user = User::select('email', 'name')->where('email', $email)->first();
if (!$user) {
return response()->json(['status' => 'error', 'message' => 'e-mail not found '], 400);
} else {
$this->reqHttpCurl($email, $hashed, $user->username, $user->name);
// $updateUser = User::where('email', $email)->update(['password'=> $hashed]);
if (User::where('email', $email)->update(['password' => md5($hashed)]))
return response()->json(['status' => 'success', 'code' => 200, 'message' => 'Password already sent to mail'], 200);
return response()->json(['status' => 'error', 'code' => 400, 'message' => 'e-mail not found '], 400);
}
}
private function reqHttpCurl($email, $password, $username, $name)
{
$postData = [
"to" => $email,
"username" => $name,
"username" => $username,
"password" => $password,
"from" => "app.integrasia@integrasiautama.com",
"alias_from" => "OSPRO",
"subject" => "Registration OSPRO",
"body" => "registration-ospro"
];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => URL_EMAIL, // your preferred url
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30000,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($postData),
CURLOPT_HTTPHEADER => array(
// Set here requred headers
"accept: */*",
"accept-language: en-US,en;q=0.8",
"content-type: application/json",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
print_r(json_decode($response));
}
}
} }

114
app/Http/Controllers/DemoController.php

@ -0,0 +1,114 @@
<?php
namespace App\Http\Controllers;
use App\Models\Demo;
use Illuminate\Http\Request;
class DemoController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'name' => 'required',
'role' => 'required',
'number_phone' => 'required',
'message' => 'required',
]);
$data = $request->all();
$data['created_by'] = '@System';
$data['status'] = 'New Request';
$result = Demo::create($data);
if ($result) {
return response()->json(['status' => 'success', 'data' => $result, 'message' => 'Request Demo successfully!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'Request Demo 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 = Demo::find($id);
if ($result) {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'failed get data Demo, 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 = Demo::find($id);
if ($data) {
$result = $data->update($request->all());
} else {
return response()->json(['status' => 'failed', 'message' => 'data Demo not found!', 'code' => 400], 400);
die();
}
if ($result) {
return response()->json(['status' => 'success', 'message' => 'data Demo successfully updated!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'data Demo failed updated!', 'code' => 400], 400);
}
}
public function delete($id)
{
$data = Demo::find($id);
if ($data) {
$delete = $data->delete();
} else {
return response()->json(['status' => 'failed', 'message' => 'data Demo not found!', 'code' => 400], 400);
die();
}
if ($delete) {
return response()->json(['status' => 'success', 'message' => 'data Demo successfully deleted!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'data Demo failed deleted!', 'code' => 400], 400);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_demo');
$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()
{
$data = Demo::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 Demo, please try again later!', 'code' => 400], 400);
}
}
}

1
app/Models/Demo.php

@ -22,5 +22,6 @@ class Demo extends Model
'created_by', 'created_by',
'updated_at', 'updated_at',
'updated_by', 'updated_by',
'company_id'
]; ];
} }

12
routes/web.php

@ -6,6 +6,7 @@ $router->get('/', function () use ($router) {
$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('/send-email', 'AuthController@sendEmail');
$router->post('/company-management-user/add', 'CompanyController@add'); $router->post('/company-management-user/add', 'CompanyController@add');
$router->post('/company-management-user/search', 'CompanyController@search'); $router->post('/company-management-user/search', 'CompanyController@search');
@ -320,9 +321,9 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->post('/image/search', 'ImageController@search'); $router->post('/image/search', 'ImageController@search');
$router->delete('/image/delete/{id}', 'ImageController@delete'); $router->delete('/image/delete/{id}', 'ImageController@delete');
$router->delete('/image/delete/{id}/{category}', 'ImageController@deleteByRef'); $router->delete('/image/delete/{id}/{category}', 'ImageController@deleteByRef');
$router->delete('/image/multiple-delete/{id}/{category}', 'ImageController@deleteByRefMultiple'); $router->delete('/image/multiple-delete/{id}/{category}', 'ImageController@deleteByRefMultiple');
$router->post('/image/upload', 'ImageController@uploadImage'); $router->post('/image/upload', 'ImageController@uploadImage');
$router->post('/image/multiple-upload', 'ImageController@uploadMultipleImage'); $router->post('/image/multiple-upload', 'ImageController@uploadMultipleImage');
$router->get('/image/{id}/{category}', 'ImageController@getByRefId'); $router->get('/image/{id}/{category}', 'ImageController@getByRefId');
$router->post('/panic-button/add', 'PanicButtonController@add'); $router->post('/panic-button/add', 'PanicButtonController@add');
@ -556,5 +557,12 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->post('/menu-company/search', 'MenuCompanyController@search'); $router->post('/menu-company/search', 'MenuCompanyController@search');
$router->get('/menu-company/management/{id}', 'MenuCompanyController@listMenu'); $router->get('/menu-company/management/{id}', 'MenuCompanyController@listMenu');
$router->get('/menu-company/list', 'MenuCompanyController@list'); $router->get('/menu-company/list', 'MenuCompanyController@list');
$router->post('/demo-management/add', 'DemoController@add');
$router->get('/demo-management/edit/{id}', 'DemoController@edit');
$router->put('/demo-management/update/{id}', 'DemoController@update');
$router->post('/demo-management/search', 'DemoController@search');
$router->delete('/demo-management/delete/{id}', 'DemoController@delete');
$router->get('/demo-management/list', 'DemoController@list');
}); });
}); });

Loading…
Cancel
Save