Browse Source

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

Reviewed-on: ibnu/generic-ospro-backend#73
pull/1/head
farhantock 8 months ago
parent
commit
cbe0e1ab5a
  1. 50
      app/Http/Controllers/ActivityController.php
  2. 26
      app/Http/Controllers/AuthController.php
  3. 2
      app/Http/Controllers/Controller.php
  4. 67
      app/Http/Controllers/DashboardBoDController.php
  5. 6
      app/Http/Controllers/ProjectController.php
  6. 1
      app/Http/Controllers/UserToActivityController.php
  7. 34
      app/Models/ProjectType.php
  8. 2
      routes/web.php

50
app/Http/Controllers/ActivityController.php

@ -629,32 +629,48 @@ class ActivityController extends Controller
return response()->json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200); return response()->json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200);
} }
public function delete($id, $company_id) public function delete($id)
{ {
if (!$data = Activity::find($id)) DB::beginTransaction();
$activity_id = (int)$id;
$data = Activity::query()
->from('m_activity as ma')
->select('mp.company_id')
->join('m_proyek as mp','ma.proyek_id','mp.id')
->where('ma.id', $activity_id);
$cloneQuery = clone $data;
if (!$data->exists()) {
DB::rollBack();
return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data not found!', 'code' => 404], 404); return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data not found!', 'code' => 404], 404);
$this->deleteRelative($id, $company_id); }
if (!$data->delete())
return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'data activity failed deleted!', 'code' => 500], 500); $this->deleteRelative($activity_id, $cloneQuery->first()->company_id);
return response()->json(['status' => 'success', "action" => "deleted", 'message' => 'data activity successfully deleted!', 'code' => 200], 200); if (!$data->delete()) {
DB::rollBack();
return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data activity failed deleted!', 'code' => 500], 500);
}
DB::commit();
return response()->json(['status' => 'success', "action" => "deleted", 'message' => 'Data activity successfully deleted!', 'code' => 200], 200);
} }
private function deleteRelative($activity_id, $company_id) private function deleteRelative($activity_id, $company_id)
{ {
UserToActivity::where('activity_id', $activity_id)->delete(); DB::transaction(function() use($activity_id, $company_id) {
AssignMaterial::where('activity_id', $activity_id)->delete(); UserToActivity::where('activity_id', $activity_id)->delete();
$dataAd = ActivityDokumen::where("activity_id", $activity_id)->get(); AssignMaterial::where('activity_id', $activity_id)->delete();
$company = Company::find($company_id); $dataAd = ActivityDokumen::where("activity_id", $activity_id)->get();
if($company) { $company = Company::find($company_id);
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); if($company) {
foreach ($dataAd as $ad) { $destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
if (file_exists($destinationPath['pathActivityDocument'] . $ad->file)) { foreach ($dataAd as $ad) {
unlink($destinationPath['pathActivityDocument'] . $ad->file); if (file_exists($destinationPath['pathActivityDocument'] . $ad->file)) {
unlink($destinationPath['pathActivityDocument'] . $ad->file);
}
} }
ActivityDokumen::where("activity_id", $activity_id)->delete();
} }
ActivityDokumen::where("activity_id", $activity_id)->delete(); });
}
} }
public function getUpdate($id) public function getUpdate($id)

26
app/Http/Controllers/AuthController.php

@ -35,14 +35,18 @@ class AuthController extends Controller
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);
} }
if (User::where('username', $username)->exists()) { $userQuery = User::query()
->where('username',$username);
if ($userQuery->exists()) {
$usernameCheck = true; $usernameCheck = true;
} $passwordValue = $userQuery->first()->password;
if (User::where('password', md5($password))->exists()) { if($passwordValue === md5($password)) {
$passwordCheck = true; $passwordCheck = true;
}
} }
if ($usernameCheck & $passwordCheck) { if ($usernameCheck && $passwordCheck) {
$user = User::where([['username', $username],['password', md5($password)]])->first(); $user = User::where([['username', $username],['password', md5($password)]])->first();
$checkExpiredOspro = $this->setExpiredTimeOspro($user['company_id']); $checkExpiredOspro = $this->setExpiredTimeOspro($user['company_id']);
if($checkExpiredOspro === false && $user['company_id'] != null) { if($checkExpiredOspro === false && $user['company_id'] != null) {
@ -113,14 +117,10 @@ class AuthController extends Controller
), ),
]); ]);
} else { } else {
if (!$usernameCheck && !$passwordCheck) { if (!$usernameCheck || !$passwordCheck) {
return response()->json(['code' => 201, 'message' => "Username and password doesn't match"], 201); return response()->json(['code' => 201, 'message' => "Username or password doesn't match"], 201);
} } else {
if (!$passwordCheck) { return response()->json(['code' => 500, 'message' => "Server error"], 500);
return response()->json(['code' => 201, 'message' => "Password doesn't match"], 201);
}
if (!$usernameCheck) {
return response()->json(['code' => 201, 'message' => "Username doesn't match"], 201);
} }
} }
} }

