|
|
|
สอบถามเรื่องการขึ้นหน้า page ใหม่ ของ mpdf โดยให้คิดจาก ค่า numrows ถ้าเกินจากที่กำหนดไว้ให้ขึ้นหน้าใหม่ |
|
|
|
|
|
|
|
Code (PHP)
<?
session_start();
include"Connect.php";
if($_SESSION["u_id"] == NULL)
echo "<meta http-equiv='Refresh' content='0; URL=../index.php'>";
$user_id=$_SESSION["u_id"] ;
include("mpdf60/mpdf.php");
ob_start();
ini_set('memory_limit', '-1');
set_time_limit(0);
$d=date("d");
$my=date("d-m-Y");
?>
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body,td,th { font-size:10px; }
</style>
<link href="css/web.css" rel="stylesheet" type="text/css">
</head>
<?
include "Connect.php";
$_month_name = array("01"=>"Jan", "02"=>"Feb", "03"=>"Mar",
"04"=>"Apr", "05"=>"May", "06"=>"June",
"07"=>"July", "08"=>"Aug", "09"=>"Sep",
"10"=>"Oct", "11"=>"Nov", "12"=>"Dec");
//$month=$_month_name[$_POST['month']];
$YM=$_POST['YM'];
$Emp_id=$_POST['Emp_id'];
if($Emp_id != ''){
$Emp_id=$_POST['Emp_id'] ;
}
else{
$Emp_id=$_SESSION["u_id"];
}
$SMY=$_POST['SMY'];
$print_status=$_POST['print_status'];
if($_POST['faredetail_id'] == ""){
$pdf = "no";
}
else{
$pdf = "";
}
$pre = array(); $rq=$_REQUEST;
foreach($rq['faredetail_id'] as $key=>$value){
// ตรวจสอบข้อมูลและแปลงค่า request ในรูปแบบที่ปลอดภัยจาก sql injection
$pre['id'][$key]=($id=intval($value)); // ตัวอย่างคิดว่า id เป็นตัวเลข ถ้าไม่ใช้ก็เปลี่ยนให้ถูกเองนะครับ
$pre['dte'][$key]=($dte=($rq['service_date'][$key]));
$pre['status'][$key]=($status=mysql_real_escape_string($rq['order_status'][$key]));
$pre['amount'][$key]=floatval($rq['sum_amount'][$key]);
$where = "service_date ='$dte' AND user = '$Emp_id' and faredetail_id ='$id' and print_status='y' ";
$resulta = mysql_query($sql='SELECT 1 as a FROM fare_detail WHERE '.$where . ' limit 1')
or die( mysql_error() . "<br>$sql");
if ( mysql_num_rows($resulta) ) { $pre=false; break; } // จบการค้นหา เมื่อเจอข้อมูลซ้ำ และ เซทค่า $pre=false
}
if($pre===false){
$wait_sec = 1;
exit('<!doctype html><html>
<head><meta http-equiv="refresh" content="'.$wait_sec.';url=fare1.php" /></head>
<body><font size="30" class="hint"><div align="center">Duplicate Data</div></font></body></html>'
);
}
foreach($pre['id'] as $key=>$value){
$pre['id'][$key];
$id=$pre['id'][$key];
$dte=$pre['dte'][$key];
$status=$pre['status'][$key];
$amount=$pre['amount'][$key];
$where = "service_date ='$dte' AND user = '$Emp_id' and faredetail_id ='$id' ";
mysql_query($sql="update fare_detail set print_status ='y' where $where") or die( mysql_error() . "<br>$sql");
$resulta = mysql_query("SELECT * FROM fare WHERE fare_date ='$my' AND fare_user = '$Emp_id' and fare_type ='fare'");
while($rowa = mysql_fetch_array($resulta))
{
$rule = $rowa['fare_date'];
}
if ($rule == "$my")
{
//notadd
}
else {
mysql_query("INSERT INTO fare (fare_date,fare_user,fare_status,user_approve,print_status,fare_type) VALUES ('$my','$Emp_id','approve','".$Emp_id."_Fare_$my.pdf','y','fare')");
//add it
}
}
?>
<div align="center" style="font-weight:bold;font-size:12px"><?=$SMY?>
<?
if($Emp_id != ''){
echo $Emp_id=$_POST['Emp_id'] ;
}
else{
echo $Emp_id=$_SESSION["u_id"];
}?>
</div>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#000000">
<tr bgcolor="#000000">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr bgcolor="#D6D6D6">
<th width="120">Order No</th>
<th width="120">Project No</th>
<th width="40">Task</th>
<th width="40">Seq</th>
<th width="60">Cost Code</th>
<th width="70">Date(Y-M-D)</th>
<th width="200">Description</th>
<th width="100">From</th>
<th width="100">To</th>
<th width="40">Go</th>
<th width="40">Back</th>
<th width="50">Sum Km</th>
<th width="70">Express</th>
<th width="50">CarPark</th>
<th width="50">Amount</th>
<th width="60">Fare Type</th>
</tr>
<?
foreach($_REQUEST['customer_name'] as $key=>$value){
$customer_name=$_REQUEST['customer_name'][$key];
$sql1="SELECT customer_name FROM customer ";
$sql1.="INNER JOIN fare_detail ";
$sql1.="ON fare_detail.customer = customer.customer_name ";
$sql1.="WHERE fare_detail.user ='$Emp_id' ";
$sql1.="AND fare_detail.service_date like '%".$YM."%' and fare_detail.customer = '".$customer_name."' ";
//$sql1.="AND fare_detail.faredetail_id = '".$faredetail_id."' ";
$sql1.="or fare_detail.user = '$Emp_id' and fare_detail.service_date < '".$YM."' and fare_detail.customer =
'".$customer_name."' ";
$sql1.="GROUP BY customer.customer_name ";
$query1 = mysql_query($sql1);
while($data1 = mysql_fetch_array($query1)){
$sum_km_go=0;
$sum_km_back=0;
$sum_km_sum=0;
$sum_group1=0;
$sum_group2=0;
$sum_fare_other=0;
?>
<tr bgcolor="#FFFFFF">
<td align="center" style="font-weight:bold"><?=$data1['customer_name']?></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<?
foreach($_REQUEST['faredetail_id'] as $key=>$value){
$faredetail_id=$_REQUEST['faredetail_id'][$key];
$service_date=$_REQUEST['service_date'][$key];
$order_status=$_REQUEST['order_status'][$key];
$sum_amount=$_REQUEST['sum_amount'][$key];
$sql = "SELECT * FROM fare_detail ";
$sql.= "WHERE user = '$Emp_id' ";
$sql.= "AND customer = '".$data1['customer_name']."' ";
$sql.= "AND service_date LIKE '%".$service_date."%' ";
$sql.="AND faredetail_id = '".$faredetail_id."' ";
// $sql.="or user = '$Emp_id' and print_status = 'y' AND customer = '".$data1['customer_name']."' and order_status = 'approve' and service_date < '$YM' ";
$sql.= "ORDER BY project_code ASC, service_date ASC "; // Sort by customer and date
$query = mysql_query($sql);?>
$row_cur+=mysql_num_rows($query); // query Row จาก Database
<? while($data = mysql_fetch_array($query)){
if($data['order_status'] != 'wait_approve'){
// $dataname=$data['f_other'];
// if($dataname =="expressway"){
// $dataname="ทางด่วน";
// }else if($dataname=="parkcar"){
// $dataname="ค่าที่จอดรถ";
// }
// else{
// if($data['f_other_price']=="-"){
// $dataname="-";
// $data['f_other_price']="";
// }
// }
?>
<tr align="center" bgcolor="#ffffff">
<td align="center"><?=$data['order_no']?></td>
<td align="center"><?=$data['project_code']?></td>
<td align="center"><?=$data['task']?></td>
<td align="center"><?=$data['seq']?></td>
<td align="center"><?=$data['cost_code']?></td>
<td align="center"><?=$data['service_date']?></td>
<td align="center"><?=$data['f_actiontaken']?></td>
<td align="center"><?=$data['f_from']?></td>
<td align="center"><?=$data['f_to']?></td>
<td align="center"><?=$data['f_amout1']?></td>
<td align="center"><?=$data['f_amout2']?></td>
<td align="center"><?=$data['sum_km']?></td>
<td align="center"><?=$data['f_expressway_price']?></td>
<td align="center"><?=$data['f_parkcar_price']?></td>
<td align="center"><?=number_format($data['sum_amount']+$data['f_expressway_price']+$data['f_parkcar_price'])?></td>
<td align="center"><?=$data['fare_type']?></td>
</tr>
<?
if($data['fare_type']=="Oil"){
$sum_km_go+=$data['f_amout1']; //รวมกี่โลไปแต่ละแถว
$sum_km_back+=$data['f_amout2']; //รวมกิโลกลับแต่ละแถว
$sum_km_sum+=$data['f_amout1']+$data['f_amout2']; //รวมกิโลไป-กลับแต่ละแถว
}
$sum_group1+=$data['sum_km']; //รวมกิโลทั้งหมดแต่ละ customer
if($sum_group1=='0'){
$sum_group1=" ";
}
$sum_group2+=$data['sum_amount']+$data['f_expressway_price']+$data['f_parkcar_price']; //รวมจำนวนเงินทั้งหมดแต่ละ customer
}}
}
}///////////////////////////////////////// fare_other //////////////////////////////////////////////
// $sql2 = "SELECT * FROM fare_other ";
// $sql2.= "WHERE fare_user = '$Emp_id' AND fare_cus = '".$data1['customer_name']."' ";
// $sql2.= "AND fare_month LIKE '%".$YM."%' ";
// $sql2.= "ORDER BY fare_project_code ASC "; // Sort by Project_code
// $query2 = mysql_query($sql2);
// while($data2 = mysql_fetch_array($query2)){
?>
<tr align="center" bgcolor="#FFFFFF">
<td></td>
<td align="center"> </td>
<td></td>
<td></td>
<td></td>
<td></td>
<td align="center"><?=$data2['fare_des']?></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"><?=$data2['fare_price']?></td>
<td></td>
</tr>
<?
$sum_fare_other+=$data2['fare_price'];
//}
?>
<tr bgcolor="#EEEEEE" style="color:blue">
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center">Sum</td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"><?=$sum_group1?></td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"><?=number_format($sum_group2+$sum_fare_other)?></td> <!-- Sum ค่าเดินทางกับค่าน้ำมัน แต่ละ Customer -->
<td> </td>
</tr>
<tr bgcolor="#FFFFFF" style="color:blue">
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<!-- Sum ค่าเดินทางกับค่าน้ำมัน แต่ละ Customer -->
<td> </td>
</tr>
<?
//$total_km_go+=$sum_km_go;
//$total_km_back+=$sum_km_back;
$total_other+=$sum_fare_other;
$total_km_sum+=$sum_group1;
$total_amount_sum+=$sum_group2;
}?>
<tr bgcolor="#ffffff" style="font-weight:bold;color:blue">
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center">Total</td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"><?=number_format($total_amount_sum+=$total_other)?></td>
<td align="center"></td>
</tr>
</table>
</td>
</tr>
</table>
</html>
<?
if($pdf != 'no'){
$html = ob_get_contents();
ob_end_clean();
$output_dir = './fare/'.$Emp_id.'/';
if (!file_exists($output_dir)) {
mkdir($output_dir, 0777, true);
}
$mpdf=new mPDF('th', 'A4-L', '0', 'Garuda');
$mpdf->WriteHTML($html);
$mpdf->Output($Emp_id.'_Fare_'.$my.'.pdf','I');
$mpdf->Output($output_dir.$Emp_id.'_Fare_'.$my.'.pdf','F');
}else{
?><script>
alert("No Data")
window.close();
</script>
<? }
exit;
?>
ผมอยากจะให้ MPDF มันขึ้นหน้าใหม่ เมื่อ ROW ของข้อมูลที่เราดึงขึ้นมา เกิน 30 ขึ้นไปจะให้ไปต่อหน้า2อะครับเพราะจากที่ผมลองปริ้นออกมาดูมันรับ data ต่อ1 หน้ามันได้แค่ 30 แถว ฉะนั้น ถ้่า มันเกินผมจะให้มันขึ้น page ใหม่ไม่ทราบว่าจะต้องเขียนแบบไหนผมลอง ADDPAGE ไปแล้วแต่มันก้ขึ้นมาแค่หน้าว่างๆ รบกวนช่วยชี้แนะทีครับ
Tag : PHP, MySQL, HTML/CSS, jQuery
|
ประวัติการแก้ไข 2015-10-02 09:59:41
|
|
|
|
|
Date :
2015-10-01 22:20:44 |
By :
wahahaboy |
View :
1638 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ใช้หลักการเดียวกับ Pagination ครับ ลอง Apply จากบทความนี้ครับ
PHP MySQL List Record Paging/Pagination
|
|
|
|
|
Date :
2015-10-02 09:53:20 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มันจะ gen ออกมาเป็น pdf นะครับใช้ Pagination ช่วยยังไงครับยังงงๆ
|
|
|
|
|
Date :
2015-10-02 10:00:30 |
By :
wahahaboy |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองหลายทางแล้ว page pdf มันไม่ยอม run ไปหน้าสองมันพยายาม บีบ ขนาด font ให้เล็กลงเรื่อยๆในหน้าเดิม
|
|
|
|
|
Date :
2015-10-03 22:00:56 |
By :
wahahaboy |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|