<div class="container">
    <ol class="breadcrumb">
        <li><a href="#">إدارة الفواتير</a></li>
        <li><a href="#">فاتورة المشتريات والمردودات</a></li>
        <li class="active">عرض الفواتير</li>
    </ol>
    <div class="row">
        <div class="panel panel-default panel-m">
            <!-- Default panel contents -->
            <div class="panel-heading">فواتير مردودات المشتريات <br />
                {if $message != ""}
                {$message}
                {/if}
                <a href="{$youtubes[34]->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">
                <input type="hidden" id="searchvalue" value="{$Programsettingdata->searchvalue}">
                <form class="form-inline hidden-print" action="returnBuyBillController.php?do=show" method="post">
                    <div class="form-group">
                        <label class="sr-only">إسم المورد</label>
                        <!--                        <select id="supplier" name="supplier" data-placeholder="اختر المورد" class="select2 wdt100" onChange="this.form.submit();">
                                                    <option value="-1"></option>



                                                    {foreach $suppliersData as $supplier}

                                                    <option value="{$supplier->supplierid}">{$supplier->suppliername}</option>

                                                    {/foreach}


                                                </select>-->
                        <input type="hidden" name="supplier" id="supplier" class="select2Supp" onChange="this.form.submit();"/>
                        <input type="hidden" name="oldsupplierid" id="oldsupplierid" value=""/>
                        <input type="hidden" name="oldsuppliername" id="oldsuppliername" value=""/>
                    </div>
                    <div class="form-group" {if {$Programsettingdata->billid} eq 1}  style="display:none" {/if}>
                        <label class="sr-only">رقم الفاتورة</label>
                        <select data-placeholder="اختر رقم الفاتورة" class="select2 wdt100" name="serial"  onChange="this.form.submit();">
                            <option value="-1"></option>



                            {foreach $returnbuybillSerialData as $returnbuybillSerial}



                            <option value="{$returnbuybillSerial->returnbuybillSerial}">{$returnbuybillSerial->returnbuybillSerial}</option>

                            {/foreach}



                        </select>
                    </div>
                    <div class="form-group">
                        <label class="sr-only">الرقم تسلسل الفاتورة</label>
                        <select data-placeholder="اختر الرقم المتسلسل" class="select2 wdt100" name="buybillid"  onChange="this.form.submit();">
                            <option value="-1"></option>



                            {foreach $returnbuybillSerialData as $buybillid}





                            <option value="{$buybillid->returnbuybillid}">{$buybillid->returnbuybillid}</option>



                            {/foreach}



                        </select>
                    </div>
                    <br/>
                    <div class="form-group">
                        <label class="sr-only">من التاريخ</label>
                        <input type="text" class="form-control awdatepicker" autocomplete="off"   data-date-format="yyyy-mm-dd" name="from" >
                    </div>
                    <div class="form-group">
                        <label class="sr-only">إلى التاريخ</label>
                        <input type="text" class="form-control awdatepicker" autocomplete="off"   data-date-format="yyyy-mm-dd" name="to" >
                    </div>
                    <div class="form-group">
                        <label class="sr-only">اخفاء المحذوف
                            <input type="checkbox" class="search_bill" name="hideDel" id="hideDel"  value="1"></label>
                    </div>
                    <button type="submit" class="btn btn-primary noprint">بحث</button>
                </form>
            </div>
            <hr/>
            <div class="col-lg-offset-8 col-lg-4 ">
                <div class="well well-sm">
                    <h4 class="text-center">إجمالي المردودات:  {$totalBills}</h4>
                </div>
            </div>
            <div class="clearfix"></div>
            {literal}
            <form id="form1" name="form1" method="post" action="returnBuyBillController.php?do=delete"onsubmit="if (Spry.Widget.Form.validate(this)) {
                        return countChoosenProducts('returnBuyBillController');
                    } else {
                        return false;
                    }" enctype="multipart/form-data">
                {/literal}
                <!-- Table -->
                <table class="table table-black">
                    <thead>
                        <tr>
                            <th class="hidden-print">
                                <label>
                                    <input type="checkbox" name="checkAll" id="checkAll"/>
                                </label>
                            </th>
                            {if $Programsettingdata->clientserial eq 1}<th>رقم تسلسل الفاتورة</th>{/if}
                            <th>اسم المورد</th>
                            <th {if {$Programsettingdata->billid} eq 1}  style="display:none" {/if}>رقم الفاتورة</th>
                            <th>إجمالي الفاتورة</th>
                            <th>التاريخ</th>
                            <th>المستخدم</th>
                            <th class="hidden-print">تفاصيل الفاتورة</th>
                            {if $usergroup->allowEditDelInBuyBills eq 0}<th class="hidden-print">تعديل الفاتورة</th>{/if}
                            <!--        <th class="hidden-print">تكويد المنتجات</th>
                            -->
                            {if $usergroup->allowEditDelInBuyBills eq 0}<th class="hidden-print">حذف</th>{/if}
                        </tr>
                    </thead>
                    <tbody>

                        {foreach $returnbuybillData as $data}
                        {if {$data->conditions} eq 1}
                        <tr class="danger"> {elseif {$data->conditions} eq 0}
                        <tr> {/if}
                            <td class="hidden-print">
                                <label>
                                    <input type="checkbox" name="choosedItem[]" id="checked{$i}" class="choosenItem" value="{$data->returnbuybillid}" />
                                </label>
                            </td>
                            {if $Programsettingdata->clientserial eq 1}<td>{$data->returnbuybillid}</td>{/if}
                            <td> {$data->suppliername} </td>
                            <td {if {$Programsettingdata->billid} eq 1}  style="display:none" {/if}>{$data->returnbuybillSerial}</td>
                            <td>{$data->returnbuybillaftertotalbill}</td>
                            <td>{$data->returnbuybilldate}</td>
                            <td>{$data->username}{if $data->delbyusername}<br/><span style="color: red">{$data->delbyusername}</span>{/if}</td>
                            <td  class="hidden-print"><a href="returnBuyBillController.php?do=details&id={$data->returnbuybillid}" type="button" class="btn btn-default btn-lg notesicon"></a></td>

                            {if $usergroup->allowEditDelInBuyBills eq 0}<td  class="hidden-print">
                                {if {$data->conditions} eq 0}
                                <a href="buyBillController.php?do=editreturn&id={$data->returnbuybillid}" type="button" class="btn btn-default btn-lg notesicon"></a>

                                {else}
                                تم حذف الفاتوره
                                {/if}</td>{/if}

                            <!--       <td  class="hidden-print"><a href="productsParcodeController.php?id={$data->returnbuybillid}&type=1" type="button" class="btn btn-default btn-lg editicon"></a></td>
                            -->
                            {if $usergroup->allowEditDelInBuyBills eq 0}<td  class="hidden-print"> {if {$data->conditions} eq 0} <a href="#" type="button" class="btn btn-default btn-lg deleteicon conformdel1" data-position="returnBuyBillController.php?do=delete&id={$data->returnbuybillid}&action={$data->dailyentryid}"> </a> {elseif {$data->conditions} eq 1 } تم حذف الفاتورة</td>{/if}
                            {/if} </tr>
                        {/foreach}
                    </tbody>

                </table>
                <div  class="hidden-print">
                    <div class="col-lg-12">
                        <div class="well well-sm">
                            <div class="form-group">
                                <div class="col-lg-4">
                                    <label for="operation"></label>
                                    <span id="spryselect2">
                                        <select name="operation" id="operation"  data-placeholder="اختر العملية" class="select2 wdt100">
                                            <option value="-1"></option>
                                            <option value="1">حذف</option>
                                        </select>
                                        <span class="selectInvalidMsg">اختر العملية</span></span></div>
                            </div>
                            <div class="form-group">
                                <div class="col-lg-4">
                                    <input name=""  class="noprint btn btn-primary" type="submit" value="تنفيذ"/>
                                </div>
                            </div>

                            <!-----------  start noElementsError alert ------------->
                            <div class="clearfix"></div>
                            <div id="noElementsError" class="alert alert-danger fade in" style="display:none;">
                                <button type="button" class="close pull-left" data-dismiss="alert" aria-hidden="true">×</button>
                                <p>يجب اختيار العناصر أولاً</p>
                                <div class="clearfix"></div>
                            </div>
                            <!----------  end noElementsError alert -------------->

                            <div class="clearfix"></div>
                        </div>
                    </div>
                    <div class="col-lg-offset-8 col-lg-4 ">
                        <div class="well well-sm">
                            <h4 class="text-center">إجمالي المردودات:  {$totalBills}</h4>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                </div>
            </form>
            <div class="clearfix"></div>

            <!-- Modal -->
            <div class="hidden-print">
                <div class="modal fade " id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close pull-left" data-dismiss="modal" aria-hidden="true">&times;</button>
                                <div class="modal-title">تأكيد حذف الفاتوره</div>
                            </div>
                            <div class="modal-body"> هل تريد حذف هذه الفاتوره؟ </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">لا</button>
                                <button type="button" class="btn btn-primary savemodel1">نعم</button>
                            </div>
                        </div>
                        <!-- /.modal-content -->
                    </div>
                    <!-- /.modal-dialog -->
                </div>
            </div>
            <!-- /.modal -->
            <hr />
            <div  class="hidden-print">
                <div class="col-lg-12">
                    <div class="form-group">
                        <div class="col-lg-4">
                            <button type="button" onclick="print_Custom('mycustomheader');" class="btn btn-success pull-right">طباعة</button>
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="clearfix"></div>
        </div>
    </div>
