
<div class="row">
    <div class="container">
         <ol class="breadcrumb">
            <li><a href="#">نظام العقارات والوحدات </a></li>
            <li><a href="realestateunitsalertsrents.php?do=show"> تنبيهات العقارات والوحدات </a></li>
            <li class="active">عرض   </li>
        </ol>

        <div class="panel panel-default panel-m">
            <form class="form-inline hidden-print" id="searchdata"  method="post" action="realestateunits.php?do=show">
                      <div class="form-group" style="width: 180px;">
                        <label class="sr-only">من التاريخ</label>
                        <input type="text" class="form-control awdatepicker searchdata" autocomplete="off"   data-date-format="yyyy-mm-dd"  id="start_date" name="start_date" value="{$date}">
                    </div>
                    <div class="form-group" style="width: 180px;">
                        <label class="sr-only">إلى التاريخ</label>
                        <input type="text" class="form-control awdatepicker searchdata" autocomplete="off"   data-date-format="yyyy-mm-dd"  id="end_date" name="end_date" value="{$date}">
                    </div>
                 
                    <div class="form-group"  >
                        <label class="sr-only">المالك</label>
                        <div style="width: 180px;">
                             <input type="text" name="supplierid" class="searchdata wdt100" id="select2supplier" data-placeholder="اختر " />
                        </div> 
                    </div>
                     

                    <div class="form-group"  >
                        <label class="sr-only">المستاجرين</label>
                        <div style="width: 180px;">
                            <input type="text" name="clientid" class="searchdata wdt100" id="select2client" data-placeholder="اختر " />
                        </div> 
                    </div>

                     <div class="form-group"  >
                        <label class="sr-only">العقارات</label>
                        <div style="width: 180px;">
                            <input id="select2realestates" type="text" name="realestateid" class="searchdata "  data-placeholder="اختر  العقار"   /> 
                        </div> 
                    </div>
                     <div class="form-group"  >
                        <label class="sr-only">الوحدات</label>
                        <div style="width: 180px;">
                            <input id="select2realestatesunits" type="text" name="realestateunitid" class="searchdata "  data-placeholder="اختر  الوحده"  /> 
                        </div> 
                    </div>
                </form>
            <hr/>
            <div id="getdata">
                
            </div>
            <div class="clearfix"></div>
        </div>
    </div>
</div>

