<?php
require_once __DIR__ . '/../magic/auth.php';

$auth = bdr_require_privilege(3, '../logout.php');
$user = $auth['user_id'];
$father = $auth['user_id'];
$branch = $auth['branch'];
$conn = $auth['conn'];
$db = $auth['conn'];

require_once "../op/wanted.php";

//check if accountant of Oprearation manager
?>
<!DOCTYPE html>
<html lang="ar" dir="rtl">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="robots" content="index,follow">
  <meta name="author" content="سامح دياب">
  <link rel="icon" href="../images/perfect.ico">
  <title> العقود المديونة </title>
  <link rel="stylesheet" href="../dist/css/bootstrap.css" />
  <link rel="stylesheet" href="../css/font-awesome.min.css" />
  <link rel="stylesheet" href="myCar.css" />
  <script src="../js/jquery.js"></script>
  <script src="../dist/js/umd/popper.min.js"></script>
  <script src="../dist/js/bootstrap.js"></script>
</head>

<body style="background-color:#270c0c ; color:#cce5ff;">
  <div class="navbar navbar-inverse bg-inverse bg-faded sticky-top">
    <div class="container-fluid">
      <div class="row">
        <div class="col">
          <div class="btn-group btn-group-lg" style="font-weight:bold;padding:5px;" role="group" aria-label="...">
            <button type="button" id="branch" style="font-weight:bold;padding:5px;font-size:2rem;" class="btn btn-success">بحث</button>
            <button type="button" id="br_rent" style="font-weight:bold;padding:5px;font-size:2rem;" class="btn btn-info">ساري</button>
            <button type="button" id="br_debt" style="font-weight:bold;padding:5px;font-size:2rem;" class="btn btn-outline-danger">مديون</button>
            <button type="button" id="check" style="font-weight:bold;padding:5px;font-size:2rem;" class="btn btn-secondary">السيارة</button> </div>
        </div>
      </div>
    </div>
  </div>
  <br />
  <?php $output = '';
  $sql = $conn->prepare("SELECT customers.cust_name ,customers.phone,customers.phone2,cars.kind , concat(cars.letters ,' ',cars.numbers) as PL  , cars.model , contracts.day_cost ,contracts.contract_id
      from customers , contracts , cars
         WHERE contracts.cust_id = customers.cust_id AND contracts.carid = cars.carid
          AND contracts.cont_status = 3 AND contracts.branch = ? order by contracts.date_in, contracts.time_in LIMIT 70");
  $sql->bindParam(1, $branch);
  $sql->execute();
  if ($sql->rowCount() > 0) {
    while ($row = $sql->fetch()) {
      $contract_id = $row['contract_id'];
      $wanted = new  Wanted($conn, $contract_id);
      $pay = $wanted->wanted();
      $ww  = $pay["wanted"];
      $days_qty = $pay["days_qty"];
      $payed    = $pay["payed"];
      $phone    = $row['phone'];
      $phone2    = $row['phone2'];
      $output .= '
               <div class="card text-center card-inverse " style="background-color: #1a1a1a; border-color: #333;">
                 <div class="card-header">
                    <h4 class="card-title" style="font-weight:bold;style="font-weight:bold;"> ' . $row['cust_name'] . '</h4>
                </div>
                 <div class="card-block" style="background-color: #333; border-color: #3d5c5c;">
               ';
      if ($ww < 100) {
        $output .= '<p class="card-text" style="font-weight:bold; font-size:1.3rem;"> رقم العقد <span style="font-weight:bold; font-size:1.7rem; color:#e6ffe6 ;">' . $row['contract_id'] . '</span> المطلوب <span style="color:#DA2D07; background-color:#F0F7E4;font-weight:bold;font-size:1.7rem;padding:3px;">' . $ww . '</span></p>';
      } else {
        $output .= '<p class="card-text" style="font-weight:bold; font-size:1.3rem;"> رقم العقد <span style="font-weight:bold; font-size:1.7rem; color:#e6ffe6 ;">' . $row['contract_id'] . '</span> المطلوب <span style="font-weight:bold; font-size:1.7rem;color:#e6ffe6 ;">' . $ww . '</span></p>';
      }
      $output .= '
                     <p class="card-text" style="font-weight:bold; font-size:1.3rem;"> جوال <a style="font-weight:bold; font-size:1.7rem; color:#e6ffe6 ;" href="tel:' . $phone . '">' . $phone . '</a> جوال2 <a style="font-weight:bold; font-size:1.7rem; color:#e6ffe6 ;" href="tel:' . $phone2 . '">' . $phone2 . '</a></p>
                      <p class="card-text" style="font-weight:bold; font-size:1.3rem;">ايام الإيجار <span style="font-weight:bold; font-size:1.7rem;color:#e6ffe6 ;">' . $days_qty . '</span> يومي <span style="font-weight:bold; font-size:1.7rem;color:#e6ffe6 ;">' . $row['day_cost'] . '</span> المدفوع <span style="font-weight:bold; font-size:1.7rem;color:#e6ffe6 ;">' . $payed . '</span></p>
                      </div>
                      <div class="card-footer text-muted">
                      <p class="card-text" style="font-weight:bold; font-size:1.7rem;">' . $row['kind'] . ' <span style="font-weight:bold; font-size:1.7rem;color:#e6ffe6 ;">' . $row['PL'] . '</span> موديل <span style="font-weight:bold; font-size:1.7rem;color:#e6ffe6 ;">' . $row['model'] . '</span></p>
                      </div>
                      </div>  ';
      $output .= '<br /><br />';
    }
  } else {
    $output .= '<p class="card-text" style="font-weight:bold; font-size:1.8rem;">عفوا لا يوجد عقود سارية</p>';
  }
  echo $output; ?>
  <script>
    $(document).ready(function() {
      $("#branch").click(function(event) {
        event.preventDefault();
        window.open("branch.php", '_self');
      });
      $("#br_rent").click(function(event) {
        event.preventDefault();
        window.open("br_rent.php", '_self');
      });

      $("#check").click(function(event) {
        event.preventDefault();
        window.open("check.php", '_self');
      });


    });
  </script>

</body>

</html
