Browse Source

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

pull/1/head
wahyun 11 months ago
parent
commit
851e13f064
  1. 43
      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. 8
      routes/web.php

43
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',
@ -51,7 +53,8 @@ class AssignMaterialController extends Controller
} }
} }
public function update(Request $request, $id){ public function update(Request $request, $id)
{
if (empty($id) || !is_int((int)$id)) if (empty($id) || !is_int((int)$id))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
@ -83,7 +86,8 @@ class AssignMaterialController extends Controller
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)) if (empty($id) || !is_int((int)$id))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
@ -117,11 +121,14 @@ class AssignMaterialController extends Controller
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)
@ -137,21 +144,26 @@ class AssignMaterialController extends Controller
->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");
->join("report_activity_material as ram", "ram.assign_material_id", "=", "assign_material_to_activity.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()) {
->groupBy("m.description") $query->leftJoin("report_activity_material as ram", "ram.assign_material_id", "=", "assign_material_to_activity.id");
} 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){
@ -205,7 +217,8 @@ class AssignMaterialController extends Controller
->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")

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'
]; ];
} }

8
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');
@ -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