wahyuun
8 months ago
6 changed files with 310 additions and 307 deletions
@ -1,160 +1,159 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
namespace App\Http\Controllers; |
namespace App\Http\Controllers; |
||||||
|
|
||||||
use Illuminate\Http\Request; |
use App\Models\{AssignMaterial,AssignTools,ToolsResource}; |
||||||
use App\Models\AssignTools; |
use Illuminate\Http\Request; |
||||||
use Datatables; |
use Yajra\Datatables\Datatables; |
||||||
use App\Models\ToolsResource; |
class AssignToolsController extends Controller |
||||||
class AssignToolsController extends Controller |
{ |
||||||
{ |
public function add(Request $request){ |
||||||
public function add(Request $request){ |
$this->validate($request, [ |
||||||
$this->validate($request, [ |
'activity_id' => 'required', |
||||||
'activity_id' => 'required', |
'tools_id' => 'required', |
||||||
'tools_id' => 'required', |
'qty_planning' => 'required', |
||||||
'qty_planning' => 'required', |
]); |
||||||
]); |
|
||||||
|
$checkStock = ToolsResource::where("id", $request->tools_id)->first(); |
||||||
$checkStock = ToolsResource::where("id", $request->tools_id)->first(); |
$currentStock = $checkStock->qty; |
||||||
$currentStock = $checkStock->qty; |
if((int)$currentStock < (int)$request->qty_planning){ |
||||||
if((int)$currentStock < (int)$request->qty_planning){ |
return response()->json(['status'=>'failed','message'=>'Not enough stock in warehouse!','code'=>400]); |
||||||
return response()->json(['status'=>'failed','message'=>'Not enough stock in warehouse!','code'=>400]); |
die(); |
||||||
die(); |
} |
||||||
} |
|
||||||
|
|
||||||
|
$data = $request->all(); |
||||||
$data = $request->all(); |
|
||||||
|
$data['created_by'] = $this->currentName; |
||||||
$data['created_by'] = $this->currentName; |
|
||||||
|
$result = AssignTools::create($data); |
||||||
$result = AssignTools::create($data); |
if($result){ |
||||||
if($result){ |
$checkStock = ToolsResource::find($request->tools_id); |
||||||
$checkStock = ToolsResource::find($request->tools_id); |
$newStock = (int)$checkStock->qty - (int)$request->qty_planning; |
||||||
$newStock = (int)$checkStock->qty - (int)$request->qty_planning; |
$dataUpdate = array( |
||||||
$dataUpdate = array( |
"qty"=>$newStock, |
||||||
"qty"=>$newStock, |
"updated_by"=>$this->currentName |
||||||
"updated_by"=>$this->currentName |
); |
||||||
); |
$checkStock->update($dataUpdate); |
||||||
$checkStock->update($dataUpdate); |
return response()->json(['status'=>'success','message'=>'Assign tools success!','code'=>200]); |
||||||
return response()->json(['status'=>'success','message'=>'Assign tools success!','code'=>200]); |
}else{ |
||||||
}else{ |
return response()->json(['status'=>'failed','message'=>'Assign tools failed','code'=>400]); |
||||||
return response()->json(['status'=>'failed','message'=>'Assign tools failed','code'=>400]); |
} |
||||||
} |
} |
||||||
} |
|
||||||
|
private function updateFromAdd($data){ |
||||||
private function updateFromAdd($data){ |
$assignTools = AssignTools::where("activity_id", $data->activity_id)->where("tools_id", $data->tools_id)->first(); |
||||||
$assignTools = AssignTools::where("activity_id", $data->activity_id)->where("tools_id", $data->tools_id)->first(); |
|
||||||
|
$newQty = (int)$assignTools->qty_planning + (int)$data->qty_planning; |
||||||
$newQty = (int)$assignTools->qty_planning + (int)$data->qty_planning; |
$dataUpdate = array( |
||||||
$dataUpdate = array( |
"qty_planning"=>$newQty, |
||||||
"qty_planning"=>$newQty, |
"updated_by"=>$this->currentName |
||||||
"updated_by"=>$this->currentName |
); |
||||||
); |
|
||||||
|
$dataWillUpdate = AssignMaterial::where("activity_id", $data->activity_id)->where("tools_id", $data->tools_id); |
||||||
$dataWillUpdate = AssignMaterial::where("activity_id", $data->activity_id)->where("tools_id", $data->tools_id); |
|
||||||
|
return $dataWillUpdate->update($dataUpdate); |
||||||
return $dataWillUpdate->update($dataUpdate); |
} |
||||||
} |
|
||||||
|
public function update(Request $request, $id){ |
||||||
public function update(Request $request, $id){ |
|
||||||
|
if(!$id || (int) $id < 0 || $id==""){ |
||||||
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); |
} |
||||||
} |
$data = AssignTools::find($id); |
||||||
$data = AssignTools::find($id); |
if($data){ |
||||||
if($data){ |
$result = $data->update($request->all()); |
||||||
$result = $data->update($request->all()); |
}else{ |
||||||
}else{ |
return response()->json(['status'=>'failed','message'=>'Data Assign tools not found!','code'=>400], 400); |
||||||
return response()->json(['status'=>'failed','message'=>'Data Assign tools not found!','code'=>400], 400); |
die(); |
||||||
die(); |
} |
||||||
} |
|
||||||
|
if($result){ |
||||||
if($result){ |
return response()->json(['status'=>'success','message'=>'Assign tools successfully updated!','code'=>200], 200); |
||||||
return response()->json(['status'=>'success','message'=>'Assign tools successfully updated!','code'=>200], 200); |
}else{ |
||||||
}else{ |
return response()->json(['status'=>'failed','message'=>'Assign tools failed updated!','code'=>400], 400); |
||||||
return response()->json(['status'=>'failed','message'=>'Assign tools failed updated!','code'=>400], 400); |
} |
||||||
} |
} |
||||||
} |
|
||||||
|
public function delete($id) |
||||||
public function delete($id) |
{ |
||||||
{ |
$data = AssignTools::find($id); |
||||||
$data = AssignTools::find($id); |
|
||||||
|
if($data){ |
||||||
if($data){ |
$id = $data->tools_id; |
||||||
$id = $data->tools_id; |
$stock = $data->qty_planning; |
||||||
$stock = $data->qty_planning; |
$toolsResource = ToolsResource::find($id); |
||||||
$toolsResource = ToolsResource::find($id); |
if($toolsResource){ |
||||||
if($toolsResource){ |
$oldStock = $toolsResource->qty; |
||||||
$oldStock = $toolsResource->qty; |
$newStock = $oldStock + $stock; |
||||||
$newStock = $oldStock + $stock; |
$dataUpdate = array( |
||||||
$dataUpdate = array( |
"qty"=>$newStock, |
||||||
"qty"=>$newStock, |
"updated_by"=>$this->currentName |
||||||
"updated_by"=>$this->currentName |
); |
||||||
); |
$toolsResource->update($dataUpdate); |
||||||
$toolsResource->update($dataUpdate); |
} |
||||||
} |
|
||||||
|
$delete = $data->delete(); |
||||||
$delete = $data->delete(); |
}else{ |
||||||
}else{ |
return response()->json(['status'=>'failed','message'=>'Data Assign tools not found!','code'=>400], 400); |
||||||
return response()->json(['status'=>'failed','message'=>'Data Assign tools not found!','code'=>400], 400); |
die(); |
||||||
die(); |
} |
||||||
} |
|
||||||
|
|
||||||
|
if($delete){ |
||||||
if($delete){ |
return response()->json(['status'=>'success','message'=>'Assign tools successfully deleted!','code'=>200], 200); |
||||||
return response()->json(['status'=>'success','message'=>'Assign tools successfully deleted!','code'=>200], 200); |
}else{ |
||||||
}else{ |
return response()->json(['status'=>'failed','message'=>'Assign tools failed deleted!','code'=>400], 400); |
||||||
return response()->json(['status'=>'failed','message'=>'Assign tools failed deleted!','code'=>400], 400); |
} |
||||||
} |
} |
||||||
} |
|
||||||
|
public function edit($id){ |
||||||
public function edit($id){ |
if(!$id || (int) $id < 0 || $id==""){ |
||||||
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); |
die(); |
||||||
die(); |
} |
||||||
} |
|
||||||
|
$result = AssignTools::find($id); |
||||||
$result = AssignTools::find($id); |
|
||||||
|
if($result){ |
||||||
if($result){ |
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
}else{ |
||||||
}else{ |
return response()->json(['status'=>'failed','message'=>'failed get data Assign tools, please try again later!','code'=>400], 400); |
||||||
return response()->json(['status'=>'failed','message'=>'failed get data Assign tools, please try again later!','code'=>400], 400); |
} |
||||||
} |
} |
||||||
} |
|
||||||
|
public function search(Request $request) |
||||||
public function search(Request $request) |
{ |
||||||
{ |
$payload = $request->all(); |
||||||
$payload = $request->all(); |
$dataBuilder = $this->setUpPayload($payload, 'assign_tools_to_activity'); |
||||||
$dataBuilder = $this->setUpPayload($payload, 'assign_tools_to_activity'); |
$builder = $dataBuilder['builder']; |
||||||
$builder = $dataBuilder['builder']; |
$countBuilder = $dataBuilder['count']; |
||||||
$countBuilder = $dataBuilder['count']; |
$dataGet = $builder->get(); |
||||||
$dataGet = $builder->get(); |
$totalRecord = $countBuilder->count(); |
||||||
$totalRecord = $countBuilder->count(); |
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
} |
||||||
} |
|
||||||
|
public function list() |
||||||
public function list() |
{ |
||||||
{ |
$data = AssignTools::all(); |
||||||
$data = AssignTools::all(); |
$countData = $data->count(); |
||||||
$countData = $data->count(); |
|
||||||
|
if($data){ |
||||||
if($data){ |
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
}else{ |
||||||
}else{ |
return response()->json(['status'=>'failed','message'=>'failed get Assign tools, please try again later!','code'=>400], 400); |
||||||
return response()->json(['status'=>'failed','message'=>'failed get Assign tools, please try again later!','code'=>400], 400); |
} |
||||||
} |
} |
||||||
} |
|
||||||
|
public function datatables(Request $request){ |
||||||
public function datatables(Request $request){ |
$id_activity = $request->query('idact'); |
||||||
$id_activity = $request->query('idact'); |
$data = AssignTools::select("assign_tools_to_activity.*","m.name as tools_name","m.uom as uom")->join("m_tools_resource as m", "m.id", "=", "assign_tools_to_activity.tools_id")->where('assign_tools_to_activity.activity_id', $id_activity)->get(); |
||||||
$data = AssignTools::select("assign_tools_to_activity.*","m.name as tools_name","m.uom as uom")->join("m_tools_resource as m", "m.id", "=", "assign_tools_to_activity.tools_id")->where('assign_tools_to_activity.activity_id', $id_activity)->get(); |
return Datatables::of($data) |
||||||
return Datatables::of($data) |
->addIndexColumn() |
||||||
->addIndexColumn() |
->addColumn('action', function($row){ |
||||||
->addColumn('action', function($row){ |
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-tools-delete"><i class="fa fa-trash"></i></a>'; |
||||||
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-tools-delete"><i class="fa fa-trash"></i></a>'; |
return $actionBtn; |
||||||
return $actionBtn; |
}) |
||||||
}) |
->rawColumns(['action'])->make(true); |
||||||
->rawColumns(['action'])->make(true); |
} |
||||||
} |
} |
||||||
} |
|
||||||
|
@ -1,140 +1,140 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
namespace App\Http\Controllers; |
namespace App\Http\Controllers; |
||||||
|
|
||||||
use Illuminate\Http\Request; |
use Illuminate\Http\Request; |
||||||
use App\Models\Holiday; |
use App\Models\Holiday; |
||||||
use Datatables; |
use Yajra\Datatables\Datatables; |
||||||
|
|
||||||
class HolidayController extends Controller |
class HolidayController extends Controller |
||||||
{ |
{ |
||||||
public function add(Request $request) |
public function add(Request $request) |
||||||
{ |
{ |
||||||
$this->validate($request, [ |
$this->validate($request, [ |
||||||
'proyek_id' => 'required', |
'proyek_id' => 'required', |
||||||
'version_gantt_id' => 'required', |
'version_gantt_id' => 'required', |
||||||
'date' => 'required' |
'date' => 'required' |
||||||
]); |
]); |
||||||
|
|
||||||
$data = $request->all(); |
$data = $request->all(); |
||||||
$duration = $request->duration; |
$duration = $request->duration; |
||||||
if(!$duration){ |
if(!$duration){ |
||||||
$data['duration'] = 1; |
$data['duration'] = 1; |
||||||
} |
} |
||||||
$data['created_by'] = $this->currentName; |
$data['created_by'] = $this->currentName; |
||||||
|
|
||||||
$result = Holiday::create($data); |
$result = Holiday::create($data); |
||||||
|
|
||||||
if($result){ |
if($result){ |
||||||
return response()->json(['status'=>'success','message'=>'add holiday successfully!','code'=>200], 200); |
return response()->json(['status'=>'success','message'=>'add holiday successfully!','code'=>200], 200); |
||||||
}else{ |
}else{ |
||||||
return response()->json(['status'=>'failed','message'=>'add holiday failed!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'add holiday failed!','code'=>400], 400); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
public function edit($id){ |
public function edit($id){ |
||||||
if(!$id || (int) $id < 0 || $id==""){ |
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); |
||||||
die(); |
die(); |
||||||
} |
} |
||||||
|
|
||||||
$result = Holiday::find($id); |
$result = Holiday::find($id); |
||||||
|
|
||||||
if($result){ |
if($result){ |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||||
}else{ |
}else{ |
||||||
return response()->json(['status'=>'failed','message'=>'failed get data holiday, please try again later!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'failed get data holiday, please try again later!','code'=>400], 400); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
public function update(Request $request, $id) |
public function update(Request $request, $id) |
||||||
{ |
{ |
||||||
if(!$id || (int) $id < 0 || $id==""){ |
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); |
||||||
} |
} |
||||||
|
|
||||||
$data = Holiday::find($id); |
$data = Holiday::find($id); |
||||||
|
|
||||||
if($data){ |
if($data){ |
||||||
$result = $data->update($request->all()); |
$result = $data->update($request->all()); |
||||||
}else{ |
}else{ |
||||||
return response()->json(['status'=>'failed','message'=>'data holiday not found!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'data holiday not found!','code'=>400], 400); |
||||||
die(); |
die(); |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
if($result){ |
if($result){ |
||||||
return response()->json(['status'=>'success','message'=>'data holiday successfully updated!','code'=>200], 200); |
return response()->json(['status'=>'success','message'=>'data holiday successfully updated!','code'=>200], 200); |
||||||
}else{ |
}else{ |
||||||
return response()->json(['status'=>'failed','message'=>'data holiday failed updated!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'data holiday failed updated!','code'=>400], 400); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
public function delete($id) |
public function delete($id) |
||||||
{ |
{ |
||||||
$data = Holiday::find($id); |
$data = Holiday::find($id); |
||||||
|
|
||||||
if($data){ |
if($data){ |
||||||
$deletedData = $data; |
$deletedData = $data; |
||||||
$delete = $data->delete(); |
$delete = $data->delete(); |
||||||
}else{ |
}else{ |
||||||
return response()->json(['status'=>'failed','message'=>'data holiday not found!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'data holiday not found!','code'=>400], 400); |
||||||
die(); |
die(); |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
if($delete){ |
if($delete){ |
||||||
return response()->json(['status'=>'success', 'data'=>$deletedData,'message'=>'data holiday successfully deleted!','code'=>200], 200); |
return response()->json(['status'=>'success', 'data'=>$deletedData,'message'=>'data holiday successfully deleted!','code'=>200], 200); |
||||||
}else{ |
}else{ |
||||||
return response()->json(['status'=>'failed','message'=>'data holiday failed deleted!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'data holiday failed deleted!','code'=>400], 400); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
public function search(Request $request) |
public function search(Request $request) |
||||||
{ |
{ |
||||||
$payload = $request->all(); |
$payload = $request->all(); |
||||||
$dataBuilder = $this->setUpPayload($payload, 'm_holidays'); |
$dataBuilder = $this->setUpPayload($payload, 'm_holidays'); |
||||||
$builder = $dataBuilder['builder']; |
$builder = $dataBuilder['builder']; |
||||||
$countBuilder = $dataBuilder['count']; |
$countBuilder = $dataBuilder['count']; |
||||||
$dataGet = $builder->get(); |
$dataGet = $builder->get(); |
||||||
$totalRecord = $countBuilder->count(); |
$totalRecord = $countBuilder->count(); |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
||||||
} |
} |
||||||
|
|
||||||
public function list() |
public function list() |
||||||
{ |
{ |
||||||
$data = Holiday::all(); |
$data = Holiday::all(); |
||||||
$countData = $data->count(); |
$countData = $data->count(); |
||||||
|
|
||||||
if($data){ |
if($data){ |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
||||||
}else{ |
}else{ |
||||||
return response()->json(['status'=>'failed','message'=>'failed get list holiday, please try again later!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'failed get list holiday, please try again later!','code'=>400], 400); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
public function datatables(Request $request){ |
public function datatables(Request $request){ |
||||||
$proyek_id = $request->query('proyek_id'); |
$proyek_id = $request->query('proyek_id'); |
||||||
$gantt_id = $request->query('gantt_id'); |
$gantt_id = $request->query('gantt_id'); |
||||||
|
|
||||||
$data = Holiday::where('proyek_id', $proyek_id)->where('version_gantt_id', $gantt_id)->get(); |
$data = Holiday::where('proyek_id', $proyek_id)->where('version_gantt_id', $gantt_id)->get(); |
||||||
|
|
||||||
return Datatables::of($data) |
return Datatables::of($data) |
||||||
->editColumn('date', function($row) { |
->editColumn('date', function($row) { |
||||||
$date = date_create($row->date); |
$date = date_create($row->date); |
||||||
$dateFormat = date_format($date,"d-m-Y"); |
$dateFormat = date_format($date,"d-m-Y"); |
||||||
return $dateFormat; |
return $dateFormat; |
||||||
}) |
}) |
||||||
->editColumn('duration', function($row) { |
->editColumn('duration', function($row) { |
||||||
$day = (int)$row->duration > 1 ? "days" : "day"; |
$day = (int)$row->duration > 1 ? "days" : "day"; |
||||||
return $row->duration." ".$day; |
return $row->duration." ".$day; |
||||||
}) |
}) |
||||||
->addIndexColumn() |
->addIndexColumn() |
||||||
->addColumn('action', function($row){ |
->addColumn('action', function($row){ |
||||||
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-holiday-delete"><i class="fa fa-trash"></i></a>'; |
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-holiday-delete"><i class="fa fa-trash"></i></a>'; |
||||||
return $actionBtn; |
return $actionBtn; |
||||||
}) |
}) |
||||||
|
|
||||||
->rawColumns(['action'])->make(true); |
->rawColumns(['action'])->make(true); |
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue