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