<?php
require_once "../magic/session_config.php";
bdr_start_session();
ob_start();
$br = $_SESSION['branch'];
$end   = date("Y-m-d");
$start = date('Y-m-d', strtotime($end. ' - 183 days'));
include "../actions/dbPDO.php";
 ?>
<div  class="panel panel-primary" id="main_supp">
  <div class="panel-heading clearfix"style="font-size:1.2em;">
  <div class="row" style="padding:4px;">
      <div class="col-md-3"style="float:right;">
        <label class="control-label"style="float:right;font-size: 15px">فواتير العقود</label>
      </div>
      
    </div>
  <div class="panel-body"  style="background-color:#00324d ; color:#cce5ff;">
    <div class="table-responsive">
         <table class="table table-bordered table-hover">
           <thead>
              <tr>
                  <th class="text-center" width="5%">م</th>
                   <th class="text-center" width="7%">رقم الفاتورة</th>
                   <th class="text-center" width="10%">رقم العقد</th>
                   <th class="text-center" width="10%">شامل الضريبة</th>
                   <th class="text-center" width="10%">من</th>
                   <th class="text-center" width="10%">إلي</th>
                   <th class="text-center" width="48%">ملاحظات</th>
              </tr>
            </thead>
              <tbody id="myData">
                <?php
      $output = '';
      $sql =$db->prepare("SELECT vat.vat_id , vat.contract_id , vat.start, vat.end , vat.after_vat , vat.addtion_desc , contracts.branch , contracts.cont_status
                 FROM `vat` , contracts 
                WHERE vat.contract_id = contracts.contract_id AND contracts.branch = ? 
                ORDER BY vat_id DESC LIMIT 25;  ");
          $sql->bindParam(1,$br);
          $sql->execute();
        if($sql->rowCount()>0)
          {$no = 0;
            while($row = $sql->fetch())
                     { $no++ ;
                      $state = $row['cont_status'] ;
                       $contract_id  = $row['contract_id'];
                       $output .= '<tr><td>' . $no . '</td>
                                    <td>';
                            if($state < 3){
                              $output .= ' <a href="rent/print/vat_print.php?vt=' . $row['vat_id'] . '"target="_blank"><button type="button" style="font-weight:bold ; font-size:14px; padding:2;" class="btn btn-success btn-xs btn-block ">' . $row['vat_id'] .'</button></a>';
                            }else{
                              $output .= ' <a href="rent/print/vat_print.php?vt=' . $row['vat_id'] . '"target="_blank"><button type="button" style="font-weight:bold ; font-size:14px; padding:2;" class="btn btn-danger btn-xs btn-block ">' . $row['vat_id'] .'</button></a>';

                            }
                                   
                           $output .=   '</td>
                                    <td>
                                    <a href="rent/cont2debt.php?id=' . $contract_id . '"target="_blank"><button type="button" style="font-weight:bold ; font-size:14px; padding:2;" class="btn btn-danger btn-xs btn-block ">' . $contract_id .'</button></a>
                                    </td>
                                    <td>' . $row['after_vat'] . '</td>
                                    <td class = "table-info">' . $row['start'] . '</td>
                                    <td class="text-center" >' . $row['end'] . '</td>
                                    <td class="text-center" >' . $row['addtion_desc'] . '</td>
                                 </tr>  '; 
                     }
                  }
                  else { $output .= '<tr><td colspan="7">لا يوجد سجلات ...</td></tr>';  }
                  echo $output;
                  ?>
              </tbody>
						<tfoot></tfoot>
          </table>
    </div>
</div>
</div>
<!-- panel body style -->

<script>
$(document).ready(function(){
  $("#nn_sr").click(function(event){
    event.preventDefault();
    var nn = $("#nn").val();
      window.open("rent/cont2debt.php?id="+nn, '_blank');
  });
    $("#ad_a").click(function(event){
        event.preventDefault();
        var ad_a  = $("#ad").val();
        var br    = "<?php echo $br ; ?>";
        var start = $("#start").val();
        var end   = $("#end").val();
    $.ajax({
          url     : "rent/action_debt2.php",
          method  : "POST",
           data    :{ad_a:ad_a,br:br,start:start,end:end},
          success : function(data){ $("#myData").html(data); },
          error   :function(result){
            alert(result.statusText);
            }
        });
      });

      $("#namm_a").click(function(event){
          event.preventDefault();
          var name = $("#namm").val();
          var br    = "<?php echo $br ; ?>";
          var start = $("#start").val();
          var end   = $("#end").val();
     $.ajax({
            url     : "rent/action_debt2.php",
            method  : "POST",
             data    :{name:name,br:br,start:start,end:end},
            success : function(data){ $("#myData").html(data); },
            error   :function(result){
              alert(result.statusText);
              }
          });
        });
        $("#model_btn").click(function(event){
            event.preventDefault();
            var model = $("#model").val();
            var br    = "<?php echo $br ; ?>";
            var start = $("#start").val();
            var end   = $("#end").val();
       $.ajax({
              url     : "rent/action_debt2.php",
              method  : "POST",
               data    :{model:model,br:br,start:start,end:end},
              success : function(data){ $("#myData").html(data); },
              error   :function(result){
                alert(result.statusText);
                }
            });
          });

      $("#datt_a").click(function(event){
          event.preventDefault();
          var datt    = "<?php echo $br ; ?>";
          var start = $("#start").val();
          var end   = $("#end").val();
     $.ajax({
            url     : "rent/action_debt2.php",
            method  : "POST",
             data    :{datt:datt,start:start,end:end},
            success : function(data){ $("#myData").html(data); },
            error   :function(result){
              alert(result.statusText);
              }
          });
        });

});
</script>
