<?php $__env->startSection('content'); ?>

    <title><?php echo e(trans('admin.SalesGifts')); ?></title>

    <main id="js-page-content" role="main" class="page-content">
        <ol class="breadcrumb page-breadcrumb">
            <li class="breadcrumb-item"><a href="javascript:void(0);"><?php echo e(trans('admin.Sales')); ?> </a></li>
            <li class="breadcrumb-item active"><?php echo e(trans('admin.SalesGifts')); ?> </li>
            <li class="position-absolute pos-top pos-right d-none d-sm-block"><span class="js-get-date"></span></li>
        </ol>

        <form id="form" action="<?php echo e(url('AddSalesGift')); ?>" method="post" enctype="multipart/form-data">
            <?php echo csrf_field(); ?>

            <?php echo view('honeypot::honeypotFormFields'); ?>
            <div class="row">
                <div class="col-lg-12">
                    <div id="panel-2" class="panel">
                        <div class="panel-hdr">
                            <h2>
                                <span class="fw-300"><i>   <?php echo e(trans('admin.SalesGifts')); ?>  </i></span>
                            </h2>
                        </div>
                        <div class="panel-container show">
                            <span id="ex"> <?php echo $__env->make('admin.layouts.messages', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?></span>
                            <div class="panel-content">


                                <div class="form-row">
                                    <div class="form-group col-lg-2">
                                        <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Code')); ?> </label>
                                        <input type="text" value="<?php echo e($Code); ?>" class="form-control " disabled>
                                        <input type="hidden" name="Code" value="<?php echo e($Code); ?>" class="form-control">
                                    </div>
                                    <div class="form-group col-lg-2">
                                        <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Date')); ?></label>
                                        <input type="date" name="Date" value="<?php echo e(date('Y-m-d')); ?>" class="form-control" required>
                                    </div>

                                    <div class="form-group col-lg-2">
                                        <label class="form-label" for=""><?php echo e(trans('admin.Store')); ?></label>
                                        <select class="select2 form-control w-100" id="store" name="Store" required>
                                            <?php $__currentLoopData = $Stores; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $stor): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($stor->id); ?>" <?php if($Def->Store == $stor->id): ?> selected <?php endif; ?>>

                                                    <?php echo e(app()->getLocale() == 'ar' ?$stor->Name :$stor->NameEn); ?>


                                                </option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </select>
                                    </div>


                                <?php if($show->Coin == 1): ?>
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for=""><?php echo e(trans('admin.Coin')); ?></label>
                                            <select class="select2 form-control w-100" name="Coin" required>
                                                <option value=""> <?php echo e(trans('admin.Coin')); ?></option>
                                                <?php $__currentLoopData = $Coins; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $coin): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <option value="<?php echo e($coin->id); ?>" <?php if($Def->Coin == $coin->id): ?> selected <?php endif; ?>>
                                                        <?php echo e(app()->getLocale() == 'ar' ?$coin->Arabic_Name :$coin->English_Name); ?>

                                                    </option>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </select>
                                        </div>
                                    <?php else: ?>
                                        <div class="form-group col-lg-2" style="display: none">
                                            <label class="form-label" for=""><?php echo e(trans('admin.Coin')); ?></label>
                                            <select class="select2 form-control w-100" name="Coin" required>
                                                <option value=""> <?php echo e(trans('admin.Coin')); ?></option>
                                                <?php $__currentLoopData = $Coins; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $coin): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <option value="<?php echo e($coin->id); ?>" <?php if($Def->Coin == $coin->id): ?> selected <?php endif; ?>>
                                                        <?php echo e(app()->getLocale() == 'ar' ?$coin->Arabic_Name :$coin->English_Name); ?>

                                                    </option>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </select>
                                        </div>
                                    <?php endif; ?>

                                    <?php if($show->Draw == 1): ?>
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Draw')); ?></label>
                                            <input type="text" name="Draw" value="1" class="form-control" required>
                                        </div>
                                    <?php else: ?>
                                        <div class="form-group col-lg-2" style="display: none">
                                            <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Draw')); ?></label>
                                            <input type="text" name="Draw" value="1" class="form-control" required>
                                        </div>
                                    <?php endif; ?>

                                    <?php if($show->Cost_Center == 1): ?>
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for=""> <?php echo e(trans('admin.Cost_Center')); ?> </label>
                                            <select class="select2 form-control w-100" name="Cost_Center">
                                                <option value=""> <?php echo e(trans('admin.Cost_Center')); ?></option>
                                                <?php $__currentLoopData = $CostCenters; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cost): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <option value="<?php echo e($cost->id); ?>">
                                                        <?php echo e(app()->getLocale() == 'ar' ?$cost->Arabic_Name :$cost->English_Name); ?>

                                                    </option>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </select>
                                        </div>
                                    <?php else: ?>
                                        <div class="form-group col-lg-2" style="display: none">
                                            <label class="form-label" for=""> <?php echo e(trans('admin.Cost_Center')); ?> </label>
                                            <select class="select2 form-control w-100" name="Cost_Center">
                                                <option value=""> <?php echo e(trans('admin.Cost_Center')); ?></option>
                                                <?php $__currentLoopData = $CostCenters; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cost): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <option value="<?php echo e($cost->id); ?>">
                                                        <?php echo e(app()->getLocale() == 'ar' ?$cost->Arabic_Name :$cost->English_Name); ?>

                                                    </option>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </select>
                                        </div>
                                    <?php endif; ?>


                                    <div class="form-group col-lg-4">
                                        <label class="form-label" for=""><?php echo e(trans('admin.Account')); ?> (<?php echo e(trans('admin.Client')); ?>)</label>
                                        <select  class="select2 form-control w-100" id="client" name="Client" required>

                                            <?php if(auth()->guard('admin')->user()->emp == 0): ?>
                                                <option value="<?php echo e($Def->Client); ?>">
                                                    <?php echo e(app()->getLocale() == 'ar' ?$Def->Client()->first()->Name :$Def->Client()->first()->NameEn); ?>

                                                </option>
                                            <?php endif; ?>
                                        </select>
                                    </div>


                                    <div class="form-group col-lg-3">
                                        <label class="form-label" for="simpleinput"> <?php echo e(trans('admin.Account_Credit')); ?> </label>
                                        <input type="text" id="AccountCredit" name="Current_Credit" value="0" class="form-control " readonly>
                                    </div>

                                    <div class="form-group col-lg-4">
                                        <label class="form-label" for=""><?php echo e(trans('admin.Accounting_Entry')); ?></label>
                                        <select  class="select2 form-control w-100" id="account" name="Account" required>
                                        </select>
                                    </div>

                                    <?php if($show->Note == 1): ?>
                                        <div class="form-group col-lg-4">
                                            <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Notes')); ?>  </label>
                                            <input type="text" name="Note" value="<?php echo e(old('Note')); ?>" class="form-control">
                                        </div>
                                    <?php else: ?>
                                        <div class="form-group col-lg-4" style="display: none">
                                            <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Notes')); ?>  </label>
                                            <input type="text" name="Note" value="<?php echo e(old('Note')); ?>" class="form-control">
                                        </div>
                                    <?php endif; ?>

                                </div>

                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-xl-12">
                    <div id="panel-1" class="panel">

                        <div class="panel-container show">
                            <div class="panel-content">
                                <div class="row">
                                    <div class="form-group col-lg-12">
                                        <label class="form-label" for="simpleinput">  </label>
                                        <div class="input-items" style="position:relative;">
                                            <input type="text" id="search" class="form-control" placeholder="<?php echo e(trans('admin.Search_For_Products')); ?>">
                                            <i class="fal fa-barcode-alt" style="position:absolute;top:5px;left:3px;"></i>
                                        </div>
                                    </div>

                                </div>
                                <div id="mobile-overflow">
                                    <table
                                        class="table table-bordered table-hover table-striped w-100 mobile-width-more table-color1">
                                        <thead>
                                        <tr>
                                            <th><?php echo e(trans('admin.Name')); ?></th>
                                            <th><?php echo e(trans('admin.Unit')); ?></th>
                                            <th><?php echo e(trans('admin.Code')); ?></th>
                                            <th><?php echo e(trans('admin.AvQty')); ?></th>
                                            <th><?php echo e(trans('admin.Qty')); ?></th>
                                            <?php if($show->Expire_Date == 1): ?>
                                                <th><?php echo e(trans('admin.Exp_Date')); ?></th>
                                            <?php endif; ?>
                                            <th><?php echo e(trans('admin.Actions')); ?></th>
                                        </tr>
                                        </thead>
                                        <tbody class="Data" id="Data">

                                        </tbody>
                                    </table>
                                </div>
                                <!-- datatable start -->
                                <div id="mobile-overflow">
                                    <table id="dt"
                                           class="table table-bordered table-hover table-striped w-100 mobile-width-more table-color2">
                                        <thead>
                                        <tr>
                                            <th><?php echo e(trans('admin.Name')); ?></th>
                                            <th><?php echo e(trans('admin.Unit')); ?></th>
                                            <th><?php echo e(trans('admin.Code')); ?></th>
                                            <th><?php echo e(trans('admin.AvQty')); ?></th>
                                            <th><?php echo e(trans('admin.Qty')); ?></th>
                                            <?php if($show->Expire_Date == 1): ?>
                                                <th><?php echo e(trans('admin.Exp_Date')); ?></th>
                                            <?php endif; ?>
                                            <th><?php echo e(trans('admin.Actions')); ?></th>
                                        </tr>
                                        </thead>
                                        <tbody id="data-dt">


                                        </tbody>

                                    </table>
                                </div>
                                <!-- datatable end -->
                                <div class="form-row">
                                    <div class="form-group col-lg-6">
                                        <label class="form-label" for="simpleinput"> <?php echo e(trans('admin.Product_Numbers')); ?> </label>
                                        <input type="text" id="Product_Numbers" name="Product_Numbers" readonly  class="form-control">

                                    </div>

                                    <div class="form-group col-lg-6">
                                        <label class="form-label" for="simpleinput">  <?php echo e(trans('admin.Total_Qty')); ?></label>
                                        <input type="text" id="Total_Qty" name="Total_Qty" readonly class="form-control">
                                        <input type="hidden" id="Total_PriceHide" name="Total_Price">
                                        <input type="hidden" id="Total_Cost" name="Total_Cost">
                                    </div>

                                </div>
                                <div class="buttons mt-3" id="Submit" style="display: none">
                                    <input type="hidden" id="sp" name="SP">
                                    <button type="button"  class="btn btn-primary" onclick="SPS()"> <i class="fal fa-folder"></i> <?php echo e(trans('admin.Save')); ?> </button>


                                    <?php if($show->A4 == 1): ?>
                                        <button type="button"  class="btn btn-primary" onclick="SPP()"><i class="fal fa-save"></i>  <?php echo e(trans('admin.SaveandPrint')); ?> </button>
                                    <?php endif; ?>



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



            </div>

        </form>
    </main>



    <?php if(app()->getLocale() == 'ar' ): ?>
        <input type="hidden" id="LANG" value="ar">
    <?php else: ?>
        <input type="hidden" id="LANG" value="en">
    <?php endif; ?>
    <input type="hidden" id="ED" value="<?php echo e($show->Expire_Date); ?>">

