From e5e4f69d5d344718a8ec10ea28ca890587db27d5 Mon Sep 17 00:00:00 2001 From: satori Date: Wed, 27 Jul 2022 04:20:40 +0700 Subject: [PATCH] implement decimal --- .../.ReportActivityMaterialController.php.swp | Bin 0 -> 20480 bytes .../Controllers/AssignMaterialController.php | 12 +++++++----- .../ReportActivityMaterialController.php | 9 ++++++++- .../Controllers/RequestMaterialController.php | 10 ++++++++-- 4 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 app/Http/Controllers/.ReportActivityMaterialController.php.swp diff --git a/app/Http/Controllers/.ReportActivityMaterialController.php.swp b/app/Http/Controllers/.ReportActivityMaterialController.php.swp new file mode 100644 index 0000000000000000000000000000000000000000..6c4666e885359659e4ceafb411f69fd965acc9c4 GIT binary patch literal 20480 zcmeI4Ym6jS6@Uv6q(P9CL=yyZw`u7f(mgZFL)L+AoY@C#VA*AtUBumGsOhemsomhk8|%m_ndq0?9BM?EnCI<(RCKD(=6-H*Zy(l*-gh<{>_#Z2cau3zus%( zrkz(_yKQ^vqRGp5ZrY|&8u-XZWP)RhL3ki)*i|PQo3X109KSX;x$(Nvl=*Hq8e><) zabs*l;KyO$c}^IO?Qj}F7*AGXcfpO9w%V~1y0+Jr7;Vfq24`^AE^dX4Wt@KHIQl`)j+C&R0F97QVpaU zNHvgZAl1PCKm&HovUa`0vYr9C|DVMFuf5Z#8o`i?s2%HHr|Gz;KVwi$ooNQT-!B63na0HsL5!S#T zPO_}u!Vw5z8ZLk{;FXMJ{Tv>JkHRf*2u^_v90OlC(Xu`Zcf(z<01-^UV{a#4sKb76 zVG=4(hIhl0Cs@|Qa4*~gharFu!fEjI@s{;_2w^>345!26ET-H8H^5F<11G}?@DK|r zUx&}Zr{Qk63+{wZ!Od_LoC|B=B^GX8gulb1@ME|g>fpgPD8kur798Cx!|NPT4QkHl z=qP&2%m$%jSLa0`SF>Y#yJ!2tjzn(3_L|O!IE08hTUgt=S*p0vrg|e@DvXRAl8Vp8 z^~QE5tU7*d&pGQvS?t+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0_HLx56Pf2#fGxxDL*S2Z{9` zfNS7t*b481EUbmsi21(G`O(q?g^1X14EfQ}C@;xh0*Ragn~$0Dmn#@ zN&2`@dd7uwFXDaDG&$uu{uVkDh$I?2_;;rh8 WOS#fI(6-#UJbkXjY`~3J)_(!rbhiKi literal 0 HcmV?d00001 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;