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