Browse Source

add kanban feature

pull/1/head
wahyun 10 months ago
parent
commit
d38f1f898e
  1. 115
      app/Http/Controllers/KanbanBoardController.php
  2. 258
      app/Http/Controllers/KanbanCardController.php
  3. 17
      app/Models/KanbanBoard.php
  4. 17
      app/Models/KanbanCard.php

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

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'
];
}
Loading…
Cancel
Save