@extends('layouts.app')
@section('title', __('tpsTransfer::lang.receive'))

@section('content')
    <div id="block-waiting-div" style="display:none;">
        <h3>{{__('tpsTransfer::lang.inserting_data')}}</h3>
    </div>
    <link rel="stylesheet" href="https://cdn.datatables.net/rowgroup/1.1.4/css/rowGroup.dataTables.min.css">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>@lang('tpsTransfer::lang.receive_products')
            <small>@lang('tpsTransfer::lang.receive_transfer_stage')</small>
        </h1>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                @component('components.filters', ['title' => __('report.filters')])
                    <div class="col-md-3">
                        <div class="form-group">
                            {!! Form::label('type', __('product.product_type') . ':') !!}
                            {!! Form::select('type', ['single' => __('lang_v1.single'), 'variable' => __('lang_v1.variable'), 'combo' => __('lang_v1.combo')], null, ['class' => 'form-control select2', 'style' => 'width:100%', 'id' => 'type', 'placeholder' => __('lang_v1.all')]); !!}
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            {!! Form::label('category_id', __('product.category') . ':') !!}
                            {!! Form::select('category_id', $categories, null, ['class' => 'form-control select2', 'style' => 'width:100%', 'id' => 'category_id', 'placeholder' => __('lang_v1.all')]); !!}
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            {!! Form::label('sub_category_id', __('product.sub_category') . ':') !!}
                            {!! Form::select('sub_category_id', [], [], ['class' => 'form-control select2', 'style' => 'width:100%', 'id' => 'sub_category_id']); !!}
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            {!! Form::label('brand_id', __('product.brand') . ':') !!}
                            {!! Form::select('brand_id', $brands, null, ['class' => 'form-control select2', 'style' => 'width:100%', 'id' => 'brand_id', 'placeholder' => __('lang_v1.all')]); !!}
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            {!! Form::label('from_location_id',  __('tpsTransfer::lang.from').__('purchase.business_location') . ':') !!}
                            {!! Form::select('from_location_id', $fromBusinessLocations, null, ['id' => 'from_location_id', 'class' => 'form-control select2 main-inputs', 'style' => 'width:100%']); !!}
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            {!! Form::label('to_location_id',  'To '.__('purchase.business_location') . ':') !!}
                            {!! Form::select('to_location_id', [], null, ['id' => 'to_location_id', 'class' => 'form-control select2 main-inputs', 'style' => 'width:100%']); !!}
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            {!! Form::label('shipping_id',  'Shipping No :') !!}
                            {!! Form::select('shipping_id', [], null, ['id' => 'shipping_id', 'class' => 'form-control select2 main-inputs', 'style' => 'width:100%']); !!}
                        </div>
                    </div>
                @endcomponent
            </div>
        </div>
        @component('components.widget', ['class' => 'box-primary', 'title' => __('tpsTransfer::lang.receive_products')])
            @php
                $colspan = 12;
                $custom_labels = json_decode(session('business.custom_labels'), true);
            @endphp
            <table class="table table-bordered table-striped ajax_view hide-footer" id="receive_data" style="width: 100%;">
                <thead>
                <tr>
                    <th><input type="checkbox" id="selectAll" data-table-id="receive_data"></th>
                    <th>@lang('sale.product')</th>
                    <th>@lang('lang_v1.lot_number')</th>
                    <th>@lang('product.sku')</th>
                    <th>@lang('product.category')</th>
{{--                    <th>@lang('product.sub_category')</th>--}}
                    <th>@lang('product.brand')</th>
                    @can('view_purchase_price')
                        @php
                            $colspan += 2;
                        @endphp
                        <th>@lang('tpsTransfer::lang.avg_unit_purchase_price')</th>
                        <th>{{__('tpsTransfer::lang.shipping_price_per_unit')}}</th>
                    @endcan
                    <th>{{__('tpsTransfer::lang.from')}} @lang('purchase.business_location') @show_tooltip(__('lang_v1.product_business_location_tooltip'))</th>
                    <th>@lang('lang_v1.stock_transfer')</th>
                    <th>{{__('tpsTransfer::lang.to')}} @lang('purchase.business_location') @show_tooltip(__('lang_v1.product_business_location_tooltip'))</th>

                    <th>@lang('lang_v1.date')</th>
                    <th>@lang('messages.action')</th>
                </tr>
                </thead>
            </table>
            <div class="form-group text-center">
                @if (auth()->user()->can('tpsTransfer.can_delete_nst_row'))
                    <button type="button" class="btn btn-danger " data-toggle="modal" data-target="#delete_selected_confirm">{{__('tpsTransfer::lang.delete_selected_data')}}</button>
                @endif
                <button id="update-receive-products" class="btn btn-primary btn-flat btn-login">@lang('messages.save')</button>
                <button id="receive-products" class="btn btn-primary btn-flat btn-login">{{__('tpsTransfer::lang.save_and_set_as_complete')}}</button>
                <span class="btn btn-primary btn-flat btn-login add-shipping">{{__('tpsTransfer::lang.add_shipping')}}</span>
            </div>
        @endcomponent
    </section>
    <!-- /.content -->

    <!-- Notes Modal -->
    <div class="modal fade" id="add_notes" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title">{{__('purchase.additional_notes')}}</h4>
                </div>
                <div class="modal-body">
                    <textarea rows='5' style="width:100%;" id="notes_content" name=""></textarea>
                </div>
                <div class="modal-footer">
                    <div class='text-center'>
                        <button type="button" class="btn btn-default" data-dismiss="modal">{{__('messages.close')}}</button>
                        <button type="button" data-id="" data-dismiss="modal" class="btn btn-info save_notes_button" id="save_notes_button">{{__('messages.save')}}</button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    @if (auth()->user()->can('tpsTransfer.can_delete_nst_row'))
        <!-- Delete Confirm Modal -->
        <div class="modal fade" id="delete_confirm" role="dialog">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">{{ __('tpsTransfer::lang.confirm_delete') }}</h4>
                    </div>
                    <div class="modal-body">
                        <h3>{!! __('tpsTransfer::lang.confirm_delete_message') !!}</h3>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">{{__('messages.close')}}</button>
                        <button type="button" data-dismiss="modal" class="btn btn-danger confirm_delete_row_button" id="delete_row_button">{{__('messages.delete')}}</button>
                    </div>
                </div>
            </div>
        </div>
    @endif

    @if (auth()->user()->can('tpsTransfer.can_delete_nst_row'))
        <!-- Delete All Data Confirm Modal -->
        <div class="modal fade" id="delete_selected_confirm" role="dialog">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">{{ __('tpsTransfer::lang.confirm_delete_selected_data') }}</h4>
                    </div>
                    <div class="modal-body">
                        <h3>{!! __('tpsTransfer::lang.confirm_delete_selected_data_message') !!}</h3>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">{{__('messages.close')}}</button>
                        <button type="button" data-dismiss="modal" class="btn btn-danger" id="confirm_delete_selected_data_button">{{__('messages.delete')}}</button>
                    </div>
                </div>
            </div>
        </div>
    @endif

    <!-- Add Shipping Modal -->
    <div class="modal fade" id="add_shipping" tabindex="-1" role="dialog">
        <div class="modal-dialog modal-xl" role="document">
            <div class="modal-content">
                {!! Form::open(['id' => 'add_shipping_table_form' ]) !!}
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="modalTitle">{{__('tpsTransfer::lang.add_shipping')}}</h4>
                </div>
                <div class="modal-body" id="add_shipping_modal_body">
                </div>
                <div class="modal-footer">
                    <div class='text-center'>
                        <span id="confirm_shipping_modal_button" class="btn btn-primary">{{__('tpsTransfer::lang.save_and_set_as_complete')}}</span>
                        <button type="button" class="btn btn-default" data-dismiss="modal">@lang( 'messages.close' )</button>
                    </div>
                </div>
                {!! Form::close() !!}

            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div>
    <!-- Product info modal -->
    <div class="modal fade" tabindex="-1" role="dialog" id="view_product_modal">
    </div>
