
<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">ادارة الفواتير</a></li>
            <li><a href="sellbillandruternController.php?do=show">فواتير مبيعات ومردودات</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[39]->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>
                <form class="form-inline hidden-print" action="sellbillandruternController.php?do=show" 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">
                        <label class="sr-only">اسم المستخدم</label>
                        <select class="select2 wdt100 search_bill"  name="selleruserid" id="selleruserid" >
                            <option value="-1">اختر المستخدم</option>



                            {foreach $sellerinsertData as $mysellerinsertData}



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


                            {/foreach}



                        </select>
                    </div>


                    <div class="form-group">
                        <label class="sr-only">رقم تسلسل الفاتورة</label>
                        <input type="text" class="form-control search_bill" placeholder="رقم تسلسل الفاتورة"  name="sellbillid" id="sellbillid">
                    </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>
                    <br/>
                    <div class="form-group">
                        <label class="sr-only">المخزن</label>
                        <select class="select2 wdt100 search_bill"  name="storeid" id="storeid" >
                            <option value="-1">اختر المخزن</option>
                            {foreach $stores as $data}
                            <option value="{$data->storeId}">{$data->storeName}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="form-group">
                        <label class="sr-only">الخزنة</label>
                        <select class="select2 wdt100 search_bill"  name="saveid" id="saveid" >
                            <option value="-1">اختر الخزنة</option>
                            {foreach $saves as $data}
                            <option value="{$data->saveid}">{$data->savename}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="form-group">
                        <label class="sr-only">نوع السعر</label>
                        <select class="select2 search_bill wdt100" name="pricetype" id="pricetype">
                            <option value="-1"></option>
                            <option value="0">جملة</option>
                            <option value="1">تجزئة</option>
                            <option value="2">نصف جملة</option>
                        </select>
                    </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="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 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">بحث</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 class="col-lg-offset-8 col-lg-4 ">
                <div class="well well-sm">
                    <h4 class="text-center">صافي المبيعات:  <span id="totalBills2">{$totalBills}</span></h4>
                </div>
            </div>
            <div class="clearfix"></div>
            {literal}
            <form method="post" action="sellbillandruternController.php?do=executeOperation" onsubmit="if (Spry.Widget.Form.validate(this)) {
                        return countChoosenProducts('sellbillandruternController');
                    } else {
                        return false;
                    }">
                {/literal}

                <table class="table table-black dataTableClass">
                    <thead>
                        <tr>
                            <th class="hidden-print">
                                <input type="checkbox" name="checkAll" id="checkAll"/>
                            </th>
                            {if $Programsettingdata->clientserial eq 1}<th>رقم تسلسل الفاتورة</th>{/if}
                            <th {if {$Programsettingdata->billid} eq 1}  style="display:none" {/if}>اجمالى الفاتورة</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>المخزن</th>
                            <th>الخزنة</th>
                            <th class="hidden-print">تفاصيل الفاتورة</th>
                            {if $usergroup->allowEditDelInBills eq 0}<th class="hidden-print">تعديل الفاتورة</th>
                            <th class="hidden-print">حذف</th>{/if}
                            <th class="hidden-print">قيد اليومية</th>
                        </tr>
                    </thead>
                    <tbody>
                        {assign var=piecesCount value=0}
                        {assign var=payedTotal value=0}
                        {assign var=remainTotal value=0}
                        {foreach $sellbillandruternData as $sellbillandrutern}
                        {assign var=piecesCount value=$piecesCount+$sellbillandrutern->sellQuantity-$sellbillandrutern->returnsellQuantity}
                        {assign var=payedTotal value=$payedTotal+$sellbillandrutern->sellbilltotalpayed}
                        {assign var=remainTotal value=$remainTotal+$sellbillandrutern->sellbillfinalbill}


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

                            {if $usergroup->allowEditDelInBills eq 0}<td class="hidden-print">{if {$sellbillandrutern->conditions} eq 0} <a href="sellbillController.php?do=editsellandrutrnBill&sellbillid={$sellbillandrutern->sellbillid}" type="button" class="btn btn-default btn-lg editicon"></a>{else}

                                {if isset($sellbillandrutern->newSellbillidAfterEdit)&& $sellbillandrutern->newSellbillidAfterEdit > 0} <!--this bill is deleted for editing-->
                                حذف للتعديل
                                {else}
                                تم حذف الفاتورة
                                {/if}


                                {/if} </td>


                            <td class="hidden-print"> {if {$sellbillandrutern->conditions} eq 0} <a href="sellbillandruternController.php?do=delete&sellbillid={$sellbillandrutern->sellbillid}" type="button" class="btn btn-default btn-lg removeicon"></a> {else}
                                تم حذف الفاتورة

                                {/if} </td>{/if}
                            <td class="hidden-print">
                                <a href="dailyentry.php?id={$sellbillandrutern->dailyentryid}" target="_blank" type="button" class="btn btn-default btn-lg editicon"></a>
                            </td>
                        </tr>

                        {/foreach}

                    </tbody>

                </table>
                <div class="clearfix"></div>
                <hr />
                <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="spryselect1">
                                        <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>
                            <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>
                            <div class="clearfix"></div>
                        </div>
                    </div>
                    <div class="col-lg-4 "><!-- col-lg-offset-8 -->
                        <div class="well well-sm">
                            <h4 class="text-center">عدد القطع:  <span id="piecesCount">{$piecesCount}</span></h4>
                        </div>
                    </div>
                    <div class="col-lg-4 "><!-- col-lg-offset-8 -->
                        <div class="well well-sm">
                            <h4 class="text-center">إجمالي المبيعات:  <span id="totalSell">{$totalSell}</span></h4>
                        </div>
                    </div>
                    <div class="col-lg-4 "><!-- col-lg-offset-8 -->
                        <div class="well well-sm">
                            <h4 class="text-center">إجمالي المردودات:  <span id="totalRet">{$totalRet}</span></h4>
                        </div>
                    </div>
                    <div class="col-lg-4 "><!-- col-lg-offset-8 -->
                        <div class="well well-sm">
                            <h4 class="text-center">اجمالى المدفوع:  <span id="payedTotal">{$payedTotal}</span></h4>
                        </div>
                    </div>
                    <div class="col-lg-4 "><!-- col-lg-offset-8 -->
                        <div class="well well-sm">
                            <h4 class="text-center">اجمالى المؤجل :  <span id="remainTotal">{$remainTotal}</span></h4>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                </div>
            </form>
        </div>
    </div>
</div>
{literal}
<script type="text/javascript">
    var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1", {isRequired: false, invalidValue: "-1"});
    $(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: 0,
                        //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}