diff --git a/app/Http/Controllers/.ReportActivityMaterialController.php.swp b/app/Http/Controllers/.ReportActivityMaterialController.php.swp new file mode 100644 index 0000000..6c4666e Binary files /dev/null and b/app/Http/Controllers/.ReportActivityMaterialController.php.swp differ diff --git a/app/Http/Controllers/AssignMaterialController.php b/app/Http/Controllers/AssignMaterialController.php index a3a7991..0122c01 100644 --- a/app/Http/Controllers/AssignMaterialController.php +++ b/app/Http/Controllers/AssignMaterialController.php @@ -10,6 +10,11 @@ use Datatables; class AssignMaterialController extends Controller { + private function sanitizeDecimal($number) { + $number = str_replace(".","",$number); + $number = str_replace(",",".",$number); + return $number; + } public function add(Request $request){ $this->validate($request, [ @@ -20,14 +25,14 @@ class AssignMaterialController extends Controller $checkStock = RequestMaterial::where("id", $request->material_id)->first(); $currentStock = $checkStock->qty; - $price = $checkStock->price; if((int)$currentStock < (int)$request->qty_planning){ return response()->json(['status'=>'failed','message'=>'Stock is not enough!','code'=> 500]); } $data = $request->all(); $data['created_by'] = $this->currentName; - $data['budget'] = $price; + $data['budget'] = $checkStock->price; + $data['qty_planning'] = $this->sanitizeDecimal($data['qty_planning']); $result = AssignMaterial::create($data); if(!$result) @@ -106,9 +111,6 @@ class AssignMaterialController extends Controller ->where('assign_material_to_activity.activity_id', $id_activity) ->orderBy('plan_date', 'desc') ->get(); - foreach($data as $d){ - $d->budget = str_replace(".", ",", $d->budget); - } return Datatables::of($data) ->addIndexColumn() ->addColumn('action', function($row){ diff --git a/app/Http/Controllers/ReportActivityMaterialController.php b/app/Http/Controllers/ReportActivityMaterialController.php index fe726a2..04ae220 100644 --- a/app/Http/Controllers/ReportActivityMaterialController.php +++ b/app/Http/Controllers/ReportActivityMaterialController.php @@ -9,7 +9,13 @@ use App\Models\AssignMaterial; use Datatables; class ReportActivityMaterialController extends Controller -{ +{ + private function sanitizeDecimal($number) { + $number = str_replace(".","",$number); + $number = str_replace(",",".",$number); + return $number; + } + public function add(Request $request){ $this->validate($request, [ @@ -20,6 +26,7 @@ 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['qty'] = $this->sanitizeDecimal($data['qty']); if(!ReportActivityMaterial::create($data)) return response()->json(['status'=>'failed','message'=>'Input progress report activity failed created','code'=>400]); diff --git a/app/Http/Controllers/RequestMaterialController.php b/app/Http/Controllers/RequestMaterialController.php index 2f4ee1a..3ef51db 100644 --- a/app/Http/Controllers/RequestMaterialController.php +++ b/app/Http/Controllers/RequestMaterialController.php @@ -8,6 +8,12 @@ use App\Models\MaterialResource; class RequestMaterialController extends Controller { + private function sanitizeDecimal($number) { + $number = str_replace(".","",$number); + $number = str_replace(",",".",$number); + return $number; + } + public function add(Request $request){ $this->validate($request, [ 'proyek_id' => 'required', @@ -19,8 +25,8 @@ class RequestMaterialController extends Controller ]); $data = $request->all(); - $data['price'] = str_replace(",", ".", $data['price']); - $data['qty'] = str_replace(",", ".", $data['qty']); + $data['price'] = $this->sanitizeDecimal($data['price']); + $data['qty'] = $this->sanitizeDecimal($data['qty']); $data['status'] = "fom"; $data['created_by'] = $this->currentName;