
<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">
            <!-- Default panel contents -->
            <div class="panel-heading">فواتير معلقه <br /><!-- عروض الاسعار -->
                {if $message != ""}
                {$message}
                {/if}
                <a href="{$youtubes[44]->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}">
                <div id="outputString" class="alert alert-block alert-success fade in hidden-print" style="display:none">
                    <button type="button" class="close pull-left" data-dismiss="alert" aria-hidden="true">&times;</button>
                    <p id="outputStringValue">{$outputString}</p>
                    <div class="clearfix"></div>
                </div>
                <input type="hidden" name="withNakdi" id="withNakdi" value="{$Usergroupdata->showClientAndSupplierOne}"/>
                <form class="form-inline hidden-print" action="sellbillController.php?do=showoffers" method="post">
                    <div class="form-group">
                        <label class="sr-only">العميل</label>
                        <!--                        <select class="select2 wdt100 search_bill"  name="clientid" id="clientid" >
                                                    <option value="-1">اختر عميل</option>
                                                    {foreach $clientData as $client}
                                                    <option value="{$client->clientid}">{$client->clientname}</option>
                                                    {/foreach}
                                                </select>-->
                        <input type="hidden" name="clientid" id="clientid" class="select2Supp search_bill"/>
                        <input type="hidden" name="oldsupplierid" id="oldsupplierid" value=""/>
                        <input type="hidden" name="oldsuppliername" id="oldsuppliername" value=""/>
                    </div>

                    <div class="form-group {if {$billsettingsData[3]->billsettingsvalue} eq 0}  {else} hidden {/if}" >
                        <label class="sr-only">{if $Programsettingdata->delegate_seller eq 0} بائع {elseif $Programsettingdata->delegate_seller == 1}مندوب {elseif $Programsettingdata->delegate_seller == 2}طبيب {/if}</label>
                        <select class="select2 wdt100 search_bill"  name="sellerid" id="sellerid" >
                            <option value="-1">اختر {if $Programsettingdata->delegate_seller eq 0} بائع {elseif $Programsettingdata->delegate_seller == 1}مندوب {elseif $Programsettingdata->delegate_seller == 2}طبيب {/if}</option>



                            {foreach $sellerData as $mysellerData}



                            <option value="{$mysellerData->userid}">{$mysellerData->employeename}</option>


                            {/foreach}



                        </select>
                    </div>

                    <div class="form-group"{if {$Programsettingdata->billid} eq 1}  style="display:none" {/if}>
                        <label class="sr-only">رقم العرض</label>
                        <input type="text" class="form-control search_bill" placeholder="رقم العرض" name="sellbillserial" id="sellbillserial">
                    </div>
                    <div class="form-group">
                        <label class="sr-only">الرقم تسلسل العرض</label>
                        <input type="text" class="form-control search_bill" placeholder="رقم تسلسل العرض" name="sellbillid" id="sellbillid">
                    </div>
                    <br/>

                    <div id="dateTimeDiv">
                        <div class="form-group">
                            <label class="sr-only">من التاريخ</label>
                            <div  class="input-group date form_datetime col-md-5" data-date="" data-date-format="yyyy-mm-dd  h:i:s" data-link-field="dtp_input1">
                                <input class="form-control search_bill" size="16" type="text" value="" name="from" id="from" readonly="" >
                                <span class="input-group-addon " style="width: 0%;"><span class=" glyphicon glyphicon-remove col-lg-4"></span></span>
                                <span class="input-group-addon"  style="width: 0%;"><span class="glyphicon glyphicon-th col-lg-4"></span></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="sr-only">إلى التاريخ</label>
                            <div  class="input-group date form_datetime col-md-5" data-date="" data-date-format="yyyy-mm-dd  h:i:s" data-link-field="dtp_input1">
                                <input class="form-control search_bill" size="16" type="text" value="" name="to" id="to" readonly="" >
                                <span class="input-group-addon " style="width: 0%;"><span class=" glyphicon glyphicon-remove col-lg-4"></span></span>
                                <span class="input-group-addon" style="width: 0%;"><span class="glyphicon glyphicon-th col-lg-4"></span></span>
                            </div>
                        </div>
                    </div>

                    <div id="dateOnlyDiv">
                        <div class="form-group">
                            <label class="sr-only">من التاريخ</label>
                            <input type="text" class="form-control awdatepicker search_bill" autocomplete="off"   data-date-format="yyyy-mm-dd" name="from" id="from">
                        </div>
                        <div class="form-group">
                            <label class="sr-only">إلى التاريخ</label>
                            <input type="text" class="form-control awdatepicker search_bill" autocomplete="off"   data-date-format="yyyy-mm-dd" name="to" id="to">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="sr-only">بحث بـ</label>
                        <div  class="input-group">
                            <label>  <input value="dateOnly" name="search" id="searchdateOnly" type="radio" checked onclick='localStorage.setItem("search", "dateOnly");
                                    window.location.reload();'>
                                تاريخ</label>
                            <label>
                                <input value="dateTime" name="search" id="searchdateTime" type="radio" onclick='localStorage.setItem("search", "dateTime");
                                        window.location.reload();'>
                                تاريخ ووقت</label>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                    <button type="submit" class="btn btn-primary">بحث</button>
                    <input type="hidden" name="getTodayBills" id="getTodayBills" value="0"/>
                    <button type="submit" class="btn btn-primary" onclick="$('#getTodayBills').val(1);">نتائج اليوم</button>
                </form>
            </div>
            <hr/>
            <div  id="tableWrap">
                <div class="clearfix"></div>
                <div class="message-table"> {$message}</div>
                {literal}


                <form>
                    {/literal}
                    <table class="table table-black dataTableClass" id="excelTable">
                        <thead>
                            <tr>
                                <th class="hidden-print">
                                    <input type="checkbox" name="checkAll" id="checkAll"/>
                                </th>
                                {if $Programsettingdata->clientserial eq 1}<th>رقم تسلسل العرض</th>{/if}
                                {if {$Programsettingdata->billid} neq 1} <th>رقم العرض</th>{/if}
                                <th>اجمالى العرض</th>
                                <th>تاريخ العرض</th>
                                <th>العميل</th>
                                <th {if {$billsettingsData[3]->billsettingsvalue} eq 0} style="display:block" {else} style="display:none" {/if}>{if $Programsettingdata->delegate_seller eq 0} بائع {elseif $Programsettingdata->delegate_seller == 1}مندوب {elseif $Programsettingdata->delegate_seller == 2}طبيب {/if}</th>
                                <th>المستخدم</th>
                                <th class="hidden-print">تفاصيل العرض</th>
                                {if $usergroup->allowEditDelInBills eq 0}
                                <th class="hidden-print">تعديل العرض</th>
                                <th class="hidden-print">تعديل و حفظ كفاتورة</th>
                                <th class="hidden-print">حفظ كفاتورة</th>
                                <th class="hidden-print">حذف</th>
                                {/if}
                            </tr>
                        </thead>
                        <tbody>
                            {assign var=piecesCount value=0}
                            {assign var=payedTotal value=0}
                            {assign var=remainTotal value=0}
                            {foreach $sellbillData as $sellbill}
                            {assign var=piecesCount value=$piecesCount+$sellbill->sellQuantity}
                            {assign var=payedTotal value=$payedTotal+$sellbill->sellbilltotalpayed}
                            {assign var=remainTotal value=$remainTotal+$sellbill->sellbillfinalbill}

                            {if isset($sellbill->newSellbillidAfterEdit)&& $sellbill->newSellbillidAfterEdit > 0} <!--this bill is deleted for editing-->
                            <tr class="danger">
                                {elseif {$sellbill->conditions} <> 0}
                            <tr class="dark">
                                {else}
                            <tr>
                                {/if}
                                <td class="hidden-print">
                                    <input type="checkbox" name="choosedItem[]" id="checked{$i}" class="choosenItem" value="{$sellbill->sellbillid}" />
                                </td>
                                {if $Programsettingdata->clientserial eq 1}<td>{$sellbill->sellbillid}</td>{/if}
                                {if {$Programsettingdata->billid} eq 0}  <td >{$sellbill->sellbillserial}</td>{/if}
                                <td>{$sellbill->sellbillaftertotalbill}</td>
                                <td>{$sellbill->sellbilldate}</td>
                                <td> {if {$sellbill->clientname} eq ""}
                                    نقدى
                                    {else}
                                    {$sellbill->clientname}
                                    {/if} </td>
                                <td {if {$billsettingsData[3]->billsettingsvalue} eq 0} style="display:block" {else} style="display:none" {/if}>{$sellbill->employeename}</td>
                                <td>{$sellbill->useremployeename}{if $sellbill->delbyusername}<br/><span style="color: red">{$sellbill->delbyusername}</span>{/if}</td>
                                <td class="hidden-print"> <a href="sellbillController.php?do=showDetail&sellbillid={$sellbill->sellbillid}&ordertype=1" type="button" class="btn btn-default btn-lg editicon"></a> </td>
                                {if $usergroup->allowEditDelInBills eq 0}
                                <td class="hidden-print">
                                    {if {$sellbill->conditions} eq 0}
                                    <a href="sellbillController.php?do=editsellBill&sellbillid={$sellbill->sellbillid}&ordertype=1" type="button" class="btn btn-default btn-lg editicon"></a>
                                    {/if}
                                </td>
                                <td class="hidden-print">
                                    {if {$sellbill->conditions} eq 0 && $sellbill->orderSavedBillId == 0}
                                    <a href="sellbillController.php?do=addsellBill&billnameid=3&offerId={$sellbill->sellbillid}&ordertype=0" type="button" class="btn btn-default btn-lg editicon"></a>
                                    {/if}
                                </td>
                                <td class="hidden-print">
                                    {if {$sellbill->conditions} eq 0 && $sellbill->orderSavedBillId == 0}
                                    <a href="sellbillController.php?do=saveOfferAsBill&offerId={$sellbill->sellbillid}" type="button" class="btn btn-default btn-lg editicon" onclick="$(this).hide()"></a>
                                    {/if}
                                </td>
                                <td class="hidden-print">
                                    {if {$sellbill->conditions} eq 0 && $sellbill->orderSavedBillId == 0}
                                    <a href="sellbillController.php?do=delete&sellbillid={$sellbill->sellbillid}&ordertype=1" type="button" class="btn btn-default btn-lg removeicon"></a> {else}
                                    {/if} </td>
                                {/if}
                            </tr>

                            {/foreach}

                        </tbody>

                    </table>
            </div>

            <div class="clearfix"></div>
            <hr />

            </form>

        </div>
    </div>
