
<?php $__env->startSection('content'); ?>
    <?php Fun::lang() ?>
    <div class="page-pos_clothess">
        <div class="preview">
            <div class="col-sm-12 col-md-12 ">
                <div class="" style="">
                    <?php if(@$_GET['sdfsdfasdf']): ?>
                        <h2 class="pull-left"><b><?php echo e(__('administrator.wholesale')); ?></b></h2>
                        <a href="<?php echo e(route('seller-request.create')); ?>"
                           class="button_info pull-right"><?php echo e(__('administrator.retail')); ?></a>
                    <?php else: ?>
                        <h2 class="pull-left"><b><?php echo e(__('administrator.retail')); ?></b></h2>
                        <a href="<?php echo e(route('seller-request.create')); ?>?sdfsdfasdf=890789345"
                           class="button_info pull-right"><?php echo e(__('administrator.wholesale')); ?></a>
                    <?php endif; ?>
                </div>
            </div>
            <div class="col-sm-5 paddin-5">
                <div class="col-sm-5">
                    <div class="form-group">
                        <?php echo Form::text('barcode', null, array('placeholder' => __('administrator.barcode') ,'class' => 'form-control typeahead', "autocomplete" => "on")); ?>

                    </div>
                </div>
                <div class="col-sm-5">
                    <div class="form-group">
                        <?php echo Form::text('search', null, array('placeholder' => __('administrator.search') ,'class' => 'form-control search')); ?>

                    </div>
                </div>
                <div class="col-sm-2">
                    <div class="form-group">
                        <button type="button" class="button_info btn_search_pos"><?php echo e(__('administrator.search')); ?></button>
                    </div>
                </div>
                <div class="product-item-list">
                    <div class="item-list">
                        <div class="row my-product-list">
                        </div>
                    </div>
                </div>
            </div>
            <?php echo Form::open(array('route' => 'seller-request.store','method'=>'POST','enctype'=>'multipart/form-data','class'=>'jform')); ?>

            <div class="col-sm-7 paddin-5">
                <div class="check-bill">
                    <div class="row">
                        <div class="check-bill-table">
                            <div class="product-view-table">
                                <div class="parent-box-pos">
                                    <table class="table table-hover item-list-tb ">
                                        <thead class="text-center">
                                        <tr>
                                            <th>#</th>
                                            <th><?php echo e(__('administrator.item_name')); ?></th>
                                            <th><?php echo e(__('administrator.qty')); ?> <span class="red">*</span></th>
                                            <th><?php echo e(__('administrator.price')); ?><span class="red">*</span></th>
                                            <th><?php echo e(__('administrator.discount')); ?>(%)</th>
                                            <th><?php echo e(__('administrator.subtotal')); ?></th>
                                            <th><?php echo e(__('administrator.total')); ?></th>
                                            <th><?php echo e(__('administrator.action')); ?></th>
                                        </tr>
                                        </thead>
                                        <tbody id="append_product">

                                        </tbody>
                                    </table>
                                </div>
                            </div>

                        </div>
                    </div>
                    <div class="blog-payment">
                        <div class="col-sm-7">
                            <div class="list-box">
                                <div class="list">
                                    <div class="col-sm-6 paddin-5">
                                        <label class="required"><?php echo e(__('administrator.cashier')); ?></label>
                                        <input type="text" name="cashier_name" class="form-control input-sm" readonly=""
                                               value="<?php echo e(findUser(Auth::user()->id)->name); ?>">
                                    </div>
                                    <div class="col-sm-6 paddin-5">
                                        <label class="required"><?php echo e(__('administrator.date')); ?></label>
                                        <input type="text" value="<?php echo e(date('d-m-Y')); ?>"
                                               class="date_picker form-control input-sm" name="date">
                                    </div>
                                </div>
                            </div>
                            <div class="list-box">
                                <div class="list">
                                    <div class="col-sm-6 paddin-5">
                                        <label><?php echo e(__('administrator.total')); ?>

                                            (<?php echo e(__('administrator.'.user_currency()->code)); ?>)</label>
                                        <input type="text" class="sub_total form-control input-sm"
                                               value="0"
                                               readonly="">
                                    </div>
                                    <div class="col-sm-6 paddin-5">
                                        <label><?php echo e(__('administrator.grand_total')); ?>

                                            (<?php echo e(__('administrator.'.user_currency()->code)); ?>)</label>
                                        <input type="text" class="g_total form-control input-sm" value="0" readonly="">
                                        <input type="hidden" class="g_total_hidden form-control input-sm" value="0"
                                               name="g_total_hidden">
                                    </div>
                                </div>
                            </div>
                            <div class="list-box">
                                <div class="list">
                                    <div class="col-sm-6 paddin-5">
                                        <label><?php echo e(__('administrator.paid')); ?>

                                            (<?php echo e(__('administrator.'.user_currency()->code)); ?>)</label>
                                        <input type="text"
                                               class="form-control input-sm number-only border bg-transparent paid"
                                               name="paid" value="" placeholder="0.00">
                                    </div>
                                    <div class="col-sm-6 paddin-5">
                                        <label class="change"><?php echo e(__('administrator.owed_amount')); ?>

                                            (<?php echo e(__('administrator.'.user_currency()->code)); ?>)</label>
                                        <input data-status="0" type="text"
                                               class=" form-control input-sm"
                                               name="change-amount" readonly>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-5">
                            <div class="list-box">
                                <div class="list">
                                    <div class="col-sm-6 paddin-5">
                                        <label><?php echo e(__('administrator.total_qty')); ?> :</label>
                                        <?php echo Form::text('total_qty', 0, ['class' => 'form-control input-sm total_qty_','placeholder'=>__('administrator.total_qty'),'readonly']); ?>

                                    </div>
                                    <div class="col-sm-6 paddin-5">
                                        <label><?php echo e(__('administrator.reference')); ?></label>
                                        <input type="file" name="reference_file" class="form-control">
                                    </div>
                                </div>
                            </div>
                            <div class="list-box">
                                <div class="list">
                                    <div class="col-sm-6 paddin-5">
                                        <label class="required"><?php echo e(__('administrator.customer')); ?></label>
                                        <button type="button" class="btn btn-xs btn btn-primary add_customer">
                                            <i class="fa fa-plus"></i>
                                        </button>
                                        <?php echo Form::select('customer', [], null, ['class' => 'form-control input-sm get_discount search_customer','placeholder'=>__('administrator.please_select'),'required']); ?>

                                    </div>
                                    <div class="col-sm-6 paddin-5 ">
                                        <label class="required"><?php echo e(__('administrator.request_to')); ?></label>
                                        <?php echo Form::select('branch_id', $branch,[], array('class' => 'form-control','placeholder'=>__('administrator.please_select'),'required')); ?>

                                    </div>
                                </div>
                            </div>
                            <div class="list-box">
                                <div class="list">
                                    <div class="col-sm-6 paddin-5">
                                        <label><?php echo e(__('administrator.discount')); ?> (%)</label>
                                        <?php echo Form::text('discount',0, array('placeholder' =>__('administrator.discount'),'class' => 'form-control input-sm number-only total-discount' ,'')); ?>

                                    </div>
                                    <div class="col-sm-6 paddin-5">
                                        <label><?php echo e(__('administrator.payment_method')); ?></label>
                                        <?php echo Form::select('payment_method_id', getPaymentMethod() , null , ['placeholder'=>__('administrator.please_select'),'class' => 'form-control']); ?>

                                    </div>
                                </div>
                            </div>
                            <div class="list-box">
                                <div class="list">

                                    <div class="col-sm-6 paddin-5">
                                        <label><?php echo e(__('administrator.delivery_fee_by')); ?></label>
                                        <?php echo Form::select('delivery_fee_by', getFeeBy() , null , ['placeholder'=>__('administrator.please_select'),'class' => 'form-control']); ?>

                                    </div>
                                    <div class="col-sm-6 paddin-5">
                                        <label><?php echo e(__('administrator.delivery_fee')); ?>

                                            (<?php echo e(__('administrator.'.user_currency()->code)); ?>)</label>
                                        <?php echo Form::text('delivery_fee', 0 , ['placeholder'=>__('administrator.delivery_fee'),'class' => 'form-control number-only']); ?>

                                    </div>
                                </div>
                            </div>
                            <div class="list-box">
                                <div class="list">
                                    <div class="col-sm-12  paddin-5">
                                        <label><?php echo e(__('administrator.note')); ?> :</label>
                                        <textarea name="note" id="" rows="3" class="form-control no-resize"></textarea>
                                    </div>
                                </div>
                            </div>
                            <div class="col-sm-12 paddin-5">
                                <div class="button_payment">
                                    <input type="submit" value="<?php echo e(__('administrator.submit')); ?>" class="button_info button_lg pull-right">
                                    <button type="button"
                                            class="button_danger btn_clear_all button_lg"><?php echo e(__('administrator.remove')); ?></button>
                                    <button type="button" class="button_warning button_lg"
                                            onclick="history.back(1)"><?php echo e(__('administrator.back')); ?></button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <?php echo Form::close(); ?>

            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('script'); ?>
    <script type="text/javascript">
        $(document).ready(function () {
            $(document).ready(function () {
                $('input[name=search]').keypress(function (e) {
                    // e.preventDefault();
                    var key = e.which;
                    if(key == 13)  // the enter key code
                    {
                        search_product();
                    }
                });
                $('.btn_search_pos').on('click',function () {
                    search_product();
                });
            });
            function search_product() {
                let value = $('.search').val();
                let branch_id = $('select[name=branch_id]').val();
                $.ajax({
                    url: "<?php echo e(route('seller-request.create')); ?>",
                    method: "get",
                    data: {
                        value: value,
                        branch_id: branch_id,
                        sdfsdfasdf:'<?php echo e(@$_GET['sdfsdfasdf']); ?>',
                    },
                    success: function (response) {
                        $('.my-product-list').html(response.html);
                    }
                });
            }

            $('.add_customer').on('click', function () {
                $.confirm({
                    title: 'Add New Customer',
                    theme: 'modern',
                    content: '<input type="text" name="customer_name" class="form-control customer_name"required placeholder="<?php echo e(__('administrator.customer_name')); ?>" maxlength="40" />&nbsp;&nbsp;&nbsp;<input  class="form-control customer_phone"required placeholder="<?php echo e(__('administrator.customer_phone')); ?>" maxlength="40" type="text" name="customer_phone" />&nbsp;&nbsp;&nbsp;<input  class="form-control customer_address"required placeholder="<?php echo e(__('administrator.location')); ?>" maxlength="40" type="text" name="customer_address" />',
                    buttons: {
                        cancel: {
                            text: 'Cancel',
                            btnClass: 'button_warning',

                        },
                        submit: {
                            text: 'Submit',
                            btnClass: 'button_primary',
                            action: function () {
                                let name = $(document).find('.customer_name').val();
                                let phone = $(document).find('.customer_phone').val();
                                let address = $(document).find('.customer_address').val();
                                $.ajax({
                                    type: 'GET',
                                    url: '<?php echo e(route('new_customer')); ?>',
                                    data: {
                                        customer_name: name,
                                        customer_phone: phone,
                                        customer_address: address,
                                    },
                                    dataType: 'json',
                                    success: function (data) {

                                        $('#addnew').modal('hide');
                                        $('.get_discount').append('<option value="' + data.customer.id + '">' + data.customer.customer_name + '</option>');
                                        $.alert('Customer Added');
                                        $('.get_discount').val(data.customer.id).change();
                                    }
                                });
                            }
                        }

                    }
                });
            });
            $(document).on('click', 'a.page-link', function (e) {
                let branch_id = $('select[name=branch_id]').val();
                e.preventDefault();
                let url = $(this).attr('href');

                $.ajax({
                    url: url,
                    data: {
                        _token: '<?php echo e(csrf_token()); ?>',
                        branch_id: branch_id
                    },
                    dataType: 'json',
                    success(data) {

                        $('.my-product-list').html(data.html);
                    }
                });
            });
            $(document).on('change', 'select[name=branch_id]', function () {
                let branch_id = $(this).val();
                if (branch_id) {
                    $.ajax({
                        url: '<?php echo e(route('seller-request.create')); ?>',
                        method: 'get',
                        data: {
                            _token: '<?php echo e(csrf_token()); ?>',
                            branch_id: branch_id,
                            sdfsdfasdf:'<?php echo e(@$_GET['sdfsdfasdf']); ?>'
                        },
                        async: false,
                        success: function (data) {
                            $('.my-product-list').html(data.html);
                        }
                    });
                }

            });
        });

        $('.typeahead').autocomplete({
            source: function (request, response) {
                let branch_id = $('select[name=branch_id]').val();
                $.ajax({
                    url: "<?php echo e(Route('seller-request-scan-code')); ?>",
                    dataType: "json",
                    method: "get",
                    data: {
                        barcode: request.term,
                        branch_id: branch_id,
                        sdfsdfasdf:'<?php echo e(@$_GET['sdfsdfasdf']); ?>'
                    },
                    success: function (rows) {
                        let check = 0;
                        let table = $('.product_unit');
                        let id = rows.data.id;
                        let name = rows.data.name;
                        let stock = rows.data.sum_stock;
                        let size = rows.data.size;
                        let code = rows.data.code;
                        let price = rows.data.price;
                        let symbol = '<?php echo e(user_currency()->symbol); ?>';
                        let count = $('#append_product tr').length;
                        let $html = `
                        <tr data-symbol="` + symbol + `">
                            <td><input type="hidden" class="product_unit" value="` + id + `" name="product_unit[]">` + (count + 1) + `</td>
                            <td>` + (name + "  ( Size: " + size + " )") + `<br>` + code + `</td>
                            <td>
                                <input type="number" value="1" class="form-control input-sm qty number-only" name="qty[]" required/>
                                <input type="hidden" value="` + stock + `" class="stock" name="stock[]"/>
                            </td>
                            <td><input type="text"  value="` + price + `"  class="form-control input-sm retail_price number-only " required name="retail_price[]" /></td>
                            <td><input type="text" value="0" class="form-control input-sm disc number-only" name="dis[]" min="0" max="100" maxlength="3" /></td>
                            <td class="text-center"><span class="subtotal_item">` + (price) + symbol + `</span></td>
                            <td class="text-center"><span class="total_item">` + (price) + symbol + `</span><input type="hidden" class="amount-hidden" name="amount_hidden" value="` + (price) + `"></td>
                            <td class="text-center"><span class="fa fa-times text-danger fa-2x  cursor remove_row"></span></td>
                        </tr>

                    `;
                        if (table.length > 0) {
                            $.each(table, function (i, v) {
                                if (parseFloat(v.value) === parseFloat(id)) {
                                    let qty = $(this).closest('tr').find('.qty').val();
                                    let add_mor = parseFloat(qty) + 1;
                                    if (parseFloat(add_mor) > parseFloat(stock)) {
                                        add_mor = stock;
                                        $.alert('Out of Stock');
                                    }
                                    $(this).closest('tr').find('.qty').val(add_mor);
                                    gen_item_total($(this));
                                    check++;
                                }
                            });
                            if (check === 0 && id) {
                                $('#append_product').append($html);
                            }
                        } else {
                            if (id) {
                                $('#append_product').append($html);
                            }
                        }
                        get_total_all();
                        $(".typeahead").val('').focus();
                    }
                });
            },
            minLength: 3,
        });

        $(document).on('click', '.listings', function () {
            let id = $(this).data('id');
            let check = 0;
            let table = $('.product_unit');
            let name = $(this).data('name');
            let stock = $(this).data('stock');
            let size = $(this).data('size');
            let code = $(this).data('code');
            let price = $(this).data('price');
            let symbol = $(this).data('symbol');
            let count = $('#append_product tr').length;
            let $html = `
                        <tr data-symbol="` + symbol + `">
                            <td><input type="hidden" class="product_unit" value="` + id + `" name="product_unit[]">` + (count + 1) + `</td>
                            <td>` + (name + "  ( Size: " + size + ")") + `<br>` + code + `</td>
                            <td>
                                <input type="number" value="1" class="form-control input-sm qty number-only" name="qty[]" required/>
                                <input type="hidden" value="` + stock + `" class="stock" name="stock[]"/>
                            </td>
                            <td><input type="text"  value="` + price + `"  class="form-control input-sm retail_price number-only " required name="retail_price[]" /></td>
                            <td><input type="text" value="0" class="form-control input-sm disc number-only" name="dis[]" min="0" max="100" maxlength="3" /></td>
                            <td class="text-center"><span class="subtotal_item">` + (price) + symbol + `</span></td>
                            <td class="text-center"><span class="total_item">` + (price) + symbol + `</span><input type="hidden" class="amount-hidden" name="amount_hidden" value="` + (price) + `"></td>
                            <td class="text-center"><span class="fa fa-times text-danger fa-2x  cursor remove_row"></span></td>
                        </tr>

                    `;
            if (table.length > 0) {
                $.each(table, function (i, v) {
                    if (parseFloat(v.value) === parseFloat(id)) {
                        let qty = $(this).closest('tr').find('.qty').val();
                        let add_mor = parseFloat(qty) + 1;
                        if (parseFloat(add_mor) > parseFloat(stock)) {
                            add_mor = stock;
                            $.alert('Out of Stock');
                        }
                        $(this).closest('tr').find('.qty').val(add_mor);
                        gen_item_total($(this));
                        check++;
                    }
                });
                if (check === 0 && id) {
                    $('#append_product').append($html);
                }
            } else {
                if (id) {
                    $('#append_product').append($html);
                }
            }
            get_total_all();
        });

        $(document).on('click', '.remove_row', function () {
            $(this).closest('tr').remove();
            get_total_all();
        });
        $(document).on('click', 'button[type=submit]', function () {
            let this__ = $(this);

            this__.prop('disabled','disabled');
            setTimeout(function () {
                this__.removeAttr('disabled');
            },5000);
        });

        $(document).on('keyup', '.number-only', function () {
            gen_item_total($(this));
        });

        function gen_item_total(this_) {
            let qty = this_.closest('tr').find('.qty').val();
            let price = this_.closest('tr').find('.retail_price').val();
            let disc = this_.closest('tr').find('.disc').val();
            let stock = this_.closest('tr').find('.stock').val();
            if (parseFloat(qty) > parseFloat(stock)) {
                qty = stock;
                this_.closest('tr').find('.qty').val(qty);
                $.alert('Out of Stock');
            }
            disc = disc ? disc : 0;
            let symbol = this_.closest('tr').data('symbol');
            let stotal = qty * price;
            let total = stotal - (stotal * disc / 100);
            this_.closest('tr').find('.subtotal_item').text(stotal + '' + symbol);
            this_.closest('tr').find('.total_item').text(total + '' + symbol);
            this_.closest('tr').find('.amount-hidden').val(total);
            get_total_all();
        }

        function get_total_all() {

            let total = 0;
            let discount = parseFloat($('input[name=discount]').val());
            let delivery_fee_by = parseFloat($('select[name=delivery_fee_by]').val());
            let delivery_fee = parseFloat($('input[name=delivery_fee ]').val());
            discount = discount ? discount : 0;
            delivery_fee_by = delivery_fee_by ? delivery_fee_by : 0;
            delivery_fee = delivery_fee ? delivery_fee : 0;
            let total_qty_ = 0;
            $('.amount-hidden').each(function () {
                let value_total = parseFloat($(this).val());
                total += parseFloat(value_total);
                let qty = $(this).closest('tr').find('.qty').val();
                qty = qty ? qty : 0;
                total_qty_ += parseFloat(qty);
            });
            let g_total = total - (total * discount / 100);
            if (delivery_fee_by === 2) {
                g_total += delivery_fee;
            }

            $('.g_total').val(parseFloat(g_total).toFixed(2));

            $('.g_total_hidden').val(parseFloat(g_total));

            $('.sub_total').val(parseFloat(total).toFixed(2));

            $('.total_qty_').val(parseFloat(total_qty_));

        }

        $('.total-discount').on('keyup', function () {
            get_total_all();
        });

        $(document).on('keyup', '.paid', function () {

            let g_total = parseFloat($('.g_total_hidden').val());
            let paid = parseFloat($('.paid').val() ? $('.paid').val() : 0);

            if (g_total <= paid) {
                $('.change').text('<?php echo e(__('administrator.change_amount')); ?>').removeClass('text-red').addClass('text-green');
            } else {
                $('.change').text('<?php echo e(__('administrator.owed_amount')); ?>').removeClass('text-green').addClass('text-red');
            }
            paid = paid - g_total;

            $('input[name="change-amount"]').val('<?php echo e(user_currency()->symbol); ?>' + Math.abs(parseFloat(paid).toFixed(2)));
        });

        $(document).on('click', '.btn_clear_all ', function () {
            $.confirm({
                title: 'Are you sure ?',
                theme: 'modern',
                buttons: {
                    cancel: {
                        btnClass: 'button_warning',
                        text: 'Cancel'
                    },
                    ok: {
                        btnClass: 'button_primary',
                        text: 'OK',
                        action: function () {
                            $('#append_product').html('');
                            get_total_all();
                        }
                    }
                }
            });
        });

    </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/seller-request/create.blade.php ENDPATH**/ ?>