@ -2,7 +2,7 @@
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;
@ -11,209 +11,182 @@ use Datatables;
class ReportActivityMaterialController extends Controller
class ReportActivityMaterialController extends Controller
{
{
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'
]);
]);
$valAssignMaterialId = AssignMaterial::where('activity_id', $request->activity_id)->first();
$data = $request->all();
$data['created_by'] = $this->currentName;
$data = $request->all();
$data['assign_material_id'] = AssignMaterial::where('activity_id', $request->activity_id)->pluck('id')->first();
$data['created_by'] = $this->currentName;
$data['assign_material_id'] = $valAssignMaterialId->id;
if(!ReportActivityMaterial::create($data))
return response()->json(['status'=>'failed','message'=>'Input progress report activity failed created','code'=>400]);
$checkPrice = AssignMaterial::where("id", $valAssignMaterialId->id)->first();
$price = $checkPrice->budget;
$this->countForProgress($request->activity_id);
return response()->json(['status'=>'success','message'=>'Input progress report activity created','code'=>200]);
$updateActivity = Activity::find($request->activity_id);
}
if($updateActivity){
$costActualOld = $updateActivity->biaya_actual == null ? 0 : (int)$updateActivity->biaya_actual;
public function updateStatusStartFinish(Request $request){
$costActualNew = $costActualOld + ($price*$request->qty);
$updateActivity->biaya_actual = $costActualNew;
$payloadUpdate = array(
$updateActivity->save();
'start_activity' => $request->start_activity,
$result = ReportActivityMaterial::create($data);
'finish_activity' => $request->finish_activity,
if($result){
'status_activity' => $request->status_activity
$this->countForProgress($request->activity_id);
);
return response()->json(['status'=>'success','message'=>'Input progress report activity created','code'=>200]);
$updateData = AssignMaterial::where('activity_id',$request->activity_id)
}else{
->update($payloadUpdate);
return response()->json(['status'=>'failed','message'=>'Input progress report activity failed created','code'=>400]);
if($updateData){
}
if($request->status_activity == 'done'){
}else{
$dataUpdate = array(
return response()->json(['status'=>'success','message'=>'Update cost actual failed','code'=>400]);
"persentase_progress" => 100,
}
"updated_by" => $this->currentName
}
);
Activity::where('id', $request->activity_id)->update($dataUpdate);
public function updateStatusStartFinish(Request $request){
}
$payloadUpdate = array(
return response()->json(['status'=>'success','message'=>'Update data status successfully ', 'code'=>200]);
'start_activity' => $request->start_activity,
}
'finish_activity' => $request->finish_activity,
else{
'status_activity' => $request->status_activity
return response()->json(['status'=>'failed','message'=>'Update data status failed', 'code'=>400]);
);
}
$updateData = AssignMaterial::where('activity_id',$request->activity_id)
}
->update($payloadUpdate);
if($updateData){
public function delete($id)
if($request->status_activity == 'done'){
{
$dataUpdate = array(
if(!ReportActivityMaterial::findOrFail($id)->delete())
"persentase_progress" => 100,
return response()->json(['status'=>'failed','message'=>'Failed to deleted the data!','code'=> 500], 500);
"updated_by" => $this->currentName
);
return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=>200], 200);
Activity::where('id', $request->activity_id)->update($dataUpdate);
}
}
private function countForProgress($id)
return response()->json(['status'=>'success','message'=>'Update data status successfully ', 'code'=>200]);
{
}
else{
$dataActivity = Activity::find($id);
return response()->json(['status'=>'failed','message'=>'Update data status failed', 'code'=>400]);
$dataPlan = AssignMaterial::where('activity_id', $id)->get();
}
$tmpPercentage1 = [];
}
if(!$dataPlan->isEmpty()){
public function delete($id)
foreach ($dataPlan as $value) {
{
# code...
$data = ReportActivityMaterial::find($id);
$price = $value->material_id;
$qty_plan = $value->qty_planning;
if($data){
$status_activity = $value->status_activity;
$delete = $data->delete();
}else{
$getDataVolActual = ReportActivityMaterial::where('assign_material_id', '=', $value->id)->sum("qty");
return response()->json(['status'=>'failed','message'=>'data menu not found!','code'=>400], 400);
$percentage1 = ($getDataVolActual * 100) / $qty_plan;
die();
}
if($status_activity == 'done'){
$tmpPercentage1[] = $percentage1 > 100 ? 100 : $percentage1;
}else if($status_activity == 'on-progress'){
if($delete){
$tmpPercentage1[] = $percentage1 >= 100 ? 90 : $percentage1;
return response()->json(['status'=>'success','message'=>'data menu successfully deleted!','code'=>200], 200);
}else{
}else{
$tmpPercentage1[] = $percentage1 >= 100 ? 90 : $percentage1;
return response()->json(['status'=>'failed','message'=>'data menu failed deleted!','code'=>400], 400);
}
}
}
}
$totalPercentage = array_sum($tmpPercentage1) / count($tmpPercentage1);
}else{
private function countForProgress($id)
$totalPercentage = 0;
{
}
$dataActivity = Activity::find($id);
$dataPlan = AssignMaterial::where('activity_id', $id)->get();
$tmpPercentage1 = [];
if(!$dataPlan->isEmpty()){
$dataUpdate = array(
"persentase_progress" => $totalPercentage,
foreach ($dataPlan as $value) {
"updated_by" => $this->currentName
# code...
);
$price = $value->material_id;
return $dataActivity->update($dataUpdate);
$qty_plan = $value->qty_planning;
}
$status_activity = $value->status_activity;
public function countForProgressTest()
$getDataVolActual = ReportActivityMaterial::where('assign_material_id', '=', $value->id)->sum("qty");
{
$percentage1 = ($getDataVolActual * 100) / $qty_plan;
$dataPlan = AssignMaterial::where('activity_id', 807)->get();
$tmpPercentage1 = [];
if($status_activity == 'done'){
$tmpPercentage1[] = $percentage1 > 100 ? 100 : $percentage1;
if(!$dataPlan->isEmpty()){
}else if($status_activity == 'on-progress'){
foreach ($dataPlan as $value) {
$tmpPercentage1[] = $percentage1 >= 100 ? 90 : $percentage1;
# code...
}else{
$price = $value->material_id;
$tmpPercentage1[] = $percentage1 >= 100 ? 90 : $percentage1;
$qty_plan = $value->qty_planning;
}
$status_activity = $value->status_activity;
}
$totalPercentage = array_sum($tmpPercentage1) / count($tmpPercentage1);
$getDataVolActual = ReportActivityMaterial::where('assign_material_id', '=', $value->id)->sum("qty");
}else{
$percentage1 = ($getDataVolActual * 100) / $qty_plan;
$totalPercentage = 0;
$percentage1 = ($getDataVolActual * 100) / $qty_plan;
}
if($status_activity == 'done'){
$tmpPercentage1[] = $percentage1 > 100 ? 100 : $percentage1;
}else if($status_activity == 'on-progress'){
$tmpPercentage1[] = $percentage1 >= 100 ? 90 : $percentage1;
}else{
$dataUpdate = array(
$tmpPercentage1[] = $percentage1 >= 100 ? 90 : $percentage1;
"persentase_progress" => $totalPercentage,
}
"updated_by" => $this->currentName
);
return $dataActivity->update($dataUpdate);
}
}
$totalPercentage = array_sum($tmpPercentage1) / count($tmpPercentage1);
}else{
public function countForProgressTest()
$totalPercentage = 0;
{
}
$dataPlan = AssignMaterial::where('activity_id', 807)->get();
$tmpPercentage1 = [];
return response()->json(['status'=>'success','code'=>200,'data'=>$dataPlan, 'tmpPercentage1'=> $tmpPercentage1, 'totalPercentage'=> $totalPercentage], 200);
}
if(!$dataPlan->isEmpty()){
foreach ($dataPlan as $value) {
public function search(Request $request)
# code...
{
$price = $value->material_id;
$payload = $request->all();
$qty_plan = $value->qty_planning;
$dataBuilder = $this->setUpPayload($payload, 'report_activity_material');
$status_activity = $value->status_activity;
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$getDataVolActual = ReportActivityMaterial::where('assign_material_id', '=', $value->id)->sum("qty");
$dataGet = $builder->get();
$percentage1 = ($getDataVolActual * 100) / $qty_plan;
$totalRecord = $countBuilder->count();
$percentage1 = ($getDataVolActual * 100) / $qty_plan;
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
if($status_activity == 'done'){
}
$tmpPercentage1[] = $percentage1 > 100 ? 100 : $percentage1;
}else if($status_activity == 'on-progress'){
public function list()
$tmpPercentage1[] = $percentage1 >= 100 ? 90 : $percentage1;
{
}else{
$data = ReportActivityMaterial::all();
$tmpPercentage1[] = $percentage1 >= 100 ? 90 : $percentage1;
$countData = $data->count();
}
if($data){
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}
}else{
$totalPercentage = array_sum($tmpPercentage1) / count($tmpPercentage1);
return response()->json(['status'=>'failed','message'=>'failed get Repport Activity material, please try again later!','code'=>400], 400);
}else{
}
$totalPercentage = 0;
}
}
public function datatables(Request $request){
return response()->json(['status'=>'success','code'=>200,'data'=>$dataPlan, 'tmpPercentage1'=> $tmpPercentage1, 'totalPercentage'=> $totalPercentage], 200);
$id_activity = $request->query('idAct');
}
$id_assign_material_id= $request->query('idAmi');
$type = $request->query('type');
public function search(Request $request)
if($type == 'plan'){
{
$data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom")
$payload = $request->all();
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
$dataBuilder = $this->setUpPayload($payload, 'report_activity_material');
->where('assign_material_to_activity.activity_id', $id_activity)
$builder = $dataBuilder['builder'];
->orderBy('assign_material_to_activity.id', 'asc')
$countBuilder = $dataBuilder['count'];
->get();
$dataGet = $builder->get();
return Datatables::of($data)
$totalRecord = $countBuilder->count();
->addIndexColumn()
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
->addColumn('action', function($row){
}
$actionBtn = '< a href = "javascript:void(0)" data-id = "'.$row->id.'" class = "delete btn btn-danger btn-sm btn-ram-delete" > < i class = "fa fa-trash" > < / i > < / a > ';
return $actionBtn;
public function list()
})
{
->rawColumns(['action'])->make(true);
$data = ReportActivityMaterial::all();
}else{
$countData = $data->count();
$data = ReportActivityMaterial::select("report_activity_material.*", "u.name as human_resource")
->join("m_users as u", "u.id", "=", "report_activity_material.user_id")
if($data){
->where('report_activity_material.activity_id', $id_activity)
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
->orderBy('report_activity_material.report_date', 'asc')
}else{
->get();
return response()->json(['status'=>'failed','message'=>'failed get Repport Activity material, please try again later!','code'=>400], 400);
return Datatables::of($data)
}
->addIndexColumn()
}
->addColumn('action', function($row){
$actionBtn = '< a href = "javascript:void(0)" data-id = "'.$row->id.'" class = "delete btn btn-danger btn-sm btn-ram-delete" > < i class = "fa fa-trash" > < / i > < / a > ';
public function datatables(Request $request){
return $actionBtn;
$id_activity = $request->query('idAct');
})
$id_assign_material_id= $request->query('idAmi');
->rawColumns(['action'])->make(true);
$type = $request->query('type');
}
if($type == 'plan'){
}
$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")
->where('assign_material_to_activity.activity_id', $id_activity)
->orderBy('assign_material_to_activity.id', 'asc')
->get();
return Datatables::of($data)
->addIndexColumn()
->addColumn('action', function($row){
$actionBtn = '< a href = "javascript:void(0)" data-id = "'.$row->id.'" class = "delete btn btn-danger btn-sm btn-ram-delete" > < i class = "fa fa-trash" > < / i > < / a > ';
return $actionBtn;
})
->rawColumns(['action'])->make(true);
}else{
$data = ReportActivityMaterial::select("report_activity_material.*", "u.name as human_resource")
->join("m_users as u", "u.id", "=", "report_activity_material.user_id")
->where('report_activity_material.activity_id', $id_activity)
->orderBy('report_activity_material.report_date', 'asc')
->get();
return Datatables::of($data)
->addIndexColumn()
->addColumn('action', function($row){
$actionBtn = '< a href = "javascript:void(0)" data-id = "'.$row->id.'" class = "delete btn btn-danger btn-sm btn-ram-delete" > < i class = "fa fa-trash" > < / i > < / a > ';
return $actionBtn;
})
->rawColumns(['action'])->make(true);
}
}
}
}