/
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">Spare Assigned To Site</h3> </div> <div class="col-lg-3"> <small> Assign Date</small> <input type="text" class="form-control" name="assign_date" id="datepicker" onchange="get_assign_date(this)" /> </div> <div class="col-lg-3"> <small>Warehouse</small> <select class="form-control mr select2" id="warehouse" onchange="get_ware_house(this)"> @foreach($warehouses as $warehouse) <option value="{{$warehouse}}">{{$warehouse}}</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">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> Fresh Qty</th> <th> Repaired_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-4"> <small>Purpose</small> <textarea class="form-control" id="purpose" onchange="get_purpose(this)"></textarea> </div> <div class="col-lg-4"> <small>Site</small> <select class="form-control mr select2" onchange="getSite(this)" id="site"> <option value=""> -- Select Site --</option> @foreach($sites as $site) <option value="{{$site->Site_id}}::{{$site->product}}">{{$site->Site_id}}({{$site->product}}) - {{$site->Site_Name}}</option> @endforeach </select> </div> <div class="col-lg-2"> <button type="button" onclick="assign_now()" class="btn btn-warning btn-fw">Assign Now</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> $( function() { $( "#datepicker" ).datepicker({ minDate: -5, maxDate: "+7D" }); } ); </script> <script type="text/javascript"> function init_cart(){ var assignedSpare = {}; assignedSpare.items = []; assignedSpare.engineer_id = ''; assignedSpare.assign_date = ''; localStorage.setItem('assignedSpare', JSON.stringify(assignedSpare)); } if(localStorage.getItem('assignedSpare') != null){ $(document).ready(function(){ var assignedSpare = JSON.parse(localStorage.getItem('assignedSpare')); if(assignedSpare.engineer_id != ""){ $('#engineer').val(assignedSpare.engineer_id); } showSelectedItems(); }); }else{ init_cart(); } function get_ware_house(t){ var warehouse = $(t).val(); if(warehouse !=""){ var url = window.location.origin+"/circle-store/get-site-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 Site --</option>'; $.each(res.sites,function(key,val){ html +=`<option value="`+val.Site_id+`::`+val.product+`">`+val.Site_id+`::`+val.product+` - `+val.Site_Name+`</option>`; }); $('#site').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", }); } } function removeItem(id){ var assignedSpare = JSON.parse(localStorage.getItem('assignedSpare')); var items = assignedSpare.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. } }); assignedSpare.items = items; localStorage.setItem('assignedSpare',JSON.stringify(assignedSpare)); showSelectedItems(); } function addselectedItem(){ var code = $('#spareCode').val(); var warehouse = $('#warehouse').val(); if(code != "" && warehouse !=""){ var url = window.location.origin+"/circle-store/get-spare-part-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 assignedSpare = JSON.parse(localStorage.getItem('assignedSpare')); var is_added = false; $.each(assignedSpare.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.fresh_qty; sparts.rqty = spare_part.repaired_qty; assignedSpare.items.push(spare_part); } localStorage.setItem('assignedSpare',JSON.stringify(assignedSpare)); 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 assignedSpare = JSON.parse(localStorage.getItem('assignedSpare')); var html = ''; var n = 0; $.each(assignedSpare.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><input type="text" name="qty" onkeypress="return onlyCurrency(event)" onblur="check_zero(this)" onkeyup="calculate(this,`+spare_part.id+`)" style="width: 80px;" value="`+spare_part.fresh_qty+`"/></td> <td><input type="text" name="qty" onkeypress="return onlyNumber(event)" onblur="check_zero(this)" onkeyup="rcalculate(this,`+spare_part.id+`)" style="width: 80px;" value="`+spare_part.rqty+`"/></td> <td><a href="#" onclick="removeItem(`+spare_part.id+`)"><i class="mdi mdi-delete-forever"></i></a></td> </tr>`; }); $('#tbody').html(html); } function onlyNumber(evt){ var charCode = (evt.which) ? evt.which : event.keyCode if (charCode > 31 && (charCode < 48 || charCode > 57)){ return false; } return true; } function onlyCurrency(event){ if(event.which == 8 || event.which == 0){ return true; } if(event.which < 46 || event.which > 59) { return false; //event.preventDefault(); } // prevent if not number/dot if(event.which == 46 && $(this).val().indexOf('.') != -1) { return false; //event.preventDefault(); } // preven } function calculate(t,id){ var qty = $(t).val(); if(qty != "" && qty != null){ addCartValueInKey(id,'qty',qty); }else{ addCartValueInKey(id,'qty',0); } } function check_zero(t){ var qty = $(t).val(); if(qty == "" || qty == null){ $(t).val(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 assignedSpare = JSON.parse(localStorage.getItem('assignedSpare')); $.each(assignedSpare.items,function(k,val){ if(parseInt(val.id) == id){ assignedSpare.items[k][key] = value; } }); localStorage.setItem('assignedSpare',JSON.stringify(assignedSpare)); } function getSite(t){ var eng_id = $(t).val(); if(eng_id !=""){ var assignedSpare = JSON.parse(localStorage.getItem('assignedSpare')); assignedSpare.site_id = eng_id; localStorage.setItem('assignedSpare',JSON.stringify(assignedSpare)); }else{ swal('Please Select Site !!', { icon: "error", }); } } // function getSiteProduct(t){ // var site_product = $(t).val(); // if(site_product !=""){ // var assignedSpare = JSON.parse(localStorage.getItem('assignedSpare')); // assignedSpare.site_product = site_product; // localStorage.setItem('assignedSpare',JSON.stringify(assignedSpare)); // }else{ // swal('Please Select Site Product !!', { icon: "error", }); // } // } function get_assign_date(t){ var assign_date = $(t).val(); if(assign_date !=""){ var assignedSpare = JSON.parse(localStorage.getItem('assignedSpare')); assignedSpare.assign_date = assign_date; localStorage.setItem('assignedSpare',JSON.stringify(assignedSpare)); }else{ swal('Please Select Engineer !!', { icon: "error", }); } } function is_valid(){ var assignedSpare = JSON.parse(localStorage.getItem('assignedSpare')); var check = true; $.each(assignedSpare.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 eng_id = $('#site').val(); var warehouse = $('#warehouse').val(); var assign_date = $('#assign_date').val(); var purpose = $('#purpose').val(); var assignedSpare = JSON.parse(localStorage.getItem('assignedSpare')); if(eng_id !="" && assignedSpare.items.length > 0 && warehouse !="" && assign_date !=""){ if(is_valid()){ swal({ title: "Is Your Spare Parts Verified ?", text: "if you verified your items 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-site-now" assignedSpare._token = "{{ csrf_token() }}"; assignedSpare.warehouse = warehouse; assignedSpare.assign_date = assign_date; assignedSpare.type = 2; assignedSpare.purpose = purpose; $('#loaderAction').show(); $.ajax({ type: "POST", url: url, data: assignedSpare, success:function(res){ console.log(res); if(res.success == true){ // swal(res.msg, { icon: "success", }); init_cart(); swal({ title: "Wow!", text: res.msg, type: "success" }).then(function() { location.reload(); }); // showSelectedItems(); }else{ swal(res.msg, { icon: "error", }); } $('#loaderAction').hide(); }, error:function(error){ console.log(error); }, dataType: 'json' }); } }); }else{ swal('Both fresh and repaired qty of spare can not be zero !!', { icon: "error", }); } }else{ swal('Please Select Site, warehouse, assign date and add at least 1 spare !!', { icon: "error", }); } } $(document).ready(function(){ $(".select2").select2(); }); </script> <script> $(document).ready(function() { $('.select2').select2({ placeholder: 'Search Warehouses', allowClear: false, language: { noResults: function() { return '<span class="no-results">No results found!</span>'; } }, escapeMarkup: function (markup) { return markup; } }); }); </script> @endpush