<?php $__env->stopSection(); ?>

<?php $__env->startPush('js'); ?>

    <link rel="stylesheet" media="screen, print" href="<?php echo e(asset('Admin/css/datagrid/datatables/datatables.bundle.css')); ?>">
    <link rel="stylesheet" media="screen, print" href="<?php echo e(asset('Admin/css/formplugins/summernote/summernote.css')); ?>">
    <link rel="stylesheet" media="screen, print" href="<?php echo e(asset('Admin/css/formplugins/select2/select2.bundle.css')); ?>">

    <script src="<?php echo e(asset('Admin/js/datagrid/datatables/datatables.bundle.js')); ?>"></script>
    <script src="<?php echo e(asset('Admin/js/datagrid/datatables/datatables.export.js')); ?>"></script>
    <script src="<?php echo e(asset('Admin/js/formplugins/summernote/summernote.js')); ?>"></script>
    <script src="<?php echo e(asset('Admin/js/formplugins/select2/select2.bundle.js')); ?>"></script>
    <script>
        var autoSave = $('#autoSave');
        var interval;
        var timer = function()
        {
            interval = setInterval(function()
            {
                //start slide...
                if (autoSave.prop('checked'))
                    saveToLocal();

                clearInterval(interval);
            }, 3000);
        };

        //save
        var saveToLocal = function()
        {
            localStorage.setItem('summernoteData', $('#saveToLocal').summernote("code"));
            console.log("saved");
        }

        //delete
        var removeFromLocal = function()
        {
            localStorage.removeItem("summernoteData");
            $('#saveToLocal').summernote('reset');
        }

        $(document).ready(function()
        {
            //init default
            $('.js-summernote').summernote(
                {
                    height: 200,
                    tabsize: 2,
                    placeholder: "Type here...",
                    dialogsFade: true,
                    toolbar: [
                        ['style', ['style']],
                        ['font', ['strikethrough', 'superscript', 'subscript']],
                        ['font', ['bold', 'italic', 'underline', 'clear']],
                        ['fontsize', ['fontsize']],
                        ['fontname', ['fontname']],
                        ['color', ['color']],
                        ['para', ['ul', 'ol', 'paragraph']],
                        ['height', ['height']]
                            ['table', ['table']],
                        ['insert', ['link', 'picture', 'video']],
                        ['view', ['fullscreen', 'codeview', 'help']]
                    ],
                    callbacks:
                        {
                            //restore from localStorage
                            onInit: function(e)
                            {
                                $('.js-summernote').summernote("code", localStorage.getItem("summernoteData"));
                            },
                            onChange: function(contents, $editable)
                            {
                                clearInterval(interval);
                                timer();
                            }
                        }
                });

            //load emojis
            $.ajax(
                {
                    url: 'https://api.github.com/emojis',
                    async: false
                }).then(function(data)
            {
                window.emojis = Object.keys(data);
                window.emojiUrls = data;
            });

            //init emoji example
            $(".js-hint2emoji").summernote(
                {
                    height: 100,
                    toolbar: false,
                    placeholder: 'type starting with : and any alphabet',
                    hint:
                        {
                            match: /:([\-+\w]+)$/,
                            search: function(keyword, callback)
                            {
                                callback($.grep(emojis, function(item)
                                {
                                    return item.indexOf(keyword) === 0;
                                }));
                            },
                            template: function(item)
                            {
                                var content = emojiUrls[item];
                                return '<img src="' + content + '" width="20" /> :' + item + ':';
                            },
                            content: function(item)
                            {
                                var url = emojiUrls[item];
                                if (url)
                                {
                                    return $('<img />').attr('src', url).css('width', 20)[0];
                                }
                                return '';
                            }
                        }
                });

            //init mentions example
            $(".js-hint2mention").summernote(
                {
                    height: 100,
                    toolbar: false,
                    placeholder: "type starting with @",
                    hint:
                        {
                            mentions: ['jayden', 'sam', 'alvin', 'david'],
                            match: /\B@(\w*)$/,
                            search: function(keyword, callback)
                            {
                                callback($.grep(this.mentions, function(item)
                                {
                                    return item.indexOf(keyword) == 0;
                                }));
                            },
                            content: function(item)
                            {
                                return '@' + item;
                            }
                        }
                });

        });

    </script>

    <!-- Search Selecet -->
    <script>
        $(document).ready(function () {
            $(function () {
                $(".select2").select2();

                $(".select2-placeholder-multiple").select2({
                    placeholder: "Select State",
                });
                $(".js-hide-search").select2({
                    minimumResultsForSearch: 1 / 0,
                });
                $(".js-max-length").select2({
                    maximumSelectionLength: 2,
                    placeholder: "Select maximum 2 items",
                });
                $(".select2-placeholder").select2({
                    placeholder: "Select a state",
                    allowClear: true,
                });

                $(".js-select2-icons").select2({
                    minimumResultsForSearch: 1 / 0,
                    templateResult: icon,
                    templateSelection: icon,
                    escapeMarkup: function (elm) {
                        return elm;
                    },
                });

                function icon(elm) {
                    elm.element;
                    return elm.id ? "<i class='" + $(elm.element).data("icon") + " mr-2'></i>" + elm.text : elm.text;
                }

                $("#Emp").select2({
                    placeholder: "select...",
                    ajax: {
                        type: "GET",
                        dataType: "json",
                        url: "AllEmps",
                        processResults: function (data) {
                            return {
                                results: $.map(data, function (obj, index) {
                                    return { id: index, text: obj };
                                }),
                            };

                            console.log(data);
                        },
                        data: function (params) {


                            var query = {
                                search: params.term,
                            };


                            $.ajax({
                                url: 'AllEmpsJ/'+params.term,
                                type:"GET",
                                dataType:"json",
                                beforeSend: function(){
                                    $('#loader').css("visibility", "visible");
                                },

                                success:function(data) {
                                    $('#Emp').empty();
                                    $.each(data, function(key, value){

                                        $('#Emp').append('<option value="'+ key +'">' + value + '</option>');

                                    });
                                },
                                complete: function(){
                                    $('#loader').css("visibility", "hidden");
                                }
                            });



                        }
                    },
                });

                $("#Emp").on("select2:select", function (e) {
                    console.log("select done", e.params.data);
                });

                $("#client").select2({
                    placeholder: "select...",
                    ajax: {
                        type: "GET",
                        dataType: "json",
                        url: "AllClientsFilter",
                        processResults: function (data) {
                            return {
                                results: $.map(data, function (obj, index) {

                                    return { id: index, text: obj };
                                }),
                            };

                            console.log(data);
                        },
                        data: function (params) {


                            var query = {
                                search: params.term,
                            };


                            $.ajax({
                                url: 'AllClientsFilterJS/'+params.term,
                                type:"GET",
                                dataType:"json",
                                beforeSend: function(){
                                    $('#loader').css("visibility", "visible");
                                },

                                success:function(data) {
                                    $('#client').empty();
                                    $.each(data, function(key, value){

                                        $('#client').append('<option value="'+ key +'">' + value + '</option>');

                                    });

                                    var countryId = $('#client').val();
                                    if(countryId) {
                                        $.ajax({
                                            url: 'AccountBalanceSOFilter/'+countryId,
                                            type:"GET",
                                            dataType:"json",
                                            beforeSend: function(){
                                                $('#loader').css("visibility", "visible");
                                            },

                                            success:function(data) {
                                                $.each(data, function(key, value){


                                                    $('#AccountCredit').val(key);
                                                    $('#AccountCredit').val(value);
                                                });
                                            },
                                            complete: function(){
                                                $('#loader').css("visibility", "hidden");
                                            }
                                        });
                                    } else {

                                        $('select[name="state"]').empty();
                                    }



                                },
                                complete: function(){
                                    $('#loader').css("visibility", "hidden");
                                }
                            });



                        }
                    },
                });

                $("#client").on("select2:select", function (e) {
                    console.log("select done", e.params.data);
                });


                $('#account').select2({
                    placeholder: "select...",
                    ajax: {
                        type: "GET",
                        dataType: 'json',
                        url: 'AllSubAccounts',
                        processResults: function (data) {
                            return {
                                results: $.map(data, function(obj, index) {
                                    return { id: index, text: obj };
                                })
                            };

                            console.log(data);

                        },
                        data: function (params) {


                            var query = {
                                search: params.term,
                            };


                            $.ajax({
                                url: 'AllSubAccountsJ/'+params.term,
                                type:"GET",
                                dataType:"json",
                                beforeSend: function(){
                                    $('#loader').css("visibility", "visible");
                                },

                                success:function(data) {
                                    $('#AccountCodeF').empty();
                                    $.each(data, function(key, value){

                                        $('#AccountCodeF').append('<option value="'+ key +'">' + value + '</option>');

                                    });
                                },
                                complete: function(){
                                    $('#loader').css("visibility", "hidden");
                                }
                            });



                        }
                    }
                });


                $('#account').on('select2:select', function (e) {
                    console.log("select done", e.params.data);
                });










            });
        });
    </script>

    <!-- Unit Change -->