</div>
{literal}
<script type="text/javascript">
    var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1", {isRequired: false, invalidValue: "-1"});
    //
    var search = localStorage.getItem("search");
    if (search == "dateTime") {
        $('#searchdateTime').attr('checked', 'checked');
        $('#searchdateOnly').removeAttr('checked');
        //
        $('#dateTimeDiv').show();
        $('#dateOnlyDiv').remove();
    } else {
        $('#searchdateOnly').attr('checked', 'checked');
        $('#searchdateTime').removeAttr('checked');
        //
        $('#dateOnlyDiv').show();
        $('#dateTimeDiv').remove();
    }
    //
    $('#excuteOperationBtn').live('click', function (e) {
        e.preventDefault();
        e.stopPropagation();
        //    $('#excuteOperationForm').
        if ($('#operation').val() == "2") {
            var ids = '';
            $(".choosenItem:checked").each(function () {
                ids += $(this).val() + ',';
            });
            if (ids != "") {
                window.open('sellbillprintController.php?do=showDetail2Bulk&id=' + ids);
            } else {
                $("#noElementsError").css("display", "block");
                setTimeout(function () {
                    $("#noElementsError").css("display", "none");
                }, 4000);
            }
        } else {
            return true;
        }
    });

    $(function () {
        $(".select2Supp").select2({
            placeholder: "العميل",
            minimumInputLength: document.getElementById("searchvalue").value,
            inimumInputLength: 0,
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "clientControllerAjax.php?do=select2ClientsAjax",
                dataType: 'json',
                data: function (term, page) {
                    return {
                        term: term, //search term
                        page_limit: 7, // page size
                        withAddOption: 0,
                        withNakdi: function () {
                            return (Number($('#withNakdi').val()) == 1) ? 0 : 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
        $('#clientid').select2('data', {id: $('#oldsupplierid').val(), text: $('#oldsuppliername').val()});
    });
</script>
{/literal}