<?php /* Smarty version Smarty-3.1.11, created on 2025-12-29 20:59:13
         compiled from "..\views\default\sellbillandruternview\show.html" */ ?>
<?php /*%%SmartyHeaderCode:16816952cf81a9c519-11402826%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
  'file_dependency' => 
  array (
    '0664f35f1ccb047a76df6b792f179dcca06711cf' => 
    array (
      0 => '..\\views\\default\\sellbillandruternview\\show.html',
      1 => 1752437506,
      2 => 'file',
    ),
  ),
  'nocache_hash' => '16816952cf81a9c519-11402826',
  'function' => 
  array (
  ),
  'variables' => 
  array (
    'message' => 0,
    'youtubes' => 0,
    'Programsettingdata' => 0,
    'outputString' => 0,
    'clientData' => 0,
    'client' => 0,
    'billsettingsData' => 0,
    'sellerData' => 0,
    'mysellerData' => 0,
    'sellerinsertData' => 0,
    'mysellerinsertData' => 0,
    'stores' => 0,
    'data' => 0,
    'saves' => 0,
    'totalBills' => 0,
    'usergroup' => 0,
    'sellbillandruternData' => 0,
    'piecesCount' => 0,
    'sellbillandrutern' => 0,
    'payedTotal' => 0,
    'remainTotal' => 0,
    'i' => 0,
    'totalSell' => 0,
    'totalRet' => 0,
  ),
  'has_nocache_code' => false,
  'version' => 'Smarty-3.1.11',
  'unifunc' => 'content_6952cf81e36b65_98083891',
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_6952cf81e36b65_98083891')) {function content_6952cf81e36b65_98083891($_smarty_tpl) {?>
<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 />
                <?php if ($_smarty_tpl->tpl_vars['message']->value!=''){?>
                <?php echo $_smarty_tpl->tpl_vars['message']->value;?>

                <?php }?>
                <a href="<?php echo $_smarty_tpl->tpl_vars['youtubes']->value[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="<?php echo $_smarty_tpl->tpl_vars['Programsettingdata']->value->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"><?php echo $_smarty_tpl->tpl_vars['outputString']->value;?>
</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>



                                                    <?php  $_smarty_tpl->tpl_vars['client'] = new Smarty_Variable; $_smarty_tpl->tpl_vars['client']->_loop = false;
 $_from = $_smarty_tpl->tpl_vars['clientData']->value; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array');}
foreach ($_from as $_smarty_tpl->tpl_vars['client']->key => $_smarty_tpl->tpl_vars['client']->value){
$_smarty_tpl->tpl_vars['client']->_loop = true;
?>



                                                    <option value="<?php echo $_smarty_tpl->tpl_vars['client']->value->clientid;?>
"><?php echo $_smarty_tpl->tpl_vars['client']->value->clientname;?>
</option>


                                                    <?php } ?>



                                                </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  <?php ob_start();?><?php echo $_smarty_tpl->tpl_vars['billsettingsData']->value[3]->billsettingsvalue;?>
<?php $_tmp1=ob_get_clean();?><?php if ($_tmp1==0){?> <?php }else{ ?> hidden <?php }?>" >
                        <label class="sr-only" ><?php if ($_smarty_tpl->tpl_vars['Programsettingdata']->value->delegate_seller==0){?> بائع <?php }elseif($_smarty_tpl->tpl_vars['Programsettingdata']->value->delegate_seller==1){?>مندوب <?php }elseif($_smarty_tpl->tpl_vars['Programsettingdata']->value->delegate_seller==2){?>طبيب <?php }?> </label>
                        <select class="select2 wdt100 search_bill"  name="sellerid" id="sellerid" >
                            <option value="-1">اختر <?php if ($_smarty_tpl->tpl_vars['Programsettingdata']->value->delegate_seller==0){?> بائع <?php }elseif($_smarty_tpl->tpl_vars['Programsettingdata']->value->delegate_seller==1){?>مندوب <?php }elseif($_smarty_tpl->tpl_vars['Programsettingdata']->value->delegate_seller==2){?>طبيب <?php }?></option>



                            <?php  $_smarty_tpl->tpl_vars['mysellerData'] = new Smarty_Variable; $_smarty_tpl->tpl_vars['mysellerData']->_loop = false;
 $_from = $_smarty_tpl->tpl_vars['sellerData']->value; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array');}
foreach ($_from as $_smarty_tpl->tpl_vars['mysellerData']->key => $_smarty_tpl->tpl_vars['mysellerData']->value){
$_smarty_tpl->tpl_vars['mysellerData']->_loop = true;
?>



                            <option value="<?php echo $_smarty_tpl->tpl_vars['mysellerData']->value->userid;?>
"><?php echo $_smarty_tpl->tpl_vars['mysellerData']->value->employeename;?>
</option>


                            <?php } ?>



                        </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>



                            <?php  $_smarty_tpl->tpl_vars['mysellerinsertData'] = new Smarty_Variable; $_smarty_tpl->tpl_vars['mysellerinsertData']->_loop = false;
 $_from = $_smarty_tpl->tpl_vars['sellerinsertData']->value; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array');}
foreach ($_from as $_smarty_tpl->tpl_vars['mysellerinsertData']->key => $_smarty_tpl->tpl_vars['mysellerinsertData']->value){
$_smarty_tpl->tpl_vars['mysellerinsertData']->_loop = true;
?>



                            <option value="<?php echo $_smarty_tpl->tpl_vars['mysellerinsertData']->value->userid;?>
"><?php echo $_smarty_tpl->tpl_vars['mysellerinsertData']->value->employeename;?>
</option>


                            <?php } ?>



                        </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" <?php ob_start();?><?php echo $_smarty_tpl->tpl_vars['Programsettingdata']->value->billid;?>
<?php $_tmp2=ob_get_clean();?><?php if ($_tmp2==1){?>  style="display:none" <?php }?>>
                        <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>
                            <?php  $_smarty_tpl->tpl_vars['data'] = new Smarty_Variable; $_smarty_tpl->tpl_vars['data']->_loop = false;
 $_from = $_smarty_tpl->tpl_vars['stores']->value; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array');}
foreach ($_from as $_smarty_tpl->tpl_vars['data']->key => $_smarty_tpl->tpl_vars['data']->value){
$_smarty_tpl->tpl_vars['data']->_loop = true;
?>
                            <option value="<?php echo $_smarty_tpl->tpl_vars['data']->value->storeId;?>
"><?php echo $_smarty_tpl->tpl_vars['data']->value->storeName;?>
</option>
                            <?php } ?>
                        </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>
                            <?php  $_smarty_tpl->tpl_vars['data'] = new Smarty_Variable; $_smarty_tpl->tpl_vars['data']->_loop = false;
 $_from = $_smarty_tpl->tpl_vars['saves']->value; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array');}
foreach ($_from as $_smarty_tpl->tpl_vars['data']->key => $_smarty_tpl->tpl_vars['data']->value){
$_smarty_tpl->tpl_vars['data']->_loop = true;
?>
                            <option value="<?php echo $_smarty_tpl->tpl_vars['data']->value->saveid;?>
"><?php echo $_smarty_tpl->tpl_vars['data']->value->savename;?>
</option>
                            <?php } ?>
                        </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"><?php echo $_smarty_tpl->tpl_vars['totalBills']->value;?>
</span></h4>
                </div>
            </div>
            <div class="clearfix"></div>
            
            <form method="post" action="sellbillandruternController.php?do=executeOperation" onsubmit="if (Spry.Widget.Form.validate(this)) {
                        return countChoosenProducts('sellbillandruternController');
                    } else {
                        return false;
                    }">
                

                <table class="table table-black dataTableClass">
                    <thead>
                        <tr>
                            <th class="hidden-print">
                                <input type="checkbox" name="checkAll" id="checkAll"/>
                            </th>
                            <?php if ($_smarty_tpl->tpl_vars['Programsettingdata']->value->clientserial==1){?><th>رقم تسلسل الفاتورة</th><?php }?>
                            <th <?php ob_start();?><?php echo $_smarty_tpl->tpl_vars['Programsettingdata']->value->billid;?>
<?php $_tmp3=ob_get_clean();?><?php if ($_tmp3==1){?>  style="display:none" <?php }?>>اجمالى الفاتورة</th>
                            <th>تاريخ الفاتورة</th>
                            <th>العميل</th>
                            <th <?php ob_start();?><?php echo $_smarty_tpl->tpl_vars['billsettingsData']->value[3]->billsettingsvalue;?>
<?php $_tmp4=ob_get_clean();?><?php if ($_tmp4==0){?> style="display:block" <?php }else{ ?> style="display:none" <?php }?>><?php if ($_smarty_tpl->tpl_vars['Programsettingdata']->value->delegate_seller==0){?> بائع <?php }elseif($_smarty_tpl->tpl_vars['Programsettingdata']->value->delegate_seller==1){?>مندوب <?php }elseif($_smarty_tpl->tpl_vars['Programsettingdata']->value->delegate_seller==2){?>طبيب <?php }?></th>
                            <th>اسم المستخدم</th>
                            <th>المخزن</th>
                            <th>الخزنة</th>
                            <th class="hidden-print">تفاصيل الفاتورة</th>
                            <?php if ($_smarty_tpl->tpl_vars['usergroup']->value->allowEditDelInBills==0){?><th class="hidden-print">تعديل الفاتورة</th>
                            <th class="hidden-print">حذف</th><?php }?>
                            <th class="hidden-print">قيد اليومية</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $_smarty_tpl->tpl_vars['piecesCount'] = new Smarty_variable(0, null, 0);?>
                        <?php $_smarty_tpl->tpl_vars['payedTotal'] = new Smarty_variable(0, null, 0);?>
                        <?php $_smarty_tpl->tpl_vars['remainTotal'] = new Smarty_variable(0, null, 0);?>
                        <?php  $_smarty_tpl->tpl_vars['sellbillandrutern'] = new Smarty_Variable; $_smarty_tpl->tpl_vars['sellbillandrutern']->_loop = false;
 $_from = $_smarty_tpl->tpl_vars['sellbillandruternData']->value; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array');}
foreach ($_from as $_smarty_tpl->tpl_vars['sellbillandrutern']->key => $_smarty_tpl->tpl_vars['sellbillandrutern']->value){
$_smarty_tpl->tpl_vars['sellbillandrutern']->_loop = true;
?>
                        <?php $_smarty_tpl->tpl_vars['piecesCount'] = new Smarty_variable($_smarty_tpl->tpl_vars['piecesCount']->value+$_smarty_tpl->tpl_vars['sellbillandrutern']->value->sellQuantity-$_smarty_tpl->tpl_vars['sellbillandrutern']->value->returnsellQuantity, null, 0);?>
                        <?php $_smarty_tpl->tpl_vars['payedTotal'] = new Smarty_variable($_smarty_tpl->tpl_vars['payedTotal']->value+$_smarty_tpl->tpl_vars['sellbillandrutern']->value->sellbilltotalpayed, null, 0);?>
                        <?php $_smarty_tpl->tpl_vars['remainTotal'] = new Smarty_variable($_smarty_tpl->tpl_vars['remainTotal']->value+$_smarty_tpl->tpl_vars['sellbillandrutern']->value->sellbillfinalbill, null, 0);?>


                        <?php if (isset($_smarty_tpl->tpl_vars['sellbillandrutern']->value->newSellbillidAfterEdit)&&$_smarty_tpl->tpl_vars['sellbillandrutern']->value->newSellbillidAfterEdit>0){?> <!--this bill is deleted for editing-->
                        <tr class="danger">
                            <?php }else{?><?php ob_start();?><?php echo $_smarty_tpl->tpl_vars['sellbillandrutern']->value->conditions;?>
<?php $_tmp5=ob_get_clean();?><?php if ($_tmp5!=0){?>
                        <tr class="dark">
                            <?php }else{ ?>
                        <tr>
                            <?php }}?>
                            <td class="hidden-print">
                                <input type="checkbox" name="choosedItem[]" id="checked<?php echo $_smarty_tpl->tpl_vars['i']->value;?>
" class="choosenItem" value="<?php echo $_smarty_tpl->tpl_vars['sellbillandrutern']->value->sellbillid;?>
" />
                            </td>
                            <?php if ($_smarty_tpl->tpl_vars['Programsettingdata']->value->clientserial==1){?><td><?php echo $_smarty_tpl->tpl_vars['sellbillandrutern']->value->sellbillid;?>
</td><?php }?>
                            <td <?php ob_start();?><?php echo $_smarty_tpl->tpl_vars['Programsettingdata']->value->billid;?>
<?php $_tmp6=ob_get_clean();?><?php if ($_tmp6==1){?>  style="display:none" <?php }?>><?php echo $_smarty_tpl->tpl_vars['sellbillandrutern']->value->sellbillaftertotalbill;?>
</td>
                            <td><?php echo $_smarty_tpl->tpl_vars['sellbillandrutern']->value->sellbilldate;?>
</td>
                            <td> <?php ob_start();?><?php echo $_smarty_tpl->tpl_vars['sellbillandrutern']->value->clientname;?>
<?php $_tmp7=ob_get_clean();?><?php if ($_tmp7==''){?>
                                نقدى
                                <?php }else{ ?>
                                <?php echo $_smarty_tpl->tpl_vars['sellbillandrutern']->value->clientname;?>

                                <?php }?> </td>
                            <td <?php ob_start();?><?php echo $_smarty_tpl->tpl_vars['billsettingsData']->value[3]->billsettingsvalue;?>
<?php $_tmp8=ob_get_clean();?><?php if ($_tmp8==0){?> style="display:block" <?php }else{ ?> style="display:none" <?php }?>><?php echo $_smarty_tpl->tpl_vars['sellbillandrutern']->value->employeename;?>
</td>
                            <td><?php echo $_smarty_tpl->tpl_vars['sellbillandrutern']->value->useremployeename;?>
<?php if ($_smarty_tpl->tpl_vars['sellbillandrutern']->value->delbyusername){?><br/><span style="color: red"><?php echo $_smarty_tpl->tpl_vars['sellbillandrutern']->value->delbyusername;?>
</span><?php }?></td>
                            <td><?php echo $_smarty_tpl->tpl_vars['sellbillandrutern']->value->storeName;?>
</td>
                            <td><?php echo $_smarty_tpl->tpl_vars['sellbillandrutern']->value->savename;?>
</td>
                            <td class="hidden-print"> <a href="sellbillandruternController.php?do=showDetail&sellbillid=<?php echo $_smarty_tpl->tpl_vars['sellbillandrutern']->value->sellbillid;?>
" type="button" class="btn btn-default btn-lg editicon"></a> </td>

                            <?php if ($_smarty_tpl->tpl_vars['usergroup']->value->allowEditDelInBills==0){?><td class="hidden-print"><?php ob_start();?><?php echo $_smarty_tpl->tpl_vars['sellbillandrutern']->value->conditions;?>
<?php $_tmp9=ob_get_clean();?><?php if ($_tmp9==0){?> <a href="sellbillController.php?do=editsellandrutrnBill&sellbillid=<?php echo $_smarty_tpl->tpl_vars['sellbillandrutern']->value->sellbillid;?>
" type="button" class="btn btn-default btn-lg editicon"></a><?php }else{ ?>

                                <?php if (isset($_smarty_tpl->tpl_vars['sellbillandrutern']->value->newSellbillidAfterEdit)&&$_smarty_tpl->tpl_vars['sellbillandrutern']->value->newSellbillidAfterEdit>0){?> <!--this bill is deleted for editing-->
                                حذف للتعديل
                                <?php }else{ ?>
                                تم حذف الفاتورة
                                <?php }?>


                                <?php }?> </td>


                            <td class="hidden-print"> <?php ob_start();?><?php echo $_smarty_tpl->tpl_vars['sellbillandrutern']->value->conditions;?>
<?php $_tmp10=ob_get_clean();?><?php if ($_tmp10==0){?> <a href="sellbillandruternController.php?do=delete&sellbillid=<?php echo $_smarty_tpl->tpl_vars['sellbillandrutern']->value->sellbillid;?>
" type="button" class="btn btn-default btn-lg removeicon"></a> <?php }else{ ?>
                                تم حذف الفاتورة

                                <?php }?> </td><?php }?>
                            <td class="hidden-print">
                                <a href="dailyentry.php?id=<?php echo $_smarty_tpl->tpl_vars['sellbillandrutern']->value->dailyentryid;?>
" target="_blank" type="button" class="btn btn-default btn-lg editicon"></a>
                            </td>
                        </tr>

                        <?php } ?>

                    </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"><?php echo $_smarty_tpl->tpl_vars['piecesCount']->value;?>
</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"><?php echo $_smarty_tpl->tpl_vars['totalSell']->value;?>
</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"><?php echo $_smarty_tpl->tpl_vars['totalRet']->value;?>
</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"><?php echo $_smarty_tpl->tpl_vars['payedTotal']->value;?>
</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"><?php echo $_smarty_tpl->tpl_vars['remainTotal']->value;?>
</span></h4>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                </div>
            </form>
        </div>
    </div>
</div>

<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>
<?php }} ?>