/
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">Scrap Stock Move To Main Stock</h3> </div> <div class="col-lg-3"> <select class="form-control mr" id="warehouse"> <option value=""> -- Select Warehouse --</option> <option value="Scrap Zone">Scrap Zone</option> </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">Faulty Stock 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> --- </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-6"></div> <div class="col-lg-3"></div> <div class="col-lg-3"><button type="button" id="faultyBtn" onclick="assign_now()" class="btn btn-warning btn-fw">Move To Stock</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 ptStockMovetoStock = {}; ptStockMovetoStock.items = []; localStorage.setItem('ptStockMovetoStock', JSON.stringify(ptStockMovetoStock)); } if(localStorage.getItem('ptStockMovetoStock') != null){ $(document).ready(function(){ var ptStockMovetoStock = JSON.parse(localStorage.getItem('ptStockMovetoStock')); showSelectedItems(); }); }else{ init_cart(); } function removeItem(id){ var ptStockMovetoStock = JSON.parse(localStorage.getItem('ptStockMovetoStock')); var items = ptStockMovetoStock.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. } }); ptStockMovetoStock.items = items; localStorage.setItem('ptStockMovetoStock',JSON.stringify(ptStockMovetoStock)); showSelectedItems(); } function addselectedItem(){ var code = $('#spareCode').val(); var warehouse = $('#warehouse').val(); if(code != "" && warehouse !=""){ var url = window.location.origin+"/circle-store/check-spare-part-from-faulty-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){ console.log(res); if(res.success == true){ var spare_part = res.spare_part; var ptStockMovetoStock = JSON.parse(localStorage.getItem('ptStockMovetoStock')); var is_added = false; $.each(ptStockMovetoStock.items,function(key,val){ if(parseInt(val.id) == spare_part.id){ is_added = true; } }); if(is_added == false){ var sparts = res.spare_part; // var pt_tocks = res.pt_tocks; sparts.qty = 0; sparts.rqty = 0; ptStockMovetoStock.items.push(sparts); } localStorage.setItem('ptStockMovetoStock',JSON.stringify(ptStockMovetoStock)); 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('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" name="qty" oninput="validateInput(this)" onblur="check_zero(this)" onkeyup="calculate(this,`+spare_part.id+`)" style="width: 80px;" value="`+spare_part.faulty_qty+`"/></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(t){ var qty = $(t).val(); if(qty == "" || qty == null){ $(t).val(0); } } function calculate(t,id){ var qty = $(t).val(); if(qty != "" && qty != null){ qty = parseInt(qty); addCartValueInKey(id,'qty',qty); }else{ addCartValueInKey(id,'qty',0); } } function flcalculate(t,id){ var flqty = $(t).val(); if(flqty != "" && flqty != null){ flqty = parseInt(flqty); addCartValueInKey(id,'rqty',flqty); }else{ addCartValueInKey(id,'rqty',0); } } function addCartValueInKey(id,key,value){ var ptStockMovetoStock = JSON.parse(localStorage.getItem('ptStockMovetoStock')); $.each(ptStockMovetoStock.items,function(k,val){ if(parseInt(val.id) == id){ ptStockMovetoStock.items[k][key] = value; } }); localStorage.setItem('ptStockMovetoStock',JSON.stringify(ptStockMovetoStock)); } function getEngineer(t){ var eng_id = $(t).val(); if(eng_id !=""){ var ptStockMovetoStock = JSON.parse(localStorage.getItem('ptStockMovetoStock')); ptStockMovetoStock.engineer_id = eng_id; localStorage.setItem('ptStockMovetoStock',JSON.stringify(ptStockMovetoStock)); }else{ swal('Please Select Engineer !!', { icon: "error", }); } } function is_valid(){ var ptStockMovetoStock = JSON.parse(localStorage.getItem('ptStockMovetoStock')); var check = true; $.each(ptStockMovetoStock.items,function(key,val){ if(val.qty == 0 && val.rqty == 0 ){ check = false; return false; } }); if(check == false){ return false }else{ return true; } } function assign_now(){ var warehouse = $('#warehouse').val(); if(warehouse !=""){ if(is_valid()){ swal({ title: "Do you want to move scrap to circle store ?", 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/scrap-zone-move-to-main-stock" var ptStockMovetoStock = JSON.parse(localStorage.getItem('ptStockMovetoStock')); ptStockMovetoStock._token = "{{ csrf_token() }}"; ptStockMovetoStock.warehouse = warehouse; $('#loaderAction').show(); var requestTimeout; var ajaxRequest = $.ajax({ type: "POST", url: url, data: ptStockMovetoStock, 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(); showSelectedItems(); // Enable the button for re-submit faultyBtn.disabled = false; // Reset the button text faultyBtn.innerHTML = 'Move To Stock'; }else{ swal(res.msg, { icon: "error", }); } $('#loaderAction').hide(); $('#loaderAction').hide(); faultyBtn.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); faultyBtn.disabled = true; faultyBtn.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 faultyBtn.disabled = false; // Reset the button text faultyBtn.innerHTML = 'Move To Stock'; }, 20000); } }); }else{ swal('faulty qty of spare can not be zero', { icon: "error", }); } }else{ swal('Please Select Warehouse', { icon: "error", }); } } $(document).ready(function(){ }); </script> @endpush