2016-07-04 5 views
0

가능한 한 코드를 줄이려고했습니다. 코드의 가장 중요한 부분은 두 번째 블록입니다. 해결해야 할 다른 법안이 필요한 시나리오는 두 가지뿐입니다. 이들은 하드 코딩 된 shippercarrierdata, shippercarrierdata1.These는 pdf를 벌금 만들 수 있습니다. 문제는 선불 고객을위한 기본 주소를 만드는 것입니다. 둘 이상의 고객이있는 경우 해당 고객의 모든 주문 목록이 포함 된 새 PDF를 작성해야합니다. 나는 TCPDF를 사용하고있다. 어떤 도움을 주시면 감사하겠습니다.모든 다른 고객 번호에 대한 새로운 pdf

<?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<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<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<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'); 

답변

1

이 문서를 생성하지 않고 있습니다. 예를 들어,이 문서를 저장할 각 고객에 대한 하위 디렉토리가 있습니다. 내 생각에 실제 문서 이름의 정적 이름 지정 때문일 것입니다.

$pdf->Output('print_manifest.pdf', 'I'); 

동적으로 고객 ID 또는 효과 등

$filename = 'manifest' . time() . '.pdf'; 
$pdf->Output($filename, 'I'); 
뭔가를 사용하여 파일 이름을 지정 할 수 있습니다