<div  class="panel panel-primary" id="newCar">
  <div class="panel-heading"style="font-size:1.2em;">القائمة السوداء</div>
  <div class="panel-body" style="background-color:#00324d; color:#cce5ff;" >

<form id="update7" method="post" class="form-horizontal" style="float:center;">
      <br />
        <div class="row" style="padding:4px;">
          <div class="col-xs-4 col-md-3"style="float:right;padding:2px;">
            <label for="namm" class="control-label"style="float:right;margin:5px;"> باسم المستاجر <span style="float:right;margin-left:10px;"><button id="namm_a"  type="button" class="btn btn-success btn-xs "> بحث </button></span></label>
            <input type="text" class="form-control" style="float:right;" id="namm" name="namm" placeholder="اسم المستأجر"/>
          </div>
          <div class="col-xs-4 col-md-2"style="float:right;padding:2px;">
            <label for="numb" class="control-label"style="float:right;margin:5px;">برقم <span style="float:right;margin-left:10px;"><button id="numb_a" type="button" class="btn btn-success btn-xs "> بحث </button></span></label>
            <input type="number" class="form-control" style="float:right;" id="numb" name="numb" placeholder="هوية رخصة جوال" />
          </div>
          <!-- <div class="col-xs-4 col-md-2"style="float:right;padding:2px;">
          <label for="datt" class="control-label"style="float:right;margin:5px;">تاريخ انتهاء<span style="float:right;margin-left:10px;"><button id="datt_a" type="button" class="btn btn-success btn-xs "> بحث </button></span></label>
          <input type="text" class="form-control" style="float:right;" id="datt" name="datt" placeholder="حتي تاريخ" readonly />
          <script>
            $(function() {
              var calendar = $.calendars.instance('');
              $('#datt').calendarsPicker({calendar: calendar});
              });
          </script>
        </div> -->
        <div class="col-xs-4 col-md-4"style="float:right;padding:2px;">
          <label for="ad" class="control-label"style="float:right;margin:5px;">جهة العمل و العنوان <span style="float:right;margin-left:10px;"><button id="ad_a"  type="button" class="btn btn-success btn-xs "> بحث </button></span></label>
          <input type="text" class="form-control" style="float:right;" id="ad" name="ad" placeholder="اي رقم في بيانات المستأجر" />
        </div>

      </div>

</form>
<br />
    <div class="table-responsive">
         <table class="table table-bordered table-hover">
           <thead>
              <tr>
                   <th class="text-center" width="12%">حركة</th>
                   <th class="text-center" width="26%">الاسم</th>
                   <th class="text-center" width="8%">رقم الجوال</th>
                   <th class="text-center" width="40%">ملاحظات</th>
                   <th class="text-center" width="13%">إجمالي مديونية</th>
              </tr>
            </thead>
              <tbody id="myTable">
                <?php
                 include "../actions/dbPDO.php";
                  $output = '';
                  $sql =$db->prepare("SELECT cust_name , cust_id , phone , comm
                            from customers where dgree < 50 order by cust_id DESC LIMIT 300  ");
                  $sql->execute();
                   if($sql->rowCount()>0)
                  {
                     while($row = $sql->fetch())
                       {
                         $cust = $row['cust_id'] ;
                         $ww = $db->prepare("SELECT sum(wanted) as ww from contracts where cust_id = ? ");
                         $ww->bindParam(1,$cust);
                         $ww->execute();
                         if($ww->rowCount()>0){$wcw = $ww->fetch(PDO::FETCH_ASSOC);
                           $wanted = $wcw['ww'];}
                            $output .= '
                                 <tr>
                                      <td>
                                      <a href="a/cust_update.php?id=' . $cust . '"target="_blank"><button type="button" class="btn btn-success btn-xs ">تحديث</button></a>
                                      <a href="a/cust_print.php?cust_id=' . $cust . '"target="_blank"><button type="button" class="btn btn-info btn-xs ">الرخصة</button></a>
                                      </td>
                                      <td >' . $row['cust_name'] . '</td>
                                      <td class="text-center" >' . $row['phone'] . '</td>
                                      <td>' . $row['comm'] . '</td>
                                      <td class="text-center" >' . $wanted . '</td>
                                  </tr>
                            ';
                       }
                  }
                  else
                  {
                       $output .= '<tr>
                                           <td colspan="7"><h3>لا يوجد سجلات ...</h3></td>
                                      </tr>';
                  }
                  echo $output;
                  ?>
              </tbody>
						<tfoot></tfoot>
          </table>
    </div>
</div>
</div>
<!-- panel body style -->

<script>
$(document).ready(function(){

  $("#ad_a").click(function(event){
      event.preventDefault();
      var ad_a = $("#ad").val();
 $.ajax({
        url     : "actions/cust_group.php",
        method  : "POST",
         data    :{ad_a:ad_a},
        success : function(data){ $("#myTable").html(data); },
        error   :function(result){
          alert(result.statusText);
          }
      });
    });

    $("#namm_a").click(function(event){
        event.preventDefault();
        var name = $("#namm").val();
   $.ajax({
          url     : "actions/cust_group.php",
          method  : "POST",
           data    :{name:name},
          success : function(data){ $("#myTable").html(data); },
          error   :function(result){
            alert(result.statusText);
            }
        });
      });
      $("#numb_a").click(function(event){
          event.preventDefault();
          var numb = $("#numb").val();
     $.ajax({
            url     : "actions/cust_group.php",
            method  : "POST",
             data    :{numb:numb},
            success : function(data){ $("#myTable").html(data); },
            error   :function(result){
              alert(result.statusText);
              }
          });
        });

  //   $("#datt_a").click(function(event){
  //       event.preventDefault();
  //       var datt = $("#datt").val();
  //        if(datt.length = 0 ){
  //          var d = new Date();
   //
  //        }
  //  $.ajax({
  //         url     : "actions/cust_group.php",
  //         method  : "POST",
  //          data    :{datt:datt},
  //         success : function(data){ $("#myTable").html(data); },
  //         error   :function(result){
  //           alert(result.statusText);
  //           }
  //       });
  //     });


function convertDates(name,ss,dest) {
  				var date = $('#' + ss).val().split('/');
  				var year = parseInt(date[0], 10);
  			if(name == 'ummalqura'){
  			if (year > 1800){ return false ;}
  				} else if (name == 'gregorian') {
  			if (year < 1800){ return false ;}
  							}
  				var month = parseInt(date[1], 10);
  				var day = parseInt(date[2], 10);
  				try {var jd = $.calendars.instance(name).newDate(year,month,day).toJD();}
  				catch (e) {alert(e);		return;	}
  				name == 'ummalqura'?showDate('gregorian', jd,dest):showDate('ummalqura', jd,dest);
  									      }
function showDate(name, jd,dest) {
  			try {
  			  $('#' + dest).val('');
  			  var date = $.calendars.instance(name).fromJD(jd);
  			  $('#' + dest).val(date.formatYear()+'/'+date.month()+'/'+date.day());
  			}
  			catch (e) { alert(e); return null; }
  			}

  });

</script>
