<div class="row">
    <div class="container">

        <ol class="breadcrumb">
            <li><a href="#"> العملاء</a></li>
            <li><a href="customerAccountMatching.php?do=show"> مطابقة حساب عميل </a></li>
            <li class="active">اضافة </li>
        </ol>

        <div class="panel panel-default panel-m">
            <div class="panel-heading">
                <h3 class="panel-title">اضافة </h3>
            </div>
            <div class="panel-body">
                {literal}
                <form class="form-horizontal" action="customerAccountMatching.php?do=savedata" id="submitformajax"
                    method="post" enctype="multipart/form-data" data-dosave="?do=savedata" data-direction="?do=show"
                    data-print="">
                    {/literal}

                    <div class="form-group">
                        <label class="col-lg-2 control-label"> مطابق او غير مطابق </label>
                        <div class="col-lg-4">
                            <div class="radio-inline">
                                <label>
                                    <input value="1" class="noradioR identical" name="identical" type="radio"
                                        checked="checked">
                                    مطابق </label>
                            </div>
                            <div class="radio-inline">
                                <label>
                                    <input value="2" class="radioR identical" name="identical" type="radio">
                                    غير مطابق </label>
                            </div>

                        </div>
                    </div>
                    <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">العملاء </label>
                        <div class="col-lg-4">
                            <input type="hidden" name="clientid" class=" wdt100" id="select2client"
                                data-placeholder="اختر " />

                        </div>
                    </div>
                    <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">المديونية </label>
                        <div class="col-lg-4">
                            <input type="text" name="currentDebt" id="currentDebt" readonly class="form-control"
                                data-placeholder="المديونية" />

                        </div>
                    </div>
                    <div id="identical" style="display: none;">
                        <div class="form-group">
                            <label for="txtName" class="col-lg-2 control-label">القيمه </label>
                            <div class="col-lg-4">
                                <input type="text" name="newclientdebt" class="form-control"
                                    data-placeholder="القيمه " />

                            </div>
                        </div>
                        <div class="form-group">
                            <label for="txtName" class="col-lg-2 control-label">التعليق </label>
                            <div class="col-lg-4">
                                <textarea rows="3" class="form-control" name="comment"></textarea>
                            </div>
                        </div>

                    </div>



                    <div class="form-group">
                        <div class="col-lg-offset-2 col-lg-4">
                            <button type="submit" class="btn btn-primary pull-left submitformajax">حفظ الامر</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


{literal}
<script type="text/javascript">
    $(document).ready(function () {
        var formatResult;
        formatResult = function (data) { return data.text; }
        //    dssd();
        //   function dssd() {
        //     var start_date = $("#start_date").val();
        //      var end_date = $("#end_date").val();
        //      var clientid = $("#select2client").val();
        //       $.post('clientsexpensereport.php?do=getdata', {start_date: start_date, end_date: end_date, clientid: clientid}, function (result) {
        //         $("#getdata").html(result);
        //         $("#tspaids").html($("#gtspaids").text());
        //         $("#tepaids").html($("#gtepaids").text());
        //         $("#tcpaids").html($("#gtcpaids").text());
        //         $("#tcspaids").html($("#gtcspaids").text());
        //       });
        //   }

        //   $('body').on('change', '.searchdata', function () {
        // var start_date = $("#start_date").val();
        //  var end_date = $("#end_date").val();
        //  var clientid = $("#select2client").val();
        //   $.post('clientsexpensereport.php?do=getdata', {start_date: start_date, end_date: end_date, clientid: clientid}, function (result) {
        //     $("#getdata").html(result);

        //    $("#tspaids").html($("#gtspaids").text());
        //     $("#tepaids").html($("#gtepaids").text());
        //     $("#tcpaids").html($("#gtcpaids").text());
        //     $("#tcspaids").html($("#gtcspaids").text());

        //   });
        // });
        $('body').on('change', '.identical', function () {
            var identical = $('input.identical:checked').val();
            if (identical == 2) {
                $("#identical").show();
            } else {
                $("#identical").hide();
            }
        });

        $('body').on('click', '.addappend', function () {
            var itr = Number($("#productsitr").val()) + 1;
            $("#productsitr").val(itr);
            $.post('customerAccountMatching.php?do=appendproduct', { itr: itr }, function (result) {
                $("#products").append(result);
                products(itr);


            });
        });

        $('body').on('click', '.removeappend', function () {
            var id = Number($(this).attr('data-id'));
            var edit = Number($(this).attr('data-edit'));
            if (edit == 1) {
                $.post('customerAccountMatching.php?do=removeappend', { id: id }, function (result) {
                    $("#products" + id).remove();
                });
            } else {
                $("#products" + edit + id).remove();

            }

        });
        products(1);
        function products($i) {
            $("#select2product" + $i).select2({
                placeholder: "إسم  المشروع",
                multiple: false,
                quietMillis: 100,
                ajax: {
                    url: "customerAccountMatching.php?do=select2product",
                    type: "post",
                    dataType: 'json',
                    data: function (term, page) {
                        return {
                            searchTerm: term,
                        };
                    },
                    results: function (data) {
                        return { results: data };
                    }
                },
                formatResult: formatResult,
                initSelection: function (element, callback) {
                    var item = element.val().split(':');
                    var data = { id: item[0], text: item[1] };
                    callback(data);
                }
            });
        }


        $("#select2client").select2({
            placeholder: "إسم  العميل",
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "customerAccountMatching.php?do=select2client",
                type: "post",
                dataType: 'json',
                data: function (term, page) {
                    return {
                        searchTerm: term,
                    };
                },
                results: function (data) {
                    return { results: data };
                }
            },
            formatResult: formatResult,
            initSelection: function (element, callback) {
                var item = element.val().split(':');
                var data = { id: item[0], text: item[1], debt: item[2] };
                callback(data);
            }
        }).on('change', function (e) {
            debt = $(this).select2('data').debt;

            if ($(this).val() > 0)
                $('#currentDebt').val(debt);
        });
    });  
</script>
{/literal}