From 459abbce15e3dc94f9e6411cc96a738fbe8e5b8e Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 3 Apr 2023 11:45:37 +0700 Subject: [PATCH] Task #860q0ukhh fix bug --- app/Http/Controllers/Controller.php | 8 +++++++- app/Http/Controllers/UserToActivityController.php | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 31cc056..a02d0d1 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -3,6 +3,9 @@ namespace App\Http\Controllers; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Http; +use App\Models\UserToActivity; +use App\Models\Activity; +use App\Models\AssignMaterial; use Laravel\Lumen\Routing\Controller as BaseController; use App\Models\ReportK3Detail; @@ -250,7 +253,10 @@ class Controller extends BaseController private function calculateMaterialCost($activity_id, $proyek_id) { - $totalCost = AssignMaterial::selectRaw("ISNULL(qty_planning,0)*ISNULL(budget,0) as totalCost")->where("proyek_id", $proyek_id)->where("activity_id", $activity_id)->sum("totalCost"); + $totalCost = AssignMaterial::selectRaw("COALESCE(qty_planning,0)*COALESCE(budget,0) as totalCost") + ->where("proyek_id", $proyek_id) + ->where("activity_id", $activity_id) + ->sum(AssignMaterial::raw("COALESCE(qty_planning, 0) * COALESCE(budget, 0)")); return $totalCost; } diff --git a/app/Http/Controllers/UserToActivityController.php b/app/Http/Controllers/UserToActivityController.php index 8cf9ad6..168af3d 100644 --- a/app/Http/Controllers/UserToActivityController.php +++ b/app/Http/Controllers/UserToActivityController.php @@ -72,6 +72,17 @@ class UserToActivityController extends Controller } + private function updatedCostPlanning($parent_id) { + $sumBiaya = Activity::selectRaw('sum(cast(rencana_biaya as double precision))') + ->where("parent_id", $parent_id) + ->first(); + if($parent = Activity::find($parent_id)){ + $parent->update([ + "rencana_biaya" => $sumBiaya->sum, + ]); + } + } + public function update(Request $request, $id){ if(empty($id) || !is_int((int)$id)) return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);