farhantock 7 months ago
parent
commit
f67a33fb27
  1. 28
      app/Console/Commands/CalculateProgressGantt.php
  2. 3
      app/Console/Kernel.php
  3. 898
      app/Helpers/MasterFunctionsHelper.php
  4. 234
      app/Http/Controllers/ActivityController.php
  5. 60
      app/Http/Controllers/ActivityDokumenController.php
  6. 79
      app/Http/Controllers/AssignMaterialController.php
  7. 5
      app/Http/Controllers/AssignToolsController.php
  8. 159
      app/Http/Controllers/AuthController.php
  9. 94
      app/Http/Controllers/CompanyController.php
  10. 115
      app/Http/Controllers/ContactSalesController.php
  11. 197
      app/Http/Controllers/Controller.php
  12. 420
      app/Http/Controllers/DashboardBoDController.php
  13. 116
      app/Http/Controllers/DemoController.php
  14. 37
      app/Http/Controllers/DivisiController.php
  15. 40
      app/Http/Controllers/FolderDocumentProyekController.php
  16. 73
      app/Http/Controllers/HierarchyFtthController.php
  17. 2
      app/Http/Controllers/HolidayController.php
  18. 200
      app/Http/Controllers/HumanResourceController.php
  19. 203
      app/Http/Controllers/ImageController.php
  20. 115
      app/Http/Controllers/KanbanBoardController.php
  21. 258
      app/Http/Controllers/KanbanCardController.php
  22. 45
      app/Http/Controllers/MenuCompanyController.php
  23. 22
      app/Http/Controllers/MenuController.php
  24. 92
      app/Http/Controllers/ProductTransactionController.php
  25. 351
      app/Http/Controllers/ProjectCarausellController.php
  26. 465
      app/Http/Controllers/ProjectController.php
  27. 74
      app/Http/Controllers/ProjectDokumenController.php
  28. 93
      app/Http/Controllers/ProjectExpenditureController.php
  29. 93
      app/Http/Controllers/ProjectFinancialHealthController.php
  30. 93
      app/Http/Controllers/ProjectInvoiceController.php
  31. 3
      app/Http/Controllers/ProjectRoleController.php
  32. 93
      app/Http/Controllers/ProjectScheduleHealthController.php
  33. 81
      app/Http/Controllers/RefferalCodeController.php
  34. 2
      app/Http/Controllers/ReportActivityController.php
  35. 31
      app/Http/Controllers/ReportActivityMaterialController.php
  36. 10
      app/Http/Controllers/RoleController.php
  37. 47
      app/Http/Controllers/RoleMenuController.php
  38. 344
      app/Http/Controllers/UserRegisterController.php
  39. 77
      app/Http/Controllers/UserToActivityController.php
  40. 28
      app/Http/Controllers/UserToProyekController.php
  41. 16
      app/Http/Controllers/VersionGanttController.php
  42. 2
      app/Models/Absent.php
  43. 19
      app/Models/Activity.php
  44. 23
      app/Models/AssignMaterial.php
  45. 2
      app/Models/Broadcast.php
  46. 3
      app/Models/ChecklistK3.php
  47. 5
      app/Models/Company.php
  48. 27
      app/Models/ContactSales.php
  49. 26
      app/Models/Demo.php
  50. 4
      app/Models/HumanResource.php
  51. 17
      app/Models/KanbanBoard.php
  52. 17
      app/Models/KanbanCard.php
  53. 2
      app/Models/PanicButton.php
  54. 2
      app/Models/Presence.php
  55. 25
      app/Models/ProductTransaction.php
  56. 8
      app/Models/Project.php
  57. 17
      app/Models/ProjectExpenditure.php
  58. 17
      app/Models/ProjectFinancialHealth.php
  59. 17
      app/Models/ProjectInvoice.php
  60. 2
      app/Models/ProjectRole.php
  61. 17
      app/Models/ProjectScheduleHealth.php
  62. 2
      app/Models/ProjectType.php
  63. 28
      app/Models/RefferalCode.php
  64. 3
      app/Models/ReportK3.php
  65. 2
      app/Models/Role.php
  66. 2
      app/Models/RoleMenu.php
  67. 17
      app/Models/User.php
  68. 31
      app/Models/UserToActivity.php
  69. 2733
      composer.lock
  70. 120
      rest-client.http
  71. 130
      routes/web.php

28
app/Console/Commands/CalculateProgressGantt.php

@ -0,0 +1,28 @@
<?php
namespace App\Console\Commands;
use App\Models\HierarchyFtth;
use Illuminate\Console\Command;
use App\Helpers\MasterFunctionsHelper;
use App\Models\Project;
class CalculateProgressGantt extends Command
{
protected $signature = 'calculate:progressgantt {hierarchy_id}';
protected $description = 'Calculate Progress Gantt';
public function handle()
{
$hierarchy_id = $this->argument('hierarchy_id');
$hierarchy = HierarchyFtth::findOrFail($hierarchy_id);
$project = Project::find($hierarchy->project_id);
$data = MasterFunctionsHelper::calculateSCurveForProgressTree($hierarchy_id);
$hierarchy->bobot_planning = 100;
$hierarchy->progress =round(((int) end($data[0]['data']['percentageReal']) / (int) end($data[0]['data']['percentagePlan'])) * 100, 2);
$hierarchy->save();
}
}

3
app/Console/Kernel.php

@ -14,7 +14,8 @@ class Kernel extends ConsoleKernel
*/
protected $commands = [
Commands\syncHumanResourceIntegration::class,
Commands\CalculateSCurve::class
Commands\CalculateSCurve::class,
Commands\CalculateProgressGantt::class
];
/**

898
app/Helpers/MasterFunctionsHelper.php

File diff suppressed because it is too large Load Diff

234
app/Http/Controllers/ActivityController.php

@ -1,9 +1,11 @@
<?php
namespace App\Http\Controllers;
use DateTime;
use App\Models\Link;
use App\Models\User;
use App\Models\Company;
use App\Models\Project;
use App\Models\Activity;
use App\Models\TmpImport;
@ -15,9 +17,11 @@ use App\Models\AssignMaterial;
use App\Models\UserToActivity;
use App\Models\ActivityDokumen;
use App\Models\CommentActivity;
use App\Models\ProductTransaction;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use App\Helpers\MasterFunctionsHelper;
use Carbon\Carbon;
class ActivityController extends Controller
{
@ -37,6 +41,94 @@ class ActivityController extends Controller
return response()->json(['status' => 'success', 'data' => $dataGantt, 'code' => 200], 200);
}
public function activitySCurve($proyek_id, $gantt_id)
{
// "data": [
// {
// "id": 1,
// "text": "Office itinerancy",
// "type": "project",
// "order": "10",
// "progress": 0.4,
// "open": true,
// "user":"0",
// "start_date": "02-04-2024 00:00",
// "duration": 17,
// "end_date": "19-04-2024 00:00",
// "parent": 0
// }
// ],
// "links": [
// {
// "id": "1",
// "source": "1",
// "target": "2",
// "type": "1"
// }
// ]
// }
$checkHeader = Activity::where('version_gantt_id', $gantt_id)->where('type_activity', 'header')->count();
$finalData = [];
if ($checkHeader > 0) {
$dataHeader = Activity::select('id', 'name as text', 'type_activity as type', 'persentase_progress as progress', 'start_date', 'end_date', 'duration', 'parent_id', 'sortorder as order')->where('version_gantt_id', $gantt_id)->where('type_activity', 'header')->first();
// $dataHeader->start_date1 = isset($dataHeader->start) ? date_format(date_create($dataHeader->start), "d-m-Y H:i") : NULL;
// $dataHeader->end_date1 = isset($dataHeader->end) ? date_format(date_create($dataHeader->end), "d-m-Y H:i") : NULL;
$dataHeader->progress = $dataHeader->progress / 100;
$dataHeader->type = "project";
$dataHeader->text = $dataHeader->name;
$finalData[] = $dataHeader;
$data = Activity::select('id', 'name as text', 'type_activity as type', 'persentase_progress as progress', 'start_date', 'end_date', 'duration', 'parent_id', 'sortorder as order')->where('version_gantt_id', $gantt_id)->where('parent_id', $dataHeader->id)->orderBy('sortorder', 'asc')->get();
} else {
$data = Activity::select('id', 'name as text', 'type_activity as type', 'persentase_progress as progress', 'start_date', 'end_date', 'duration', 'parent_id', 'sortorder as order')->where('version_gantt_id', $gantt_id)->whereNull('parent_id')->orderBy('sortorder', 'asc')->get();
}
foreach ($data as $objRow) {
$type = "project";
$dataChildren = $this->getChildrenSCurve($gantt_id, $objRow->id);
if ($objRow->type_activity == "milestone")
$type = $objRow->type_activity;
if (empty($dataChildren))
$type = "task";
$objRow->parent = $objRow->parent_id ? $objRow->parent_id : null;
// $objRow->start_date = isset($objRow->start) ? date_format(date_create($objRow->start), "d-m-Y H:i") : NULL;
// $objRow->end_date1 = isset($objRow->end) ? date_format(date_create($objRow->end), "d-m-Y H:i") : NULL;
$objRow->progress = $objRow->persentase_progress / 100;
$objRow->type = $type;
$finalData[] = $objRow;
$finalData = array_merge($finalData, $dataChildren);
}
$dataLink = Link::where('version_gantt_id', $gantt_id)->get();
$finalLink = [];
foreach ($dataLink as $objRow) {
$dataRow = array(
'id' => $objRow->id,
'source' => $objRow->s_activity_id,
'target' => $objRow->t_activity_id,
'type' => $objRow->type_link,
'code' => $objRow->code_link
);
if ($objRow->lag)
$dataRow['lag'] = $objRow->lag;
$finalLink[] = $dataRow;
}
$resultData = array(
"data" => $finalData,
"links" => $finalLink
);
return response()->json(['status' => 'success', 'data' => $resultData, 'code' => 200], 200);
}
private function getDataActivity($id)
{
$checkHeader = Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->count();
@ -116,6 +208,43 @@ class ActivityController extends Controller
return $resultData;
}
private function getChildrenSCurve($gantt_id, $parent_id)
{
$finalData = [];
$data = Activity::select('id', 'name as text', 'type_activity as type', 'bobot_planning', 'persentase_progress as progress', 'start_date', 'end_date', 'duration', 'parent_id', 'sortorder as order')
->where('version_gantt_id', $gantt_id)->where('parent_id', $parent_id)->orderBy('sortorder', 'asc')->get();
foreach ($data as $objRow) {
$objRow->parent = $parent_id;
$objRow->progress = (float) $objRow->bobot_planning / 100;
// $objRow->start_date1 = isset($objRow->start) ? date_format(date_create($objRow->start), "d-m-Y H:i") : NULL;
// $objRow->end_date1 = isset($objRow->end) ? date_format(date_create($objRow->end), "d-m-Y H:i") : NULL;
$dataChildren = $this->getChildrenSCurve($gantt_id, $objRow->id);
if ($objRow->type_activity == "milestone") {
$objRow->type = $objRow->type_activity;
// $objRow->actual_start = isset($objRow->actual_start) ? date_format(date_create($objRow->actual_start), "d-m-Y") : NULL;
} elseif (empty($dataChildren)) {
$objRow->type = "task";
// $objRow->actual_start = isset($objRow->actual_start) ? date_format(date_create($objRow->actual_start), "d-m-Y") : NULL;
// $objRow->actual_end = isset($objRow->actual_end) ? date_format(date_create($objRow->actual_end), "d-m-Y") : NULL;
// if(isset($objRow->actual_start)){
// $objRow->auto_scheduling = false;
// }
} else {
$objRow->type = "project";
// $actualStart = $this->getFirstLastDateActivity($objRow->id, "start");
// $objRow->actual_start = isset($actualStart) ? date_format(date_create($actualStart), "d-m-Y") : NULL;
// $actualEnd = $this->getFirstLastDateActivity($objRow->id, "end");
// $objRow->actual_end = isset($actualEnd) ? date_format(date_create($actualEnd), "d-m-Y") : NULL;
}
$finalData[] = $objRow;
$finalData = array_merge($finalData, $dataChildren);
}
return $finalData;
}
private function getChildren($gantt_id, $parent_id)
{
$finalData = [];
@ -156,7 +285,8 @@ class ActivityController extends Controller
return $finalData;
}
public function getActivityFirst($parentId){
public function getActivityFirst($parentId)
{
$activity = Activity::where('parent_id', $parentId)->orderByRaw('actual_start ASC')->first();
if (!isset($activity)) {
return null;
@ -167,10 +297,10 @@ class ActivityController extends Controller
} else {
return $this->getActivityFirst($activity->id);
}
}
public function getFirstLastDateActivity($id, $params){
public function getFirstLastDateActivity($id, $params)
{
if ($params == "start") {
$data = Activity::select('id', 'parent_id', 'name', 'actual_start')->where('parent_id', $id)->get();
} else {
@ -182,7 +312,6 @@ class ActivityController extends Controller
$activity = $this->getchildActivityForActual($val->id, $params);
$dataFinal[] = $val;
$dataFinal = array_merge($dataFinal, $activity);
}
if ($params == "start") {
$actualStartValues = array_column(array_filter($dataFinal, function ($item) {
@ -197,7 +326,7 @@ class ActivityController extends Controller
$actualEndValues = array_column(array_filter($dataFinal, function ($item) {
return isset($item['actual_end']);
}), 'actual_end');
$returnActualStartOrEnd = count($actualEndValues) == count($dataFinal) ? max($actualEndValues) : null;
$returnActualStartOrEnd = count($actualEndValues) == count($dataFinal) && count($actualEndValues) > 0 ? max($actualEndValues) : null;
if (isset($parent)) {
$parent->actual_end = $returnActualStartOrEnd;
$parent->save();
@ -208,7 +337,8 @@ class ActivityController extends Controller
return $returnActualStartOrEnd;
}
public function getchildActivityForActual($parent, $params){
public function getchildActivityForActual($parent, $params)
{
if ($params == "start") {
$activity = Activity::select('id', 'actual_start')->where('parent_id', $parent)->get();
} else {
@ -223,7 +353,8 @@ class ActivityController extends Controller
return $temp;
}
public function getActivityLast($parentId){
public function getActivityLast($parentId)
{
$activity = Activity::where('parent_id', $parentId)->orderByRaw('actual_end DESC')->first();
if (!isset($activity)) {
return null;
@ -234,7 +365,6 @@ class ActivityController extends Controller
} else {
return $this->getActivityLast($activity->id);
}
}
private function cloneTemplate($id, $proyek_id, $hierarchy_ftth_id = null)
@ -422,7 +552,8 @@ class ActivityController extends Controller
return response()->json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200);
}
public function updateSchedule($ganttId){
public function updateSchedule($ganttId)
{
if (empty($ganttId) || !is_int((int) $ganttId))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
@ -479,6 +610,7 @@ class ActivityController extends Controller
$activityToUpdate = $activity->firstWhere('id', $entity['data']['id']);
$entity['data']['name'] = $entity['data']['text'];
$entity['data']['persentase_progress'] = $entity['data']['progress'] * 100;
$entity['data']['type_activity'] = $entity['data']['type'] ?? 'task';
if (isset($entity['data']['rencana_biaya'])) {
$entity['data']['rencana_biaya'] = str_replace(",", ".", $entity['data']['rencana_biaya']);
}
@ -499,27 +631,47 @@ class ActivityController extends Controller
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);
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)
private function deleteRelative($activity_id, $company_id)
{
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($this->pathActivityDocument.$ad->file)){
unlink($this->pathActivityDocument.$ad->file);
if (file_exists($destinationPath['pathActivityDocument'] . $ad->file)) {
unlink($destinationPath['pathActivityDocument'] . $ad->file);
}
}
ActivityDokumen::where("activity_id", $activity_id)->delete();
}
});
}
public function getUpdate($id)
{
@ -562,6 +714,7 @@ class ActivityController extends Controller
'selfTable.name',
'persentase_progress',
'selfTable.start_date',
'selfTable.id',
'selfTable.end_date',
'selfTable.planned_start',
'selfTable.planned_end',
@ -571,9 +724,10 @@ class ActivityController extends Controller
'm_version_gantt.name_version',
DB::raw('user_names.user_name as user_name'),
DB::raw('SUM(report_activity_material.qty) as qty'),
'assign_material_to_activity.qty_planning',
// DB::raw('SUM(assign_material_to_activity.qty_planning) as qty_planning'),
'assign_material_to_activity.id as join_third_id'
)
->addSelect(DB::raw('(SELECT SUM(assign_material_to_activity.qty_planning) FROM assign_material_to_activity WHERE assign_material_to_activity.activity_id = report_activity_material.activity_id) as qty_planning'))
->join('m_version_gantt', 'm_version_gantt.id', '=', 'selfTable.version_gantt_id')
->leftJoin('assign_hr_to_activity', 'assign_hr_to_activity.activity_id', '=', 'selfTable.id')
->leftJoin('report_activity_material', 'report_activity_material.activity_id', '=', 'selfTable.id')
@ -584,13 +738,12 @@ class ActivityController extends Controller
GROUP BY activity_id) as user_names'), function ($join) {
$join->on('user_names.activity_id', '=', 'selfTable.id');
})
->where('assign_material_to_activity.id', '=', DB::raw('report_activity_material.assign_material_id'))
->groupBy('selfTable.id')
->groupBy('selfTable.name')
->groupBy('selfTable.persentase_progress')
->groupBy('m_version_gantt.name_version')
->groupBy('assign_material_to_activity.qty_planning')
->groupBy('assign_material_to_activity.id')
->groupBy('user_names.user_name')
->groupBy('report_activity_material.activity_id')
->get();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet], 200);
}
@ -651,8 +804,7 @@ class ActivityController extends Controller
$data['activities'][$key]['weight'] = $parentWeight / $siblingsCount;
}
}
;
};
}
$projectStart = Project::select('mulai_proyek')->where('id', $projectId)->first();
foreach ($data['activities'] as $i => $activity_row) {
@ -991,13 +1143,29 @@ class ActivityController extends Controller
public function uploadTmpImport(Request $request)
{
DB::beginTransaction();
if ($request->hasFile('dokumen')) {
$document = $request->file('dokumen');
$gantt_id = $request->gantt_id;
$name = $document->getClientOriginalName();
$timeNow = Carbon::now();
$originalFilename = $document->getClientOriginalName();
$extension = pathinfo($originalFilename, PATHINFO_EXTENSION);
$filename = pathinfo($originalFilename, PATHINFO_FILENAME);
$name = $filename . '_' . $timeNow->format('d-m-y-His') . '.' . $extension;
// Limited Storage
$company = Company::where('company_name', $request->company_name)->first();
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$getLimitStorage = $this->setLimitsStorage($company, $document, $destinationPath['pathTmpImport'], $destinationPath);
}
if (isset($getLimitStorage)) {
if($getLimitStorage === false) {
DB::rollBack();
return response()->json(['status' => 'failed', 'message' => 'Limited storage maximum!', 'code' => 500], 500);
}
$result = $document->move($this->pathTmpImport, $name);
if ($result) {
$data = [
'gantt_id' => (int) $gantt_id,
'file' => $name,
@ -1006,15 +1174,18 @@ class ActivityController extends Controller
$result = TmpImport::create($data);
if (!$result) {
unlink($this->pathTmpImport . $name);
if (!$document->move($destinationPath['pathTmpImport'], $name) && $result) {
unlink($destinationPath['pathTmpImport'].$name);
DB::rollBack();
return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500);
}
DB::commit();
return response()->json(['status' => 'success', 'message' => 'Upload successful!', 'code' => 200], 200);
}
DB::rollBack();
return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500);
}
DB::rollBack();
return response()->json(['status' => 'failed', 'message' => 'File is required!', 'code' => 400], 400);
}
@ -1030,4 +1201,9 @@ class ActivityController extends Controller
}
return response()->json(['status' => 'success', 'data' => $request, 'message' => 'Update successful!', 'code' => 200], 200);
}
// public function recalculateProject($by, $id){
// // query get activity
// $cekActivity =
// }
}

60
app/Http/Controllers/ActivityDokumenController.php

@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Models\Company;
use Illuminate\Http\Request;
use App\Models\ActivityDokumen;
@ -16,50 +17,53 @@ class ActivityDokumenController extends Controller
return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200);
}
public function delete($id)
public function delete($id, $company_id)
{
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400);
$document = ActivityDokumen::find($id);
if(!$document)
if(!$document) {
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
if(file_exists($this->pathActivityDocument.$document->file))
unlink($this->pathActivityDocument.$document->file);
}
$company = Company::find($company_id);
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
if(file_exists($destinationPath['pathActivityDocument'].$document->file)){
unlink($destinationPath['pathActivityDocument'].$document->file);
}
}
$document->delete();
return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200);
}
public function uploadProjectDokumen(Request $request)
{
if(!$request->hasFile('dokumen'))
if(!$request->hasFile('dokumen')) {
return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400);
}
$activity_id = $request->activity_id;
$document = $request->file('dokumen');
$name = $document->getClientOriginalName();
$result = $document->move($this->pathActivityDocument, $name);
if(!$result)
$company = Company::find($request->company_id);
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$result = $document->move($destinationPath['pathActivityDocument'], $name);
}
if(!$result || !$company) {
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
}
$data = [
'activity_id' => (int)$activity_id,
'file' => $name,
'description' => $request->description
];
$result = ActivityDokumen::create($data);
if(!$result){
unlink($this->pathActivityDocument.$name);
if(!$result || !$company) {
unlink($destinationPath['pathActivityDocument'].$name);
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
}
return response()->json(['status'=>'success','message'=>'Upload success!','code'=>200], 200);
}
@ -75,21 +79,23 @@ class ActivityDokumenController extends Controller
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
public function downloadDokumen($id)
public function downloadDokumen($id, $company_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);
}
$document = ActivityDokumen::find($id);
if(!$document)
$company = Company::find($company_id);
if(!$document || !$company) {
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400);
if(file_exists($this->pathActivityDocument.$document->file)){
$pathToFile = $this->pathActivityDocument.$document->file;
}
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
if(file_exists($destinationPath['pathActivityDocument'].$document->file)) {
$pathToFile = $destinationPath['pathActivityDocument'].$document->file;
return response()->download($pathToFile);
}
}
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400);
}
}

79
app/Http/Controllers/AssignMaterialController.php

@ -7,17 +7,20 @@ use App\Models\AssignMaterial;
use App\Models\RequestMaterial;
use App\Models\Activity;
use App\Models\ReportActivityMaterial;
use Datatables;
use Illuminate\Support\Facades\DB;
use Yajra\Datatables\Datatables;
class AssignMaterialController extends Controller
{
private function sanitizeDecimal($number) {
private function sanitizeDecimal($number)
{
$number = str_replace(".", "", $number);
$number = str_replace(",", ".", $number);
return $number;
}
public function add(Request $request){
public function add(Request $request)
{
$this->validate($request, [
'activity_id' => 'required',
'material_id' => 'required',
@ -44,13 +47,18 @@ class AssignMaterialController extends Controller
if ($planDate >= $startDate) {
$result = AssignMaterial::create($data);
if($result) {
return response()->json(['status' => 'success', 'message' => 'Data added!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 400], 400);
}
} else {
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);
@ -82,7 +90,8 @@ class AssignMaterialController extends Controller
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);
@ -116,11 +125,14 @@ class AssignMaterialController extends Controller
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');
$type = $request->query('type') ?? "material";
$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")
->where('assign_material_to_activity.activity_id', $id_activity)
@ -136,32 +148,38 @@ class AssignMaterialController extends Controller
->rawColumns(['action'])->make(true);
}
public function datatablesForReportActivity(Request $request){
public function datatablesForReportActivity(Request $request)
{
$id_activity = $request->query('idact');
$data =
AssignMaterial::select(
AssignMaterial::raw('SUM(qty_planning) as qty_planning'),
$query = 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('SUM(ram.qty) as qty_sum'),
"m.description as material_name",
"assign_material_to_activity.activity_id",
"assign_material_to_activity.type"
// "assign_material_to_activity.material_id",
"assign_material_to_activity.activity_id"
)
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->groupBy("m.description")
->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()) {
$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("assign_material_to_activity.activity_id")
->groupBy("assign_material_to_activity.type")
->where("assign_material_to_activity.activity_id", $id_activity)->get();
->where("assign_material_to_activity.activity_id", $id_activity)
->get();
return Datatables::of($data)
->addIndexColumn()
->addColumn('qty_sum', function($row){
$val_qty_act = AssignMaterial::select(ReportActivityMaterial::raw('SUM(ram.qty) as qty_sum'),"m.description as material_name1")
->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")
->groupBy("m.description")
->where("m.description", strval($row->material_name))
->where("ram.activity_id", $row->activity_id)->first();
return $val_qty_act ? $val_qty_act->qty_sum : '-';
})
// ->addColumn('qty_planning', function($row){
// $val_qty_act = AssignMaterial::select(ReportActivityMaterial::raw('SUM(ram.qty) as qty_sum'),"m.description as material_name1","m.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")
// ->groupBy("m.description")
// ->groupBy("m.id")
// ->where("m.description", strval($row->material_name))
// ->where("ram.activity_id", $row->activity_id)->first();
// return $val_qty_act ? $val_qty_act->qty_sum : '-';
// })
->addColumn('status_activity', function ($row) {
$val_status = AssignMaterial::select("status_activity")
->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id')
@ -196,14 +214,15 @@ class AssignMaterialController extends Controller
->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")
->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-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-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="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>';
return $actionBtn;
})
->rawColumns(['action'])->make(true);
}
public function ForReportActivityByMaterial(Request $request){
public function ForReportActivityByMaterial(Request $request)
{
$id_activity = $request->idact;
$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")

5
app/Http/Controllers/AssignToolsController.php

@ -2,10 +2,9 @@
namespace App\Http\Controllers;
use App\Models\{AssignMaterial,AssignTools,ToolsResource};
use Illuminate\Http\Request;
use App\Models\AssignTools;
use Datatables;
use App\Models\ToolsResource;
use Yajra\Datatables\Datatables;
class AssignToolsController extends Controller
{
public function add(Request $request){

159
app/Http/Controllers/AuthController.php

@ -2,21 +2,24 @@
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use App\Models\User;
use App\Models\Role;
use App\Models\User;
use App\Models\Company;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Password;
use Illuminate\Validation\ValidationException;
const URL_EMAIL = 'https://notifapp.odm-iu.com/service-mail/notif_mail.php';
class AuthController extends Controller
{
public function __construct()
{
$this->middleware('auth:api', ['except' => ['login']]);
$this->middleware('auth:api', ['except' => ['login','sendEmail']]);
}
public function login(Request $request)
@ -25,26 +28,36 @@ class AuthController extends Controller
$password = $request->password;
$remember = $request->remember;
$is_mobile = $request->is_mobile;
$usernameCheck = false;
$passwordCheck = false;
if (empty($username) || empty($password))
if (empty($username) || empty($password)) {
return response()->json(['status' => 'error', 'message' => 'You must fill all the fields'], 400);
}
$usernameCheck = false;
$passwordCheck = false;
$userQuery = User::query()
->where('username',$username);
if (User::where('username', $username)->exists())
if ($userQuery->exists()) {
$usernameCheck = true;
if (User::where('password', md5($password))->exists())
$passwordValue = $userQuery->first()->password;
if($passwordValue === md5($password)) {
$passwordCheck = true;
}
}
if ($usernameCheck & $passwordCheck) {
$user = User::where('username', $username)->where('password', md5($password))->first();
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) {
return response()->json(['status' => 'error', 'message' => 'Expired! Please update license!'], 201);
}
if ($is_mobile) {
$fcm_token = $request->fcm_token;
if (!$fcm_token || $fcm_token == "")
if (!$fcm_token || $fcm_token == "") {
return response()->json(['status' => 'error', 'message' => 'FCM Token is required'], 400);
}
$dataUpdateFcm = array(
"fcm_token" => $fcm_token
@ -52,25 +65,43 @@ class AuthController extends Controller
$hr = User::find($user->id);
if ($hr)
if ($hr) {
$hr->update($dataUpdateFcm);
}
}
$dataRole = Role::find($user->role_id);
$dataHierarchy = $this->getDataHierarchy($user->divisi_id, $user->id);
$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) {
$user->configApp = $configApp;
}
if ($dataRole)
if ($dataRole) {
$user->role = $dataRole;
}
if ($dataHierarchy)
if ($dataHierarchy) {
$user->hierarchy = $dataHierarchy;
}
if (!$token = Auth::login($user))
if (!$token = Auth::login($user)) {
return response()->json(['error' => 'Unauthorized'], 401);
}
$ttl = 60;
if ($remember)
if ($remember) {
$ttl = 10080;
}
// todo : change existing md5 hashed function to laravel's originally bcrypt
/* $token = auth()->setTTL($ttl)->attempt(['username' => $username, 'password' => Hash::make($password)]); */
@ -86,12 +117,88 @@ 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);
}
}
}
public function sendEmail(Request $request)
{
if (empty($request->password)) {
$hashed = Str::random(15);
} else {
$hashed = $request->password;
}
$email = $request->email;
$user = User::select('email', 'name', 'username')->where('email', $email)->first();
if (!$user || empty($email)) {
return response()->json(['status' => 'error', 'message' => 'e-mail not found'], 400);
} else {
if($request->username) {
$username = $request->username;
$name = $request->username;
} else {
$username = $user->username;
$name = $user->name;
}
$this->reqHttpCurl($email, $hashed, $username, $name);
if(empty($request->password)) {
if (User::where('email', $email)->update(['password' => md5($hashed)])) {
return response()->json(['status' => 'success', 'code' => 200, 'message' => 'Password already sent to mail'], 200);
}
} else {
return response()->json(['status' => 'success', 'code' => 200, 'message' => 'Password already sent to mail'], 200);
}
}
}
private function reqHttpCurl($email, $password, $username, $name)
{
$postData = [
"to" => $email,
"name" => $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));
}
}
}

