SalesController.php изменения
public function getUnitSellingPrice(Request $request, $stock_id)
{
$stock = Stock::where('stock_id', $stock_id)->first();
if ($stock == null) {
return null;
}
return response()->json($stock->unit_selling_price);
}
create.blade.php изменения
<div class="form-group">
<label>Product Name</label>
<select name="product_name" class="form-control" id="stock_name">
<option>Select Product Name</option>
@foreach ($stocks as $stock)
<option value="{{ $stock->stock_id }}">{{ $stock->stock_name}}</option>
@endforeach
</select>
</div>
<div class="form-group">
{{Form::label('unit_selling_price', 'Unit Selling Price')}}
{{Form::text('unit_selling_price', '', ['class' => 'form-control', 'placeholder' => 'Unit Selling Price', 'id' => 'unit_selling_price'])}}
</div>
<div class="form-group">
{{Form::label('sale_quantity', 'Quantity')}}
{{Form::text('sale_quantity', '', ['class' => 'form-control', 'placeholder' => 'Quantity', 'id' => 'sales_quantity'])}}
</div>
<div class="form-group">
{{Form::label('total_sales_cost', 'Total Sales Cost')}}
{{Form::text('total_sales_cost', '', ['class' => 'form-control', 'placeholder' => 'Total Sales Cost', 'id' => 'total_sales_cost', 'readonly' => 'true', 'cursor: pointer' => 'true' ])}}
</div>
{{Form::submit('Submit', ['class' => 'btn btn-primary'])}}
{!! Form::close() !!}
<script>
$(document).ready(function () {
$("#stock_name").on('change', function () {
var stock_id = $(this).val();
$.ajax({
url: '/sales-price/getunitsellingprice/'+stock_id,
method: 'GET',
success: function (response) {
console.log(response);
$("#unit_selling_price").val(response);
},
});
});
});
</script>
<script>
$(document).ready(function () {
$("#total_sales_cost").click(function () {
var sales_quantity = $("#sales_quantity").val();
var unit_selling_price = $("#unit_selling_price").val();
var total_sales_cost = (sales_quantity * unit_selling_price);
$('#total_sales_cost').val(total_sales_cost);
});
});
</script>
изменения маршрута
Route::any('sales-price/getunitsellingprice/{stock_id}','SalesController@getUnitSellingPrice');