<div class="container">
    <ol class="breadcrumb">
        <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" style="padding:5px 15px 15px">
                <h3 class="panel-title" style="display: inline-block;">اوامر الشراء<br />
                    {if $message != ""}
                    {$message}
                    {/if}</h3>
                <a href="{$youtubes[46]->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="supplierWithAddOption" value="1">
                <input type="hidden" id="searchvalue" value="{$Programsettingdata->searchvalue}">
                <form class="form-inline hidden-print" action="buyBillController.php?do=showoffers" 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">
                        <label class="sr-only">رقم تسلسل الفاتورة</label>
                        <select data-placeholder="اختر رقم التسلسل" class="select2 wdt100" name="buybillid"  onChange="this.form.submit();">
                            <option value="-1"></option>



                            {foreach $billSerials as $buybillid}



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





                            {/foreach}



                        </select>
                    </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 $billSerials as $serial}


                            <option value="{$serial->buybillSerial}">{$serial->buybillSerial}</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>
            <form id="form1" name="form1" method="post" >
                <!-- Table -->
                <table class="table table-black">
                    <thead>
                        <tr>
                            {if $Programsettingdata->clientserial eq 1}<th>رقم تسلسل الفاتورة</th>{/if}
                            <th>اسم المورد</th>
                            <th {if {$Programsettingdata->billid} eq 1}  style="display:none" {/if}>رقم الفاتورة</th>
                            {if $Programsettingdata->showparcode eq 1}<th>باركود  المنتجات</th>{/if}

                            <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>
                            <th class="hidden-print">حفظ كفاتورة</th>
                            {if $usergroup->allowEditDelInBuyBills eq 0}<th class="hidden-print">حذف</th>{/if}
                        </tr>
                    </thead>
                    <tbody>

                        {foreach $buyBillData as $data}
                        {if {$data->conditions} eq 1}
                        <tr class="danger"> {elseif {$data->conditions} eq 0}
                        <tr> {/if}

                            {if $Programsettingdata->clientserial eq 1}<td> {$data->buybillid} </td>{/if}
                            <td> {$data->suppliername} </td>
                            <td {if {$Programsettingdata->billid} eq 1}  style="display:none" {/if}>{$data->buybillSerial}</td>
                            {if $Programsettingdata->showparcode eq 1}<td>{$data->parcodepro}</td>{/if}

                            <td>{$data->buybillaftertotalbill}</td>
                            <td>{$data->buybilldate}</td>
                            <td>{$data->username} {if $data->delbyusername}<br/><span style="color: red">{$data->delbyusername}</span>{/if}</td>
                            <td  class="hidden-print"><a href="buyBillController.php?do=details&id={$data->buybillid}&ordertype=1" 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=editbill&id={$data->buybillid}&ordertype=1" type="button" class="btn btn-default btn-lg editicon"></a>
                                {else}
                                الفاتوره محذوفه
                                {/if}</td>{/if}
                            <td class="hidden-print">
                                {if {$data->conditions} eq 0 && $data->orderSavedBillId == 0}
                                <a href="buyBillController.php?do=bill&billnameid={$data->billnameid}&offerId={$data->buybillid}&ordertype=0" type="button" class="btn btn-default btn-lg editicon"></a>
                                {/if}
                            </td>
                            <td class="hidden-print">
                                {if {$data->conditions} eq 0 && $data->orderSavedBillId == 0}
                                <a href="buyBillController.php?do=saveOfferAsBill&offerId={$data->buybillid}" type="button" class="btn btn-default btn-lg editicon"></a>
                                {/if}
                            </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="buyBillController.php?do=delete&id={$data->buybillid}&ordertype=1"></a> {elseif {$data->conditions} eq 1 } تم حذف الفاتورة</td>{/if}
                            {/if} </tr>
                        {/foreach}
                    </tbody>

                </table>



                <!-- 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 -->
            </form>
            <div class="clearfix"></div>
            <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});
    $('.printparcode').mousedown(function (e) {
        e.preventDefault();
        var href = $(this).attr('href') + '&parcodeTypeToPrint=' + Number(localStorage.getItem("parcodeTypeToPrint"));
        window.open(href)
    });


    $('.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;
    });

</script>
{/literal}