/
home
/
sjslayjy
/
public_html
/
assets
/
resources
/
views
/
circle-store
/
Upload File
HOME
@extends('layout.master') @push('plugin-styles') <!-- {!! Html::style('/assets/plugins/plugin.css') !!} --> @endpush @section('content') <!-- SweetAlert2 CSS --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.18/dist/sweetalert2.min.css"> <!-- SweetAlert2 JS --> <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.18/dist/sweetalert2.all.min.js"></script> <div class="row"> <div class="col-lg-12 grid-margin"> <div class="card"> <div class="card-body"> <div class="row"> <div class="col-lg-9"> <h3 class="card-title">Stock Move To Scrap Zone</h3> </div> <div class="col-lg-3"> <select class="form-control mr" id="warehouse"> <option value=""> -- Select Warehouse --</option> @foreach($warehouses as $warehouse) <option value="SER{{$warehouse->fieldUserCodes}}">SER{{$warehouse->fieldUserCodes}}</option> @endforeach @if($userInfo->fieldUserCodes == 'PNT') <!--<option value="SUPPNT">SUPPNT</option>--> @endif </select> </div> </div> </div> </div> </div> <div class="col-lg-12 grid-margin"> <div class="card"> <div class="card-body"> <div class="row grid-margin"> <div class="col-lg-4"> <h4 class="card-title">Spare Parts List</h4> </div> <div class="col-lg-6"> <input type="text" class="form-control" id="spareCode" placeholder="Enter Spare Code"> </div> <div class="col-lg-2"> <button type="button" class="btn btn-success btn-fw" onclick="addselectedItem()">Add Spare</button> </div> </div> <div class="table-responsive"> <table class="table table-striped table-bordered"> <thead> <tr> <th> Spare Code</th> <th> Description</th> <th> UOM</th> <th> Category</th> <th> Faulty Qty</th> <!--<th> Rate</th>--> <th> --- </th> </tr> </thead> <tbody id="tbody"> </tbody> </table> <div id="loaderAction"> <div class="loader"></div> </div> </div> </div> </div> </div> <div class="col-lg-12 grid-margin"> <div class="card"> <div class="card-body"> <div class="row"> <div class="col-lg-9"></div> <div class="col-lg-3"><button type="button" id="spareBtn" onclick="move_to_pt_stock()" class="btn btn-warning btn-fw"> Move To Scrap Zone </button></div> </div> </div> </div> </div> </div> @endsection @push('plugin-scripts') {!! Html::script('/assets/plugins/chartjs/chart.min.js') !!} {!! Html::script('/assets/plugins/jquery-sparkline/jquery.sparkline.min.js') !!} @endpush @push('custom-scripts') {!! Html::script('/assets/js/dashboard.js') !!} <script type="text/javascript"> function init_cart(){ var spareMoveToPt = {}; spareMoveToPt.items = []; spareMoveToPt.engineer_id = ''; localStorage.setItem('spareMoveToPt', JSON.stringify(spareMoveToPt)); } if(localStorage.getItem('spareMoveToPt') != null){ $(document).ready(function(){ var spareMoveToPt = JSON.parse(localStorage.getItem('spareMoveToPt')); if(spareMoveToPt.engineer_id != ""){ $('#engineer').val(spareMoveToPt.engineer_id); } showSelectedItems(); }); }else{ init_cart(); } function removeItem(id){ var spareMoveToPt = JSON.parse(localStorage.getItem('spareMoveToPt')); var items = spareMoveToPt.items; $(items).each(function (index){ if(items[index].id == id){ items.splice(index,1); // This will remove the object that first name equals to Test1 return false; // This will stop the execution of jQuery each loop. } }); spareMoveToPt.items = items; localStorage.setItem('spareMoveToPt',JSON.stringify(spareMoveToPt)); showSelectedItems(); } function addselectedItem(){ var code = $('#spareCode').val(); var warehouse = $('#warehouse').val(); if(code != "" && warehouse !=""){ var url = window.location.origin+"/circle-store/get-faulty-spare-from-circle-stock" var data = {}; data.code = code; data._token = "{{ csrf_token() }}"; data.warehouse = warehouse; $('#loaderAction').show(); $.ajax({ type: "POST", url: url, data: data, success:function(res){ if(res.success == true){ $('#warehouse').attr('disabled',true); var spare_part = res.spare_part; var spareMoveToPt = JSON.parse(localStorage.getItem('spareMoveToPt')); var is_added = false; $.each(spareMoveToPt.items,function(key,val){ if(parseInt(val.id) == spare_part.id){ is_added = true; } }); if(is_added == false){ var sparts = spare_part; sparts.qty = spare_part.faulty_qty; sparts.rqty = 0; spareMoveToPt.items.push(spare_part); } localStorage.setItem('spareMoveToPt',JSON.stringify(spareMoveToPt)); showSelectedItems(); }else{ swal(res.msg, { icon: "error", }); } $('#loaderAction').hide(); }, error:function(error){ console.log(error); }, dataType: 'json' }); }else{ swal("Please Enter Spare Code in Textbox and Select warehouse !", { icon: "error", }); } } function showSelectedItems(){ var ptStockMovetoStock = JSON.parse(localStorage.getItem('spareMoveToPt')); //console.log(ptStockMovetoStock); var html = ''; var n = 0; $.each(ptStockMovetoStock.items,function(key,spare_part){ html +=`<tr class="row_`+spare_part.id+`"> <td class="font-weight-medium">`+spare_part.spare_code+`</td> <td>`+spare_part.description+`</td> <td>`+spare_part.uom+`</td> <td>`+spare_part.category+`</td> <td><input type="text" oninput="validateInput(this)" name="qty" onblur="check_zero(this)" onkeyup="calculate(this,`+spare_part.id+`)" style="width: 80px;" value="`+spare_part.faulty_qty+`" min="0"/></td> <td><a href="#" onclick="removeItem(`+spare_part.id+`)"><i class="mdi mdi-delete-forever"></i></a></td> </tr>`; }); $('#tbody').html(html); } function validateInput(input) { // Get the input value var qty = parseFloat(input.value); // Check if the value is negative if (qty < 0) { Swal.fire({ icon: 'error', title: 'Invalid Input', text: 'Negative values are not allowed!', }); // Set the input value to 0 input.value = 0; } } function check_zero(input){ var qty = $(t).val(); if(qty == "" || qty == null){ $(t).val(0); } } function calculate(t,id){ var qty = $(t).val(); if(qty != "" && qty != null){ addCartValueInKey(id,'qty',qty); }else{ addCartValueInKey(id,'qty',0); } } function rcalculate(t,id){ var rqty = $(t).val(); if(rqty != "" && rqty != null){ addCartValueInKey(id,'rqty',rqty); }else{ addCartValueInKey(id,'rqty',0); } } function addCartValueInKey(id,key,value){ var spareMoveToPt = JSON.parse(localStorage.getItem('spareMoveToPt')); $.each(spareMoveToPt.items,function(k,val){ if(parseInt(val.id) == id){ spareMoveToPt.items[k][key] = value; } }); localStorage.setItem('spareMoveToPt',JSON.stringify(spareMoveToPt)); } function getEngineer(t){ var eng_id = $(t).val(); if(eng_id !=""){ var spareMoveToPt = JSON.parse(localStorage.getItem('spareMoveToPt')); spareMoveToPt.engineer_id = eng_id; localStorage.setItem('spareMoveToPt',JSON.stringify(spareMoveToPt)); }else{ swal('Please Select Engineer !!', { icon: "error", }); } } function is_valid(){ var spareMoveToPt = JSON.parse(localStorage.getItem('spareMoveToPt')); var check = true; $.each(spareMoveToPt.items,function(key,val){ if(val.qty == 0 && val.rqty == 0 ){ check = false; return false; } }); if(check == false){ return false }else{ return true; } } function move_to_pt_stock(){ var warehouse = $('#warehouse').val(); var spareMoveToPt = JSON.parse(localStorage.getItem('spareMoveToPt')); if(spareMoveToPt.items.length > 0 && warehouse !=""){ if(is_valid()){ swal({ title: "Do you want to move spare in Scrap Zone ?", text: "if yes then press 'Ok',otherwise press 'Cancel' and check again.", icon: "warning", buttons: true, dangerMode: true, }).then((willDelete) => { if (willDelete) { var url = window.location.origin+"/circle-store/assign-spare-to-faulty-stock" spareMoveToPt._token = "{{ csrf_token() }}"; spareMoveToPt.warehouse = warehouse; $('#loaderAction').show(); var requestTimeout; var ajaxRequest = $.ajax({ type: "POST", url: url, data: spareMoveToPt, timeout: 20000, // Set the timeout to 5 seconds (5000 milliseconds) success:function(res){ clearTimeout(requestTimeout); console.log(res); if(res.success == true){ swal(res.msg, { icon: "success", }); init_cart(); showSelectedItems(); // Enable the button for re-submit scrapBtn.disabled = false; // Reset the button text scrapBtn.innerHTML = 'Move To Scrap Zone'; }else{ swal(res.msg, { icon: "error", }); } $('#loaderAction').hide(); scrapBtn.disabled = res.success !== true; // placeAmcButton.innerHTML = 'AMC Request Placed !';; }, error:function(xhr, status, error){ var requestTimeout = setTimeout(function () { $('#loaderAction').hide(); swal("Process has been cancelled due to exceeding the execution time!", { icon: "error" }); ajaxRequest.abort(); }, 20000); console.log(error); scrapBtn.disabled = true; scrapBtn.innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> <span class="animated-text">Please wait, request is under process...</span>'; // Clear the timeout on error clearTimeout(requestTimeout); }, dataType: 'json' }); // Set the timeout for the request requestTimeout = setTimeout(function() { $('#loaderAction').hide(); swal("Process has been cancelled due to exceeding the execution time!", { icon: "error" }); ajaxRequest.abort(); // Enable the button for re-submit scrapBtn.disabled = false; // Reset the button text scrapBtn.innerHTML = 'Move To Scrap Zone'; }, 20000); } }); }else{ swal('faulty qty of spare can not be zero !!', { icon: "error", }); } }else{ swal('Please Select warehouse and add at least 1 spare !!', { icon: "error", }); } } $(document).ready(function(){ }); </script> @endpush