403Webshell
Server IP : 14.225.204.176  /  Your IP : 216.73.216.6
Web Server : nginx/1.24.0
System : Linux nodejs-ybgk 6.8.0-40-generic #40-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 5 10:34:03 UTC 2024 x86_64
User : root ( 0)
PHP Version : 8.1.34
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/html/php/thanhphuong/resources/views/adjustment/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/php/thanhphuong/resources/views/adjustment/create.blade.php
@extends('layout.main')
@section('content')
<section class="forms">
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-body">
                        {!! Form::open(['route' => 'qty_adjustment.store', 'method' => 'post', 'files' => true, 'id' => 'adjustment-form']) !!}
                        <div class="row">
                            <div class="col-md-12">
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="card-header d-flex p-0">
                                            <h4>{{trans('file.Import / Export')}}</h4>
                                        </div>
                                        <p class="italic"><small>{{trans('file.The field labels marked with * are required input fields')}}.</small></p>
                                        <div class="form-group">
                                            <label>{{trans('file.Warehouse')}} *</label>
                                            <select required id="warehouse_id" name="warehouse_id" class="selectpicker form-control" data-live-search="true" data-live-search-style="begins" title="Select warehouse...">
                                                @foreach($lims_warehouse_list as $warehouse)
                                                <option value="{{$warehouse->id}}">{{$warehouse->name}}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                        <div class="form-group">
                                            <label>{{trans('file.Attach Document')}}</label>
                                            <input type="file" name="document" class="form-control" >
                                        </div>
                                        <div class="form-group">
                                            <label>{{trans('file.Inventory type')}} *</label>
                                            <select required id="method" name="method" class="selectpicker form-control" data-live-search="true" data-live-search-style="begins" title="{{trans('file.Select inventory type')}}...">
                                                <option selected value="import">{{trans('file.Import')}}</option>
                                                <option value="export">{{trans('file.Export')}}</option>
                                                <option value="transfer">{{trans('file.Transfer')}}</option>
                                                <option value="return">{{trans('file.Import Product Return')}}</option>
                                            </select>
                                        </div>
                                        <div class="form-group d-none" id="select_to_warehouse_id">
                                            <label>{{trans('file.To Warehouse')}} *</label>
                                            <select id="to_warehouse_id" name="to_warehouse_id" class="selectpicker form-control" data-live-search="true" data-live-search-style="begins" title="Select warehouse...">
                                                @foreach($lims_warehouse_list as $warehouse)
                                                <option value="{{$warehouse->id}}">{{$warehouse->name}}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-md-6"> 
                                        <div class="card-header d-flex p-0">
                                            <h4>{{trans('file.Customer Details')}}</h4>
                                        </div>
                                        <p class="italic"><small>{{trans('file.The field labels marked with * are required input fields')}}.</small></p>
                                        <div class="row">
                                            <div class="col-md-12">
                                                <div class="form-group">
                                                    <label>{{trans('file.Phone Number')}} *</label>
                                                    <input type="search" name="customer_phone_number" class="form-control customer-phone-number" autocomplete="new-password" title="{{trans('file.This field is required')}}" required />
                                                    <input type="hidden" name="customer_id" class="customer-id" />
                                                    <span class="validation-msg"></span>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-md-12">
                                                <div class="form-group">
                                                    <label>{{trans('file.customer')}} *</label>
                                                    <input type="text" name="customer_name" class="form-control customer-name" title="{{trans('file.This field is required')}}" required />
                                                    <span class="validation-msg"></span>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-md-12">
                                                <div class="form-group">
                                                    <label>{{trans('file.Email')}} *</label>
                                                    <input type="email" name="customer_email" class="form-control customer-email" title="{{trans('file.This field is required')}}" required />
                                                    <span class="validation-msg"></span>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-md-12">
                                                <div class="form-group">
                                                    <label>{{trans('file.Address')}}</label>
                                                    <input type="text" name="customer_address" class="form-control customer-address" />
                                                    <span class="validation-msg"></span>
                                                </div>
                                            </div>
                                        </div>  
                                    </div>
                                </div>
                                <div class="row mt-3">
                                    <div class="col-md-12">
                                        <label>{{trans('file.Select Product')}}</label>
                                        <div class="search-box input-group">
                                            <button type="button" class="btn btn-secondary btn-lg"><i class="fa fa-barcode"></i></button>
                                            <input type="text" name="product_code_name" id="lims_productcodeSearch" placeholder="Please type product code and select..." class="form-control" />
                                        </div>
                                    </div>
                                </div>
                                <div class="row mt-5">
                                    <div class="col-md-12">
                                        <h5>{{trans('file.Order Table')}} *</h5>
                                        <div class="table-responsive mt-3">
                                            <table id="myTableImport" class="table table-hover order-list order-list-import ">
                                                <thead>
                                                    <tr>
                                                        <th>{{trans('file.name')}}</th>
                                                        <th>{{trans('file.Code')}}</th>
                                                        <th>{{trans('file.Quantity')}}</th>
                                                        <th>{{trans('file.Lot Number')}}</th>
                                                        <th>{{trans('file.Serial Number')}}</th>
                                                        <th>{{trans('file.Batch Number')}}</th>
                                                        <th>{{trans('file.Invoice Number')}}</th>
                                                        <th>{{trans('file.Invoice Date')}}</th>
                                                        <th>{{trans('file.OC Number')}}</th>
                                                        <th>{{trans('file.TR Number')}}</th>
                                                        <th><i class="dripicons-trash"></i></th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                </tbody>
                                                <tfoot class="tfoot active">
                                                    <th colspan="2">{{trans('file.Total')}}</th>
                                                    <th id="total-qty-import" colspan="2">0</th>
                                                    <th colspan="6"></th>
                                                    <th><i class="dripicons-trash"></i></th>
                                                </tfoot>
                                            </table>

                                            <table id="myTableExport" class="table table-hover order-list order-list-export d-none">
                                                <thead>
                                                    <tr>
                                                        <th>{{trans('file.name')}}</th>
                                                        <th>{{trans('file.Code')}}</th>
                                                        <th>{{trans('file.Quantity')}}</th>
                                                        <th>{{trans('file.Lot Number')}}</th>
                                                        <th>{{trans('file.Serial Number')}}</th>
                                                        <th>{{trans('file.Batch Number')}}</th>
                                                        <th>{{trans('file.Invoice Number')}}</th>
                                                        <th>{{trans('file.Invoice Date')}}</th>
                                                        <th>{{trans('file.TR Number')}}</th>
                                                        <th><i class="dripicons-trash"></i></th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                </tbody>
                                                <tfoot class="tfoot active">
                                                    <th colspan="2">{{trans('file.Total')}}</th>
                                                    <th id="total-qty-export" colspan="2">0</th>
                                                    <th colspan="5"></th>
                                                    <th><i class="dripicons-trash"></i></th>
                                                </tfoot>
                                            </table>

                                            <table id="myTableTransfer" class="table table-hover order-list order-list-transfer d-none">
                                                <thead>
                                                    <tr>
                                                        <th>{{trans('file.name')}}</th>
                                                        <th>{{trans('file.Code')}}</th>
                                                        <th>{{trans('file.Quantity')}}</th>
                                                        <th>{{trans('file.Lot Number')}}</th>
                                                        <th>{{trans('file.Serial Number')}}</th>
                                                        <th>{{trans('file.Batch Number')}}</th>
                                                        <th>{{trans('file.OC Number')}}</th>
                                                        <th>{{trans('file.TR Number')}}</th>
                                                        <th><i class="dripicons-trash"></i></th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                </tbody>
                                                <tfoot class="tfoot active">
                                                    <th colspan="2">{{trans('file.Total')}}</th>
                                                    <th id="total-qty-transfer" colspan="2">0</th>
                                                    <th colspan="4"></th>
                                                    <th><i class="dripicons-trash"></i></th>
                                                </tfoot>
                                            </table>

                                            <table id="myTableReturn" class="table table-hover order-list order-list-return d-none">
                                                <thead>
                                                    <tr>
                                                        <th>{{trans('file.name')}}</th>
                                                        <th>{{trans('file.Code')}}</th>
                                                        <th>{{trans('file.Quantity')}}</th>
                                                        <th>{{trans('file.Lot Number')}}</th>
                                                        <th>{{trans('file.Serial Number')}}</th>
                                                        <th>{{trans('file.Batch Number')}}</th>
                                                        <th>{{trans('file.Invoice Number')}}</th>
                                                        <th>{{trans('file.Invoice Date')}}</th>
                                                        <th>{{trans('file.OC Number')}}</th>
                                                        <th>{{trans('file.TR Number')}}</th>
                                                        <th><i class="dripicons-trash"></i></th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                </tbody>
                                                <tfoot class="tfoot active">
                                                    <th colspan="2">{{trans('file.Total')}}</th>
                                                    <th id="total-qty-return" colspan="2">0</th>
                                                    <th colspan="6"></th>
                                                    <th><i class="dripicons-trash"></i></th>
                                                </tfoot>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-2">
                                        <div class="form-group">
                                            <input type="hidden" name="total_qty" />
                                            <input type="hidden" name="item" />
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label>{{trans('file.Note')}}</label>
                                            <textarea rows="5" class="form-control" name="note"></textarea>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <input type="submit" value="{{trans('file.submit')}}" class="btn btn-primary" id="submit-button">
                                </div>
                            </div>
                        </div>
                        {!! Form::close() !!}
                    </div>
                </div>
            </div>
        </div>
    </div>   
