 <?php $__env->startSection('content'); ?>
    <style>
        .btn-search {
            margin-top: -20px !important;
            right: 0px !important;
        }
    </style>
    <?php Fun::lang()?>

    <div class="page">
        <div class=container>
            <div class="top-content">
                <div class="row">
                    <div class="col-sm-12 col-xs-12">
                        <div class="title-add">
                            <div class="pull-left">
                                <h3><?php echo e(__('administrator.stock_return')); ?></h3>
                            </div>

                        </div>
                    </div>
                </div>
            </div>

            <?php echo Form::open(array('route' => 'adjustment.store','method'=>'POST','enctype'=>'multipart/form-data')); ?>

            <div class="row">
                <div class="col-sm-12">
                    <div class="master-form">
                        <div class="title-note">
                            <h3><span class="fa fa-exclamation-triangle"></span> <?php echo e(__('administrator.stock_return')); ?>

                                <i>(<?php echo e(__('administrator.fields_in_red_are_required')); ?>)</i></h3>
                        </div>
                        <div class="form-group col-sm-12 col-xs-6">
                            <div class="col-sm-2 col-xs-12 ">
                                <label for="name" class="required"><?php echo e(__('administrator.date')); ?></label>
                            </div>
                            <div class="col-sm-9">
                                <?php echo Form::text('adjustment_date', date('d-m-Y'), ['class' => 'form-control date_picker']); ?>

                            </div>
                        </div>
                        <div class="form-group col-sm-12 col-xs-6">
                            <div class="col-sm-2 col-xs-12 ">
                                <label for="name" class="required"><?php echo e(__('administrator.reference')); ?></label>
                            </div>
                            <div class="col-sm-9">
                                <?php echo Form::text('reference', null, ['class' => 'form-control']); ?>

                            </div>
                        </div>

                        <div class="form-group col-sm-12 col-xs-12">
                            <div class="col-sm-2 col-xs-12 ">

                            </div>
                            <div class="col-sm-9 col-xs-12 ">
                                <?php echo Form::text('bar_code', null, array('placeholder' => __('administrator.barcode'),'class' => 'form-control')); ?>

                                <div id="autocomplete" class="col-sm-12"
                                     style="position: absolute; z-index: 99;left: -12px">
                                </div>
                                <span class="btn-search btn btn-sm btn-success"><i class="fa fa-search"></i></span>
                            </div>
                        </div>

                        <table id="datatable_balances" width="100%" class="table table-striped table-hover ">
                            <thead>
                            <tr>
                                <th>#</th>
                                <th><?php echo e(__('administrator.code')); ?></th>
                                <th><?php echo e(__('administrator.product')); ?></th>
                                <th><?php echo e(__('administrator.qty')); ?></th>
                                <th><?php echo e(__('administrator.unit')); ?></th>
                                <th><?php echo e(__('administrator.type')); ?></th>
                                <th><?php echo e(__('administrator.qty')); ?></th>
                                <th><?php echo e(__('administrator.action')); ?></th>
                            </tr>
                            </thead>
                            <tbody id="tbody">

                            </tbody>
                        </table>

                        <div class="col-sm-12 col-xs-12">
                            <div class="form-group footer-save">
                                <button type="submit" class=" button_primary pull-right"><span
                                            class="fa fa-save"></span> <?php echo e(__('administrator.save')); ?></button>
                                <button type="button" onClick="history.go(-1)"
                                        class=" button_warning pull-right">
                                    <span class=" fa fa-arrow-circle-left"></span> <?php echo e(__('administrator.back')); ?></button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <?php echo Form::close(); ?>

        </div>
    </div>
        <?php $__env->stopSection(); ?>
        <?php $__env->startSection('script'); ?>

            <script type="text/javascript">
                $(document).ready(function () {
                    $(document).on('keyup', '.adjustment_qty', function () {
                        var stock_qty = $(this).closest('tr').find('.stock_qty').val();
                        var type = $(this).closest('tr').find('.type').val();
                        if (type == 'Subtraction') {
                            if (parseFloat($(this).val()) > parseFloat(stock_qty)) {
                                console.log($(this).val());
                                $(this).val(stock_qty);
                            }
                        }
                    });
                    $('input[name=bar_code]').on('click', function () {
                        $(this).select();
                    });
                });

                $(document).ready(function () {
                    ajax_stock_adjustment();
                    $(document).on('click', '.abc', function () {
                        var id = $(this).data('pro');
                        var route = "<?php echo e(route('stock-return-addcart',':id')); ?>";
                        route = route.replace(':id', id);
                        $.ajax({
                            type: 'GET',
                            url: route,
                            dataType: 'json',
                            success: function (data) {
                                ajax_stock_adjustment();
                            }
                        });
                    });
                });
                $(document).ready(function () {
                    $('input[name="bar_code"]').autocomplete({
                        source: function (request, response) {
                            $.ajax({
                                url: "<?php echo e(route('stock-return-autocomplete')); ?>",
                                dataType: "json",
                                data: {
                                    term: request.term,
                                },
                                success: function (data) {

                                    if (data != '') {
                                        $('#autocomplete').html(data.html);
                                    } else {
                                        $('#autocomplete').empty();
                                    }
                                }
                            });
                        },
                        minLength: 3,
                    });


                });

                $(document).on('click', '.add_adjustment', function () {
                    var product_id = $(this).data('id');
                    $.ajax({
                        type: "post",
                        url: '<?php echo e(route("stock-return-addcart")); ?>',
                        dataType: 'json',
                        data: {
                            '_token': '<?php echo e(csrf_token()); ?>',
                            product_id: product_id,
                        },
                        success: function (data) {
                            if (data == 'success') {
                                ajax_stock_adjustment();
                            } else {
                                alert(data);
                            }
                        }
                    });
                });

                function ajax_stock_adjustment() {

                    $.ajax({
                        type: "get",
                        dataType: 'text',
                        url: '<?php echo e(route("ajax-stock-return")); ?>',
                        success: function (msg) {
                            data = msg;
                            $('#tbody').html(data);
                        }
                    });
                }

                $(document).on('click', '.remove', function () {
                    var product_id = $(this).data('product_id');
                    $.ajax({
                        type: "post",
                        dataType: 'json',
                        url: '<?php echo e(route("remove-stock-return")); ?>',
                        data: {
                            '_token': '<?php echo e(csrf_token()); ?>',
                            product_id: product_id,
                        },
                        success: function (data) {
                            if (data.status == 'success') {
                                ajax_stock_adjustment();
                            } else {
                                alert('Remove Not Successfully')
                            }
                        }
                    });
                });

                $(document).mouseup(function (e) {
                    var container = $("#autocomplete");
                    if (!container.is(e.target) && container.has(e.target).length === 0) {
                        container.empty();
                    }
                });

                $(document).on('change', '.type', function () {
                    $(this).closest('tr').find('.adjustment_qty').val(0);
                });
                $(document).on('change', '.unit', function () {
                    var unit = $(this).val();
                    var stock_qty = $(this).closest('tr').find('.qty').val();
                    var parent_qty = $(this).closest('tr').find('.qty_one').val();
                    $(this).closest('tr').find('.adjustment_qty').val(0);
                    var result = 0;
                    if (unit == 1) {
                        result = parent_qty;
                    } else {
                        result = parseInt(stock_qty);
                    }
                    $(this).closest('tr').find('.stock_qty').val(result);
                });

            </script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.app-seller', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/nsowos/public_html/shr-brand/resources/views/pos/stock-return/create.blade.php ENDPATH**/ ?>