</div>
{literal}
<script type="text/javascript">
    var spryselect2 = new Spry.Widget.ValidationSelect("spryselect2", {invalidValue: "-1", isRequired: false});
    $('.conformdel1').click(function (e) {

        e.preventDefault();

        var elemposition = $(this).data('position');

        $("#myModal1").find(".savemodel1").attr('data-position', elemposition);
        $('#myModal1').modal('show');
    });
    $('.savemodel1').on('click', function () {

        $('#myModal1').modal('hide');
        var pos = $(this).attr('data-position');

        window.location.href = pos;
    });

    $(function () {
        $(".select2Supp").select2({
            placeholder: "المورد",
            minimumInputLength: document.getElementById("searchvalue").value,
            //inimumInputLength: 0,
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "supplierAjaxController.php?do=select2supplier",
                dataType: 'json',
                data: function (term, page) {
                    return {
                        term: term, //search term
                        page_limit: 7, // page size
                        withAddOption: 0,
                        withNakdi: 1,
                        //jsonRowRet: 1,
                    };
                },
                results: function (data) {
                    return {results: data};
                }
            },
            formatResult: function (data) {
                if (Number(data.id) == -2) {
                    return  '<span class="newoption">' + data.text + '</span >';
                } else {
                    return  '<span>' + data.text + '</span >';
                }
            },
            initSelection: function (element, callback) {
                var item = element.val().split(':');
                //  var data = {id: item[0], text: item[1]};
                var data = {id: item[0], text: item[1], productquantity: item[2], price: item[3]};
                callback(data);
            },
            //dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
        });
        //this is needed for ajax =>to obtain id from it  and use in ajax
        $('#supplier').select2('data', {id: $('#oldsupplierid').val(), text: $('#oldsuppliername').val()});
    });
</script>
{/literal}