<?php
if (!isset($_SESSION)) {
  session_start();
}
// ob_start();
if (!isset($_SESSION["user_id"])) {
  header("location:../../logout.php");
}
include_once('newCont_api.php');
$contt = $_REQUEST['contt'];
?>
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>print</title>
  <link rel="stylesheet" href="css/print.css">
</head>
<style>
@media print {
 body, html , page{
    margin: 0;
    width: 210mm;
    height: 277mm;
    box-shadow: 0; 
    background-position: top left;
    /* background-size: 100%; */
    width:100%;
    min-height: 100%;
  }
}
page{
  background-image: url("css/form3.png");
  background-repeat: no-repeat;
  text-align: center;
  padding: 5px;
  background-size: cover;
}
.zero{
      line-height:123%;
      padding: 3px;
      float : right;
  }
</style>

<body>
  <section>
    <page size="A4">
    <br /><br /><br />
      <br /><br /><br />
      <br /><br/>
      <div class="row">
          <output style="padding: 0px; margin:0px;" class="zero w100 t_center "type="text">هذة ليست فاتورة ضريبة القيمة المضافة </output>
        </div>
        <br />
      <div class="row">
        <article class="w4 brr">
          <div class="row">
            <output class="out_free w35 t_right t_h " type="text" id="cust_name"></output>
            <output class="out_free w1 t_right " type="text">:المستاجر</output>
          </div>
          <div class="row">
            <output class="out_free w2 t_right " type="text" id="nation"></output>
            <output class="out_free w2 t_center " type="text"> : الجنسية</output>
            <output class="out_free w2 t_center t_h" type="text" id="idSA"></output>
            <output class="out_free w2 t_right " type="text"> :رقم الهوية</output>
          </div>
          <div class="row">
            <output class="out_free w2 t_center " type="text" id="lic_expire"></output>
            <output class="out_free w2 t_right" type="text"> :نهاية الرخصة </output>
            <output class="out_free w2 t_right t_h " type="text" id="license"></output>
            <output class="out_free w2 t_right " type="text"> :رقم الرخصة</output>
          </div>
        </article>
        <article class="w4 brr">
          <div class="row">
            <output class="out_free w2 t_right t_h " type="text" id="days"></output>
            <output class="out_free w2 t_right " type="text">فترة العقد</output>
            <output class="out_free w2 t_right t_h " type="text" id="contract_id"></output>
            <output class="out_free w2 t_right " type="text">رقم العقد</output>
          </div>
          <div class="row brr">
            <output class="out_free w62 t_center t_h" type="text" id="used_area"></output>
            <output class="out_free w3 t_right hd" type="text">منطقة الإستخدام</output>
          </div>
          <div class="row">
            <output class="out_free w3 t_right " type="text" id="model"></output>
            <output class="out_free w1 t_right hd " type="text">: موديل</output>
            <output class="out_free w2 t_center" type="text" id="PL"></output>
            <output class="out_free w2 t_right hd " type="text"> :رقم اللوحة</output>
          </div>
          <div class="row">
            <output class="out_free w3 t_right " type="text" id="color"></output>
            <output class="out_free w1 t_right hd" type="text">: اللون</output>
            <output class="out_free w4 t_center" type="text" id="kind">سيارة </output>
          </div>
        </article>
      </div>
      <div class="row">
        <article class="w4 brr">
          <div class="row">
            <output class="out_free w35 t_right " type="text" id="address"></output>
            <output class="out_free w1 t_right " type="text">:العنوان</output>
          </div>
          <div class="row">
            <output class="out_free w2 t_center " type="text" id="phone2"></output>
            <output class="out_free w2 t_right hd" type="text">: تليفون</output>
            <output class="out_free w2 t_right" type="text" id="phone"></output>
            <output class="out_free w2 t_right hd" type="text">: جوال رقم</output>
          </div>
          <div class="row">
            <output class="out_free w75 t_right" type="text" id="working_woner"></output>
            <output class="out_free w2 t_right hd" type="text">: جهة العمل</output>
          </div>
          <div class="row">
            <output class="out_free w2 t_center " type="text" id="w_phone"></output>
            <output class="out_free w2 t_right hd" type="text">: تليفون</output>
            <output class="out_free w2 t_right" type="text" id="w_phone2"></output>
            <output class="out_free w2 hd t_right" type="text">: جوال رقم</output>
          </div>
          <div class="row">
            <output class="out_free w35 t_right " type="text" id="working_address"></output>
            <output class="out_free w1 hd t_right " type="text">: العنوان</output>
          </div>
        </article>


        <article class="w4" id="second_customer">
          
        </article>


      </div>
      <br />
      <div class="row">
        <article class="w100">
          <div class="row">
            <output class="out_free w2 t_center " type="text"></output>
            <output class="out_free br2 w1 t_h hd t_center " type="text">إجمالي</output>
            <output class="out_free br2 w1 t_h hd t_center " type="text">سعر</output>
            <output class="out_free br2 w1 t_h hd t_center " type="text">عدد</output>
            <output class="out_free br2 w1 t_h hd t_center " type="text">العودة</output>
            <output class="out_free br w1 t_h hd t_center " type="text">خروج</output>
            <output class="out_free  w1 t_center " type="text"></output>
          </div>
          <div class="row">
            <output class="out_free br2 w1 t_center " type="text">الكيلومتر المستخدم</output>
            <output class="out_free br2 w1 t_center " type="text">الكيلومتر اليومي</output>
            <output class="out_free br2 w1 t_center " type="text" id="days_cost"></output>
            <output class="out_free br2 w1 t_center " type="text" id="day_cost"></output>
            <output class="out_free br2 w1 t_center " type="text" id="days_qty"></output>
            <output class="out_free br2 w1 t_center " type="text" id="date_in"></output>
            <output class="out_free br2 w1 t_center " type="text" id="date_out"></output>
            <output class="out_free br w1 t_center hd t_h " type="text">تاريخ</output>
          </div>
          <div class="row">
            <output class="out_free br2 w1 t_center " type="text" id="used_km"></output>
            <output class="out_free br2 w1 t_center " type="text" id="free_kilo"></output>
            <output class="out_free br2 w1 t_center " type="text" id="kilos_cost"></output>
            <output class="out_free br2 w1 t_center " type="text" id="kilo_cost"></output>
            <output class="out_free br2 w1 t_center " type="text" id="km_qty"></output>
            <output class="out_free br2 w1 t_center " type="text" id="km_in"></output>
            <output class="out_free br2 w1 t_center " type="text" id="km_out"></output>
            <output class="out_free br w1 t_center hd t_h " type="text">عداد</output>
          </div>
          <div class="row">
            <output class="out_free  w1 t_center " type="text"></output>
            <output class="out_free  w1 t_center " type="text"></output>
            <output class="out_free br2 w1 t_center " type="text" id="hours_cost"></output>
            <output class="out_free br2 w1 t_center " type="text" id="">طبقا للمعادلة</output>
            <output class="out_free br2 w1 t_center " type="text" id="hour_qty"></output>
            <output class="out_free br2 w1 t_center " type="text" id="time_in"></output>
            <output class="out_free br2 w1 t_center " type="text" id="time_out"></output>
            <output class="out_free br w1 t_center hd t_h " type="text">ساعة</output>
          </div>
        </article>
      </div>
      <!-- حسابات و اضافي  -->
      <div class="row">
        <article class="w4">
          <div class="row" style="margin-right:-6px;">
            <output class="out_free w2 sb2 sb3 t_right " type="text" id="addtion_cost">123</output>
            <output class="out_free w2 sb2 t_left" type="text">تلافيات</output>
            <output class="out_free br2 w2 t_center t_h " type="text" id="rent_cost">00</output>
            <output class="out_free br w2 t_center hd" type="text">إجمالي إيجار</output>
          </div>
          <div class="row" style="margin-right:-6px;">
            <output class="out_free w2 sb3 t_right " type="text" id="ins_claim">123</output>
            <output class="out_free w2 t_left " type="text">قسط تحمل</output>
            <output class="out_free br2 w2 t_center " type="text" id="tot_addtion">00</output>
            <output class="out_free br w2 t_center " type="text">إضافي</output>
          </div>
          <div class="row" style="margin-right:-6px;">
            <output class="out_free w2 sb3 t_right " type="text" id="violations">123</output>
            <output class="out_free w2  t_left " type="text">مخالفات</output>
            <output class="out_free br2 w2 t_center " type="text" id="tot_cutt">00</output>
            <output class="out_free br w2 t_center " type="text">خصم</output>
          </div>
        </article>
        <article class="w4 ">
          <div class="row">
            <output class="out_free w100 zero t_right" style="line-height: 0.59cm;" type="text" id="addtion_desc">
            </output>
          </div>
        </article>
      </div>
      <!-- نهاية العقد   -->
      <div class="row">
        <article class="w100">
          <div class="row">
            <output class="out_free w1 sb4 sb3 t_right " type="text" id="next_cust">123</output>
            <output class="out_free w1 sb4 t_left " type="text">مستاجر2</output>
            <output class="out_free br2 w1 t_center t_h " type="text" id="net_cost">00</output>
            <output class="out_free br2 w1 t_center " type="text">قيمة العقد</output>
            <output class="out_free br2 w1 t_center " type="text">سندات صرف</output>
            <output class="out_free br w1 t_center " type="text">سندات قبض</output>
            <output class="out_free w2 t_right sb2 sb3  " type="text">تم فتح العقد بواسطة</output>
          </div>
          <div class="row">
            <output class="out_free w2 t_center " type="text"></output>
            <output class="out_free br2 w1 t_center " type="text" id="vat_req">00</output>
            <output class="out_free br2 w1 t_center " type="text">القيمة المضافة</output>
            <output class="out_free br2 w1 t_center " type="text" id="total_out">00</output>
            <output class="out_free br w1 t_center " type="text" id="total_in">00</output>
            <output class="out_free w2 t_right sb3 " type="text" id="realName">00</output>
          </div>
          <div class="row">
            <output class="out_free br2  w1 t_center t_h " type="text" id="wanted">00</output>
            <output class="out_free br2 hd w1 t_center t_h " type="text">المطلوب</output>
            <output class="out_free br2 w1 t_center t_h " type="text" id="after_vat"></output>
            <output class="out_free br2 hd w1 t_center " type="text">إجمالي عام</output>
            <output class="out_free br2 w1 t_center " type="text" id="payed">00</output>
            <output class="out_free br hd w1 t_center " type="text">صافي المدفوع</output>
            <output class="out_free w2 t_right sb4 sb3 " type="text" id="branch"></output>
          </div>
        </article>
      </div>
      </div>
      <div class="row">
        <article class="w4">
          <div class="row">
            <output class="out_free w4" type="text"></output>
            <output class="out_free w4 t_right " type="text">توقيع المستأجر</output>
          </div>
        </article>
        <article class="w4">
          <div class="row ">
            <output class="out_free w4 " type="text"></output>
            <output class="out_free w2 sb4 t_right" type="text" id="branch2"></output>
            <output class="out_free  w2 sb4 t_right" type="text">: إستلام السيارة</output>
          </div>
          <div class="row ">
            <output class="out_free w4 " type="text"></output>
            <output class="out_free w2  sb4 t_right" type="text" id="closer"></output>
            <output class="out_free w2 sb4 t_right" type="text">موظف الفرع</output>
          </div>
        </article>
      </div>
      <br/><br/><br/>
      <br/><br/><br/>
      <br/>
      <div class="row">
    <output class="zero w2 t_center br zero"type="text" >alwassam2030@gmail.com</output>
    <output class="zero w75 t_center br zero"type="text" id="address3"></output>
  </div>
      <!-- end of page -->
    </page>
  </section>
  <script src="myclass.js"></script>
  <script>
    var contt = <?php echo $contt; ?>;

    function formatAMPM(date) {
      var hours = date.getHours();
      var minutes = date.getMinutes();
      var ampm = hours >= 12 ? 'pm' : 'am';
      hours = hours % 12;
      hours = hours ? hours : 12; // the hour '0' should be '12'
      minutes = minutes < 10 ? '0' + minutes : minutes;
      var strTime = hours + ':' + minutes + ' ' + ampm;
      return strTime;
    }
    const http = new ApiData;
    const ui = new UI;
    let url = 'newCont_api.php?ct=' + contt;
    const second = document.getElementById('second_customer');
   http.get(url)
      .then(data => {
        document.getElementById('payed').value = data.payed;
        document.getElementById('days').value = data.rent_days;
        document.getElementById('contract_id').value = data.contract_id;
        document.getElementById('used_area').value = data.used_area;

        document.getElementById('PL').value = data.PL;
        document.getElementById('model').value = data.model;
        document.getElementById('kind').value = data.brand + ' ' + data.kind;
        document.getElementById('color').value = data.color;

        document.getElementById('cust_name').value = data.cust_name;
        document.getElementById('idSA').value = data.idSA;
        document.getElementById('nation').value = data.nation;
        document.getElementById('license').value = data.license;
        document.getElementById('lic_expire').value = data.lic_expire;
        document.getElementById('address').value = data.address;
        document.getElementById('phone').value = data.phone;
        document.getElementById('phone2').value = data.phone2||"";
        document.getElementById('working_woner').value = data.working_woner;
        document.getElementById('w_phone').value = data.w_phone||"";
        document.getElementById('w_phone2').value = data.w_phone2||"";
        document.getElementById('working_address').value = data.working_address;

        document.getElementById('date_out').value = data.date_out;
        document.getElementById('date_in').value = data.date_in;

        let open_kilo = parseFloat(data.open_kilo_day) ;
        let wesam_ins = parseFloat(data.wesam_ins_day) ;
        let daycost = parseFloat(data.day_cost);
        let day = (daycost + open_kilo + wesam_ins) ;
        var kilo_ins = open_kilo + wesam_ins ;
        kilo_ins = kilo_ins * data.days_qty ;
        document.getElementById('day_cost').value = parseFloat(day).toFixed(2);

        document.getElementById('days_qty').value = data.days_qty;
        document.getElementById('days_cost').value = data.days_cost + kilo_ins;
        document.getElementById('km_out').value = data.km_out;
        document.getElementById('km_in').value = data.km_in;
        document.getElementById('km_qty').value = data.km_qty;
        document.getElementById('kilo_cost').value = data.kilo_cost;
        document.getElementById('kilos_cost').value = data.kilos_cost;
        document.getElementById('used_km').value = data.used_km;
        document.getElementById('time_out').value = data.time_out;
        document.getElementById('time_in').value = data.time_in;
        document.getElementById('hour_qty').value = data.hour_qty;
        document.getElementById('hours_cost').value = data.hours_cost;
        document.getElementById('free_kilo').value = data.free_kilo;
        document.getElementById('branch').value = " فرع " + data.branch;
        document.getElementById('branch2').value = " فرع " + data.branch2;
        document.getElementById('realName').value = data.realName;

        document.getElementById('addtion_desc').value = data.addtion_desc;
        document.getElementById('tot_addtion').value = data.tot_addtion;
        document.getElementById('tot_cutt').value = data.tot_cut;
        document.getElementById('total_in').value = data.total_in;
        document.getElementById('total_out').value = data.total_out;
        document.getElementById('rent_cost').value = data.rent_cost + kilo_ins;;
        document.getElementById('net_cost').value = data.net_cost;
        document.getElementById('vat_req').value = data.vat_req;
        document.getElementById('after_vat').value = data.after_vat;
        document.getElementById('wanted').value = data.wanted;
        document.getElementById('closer').value = data.closer;

        document.getElementById('addtion_cost').value = data.addtion_cost;
        document.getElementById('ins_claim').value = data.ins_claim;
        document.getElementById('violations').value = data.violations;
        document.getElementById('address3').value = data.branch+" "+data.address4+" هاتف "+data.phone4 + " # "+data.phone5 ;
        document.getElementById('next_cust').value = data.next_cust;
        if(data.cust_id2 != 0){
      second.innerHTML = `

      <div class="row brr">
            <output class="out_free w75 t_right t_h " type="text">${data.cust_name3}</output>
            <output class="out_free w2 t_right " type="text">:مستأجر إضافي</output>
          </div>
          <div class="row">
            <output class="out_free w2 t_right " type="text">${data.nation3}</output>
            <output class="out_free w2 t_center " type="text"> : الجنسية</output>
            <output class="out_free w2 t_center t_h" type="text">${data.idSA3}</output>
            <output class="out_free w2 t_right " type="text"> :رقم الهوية</output>
          </div>
          <div class="row">
            <output class="out_free w35 t_right " type="text">${data.address3}</output>
            <output class="out_free w1 t_right " type="text">:العنوان</output>
          </div>
          <div class="row">
            <output class="out_free w2 t_center " type="text">${data.phone23}</output>
            <output class="out_free w2 t_right hd" type="text">: تليفون</output>
            <output class="out_free w2 t_right" type="text">${data.phone3}</output>
            <output class="out_free w2 t_right hd" type="text">: جوال رقم</output>
          </div> `;
    }
  setTimeout(window.print , 1200);
  setTimeout(window.close, 1500);
      }).catch(err => console.log(err));
  </script>
</body>
</html>