Browse Source

new flow & bugfix old reporting problem

pull/3/head
Muhammad Sulaiman Yusuf 2 years ago
parent
commit
fc445ebe02
  1. 17
      app/Http/Controllers/AssignMaterialController.php
  2. 9
      app/Http/Controllers/ReportActivityMaterialController.php
  3. 13
      app/Models/Activity.php
  4. 2
      app/Models/AssignMaterial.php

17
app/Http/Controllers/AssignMaterialController.php

@ -104,11 +104,13 @@ class AssignMaterialController extends Controller
public function datatables(Request $request){
$id_activity = $request->query('idact');
$type = $request->query('type') ?? "material";
$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)
->where('assign_material_to_activity.type', $type)
->orderBy('plan_date', 'desc')
->get();
return Datatables::of($data)
@ -124,14 +126,15 @@ class AssignMaterialController extends Controller
$id_activity = $request->query('idact');
$data =
AssignMaterial::select(
AssignMaterial::raw(
'SUM(qty_planning) as qty_planning'),
AssignMaterial::raw('SUM(qty_planning) as qty_planning'),
"m.description as material_name",
"assign_material_to_activity.activity_id as activity_id"
"assign_material_to_activity.activity_id",
"assign_material_to_activity.type",
)
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->groupBy("m.description")
->groupBy("assign_material_to_activity.activity_id")
->groupBy("assign_material_to_activity.type")
->where("assign_material_to_activity.activity_id", $id_activity)->get();
return Datatables::of($data)
->addIndexColumn()
@ -171,8 +174,10 @@ class AssignMaterialController extends Controller
return $val_uom ? $val_uom->uom : null;
})
->addColumn('action', function($row){
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" data-material-name="'.$row->material_name.'" class="primary btn btn-primary btn-sm btn-lihat-plan" data-toggle="tooltip" title="Lihat Plan" data-placement="top"><i class="fa fa-align-justify"></i></a>';
$actionBtn .= '<a href="javascript:void(0)" data-id="'.$row->id.'" data-material-name="'.$row->material_name.'" class="warning btn btn-warning btn-sm btn-lihat-actual" data-toggle="tooltip" title="Input Progress" data-placement="top"><i class="fa fa-edit" aria-hidden="true"></i></a>';
$dataPlan = AssignMaterial::select('assign_material_to_activity.id')->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('activity_id', $row->activity_id)->where('m.description', $row->material_name)->first();
$actionBtn = '<a href="javascript:void(0)" data-id="'.$dataPlan->id.'" data-activity_id="'.$row->activity_id.'" data-material-name="'.$row->material_name.'" class="primary btn btn-primary btn-sm btn-lihat-plan" data-toggle="tooltip" title="Lihat Plan" data-placement="top"><i class="fa fa-align-justify"></i></a>';
$actionBtn .= '<a href="javascript:void(0)" data-id="'.$dataPlan->id.'" data-activity_id="'.$row->activity_id.'" data-material-name="'.$row->material_name.'" class="warning btn btn-warning btn-sm btn-lihat-actual" data-toggle="tooltip" title="Input Progress" data-placement="top"><i class="fa fa-edit" aria-hidden="true"></i></a>';
return $actionBtn;
})
->rawColumns(['action'])->make(true);
@ -184,8 +189,6 @@ class AssignMaterialController extends Controller
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('assign_material_to_activity.activity_id', $id_activity)->get();
foreach ($data as $key) {
# code...
$val_qty_sum = ReportActivityMaterial::where('assign_material_id', '=', $key->id)->sum("qty");
}
$countData = $data->count();

9
app/Http/Controllers/ReportActivityMaterialController.php

@ -25,7 +25,8 @@ class ReportActivityMaterialController extends Controller
$data = $request->all();
$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['qty'] = $this->sanitizeDecimal($data['qty']);
if(!ReportActivityMaterial::create($data))
@ -92,12 +93,13 @@ class ReportActivityMaterialController extends Controller
public function datatables(Request $request){
$id_activity = $request->query('idAct');
$id_assign_material_id= $request->query('idAmi');
$type = $request->query('type');
$materialName = $request->query('materialName');
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)
->where('m.description', $materialName)
->orderBy('assign_material_to_activity.id', 'asc')
->get();
return Datatables::of($data)
@ -109,8 +111,11 @@ class ReportActivityMaterialController extends Controller
->rawColumns(['action'])->make(true);
}else{
$data = ReportActivityMaterial::select("report_activity_material.*", "u.name as human_resource")
->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_users as u", "u.id", "=", "report_activity_material.user_id")
->where('report_activity_material.activity_id', $id_activity)
->where('m.description', $materialName)
->orderBy('report_activity_material.report_date', 'asc')
->get();
return Datatables::of($data)

13
app/Models/Activity.php

@ -28,7 +28,7 @@ class Activity extends Model
];
protected $appends = [
'jobs_done', 'assign_hr', 'assign_material', 'assign_tools'
'jobs_done', 'assign_hr', 'assign_material', 'assign_tools', 'assign_expense'
];
@ -153,6 +153,17 @@ class Activity extends Model
return Arr::flatten(AssignMaterial::select("m.description as name")
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('assign_material_to_activity.activity_id', $this->id)
->where('assign_material_to_activity.type', "material")
->get()
->toArray());
}
public function getAssignExpenseAttribute()
{
return Arr::flatten(AssignMaterial::select("m.description as name")
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('assign_material_to_activity.activity_id', $this->id)
->where('assign_material_to_activity.type', "expense")
->get()
->toArray());
}

2
app/Models/AssignMaterial.php

@ -15,7 +15,7 @@ class AssignMaterial extends Model
protected $fillable = [
'proyek_id', 'activity_id', 'material_id', 'qty_planning',
'budget', 'plan_date', 'status_activity',
'budget', 'plan_date', 'status_activity', 'type',
'created_at', 'created_by', 'updated_at', 'updated_by'
];

Loading…
Cancel
Save