{literal}
<script type="text/javascript" charset="utf-8">
    $("[id^='parcode']").live('keypress', function () {
        if (event.which == '10' || event.which == '13') {
            event.preventDefault();
        }
    });
    function getproductbyParcode(e, value) {
        //\s means "one space", and \s+ means "one or more spaces".
        value = value.replace(/\s+/g, '');//\s is the regex for "whitespace", and g is the "global" flag, meaning match ALL \s (whitespaces).
        var code = (e.keyCode ? e.keyCode : e.which);
        //to stop the submit of the form
        if (e.which == 13 && value != "") {
            var billnameid = 3;
            value = value.replace("ه", "i");//this replacement is for parcode reader
            value = value.replace("÷", "i");//this replacement is for parcode reader
            value = value.replace("/", "i");//this replacement is for parcode reader
            value = value.replace("I", "i");//this replacement is for parcode reader
            //alert(value.charAt(0));
            $.ajax({
                url: 'sellbillAjaxController.php?do=getproductNamebyOnlyParcode&parcode=' + value + '&billnameid=' + billnameid + '',
                success: function (data) {
                    var response = $.parseJSON(data);
                    $("#product").select2('data', {id: response.id, text: response.text});
                }
            });
            // }
        }
    }
</script>
{/literal}

<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">المنتجات</a></li>
            <li class="active">تقرير الجرد</li>
        </ol>
        <div class="panel panel-default panel-m">
            <div class="panel-heading">
                <h3 class="panel-title">تقرير الجرد</h3>
                <a href="{$youtubes[58]->url}" target="_blank" class="hidden-print"><img
                        src="../views/default/assets/img/youtube.png" class="pull-left" alt="Youtube"
                        style="width: 2%;"></a>

            </div>
            <div class="panel-body">
                <form class="form-horizontal" role="form" action="inventoryController.php?do=invReport" method="post">
                    <div class="form-group">
                        <label for="storesData" class="col-lg-2 control-label">المخزن</label>
                        <div class="col-lg-4">
                            <select class="select2 wdt100" name="storeId" id="storeId">
                                <option value="-1">اختر مخزن</option>
                                {foreach $storesData as $store}
                                <option value="{$store->storeId}">{$store->storeName}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>

                    <!-- ================================================= -->
                    <div class="form-group">
                        <label for="catId" class="col-lg-2 control-label">التصنيف الرئيسى</label>
                        <div class="col-lg-4">
                            <select class="select2 wdt100 productCat" data-level="0" name="productCatId0"
                                    id="productCatId0">
                                <option value="-1">اختر تصنيف</option>
                                {foreach $catData as $data}
                                <option value="{$data->productCatId}">{$data->productCatName}</option>
                                {/foreach}
                            </select>
                        </div>
                        <input type="hidden" id="level" name="level" value="0">
                    </div>

                    <div id="manyParents">

                    </div>

                    <!-- ================================================= -->

                    <div class="form-group">
                        <label for="parent" class="col-lg-2 control-label">المنتج</label>
                        <div class="col-lg-4">
                            <input type="hidden" id="product" name="product" data-placeholder="اختر"
                                   class="select2product wdt100" />
                        </div>
                    </div>

                    <!-- ================================================= -->

                    <div class="form-group">
                        <label for="parent" class="col-lg-2 control-label">الباركود</label>
                        <div class="col-lg-4">
                            <input type="text" name="parcode" id="parcode" class="form-control"
                                   onkeypress="getproductbyParcode(event, this.value);" placeholder="need to press enter">
                        </div>
                        <!--                        <div class="col-lg-2">
                                                    {if $manyParcodes != 1}
                                                    <button type="button" class="btn btn-success pull-left ft-nor addManyParcodes"
                                                            id="addManyParcodes" data-type="sell" style="margin-left:3px;">إضافة بالباركود المجمع
                                                    </button>
                                                    <span
                                                        class="col-lg-4 pull-left {if $billsettingsData[99]->billsettingsvalue != 1} hidden {/if} ">
                                                        <select class="select2 wdt100" id="billTemplatesId"
                                                                data-placeholder="الفواتير المحفوظة">
                                                            <option value=""></option>
                                                            {foreach $allBillTemplates as $item}
                                                            <option value="{$item->id}">{$item->name}</option>
                                                            {/foreach}
                                                        </select>
                                                        {/if}
                                                    </span>
                                                </div>-->
                        <div class="col-lg-1"><button type="submit" class="btn btn-primary pull-left"
                                                      id="searchnow">بحث</button></div>
                    </div>


                    <div class="form-group">
                        <label for="parent" class="col-lg-2 control-label">التاريخ من</label>

                        <div class="col-lg-4">
                            <input type="text" class="form-control awdatepicker " autocomplete="off"
                                   data-date-format="yyyy-mm-dd" name="from" id="from" value="">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="parent" class="col-lg-2 control-label">التاريخ الى</label>

                        <div class="col-lg-4">
                            <input type="text" class="form-control awdatepicker " autocomplete="off"
                                   data-date-format="yyyy-mm-dd" name="to" id="to" value="">
                        </div>
                    </div>



                    <!-- ================================================= -->
                    <div id="productsDiv">

                    </div>
                    <input name="storenegative" type="hidden" value="{$storenegative}" id="storenegative" />
                    <!--  <div class="form-group">
                        <div class="col-lg-offset-2 col-lg-4">
                            <button type="submit"  class="btn btn-primary pull-left">حفظ</button>
                        </div>
                    </div> -->
                </form>
                <input type="hidden" name="searchvalue"  value="{$programsettingsdata->searchvalue}" /><!--id="searchvalue"-->

                <div class="col-lg-offset-8 col-lg-4">
                    <div class="well well-sm">
                        <h4 class="text-center">مجموع الإجماليات:  {$sum+0}</h4>
                    </div>
                </div>
                <div class="clearfix"></div>
                <table class="dataTableClass" id="productsTable">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>المنتج</th>
                            <th>التصنيف</th>
                            <th>التاريخ</th>
                            <th>قبل الجرد</th>
                            <th>بعد الجرد</th>
                            <th>الهالك بالزياده</th>
                            <th>الهالك بالنقص</th>
                            <th>القيمة</th>
                            <th>الإجمالي</th>
                            <th>المستخدم</th>
                        </tr>
                    </thead>
                    <tbody>
                        {assign var=i value=1}
                        {assign var=totalPlus value=0}
                        {assign var=totalMinus value=0}
                        {assign var=totalVal value=0}
                        {assign var=totalSum value=0}

                        {foreach $result as $data}
                        
                        {assign var=totalVal value=$totalVal+$data['price']}
                        {assign var=totalSum value=$totalSum+($data['price'] * $data['productafter'])}
                        <tr>
                            <td>{$i}</td>
                            <td>{$data['productName']}</td>
                            <td>{$data['productCatName']}</td>
                            <td>{$data['storereportdate']}</td>
                            <td>{$data['productbefore']}</td>
                            <td>{$data['productafter']}</td>
                            <td>{if $data['productbefore'] <= $data['productafter']}
                                {abs($data['productquantity'])}
                                {assign var=totalPlus value=$totalPlus+abs($data['productquantity'])}
                                {/if}</td>
                            <td>{if $data['productbefore'] > $data['productafter']}
                                {abs($data['productquantity'])}
                                {assign var=totalMinus value=$totalMinus+abs($data['productquantity'])}
                                {/if}</td>
                            <td>{$data['price']}</td>
                            <td>{$data['price'] * $data['productafter']}</td>
                            <td>{$data['employeename']}</td>
                        </tr>
                        {assign var=i value=$i+1}
                        {/foreach}
                    </tbody>
                    <tfoot>
                        <tr>
                            <th colspan="6" class="text-center">المجموع</th>
                            <th>{$totalPlus}</th>
                            <th>{$totalMinus}</th>
                            <th>{$totalVal}</th>
                            <th>{$totalSum}</th>
                            <th></th>
                        </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </div>