94
app/Http/Controllers/CompanyController.php

@ -2,28 +2,38 @@
namespace App\Http\Controllers;
use App\Models\Company;
use App\Models\{User, RoleMenu, Role, ProductTransaction, MenuCompany, Company};
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
use Carbon\Carbon;
class CompanyController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'name' => 'required',
'description' => 'required'
'company_name' => 'required',
'registration_no' => 'required',
'template_id' => 'required',
'is_active' => 'required',
'type_paket' => 'required|in:Free,Basic,Enterprise',
'base_url' => 'required'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
if(isset($data['base_url']) && $data['base_url'] != NULL) {
$data['base_url'] = json_encode($data['base_url'], true);
}
$result = Company::create($data);
$addTransaction = $this->addTransaction($result['id'],$data['type_paket']);
if ($result) {
return response()->json(['status' => 'success', 'message' => 'add Company successfully!', 'code' => 200], 200);
if ($result && $addTransaction) {
return response()->json(['status' => 'success','data' => $result, 'message' => 'Add Company successfully!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'add data Company failed!', 'code' => 400], 400);
return response()->json(['status' => 'failed', 'message' => 'Add data Company failed!', 'code' => 400], 400);
}
}
@ -51,15 +61,18 @@ class CompanyController extends Controller
$data = Company::find($id);
if(isset($data['base_url']) && $data['base_url'] != NULL) {
$data->update(['base_url'=>null]);
$data['base_url'] = json_encode($data['base_url'], true);
}
if ($data) {
$result = $data->update($request->all());
$updateTransaction = $this->updateTransaction($id,$request->type_paket);
} else {
return response()->json(['status' => 'failed', 'message' => 'data Company not found!', 'code' => 400], 400);
die();
}
if ($result) {
if ($result && $updateTransaction) {
return response()->json(['status' => 'success', 'message' => 'data Company successfully updated!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'data Company failed updated!', 'code' => 400], 400);
@ -68,20 +81,67 @@ class CompanyController extends Controller
public function delete($id)
{
$data = Company::find($id);
DB::beginTransaction();
$data = Company::find((int)$id);
if ($data) {
$delete = $data->delete();
$this->deleteRelative($data);
if ($data->delete()) {
DB::commit();
return response()->json(['status' => 'success', 'message' => 'Data Company successfully deleted!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'data Company not found!', 'code' => 400], 400);
DB::rollBack();
return response()->json(['status' => 'failed', 'message' => 'Data Company failed deleted!', 'code' => 400], 400);
}
} else {
DB::rollBack();
return response()->json(['status' => 'failed', 'message' => 'Data Company not found!', 'code' => 400], 400);
die();
}
}
private function deleteRelative($data)
{
$directory = 'assets/' . $data['company_name'];
if (is_dir($directory)) {
File::deleteDirectory($directory);
}
if ($delete) {
return response()->json(['status' => 'success', 'message' => 'data Company successfully deleted!', 'code' => 200], 200);
MenuCompany::where('company_id', $data['id'])->delete();
User::where('company_id', $data['id'])->delete();
$role = Role::where('company_id', $data['id'])->first();
if ($role) {
RoleMenu::where('role_id', $role->id)->delete();
$role->delete();
}
ProductTransaction::where('company_id', $data['id'])->delete();
}
protected function addTransaction($id_company, $type_paket)
{
$currentDate = Carbon::now();
$finalDate = $currentDate->copy()->addDays(30);
$formData = array(
'company_id' => (int)$id_company,
'type_paket' => $type_paket,
'exp_ospro' => $finalDate,
'amount' => $type_paket === 'Free' ? 0 : 250000
);
$result = ProductTransaction::create($formData);
if($result) {
return true;
} else {
return false;
}
}
protected function updateTransaction($id_company, $type_paket)
{
$result = ProductTransaction::where('company_id', (int)$id_company)->first();
$result->update(['type_paket' => $type_paket]);
if($result) {
return true;
} else {
return response()->json(['status' => 'failed', 'message' => 'data Company failed deleted!', 'code' => 400], 400);
return false;
}
}

115
app/Http/Controllers/ContactSalesController.php

@ -0,0 +1,115 @@
<?php
namespace App\Http\Controllers;
use App\Models\ContactSales;
use Illuminate\Http\Request;
class ContactSalesController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'name' => 'required',
'role' => 'required',
'email' => 'required',
'number_phone' => 'required',
'status' => 'required',
]);
$data = $request->all();
$data['created_by'] = '@System';
$data['status'] = 'New Request';
$result = ContactSales::create($data);
if ($result) {
return response()->json(['status' => 'success', 'data' => $result, 'message' => 'Your message has been successfully received by our Sales team! Someone from our team will be in touch with you shortly.', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'Your message has been 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 = ContactSales::find($id);
if ($result) {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'failed get data Contact Sales, 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 = ContactSales::find($id);
if ($data) {
$result = $data->update($request->all());
} else {
return response()->json(['status' => 'failed', 'message' => 'data Contact Sales not found!', 'code' => 400], 400);
die();
}
if ($result) {
return response()->json(['status' => 'success', 'message' => 'data Contact Sales successfully updated!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'data Contact Sales failed updated!', 'code' => 400], 400);
}
}
public function delete($id)
{
$data = ContactSales::find($id);
if ($data) {
$delete = $data->delete();
} else {
return response()->json(['status' => 'failed', 'message' => 'data Contact Sales not found!', 'code' => 400], 400);
die();
}
if ($delete) {
return response()->json(['status' => 'success', 'message' => 'data Contact Sales successfully deleted!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'data Contact Sales failed deleted!', 'code' => 400], 400);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_contact_sales');
$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 = ContactSales::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 Contact Sales, please try again later!', 'code' => 400], 400);
}
}
}

197
app/Http/Controllers/Controller.php

@ -2,16 +2,22 @@
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use App\Models\UserToActivity;
use App\Models\Activity;
use App\Models\AssignMaterial;
use App\Models\User;
use App\Models\Divisi;
use Laravel\Lumen\Routing\Controller as BaseController;
use App\Models\Activity;
use App\Models\AssignMaterial;
use App\Models\Company;
use App\Models\ReportK3Detail;
use App\Models\UserToActivity;
use App\Models\ProductTransaction;
use App\Models\Project;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;
use Illuminate\Support\Facades\Http;
use Laravel\Lumen\Routing\Controller as BaseController;
use RecursiveIteratorIterator;
use RecursiveDirectoryIterator;
use Exception;
class Controller extends BaseController
{
@ -33,12 +39,161 @@ class Controller extends BaseController
$this->currentDate = date("Y-m-d H:i:s");
$this->currentName = auth()->user() ? auth()->user()->name : "system";
$this->currentId = auth()->user() ? auth()->user()->id : 0;
$this->companyId = auth()->user() ? auth()->user()->company_id : 0;
$this->pathImage = config('assets.image');
$this->pathDocument = config('assets.project');
$this->pathActivityDocument = config('assets.activity');
}
protected function setCustomeDirectoryUpload($company_name)
{
$current_date = date('Y-m-d');
[$year, $month] = explode('-', $current_date);
$yearMonth = $year.'-'.$month;
$pathImage = 'assets/' . $company_name .'/'. $yearMonth . '/image/';
$pathDocument = 'assets/' . $company_name .'/'. $yearMonth . '/file/project/';
$pathTmpImport = 'assets/' . $company_name .'/'. $yearMonth . '/file/tmpimport/';
$pathActivityDocument = 'assets/' . $company_name .'/'. $yearMonth . '/file/activity/';
return [
'pathImage' => $pathImage,
'pathDocument' => $pathDocument,
'pathTmpImport' => $pathTmpImport,
'pathActivityDocument' => $pathActivityDocument
];
}
public function storage($company_name)
{
$directory = 'assets/' . urldecode($company_name);
if (!is_dir($directory)) {
return "Directory not found";
}
$size = 0;
try {
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file) {
$size += $file->getSize();
}
} catch (Exception $e) {
return "Error while calculating size: " . $e->getMessage();
}
return round($size / 1048576, 2);
}
public function storageAllCompany()
{
$companies = Company::get();
$formData = [];
foreach($companies as $data) {
$size = 0;
$directory = 'assets/' . urldecode($data['company_name']);
if (is_dir($directory)) {
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file) {
$size += $file->getSize();
}
}
$formData[] = [
'company_name' => $data['company_name'],
'size' => round($size / 1048576, 2),
'exp_ospro' => ProductTransaction::query()->where('company_id', $data['id'])->value('exp_ospro'),
'project_total' => Project::query()->where('company_id',$data['id'])->count()
];
}
return $formData;
}
public function setExpiredTimeOspro($company_id)
{
$currentDate = Carbon::now();
$countCreate = false;
$transaction = ProductTransaction::query()
->where('company_id', $company_id)->first();
if(!empty($transaction)) {
$dateExpired = $transaction['exp_ospro'];
if ($currentDate->gt(Carbon::parse($dateExpired))) {
$countCreate = false;
} else {
$countCreate = true;
}
return $countCreate;
} else {
return $countCreate = true;
}
}
protected function setLimitsStorage($company, $dokumen, $initPath, $destinatePath)
{
$countCreate = false;
DB::transaction(function() use($company, $dokumen, $initPath, $destinatePath, &$countCreate) {
$totalSize = 0;
$sizeFile = $dokumen->getSize();
// Path
$folderPath = $destinatePath['pathDocument'];
$folderPathImage = $destinatePath['pathImage'];
$folderPathTmpImport = $destinatePath['pathTmpImport'];
$folderPathActivityDocument = $destinatePath['pathActivityDocument'];
// Create Directory
if (!file_exists($initPath)) {
mkdir($initPath, 0777, true);
}
// Scanning & Existing Folder
if (file_exists($folderPathImage)) {
$files = scandir($folderPathImage);
foreach ($files as $file) {
if (is_file($folderPathImage . '/' . $file)) {
$totalSize += filesize($folderPathImage . '/' . $file);
}
}
}
if (file_exists($folderPath)) {
$filesImage = scandir($folderPath);
foreach ($filesImage as $file) {
if (is_file($folderPath . '/' . $file)) {
$totalSize += filesize($folderPath . '/' . $file);
}
}
}
if (file_exists($folderPathTmpImport)) {
$filesTmpImport = scandir($folderPathTmpImport);
foreach ($filesTmpImport as $file) {
if (is_file($folderPathTmpImport . '/' . $file)) {
$totalSize += filesize($folderPathTmpImport . '/' . $file);
}
}
}
if (file_exists($folderPathActivityDocument)) {
$filesActivityDocument = scandir($folderPathActivityDocument);
foreach ($filesActivityDocument as $file) {
if (is_file($folderPathActivityDocument . '/' . $file)) {
$totalSize += filesize($folderPathActivityDocument . '/' . $file);
}
}
}
// Logic
$totalSize += $sizeFile;
$transaction = ProductTransaction::query()
->where('company_id', $company['id']);
$cloneQueryTransaction = clone $transaction;
if ($transaction->where([['type_paket', 'Basic'], ['amount', '!=', null]])->exists()) {
$maximumSize = 500 * 1024 * 1024;
$countCreate = true;
} elseif ($cloneQueryTransaction->where([['type_paket', 'Free'], ['amount', 0]])->exists()) {
$maximumSize = 50 * 1024 * 1024;
$countCreate = true;
} else {
$countCreate = true;
}
if ($countCreate && isset($maximumSize)) { // kondisi $maximumSize sementara karena blm ada paket enterprise
if (floatval($totalSize) > floatval($maximumSize)) {
$countCreate = false;
}
}
});
return $countCreate;
}
protected function setUpPayload($condition, $tableSelf)
{
$alias = "selfTable";
@ -184,6 +339,10 @@ class Controller extends BaseController
$query = $query->whereIn($tableColumn . "." . $column, $value);
} else if ($operator == "notin") {
$query = $query->whereNotIn($tableColumn . "." . $column, $value);
} else if ($operator == "isnull") {
$query = $query->WhereNull($tableColumn . "." . $column);
} else if ($operator == "notnull") {
$query = $query->WhereNotNull($tableColumn . "." . $column);
} else {
$query = $query->where($tableColumn . "." . $column, $operator, $value);
}
@ -281,6 +440,28 @@ class Controller extends BaseController
return $totalCost;
}
protected function paramsMethodGet($query, $countData, $request)
{
$start = $request->start;
$length = $request->length == '-1' ? $countData : $request->length;
$orderBy = $request->orderby;
$asc = $request->asc == 'false' ? 'desc' : 'asc';
$where = $request->column;
$logicOp = $request->logic;
$valColumn = str_replace("\\", "", "$request->value");
if ($logicOp == 'like' || $logicOp == 'ilike') {
$valColumnFilter = '%' . $valColumn . '%';
} else {
$valColumnFilter = $valColumn;
}
$data = $query->where($where, $logicOp, $valColumnFilter)
->orderBy($orderBy, $asc)
->offset($start)->limit($length)->get();
return $data;
}
protected function getLoc($lat, $lng)
{
// $response = Http::get(config('api.nominatim') . "/reverse?lat=".$lat."&lon=".$lng."&format=json");

420
app/Http/Controllers/DashboardBoDController.php

@ -2,15 +2,19 @@
namespace App\Http\Controllers;
use App\Helpers\MasterFunctionsHelper;
use App\Models\User;
use App\Models\Divisi;
use App\Models\Project;
use App\Models\ProjectPhase;
use App\Models\User;
use App\Models\ProjectExpenditure;
use App\Models\UserToVersionGantt;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use App\Models\ProjectScheduleHealth;
use App\Helpers\MasterFunctionsHelper;
use App\Models\ProjectFinancialHealth;
use App\Models\ProjectInvoice;
class DashboardBoDController extends Controller
{
@ -22,30 +26,51 @@ class DashboardBoDController extends Controller
}
// to do
public function getCompanyCashFlow($year = '%')
public function getCompanyCashFlow($company_id, $all_project, $hierarchy, $role_name)
{
$year = $this->interpolateYear($year);
$totalExpenditure = $totalInvoice = $totalPaidInvoice = 0;
// we can't use eloquent's sum() method because someone decided to use varchar as datatype in rencana_biaya field
$totalBudgets = Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))'))
->where('mulai_proyek', 'like', $year)
->pluck('sum')
->first();
$totalBudgets = null;
$role = urldecode($role_name);
if ($role === "Super Admin") {
$totalBudgets = Project::sum(DB::raw('CAST("rencana_biaya" AS DOUBLE PRECISION)'));
} elseif (!empty($all_project)) {
$totalBudgets = Project::where('company_id', $company_id)
->sum(DB::raw('CAST("rencana_biaya" AS DOUBLE PRECISION)'));
} else {
$totalBudgets = Project::where('created_by_id', $hierarchy)
->sum(DB::raw('CAST("rencana_biaya" AS DOUBLE PRECISION)'));
}
$projects = Project::where('mulai_proyek', 'like', $year)
$projects = null;
if ($role === "Super Admin") {
$projects = Project::get();
} elseif (!empty($all_project)) {
$projects = Project::where('company_id', $company_id)
->get();
} else {
$projects = Project::where('created_by_id', $hierarchy)
->get();
}
foreach ($projects as $project) {
$project->expenses = 0;
$resp = null;
if ($project->kode_sortname != "") {
// $resp = $this->getInvoiceIntegration($project->kode_sortname);
// $cost = $resp->data->total_cost ?? 0;
// $cost = substr($cost, 0, strpos($cost, "."));
$cost = 0;
$cost = substr($cost, 0, strpos($cost, "."));
$totalExpenditure += (int) $cost;
$totalInvoice += 0;
$totalPaidInvoice += 0;
$totalExpenditure = 0;
$totalInvoice = 0;
$totalPaidInvoice = 0;
// $totalExpenditure += (int) $cost;
// $totalInvoice += $resp->data->total_invoice_amount ?? 0;
// $totalPaidInvoice += $resp->data->total_invoice_paid_amount ?? 0;
}
}
@ -59,11 +84,145 @@ class DashboardBoDController extends Controller
], 200);
}
public function getInvoiceOutstanding($year = '%')
public function getDetailExpenditureColor($role_name, $company_id)
{
$year = $this->interpolateYear($year);
$projects = Project::where('mulai_proyek', 'like', $year)
$role = urldecode($role_name);
$query = null;
if ($role === 'Super Admin') {
$query = ProjectExpenditure::get();
} else {
$query = ProjectExpenditure::where('company_id', $company_id)->get();
}
$data = [];
foreach ($query as $value) {
if ($value['name'] === 'Total Budget') {
$data['total_budget'] = $value['color'];
}
if ($value['name'] === 'Expenditure') {
$data['total_expenditure'] = $value['color'];
}
if ($value['name'] === 'Invoice') {
$data['total_invoice'] = $value['color'];
}
if ($value['name'] === 'Cash In') {
$data['total_paid_invoice'] = $value['color'];
}
}
return response()->json([
'data' => [
'total_budget' => $data['total_budget'] ?? '',
'total_expenditure' => $data['total_expenditure'] ?? '',
'total_invoice' => $data['total_invoice'] ?? '',
'total_paid_invoice' => $data['total_paid_invoice'] ?? '',
]
], 200);
}
public function getDetailFinancialHealthColor($role_name, $company_id)
{
$role = urldecode($role_name);
$query = null;
if ($role === 'Super Admin') {
$query = ProjectFinancialHealth::get();
} else {
$query = ProjectFinancialHealth::where('company_id', $company_id)->get();
}
$data = [];
foreach ($query as $value) {
if ($value['name'] === 'Cost Overrun') {
$data['overrun'] = $value['color'];
}
if ($value['name'] === 'Early Warning') {
$data['warning'] = $value['color'];
}
if ($value['name'] === 'On Budget') {
$data['on-budget'] = $value['color'];
}
}
return response()->json([
'data' => [
'overrun' => $data['overrun'] ?? '',
'warning' => $data['warning'] ?? '',
'on-budget' => $data['on-budget'] ?? '',
]
], 200);
}
public function getDetailScheduleHealthColor($role_name, $company_id)
{
$role = urldecode($role_name);
$query = null;
if ($role === 'Super Admin') {
$query = ProjectScheduleHealth::get();
} else {
$query = ProjectScheduleHealth::where('company_id', $company_id)->get();
}
$data = [];
foreach ($query as $value) {
if ($value['name'] === 'Behind Schedule') {
$data['behind-schedule'] = $value['color'];
}
if ($value['name'] === 'Early Warning') {
$data['warning'] = $value['color'];
}
if ($value['name'] === 'On Schedule') {
$data['on-schedule'] = $value['color'];
}
}
return response()->json([
'data' => [
'behind-schedule' => $data['behind-schedule'] ?? '',
'warning' => $data['warning'] ?? '',
'on-schedule' => $data['on-schedule'] ?? '',
]
], 200);
}
public function getDetailInvoiceColor($role_name, $company_id)
{
$role = urldecode($role_name);
$query = null;
if ($role === 'Super Admin') {
$query = ProjectInvoice::get();
} else {
$query = ProjectInvoice::where('company_id', $company_id)->get();
}
$data = [];
foreach ($query as $value) {
if ($value['name'] === 'Invoiced') {
$data['invoiced'] = $value['color'];
}
if ($value['name'] === 'Cash In') {
$data['paid'] = $value['color'];
}
}
return response()->json([
'data' => [
'invoiced' => $data['invoiced'] ?? '',
'paid' => $data['paid'] ?? ''
]
], 200);
}
// integrasi
public function getInvoiceOutstanding($role_name, $company_id, $all_project, $hierarchy)
{
$role = urldecode($role_name);
$projects = null;
if ($role === 'Super Admin') {
$projects = Project::get();
} elseif (!empty($all_project)) {
$projects = Project::where('company_id', $company_id)
->get();
} else {
$projects = Project::where('created_by_id', $hierarchy)
->get();
}
$return = [];
foreach ($projects as $project) {
if ($project->kode_sortname != "") {
@ -81,17 +240,33 @@ class DashboardBoDController extends Controller
], 200);
}
public function getTotalProjectPerScheduleHealth($year = '%')
public function getTotalProjectPerScheduleHealth($role_name, $company_id, $all_project, $hierarchy)
{
$year = $this->interpolateYear($year);
$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 == 'true') {
$projects = Project::whereIn('divisi_id', $divisi)
->where('company_id', $company_id)
->get();
} else {
$projects = Project::whereIn('divisi_id', $divisi)
->where('created_by_id', $replaceHierarchy)
->get();
}
$projects = Project::where('mulai_proyek', 'like', $year)->get();
foreach ($projects as $index => $project) {
$project->scurve = MasterFunctionsHelper::getSCurve($project->id);
$selisihProgress = 0;
@ -106,7 +281,7 @@ class DashboardBoDController extends Controller
}
$selisihProgress = $planningProgress - $actualProgress;
try {
if ($selisihProgress > 0 && $selisihProgress <= 5) {
if ($selisihProgress > 0 && $selisihProgress <= 20) {
$return['warning'] += 1;
$projects[$index]->status = 'warning';
} elseif ($selisihProgress == 0) {
@ -124,17 +299,24 @@ class DashboardBoDController extends Controller
return response()->json(['data' => $return, 'q' => $projects], 200);
}
public function getTotalProjectScheduleHealthPerDivision($year = '%')
public function getTotalProjectScheduleHealthPerDivision($role_name, $company_id)
{
$year = $this->interpolateYear($year);
$role = urldecode($role_name);
$divisions = null;
if ($role === 'Super Admin') {
$divisions = Divisi::whereNull('parent')
->get();
} else {
$divisions = Divisi::whereNull('parent')
->where('company_id', $company_id)
->get();
}
$divisions = Divisi::whereNull('parent')->get();
foreach ($divisions as $index => $division) {
$scheduleData = new Collection();
$behindSchedule = $warning = $onSchedule = 0;
$projects = Project::where('mulai_proyek', 'like', $year)->where('divisi_id', $division->id)->get();
$projects = Project::where('divisi_id', $division->id)->get();
foreach ($projects as $project) {
$project->scurve = MasterFunctionsHelper::getSCurve($project->id);
$selisihProgress = 0;
@ -169,51 +351,103 @@ class DashboardBoDController extends Controller
], 200);
}
public function getTotalProjectPerBudgetHealth($year = '%')
public function getTotalProjectPerBudgetHealth($role_name, $company_id, $all_project, $hierarchy)
{
$year = $this->interpolateYear($year);
return response()->json([
$role = urldecode($role_name);
$replaceHierarchy = preg_replace('/[\[\]]/', '', $hierarchy);
$response = [
'data' => [
'overrun' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'overrun')->count(),
'warning' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'warning')->count(),
'on-budget' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'on-budget')->count(),
'overrun' => 0,
'warning' => 0,
'on-budget' => 0,
]
], 200);
];
$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 == 'true') {
$response['data']['overrun'] = Project::whereIn('divisi_id', $divisi)
->where([['budget_health', 'overrun'], ['company_id', $company_id]])
->count();
} else {
$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']['warning'] = Project::where('budget_health', 'warning')
->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::whereIn('divisi_id', $divisi)
->where([['budget_health', 'warning'], ['created_by_id', $replaceHierarchy]])
->count();
}
// arr on-budget
if ($role === 'Super Admin') {
$response['data']['on-budget'] = Project::where('budget_health', 'on-budget')
->count();
} 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::whereIn('divisi_id', $divisi)
->where([['budget_health', 'on-budget'], ['created_by_id', $replaceHierarchy]])
->count();
}
return response()->json($response, 200);
}
private function countTotalProjectByBudgetHealthInDivision($divisi, $year, $health)
private function countTotalProjectByBudgetHealthInDivision($divisi, $health)
{
return Project::where('divisi_id', $divisi)
->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->where('budget_health', $health)
->count();
$project = Project::where([['divisi_id', $divisi], ['budget_health', $health]])->count();
return $project;
}
public function getTotalProjectBudgetHealthPerDivision($year = '%')
public function getTotalProjectBudgetHealthPerDivision($role_name, $company_id)
{
$year = $this->interpolateYear($year);
$role = urldecode($role_name);
$divisions = null;
if ($role === 'Super Admin') {
$divisions = Divisi::select('id', 'name')
->with('children')
->whereNull('parent')
->get();
} else {
$divisions = Divisi::select('id', 'name')
->with('children')
->whereNull('parent')
->where('company_id', $company_id)
->get();
}
// to do : count in more than 1 level child
foreach ($divisions as $division) {
$budgetData = new Collection();
$budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, $year, 'overrun'), 'overrun');
$budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, $year, 'warning'), 'warning');
$budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, $year, 'on-budget'), 'on-budget');
$budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, 'overrun'), 'overrun');
$budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, 'warning'), 'warning');
$budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, 'on-budget'), 'on-budget');
foreach ($division->children as $d) {
$budgetData['overrun'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, $year, 'overrun');
$budgetData['warning'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, $year, 'warning');
$budgetData['on-budget'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, $year, 'on-budget');
$budgetData['overrun'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, 'overrun');
$budgetData['warning'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, 'warning');
$budgetData['on-budget'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, 'on-budget');
}
unset($division->children);
$division->budgetData = $budgetData;
}
foreach ($divisions as $division) {
}
return response()->json([
'data' => [
$divisions
@ -221,15 +455,31 @@ class DashboardBoDController extends Controller
], 200);
}
public function getTotalProjectPerPhase($year = '%')
public function getTotalProjectPerPhase($role_name, $company_id, $all_project, $hierarchy)
{
$year = $this->interpolateYear($year);
$role = urldecode($role_name);
$projectPhases = null;
if ($role === 'Super Admin') {
$projectPhases = ProjectPhase::orderBy('order')->get();
} else {
$projectPhases = ProjectPhase::where('company_id', $company_id)->orderBy('order')->get();
}
foreach ($projectPhases as $phase) {
if ($role === 'Super Admin') {
$phase->totalProject = Project::where('phase_id', $phase->id)
->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->count();
} elseif ($all_project) {
$phase->totalProject = Project::where('phase_id', $phase->id)
->where('company_id', $company_id)
->count();
} else {
$phase->totalProject = Project::where('phase_id', $phase->id)
->where('created_by_id', $hierarchy)
->count();
}
}
return response()->json([
'data' => [
@ -238,27 +488,37 @@ class DashboardBoDController extends Controller
], 200);
}
private function countTotalProjectInDivision($id, $year)
private function countTotalProjectInDivision($id)
{
return Project::where('divisi_id', $id)
->where('mulai_proyek', 'like', $year)
->count();
}
public function getTotalProjectPerDivision($year = '%')
public function getTotalProjectPerDivision($role_name, $company_id)
{
$year = $this->interpolateYear($year);
$role = urldecode($role_name);
$divisions = null;
if ($role === 'Super Admin') {
$divisions = Divisi::select('id', 'name', 'parent', 'color')
->with('children')
->whereNull('parent')
->get();
} else {
$divisions = Divisi::select('id', 'name', 'parent', 'color')
->with('children')
->whereNull('parent')
->where('company_id', $company_id)
->get();
}
// to do : count in more than 1 level child
foreach ($divisions as $v) {
$v->total = $this->countTotalProjectInDivision($v->id, $year);
$v->total = $this->countTotalProjectInDivision($v->id);
foreach ($v->children as $d) {
$v->total += $this->countTotalProjectInDivision($d->id, $year);
$v->total += $this->countTotalProjectInDivision($d->id);
}
unset($v->children);
}
@ -268,30 +528,35 @@ class DashboardBoDController extends Controller
], 200);
}
private function countTotalProjectValueInDivision($id, $year)
private function countTotalProjectValueInDivision($id)
{
return Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))'))
->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->where('divisi_id', $id)
->pluck('sum')
->first();
}
public function getTotalProjectValuePerDivision($year = '%')
public function getTotalProjectValuePerDivision($role_name, $company_id)
{
$year = $this->interpolateYear($year);
$role = urldecode($role_name);
if ($role === 'Super Admin') {
$divisions = Divisi::select('id', 'name', 'color')
->with('children')
->whereNull('parent')
->get();
} else {
$divisions = Divisi::select('id', 'name', 'color')
->with('children')
->whereNull('parent')
->where('company_id', $company_id)
->get();
}
// to do : count in more than 1 level child
foreach ($divisions as $v) {
$v->total = $this->countTotalProjectValueInDivision($v->id, $year);
$v->total = $this->countTotalProjectValueInDivision($v->id);
foreach ($v->children as $d) {
$v->total += $this->countTotalProjectValueInDivision($d->id, $year);
$v->total += $this->countTotalProjectValueInDivision($d->id);
}
unset($v->children);
}
@ -302,13 +567,22 @@ class DashboardBoDController extends Controller
}
public function getDetailExpenditure($year = '%')
public function getDetailExpenditure($year = '%', $company_id, $all_project, $hierarchy)
{
$year = $this->interpolateYear($year);
$projects = null;
if ($all_project) {
$projects = Project::where('mulai_proyek', 'like', $year)
->where('company_id', $company_id)
->orderBy('id', 'desc')
->get();
} else {
$projects = Project::where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->where('created_by_id', $hierarchy)
->orderBy('id', 'desc')
->get();
}
foreach ($projects as $project) {
$lastGantt = MasterFunctionsHelper::getLatestGantt($project->id);

116
app/Http/Controllers/DemoController.php

@ -0,0 +1,116 @@
<?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',
'email' => 'required',
'number_phone' => 'required',
'status' => '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);
}
}
}

37
app/Http/Controllers/DivisiController.php

@ -4,11 +4,13 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Divisi;
use Illuminate\Support\Facades\Log;
class DivisiController extends Controller
{
private function getAllChildren($divisi, $depth = 0, $array = []) {
private function getAllChildren($divisi, $depth = 0, $array = [])
{
$divisi->depth = $depth;
array_push($array, $divisi);
foreach ($divisi->children as $child) {
@ -17,9 +19,10 @@ class DivisiController extends Controller
return $array;
}
public function add(Request $request){
public function add(Request $request)
{
$this->validate($request, [
'name' => 'string|required|unique:m_divisi,name',
'name' => 'string|required|unique:m_divisi,name,NULL,id,company_id,' . $request->input('company_id'),
'description' => 'nullable|string',
'parent' => 'nullable|integer',
'color' => 'nullable|string|max:10'
@ -36,7 +39,8 @@ class DivisiController extends Controller
return response()->json(['status' => 'success', 'message' => 'Data created!', 'code' => 200]);
}
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);
@ -80,15 +84,22 @@ class DivisiController extends Controller
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_divisi');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
//return $this->list();
// cant use builder for this case
$companyId = $request->input('columns.0.value');
$parentDivisi = Divisi::whereNull('parent')
->where('company_id', $companyId)
->with('children')
->get();
$divisions = [];
foreach ($parentDivisi as $objRow) {
$objRow->children = $this->getAllChildren($objRow);
// $objRow->key = rand(1, 1000);
$divisions[] = $objRow;
}
$countData = count($divisions);
if ($countData == 0)
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $divisions, 'totalRecord' => $countData], 200);
}
public function list()

40
app/Http/Controllers/FolderDocumentProyekController.php

@ -2,9 +2,12 @@
namespace App\Http\Controllers;
use App\Models\Company;
use Illuminate\Http\Request;
use App\Models\FolderDocumentProyek;
use App\Models\DokumenProject;
use App\Models\FolderDocumentProyek;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class FolderDocumentProyekController extends Controller
{
@ -44,23 +47,31 @@ class FolderDocumentProyekController extends Controller
}
}
public function delete($id)
public function delete($id, $company_id)
{
DB::beginTransaction();
$data = FolderDocumentProyek::find($id);
if($data){
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data Folder Document Proyek not found!','code'=>400], 400);
die();
}
if($delete){
$company = Company::find($company_id);
if($data && $company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$dir = $destinationPath['pathDocument'];
$dataFile = DokumenProject::where([['type_dokumen', 'project-document-in-folder'],['ref_id', $data['id']]])->orderByRaw('id ASC')->get();
if (is_dir($dir)) {
foreach ($dataFile as $file) {
unlink($dir.$file['file']);
}
}
if($data->delete()) {
DB::commit();
return response()->json(['status'=>'success','message'=>'Folder Document Proyek successfully deleted!','code'=>200], 200);
} else {
DB::rollBack();
return response()->json(['status'=>'failed','message'=>'Folder Document Proyek failed deleted!','code'=>400], 400);
}
} else {
DB::rollBack();
return response()->json(['status'=>'failed','message'=>'Data Folder Document Proyek not found!','code'=>400], 400);
}
}
public function search(Request $request)
@ -85,6 +96,7 @@ class FolderDocumentProyekController extends Controller
return response()->json(['status'=>'failed','message'=>'failed get list tools request, please try again later!','code'=>400], 400);
}
}
public function getTree($id)
{
$data = FolderDocumentProyek::where('proyek_id', $id)->whereNull('parent_id')->orderByRaw('id ASC')->get();
@ -100,7 +112,7 @@ class FolderDocumentProyekController extends Controller
foreach($dataFile as $objRowFile) {
$objRowFile->key = rand(1, 1000);
$objRowFile->isDir = false;
$objRowFile->proyek_id = $id;
$objRowFile->proyek_id = (int)$id;
$finalData[] = $objRowFile;
}
@ -122,7 +134,7 @@ class FolderDocumentProyekController extends Controller
foreach($dataFile as $objRowFile) {
$objRowFile->key = rand(1, 1000);
$objRowFile->isDir = false;
$objRowFile->proyek_id = $proyek_id;
$objRowFile->proyek_id = (int)$proyek_id;
$finalData[] = $objRowFile;
}

73
app/Http/Controllers/HierarchyFtthController.php

@ -6,6 +6,7 @@ use Illuminate\Http\Request;
use App\Models\HierarchyFtth;
use App\Models\VersionGantt;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Artisan;
class HierarchyFtthController extends Controller
{
@ -102,36 +103,41 @@ class HierarchyFtthController extends Controller
}
}
public function countProgress($project_id) {
$ftthIds = VersionGantt::select('hierarchy_ftth_id')
->where('proyek_id', $project_id)
->groupBy('hierarchy_ftth_id')
->get();
if($ftthIds){
foreach ($ftthIds as $ftthId) {
$gantts = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->sum('progress');
$bobot_planning = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->sum('bobot');
$ganttCount = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->count();
$ftth = HierarchyFtth::find($ftthId->hierarchy_ftth_id);
if($ftth){
$round = $gantts/$ganttCount;
$round_bobot = $bobot_planning/$ganttCount;
$ftth->progress = round($round, 2);
$ftth->bobot_planning = round($round_bobot, 2);
try {
$ftth->save();
} catch (\Exception $e) {
// Log the error or handle it in some other way
Log::error($e->getMessage());
}
public function countProgress($hierarchy_id) {
// $ftthIds = VersionGantt::select('hierarchy_ftth_id')
// ->where('proyek_id', $project_id)
// ->groupBy('hierarchy_ftth_id')
// ->get();
// if($ftthIds){
// foreach ($ftthIds as $ftthId) {
// $gantts = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->sum('progress');
// $bobot_planning = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->sum('bobot');
// $ganttCount = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->count();
if($ftth->parent_id){
$this->countParent($ftth);
}
}
}
}
// $ftth = HierarchyFtth::find($ftthId->hierarchy_ftth_id);
// if($ftth){
// $round = $gantts/$ganttCount;
// $round_bobot = $bobot_planning/$ganttCount;
// $ftth->progress = round($round, 2);
// $ftth->bobot_planning = round($round_bobot, 2);
// try {
// $ftth->save();
// } catch (\Exception $e) {
// // Log the error or handle it in some other way
// Log::error($e->getMessage());
// }
// if($ftth->parent_id){
// $this->countParent($ftth);
// }
// }
// }
// }
// calculate ke curva berdasarkan site
Artisan::call('calculate:progressgantt', [
'hierarchy_id' => $hierarchy_id
]);
}
public function countParent($ftth){
@ -179,7 +185,6 @@ class HierarchyFtthController extends Controller
public function getTreeByProject($project_id)
{
$this->countProgress(intval($project_id));
$data = HierarchyFtth::where('project_id', $project_id)->whereNull('parent_id')->orderByRaw('id ASC')->get();
$finalData = [];
foreach($data as $objRow){
@ -204,7 +209,13 @@ class HierarchyFtthController extends Controller
return response()->json(['status'=>'success','data'=>$finalData,'code'=>200], 200);
}
public function countProgressTree($hierarchy_id)
{
Artisan::call('calculate:progressgantt', [
'hierarchy_id' => $hierarchy_id
]);
return response()->json(['status'=>'success','code'=>200], 200);
}
private function getChildren($project_id, $parent_id)
{
$finalData = [];

2
app/Http/Controllers/HolidayController.php

@ -4,7 +4,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Holiday;
use Datatables;
use Yajra\Datatables\Datatables;
class HolidayController extends Controller
{

200
app/Http/Controllers/HumanResourceController.php

@ -3,20 +3,82 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\HumanResource;
use App\Models\UserToActivity;
use App\Models\UserToProyek;
use App\Models\{HumanResource,ProductTransaction,UserToActivity,UserToProyek,User};
use Illuminate\Support\Facades\Artisan;
const URL_EMAIL = 'https://notifapp.odm-iu.com/service-mail/notif_mail.php';
class HumanResourceController extends Controller
{
public function add(Request $request)
{
$messages = [
'ktp_number.unique' => 'Nomor KTP/ID Card tidak boleh sama',
'username.unique' => 'Username tidak boleh sama',
'required' => 'Data tidak boleh kosong'
];
$this->validate($request, [
'name' => 'required|string',
'ktp_number' => 'required|string|unique:m_users,ktp_number',
'employee_type' => 'required|in:employee,subcon,freelance',
'company_id' => 'required|integer',
'username' => 'string|unique:m_users,username',
'email' => 'string|unique:m_users,email'
], $messages);
$data = $request->all();
!$request->is_customer ? $this->validate($request,['role_id' => 'required','divisi_id' => 'required'], $messages) : '';
if (isset($request->password) && $request->password != "") {
$data['password'] = md5($request->password);
}
$transaction = ProductTransaction::query()
->where('company_id', (int) $request->company_id);
$cloneQueryTransaction = clone $transaction;
$countCreate = false;
$projectResult = HumanResource::query()
->selectRaw('count(*) as total_hr')
->where('company_id', (int) $request->company_id)
->first();
if($transaction->where([['type_paket','Basic'],['amount','!=',null]])->exists()) {
if($projectResult['total_hr'] < 50) {
$countCreate = true;
}
} elseif ($cloneQueryTransaction->where([['type_paket','Free'],['amount',0]])->exists()) {
if($projectResult['total_hr'] < 1) {
$countCreate = true;
}
} else {
$countCreate = true;
}
if($countCreate) {
$result = HumanResource::create($data);
} else {
return response()->json(['status' => 'failed', 'message' => 'Limited to create human resource!', 'code' => 500], 500);
}
if ($result) {
return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfull created', 'code' => 200]);
} else {
return response()->json(['status' => 'failed', 'message' => 'Human Resource Pool failed created', 'code' => 400]);
}
}
public function add_user(Request $request)
{
$this->validate($request, [
'role_id' => 'required',
'name' => 'required',
'ktp_number' => 'required|numeric|unique:m_users,ktp_number',
'employee_type' => 'required'
'ktp_number' => 'required|string|unique:m_users,ktp_number',
'employee_type' => 'required',
'company_id' => 'required',
'username' => 'required',
'email' => 'required|unique:m_users,email|email'
]);
$data = $request->all();
@ -28,6 +90,7 @@ class HumanResourceController extends Controller
$result = HumanResource::create($data);
if ($result) {
$this->sendEmail($request->email, $request->password);
return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfull created', 'code' => 200]);
} else {
return response()->json(['status' => 'failed', 'message' => 'Human Resource Pool failed created', 'code' => 400]);
@ -52,35 +115,75 @@ class HumanResourceController extends Controller
public function update(Request $request, $id)
{
$messages = [
'ktp_number.unique' => 'Nomor KTP/ID Card tidak boleh sama',
'username.unique' => 'Username tidak boleh sama',
'required' => 'Data tidak boleh kosong'
];
$request->validate($request, [
'name' => 'required|string',
'ktp_number' => 'required|string|unique:m_users,ktp_number,'.$id . ',id',
'employee_type' => 'required|in:employee,subcon,freelance',
'company_id' => 'required|integer',
'username' => 'unique:m_users,username,'.$id . ',id',
'email' => 'string|unique:m_users,email,'.$id . ',id'
], $messages);
!$request->is_customer ? $this->validate($request,['role_id'=>'required', 'divisi_id'=>'required'], $messages) : '';
$request->password ? $this->validate($request,['password'=>'required|min:8']) : '';
$data = $request->all();
if (!$id || (int) $id < 0 || $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);
}
$humanresource = HumanResource::find($id);
$request->ktp_number !== $humanresource['ktp_number'] ? $this->validate($request,['ktp_number'=>'unique:m_users,ktp_number|numeric']) : '';
$request->email !== $humanresource['email'] ? $this->validate($request,['email'=>'unique:m_users,email|email']) : '';
$request->password ? $this->validate($request,['password'=>'required|min:8']) : '';
$humanresource = HumanResource::find($id);
if(empty($humanresource)) {
return response()->json(['status' => 'failed', 'message' => 'Data Human Resource not found!', 'code' => 400], 400);
}
$data = $request->all();
if($request->company_id && isset($request->password) && isset($request->username)) {
$transaction = ProductTransaction::query()
->where('company_id', $request->company_id);
$cloneQueryTransaction = clone $transaction;
$countCreate = false;
$projectResult = HumanResource::query()
->selectRaw('count(*) as total_hr')
->where([
['company_id', $request->company_id],
['username', '!=', null],
['password', '!=', null]
])
->first();
if($transaction->where([['type_paket','Basic'],['amount','!=',null]])->exists()) {
if($projectResult['total_hr'] < 10) {
$countCreate = true;
}
} elseif ($cloneQueryTransaction->where([['type_paket','Free'],['amount',0]])->exists()) {
if($projectResult['total_hr'] < 1) {
$countCreate = true;
}
} else {
$countCreate = true;
}
} else {
$countCreate = true;
}
if (isset($request->password) && $request->password != "") {
$data['password'] = md5($request->password);
}
if (isset($data['username']) && HumanResource::where('username', $data['username'])->where('id', '<>', $id)->exists()) {
return response()->json(['status' => 'failed', 'message' => 'Username already exists!', 'code' => 400], 400);
}
if ($humanresource) {
if ($countCreate) {
$result = $humanresource->update($data);
} else {
return response()->json(['status' => 'failed', 'message' => 'data Human Resource Pool not found!', 'code' => 400], 400);
die();
return response()->json(['status' => 'failed', 'message' => 'Limited to create human resource!', 'code' => 500], 500);
}
if ($result) {
return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfully updated!', 'code' => 200], 200);
return response()->json(['status' => 'success', 'data' => $result, 'message' => 'Human Resource Pool successfully updated!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'Human Resource Pool failed updated!', 'code' => 400], 400);
}
@ -94,7 +197,6 @@ class HumanResourceController extends Controller
$delete = $data->delete();
} else {
return response()->json(['status' => 'failed', 'message' => 'data Human Resource Pool not found!', 'code' => 400], 400);
die();
}
@ -118,7 +220,7 @@ class HumanResourceController extends Controller
public function list()
{
$data = HumanResource::select('id', 'name', 'role_id')->get();
$data = HumanResource::select('id', 'name', 'role_id','company_id')->get();
$countData = $data->count();
if ($data) {
@ -196,4 +298,60 @@ class HumanResourceController extends Controller
{
Artisan::call('sync:integration-human-resources');
}
public function sendEmail($email, $password)
{
$user = User::select('email', 'name', 'username')->where('email', $email)->first();
if (!$user) {
return response()->json(['status' => 'error', 'message' => 'e-mail not found '], 400);
} else {
$this->reqHttpCurl($email, $password, $user->username, $user->name);
return response()->json(['status' => 'error', 'code'=>400, 'message' => 'e-mail not found '], 400);
}
}
private function reqHttpCurl($email, $password, $username, $name)
{
$postData = [
"to" => $email,
"name" => $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,
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));
}
}
}

203
app/Http/Controllers/ImageController.php

@ -2,13 +2,17 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Image;
use App\Models\Company;
use Illuminate\Http\Request;
use App\Models\ProductTransaction;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class ImageController extends Controller
{
public function uploadImage(Request $request){
DB::beginTransaction();
if($request->hasFile('files')){
$this->validate($request, [
@ -19,34 +23,173 @@ class ImageController extends Controller
$ref_id = $request->ref_id;
$dokumen = $request->file('files');
$extension = $dokumen->extension();
$category = $request->category;
$name = $ref_id.date("YmdHis").".".$extension;
$resultMove = $dokumen->move($this->pathImage, $name);
if($resultMove){
// Limited Storage
$company = Company::where('company_name', $request->company_name)->first();
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$getLimitStorage = $this->setLimitsStorage($company, $dokumen, $destinationPath['pathImage'], $destinationPath);
}
if(isset($getLimitStorage)) {
if($getLimitStorage === false) {
DB::rollBack();
return response()->json(['status' => 'failed', 'message' => 'Limited storage maximum!', 'code' => 500], 500);
}
$data = [
'ref_id' => (int)$ref_id,
'image' => $name,
'category' => $request->category
'category' => $category
];
$result = Image::create($data);
if($result){
$company = Company::find((int)$ref_id);
if($company && $category === 'company_logo_login') {
$dataArray = json_decode($company['logo_login'], true);
if(isset($dataArray['slider'])) {
$jsonImageSlider['login'] = $name;
$jsonImageSlider['slider'] = $dataArray['slider'];
} else {
$jsonImageSlider['login'] = $name;
}
$company->update([
'logo_login' => $jsonImageSlider
]);
}
if($company && $category === 'company_logo_header') {
$company->update([
'logo_header' => array('content' => $name)
]);
}
if($company && $category === 'company_favicon') {
$company->update([
'favicon_image' => array('content' => $name)
]);
}
if($dokumen->move($destinationPath['pathImage'], $name) && $result) {
DB::commit();
return response()->json(['status' => 'success', "name_image" => $name,'message' => 'image upload is successfully!','code' => 200], 200);
} else {
unlink($this->pathImage.$name);
DB::rollBack();
unlink($destinationPath['pathImage'].$name);
return response()->json(['status' => 'failed','message' => 'image upload is failed!' ,'code' => 400], 400);
}
} else {
DB::rollBack();
return response()->json(['status'=>'failed','message'=>'image upload is failed!','code'=>400], 400);
}
} else {
DB::rollBack();
return response()->json(['status'=>'failed','message'=>'image is required!','code'=>400], 400);
}
}
public function uploadMultipleImage(Request $request) {
$this->validate($request, [
'ref_id' => 'required',
'category' => 'required',
'files.*' => 'required|file|mimes:jpeg,png,jpg,gif|max:2048',
]);
if ($request->hasFile('files')) {
$ref_id = $request->ref_id;
$category = $request->category;
$dokumen = $request->file('files');
$successCount = 0;
$imageSlider = [];
// Limited Storage
$company = Company::where('company_name', $request->company_name)->first();
if($company) {
$totalSize = 0;
$sizeFile = 0;
foreach ($dokumen as $file) {
$sizeFile += $file->getSize();
}
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$folderPath = $destinationPath['pathImage'];
if (!file_exists($folderPath)) {
mkdir($folderPath, 0777, true);
}
$files = scandir($folderPath);
foreach ($files as $file) {
if (is_file($folderPath . '/' . $file)) {
$totalSize += filesize($folderPath . '/' . $file);
}
}
$totalSize += $sizeFile;
$transaction = ProductTransaction::query()
->where('company_id', $company['id']);
$cloneQueryTransaction = clone $transaction;
$countCreate = false;
if($transaction->where([['type_paket','Basic'], ['amount','!=',null]])->exists()) {
$maximumSize = 500 * 1024 * 1024;
$countCreate = true;
} elseif ($cloneQueryTransaction->where([['type_paket','Free'], ['amount', 0]])->exists()) {
$maximumSize = 50 * 1024 * 1024;
$countCreate = true;
}
if($countCreate) {
if ($totalSize > $maximumSize) {
return response()->json(['status'=>'failed','message'=>'Limited storage maximum!','code'=> 500], 500);
}
}
}
foreach ($dokumen as $file) {
$extension = $file->extension();
$name = $ref_id.date("YmdHis").$successCount.".".$extension;
$resultMove = $file->move($folderPath, $name);
if ($resultMove) {
$data = [
'ref_id' => (int) $ref_id,
'image' => $name,
'category' => $category
];
$imageSlider[] = [
'content' => $name
];
$result = Image::create($data);
if ($result) {
$successCount++;
} else {
unlink($folderPath . $name);
}
}
}
$company = Company::find((int)$ref_id);
if($company && $category === 'company_slider_login') {
$dataArray = json_decode($company['logo_login'], true);
if(isset($dataArray['login'])) {
$jsonImageSlider['login'] = $dataArray['login'];
$jsonImageSlider['slider'] = $imageSlider;
} else {
$jsonImageSlider['slider'] = $imageSlider;
}
$company->update([
'logo_login' => $jsonImageSlider
]);
}
if ($successCount > 0 && $company) {
return response()->json(['status' => 'success', 'message' => "$successCount images uploaded successfully!", 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'No images uploaded successfully!', 'code' => 400], 400);
}
} else {
return response()->json(['status' => 'failed', 'message' => 'Image is required!', 'code' => 400], 400);
}
}
public function delete($id)
{
$data = Image::find($id);
@ -58,8 +201,6 @@ class ImageController extends Controller
return response()->json(['status'=>'failed','message'=>'data image not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'data image successfully deleted!','code'=>200], 200);
}else{
@ -78,12 +219,13 @@ class ImageController extends Controller
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
public function deleteByRef($id, $category)
public function deleteByRef($id, $category, $company_id)
{
$data = Image::where("ref_id", $id)->where("category", $category)->first();
if($data){
unlink($this->pathImage.$data->image);
$data = Image::where("ref_id", (int)$id)->where("category", $category)->first();
$company = Company::find($company_id);
if($data && $company){
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
unlink($destinationPath['pathImage'].$data->image);
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data image not found!','code'=>400], 400);
@ -98,6 +240,35 @@ class ImageController extends Controller
}
}
public function deleteByRefMultiple($id, $category, $company_id)
{
$successCount = 0;
$data = Image::where([
["ref_id", intval($id)],
["category", $category]
])->get();
$company = Company::find($company_id);
if($data->isNotEmpty() && $company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
foreach($data as $img) {
unlink($destinationPath['pathImage'].$img->image);
$delete = $img->delete();
if($delete){
$successCount++;
}
}
} else {
return response()->json(['status'=>'failed','message'=>'data image not found!','code'=>400], 400);
die();
}
if($successCount > 0) {
return response()->json(['status'=>'success','message'=>'data image successfully deleted!','code'=>200], 200);
} else {
return response()->json(['status'=>'failed','message'=>'data image failed deleted!','code'=>400], 400);
}
}
public function getByRefId($id, $category)
{
if(!$id || (int) $id < 0 || $id==""){

115
app/Http/Controllers/KanbanBoardController.php

@ -0,0 +1,115 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\KanbanBoard;
class KanbanBoardController extends Controller
{
public function add(Request $request){
$this->validate($request, [
'name_board' => 'required',
'header_color' => 'required',
'body_color' => 'required',
'proyek_id' => 'required',
'version_gantt_id' => 'required',
'status_progress' => 'required'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$statusCount = KanbanBoard::where('version_gantt_id', $request->version_gantt_id)
->where('status_progress', $request->status_progress)
->get()
->count();
if ($statusCount < 1 || $request->status_progress == 'none') {
$result = KanbanBoard::create($data);
} else {
return response()->json(['status'=>'failed','message'=>'Board kanban failed created','code'=>400], 400);
}
if($result){
return response()->json(['status'=>'success','message'=>'Board kanban successfull created','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'Board kanban failed created','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 = KanbanBoard::find($id);
if($data){
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'Data Board kanban not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'Board kanban successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'Board kanban failed updated!','code'=>400], 400);
}
}
public function delete($id)
{
$data = KanbanBoard::find($id);
if($data){
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'Data Board kanban not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'Board kanban successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'Board kanban failed deleted!','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 = KanbanBoard::find($id);
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get data Board kanban, please try again later!','code'=>400], 400);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'kanban_board');
$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(Request $request)
{
$query = KanbanBoard::select("*");
$countData = $query->count();
$data = $this->paramsMethodGet($query, $countData, $request);
if($data)
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>count($data)], 200);
return response()->json(['status'=>'failed','message'=>'failed get Board kanban, please try again later!','code'=>400], 400);
}
}

258
app/Http/Controllers/KanbanCardController.php

@ -0,0 +1,258 @@
<?php
namespace App\Http\Controllers;
use App\Models\User;
use App\Models\Project;
use App\Models\Activity;
use App\Models\KanbanCard;
use App\Models\KanbanBoard;
// use Illuminate\Support\Arr;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class KanbanCardController extends Controller
{
private function add($board_id, $gantt_id, $type_activity, $status_progress)
{
$dataActivity = Activity::where("version_gantt_id", $gantt_id)
->where("type_activity", $type_activity)
->get();
foreach ($dataActivity as $keyA) {
// $this->add($keyA->id, $gantt_id, $board_id);
$data = array(
'activity_id' => $keyA->id,
'kanban_board_id' => $board_id,
'version_gantt_id' => $gantt_id,
'created_by' => $this->currentName
);
switch ($status_progress) {
case 'open':
if ($keyA->persentase_progress == 0) {
$add = KanbanCard::create($data);
}
break;
case 'on-progress':
if ($keyA->persentase_progress > 0 && $keyA->persentase_progress < 100) {
$cardIds = DB::table('kanban_card as kc')
->join('m_activity as ma', 'kc.activity_id', '=', 'ma.id')
->where('kc.activity_id', '=', $keyA->id)
->select('kc.id')
->get();
foreach ($cardIds as $cardId) {
$this->delete($cardId->id);
}
$add = KanbanCard::create($data);
}
break;
case 'done':
if ($keyA->persentase_progress == 100) {
$cardIds = DB::table('kanban_card as kc')
->join('m_activity as ma', 'kc.activity_id', '=', 'ma.id')
->where('kc.activity_id', '=', $keyA->id)
->select('kc.id')
->get();
foreach ($cardIds as $cardId) {
$this->delete($cardId->id);
}
$add = KanbanCard::create($data);
}
break;
}
}
return "success";
}
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 = KanbanCard::where("activity_id", $id);
if ($data) {
$result = $data->update($request->all());
} else {
return response()->json(['status' => 'failed', 'message' => 'Data Card kanban not found!', 'code' => 400], 400);
die();
}
$board = KanbanBoard::find($request->kanban_board_id);
$activity = Activity::find($id);
if ($board->status_progress == "done" && $activity) {
$activity->update(['persentase_progress' => 100]);
} else{
if($activity['persentase_progress'] != 95 && $activity['persentase_progress'] != 100){
$activity->update(['persentase_progress' => 0]);
}else{
$activity->update(['persentase_progress' => 95]);
}
}
if ($result) {
return response()->json(['status' => 'success', 'message' => 'Board kanban successfully updated!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'Board kanban failed updated!', 'code' => 400], 400);
}
}
public function delete($id)
{
$data = KanbanCard::find($id);
if ($data) {
$delete = $data->delete();
} else {
return response()->json(['status' => 'failed', 'message' => 'Data Board kanban not found!', 'code' => 400], 400);
die();
}
if ($delete) {
return response()->json(['status' => 'success', 'message' => 'Board kanban successfully deleted!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'Board kanban failed deleted!', '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 = KanbanCard::find($id);
if ($result) {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'failed get data Board kanban, please try again later!', 'code' => 400], 400);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'kanban_board');
$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 getData($project_id, $gantt_id, $board_id, Request $request)
{
// cek ketika dia owner dari project maka
$SESSIONID = $request->session;
$status_progress = KanbanBoard::select("status_progress")->where('id', $board_id)->first();
if ($status_progress) {
if (DB::table('user_to_version_gantt')->where('user_id', $SESSIONID)->where('version_gantt_id', $gantt_id)->exists()) {
$dataCard = $this->getDataAll($project_id, $gantt_id, $board_id, $status_progress->status_progress, true);
} else {
$dataCard = $this->getDataContributor($project_id, $gantt_id, $board_id, $request, $status_progress->status_progress, true);
}
} else {
return response()->json(['status' => 'empty', 'message' => 'data board is empty, please you insert!', 'code' => 200], 200);
}
if ($dataCard && count($dataCard) > 0){
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataCard, "totalRecord" => count($dataCard)], 200);
}else{
return response()->json(['status' => 'empty', 'message' => 'data card is empty, please you insert!', 'code' => 200], 200);
}
}
private function getDataAll($project_id, $gantt_id, $board_id, $status_progress, $status)
{
$dataFinal = [];
if($status == true){
if ($status_progress != 'none') {
if (KanbanCard::where('kanban_board_id', $board_id)->where("version_gantt_id", $gantt_id)->count() == 0) {
$this->add($board_id, $gantt_id, 'task', $status_progress);
$this->getDataAll($project_id, $gantt_id, $board_id, $status_progress, false);
}
}
}
$dataCard = DB::table("kanban_card as kc")
->select("ma.id as activity_id", "ma.name", "ma.start_date", "ma.end_date", "ma.persentase_bobot", "ma.jumlah_pekerjaan", "ma.bobot_planning", "ma.persentase_progress")
->join("m_activity as ma", "ma.id", "=", "kc.activity_id")
->where("kc.kanban_board_id", $board_id)
->where("kc.version_gantt_id", $gantt_id)
->orderBy('ma.sortorder')
->get();
foreach ($dataCard as $keyCard) {
$query = DB::table("assign_hr_to_activity as ahta")
->select("ahta.id", "mu.name", "mu.id as id_hr")
->join("m_users as mu", "mu.id", "=", "ahta.user_id")
->where("ahta.activity_id", $keyCard->activity_id)
->get();
$dataArray = array(
"id" => $keyCard->activity_id,
"assign_hr" => $query,
"activity" => $keyCard->name,
"start_date" => $keyCard->start_date,
"end_date" => $keyCard->end_date,
"jumlah_pekerjaan" => $keyCard->jumlah_pekerjaan,
"bobot_planning" => $keyCard->bobot_planning,
"persentase_progress" => $keyCard->persentase_progress
);
$dataFinal[] = $dataArray;
}
// }
return $dataFinal;
}
private function getDataContributor($project_id, $gantt_id, $board_id, $request, $status_progress, $status)
{
$dataFinal = [];
if($status == true){
if ($status_progress != 'none') {
if (KanbanCard::where('kanban_board_id', $board_id)->where("version_gantt_id", $gantt_id)->count() == 0) {
$this->add($board_id, $gantt_id, 'task', $status_progress);
$this->getDataContributor($project_id, $gantt_id, $board_id, $request, $status_progress, false);
}
}
$dataUser = User::whereId($request->session)->first();
$dataCard = DB::table("kanban_card as kc")
->select("ma.id as activity_id", "ma.name", "ma.start_date", "ma.end_date", "ma.persentase_bobot", "ma.jumlah_pekerjaan", "ma.bobot_planning", "ma.persentase_progress")
->join("m_activity as ma", "ma.id", "=", "kc.activity_id")
->where([
["kc.created_by", $dataUser['name']],
["kc.kanban_board_id", $board_id],
["kc.version_gantt_id", $gantt_id]
])
->orderBy('ma.sortorder')
->get();
foreach ($dataCard as $keyCard) {
$query = DB::table("assign_hr_to_activity as ahta")
->select("ahta.id", "mu.name", "mu.id as id_hr")
->join("m_users as mu", "mu.id", "=", "ahta.user_id")
->where("ahta.activity_id", $keyCard->activity_id)
->get();
$dataArray = array(
"id" => $keyCard->activity_id,
"assign_hr" => $query,
"activity" => $keyCard->name,
"start_date" => $keyCard->start_date,
"end_date" => $keyCard->end_date,
"jumlah_pekerjaan" => $keyCard->jumlah_pekerjaan,
"bobot_planning" => $keyCard->bobot_planning,
"persentase_progress" => $keyCard->persentase_progress,
"test" => $request->session
);
$dataFinal[] = $dataArray;
}
}
return $dataFinal;
}
}

45
app/Http/Controllers/MenuCompanyController.php

@ -9,33 +9,15 @@ use Illuminate\Support\Facades\Log;
class MenuCompanyController extends Controller
{
// public function add(Request $request)
// {
// $this->validate($request, [
// 'icon' => 'required',
// 'name' => 'string|required',
// 'url' => 'required|unique:m_company_menu,url',
// 'sequence' => 'required|integer',
// ]);
// $data = $request->all();
// $data['created_by'] = $this->currentName;
// $result = MenuCompany::create($data);
// if ($result) {
// return response()->json(['status' => 'success', 'message' => 'add data menu successfully!', 'code' => 200], 200);
// } else {
// return response()->json(['status' => 'failed', 'message' => 'add data menu failed!', 'code' => 400], 400);
// }
// }
public function addMultiple(Request $request)
{
$menus = $request->all();
if (is_array($menus) && count($menus) > 0) {
$data = MenuCompany::where('company_id',$menus[0]['company_id']);
if($data){
$data->delete();
}
if (is_array($menus) && count($menus) > 0 && isset($menus)) {
$countRes = 0;
foreach ($menus as $menu) {
@ -60,12 +42,17 @@ class MenuCompanyController extends Controller
}
if ($countRes > 0) {
return response()->json(['status' => 'success', 'message' => 'add data menu successfully!', 'code' => 200]);
return response()->json(['status' => 'success', 'message' => 'Add data menu successfully!', 'code' => 200]);
} else {
return response()->json(['status' => 'failed', 'message' => 'add data menu failed created!', 'code' => 400]);
return response()->json(['status' => 'failed', 'message' => 'Add data menu failed created!', 'code' => 500]);
}
} else {
return response()->json(['status' => 'failed', 'message' => 'add data menu failed created!', 'code' => 400]);
if(isset($data))
{
return response()->json(['status' => 'success', 'message' => 'Add data menu successfully!', 'code' => 200]);
}else{
return response()->json(['status' => 'failed', 'message' => 'Add data menu failed created!', 'code' => 500]);
}
}
}
@ -120,15 +107,15 @@ class MenuCompanyController extends Controller
if ($data) {
$delete = $data->delete();
} else {
return response()->json(['status' => 'failed', 'message' => 'data menu not found!', 'code' => 400], 400);
return response()->json(['status' => 'failed', 'message' => 'Data menu not found!', 'code' => 400], 400);
die();
}
if ($delete) {
return response()->json(['status' => 'success', 'message' => 'data menu successfully deleted!', 'code' => 200], 200);
return response()->json(['status' => 'success', 'message' => 'Data menu successfully deleted!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'data menu failed deleted!', 'code' => 400], 400);
return response()->json(['status' => 'failed', 'message' => 'Data menu failed deleted!', 'code' => 400], 400);
}
}

22
app/Http/Controllers/MenuController.php

@ -30,7 +30,8 @@ class MenuController extends Controller
}
}
public function edit($id){
public function edit($id)
{
if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
die();
@ -108,7 +109,13 @@ class MenuController extends Controller
public function listMenu($id)
{
$dataParent = RoleMenu::select("m_menu.*")
$dataParent = RoleMenu::select(
'm_menu.*',
"t_roles_menu.create",
"t_roles_menu.read",
"t_roles_menu.update",
"t_roles_menu.delete"
)
->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id')
->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id')
->whereNull('m_menu.parent_id')
@ -127,7 +134,13 @@ class MenuController extends Controller
protected function getChildrenMenu($id, $role_id)
{
$dataChildren = RoleMenu::select("m_menu.*")
$dataChildren = RoleMenu::select(
'm_menu.*',
"t_roles_menu.create",
"t_roles_menu.read",
"t_roles_menu.update",
"t_roles_menu.delete"
)
->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id')
->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id')
->where('m_roles.id', $role_id)
@ -136,8 +149,7 @@ class MenuController extends Controller
->get();
$children = [];
if ($dataChildren) {
foreach($dataChildren as $data)
{
foreach ($dataChildren as $data) {
$data->children = $this->getChildrenMenu($data->id, $role_id);
$children[] = $data;
}

92
app/Http/Controllers/ProductTransactionController.php

@ -0,0 +1,92 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\ProductTransaction;
class ProductTransactionController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'company_id' => 'required|integer',
'type_paket' => 'required|string',
'amount' => 'required',
'exp_ospro' => 'required'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = ProductTransaction::create($data);
if ($result) {
return response()->json(['status' => 'success', 'data' => $result, 'message' => 'Add Transaction successfully!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'Add Transaction 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 = ProductTransaction::find($id);
if ($result) {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'Failed get data transaction, 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 = ProductTransaction::find($id);
if($data){
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'Data transaction not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'Data transaction successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'Data transaction failed updated!','code'=>400], 400);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 't_transaction');
$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 = ProductTransaction::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 Transaction, please try again later!', 'code' => 400], 400);
}
}
}

351
app/Http/Controllers/ProjectCarausellController.php

@ -2,313 +2,53 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\{
User,
Project,
Activity,
HierarchyFtth,
ProjectComment,
VersionGantt,
UserToProyek,
UserToActivity,
Presence
ProjectIssues,
ProjectRisks
};
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Helpers\MasterFunctionsHelper;
use Carbon\Carbon;
class ProjectCarausellController extends Controller
{
// public function invoke($id)
// {
// $dateStart = Carbon::now()->startOfDay();
// $dateEnd = Carbon::now()->endOfDay();
// // Mengatur waktu awal bulan dan mengurangkan 1 tahun
// $startDate = Carbon::now()->startOfMonth()->subYear()->format('Y-m-d');
// // Mengatur waktu saat ini dan mengurangkan 1 tahun
// $endDate = Carbon::now()->subYear()->format('Y-m-d');
// if(empty($id) || !is_int((int)$id)){
// return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
// }
// $result = Project::select('id','nama','budget_health','kode_sortname','pm_id','rencana_biaya','company','scurve','calculation_status')->find($id);
// if(!$result){
// return response()->json(['status'=>'failed','message'=> 'Project not found!','code'=> 404], 404);
// }
// $ganttData = VersionGantt::where('proyek_id', $id)
// ->select('id', 'name_version','hierarchy_ftth_id','cost_to_complete')
// ->get();
// // Get Id Gantt & hierarchy_ftth_id
// $gantt_id = $ganttData->pluck('id')->toArray();
// $hierarchy_ftth_id = $ganttData->pluck('hierarchy_ftth_id')->toArray();
// // Heararchy
// $finalData = [];
// if($hierarchy_ftth_id){
// $ftth = HierarchyFtth::whereIn('id',$hierarchy_ftth_id)->get();
// if($ftth->first() != null)
// {
// array_push($finalData, $ftth->first());
// }
// if($ftth->where('parent_id','!=', null)->first()){
// $this->getParents($finalData, $ftth->pluck('parent_id')->toArray());
// }
// } else {
// return $finalData;
// }
// // SCurve
// $SCurve = MasterFunctionsHelper::getSCurveCarausell($result['id'],$gantt_id,'week');
// // Overdue Activities
// $endDate = Activity::where('proyek_id', $result['id'])
// ->orderByDesc('end_date')
// ->value('end_date');
// $overdueActivities = Activity::whereIn('version_gantt_id', $gantt_id)->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$endDate)->orderBy('end_date', 'asc')->get();
// // Project Comment
// $projectComment = ProjectComment::query()
// ->select('project_id','gantt_id','comment','created_at')
// ->where('project_id',$result['id'])
// ->whereIn('gantt_id',$gantt_id)
// ->get();
// // Manpower
// $manCount = UserToProyek::where('proyek_id', $result['id'])->count();
// // Assigned
// $utAct = UserToActivity::query()
// ->whereIn('version_gantt_id', $gantt_id)
// ->get();
// // Actual
// $presence = Presence::whereBetween('clock_in', [$dateStart, $dateEnd])
// ->select('m_users.name','m_users.ktp_number')
// ->join('m_users','t_clock_in_out.user_id','m_users.id')
// ->get();
// // Report distribution
// $reportsDistribution = DB::table('assign_material_to_activity as ama')
// ->select('u.name', 'a.name as activity_name', 'ama.qty_planning', 'ram.qty as qty_real','rm.description as material_name', 'rm.uom as material_unit',
// 'ram.lat', 'ram.lon', 'ram.description as report_notes', 'ram.report_date')
// ->join('report_activity_material as ram', 'ram.assign_material_id', '=', 'ama.id')
// ->join('m_req_material as rm', 'rm.id', '=', 'ama.material_id')
// ->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
// ->join('m_users as u', 'u.id', '=', 'ram.user_id')
// ->where('ama.proyek_id', '=', $result['id'])
// ->whereNotNull('ram.lat')
// ->whereBetween('ram.report_date', [$startDate, $startDate]);
// // Check Existing
// $actualStartExist = Activity::whereIn('version_gantt_id',$gantt_id)->whereNotNull('actual_start')->exists();
// $actualEndExist = Activity::whereIn('version_gantt_id',$gantt_id)->exists();
// $query = Activity::query()->whereIn('version_gantt_id', $gantt_id);
// // Start
// if ($actualStartExist) {
// $startDate = $query->select('version_gantt_id',DB::raw('MIN(start_date) as min_start'))
// ->groupBy('version_gantt_id')
// ->get();
// } else {
// $startDate = $query->select('version_gantt_id',DB::raw('MIN(start_date) as min_start','version_gantt_id'))
// ->groupBy('version_gantt_id')
// ->orderBy('min_start', 'ASC')
// ->get();
// }
// // End
// if($actualEndExist)
// {
// $maxIds = $query->selectRaw('MAX(id) as max_id')
// ->groupBy('version_gantt_id')
// ->pluck('max_id', 'version_gantt_id');
// $endDate = Activity::whereIn('id', $maxIds)->select('end_date','version_gantt_id')->get();
// }
// $plannedStart = $query->selectRaw('MIN(planned_start) as min_planned_start, version_gantt_id')
// ->groupBy('version_gantt_id')
// ->orderBy('min_planned_start')
// ->get();
// $plannedEnd = $query->selectRaw('MAX(planned_end) as max_planned_end, version_gantt_id')
// ->groupBy('version_gantt_id')
// ->orderByDesc('max_planned_end')
// ->get();
// $projectManager = User::whereId($result['pm_id'])->value('name');
// $key =1;
// foreach($ganttData as $gantt)
// {
// $pStart =$plannedStart->where('version_gantt_id',$gantt['id'])->first();
// $actStart =$startDate->where('version_gantt_id',$gantt['id'])->first();
// $actEnd =$endDate->where('version_gantt_id',$gantt['id'])->first();
// $pEnd =$plannedEnd->where('version_gantt_id',$gantt['id'])->first();
// $matchingActivities = $overdueActivities->where('version_gantt_id', $gantt['id']);
// $matchingProjectComment = $projectComment->where('version_gantt_id', $gantt['id']);
// $usAtc = $utAct->where('version_gantt_id', $gantt['id']);
// $arr[] =
// [
// 'gantt_id'=>$gantt['id'],
// 'projectManager'=>$projectManager,
// 'name_version'=>$gantt['name_version'],
// 'cost_to_complete'=>$gantt['cost_to_complete'],
// 'schedule' => [
// 'plannedStart'=> $pStart['min_planned_start'],
// 'actual_start'=>$actStart['min_start'],
// 'plannedFinish'=>$pEnd['max_planned_end'],
// 'estimatedFinish'=>$actEnd['end_date']
// ],
// 'manpower'=>$manCount,
// 'assigned'=>$usAtc->toArray(),
// 'actual'=>count($presence->toArray()),
// 'overdue_activities'=>$matchingActivities->toArray(),
// 'project_comment'=>$matchingProjectComment->toArray(),
// 'hierarchy'=>$finalData,
// 'proyek'=>$result,
// 'key'=>$key++
// ];
// }
// return response()->json(['status'=>'success','code'=> 200,'data'=>$arr,'report_distribution'=>$reportsDistribution,'sCurve'=>$SCurve, 'count'=>count($arr)], 200);
// }
// public function getParents(&$data, $id){
// $ftth = HierarchyFtth::whereIn('id',$id)->get();
// array_push($data, $ftth);
// if ($ftth->pluck('parent_id')->toArray()) {
// $this->getParents($data, $ftth->pluck('parent_id')->toArray());
// }
// }
public function invoke()
public function invoke(Request $request)
{
// Data Master
// Mengatur waktu awal bulan dan mengurangkan 1 tahun
$startDate = Carbon::now()->startOfMonth()->subYear()->format('Y-m-d');
// Mengatur waktu saat ini dan mengurangkan 1 tahun
$endDate = Carbon::now()->subYear()->format('Y-m-d');
$ganttData = VersionGantt::query()
->select('id', 'name_version','hierarchy_ftth_id','cost_to_complete','proyek_id')
->get();
$projectData = Project::query()
->select("id","nama","kode_sortname","pm_id","budget_health","calculation_status","mulai_proyek","akhir_proyek","rencana_biaya","company","scurve")
->get();
// nested looping
$arr = [];
foreach($projectData as $project) {
$ganttForProject = [];
foreach ($ganttData as $gantt) {
if ($gantt['proyek_id'] === $project['id']) {
// Gantt
$ganttForProject[] = [
"gantt_id" => $gantt['id'],
'proyek_id' => $gantt['proyek_id'],
"name_version" => $gantt['name_version'],
"hierarchy_ftth_id" => $gantt['hierarchy_ftth_id'],
"cost_to_complete" => $gantt['cost_to_complete'],
];
// Activity
$activity = Activity::query()
->select('id','name','proyek_id','version_gantt_id','type_activity','parent_id','kode_sortname','rencana_biaya','start_date','end_date','biaya_actual','persentase_bobot','persentase_progress','planned_start','planned_end','actual_start','actual_end')
->whereNull('parent_id')
->where([
["proyek_id", $project['id']],
["version_gantt_id", $gantt['id']]
])
->first();
$actualStartExist = Activity::query()
->where('version_gantt_id', $gantt['id'])
->whereNotNull('actual_start')
->exists();
$actualEndExist = Activity::query()
->where('version_gantt_id', $gantt['id'])
->exists();
$query = Activity::where('version_gantt_id', $gantt['id']);
if ($actualStartExist) {
$startDate = $query->orderBy('actual_start')->value('start_date');
} else {
$startDate = $query->orderBy('start_date')->value('start_date');
}
if($actualEndExist)
{
$maxEndDate = $query->max('id');
$endDate = $query->where('id',$maxEndDate)->first()->end_date;
}
// Master Data
$company_id = $request->route('company_id');
$all_project = $request->route('all_project');
$hierarchy = $request->route('hierarchy');
$plannedStart = Activity::where('version_gantt_id', $gantt['id'])
->orderBy('planned_start')
->value('planned_start');
$plannedEnd = Activity::where('version_gantt_id', $gantt['id'])
->orderByDesc('planned_end')
->value('planned_end');
$query = Project::query()
->select("id", "nama", "kode_sortname", "pm_id", "budget_health", "calculation_status", "mulai_proyek", "akhir_proyek", "rencana_biaya", "company", "scurve");
// SCurve
$req = (object)[
'project_id' => $project['id'],
'gantt_id' => $gantt['id'],
'period' => 'week',
];
$SCurve = MasterFunctionsHelper::getSCurveCarausell($req);
// Overdue
$endDate = Activity::where('proyek_id', $project['id'])
->orderByDesc('end_date')
->value('end_date');
$overdueActivities = Activity::query()
->where([
['version_gantt_id', $gantt['id']],
['persentase_progress', '!=', 100]
])
->whereNotNull('parent_id')
->whereDate('end_date','<=',$endDate)
->orderBy('end_date', 'asc')
->get();
// Manpower
$manCount = UserToProyek::where('proyek_id', $project['id'])->count();
// Assigned
$assigned = UserToActivity::query()
->select('assign_hr_to_activity.proyek_id', 'assign_hr_to_activity.user_id', 'm_activity.id', 'm_activity.name', 'm_activity.start_date', 'm_activity.end_date')
->join('m_activity', 'm_activity.id', '=', 'assign_hr_to_activity.activity_id')
->where('assign_hr_to_activity.version_gantt_id', $gantt['id'])
->get();
// Project Comment
$projectComment = ProjectComment::query()
->select('m_users.name','m_users.username','m_project_comment.project_id','m_project_comment.gantt_id','m_project_comment.comment','m_project_comment.created_at')
->join('m_users','m_project_comment.sender_id','m_users.id')
->where([
['project_id',$project['id']],
['gantt_id',$gantt['id']]
])
->get();
// Hierarchy
$finalData = [];
$ganttHierarchy = VersionGantt::find($gantt['id']);
if ($ganttHierarchy->hierarchy_ftth_id) {
$ftth = HierarchyFtth::find($ganttHierarchy->hierarchy_ftth_id);
array_push($finalData, $ftth);
if($ftth->parent_id){
$this->getParents($finalData, $ftth->parent_id);
}
if ($all_project) {
$query->where('company_id', $company_id);
} else {
$finalData = $finalData;
$query->where('created_by_id', $hierarchy);
}
$reports = DB::table('assign_material_to_activity as ama')
->select('u.name', 'a.name as activity_name', 'ama.qty_planning', 'ram.qty as qty_real','rm.description as material_name', 'rm.uom as material_unit',
'ram.lat', 'ram.lon', 'ram.description as report_notes', 'ram.report_date')
->join('report_activity_material as ram', 'ram.assign_material_id', '=', 'ama.id')
->join('m_req_material as rm', 'rm.id', '=', 'ama.material_id')
->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->join('m_users as u', 'u.id', '=', 'ram.user_id')
->where('ama.proyek_id', '=', $project['id'])
->whereNotNull('ram.lat')
->whereBetween('ram.report_date', [$startDate, $endDate]);
}
}
$projectData = $query->get();
$arr = [];
foreach ($projectData as $project) {
$projectRisk = ProjectRisks::query()
->select('proyek_id', 'description', 'level_risk', 'preventive_risk')
->where('proyek_id', $project['id'])
->get()
->toArray();
$projectIssue = ProjectIssues::query()
->select('proyek_id', 'description', 'level_issue')
->where('proyek_id', $project['id'])
->get()
->toArray();
$ganttData = VersionGantt::query()
->select('id', 'name_version', 'hierarchy_ftth_id', 'cost_to_complete', 'proyek_id', 'calculation_type')
->where('proyek_id', $project['id'])
->orderByDesc('id')
->first();
$projectManager = User::where('id', $project['pm_id'])->value('name');
$arr[] = [
"project" => [
"id" => $project['id'],
@ -322,34 +62,13 @@ class ProjectCarausellController extends Controller
"rencana_biaya" => $project['rencana_biaya'],
"company" => $project['company'],
"scurve" => $project['scurve'],
"gantt"=>$ganttForProject
],
"hierarchy"=>$finalData,
"manpower"=>$manCount,
"assigned"=>$assigned,
"actual"=>0,
"project_comment"=>$projectComment,
"project_manager" => $projectManager,
"activity" => [
"data" => $activity,
"start_date"=>$startDate,
"end_date"=>$endDate,
"planned_start"=>$plannedStart,
"planned_end"=>$plannedEnd
],
"report_distribution"=>$reports,
"overdueActivities"=>$overdueActivities,
"SCurve"=>$SCurve
"project_risk" => $projectRisk,
"project_issue" => $projectIssue,
"gantt" => $ganttData
];
}
return response()->json(['status'=>'success','code'=> 200,'data'=>$arr, "count"=>count($arr)], 200);
}
public function getParents(&$data, $id){
$ftth = HierarchyFtth::find($id);
array_push($data, $ftth);
if ($ftth->parent_id) {
$this->getParents($data, $ftth->parent_id);
}
return response()->json(['status' => 'success', 'code' => 200, 'data' => $arr, "total_project" => count($arr)], 200);
}
}

465
app/Http/Controllers/ProjectController.php

@ -3,43 +3,48 @@
namespace App\Http\Controllers;
use DateTime;
use App\Models\Link;
use App\Models\User;
use App\Models\Image;
use App\Models\Holiday;
use App\Models\Project;
use App\Models\Activity;
use App\Models\ReportK3;
use App\Jobs\ProcessSCurve;
use App\Models\AssignTools;
use App\Models\OfficeHours;
use App\Models\ProjectType;
use App\Models\ProjectPhase;
use App\Models\ProjectRisks;
use App\Models\UserToProyek;
use App\Models\VersionGantt;
use Illuminate\Http\Request;
use App\Models\HierarchyFtth;
use App\Models\ProjectIssues;
use App\Models\AssignMaterial;
use App\Models\DokumenProject;
use App\Models\ProjectCharter;
use App\Models\ReportActivity;
use App\Models\ShowHideColumn;
use App\Models\UserToActivity;
use App\Models\ActivityDokumen;
use App\Models\CommentActivity;
use App\Models\ProjectApproval;
use App\Models\RequestMaterial;
use App\Models\ProjectMileStone;
use App\Models\ProjectChecklists;
use Illuminate\Support\Facades\DB;
use App\Models\ProjectParticipants;
use App\Models\FolderDocumentProyek;
use App\Models\ProjectToChecklistK3;
use App\Models\{
ReportActivityMaterial,
ProjectToChecklistK3,
FolderDocumentProyek,
ProjectParticipants,
ProductTransaction,
ProjectChecklists,
ProjectMileStone,
RequestMaterial,
ProjectApproval,
CommentActivity,
ActivityDokumen,
UserToActivity,
ShowHideColumn,
ReportActivity,
ProjectCharter,
DokumenProject,
AssignMaterial,
ProjectIssues,
HierarchyFtth,
VersionGantt,
UserToProyek,
ProjectRisks,
ProjectPhase,
ProjectType,
OfficeHours,
AssignTools,
ReportK3,
Activity,
Project,
Holiday,
Company,
Image,
User,
Link
};
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\{Artisan, DB};
use App\Helpers\MasterFunctionsHelper;
use App\Models\ReportActivityMaterial;
use Illuminate\Support\Facades\Artisan;
use Carbon\Carbon;
const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1";
@ -51,68 +56,127 @@ class ProjectController extends Controller
$this->validate($request, [
'nama' => 'required',
'mulai_proyek' => 'required',
'mulai_proyek' => 'required',
'akhir_proyek' => 'required',
'rencana_biaya' => 'required',
'type_proyek_id' => 'required'
'type_proyek_id' => 'required',
'company_id' => 'required'
]);
DB::beginTransaction();
try {
$data = $request->all();
$data['created_by'] = $this->currentName;
$data['created_by_id'] = $this->currentId;
if (empty($data['phase_id']))
if (empty($data['phase_id'])) {
$data['phase_id'] = 1;
}
$transaction = ProductTransaction::query()
->where('company_id', $request->company_id);
$cloneQueryTransaction = clone $transaction;
$result = Project::create($data);
$countCreate = false;
$projectResult = Project::query()
->selectRaw('count(*) as total_project')
->where('company_id', $request->company_id)
->first();
if ($transaction->where([['type_paket', 'Basic'], ['amount', '!=', null]])->exists()) {
if ($projectResult['total_project'] < 10) {
$countCreate = true;
}
} elseif ($cloneQueryTransaction->where([['type_paket', 'Free'], ['amount', 0]])->exists()) {
if ($projectResult['total_project'] < 1) {
$countCreate = true;
}
} else {
$countCreate = true;
}
if (!$result)
if ($countCreate) {
$result = Project::create($data);
if (!$result) {
return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 500], 500);
$this->createOfficeHours($result->id);
$dataResultInsert = Project::where('nama', $data['nama'])->where('mulai_proyek', $data['mulai_proyek'])->first();
} else {
$this->createOfficeHours($result['id']);
$dataResultInsert = Project::where([['nama', $data['nama']], ['mulai_proyek', $data['mulai_proyek']]])->first();
DB::commit();
return response()->json(['status' => 'success', 'message' => 'Data added!', 'data_result' => $dataResultInsert, 'code' => 200], 200);
}
} else {
return response()->json(['status' => 'failed', 'message' => 'Limited to create project!', 'code' => 500], 500);
}
} catch (\Throwable $th) {
DB::rollBack();
}
}
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);
$result = Project::query()
->from('m_proyek AS mp')
->where('mp.id', $id)
->selectRaw('value_proyek,scoupe_of_work,kode_sortname,jumlah_stakeholder,nama,mulai_proyek,akhir_proyek,area_kerja,rencana_biaya,biaya_actual,company,pm_id,type_proyek_id,divisi_id,persentase_progress,keterangan,durasi_proyek,progress_by_worklog,currency_symbol,late_consequence,assumtion,currency_code,currency_name,project_objectives,considered_success_when,potential_risk,testing_environment,budget_health,phase_id,calculation_status');
if (!is_null($result->first()['divisi_id'])) {
$result->leftJoin('m_divisi', 'mp.divisi_id', '=', 'm_divisi.id')
->addSelect(DB::raw('m_divisi.name AS nama_divisi'));
}
$result = $result->first();
if (!$result)
$result = Project::select(
'value_proyek',
'scoupe_of_work',
'kode_sortname',
'jumlah_stakeholder',
'nama',
'mulai_proyek',
'akhir_proyek',
'area_kerja',
'rencana_biaya',
'biaya_actual',
'company',
'pm_id',
'type_proyek_id',
'divisi_id',
'persentase_progress',
'keterangan',
'durasi_proyek',
'progress_by_worklog',
'currency_symbol',
'late_consequence',
'assumtion',
'currency_code',
'currency_name',
'project_objectives',
'considered_success_when',
'potential_risk',
'testing_environment',
'budget_health',
'phase_id',
'calculation_status',
'md.name as divisi_name',
'm_proyek.company_id'
)
->leftJoin('m_divisi as md', 'md.id', '=', 'm_proyek.divisi_id')
->where('m_proyek.id', $id)
->first();
if (!$result) {
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
} else {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
}
}
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 = Project::find($id);
if (!$data)
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
$result = $data->update($request->all());
if (!$result)
return response()->json(['status' => 'failed', 'message' => 'Failed to update!', 'code' => 500], 500);
if ($data) {
if ($data->update($request->all())) {
return response()->json(['status' => 'success', 'message' => 'Data updated!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'Failed to update!', 'code' => 500], 500);
}
} else {
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
}
}
private function createOfficeHours($proyek_id)
@ -141,23 +205,30 @@ class ProjectController extends Controller
return true;
}
public function delete($id)
public function delete($id, $company_id)
{
DB::beginTransaction();
$data = Project::find($id);
if (!$data)
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
$this->deleteRelative($id);
if (!$data->delete())
return response()->json(['status' => 'failed', 'message' => 'Delete failed!', 'code' => 500], 500);
$dateNow = Carbon::now();
if ($data) {
$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 {
DB::rollBack();
return response()->json(['status' => 'failed', 'message' => 'Delete failed!', 'code' => 500], 500);
}
} else {
DB::rollBack();
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
}
}
private function deleteRelative($project_id)
private function deleteRelative($project_id, $company_id)
{
DB::transaction(function () use ($project_id, $company_id) {
UserToProyek::where('proyek_id', $project_id)->delete();
UserToActivity::where('proyek_id', $project_id)->delete();
AssignMaterial::where('proyek_id', $project_id)->delete();
@ -174,30 +245,36 @@ class ProjectController extends Controller
OfficeHours::where('proyek_id', $project_id)->delete();
ReportK3::where('proyek_id', $project_id)->delete();
RequestMaterial::where('proyek_id', $project_id)->delete();
$this->deleteVersionGantt($project_id);
$this->deleteDokumenProject($project_id);
$this->deleteVersionGantt($project_id, $company_id);
$this->deleteDokumenProject($project_id, $company_id);
}, 5);
}
private function deleteVersionGantt($project_id)
private function deleteVersionGantt($project_id, $company_id)
{
DB::transaction(function () use ($project_id, $company_id) {
$dataVg = VersionGantt::where("proyek_id", $project_id)->pluck("id");
$vhIds = $dataVg->all();
$activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id');
$activityIds = $activity->all();
$dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get();
$company = Company::find($company_id);
if ($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
foreach ($dataRa as $ra) {
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get();
foreach ($images as $image) {
if (file_exists($this->pathImage . $image->image)) {
unlink($this->pathImage . $image->image);
if (file_exists($destinationPath['pathImage'] . $image->image)) {
unlink($destinationPath['pathImage'] . $image->image);
}
}
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete();
}
$dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get();
foreach ($dataAd as $ad) {
if (file_exists($this->pathActivityDocument . $ad->file)) {
unlink($this->pathActivityDocument . $ad->file);
if (file_exists($destinationPath['pathActivityDocument'] . $ad->file)) {
unlink($destinationPath['pathActivityDocument'] . $ad->file);
}
}
}
ActivityDokumen::whereIn("activity_id", $activityIds)->delete();
@ -208,29 +285,33 @@ class ProjectController extends Controller
ShowHideColumn::whereIn("version_gantt_id", $vhIds)->delete();
Activity::whereIn("version_gantt_id", $vhIds)->delete();
ReportActivity::whereIn("activity_id", $activityIds)->delete();
}, 5);
}
private function deleteDokumenProject($project_id)
private function deleteDokumenProject($project_id, $company_id)
{
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->get();
DB::transaction(function () use ($project_id, $company_id) {
$dataDokumen = DokumenProject::where([['type_dokumen', 'project-document-out-folder'], ['ref_id', $project_id]])->get();
$company = Company::find($company_id);
if ($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
foreach ($dataDokumen as $dokumen) {
if (file_exists($this->pathDocument . $dokumen->file)) {
unlink($this->pathDocument . $dokumen->file);
if (file_exists($destinationPath['pathDocument'] . $dokumen->file)) {
unlink($destinationPath['pathDocument'] . $dokumen->file);
}
}
DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete();
}
DokumenProject::where([['type_dokumen', 'project-document-out-folder'], ['ref_id', $project_id]])->delete();
$dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id");
$ref_ids = $dataFolder->all();
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get();
foreach ($dataDokumen as $dokumen) {
if (file_exists($this->pathDocument . $dokumen->file)) {
unlink($this->pathDocument . $dokumen->file);
if (file_exists($destinationPath['pathDocument'] . $dokumen->file)) {
unlink($destinationPath['pathDocument'] . $dokumen->file);
}
}
DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete();
}, 5);
}
public function search(Request $request)
@ -240,7 +321,6 @@ class ProjectController extends Controller
$dataBuilder = $this->setUpPayload($payload, 'm_proyek');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
// $builder->where("selfTable.created_by",$this->currentName);
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
@ -249,6 +329,8 @@ class ProjectController extends Controller
public function list()
{
DB::beginTransaction();
try {
$data = Project::select(
'id',
'kode_sortname',
@ -286,13 +368,12 @@ class ProjectController extends Controller
'created_by',
'updated_at',
'updated_by'
)->orderBy('id', 'desc')
// ->where("created_by",$this->currentName)
)->orderByDesc('id')
->get();
$countData = $data->count();
if (!$data)
if (!$data) {
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
}
$totalPlannedCost = array_sum(array_map('intval', array_column($data->toArray(), 'plannedCost')));
$totalActualCost = $data->sum('actualCost');
@ -300,25 +381,17 @@ class ProjectController extends Controller
$projectsOnDanger = Project::where('budget_health', 'overrun')->count();
$projectPhases = ProjectPhase::orderBy('order', 'asc')->pluck('name');
$projectTypes = ProjectType::orderBy('id', 'asc')->pluck('name');
try {
$projectsByPhase = DB::table('m_proyek')
->select('m_proyek_phase.name', 'm_proyek_phase.color', DB::raw('count(*) as total'))
->join('m_proyek_phase', 'm_proyek_phase.id', '=', 'm_proyek.phase_id')
->groupBy('m_proyek_phase.name', 'm_proyek_phase.color')
->get();
} catch (\Exception $e) {
return response()->json(['message' => $e->getMessage()]);
}
try {
$projectsByType = DB::table('m_proyek')
->select('m_type_proyek.name', DB::raw('count(m_type_proyek.id) as total'))
->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id')
->groupBy('m_type_proyek.name')
->get();
} catch (\Exception $e) {
return response()->json(['message' => $e->getMessage()]);
}
DB::commit();
return response()->json(
[
'status' => 'success',
@ -337,6 +410,9 @@ class ProjectController extends Controller
],
200
);
} catch (\Throwable $th) {
DB::rollBack();
}
}
public function getListProjectTask($id)
@ -347,10 +423,11 @@ class ProjectController extends Controller
->groupBy("m_proyek.proyek_id")
->get();
if (!$data)
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
if ($data) {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
}
}
public function getSCurve(Request $request)
@ -359,6 +436,13 @@ class ProjectController extends Controller
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
}
// testing
public function calculateSCurvetest(Request $request)
{
$data = MasterFunctionsHelper::calculateSCurve($request->project_id);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
}
public function calculateSCurve(Request $request)
{
$sCurve = Project::select('scurve')->where('id', $request->project_id)->first();
@ -389,15 +473,17 @@ class ProjectController extends Controller
public static function setSyncDate($activity_id, $activity, $report)
{
DB::beginTransaction();
try {
$status = AssignMaterial::where('activity_id', $activity_id)->first();
if (!isset($status)) {
$reports = array(
DB::commit();
return [
'activity_id' => $activity_id,
'min_date' => new DateTime($activity->start_date),
'max_date' => new DateTime($activity->end_date),
'status' => 'open'
);
return $reports;
];
}
if (!isset($status->status_activity)) {
$status->status_activity = 'open';
@ -411,17 +497,22 @@ class ProjectController extends Controller
$minDate = date_create($material->start_activity);
$maxDate = date_create($material->finish_activity);
}
$reports = array(
DB::commit();
return [
'activity_id' => $activity_id,
'min_date' => $minDate,
'max_date' => $maxDate,
'status' => $status->status_activity
);
return $reports;
];
} catch (\Throwable $th) {
DB::rollBack();
}
}
public function synchronizeReport($gantt_id)
{
DB::beginTransaction();
try {
$activities = Activity::where("version_gantt_id", $gantt_id)->get();
$reports = [];
@ -431,12 +522,12 @@ class ProjectController extends Controller
if ($countReports === 1) {
$dataReports = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->get();
foreach ($dataReports as $dr) {
$reports[] = ProjectController::setSyncDate($activity_id, $activity, $dr);
$reports[] = self::setSyncDate($activity_id, $activity, $dr);
}
}
if ($countReports > 1) {
$firstReport = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->first();
$reports[] = ProjectController::setSyncDate($activity_id, $activity, $firstReport);
$reports[] = self::setSyncDate($activity_id, $activity, $firstReport);
}
$successor = Link::where('t_activity_id', $activity->id)->first();
if ($successor) {
@ -448,9 +539,6 @@ class ProjectController extends Controller
}
$activity->save();
}
/* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */
/* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */
for ($i = 0; $i < count($reports); $i++) {
$activity = Activity::find($reports[$i]['activity_id']);
if ($reports[$i]['status'] != 'done') {
@ -467,8 +555,11 @@ class ProjectController extends Controller
$activity->actual_start = $reports[$i]['min_date'];
$activity->save();
}
DB::commit();
return response()->json(['status' => 'success', 'message' => 'Synchronize to report success!', 'code' => 200], 200);
} catch (\Throwable $th) {
DB::rollBack();
}
}
public function setBaseline($gantt_id)
@ -487,18 +578,26 @@ class ProjectController extends Controller
return response()->json(['status' => 'success', 'message' => 'Set baseline success!', 'code' => 200], 200);
}
public function setBaselineActivity($activity_id, $gantt_id)
{
$activity = Activity::where([["version_gantt_id", $gantt_id], ['id', $activity_id]])->first();
$activity->update([
"planned_start" => $activity->start_date,
"planned_end" => $activity->end_date,
"early_start" => $activity->start_date,
"early_end" => $activity->end_date,
]);
return response()->json(['status' => 'success', 'message' => 'Set baseline activity success!', 'code' => 200], 200);
}
public function getByUser($id)
{
$alias = "utp";
$userProyek = UserToProyek::query()
->from('assign_hr_to_proyek AS ' . $alias)
->where([
['is_customer', true],
['user_id', $id]
])
->leftJoin('m_users', $alias . '.user_id', '=', 'm_users.id')
->leftJoin('m_proyek', $alias . '.proyek_id', '=', 'm_proyek.id')
->from('assign_hr_to_proyek AS utp')
->where([['is_customer', true], ['user_id', $id]])
->leftJoin('m_users', 'utp.user_id', '=', 'm_users.id')
->leftJoin('m_proyek', 'utp.proyek_id', '=', 'm_proyek.id')
->leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id')
->select('m_proyek.*', 'm_type_proyek.name AS join_second_name', 'm_users.name AS join_first_name')
->get();
@ -506,15 +605,19 @@ class ProjectController extends Controller
return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200);
}
public function detail(Request $request, $id, $gantt_id = null, $s_curve = null)
{
if (empty($id) || !is_int((int)$id))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
DB::beginTransaction();
try {
if (empty($id) || !is_int((int)$id)) {
return response()->json(['status' => 'failed', 'message' => 'Id is required!', 'code' => 400], 400);
}
$result = Project::find($id);
if (!$result)
if (!$result) {
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
}
if (!isset($gantt_id)) {
$gantt = MasterFunctionsHelper::getLatestGantt($id);
$ganttId = $gantt['last_gantt_id'];
@ -527,16 +630,25 @@ class ProjectController extends Controller
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->first();
$actualStartExist = Activity::where('proyek_id', $id)->whereNotNull('actual_start')->exists();
if ($result['type_proyek_id'] === 9) {
$actualEndExist = Activity::where('proyek_id', $id)->exists();
// $actualEndExist = Activity::where('proyek_id', $id)->exists();
$query = Activity::where('proyek_id', $id);
$maxEndDate = Activity::where('proyek_id', $id)->select('end_date')
->orderBy('end_date', 'desc')
->first();
} else {
$actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists();
// $actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists();
$maxEndDate = Activity::where('version_gantt_id', $ganttId)->select('end_date')
->orderByDesc('end_date')
->first();
$query = Activity::where('version_gantt_id', $ganttId);
}
} else {
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $ganttId)->first();
$actualStartExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_start')->exists();
$actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists();
// $actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists();
$maxEndDate = Activity::where('version_gantt_id', $ganttId)->select('end_date')
->orderByDesc('end_date')
->first();
$query = Activity::where('version_gantt_id', $ganttId);
}
@ -545,10 +657,13 @@ class ProjectController extends Controller
} else {
$startDate = $query->orderBy('start_date')->value('start_date');
}
if ($actualEndExist) {
$maxEndDate = $query->max('id');
$endDate = $query->where('id', $maxEndDate)->first()->end_date;
}
// if($actualEndExist)
// {
// // $maxEndDate = $query->max('id');
// // get last end_date
// // $endDate = $query->where('id',$maxEndDate)->first()->end_date;
// }
$plannedStart = Activity::where('version_gantt_id', $ganttId)
->orderBy('planned_start')
@ -556,53 +671,70 @@ class ProjectController extends Controller
$plannedEnd = Activity::where('version_gantt_id', $ganttId)
->orderByDesc('planned_end')
->value('planned_end');
if (isset($result->header)) {
$result->header->start_date = $startDate;
$result->header->end_date = $endDate;
$result->header->end_date = $maxEndDate->end_date;
$result->header->planned_start = $plannedStart;
$result->header->planned_end = $plannedEnd;
}
DB::commit();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result, 'gantt' => $ganttId], 200);
} catch (\Throwable $th) {
DB::rollBack();
}
}
public function getOverdueActivities(Request $request)
{
DB::beginTransaction();
try {
$payload = $request->all();
if (empty($payload['id']) || !is_int((int)$payload['id']))
if (empty($payload['id']) || !is_int((int)$payload['id'])) {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
}
$result = Project::find($payload['id']);
if (!$result)
if (!$result) {
return response()->json(['status' => 'failed', 'message' => 'Project not found!', 'code' => 404], 404);
}
//TODO possible overdue bug
$endDate = Activity::where('proyek_id', $payload['id'])
->orderByDesc('end_date')
->value('end_date');
if (isset($payload['till_date'])) {
if (isset($payload['scurve'])) {
$overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date', '<=', $endDate)->orderBy('end_date', 'asc')->get();
$overdueActivities = Activity::join('m_version_gantt', 'm_activity.version_gantt_id', '=', 'm_version_gantt.id')->where('m_activity.proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date', '<=', $endDate)->orderBy('end_date', 'asc')->get();
} else {
$overdueActivities = Activity::where('version_gantt_id', $payload['gantt'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date', '<=', $endDate)->orderBy('end_date', 'asc')->get();
$overdueActivities = Activity::join('m_version_gantt', 'm_activity.version_gantt_id', '=', 'm_version_gantt.id')->where('version_gantt_id', $payload['gantt'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date', '<=', $endDate)->orderBy('end_date', 'asc')->get();
}
} else {
if (isset($payload['scurve'])) {
$overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get();
$overdueActivities = Activity::join('m_version_gantt', 'm_activity.version_gantt_id', '=', 'm_version_gantt.id')->where('m_activity.proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get();
} else {
$overdueActivities = Activity::where('version_gantt_id', $payload['gantt'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get();
$overdueActivities = Activity::join('m_version_gantt', 'm_activity.version_gantt_id', '=', 'm_version_gantt.id')->where('version_gantt_id', $payload['gantt'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get();
}
}
$result->overdueActivities = $overdueActivities;
DB::commit();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
} catch (\Throwable $th) {
DB::rollBack();
}
}
public function getReportDistribution(Request $request)
{
DB::beginTransaction();
try {
$payload = $request->all();
if (empty($payload['project_id']) || !is_int((int)$payload['project_id']))
if (empty($payload['project_id']) || !is_int((int)$payload['project_id'])) {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
}
$reports = DB::table('assign_material_to_activity as ama')
$reports = AssignMaterial::query()
->from('assign_material_to_activity AS ama')
->select(
'u.name',
'a.name as activity_name',
@ -622,8 +754,11 @@ class ProjectController extends Controller
->where('ama.proyek_id', '=', $payload['project_id'])
->whereNotNull('ram.lat')
->whereBetween('ram.report_date', [$payload['start_date'], $payload['end_date']]);
DB::commit();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $reports], 200);
} catch (\Throwable $th) {
DB::rollBack();
}
}
public function getManpower($proyek_id)
@ -643,7 +778,10 @@ class ProjectController extends Controller
public function dashboard($id)
{
$data = DB::table('m_proyek as mp')
DB::beginTransaction();
try {
$data = Project::query()
->from('m_proyek AS mp')
->select(
'mp.kode_sortname',
'mp.nama as name_project',
@ -659,16 +797,18 @@ class ProjectController extends Controller
->where('mp.id', $id)
->first();
if (!$data)
return response()->json(['status' => 'failed', 'message' => 'Data tidak ditemukan!', 'code' => 404], 404);
if (!$data) {
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
}
$manpowers = UserToProyek::where('proyek_id', $id)->count();
$rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderBy('version_gantt_id', 'desc')->first();
$rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderByDesc('version_gantt_id')->first();
$actualCost = @$rootActivity->biaya_actual ?? 0;
$progress = @$rootActivity->persentase_progress ?? 0;
$commentActivity = DB::table('m_comment_activity as mca')
$commentActivity = CommentActivity::query()
->from('m_comment_activity AS mca')
->select(
'mca.activity_id',
'mca.comment as comment',
@ -686,8 +826,11 @@ class ProjectController extends Controller
$data->progress = $progress;
$data->comment = $commentActivity;
$data->man_power = $manpowers;
DB::commit();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
} catch (\Throwable $th) {
DB::rollBack();
}
}
private function httpReq($search)

74
app/Http/Controllers/ProjectDokumenController.php

@ -3,7 +3,9 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\DokumenProject;
use App\Models\{DokumenProject,Company};
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
class ProjectDokumenController extends Controller
{
@ -20,7 +22,7 @@ class ProjectDokumenController extends Controller
return response()->json(['status'=>'success','data'=> $document ,'code'=>200], 200);
}
public function delete($id)
public function delete($id, $company_id)
{
if(empty($id) || !is_int((int)$id)) {
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
@ -30,25 +32,40 @@ class ProjectDokumenController extends Controller
if(!$document){
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400);
}
if(file_exists($this->pathDocument.$document->file)){
unlink($this->pathDocument.$document->file);
$company = Company::find($company_id);
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
if(file_exists($destinationPath['pathDocument'].$document['file'])){
unlink($destinationPath['pathDocument'].$document['file']);
}
}
$document->delete();
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200);
}
public function uploadProjectDokumen(Request $request)
{
DB::beginTransaction();
$timeNow = Carbon::now();
if($request->hasFile('dokumen')){
$document = $request->file('dokumen');
$ref_id = $request->ref_id;
$name = $document->getClientOriginalName();
$result = $document->move($this->pathDocument, $name);
if($result){
$originalFilename = $document->getClientOriginalName();
$extension = pathinfo($originalFilename, PATHINFO_EXTENSION);
$filename = pathinfo($originalFilename, PATHINFO_FILENAME);
$name = $filename . '_' . $timeNow->format('d-m-y-His') . '.' . $extension;
// Limited Storage
$company = Company::whereId($request->company_id)->first();
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$getLimitStorage = $this->setLimitsStorage($company, $document, $destinationPath['pathDocument'],$destinationPath);
}
if(isset($getLimitStorage)) {
if($getLimitStorage === false) {
DB::rollBack();
return response()->json(['status' => 'failed', 'message' => 'Limited storage maximum!', 'code' => 500], 500);
}
$data = [
'ref_id' => (int)$ref_id,
'file' => $name,
@ -57,15 +74,18 @@ class ProjectDokumenController extends Controller
$result = DokumenProject::create($data);
if(!$result){
unlink($this->pathDocument.$name);
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
if(!$document->move($destinationPath['pathDocument'], $name) && $result) {
unlink($destinationPath['pathDocument'].$name);
DB::rollBack();
return response()->json(['status'=>'failed','message'=>'Dokumen project gagal diupload!','code'=> 500], 500);
}
return response()->json(['status'=>'success','message'=>'Upload successful!','code'=>200], 200);
DB::commit();
return response()->json(['status'=>'success','message'=>'Dokumen project berhasil diupload!','code'=>200], 200);
}
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
DB::rollBack();
return response()->json(['status'=>'failed','message'=>'Dokumen project gagal diupload!','code'=> 500], 500);
}
DB::rollBack();
return response()->json(['status'=>'failed','message'=>'File is required!','code'=>400], 400);
}
@ -81,25 +101,31 @@ class ProjectDokumenController extends Controller
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
public function downloadDokumen($id)
public function downloadDokumen($id, $company_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);
}
$document = DokumenProject::find($id);
$company = Company::find($company_id);
if(!$document)
if(!$document || !$company) {
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
}
if(!file_exists($this->pathDocument.$document->file))
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$pathToFile = $destinationPath['pathDocument'].$document['file'];
$pathToFile = $this->pathDocument.$document->file;
if(!file_exists($pathToFile)) {
return response()->json(['status'=>'failed','message'=>'Directory not found!','code'=> 404], 404);
}
if($company) {
$name = pathinfo($pathToFile, PATHINFO_FILENAME) . "." . pathinfo($pathToFile, PATHINFO_EXTENSION);
}
$headers = [
'Content-Disposition' => 'attachment; filename="'.$name.'"'
];
// dd($name, $headers);
return response()->download($pathToFile, $name, $headers);
}
}

93
app/Http/Controllers/ProjectExpenditureController.php

@ -0,0 +1,93 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\ProjectExpenditure;
class ProjectExpenditureController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'name' => 'required'
]);
$data = $request->all();
// Set Unique
$result = ProjectExpenditure::query()
->where([
['company_id',$data['company_id']],
['name', $data['name']]
])->first();
if($result) {
return response()->json(['status'=>'failed','message'=>'Name is already exists!','code'=> 500], 500);
die;
}
$data['created_by'] = $this->currentName;
if(!ProjectExpenditure::create($data))
return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500], 500);
return response()->json(['status'=>'success','message'=>'data added!','code'=>200], 200);
}
public function edit($id){
if(!$id || (int) $id < 0 || $id=="")
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
if(!$result = ProjectExpenditure::find($id))
return response()->json(['status'=>'failed','message'=>'Failed to get data!','code'=> 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}
public function update(Request $request, $id)
{
if(!$id || (int) $id < 0 || $id=="")
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
if(!$data = ProjectExpenditure::find($id))
return response()->json(['status'=>'failed','message'=>'data project expenditure not found!','code'=>400], 400);
if(!$data->update($request->all()))
return response()->json(['status'=>'failed','message'=>'data project expenditure failed updated!','code'=>400], 400);
return response()->json(['status'=>'success','message'=>'Data berhasil disimpan!','code'=>200], 200);
}
public function delete($id)
{
if(!$data = ProjectExpenditure::find($id))
return response()->json(['status'=>'failed','message'=>'data project expenditure not found!','code'=>400], 400);
if(!$data->delete())
return response()->json(['status'=>'failed','message'=>'Data gagal dihapus!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=>'Data berhasil dihapus!','code'=>200], 200);
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_proyek_expenditure');
$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 = ProjectExpenditure::all();
$countData = $data->count();
if(!$data)
return response()->json(['status'=>'failed','message'=>'failed get list project expenditure, please try again later!','code'=>400], 400);
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}
}

93
app/Http/Controllers/ProjectFinancialHealthController.php

@ -0,0 +1,93 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\ProjectFinancialHealth;
class ProjectFinancialHealthController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'name' => 'required'
]);
$data = $request->all();
// Set Unique
$result = ProjectFinancialHealth::query()
->where([
['company_id',$data['company_id']],
['name', $data['name']]
])->first();
if($result) {
return response()->json(['status'=>'failed','message'=>'Name is already exists!','code'=> 500], 500);
die;
}
$data['created_by'] = $this->currentName;
if(!ProjectFinancialHealth::create($data))
return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500], 500);
return response()->json(['status'=>'success','message'=>'data added!','code'=>200], 200);
}
public function edit($id){
if(!$id || (int) $id < 0 || $id=="")
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
if(!$result = ProjectFinancialHealth::find($id))
return response()->json(['status'=>'failed','message'=>'Failed to get data!','code'=> 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}
public function update(Request $request, $id)
{
if(!$id || (int) $id < 0 || $id=="")
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
if(!$data = ProjectFinancialHealth::find($id))
return response()->json(['status'=>'failed','message'=>'data financial health not found!','code'=>400], 400);
if(!$data->update($request->all()))
return response()->json(['status'=>'failed','message'=>'Data financial health failed updated!','code'=>400], 400);
return response()->json(['status'=>'success','message'=>'Data berhasil disimpan!','code'=>200], 200);
}
public function delete($id)
{
if(!$data = ProjectFinancialHealth::find($id))
return response()->json(['status'=>'failed','message'=>'data financial health not found!','code'=>400], 400);
if(!$data->delete())
return response()->json(['status'=>'failed','message'=>'Data gagal dihapus!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=>'Data berhasil dihapus!','code'=>200], 200);
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_proyek_financial_health');
$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 = ProjectFinancialHealth::all();
$countData = $data->count();
if(!$data)
return response()->json(['status'=>'failed','message'=>'failed get list financial health, please try again later!','code'=>400], 400);
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}
}

93
app/Http/Controllers/ProjectInvoiceController.php

@ -0,0 +1,93 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\ProjectInvoice;
class ProjectInvoiceController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'name' => 'required'
]);
$data = $request->all();
// Set Unique
$result = ProjectInvoice::query()
->where([
['company_id',$data['company_id']],
['name', $data['name']]
])->first();
if($result) {
return response()->json(['status'=>'failed','message'=>'Name is already exists!','code'=> 500], 500);
die;
}
$data['created_by'] = $this->currentName;
if(!ProjectInvoice::create($data))
return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500], 500);
return response()->json(['status'=>'success','message'=>'data added!','code'=>200], 200);
}
public function edit($id){
if(!$id || (int) $id < 0 || $id=="")
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
if(!$result = ProjectInvoice::find($id))
return response()->json(['status'=>'failed','message'=>'Failed to get data!','code'=> 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}
public function update(Request $request, $id)
{
if(!$id || (int) $id < 0 || $id=="")
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
if(!$data = ProjectInvoice::find($id))
return response()->json(['status'=>'failed','message'=>'data project invoice not found!','code'=>400], 400);
if(!$data->update($request->all()))
return response()->json(['status'=>'failed','message'=>'data project invoice failed updated!','code'=>400], 400);
return response()->json(['status'=>'success','message'=>'Data berhasil disimpan!','code'=>200], 200);
}
public function delete($id)
{
if(!$data = ProjectInvoice::find($id))
return response()->json(['status'=>'failed','message'=>'data project invoice not found!','code'=>400], 400);
if(!$data->delete())
return response()->json(['status'=>'failed','message'=>'Data gagal dihapus!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=>'Data berhasil dihapus!','code'=>200], 200);
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_proyek_invoice');
$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 = ProjectInvoice::all();
$countData = $data->count();
if(!$data)
return response()->json(['status'=>'failed','message'=>'failed get list project invoice, please try again later!','code'=>400], 400);
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}
}

3
app/Http/Controllers/ProjectRoleController.php

@ -11,7 +11,8 @@ class ProjectRoleController extends Controller
{
$this->validate($request, [
'name' => 'required',
'description' => 'required'
'description' => 'required',
'company_id' => 'required'
]);
$data = $request->all();

93
app/Http/Controllers/ProjectScheduleHealthController.php

@ -0,0 +1,93 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\ProjectScheduleHealth;
class ProjectScheduleHealthController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'name' => 'required'
]);
$data = $request->all();
// Set Unique
$result = ProjectScheduleHealth::query()
->where([
['company_id',$data['company_id']],
['name', $data['name']]
])->first();
if($result) {
return response()->json(['status'=>'failed','message'=>'Name is already exists!','code'=> 500], 500);
die;
}
$data['created_by'] = $this->currentName;
if(!ProjectScheduleHealth::create($data))
return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500], 500);
return response()->json(['status'=>'success','message'=>'data added!','code'=>200], 200);
}
public function edit($id){
if(!$id || (int) $id < 0 || $id=="")
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
if(!$result = ProjectScheduleHealth::find($id))
return response()->json(['status'=>'failed','message'=>'Failed to get data!','code'=> 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}
public function update(Request $request, $id)
{
if(!$id || (int) $id < 0 || $id=="")
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
if(!$data = ProjectScheduleHealth::find($id))
return response()->json(['status'=>'failed','message'=>'data schedule health not found!','code'=>400], 400);
if(!$data->update($request->all()))
return response()->json(['status'=>'failed','message'=>'data schedule health failed updated!','code'=>400], 400);
return response()->json(['status'=>'success','message'=>'Data berhasil disimpan!','code'=>200], 200);
}
public function delete($id)
{
if(!$data = ProjectScheduleHealth::find($id))
return response()->json(['status'=>'failed','message'=>'data schedule health not found!','code'=>400], 400);
if(!$data->delete())
return response()->json(['status'=>'failed','message'=>'Data gagal dihapus!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=>'Data berhasil dihapus!','code'=>200], 200);
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_proyek_schedule_health');
$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 = ProjectScheduleHealth::all();
$countData = $data->count();
if(!$data)
return response()->json(['status'=>'failed','message'=>'failed get list schedule health, please try again later!','code'=>400], 400);
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}
}

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', 'data'=> $result, '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);
}
}

2
app/Http/Controllers/ReportActivityController.php

@ -6,7 +6,7 @@ use Illuminate\Http\Request;
use App\Models\ReportActivity;
use App\Models\Activity;
use App\Models\Image;
use Datatables;
use Yajra\Datatables\Datatables;
class ReportActivityController extends Controller
{

31
app/Http/Controllers/ReportActivityMaterialController.php

@ -4,10 +4,13 @@ namespace App\Http\Controllers;
use App\Helpers\MasterFunctionsHelper;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Models\ReportActivityMaterial;
use App\Models\Activity;
use App\Models\AssignMaterial;
use Datatables;
use App\Models\Company;
use App\Models\Image;
use Yajra\Datatables\Datatables;
use DateTime;
class ReportActivityMaterialController extends Controller
@ -64,10 +67,18 @@ class ReportActivityMaterialController extends Controller
} else {
$sumAssignMaterial = AssignMaterial::where('activity_id', $request->activity_id)->sum('qty_planning');
$sumReportActivityMaterial = ReportActivityMaterial::where('activity_id', $request->activity_id)->sum('qty');
// if actual >= plan
if ($sumReportActivityMaterial >= $sumAssignMaterial){
$persentaseProgress = 95;
}else{
// actual < plan
$persentaseProgress = $sumReportActivityMaterial/$sumAssignMaterial*100;
}
$dataUpdate = array(
"actual_start" => null,
"actual_end" => null,
"persentase_progress" => $sumReportActivityMaterial/$sumAssignMaterial*100,
"persentase_progress" => $persentaseProgress,
"updated_by" => $this->currentName
);
if ($sumReportActivityMaterial > 0) {
@ -91,10 +102,19 @@ class ReportActivityMaterialController extends Controller
}
}
public function delete($id)
public function delete($id, $company_id)
{
if(!ReportActivityMaterial::findOrFail($id)->delete())
$data = ReportActivityMaterial::findOrFail($id);
$company = Company::find($company_id);
$image = Image::where([['ref_id', $id],['category','report_activity']])->first();
if($data && $company && $image) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
unlink($destinationPath['pathImage'].$image['image']);
}
if(!$data->delete()) {
return response()->json(['status'=>'failed','message'=>'Failed to deleted the data!','code'=> 500], 500);
}
return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=>200], 200);
}
@ -124,8 +144,10 @@ class ReportActivityMaterialController extends Controller
public function datatables(Request $request){
$id_activity = $request->query('idAct');
$id_am = $request->query('idAmi');
$type = $request->query('type');
$materialName = $request->query('materialName');
$materialId = $request->query('materialId');
if($type == 'plan'){
$activity = Activity::findOrFail($id_activity);
$baselineDuration = 0;
@ -135,6 +157,7 @@ class ReportActivityMaterialController extends Controller
$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")
->where('assign_material_to_activity.activity_id', $id_activity)
->where('assign_material_to_activity.id', $id_am)
->where('m.description', $materialName)
->orderBy('assign_material_to_activity.id', 'asc')
->get();

10
app/Http/Controllers/RoleController.php

@ -11,8 +11,9 @@ class RoleController extends Controller
public function add(Request $request)
{
$this->validate($request, [
'name' => 'string|required|unique:m_roles,name',
'description' => 'required'
'name' => 'string|required|unique:m_roles,name,NULL,id,company_id,' . $request->input('company_id'),
'description' => 'required',
'company_id' => 'required'
]);
$data = $request->all();
@ -27,10 +28,11 @@ class RoleController extends Controller
if (!$result)
return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 500], 500);
return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200);
return response()->json(['status' => 'success', 'data' => $result, 'message' => 'Data added!', 'code' => 200], 200);
}
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);

47
app/Http/Controllers/RoleMenuController.php

@ -5,26 +5,61 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Menu;
use App\Models\RoleMenu;
use Illuminate\Support\Facades\Log;
class RoleMenuController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'role_id' => 'required',
'menu_id' => 'required',
'role_id.*' => 'required',
'menu_id.*' => 'required'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$countData = 0;
foreach($data as $arrData) {
$arrData['created_by'] = $this->currentName;
$result = RoleMenu::create($arrData);
$countData++;
}
if($result && $countData > 0) {
return response()->json(['status'=>'success','message'=>'add data role menu successfully!','code'=>200], 200);
} else {
return response()->json(['status'=>'failed','message'=>'add data role menu failed!','code'=>400], 400);
}
}
public function addMultiple(Request $request)
{
$menus = $request->all();
if (is_array($menus) && count($menus) > 0 && isset($menus)) {
$countRes = 0;
foreach ($menus as $menu) {
$result = RoleMenu::create($data);
$dataInsert = array(
"menu_id" => $menu['menu_id'],
"role_id" => $menu['role_id'],
);
$result = RoleMenu::create($dataInsert);
if ($result) {
return response()->json(['status'=>'success','message'=>'add data role menu successfully!','code'=>200], 200);
$countRes++;
} else {
return response()->json(['status'=>'failed','message'=>'add data role menu failed!','code'=>400], 400);
$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 {
return response()->json(['status' => 'failed', 'message' => 'Add data menu role failed created!', 'code' => 500]);
}
}

344
app/Http/Controllers/UserRegisterController.php

@ -0,0 +1,344 @@
<?php
namespace App\Http\Controllers;
use Carbon\Carbon;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\{DB,Log};
use App\Models\{User, Company, HumanResource, Menu, ProductTransaction, RefferalCode, Role, RoleMenu, MenuCompany};
const URL_EMAIL = 'https://notifapp.odm-iu.com/service-mail/notif_mail.php';
class UserRegisterController extends Controller
{
public function add(Request $request)
{
DB::beginTransaction();
$this->validate($request, [
'cluster' => 'required|string',
'address' => 'required|string',
'email' => 'required|string',
'type_paket' => ($request->type_account === 'Personal' ? 'required' : 'nullable') . '|in:Basic,Free',
'phone_no' => 'required',
'type_account' => 'string|in:Personal,Company',
'company_name' => 'required|string',
'username' => 'required|string'
]);
try {
$data = $request->all();
$company_name = $data['company_name'];
$type_account = $data['type_account'];
$refferal = $request->refferal ? $data['refferal'] : null;
$cluster = $data['cluster'];
$address = $data['address'];
$phone_no = $data['phone_no'];
$email = $data['email'];
$username = $data['username'];
$type_paket = $data['type_paket'];
$company_address = $request->type_account === 'Company' ? $data['companyAddress'] : '';
$full_name = $request->type_account === 'Personal' ? $data['full_name'] : '';
// check email & username already exist
$emailExists = Company::where('email', $email)->exists() || User::where('email', $email)->exists();
if ($emailExists) {
return response()->json(['status' => 'failed', 'message' => 'Email already exists, please check again!', 'code' => 500], 500);
}
$usernameExists = User::where('username', $username)->exists();
if ($usernameExists) {
return response()->json(['status' => 'failed', 'message' => 'Username already exists, please check again!', 'code' => 500], 500);
}
// Get last registration number
$getCompany = $this->getCompany();
$formDataCompany = array(
'company_name' => $company_name,
'newRegistrationNumber' => $getCompany['newRegistrationNumber'],
'cluster' => $cluster,
'phone_no' => $phone_no,
'email' => $email,
'address' => $address,
'type_account' => $type_account,
'username' => $username,
'type_paket' => $type_paket,
'companyAddress' => $company_address,
'full_name' => $full_name
);
if(empty($refferal)) {
$addCompany = $this->addCompany($formDataCompany, null);
} else {
$getRefferal = $this->getRefferalCode($refferal);
if(empty($getRefferal)) {
return response()->json(['status' => 'failed', 'message' => 'Refferal code not found!', 'code' => 404], 404);
}
$addCompany = $this->addCompany($formDataCompany, (int)$getRefferal['id']);
}
if(empty($addCompany)) {
return;
}
$addRole = $this->addRole((int)$addCompany['id']);
if(empty($addRole)) {
return;
}
$addHR = $this->addHR((int)$addCompany['id'], (int)$addRole['id'], $formDataCompany);
if(empty($addHR)) {
return;
}
$getMenu = $this->getMenu();
if(empty($getMenu)) {
return;
}
$this->addTransaction((int)$addCompany['id'], $formDataCompany);
$addMenuCompany = $this->addMenuCompany($getMenu, (int)$addCompany['id']);
if(empty($addMenuCompany)) {
return;
}
$addMenuRole = $this->addMenuRole($getMenu, (int)$addRole['id']);
if(empty($addMenuRole)) {
return;
}
DB::commit();
return response()->json(['status' => 'success', 'message' => 'Register is successful, please check your email!', 'generateRandom' => $addHR['generateRandom'], 'code' => 200], 200);
} catch (\Throwable $th) {
DB::rollBack();
Log::channel('daily')->error($th->getMessage());
return response()->json(['status' => 'failed', 'message' => 'Failed to register, please check again!', 'code' => 500], 500);
}
}
protected function getRefferalCode($refferal)
{
$result = RefferalCode::query()
->select('id','code','amount','exp','type','allocation','description')
->where('code', $refferal)
->first();
return $result;
}
protected function addCompany($formData, $id_refferal)
{
$formData = array(
'company_name' => $formData['company_name'],
'registration_no' => $formData['newRegistrationNumber'],
'cluster' => $formData['cluster'],
'date_register' => Carbon::now(),
'template_id' => 1,
'email' => $formData['email'],
'address' => $formData['type_account'] === 'Company' ? $formData['companyAddress'] : $formData['address'],
'phone_no' => $formData['phone_no'],
'type_account' => $formData['type_account'],
'is_active' => true,
'discount_id' => $id_refferal === null ? null : $id_refferal
);
$result = Company::create($formData);
return $result;
}
protected function addRole($id_company)
{
$formData = [
'name' => 'Admin',
'company_id' => $id_company,
'description' => '-'
];
$result = Role::create($formData);
return $result;
}
protected function addHR($id_company, $id_role, $data)
{
$generateRandom = Str::random(8);
$formData = array(
'name'=> $data['type_account'] === 'Company' ? $data['username'] : $data['full_name'],
'phone_number'=> $data['phone_no'],
'email'=> $data['email'],
'username' => $data['username'],
'password'=> md5($generateRandom),
'role_id'=> $id_role,
'ktp_number'=> $data['type_account'] === 'Company' ? 'CP-'. $generateRandom : 'PR-' . $generateRandom,
'employee_type'=> 'employee',
'address' => $data['address'],
'status_resource'=> 'active',
'company_id'=> $id_company
);
$result = HumanResource::create($formData);
if(!empty($result)) {
$this->sendEmail($data['email'], $generateRandom);
}
return [
'result' => $result,
'generateRandom' => $generateRandom
];
}
protected function addMenuCompany($baseDataMenu, $id_company)
{
$data = MenuCompany::where('company_id', $id_company);
if($data->exists()){
$data->delete();
}
if (is_object($baseDataMenu) && count($baseDataMenu) > 0 && isset($baseDataMenu)) {
$countRes = 0;
foreach ($baseDataMenu as $menu) {
$dataInsert = array(
"menu_id" => $menu['id'],
"parent_menu_id" => $menu['parent_id'],
"company_id" => $id_company,
"icon" => $menu['icon'],
"alias_name" => $menu['alias_name'],
"url" => $menu['url'],
"sequence" => $menu['sequence'],
"created_by" => $this->currentName
);
$result = MenuCompany::create($dataInsert);
if ($result) {
$countRes++;
} else {
$countRes--;
}
}
if ($countRes > 0) {
return $result;
} else {
die();
}
} else {
die();
}
}
protected function addMenuRole($baseDataMenu, $id_role)
{
if (is_object($baseDataMenu) && count($baseDataMenu) > 0 && isset($baseDataMenu)) {
$countRes = 0;
foreach ($baseDataMenu as $menu) {
$dataInsert = array(
"menu_id" => $menu['id'],
"role_id" => $id_role,
);
$result = RoleMenu::create($dataInsert);
if ($result) {
$countRes++;
} else {
$countRes--;
}
}
if ($countRes > 0) {
return $result;
} else {
die();
}
} else {
die();
}
}
protected function addTransaction($id_company, $data)
{
$currentDate = Carbon::now();
$finalDate = $currentDate->copy()->addDays(30);
if(is_array($data)) {
$formData = array(
'company_id' => $id_company,
'type_paket' => $data['type_paket'],
'exp_ospro' => $finalDate,
'amount' => $data['type_paket'] === 'Free' ? 0 : 250000
);
$result = ProductTransaction::create($formData);
return $result;
}
}
protected function getMenu()
{
$result = Menu::query()
->select("id", "name", "parent_id", "alias_name", "icon", "url", "sequence")
->whereNotIn('alias_name', ['Dashboard Customer', 'Registration Management', 'Demo Management'])
->get();
return $result;
}
protected function getCompany()
{
$newRegistrationNumber = '';
$company = Company::query()
->select('id','type_account','registration_no','discount_id')
->orderByDesc('id')
->first();
if(!empty($company)) {
$lastRegistrationNumber = $company['registration_no'];
$lastNumber = (int)preg_replace('/\D/', '', $lastRegistrationNumber);
$newNumber = $lastNumber + 1;
$newRegistrationNumber = 'RG-'. $newNumber;
} else{
return false;
}
return [
'newRegistrationNumber' => $newRegistrationNumber
];
}
public function sendEmail($email, $password)
{
$user = User::select('email', 'name', 'username')->where('email', $email)->first();
if (!$user) {
return response()->json(['status' => 'error', 'message' => 'e-mail not found '], 400);
} else {
$this->reqHttpCurl($email, $password, $user->username, $user->name);
return response()->json(['status' => 'error', 'code'=>400, 'message' => 'e-mail not found '], 400);
}
}
private function reqHttpCurl($email, $password, $username, $name)
{
$postData = [
"to" => $email,
"name" => $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,
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));
}
}
}

77
app/Http/Controllers/UserToActivityController.php

@ -7,11 +7,12 @@ use App\Models\UserToActivity;
use App\Models\Activity;
use App\Models\AssignMaterial;
use Illuminate\Support\Facades\DB;
use Datatables;
use Yajra\Datatables\Datatables;
class UserToActivityController extends Controller
{
public function add(Request $request){
public function add(Request $request)
{
$this->validate($request, [
'activity_id' => 'required',
'user_id' => 'required'
@ -26,7 +27,8 @@ class UserToActivityController extends Controller
return response()->json(['status' => 'success', 'message' => 'Data added!', 'code' => 200]);
}
public function addMultiple(Request $request){
public function addMultiple(Request $request)
{
$users_id = $request->user_id;
$users_role = $request->role_proyek_id;
@ -75,10 +77,10 @@ class UserToActivityController extends Controller
} else {
return response()->json(['status' => 'success', 'message' => 'Data added!', 'code' => 200]);
}
}
private function updatedCostPlanning($parent_id) {
private function updatedCostPlanning($parent_id)
{
$sumBiaya = Activity::selectRaw('sum(cast(rencana_biaya as double precision))')
->where("parent_id", $parent_id)
->first();
@ -89,7 +91,8 @@ class UserToActivityController extends Controller
}
}
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);
@ -116,7 +119,8 @@ class UserToActivityController extends Controller
return response()->json(['status' => 'failed', 'message' => 'Failed to delete!', 'code' => 500], 500);
}
public function edit($id){
public function edit($id)
{
if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
die();
@ -136,11 +140,19 @@ class UserToActivityController extends Controller
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$builder->addSelect(DB::raw('SUM(report_activity_material.qty) as volume_actual'));
$builder->groupBy("m_activity.id");
$builder->groupBy("m_activity.name");
$builder->groupBy("m_activity.persentase_progress");
$builder->groupBy("m_activity.actual_start");
$builder->groupBy("m_activity.actual_end");
$builder->groupBy("m_activity.planned_start");
$builder->groupBy("m_activity.planned_end");
$builder->groupBy("m_activity.start_date");
$builder->groupBy("m_activity.end_date");
$builder->groupBy("m_activity.duration");
$builder->groupBy("selfTable.id");
$builder->groupBy("selfTable.start_date");
$builder->groupBy("selfTable.end_date");
$builder->groupBy("m_users.name");
$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();
@ -158,7 +170,7 @@ class UserToActivityController extends Controller
$dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_activity');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
// $countBuilder = $dataBuilder['count'];
if (isset($join_column)) {
$startDate = $join_column['start_date'];
$endDate = $join_column['end_date'];
@ -187,8 +199,46 @@ class UserToActivityController extends Controller
}
$dataGet = $filteredData;
}
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
// $totalRecord = $countBuilder->count();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => count($dataGet)], 200);
}
public function activityUser(Request $request)
{
$payload = $request->all();
$activity = DB::table('m_activity as ma')
->select(
'ahta.id',
'ma.id as activity_id',
'ma.proyek_id',
'ma.name as join_second_name',
'ma.start_date as join_second_start_date',
'ma.end_date as join_second_end_date',
'ma.persentase_progress',
'mvg.name_version',
'mp.nama as nama_proyek',
'mp.type_proyek_id'
)
->join('assign_hr_to_activity as ahta', 'ahta.activity_id', '=', 'ma.id')
->join('m_version_gantt as mvg', 'mvg.id', '=', 'ma.version_gantt_id')
->join('m_proyek as mp', 'mp.id', '=', 'ma.proyek_id')
->where('ahta.user_id', $payload['user_id'])
->where('ma.start_date', '<=', $payload['end_date'])
->where('ma.end_date', '>=', $payload['start_date'])
->where('ma.proyek_id', $payload['proyek_id'])
->get();
if ($payload['status'] != "") {
$filteredData = [];
foreach ($activity as $value) {
$assignMaterial = AssignMaterial::where('activity_id', $value->activity_id)->first();
if ($assignMaterial->status_activity == $payload['status']) {
$filteredData[] = $value;
}
}
$activity = $filteredData;
}
return response()->json(['status' => 'success', 'code' => 200, 'data' => $activity, 'totalRecord' => count($activity)], 200);
}
public function list()
@ -235,7 +285,8 @@ class UserToActivityController extends Controller
}
}
public function datatables(Request $request){
public function datatables(Request $request)
{
$id_activity = $request->query('idact');
$data = UserToActivity::select("assign_hr_to_activity.id as id", "assign_hr_to_activity.start_date", "assign_hr_to_activity.end_date", "u.name as user_name", "mrp.name as role_name")
->join("m_role_proyek as mrp", "mrp.id", "=", "assign_hr_to_activity.role_proyek_id")

28
app/Http/Controllers/UserToProyekController.php

@ -2,11 +2,12 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Image;
use App\Models\Company;
use App\Models\UserToProyek;
use App\Models\UserToActivity;
use Illuminate\Http\Request;
use App\Models\ReportActivity;
use App\Models\Image;
use App\Models\UserToActivity;
class UserToProyekController extends Controller
{
@ -51,7 +52,8 @@ class UserToProyekController extends Controller
"user_id" => $item,
"proyek_id" => $request->proyek_id,
"created_by" => $this->currentName,
'is_customer' => true
'is_customer' => true,
'project_role' => $request->project_role
);
$result = UserToProyek::create($dataInsert);
@ -65,10 +67,10 @@ class UserToProyekController extends Controller
if ($countRes > 0) {
return response()->json(['status' => 'success', 'message' => 'Project customer successfull created', 'code' => 200]);
} else {
return response()->json(['status' => 'success', 'message' => 'Project customer failed created', 'code' => 400]);
return response()->json(['status' => 'failed', 'message' => 'Project customer failed created', 'code' => 400]);
}
} else {
return response()->json(['status' => 'success', 'message' => 'Project customer successfull created', 'code' => 200]);
return response()->json(['status' => 'failed', 'message' => 'Project customer failed created', 'code' => 200]);
}
}
@ -111,7 +113,7 @@ class UserToProyekController extends Controller
}
}
public function delete($id)
public function delete($id, $company_id)
{
$data = UserToProyek::find($id);
if ($data) {
@ -119,7 +121,7 @@ class UserToProyekController extends Controller
$proyekId = $data->proyek_id;
$delete = $data->delete();
if ($delete) {
$this->deleteRelative($proyekId, $userId);
$this->deleteRelative($proyekId, $userId, $company_id);
}
} else {
return response()->json(['status' => 'failed', 'message' => 'data assign hr to proyek not found!', 'code' => 400], 400);
@ -134,22 +136,26 @@ class UserToProyekController extends Controller
}
}
private function deleteRelative($proyekId, $userId)
private function deleteRelative($proyekId, $userId, $company_id)
{
$uta = UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->get();
foreach ($uta as $value) {
$dataRa = ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->get();
$company = Company::find($company_id);
if ($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
foreach ($dataRa as $ra) {
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get();
foreach ($images as $image) {
if (file_exists($this->pathImage . $image->image)) {
unlink($this->pathImage . $image->image);
if (file_exists($destinationPath['pathImage'] . $image->image)) {
unlink($destinationPath['pathImage'] . $image->image);
}
}
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete();
}
ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->delete();
}
}
UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->delete();
}

16
app/Http/Controllers/VersionGanttController.php

@ -14,7 +14,8 @@ use App\Models\ActivityProgressLog;
class VersionGanttController extends Controller
{
public function add(Request $request){
public function add(Request $request)
{
$this->validate($request, [
'name_version' => 'required',
'proyek_id' => 'required'
@ -24,13 +25,14 @@ class VersionGanttController extends Controller
$result = VersionGantt::create($data);
if ($result) {
return response()->json(['status'=>'success','message'=>'version gantt Project successfull created','code'=>200]);
return response()->json(['status' => 'success', 'message' => 'version gantt Project successfull created', 'code' => 200, 'id' => $result->id]);
} else {
return response()->json(['status' => 'failed', 'message' => 'version gantt Project failed created', 'code' => 400]);
}
}
public function update(Request $request, $id){
public function update(Request $request, $id)
{
if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
@ -81,7 +83,8 @@ class VersionGanttController extends Controller
ActivityProgressLog::where('version_gantt_id', $version_gantt_id)->delete();
}
public function edit($id){
public function edit($id)
{
if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
die();
@ -109,7 +112,8 @@ class VersionGanttController extends Controller
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet], 200);
}
public function ganttProgress($column, $value){
public function ganttProgress($column, $value)
{
$progress = VersionGantt::select('m_version_gantt.id', 'm_activity.persentase_progress', 'm_activity.bobot_planning')
->join('m_activity', 'm_version_gantt.id', '=', 'm_activity.version_gantt_id')
->where("m_version_gantt." . $column, $value)
@ -117,13 +121,11 @@ class VersionGanttController extends Controller
->where('m_activity.parent_id', null)
->get();
foreach ($progress as $item) {
if($item->persentase_progress){
$item->progress = $item->persentase_progress;
$item->bobot = $item->bobot_planning;
$item->save();
}
}
}
public function list()
{

2
app/Models/Absent.php

@ -12,6 +12,6 @@ class Absent extends Model
const UPDATED_AT = 'updated_at';
protected $fillable = [
'user_id', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by'
'user_id', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id'
];
}

19
app/Models/Activity.php

@ -33,6 +33,9 @@ class Activity extends Model
'jobs_done', 'assign_hr', 'assign_material', 'assign_tools', 'assign_expense'
];
protected $casts = [
'rencana_biaya' => 'double'
];
public function getStartDateAttribute($value)
{
@ -61,7 +64,7 @@ class Activity extends Model
public static function boot() {
parent::boot();
DB::transaction(function() {
static::updating(function($data) {
$data->logPersentaseProgress();
});
@ -96,23 +99,25 @@ class Activity extends Model
$data->updateCostActual();
$data->updateStartEndDateHeader();
});
},5);
}
private function updateBobot($isDelete = false)
{
$root = Activity::where('version_gantt_id', $this->version_gantt_id)
->where("proyek_id", $this->proyek_id)
$root = Activity::where([
['version_gantt_id', $this->version_gantt_id],
['proyek_id', $this->proyek_id]
])
->whereNull('parent_id')
->first();
if(isset($root) && $root->rencana_biaya > 0){
$activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->version_gantt_id)->get();
if(isset($root) && doubleval($root->rencana_biaya) > 0){
$activities = Activity::where([['proyek_id', $this->proyek_id],['version_gantt_id', $this->version_gantt_id]])->get();
foreach ($activities as $activity) {
if($isDelete && $activity->id == $this->id)
continue;
$activity->bobot_planning = ( (int)$activity->rencana_biaya / $root->rencana_biaya) * 100;
$activity->bobot_planning = ( doubleval($activity->rencana_biaya) / doubleval($root->rencana_biaya)) * 100;
$activity->updated_by = auth()->user() ? auth()->user()->name : "system";
$activity->saveQuietly();

23
app/Models/AssignMaterial.php

@ -3,10 +3,8 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\RequestMaterial;
use App\Models\Activity;
use App\Models\ReportActivityMaterial;
use App\Models\{Activity,RequestMaterial,ReportActivityMaterial};
use Illuminate\Support\Facades\DB;
class AssignMaterial extends Model
{
protected $table = 'assign_material_to_activity';
@ -23,24 +21,25 @@ class AssignMaterial extends Model
protected $casts = [
'id' => 'integer',
'budget' => 'string',
'qty_planning' => 'float'
];
public static function boot() {
parent::boot();
DB::transaction(function () {
static::created(function($data) {
$activity = Activity::find($data->activity_id);
$material = RequestMaterial::where("id", $data->material_id)->first();
$activity->rencana_biaya += floatval($material->price) * floatval($data->qty_planning);
$activity = Activity::find((int)$data->activity_id);
$material = RequestMaterial::find((int)$data->material_id);
$activity->rencana_biaya += (doubleval($material->price) * doubleval($data->qty_planning));
$activity->save();
});
static::deleted(function($data) {
$reportActivities = ReportActivityMaterial::where('assign_material_id', $data->id)->delete();
$activity = Activity::where('id', $data->activity_id)->first();
$activity->rencana_biaya -= floatval($data->budget) * floatval($data->qty_planning);
ReportActivityMaterial::where('assign_material_id', $data->id)->delete();
$activity = Activity::find($data->activity_id);
$activity->rencana_biaya -= (doubleval($data->budget) * doubleval($data->qty_planning));
$activity->save();
});
}, 5);
}
}

2
app/Models/Broadcast.php

@ -12,6 +12,6 @@ class Broadcast extends Model
const UPDATED_AT = 'updated_at';
protected $fillable = [
'title_notif', 'message_notif', 'description', 'send_to_type', 'send_to_id', 'status_send', 'created_at', 'created_by', 'updated_at', 'updated_by'
'title_notif', 'message_notif', 'description', 'send_to_type', 'send_to_id', 'status_send', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id'
];
}

3
app/Models/ChecklistK3.php

@ -17,6 +17,7 @@ class ChecklistK3 extends Model
'created_at',
'created_by',
'updated_at',
'updated_by'
'updated_by',
'company_id'
];
}

5
app/Models/Company.php

@ -32,6 +32,9 @@ class Company extends Model
'created_by',
'updated_at',
'updated_by',
'company_id'
'cluster',
'type_account',
'date_register',
'discount_id'
];
}

27
app/Models/ContactSales.php

@ -0,0 +1,27 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ContactSales extends Model
{
protected $table = 'm_contact_sales';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'name',
'company_name',
'email',
'role',
'number_phone',
'status',
'message',
'created_at',
'created_by',
'updated_at',
'updated_by',
];
}

26
app/Models/Demo.php

@ -0,0 +1,26 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Demo extends Model
{
protected $table = 'm_demo';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'name',
'email',
'role',
'number_phone',
'status',
'message',
'created_at',
'created_by',
'updated_at',
'updated_by',
];
}

4
app/Models/HumanResource.php

@ -14,6 +14,7 @@ class HumanResource extends Model
protected $fillable = [
'role_id',
'username',
'discount_id',
'password',
'session_login',
'name',
@ -26,6 +27,7 @@ class HumanResource extends Model
'birth_date',
'blood_type',
'ktp_number',
'company_id',
'employee_type',
'status_resource',
'created_at',
@ -34,6 +36,6 @@ class HumanResource extends Model
'updated_by',
'divisi_id',
'status_boundary',
'company_id'
'is_customer'
];
}

17
app/Models/KanbanBoard.php

@ -0,0 +1,17 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class KanbanBoard extends Model
{
protected $table = 'kanban_board';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'name_board', 'header_color', 'body_color', 'status_progress', 'proyek_id', 'version_gantt_id', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
}

17
app/Models/KanbanCard.php

@ -0,0 +1,17 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class KanbanCard extends Model
{
protected $table = 'kanban_card';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'activity_id', 'kanban_board_id', 'version_gantt_id', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
}

2
app/Models/PanicButton.php

@ -12,6 +12,6 @@ class PanicButton extends Model
const UPDATED_AT = 'updated_at';
protected $fillable = [
'user_id', 'lat', 'lon', 'status_response', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by'
'user_id', 'lat', 'lon', 'status_response', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id'
];
}

2
app/Models/Presence.php

@ -16,6 +16,6 @@ class Presence extends Model
'user_id', 'clock_in', 'clock_out', 'date_presence',
'clock_in_lat', 'clock_in_lng', 'clock_out_lat', 'clock_out_lng',
'clock_in_loc', 'clock_out_loc', 'clock_in_boundary', 'clock_out_boundary',
'created_at', 'created_by', 'updated_at', 'updated_by'
'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id'
];
}

25
app/Models/ProductTransaction.php

@ -0,0 +1,25 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ProductTransaction extends Model
{
protected $table = 't_transaction';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'company_id',
'type_paket',
'amount',
'exp_ospro',
'pay_date',
'created_at',
'updated_at',
'created_by',
'updated_by'
];
}

8
app/Models/Project.php

@ -15,6 +15,7 @@ class Project extends Model
'kode_sortname',
'jumlah_stakeholder',
'nama',
'nickname',
'mulai_proyek',
'akhir_proyek',
'area_kerja',
@ -23,8 +24,10 @@ class Project extends Model
'biaya_actual',
'company',
'pm_id',
'scoupe_of_work',
'type_proyek_id',
'divisi_id',
'value_proyek',
'persentase_progress',
'keterangan',
'durasi_proyek',
@ -48,6 +51,9 @@ class Project extends Model
'created_by',
'updated_at',
'updated_by',
'created_by_id'
'created_by_id',
'company_id',
'deleted_at',
'deleted_by_id'
];
}

17
app/Models/ProjectExpenditure.php

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

17
app/Models/ProjectFinancialHealth.php

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

17
app/Models/ProjectInvoice.php

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

2
app/Models/ProjectRole.php

@ -12,6 +12,6 @@ class ProjectRole 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', 'company_id', 'updated_by'
];
}

17
app/Models/ProjectScheduleHealth.php

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

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

28
app/Models/RefferalCode.php

@ -0,0 +1,28 @@
<?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 = [
'code',
'amount',
'exp',
'type',
'allocation',
'description',
'created_at',
'created_by',
'updated_at',
'updated_by',
'deleted_at',
'deleted_by'
];
}

3
app/Models/ReportK3.php

@ -20,6 +20,7 @@ class ReportK3 extends Model
'created_at',
'created_by',
'updated_at',
'updated_by'
'updated_by',
'company_id'
];
}

2
app/Models/Role.php

@ -12,6 +12,6 @@ class Role extends Model
const UPDATED_AT = 'updated_at';
protected $fillable = [
'name', 'description', 'default_page', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id'
'name', 'description', 'default_page', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id', 'all_project'
];
}

