
<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="suppform" class="nameToBeChecked form-horizontal" action="supplierControllerOpen.php?do=saveexchangeorclosing" method="post" >


                    <div class="form-group">
                        <label class="col-lg-2 control-label">العملية </label>
                        <div class="col-lg-4">
                            <div class="radio-inline">
                                <label>  <input value="0" name="thetype" type="radio">
                                    صرف</label>
                            </div>
                            <div class="radio-inline">
                                <label> <input value="1" name="thetype" type="radio">
                                    تقفيل</label>
                            </div>
                        </div>
                    </div>
                    <!--==============================-->
                    <div id="expenseDiv" style="display: none">



                        <div class="form-group">
                            <label class="col-lg-2 control-label">مدينون الشجرة(حسابات مفتوحة)  </label>
                            <div class="col-lg-4">
                                <select name="supplieropenidEx" id="supplieropenidEx" class="select2">
                                    <option></option>
                                    {foreach $supplierOpenAll as $data}
                                    <option value="{$data->id}">{$data->name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <!--==============================-->
                        <div class="form-group">
                            <label class="col-lg-2 control-label">الخزنة </label>
                            <div class="col-lg-4">
                                <select name="saveidEx" id="saveidEx" class="select2">
                                    <option></option>
                                    {foreach $saveData as $data}
                                    <option value="{$data->saveid}">{$data->savename}</option>
                                    {/foreach}
                                </select>
                            </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="ExVal" id="ExVal" class="positivefloat form-control"/>
                                    <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 style="width: 358px;" name="commentEx" cols="50" rows="5" class="form-control"></textarea>
                            </div>
                        </div>





                    </div>
                    <div id="closingDiv" style="display: none">


                        <div class="form-group">
                            <label class="col-lg-2 control-label">مدينون الشجرة(حسابات مفتوحة)  </label>
                            <div class="col-lg-4">
                                <select name="supplieropenidClosing" id="supplieropenidClosing" class="select2">
                                    <option></option>
                                    {foreach $supplierOpenAll as $data}
                                    <option value="{$data->id}">{$data->name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <!--==============================-->
                        <div class="form-group">
                            <label class="col-lg-2 control-label">اصل ام مصروف </label>
                            <div class="col-lg-4">
                                <div class="radio-inline">
                                    <label>  <input value="0" name="assetorexpense" type="radio" checked>
                                        اصل</label>
                                </div>
                                <div class="radio-inline">
                                    <label> <input value="1" name="assetorexpense" type="radio">
                                        مصروف</label>
                                </div>
                            </div>
                        </div>
                        <!--==============================-->
                        <div class="form-group">
                            <label class="col-lg-2 control-label">الاصل او المصروف </label>
                            <div class="col-lg-4">
                                <input type="hidden" name="assetorexpenseid" id="assetorexpenseid" value=""/>
                            </div>
                        </div>
                        <!--==============================-->
                        <div class="form-group">
                            <label class="col-lg-2 control-label">الخزنة </label>
                            <div class="col-lg-4">
                                <select name="saveidclosing" id="saveidclosing" class="select2">
                                    <option></option>
                                    {foreach $saveData as $data}
                                    <option value="{$data->saveid}">{$data->savename}</option>
                                    {/foreach}
                                </select>
                            </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="closingVal" id="closingVal" class="positivefloat form-control"/>
                                    <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 style="width: 358px;" name="commentClosing" cols="50" rows="5" class="form-control"></textarea>
                            </div>
                        </div>




                    </div>


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

                    <div class="form-group">
                        <div class="col-lg-offset-2 col-lg-4">
                            <button name="saveIncBtn" type="submit" id="saveIncBtn" class="btn btn-primary pull-left" onclick="$(this).hide()">حفظ</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

{literal}
<script>
    $('input[name="thetype"]').live('change', function () {
        var thetype = $('input[name="thetype"]:checked').val();
        if (thetype == 0) {
            $('#expenseDiv').show();
            $('#closingDiv').hide();
        } else if (thetype == 1) {
            $('#expenseDiv').hide();
            $('#closingDiv').show();
        }
    });
    $(function () {
        $("#assetorexpenseid").select2({
            placeholder: "اختر",
            minimumInputLength: 0,
            inimumInputLength: 0,
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "expensesControllerajex.php?do=expenseTypeAjax",
                dataType: 'json',
                data: function (term, page) {
                    return {
                        term: term, //search term
                        page_limit: 7, // page size
                        assetorexpense: $('input[name="assetorexpense"]:checked').val(), // page size
                    };
                },
                results: function (data) {
                    return {results: data};
                }
            },
            formatResult: function (data) {
                return  data.text;
            },
            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]};
                callback(data);
            },
        });
    });
</script>
{/literal}
