You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
258 lines
11 KiB
258 lines
11 KiB
<?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; |
|
} |
|
|
|
}
|
|
|