diff --git a/app/Http/Controllers/AssignMaterialController.php b/app/Http/Controllers/AssignMaterialController.php
index e385a95..7a5e9d8 100644
--- a/app/Http/Controllers/AssignMaterialController.php
+++ b/app/Http/Controllers/AssignMaterialController.php
@@ -8,7 +8,7 @@ use App\Models\RequestMaterial;
use App\Models\Activity;
use App\Models\ReportActivityMaterial;
use Illuminate\Support\Facades\DB;
-use Datatables;
+use Yajra\Datatables\Datatables;
class AssignMaterialController extends Controller
{
@@ -47,7 +47,11 @@ class AssignMaterialController extends Controller
if ($planDate >= $startDate) {
$result = AssignMaterial::create($data);
- return response()->json(['status' => 'success', 'message' => 'Data added!', 'code' => 200], 200);
+ 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);
}
diff --git a/app/Http/Controllers/AssignToolsController.php b/app/Http/Controllers/AssignToolsController.php
index 4e2b2c6..4185991 100644
--- a/app/Http/Controllers/AssignToolsController.php
+++ b/app/Http/Controllers/AssignToolsController.php
@@ -1,160 +1,159 @@
-validate($request, [
- 'activity_id' => 'required',
- 'tools_id' => 'required',
- 'qty_planning' => 'required',
- ]);
-
- $checkStock = ToolsResource::where("id", $request->tools_id)->first();
- $currentStock = $checkStock->qty;
- if((int)$currentStock < (int)$request->qty_planning){
- return response()->json(['status'=>'failed','message'=>'Not enough stock in warehouse!','code'=>400]);
- die();
- }
-
-
- $data = $request->all();
-
- $data['created_by'] = $this->currentName;
-
- $result = AssignTools::create($data);
- if($result){
- $checkStock = ToolsResource::find($request->tools_id);
- $newStock = (int)$checkStock->qty - (int)$request->qty_planning;
- $dataUpdate = array(
- "qty"=>$newStock,
- "updated_by"=>$this->currentName
- );
- $checkStock->update($dataUpdate);
- return response()->json(['status'=>'success','message'=>'Assign tools success!','code'=>200]);
- }else{
- return response()->json(['status'=>'failed','message'=>'Assign tools failed','code'=>400]);
- }
- }
-
- private function updateFromAdd($data){
- $assignTools = AssignTools::where("activity_id", $data->activity_id)->where("tools_id", $data->tools_id)->first();
-
- $newQty = (int)$assignTools->qty_planning + (int)$data->qty_planning;
- $dataUpdate = array(
- "qty_planning"=>$newQty,
- "updated_by"=>$this->currentName
- );
-
- $dataWillUpdate = AssignMaterial::where("activity_id", $data->activity_id)->where("tools_id", $data->tools_id);
-
- return $dataWillUpdate->update($dataUpdate);
- }
-
- 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 = AssignTools::find($id);
- if($data){
- $result = $data->update($request->all());
- }else{
- return response()->json(['status'=>'failed','message'=>'Data Assign tools not found!','code'=>400], 400);
- die();
- }
-
- if($result){
- return response()->json(['status'=>'success','message'=>'Assign tools successfully updated!','code'=>200], 200);
- }else{
- return response()->json(['status'=>'failed','message'=>'Assign tools failed updated!','code'=>400], 400);
- }
- }
-
- public function delete($id)
- {
- $data = AssignTools::find($id);
-
- if($data){
- $id = $data->tools_id;
- $stock = $data->qty_planning;
- $toolsResource = ToolsResource::find($id);
- if($toolsResource){
- $oldStock = $toolsResource->qty;
- $newStock = $oldStock + $stock;
- $dataUpdate = array(
- "qty"=>$newStock,
- "updated_by"=>$this->currentName
- );
- $toolsResource->update($dataUpdate);
- }
-
- $delete = $data->delete();
- }else{
- return response()->json(['status'=>'failed','message'=>'Data Assign tools not found!','code'=>400], 400);
- die();
- }
-
-
- if($delete){
- return response()->json(['status'=>'success','message'=>'Assign tools successfully deleted!','code'=>200], 200);
- }else{
- return response()->json(['status'=>'failed','message'=>'Assign tools 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 = AssignTools::find($id);
-
- if($result){
- return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
- }else{
- return response()->json(['status'=>'failed','message'=>'failed get data Assign tools, please try again later!','code'=>400], 400);
- }
- }
-
- public function search(Request $request)
- {
- $payload = $request->all();
- $dataBuilder = $this->setUpPayload($payload, 'assign_tools_to_activity');
- $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 = AssignTools::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 Assign tools, please try again later!','code'=>400], 400);
- }
- }
-
- public function datatables(Request $request){
- $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();
- return Datatables::of($data)
- ->addIndexColumn()
- ->addColumn('action', function($row){
- $actionBtn = '';
- return $actionBtn;
- })
- ->rawColumns(['action'])->make(true);
- }
-}
+validate($request, [
+ 'activity_id' => 'required',
+ 'tools_id' => 'required',
+ 'qty_planning' => 'required',
+ ]);
+
+ $checkStock = ToolsResource::where("id", $request->tools_id)->first();
+ $currentStock = $checkStock->qty;
+ if((int)$currentStock < (int)$request->qty_planning){
+ return response()->json(['status'=>'failed','message'=>'Not enough stock in warehouse!','code'=>400]);
+ die();
+ }
+
+
+ $data = $request->all();
+
+ $data['created_by'] = $this->currentName;
+
+ $result = AssignTools::create($data);
+ if($result){
+ $checkStock = ToolsResource::find($request->tools_id);
+ $newStock = (int)$checkStock->qty - (int)$request->qty_planning;
+ $dataUpdate = array(
+ "qty"=>$newStock,
+ "updated_by"=>$this->currentName
+ );
+ $checkStock->update($dataUpdate);
+ return response()->json(['status'=>'success','message'=>'Assign tools success!','code'=>200]);
+ }else{
+ return response()->json(['status'=>'failed','message'=>'Assign tools failed','code'=>400]);
+ }
+ }
+
+ private function updateFromAdd($data){
+ $assignTools = AssignTools::where("activity_id", $data->activity_id)->where("tools_id", $data->tools_id)->first();
+
+ $newQty = (int)$assignTools->qty_planning + (int)$data->qty_planning;
+ $dataUpdate = array(
+ "qty_planning"=>$newQty,
+ "updated_by"=>$this->currentName
+ );
+
+ $dataWillUpdate = AssignMaterial::where("activity_id", $data->activity_id)->where("tools_id", $data->tools_id);
+
+ return $dataWillUpdate->update($dataUpdate);
+ }
+
+ 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 = AssignTools::find($id);
+ if($data){
+ $result = $data->update($request->all());
+ }else{
+ return response()->json(['status'=>'failed','message'=>'Data Assign tools not found!','code'=>400], 400);
+ die();
+ }
+
+ if($result){
+ return response()->json(['status'=>'success','message'=>'Assign tools successfully updated!','code'=>200], 200);
+ }else{
+ return response()->json(['status'=>'failed','message'=>'Assign tools failed updated!','code'=>400], 400);
+ }
+ }
+
+ public function delete($id)
+ {
+ $data = AssignTools::find($id);
+
+ if($data){
+ $id = $data->tools_id;
+ $stock = $data->qty_planning;
+ $toolsResource = ToolsResource::find($id);
+ if($toolsResource){
+ $oldStock = $toolsResource->qty;
+ $newStock = $oldStock + $stock;
+ $dataUpdate = array(
+ "qty"=>$newStock,
+ "updated_by"=>$this->currentName
+ );
+ $toolsResource->update($dataUpdate);
+ }
+
+ $delete = $data->delete();
+ }else{
+ return response()->json(['status'=>'failed','message'=>'Data Assign tools not found!','code'=>400], 400);
+ die();
+ }
+
+
+ if($delete){
+ return response()->json(['status'=>'success','message'=>'Assign tools successfully deleted!','code'=>200], 200);
+ }else{
+ return response()->json(['status'=>'failed','message'=>'Assign tools 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 = AssignTools::find($id);
+
+ if($result){
+ return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
+ }else{
+ return response()->json(['status'=>'failed','message'=>'failed get data Assign tools, please try again later!','code'=>400], 400);
+ }
+ }
+
+ public function search(Request $request)
+ {
+ $payload = $request->all();
+ $dataBuilder = $this->setUpPayload($payload, 'assign_tools_to_activity');
+ $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 = AssignTools::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 Assign tools, please try again later!','code'=>400], 400);
+ }
+ }
+
+ public function datatables(Request $request){
+ $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();
+ return Datatables::of($data)
+ ->addIndexColumn()
+ ->addColumn('action', function($row){
+ $actionBtn = '';
+ return $actionBtn;
+ })
+ ->rawColumns(['action'])->make(true);
+ }
+}
diff --git a/app/Http/Controllers/HolidayController.php b/app/Http/Controllers/HolidayController.php
index c64fee8..000a925 100644
--- a/app/Http/Controllers/HolidayController.php
+++ b/app/Http/Controllers/HolidayController.php
@@ -1,140 +1,140 @@
-validate($request, [
- 'proyek_id' => 'required',
- 'version_gantt_id' => 'required',
- 'date' => 'required'
- ]);
-
- $data = $request->all();
- $duration = $request->duration;
- if(!$duration){
- $data['duration'] = 1;
- }
- $data['created_by'] = $this->currentName;
-
- $result = Holiday::create($data);
-
- if($result){
- return response()->json(['status'=>'success','message'=>'add holiday successfully!','code'=>200], 200);
- }else{
- return response()->json(['status'=>'failed','message'=>'add holiday 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 = Holiday::find($id);
-
- if($result){
- return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
- }else{
- return response()->json(['status'=>'failed','message'=>'failed get data holiday, 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 = Holiday::find($id);
-
- if($data){
- $result = $data->update($request->all());
- }else{
- return response()->json(['status'=>'failed','message'=>'data holiday not found!','code'=>400], 400);
- die();
- }
-
-
- if($result){
- return response()->json(['status'=>'success','message'=>'data holiday successfully updated!','code'=>200], 200);
- }else{
- return response()->json(['status'=>'failed','message'=>'data holiday failed updated!','code'=>400], 400);
- }
- }
-
- public function delete($id)
- {
- $data = Holiday::find($id);
-
- if($data){
- $deletedData = $data;
- $delete = $data->delete();
- }else{
- return response()->json(['status'=>'failed','message'=>'data holiday not found!','code'=>400], 400);
- die();
- }
-
-
- if($delete){
- return response()->json(['status'=>'success', 'data'=>$deletedData,'message'=>'data holiday successfully deleted!','code'=>200], 200);
- }else{
- return response()->json(['status'=>'failed','message'=>'data holiday failed deleted!','code'=>400], 400);
- }
- }
-
- public function search(Request $request)
- {
- $payload = $request->all();
- $dataBuilder = $this->setUpPayload($payload, 'm_holidays');
- $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 = Holiday::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 holiday, please try again later!','code'=>400], 400);
- }
- }
-
- public function datatables(Request $request){
- $proyek_id = $request->query('proyek_id');
- $gantt_id = $request->query('gantt_id');
-
- $data = Holiday::where('proyek_id', $proyek_id)->where('version_gantt_id', $gantt_id)->get();
-
- return Datatables::of($data)
- ->editColumn('date', function($row) {
- $date = date_create($row->date);
- $dateFormat = date_format($date,"d-m-Y");
- return $dateFormat;
- })
- ->editColumn('duration', function($row) {
- $day = (int)$row->duration > 1 ? "days" : "day";
- return $row->duration." ".$day;
- })
- ->addIndexColumn()
- ->addColumn('action', function($row){
- $actionBtn = '';
- return $actionBtn;
- })
-
- ->rawColumns(['action'])->make(true);
- }
-}
+validate($request, [
+ 'proyek_id' => 'required',
+ 'version_gantt_id' => 'required',
+ 'date' => 'required'
+ ]);
+
+ $data = $request->all();
+ $duration = $request->duration;
+ if(!$duration){
+ $data['duration'] = 1;
+ }
+ $data['created_by'] = $this->currentName;
+
+ $result = Holiday::create($data);
+
+ if($result){
+ return response()->json(['status'=>'success','message'=>'add holiday successfully!','code'=>200], 200);
+ }else{
+ return response()->json(['status'=>'failed','message'=>'add holiday 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 = Holiday::find($id);
+
+ if($result){
+ return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
+ }else{
+ return response()->json(['status'=>'failed','message'=>'failed get data holiday, 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 = Holiday::find($id);
+
+ if($data){
+ $result = $data->update($request->all());
+ }else{
+ return response()->json(['status'=>'failed','message'=>'data holiday not found!','code'=>400], 400);
+ die();
+ }
+
+
+ if($result){
+ return response()->json(['status'=>'success','message'=>'data holiday successfully updated!','code'=>200], 200);
+ }else{
+ return response()->json(['status'=>'failed','message'=>'data holiday failed updated!','code'=>400], 400);
+ }
+ }
+
+ public function delete($id)
+ {
+ $data = Holiday::find($id);
+
+ if($data){
+ $deletedData = $data;
+ $delete = $data->delete();
+ }else{
+ return response()->json(['status'=>'failed','message'=>'data holiday not found!','code'=>400], 400);
+ die();
+ }
+
+
+ if($delete){
+ return response()->json(['status'=>'success', 'data'=>$deletedData,'message'=>'data holiday successfully deleted!','code'=>200], 200);
+ }else{
+ return response()->json(['status'=>'failed','message'=>'data holiday failed deleted!','code'=>400], 400);
+ }
+ }
+
+ public function search(Request $request)
+ {
+ $payload = $request->all();
+ $dataBuilder = $this->setUpPayload($payload, 'm_holidays');
+ $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 = Holiday::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 holiday, please try again later!','code'=>400], 400);
+ }
+ }
+
+ public function datatables(Request $request){
+ $proyek_id = $request->query('proyek_id');
+ $gantt_id = $request->query('gantt_id');
+
+ $data = Holiday::where('proyek_id', $proyek_id)->where('version_gantt_id', $gantt_id)->get();
+
+ return Datatables::of($data)
+ ->editColumn('date', function($row) {
+ $date = date_create($row->date);
+ $dateFormat = date_format($date,"d-m-Y");
+ return $dateFormat;
+ })
+ ->editColumn('duration', function($row) {
+ $day = (int)$row->duration > 1 ? "days" : "day";
+ return $row->duration." ".$day;
+ })
+ ->addIndexColumn()
+ ->addColumn('action', function($row){
+ $actionBtn = '';
+ return $actionBtn;
+ })
+
+ ->rawColumns(['action'])->make(true);
+ }
+}
diff --git a/app/Http/Controllers/ReportActivityController.php b/app/Http/Controllers/ReportActivityController.php
index 94a8d89..4607f5c 100644
--- a/app/Http/Controllers/ReportActivityController.php
+++ b/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
{
diff --git a/app/Http/Controllers/ReportActivityMaterialController.php b/app/Http/Controllers/ReportActivityMaterialController.php
index a55e15f..62e08f3 100644
--- a/app/Http/Controllers/ReportActivityMaterialController.php
+++ b/app/Http/Controllers/ReportActivityMaterialController.php
@@ -8,7 +8,7 @@ use Illuminate\Support\Facades\DB;
use App\Models\ReportActivityMaterial;
use App\Models\Activity;
use App\Models\AssignMaterial;
-use Datatables;
+use Yajra\Datatables\Datatables;
use DateTime;
class ReportActivityMaterialController extends Controller
@@ -72,10 +72,10 @@ class ReportActivityMaterialController extends Controller
// actual < plan
$persentaseProgress = $sumReportActivityMaterial/$sumAssignMaterial*100;
}
-
+
$dataUpdate = array(
"actual_start" => null,
- "actual_end" => null,
+ "actual_end" => null,
"persentase_progress" => $persentaseProgress,
"updated_by" => $this->currentName
);
diff --git a/app/Http/Controllers/UserToActivityController.php b/app/Http/Controllers/UserToActivityController.php
index b6f9926..5313b5d 100644
--- a/app/Http/Controllers/UserToActivityController.php
+++ b/app/Http/Controllers/UserToActivityController.php
@@ -7,7 +7,7 @@ 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
{