Viewing file: FormCostestimatesPDF.php (15.44 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
//PDF USING MULTIPLE PAGES
//FILE CREATED BY: Carlos José Vásquez Sáez
//YOU CAN CONTACT ME: carlos@magallaneslibre.com
//FROM PUNTA ARENAS, MAGALLANES
//INOVO GROUP - http://www.inovo.cl
/** Configuration */
require_once( "../configuration.php" );
require_once( $_Config_absolute_path . "/includes/connMySQL.class.php");
require('../fpdf/fpdf.php');
/** Config Table for This Page */
$myTable1 = "personal_tb";
$myTable2 = "formaoffice"; //
$myTable3 = "budget_year_tb";
$myTable4 ="form_costestimates" ;
$myTable2PK = "Cost_Id";
/** Create Database Object */
$dbObj = new DBConn;
$query = "SELECT * FROM formaoffice WHERE maNo = '".$_REQUEST["maNo"]."' and Teacher_code = '".$_REQUEST["Flag"]."' ";
$result5 = $dbObj->execQuery($query);
$rss5 = $dbObj->fetchArray($result5);
$query3 = "Select * From college Where collegeStatus ='1'";
$result3 = $dbObj->execQuery($query3);
$rs3 = $dbObj->fetchArray($result3);
$query6 = " SELECT * FROM personal_tb AS pe LEFT JOIN formaoffice AS fm ON pe.Teacher_code=fm.Teacher_code LEFT JOIN formaoffice AS fo ON fm.codeId=fo.codeId WHERE fm.maNo = '".$_REQUEST["maNo"]."' and fm.Flag = '".$_REQUEST["Flag"]."' ";
$result6 = $dbObj->execQuery($query6);
$num_rows = mysql_num_rows($result6);
$query10 = " SELECT * FROM personal_tb AS pe LEFT JOIN formaoffice AS fm ON pe.Teacher_code=fm.Teacher_code LEFT JOIN formaoffice AS fo ON fm.codeId=fo.codeId WHERE fm.maNo = '".$_REQUEST["maNo"]."' and fm.Flag = '".$_REQUEST["Flag"]."' ";
$result10 = $dbObj->execQuery($query10);
$num_rows10 = mysql_num_rows($result10);
$query11 = " SELECT * FROM personal_tb AS pe LEFT JOIN formaoffice AS fm ON pe.Teacher_code=fm.Teacher_code LEFT JOIN formaoffice AS fo ON fm.codeId=fo.codeId WHERE fm.maNo = '".$_REQUEST["maNo"]."' and fm.Flag = '".$_REQUEST["Flag"]."' ";
$result11 = $dbObj->execQuery($query11);
$num_rows11 = mysql_num_rows($result11);
function readNumber($number, $len) {
if($number=='0') { $number = ""; }
else if($number=='1') {
if($len==2) { $number = ""; }
else { $number = "˹Öè§"; }
}
else if($number=='2') {
if($len==2) { $number = "ÂÕè"; }
else { $number = "Êͧ"; }
}
else if($number=='3') { $number = "ÊÒÁ"; }
else if($number=='4') { $number = "ÊÕè"; }
else if($number=='5') { $number = "ËéÒ"; }
else if($number=='6') { $number = "Ë¡"; }
else if($number=='7') { $number = "à¨ç´"; }
else if($number=='8') { $number = "á»´"; }
else if($number=='9') { $number = "à¡éÒ"; }
return $number;
}
function readUnit($len) {
if($len=='1') { $len = ""; }
else if($len=='2') { $len = "ÊÔº"; }
else if($len=='3') { $len = "ÃéÍÂ"; }
else if($len=='4') { $len = "¾Ñ¹"; }
else if($len=='5') { $len = "ËÁ×è¹"; }
else if($len=='6') { $len = "áʹ"; }
else if($len=='7') { $len = "ÅéÒ¹"; }
return $len;
}
function convertNumberToString($amount) {
list($baht, $satang) = split('[.]', $amount);
while(strlen($satang) < 2)
$satang .= '0';
$str = "";
$len = strlen($baht);
$i = 0;
while($i <= strlen($baht)) {
if($len==1 && $baht[$i-1]!=0 && $baht[$i]==1)
$str .= "àÍç´";
else
$str .= readNumber($baht[$i], $len);
if($baht[$i] != 0)
$str .= readUnit($len);
$len--;
$i++;
}
if($str != "")
$str .= "ºÒ·";
$len = strlen($satang);
$i = 0;
while($i <= strlen($satang)) {
if($len==1 && $satang[$i-1]!=0 && $satang[$i]==1)
$str .= "àÍç´";
else
$str .= readNumber($satang[$i], $len);
if($satang[$i] != 0)
$str .= readUnit($len);
$len--;
$i++;
}
if($satang != '00')
$str .= "ʵҧ¤ì";
return $str;
}
//----------------------------------------
function getMonthTh($mm) {
if($mm=='01') { $mm='Á¡ÃÒ¤Á'; }
else if($mm=='02') { $mm='¡ØÁÀҾѹ¸ì'; }
else if($mm=='03') { $mm='ÁÕ¹Ò¤Á'; }
else if($mm=='04') { $mm='àÁÉÒ¹'; }
else if($mm=='05') { $mm='¾ÄÉÀÒ¤Á';}
else if($mm=='06') { $mm='ÁԶعÒ¹'; }
else if($mm=='07') { $mm='¡Ã¡®Ò¤Á'; }
else if($mm=='08') { $mm='ÊÔ§ËÒ¤Á'; }
else if($mm=='09') { $mm='¡Ñ¹ÂÒ¹'; }
else if($mm=='10') { $mm='µØÅÒ¤Á';}
else if($mm=='11') { $mm='¾ÄȨԡÒ¹';}
else if($mm=='12') { $mm='¸Ñ¹ÇÒ¤Á'; }
return "$mm";
}
function getShortMonthTh($mm) {
if($mm=='01') { $mm='Á.¤.'; }
else if($mm=='02') { $mm='¡.¾.'; }
else if($mm=='03') { $mm='ÁÕ.¤.'; }
else if($mm=='04') { $mm='àÁ.Â.'; }
else if($mm=='05') { $mm='¾.¤.';}
else if($mm=='06') { $mm='ÁÔ.Â.'; }
else if($mm=='07') { $mm='¡.¤.'; }
else if($mm=='08') { $mm='Ê.¤.'; }
else if($mm=='09') { $mm='¡.Â.'; }
else if($mm=='10') { $mm='µ.¤.';}
else if($mm=='11') { $mm='¾.Â.';}
else if($mm=='12') { $mm='¸.¤.'; }
return "$mm";
}
//Create new pdf file
$pdf = new FPDF('L' , 'mm' , 'A4');
//Set thai font
$pdf->SetThaiFont();
$pdf->AddPage();
//-- Load Form Image to Background
$pdf->Image('../form/FormCostestimates.jpg', 0, 0, 297, 210);
//-- Set Font
$pdf->SetFont('AngsanaNew','',15);
//-- ÊèǹÃÒª¡ÒÃ
$pdf->Text(110,30,$rs3['collegeName']);
//-- Set Font
$pdf->SetFont('AngsanaNew','',15);
//-- àºÔ¡¤èÒãªé¨èÒ¢ͧ - ª×èÍ ¹ÒÁÊ¡ØÅ ÍÒ¨ÒÃÂì
$Teacher_code = $Flag ;
$sql = "Select * From $myTable1 LEFT JOIN prefix ON $myTable1.First_name = prefix.prefixId Where Teacher_code ='$Teacher_code' ";
$result8 = mysql_query($sql) or die("Error".mysql_error());
$rs8 = mysql_fetch_array($result8);
$pdf->SetXY(100,33);
$pdf->Cell(73,5,$rs8['prefixName'].' '.$rs8['Teacher_name'].' '.$rs8['Teacher_lastname'].' áÅФ³Ð',0,0,'C');
// ŧÇѹ·Õè
$date = explode("-",$rss5['Date_start']);
$day = intval($date[2]);
$month = getMonthTh(intval($date[1]));
$year = intval($date[0]);
if(!empty($day)){
$pdf->SetXY(190.5,33);
$pdf->Cell(9,5,$day,0,0,'C');
$pdf->SetXY(210,33);
$pdf->Cell(23.5,5,$month,0,0,'C');
$pdf->SetXY(247,33);
$pdf->Cell(12,5,$year,0,0,'C');
}
else{
$pdf->SetXY(190.5,33);
$pdf->Cell(9,5,'-',0,0,'C');
$pdf->SetXY(210,33);
$pdf->Cell(23.5,5,'-',0,0,'C');
$pdf->SetXY(247,33);
$pdf->Cell(12,5,'-',0,0,'C');
}
$pdf->SetFont('AngsanaNew','',13);
//-- ¤ÍÅÑÁ¹ì ª×èÍ - ¹ÒÁÊ¡ØÅ
if($num_rows){
$i = 1;
while($data = $dbObj->fetchObject($result6)){
$query7 = "Select * From $myTable1 LEFT JOIN prefix ON $myTable1.First_name = prefix.prefixId Where Teacher_code='".$data->Teacher_code."' ";
$result7 = $dbObj->execQuery($query7);
$rs7 = $dbObj->fetchArray($result7);
switch($i){
case "1" : $pdf->Text(33,60.5,$rs7['prefixName'].' '.$rs7['Teacher_name'].' '.$rs7['Teacher_lastname']); break;
case "2" : $pdf->Text(33,67.5,$rs7['prefixName'].' '.$rs7['Teacher_name'].' '.$rs7['Teacher_lastname']); break;
case "3" : $pdf->Text(33,75.7,$rs7['prefixName'].' '.$rs7['Teacher_name'].' '.$rs7['Teacher_lastname']); break;
case "4" : $pdf->Text(33,83,$rs7['prefixName'].' '.$rs7['Teacher_name'].' '.$rs7['Teacher_lastname']); break;
case "5" : $pdf->Text(33,90,$rs7['prefixName'].' '.$rs7['Teacher_name'].' '.$rs7['Teacher_lastname']); break;
case "6" : $pdf->Text(33,96.5,$rs7['prefixName'].' '.$rs7['Teacher_name'].' '.$rs7['Teacher_lastname']); break;
case "7" : $pdf->Text(33,104,$rs7['prefixName'].' '.$rs7['Teacher_name'].' '.$rs7['Teacher_lastname']); break;
case "8" : $pdf->Text(33,111,$rs7['prefixName'].' '.$rs7['Teacher_name'].' '.$rs7['Teacher_lastname']); break;
case "9" : $pdf->Text(33,118,$rs7['prefixName'].' '.$rs7['Teacher_name'].' '.$rs7['Teacher_lastname']); break;
case "10" : $pdf->Text(33,125,$rs7['prefixName'].' '.$rs7['Teacher_name'].' '.$rs7['Teacher_lastname']); break;
case "11" : $pdf->Text(33,132.5,$rs7['prefixName'].' '.$rs7['Teacher_name'].' '.$rs7['Teacher_lastname']); break;
case "12" : $pdf->Text(33,139.3,$rs7['prefixName'].' '.$rs7['Teacher_name'].' '.$rs7['Teacher_lastname']); break;
}
$i++;
}
}
if($num_rows10){
$j = 1;
while($data1 = $dbObj->fetchObject($result10)){
$query9 = " Select * From personal_tb LEFT JOIN position_tb ON personal_tb.PositionId = position_tb.PositionId WHERE Teacher_code='".$data1->Teacher_code."' ";
$result9 = $dbObj->execQuery($query9);
$rs9 = $dbObj->fetchArray($result9);
switch($j){
case "1" : $pdf->Text(80,60.5,$rs9['Position_name']); break;
case "2" : $pdf->Text(80,67.5,$rs9['Position_name']); break;
case "3" : $pdf->Text(80,75.7,$rs9['Position_name']); break;
case "4" : $pdf->Text(80,83,$rs9['Position_name']); break;
case "5" : $pdf->Text(80,90,$rs9['Position_name']); break;
case "6" : $pdf->Text(80,96.5,$rs9['Position_name']); break;
case "7" : $pdf->Text(80,104,$rs9['Position_name']); break;
case "8" : $pdf->Text(80,111,$rs9['Position_name']); break;
case "9" : $pdf->Text(80,118,$rs9['Position_name']); break;
case "10" : $pdf->Text(80,125,$rs9['Position_name']); break;
case "11" : $pdf->Text(80,132.5,$rs9['Position_name']); break;
case "12" : $pdf->Text(80,139.3,$rs9['Position_name']); break;
}
$j++;
}
}
if($num_rows11){
$k = 1;
while($data2 = $dbObj->fetchObject($result11)){
$query12 = " SELECT * FROM form_costestimates fc LEFT JOIN formaoffice f ON fc.codeId=f.codeId WHERE fc.Teacher_code='".$data2->Teacher_code."' and f.maNo = '".$data2->maNo."' ";
$result12 = $dbObj->execQuery($query12);
$rs12 = $dbObj->fetchArray($result12);
$Total1 = $rs12['Smtotal']+$rs12['STtotal']+$rs12['Vehicletotal']+$rs12['Crgestotal'];
switch($k){
case "1" : $pdf->Text(132,60.5,number_format($rs12['Smtotal'],2,'.',',')); $pdf->Text(155,60.5,number_format($rs12['STtotal'],2,'.',',')); $pdf->Text(177,60.5,number_format($rs12['Vehicletotal'],2,'.',',')); $pdf->Text(200,60.5,number_format($rs12['Crgestotal'],2,'.',',')); $pdf->Text(224,60.5,number_format($Total1,2,'.',',')); break;
case "2" : $pdf->Text(132,67.5,number_format($rs12['Smtotal'],2,'.',',')); $pdf->Text(155,67.5,number_format($rs12['STtotal'],2,'.',',')); $pdf->Text(177,67.5,number_format($rs12['Vehicletotal'],2,'.',',')); $pdf->Text(200,67.5,number_format($rs12['Crgestotal'],2,'.',',')); $pdf->Text(224,67.5,number_format($Total1,2,'.',',')); break;
case "3" : $pdf->Text(132,75.7,number_format($rs12['Smtotal'],2,'.',',')); $pdf->Text(155,75.7,number_format($rs12['STtotal'],2,'.',',')); $pdf->Text(177,75.7,number_format($rs12['Vehicletotal'],2,'.',',')); $pdf->Text(200,75.7,number_format($rs12['Crgestotal'],2,'.',',')); $pdf->Text(224,75.7,number_format($Total1,2,'.',',')); break;
case "4" : $pdf->Text(132,83,number_format($rs12['Smtotal'],2,'.',',')); $pdf->Text(155,83,number_format($rs12['STtotal'],2,'.',',')); $pdf->Text(177,83,number_format($rs12['Vehicletotal'],2,'.',',')); $pdf->Text(200,83,number_format($rs12['Crgestotal'],2,'.',',')); $pdf->Text(224,83,number_format($Total1,2,'.',',')); break;
case "5" : $pdf->Text(132,90,number_format($rs12['Smtotal'],2,'.',',')); $pdf->Text(155,90,number_format($rs12['STtotal'],2,'.',',')); $pdf->Text(177,90,number_format($rs12['Vehicletotal'],2,'.',',')); $pdf->Text(200,90,number_format($rs12['Crgestotal'],2,'.',',')); $pdf->Text(224,90,number_format($Total1,2,'.',',')); break;
case "6" : $pdf->Text(132,96.5,number_format($rs12['Smtotal'],2,'.',',')); $pdf->Text(155,96.5,number_format($rs12['STtotal'],2,'.',',')); $pdf->Text(177,96.5,number_format($rs12['Vehicletotal'],2,'.',',')); $pdf->Text(200,96.5,number_format($rs12['Crgestotal'],2,'.',',')); $pdf->Text(224,96.5,number_format($Total1,2,'.',',')); break;
case "7" : $pdf->Text(132,104,number_format($rs12['Smtotal'],2,'.',',')); $pdf->Text(155,104,number_format($rs12['STtotal'],2,'.',',')); $pdf->Text(177,104,number_format($rs12['Vehicletotal'],2,'.',',')); $pdf->Text(200,104,number_format($rs12['Crgestotal'],2,'.',',')); $pdf->Text(224,104,number_format($Total1,2,'.',',')); break;
case "8" : $pdf->Text(132,111,number_format($rs12['Smtotal'],2,'.',',')); $pdf->Text(155,111,number_format($rs12['STtotal'],2,'.',',')); $pdf->Text(177,111,number_format($rs12['Vehicletotal'],2,'.',',')); $pdf->Text(200,111,number_format($rs12['Crgestotal'],2,'.',',')); $pdf->Text(224,111,number_format($Total1,2,'.',',')); break;
case "9" : $pdf->Text(132,118,number_format($rs12['Smtotal'],2,'.',',')); $pdf->Text(155,118,number_format($rs12['STtotal'],2,'.',',')); $pdf->Text(177,118,number_format($rs12['Vehicletotal'],2,'.',',')); $pdf->Text(200,118,number_format($rs12['Crgestotal'],2,'.',',')); $pdf->Text(224,118,number_format($Total1,2,'.',',')); break;
case "10" : $pdf->Text(132,125,number_format($rs12['Smtotal'],2,'.',',')); $pdf->Text(155,125,number_format($rs12['STtotal'],2,'.',',')); $pdf->Text(177,125,number_format($rs12['Vehicletotal'],2,'.',',')); $pdf->Text(200,125,number_format($rs12['Crgestotal'],2,'.',',')); $pdf->Text(224,125,number_format($Total1,2,'.',',')); break;
case "11" : $pdf->Text(132,132.5,number_format($rs12['Smtotal'],2,'.',',')); $pdf->Text(155,132.5,number_format($rs12['STtotal'],2,'.',',')); $pdf->Text(177,132.5,number_format($rs12['Vehicletotal'],2,'.',',')); $pdf->Text(200,132.5,number_format($rs12['Crgestotal'],2,'.',',')); $pdf->Text(224,132.5,number_format($Total1,2,'.',',')); break;
case "12" : $pdf->Text(132,139.3,number_format($rs12['Smtotal'],2,'.',',')); $pdf->Text(155,139.3,number_format($rs12['STtotal'],2,'.',',')); $pdf->Text(177,139.3,number_format($rs12['Vehicletotal'],2,'.',',')); $pdf->Text(200,139.3,number_format($rs12['Crgestotal'],2,'.',',')); $pdf->Text(224,139.3,number_format($Total1,2,'.',',')); break;
}
$k++;
}
}
//-- ¤èÒàºÕéÂàÅÕé§
$sql1 = " SELECT SUM(fc.Smtotal) AS SumB1 FROM form_costestimates AS fc LEFT JOIN formaoffice AS f ON fc.codeId=f.codeId WHERE Flag='$Flag' and maNo='$maNo' ";
$result1 = mysql_query($sql1);
$rss1 = mysql_fetch_array($result1);
if(!empty($rss1['SumB1'])){
$pdf->SetXY(113.5,142.5);
$pdf->Cell(45,5,number_format($rss1['SumB1'], 2, '.', ','),0,0,'C');
}
else{
$pdf->SetXY(113.5,142.5);
$pdf->Cell(45,5,'-',0,0,'C');
}
//-- ¤èÒ·Õè¾Ñ¡
$sql2 = " SELECT SUM(fc.STtotal) AS SumB2 FROM form_costestimates AS fc LEFT JOIN formaoffice AS f ON fc.codeId=f.codeId WHERE Flag='$Flag' and maNo='$maNo' ";
$result2 = mysql_query($sql2);
$rss2 = mysql_fetch_array($result2);
if(!empty($rss2['SumB2'])){
$pdf->SetXY(137,142.5);
$pdf->Cell(45,5,number_format($rss2['SumB2'], 2, '.', ','),0,0,'C');
}
else{
$pdf->SetXY(137,142.5);
$pdf->Cell(45,5,'-',0,0,'C');
}
//-- ¤èÒ¾Ò˹Ð
$sql3 = " SELECT SUM(fc.Vehicletotal) AS SumB3 FROM form_costestimates AS fc LEFT JOIN formaoffice AS f ON fc.codeId=f.codeId WHERE Flag='$Flag' and maNo='$maNo' ";
$result3 = mysql_query($sql3);
$rss3 = mysql_fetch_array($result3);
if(!empty($rss3['SumB3'])){
$pdf->SetXY(157,142.5);
$pdf->Cell(45,5,number_format($rss3['SumB3'], 2, '.', ','),0,0,'C');
}
else{
$pdf->SetXY(157,142.5);
$pdf->Cell(45,5,'-',0,0,'C');
}
//-- ¤èÒÍ×è¹æ
$sql4 = " SELECT SUM(fc.Crgestotal) AS SumB4 FROM form_costestimates AS fc LEFT JOIN formaoffice AS f ON fc.codeId=f.codeId WHERE Flag='$Flag' and maNo='$maNo' ";
$result4 = mysql_query($sql4);
$rss4 = mysql_fetch_array($result4);
if(!empty($rss4['SumB4'])){
$pdf->SetXY(182,142.5);
$pdf->Cell(45,5,number_format($rss4['SumB4'], 2, '.', ','),0,0,'C');
}
else{
$pdf->SetXY(182,142.5);
$pdf->Cell(45,5,'-',0,0,'C');
}
// ¨Ó¹Ç¹à§Ô¹ÃÇÁ
$Total2 = $rss1['SumB1']+$rss2['SumB2']+$rss3['SumB3']+$rss4['SumB4'];
$pdf->Text(222.5,146.5,number_format($Total2 ,2,'.',','));
// ¨Ó¹Ç¹à§Ô¹ (µÑÇÍÑ¡ÉÃ)
$SumB5 = convertNumberToString($Total2);
$pdf->Text(100,158,$SumB5."¶éǹ" );
//Create file
$pdf->Output();
?>
|