<?php
    $rs = $db->findAll('tbbooking')->execute();
        function DateThai($strDate){
      $strYear = date("Y",strtotime($strDate))+543;
      $strMonth= date("n",strtotime($strDate));
      $strDay= date("j",strtotime($strDate));
      $strHour= date("H",strtotime($strDate));
      $strMinute= date("i",strtotime($strDate));
      $strSeconds= date("s",strtotime($strDate));
      $strMonthCut = Array("","ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");
      $strMonthThai=$strMonthCut[$strMonth];
      return "$strDay $strMonthThai $strYear";
    }

          function DateGoBack($DateGo,$DateBack){
      $strYear = date("Y",strtotime($DateBack))+543;
      $strMonth= date("n",strtotime($DateBack));
      $strDay = date("j",strtotime($DateBack));
      $strDay2 = date("j",strtotime($DateGo));
      $strMonth2= date("n",strtotime($DateGo));
      $strYear2 = date("Y",strtotime($DateGo))+543;
      // $strMonthCut = Array("","มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
      $strMonthCut = Array("","ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");
      $strMonthCut2 = Array("","ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");
      $strMonthThai=$strMonthCut[$strMonth];
      $strMonthThai2=$strMonthCut2[$strMonth2];

      return "$strDay2-$strDay $strMonthThai $strYear";
    }

function DateDiff($strDate1,$strDate2)
   {
  return (strtotime($strDate2) - strtotime($strDate1))/  ( 60 * 60 * 24 );  // 1 day = 60*60*24
   }

$todayisreal = date("m/d/Y");
   // $todays = date("m/d/Y");
   $todays = date("Y-m-d");

  $todays2 = date("Y-m-d");

  $todays10 = date("Y-m-d", strtotime("+10 day"));
  

  $todays1 = date("m/d/Y");

   $book_today = $db->findByAttributes('tbbooking',array('book_date =' => $todays1))->execute();


   if ($_SESSION['admin_status'] == 0 || $_SESSION['admin_status'] == 2 || $_SESSION['admin_id'] == 51) {
    $rstime = $db->findorderid('tbiv', 'iv_status_2','0','str_to_date(pro_datego,"%m/%d/%Y") asc, iv_id')->execute();
    $diss = 'disabled';
   }else{
    if($_SESSION['admin_id'] == 49){
    $admintest = 'เฟิร์น';;
    $rstime = $db->findByAttributes('tbiv',array('iv_admin =' => 'เฟิร์น'))->execute();
    }else if($_SESSION['admin_id'] == 51){
    $book_ad = $db->findAll('tbiv')->execute();
    $rs = $db->findByAttributes('tbiv',array('admin_id =' => $admin_id))->execute();
     $book_dateline = $db->findByAttributes('tbiv',array('date_line =' => $todays))->execute();
    }else if($_SESSION['admin_id'] == 52){
    $book_t = $db->findByAttributes('tbiv',array('iv_date =' => $today, 'iv_admin =' => 'Patra'))->execute();
    $book_t2 = $db->findByAttributes('tbiv',array('iv_date =' => $today, 'iv_admin =' => $admin_id))->execute();
    $book_ad = $db->findByAttributes('tbiv',array('admin_nickname =' => $admin_id))->execute();
    $rs = $db->findByAttributes('tbiv',array('iv_admin =' => 'Patra'))->execute();
    $rs2 = $db->findByAttributes('tbiv',array('iv_admin =' => $admin_id))->execute();
    $rstime = $db->findByAttributes('tbiv',array('iv_admin =' => 'Patra'))->execute();
        $book_dep = $db->findByAttributes('tbiv',array('mus_date =' => $todays, 'iv_admin =' =>'Patra'))->execute();
        $book_dateline = $db->findByAttributes('tbiv',array('date_line =' => $todays, 'iv_admin =' => 'Patra'))->execute();
    }else if($_SESSION['admin_id'] == 53){
    $rstime = $db->findByAttributes('tbiv',array('iv_admin =' => 'เล็ก'))->execute();
    }else if($_SESSION['admin_id'] == 56){
    $rstime = $db->findByAttributes('tbiv',array('iv_admin =' => 'Nok'))->execute();
    }else if($_SESSION['admin_id'] == 55){
    $rstime = $db->findByAttributes('tbiv',array('iv_admin =' => 'Noon'))->execute();
    }else{
    $book_ad = $db->findAll('tbiv')->execute();
    $rs = $db->findByAttributes('tbiv',array('admin_id =' => $admin_id))->execute();
    $book_dateline = $db->findByAttributes('tbiv',array('date_line =' => $todays))->execute();
   }

   }
?>
<div class="row m-auto" style="display: ;">
<div class="col-xl-3 col-md-4"> 
<div class="panel panel-default">
  <div class="panel-body" style="padding: 0;">
    <a href="?url=iv_pay" data-link="?url=iv_pay" class="btn btn-primary with-shadow-primary btn-block">
    <i class="fa-solid fa-rectangle-xmark fa-3x"></i> <br><br>
    ใบจองที่ชำระแล้ว
  </a>
  </div>
