
<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">المصروفات والإيرادات</a></li>
            <li><a href="#">الكمبيالات</a></li>
            <li class="active">إضافة كمبيالة</li>
        </ol>
        <div class="panel panel-default panel-m">
            <!-- Default panel contents -->
            <div class="panel-heading">
                <h3 class="panel-title">إضافة كمبيالة</h3>
            </div>
            <div class="panel-body">
                <form id="myform" class="form-horizontal" action="?do=add" method="post">
    
                    <input type="hidden" id="clientsearchvalue" value="{$Programsettingdata->clientsearchvalue}" />
                    <input type="hidden" name="supplierWithAddOption" id="supplierWithAddOption" value="1" />
                    <input type="hidden" name="withNakdi" id="withNakdi" value="{$Usergroupdata->showClientAndSupplierOne}" />
                    <input type="hidden" name="supplieridBeforeChange" id="supplieridBeforeChange" value="" />
                    <input type="hidden" name="suppliernameBeforeChange" id="suppliernameBeforeChange" value="" />

                    <div class="form-group">
                        <label class="col-lg-2 control-label">إسم العميل</label>
                        <div class="col-lg-4">
                            <!-- <select name="clientID" id="clientID" class="select2 wdt100">
                                <option value="-1">اختر عميل</option>
                                {foreach $allclientdata as $clientdata}
                                <option value="{$clientdata->clientid}">{$clientdata->clientname}</option>
                                {/foreach}
                            </select>
                            <div id="clientError" style="display:none;"></div> -->
                            <div id="clientDiv">
                                <input type="hidden" required name="clientID" id="clientID" class="select2Supp" />
                                <input type="hidden" id="oldsupplierid" value="" />
                                <input type="hidden" id="oldsuppliername" value="" />
                            </div>
                            <label id="clientError" class="error" for="clientID" style="display: none;">هذا الحقل إلزامي</label>
                        </div>
                    </div>

                    <!--==============================-->

                    <div class="form-group">
                        <label class="col-lg-2 control-label">تاريخ اليوم</label>
                        <div class="col-lg-4">
                            <input name="recievingdate" type="text" id="textfield2" value="{$today}" readonly class="form-control">
                        </div>
                    </div>

                    <!--==============================-->

                    <div class="form-group">
                        <label class="col-lg-2 control-label">تاريخ الاستحقاق</label>
                        <div class="col-lg-4">
                            <input type="text" name="expiredate" id="expiredate" class="form-control awdatepicker" autocomplete="off"   data-date-format="yyyy-mm-dd">
                            <div id="dateError" style="display:none;"></div>
                        </div>
                    </div>

                    <!--==============================-->

                    <div class="form-group">
                        <label class="col-lg-2 control-label">القيمة</label>
                        <div class="col-lg-4">
                            <div class="input-group">
                                <input type="text" name="value" id="valuetxt" class="form-control positivefloat">
                                <span class="input-group-addon">{$currency}</span>
                            </div>
                            <div id="valueError" style="display:none;"></div>
                        </div>
                    </div>

                    <!--==============================-->

                    <div class="form-group">
                        <label class="col-lg-2 control-label">تعليق</label>
                        <div class="col-lg-4">
                            <textarea name="clientcomment" id="clientcomment" cols="45" rows="5" class="form-control"></textarea>
                        </div>
                    </div>

                    <!--==============================-->

                    <div class="form-group">
                        <div class="col-lg-offset-2 col-lg-4">
                            <button type="button"  id="savebtn" class="btn btn-primary pull-left">حفظ</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{literal}
<script type="text/javascript">
    var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "integer");

    $(document).ready(function () {
        var supplierWithAddOption = (Number($('#supplierWithAddOption').val()) == 1) ? 0 : 1;
        var withNakdi = (Number($('#withNakdi').val()) == 1) ? 0 : 1;
        var clientval = $('#clientsearchvalue').val();
        if(!clientval)
            clientval=  0;
        $(".select2Supp").select2({
            placeholder: "العميل",
            minimumInputLength: clientval,
            inimumInputLength: 0,
            multiple: false,
            quietMillis: 100,
            formatInputTooShort: function (input, min) {
                var n = min - input.length;
                $lenMsg = '<ul class="select2-results">';
                if (supplierWithAddOption == 1)
                    $lenMsg += '<li class="select2-results-dept-0 select2-result select2-result-selectable" onclick="newOptionAtInputTooShort();"><div class="select2-result-label newoption"><span class="newoption">اضافة عميل جديد</span></div></li>';
                $lenMsg += '</ul><div class="select2-result-label"><span>من فضلك أدخل ' + n + ' حروف أكثر</span></div>';
                // Append it to the select
                return $lenMsg;
            },
            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: withNakdi,
                        //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
        }).on('select2-loaded', function (e) {// not "select2-open" nor "select2-opening" //http://mkurz.github.io/select2/index.html
            $('.newoption').parent().addClass('newoption');
        }).on("select2-selecting", function (e) {
            // the class to make diffrence of change from select2 itself "choose another option" ,it wont exist for triggering change
            $('#clientid').addClass('selectingClass');
        })
        //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}