+
@@ -117,12 +117,11 @@
numberInc = $('.product-card').length
$.ajax({
type: 'get',
- url: '{{ url('clone-sales-product') }}',
-
+ url: '{{ route('salesEntry.cloneSalesProduct') }}',
data: {
numberInc: numberInc
},
- success: function(response) {
+ success: function(response) {
$('.appendProductCard').append(response.view)
// $('#salesEntry-container').html(response.view).fadeIn()
},
@@ -143,6 +142,11 @@
recalculate();
})
+ function validateNumericInput(input) {
+ // Allow only numbers and remove any non-numeric input
+ input.value = input.value.replace(/[^0-9]/g, '');
+ }
+
function amountKeyup() {
$("body").on('keyup', '.product-price', function() {
@@ -187,8 +191,10 @@
// $("#shipping").val(shipping.toFixed(2));
$("#total").val(subtotal.toFixed(2));
}
-
+
$(document).ready(function() {
+ $('.product_id').prop('disabled', true);
+ $('.stock_id').prop('disabled', true);
$('body').on('change', '.product_id', function() {
var selectedId = $(this).find(':selected').val();
var formRow = $(this).closest('.row');
@@ -214,6 +220,72 @@
});
}
});
+
+
+ // When category is selected, load products dynamically
+ $('body').on('change', '.category_id', function () {
+ var categoryId = $(this).val();
+ var formRow = $(this).closest('.row');
+ var productSelect = formRow.find('.product_id');
+ var stockSelect = formRow.find('.stock_id');
+
+ // Reset stock field
+
+ if (categoryId) {
+ $.ajax({
+ type: 'GET',
+ url: '{{ route('products-by-category') }}', // Route to get products by category
+ data: {category_id:categoryId},
+ success: function (response) {
+ productSelect.empty().append('
');
+ productSelect.prop('disabled', false);
+
+ $.each(response.products, function (id, name) {
+ productSelect.append('
');
+ });
+ },
+ error: function (xhr) {
+ // Handle error
+ }
+ });
+ stockSelect.empty().prop('disabled', true);
+
+ } else {
+ productSelect.prop('disabled', true);
+ }
+ });
+
+ // When product is selected, load stocks dynamically
+ $('body').on('change', '.product_id', function () {
+ var productId = $(this).val();
+ var formRow = $(this).closest('.row');
+ var productSelect = formRow.find('.product_id');
+ var stockSelect = formRow.find('.stock_id');
+
+
+ if (productId) {
+ $.ajax({
+ type: 'GET',
+ url: '{{ route('stocks-by-product') }}', // Route to get stocks by product
+ data: {product_id:productId},
+ success: function (response) {
+ stockSelect.empty().append('
');
+ stockSelect.prop('disabled', false);
+
+ $.each(response.stocks, function (id, title) {
+ stockSelect.append('
');
+ });
+ },
+ error: function (xhr) {
+ // Handle error
+ }
+ });
+ } else {
+ stockSelect.prop('disabled', true);
+ }
+ });
});
+
+
@endpush
diff --git a/Modules/SalesEntry/resources/views/salesEntry/partials/menu.blade.php b/Modules/SalesEntry/resources/views/salesEntry/partials/menu.blade.php
new file mode 100644
index 0000000..c9926ad
--- /dev/null
+++ b/Modules/SalesEntry/resources/views/salesEntry/partials/menu.blade.php
@@ -0,0 +1,74 @@
+
+
+
+
+ {{ html()->form('GET')->route('salesEntry.index')->open() }}
+
+ {{--
+
+ {{ html()->text('search')->class('form-control search')->value(request('search'))->placeholder('Search...') }}
+
+
+
--}}
+
+
+
+ {{ html()->text('date')->class('form-control')->value(request('date'))->placeholder('Date Range')->attributes([
+ 'id' => 'datepicker-range',
+ 'data-provider' => 'flatpickr',
+ 'data-date-format' => 'Y-m-d',
+ 'data-range-date' => 'true',
+ ]) }}
+
+
+
+
+
+ {{ html()->select('category_id', $categoryList)->class('form-control select2')->value(request('category_id'))->placeholder('By Category') }}
+
+
+
+
+ {{ html()->select('stock_id', $stockList)->class('form-control select2')->value(request('stock_id'))->placeholder('By Stock') }}
+
+
+
+
+ {{ html()->select('product_id', $productList)->class('form-control select2')->value(request('product_id'))->placeholder('By Product') }}
+
+
+
+ {{--
--}}
+
+
+
+ {{ html()->form()->close() }}
+
+
+
+
+
+
+
+
+
+
diff --git a/Modules/Stock/app/Http/Controllers/StockController.php b/Modules/Stock/app/Http/Controllers/StockController.php
index 44c7101..75fa2d2 100644
--- a/Modules/Stock/app/Http/Controllers/StockController.php
+++ b/Modules/Stock/app/Http/Controllers/StockController.php
@@ -94,4 +94,16 @@ class StockController extends Controller
return response()->json(['status' => true, 'message' => 'Stock Deleted Successfully']);
}
+
+ public function getStocksByProduct(Request $request)
+ {
+ $productId = $request->product_id;
+ try {
+ $stocks = $this->stockRepository->getStocksByProduct($productId);
+ } catch (\Throwable $th) {
+ toastr()->error($th->getMessage());
+ }
+ return response()->json(['stocks' => $stocks]);
+ }
+
}
diff --git a/Modules/Stock/app/Repositories/StockInterface.php b/Modules/Stock/app/Repositories/StockInterface.php
index 5b87f54..ea52870 100644
--- a/Modules/Stock/app/Repositories/StockInterface.php
+++ b/Modules/Stock/app/Repositories/StockInterface.php
@@ -7,6 +7,7 @@ interface StockInterface
public function findAll();
public function getStockById($StockId);
public function getStockByEmail($email);
+ public function getStocksByProduct($productId);
public function delete($StockId);
public function create($StockDetails);
public function update($StockId, array $newDetails);
diff --git a/Modules/Stock/app/Repositories/StockRepository.php b/Modules/Stock/app/Repositories/StockRepository.php
index e4f91ce..a151116 100644
--- a/Modules/Stock/app/Repositories/StockRepository.php
+++ b/Modules/Stock/app/Repositories/StockRepository.php
@@ -23,6 +23,11 @@ class StockRepository implements StockInterface
return Stock::where('email', $email)->first();
}
+ public function getStocksByProduct($productId)
+ {
+ return Stock::where('product_id', $productId)->pluck('title', 'id');
+ }
+
public function delete($StockId)
{
Stock::destroy($StockId);
diff --git a/Modules/Stock/routes/web.php b/Modules/Stock/routes/web.php
index d5c03ae..0e216aa 100644
--- a/Modules/Stock/routes/web.php
+++ b/Modules/Stock/routes/web.php
@@ -19,5 +19,7 @@ use Modules\Stock\Http\Controllers\StockLocationController;
Route::group([], function () {
Route::resource('stock', StockController::class)->names('stock');
Route::resource('stockLocation', StockLocationController::class)->names('stockLocation');
+ Route::get('/stocks-by-product', [StockController::class, 'getStocksByProduct'])->name('stocks-by-product');
+
});