Browse Source

implement decimal

pull/3/head
satori 2 years ago
parent
commit
e5e4f69d5d
  1. BIN
      app/Http/Controllers/.ReportActivityMaterialController.php.swp
  2. 12
      app/Http/Controllers/AssignMaterialController.php
  3. 9
      app/Http/Controllers/ReportActivityMaterialController.php
  4. 10
      app/Http/Controllers/RequestMaterialController.php

BIN
app/Http/Controllers/.ReportActivityMaterialController.php.swp

Binary file not shown.

12
app/Http/Controllers/AssignMaterialController.php

@ -10,6 +10,11 @@ use Datatables;
class AssignMaterialController extends Controller class AssignMaterialController extends Controller
{ {
private function sanitizeDecimal($number) {
$number = str_replace(".","",$number);
$number = str_replace(",",".",$number);
return $number;
}
public function add(Request $request){ public function add(Request $request){
$this->validate($request, [ $this->validate($request, [
@ -20,14 +25,14 @@ class AssignMaterialController extends Controller
$checkStock = RequestMaterial::where("id", $request->material_id)->first(); $checkStock = RequestMaterial::where("id", $request->material_id)->first();
$currentStock = $checkStock->qty; $currentStock = $checkStock->qty;
$price = $checkStock->price;
if((int)$currentStock < (int)$request->qty_planning){ if((int)$currentStock < (int)$request->qty_planning){
return response()->json(['status'=>'failed','message'=>'Stock is not enough!','code'=> 500]); return response()->json(['status'=>'failed','message'=>'Stock is not enough!','code'=> 500]);
} }
$data = $request->all(); $data = $request->all();
$data['created_by'] = $this->currentName; $data['created_by'] = $this->currentName;
$data['budget'] = $price; $data['budget'] = $checkStock->price;
$data['qty_planning'] = $this->sanitizeDecimal($data['qty_planning']);
$result = AssignMaterial::create($data); $result = AssignMaterial::create($data);
if(!$result) if(!$result)
@ -106,9 +111,6 @@ class AssignMaterialController extends Controller
->where('assign_material_to_activity.activity_id', $id_activity) ->where('assign_material_to_activity.activity_id', $id_activity)
->orderBy('plan_date', 'desc') ->orderBy('plan_date', 'desc')
->get(); ->get();
foreach($data as $d){
$d->budget = str_replace(".", ",", $d->budget);
}
return Datatables::of($data) return Datatables::of($data)
->addIndexColumn() ->addIndexColumn()
->addColumn('action', function($row){ ->addColumn('action', function($row){

9
app/Http/Controllers/ReportActivityMaterialController.php

@ -9,7 +9,13 @@ use App\Models\AssignMaterial;
use Datatables; use Datatables;
class ReportActivityMaterialController extends Controller class ReportActivityMaterialController extends Controller
{ {
private function sanitizeDecimal($number) {
$number = str_replace(".","",$number);
$number = str_replace(",",".",$number);
return $number;
}
public function add(Request $request){ public function add(Request $request){
$this->validate($request, [ $this->validate($request, [
@ -20,6 +26,7 @@ class ReportActivityMaterialController extends Controller
$data = $request->all(); $data = $request->all();
$data['created_by'] = $this->currentName; $data['created_by'] = $this->currentName;
$data['assign_material_id'] = AssignMaterial::where('activity_id', $request->activity_id)->pluck('id')->first(); $data['assign_material_id'] = AssignMaterial::where('activity_id', $request->activity_id)->pluck('id')->first();
$data['qty'] = $this->sanitizeDecimal($data['qty']);
if(!ReportActivityMaterial::create($data)) if(!ReportActivityMaterial::create($data))
return response()->json(['status'=>'failed','message'=>'Input progress report activity failed created','code'=>400]); return response()->json(['status'=>'failed','message'=>'Input progress report activity failed created','code'=>400]);

10
app/Http/Controllers/RequestMaterialController.php

@ -8,6 +8,12 @@ use App\Models\MaterialResource;
class RequestMaterialController extends Controller class RequestMaterialController extends Controller
{ {
private function sanitizeDecimal($number) {
$number = str_replace(".","",$number);
$number = str_replace(",",".",$number);
return $number;
}
public function add(Request $request){ public function add(Request $request){
$this->validate($request, [ $this->validate($request, [
'proyek_id' => 'required', 'proyek_id' => 'required',
@ -19,8 +25,8 @@ class RequestMaterialController extends Controller
]); ]);
$data = $request->all(); $data = $request->all();
$data['price'] = str_replace(",", ".", $data['price']); $data['price'] = $this->sanitizeDecimal($data['price']);
$data['qty'] = str_replace(",", ".", $data['qty']); $data['qty'] = $this->sanitizeDecimal($data['qty']);
$data['status'] = "fom"; $data['status'] = "fom";
$data['created_by'] = $this->currentName; $data['created_by'] = $this->currentName;

Loading…
Cancel
Save