2
app/Models/RoleMenu.php

@ -12,6 +12,6 @@ class RoleMenu extends Model
const UPDATED_AT = 'updated_at';
protected $fillable = [
'role_id', 'menu_id', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id', "create", "read", "update", "delete"
'role_id', 'menu_id', 'create', 'read', 'update', 'delete', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
}

17
app/Models/User.php

@ -24,7 +24,7 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
protected $fillable = [
'name', 'email', 'role_id', 'username', 'session_login', 'phone_number', 'email', 'address',
'fcm_token', 'gender', 'birth_place', 'birth_date', 'blood_type', 'ktp_number', 'working_hours',
'created_at', 'created_by', 'updated_at', 'updated_by', 'status_resource'
'created_at', 'created_by', 'updated_at', 'updated_by', 'status_resource', 'discount_id','company_id','is_customer'
];
const CREATED_AT = 'created_at';
@ -83,11 +83,9 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
->first();
$shift = null;
if ($userShift !== null)
{
if ($userShift !== null) {
$shiftId = null;
switch ($ts->shortEnglishDayOfWeek)
{
switch ($ts->shortEnglishDayOfWeek) {
case "Mon":
$shiftId = $userShift->mon_shift_id;
break;
@ -123,8 +121,7 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
}
if ($shift !== null)
{
if ($shift !== null) {
$from = Carbon::createFromTimeString($shift->start_time, $tz)
->subMinutes($shift->flex_time_minute);
$to = Carbon::createFromTimeString($shift->end_time, $tz)
@ -150,16 +147,14 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
{
$ts = $at;
if ($at !== null)
{
if ($at !== null) {
$ts = Carbon::now($tz);
}
$tsSec = $ts->secondsSinceMidnight();
$status = "";
$wt = $this->getWorkingTime($ts, $tz);
if ($wt === null)
{
if ($wt === null) {
$status = self::HOLIDAY;
} else {
$from = $wt->from;

31
app/Models/UserToActivity.php

@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Activity;
use Illuminate\Support\Facades\DB;
class UserToActivity extends Model
{
@ -29,35 +30,37 @@ class UserToActivity extends Model
public static function boot() {
parent::boot();
DB::transaction(function(){
static::created(function($data) {
$activity = Activity::find($data->activity_id);
$getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first();
$salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100);
if($getWorkingHours->uom_standart_rate == "Hour")
$salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100);
$activity->rencana_biaya += $salary;
$getWorkingHours = UserToProyek::where([['user_id', $data->user_id],['proyek_id', $activity->proyek_id]])->first();
$salary = 0;
if($getWorkingHours->uom_standart_rate == "Hour") {
$salary = (doubleval($getWorkingHours->standart_rate) * 8) * (int)$activity->duration * ($getWorkingHours->max_used / 100);
} else {
$salary = (doubleval($getWorkingHours->standart_rate) * (int)$activity->duration) * ($getWorkingHours->max_used / 100);
}
$activity->rencana_biaya += doubleval($salary);
$activity->save();
});
static::deleted(function($data) {
$activity = Activity::find($data->activity_id);
$getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first();
$salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100);
$getWorkingHours = UserToProyek::where([['user_id', $data->user_id],['proyek_id', $activity->proyek_id]])->first();
$salary = 0;
if($getWorkingHours->uom_standart_rate == "Hour"){
$salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100);
$salary = (doubleval($getWorkingHours->standart_rate) * 8) * (int)$activity->duration * ($getWorkingHours->max_used / 100);
} else {
$salary = (doubleval($getWorkingHours->standart_rate) * (int)$activity->duration) * ($getWorkingHours->max_used / 100);
}
$activity->rencana_biaya -= doubleval($salary);
$activity->rencana_biaya -= $salary;
if ($activity->rencana_biaya < 0) {
$activity->rencana_biaya = 0;
}
$activity->save();
});
}, 5);
}
}

2733
composer.lock generated

File diff suppressed because it is too large Load Diff

120
rest-client.http

@ -1,4 +1,5 @@
@token = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3Q6ODQ0NFwvYXBpXC9sb2dpbiIsImlhdCI6MTY5MTc2MDYyNCwiZXhwIjoxNjkyMzY1NDI0LCJuYmYiOjE2OTE3NjA2MjQsImp0aSI6Ikd2bEFPTE4yZ2FuRFdVbjEiLCJzdWIiOjEsInBydiI6IjIzYmQ1Yzg5NDlmNjAwYWRiMzllNzAxYzQwMDg3MmRiN2E1OTc2ZjcifQ.XNGbsmcgQ-CkV8vLlvnItGKM0R1am5X5b6qUFOR1DRo
@token = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9iYWNrZW5kLnRlc3RcL2FwaVwvbG9naW4iLCJpYXQiOjE3MDEzNzMzNzQsImV4cCI6MTcwMTk3ODE3NCwibmJmIjoxNzAxMzczMzc0LCJqdGkiOiJhbkJWOHIwUDZndFRXZk5KIiwic3ViIjoxNzg4LCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.QCiXq-62da7Sdk7sEb_J0apEij_R6IQgZVYG9iL6M8g
@tokenS = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9hZHctYXBpLm9zcHJvLmlkXC9hcGlcL2xvZ2luIiwiaWF0IjoxNjkxNTcyMTIwLCJleHAiOjE2OTIxNzY5MjAsIm5iZiI6MTY5MTU3MjEyMCwianRpIjoiVUdqbnhLRVdlZzYyTTBnayIsInN1YiI6MSwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.5QqK0dLW5jzbVOkSCSW0mFo0K7ycGOBW9NCG_2Zldm4
@ -6,7 +7,7 @@
# @hostname = https://ospro-api.ospro.id/api
# @hostname = https://api-iu.ospro.id/api
# @hostname = https://api-staging-adw.ospro.id/api
@hostname = http://localhost:8444/api
@hostname = http://backend.test/api
# @hostname = http://103.73.125.81:8444/api
# @hostname = http://localhost:8444/adw-backend/api
@ -17,8 +18,8 @@ POST {{hostname}}/login
content-type: application/json
{
"username": "admin",
"password": "1nt3gr4s14"
"username": "testing",
"password": "testing123"
}
###### Tools Req
@ -418,7 +419,7 @@ content-type: application/json
"operator": "AND"
}
],
"select": ["kode_sortname", "nama", "mulai_proyek"],
"select": ["id", "nama", "rencana_biaya", "type_proyek_id", "currency_symbol", "mulai_proyek", "akhir_proyek"],
"joins": [
{
"name": "m_users",
@ -455,7 +456,43 @@ Authorization: Bearer {{tokenS}}
content-type: application/json
{
"columns":[{"name":"nama","logic_operator":"ilike","value":"","operator":"AND"}],"joins":[{"name":"m_users","column_join":"pm_id","column_results":["name","username"]},{"name":"m_type_proyek","column_join":"type_proyek_id","column_results":["name","description"]}],"orders":{"columns":["id"],"ascending":false},"paging":{"start":0,"length":10}
"columns": [
{
"name": "nama",
"logic_operator": "ilike",
"value": "",
"operator": "AND"
}
],
"select": ["id", "nama", "rencana_biaya", "color_progress", "currency_symbol", "mulai_proyek", "akhir_proyek"],
"joins": [
{
"name": "m_users",
"column_join": "pm_id",
"column_results": [
"name",
"username"
]
},
{
"name": "m_type_proyek",
"column_join": "type_proyek_id",
"column_results": [
"name",
"description"
]
}
],
"orders": {
"columns": [
"id"
],
"ascending": false
},
"paging": {
"start": 0,
"length": 10
}
}
### add
@ -529,7 +566,7 @@ content-type: application/json
###### Activity
### get data by id version
GET {{hostname}}/activity/33/29/get
GET {{hostname}}/activity/550/137/get
Authorization: Bearer {{token}}
content-type: application/json
@ -785,24 +822,44 @@ content-type: application/json
###
POST {{hostname}}/activity/get-curva-s
POST {{hostname}}/dashboard/curva-s
Authorization: Bearer {{token}}
content-type: application/json
{
"project_id": [47],
"period": "week"
"project_id": [15]
}
###
POST {{hostname}}/project/s-curve-command-test
Authorization: Bearer {{token}}
content-type: application/json
# {"period":"week","project_id":"137","gantt_id":"916"}
# {"period":"week","project_id":"129","gantt_id":"862"}
{"period":"week","project_id":"140","gantt_id":"1103"}
###
POST {{hostname}}/dashboard/curva-s
POST {{hostname}}/project/calculate-s-curve
Authorization: Bearer {{token}}
content-type: application/json
{"period":"week","project_id":"129","gantt_id":"862"}
### {"period":"week","project_id":"135","gantt_id":"891"}
#######
POST {{hostname}}/project/get-s-curve
Authorization: Bearer {{token}}
content-type: application/json
{"project_id":"164","gantt_id":"973","period":"week"}
### {"period":"week","project_id":"129","gantt_id":"800"}
#######
GET {{hostname}}/activity/s-curve/137/892
Authorization: Bearer {{token}}
content-type: application/json
{
"project_id": [15]
}
###
GET https://adw-api.ospro.id/api/request-material/get-material-integration?name=c
@ -957,6 +1014,27 @@ content-type: application/json
"user_id": 1247
}
# -6.226761,106.809311 jkarta
# -6.465806,106.760559
# -6.356175,108.336182 indramayu
# -6.266805,106.468048, tigaraksa
# -6.205115,106.918373 jatinegara
######
POST {{hostname}}/presence/test
Authorization: Bearer {{token}}
content-type: application/json
{
"clock_in_out": {
"clock_out_lat": -6.356175,
"clock_out_lng": 108.336182,
"type" : "out"
},
"time": "2023-08-15T14:48:17+07:00",
"user_id": 1566
}
######
POST {{hostname}}/presence/add
Authorization: Bearer {{token}}
@ -1016,9 +1094,7 @@ POST {{hostname}}/map-monitoring/search
Authorization: Bearer {{token}}
content-type: application/json
{
"project_id" : [75, 76, 78]
}
{"project_id":[140,138,132,130]}
######
POST {{hostname}}/waypoint/add-bulk
@ -1159,13 +1235,3 @@ content-type: application/json
}
}
#######
POST {{hostname}}/project/get-s-curve
Authorization: Bearer {{token}}
content-type: application/json
{
"period":"week",
"project_id":"118",
"gantt_id":"287"
}

130
routes/web.php

@ -6,6 +6,19 @@ $router->get('/', function () use ($router) {
$router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($router) {
$router->post('/login', 'AuthController@login');
// Landing Route
$router->post('/send-email', 'AuthController@sendEmail');
$router->post('/user-register','UserRegisterController@add');
$router->post('/company-management-user/add', 'CompanyController@add');
$router->post('/product-transaction-user/add', 'ProductTransactionController@add');
$router->post('/company-management-user/search', 'CompanyController@search');
$router->post('/human-resource-user/add', 'HumanResourceController@add_user');
$router->get('/company-management-user/edit/{id}', 'CompanyController@edit');
$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-user/search', 'RefferalCodeController@search');
$router->post('/menu/add', 'MenuController@add');
$router->get('/menu/edit/{id}', 'MenuController@edit');
@ -21,18 +34,28 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->post('/role-menu/search', 'RoleMenuController@search');
$router->get('/role-menu/get-role/{id}', 'RoleMenuController@listMenu');
$router->post('/sales-contact/add', 'ContactSalesController@add');
$router->get('/sales-contact/edit/{id}', 'ContactSalesController@edit');
$router->put('/sales-contact/update/{id}', 'ContactSalesController@update');
$router->post('/sales-contact/search', 'ContactSalesController@search');
$router->delete('/sales-contact/delete/{id}', 'ContactSalesController@delete');
$router->group(['middleware' => ['auth', 'cors']], function () use ($router) {
$router->get('/dashboard/get-company-cashflow[/{year}]', 'DashboardBoDController@getCompanyCashFlow'); // project expenditure
$router->get('/dashboard/get-invoice-outstanding[/{year}]', 'DashboardBoDController@getInvoiceOutstanding'); // project invoice vs cash in
$router->get('/dashboard/get-total-project-per-schedule-health[/{year}]', 'DashboardBoDController@getTotalProjectPerScheduleHealth');
$router->get('/dashboard/get-total-project-per-budget-health[/{year}]', 'DashboardBoDController@getTotalProjectPerBudgetHealth');
$router->get('/dashboard/get-total-project-schedule-health-per-division[/{year}]', 'DashboardBoDController@getTotalProjectScheduleHealthPerDivision');
$router->get('/dashboard/get-total-project-budget-health-per-division[/{year}]', 'DashboardBoDController@getTotalProjectBudgetHealthPerDivision');
$router->get('/dashboard/get-total-project-per-phase[/{year}]', 'DashboardBoDController@getTotalProjectPerPhase');
$router->get('/dashboard/get-total-project-per-division[/{year}]', 'DashboardBoDController@getTotalProjectPerDivision');
$router->get('/dashboard/get-total-project-value-per-division[/{year}]', 'DashboardBoDController@getTotalProjectValuePerDivision');
$router->get('/dashboard/get-detail-expenditure[/{year}]', 'DashboardBoDController@getDetailExpenditure');
$router->get('/dashboard/get-company-cashflow/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getCompanyCashFlow'); // project expenditure
$router->get('/dashboard/get-invoice-outstanding/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getInvoiceOutstanding'); // project invoice vs cash in
$router->get('/dashboard/get-total-project-per-schedule-health/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getTotalProjectPerScheduleHealth');
$router->get('/dashboard/get-total-project-per-budget-health/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getTotalProjectPerBudgetHealth');
$router->get('/dashboard/get-total-project-schedule-health-per-division/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getTotalProjectScheduleHealthPerDivision');
$router->get('/dashboard/get-total-project-budget-health-per-division/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getTotalProjectBudgetHealthPerDivision');
$router->get('/dashboard/get-total-project-per-phase/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getTotalProjectPerPhase');
$router->get('/dashboard/get-total-project-per-division/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getTotalProjectPerDivision');
$router->get('/dashboard/get-total-project-value-per-division/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getTotalProjectValuePerDivision');
$router->get('/dashboard/get-detail-expenditure/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getDetailExpenditure');
$router->get('/dashboard/get-detail-expenditure-color/{company_id}/{role_name}', 'DashboardBoDController@getDetailExpenditureColor');
$router->get('/dashboard/get-detail-financial-health-color/{company_id}/{role_name}', 'DashboardBoDController@getDetailFinancialHealthColor');
$router->get('/dashboard/get-detail-schedule-health-color/{company_id}/{role_name}', 'DashboardBoDController@getDetailScheduleHealthColor');
$router->get('/dashboard/get-detail-invoice-color/{company_id}/{role_name}', 'DashboardBoDController@getDetailInvoiceColor');
$router->post('/role/search', 'RoleController@search');
$router->post('/role/add', 'RoleController@add');
@ -43,15 +66,15 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->post('/document-project/upload', 'ProjectDokumenController@uploadProjectDokumen');
$router->get('/document-project/get/{id}', 'ProjectDokumenController@dokumenByProyekId');
$router->delete('/document-project/delete/{id}', 'ProjectDokumenController@delete');
$router->delete('/document-project/delete/{id}/{company_id}', 'ProjectDokumenController@delete');
$router->post('/document-project/search', 'ProjectDokumenController@searchDocProject');
$router->get('/document-project/download/{id}', 'ProjectDokumenController@downloadDokumen');
$router->get('/document-project/download/{id}/{company_id}', 'ProjectDokumenController@downloadDokumen');
$router->post('/document-activity/upload', 'ActivityDokumenController@uploadProjectDokumen');
$router->get('/document-activity/get/{id}', 'ActivityDokumenController@dokumenByActivityId');
$router->delete('/document-activity/delete/{id}', 'ActivityDokumenController@delete');
$router->delete('/document-activity/delete/{id}/{company_id}', 'ActivityDokumenController@delete');
$router->post('/document-activity/search', 'ActivityDokumenController@searchDocProject');
$router->get('/document-activity/download/{id}', 'ActivityDokumenController@downloadDokumen');
$router->get('/document-activity/download/{id}/{company_id}', 'ActivityDokumenController@downloadDokumen');
$router->get('/project-by-customer/{id}', 'ProjectController@getByUser');
$router->post('/project/search', 'ProjectController@search');
@ -59,9 +82,10 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->put('/project/update/{id}', 'ProjectController@update');
$router->get('/project/edit/{id}', 'ProjectController@edit');
$router->get('/project/detail/{id}[/{gantt_id}[/{s_curve}]]', 'ProjectController@detail');
$router->delete('/project/delete/{id}', 'ProjectController@delete');
$router->delete('/project/delete/{id}/{company_id}', 'ProjectController@delete');
$router->get('/project/list', 'ProjectController@list');
$router->get('/project/set-baseline/{gantt_id}', 'ProjectController@setBaseline');
$router->get('/project/set-baseline-activity/{activity_id}/{gantt_id}', 'ProjectController@setBaselineActivity');
$router->get('/project/synchronize-report/{gantt_id}', 'ProjectController@synchronizeReport');
$router->get('/project/manpower/{proyek_id}', 'ProjectController@getManpower');
$router->get('/project/manpower/assigned/{gantt_id}', 'ProjectController@getAssignedHR');
@ -69,17 +93,20 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->post('/project/get-s-curve', 'ProjectController@getSCurve');
$router->post('/project/calculate-s-curve', 'ProjectController@calculateSCurve');
$router->post('/project/s-curve-command', 'ProjectController@sCurveCommand');
$router->post('/project/s-curve-command-test', 'ProjectController@calculateSCurvetest');
$router->post('/project/get-linear-s-curve', 'ProjectController@getLinearSCurve');
$router->post('/project/get-overdue-activities', 'ProjectController@getOverdueActivities');
$router->post('/project/get-integration-invoice', 'ProjectController@getInvoiceIntegration');
$router->post('/project/get-report-distribution', 'ProjectController@getReportDistribution');
$router->get('/project/get-integration-project-cost={name}', 'ProjectController@getProjectCostIntegration');
/* $router->get('/project/get-expenditure/{id}/{date?}', 'ProjectController@getExpenditure'); */
/* $router->get('/project/get-total-expenditure/{id}', 'ProjectController@getTotalExpenditure'); */
/* $router->get('/project/get-status-health-schedule/{id}', 'ProjectController@getStatusSchedule'); */
/* $router->get('/project/get-status-health-budget/{id}', 'ProjectController@getStatusBudget'); */
$router->get('/project-carausell','ProjectCarausellController@invoke');
$router->get('/project-carausell/{company_id}/{all_project}/{hierarchy}', 'ProjectCarausellController@invoke');
$router->post('/project-charter/search', 'ProjectCharterController@search');
$router->post('/project-charter/add', 'ProjectCharterController@add');
@ -137,6 +164,30 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->delete('/project-phase/delete/{id}', 'ProjectPhaseController@delete');
$router->get('/project-phase/list', 'ProjectPhaseController@list');
$router->post('/project-expenditure/add', 'ProjectExpenditureController@add');
$router->post('/project-expenditure/search', 'ProjectExpenditureController@search');
$router->get('/project-expenditure/edit/{id}', 'ProjectExpenditureController@edit');
$router->put('/project-expenditure/update/{id}', 'ProjectExpenditureController@update');
$router->delete('/project-expenditure/delete/{id}', 'ProjectExpenditureController@delete');
$router->post('/project-financial-health/add', 'ProjectFinancialHealthController@add');
$router->post('/project-financial-health/search', 'ProjectFinancialHealthController@search');
$router->get('/project-financial-health/edit/{id}', 'ProjectFinancialHealthController@edit');
$router->put('/project-financial-health/update/{id}', 'ProjectFinancialHealthController@update');
$router->delete('/project-financial-health/delete/{id}', 'ProjectFinancialHealthController@delete');
$router->post('/project-schedule-health/add', 'ProjectScheduleHealthController@add');
$router->post('/project-schedule-health/search', 'ProjectScheduleHealthController@search');
$router->get('/project-schedule-health/edit/{id}', 'ProjectScheduleHealthController@edit');
$router->put('/project-schedule-health/update/{id}', 'ProjectScheduleHealthController@update');
$router->delete('/project-schedule-health/delete/{id}', 'ProjectScheduleHealthController@delete');
$router->post('/project-invoice/add', 'ProjectInvoiceController@add');
$router->post('/project-invoice/search', 'ProjectInvoiceController@search');
$router->get('/project-invoice/edit/{id}', 'ProjectInvoiceController@edit');
$router->put('/project-invoice/update/{id}', 'ProjectInvoiceController@update');
$router->delete('/project-invoice/delete/{id}', 'ProjectInvoiceController@delete');
$router->post('/user-to-project/assign', 'UserProyekController@assignUserProyek');
$router->post('/request-material/add', 'RequestMaterialController@add');
@ -198,6 +249,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->get('/user-to-activity/edit/{id}', 'UserToActivityController@edit');
$router->put('/user-to-activity/update/{id}', 'UserToActivityController@update');
$router->post('/user-to-activity/search', 'UserToActivityController@search');
$router->post('/user-to-activity/by-date-status', 'UserToActivityController@activityUser');
$router->post('/user-to-activity/search-analysis', 'UserToActivityController@searchAnalysis');
$router->post('/user-to-activity/list-filtered', 'UserToActivityController@listFiltered');
$router->delete('/user-to-activity/delete/{id}', 'UserToActivityController@delete');
@ -214,6 +266,8 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->post('/activity/import-old', 'ActivityController@importOld');
$router->post('/activity/batch-update/{ganttId}', 'ActivityController@batchUpdate');
$router->get('/activity/update-schedule/{ganttId}', 'ActivityController@updateSchedule');
$router->get('/activity/s-curve/{proyek_id}/{gantt_id}', 'ActivityController@activitySCurve');
$router->post('/task', 'ActivityController@add');
$router->get('/task/edit/{id}', 'ActivityController@edit');
$router->put('/task/{id}', 'ActivityController@update');
@ -279,8 +333,10 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->post('/image/search', 'ImageController@search');
$router->delete('/image/delete/{id}', 'ImageController@delete');
$router->delete('/image/delete/{id}/{category}', 'ImageController@deleteByRef');
$router->delete('/image/delete/{id}/{category}/{company_id}', 'ImageController@deleteByRef');
$router->delete('/image/multiple-delete/{id}/{category}/{company_id}', 'ImageController@deleteByRefMultiple');
$router->post('/image/upload', 'ImageController@uploadImage');
$router->post('/image/multiple-upload', 'ImageController@uploadMultipleImage');
$router->get('/image/{id}/{category}', 'ImageController@getByRefId');
$router->post('/panic-button/add', 'PanicButtonController@add');
@ -315,6 +371,18 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->get('/project-issues/list', 'ProjectIssuesController@list');
$router->get('/project-issues/{where}/{val}', 'ProjectIssuesController@customWhere');
$router->get('/kanban-board/list', 'KanbanBoardController@list');
$router->post('/kanban-board/add', 'KanbanBoardController@add');
$router->put('/kanban-board/update/{id}', 'KanbanBoardController@update');
$router->delete('/kanban-board/delete/{id}', 'KanbanBoardController@delete');
$router->post('/kanban-board/search', 'KanbanBoardController@search');
$router->get('/kanban-card/get-data/{project_id}/{gantt_id}/{board_id}', 'KanbanCardController@getData');
$router->post('/kanban-card/add', 'KanbanCardController@add');
$router->put('/kanban-card/update/{id}', 'KanbanCardController@update');
$router->delete('/kanban-card/delete/{id}', 'KanbanCardController@delete');
$router->post('/kanban-card/search', 'KanbanCardController@search');
$router->post('/project-risks/add', 'ProjectRisksController@add');
$router->get('/project-risks/edit/{id}', 'ProjectRisksController@edit');
$router->put('/project-issues/update/{id}', 'ProjectRisksController@update');
@ -363,7 +431,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->post('/report-activity-material/add', 'ReportActivityMaterialController@add');
$router->post('/report-activity-material/search', 'ReportActivityMaterialController@search');
$router->delete('/report-activity-material/delete/{id}', 'ReportActivityMaterialController@delete');
$router->delete('/report-activity-material/delete/{id}/{company_id}', 'ReportActivityMaterialController@delete');
$router->get('/report-activity-material/list', 'ReportActivityMaterialController@list');
$router->get('/report-activity-material/datatables', 'ReportActivityMaterialController@datatables');
$router->post('/report-activity-material/update-status', 'ReportActivityMaterialController@updateStatusStartFinish');
@ -417,7 +485,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->get('/user-to-proyek/edit/{id}', 'UserToProyekController@edit');
$router->put('/user-to-proyek/update/{id}', 'UserToProyekController@update');
$router->post('/user-to-proyek/search', 'UserToProyekController@search');
$router->delete('/user-to-proyek/delete/{id}', 'UserToProyekController@delete');
$router->delete('/user-to-proyek/delete/{id}/{company_id}', 'UserToProyekController@delete');
$router->get('/user-to-proyek/list', 'UserToProyekController@list');
$router->get('/user-to-proyek/select', 'UserToProyekController@select');
$router->get('/user-to-proyek/get-employee-integration', 'UserToProyekController@getEmployeeIntegration');
@ -426,7 +494,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->get('/folder-document-proyek/edit/{id}', 'FolderDocumentProyekController@edit');
$router->put('/folder-document-proyek/update/{id}', 'FolderDocumentProyekController@update');
$router->post('/folder-document-proyek/search', 'FolderDocumentProyekController@search');
$router->delete('/folder-document-proyek/delete/{id}', 'FolderDocumentProyekController@delete');
$router->delete('/folder-document-proyek/delete/{id}/{company_id}', 'FolderDocumentProyekController@delete');
$router->get('/folder-document-proyek/list', 'FolderDocumentProyekController@list');
$router->get('/folder-document-proyek/get-tree/{id}', 'FolderDocumentProyekController@getTree');
@ -488,6 +556,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->put('/hierarchy-ftths/{id}', 'HierarchyFtthController@update');
$router->delete('/hierarchy-ftths/{id}', 'HierarchyFtthController@destroy');
$router->get('/hierarchy-ftths/tree/{project_id}', 'HierarchyFtthController@getTreeByProject');
$router->get('/hierarchy-ftths/count-tree/{hierarchy_id}', 'HierarchyFtthController@countProgressTree');
$router->get('/hierarchy-ftths/tree-gantt/{gantt_id}', 'HierarchyFtthController@getTreeByGantt');
$router->post('/map-monitoring/search', 'MapMonitoringController@search');
@ -513,5 +582,26 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->post('/menu-company/search', 'MenuCompanyController@search');
$router->get('/menu-company/management/{id}', 'MenuCompanyController@listMenu');
$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');
$router->get('/information-storage/{company_name}', 'Controller@storage');
$router->get('/information-storage-all-company','Controller@storageAllCompany');
$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('/product-transaction/edit/{id}', 'ProductTransactionController@add');
$router->put('/product-transaction/update/{id}', 'ProductTransactionController@update');
$router->post('/product-transaction/search', 'ProductTransactionController@search');
$router->delete('/product-transaction/delete/{id}', 'ProductTransactionController@delete');
$router->get('/product-transaction/list', 'ProductTransactionController@list');
});
});

Loading…
Cancel
Save