<!-- Modal -->
<div class="modal fade" id="exampleModals" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">استكمال الدفع</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form>
          <div class="form-group" id="showsupplier" style="display:none;">
            <label for="suppliername" >المالك</label>
            <input type="text" class="form-control" id="suppliername" >
            <input type="hidden" id="supplierid" >
          </div>
          <div class="form-group" id="showclient" style="display:none;">
            <label for="clientname">المالك</label>
            <input type="text" class="form-control" id="clientname" >
            <input type="hidden" id="clientid" >
          </div>
          <div class="form-group" >
            <label for="realestatename">العقار</label>
            <input type="text" class="form-control" id="realestatename" >
            <input type="hidden" class="form-control" id="realestateid" >
          </div>
         <div class="form-group" id="showunitname" style="display:none;">
            <label for="realestatename">الوحده</label>
            <input type="text" class="form-control" id="unitname" >
          </div> 
          <div class="form-group">
            <label for="valuerent">الايجار</label>
            <input type="text" class="form-control" readonly id="valuerent" >
          </div>
          <div class="form-group">
            <label for="totalpaid">المدفوع</label>
            <input type="text" class="form-control" readonly id="totalpaid" >
          </div>
          <div class="form-group">
            <label for="totalpaid">الدفع</label>
            <input type="text" class="form-control" id="payed" name="payed" >
          </div>
          <input type="hidden" id="realestateunitspaidid"  name="realestateunitspaidid">
          <input type="hidden" id="realestateunitpaidinstallmentid"  name="realestateunitpaidinstallmentid">
          <input type="hidden" id="continer"  name="continer">
        </form>
        
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">اغلاق</button>
        <button type="button" class="btn btn-primary savepayed">حفظ</button>
      </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 supplierid = $("#select2supplier").val();
             var clientid = $("#select2client").val();
             var realestateid = $("#select2realestates").val();
             var realestateunitid = $("#select2realestatesunits").val();
              $.post('realestateunitsalertsrents.php?do=getdata', {start_date: start_date, end_date: end_date, supplierid: supplierid, clientid: clientid, realestateid: realestateid ,realestateunitid: realestateunitid}, function (result) {
                $("#getdata").html(result);
              });
          }

          $('body').on('change', '.searchdata', function () {
             var start_date = $("#start_date").val();
             var end_date = $("#end_date").val();
             var supplierid = $("#select2supplier").val();
             var clientid = $("#select2client").val();
             var realestateid = $("#select2realestates").val();
             var realestateunitid = $("#select2realestatesunits").val();
              $.post('realestateunitsalertsrents.php?do=getdata', {start_date: start_date, end_date: end_date, supplierid: supplierid, clientid: clientid, realestateid: realestateid ,realestateunitid: realestateunitid}, function (result) {
                $("#getdata").html(result);
              });
            });


           $('body').on('click', '.savepayed', function () {
             var realestateunitpaidid =  Number($("#realestateunitspaidid").val());
             var realestateunitpaidinstallmentid =  Number($("#realestateunitpaidinstallmentid").val());
             var payed =  Number($("#payed").val());
              $.post($("#continer").val()+'.php?do=savepayed', {realestateunitpaidid: realestateunitpaidid, realestateunitpaidinstallmentid: realestateunitpaidinstallmentid, payed: payed}, function (result) {
                if (result == 1) {
                     $('#exampleModals').modal('hide');
                }else{
                     alert('هناك مشكله اثناء التنفيذ');
                }
                
              });
            });


          $('body').on('click', '.payednow', function () {
             var continer = $(this).attr('data-continer');
             $("#continer").val(continer);
             var supplierid =  Number($(this).attr('data-supplierid'));
             if (supplierid > 1) {
                $("#showsupplier").show();
             }else{
                $("#showsupplier").hide();
             }
             $("#supplierid").val(supplierid);
             var suppliername = $(this).attr('data-suppliername');
             $("#suppliername").val(suppliername);
             var clientid =  Number($(this).attr('data-clientid'));
             if (clientid > 1) {
                $("#showclient").show();
             }else{
                $("#showclient").hide();
             }
             var unitname = $(this).attr('data-unitname');
             $("#unitname").val(unitname);
             if (unitname) {
                $("#showunitname").show();
             }else{
                $("#showunitname").hide();
             }
             $("#clientid").val(clientid);
             var clientname = $(this).attr('data-clientname');
             $("#clientname").val(clientname);
             var realestatename = $(this).attr('data-realestatename');
             $("#realestatename").val(realestatename);
             var realestateunitspaidid =  Number($(this).attr('data-realestateunitspaidid'));
             $("#realestateunitspaidid").val(realestateunitspaidid);
             var realestateunitpaidinstallmentid =  Number($(this).attr('data-realestateunitpaidinstallmentid'));
             $("#realestateunitpaidinstallmentid").val(realestateunitpaidinstallmentid);
             var values =  Number($(this).attr('data-value'));
             $("#valuerent").val(values);
             var paid =  Number($(this).attr('data-paid'));
             $("#totalpaid").val(paid);
             var rem =  Number($(this).attr('data-rem'));
             $("#payed").val(rem);
             $('#exampleModals').modal('show');
            });













         $("#select2supplier").select2({
            placeholder: "إسم  المشروع",
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "realestateunits.php?do=select2supplier",
                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: "realestateunits.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]};
                callback(data);
            }
        });




        $("#select2realestates").select2({
            placeholder: "إسم  المشروع",
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "realestateunits.php?do=select2realestates",
                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);
            }
        });
        $("#select2realestatesunits").select2({
            placeholder: "الوحده",
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "realestateunits.php?do=select2realestatesunits",
                type: "post",
                dataType: 'json',
                data: function (term, page) {
                    var select2realestates = Number($('#select2realestates').val());
                     if (!select2realestates) {
                        alert('يجب اختيار العقار اولا');
                        return false;
                     }
                    return {
                        searchTerm: term,
                        realestateid: select2realestates,
                    };
                },
                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);
            }
        });
        // deldata();
});  
</script>
{/literal}
