/
home
/
sjslayjy
/
public_html
/
devlok
/
resources
/
views
/
dashboard
/
stock
/
Upload File
HOME
@extends('dashboard.layouts.app') @section('title','Stock Report') @section('content') <div class="main-content"> <div class="main-content-inner"> <div class="breadcrumbs ace-save-state" id="breadcrumbs"> <ul class="breadcrumb"> <li> <i class="ace-icon fa fa-home home-icon"></i> <a href="#">{{__('messages.Home')}}</a> </li> <li class="active">Warehouse Stock</li> </ul> </div> <div class="page-content"> <h3 class="header smaller lighter blue">Warehouse Stock</h3> <div class="row"> <div class="col-xs-12"> <form action="{{ url('stock/warehouse-stock') }}" method="GET" role="form"> <div class="row"> @csrf <div class="col-md-3"> <div class="form-group"> <label for="warehouse_id">Warehouse Stock</label> <select class="form-control select2" name="warehouse_id" id="warehouse_id"> <option value="">All Warehouses</option> @foreach($warehouses as $warehouse) <option value="{{ $warehouse->id }}" {{ isset($selectedWarehouse) && $selectedWarehouse == $warehouse->id ? 'selected' : '' }}> {{ $warehouse->name }} </option> @endforeach </select> </div> </div> <div class="col-md-3"> <div class="form-group"> <input type="submit" class="btn btn-sm btn-primary" value="Filter" style="margin-top: 20px;"> </div> </div> </div> </form> <div class="clearfix"> <div class="pull-right tableTools-container"> </div> </div> @if (session('success')) <div class="alert alert-success"> {{ session('success') }} </div> @endif @if (session('error')) <div class="alert alert-danger"> {{ session('error') }} </div> @endif <div class="table-header"> Warehouse Report <div class="widget-toolbar no-border"> <a class="btn btn-xs bigger btn-danger dropdown-toggle" data-toggle="modal" href='#addWarehouseStockModal'> Opening Stock <i class="ace-icon fa fa-plus icon-on-right"></i> </a> </div> <div class="widget-toolbar no-border"> <a class="btn btn-xs bigger btn-danger dropdown-toggle" data-toggle="modal" href='#ManageDamgeStockMdel'> Manage Damage Stock <i class="ace-icon fa fa-plus icon-on-right"></i> </a> </div> </div> <div class="table-responsive"> <div class="dataTables_borderWrap"> <table id="dynamic-table" class="table table-striped table-bordered table-hover"> <thead> <tr> <th>Id</th> <th>Product Company</th> <th>Warehouse</th> <th>Product Brand</th> <th>Product</th> <th>Unit</th> <th>quantity</th> <th>Damage Qty</th> <th>Scrap Qty</th> @if(Auth::check() && Auth::user()->role_id == 1 && Auth::user()->email == 'admin@gmail.com') <th>Action</th> @endif </tr> </thead> <tbody> @foreach($inventories as $invntry=>$inventorie) <tr> <td>{{$invntry+1}}</td> <td>{{$inventorie->product_companies_name}}</td> <td>{{$inventorie->warehouse_name}}</td> <td>{{$inventorie->brand_name}}</td> <td>{{$inventorie->product_name}}</td> <td>{{$inventorie->units}}</td> <td>{{$inventorie->quantity}}</td> <td>{{$inventorie->damage_qty}}</td> <td>{{$inventorie->scrap_qty}}</td> @if(Auth::check() && Auth::user()->role_id == 1 && Auth::user()->email == 'admin@gmail.com') <td> <div class="btn-group"> <a class="btn btn-xs btn-info" onclick="getEdit({{ $inventorie->id }})"><i class="ace-icon fa fa-pencil bigger-120"></i></a> </div> </td> @endif </tr> @endforeach </tbody> </table> </div> </div> </div> </div> </div> </div> </div> <!-- Add Warehouse stock Modal --> <div class="modal fade" id="addWarehouseStockModal"> <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title">Add New Warehouse Stock</h4> </div> <div class="modal-body"> <form action="" role="form" id="addWarehouseStockForm"> @csrf <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="name">Warehouse List</label> <select class="form-control select2" name="warehouse_id" id="warehouse_id"> <option value="">Select Warehouse List</option> @foreach($warehouses as $key=> $warehosue) <option value="{{$warehosue->id}}">{{$warehosue->name}}</option> @endforeach </select> <span class="label label-danger" id="add_warehouse_ist_error" style="display: none;"></span> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="name">Product Company</label> <select class="form-control select2" name="product_company_id" id="product_company_id1"> <option value="">Select Product Company</option> <option value="1">HeidelbergCement India Limited</option> </select> <span class="label label-danger" id="add_product_company_error" style="display: none;"></span> </div> </div> <div class="clearfix"></div> <div class="col-md-6"> <div class="form-group"> <label for="name">Date</label> <input type="date" class="form-control date-picker" name="date" id="date" placeholder="Date" > <span class="label label-danger" id="add_date_error" style="display: none;"></span> </div> </div> </div> <div class="row"> <div class="col-md-5"> <div class="form-group"> <label for="proruct">Product</label> <select class="form-control select2 checkIfValid" name="product_id[]" id="product_id"> <option value="">Select Product</option> @foreach($products as $key=> $product) <option value="{{$product->id}}" id="product_{{$product->id}}">{{$product->name}}</option> @endforeach </select> <span class="label label-danger" id="add_product_id_error" style="display: none;"></span> </div> </div> <div class="col-md-3"> <div class="form-group"> <label for="rate">Fresh Quantity</label> <input type="text" class="form-control checkIfValid" name="fresh_qty[]" placeholder="Fresh Quantity"> <span class="label label-danger" id="add_quantity_error" style="display: none;"></span> </div> </div> <div class="col-md-3"> <div class="form-group"> <label for="rate">Damage Quantity</label> <input type="text" class="form-control checkIfValid" name="damage_qty[]" placeholder="Damage Quantity"> <span class="label label-danger" id="add_quantity_error" style="display: none;"></span> </div> </div> </div> <div id="addMoreRowSection"> </div> <div class="pull-left"> <button type="button" id="addMoreRow" class="btn btn-danger"><i class="fa fa-plus"></i> Add More </button> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <!-- <button type="button" id="addMasterRakeBtn" class="btn btn-primary">Submit</button> --> <input type="submit" value="submit" class="btn btn-primary" id="openingStockBtn"> </div> </form> </div> </div> </div> <!-- Add Warehouse stock Modal --> <!-- Edit Session Modal --> <div class="modal fade" id="editInventoryModal"> <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title">Update Warehouse Stock</h4> </div> <div class="modal-body" id="EditBody"> </div> </div> </div> </div> <!-- Edit Session Modal --> <!--Start Manage DamgeStock--> <div class="modal fade" id="ManageDamgeStockMdel"> <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title">Manage Damge Product Stock</h4> </div> <div class="modal-body"> <form action="" role="form" id="ManageDamgeStock"> @csrf <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="name">Warehouse List</label> <select class="form-control select2" name="warehouse_id" id="ManageDamgeStockwarehouse_id"> <option value="">Select Warehouse List</option> @foreach($warehouses as $key => $warehosue) <option value="{{$warehosue->id}}">{{$warehosue->name}}</option> @endforeach </select> <span class="label label-danger" id="ManageDamgeStockadd_warehouse_ist_error" style="display: none;"></span> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="name">Product Company</label> <select class="form-control select2" name="product_company_id" id="ManageDamgeStockproduct_company_id1"> <option value="">Select Product Company</option> <option value="1">HeidelbergCement India Limited</option> </select> <span class="label label-danger" id="ManageDamgeStockadd_product_company_error" style="display: none;"></span> </div> </div> <div class="clearfix"></div> <!--<div class="col-md-6">--> <!-- <div class="form-group">--> <!-- <label for="name">Date</label>--> <!-- <input type="date" class="form-control date-picker" name="date" id="ManageDamgeStockdate" placeholder="Date">--> <!-- <span class="label label-danger" id="ManageDamgeStockadd_date_error" style="display: none;"></span>--> <!-- </div>--> <!--</div>--> </div> <div class="row"> <div class="col-md-5"> <div class="form-group"> <label for="product_id">Product</label> <select class="form-control select2 checkIfValid" name="product_id[]" id="ManageDamgeStockproduct_id" multiple> <option value="">Select Product</option> @foreach($products as $key => $product) <option value="{{ $product->id }}" id="ManageDamgeStockproduct_{{ $product->id }}">{{ $product->name }}</option> @endforeach </select> <span class="label label-danger" id="ManageDamgeStockadd_product_id_error" style="display: none;"></span> </div> </div> <!--<div class="col-md-3">--> <!-- <div class="form-group">--> <!-- <label for="rate">Fresh Quantity</label>--> <!-- <input type="text" class="form-control checkIfValid" name="fresh_qty[]" placeholder="Fresh Quantity" id="ManageDamgeStockfresh_qty">--> <!-- <span class="label label-danger" id="ManageDamgeStockadd_quantity_error" style="display: none;"></span>--> <!-- </div>--> <!--</div>--> <!--<div class="col-md-3">--> <!-- <div class="form-group">--> <!-- <label for="rate">Damage Quantity</label>--> <!-- <input type="text" class="form-control checkIfValid" name="damage_qty[]" placeholder="Damage Quantity" id="ManageDamgeStockdamage_qty">--> <!-- <span class="label label-danger" id="ManageDamgeStockadd_quantity_error" style="display: none;"></span>--> <!-- </div>--> <!--</div>--> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <input type="submit" value="submit" class="btn btn-primary" id="ManageDamgeStockopeningStockBtn"> </div> </form> <div class="table-responsive" id="productInputTableSection" style="margin-top: 20px;"> <table class="table table-bordered" id="stockPreviewTable" style="display: none;"> <thead> <tr> <th>Product Name</th> <th>Fresh Quantity</th> <th>Damage Quantity</th> </tr> </thead> <tbody></tbody> </table> <button id="saveStockBtn" class="btn btn-success mt-2" style="display: none;">Save Stock</button> </div> </div> </div> </div> <!--END Manage DamgeStock--> @section('script') {{ Html::script("assets/js/jquery.dataTables.min.js")}} {{ Html::script("assets/js/jquery.dataTables.bootstrap.min.js")}} {{ Html::script("assets/js/dataTables.buttons.min.js")}} {{ Html::script("assets/js/buttons.flash.min.js")}} {{ Html::script("assets/js/buttons.html5.min.js")}} {{ Html::script("assets/js/buttons.print.min.js")}} {{ Html::script("assets/js/buttons.colVis.min.js")}} {{ Html::script("assets/js/dataTables.select.min.js")}} {{ Html::script("assets/js/ace-elements.min.js")}} {{ Html::script("assets/js/ace.min.js")}} <script type="text/javascript"> $('#filter').click(function(){ var warehouse_name = $('#warehouse_name').val(); if(dealer_id !='') { $('#dynamic-table').DataTable().destroy(); display(warehouse_name); }else if(warehouse_name!=''){ $('#dynamic-table').DataTable().destroy(); display(warehouse_name); }else{ alert('Warehouse is required'); } }); jQuery(function($) { $('#openingStockBtn').click(function(e){ e.preventDefault(); var data = $('#addWarehouseStockForm').serialize(); $.ajax({ url: "{{url('/stock/add-opening-balance')}}", type: 'POST', data: data, success:function(data){ if(data.flag){ swal({ title: "Success!", text: data.message, type: "success" }, function() { window.location.reload(); }); }else{ console.log(data.message); swal({ title: "Error", text: data.message, type: "error" }, function() { window.location.reload(); }); } } }); }); //initiate dataTables plugin var myTable = $('#dynamic-table').DataTable( { bAutoWidth: false, "aaSorting": [], } ); $.fn.dataTable.Buttons.defaults.dom.container.className = 'dt-buttons btn-overlap btn-group btn-overlap'; new $.fn.dataTable.Buttons( myTable, { buttons: [ { "extend": "colvis", "text": "<i class='fa fa-search bigger-110 blue'></i> <span class='hidden'>Show/hide columns</span>", "className": "btn btn-white btn-primary btn-bold", columns: ':not(:first):not(:last)' }, { "extend": "copy", "text": "<i class='fa fa-copy bigger-110 pink'></i> <span class='hidden'>Copy to clipboard</span>", "className": "btn btn-white btn-primary btn-bold" }, { "extend": "csv", "text": "<i class='fa fa-database bigger-110 orange'></i> <span class='hidden'>Export to CSV</span>", "className": "btn btn-white btn-primary btn-bold" }, { "extend": "excel", "text": "<i class='fa fa-file-excel-o bigger-110 green'></i> <span class='hidden'>Export to Excel</span>", "className": "btn btn-white btn-primary btn-bold" }, { "extend": "pdf", "text": "<i class='fa fa-file-pdf-o bigger-110 red'></i> <span class='hidden'>Export to PDF</span>", "className": "btn btn-white btn-primary btn-bold" }, { "extend": "print", "text": "<i class='fa fa-print bigger-110 grey'></i> <span class='hidden'>Print</span>", "className": "btn btn-white btn-primary btn-bold", autoPrint: true, message: 'IManager', exportOptions: { columns: ':visible' } } ] } ); }) function removeRow(id){ $('#newRow'+id).remove(); } $('#addMoreRow').click(function(){ var count = $('.row').length + 1; console.log(count); var newRow = `<div class="row" id="newRow`+count+`"> <div class="col-md-5"> <div class="form-group"> <label for="product">Product</label> <select class="form-control select2 checkIfValid" name="product_id[]" id="product_id"> <option value="">Select Product</option> @foreach($products as $key=> $product) <option value="{{$product->id}}" id="product_{{$product->id}}">{{$product->name}}</option> @endforeach </select> <span class="label label-danger" id="add_product_id_error" style="display: none;"></span> </div> </div> <div class="col-md-3"> <div class="form-group"> <label for="rate">Fresh Quantity</label> <input type="text" class="form-control checkIfValid" name="fresh_qty[]" placeholder="Fresh Quantity"> <span class="label label-danger" id="add_quantity_error" style="display: none;"></span> </div> </div> <div class="col-md-3"> <div class="form-group"> <label for="rate">Damage Quantity</label> <input type="text" class="form-control checkIfValid" name="damage_qty[]" placeholder="Damage Quantity"> <span class="label label-danger" id="add_quantity_error" style="display: none;"></span> </div> </div> <div class="col-md-1" style="margin-top: 33px;"> <a href="javascript:;" onclick="removeRow(`+count+`)"><i class="fa fa-close fa-2x"></i></a> </div> </div> `; $('#addMoreRowSection').append(newRow); $('.select2').select2(); }); function getEdit(id){ if(id == ""){ swal('Error','Inventory id is missing','warning'); }else{ $.ajax({ url: "{{url('/user/edit-stock/')}}"+"/"+id, type: 'GET', success:function(data){ $('#EditBody').html(data); $('#editInventoryModal').modal('toggle'); } }); } } $(document).on('submit', '#editInventoryModal form', function (e) { e.preventDefault(); // Prevent default form submission var form = this; // Use `this` directly as it refers to the form var formData = new FormData(form); // Pass the form element to FormData $.ajax({ url: "{{ url('/user/edit-inventory') }}", type: 'POST', data: formData, processData: false, // Prevent jQuery from processing the data contentType: false, // Prevent jQuery from setting the content type success: function (response) { if (response.flag) { swal({ title: "Success!", text: response.message, type: "success" }, function () { window.location.reload(); }); } else { swal({ title: "Error", text: response.message, type: "error" }); } }, error: function (xhr) { swal({ title: "Error", text: "An error occurred while updating the inventory.", type: "error" }); } }); }); </script> <script> $('#ManageDamgeStockproduct_id').select2({ placeholder: "Select Product", allowClear: true }); $('#ManageDamgeStock').on('submit', function (e) { e.preventDefault(); let warehouseId = $('#ManageDamgeStockwarehouse_id').val(); let companyId = $('#ManageDamgeStockproduct_company_id1').val(); let productIds = $('#ManageDamgeStockproduct_id').val(); if (!warehouseId || !companyId || productIds.length === 0) { swal("Warning", "Please fill all required fields.", "warning"); return; } $.ajax({ url: "{{ route('get.product.stock.details') }}", type: "POST", data: { _token: "{{ csrf_token() }}", warehouse_id: warehouseId, product_company_id: companyId, product_ids: productIds }, success: function (response) { let html = ''; response.forEach(function (item) { console.log(item); let totalQty = parseFloat(item.fresh_qty) + parseFloat(item.damage_qty); html += ` <tr> <td>${item.name}</td> <td><input type="text" name="fresh_qty[]" class="form-control fresh_qty" value="${item.fresh_qty}" readonly data-original-fresh="${item.fresh_qty}" /></td> <td><input type="text" name="damage_qty[]" class="form-control damage_qty" value="${item.damage_qty}" data-old-damage="${item.damage_qty}" /></td> <input type="hidden" name="product_id[]" value="${item.id}" class="product_id" /> <input type="hidden" name="max_value[]" value="${totalQty}" class="max_value" /> <input type="hidden" name="old_d_val[]" value="${item.damage_qty}" class="old_d_val" /> <input type="hidden" name="old_s_val[]" value="${item.scrap_qty}" class="old_s_val" /> </tr> `; }); $('#stockPreviewTable tbody').html(html); $('#stockPreviewTable').show(); $('#saveStockBtn').show(); } }); }); $('#saveStockBtn').on('click', function () { let isValid = true; let products = []; $('#stockPreviewTable tbody tr').each(function () { let $row = $(this); let productId = $row.find('input[name="product_id[]"]').val(); let freshValRaw = $row.find('.fresh_qty').val(); let damageValRaw = $row.find('.damage_qty').val(); let totalval = $row.find('.max_value').val(); let old_d_val = $row.find('.old_d_val').val(); let old_s_val = $row.find('.old_s_val').val(); let freshVal = freshValRaw ? freshValRaw.trim() : ''; let damageVal = damageValRaw ? damageValRaw.trim() : ''; let freshQty = freshVal ? parseFloat(freshVal) : 0; let damageQty = damageVal ? parseFloat(damageVal) : 0; if (isNaN(freshQty) || isNaN(damageQty)) { swal("Error", "Quantities must be numeric", "error"); isValid = false; return false; } // if (freshQty + damageQty > totalval) { // swal("Error", `Total quantity for product ID ${productId} exceeds available stock (${totalval})`, "error"); // isValid = false; // return false; // } products.push({ product_id: productId, fresh_qty: freshQty, damage_qty: damageQty, old_d_val:old_d_val, old_s_val:old_s_val }); }); if (!isValid) return; $.ajax({ url: "{{ route('save.stock.data') }}", type: "POST", data: { _token: "{{ csrf_token() }}", warehouse_id: $('#ManageDamgeStockwarehouse_id').val(), product_company_id: $('#ManageDamgeStockproduct_company_id1').val(), date: $('#date').val(), products: products }, success: function (response) { if (response.flag) { swal({ title: "Success!", text: response.message, icon: "success" },function () { $('#ManageDamgeStockMdel').modal('toggle'); window.location.reload(); }); } else { swal("Error", response.message || "Error saving stock.", "error"); } } }); }); // $(document).on('input', '.damage_qty', function () { // let $row = $(this).closest('tr'); // let enteredQty = parseFloat($(this).val()) || 0; // let oldDamageQty = parseFloat($(this).data('old-damage')) || 0; // let totalStock = parseFloat($row.find('.max_value').val()) || 0; // if (enteredQty > oldDamageQty) { // swal("Invalid Input", "You cannot increase damage quantity. Only reduce it.", "warning"); // $(this).val(oldDamageQty); // Reset to original // $row.find('.fresh_qty').val(totalStock - oldDamageQty); // return; // } // let freshQty = totalStock - enteredQty; // $row.find('.fresh_qty').val(freshQty); // }); $(document).on('input', '.damage_qty', function () { let $row = $(this).closest('tr'); let enteredQty = parseFloat($(this).val()) || 0; let oldDamageQty = parseFloat($(this).data('old-damage')) || 0; let originalFreshQty = parseFloat($row.find('.fresh_qty').data('original-fresh')) || 0; if (enteredQty > oldDamageQty) { swal("Invalid Input", "You cannot enter more than the original damage quantity.", "warning"); $(this).val(oldDamageQty); // Clear input $row.find('.fresh_qty').val(originalFreshQty); // Reset fresh return; } let updatedFreshQty = originalFreshQty + enteredQty; $row.find('.fresh_qty').val(updatedFreshQty); }); </script> <script> $(document).ready(function () { $('.select2').select2(); $('#ManageDamgeStockwarehouse_id').on('change', function () { let warehouseId = $(this).val(); let $productSelect = $('#ManageDamgeStockproduct_id'); $productSelect.html('<option value="">Loading...</option>'); if (warehouseId) { $.ajax({ url: '/products-by-warehouse/' + warehouseId, method: 'GET', success: function (response) { let options = '<option value="">Select Product</option>'; response.forEach(function (product) { options += `<option value="${product.id}">${product.name}</option>`; }); $productSelect.html(options).trigger('change'); }, error: function () { swal("Error", "Unable to load products.", "error"); $productSelect.html('<option value="">Select Product</option>'); } }); } else { $productSelect.html('<option value="">Select Product</option>'); } }); }); </script> @endsection @endsection