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. 2
      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);
}
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);
$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)
{
UserToActivity::where('activity_id', $activity_id)->delete();
AssignMaterial::where('activity_id', $activity_id)->delete();
$dataAd = ActivityDokumen::where("activity_id", $activity_id)->get();
$company = Company::find($company_id);
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
foreach ($dataAd as $ad) {
if (file_exists($destinationPath['pathActivityDocument'] . $ad->file)) {
unlink($destinationPath['pathActivityDocument'] . $ad->file);
DB::transaction(function() use($activity_id, $company_id) {
UserToActivity::where('activity_id', $activity_id)->delete();
AssignMaterial::where('activity_id', $activity_id)->delete();
$dataAd = ActivityDokumen::where("activity_id", $activity_id)->get();
$company = Company::find($company_id);
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
foreach ($dataAd as $ad) {
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)

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

2
app/Http/Controllers/Controller.php

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

67
app/Http/Controllers/DashboardBoDController.php

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

6
app/Http/Controllers/ProjectController.php

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

1
app/Http/Controllers/UserToActivityController.php

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

2
app/Models/ProjectType.php

@ -12,6 +12,6 @@ class ProjectType extends Model
const UPDATED_AT = 'updated_at';
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->put('/task/{id}', 'ActivityController@update');
$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->post('/tmp-import/upload', 'ActivityController@uploadTmpImport');

Loading…
Cancel
Save