/
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') <div class="row"> <div class="col-lg-12 grid-margin"> <div class="card"> <div class="card-body"> <div class="row"> <div class="col-lg-6"> <h3 class="card-title">Repaired Spare Move To Stock</h3> </div> <div class="col-lg-3"> <small>Select Warehouse</small> <select class="form-control mr" id="warehouse" onchange="get_ware_house(this)"> <option value=""> -- Select Warehouse --</option> @foreach($warehouses as $warehouse) <option value="{{$warehouse}}" {{ $current_warehouse == $warehouse ? 'selected' : ''}}>{{$warehouse}}</option> @endforeach </select> </div> <div class="col-lg-3"> <small>Select Engineer</small> <select class="form-control mr" id="engineer" > <option value=""> -- Select Engineer --</option> @foreach($engineers as $engineer) <option value="{{$engineer->LoginID}}">{{$engineer->LoginID}} - {{$engineer->StaffName}}</option> @endforeach </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">Repaired 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> Rate</th> <th> Total Qty</th> <th> Repaired Qty</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="row grid-margin"> <div class="col-lg-4"> <label>Are Components used to repair the Spare?</label> </div> <div class="col-lg-6"> <select class="form-control mr" style="width: 100px;" onchange="showComponent(this)"> <option value="no">No</option> <option value="yes">Yes</option> </select> </div> </div> </div> <div class="col-lg-12 grid-margin" style="display: none;" id="showComponent"> <div class="card"> <div class="card-body"> <div class="row grid-margin"> <div class="col-lg-6"> <h4 class="card-title">List Of Component Used To Repair The Spare</h4> </div> <div class="col-lg-4"> <input type="text" class="form-control" id="component_code" placeholder="Enter Spare Component Code"> </div> <div class="col-lg-2"> <button type="button" class="btn btn-success btn-fw" onclick="add_component()">Add Component</button> </div> </div> <div class="table-responsive"> <table class="table table-striped table-bordered"> <thead> <tr> <th> Spare Component Code</th> <th> Description</th> <th> UOM</th> <th> Category</th> <th> Qty</th> <th> Rate</th> </tr> </thead> <tbody id="componentbody"> </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="stockBtn" 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 repairedStockMoveToStock = {}; repairedStockMoveToStock.items = []; repairedStockMoveToStock.engineer_id = ''; repairedStockMoveToStock.components = []; repairedStockMoveToStock.iscomponents ='no'; localStorage.setItem('repairedStockMoveToStock', JSON.stringify(repairedStockMoveToStock)); } if(localStorage.getItem('repairedStockMoveToStock') != null){ $(document).ready(function(){ var repairedStockMoveToStock = JSON.parse(localStorage.getItem('repairedStockMoveToStock')); showSelectedItems(); showComponentItems(); }); }else{ init_cart(); } function removeItem(id){ var repairedStockMoveToStock = JSON.parse(localStorage.getItem('repairedStockMoveToStock')); var items = repairedStockMoveToStock.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. } }); repairedStockMoveToStock.items = items; localStorage.setItem('repairedStockMoveToStock',JSON.stringify(repairedStockMoveToStock)); showSelectedItems(); } function removeComponent(id){ var repairedStockMoveToStock = JSON.parse(localStorage.getItem('repairedStockMoveToStock')); var items = repairedStockMoveToStock.components; $(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. } }); repairedStockMoveToStock.components = items; localStorage.setItem('repairedStockMoveToStock',JSON.stringify(repairedStockMoveToStock)); showComponentItems(); } function showComponent(t){ var optionValue = $(t).val(); var repairedStockMoveToStock = JSON.parse(localStorage.getItem('repairedStockMoveToStock')); if(optionValue == 'yes'){ repairedStockMoveToStock.iscomponents ='yes'; $('#showComponent').show(); }else{ repairedStockMoveToStock.iscomponents ='no'; repairedStockMoveToStock.components =[]; $('#showComponent').hide(); } localStorage.setItem('repairedStockMoveToStock',JSON.stringify(repairedStockMoveToStock)); showComponentItems(); } function add_component(argument) { var component_code = $('#component_code').val(); var warehouse = $('#warehouse').val(); var engineer_id = $('#engineer').val(); if(component_code != "" && warehouse != "" && engineer != ""){ var url = window.location.origin+"/circle-store/get-spare-part-from-engineer-stock" var data = {}; data.code = component_code; data._token = "{{ csrf_token() }}"; data.warehouse = warehouse; data.engineer_id = engineer_id; $('#loaderAction').show(); $.ajax({ type: "POST", url: url, data: data, success:function(res){ if(res.success == true){ var spare_part = res.spare_part; var spare_rate = res.spare_rate; var repairedStockMoveToStock = JSON.parse(localStorage.getItem('repairedStockMoveToStock')); var is_added = false; $.each(repairedStockMoveToStock.components,function(key,val){ if(parseInt(val.id) == spare_part.id){ is_added = true; } }); if(is_added == false){ var sparts = spare_part; sparts.qty = 0; sparts.spare_rate = spare_rate; repairedStockMoveToStock.components.push(spare_part); } localStorage.setItem('repairedStockMoveToStock',JSON.stringify(repairedStockMoveToStock)); showComponentItems(); }else{ swal(res.msg, { icon: "error", }); } $('#loaderAction').hide(); }, error:function(error){ console.log(error); }, dataType: 'json' }); }else{ swal("Please Enter Spare Code in Textbox, Select warehouse and Select Engineer !", { icon: "error", }); } } function addselectedItem(){ var code = $('#spareCode').val(); var warehouse = $('#warehouse').val(); if(code != "" && warehouse !=""){ var url = window.location.origin+"/circle-store/get-spare-part-from-trc" 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){ var spare_part = res.spare_part; var repairedStockMoveToStock = JSON.parse(localStorage.getItem('repairedStockMoveToStock')); var is_added = false; $.each(repairedStockMoveToStock.items,function(key,val){ if(parseInt(val.id) == spare_part.id){ is_added = true; } }); if(is_added == false){ var sparts = spare_part; var trc_stock = res.trc_stock; sparts.qty = 0; sparts.flqty = 0; sparts.total_qty = trc_stock.qty; repairedStockMoveToStock.items.push(spare_part); } localStorage.setItem('repairedStockMoveToStock',JSON.stringify(repairedStockMoveToStock)); 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 repairedStockMoveToStock = JSON.parse(localStorage.getItem('repairedStockMoveToStock')); var html = ''; var n = 0; $.each(repairedStockMoveToStock.items,function(key,spare_part){ html +=`<tr class="row_`+spare_part.id+`"> <td class="font-weight-medium">`+spare_part.code+`</td> <td>`+spare_part.description+`</td> <td>`+spare_part.uom+`</td> <td>`+spare_part.category+`</td> <td>`+spare_part.rate+`</td> <td>`+spare_part.total_qty+`</td> <td><input type="text" name="qty" onkeyup="calculate(this,`+spare_part.id+`)" onblur="check_zero(this)" style="width: 80px;" value="`+spare_part.qty+`"/></td> <td><input type="text" name="flqty" onkeyup="flcalculate(this,`+spare_part.id+`)" style="width: 80px;" onblur="check_zero(this)" value="`+spare_part.flqty+`"/></td> <td><a href="#" onclick="removeItem(`+spare_part.id+`)"><i class="mdi mdi-delete-forever"></i></a></td> </tr>`; }); $('#tbody').html(html); } function showComponentItems(){ var repairedStockMoveToStock = JSON.parse(localStorage.getItem('repairedStockMoveToStock')); var chtml = ''; var n = 0; $.each(repairedStockMoveToStock.components,function(key,spare_part){ chtml +=`<tr class="comp_`+spare_part.id+`"> <td class="font-weight-medium">`+spare_part.code+`</td> <td>`+spare_part.description+`</td> <td>`+spare_part.uom+`</td> <td>`+spare_part.category+`</td> <td><input type="text" name="qty" onblur="check_zero(this)" onkeyup="com_calculate(this,`+spare_part.id+`)" style="width: 80px;" value="`+spare_part.qty+`" onkeypress="return (event.charCode == 46 || (event.charCode >= 48 && event.charCode <= 57))"/></td> <td><input type="text" name="spare_rate" onblur="check_zero(this)" onkeyup="add_spare_rate(this,`+spare_part.id+`)" style="width: 80px;" value="`+spare_part.spare_rate+`" onkeypress="return (event.charCode == 46 || (event.charCode >= 48 && event.charCode <= 57))"/></td> <td><a href="#" onclick="removeComponent(`+spare_part.id+`)"><i class="mdi mdi-delete-forever"></i></a></td> </tr>`; }); $('#componentbody').html(chtml); } 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 com_calculate(t,id){ var qty = $(t).val(); if(qty != "" && qty != null){ qty = parseFloat(qty); addComponentValueInKey(id,'qty',qty); }else{ addComponentValueInKey(id,'qty',0); } } function add_spare_rate(t,id){ var spare_rate = $(t).val(); if(spare_rate != "" && spare_rate != null){ spare_rate = parseFloat(spare_rate); addComponentValueInKey(id,'spare_rate',spare_rate); }else{ addComponentValueInKey(id,'spare_rate',0); } } function flcalculate(t,id){ var flqty = $(t).val(); if(flqty != "" && flqty != null){ flqty = parseInt(flqty); addCartValueInKey(id,'flqty',flqty); }else{ addCartValueInKey(id,'flqty',0); } } function addCartValueInKey(id,key,value){ var repairedStockMoveToStock = JSON.parse(localStorage.getItem('repairedStockMoveToStock')); $.each(repairedStockMoveToStock.items,function(k,val){ if(parseInt(val.id) == id){ repairedStockMoveToStock.items[k][key] = value; } }); localStorage.setItem('repairedStockMoveToStock',JSON.stringify(repairedStockMoveToStock)); } function addComponentValueInKey(id,key,value){ var repairedStockMoveToStock = JSON.parse(localStorage.getItem('repairedStockMoveToStock')); $.each(repairedStockMoveToStock.components,function(k,val){ if(parseInt(val.id) == id){ repairedStockMoveToStock.components[k][key] = value; } }); localStorage.setItem('repairedStockMoveToStock',JSON.stringify(repairedStockMoveToStock)); } function getEngineer(t){ var eng_id = $(t).val(); if(eng_id !=""){ var repairedStockMoveToStock = JSON.parse(localStorage.getItem('repairedStockMoveToStock')); repairedStockMoveToStock.engineer_id = eng_id; localStorage.setItem('repairedStockMoveToStock',JSON.stringify(repairedStockMoveToStock)); }else{ swal('Please Select Engineer !!', { icon: "error", }); } } function is_valid(){ var repairedStockMoveToStock = JSON.parse(localStorage.getItem('repairedStockMoveToStock')); var check = true; $.each(repairedStockMoveToStock.items,function(key,val){ if(val.total_qty < (val.qty+val.flqty) || (val.qty == 0 && val.flqty == 0) ){ check = false; return false; } }); if(check == false){ return false }else{ return true; } } function is_com_valid(){ var repairedStockMoveToStock = JSON.parse(localStorage.getItem('repairedStockMoveToStock')); var check = true; $.each(repairedStockMoveToStock.components,function(key,val){ if(val.qty == 0){ check = false; return false; } }); if(check == false){ return false }else{ return true; } } function assign_now(){ var warehouse = $('#warehouse').val(); var engineer = $('#engineer').val(); var repairedStockMoveToStock = JSON.parse(localStorage.getItem('repairedStockMoveToStock')); if(warehouse =="" || engineer == ""){ swal('Please Select Warehouse and Engineer', { icon: "error", }); }else if(!is_valid()){ swal('Repaired and faulty spare qty will not greater than total qty of item and not zero in both.', { icon: "error", }); }else if(!is_com_valid() && repairedStockMoveToStock.iscomponents =='yes'){ swal('Zero Component Not Allow !! please check !', { icon: "error", }); }else{ var url = window.location.origin+"/circle-store/repaired-stock-move-to-stock" repairedStockMoveToStock._token = "{{ csrf_token() }}"; repairedStockMoveToStock.warehouse = warehouse; repairedStockMoveToStock.engineer_id = engineer; $('#loaderAction').show(); var requestTimeout; var ajaxRequest = $.ajax({ type: "POST", url: url, data: repairedStockMoveToStock, 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 stockBtn.disabled = false; // Reset the button text stockBtn.innerHTML = 'Move To Stock'; }else{ swal(res.msg, { icon: "error", }); } $('#loaderAction').hide(); stockBtn.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); stockBtn.disabled = true; stockBtn.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 stockBtn.disabled = false; // Reset the button text stockBtn.innerHTML = 'Move To Stock'; }, 20000); } } function get_ware_house(t){ var warehouse = $(t).val(); if(warehouse !=""){ var url = window.location.origin+"/circle-store/get-trc-engineer-of-warehouse" var data = {}; data._token = "{{ csrf_token() }}"; data.warehouse = warehouse; $('#loaderAction').show(); $.ajax({ type: "POST", url: url, data: data, success:function(res){ if(res.success == true){ var html = '<option value=""> -- Select Engineer --</option>'; $.each(res.engineers,function(key,val){ html +=`<option value="`+val.LoginID+`">`+val.LoginID+` - `+val.StaffName+`</option>`; }); $('#engineer').html(html); }else{ swal(res.msg, { icon: "error", }); } $('#loaderAction').hide(); }, error:function(error){ console.log(error); }, dataType: 'json' }); }else{ swal("Please Select warehouse !", { icon: "error", }); } } $(document).ready(function(){ }); </script> @endpush