2
app/Http/Controllers/Controller.php

@ -185,7 +185,7 @@ class Controller extends BaseController
$countCreate = true; $countCreate = true;
} }
if ($countCreate) { if ($countCreate && isset($maximumSize)) { // kondisi $maximumSize sementara karena blm ada paket enterprise
if (floatval($totalSize) > floatval($maximumSize)) { if (floatval($totalSize) > floatval($maximumSize)) {
$countCreate = false; $countCreate = false;
} }

67
app/Http/Controllers/DashboardBoDController.php

@ -262,7 +262,6 @@ class DashboardBoDController extends Controller
foreach ($projects as $project) { foreach ($projects as $project) {
$resp = null; $resp = null;
if ($project->kode_sortname != "") { if ($project->kode_sortname != "") {
// $resp = $this->getInvoiceIntegration($project->kode_sortname);
array_push($return, [ array_push($return, [
'project' => $project->nama, 'project' => $project->nama,
'project_code' => $project->kode_sortname, 'project_code' => $project->kode_sortname,
@ -281,22 +280,28 @@ class DashboardBoDController extends Controller
public function getTotalProjectPerScheduleHealth($role_name, $company_id, $all_project, $hierarchy) public function getTotalProjectPerScheduleHealth($role_name, $company_id, $all_project, $hierarchy)
{ {
$role = urldecode($role_name); $role = urldecode($role_name);
$replaceHierarchy = preg_replace('/[\[\]]/', '', $hierarchy);
$return = [ $return = [
'behind-schedule' => 0, 'behind-schedule' => 0,
'warning' => 0, 'warning' => 0,
'on-schedule' => 0, 'on-schedule' => 0,
]; ];
$divisi = Divisi::query()
->where('company_id',$company_id)
->pluck('id');
$projects = null; $projects = null;
if ($role === 'Super Admin') { if ($role === 'Super Admin') {
$projects = Project::get(); $projects = Project::get();
} elseif ($all_project) { } elseif ($all_project == 'true') {
$projects = Project::where('company_id', $company_id) $projects = Project::whereIn('divisi_id',$divisi)
->get(); ->where('company_id', $company_id)
->get();
} else { } else {
$projects = Project::where('created_by_id', $hierarchy) $projects = Project::whereIn('divisi_id',$divisi)
->get(); ->where('created_by_id', $replaceHierarchy)
->get();
} }
foreach ($projects as $index => $project) { foreach ($projects as $index => $project) {
@ -386,6 +391,8 @@ class DashboardBoDController extends Controller
public function getTotalProjectPerBudgetHealth($role_name, $company_id, $all_project, $hierarchy) public function getTotalProjectPerBudgetHealth($role_name, $company_id, $all_project, $hierarchy)
{ {
$role = urldecode($role_name); $role = urldecode($role_name);
$replaceHierarchy = preg_replace('/[\[\]]/', '', $hierarchy);
$response = [ $response = [
'data' => [ 'data' => [
'overrun' => 0, 'overrun' => 0,
@ -393,43 +400,47 @@ class DashboardBoDController extends Controller
'on-budget' => 0, 'on-budget' => 0,
] ]
]; ];
$divisi = Divisi::query()
->where('company_id',$company_id)
->pluck('id');
// arr overrun
if ($role === 'Super Admin') { if ($role === 'Super Admin') {
$response['data']['overrun'] = Project::where('budget_health', 'overrun') $response['data']['overrun'] = Project::where('budget_health', 'overrun')
->count(); ->count();
} elseif ($all_project) { } elseif ($all_project == 'true') {
$response['data']['overrun'] = Project::where('budget_health', 'overrun') $response['data']['overrun'] = Project::whereIn('divisi_id',$divisi)
->where('company_id', $company_id) ->where([['budget_health', 'overrun'],['company_id', $company_id]])
->count(); ->count();
} else { } else {
$response['data']['overrun'] = Project::where('budget_health', 'overrun') $response['data']['overrun'] = Project::whereIn('divisi_id',$divisi)
->where('created_by_id', $hierarchy) ->where([['budget_health', 'overrun'],['created_by_id', $replaceHierarchy]])
->count(); ->count();
} }
// arr warning
if ($role === 'Super Admin') { if ($role === 'Super Admin') {
$response['data']['overrun'] = Project::where('budget_health', 'warning')
->count();
} elseif ($all_project) {
$response['data']['warning'] = Project::where('budget_health', 'warning') $response['data']['warning'] = Project::where('budget_health', 'warning')
->where('company_id', $company_id) ->count();
} elseif ($all_project == 'true') {
$response['data']['warning'] = Project::whereIn('divisi_id',$divisi)
->where([['budget_health', 'warning'],['company_id', $company_id]])
->count(); ->count();
} else { } else {
$response['data']['warning'] = Project::where('budget_health', 'warning') $response['data']['warning'] = Project::whereIn('divisi_id',$divisi)
->where('created_by_id', $hierarchy) ->where([['budget_health', 'warning'],['created_by_id', $replaceHierarchy]])
->count(); ->count();
} }
// arr on-budget
if ($role === 'Super Admin') { if ($role === 'Super Admin') {
Log::info('on-budget');
$response['data']['on-budget'] = Project::where('budget_health', 'on-budget') $response['data']['on-budget'] = Project::where('budget_health', 'on-budget')
->count(); ->count();
} elseif ($all_project) { } elseif ($all_project == 'true') {
$response['data']['on-budget'] = Project::where('budget_health', 'on-budget') $response['data']['on-budget'] = Project::whereIn('divisi_id',$divisi)
->where('company_id', $company_id) ->where([['company_id', $company_id],['budget_health', 'on-budget']])
->count(); ->count();
} else { } else {
$response['data']['on-budget'] = Project::where('budget_health', 'on-budget') $response['data']['on-budget'] = Project::whereIn('divisi_id',$divisi)
->where('created_by_id', $hierarchy) ->where([['budget_health', 'on-budget'],['created_by_id', $replaceHierarchy]])
->count(); ->count();
} }
return response()->json($response, 200); return response()->json($response, 200);
@ -437,10 +448,8 @@ class DashboardBoDController extends Controller
private function countTotalProjectByBudgetHealthInDivision($divisi, $health) private function countTotalProjectByBudgetHealthInDivision($divisi, $health)
{ {
return Project::where('divisi_id', $divisi) $project = Project::where([['divisi_id', $divisi],['budget_health', $health]])->count();
/* ->orWhere('akhir_proyek', 'like', $year) */ return $project;
->where('budget_health', $health)
->count();
} }
@ -476,8 +485,6 @@ class DashboardBoDController extends Controller
unset($division->children); unset($division->children);
$division->budgetData = $budgetData; $division->budgetData = $budgetData;
} }
foreach ($divisions as $division) {
}
return response()->json([ return response()->json([
'data' => [ 'data' => [
$divisions $divisions

6
app/Http/Controllers/ProjectController.php

@ -181,9 +181,9 @@ class ProjectController extends Controller
$data = Project::find($id); $data = Project::find($id);
$dateNow = Carbon::now(); $dateNow = Carbon::now();
if ($data) { if ($data) {
// $this->deleteRelative($id, $company_id); $this->deleteRelative($id, $company_id);
// if ($data->delete()) { if ($data->delete()) {
if ($data->update(['deleted_at' => $dateNow, 'deleted_by_id' => $this->currentId])) { // if ($data->update(['deleted_at' => $dateNow, 'deleted_by_id' => $this->currentId])) {
DB::commit(); DB::commit();
return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200); return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200);
} else { } else {

1
app/Http/Controllers/UserToActivityController.php

@ -153,6 +153,7 @@ class UserToActivityController extends Controller
$builder->groupBy("selfTable.start_date"); $builder->groupBy("selfTable.start_date");
$builder->groupBy("selfTable.end_date"); $builder->groupBy("selfTable.end_date");
$builder->groupBy("assign_material_to_activity.qty_planning"); $builder->groupBy("assign_material_to_activity.qty_planning");
$builder->groupBy("assign_material_to_activity.id");
$builder->groupBy("m_version_gantt.name_version"); $builder->groupBy("m_version_gantt.name_version");
$dataGet = $builder->get(); $dataGet = $builder->get();
$totalRecord = $countBuilder->count(); $totalRecord = $countBuilder->count();

34
app/Models/ProjectType.php

@ -1,17 +1,17 @@
<?php <?php
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
class ProjectType extends Model class ProjectType extends Model
{ {
protected $table = 'm_type_proyek'; protected $table = 'm_type_proyek';
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [ protected $fillable = [
'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id' 'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id', 'is_multiLocation'
]; ];
} }

2
routes/web.php

@ -272,7 +272,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$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');
$router->put('/task/update-regular/{id}', 'ActivityController@updateRegular'); $router->put('/task/update-regular/{id}', 'ActivityController@updateRegular');
$router->delete('/task/{id}/{company_id}', 'ActivityController@delete'); $router->delete('/task/{id}', 'ActivityController@delete');
$router->get('/task/get-update/{id}', 'ActivityController@getUpdate'); $router->get('/task/get-update/{id}', 'ActivityController@getUpdate');
$router->post('/tmp-import/upload', 'ActivityController@uploadTmpImport'); $router->post('/tmp-import/upload', 'ActivityController@uploadTmpImport');

Loading…
Cancel
Save