参考了BOSS的代码和网络资料,效果如图:
<?php
/**
* Require Core File
*/
require_once("../../common/initialize.php");
require_once("../../common/fpdf/chinese-unicode.php");
/**
* Check Authority
*/
CheckAuthLevel(0, $WEB_ROOT."admin/blank.php");
$invoice_id = $_SESSION['record1'];
//print_r($invoice_id);
$record=array();
for($i=0;$i<count($invoice_id);$i++){
$query=RunQUERY("select * from `invoice` where `id`='".$invoice_id[$i]."'");
array_push($record,mysql_fetch_assoc($query));
mysql_free_result($query);
}
/*print_r($record);
foreach($record as $k=>$v){
echo $v['applicant'].'<br>';
}
*/
class InvoicePDF extends PDF_Chinese
{
function BasicTable($x,$y,$invoice){
global $_DEPARTMENT;
$w = 18;
$h = 7;
//print_r($invoice);
//$this->SetX($x);
$this->SetXY($x,$y);
$this->SetFont("Gb", "B", 12);
$this->Cell($w*6, $h*1.5, iconv("UTF-8", "GB2312//TRANSLIT", "ECTHK_付款申请单"), 0, 1, "C");
$this->SetX($x);
$this->SetFont("Gb", "", 8);
$this->Cell($w*5, $h*0.8, iconv("UTF-8", "GB2312//TRANSLIT", "编号:"), 0, 0, "R");
$this->Cell($w, $h*0.8, iconv("UTF-8", "GB2312//TRANSLIT", $invoice['invoice_no']), 0, 1, "L");
$this->SetX($x);
$this->Cell($w, $h, iconv("UTF-8", "GB2312//TRANSLIT", "申请部门"), 1, 0, "C");
for ($i = 0; $i < sizeof($_DEPARTMENT); $i++){
if ($invoice['department'] == $i){
$department = $_DEPARTMENT[$i];
}
}
$this->Cell($w, $h, iconv("UTF-8", "GB2312//TRANSLIT", $department), 1, 0, "C");
$this->Cell($w, $h, iconv("UTF-8", "GB2312//TRANSLIT", "申请人"), 1, 0, "C");
$this->Cell($w, $h, iconv("UTF-8", "GB2312//TRANSLIT", $invoice['applicant']), 1, 0, "C");
$this->Cell($w, $h, iconv("UTF-8", "GB2312//TRANSLIT", "申请日期"), 1, 0, "C");
$this->Cell($w, $h, iconv("UTF-8", "GB2312//TRANSLIT", date("j-n-Y", $invoice['app_date'])), 1, 1, "C");
$this->SetX($x);
$this->Cell($w, $h*1.5, iconv("UTF-8", "GB2312//TRANSLIT", "付款事由"), 1, 0, "C");
//$this->SetFont("Gb", "", 6);
$this->Cell($w*5, $h*1.5, iconv("UTF-8", "GB2312//TRANSLIT", stripslashes($invoice['subject'])),1,1,"L");
$this->SetFont("Gb", "", 8);
$this->SetX($x);
$this->Cell($w, $h, iconv("UTF-8", "GB2312//TRANSLIT", "收款单位"), 1, 0, "C");
$company_query = RunQuery("select `id`,`company` from `customer` where `id`='".$invoice['receive']."'");
$company=mysql_fetch_assoc($company_query);
$this->Cell($w*5, $h, iconv("UTF-8", "GB2312//TRANSLIT", $company['company']), 1, 1, "L");
$this->SetX($x);
$this->Cell($w, $h, iconv("UTF-8", "GB2312//TRANSLIT", "付款方式"), 1, 0, "C");
$payment_query = RunQuery("select `id`,`name` from `payment` where `id`='".$invoice['payment']."'");
$payment=mysql_fetch_assoc($payment_query);
$this->Cell($w*5, $h, iconv("UTF-8", "GB2312//TRANSLIT", stripslashes($payment['name'])), 1, 1, "L");
$this->SetX($x);
$this->Cell($w, $h, iconv("UTF-8", "GB2312//TRANSLIT", "付款币别"), 1, 0, "C");
$exchange_query = RunQuery("select * from `exchange` where `id`='".$invoice['currency']."'");
$exchange=mysql_fetch_assoc($exchange_query);
$this->Cell($w, $h, iconv("UTF-8", "GB2312//TRANSLIT", $exchange['currency']), 1, 0, "C");
$this->Cell($w, $h, iconv("UTF-8", "GB2312//TRANSLIT", "付款金额"), 1, 0, "C");
switch($invoice['currency']){
case '1':
$price=$invoice['price_rmb'];
break;
case '2':
$price=$invoice['price_hk'];
break;
case '3':
$price=$invoice['price_usd'];
break;
case '4':
$price=$invoice['price_twd'];
break;
}
$this->Cell($w, $h, iconv("UTF-8", "GB2312//TRANSLIT", number_format($price,2)), 1, 0, "C");
$this->Cell($w, $h, iconv("UTF-8", "GB2312//TRANSLIT", "应付款日期"), 1, 0, "C");
$this->Cell($w, $h, iconv("UTF-8", "GB2312//TRANSLIT", date("j-n-Y", $invoice['pay_date'])), 1, 1, "C");
$this->SetX($x);
$this->Cell($w, $h, iconv("UTF-8", "GB2312//TRANSLIT", "大写金额"), 1, 0, "C");
$big_price= toCNcap($price);
$this->Cell($w*5, $h, iconv("UTF-8", "GB2312//TRANSLIT", $big_price), 1, 1, "L");
$this->SetX($x);
$this->Cell($w, $h, iconv("UTF-8", "GB2312//TRANSLIT", "备注"), 1, 0, "C");
$this->Cell($w*5, $h, iconv("UTF-8", "GB2312//TRANSLIT", stripslashes($invoice['remark'])), 1, 1, "L");
$this->SetX($x);
$this->Cell($w, $h, iconv("UTF-8", "GB2312//TRANSLIT", "付款日期"), 1, 0, "C");
$this->Cell($w*2, $h, iconv("UTF-8", "GB2312//TRANSLIT", date("j-n-Y", $invoice['payed_date'])), 1, 0, "C");
$this->Cell($w, $h, iconv("UTF-8", "GB2312//TRANSLIT", "报销日期"), 1, 0, "C");
$this->Cell($w*2, $h, iconv("UTF-8", "GB2312//TRANSLIT", date("j-n-Y", $invoice['reim_date'])), 1, 1, "C");
$this->SetX($x);
$this->Cell($w, $h, iconv("UTF-8", "GB2312//TRANSLIT", "会计:"), 0, 0, "R");
$this->Cell($w, $h,'', 0, 0, "C");
$this->Cell($w, $h, iconv("UTF-8", "GB2312//TRANSLIT", "出纳:"), 0, 0, "R");
$this->Cell($w, $h, '', 0, 0, "C");
$this->Cell($w, $h, iconv("UTF-8", "GB2312//TRANSLIT", "部门主管:"), 0, 0, "R");
$this->Cell($w, $h, '', 0, 1, "C");
}
}
$pdf = new InvoicePDF('L','mm','A4');
$pdf->AddGbFont();
//$pdf->AddGBFont();
for($i=0;$i<count($record);$i++){
if($i%4==0){
$pdf->AddPage();
$pdf->BasicTable(25,10,$record[$i]);
}elseif($i%4==1){
$pdf->BasicTable(165,10,$record[$i]);
}elseif($i%4==2){
$pdf->BasicTable(25,105,$record[$i]);
}elseif($i%4==3){
$pdf->BasicTable(165,105,$record[$i]);
}
}
$pdf->Output(date('YmdHis',time()).".pdf", "D");
?>