Home about IT Motivation Course Sales Project About Me

Monday, March 09, 2009

PHP: print button to print report use FPDF on the MySQL database

below script for function print:

function print1()
{
var docForm = document.form1;
var po_no = docForm.po_no.value;
if (po_no == "")
{
alert ("You Must Select PO No !");
return false
}
else
{
if(confirm("Preview ?")) {
window.open("pr_pdf.php?po_no="+po_no,"",
"height=710,width=1020,menubar=no,scrollbars=no,status=no,toolbar=no,top=0,left=0");
}
}
}

below script at the FPDF:

<?php
require_once('fpdf.php');
require_once('koneksi.php');
$pdf=new FPDF();
$pdf->AddPage();
$pdf->setFont('Helvetica','',10);

$exe1=mysql_query("select * from t_po , t_msup where po_sup = msup_abrv and po_no = '$po_no'");
$data1=mysql_fetch_array($exe1);
$pdf->Text(20, 32, $data1['msup_name']);
$pdf->Text(20, 36, $data1['msup_adrs1']);
$pdf->Text(20, 40, $data1['msup_adrs2']);
$pdf->Text(20, 44, $data1['msup_adrs3']);
$pdf->Text(20, 48, "telp:");
$pdf->Text(30, 48, $data1['msup_telp']);
$pdf->Text(20, 52, "fax:");
$pdf->Text(30, 52, $data1['msup_fax']);
$pdf->Text(160, 28, date("d-M-Y"));

$pdf->SetXY(20,80);
$exe=mysql_query("select po_item,po_qty,po_oum,po_cur,po_purprc,(po_qty*po_purprc)amount,po_no,po_desc from t_po where po_no = '$po_no' and po_dsc = '0'");

$i=1;
while ($data=mysql_fetch_array($exe)){

$pdf->setFont('Helvetica','',10);
$pdf->SetleftMargin(15);
$pdf->ln(0);
$pdf->Cell(9, 4, $i, 0, 0, 'L');
$pdf->Cell(78, 4, $data['po_item'], 0, 0, 'L');
$pdf->Cell(8, 4, $data['po_qty'], 0, 0, 'R');
$pdf->Cell(10, 4, $data['po_oum'], 0, 0, 'L');
$pdf->Cell(12, 4, $data['po_cur'], 0, 0, 'R');
$pdf->Cell(25, 4, number_format($data['po_purprc'],2,".",","), 0, 0, 'R');
$pdf->Cell(10, 4, $data['po_cur'], 0, 0, 'R');
$pdf->Cell(30, 4, number_format($data['amount'],2,".",","), 0, 0, 'R');

$pdf->Ln();
$pdf->Cell(9, 4,' ', 0, 0, 'L');
$pdf->Cell(70, 4, $data['po_desc'], 0, 0, 'L');
$pdf->Ln(6);
$i+=1;
$pdf->setFont('Helvetica','',12);
$pdf->Text(147,15,$data['po_no']);
}
$pdf->setFont('Helvetica','',10);
$pdf->Text(25, 235, "$NoteL");
$pdf->Text(117, 235, "$NoteR");
$pdf->Text(77, 283, "Mr. R");
$pdf->Text(107, 283, "Mr. Y");
$pdf->Text(156, 283, "Mr. H");
$pdf->setFont('Helvetica','B',10);

$pdf->SetleftMargin(25);
$exe3=mysql_query("SELECT * FROM t_po WHERE po_no = '$po_no' and po_dsc = '1'");
$data3=mysql_fetch_array($exe3);
$pdf->Cell(16, 6, $data3['po_item'], 0, 0, 'L');
$pdf->Cell(126, 6, $data3['po_cur'], 0, 0, 'R');
$pdf->Cell(30, 6, $data3['po_amt'], 0, 0, 'R');
$pdf->setFont('Helvetica','B',10);
$pdf->SetleftMargin(45);
$pdf->ln();
$pdf->Cell(150, 0, '', 1, 0, 'C');
$pdf->ln();
$pdf->Cell(50, 5, 'T O T A L A M O U N T', 0, 0, 'L');
$pdf->ln();

$exe2=mysql_query("SELECT sum(po_amt) FROM t_po WHERE po_no = '$po_no'");
$data2=mysql_fetch_array($exe2);
$pdf->Cell(152, -5,number_format($data2['sum(po_amt)'],2,".",","), 0, 0, 'R');
$pdf->Output();
?>

Please cek :
  • PHP 4 and PHP 5 different on decimal script. PHP5 need to writedown the format as below : $pdf->Cell(30, 4, number_format($data['amount'],2,".",","), 0, 0, 'R');

No comments: