/
home
/
sjslayjy
/
public_html
/
tabson
/
resources
/
views
/
dashboard
/
production-order
/
Upload File
HOME
@extends('dashboard.layouts.app') @section('title','Edit Production Order') @section('style') <style type="text/css"> span.close-now { background: red; width: 25px; height: 25px; display: block; text-align: center; border-radius: 50%; padding: 3px; color: #fff; margin-top: 30px; } </style> @endsection @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="#">Home</a> </li> <li class="active">Edit Production Order</li> </ul> </div> <div class="page-content"> <div class="row"> <div class="panel panel-primary"> <div class="panel-heading"> <h3 class="panel-title">Edit Production Order</h3> </div> <div class="panel-body"> <form action="{{ url('/user/update-production-order/' . $production_order->id) }}" method="post" id="updateProductionOrderForm" enctype="multipart/form-data"> {{ csrf_field() }} <input type="hidden" id="prod_id" name="prod_id" value="{{ $production_order->id }}"> <div class="row grid-margin"> <div class="col-lg-4"> <div class="form-group"> <label>Requested By:</label> <input type="text" id="requested_by" name="requested_by" value="{{ $production_order->created_by_name }}" class="form-control"> </div> </div> <div class="col-lg-4"> <div class="form-group"> <label for="circle">Unit :</label> <select class="form-control e1" id="circle" name="circle"> <option value="">Select Unit</option> @foreach($circles as $circle) <option value="{{ $circle->id }}" {{ $production_order->circle == $circle->id ? 'selected' : '' }}>{{ $circle->name }}</option> @endforeach </select> </div> </div> <div class="col-lg-4"> <div class="form-group"> <label for="department">Department :</label> <select class="form-control e1" id="department" name="department"> <option value="">Select Department</option> @foreach($departments as $department) <option value="{{ $department->id }}" {{ $production_order->department == $department->id ? 'selected' : '' }}> {{ $department->department_id }} - {{ $department->name }} </option> @endforeach </select> </div> </div> </div> <div class="row grid-margin"> <div class="col-lg-4"> <div class="form-group"> <label>BOM Number:</label> <input type="text" id="bom_number" name="bom_number" value="{{ $production_order->bom_number }}" class="form-control" readonly> </div> </div> <div class="col-lg-4"> <div class="form-group"> <label>BOM Version:</label> <input type="text" id="bom_version" name="bom_version" value="{{ $production_order->bom_version }}" class="form-control"> </div> </div> <div class="col-lg-4"> <div class="form-group"> <label>Business Unit :</label> <select class="form-control e1" id="business_unit" name="business_unit"> <option value="">Select Business Unit</option> @foreach($business_units as $business_unit) <option value="{{ $business_unit->id }}" {{ $production_order->business_unit == $business_unit->id ? 'selected' : '' }}>{{ $business_unit->name }}</option> @endforeach </select> </div> </div> </div> <div class="row grid-margin"> <div class="col-lg-4"> <div class="form-group"> <label>Project Name:</label> <input type="text" id="project_name" name="project_name" value="{{ $production_order->project_name }}" class="form-control"> </div> </div> <div class="col-lg-4"> <div class="form-group"> <label>Production Supervisor:</label> <input type="text" id="supervisor_name" name="supervisor_name" value="{{ $production_order->supervisor_name }}" class="form-control"> </div> </div> <div class="col-lg-4"> <div class="form-group"> <label>Production Required Qty :</label> <input type="text" id="required_qty" name="required_qty" value="{{ $production_order->required_qty }}" class="form-control"> </div> </div> </div> <div class="row grid-margin"> <div class="col-lg-4"> <div class="form-group"> <label>Production Start Date:</label> <input type="date" id="prod_start_date" name="prod_start_date" value="{{ $production_order->prod_start_date }}" class="form-control"> </div> </div> <div class="col-lg-4"> <div class="form-group"> <label>Expected Completion Date:</label> <input type="date" id="completion_date" name="completion_date" value="{{ $production_order->completion_date }}" class="form-control"> </div> </div> <div class="col-lg-4"> <div class="form-group"> <label>Production Order Date:</label> <input type="date" id="prod_date" name="prod_date" value="{{ $production_order->prod_date }}" class="form-control"> </div> </div> </div> <div class="row grid-margin"> <div class="col-lg-4"> <div class="form-group"> <label>Production Order Type :</label> <select class="form-control e1" id="production_order_type" name="production_order_type"> <option value="">Select Production Order Type </option> @foreach($po_types as $po_type) <option value="{{ $po_type->id }}" {{ $production_order->production_order_type == $po_type->id ? 'selected' : '' }}>{{ $po_type->name }}</option> @endforeach </select> </div> </div> <div class="col-md-4"> <div class="form-group"> <label for="name">Reference Document:</label> @if($production_order->document1) <a href="{{ url($production_order->document1) }}" target="_blank">View Current Document</a><br> @endif <input class="form-control" type="file" name="document1" id="document1"> </div> </div> <div class="col-lg-4"> <div class="form-group"> <label>Description/Remark</label> <textarea class="form-control" id="delivery_terms" name="delivery_terms">{{ $production_order->delivery_terms }}</textarea> </div> </div> </div> <hr> <!-- Item List Section --> <div class="row grid-margin"> <div class="col-lg-4"> <h4 class="card-title">Item List</h4> </div> </div> <div> <table class="table table-striped table-bordered"> <thead> <tr> <th>BOM Number</th> <th>Item Code</th> <th>Description</th> <th>Make</th> <th>UOM</th> <th>Qty</th> <th>Unit Price</th> <th>Amount</th> <th>GST %</th> <th>GST Amount</th> <th>Total Amount</th> <th>---</th> </tr> </thead> <tbody id="tbody"></tbody> </table> </div> <div class="row"> <div class="col-md-3"> <div class="form-group"> <label>Grand Total :</label> <input type="text" id="prod_amount" name="prod_amount" value="{{ $production_order->prod_amount }}" class="form-control" readonly> </div> </div> <div class="col-md-3"> <div class="form-group"> <label>GST Grand Total :</label> <input type="text" id="prod_gst_amount" name="prod_gst_amount" value="{{ $production_order->prod_gst_amount }}" class="form-control" readonly> </div> </div> </div> <div class="row" style="float: right;"> <div class="col-md-6"> <button type="submit" id="updateOrderBtn" class="btn btn-primary float-right">Update</button> </div> </div> </form> </div> </div> </div> </div><!-- /.page-content --> </div> </div> @endsection @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"> var productionData = {}; productionData.items = []; productionData.circle = '{{ $production_order->circle }}'; productionData.department = '{{ $production_order->department }}'; productionData.business_unit = '{{ $production_order->business_unit }}'; productionData.bom_number = '{{ $production_order->bom_number }}'; productionData.bom_version = '{{ $production_order->bom_version }}'; productionData.project_name = '{{ $production_order->project_name }}'; productionData.production_order_type = '{{ $production_order->production_order_type }}'; productionData.supervisor_name = '{{ $production_order->supervisor_name }}'; productionData.required_qty = '{{ $production_order->required_qty }}'; productionData.prod_start_date = '{{ $production_order->prod_start_date }}'; productionData.completion_date = '{{ $production_order->completion_date }}'; productionData.prod_date = '{{ $production_order->prod_date }}'; productionData.prod_amount = '{{ $production_order->prod_amount }}'; productionData.prod_gst_amount = '{{ $production_order->prod_gst_amount }}'; productionData.delivery_terms = `{{ $production_order->delivery_terms }}`; productionData._token = $('meta[name=\"_token\"]').attr('content'); localStorage.setItem('productionData', JSON.stringify(productionData)); get_items(); function get_items() { var prod_id = "{{ $production_order->id }}"; var url = window.location.origin + "/get-production-order-items"; var data = { _token: $('meta[name=\"_token\"]').attr('content'), prod_id: prod_id }; $.ajax({ type: "POST", url: url, data: data, success: function(res) { var productionData = JSON.parse(localStorage.getItem('productionData')); productionData.items = []; var requiredQty = parseFloat($('#required_qty').val()) || 1; $.each(res.items, function(k, v) { v['is_deleted'] = 0; // Set base_qty for scaling v['base_qty'] = v.qty / requiredQty; productionData.items.push(v); }); localStorage.setItem('productionData', JSON.stringify(productionData)); show_items(); calculate_total(); }, error: function(error) { console.log(error); }, dataType: 'json' }); } function show_items() { var productionData = JSON.parse(localStorage.getItem('productionData')); var items = productionData.items; var html = ""; $.each(items, function(key, val) { let gstAmount = (val.qty * val.rate) * (val.gst / 100); let totalAmount = (val.qty * val.rate) + gstAmount; html += `<tr id=\"item_${val.id}\"> <td>${val.BomN || ''}</td> <td>${val.item_code}</td> <td>${val.description}</td> <td><input type=\"text\" id=\"make_${val.id}\" value=\"${val.make}\" name=\"item_make[${val.id}]\" onkeyup=\"getmake(this,${val.id})\" style=\"width:100px;\" /></td> <td><input type=\"text\" id=\"uom_${val.id}\" value=\"${val.uom}\" name=\"item_uom[${val.id}]\" onkeyup=\"getuom(this,${val.id})\" style=\"width:80px;\" /></td> <td><input type=\"text\" id=\"input_${val.id}\" value=\"${val.qty}\" name=\"item_qty[${val.id}]\" onkeyup=\"getvalue(this,${val.id})\" style=\"width:100px;\" /></td> <td><input type=\"text\" id=\"inputrate_${val.id}\" value=\"${val.rate}\" name=\"item_rate[${val.id}]\" onkeyup=\"getrate(this,${val.id})\" style=\"width:100px;\" /></td> <td id=\"itemtotal_${val.id}\">${(val.qty * val.rate).toFixed(2)}</td> <td><input type=\"text\" id=\"gst_${val.id}\" value=\"${val.gst}\" name=\"item_gst[${val.id}]\" onkeyup=\"getgst(this,${val.id})\" style=\"width:80px;\" /></td> <td id=\"gstamount_${val.id}\">${gstAmount.toFixed(2)}</td> <td id=\"totalamount_${val.id}\">${totalAmount.toFixed(2)}</td> <td><button type=\"button\" class=\"btn btn-sm btn-danger\" onclick=\"deleteItem(${val.id})\"><i class=\"fa fa-trash\"></i></button></td> </tr>`; }); $('#tbody').html(html); localStorage.setItem('productionData', JSON.stringify(productionData)); } function getmake(make, id){ var val = $(make).val(); addCartValueInKey(id, 'make', val); } function getuom(uom, id){ var val = $(uom).val(); addCartValueInKey(id, 'uom', val); } function getvalue(qty, id){ var val = $(qty).val(); addCartValueInKey(id, 'qty', parseFloat(val) || 0); calculate(id); } function getrate(rate, id){ var val = $(rate).val(); addCartValueInKey(id, 'rate', parseFloat(val) || 0); calculate(id); } function getgst(gst, id){ var val = $(gst).val(); addCartValueInKey(id, 'gst', parseFloat(val) || 0); calculate(id); } function addCartValueInKey(id, key, value){ var productionData = JSON.parse(localStorage.getItem('productionData')); $.each(productionData.items, function(k, val){ if(parseInt(val.id) == id){ productionData.items[k][key] = value; } }); localStorage.setItem('productionData', JSON.stringify(productionData)); } function deleteItem(id){ var productionData = JSON.parse(localStorage.getItem('productionData')); var items = productionData.items; $(items).each(function(index){ if(items[index].id == id){ items[index]['is_deleted'] = 1; items[index]['qty'] = 0; $('#item_'+id).remove(); return false; } }); productionData.items = items; localStorage.setItem('productionData', JSON.stringify(productionData)); calculate_total(); } function calculate(id){ var productionData = JSON.parse(localStorage.getItem('productionData')); $.each(productionData.items, function(key, val){ if(val.id == id){ let qty = parseFloat(val.qty); let rate = parseFloat(val.rate); let gst = parseFloat(val.gst); let total = qty * rate; let gstAmount = total * (gst / 100); let totalAmount = total + gstAmount; $('#itemtotal_'+id).text(total.toFixed(2)); $('#gstamount_'+id).text(gstAmount.toFixed(2)); $('#totalamount_'+id).text(totalAmount.toFixed(2)); } }); calculate_total(); } function calculate_total(){ var productionData = JSON.parse(localStorage.getItem('productionData')); var sub_total = 0; var sub_gst_amount = 0; var sub_total_amount = 0; $.each(productionData.items, function(k, val){ if(val.is_deleted != 1){ let subtotal = parseFloat(val.qty * val.rate); let subTotalGstAmount = parseFloat((val.qty * val.rate) * (val.gst / 100)); let subTotalAmount = parseFloat((val.qty * val.rate) + ((val.qty * val.rate) * (val.gst / 100))); sub_total += subtotal; sub_gst_amount += subTotalGstAmount; sub_total_amount += subTotalAmount; } }); $('#prod_amount').val(sub_total.toFixed(2)); $('#prod_gst_amount').val(sub_total_amount.toFixed(2)); } function is_valid(){ var productionData = JSON.parse(localStorage.getItem('productionData')); var check = true; $.each(productionData.items, function(key, val){ if(val.qty == 0 && val.is_deleted != 1){ check = false; $('#input_'+val.id).css({'border':'1px solid #bf0606'}); return false; }else{ $('#input_'+val.id).css({'border':'1px solid #b5b5b5'}); } }); return check; } function showError(id, error){ if(typeof(error) === "undefined"){ $('#'+id).hide(); }else{ $('#'+id).show(); $('#'+id).text(error); } } $('#updateProductionOrderForm').submit(function(e){ e.preventDefault(); var productionData = JSON.parse(localStorage.getItem('productionData')); productionData.prod_amount = $('#prod_amount').val(); productionData.prod_id = $('#prod_id').val(); productionData.prod_gst_amount = $('#prod_gst_amount').val(); localStorage.setItem('productionData', JSON.stringify(productionData)); productionData = JSON.parse(localStorage.getItem('productionData')); if(productionData.items.length < 1){ swal('Error','Please add at least one item!','error'); } else if(!is_valid()){ swal('Error','Quantity cannot be zero. Please check!','error'); } else { var url = $('#updateProductionOrderForm').attr('action'); var formData = new FormData(this); formData.append('items', JSON.stringify(productionData.items)); $('.loading-bg').show(); $.ajax({ url: url, method: 'POST', data: formData, contentType: false, cache: false, processData: false, dataType: 'json', success: function(data){ $('.loading-bg').hide(); if(data.success == true){ swal({ title: "Success", text: data.prod_number + ' Production Order Updated Successfully!', type: "success" }, function(){ window.location.href = window.location.origin + "/circle-store/production-history"; }); } if (data.flag == false) { // Show backend error in SweetAlert if present if (data.error) { swal('Error', data.error, 'error'); } // Also show field errors if present if (typeof data.error === 'object') { $.each(data.error, function(key,val) { showError('add_'+key+'_error',val); }); } } }, error:function(error){ $('.loading-bg').hide(); swal('Error', 'An unexpected error occurred.', 'error'); console.log(error); } }); } return false; }); </script> <script> $(document).ready(function() { $(".e1").select2(); }); $('#required_qty').on('input', function() { var requiredQty = parseFloat($(this).val()) || 0; var productionData = JSON.parse(localStorage.getItem('productionData')); $.each(productionData.items, function(i, item) { if (item.base_qty !== undefined) { item.qty = item.base_qty * requiredQty; } }); localStorage.setItem('productionData', JSON.stringify(productionData)); show_items(); calculate_total(); }); </script> @endsection