<script>
    //
    // Unit Code and Name V-->
    //
    function UnitCodePurch(r) {

        var countryId = $('#UnitPurch' + r).val();
        var Pro = $('#Product' + r).val();
        var client = $('#client').val();
        var code = $('#CodePurch' + r).val();
        var Store = $('#store').val();

        if (countryId) {
            $.ajax({
                url: 'UnitSalesFilter',
                type: "GET",
                data: {
                    countryId: countryId,
                    Pro: Pro,
                    client: client,
                    code: code,
                    Store: Store
                },
                dataType: "json",
                beforeSend: function() {
                    $('#loader').css("visibility", "visible");
                },

                success: function(data) {
                    $.each(data, function(key, value) {


                        $('#UnitPurchName' + r).val(data.name);
                        $('#Price' + r).val(data.price);
                        $('#AvQty' + r).val(parseFloat(data.qty).toFixed(2));
                        $("#CostPrice" + r).val(data.cost);



                    });


                    var Qty = $("#Qty" + r).val();
                    var AvQty = $("#AvQty" + r).val();
                    var Price = $("#Price" + r).val();
                    var CostPrice = $("#CostPrice" + r).val();


                    var tot= parseFloat(Price) * parseFloat(Qty) ;
                    var totCost= parseFloat(CostPrice) * parseFloat(Qty) ;

                    $("#Total" + r).val(parseFloat(tot).toFixed(2));
                    $("#TotalCost" + r).val(parseFloat(totCost).toFixed(2));

                    var Total = $("#Total" + r).val();
                    var TotalCost = $("#TotalCost" + r).val();



                    if(parseFloat(Qty) <= parseFloat(AvQty)) {

                        if (Qty == '' || Price == '' || Total == '' || TotalCost == '') {

                            document.getElementById("AddBtnPur" + r).style.display = "none";
                        }


                        if (Qty != '' && Price != '' && Total != '' && TotalCost != 0) {

                            if (Qty < 0 || Price < 0 || Total < 0) {

                                document.getElementById("AddBtnPur" + r).style.display = "none";


                            } else {

                                document.getElementById("AddBtnPur" + r).style.display = "inline-block";

                            }

                        }
                    }else{

                        document.getElementById("AddBtnPur" + r).style.display = "none";
                    }


                },
                complete: function() {
                    $('#loader').css("visibility", "hidden");
                }
            });
        } else {

            $('select[name="state"]').empty();
        }




    }

    //
    // Unit Code and Name -->
    //
    function UnitCodePurchh(r) {

        var countryId = $('#UnitPurch' + r).val();
        var Pro = $('#Product' + r).val();
        var client = $('#client').val();
        var code = $('#CodePurch' + r).val();
        var Store = $('#store').val();
        if (countryId) {
            $.ajax({
                url: 'UnitSalesFilter',
                type: "GET",
                data: {
                    countryId: countryId,
                    Pro: Pro,
                    client: client,
                    code: code,
                    Store: Store
                },
                dataType: "json",
                beforeSend: function() {
                    $('#loader').css("visibility", "visible");
                },

                success: function(data) {
                    $.each(data, function(key, value) {

                        $('#CodePurch' + r).val(data.code);
                        $('#UnitPurchName' + r).val(data.name);
                        $('#Price' + r).val(data.price);
                        $('#AvQty' + r).val(parseFloat(data.qty).toFixed(2));
                        $("#CostPrice" + r).val(data.cost);
                    });

                    var Qty = $("#Qty" + r).val();
                    var AvQty = $("#AvQty" + r).val();
                    var Price = $("#Price" + r).val();
                    var CostPrice = $("#CostPrice" + r).val();


                    var tot= parseFloat(Price) * parseFloat(Qty) ;
                    var totCost= parseFloat(CostPrice) * parseFloat(Qty) ;

                    $("#Total" + r).val(parseFloat(tot).toFixed(2));
                    $("#TotalCost" + r).val(parseFloat(totCost).toFixed(2));

                    var Total = $("#Total" + r).val();
                    var TotalCost = $("#TotalCost" + r).val();



                    if(parseFloat(Qty) <= parseFloat(AvQty)) {

                        if (Qty == '' || Price == '' || Total == '' || TotalCost == '') {

                            document.getElementById("AddBtnPur" + r).style.display = "none";
                        }


                        if (Qty != '' && Price != '' && Total != '' && TotalCost != 0) {

                            if (Qty < 0 || Price < 0 || Total < 0) {

                                document.getElementById("AddBtnPur" + r).style.display = "none";


                            } else {

                                document.getElementById("AddBtnPur" + r).style.display = "inline-block";

                            }

                        }
                    }else{

                        document.getElementById("AddBtnPur" + r).style.display = "none";
                    }




                },
                complete: function() {
                    $('#loader').css("visibility", "hidden");
                }
            });
        } else {

            $('select[name="state"]').empty();
        }

    }

</script>


    <!-- Account Balance -->
    <script>
        $(document).ready(function() {

            $('#client').on('change', function(){
                var countryId = $(this).val();
                if(countryId) {
                    $.ajax({
                        url: 'AccountBalanceSOFilter/'+countryId,
                        type:"GET",
                        dataType:"json",
                        beforeSend: function(){
                            $('#loader').css("visibility", "visible");
                        },

                        success:function(data) {
                            $.each(data, function(key, value){


                                $('#AccountCredit').val(key);
                                $('#AccountCredit').val(value);
                            });
                        },
                        complete: function(){
                            $('#loader').css("visibility", "hidden");
                        }
                    });
                } else {

                    $('select[name="state"]').empty();
                }

            });

        });

        $(document).ready(function() {

            var countryId = $('#client').val();

                $.ajax({
                    url: 'AccountBalanceSFilter/'+countryId,
                    type:"GET",
                    dataType:"json",
                    beforeSend: function(){
                        $('#loader').css("visibility", "visible");
                    },

                    success:function(data) {
                        $.each(data, function(key, value){


                            $('#AccountCredit').val(key);
                            $('#AccountCredit').val(value);
                        });
                    },
                    complete: function(){
                        $('#loader').css("visibility", "hidden");
                    }
                });


        });
    </script>

    <!--  Filter Products -->
    <script>

        $(document).ready(function(){

            fetch_customer_data();

            function fetch_customer_data(search = '',client='')
            {
                var store=$('#store').val();
                $.ajax({
                    url:'SalesGiftsFilter',
                    method:'GET',
                    data:{search:search,client:client,store:store},
                    dataType:'json',
                    success:function(data)
                    {


                        $('.Data').html(data.table_data);
                        $("#Data").show();

                    }
                })
            }

            $(document).on('keyup', '#search', function(event){
                var search = $(this).val();
                var client = $('#client').val();

                if (event.which != '13') {

                    fetch_customer_data(search,client);

                }

            });


            $(document).on('change', '#client', function(){
                var client = $(this).val();
                var search = $('#search').val();
                fetch_customer_data(search,client);
            });


        });
    </script>

    <!-- Add Products -->
    <script>
        function Fun(r) {

            var P_Ar_Name = $("#P_Ar_Name"+r).val();
            var P_En_Name= $("#P_En_Name"+r).val();
            var Product = $("#Product"+r).val();
            var UnitID = $("#UnitPurch"+r).val();
            var UnitName = $("#UnitPurchName"+r).val();
            var Barcode = $("#CodePurch"+r).val();
            var Price = $("#Price"+r).val();
            var Cost = $("#CostPrice"+r).val();
            var Total = $("#Total"+r).val();
            var TotalCost = $("#TotalCost"+r).val();
            var VOne = $("#VOne"+r).val();
            var VTwo = $("#VTwo"+r).val();
            var V_Name = $("#V_Name"+r).val();
            var VV_Name = $("#VV_Name"+r).val();
            var AvQty = $("#AvQty"+r).val();
            var Qty = $("#Qty"+r).val();
            var ExpDate = $("#ExpDate"+r).val();
            var Viro = '';
            var VViro = '';
            var NSUB = '';
            var serial =$("#serial"+r).val();

            if( V_Name != ''){

                Viro= '(' + V_Name +')';
            }

            if( VV_Name != ''){

                VViro= '(' + VV_Name +')';
            }


            var Exp='';
            var ED = $("#ED").val();

            if(ED == 1){

                Exp = "<td><input type='hidden' name='Exp_Date[]' value='"+ExpDate+"'>" + ExpDate + "</td>";

            }else{

                Exp = "<input type='hidden' name='Exp_Date[]' value='"+ExpDate+"'>";
            }



            document.getElementById("AddBtnPur"+r).style.display = "none";
            document.getElementById("Row"+r).style.display = "none";
            $("#Data").hide();


            var LANG = $("#LANG").val();
            if(LANG == 'ar' ){
                var Nemo = P_Ar_Name ;
            }else{
                var Nemo = P_En_Name ;
            }


            var markup = "<tr><td><input type='hidden' name='P_Ar_Name[]' value='"+P_Ar_Name+"'><input type='hidden' name='P_En_Name[]' value='"+P_En_Name+"'>" + Nemo + ""+ Viro +" "+ VViro +"</td><td><input type='hidden' name='Unit[]' value='"+UnitID+"'>" + UnitName + "</td><td><input type='hidden' id='BAR"+r+"' name='P_Code[]' value='"+Barcode+"'>" + Barcode + "</td><td><input class='form-control' name='AvQty[]' type='text' readonly  value='"+AvQty+"'></td><td><input type='text' readonly class='form-control Qun'  name='Qty[]'  value='"+Qty+"'></td>"+Exp+"<td><button id='DelAssem' type='button' class='btn btn-default'><i class='fal fa-trash'></i></button><input id='PRO"+r+"' type='hidden' name='Product[]' value='"+Product+"'><input type='hidden' name='VOne[]' value='"+VOne+"'><input type='hidden' name='VTwo[]' value='"+VTwo+"'></td><input type='hidden' name='V_Name[]' value='"+Viro+"'><input type='hidden' name='VV_Name[]' value='"+VViro+"'><input type='hidden' name='Price[]'  value='"+Price+"'><input type='hidden'  name='CostPrice[]'  value='"+Cost+"'><input type='hidden'  name='Total[]' class='Tot'  value='"+Total+"'><input type='hidden' class='TotCost'  name='TotCost[]'  value='"+TotalCost+"'></tr>";



            var P = $("#PRO"+r).val();
            var Bar = $("#BAR"+r).val();
            if(Product != P &&  Barcode != Bar){
                $("#data-dt").append(markup);
            }

            $.fn.rowCount = function() {
                return $('tr', $(this).find('tbody')).length;
            };

            var rowctr = $('#dt').rowCount();

            var sumQ = 0;
            $('.Qun').each(function(){
                sumQ += parseFloat($(this).val());
            });

            var sumT = 0;
            $('.Tot').each(function(){
                sumT += parseFloat($(this).val());
            });
      var sumCost = 0;
            $('.TotCost').each(function(){
                sumCost += parseFloat($(this).val());
            });




            $('#Product_Numbers').val(parseFloat(rowctr));
            $('#Product_NumbersHide').val(parseFloat(rowctr));
            $('#Total_Qty').val(parseFloat(sumQ));
            $('#Total_PriceHide').val(parseFloat(sumT));
            $('#Total_Cost').val(parseFloat(sumCost));






            if(rowctr == 0){
                document.getElementById("Submit").style.display = "none";

            }else{

                document.getElementById("Submit").style.display = "block";
            }


            $('#data-dt').on('click', '#DelAssem', function(e){
                $(this).closest('tr').remove();


                $.fn.rowCount = function() {
                    return $('tr', $(this).find('tbody')).length;
                };

                var rowctr = $('#dt').rowCount();

                var sumQ = 0;
                $('.Qun').each(function(){
                    sumQ += parseFloat($(this).val());
                });

                var sumT = 0;
                $('.Tot').each(function(){
                    sumT += parseFloat($(this).val());
                });


                var sumCost = 0;
                $('.TotCost').each(function(){
                    sumCost += parseFloat($(this).val());
                });




                $('#Product_Numbers').val(parseFloat(rowctr));
                $('#Product_NumbersHide').val(parseFloat(rowctr));
                $('#Total_Qty').val(parseFloat(sumQ));
                $('#Total_PriceHide').val(parseFloat(sumT));
                $('#Total_Cost').val(parseFloat(sumCost));




            })


        }
    </script>

    <!-- Total Function -->
    <script>
        function PurchTotal(r) {

            var Qty = $("#Qty" + r).val();
            var AvQty = $("#AvQty" + r).val();
            var Price = $("#Price" + r).val();
            var CostPrice = $("#CostPrice" + r).val();


           var tot= parseFloat(Price) * parseFloat(Qty) ;
           var totCost= parseFloat(CostPrice) * parseFloat(Qty) ;

            $("#Total" + r).val(parseFloat(tot).toFixed(2));
            $("#TotalCost" + r).val(parseFloat(totCost).toFixed(2));

            var Total = $("#Total" + r).val();
            var TotalCost = $("#TotalCost" + r).val();



            if(parseFloat(Qty) <= parseFloat(AvQty)) {

                if (Qty == '' || Price == '' || Total == '' || TotalCost == '') {

                    document.getElementById("AddBtnPur" + r).style.display = "none";
                }


                if (Qty != '' && Price != '' && Total != '' && TotalCost != 0) {

                    if (Qty < 0 || Price < 0 || Total < 0) {

                        document.getElementById("AddBtnPur" + r).style.display = "none";


                    } else {

                        document.getElementById("AddBtnPur" + r).style.display = "inline-block";

                    }

                }
            }else{

                document.getElementById("AddBtnPur" + r).style.display = "none";
            }


        }
    </script>

    <!-- Scanner  problem -->
    <script>
        $(".form-control").keypress(function(event){
            if (event.which == '10' || event.which == '13') {
                event.preventDefault();
            }
        });


    </script>

    <!-- Submit Script -->
    <script>

        function SPS(){
            $('#sp').val(0);
            var x= $('#sp').val();

            if(x == 0){
                document.getElementById("Submit").style.display = "none";
                document.getElementById('form').submit();
            }



        }

        function SPP(){
            $('#sp').val(1);
            var x= $('#sp').val();

            if(x == 1){
                document.getElementById("Submit").style.display = "none";
                document.getElementById('form').submit();
            }



        }

    </script>


<?php $__env->stopPush(); ?>

<?php echo $__env->make('admin.index', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/limraerp/public_html/orient.limraerp.com/resources/views/admin/Sales/Gifts.blade.php ENDPATH**/ ?>