@endsection

@section('javascript')
    <script src="https://malsup.github.io/jquery.blockUI.js"></script>
    <script src="https://cdn.datatables.net/rowgroup/1.1.4/js/dataTables.rowGroup.min.js"></script>
    <script src="{{ asset('js/product.js?v=' . $asset_v) }}"></script>
    <script src="{{ asset('js/opening_stock.js?v=' . $asset_v) }}"></script>

    <script type="text/javascript">
        let receiveTpsData = new Object();
        let receiveDoneTpsData = new Object();

        $(document).ready(function () {
            __select2($('.select2'));

            receive_data = $('#receive_data').DataTable({
                aaSorting: [],
                rowGroup: {
                    dataSrc: function(data) {
                        return data.product_name+'-'+data.sku
                    },
                    startRender: function ( rows, group ) {
                        return '<a onclick="callCoreProductInfoModal(this)" data-href="'+rows.data()[0]['data-href']+'">'+group+'</a>';
                    }
                },
                processing: true,
                serverSide: true,
                scrollY: "130vh",
                scrollX: true,
                scrollCollapse: true,
                ajax: {
                    "url": "{{action('\Modules\AdvancedTransfer\Http\Controllers\TpsReceiveStockController@table')}}",
                    "type": "POST",
                    "data": function (d) {
                        d.type = $('#type').val();
                        d.category_id = $('#category_id').val();
                        d.sub_category_id = $('#sub_category_id').val();
                        d.brand_id = $('#brand_id').val();
                        d.from_location_id = $('#from_location_id').val();
                        d.to_location_id = $('#to_location_id').val();
                        d.shipping_id = $('#shipping_id').val();
                        d = __datatable_ajax_callback(d);
                    }
                },
                columnDefs: [ {
                    "targets": [0],
                    "orderable": false,
                    "searchable": false
                } ],
                columns: [
                    {data: 'row_checkbox', sortable: false, searchable: false, className: "selectable_td input"},
                    {data: 'product_name', name: 'products.name'},
                    {data: 'lot_number', name: 'purchase_lines.lot_number', className: "selectable_td"},
                    {data: 'sku', name: 'products.sku', className: "selectable_td"},
                    {data: 'category', name: 'c1.name', className: "selectable_td"},
                    // {data: 'sub_category', name: 'c2.name', className: "selectable_td"},
                    {data: 'brand', name: 'brands.name', className: "selectable_td"},
                        @can('view_purchase_price')
                    { data: 'purchase_price', name: 'purchase_lines.purchase_price', searchable: false, className: "selectable_td"},
                    { data: 'value_per_unit', name: 'value_per_unit', searchable: false, className: "selectable_td"},
                        @endcan
                    {data: 'from_location_name', name: 'from_business_locations.name', className: "selectable_td"},
                    {data: 'transfer_quantity_input', sortable: false, searchable: false, className: "clickable_td"},
                    {data: 'to_location_name', name: 'to_business_locations.name', className: "selectable_td"},
                    {data: 'created_at', name: 'created_at'},
                    {data: 'actions', name: 'actions', sortable: false, searchable: false, className: "button"},
                ],
                lengthMenu: [[10, 25, 50, 200, 500], [10, 25, 50, 200, 500]],
                rowCallback: function (row, data) {
                    // write old inputs
                    if(receiveTpsData[data['id']]){
                        if(receiveTpsData[data['id']]['accepted']){
                            checkbox = $(row).find('input[type=checkbox]');
                            $(row).find('input[type="checkbox"]').prop('checked', true);
                            $(row).addClass("selected");
                        }

                        if(receiveTpsData[data['id']]['transfer_quantity']){
                            $(row).find('input[type="number"]').val(receiveTpsData[data['id']]['transfer_quantity']);
                        }

                        if(receiveTpsData[data['id']]['is_important'] == 1){
                            $(row).addClass("bg-yellow");
                        }

                        if(receiveTpsData[data['id']]['note']){
                            if (receiveTpsData[data['id']]['note'] != "") {
                                $(row).find('#actions_btn_'+data['id']).addClass("btn-success")
                            } else {
                                $(row).find('#actions_btn_'+data['id']).removeClass("btn-success")
                            }
                        }
                    }else{
                        receiveTpsData[data['id']] = {};
                        receiveTpsData[data['id']]['transfer_quantity'] = data['transfer_quantity'];
                        receiveTpsData[data['id']]['is_important'] = data['is_important'];
                        receiveTpsData[data['id']]['note'] = data['note'];
                        receiveTpsData[data['id']]['purchase_price'] = data['purchase_price'];

                        if(data['is_important'] == 1){
                            $(row).addClass("bg-yellow");
                        }

                        if(data['note']){
                            $(row).find('#actions_btn_'+data['id']).addClass("btn-success")
                        }
                    }
                },
            });

            // delete all data if from location || to location || shipping ID changed
            $(document).on('change', '#from_location_id, #to_location_id, #shipping_id', function(){
                if(receiveTpsData){
                    for (let key in receiveTpsData) delete receiveTpsData[key]
                }
                if(receiveDoneTpsData){
                    for (let key in receiveDoneTpsData) delete receiveDoneTpsData[key]
                }
            });

            $(document).on('change', '#type, #category_id, #sub_category_id, #brand_id, #from_location_id, #to_location_id, #shipping_id', function(){
                $('#receive_data').DataTable().ajax.reload();
            });

            $('#receive_data tbody').on('click', 'tr td.selectable_td:not(".input")', function () {
                checkbox = $(this).parent().find('input[type=checkbox]');
                checkbox.prop("checked", !checkbox.prop("checked")).change();
            });

            // Return add shipping modal content
            $(document).on("click", ".add-shipping", function (e) {
                e.preventDefault();
                $.ajax({
                    type: 'POST',
                    url: '{{action('\Modules\AdvancedTransfer\Http\Controllers\TpsPrepareStockController@addShippingModal')}}',
                    data: {
                        tpsData: receiveDoneTpsData,
                    },
                    success: function (response) {
                        // Add response in Modal body
                        $('#add_shipping_modal_body').html(response);

                        // Display Modal
                        $("#add_shipping").modal('show');
                    }
                });

            });
        });

        $(document).on("keyup change", ".transfer_quantity", function () {
            // Get value of input, max and min
            var current = $(this).val();
            var max = parseInt($(this).attr("max"));

            // Compare the max and min with the current value
            if (current <= max) {
                return;
            } else {
                value = $(this).val(max)
            }
        });

        $(document).on('change', '#category_id',function () {
            var category = $(this).val();
            var none = '{{__("lang_v1.none")}}'

            if(category == ''){
                $('#sub_category_id').html('<option value="">'+none+'</option>')
            }
        });

        $(document).on("change", ".product-row-input", function () {
            id = $(this).data('id');
            name = $(this).data('name');
            var tr = $(this).closest('tr');

            if(!receiveTpsData[id]){
                receiveTpsData[id] = {};
            }
            if(name == 'transfer_quantity'){
                receiveTpsData[id]["transfer_quantity"] = $(this).val();
            }else if(name == 'accepted'){
                if($(this).is(":checked")){
                    receiveTpsData[id][name] = 1;
                    receiveDoneTpsData[id] = receiveTpsData[id];
                    tr.addClass('selected');
                }else{
                    receiveTpsData[id][name] = 0;
                    delete receiveDoneTpsData[id];
                    tr.removeClass('selected');
                }
            }
        });

        $(document).on("click", ".delete_row_button", function () {
            id = $(this).data('id');
            $("#delete_row_button").attr('data-id',id);
        });

        $(document).on("click", ".confirm_delete_row_button", function () {
            // Delete row from receive table by id
            $.ajax({
                type: 'DELETE',
                url: "{{ action('\Modules\AdvancedTransfer\Http\Controllers\TpsReceiveStockController@destroy') }}",
                data: {
                    _token: $("meta[name='csrf-token']").attr("content"),
                    id: $("#delete_row_button").attr('data-id'),
                },
                success: function(r) {
                    // console.log('success')
                    if((r.status) && (r.status == 'success')){
                        $('#receive_data').DataTable().ajax.reload();
                    }else{
                        let msg
                        $.unblockUI();
                        if(r.msg){
                            msg = r.msg
                        }else{
                            msg = '{{__('tpsTransfer::lang.an_error_has_been_occurred')}}'
                        }
                        toastr.error(msg);
                    }
                },
            });
        });

        $(document).on("click", "#confirm_delete_selected_data_button", function () {
            // Delete row from prepare table by id
            $.ajax({
                type: 'DELETE',
                url: '{{action('\Modules\AdvancedTransfer\Http\Controllers\TpsReceiveStockController@destroySelected')}}',
                data: {
                    _token: $("meta[name='csrf-token']").attr("content"),
                    receiveDoneTpsData: receiveDoneTpsData,
                },
                success: function(r) {
                    // console.log('success')
                    if((r.status) && (r.status == 'success')){
                        $('#receive_data').DataTable().ajax.reload();
                    }else{
                        let msg
                        $.unblockUI();
                        if(r.msg){
                            msg = r.msg
                        }else{
                            msg = '{{__('tpsTransfer::lang.an_error_has_been_occurred')}}'
                        }
                        toastr.error(msg);
                    }
                },
            });
        });

        $(document).on("click", ".add_notes", function () {
            id = $(this).data('id');
            $("#save_notes_button").attr('data-id',id);

            if((receiveTpsData[id]) && (receiveTpsData[id]['note']) ){
                $("#notes_content").val(receiveTpsData[id]['note']);
            }
        });

        // Update receive products
        $(document).on("click", "#update-receive-products", function (e) {
            // Prevent actual form submission
            e.preventDefault();
            $.blockUI({ message: '{{__('tpsTransfer::lang.preparing_data')}}' });

            $('#receive_data').DataTable().page.len( -1 ).ajax.reload( function() { //todo need test
                $.blockUI({ message: '{{__('tpsTransfer::lang.inserting_data')}}' });

                // Send data by ajax to server side to start auto process and return with products and qty
                $.ajax({
                    type: 'PUT',
                    url: '{{action('\Modules\AdvancedTransfer\Http\Controllers\TpsReceiveStockController@update')}}',
                    data: {
                        _token: $("meta[name='csrf-token']").attr("content"),
                        receiveDoneTpsData: receiveDoneTpsData,
                    },
                    beforeSend: function() {
                        requestWaitingMessage()
                        $.blockUI({ message: $('#block-waiting-div') });
                    },
                    success: function(r) {
                        // console.log('success')
                        if((r.status) && (r.status == 'success')){
                            $.unblockUI();
                            window.location.href = "{{ action('\Modules\AdvancedTransfer\Http\Controllers\TpsReceiveStockController@index') }}";
                        }else{
                            let msg
                            $.unblockUI();
                            if(r.msg){
                                msg = r.msg
                            }else{
                                msg = '{{__('tpsTransfer::lang.an_error_has_been_occurred')}}'
                            }
                            toastr.error(msg);
                        }
                    },
                    error: function(xhr) { // if error occurred
                        $.unblockUI();
                        toastr.error('{{__('tpsTransfer::lang.an_error_has_been_occurred')}}');
                    }
                });
            })
        });

        $(document).on("click",".save_notes_button",function(){
            content = $("#notes_content").val();
            $("#notes_content").val('');

            id = $("#save_notes_button").attr('data-id');
            receiveTpsData[id]["note"] = content;

            if (content != "") {
                $("#actions_btn_"+id).addClass("btn-success");
            } else {
                $("#actions_btn_"+id).removeClass("btn-success");
            }
        })

        // Check/uncheck all rows
        $('#selectAll').click(function () {
            $('.product-row-input').prop('checked', $(this).is(":checked")).change()
        });

        // Get product info
        function callCoreProductInfoModal(el) {
            $.ajax({
                url: $(el).data('href'),
                dataType: 'html',
                success: function(result) {
                    $('#view_product_modal').html(result).modal('show');
                },
            });

        }

        function requestWaitingMessage(){
            var seconds = 31;
            handle = setInterval(function() {
                --seconds;
                $('#block-waiting-div').html('<h3>{{__('tpsTransfer::lang.less_than')}}'+seconds+'</h3>');

                if(seconds <= 0){
                    clearInterval(handle);
                    $('#block-waiting-div').html('<h3>{{ __('tpsTransfer::lang.validating_data') }}</h3>');
                }
            }, 1000);
        };

        $(document).on('shown.bs.modal', 'div.view_product_modal, div.view_modal, #view_product_modal',
            function(){
                var div = $(this).find('#view_product_stock_details');
                if (div.length) {
                    $.ajax({
                        url: "{{action('\App\Http\Controllers\ReportController@getStockReport')}}"  + '?for=view_product&product_id=' + div.data('product_id'),
                        dataType: 'html',
                        success: function(result) {
                            div.html(result);
                            __currency_convert_recursively(div);
                        },
                    });
                }
                __currency_convert_recursively($(this));
            });

        $(document).on("click", "#receive-products", function (e) {
            // Prevent actual form submission
            e.preventDefault();
            $.blockUI({ message: '{{__('tpsTransfer::lang.preparing_data')}}' });

            $('#receive_data').DataTable().page.len( -1 ).ajax.reload( function() { //todo need test
                $.blockUI({ message: '{{__('tpsTransfer::lang.inserting_data')}}' });

                // Send data by ajax to server side to start auto process and return with products and qty
                $.ajax({
                    type: 'PUT',
                    url: '{{action('\Modules\AdvancedTransfer\Http\Controllers\TpsReceiveStockController@receive')}}',
                    data: {
                        _token: $("meta[name='csrf-token']").attr("content"),
                        receiveDoneTpsData: receiveDoneTpsData,
                        from_location_id: $('#from_location_id').val(),
                        to_location_id: $('#to_location_id').val(),
                        shipping_id: $('#shipping_id').val(),
                    },
                    beforeSend: function() {
                        requestWaitingMessage()
                        $.blockUI({ message: $('#block-waiting-div') });
                    },
                    success: function(r) {
                        // console.log('success')
                        if((r.status) && (r.status == 'success')){
                            $.unblockUI();
                            window.location.href = "{{ action('\Modules\AdvancedTransfer\Http\Controllers\TpsReceiveStockController@index') }}";
                        }else{
                            let msg
                            $.unblockUI();
                            if(r.msg){
                                msg = r.msg
                            }else{
                                msg = '{{__('tpsTransfer::lang.an_error_has_been_occurred')}}'
                            }
                            toastr.error(msg);
                        }
                    },
                    error: function(xhr) { // if error occurred
                        $.unblockUI();
                        toastr.error('{{__('tpsTransfer::lang.an_error_has_been_occurred')}}');
                        return;
                    }
                });
            })
        });

        jQuery(function($) {
            $('#from_location_id').on('change', function(e) {
                // Prevent actual form submission
                e.preventDefault();

                var from_location_id = $('#from_location_id').val();
                $.ajax({
                    method: 'POST',
                    url: '{{action('\Modules\AdvancedTransfer\Http\Controllers\TpsController@getToLocationByFromLocationId')}}',
                    dataType: 'html',
                    data: { from_location_id: from_location_id, status: 'receive' },
                    success: function(result) {
                        if (result) {
                            $('#to_location_id').html(result).change();
                        }
                    },
                });
            }).trigger('change');
        });

        jQuery(function($) {
            $('#to_location_id').on('change', function(e) {
                // Prevent actual form submission
                e.preventDefault();

                var from_location_id = $('#from_location_id').val();
                if(!from_location_id){
                    return
                }
                var to_location_id = $('#to_location_id').val();
                if(!to_location_id){
                    return
                }
                $.ajax({
                    method: 'POST',
                    url: '{{action('\Modules\AdvancedTransfer\Http\Controllers\TpsController@getShippingIdsWithLocations')}}',
                    dataType: 'html',
                    data: { from_location_id: from_location_id, to_location_id: to_location_id, status: 'receive', preAppendNone: true },
                    success: function(result) {
                        if (result) {
                            $('#shipping_id').html(result).change();
                        }
                    },
                });
            }).trigger('change');
        });
    </script>
@endsection