</section>
<script type="text/javascript">
	$("ul#inventory").siblings('a').attr('aria-expanded','true');
    $("ul#inventory").addClass("show");
    $("ul#inventory #adjustment-create-menu").addClass("active");
    
    // array data depend on warehouse
    var lims_product_array = [];
    var product_code = [];
    var product_name = [];
    var product_qty = [];

    $('select[name="method"]').on('change', function() {
        var method = $(this).val();
        if(method == "import"){
            $("#myTableImport").removeClass("d-none");
            $("#myTableExport").addClass("d-none");
            $("#myTableTransfer").addClass("d-none");
            $("#myTableReturn").addClass("d-none");
            $("#select_to_warehouse_id").addClass("d-none");
            // xóa thẻ tr khỏi tbody
            $('table.order-list-export tbody tr').empty();
            $('table.order-list-transfer tbody tr').empty();
            $('table.order-list-return tbody tr').empty();
        }
        if(method == "export"){
            $("#myTableExport").removeClass("d-none");
            $("#myTableImport").addClass("d-none");
            $("#myTableTransfer").addClass("d-none");
            $("#myTableReturn").addClass("d-none");
            $("#select_to_warehouse_id").addClass("d-none");
            // xóa thẻ tr khỏi tbody
            $('table.order-list-import tbody tr').empty();
            $('table.order-list-transfer tbody tr').empty();
            $('table.order-list-return tbody tr').empty();
        }
        if(method == "transfer"){
            $("#myTableTransfer").removeClass("d-none");
            $("#myTableExport").addClass("d-none");
            $("#myTableImport").addClass("d-none");
            $("#myTableReturn").addClass("d-none");
            $("#select_to_warehouse_id").removeClass("d-none");
            // xóa thẻ tr khỏi tbody
            $('table.order-list-import tbody tr').empty();
            $('table.order-list-export tbody tr').empty();
            $('table.order-list-return tbody tr').empty();
        }
        if(method == "return"){
            $("#myTableReturn").removeClass("d-none");
            $("#myTableTransfer").addClass("d-none");
            $("#myTableExport").addClass("d-none");
            $("#myTableImport").addClass("d-none");
            $("#select_to_warehouse_id").addClass("d-none");
            // xóa thẻ tr khỏi tbody
            $('table.order-list-import tbody tr').empty();
            $('table.order-list-export tbody tr').empty();
            $('table.order-list-transfer tbody tr').empty();
        }
	});

	$('.selectpicker').selectpicker({
	    style: 'btn-link',
	});

	$('#lims_productcodeSearch').on('input', function(){
	    var warehouse_id = $('#warehouse_id').val();
	    temp_data = $('#lims_productcodeSearch').val();
	    if(!warehouse_id){
	        $('#lims_productcodeSearch').val(temp_data.substring(0, temp_data.length - 1));
	        alert('Please select Warehouse!');
	    }
	});

	$('select[name="warehouse_id"]').on('change', function() {
	    var id = $(this).val();
	    $.get('getproduct/' + id, function(data) {
	        lims_product_array = [];
	        product_code = data[0];
	        product_name = data[1];
	        product_qty = data[2];
	        $.each(product_code, function(index) {
	            lims_product_array.push(product_code[index] + ' (' + product_name[index] + ')');
	        });
	    });
	});

    $('select[name="to_warehouse_id"]').on('change', function() {
	    var warehouse_id = $("#warehouse_id").val()
        var to_warehouse_id = $(this).val()
        if(to_warehouse_id == ""){
            alert("Please select to warehouse!")
            e.preventDefault();
        }
        if(to_warehouse_id == warehouse_id){
            alert("To warehouse is the same as warehouse. Please select to warehouse again!")
            e.preventDefault();
        }
	});

	var lims_productcodeSearch = $('#lims_productcodeSearch');

	lims_productcodeSearch.autocomplete({
	    source: function(request, response) {
	        var matcher = new RegExp(".?" + $.ui.autocomplete.escapeRegex(request.term), "i");
	        response($.grep(lims_product_array, function(item) {
	            return matcher.test(item);
	        }));
	    },
	    response: function(event, ui) {
	        if (ui.content.length == 1) {
	            var data = ui.content[0].value;
	            $(this).autocomplete( "close" );
	            productSearch(data);
	        };
	    },
	    select: function(event, ui) {
	        var data = ui.item.value;
	        productSearch(data);
	    }
	});

    // nhập hàng
	$("#myTableImport").on('input', '.qty', function() {
	    rowindex = $(this).closest('tr').index();
	    checkQuantity($(this).val(), true);
	});

	$("table.order-list-import tbody").on("click", ".ibtnDel", function(event) {
	    rowindex = $(this).closest('tr').index();
	    $(this).closest("tr").remove();
	    calculateTotal();
	});

    // xuất hàng
    $("#myTableExport").on('input', '.qty', function() {
	    rowindex = $(this).closest('tr').index();
	    checkQuantity($(this).val(), true);
	});

	$("table.order-list-export tbody").on("click", ".ibtnDel", function(event) {
	    rowindex = $(this).closest('tr').index();
	    $(this).closest("tr").remove();
	    calculateTotal();
	});

    // chuyển kho
    $("#myTableTransfer").on('input', '.qty', function() {
	    rowindex = $(this).closest('tr').index();
	    checkQuantity($(this).val(), true);
	});

	$("table.order-list-transfer tbody").on("click", ".ibtnDel", function(event) {
	    rowindex = $(this).closest('tr').index();
	    $(this).closest("tr").remove();
	    calculateTotal();
	});

    // hàng trả lại
    $("#myTableReturn").on('input', '.qty', function() {
	    rowindex = $(this).closest('tr').index();
	    checkQuantity($(this).val(), true);
	});

	$("table.order-list-return tbody").on("click", ".ibtnDel", function(event) {
	    rowindex = $(this).closest('tr').index();
	    $(this).closest("tr").remove();
	    calculateTotal();
	});

	$(window).keydown(function(e){
	    if (e.which == 13) {
	        var $targ = $(e.target);
	        if (!$targ.is("textarea") && !$targ.is(":button,:submit")) {
	            var focusNext = false;
	            $(this).find(":input:visible:not([disabled],[readonly]), a").each(function(){
	                if (this === e.target) {
	                    focusNext = true;
	                }
	                else if (focusNext){
	                    $(this).focus();
	                    return false;
	                }
	            });
	            return false;
	        }
	    }
	});

	$('#adjustment-form').on('submit',function(e){
        var method = $("#method").val()
        if(method == "import"){
            var rownumber = $('table.order-list-import tbody tr:last').index();
            if (rownumber < 0) {
                alert("Please insert product to order table!")
                e.preventDefault();
            }
        } 
        if(method == "export"){
            var rownumber = $('table.order-list-export tbody tr:last').index();
            if (rownumber < 0) {
                alert("Please insert product to order table!")
                e.preventDefault();
            }
        } 
        if(method == "transfer"){
            var rownumber = $('table.order-list-transfer tbody tr:last').index();
            if (rownumber < 0) {
                alert("Please insert product to order table!")
                e.preventDefault();
            }

            var warehouse_id = $("#warehouse_id").val()
            var to_warehouse_id = $("#to_warehouse_id").val()
            if(to_warehouse_id == ""){
                alert("Please select to warehouse!")
                e.preventDefault();
            }
            if(to_warehouse_id == warehouse_id){
                alert("To warehouse is the same as warehouse. Please select to warehouse again!")
                e.preventDefault();
            }
        } 
        if(method == "return"){
            var rownumber = $('table.order-list-return tbody tr:last').index();
            if (rownumber < 0) {
                alert("Please insert product to order table!")
                e.preventDefault();
            }
        } 
	});

	function productSearch(data){
		$.ajax({
            type: 'GET',
            url: 'lims_product_search',
            data: {
                data: data
            },
            success: function(data) {
                var method = $("#method").val()
                if(method == "import"){
                    $("input[name='product_code_name']").val('');
                    var newRow = $("<tr>");
                    var cols = '';
                    cols += '<td>' + data[0] + '</td>';
                    cols += '<td>' + data[1] + '</td>';
                    cols += '<td><input type="number" class="form-control qty" name="qty[]" value="1" required step="any" /></td>';
                    cols += '<td><input type="text" class="form-control no-border lot_number" name="lot_number[]" value=""/></td>';
                    cols += '<td><input type="text" class="form-control no-border serial_number" name="serial_number[]" value=""/></td>';
                    cols += '<td><input type="text" class="form-control no-border batch_number" name="batch_number[]" value=""/></td>';
                    cols += '<td><input type="text" class="form-control no-border invoice_number" name="invoice_number[]" value=""/></td>';
                    cols += '<td><input type="text" class="form-control no-border invoice_date" name="invoice_date[]" value=""/></td>';
                    cols += '<td><input type="text" class="form-control no-border oc_number" name="oc_number[]" value=""/></td>';
                    cols += '<td><input type="text" class="form-control no-border tr_number" name="tr_number[]" value=""/></td>';
                    cols += '<td><button type="button" class="ibtnDel btn btn-md btn-danger">{{trans("file.delete")}}</button></td>';
                    cols += '<input type="hidden" class="product-code" name="product_code[]" value="' + data[1] + '"/>';
                    cols += '<input type="hidden" class="product-id" name="product_id[]" value="' + data[2] + '"/>';

                    newRow.append(cols);
                    $("table.order-list-import tbody").append(newRow);
                    $('.invoice_date').datepicker({
                        format: "{{$date_format->js_format}}",
                        autoclose: true,
                        todayHighlight: true
                    });
                    rowindex = newRow.index();
                    calculateTotal();
                }
                if(method == "export"){
                    $("input[name='product_code_name']").val('');
                    var newRow = $("<tr>");
                    var cols = '';
                    cols += '<td>' + data[0] + '</td>';
                    cols += '<td>' + data[1] + '</td>';
                    cols += '<td><input type="number" class="form-control qty" name="qty[]" value="1" required step="any" /></td>';
                    cols += '<td><input type="text" class="form-control no-border lot_number" name="lot_number[]" value=""/></td>';
                    cols += '<td><input type="text" class="form-control no-border serial_number" name="serial_number[]" value=""/></td>';
                    cols += '<td><input type="text" class="form-control no-border batch_number" name="batch_number[]" value=""/></td>';
                    cols += '<td><input type="text" class="form-control no-border invoice_number" name="invoice_number[]" value=""/></td>';
                    cols += '<td><input type="text" class="form-control no-border invoice_date" name="invoice_date[]" value=""/></td>';
                    cols += '<td><input type="text" class="form-control no-border tr_number" name="tr_number[]" value=""/></td>';
                    cols += '<td><button type="button" class="ibtnDel btn btn-md btn-danger">{{trans("file.delete")}}</button></td>';
                    cols += '<input type="hidden" class="product-code" name="product_code[]" value="' + data[1] + '"/>';
                    cols += '<input type="hidden" class="product-id" name="product_id[]" value="' + data[2] + '"/>';
                    cols += '<input type="hidden" class="oc_number" name="oc_number[]" value=""/>';

                    newRow.append(cols);
                    $("table.order-list-export tbody").append(newRow);
                    $('.invoice_date').datepicker({
                        format: "{{$date_format->js_format}}",
                        autoclose: true,
                        todayHighlight: true
                    });
                    rowindex = newRow.index();
                    calculateTotal();
                }
                if(method == "transfer"){
                    $("input[name='product_code_name']").val('');
                    var newRow = $("<tr>");
                    var cols = '';
                    cols += '<td>' + data[0] + '</td>';
                    cols += '<td>' + data[1] + '</td>';
                    cols += '<td><input type="number" class="form-control qty" name="qty[]" value="1" required step="any" /></td>';
                    cols += '<td><input type="text" class="form-control no-border lot_number" name="lot_number[]" value=""/></td>';
                    cols += '<td><input type="text" class="form-control no-border serial_number" name="serial_number[]" value=""/></td>';
                    cols += '<td><input type="text" class="form-control no-border batch_number" name="batch_number[]" value=""/></td>';
                    cols += '<td><input type="text" class="form-control no-border oc_number" name="oc_number[]" value=""/></td>';
                    cols += '<td><input type="text" class="form-control no-border tr_number" name="tr_number[]" value=""/></td>';
                    cols += '<td><button type="button" class="ibtnDel btn btn-md btn-danger">{{trans("file.delete")}}</button></td>';
                    cols += '<input type="hidden" class="product-code" name="product_code[]" value="' + data[1] + '"/>';
                    cols += '<input type="hidden" class="product-id" name="product_id[]" value="' + data[2] + '"/>';
                    cols += '<input type="hidden" class="invoice_number" name="invoice_number[]" value=""/>';
                    cols += '<input type="hidden" class="invoice_date" name="invoice_date[]" value=""/>';

                    newRow.append(cols);
                    $("table.order-list-transfer tbody").append(newRow);
                    rowindex = newRow.index();
                    calculateTotal();
                }
                if(method == "return"){
                    $("input[name='product_code_name']").val('');
                    var newRow = $("<tr>");
                    var cols = '';
                    cols += '<td>' + data[0] + '</td>';
                    cols += '<td>' + data[1] + '</td>';
                    cols += '<td><input type="number" class="form-control qty" name="qty[]" value="1" required step="any" /></td>';
                    cols += '<td><input type="text" class="form-control no-border lot_number" name="lot_number[]" value=""/></td>';
                    cols += '<td><input type="text" class="form-control no-border serial_number" name="serial_number[]" value=""/></td>';
                    cols += '<td><input type="text" class="form-control no-border batch_number" name="batch_number[]" value=""/></td>';
                    cols += '<td><input type="text" class="form-control no-border invoice_number" name="invoice_number[]" value=""/></td>';
                    cols += '<td><input type="text" class="form-control no-border invoice_date" name="invoice_date[]" value=""/></td>';
                    cols += '<td><input type="text" class="form-control no-border oc_number" name="oc_number[]" value=""/></td>';
                    cols += '<td><input type="text" class="form-control no-border tr_number" name="tr_number[]" value=""/></td>';
                    cols += '<td><button type="button" class="ibtnDel btn btn-md btn-danger">{{trans("file.delete")}}</button></td>';
                    cols += '<input type="hidden" class="product-code" name="product_code[]" value="' + data[1] + '"/>';
                    cols += '<input type="hidden" class="product-id" name="product_id[]" value="' + data[2] + '"/>';

                    newRow.append(cols);
                    $("table.order-list-return tbody").append(newRow);
                    $('.invoice_date').datepicker({
                        format: "{{$date_format->js_format}}",
                        autoclose: true,
                        todayHighlight: true
                    });
                    rowindex = newRow.index();
                    calculateTotal();
                }
            }
        });
	}

	function checkQuantity(qty) {
        var method = $("#method").val()
        if(method == "import"){
            var row_product_code = $('table.order-list-import tbody tr:nth-child(' + (rowindex + 1) + ')').find('td:nth-child(2)').text();
            var action = $('table.order-list-import tbody tr:nth-child(' + (rowindex + 1) + ')').find('.act-val').val();
            var pos = product_code.indexOf(row_product_code);

            if ( (qty > parseFloat(product_qty[pos])) && (action == '-') ) {
                alert('Quantity exceeds stock quantity!');
                var row_qty = $('table.order-list-import tbody tr:nth-child(' + (rowindex + 1) + ')').find('.qty').val();
                row_qty = row_qty.substring(0, row_qty.length - 1);
                $('table.order-list-import tbody tr:nth-child(' + (rowindex + 1) + ')').find('.qty').val(row_qty);
            }
            else {
                $('table.order-list-import tbody tr:nth-child(' + (rowindex + 1) + ')').find('.qty').val(qty);
            }
            calculateTotal();
        } 
        if(method == "export"){
            var row_product_code = $('table.order-list-export tbody tr:nth-child(' + (rowindex + 1) + ')').find('td:nth-child(2)').text();
            var action = $('table.order-list-export tbody tr:nth-child(' + (rowindex + 1) + ')').find('.act-val').val();
            var pos = product_code.indexOf(row_product_code);

            if ( (qty > parseFloat(product_qty[pos])) && (action == '-') ) {
                alert('Quantity exceeds stock quantity!');
                var row_qty = $('table.order-list-export tbody tr:nth-child(' + (rowindex + 1) + ')').find('.qty').val();
                row_qty = row_qty.substring(0, row_qty.length - 1);
                $('table.order-list-export tbody tr:nth-child(' + (rowindex + 1) + ')').find('.qty').val(row_qty);
            }
            else {
                $('table.order-list-export tbody tr:nth-child(' + (rowindex + 1) + ')').find('.qty').val(qty);
            }
            calculateTotal();
        }
        if(method == "transfer"){
            var row_product_code = $('table.order-list-transfer tbody tr:nth-child(' + (rowindex + 1) + ')').find('td:nth-child(2)').text();
            var action = $('table.order-list-transfer tbody tr:nth-child(' + (rowindex + 1) + ')').find('.act-val').val();
            var pos = product_code.indexOf(row_product_code);

            if ( (qty > parseFloat(product_qty[pos])) && (action == '-') ) {
                alert('Quantity exceeds stock quantity!');
                var row_qty = $('table.order-list-transfer tbody tr:nth-child(' + (rowindex + 1) + ')').find('.qty').val();
                row_qty = row_qty.substring(0, row_qty.length - 1);
                $('table.order-list-transfer tbody tr:nth-child(' + (rowindex + 1) + ')').find('.qty').val(row_qty);
            }
            else {
                $('table.order-list-transfer tbody tr:nth-child(' + (rowindex + 1) + ')').find('.qty').val(qty);
            }
            calculateTotal();
        }
        if(method == "return"){
            var row_product_code = $('table.order-list-return tbody tr:nth-child(' + (rowindex + 1) + ')').find('td:nth-child(2)').text();
            var action = $('table.order-list-return tbody tr:nth-child(' + (rowindex + 1) + ')').find('.act-val').val();
            var pos = product_code.indexOf(row_product_code);

            if ( (qty > parseFloat(product_qty[pos])) && (action == '-') ) {
                alert('Quantity exceeds stock quantity!');
                var row_qty = $('table.order-list-return tbody tr:nth-child(' + (rowindex + 1) + ')').find('.qty').val();
                row_qty = row_qty.substring(0, row_qty.length - 1);
                $('table.order-list-return tbody tr:nth-child(' + (rowindex + 1) + ')').find('.qty').val(row_qty);
            }
            else {
                $('table.order-list-return tbody tr:nth-child(' + (rowindex + 1) + ')').find('.qty').val(qty);
            }
            calculateTotal();
        } 
	}

	function calculateTotal() {
        var method = $("#method").val()
        if(method == "import"){
            var total_qty = 0;
            $(".qty").each(function() {
                if ($(this).val() == '') {
                    total_qty += 0;
                } else {
                    total_qty += parseFloat($(this).val());
                }
            });
            $("#total-qty-import").text(total_qty);
            $('input[name="total_qty"]').val(total_qty);
            $('input[name="item"]').val($('table.order-list-import tbody tr:last').index() + 1);
        } 
        if(method == "export"){
            var total_qty = 0;
            $(".qty").each(function() {
                if ($(this).val() == '') {
                    total_qty += 0;
                } else {
                    total_qty += parseFloat($(this).val());
                }
            });
            $("#total-qty-export").text(total_qty);
            $('input[name="total_qty"]').val(total_qty);
            $('input[name="item"]').val($('table.order-list-export tbody tr:last').index() + 1);
        }
        if(method == "transfer"){
            var total_qty = 0;
            $(".qty").each(function() {
                if ($(this).val() == '') {
                    total_qty += 0;
                } else {
                    total_qty += parseFloat($(this).val());
                }
            });
            $("#total-qty-transfer").text(total_qty);
            $('input[name="total_qty"]').val(total_qty);
            $('input[name="item"]').val($('table.order-list-transfer tbody tr:last').index() + 1);
        }
        if(method == "return"){
            var total_qty = 0;
            $(".qty").each(function() {
                if ($(this).val() == '') {
                    total_qty += 0;
                } else {
                    total_qty += parseFloat($(this).val());
                }
            });
            $("#total-qty-return").text(total_qty);
            $('input[name="total_qty"]').val(total_qty);
            $('input[name="item"]').val($('table.order-list-return tbody tr:last').index() + 1);
        } 
    }
    
    $('.customer-phone-number').autocomplete({
        source: function (request, response) {
            $.ajax({
                url: '{{route('customer.search')}}',
                type: 'GET',
                dataType: "json",
                data: {
                    phone: request.term,
                },
                success: function (data) {
                    response(data.customers);
                }
            });
        },
        select: function (event, ui) {
            // Update data for customer
            var customer = ui.item;
            $('.customer-id').val(customer.id);
            $('.customer-phone-number').val(customer.phone_number).data('default', customer.phone_number);
            $('.customer-name').val(customer.name).prop('disabled', true);
            $('.customer-email').val(customer.email).prop('disabled', true);
            $('.customer-address').val(customer.address).prop('disabled', true);
            return false;
        }
    }).autocomplete("instance")._renderItem = function (ul, item) {
        return $("<li>")
            .append("<div>" + item.phone_number + "</div>")
            .appendTo(ul);
    };

    $(document).on('input', '.customer-phone-number', function (e) {
        var originPhoneNumber = $(this).data('default');
        if($(this).val() != originPhoneNumber && originPhoneNumber != '') {
            $('.customer-id').val('');
            $('.customer-name').val('').prop('disabled', false);
            $('.customer-email').val('').prop('disabled', false);
            $('.customer-address').val('').prop('disabled', false);
        }
    });
</script>
@endsection

Youez - 2016 - github.com/yon3zu
LinuXploit