<?
include getenv("DOCUMENT_ROOT")."/include/session_include.php";

//$func->checkAdmin("index.php");

$d_accountno = trim($_POST["d_accountno"]);

//echo "[$d_uid]";exit;

if($d_accountno == "") {
		$msg = "Invalid data. Please try again. [Err - d_uid / HISTORY]";
		$func -> modalMsg ($msg, 1);
		exit();
} else {
	
		//total record
		$qry_oil = "SELECT COUNT(d_uid) FROM tbl_daily
							WHERE d_accountno = '$d_accountno' AND d_status = 'F' ". $add_driver_query;

		$total_count=$jdb->rQuery($qry_oil, "record query error");
		//echo "[$total_count][$qry_oil]<br>";

		//페이징변수설정
		$INIT_PAGECNT = 500;
		if(!$pageqna) $pageqna = 1;
		if ($pageflag != "note") $pageqna = 1;
		if(!$list_count) $list_count = $INIT_PAGECNT; //출력리스트 갯수
		if(!$page_count) $page_count = $INIT_PAGEVIEWCNT; //출력페이지 갯수
		$list_number = $total_count - (($pageqna-1)*$list_count);
		$start_number = $list_count * ($pageqna-1);

		$add_query .= " LIMIT $start_number, $INIT_PAGECNT";
		$qry_oilh = "SELECT * FROM tbl_daily
							WHERE d_accountno = '$d_accountno' AND d_status = 'F' ". $add_driver_query .
							" ORDER BY d_visitdate DESC " . $add_query;
		//echo "<<br><br><br><br><br>[$qry_oilh]";

		$rt_oilh = $jdb->nQuery($qry_oilh, "list error");

		while($list=mysqli_fetch_array($rt_oilh, MYSQLI_ASSOC)) {
				for($i=0; $i<sizeof($list); $i++) {
				//list($key, $value) = each($list);
				foreach ( (Array) $list as $key => $value )					
					$$key = $value;
				}

				
				//$signupdateStr = $func -> convertFormat ($MSIGNUPDATE, 1);
					
				//$qry = "SELECT CNAME  FROM tbl_company WHERE CUID = '$MCOMPANY' ";
				//$rtd=$jdb->fQuery($qry, "fetch query error"); 
				//if ($MCOMPANY == "0" || $MCOMPANY == "") $companyStr = "-";
				//else $companyStr = $rtd[CNAME];
				
				$d_visitdateSTR = $func -> convertFormat ($d_visitdate, 3);
				
				if ($d_paymenttype == "CA") {
					$d_paystatusSTR = $arrPaidStatus[$d_paystatus];
					if ($d_paystatus == "P") $d_paystatusSTR = $d_paystatusSTR." ($".$d_payamount.")";
				}
				else $d_paystatusSTR = "";
				
				$d_quantitySTR = number_format(floatval($d_quantity));
				
				//$qry_dvr = "SELECT m_initial FROM tbl_member WHERE m_uid = '".$d_driveruid."' ";
				//$rt_dvr = $jdb->fQuery($qry_dvr, "fetch query error");

				$strList .= "
            <tr>
            	<td class='td-text-info'>$list_number</td>
              <td class='td-text-info' style=\"text-align: center;\">$d_visitdateSTR</td>
              <td class='td-text-info' style=\"text-align: right;margin-right: 20px;\">$d_quantitySTR</td>
              <td class='td-text-info' style=\"text-align: center;\">$d_drinitial</td>
              <td class='td-text-info'>$d_paystatusSTR</span></td>
            </tr>				
				";

				$list_number--;
		}

		if( $total_count < 1 ) {
			$strList = "
				<tr><td colspan='5' align=center height='30'><B>No Data</B></td></tr>
				";
		}		
            
}

?>

      <div class="modal-header">
        <h4 class="modal-title">HISTORY</h4>
        <button type="button" class="btn" data-dismiss="modal" aria-label="Close" style="color:#fff;"><i class="bi bi-x"></i></button>
      </div>
      <div class="modal-body">
      	<div class="history-warp-scroll">
        <form method="POST" action="#">
          <table class="tb-info-box1">
            <tr>
            	<td class="td-title-info td-no">No</td>
              <td class="td-title-info td-date-history">Date</td>
              <td class="td-title-info td-oil-quantity-history">Oil Quantity</td>
              <td class="td-title-info td-date-history">Driver</td>
              <td class="td-title-info td-paid">Paid (Cash)</td>
            </tr>

						<?=$strList?>

<!--
            <tr>
              <td class="td-text-info">2023-10-31</td>
              <td class="td-text-info">543</td>
              <td class="td-text-info">D.S</td>
              <td class="td-text-info">Paid <span>($50)</span></td>
            </tr>

            <tr>
              <td class="td-text-info">2023-10-31</td>
              <td class="td-text-info">543</td>
              <td class="td-text-info">D.S</td>
              <td class="td-text-info">Paid <span>($50)</span></td>
            </tr>
-->

          </table>
        </div>
          
          <!--div class="container-inner">
            <div class="pagination">
              <a href="#" ><i class="bi bi-arrow-left"></i></a>
              <a href="#"class="active">1</a>
              <a href="#">2</a>
              <a href="#">3</a>
              <a href="#">4</a>
              <a href="#">5</a>
              <a href="#">6</a>
              <a href="#"><i class="bi bi-arrow-right"></i></a>
            </div>
          </div-->

          <br>
          <div class="text-center">
          	<button type="button" class="btn-gray width-200" data-dismiss="modal">CLOSE</button>
          </div>
        </form>
      </div>
