<?
// Level 9 이하만 사용 가능
$func->checkLevelModal(9);

// Delete 기능 제한 (Admin : 1, Staff : 5, Accounting : 6 만 가능)
$permit = array("1", "5", "6");
if (in_array($_SESSION['ss_LEVEL'], $permit)) {
    $setTag = "";
}
else $setTag = "DISABLED";	

// Admin 만 사용하는 기능을 위해
$permitAdm = array("1");
if (in_array($_SESSION['ss_LEVEL'], $permitAdm)) {
    $setTagAdm = "";
}
else $setTagAdm = "DISABLED";	

$goStr = "&searchtype=$searchtype&searchDriver=$searchDriver&switched=$switched&page=$page&key_word=$key_word&column=$column&sorting_type=$sorting_type&switch=$switch&mode=$mode&cstatus=$cstatus";

// User data query
if($d_customeruid == "") {
	$msg = "Invaild data. Please try again.";
	$func -> modalMsg ($msg, "/index_intranet.php?view=oilhistory_list&$goStr");
	exit();
}
					
$query = "SELECT * FROM tbl_customer WHERE c_uid = '$d_customeruid'";
$result = $jdb->fQuery($query, "query error");

// No data
if ($result[0] =="") {
	$msg = "Invaild data. Please try again.";
	$func -> modalMsg ($msg, "/index_intranet.php?view=oilhistory_list&$goStr");
	exit();
}

//echo "[$query]";
for($i=0; $i<sizeof($result); $i++) {
	//list($key, $value) = each($result);
	foreach ( (Array) $result as $key => $value )
	$$key = $value;
}

$c_nameSTR = str_replace("\\", "", $c_name);
$c_payabletoSTR = str_replace("\\", "", $c_payableto);
$c_mailingaddrSTR = str_replace("\\", "", $c_mailingaddr);

//echo "<br><br><br><br><br>[".utf8_encode($c_phone)."]";
$c_addressSTR = str_replace("\\", "", $c_address);

$c_containerSTR = str_replace("\\", "", $c_container);
if ($c_fullcycleflag == 1) {
  $c_fullcycleSTR = $c_fullcycleforced;
  $c_fullcycleCSS = "style='color:red;'";
}
else {
  $c_fullcycleSTR = $c_fullcycle;
  $c_fullcycleCSS = "";
}


///////////////////
// Get Oil History
///////////////////


if ($searchtype == "D") $add_driver_query = "AND d_driveruid = '".$searchDriver."' ";
else $add_driver_query = "";

//total record
$qry_oil = "SELECT COUNT(d_uid) FROM tbl_daily
					WHERE d_customeruid = '$d_customeruid' AND d_status = 'F' ". $add_driver_query;

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

//페이징변수설정
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_customeruid = '$d_customeruid' 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);
		
	$d_paystatusSTR = $arrPaidStatus[$d_paystatus];
	if ($d_paystatus == "P") $d_paystatusSTR = $d_paystatusSTR." ($".$d_payamount.")";
    if ($d_paystatus == "N" && $d_paynote != '') $d_paystatusSTR = $d_paynote;
	
	$d_quantitySTR = number_format(floatval($d_quantity));


	$strList .= "
            <tr>
              <td>$list_number</td>
              <td>$d_visitdateSTR</td>
              <td>$d_quantitySTR</td>
              <td>$d_sludge</td>
              <td>".$d_drinitial."</td>
              <td>$d_paystatusSTR</td>
            </tr>

	";

	$list_number--;

            
}

