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. 7
      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
{
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){

7
app/Http/Controllers/ReportActivityMaterialController.php

@ -10,6 +10,12 @@ 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]);

10
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;

Loading…
Cancel
Save