我试图尽可能地减少代码。代码中最重要的部分是第二个块。我只需要两种方案来解决不同的账单问题。这些是在shippercarrierdata,shippercarrierdata1中硬编码的。这些创建pdfs很好。问题是当有多个客户需要它来创建一个新的pdf以及该客户的所有订单列表时,为预付费客户创建默认地址。我正在使用TCPDF。任何帮助,将不胜感激。
<?php
//
include('inc/connections.php');
$pickUpDate = $_REQUEST['pickUpDate'];
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');
// Extend the TCPDF class to create custom Header and Footer
class ManafestPrint extends TCPDF {
//Page header
public function Header()
{
global $pickUpDate;
// Set font
$this->SetFont('helvetica', 'B', 20);
// Title
$titleHTML = '
<table width="100%" border="0" style="font-weight: bold; font-size: 9pt;">
<tr>
<td width="25%" align="left">PICK UP DATE: '.$pickUpDate.'</td>
<td width="50%" align="center" style="font-size: 16pt;">SHIPPING MANIFEST</td>
<td width="25%" align="right">Page '.$this->getPageNumGroupAlias().' of '.$this->getPageGroupAlias().'</td>
</tr>
</table>
';
$this->writeHTMLCell(280, 25, 7, 5, $titleHTML);
}
}
$orders = explode(',', $_REQUEST['orders']);
$infinity = '';
$i = 0;
foreach($orders as $order) {
$sql = "
SELECT
oeordhdr_sql.ship_via_cd AS shipper,
oeordlin_sql.ord_no AS ordnum,
oeordhdr_sql.frt_pay_cd AS thirdparty,
oeordhdr_sql.cus_no AS customer
FROM oeordhdr_sql JOIN oeordlin_sql ON oeordhdr_sql.ord_no = oeordlin_sql.ord_no
WHERE
oeordhdr_sql.ord_no = oeordlin_sql.ord_no
AND oeordlin_sql.loc IN ('PMD','OM1')
AND oeordhdr_sql.shipping_dt>=getdate()-21
AND oeordlin_sql.ord_no = ' $order'
ORDER BY oeordlin_sql.ord_no ASC
";
$query = odbc_exec($connect, $sql);
$row = odbc_fetch_array($query);
if (($row['customer']) == '0000' && ($row['thirdparty']) == 'C' && ($row['shipper']) == 'EST') {
$tablerows= "<tr><td>'.$row['customer'].'</td><td>'.$row['customer'].'</td><td>'.$row['ord_num'].'</td><td>'.$row['item_no'].'</td><td>'.$row['shipper'].'</td><td>'.$row['thirdpart'].'</td></tr>";
}elseif (($row['customer']) == '0001' && ($row['thirdparty']) == 'C' && ($row['shipper']) == 'EST') {
$tablerows1 = "<tr><td>'.$row['customer'].'</td><td>'.$row['customer'].'</td><td>'.$row['ord_num'].'</td><td>'.$row['item_no'].'</td><td>'.$row['shipper'].'</td><td>'.$row['thirdpart'].'</td></tr>";
}else{
$tablerows2 = "<tr><td>'.$row['customer'].'</td><td>'.$row['customer'].'</td><td>'.$row['ord_num'].'</td><td>'.$row['item_no'].'</td><td>'.$row['shipper'].'</td><td>'.$row['thirdpart'].'</td></tr>";
}
}
$tableData = '
<style>
table#manifestTable tr.odd td{
background-color: #F0F0F0;
}
div.totalDIV{
vertical-align: bottom;
font-weight: bold;
}
</style>
<table id="manifestTable" width="100%" cellpadding="0" cellspacing="0" border="0" style="font-size: 8pt;">
<thead>
<tr style="font-weight: bold; text-decoration: underline;">
<th align="center" style="width: 40px;">REF#</th>
<th align="center" style="width: 75px;">PO#</th>
<th align="center" style="width: 75px;">PRO#</th>
<th align="left" style="width: 125px;">CONSIGNEE ADDRESS</th>
<th align="center" style="width: 125px;">SPECIAL INST</th>
<th align="center" style="width: 100px;">COMMODITY</th>
<th align="center" style="width: 40px;">NMFC#</th>
<th align="center" style="width: 30px;">SUB</th>
<th align="center" style="width: 40px;">CLASS</th>
<th align="center" style="width: 40px;">UNITS</th>
<th align="center" style="width: 30px;">PKGS</th>
<th align="RIGHT" style="width: 40px;">WEIGHT</th>
</tr>
</thead>
<tbody>
'.$tablerows.'
</tbody>
</table>
';
$tableData = '
<style>
table#manifestTable tr.odd td{
background-color: #F0F0F0;
}
div.totalDIV{
vertical-align: bottom;
font-weight: bold;
}
</style>
<table id="manifestTable" width="100%" cellpadding="0" cellspacing="0" border="0" style="font-size: 8pt;">
<thead>
<tr style="font-weight: bold; text-decoration: underline;">
<th align="center" style="width: 40px;">REF#</th>
<th align="center" style="width: 75px;">PO#</th>
<th align="center" style="width: 75px;">PRO#</th>
<th align="left" style="width: 125px;">CONSIGNEE ADDRESS</th>
<th align="center" style="width: 125px;">SPECIAL INST</th>
<th align="center" style="width: 100px;">COMMODITY</th>
<th align="center" style="width: 40px;">NMFC#</th>
<th align="center" style="width: 30px;">SUB</th>
<th align="center" style="width: 40px;">CLASS</th>
<th align="center" style="width: 40px;">UNITS</th>
<th align="center" style="width: 30px;">PKGS</th>
<th align="RIGHT" style="width: 40px;">WEIGHT</th>
</tr>
</thead>
<tbody>
'.$tablerows1.'
</tbody>
</table>
';
$tableData = '
<style>
table#manifestTable tr.odd td{
background-color: #F0F0F0;
}
div.totalDIV{
vertical-align: bottom;
font-weight: bold;
}
</style>
<table id="manifestTable" width="100%" cellpadding="0" cellspacing="0" border="0" style="font-size: 8pt;">
<thead>
<tr style="font-weight: bold; text-decoration: underline;">
<th align="center" style="width: 40px;">REF#</th>
<th align="center" style="width: 75px;">PO#</th>
<th align="center" style="width: 75px;">PRO#</th>
<th align="left" style="width: 125px;">CONSIGNEE ADDRESS</th>
<th align="center" style="width: 125px;">SPECIAL INST</th>
<th align="center" style="width: 100px;">COMMODITY</th>
<th align="center" style="width: 40px;">NMFC#</th>
<th align="center" style="width: 30px;">SUB</th>
<th align="center" style="width: 40px;">CLASS</th>
<th align="center" style="width: 40px;">UNITS</th>
<th align="center" style="width: 30px;">PKGS</th>
<th align="RIGHT" style="width: 40px;">WEIGHT</th>
</tr>
</thead>
<tbody>
'.$tablerows2.'
</tbody>
</table>
';
$shipperCarierData ='
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="font-size: 10pt;">
<tr>
<td width="35%" align="left" valign="top" style="padding-left: 25px;">
<table width="250" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top" width="55">Shipper:</td>
<td align="left" valign="top">
company name<br />
9000 dummy street<br />
town, usa 01234<br />
Jon doe (123) 456-7890
</td>
</tr>
</table>
</td>
<td align="left" valign="top" width="45"><strong>Bill To:</strong></td>
<td width="25%" align="left" valign="top">
EST<br/>
4444 street name<br/>
dummy town, 10004<br/>
<br/>
</td>
<td align="left" valign="top" width="250">
<strong>Carrier:</strong> '.$row['shipper'].'<br />
<strong>Trailer#:</strong> '.$row['trailer'].'<br />
<strong>Service:</strong> Standard-Bill Accessorial Code WGST<br />
<strong>Terms:</strong> Prepaid
</td>
</tr>
</table>
';
$shipperCarierData1 ='
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="font-size: 10pt;">
<tr>
<td width="35%" align="left" valign="top" style="padding-left: 25px;">
<table width="250" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top" width="55">Shipper:</td>
<td align="left" valign="top">
company name 2<br />
9000 dummy street<br />
town, usa 01234<br />
Jon doe (123) 456-7890
</td>
</tr>
</table>
</td>
<td align="left" valign="top" width="45"><strong>Bill To:</strong></td>
<td width="25%" align="left" valign="top">
EST<br/>
4444 street name<br/>
dummy town, 10004<br/>
<br/>
</td>
<td align="left" valign="top" width="250">
<strong>Carrier:</strong> '.$row['shipper'].'<br />
<strong>Trailer#:</strong> '.$row['trailer'].'<br />
<strong>Service:</strong> Standard-Bill Accessorial Code WGST<br />
<strong>Terms:</strong> Prepaid
</td>
</tr>
</table>
';
$shipperCarierData2 ='
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="font-size: 10pt;">
<tr>
<td width="35%" align="left" valign="top" style="padding-left: 25px;">
<table width="250" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top" width="55">Shipper:</td>
<td align="left" valign="top">
company name<br />
9000 dummy street<br />
town, usa 01234<br />
Jon doe (123) 456-7890
</td>
</tr>
</table>
</td>
<td align="left" valign="top" width="250">
<strong>Carrier:</strong> '.$row['shipper'].'<br />
<strong>Trailer#:</strong> '.$row['trailer'].'<br />
<strong>Service:</strong> Standard-Bill Accessorial Code WGST<br />
<strong>Terms:</strong> Prepaid
</td>
</tr>
</table>
';
这是使用TCPDF创建的pdf。我正在尝试使用foreach为每个客户创建一个新的pdf。我意识到这不起作用。
if(!empty($tablerows)) {
$pdf->startPageGroup();
$pdf->SetPrintFooter(false);
$pdf->AddPage();
$pdf->writeHTMLCell(280, 0, 5, 15, $shipperCarierData, 0, 0, false, true, 'C', true);
$pdf->writeHTMLCell(280, 0, 3, 35, $tableData, 0, 0, false, true, 'C', true);
$pdf->AddPage();
$pdf->writeHTMLCell(280, 0, 5, 160, $disclaimerHTML, 0, 0, false, true, 'C', true);
$pdf->SetPrintFooter(true);
}
if(!empty($tablerows1)) {
$pdf->startPageGroup();
$pdf->SetPrintFooter(false);
$pdf->AddPage();
$pdf->writeHTMLCell(280, 0, 5, 15, $shipperCarierData1, 0, 0, false, true, 'C', true);
#WRITE TABLE ROWS
$pdf->writeHTMLCell(280, 0, 3, 35, $tableData1, 0, 0, false, true, 'C', true);
$pdf->lastPage();
//$pdf->writeHTMLCell(280, 0, 5, 160, $disclaimerHTML, 0, 0, false, true, 'C', true);
$pdf->AddPage();
$pdf->writeHTMLCell(280, 0, 5, 160, $disclaimerHTML, 0, 0, false, true, 'C', true);
}
foreach($row['customer'] as $cus) {
if (!empty($tablerows2)) {
$pdf->startPageGroup();
$pdf->SetPrintFooter(false);
$pdf->AddPage();
$pdf->writeHTMLCell(280, 0, 5, 15, $shipperCarierData2, 0, 0, false, true, 'C', true);
#WRITE TABLE ROWS
$pdf->writeHTMLCell(280, 0, 3, 35, $tableData2, 0, 0, false, true, 'C', true);
$pdf->lastPage();
$pdf->AddPage();
$pdf->writeHTMLCell(280, 0, 5, 160, $disclaimerHTML, 0, 0, false, true, 'C', true);
}
}
//Close and output PDF document
$pdf->Output('print_manifest.pdf', 'I');
答案 0 :(得分:1)
没有看到您在哪里生成此文档。示例为每个客户都有一个子目录来存储此文档。我的猜测是因为实际文档名称的静态命名。
*.c
可能希望使用customerID或其他类似的东西动态命名文件,例如
$pdf->Output('print_manifest.pdf', 'I');