Browse Source

Merge pull request 'dev-wahyu' (#196) from dev-wahyu into staging

Reviewed-on: ordo/adw-backend#196
pull/3/head
ibnu 1 year ago
parent
commit
2486af7c00
  1. 4
      app/Http/Controllers/ActivityController.php
  2. 304
      app/Http/Controllers/ReportActivityMaterialController.php

4
app/Http/Controllers/ActivityController.php

@ -431,10 +431,10 @@ class ActivityController extends Controller
$duration = MasterFunctionsHelper::countDays($ganttId, $plannedStart, $plannedEnd); $duration = MasterFunctionsHelper::countDays($ganttId, $plannedStart, $plannedEnd);
if ($today >= $endDate) { if ($today >= $endDate) {
$endDate = $today; $endDate = $today;
$rerataBobot = $activity->bobot_planning / $duration; $rerataBobot = $duration > 0 ? $activity->bobot_planning / $duration : 0;
$bobotActual = $activity->progress * $activity->bobot_planning; $bobotActual = $activity->progress * $activity->bobot_planning;
$sisaBobot = $activity->bobot_planning - $bobotActual; $sisaBobot = $activity->bobot_planning - $bobotActual;
$sisaHari = $sisaBobot / $rerataBobot; $sisaHari = $rerataBobot > 0 ? $sisaBobot / $rerataBobot : 0;
$endDate->modify("+".$sisaHari." Days"); $endDate->modify("+".$sisaHari." Days");
$actualDuration = MasterFunctionsHelper::countDays($ganttId, $startDate, $endDate); $actualDuration = MasterFunctionsHelper::countDays($ganttId, $startDate, $endDate);
$activity->duration = $actualDuration; $activity->duration = $actualDuration;

304
app/Http/Controllers/ReportActivityMaterialController.php

@ -1,152 +1,152 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\ReportActivityMaterial; use App\Models\ReportActivityMaterial;
use App\Models\Activity; use App\Models\Activity;
use App\Models\AssignMaterial; use App\Models\AssignMaterial;
use Datatables; use Datatables;
class ReportActivityMaterialController extends Controller class ReportActivityMaterialController extends Controller
{ {
private function sanitizeDecimal($number) { private function sanitizeDecimal($number) {
$number = str_replace(".","",$number); $number = str_replace(".","",$number);
$number = str_replace(",",".",$number); $number = str_replace(",",".",$number);
return $number; return $number;
} }
public function add(Request $request){ public function add(Request $request){
$this->validate($request, [ $this->validate($request, [
'activity_id' => 'required', 'activity_id' => 'required',
'qty' => 'required' 'qty' => 'required'
]); ]);
$activity = Activity::where('id', $request->activity_id)->first(); $activity = Activity::where('id', $request->activity_id)->first();
$start_date = $activity->start_date; $start_date = $activity->start_date;
$start_date = substr($start_date, 0, 19); // remove the timezone offset $start_date = substr($start_date, 0, 19); // remove the timezone offset
$startDate = new \DateTime(date("Y-m-d", strtotime($start_date))); $startDate = new \DateTime(date("Y-m-d", strtotime($start_date)));
$reportDate = new \DateTime(date("Y-m-d", strtotime($request->report_date))); $reportDate = new \DateTime(date("Y-m-d", strtotime($request->report_date)));
$data = $request->all(); $data = $request->all();
$data['created_by'] = $this->currentName; $data['created_by'] = $this->currentName;
/* $data['assign_material_id'] = AssignMaterial::where('activity_id', $request->activity_id)->pluck('id')->first(); */ /* $data['assign_material_id'] = AssignMaterial::where('activity_id', $request->activity_id)->pluck('id')->first(); */
$data['assign_material_id'] = $request->assign_material_id; $data['assign_material_id'] = $request->assign_material_id;
$data['qty'] = $this->sanitizeDecimal($data['qty']); $data['qty'] = $this->sanitizeDecimal($data['qty']);
if($reportDate >= $startDate){ if($reportDate >= $startDate || isset($data['force']) && $data['force'] == "true"){
$created = ReportActivityMaterial::create($data); $created = ReportActivityMaterial::create($data);
return response()->json(['status'=>'success','message'=>'Input progress report activity created','code'=>200,'data'=>array('report_id'=>$created->id)]); return response()->json(['status'=>'success','message'=>'Input progress report activity created','code'=>200,'data'=>array('report_id'=>$created->id)]);
} else { } else {
return response()->json(['status'=>'failed','message'=>'Input progress report activity failed created','code'=>400,'data'=>null], 400); return response()->json(['status'=>'failed','message'=>'Report date is before early start, still wanna add data ?','code'=>400,'data'=>$data], 400);
} }
} }
public function updateStatusStartFinish(Request $request){ public function updateStatusStartFinish(Request $request){
$payloadUpdate = array( $payloadUpdate = array(
'start_activity' => $request->start_activity, 'start_activity' => $request->start_activity,
'finish_activity' => $request->finish_activity, 'finish_activity' => $request->finish_activity,
'status_activity' => $request->status_activity 'status_activity' => $request->status_activity
); );
$updateData = AssignMaterial::where('activity_id',$request->activity_id) $updateData = AssignMaterial::where('activity_id',$request->activity_id)
->update($payloadUpdate); ->update($payloadUpdate);
if($updateData){ if($updateData){
if($request->status_activity == 'done'){ if($request->status_activity == 'done'){
$dataUpdate = array( $dataUpdate = array(
"persentase_progress" => 100, "persentase_progress" => 100,
"updated_by" => $this->currentName "updated_by" => $this->currentName
); );
Activity::where('id', $request->activity_id)->update($dataUpdate); Activity::where('id', $request->activity_id)->update($dataUpdate);
} else { } else {
$sumAssignMaterial = AssignMaterial::where('activity_id', $request->activity_id)->sum('qty_planning'); $sumAssignMaterial = AssignMaterial::where('activity_id', $request->activity_id)->sum('qty_planning');
$sumReportActivityMaterial = ReportActivityMaterial::where('activity_id', $request->activity_id)->sum('qty'); $sumReportActivityMaterial = ReportActivityMaterial::where('activity_id', $request->activity_id)->sum('qty');
$dataUpdate = array( $dataUpdate = array(
"persentase_progress" => $sumReportActivityMaterial/$sumAssignMaterial*100, "persentase_progress" => $sumReportActivityMaterial/$sumAssignMaterial*100,
"updated_by" => $this->currentName "updated_by" => $this->currentName
); );
Activity::where('id', $request->activity_id)->update($dataUpdate); Activity::where('id', $request->activity_id)->update($dataUpdate);
} }
return response()->json(['status'=>'success','message'=>'Update data status successfully ', 'code'=>200]); return response()->json(['status'=>'success','message'=>'Update data status successfully ', 'code'=>200]);
} }
else{ else{
return response()->json(['status'=>'failed','message'=>'Update data status failed', 'code'=>400]); return response()->json(['status'=>'failed','message'=>'Update data status failed', 'code'=>400]);
} }
} }
public function delete($id) public function delete($id)
{ {
if(!ReportActivityMaterial::findOrFail($id)->delete()) if(!ReportActivityMaterial::findOrFail($id)->delete())
return response()->json(['status'=>'failed','message'=>'Failed to deleted the data!','code'=> 500], 500); 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); return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=>200], 200);
} }
public function search(Request $request) public function search(Request $request)
{ {
$payload = $request->all(); $payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'report_activity_material'); $dataBuilder = $this->setUpPayload($payload, 'report_activity_material');
$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 = ReportActivityMaterial::all(); $data = ReportActivityMaterial::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 Repport Activity material, please try again later!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'failed get Repport Activity material, 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');
$type = $request->query('type'); $type = $request->query('type');
$materialName = $request->query('materialName'); $materialName = $request->query('materialName');
if($type == 'plan'){ if($type == 'plan'){
$data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom") $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") ->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.activity_id', $id_activity)
->where('m.description', $materialName) ->where('m.description', $materialName)
->orderBy('assign_material_to_activity.id', 'asc') ->orderBy('assign_material_to_activity.id', 'asc')
->get(); ->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="info btn btn-info btn-sm btn-ram-image" data-toggle="tooltip" title="Lihat Foto Report" data-placement="top"><i class="fa fa-image"></i></a>'; $actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="info btn btn-info btn-sm btn-ram-image" data-toggle="tooltip" title="Lihat Foto Report" data-placement="top"><i class="fa fa-image"></i></a>';
if ($row->status_activity != 'done') { if ($row->status_activity != 'done') {
$actionBtn .= '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-ram-delete" data-toggle="tooltip" title="Hapus Report" data-placement="top"><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-ram-delete" data-toggle="tooltip" title="Hapus Report" data-placement="top"><i class="fa fa-trash"></i></a>';
} }
return $actionBtn; return $actionBtn;
}) })
->rawColumns(['action'])->make(true); ->rawColumns(['action'])->make(true);
}else{ }else{
$data = ReportActivityMaterial::select("report_activity_material.*", "u.name as human_resource", "amta.status_activity") $data = ReportActivityMaterial::select("report_activity_material.*", "u.name as human_resource", "amta.status_activity")
->join("assign_material_to_activity as amta", "amta.id", "=", "report_activity_material.assign_material_id") ->join("assign_material_to_activity as amta", "amta.id", "=", "report_activity_material.assign_material_id")
->join("m_req_material as m", "m.id", "=", "amta.material_id") ->join("m_req_material as m", "m.id", "=", "amta.material_id")
->join("m_users as u", "u.id", "=", "report_activity_material.user_id") ->join("m_users as u", "u.id", "=", "report_activity_material.user_id")
->where('report_activity_material.activity_id', $id_activity) ->where('report_activity_material.activity_id', $id_activity)
->where('m.description', $materialName) ->where('m.description', $materialName)
->orderBy('report_activity_material.report_date', 'asc') ->orderBy('report_activity_material.report_date', 'asc')
->get(); ->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="info btn btn-info btn-sm btn-ram-image" data-toggle="tooltip" title="Lihat Foto Report" data-placement="top"><i class="fa fa-image"></i></a>'; $actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="info btn btn-info btn-sm btn-ram-image" data-toggle="tooltip" title="Lihat Foto Report" data-placement="top"><i class="fa fa-image"></i></a>';
if ($row->status_activity != 'done') { if ($row->status_activity != 'done') {
$actionBtn .= '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-ram-delete" data-toggle="tooltip" title="Hapus Report" data-placement="top"><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-ram-delete" data-toggle="tooltip" title="Hapus Report" data-placement="top"><i class="fa fa-trash"></i></a>';
} }
return $actionBtn; return $actionBtn;
}) })
->rawColumns(['action'])->make(true); ->rawColumns(['action'])->make(true);
} }
} }
} }

Loading…
Cancel
Save