@ -137,21 +144,26 @@ class AssignMaterialController extends Controller
->rawColumns(['action'])->make(true);
}
public function datatablesForReportActivity(Request $request){
public function datatablesForReportActivity(Request $request)
{
$id_activity = $request->query('idact');
$data =
AssignMaterial::select(
$query = 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('SUM(ram.qty) as qty_sum'),
"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("report_activity_material as ram", "ram.assign_material_id", "=", "assign_material_to_activity.id")
->groupBy("m.description")
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_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()) {
$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");