</div>
</div>
<div class="col-xl-3 col-md-4"> 
<div class="panel panel-default">
  <div class="panel-body" style="padding: 0;">
    <a href="?url=iv_nopay" data-link="?url=iv_nopay" class="btn btn-dark with-shadow-dark btn-block">
    <i class="fa-solid fa-rectangle-xmark fa-3x"></i> <br><br>
    ใบจองที่ยังไม่ชำระ
  </a>
  </div>
</div>
</div>
  </div>
<section class="panel panel-danger">
<header class="panel-heading bg-primary">
<div class="panel-actions">
<a href="#" class="fa fa-caret-down"></a>
</div>
<h2 class="panel-title">ใบจองที่มีการชำระ (<?=$_SESSION['admin_nickname'];?>)</h2>
</header>
<div class="panel-body text-dark">
                    <table class="table table-bordered table-striped mb-none datatable" id="datatable-iv">
                      <thead>
                          <tr style="text-align:center;">
                            <th style="width:340px;">ชื่อรายการทัวร์</th>
                            <th style="text-align:center;width:70px;">พนักงานขาย</th>
                            <th style="text-align:center;width:180px;">วันที่เดินทาง</th>
                            <th style="text-align:center;width:80px;">จำนวน</th>
                            <th style="text-align:center;width:80px;">STATUS</th>
                            <th style="text-align:center;width:80px;">#</th>
                          </tr>
                      </thead>
                          <tbody>
                       <?php
                        while($dbarr= mysql_fetch_array($rstime)){ 
             $datediff = DateDiff($todayisreal,$dbarr['pro_datego']);
            $g_date = $dbarr['pro_datego'];
            $g_explode = explode("-", $g_date);
            $g_year = $g_explode[0];
            $g_month = $g_explode[1];
            $g_day = $g_explode[2];
            $book_all = $dbarr['adult_num']+$dbarr['c_num']+$dbarr['nb_num'];
             ?>
              <?if($dbarr['iv_status_2'] == '0'){?>
             <?if($g_date >= $todays2){
              $payin = $db->findByPK('tbpayment','payment_iv',$dbarr['iv_id'])->executeRow();?>
              <?if ($payin['payment_iv'] == $dbarr['iv_id']) {?>
                          <tr>
                            <td style="line-height:1.6;vertical-align:middle;">
                            <span style="font-size:1.2rem;">รหัสทัวร์ : <?=$dbarr[iv_codepro];?></span><br>
                            <span style="font-size:1.2rem;"><?=$dbarr[iv_namepro];?></span><br>
                             <span style="font-size:1.2rem;">ชื่อลูกค้า : คุณ <?=$dbarr[cus_name];?></span><br>
                              <span>INVOICE : </span><a href="https://www.imaginetourservice.com/ivnew.php?id=<?=$dbarr[iv_id];?>" target="_blank">IM<?=$dbarr['iv_id'];?></a><br>
                              <span style="font-size:1rem;font-weight:400;" class="label label-dark">BOOKTIME : <?=DateThai($dbarr[iv_date]);?></span>
                            </td>
                            <td style="text-align:center;"><?=$dbarr['iv_admin'];?></td>
                            <td style="text-align:center;line-height:1.4;"><?=DateGoBack($dbarr['pro_datego'],$dbarr['pro_dateback']);?> <br>
                              <span style="color:red;"><?=$datediff;?>วัน ออกเดินทาง</span>
                              <br>
  <?if(!empty($dbarr['iv_status_work4'])){?>
  <span style="font-size:0.8rem;" class="text-success">ใบนัดหมาย : <?=$dbarr['iv_status_work4'];?></span> 
  <?}else{?>
  <span style="font-size:0.8rem;" class="text-danger">ใบนัดหมาย : ยังไม่มีการดำเนินการ</span> 
  <?}?>
                          </td>
                            <td style="text-align:center;font-weight:bold;font-size:1.5rem;"><?=$book_all;?></td>
                            <?if ($payin['payment_iv'] == $dbarr['iv_id']) {
                            echo "<td style='line-height:21pt;text-align:center;'  class='text-danger'>
                             <a class='btn btn-primary' href='?url=maindatabase_update&id=$dbarr[iv_id]'  style='font-size:0.8rem;display:block;' target='_blank'>มีการขำระเงิน</a>
                             </td>";
                            }else{
                            echo "<td style='line-height:21pt;text-align:center;'  class='text-danger'>
                             <a class='btn btn-dark' href='?url=maindatabase_update&id=$dbarr[iv_id]' style='font-size:0.8rem;display:block;' target='_blank'>ยังไม่มีการชำระ</a>
                             </td>";
                            } ?>
                            <td style="text-align:center;"> <a class='btn btn-danger' href='?url=maindatabase_update&id=<?=$dbarr[iv_id];?>' target="_blank">จัดการ</a></td>

                          </tr>
                         <? } }}}?>

                         </tbody>
      </table>
</div>
</section>