?>


  <main id="main" class="main">

    <!-- ======= Breadcrumbs ======= -->
    <div class="breadcrumbs">
      <div class="container">

        <div class="d-flex justify-content-between align-items-center">
          <h2>DETAIL INFORMATION</h2>
          <ol>
            <li><a href="index.html">HOME</a></li>
            <li>DETAIL INFORMATION</li>
          </ol>
        </div>

      </div>
    </div><!-- End Breadcrumbs -->

    <section class="page">


      <div class="container" data-aos="fade-up">


        <div class="container section-oil-history-details" data-aos="fade-up">
          <div class="oil-history-detail-info-cols top-border">
            <div class="oil-history-detail-info-col oil-history-title">Restaurant Name</div>
            <div class="oil-history-detail-info-col"><?=$c_nameSTR?></div>
            <div class="oil-history-detail-info-col oil-history-title">Payment</div>
            <div class="oil-history-detail-info-col"><?=$arrPaymenttype[$c_paymenttype]?></div>

            <div class="oil-history-detail-info-col oil-history-title">Account</div>
            <div class="oil-history-detail-info-col"><?=$c_accountno?></div>
            <div class="oil-history-detail-info-col oil-history-title">Payment Cycle</div>
            <div class="oil-history-detail-info-col"><?=$arrPaymentCycle[$c_paymentcycle]?></div>

            <div class="oil-history-detail-info-col oil-history-title">Address</div>
            <div class="oil-history-detail-info-col"><?=$c_addressSTR?></div>
            <div class="oil-history-detail-info-col oil-history-title">Payable To</div>
            <div class="oil-history-detail-info-col"><?=$c_payabletoSTR?></div>

            <div class="oil-history-detail-info-col oil-history-title">Rate</div>
            <div class="oil-history-detail-info-col"><?=$c_rate?></div>
            <div class="oil-history-detail-info-col oil-history-title">Mailing Address</div>
            <div class="oil-history-detail-info-col"><?=$c_mailingaddrSTR?></div>

            <div class="oil-history-detail-info-col oil-history-title">Container</div>
            <div class="oil-history-detail-info-col"><?=htmlspecialchars($c_containerSTR, ENT_QUOTES)?></div>
            <div class="oil-history-detail-info-col oil-history-title">Cycle</div>
            <div class="oil-history-detail-info-col"<?=$c_fullcycleCSS?>><?=$c_fullcycleSTR?></div>

          </div>
        </div>
        


        <div class="wrap-overflow forecast-info">
          <table class="tb-list">
            <tr>
                <th>No</th>
                <th>Pickup Date</th>
                <th>Oil Quantity</th>
                <th>Sludge</th>
                <th>Driver</th>
                <th>Paid (Cash)</th>
            </tr>

<?=$strList?>

<!--
            <tr>
              <td>1</td>
              <td>2023-01-20</td>
              <td>350</td>
              <td>D.S</td>
              <td>Paid ($50)</td>
            </tr>

            <tr>
              <td>2</td>
              <td>2023-01-20</td>
              <td>350</td>
              <td>D.S</td>
              <td>Paid ($50)</td>
            </tr>

            <tr>
              <td>3</td>
              <td>2023-01-20</td>
              <td>350</td>
              <td>D.S</td>
              <td>Paid ($50)</td>
            </tr>

            <tr>
              <td>4</td>
              <td>2023-01-20</td>
              <td>350</td>
              <td>D.S</td>
              <td>Paid ($50)</td>
            </tr>

            <tr>
              <td>5</td>
              <td>2023-01-20</td>
              <td>350</td>
              <td>D.S</td>
              <td>Paid ($50)</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-->

					<?

					$page_string = "view=$view&d_customeruid=$d_customeruid&searchtype=$searchtype&searchDriver=$searchDriver&pageflag=note&key_word=$key_word&key_CTGSEQ=$key_CTGSEQ&column=$column&mode=$mode&switched=$getSWHStr";
					//$paging = new PAGE('page',$total_count,$list_count,$page_count,$page,$page_string,'#c71930','','','#c71930','');
					$paging = new PAGE('pageqna',$total_count,$list_count,$page_count,$pageqna,$page_string,'#c71930','','','#c71930','');
					?>
					
          </div>
        </div>        


        <div class="row text-center">
          <div class="col-sm-4 item-inner">
          <a class="btn-sub" href="/index_intranet.php?view=oilhistory_list&<?=$goStr?>">LIST</a>
         </div>
        </div>
<!--
        <div class="grid-layout-col-2">

          <div class="grid-col-2">
            <a class="btn-sub text-center" href="/index_intranet.php?view=oilhistory_list&<?=$goStr?>">LIST</a>
          </div>
          <div class="grid-col-2">
            <a class="btn-orange text-center" href="#">DOWNLOAD</a>
          </div>

    </div>
-->



      </div>

        

    </section>



</div><!--container Ends-->
    </section>

  </main><!-- End #main -->