</div>


<!-- Modal -->
<div class="modal fade" id="myModalManyParcodes" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content bg-modal">
            <div class="modal-header">
                <button type="button" class="close pull-left savemodel2" data-dismiss="modal"
                        aria-hidden="true">&times;</button>
                <h4 class="modal-title">اضافة منتجات بالباركود المجمع</h4>
            </div>
            <div class="modal-body">
                <form id="manyParcodesForm" action="inventoryControllerAjax.php?do=addManyParcodes" method="post"
                      class="form-horizontal">
                    <div class="form-group">
                        <label for="debtLimit" class="col-lg-3 control-label">الباركودات مجمعة</label>
                        <div class="col-lg-9">
                            <textarea name="manyParcodes" class="form-control" style="background: url(http://i.imgur.com/2cOaJ.png);
                                      background-attachment: local;
                                      background-repeat: no-repeat;
                                      padding-left: 35px;
                                      padding-top: 10px;
                                      text-align: left !important;
                                      border-color:#ccc;
                                      direction: ltr;" id="manyParcodes" rows="5"></textarea>

                        </div>
                        <div id='hazemc'>1</div>
                    </div>
                    <input type="hidden" name="manyParcodesstoreid" id="manyParcodesstoreid" value="" />
                    <input type="hidden" name="manyParcodesproductCatId" id="manyParcodesproductCatId" value="" />
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default savemodel2" data-dismiss="modal">الغاء</button>
                <button type="button" class="btn btn-primary" id="doAddManyParcodes">تم</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

{literal}
<script type="text/javascript">
    $(document).on('click', "#addManyParcodes", function () {
        if ($('#storeId').val() == "-1" || $('#storeidto').val() == "-1") {
            alert('اختر المخزن اولا');
        } else {
            $('#myModalManyParcodes').modal('show');
            setTimeout(function () {
                $('#manyParcodes').focus();
            }, 800);
        }
    });


</script>
{/literal}