public function report($id) { $dataObj = $this->FacsimileMassage->findById($id); if ($dataObj) { $this->checkCanDo($dataObj); $this->layout = 'blank'; App::uses('PdfLib', 'Lib'); $marginWidth = 50; $pdf = new PdfLib(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); $pdf->SetMargins(0, 0, 0, true); $pdf->SetFont('freeserif', '', 10, '', false); $logoHeaderPath = WWW_ROOT . 'img/document_header_logo.png'; $headerHtml = '<label style="text-align:center"><img src="' . $logoHeaderPath . '" /></label><br>'; $pdf->SetHeaderData($logoHeaderPath, 200, 'custom', $headerHtml); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->setFooterMargin($marginWidth); $pdf->Cell(0, 1, '', 0, 1, 'C'); $pdf->AddPage('P'); $pageTitle = "BẢNG CHÀO GIÁ BAO BÌ"; $titleHtml = '<label style="font-size:15px; text-align:center"><u>' . $pageTitle . '</u></label><br>'; $pdf->setY(40); $pdf->writeHTML($titleHtml, true, false, false, false, ''); $totalPage = $pdf->getAliasNbPages(); $view = new View($this); $view->set('data', $dataObj); $view->set('totalPage', $totalPage); $productItems = $this->FacsimileMassageProduct->find('all', array('conditions' => array('facsimile_massage_id' => $id))); $view->set('productItems', $productItems); $html = $view->render('report_pdf'); //echo $html; die(); $pdf->setX(30); $pdf->writeHTML($html, true, false, false, false, ''); $date = reformatDate($dataObj['FacsimileMassage']['created_time'], '\\N\\g\\à\\y d \\t\\h\\á\\n\\g m \\n\\ă\\m Y'); $pdf->setX(150); $pdf->MultiCell(225, 101, $date, 0, 'J', 0, 1, '', '', true, null, true); $exportFileName = 'pdf_report_' . date('Y_m_d_H_i_s') . '.pdf'; $tmpFile = WWW_ROOT . 'files/uploads/tmp/' . $exportFileName; $pdf->Output($tmpFile, 'I'); } }
public function report($id) { $dataObj = $this->WorksSheet->findById($id); if ($dataObj) { $this->checkCanDo($dataObj); $costingProduct = $this->Costing->find("first", array('conditions' => array('Costing.product_id' => $dataObj['Product']['id']))); if ($costingProduct) { $productPO = $this->PurchaseOrder->find('first', array('joins' => array(array('table' => $this->PurchaseOrderProduct->useTable, 'alias' => 'PurchaseOrderProduct', 'type' => 'INNER', 'conditions' => array('PurchaseOrder.id = PurchaseOrderProduct.purchase_order_id', 'PurchaseOrderProduct.deleted_time IS NULL')), array('table' => $this->Product->useTable, 'alias' => 'Product', 'type' => 'INNER', 'conditions' => array('Product.id = PurchaseOrderProduct.product_id', 'Product.deleted_time IS NULL'))), 'conditions' => array('PurchaseOrder.customer_id' => $dataObj['WorksSheet']['customer_id'], 'PurchaseOrderProduct.product_id' => $dataObj['WorksSheet']['product_id']), 'fields' => array('PurchaseOrder.*'))); $listUnit = Hash::combine($this->ProductUnit->find('all'), '{n}.ProductUnit.id', '{n}.ProductUnit'); $this->layout = 'blank'; App::uses('PdfLib', 'Lib'); $marginWidth = 50; $pdf = new PdfLib(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); $pdf->SetMargins(0, 0, 0, true); $pdf->SetFont('freeserif', '', 10, '', false); $logoHeaderPath = WWW_ROOT . 'img/document_header_logo.png'; $headerHtml = '<label style="text-align:center"><img src="' . $logoHeaderPath . '" /></label><br>'; $pdf->SetHeaderData($logoHeaderPath, 200, 'custom', $headerHtml); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->setFooterMargin($marginWidth); $pdf->AddPage('P'); $pageTitle = "PHIẾU BÁO SẢN XUẤT"; $titleHtml = '<label style="font-size:15px; text-align:center"><u>' . $pageTitle . '</u></label><br>'; $pdf->setY(40); $pdf->writeHTML($titleHtml, true, false, false, false, ''); $view = new View($this); $view->set('data', $dataObj); $view->set('listUnit', $listUnit); $orderProgress = $this->WorksSheetProgress->find('all', array('conditions' => array('product_order_id' => $id), 'order' => array('order asc'))); $view->set('orderProgress', $orderProgress); $view->set('productPO', $productPO); //--------------------- $cutting = $costingProduct['Costing']['paper_cutting']; $numProduc = $costingProduct['Costing']['quantity']; $haoPhi = $numProduc / $cutting / 50; $reportNum = $numProduc / $cutting + $haoPhi; $view->set('reportNum', $reportNum); $view->set('haoPhi', $haoPhi); $view->set('costingProduct', $costingProduct); $paperName = Configure::read("PAPER_NAME"); $view->set('paperName', $paperName); //-------------------- $html = $view->render('report_pdf'); //$pdf->setY(40); $pdf->setX(30); $pdf->writeHTML($html, true, false, false, false, ''); $pdf->setX(31); $note = trim($dataObj['WorksSheet']['special_note']); $strText = str_replace("\n", "<br>", $note); $pdf->MultiCell(205, 10, $strText, 0, 'J', 0, 1, '', '', true, null, true); $date = reformatDate($dataObj['WorksSheet']['created_time'], '\\N\\g\\à\\y d \\t\\h\\á\\n\\g m \\n\\ă\\m Y'); $pdf->setX(130); $pdf->MultiCell(205, 10, $date, 0, 'J', 0, 1, '', '', true, null, true); //$pdf->Write(0, $date); $pdf->setX(31); $htmlFooter = '<table>'; $htmlFooter .= '<tr>'; $htmlFooter .= '<td width="50%">Người lập phiếu</td>'; $htmlFooter .= '<td width="50%">Người duyệt</td>'; $htmlFooter .= '</tr>'; /*$htmlFooter .= '<tr><td></td></tr>'; $htmlFooter .= '<tr><td></td></tr>'; $htmlFooter .= '<tr><td></td></tr>'; $htmlFooter .= '<tr><td></td></tr>'; $htmlFooter .= '<tr>'; $htmlFooter .= '<td width="50%">'.$dataObj['User']['display_name'].'</td>'; $htmlFooter .= '<td width="50%"></td>'; $htmlFooter .= '</tr>';*/ $htmlFooter .= '</table>'; $pdf->MultiCell(205, 35, $htmlFooter, 0, 'J', 0, 1, '', '', true, null, true); //$text2 = "<b>".$dataObj['CreatedUser']['display_name']."<b>".$tabSpace.$dataObj['ApprovedUser']['display_name']; //$pdf->setX(31); //$pdf->MultiCell(205, 5,$text2, 0, 'J', 0, 1, '', '', true, null, true); $exportFileName = 'pdf_report_' . date('Y_m_d_H_i_s') . '.pdf'; $tmpFile = WWW_ROOT . 'files/uploads/tmp/' . $exportFileName; header("Content-type: application/pdf"); $pdf->Output($tmpFile, 'I'); } else { } } }