Browse Source

Merge pull request 'update filter datatables' (#38) from Dev-Farhan into staging

Reviewed-on: ibnu/generic-ospro-backend#38
pull/1/head
farhantock 11 months ago
parent
commit
d46ed84025
  1. 43
      app/Http/Controllers/AssignMaterialController.php

43
app/Http/Controllers/AssignMaterialController.php

@ -12,13 +12,15 @@ use Datatables;
class AssignMaterialController extends Controller class AssignMaterialController 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',
'material_id' => 'required', 'material_id' => 'required',
@ -51,7 +53,8 @@ class AssignMaterialController extends Controller
} }
} }
public function update(Request $request, $id){ public function update(Request $request, $id)
{
if (empty($id) || !is_int((int)$id)) if (empty($id) || !is_int((int)$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);
@ -83,7 +86,8 @@ class AssignMaterialController extends Controller
return response()->json(['status' => 'failed', 'message' => 'Failed to delete!', 'code' => 500], 500); return response()->json(['status' => 'failed', 'message' => 'Failed to delete!', 'code' => 500], 500);
} }
public function edit($id){ public function edit($id)
{
if (empty($id) || !is_int((int)$id)) if (empty($id) || !is_int((int)$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);
@ -117,11 +121,14 @@ class AssignMaterialController extends Controller
return response()->json(['status' => 'failed', 'message' => 'Failed to get the data!', 'code' => 500], 500); return response()->json(['status' => 'failed', 'message' => 'Failed to get the data!', 'code' => 500], 500);
} }
public function datatables(Request $request){ public function datatables(Request $request)
{
$id_activity = $request->query('idact'); $id_activity = $request->query('idact');
$type = $request->query('type') ?? "material"; $type = $request->query('type') ?? "material";
$data = AssignMaterial::select( $data = AssignMaterial::select(
"assign_material_to_activity.*","m.description as material_name", "m.uom as uom" "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)
@ -137,21 +144,26 @@ class AssignMaterialController extends Controller
->rawColumns(['action'])->make(true); ->rawColumns(['action'])->make(true);
} }
public function datatablesForReportActivity(Request $request){ public function datatablesForReportActivity(Request $request)
{
$id_activity = $request->query('idact'); $id_activity = $request->query('idact');
$data = $query = AssignMaterial::select(
AssignMaterial::select(
DB::raw('(SELECT SUM(assign_material_to_activity.qty_planning) FROM assign_material_to_activity WHERE assign_material_to_activity.activity_id = ram.activity_id) as qty_planning'), DB::raw('(SELECT SUM(assign_material_to_activity.qty_planning) FROM assign_material_to_activity WHERE assign_material_to_activity.activity_id = ram.activity_id) as qty_planning'),
DB::raw('SUM(ram.qty) as qty_sum'), DB::raw('SUM(ram.qty) as qty_sum'),
"m.description as material_name", "m.description as material_name",
"assign_material_to_activity.activity_id", "assign_material_to_activity.activity_id"
) )
->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");
->join("report_activity_material as ram", "ram.assign_material_id", "=", "assign_material_to_activity.id") if (!AssignMaterial::join("report_activity_material as ram", "ram.assign_material_id", "=", "assign_material_to_activity.id")->where("assign_material_to_activity.activity_id", $id_activity)->exists()) {
->groupBy("m.description") $query->leftJoin("report_activity_material as ram", "ram.assign_material_id", "=", "assign_material_to_activity.id");
} else {
$query->join("report_activity_material as ram", "ram.assign_material_id", "=", "assign_material_to_activity.id");
}
$data = $query->groupBy("m.description")
->groupBy("ram.activity_id") ->groupBy("ram.activity_id")
->groupBy("assign_material_to_activity.activity_id") ->groupBy("assign_material_to_activity.activity_id")
->where("assign_material_to_activity.activity_id", $id_activity)->get(); ->where("assign_material_to_activity.activity_id", $id_activity)
->get();
return Datatables::of($data) return Datatables::of($data)
->addIndexColumn() ->addIndexColumn()
// ->addColumn('qty_planning', function($row){ // ->addColumn('qty_planning', function($row){
@ -205,7 +217,8 @@ class AssignMaterialController extends Controller
->rawColumns(['action'])->make(true); ->rawColumns(['action'])->make(true);
} }
public function ForReportActivityByMaterial(Request $request){ public function ForReportActivityByMaterial(Request $request)
{
$id_activity = $request->idact; $id_activity = $request->idact;
$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")

Loading…
Cancel
Save