Example #1
18
    public function testPdfOutput()
    {
        // create new PDF document
        $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
        // set document information
        $pdf->SetCreator(PDF_CREATOR);
        $pdf->SetAuthor('Nicola Asuni');
        $pdf->SetTitle('TCPDF Example 001');
        $pdf->SetSubject('TCPDF Tutorial');
        $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
        // set default header data
        $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 001', PDF_HEADER_STRING, array(0, 64, 255), array(0, 64, 128));
        $pdf->setFooterData(array(0, 64, 0), array(0, 64, 128));
        // set header and footer fonts
        $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
        $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
        // set default monospaced font
        $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
        // set margins
        $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
        $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
        $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
        // set auto page breaks
        $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
        // set image scale factor
        $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
        // set some language-dependent strings (optional)
        $pdf->setLanguageArray($this->langSettings);
        // ---------------------------------------------------------
        // set default font subsetting mode
        $pdf->setFontSubsetting(true);
        // Set font
        // dejavusans is a UTF-8 Unicode font, if you only need to
        // print standard ASCII chars, you can use core fonts like
        // helvetica or times to reduce file size.
        $pdf->SetFont('dejavusans', '', 14, '', true);
        // Add a page
        // This method has several options, check the source code documentation for more information.
        $pdf->AddPage();
        // set text shadow effect
        $pdf->setTextShadow(array('enabled' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 1, 'blend_mode' => 'Normal'));
        // Set some content to print
        $html = <<<EOD
<h1>Welcome to <a href="http://www.tcpdf.org" style="text-decoration:none;background-color:#CC0000;color:black;">&nbsp;<span style="color:black;">TC</span><span style="color:white;">PDF</span>&nbsp;</a>!</h1>
<i>This is the first example of TCPDF library.</i>
<p>This text is printed using the <i>writeHTMLCell()</i> method but you can also use: <i>Multicell(), writeHTML(), Write(), Cell() and Text()</i>.</p>
<p>Please check the source code documentation and other examples for further information.</p>
<p style="color:#CC0000;">TO IMPROVE AND EXPAND TCPDF I NEED YOUR SUPPORT, PLEASE <a href="http://sourceforge.net/donate/index.php?group_id=128076">MAKE A DONATION!</a></p>
EOD;
        // Print text using writeHTMLCell()
        $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
        $this->comparePdfs($pdf);
    }
/**
 * Creates an example PDF TEST document using TCPDF
 * @package com.tecnick.tcpdf
 * @abstract TCPDF - Example: Default Header and Footer
 * @author Nicola Asuni
 * @since 2008-03-04
 */
function citation_exporter_create_pdf($html_input, $output_filename)
{
    module_load_include('php', 'citation_exporter', '/lib/tcpdf/config/lang/eng');
    module_load_include('php', 'citation_exporter', '/lib/tcpdf/tcpdf');
    // create new PDF document
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    // set document information
    //$pdf->SetCreator(PDF_CREATOR);
    //$pdf->SetAuthor('Nicola Asuni');
    //$pdf->SetTitle('Exported Citations');
    //$pdf->SetSubject('Citations');
    //$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
    // set default header data
    //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 001', PDF_HEADER_STRING);
    // set header and footer fonts
    //$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
    //$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
    // set default monospaced font
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    //set margins
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
    //set auto page breaks
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    //set image scale factor
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    //set some language-dependent strings
    $pdf->setLanguageArray($l);
    // ---------------------------------------------------------
    // set default font subsetting mode
    $pdf->setFontSubsetting(true);
    // Set font
    // dejavusans is a UTF-8 Unicode font, if you only need to
    // print standard ASCII chars, you can use core fonts like
    // helvetica or times to reduce file size.
    $pdf->SetFont('dejavusans', '', 14, '', true);
    // Add a page
    // This method has several options, check the source code documentation for more information.
    $pdf->AddPage();
    // Print text using writeHTMLCell()
    $pdf->writeHTMLCell($w = 0, $h = 0, $x = '', $y = '', $html_input, $border = 0, $ln = 1, $fill = 0, $reseth = true, $align = '', $autopadding = true);
    // ---------------------------------------------------------
    // Close and output PDF document
    // This method has several options, check the source code documentation for more information.
    $pdf->Output($output_filename, 'F');
    //============================================================+
    // END OF FILE
    //============================================================+
}
    public function pdfthongkeAction()
    {
        $translate = Zend_Registry::get('Zend_Translate');
        $this->view->title = 'Thống kê - ' . $translate->_('TEXT_DEFAULT_TITLE');
        $this->view->headTitle($this->view->title);
        $layoutPath = APPLICATION_PATH . '/templates/' . TEMPLATE_USED;
        $option = array('layout' => '1_column/layout', 'layoutPath' => $layoutPath);
        Zend_Layout::startMvc($option);
        $date = new Zend_Date();
        $date->subMonth(1);
        $thang = $this->_getParam('thang', $date->toString('M'));
        $nam = $this->_getParam('nam', $date->toString('Y'));
        $auth = Zend_Auth::getInstance();
        $identity = $auth->getIdentity();
        $em_id = $identity->em_id;
        $emModel = new Front_Model_Employees();
        $phongbanModel = new Front_Model_Phongban();
        $my_info = $emModel->fetchRow('em_id=' . $em_id . ' and em_status=1');
        $phong_ban_id = $list_phongban = $phong_ban = array();
        if ($my_info) {
            $phong_ban_id[] = $my_info->em_phong_ban;
            $list_phongban = $phongbanModel->fetchDataStatus($my_info->em_phong_ban, $phong_ban);
        }
        if (sizeof($list_phongban)) {
            foreach ($list_phongban as $phong_ban_info) {
                $phong_ban_id[] = $phong_ban_info->pb_parent;
            }
        }
        $phong_ban_id = implode(',', $phong_ban_id);
        $list_nhan_vien = $emModel->fetchAll("em_phong_ban in ({$phong_ban_id}) and em_status=1");
        $holidaysModel = new Front_Model_Holidays();
        $holidays = $holidaysModel->fetchData();
        $listHoliday = array();
        foreach ($holidays as $holiday) {
            $listHoliday[$holiday['hld_id']] = $holiday['hld_code'];
        }
        $k = 0;
        if ($list_nhan_vien) {
            $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
            $pdf->SetCreator(PDF_CREATOR);
            $pdf->SetAuthor(PDF_AUTHOR);
            $pdf->SetTitle(PDF_HEADER_TITLE);
            $pdf->SetSubject(PDF_HEADER_TITLE);
            $pdf->SetKeywords('bang luong');
            $pdf->setPrintHeader(false);
            $pdf->setFooterData(array(0, 64, 0), array(0, 64, 128));
            $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
            $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
            $pdf->SetMargins(5, PDF_MARGIN_TOP, 5);
            $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
            $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
            $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
            $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
            $pdf->setFontSubsetting(true);
            $pdf->SetFont('dejavusans', '', 14, '', true);
            $pdf->AddPage('L', 'A4');
            $pdf->setTextShadow(array('enabled' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 1, 'blend_mode' => 'Normal'));
            $text_outout = '
                        <style>
                            .ten-co-quan {
                                color: #000;
                                font-size: 10pt;
                                height: 50px;
                                text-align:center;
                            }
                            .ten-bang-luong{
                                height: 30px;
                                text-align:center;
                                font-size: 10pt;
                            }

                            table.first {
                                color: #003300;
                                font-family: helvetica;
                                font-size: 8pt;
                                border-left: 3px solid red;
                                border-right: 3px solid #FF00FF;
                                border-top: 3px solid green;
                                border-bottom: 3px solid blue;
                                background-color: #ccffcc;
                            }
                            .borders {
                                border: 1px solid #000;
                                font-size: 10px;
                            }

                            .tieu-de{
                                height: 20px;
                                font-size: 11px;
                            }
                            .noi-dung{
                                font-size: 10px;
                            }
                            td.second {
                                border: 2px dashed green;
                            }

                            .lowercase {
                                text-transform: lowercase;
                            }
                            .uppercase {
                                text-transform: uppercase;
                            }
                            .capitalize {
                                text-transform: capitalize;
                            }
                            
                            .error{
                                background-color: #dddddd;
                            }
                        </style>
                        <table width="100%">
                            <tr>
                                <td width="200" class="ten-co-quan uppercase">
                                    TỔNG CỤC HẢI QUAN
                                    <div><strong>CỤC HẢI QUAN HÀ TĨNH</strong></div>
                                </td>
                                <td colspan="2">&nbsp;</td>
                            </tr>
                            <tr>
                                <td colspan="3" class="ten-bang-luong uppercase">BẢNG CHẤM CÔNG VÀ XẾP LOẠI A,B,C THÁNG ' . $thang . '-' . $nam . '</td>
                            </tr>';
            $text_outout .= '<tr>
                                <td colspan="3">
                                    <br/>
                                    <table border="1" class="noi-dung" cellpadding="5" nobr="true">
                                        <tr>
                                            <td style="width: 25pt;" rowspan="2"><strong>STT</strong></td>
                                            <td style="width: 70pt;" rowspan="2"><strong>HỌ TÊN</strong></td>
                                            <td colspan="31" style="text-align:center;"><strong>Ngày Công Trong Tháng</strong></td>
                                            <td style="width: 50pt;" rowspan="2"><strong>Phân loại A,B,C</strong></td>
                                            <td style="width: 50pt;" rowspan="2"><strong>Ghi chú</strong></td>
                                        </tr>
                                        <tr>';
            for ($i = 1; $i <= 31; $i++) {
                $text_outout .= '<td >' . $i . '</td>';
            }
            $text_outout .= '</tr>';
            $k = 0;
            $chamcongModel = new Front_Model_ChamCong();
            foreach ($list_nhan_vien as $nhan_vien) {
                $phan_loai_label = 'A';
                $phan_loai = $this->view->viewGetPhanLoai($nhan_vien->em_id, $thang, $nam);
                if ($phan_loai) {
                    $phan_loai_label = $phan_loai->dg_ptccb_status;
                    if (!$phan_loai_label || $phan_loai_label == null || $phan_loai_label == '-') {
                        $phan_loai_label = 'A';
                    }
                } else {
                    $phan_loai_label = '';
                }
                $text_outout .= '<tr>';
                $k++;
                $cham_cong = $chamcongModel->fetchOneData(array('c_em_id' => $nhan_vien['em_id'], 'c_thang' => (int) $thang, 'c_nam' => (int) $nam));
                $text_outout .= '<td>' . $k . '</td>';
                $text_outout .= '<td>' . $nhan_vien->em_ho . ' ' . $nhan_vien->em_ten_dem . ' ' . $nhan_vien->em_ten . '</td>';
                for ($i = 1; $i <= 31; $i++) {
                    $ngay_chamcong = 'c_ngay_' . $i;
                    $trangthai_ngaycong = $cham_cong->{$ngay_chamcong};
                    $status = !empty($listHoliday[$trangthai_ngaycong]) ? $listHoliday[$trangthai_ngaycong] : '&nbsp;';
                    $text_outout .= '<td ' . $this->view->viewCheckChuNhatThuBay($i, (int) $thang, (int) $nam) . '>' . $status . '</td>';
                }
                $text_outout .= '<td>' . $phan_loai_label . '</td>';
                $text_outout .= '<td></td>';
                $text_outout .= '</tr>';
            }
            $text_outout .= '</table>
                                </td>
                            </tr>';
            $text_outout .= '</table>
                                </td>
                            </tr>';
            $text_outout .= '<tr><td style=""></td><td style="width: 120pt;">&nbsp;</td><td style="width: 50pt;">&nbsp;</td></tr>';
            foreach ($holidays as $holiday) {
                $text_outout .= '<tr class="noi-dung"><td style="width: 32pt;"></td><td style="width: 70pt;">' . $holiday['hld_name'] . '</td><td style="width: 50pt;">' . $holiday['hld_code'] . '</td></tr>';
            }
            $text_outout .= '</table> ';
            $pdf->writeHTMLCell(0, 0, '', '', $text_outout, 0, 1, 0, true, '', true);
            $pdf->Output($file_name, 'I');
            die;
            $k += 5;
            foreach ($holidays as $holiday) {
                $k++;
                $objPHPExcel->getActiveSheet()->SetCellValue('B' . ($k + 7), $holiday['hld_name']);
                $objPHPExcel->getActiveSheet()->SetCellValue('C' . ($k + 7), $holiday['hld_code']);
            }
            if ($k) {
                $objPHPExcel->getActiveSheet()->setTitle('Bảng lương');
                if ($pb_selected && $phong_ban_selected_info) {
                    $file_name = 'Thong_ke_luong_' . str_replace(' ', '_', $this->loc_tieng_viet($phong_ban_selected_info->pb_name)) . '_' . $thang . '-' . $nam . '.xls';
                } else {
                    $file_name = 'Thong_ke_luong_' . $thang . '-' . $nam . '.xls';
                }
                header('Content-Type: application/vnd.ms-excel');
                header('Content-Disposition: attachment;
                filename = "' . $file_name . '"');
                header('Cache-Control: max-age = 0');
                $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
                $objWriter->save('php://output');
                die;
                /*
                                  $file_name = 'Bang_luong_.xls';
                                  $objPHPExcel->getActiveSheet()->setTitle('Bảng lương');
                
                                  header('Content-Type: application/vnd.ms-excel');
                                  header('Content-Disposition: attachment;filename="hungnm.xls"');
                                  header('Cache-Control: max-age=0');
                                  $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
                                  $objWriter->save('php://output'); */
            } else {
                $this->_helper->viewRenderer->setRender('loi');
            }
        } else {
            $this->_helper->viewRenderer->setRender('loi');
        }
    }
function create_pdf($content, $title)
{
    tcpdf();
    $obj_pdf = new TCPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $obj_pdf->SetCreator(PDF_CREATOR);
    $title = $title;
    $obj_pdf->SetTitle('MultiTV analytics');
    $obj_pdf->SetAuthor('MultiTv');
    $obj_pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $title, PDF_HEADER_STRING);
    $obj_pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
    $obj_pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
    $obj_pdf->SetDefaultMonospacedFont('helvetica');
    $obj_pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
    $obj_pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $obj_pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    $obj_pdf->SetFont('helvetica', '', 9);
    $obj_pdf->setFontSubsetting(false);
    $obj_pdf->AddPage();
    //ob_start();
    // we can have any view part here like HTML, PHP etc
    //$content = ob_get_contents();
    ob_end_clean();
    $obj_pdf->writeHTML($content, true, false, true, false, '');
    $obj_pdf->Output('output.pdf', 'I');
}
Example #5
0
 function display($tpl = null)
 {
     global $mainframe;
     $app = JFactory::getApplication();
     $params = $app->getParams();
     $this->assignRef('params', $params);
     $user = JFactory::getUser();
     $username = $user->username;
     $this->child = JFactory::getUser($username);
     $layout = $params->get('layout');
     $this->tasks = JoomdleHelperContent::call_method("get_children_grade_user_report", $username);
     $tpl = "catspdf";
     $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));
     $this->_prepareDocument();
     $htmlcontent = parent::loadTemplate($tpl);
     require_once JPATH_SITE . '/libraries/tcpdf/tcpdf.php';
     $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     $header = JText::_('COM_JOOMDLE_GRADES');
     $pdf->SetHeaderData('', 0, $header);
     //set margins
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
     $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
     $pdf->setFontSubsetting(false);
     $pdf->SetFont('times', '', 8);
     // add a page
     $pdf->AddPage("L");
     // output the HTML content
     $pdf->writeHTML($htmlcontent, true, 0, true, 0);
     $pdf->Output("grades.pdf", 'D');
     exit;
 }
Example #6
0
 function display($tpl = null)
 {
     $app = JFactory::getApplication();
     $params = $app->getParams();
     $this->assignRef('params', $params);
     $this->course_id = $params->get('course_id');
     if (!$this->course_id) {
         $this->course_id = JRequest::getVar('course_id');
     }
     $this->course_id = (int) $this->course_id;
     // Only for logged users
     $user = JFactory::getUser();
     $username = $user->username;
     if (!$username) {
         return;
     }
     if (!$this->course_id) {
         echo JText::_('COM_JOOMDLE_NO_COURSE_SELECTED');
         return;
     }
     $this->course_info = JoomdleHelperContent::getCourseInfo($this->course_id, $username);
     // user not enroled
     if (!$this->course_info['enroled']) {
         return;
     }
     $document = JFactory::getDocument();
     $document->setTitle($this->course_info['fullname'] . ': ' . JText::_('COM_JOOMDLE_GRADES'));
     $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));
     //  $this->gcats = JoomdleHelperContent::call_method ("get_course_grades_by_category", $this->course_id, $username);
     $this->gcats = JoomdleHelperContent::call_method("get_grade_user_report", $this->course_id, $username);
     $tpl = "catspdf";
     $this->_prepareDocument();
     $htmlcontent = parent::loadTemplate($tpl);
     require_once JPATH_SITE . '/libraries/tcpdf/tcpdf.php';
     $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     $header = $this->course_info['fullname'];
     $header2 = JText::_('COM_JOOMDLEGRADES_TEACHER') . ': ' . $user->name;
     $header2 .= ' ' . JText::_('COM_JOOMDLEGRADES_DATE') . ': ' . date('d-m-Y');
     //	$pdf->SetHeaderData('', 0, $header, $header2);
     $pdf->SetHeaderData('', 0, $header);
     //set margins
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
     $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
     $pdf->setFontSubsetting(false);
     $pdf->SetFont('times', '', 8);
     // add a page
     $pdf->AddPage("L");
     // output the HTML content
     $pdf->writeHTML($htmlcontent, true, 0, true, 0);
     $pdf->Output("grades.pdf", 'D');
     exit;
     //parent::display($tpl);
 }
 public function __construct($s_title, $sPageFormat = 'A4', $sPageOrientation = 'L')
 {
     parent::__construct($s_title);
     define(K_PATH_FONTS, APPROOT . 'lib/tcpdf/fonts');
     $this->oPdf = new iTopPDF($sPageOrientation, 'mm', $sPageFormat, true, 'UTF-8', false);
     // set document information
     $this->oPdf->SetCreator(PDF_CREATOR);
     $this->oPdf->SetAuthor('iTop');
     $this->oPdf->SetTitle($s_title);
     $this->oPdf->SetDocumentTitle($s_title);
     $this->oPdf->setFontSubsetting(true);
     // Set font
     // dejavusans is a UTF-8 Unicode font. Standard PDF fonts like helvetica or times new roman are NOT UTF-8
     $this->oPdf->SetFont('dejavusans', '', 10, '', true);
     // set auto page breaks
     $this->oPdf->SetAutoPageBreak(true, 15);
     // 15 mm break margin at the bottom
     $this->oPdf->SetTopMargin(15);
     // Add a page, we're ready to start
     $this->oPdf->AddPage();
     $this->SetContentDisposition('inline', $s_title . '.pdf');
     $this->SetDefaultStyle();
 }
Example #8
0
 /**
  *  Save PHPExcel to file
  *
  *  @param     string     $pFilename   Name of the file to save as
  *  @throws    PHPExcel_Writer_Exception
  */
 public function save($pFilename = null)
 {
     $fileHandle = parent::prepareForSave($pFilename);
     //  Default PDF paper size
     $paperSize = 'LETTER';
     //    Letter    (8.5 in. by 11 in.)
     //  Check for paper size and page orientation
     if (is_null($this->getSheetIndex())) {
         $orientation = $this->_phpExcel->getSheet(0)->getPageSetup()->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE ? 'L' : 'P';
         $printPaperSize = $this->_phpExcel->getSheet(0)->getPageSetup()->getPaperSize();
         $printMargins = $this->_phpExcel->getSheet(0)->getPageMargins();
     } else {
         $orientation = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE ? 'L' : 'P';
         $printPaperSize = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize();
         $printMargins = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageMargins();
     }
     //  Override Page Orientation
     if (!is_null($this->getOrientation())) {
         $orientation = $this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE ? 'L' : 'P';
     }
     //  Override Paper Size
     if (!is_null($this->getPaperSize())) {
         $printPaperSize = $this->getPaperSize();
     }
     if (isset(self::$paperSizes[$printPaperSize])) {
         $paperSize = self::$paperSizes[$printPaperSize];
     }
     //  Create PDF
     $pdf = new TCPDF($orientation, 'pt', $paperSize);
     $pdf->setFontSubsetting(false);
     //    Set margins, converting inches to points (using 72 dpi)
     $pdf->SetMargins($printMargins->getLeft() * 72, $printMargins->getTop() * 72, $printMargins->getRight() * 72);
     $pdf->SetAutoPageBreak(true, $printMargins->getBottom() * 72);
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $pdf->AddPage();
     //  Set the appropriate font
     $pdf->SetFont($this->getFont());
     $pdf->writeHTML($this->generateHTMLHeader(false) . $this->generateSheetData() . $this->generateHTMLFooter());
     //  Document info
     $pdf->SetTitle($this->_phpExcel->getProperties()->getTitle());
     $pdf->SetAuthor($this->_phpExcel->getProperties()->getCreator());
     $pdf->SetSubject($this->_phpExcel->getProperties()->getSubject());
     $pdf->SetKeywords($this->_phpExcel->getProperties()->getKeywords());
     $pdf->SetCreator($this->_phpExcel->getProperties()->getCreator());
     //  Write to file
     fwrite($fileHandle, $pdf->output($pFilename, 'S'));
     parent::restoreStateAfterSave($fileHandle);
 }
Example #9
0
    public function testPdfOutput()
    {
        $this->markTestIncomplete('Repository excludes pdfahelvetica font.');
        // create new PDF document
        $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false, true);
        // set document information
        $pdf->SetCreator(PDF_CREATOR);
        $pdf->SetAuthor('Nicola Asuni');
        $pdf->SetTitle('TCPDF Example 065');
        $pdf->SetSubject('TCPDF Tutorial');
        $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
        // set default header data
        $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 065', PDF_HEADER_STRING);
        // set header and footer fonts
        $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
        $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
        // set default monospaced font
        $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
        // set margins
        $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
        $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
        $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
        // set auto page breaks
        $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
        // set image scale factor
        $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
        // set some language-dependent strings (optional)
        $pdf->setLanguageArray($this->langSettings);
        // ---------------------------------------------------------
        // set default font subsetting mode
        $pdf->setFontSubsetting(true);
        // Set font
        $pdf->SetFont('helvetica', '', 14, '', true);
        // Add a page
        // This method has several options, check the source code documentation for more information.
        $pdf->AddPage();
        // Set some content to print
        $html = <<<EOD
<h1>Example of <a href="http://www.tcpdf.org" style="text-decoration:none;background-color:#CC0000;color:black;">&nbsp;<span style="color:black;">TC</span><span style="color:white;">PDF</span>&nbsp;</a> document in <span style="background-color:#99ccff;color:black;"> PDF/A-1b </span> mode.</h1>
<i>This document conforms to the standard <b>PDF/A-1b (ISO 19005-1:2005)</b>.</i>
<p>Please check the source code documentation and other examples for further information (<a href="http://www.tcpdf.org">http://www.tcpdf.org</a>).</p>
<p style="color:#CC0000;">TO IMPROVE AND EXPAND TCPDF I NEED YOUR SUPPORT, PLEASE <a href="http://sourceforge.net/donate/index.php?group_id=128076">MAKE A DONATION!</a></p>
EOD;
        // Print text using writeHTMLCell()
        $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
        // ---------------------------------------------------------
        $this->comparePdfs($pdf);
    }
Example #10
0
function create_pdf($campdata)
{
    // create new PDF document
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    // set document information
    $pdf->SetCreator('Dreamcity');
    $pdf->SetAuthor('Dreamcity');
    $pdf->SetTitle('TCPDF Example 001');
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    // set margins
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_RIGHT);
    // set auto page breaks
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    // set default font subsetting mode
    $pdf->setFontSubsetting(true);
    // Set font
    // dejavusans is a UTF-8 Unicode font, if you only need to
    // print standard ASCII chars, you can use core fonts like
    // helvetica or times to reduce file size.
    $pdf->SetFont('dejavusans', '', 14, '', true);
    // Add a page
    // This method has several options, check the source code documentation for more information.
    $pdf->AddPage();
    // Set some content to print
    $html = "<h1>Dear Dreamer</h1>\r\n<i>Here is a Copy of your previous application</i>\r\n<p></p>" . "<br/>" . $campdata->camp_description . "<br/>" . $campdata->camp_short_desc . "<br/>" . $campdata->camp_construction . "<br/>" . $campdata->camp_participants . "<br/>" . $campdata->camp_registration_date;
    // Print text using writeHTMLCell()
    $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
    // Close and output PDF document
    // This method has several options, check the source code documentation for more information.
    //$data = $pdf->Output('application.pdf', 'E');
    $data = $pdf->Output('application.pdf', 'S');
    //$data = array($fileatt);
    //$data = chunk_split($fileatt);
    /*
        //$fileatt = "./test.pdf";
    
        $fileatttype = "application/pdf";
        $fileattname = "newname.pdf";
    
        $file = fopen($fileatt, 'rb');
        $data = fread($file, filesize($fileatt));
    
        fclose($file);
    */
    return $data;
}
Example #11
0
 public function testPdfOutput()
 {
     // create new PDF document
     $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     // set document information
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor('Nicola Asuni');
     $pdf->SetTitle('TCPDF Example 033');
     $pdf->SetSubject('TCPDF Tutorial');
     $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
     // set default header data
     $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 033', PDF_HEADER_STRING);
     // set header and footer fonts
     $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
     $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
     // set default monospaced font
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     // set margins
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
     $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     // set auto page breaks
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     // set image scale factor
     $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     // set some language-dependent strings (optional)
     $pdf->setLanguageArray($this->langSettings);
     // ---------------------------------------------------------
     // add a page
     $pdf->AddPage();
     // set default font subsetting mode
     $pdf->setFontSubsetting(false);
     $pdf->SetFont('helvetica', 'B', 20);
     $pdf->Write(0, 'Font Types', '', 0, 'C', 1, 0, false, false, 0);
     $pdf->Ln(10);
     $pdf->SetFont('times', '', 10);
     $pdf->MultiCell(80, 0, "[Core font] : Cras eros leo, porttitor porta, accumsan fermentum, ornare ac, est. Praesent dui lorem, imperdiet at, cursus sed, facilisis aliquam, nibh. Nulla accumsan nonummy diam. Donec tempus. Etiam posuere. Proin lectus. Donec purus. Duis in sem pretium urna feugiat vehicula. Ut suscipit velit eget massa. Nam nonummy, enim commodo euismod placerat, tortor elit tempus lectus, quis suscipit metus lorem blandit turpis.\n", 1, 'J', 0, 1, '', '', true, 0);
     $pdf->Ln(2);
     $pdf->SetFont('dejavusans', '', 10);
     $pdf->MultiCell(80, 0, "[True Type Unicode font] : Cras eros leo, porttitor porta, accumsan fermentum, ornare ac, est. Praesent dui lorem, imperdiet at, cursus sed, facilisis aliquam, nibh. Nulla accumsan nonummy diam. Donec tempus. Etiam posuere. Proin lectus. Donec purus. Duis in sem pretium urna feugiat vehicula. Ut suscipit velit eget massa. Nam nonummy, enim commodo euismod placerat, tortor elit tempus lectus, quis suscipit metus lorem blandit turpis.\n", 1, 'J', 0, 1, '', '', true, 0);
     $pdf->Ln(2);
     $pdf->SetFont('cid0jp', '', 9);
     $pdf->MultiCell(80, 0, "[CID-0 font] : Cras eros leo, porttitor porta, accumsan fermentum, ornare ac, est. Praesent dui lorem, imperdiet at, cursus sed, facilisis aliquam, nibh. Nulla accumsan nonummy diam. Donec tempus. Etiam posuere. Proin lectus. Donec purus. Duis in sem pretium urna feugiat vehicula. Ut suscipit velit eget massa. Nam nonummy, enim commodo euismod placerat, tortor elit tempus lectus, quis suscipit metus lorem blandit turpis.\n", 1, 'J', 0, 1, '', '', true, 0);
     $this->comparePdfs($pdf);
 }
 /**
  * @param string $content
  * @param string $destination
  * @return string
  */
 public function generatePdf($content, $destination)
 {
     $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false, true);
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetTitle($this->getFileName());
     $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
     $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
     $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     $pdf->setFontSubsetting(true);
     $pdf->SetFont('helvetica', '', 9, '', true);
     $pdf->AddPage();
     $pdf->writeHTMLCell(0, 0, '', '', $content, 0, 1, 0, true, '', true);
     $pdf->Output($destination, 'F');
     return $destination;
 }
Example #13
0
 /**
  * Generate the pdf document
  * @param   IsotopeProductCollection
  * @param   array
  * @return  \TCPDF
  */
 protected function generatePDF(IsotopeProductCollection $objCollection, array $arrTokens)
 {
     // TCPDF configuration
     $l = array();
     $l['a_meta_dir'] = 'ltr';
     $l['a_meta_charset'] = $GLOBALS['TL_CONFIG']['characterSet'];
     $l['a_meta_language'] = substr($GLOBALS['TL_LANGUAGE'], 0, 2);
     $l['w_page'] = 'page';
     // Include TCPDF config
     require_once TL_ROOT . '/system/config/tcpdf.php';
     if (version_compare(VERSION, '3.3', '<')) {
         require_once TL_ROOT . '/system/modules/core/vendor/tcpdf/tcpdf.php';
     }
     // Create new PDF document
     $pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true);
     // Set document information
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor(PDF_AUTHOR);
     $pdf->SetTitle(\String::parseSimpleTokens($this->documentTitle, $arrTokens));
     // Prevent font subsetting (huge speed improvement)
     $pdf->setFontSubsetting(false);
     // Remove default header/footer
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     // Set margins
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     // Set auto page breaks
     $pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);
     // Set image scale factor
     $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     // Set some language-dependent strings
     $pdf->setLanguageArray($l);
     // Initialize document and add a page
     $pdf->AddPage();
     // Set font
     $pdf->SetFont(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN);
     // Write the HTML content
     $pdf->writeHTML($this->generateTemplate($objCollection, $arrTokens), true, 0, true, 0);
     $pdf->lastPage();
     return $pdf;
 }
Example #14
0
 /**
  * Init PDF exportu
  *
  * @param string $title nadpis stránky
  * @param char $orientation P|L
  */
 public function pdfInit($title = null, $orientation = 'P')
 {
     $this->filename .= $title;
     // pdf object
     $this->pdf = new TCPDF($orientation);
     // set document information
     $this->pdf->SetCreator(PDF_CREATOR);
     $this->pdf->SetAuthor(EaseShared::user()->getUsername());
     $this->pdf->SetTitle($title);
     $this->pdf->SetSubject('');
     $this->pdf->SetKeywords($title);
     // set default header data
     $this->pdf->SetHeaderData('logo.png', 45, $title, "DB Finance s.r.o - nezávislý investiční zprostředkovatel a pojišťovací makléř\n" . "✉ dbfinance@dbfinance.cz ☎ 222 541 990 – 995 ⌨ www.dbfinance.cz ");
     // set header and footer fonts
     $this->pdf->setHeaderFont(array('dejavusans', '', 8));
     $this->pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
     // set default monospaced font
     $this->pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     //set margins
     $this->pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     $this->pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
     $this->pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     //set auto page breaks
     $this->pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     //set image scale factor
     $this->pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     // ---------------------------------------------------------
     // set default font subsetting mode
     $this->pdf->setFontSubsetting(true);
     // Set font
     // dejavusans is a UTF-8 Unicode font, if you only need to
     // print standard ASCII chars, you can use core fonts like
     // helvetica or times to reduce file size.
     $this->pdf->SetFont('dejavusans', '', 8, '', true);
     // Add a page
     // This method has several options, check the source code documentation for more information.
     $this->pdf->AddPage();
     // ---------------------------------------------------------
     // Close and output PDF document
     // This method has several options, check the source code documentation for more information.
 }
Example #15
0
 public function getAttatchment()
 {
     $title = $this->input->get('title');
     $attatch = $this->input->get('attatchment');
     $this->form_validation->set_rules('reportTitle', 'Report Title', 'required');
     $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
     tcpdf();
     // create new PDF document
     $obj_pdf = new TCPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     //set title of report
     $obj_pdf->SetAuthor($this->session->userdata['username']);
     $obj_pdf->SetTitle($title);
     $obj_pdf->SetCreator(PDF_CREATOR);
     $obj_pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $title, PDF_HEADER_STRING);
     $obj_pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
     $obj_pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
     $obj_pdf->SetDefaultMonospacedFont('helvetica');
     $obj_pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
     $obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     $obj_pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     $obj_pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     $obj_pdf->SetFont('helvetica', '', 9);
     $obj_pdf->setFontSubsetting(false);
     $obj_pdf->AddPage();
     $obj_pdf->Image($attatch, 15, 140, 75, 113, 'JPG', 'http://www.tcpdf.org', '', true, 150, '', false, false, 1, false, false, false);
     $path = 'C:/xampp/htdocs/QADash/public_html/reports';
     // Supply a filename including the .pdf extension
     $filename = $this->{$title};
     // Create the full path
     $full_path = $path . '/' . $filename;
     // Output PDF
     $obj_pdf->Output($full_path, 'F');
     //save report details in database
     $details = $this->saveReport($this->session->userdata['uid'], $filename, $path . '/' . $filename);
     $this->report_m->saveReport($details);
     //redirect to view the generated pdf file
     $this->data['report'] = $filename;
     $this->data['subview'] = 'manager/user/report/singleReport_view';
     $this->load->view("manager/_layout_main", $this->data);
 }
Example #16
0
function print_pdf($pdf_filename, $pdf_body)
{
    // Include the main TCPDF library (search for installation path).
    require_once ABSPATH . 'lib/tcpdf/tcpdf.php';
    // create new PDF document
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    // set document information
    $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetAuthor('Περιφέρεια Δυτικής Μακεδονίας');
    $pdf->SetTitle('Περιφέρεια Δυτικής Μακεδονίας');
    $pdf->SetSubject('Περιφέρεια Δυτικής Μακεδονίας');
    $pdf->SetKeywords('Περιφέρεια Δυτικής Μακεδονίας');
    // set default header data
    $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
    // set header and footer fonts
    $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
    $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
    // set default monospaced font
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    // set margins
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
    // set auto page breaks
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    // set image scale factor
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    // ---------------------------------------------------------
    // set default font subsetting mode
    $pdf->setFontSubsetting(true);
    // set font
    $pdf->SetFont('freeserif', '', 11);
    // add a page el
    $pdf->AddPage();
    $pdf->Write(0, '', '', 0, 'L', true, 0, false, false, 0);
    $pdf->writeHTML($pdf_body, true, false, false, false, '');
    //Close and output PDF document
    $pdf->Output($pdf_filename, 'F');
}
Example #17
0
function create_voucher_file($p, $q, $c, $b = "Mytour Voucher", $r = "Mytour.vn", $t = "Mytour.vn", $u = "mytour, mytour.vn, voucher")
{
    global $v;
    $z = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $z->SetCreator(PDF_CREATOR);
    $z->SetAuthor($r);
    $z->SetTitle($b);
    $z->SetSubject($t);
    $z->SetKeywords($u);
    $z->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    $z->SetMargins(5, 10, 5);
    $z->SetHeaderMargin(-10);
    $z->SetFooterMargin(10);
    $z->SetAutoPageBreak(TRUE, 10);
    $z->setImageScale(PDF_IMAGE_SCALE_RATIO);
    $z->setLanguageArray($v);
    $z->setFontSubsetting(true);
    $z->addFont('DejaVuSerif', '', 'dejavuserif.php');
    $z->SetFont('DejaVuSerif', '', 9, '', 'true');
    $z->AddPage();
    $z->writeHTMLCell($aa = 0, $bb = 0, $cc = '', $dd = '', $c, $ee = 0, $ff = 1, $gg = 0, $hh = true, $ii = '', $jj = true);
    $z->Output($p . $q . '.pdf', 'F');
}
Example #18
0
 private function cetak_kode()
 {
     $this->load->library("Pdf");
     $pageLayout = array(300, 528);
     //  or array($height, $width)
     $pdf = new TCPDF('p', 'px', $pageLayout, true, 'UTF-8', false);
     //$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     $pdf->SetMargins(3, 2, PDF_MARGIN_RIGHT);
     // set some language-dependent strings (optional)
     if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
         require_once dirname(__FILE__) . '/lang/eng.php';
         $pdf->setLanguageArray($l);
     }
     // set default font subsetting mode
     $pdf->setFontSubsetting(true);
     // Set font
     $pdf->SetFont('dejavusans', '', 11, '', true);
     // Add a page
     $pdf->AddPage();
     // ====================== CONTENT LOGIC ================================================
     $html = '';
     $searchterm = $this->session->userdata('searchterm');
     $totalrow = $this->material_inventory_model->record_count($searchterm);
     for ($i = 0; $i <= $totalrow; $i++) {
         $ch = $this->input->post('ch' . $i);
         if (isset($_POST['ch' . $i])) {
             $html .= $this->form_bahan_html($ch);
         }
     }
     // Print text using writeHTMLCell()
     $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
     // ---------------------------------------------------------
     // Close and output PDF document
     // This method has several options, check the source code documentation for more information.
     $pdf->Output('example_001.pdf', 'I');
 }
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
    require_once dirname(__FILE__) . '/lang/eng.php';
    $pdf->setLanguageArray($l);
}
// ---------------------------------------------------------
// set default font subsetting mode
$pdf->setFontSubsetting(true);
// Set font
// dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size.
$pdf->SetFont('dejavusans', '', 10, '', true);
// Add a page
// This method has several options, check the source code documentation for more information.
$pdf->AddPage();
// set text shadow effect
$pdf->setTextShadow(array('enabled' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 1, 'blend_mode' => 'Normal'));
$con_error = "cannot be connected";
$mysql_host = "localhost";
$mysql_user = "******";
$mysql_pass = "";
$mysql_db = "users";
Example #20
0
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
  require_once(dirname(__FILE__).'/lang/eng.php');
  $pdf->setLanguageArray($l);
}
// ---------------------------------------------------------

// set font
//$pdf->SetFont('helvetica', 'B', 10);

// add a page
$pdf->AddPage();

$pdf->setFontSubsetting(false);

$pdf->SetFont('helvetica', '', 8);

$txt = '<table align="right" border="0" cellpading="2" width="100%"><tr><td>LAMPIRAN A-PPMT-004</td></tr></table>';

$pdf->writeHTML($txt, true, false, false, false, '');

$pdf->SetFont('helvetica', 'B', 10);

//$image_file = K_PATH_IMAGES.'logo_kkm.png';

//$pdf->Image($image_file, 10, 10, 15, '', 'PNG', '', 'T', false, 300, 'C', false, false, 0, false, false, false);
//adjust here to comply paper logo
$pdf->Ln(45);
Example #21
0
    function cetak_nota_dan_alamat()
    {
        $this->load->library("Pdf");
        //$pageLayout = array(300, 528); //  or array($height, $width)
        //$pdf = new TCPDF('p', 'px', $pageLayout, true, 'UTF-8', false);
        $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
        $pdf->SetMargins(3, 2, PDF_MARGIN_RIGHT);
        // set some language-dependent strings (optional)
        if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
            require_once dirname(__FILE__) . '/lang/eng.php';
            $pdf->setLanguageArray($l);
        }
        // set default font subsetting mode
        $pdf->setFontSubsetting(true);
        // Set font
        $pdf->SetFont('dejavusans', '', 9, '', true);
        // Add a page
        $pdf->AddPage();
        // FETCHING DATA
        $order_id = $this->uri->segment(3);
        $this->db->where('id', $order_id);
        $this->db->join('billing', 'billing.billing_id = orders.billing_id');
        $this->db->limit(1);
        $queryorder = $this->db->get('orders');
        $subtotal = 0;
        $diskon = $queryorder->row()->discount_amount;
        $ongkir = $queryorder->row()->exp_cost;
        $order_date = $queryorder->row()->order_date;
        $order_id = $order_id;
        $billing_name = $queryorder->row()->billing_name;
        $price_level = $queryorder->row()->price_level;
        $adjustment_desc = $queryorder->row()->adjustment_desc;
        $adjustment_nominal = $queryorder->row()->adjustment_nominal;
        // ====================== CONTENT LOGIC ================================================
        /** $subtotal = 0;
        		$diskon = $this->input->post('discount_amount');
        		$ongkir = $this->input->post('exp_cost');
        		$order_id = $this->input->post('order_id');
        		$billing_name = $this->input->post('billing_name');
        		$order_date = $this->input->post('order_date');
        		**/
        $html = '';
        //echo 'masuk alamat';
        $html .= $this->alamat_html($order_id, 'landscape');
        //echo 'keluar alamat';
        $html .= '
		<table border="1px" cellpadding="3px" style="margin-top: 5px;">
			<tr><td colspan="5" align="right">Penerima : ' . $billing_name . '</td></tr>
			<tr>
				<td colspan="1">Nota No : ' . $order_id . '</td>
				<td colspan="4" align="right">Tanggal : ' . date('d-M-Y', strtotime($order_date)) . '</td>
			</tr>	
		
			<tr align="center">
				<td width="20%">Kode</td>
				<td colspan="2" width="45%">Nama Barang</td>
				<td width="5%">Qty</td>
				<td width="15%">Harga</td>
				<td width="15%">Total</td>
			</tr>';
        // masukkan produk kedalam tb_cart
        $this->db->where('order_id', $order_id);
        $this->db->join('tb_stock', 'tb_stock.stock_id = tb_cart.stock_id');
        $this->db->join('tb_product', 'tb_product.product_id = tb_stock.product_id');
        $queryCart = $this->db->get('tb_cart');
        if ($queryCart->num_rows > 0) {
            $total_qty = 0;
            $subtotal = 0;
            $cart = array(null);
            foreach ($queryCart->result() as $rowCart) {
                if ($rowCart->cart_qty > 0) {
                    $cart_in_html = '<tr>
						<td align="center">' . $rowCart->product_code . '</td>
						<td colspan="2">' . $rowCart->product_name . ' - ' . $rowCart->stock_desc . '</td>
						<td align="center">' . $rowCart->cart_qty . '</td>
						';
                    if ($price_level == 1) {
                        $cart_in_html .= '<td align="center">' . $rowCart->current_special_price . '</td>
								 <td align="right">' . $rowCart->current_special_price * $rowCart->cart_qty . '</td>
							 </tr>';
                        $subtotal += $rowCart->current_special_price * $rowCart->cart_qty;
                    } else {
                        if ($price_level == 2) {
                            $cart_in_html .= '<td align="center">' . $rowCart->current_wholesale_price . '</td>
								 <td align="right">' . $rowCart->current_wholesale_price * $rowCart->cart_qty . '</td>
							 </tr>';
                            $subtotal += $rowCart->current_wholesale_price * $rowCart->cart_qty;
                        } else {
                            $cart_in_html .= '<td align="center">' . $rowCart->stock_price . '</td>
								 <td align="right">' . $rowCart->stock_price * $rowCart->cart_qty . '</td>
							 </tr>';
                            $subtotal += $rowCart->stock_price * $rowCart->cart_qty;
                        }
                    }
                    array_push($cart, $cart_in_html);
                    $total_qty = $total_qty + $rowCart->cart_qty;
                }
            }
            sort($cart);
            foreach ($cart as $row) {
                $html .= $row;
            }
        }
        // space
        $html .= '<tr>
					<td colspan="5"></td>
				  </tr>';
        // Subtotal
        $html .= '<tr>
					<td rowspan="5" colspan="2">
						<div>
							<br/>
							&nbsp; &nbsp; &nbsp; &nbsp; Hormat Kami, 
							&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Penerima, 
							
							<br/><br/><br/><br/><br/> 
							&nbsp; &nbsp; (_________________)
							&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; (_________________)
						</div>
					</td>
					<td>' . 'Subtotal : </td>
					<td align="left" colspan="2">' . $total_qty . ' pcs</td>
					<td align="right" class="nominal"> ' . $subtotal . '</td>
				  </tr>';
        // Ongkir
        $html .= '<tr>
					<td>Ongkos Kirim :</td>
					<td colspan="2"></td>
					<td align="right" class="nominal"> ' . $ongkir . '</td>
				  </tr>';
        $adjustment = '';
        if ($adjustment_nominal >= 0) {
            $adjustment = 'Biaya Tambahan';
        } else {
            $adjustment = 'Diskon';
        }
        // Adjustment
        $html .= '<tr>
					<td>' . $adjustment . '</td>
					<td colspan="2">' . $adjustment_desc . '</td>
					<td align="right"> ' . $adjustment_nominal . '</td>
				  </tr>';
        // space
        $html .= '<tr>
					<td colspan="4"></td>
				  </tr>';
        // TOTAL
        $total = $subtotal + $ongkir + $adjustment_nominal;
        $html .= '<tr>
					<td colspan="1">TOTAL :</td>
					<td colspan="2"></td>
					<td align="right" class="nominal">' . $total . '</td>
				  </tr>';
        $html .= '</table>';
        // Print text using writeHTMLCell()
        $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
        // ---------------------------------------------------------
        // Close and output PDF document
        // This method has several options, check the source code documentation for more information.
        $pdf->Output('example_002.pdf', 'I');
    }
Example #22
0
foreach ($ckhasil as $key) {
    $hasil = $key->status;
}
$obj_pdf->SetTitle($toko);
$obj_pdf->SetHeaderData("", "", "", "");
$obj_pdf->SetPrintHeader(FALSE);
$obj_pdf->SetPrintFooter(FALSE);
$obj_pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', 9));
$obj_pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$obj_pdf->SetDefaultMonospacedFont('helvetica');
$obj_pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$obj_pdf->SetMargins(10, 34, 10);
$obj_pdf->SetAutoPageBreak(FALSE, PDF_MARGIN_BOTTOM);
$obj_pdf->SetFont('helvetica', '', 10);
$obj_pdf->setFontSubsetting(FALSE);
$obj_pdf->SetDisplayMode('fullpage', 'SinglePage', 'UseNone');
$obj_pdf->AddPage();
$obj_pdf->SetFont("helvetica", '', 20);
$obj_pdf->Ln(107);
$obj_pdf->MultiCell(180, 10, $no, 0, 'C', 0, 1, '', '', true, 0, false, true, 10, 'B');
$obj_pdf->Ln(30);
$obj_pdf->SetFont($fontnama, '', 22);
$obj_pdf->MultiCell(220, 10, $nama, 0, 'C', 0, 1, '', '', true, 0, false, true, 10, 'B');
$obj_pdf->Ln(5);
$obj_pdf->SetFont('helvetica', '', 12);
$obj_pdf->MultiCell(75, 8, "", 0, 'L', 0, 0, '', '', true, 0, false, true, 8, 'B');
$obj_pdf->MultiCell(50, 8, $tgl, 0, 'L', 0, 0, '', '', true, 0, false, true, 8, 'B');
$obj_pdf->MultiCell(20, 8, "", 0, 'L', 0, 0, '', '', true, 0, false, true, 8, 'B');
$obj_pdf->MultiCell(40, 8, strtoupper($tempat), 0, 'L', 0, 1, '', '', true, 0, false, true, 9, 'B');
$obj_pdf->Ln(7);
Example #23
0
    /**
     * Generate JSON array for grid rendering
     * @param $grid_id Unique ID for grid
     */
    function render($grid_id)
    {
        // render grid for first time (non ajax), but specific grid on ajax calls
        $is_ajax = isset($_REQUEST["nd"]) || isset($_REQUEST["oper"]) || isset($_REQUEST["export"]);
        if ($is_ajax && $_REQUEST["grid_id"] != $grid_id) {
            return;
        }
        $append_by = strpos($this->options["url"], "?") === false ? "?" : "&";
        $this->options["url"] .= $append_by . "grid_id={$grid_id}";
        $this->options["editurl"] .= $append_by . "grid_id={$grid_id}";
        $this->options["cellurl"] .= $append_by . "grid_id={$grid_id}";
        if (isset($_REQUEST["subgrid"])) {
            $grid_id .= "_" . $_REQUEST["subgrid"];
        }
        // generate column names, if not defined
        if (!$this->options["colNames"]) {
            $this->set_columns();
        }
        // manage uploaded files
        foreach ($this->options["colModel"] as $col) {
            if ($col["edittype"] == "file") {
                $this->require_upload_ajax = 1;
                $this->options["add_options"]["onInitializeForm"] = "function(formid) \n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\tjQuery(formid).attr('method','POST');\n\t\t\t\t\t\t\t\t\t\t\t\t\tjQuery(formid).attr('action','');\n\t\t\t\t\t\t\t\t\t\t\t\t\tjQuery(formid).attr('enctype','multipart/form-data');\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}";
                $this->options["add_options"]["recreateForm"] = true;
                $this->options["add_options"]["afterSubmit"] = "function(r,d) { \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tajaxFileUpload('" . $col["name"] . "','" . $this->options["url"] . "'); \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn [true,'','']; \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}";
                $this->options["edit_options"]["afterSubmit"] = "function(formid) { \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tajaxFileUpload('" . $col["name"] . "','" . $this->options["url"] . "'); \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn [true,'','']; \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}";
                break;
            }
        }
        // manage uploaded files
        if (count($_FILES)) {
            $files = array_keys($_FILES);
            $fileElementName = $files[0];
            if (!empty($_FILES[$fileElementName]['error'])) {
                switch ($_FILES[$fileElementName]['error']) {
                    case '1':
                        $error = 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
                        break;
                    case '2':
                        $error = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
                        break;
                    case '3':
                        $error = 'The uploaded file was only partially uploaded';
                        break;
                    case '4':
                        $error = 'No file was uploaded.';
                        break;
                    case '6':
                        $error = 'Missing a temporary folder';
                        break;
                    case '7':
                        $error = 'Failed to write file to disk';
                        break;
                    case '8':
                        $error = 'File upload stopped by extension';
                        break;
                    case '999':
                    default:
                        $error = 'No error code avaiable';
                }
            } elseif (empty($_FILES[$fileElementName]['tmp_name']) || $_FILES[$fileElementName]['tmp_name'] == 'none') {
                $error = 'No file was uploaded..';
            } else {
                foreach ($this->options["colModel"] as $col) {
                    if ($col["edittype"] == "file" && $col["name"] == $fileElementName) {
                        $tmp_name = $_FILES[$fileElementName]["tmp_name"];
                        $name = $_FILES[$fileElementName]["name"];
                        $uploads_dir = $col["upload_dir"];
                        if (move_uploaded_file($tmp_name, "{$uploads_dir}/{$name}")) {
                            $msg = "File Uploaded";
                        } else {
                            $error = "Unable to move to desired folder {$uploads_dir}/{$name}";
                        }
                        break;
                    }
                }
            }
            echo "{";
            echo "error: '" . $error . "',\n";
            echo "msg: '" . $msg . "'\n";
            echo "}";
            die;
        }
        // for duplicate row function
        if ($_POST["id"] == "_empty") {
            $_POST["oper"] = "add";
        }
        if (isset($_POST['oper'])) {
            $op = $_POST['oper'];
            $data = $_POST;
            $id = $data['id'];
            $pk_field = $this->options["colModel"][0]["index"];
            // reformat date w.r.t mysql
            foreach ($this->options["colModel"] as $c) {
                // fix for d/m/Y date format. strtotime expects m/d/Y
                if ($c["formatoptions"]["newformat"] == "d/m/Y") {
                    $tmp = explode("/", $data[$c["index"]]);
                    $data[$c["index"]] = $tmp[1] . "/" . $tmp[0] . "/" . $tmp[2];
                }
                // put zeros for blank date field
                if (($c["formatter"] == "date" || $c["formatter"] == "datetime") && (empty($data[$c["index"]]) || $data[$c["index"]] == "//")) {
                    $data[$c["index"]] = "NULL";
                } else {
                    if ($c["isnull"] && empty($data[$c["index"]])) {
                        $data[$c["index"]] = "NULL";
                    } else {
                        if ($c["formatter"] == "date") {
                            $data[$c["index"]] = date("Y-m-d", strtotime($data[$c["index"]]));
                        } else {
                            if ($c["formatter"] == "datetime") {
                                $data[$c["index"]] = date("Y-m-d H:i:s", strtotime($data[$c["index"]]));
                            } else {
                                if ($c["formatter"] == "autocomplete") {
                                    unset($data[$c["index"]]);
                                }
                            }
                        }
                    }
                }
            }
            // handle grid operations of CRUD
            switch ($op) {
                case "autocomplete":
                    $field = $data['element'];
                    $term = $data['term'];
                    foreach ($this->options["colModel"] as $c) {
                        if ($c["index"] == $field) {
                            $sql = $c["formatoptions"]["sql"] . " WHERE {$c["formatoptions"]["search_on"]} like '{$term}%'";
                            $rs = $this->execute_query($sql);
                            $data_client = array();
                            while ($row = mysql_fetch_assoc($rs)) {
                                $arr['id'] = $row['client_id'];
                                $arr['label'] = $row['name'];
                                $arr['value'] = $row['name'];
                                $data_arr[] = $arr;
                            }
                            header('Content-type: application/json');
                            echo json_encode($data_arr);
                            die;
                        }
                    }
                    break;
                case "add":
                    unset($data['id']);
                    unset($data['oper']);
                    $update_str = array();
                    // custom onupdate event execution
                    if (!empty($this->events["on_insert"])) {
                        $func = $this->events["on_insert"][0];
                        $obj = $this->events["on_insert"][1];
                        $continue = $this->events["on_insert"][2];
                        if ($obj) {
                            call_user_method($func, $obj, array($pk_field => $id, "params" => &$data));
                        } else {
                            call_user_func($func, array($pk_field => $id, "params" => &$data));
                        }
                        if (!$continue) {
                            break;
                        }
                    }
                    foreach ($data as $k => $v) {
                        // remove any table alias from query - obseleted
                        if (strstr($k, "::") !== false) {
                            list($tmp, $k) = explode("::", $k);
                        }
                        $k = addslashes($k);
                        $v = addslashes($v);
                        $fields_str[] = "{$k}";
                        $v = $v == "NULL" ? $v : "'{$v}'";
                        $values_str[] = "{$v}";
                    }
                    $insert_str = "(" . implode(",", $fields_str) . ") VALUES (" . implode(",", $values_str) . ")";
                    $sql = "INSERT INTO {$this->table} {$insert_str}";
                    $insert_id = $this->execute_query($sql, "insert_id");
                    // custom onupdate event execution
                    if (!empty($this->events["on_after_insert"])) {
                        $func = $this->events["on_after_insert"][0];
                        $obj = $this->events["on_after_insert"][1];
                        $continue = $this->events["on_after_insert"][2];
                        if ($obj) {
                            call_user_method($func, $obj, array($pk_field => $insert_id, "params" => &$data));
                        } else {
                            call_user_func($func, array($pk_field => $insert_id, "params" => &$data));
                        }
                        if (!$continue) {
                            break;
                        }
                    }
                    // for inline row addition, return insert id to update PK of grid (e.g. order_id#33)
                    if ($id == "new_row") {
                        die($pk_field . "#" . $insert_id);
                    }
                    break;
                case "edit":
                    //pr($_POST);
                    unset($data['id']);
                    unset($data['oper']);
                    $update_str = array();
                    // custom onupdate event execution
                    if (!empty($this->events["on_update"])) {
                        $func = $this->events["on_update"][0];
                        $obj = $this->events["on_update"][1];
                        $continue = $this->events["on_update"][2];
                        if ($obj) {
                            call_user_method($func, $obj, array($pk_field => $id, "params" => &$data));
                        } else {
                            call_user_func($func, array($pk_field => $id, "params" => &$data));
                        }
                        if (!$continue) {
                            break;
                        }
                    }
                    foreach ($data as $k => $v) {
                        // remove any table alias from query - obseleted
                        if (strstr($k, "::") !== false) {
                            list($tmp, $k) = explode("::", $k);
                        }
                        $k = addslashes($k);
                        $v = addslashes($v);
                        $v = $v == "NULL" ? $v : "'{$v}'";
                        $update_str[] = "{$k}={$v}";
                    }
                    $update_str = "SET " . implode(",", $update_str);
                    if (strstr($pk_field, "::") !== false) {
                        $pk_field = explode("::", $pk_field);
                        $pk_field = $pk_field[1];
                    }
                    $sql = "UPDATE {$this->table} {$update_str} WHERE {$pk_field} = '{$id}'";
                    $this->execute_query($sql);
                    break;
                case "del":
                    // obseleted
                    if (strstr($pk_field, "::") !== false) {
                        $pk_field = explode("::", $pk_field);
                        $pk_field = $pk_field[1];
                    }
                    // custom onupdate event execution
                    if (!empty($this->events["on_delete"])) {
                        $func = $this->events["on_delete"][0];
                        $obj = $this->events["on_delete"][1];
                        $continue = $this->events["on_delete"][2];
                        if ($obj) {
                            call_user_method($func, $obj, array($pk_field => $id));
                        } else {
                            call_user_func($func, array($pk_field => $id));
                        }
                        if (!$continue) {
                            break;
                        }
                    }
                    $id = "'" . implode("','", explode(",", $id)) . "'";
                    $sql = "DELETE FROM {$this->table} WHERE {$pk_field} IN ({$id})";
                    $this->execute_query($sql);
                    break;
            }
            die;
        }
        // apply search conditions (where clause)
        $wh = "";
        if (!isset($_REQUEST['_search'])) {
            $_REQUEST['_search'] = "";
        }
        $searchOn = $this->strip($_REQUEST['_search']);
        if ($searchOn == 'true') {
            $fld = $this->strip($_REQUEST['searchField']);
            $cols = array();
            foreach ($this->options["colModel"] as $col) {
                $cols[] = $col["index"];
            }
            // quick search bar
            if (!$fld) {
                $searchstr = $this->strip($_REQUEST['filters']);
                $wh = $this->construct_where($searchstr);
            } else {
                if (in_array($fld, $cols)) {
                    $fldata = $this->strip($_REQUEST['searchString']);
                    $foper = $this->strip($_REQUEST['searchOper']);
                    // costruct where
                    $wh .= " AND " . $fld;
                    switch ($foper) {
                        case "eq":
                            if (is_numeric($fldata)) {
                                $wh .= " = " . $fldata;
                            } else {
                                $wh .= " = '" . $fldata . "'";
                            }
                            break;
                        case "ne":
                            if (is_numeric($fldata)) {
                                $wh .= " <> " . $fldata;
                            } else {
                                $wh .= " <> '" . $fldata . "'";
                            }
                            break;
                        case "lt":
                            if (is_numeric($fldata)) {
                                $wh .= " < " . $fldata;
                            } else {
                                $wh .= " < '" . $fldata . "'";
                            }
                            break;
                        case "le":
                            if (is_numeric($fldata)) {
                                $wh .= " <= " . $fldata;
                            } else {
                                $wh .= " <= '" . $fldata . "'";
                            }
                            break;
                        case "gt":
                            if (is_numeric($fldata)) {
                                $wh .= " > " . $fldata;
                            } else {
                                $wh .= " > '" . $fldata . "'";
                            }
                            break;
                        case "ge":
                            if (is_numeric($fldata)) {
                                $wh .= " >= " . $fldata;
                            } else {
                                $wh .= " >= '" . $fldata . "'";
                            }
                            break;
                        case "ew":
                            $wh .= " LIKE '%" . $fldata . "'";
                            break;
                        case "en":
                            $wh .= " NOT LIKE '%" . $fldata . "'";
                            break;
                        case "cn":
                            $wh .= " LIKE '%" . $fldata . "%'";
                            break;
                        case "nc":
                            $wh .= " NOT LIKE '%" . $fldata . "%'";
                            break;
                        case "in":
                            $wh .= " IN (" . $fldata . ")";
                            break;
                        case "ni":
                            $wh .= " NOT IN (" . $fldata . ")";
                            break;
                        case "bw":
                        default:
                            $fldata .= "%";
                            $wh .= " LIKE '" . $fldata . "'";
                            break;
                    }
                }
            }
            // setting to persist where clause in export option
            $_SESSION["jqgrid_filter"] = $wh;
        } elseif ($searchOn == 'false') {
            $_SESSION["jqgrid_filter"] = '';
        }
        // generate main json
        if (isset($_GET['jqgrid_page'])) {
            $page = $_GET['jqgrid_page'];
            // get the requested page
            $limit = $_GET['rows'];
            // get how many rows we want to have into the grid
            $sidx = $_GET['sidx'];
            // get index row - i.e. user click to sort
            $sord = $_GET['sord'];
            // get the direction
            if (!$sidx) {
                $sidx = 1;
            }
            if (!$limit) {
                $limit = 20;
            }
            $sidx = str_replace("::", ".", $sidx);
            // if export option is requested
            if (isset($_GET["export"])) {
                $arr = array();
                // by default export all
                $export_where = "";
                if ($this->options["export"]["range"] == "filtered") {
                    $export_where = $_SESSION["jqgrid_filter"];
                }
                $limit_sql = "";
                if ($this->options["export"]["paged"] == "1") {
                    $offset = $limit * $page - $limit;
                    // do not put $limit*($page - 1)
                    if ($offset < 0) {
                        $offset = 0;
                    }
                    $limit_sql = "LIMIT {$limit} OFFSET {$offset}";
                }
                if (($p = stripos($this->select_command, "GROUP BY")) !== false) {
                    $start = substr($this->select_command, 0, $p);
                    $end = substr($this->select_command, $p);
                    $SQL = $start . $export_where . $end . " ORDER BY {$sidx} {$sord} {$limit_sql}";
                } else {
                    $SQL = $this->select_command . $export_where . " ORDER BY {$sidx} {$sord} {$limit_sql}";
                }
                $result = $this->execute_query($SQL);
                // export only selected columns
                $cols_not_to_export = array();
                if ($this->options["colModel"]) {
                    foreach ($this->options["colModel"] as $c) {
                        if ($c["export"] === false) {
                            $cols_not_to_export[] = $c["name"];
                        }
                    }
                }
                foreach ($this->options["colModel"] as $c) {
                    $header[$c["name"]] = $c["title"];
                }
                $arr[] = $header;
                if ($this->con) {
                    $arr = $result->GetRows();
                } else {
                    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                        foreach ($header as $k => $v) {
                            $export_data[$k] = $row[$k];
                        }
                        $arr[] = $export_data;
                    }
                }
                if (!empty($cols_not_to_export)) {
                    $export_arr = array();
                    foreach ($arr as $arr_item) {
                        foreach ($arr_item as $k => $i) {
                            if (in_array($k, $cols_not_to_export)) {
                                unset($arr_item[$k]);
                            }
                        }
                        $export_arr[] = $arr_item;
                    }
                    $arr = $export_arr;
                }
                if (!$this->options["export"]["filename"]) {
                    $this->options["export"]["filename"] = $grid_id;
                }
                if (!$this->options["export"]["sheetname"]) {
                    $this->options["export"]["sheetname"] = ucwords($grid_id) . " Sheet";
                }
                if ($this->options["export"]["format"] == "pdf") {
                    $html = "";
                    // if customized pdf render is defined, use that
                    if (!empty($this->events["on_render_pdf"])) {
                        $func = $this->events["on_render_pdf"][0];
                        $obj = $this->events["on_render_pdf"][1];
                        if ($obj) {
                            $html = call_user_method($func, $obj, array("grid" => $this, "data" => $arr));
                        } else {
                            $html = call_user_func($func, array("grid" => $this, "data" => $arr));
                        }
                    } else {
                        $html .= "<h1>" . $this->options["export"]["heading"] . "</h1>";
                        $html .= '<table border="1" cellpadding="4" cellspacing="0">';
                        $i = 0;
                        foreach ($arr as $v) {
                            $shade = $i++ % 2 ? 'bgcolor="#efefef"' : '';
                            $html .= "<tr>";
                            foreach ($v as $d) {
                                // bold header
                                if ($i == 1) {
                                    $html .= "<td bgcolor=\"lightgrey\"><strong>{$d}</strong></td>";
                                } else {
                                    $html .= "<td {$shade}>{$d}</td>";
                                }
                            }
                            $html .= "</tr>";
                        }
                        $html .= "</table>";
                    }
                    $orientation = $this->options["export"]["orientation"];
                    if ($orientation == "landscape") {
                        $orientation = "L";
                    } else {
                        $orientation = "P";
                    }
                    $paper = $this->options["export"]["paper"];
                    // Using opensource TCPdf lib
                    // for more options visit http://www.tcpdf.org/examples.php
                    require_once 'tcpdf/config/lang/eng.php';
                    require_once 'tcpdf/tcpdf.php';
                    // create new PDF document
                    $pdf = new TCPDF($orientation, PDF_UNIT, $paper, true, 'UTF-8', false);
                    // set document information
                    $pdf->SetCreator("www.phpgrid.org");
                    $pdf->SetAuthor('www.phpgrid.org');
                    $pdf->SetTitle('TCPDF Example 002');
                    $pdf->SetSubject($this->options["caption"]);
                    $pdf->SetKeywords('www.phpgrid.org');
                    // remove default header/footer
                    $pdf->setPrintHeader(false);
                    $pdf->setPrintFooter(false);
                    // set default monospaced font
                    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
                    $pdf->setFontSubsetting(false);
                    //set margins
                    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
                    //set auto page breaks
                    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
                    //set image scale factor
                    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
                    // set some language dependent data:
                    // lines for rtl pdf generation
                    if ($this->options["direction"] == "rtl") {
                        $lg = array();
                        $lg['a_meta_charset'] = 'UTF-8';
                        $lg['a_meta_dir'] = 'rtl';
                        $lg['a_meta_language'] = 'fa';
                        $lg['w_page'] = 'page';
                    }
                    $pdf->setLanguageArray($lg);
                    // To set your custom font
                    // $fontname = $pdf->addTTFfont('/path-to-font/DejaVuSans.ttf', 'TrueTypeUnicode', '', 32);
                    // set font http://www.tcexam.org/doc/code/classTCPDF.html#afd56e360c43553830d543323e81bc045
                    $pdf->SetFont('helvetica', '', 12);
                    // add a page
                    $pdf->AddPage();
                    // output the HTML content
                    $pdf->writeHTML($html, true, false, true, false, '');
                    //Close and output PDF document
                    $pdf->Output($this->options["export"]["filename"] . ".pdf", 'I');
                    die;
                } else {
                    if ($this->options["export"]["format"] == "csv") {
                        header('Content-Type: text/csv');
                        header('Content-Disposition: attachment;filename=' . $this->options["export"]["filename"] . '.csv');
                        $fp = fopen('php://output', 'w');
                        foreach ($arr as $key => $value) {
                            fputcsv($fp, $value);
                        }
                        die;
                    } else {
                        $html = "";
                        $html .= "<table border='0' cellpadding='2' cellspacing='2'>";
                        $i = 0;
                        foreach ($arr as $v) {
                            $html .= "<tr>";
                            foreach ($v as $d) {
                                $html .= "<td>{$d}</td>";
                            }
                            $html .= "</tr>";
                        }
                        $html .= "<table>";
                        // Convert to UTF-16LE
                        $output = mb_convert_encoding($html, 'UTF-16LE', 'UTF-8');
                        // Prepend BOM
                        $output = "ÿþ" . $output;
                        header('Pragma: public');
                        header("Content-type: application/x-msexcel");
                        header('Content-Disposition: attachment;  filename="' . $this->options["export"]["filename"] . '.xls"');
                        echo $output;
                    }
                }
                die;
            }
            // make count query
            if (($p = stripos($this->select_command, "GROUP BY")) !== false) {
                $sql_count = preg_replace("/SELECT (.*) FROM/i", "SELECT 1 as c FROM", $this->select_command);
                $p = stripos($sql_count, "GROUP BY");
                $start_q = substr($sql_count, 0, $p);
                $end_q = substr($sql_count, $p);
                $sql_count = "SELECT count(*) as c FROM ({$start_q} {$wh} {$end_q}) o";
            } else {
                $sql_count = $this->select_command . $wh;
                $sql_count = "SELECT count(*) as c FROM (" . $sql_count . ") table_count";
            }
            # print_r($sql_count);
            $result = $this->execute_query($sql_count);
            if ($this->con) {
                $row = $result->FetchRow();
            } else {
                $row = mysql_fetch_array($result, MYSQL_ASSOC);
            }
            $count = $row['c'];
            // fix for oracle, alias in capitals
            if (empty($count)) {
                $count = $row['C'];
            }
            if ($count > 0) {
                $total_pages = ceil($count / $limit);
            } else {
                $total_pages = 0;
            }
            if ($page > $total_pages) {
                $page = $total_pages;
            }
            $start = $limit * $page - $limit;
            // do not put $limit*($page - 1)
            if ($start < 0) {
                $start = 0;
            }
            $responce = new stdClass();
            $responce->page = $page;
            $responce->total = $total_pages;
            $responce->records = $count;
            if (($p = stripos($this->select_command, "GROUP BY")) !== false) {
                $start_q = substr($this->select_command, 0, $p);
                $end_q = substr($this->select_command, $p);
                $SQL = "{$start_q} {$wh} {$end_q} ORDER BY {$sidx} {$sord} LIMIT {$limit} OFFSET {$start}";
            } else {
                $SQL = $this->select_command . $wh . " ORDER BY {$sidx} {$sord} LIMIT {$limit} OFFSET {$start}";
            }
            $SQL = $this->prepare_sql($SQL, $this->db_driver);
            $result = $this->execute_query($SQL);
            if ($this->con) {
                $rows = $result->GetRows();
                // simulate artificial paging for mssql
                if (count($rows) > $limit) {
                    $rows = array_slice($rows, count($rows) - $limit);
                }
            } else {
                $rows = array();
                while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                    $rows[] = $row;
                }
            }
            // custom on_data_display event execution
            if (!empty($this->events["on_data_display"])) {
                $func = $this->events["on_data_display"][0];
                $obj = $this->events["on_data_display"][1];
                $continue = $this->events["on_data_display"][2];
                if ($obj) {
                    call_user_method($func, $obj, array("params" => &$rows));
                } else {
                    call_user_func($func, array("params" => &$rows));
                }
                if (!$continue) {
                    break;
                }
            }
            foreach ($rows as $row) {
                // apply php level formatter for image url 30.12.10
                foreach ($this->options["colModel"] as $c) {
                    $col_name = $c["name"];
                    if (isset($c["default"]) && !isset($row[$col_name])) {
                        $row[$col_name] = $c["default"];
                    }
                    // link data in grid to any given url
                    if (!empty($c["default"])) {
                        // replace any param in link e.g. http://domain.com?id={id} given that, there is a $col["name"] = "id" exist
                        $row[$col_name] = $this->replace_row_data($row, $c["default"]);
                    }
                    // check conditional data
                    if (!empty($c["condition"][0])) {
                        $r = true;
                        // replace {} placeholders from connditional data
                        $c["condition"][1] = $this->replace_row_data($row, $c["condition"][1]);
                        $c["condition"][2] = $this->replace_row_data($row, $c["condition"][2]);
                        eval("\$r = " . $c["condition"][0] . ";");
                        $row[$col_name] = $r ? $c["condition"][1] : $c["condition"][2];
                    }
                    // link data in grid to any given url
                    if (!empty($c["link"])) {
                        // replace any param in link e.g. http://domain.com?id={id} given that, there is a $col["name"] = "id" exist
                        foreach ($this->options["colModel"] as $link_c) {
                            $link_row_data = urlencode($row[$link_c["name"]]);
                            $c["link"] = str_replace("{" . $link_c["name"] . "}", $link_row_data, $c["link"]);
                        }
                        if (!empty($c["linkoptions"])) {
                            $attr = $c["linkoptions"];
                        }
                        $row[$col_name] = "<a {$attr} href='{$c["link"]}'>{$row[$col_name]}</a>";
                    }
                    // render row data as "src" value of <img> tag
                    if (isset($c["formatter"]) && $c["formatter"] == "image") {
                        $attr = array();
                        foreach ($c["formatoptions"] as $k => $v) {
                            $attr[] = "{$k}='{$v}'";
                        }
                        $attr = implode(" ", $attr);
                        $row[$col_name] = "<img {$attr} src='" . $row[$col_name] . "'>";
                    }
                    // show masked data in password
                    if (isset($c["formatter"]) && $c["formatter"] == "password") {
                        $row[$col_name] = "*****";
                    }
                }
                foreach ($row as $k => $r) {
                    $row[$k] = stripslashes($row[$k]);
                }
                $responce->rows[] = $row;
            }
            echo json_encode($responce);
            die;
        }
        // if loading from array
        if (is_array($this->table)) {
            $this->options["data"] = json_encode($this->table);
            $this->options["datatype"] = "local";
            $this->actions["rowactions"] = false;
            $this->actions["add"] = false;
            $this->actions["edit"] = false;
            $this->actions["delete"] = false;
        }
        // few overides - pagination fixes
        $this->options["pager"] = '#' . $grid_id . "_pager";
        $this->options["jsonReader"] = array("repeatitems" => false, "id" => "0");
        // allow/disallow edit,del operations
        if ($this->actions["edit"] === false && $this->actions["delete"] === false || $this->options["cellEdit"] === true) {
            $this->actions["rowactions"] = false;
        }
        if ($this->actions["rowactions"] !== false) {
            // CRUD operation column
            $f = false;
            $defined = false;
            foreach ($this->options["colModel"] as &$c) {
                if ($c["name"] == "act") {
                    $defined =& $c;
                }
                if (!empty($c["width"])) {
                    $f = true;
                }
            }
            // width adjustment for row actions column
            if ($f) {
                $action_column = array("name" => "act", "align" => "center", "index" => "act", "width" => "40", "sortable" => false, "search" => false, "viewable" => false);
            } else {
                $action_column = array("name" => "act", "align" => "center", "index" => "act", "width" => "60", "sortable" => false, "search" => false, "viewable" => false);
            }
            if (!$defined) {
                $this->options["colNames"][] = "Actions";
                $this->options["colModel"][] = $action_column;
            } else {
                $defined = array_merge($action_column, $defined);
            }
        }
        $out = json_encode_jsfunc($this->options);
        $out = substr($out, 0, strlen($out) - 1);
        // create Edit/Delete - Save/Cancel column in grid
        if ($this->actions["rowactions"] !== false) {
            $act_links = array();
            if ($this->actions["edit"] !== false) {
                $act_links[] = "<a title=\"Edit this row\" href=\"javascript:void(0);\" onclick=\"jQuery(\\'#{$grid_id}\\').editRow(\\''+cl+'\\',true); jQuery(this).parent().hide(); jQuery(this).parent().next().show(); \">Edit</a>";
            }
            if ($this->actions["delete"] !== false) {
                $act_links[] = "<a title=\"Delete this row\" href=\"javascript:void(0);\" onclick=\"jQuery(\\'#{$grid_id}\\').delGridRow(\\''+cl+'\\'); \">Delete</a>";
            }
            if ($this->actions["clone"] === true) {
                $act_links[] = "<a title=\"Duplicate this row\" href=\"javascript:void(0);\" onclick=\"duplicate_row(\\'#{$grid_id}\\',\\''+cl+'\\'); \">Clone</a>";
            }
            $act_links = implode(" | ", $act_links);
            $out .= ",'gridComplete': function(){\n\t\t\t\t\t\tvar ids = jQuery('#{$grid_id}').jqGrid('getDataIDs');\n\t\t\t\t\t\tfor(var i=0;i < ids.length;i++){\n\t\t\t\t\t\t\tvar cl = ids[i];\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tbe = '{$act_links}'; \n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tse = ' <a title=\"Save this row\" href=\"javascript:void(0);\" onclick=\"if (jQuery(\\'#{$grid_id}\\').saveRow(\\''+cl+'\\')) { jQuery(this).parent().hide(); jQuery(this).parent().prev().show(); }\">Save</a>'; \n\t\t\t\t\t\t\tce = ' | <a title=\"Restore this row\" href=\"javascript:void(0);\" onclick=\"jQuery(\\'#{$grid_id}\\').restoreRow(\\''+cl+'\\'); jQuery(this).parent().hide(); jQuery(this).parent().prev().show();\">Cancel</a>'; \n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tif (ids[i] == 'new_row')\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tse = ' <a title=\"Save this row\" href=\"javascript:void(0);\" onclick=\"jQuery(\\'#{$grid_id}_ilsave\\').click(); \">Save</a>'; \n\t\t\t\t\t\t\t\tce = ' | <a title=\"Restore this row\" href=\"javascript:void(0);\" onclick=\"jQuery(\\'#{$grid_id}_ilcancel\\').click(); jQuery(this).parent().hide(); jQuery(this).parent().prev().show();\">Cancel</a>'; \n\t\t\t\t\t\t\t\tjQuery('#{$grid_id}').jqGrid('setRowData',ids[i],{act:'<span style=display:none id=\"edit_row_{$grid_id}_'+cl+'\">'+be+'</span>'+'<span id=\"save_row_{$grid_id}_'+cl+'\">'+se+ce+'</span>'});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tjQuery('#{$grid_id}').jqGrid('setRowData',ids[i],{act:'<span id=\"edit_row_{$grid_id}_'+cl+'\">'+be+'</span>'+'<span style=display:none id=\"save_row_{$grid_id}_'+cl+'\">'+se+ce+'</span>'});\n\t\t\t\t\t\t}\t\n\t\t\t\t\t}";
            /*
            // theme buttons -- not looking good
            $out .= ",'gridComplete': function(){
            			var ids = jQuery('#$grid_id').jqGrid('getDataIDs');
            			for(var i=0;i < ids.length;i++){
            				var cl = ids[i];
            				be = ' <a style=\"padding:0 0.5em;padding-left:1.6em;font-weight:normal;\" class=\"fm-button fm-button-icon-left ui-state-default ui-corner-all\" title=\"Edit this row\" onclick=\"jQuery(\'#$grid_id\').editRow('+cl+',true); jQuery(this).parent().hide(); jQuery(this).parent().next().show(); \">Edit <span class=\"ui-icon ui-icon-pencil\"></span></a>'; 
            				de = ' <a style=\"padding:0 0.5em;padding-left:1.6em;font-weight:normal;\" class=\"fm-button fm-button-icon-left ui-state-default ui-corner-all\" title=\"Delete this row\" onclick=\"jQuery(\'#$grid_id\').delRowData('+cl+'); \">Delete <span class=\"ui-icon ui-icon-close\"></span></a>';
            
            				se = ' <a style=\"padding:0 0.5em;padding-left:1.6em;font-weight:normal;\" class=\"fm-button fm-button-icon-left ui-state-default ui-corner-all\" title=\"Save this row\" onclick=\"jQuery(\'#$grid_id\').saveRow('+cl+'); jQuery(this).parent().hide(); jQuery(this).parent().prev().show();\">Save <span class=\"ui-icon ui-icon-disk\"></span></a>'; 
            				ce = ' <a style=\"padding:0 0.5em;padding-left:1.6em;font-weight:normal;\" class=\"fm-button fm-button-icon-left ui-state-default ui-corner-all\" title=\"Restore this row\" href=\"javascript:void(0);\" onclick=\"jQuery(\'#$grid_id\').restoreRow('+cl+'); jQuery(this).parent().hide(); jQuery(this).parent().prev().show();\">Cancel <span class=\"ui-icon ui-icon-cancel\"></span></a>'; 
            				
            				jQuery('#$grid_id').jqGrid('setRowData',ids[i],{act:'<div style=\"white-space:nowrap;float:left\" id=\"edit_row_'+cl+'\">'+be+de+'</div>'+'<div style=\"white-space:nowrap;float:left;display:none;\" id=\"save_row_'+cl+'\">'+se+ce+'</div>'});
            			}	
            		}";
            */
        }
        // double click editing option
        if ($this->actions["rowactions"] !== false && $this->actions["edit"] !== false && $this->options["cellEdit"] !== true) {
            if ($this->options["reloadedit"] === true) {
                $reload_after_edit = "jQuery('#{$grid_id}').jqGrid().trigger('reloadGrid',[{jqgrid_page:1}]);";
            }
            $out .= ",'ondblClickRow':function(id)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif(id && id!==lastSel){ \n\t\t\t\t\t\t\t\tjQuery('#{$grid_id}').restoreRow(lastSel); \n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t// disabled previously edit icons\n\t\t\t\t\t\t\t\tjQuery('#edit_row_{$grid_id}_'+lastSel).show();\n\t\t\t\t\t\t\t\tjQuery('#save_row_{$grid_id}_'+lastSel).hide();\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tlastSel=id; \t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tjQuery('#{$grid_id}').editRow(id, true, function(){}, function(){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tjQuery('#edit_row_{$grid_id}_'+id).show();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tjQuery('#save_row_{$grid_id}_'+id).hide();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},null,null,function(){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t// force reload grid after inline save\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{$reload_after_edit}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},null,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tfunction(){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tjQuery('#edit_row_{$grid_id}_'+id).show();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tjQuery('#save_row_{$grid_id}_'+id).hide();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t); \n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tjQuery('#edit_row_{$grid_id}_'+id).hide();\n\t\t\t\t\t\t\tjQuery('#save_row_{$grid_id}_'+id).show();\n\t\t\t\t\t\t}";
        }
        // if subgrid is there, enable subgrid feature
        if (isset($this->options["subgridurl"]) && $this->options["subgridurl"] != '') {
            // we pass two parameters
            // subgrid_id is a id of the div tag created within a table
            // the row_id is the id of the row
            // If we want to pass additional parameters to the url we can use
            // the method getRowData(row_id) - which returns associative array in type name-value
            // here we can easy construct the following
            $pass_params = "false";
            if (!empty($this->options["subgridparams"])) {
                $pass_params = "true";
            }
            $out .= ",'subGridRowExpanded': function(subgridid, id) \n\t\t\t\t\t\t\t\t\t\t\t{ \n\t\t\t\t\t\t\t\t\t\t\t\tvar data = {subgrid:subgridid, rowid:id};\n\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\tif('{$pass_params}' == 'true') {\n\t\t\t\t\t\t\t\t\t\t\t\t\tvar anm= '" . $this->options["subgridparams"] . "';\n\t\t\t\t\t\t\t\t\t\t\t\t\tanm = anm.split(',');\n\t\t\t\t\t\t\t\t\t\t\t\t\tvar rd = jQuery('#" . $grid_id . "').jqGrid('getRowData', id);\n\t\t\t\t\t\t\t\t\t\t\t\t\tif(rd) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfor(var i=0; i<anm.length; i++) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif(rd[anm[i]]) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdata[anm[i]] = rd[anm[i]];\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\tjQuery('#'+jQuery.jgrid.jqID(subgridid)).load('" . $this->options["subgridurl"] . "',data);\n\t\t\t\t\t\t\t\t\t\t\t}";
        }
        // on error
        $out .= ",'loadError': function(xhr,status, err) { \n\t\t\t\t\ttry \n\t\t\t\t\t{\n\t\t\t\t\t\tjQuery.jgrid.info_dialog(jQuery.jgrid.errors.errcap,'<div class=\"ui-state-error\">'+ xhr.responseText +'</div>', \n\t\t\t\t\t\t\t\t\t\t\t\t\tjQuery.jgrid.edit.bClose,{buttonalign:'right'});\n\t\t\t\t\t} \n\t\t\t\t\tcatch(e) { alert(xhr.responseText);}\n\t\t\t\t}\n\t\t\t\t";
        // on row selection operation
        $out .= ",'onSelectRow': function(ids) { ";
        if (isset($this->options["detail_grid_id"]) && $this->options["detail_grid_id"] != '') {
            $detail_grid_id = $this->options["detail_grid_id"];
            $d_grids = explode(",", $detail_grid_id);
            foreach ($d_grids as $detail_grid_id) {
                $detail_url = "?grid_id=" . $detail_grid_id;
                $out .= "\n\t\t\n\t\t\t\t\t\tvar data = '';\n\t\t\t\t\t\tif ('{$this->options["subgridparams"]}'.length > 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tvar anm = '" . $this->options["subgridparams"] . "';\n\t\t\t\t\t\t\tanm = anm.split(',');\n\t\t\t\t\t\t\tvar rd = jQuery('#" . $grid_id . "').jqGrid('getRowData', ids);\n\t\t\t\t\t\t\tif(rd) {\n\t\t\t\t\t\t\t\tfor(var i=0; i<anm.length; i++) {\n\t\t\t\t\t\t\t\t\tif(rd[anm[i]]) {\n\t\t\t\t\t\t\t\t\t\tdata += '&' + anm[i] + '=' + rd[anm[i]];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\tif(ids == null) \n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tids=0;\n\t\t\t\t\t\t\tif(jQuery('#" . $detail_grid_id . "').jqGrid('getGridParam','records') >0 )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tjQuery('#" . $detail_grid_id . "').jqGrid('setGridParam',{url:'" . $detail_url . "&rowid='+ids+data,editurl:'" . $detail_url . "&rowid='+ids,jqgrid_page:1});\n\t\t\t\t\t\t\t\tjQuery('#" . $detail_grid_id . "').trigger('reloadGrid',[{jqgrid_page:1}]);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} \n\t\t\t\t\t\telse \n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tjQuery('#" . $detail_grid_id . "').jqGrid('setGridParam',{url:'" . $detail_url . "&rowid='+ids+data,editurl:'" . $detail_url . "&rowid='+ids,jqgrid_page:1});\n\t\t\t\t\t\t\tjQuery('#" . $detail_grid_id . "').trigger('reloadGrid',[{jqgrid_page:1}]);\t\t\t\n\t\t\t\t\t\t}\n\t\t\t\t\t\t";
            }
        }
        if (!empty($this->events["js_on_select_row"])) {
            $out .= "if (typeof({$this->events["js_on_select_row"]}) != 'undefined') {$this->events["js_on_select_row"]}(ids);";
        }
        // closing of select row events
        $out .= "}";
        // on load complete operation
        $out .= ",'loadComplete': function(ids) { ";
        $out .= "if(ids.rows) jQuery.each(ids.rows,function(i){";
        if (count($this->conditional_css)) {
            foreach ($this->conditional_css as $value) {
                if ($value["op"] == "cn") {
                    $out .= "\n\t\t\t\t\t\t\t\tif (this.{$value[column]}.toLowerCase().indexOf('{$value[value]}'.toLowerCase()) != -1)\n\t\t\t\t\t\t\t \t{\n\t\t\t\t\t\t\t \t\tjQuery('tr.jqgrow:eq('+i+')').removeClass('ui-widget-content').css({{$value[css]}});\n\t\t\t\t\t\t\t \t}";
                } else {
                    if ($value["op"] == "eq") {
                        $out .= "\n\t\t\t\t\t\t\t\tif (this.{$value[column]}.toLowerCase() == '{$value[value]}'.toLowerCase())\n\t\t\t\t\t\t\t \t{\n\t\t\t\t\t\t\t \t\tjQuery('tr.jqgrow:eq('+i+')').removeClass('ui-widget-content').css({{$value[css]}});\n\t\t\t\t\t\t\t \t}";
                    } else {
                        if ($value["op"] == "<" || $value["op"] == "<=" || $value["op"] == ">" || $value["op"] == ">=" || $value["op"] == "!=") {
                            $out .= "\n\t\t\t\t\t\t\t\tif (this.{$value[column]} {$value["op"]} {$value[value]})\n\t\t\t\t\t\t\t \t{\n\t\t\t\t\t\t\t \t\tjQuery('tr.jqgrow:eq('+i+')').removeClass('ui-widget-content').css({{$value[css]}});\n\t\t\t\t\t\t\t \t}";
                        } else {
                            if (empty($value["op"]) && !empty($value["column"]) && !empty($value["css"])) {
                                $out .= "\n\t\t\t\t\t\t\t \t{\n\t\t\t\t\t\t\t \t\tjQuery('td[aria-describedby={$grid_id}_{$value["column"]}]').removeClass('ui-widget-content').css({{$value[css]}});\n\t\t\t\t\t\t\t \t}";
                            }
                        }
                    }
                }
            }
        }
        $out .= "});";
        // closing of load complete events
        $out .= "}";
        // closing of param list
        $out .= "}";
        // Geneate HTML/JS code
        ob_start();
        ?>
			<table id="<?php 
        echo $grid_id;
        ?>
"></table> 
			<div id="<?php 
        echo $grid_id . "_pager";
        ?>
"></div> 

			<script>
			var phpgrid = jQuery("#<?php 
        echo $grid_id;
        ?>
");
			var phpgrid_pager = jQuery("#<?php 
        echo $grid_id . "_pager";
        ?>
");
			jQuery(document).ready(function(){
				<?php 
        echo $this->render_js($grid_id, $out);
        ?>
			});	
			</script>	
		<?php 
        return ob_get_clean();
    }
Example #24
0
    public function cetakDaftar($idrefstore = null)
    {
        ini_set('memory_limit', '512M');
        //akses dari web
        if ($idrefstore == null) {
            $store = $this->orm->refstore->where('idrefstore', $_SESSION['user']['idrefstore'])->fetch();
            $data = $this->orm->deliveryorder->where('idrefstore', $_SESSION['user']['idrefstore'])->order('tanggaldo DESC');
            $email = $_SESSION['user']['email'];
        } else {
            $store = $this->orm->refstore->where('idrefstore', $idrefstore)->fetch();
            $data = $this->orm->deliveryorder->where('idrefstore', $idrefstore)->order('tanggaldo DESC');
            $email = $this->input->post('email');
        }
        $image_store = ($store['image_file'] == "" or $store['image_file'] == NULL) ? "./front_assets/img/bizon_inventory.jpg" : "./uploads/stores/" . $store['image_file'];
        $this->load->library('TCPDF');
        // create new PDF document
        $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, 'A4', true, 'UTF-8', false);
        // set document information
        $pdf->SetCreator(WEB_TITLE);
        $pdf->SetAuthor($email);
        $pdf->SetTitle("Delivery Order - " . $store['nama']);
        $pdf->SetSubject($store['nama']);
        // set default monospaced font
        $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
        //set margins
        $pdf->SetMargins(5, 10, 5);
        $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
        $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
        //set auto page breaks
        $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
        //set auto page breaks
        $pdf->SetAutoPageBreak(TRUE, 80);
        //set auto page breaks
        $pdf->SetAutoPageBreak(TRUE, 80);
        //set image scale factor
        $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
        // ---------------------------------------------------------
        // set default font subsetting mode
        $pdf->setFontSubsetting(true);
        // Set font
        // dejavusans is a UTF-8 Unicode font, if you only need to
        // print standard ASCII chars, you can use core fonts like
        // helvetica or times to reduce file size.
        // use the font
        $pdf->SetFont('times', '', 10, '', false);
        // Add a page
        $pdf->AddPage('L');
        // Set some content to print
        $html = '
            
<style>
body {
letter-spacing:5px;
}      
</style> 
	<style type="text/css">
.rotate-text
 {

/* Safari */
-webkit-transform: rotate(-90deg);

/* Firefox */
-moz-transform: rotate(-90deg);

/* IE */
-ms-transform: rotate(-90deg);

/* Opera */
-o-transform: rotate(-90deg);

/* Internet Explorer */
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);

}
.border-table{
	border:0.5px solid #000;
		
}

table {
padding-top:2px;
}

</style>
	
<body>
<table><tr><td>
<h3>Daftar Delivery Order - ' . $store['nama'] . '</h3>
</td><td style="text-align:right">
<img src="' . $image_store . '" width="150"><br/></td></tr></table>

  <table border="1">
 <tr><th style="text-align: center;" width="60"> No </th><th width="200" style="text-align: center;"> Nomor DO </th><th style="text-align: center;" width="140"> Tanggal DO </th><td style="text-align: center; "width="210"> Pelanggan </td><td style="text-align: center; "width="150"> Status </td><td style="text-align: center; "width="200"> Disetujui Oleh </td></tr>
';
        $no = 1;
        foreach ($data as $row) {
            $html .= "<tr><td>" . $no . "</td><td>" . $row['nomordo'] . "</td><td>" . Tanggal::formatDate($row['tanggaldo']) . "</td><td>" . $row->pelanggan['namapelanggan'] . "</td><td>" . $row['status'] . "</td><td>" . $row['disetujui'] . "</td></tr>";
            $no++;
        }
        $html .= '</table>
</body>';
        //print_r($html); exit;
        // Print text using writeHTMLCell()
        $pdf->writeHTMLCell($w = 0, $h = 0, $x = '', $y = '', $html, $border = 0, $ln = 1, $fill = 0, $reseth = true, $align = '', $autopadding = true);
        //$pdf->writeHTML($html, true, 0, true, true);
        // ---------------------------------------------------------
        // Close and output PDF document
        // This method has several options, check the source code documentation for more information.
        $pdf->Output("Daftar Delivery Order", 'I');
        //============================================================+
        // END OF FILE
        //============================================================+
    }
 protected function download_pdf($html)
 {
     $this->load->library('tcpdf');
     $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor('Nicola Asuni');
     $pdf->SetTitle('TCPDF Example 001');
     $pdf->SetSubject('TCPDF Tutorial');
     $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 001', PDF_HEADER_STRING, array(0, 64, 255), array(0, 64, 128));
     $pdf->setFooterData(array(0, 64, 0), array(0, 64, 128));
     $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
     $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
     $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
         require_once dirname(__FILE__) . '/lang/eng.php';
         $pdf->setLanguageArray($l);
     }
     $pdf->setFontSubsetting(true);
     $pdf->SetFont('dejavusans', '', 14, '', true);
     $pdf->AddPage();
     $pdf->setTextShadow(array('enabled' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 1, 'blend_mode' => 'Normal'));
     $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
     $pdf->Output('example_001.pdf', 'I');
 }
Example #26
0
 public function generateTcpdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape = false, $aProperties = array())
 {
     require_once PATH_THIRDPARTY . "tcpdf" . PATH_SEP . "config" . PATH_SEP . "lang" . PATH_SEP . "eng.php";
     require_once PATH_THIRDPARTY . "tcpdf" . PATH_SEP . "tcpdf.php";
     $nrt = array("\n", "\r", "\t");
     $nrthtml = array("(n /)", "(r /)", "(t /)");
     $strContentAux = str_replace($nrt, $nrthtml, $sContent);
     $sContent = null;
     while (preg_match("/^(.*)<font([^>]*)>(.*)\$/i", $strContentAux, $arrayMatch)) {
         $str = trim($arrayMatch[2]);
         $strAttribute = null;
         if (!empty($str)) {
             $strAux = $str;
             $str = null;
             while (preg_match("/^(.*)([\"'].*[\"'])(.*)\$/", $strAux, $arrayMatch2)) {
                 $strAux = $arrayMatch2[1];
                 $str = str_replace(" ", "__SPACE__", $arrayMatch2[2]) . $arrayMatch2[3] . $str;
             }
             $str = $strAux . $str;
             //Get attributes
             $strStyle = null;
             $array = explode(" ", $str);
             foreach ($array as $value) {
                 $arrayAux = explode("=", $value);
                 if (isset($arrayAux[1])) {
                     $a = trim($arrayAux[0]);
                     $v = trim(str_replace(array("__SPACE__", "\"", "'"), array(" ", null, null), $arrayAux[1]));
                     switch (strtolower($a)) {
                         case "color":
                             $strStyle = $strStyle . "color: {$v};";
                             break;
                         case "face":
                             $strStyle = $strStyle . "font-family: {$v};";
                             break;
                         case "size":
                             $arrayPt = array(0, 8, 10, 12, 14, 18, 24, 36);
                             $strStyle = $strStyle . "font-size: " . $arrayPt[intval($v)] . "pt;";
                             break;
                         case "style":
                             $strStyle = $strStyle . "{$v};";
                             break;
                         default:
                             $strAttribute = $strAttribute . " {$a}=\"{$v}\"";
                             break;
                     }
                 }
             }
             if ($strStyle != null) {
                 $strAttribute = $strAttribute . " style=\"{$strStyle}\"";
             }
         }
         $strContentAux = $arrayMatch[1];
         $sContent = "<span" . $strAttribute . ">" . $arrayMatch[3] . $sContent;
     }
     $sContent = $strContentAux . $sContent;
     $sContent = str_ireplace("</font>", "</span>", $sContent);
     $sContent = str_replace($nrthtml, $nrt, $sContent);
     // define Save file
     $sOutput = 2;
     $sOrientation = $sLandscape == false ? PDF_PAGE_ORIENTATION : 'L';
     $sMedia = isset($aProperties['media']) ? $aProperties['media'] : PDF_PAGE_FORMAT;
     $sLang = defined('SYS_LANG') ? SYS_LANG : 'en';
     // create new PDF document
     $pdf = new TCPDF($sOrientation, PDF_UNIT, $sMedia, true, 'UTF-8', false);
     // set document information
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor($aFields['USR_USERNAME']);
     $pdf->SetTitle('Processmaker');
     $pdf->SetSubject($sFilename);
     $pdf->SetCompression(true);
     $margins = $aProperties['margins'];
     $margins["left"] = $margins["left"] >= 0 ? $margins["left"] : PDF_MARGIN_LEFT;
     $margins["top"] = $margins["top"] >= 0 ? $margins["top"] : PDF_MARGIN_TOP;
     $margins["right"] = $margins["right"] >= 0 ? $margins["right"] : PDF_MARGIN_RIGHT;
     $margins["bottom"] = $margins["bottom"] >= 0 ? $margins["bottom"] : PDF_MARGIN_BOTTOM;
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $pdf->SetLeftMargin($margins['left']);
     $pdf->SetTopMargin($margins['top']);
     $pdf->SetRightMargin($margins['right']);
     $pdf->SetAutoPageBreak(true, $margins['bottom']);
     $oServerConf =& serverConf::getSingleton();
     // set some language dependent data:
     $lg = array();
     $lg['a_meta_charset'] = 'UTF-8';
     $lg['a_meta_dir'] = $oServerConf->isRtl($sLang) ? 'rtl' : 'ltr';
     $lg['a_meta_language'] = $sLang;
     $lg['w_page'] = 'page';
     //set some language-dependent strings
     $pdf->setLanguageArray($lg);
     if (isset($aProperties['pdfSecurity'])) {
         $pdfSecurity = $aProperties['pdfSecurity'];
         $userPass = G::decrypt($pdfSecurity['openPassword'], $sUID);
         $ownerPass = $pdfSecurity['ownerPassword'] != '' ? G::decrypt($pdfSecurity['ownerPassword'], $sUID) : null;
         $permissions = explode("|", $pdfSecurity['permissions']);
         $pdf->SetProtection($permissions, $userPass, $ownerPass);
     }
     // ---------------------------------------------------------
     // set default font subsetting mode
     $pdf->setFontSubsetting(true);
     // Set font
     // dejavusans is a UTF-8 Unicode font, if you only need to
     // print standard ASCII chars, you can use core fonts like
     // helvetica or times to reduce file size.
     //$pdf->SetFont('dejavusans', '', 14, '', true);
     // Detect chinese, japanese, thai
     if (preg_match('/[\\x{30FF}\\x{3040}-\\x{309F}\\x{4E00}-\\x{9FFF}\\x{0E00}-\\x{0E7F}]/u', $sContent, $matches)) {
         $pdf->SetFont('kozminproregular');
     }
     // Add a page
     // This method has several options, check the source code documentation for more information.
     $pdf->AddPage();
     // set text shadow effect
     //$pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));
     // Print text using writeHTMLCell()
     // $pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
     if (mb_detect_encoding($sContent) == 'UTF-8') {
         $sContent = mb_convert_encoding($sContent, 'HTML-ENTITIES', 'UTF-8');
     }
     $doc = new DOMDocument('1.0', 'UTF-8');
     $doc->loadHtml($sContent);
     $pdf->writeHTML($doc->saveXML(), false, false, false, false, '');
     // ---------------------------------------------------------
     // Close and output PDF document
     // This method has several options, check the source code documentation for more information.
     //$pdf->Output('example_00.pdf', 'I');
     //$pdf->Output('/home/hector/processmaker/example_00.pdf', 'D');
     switch ($sOutput) {
         case 0:
             // Vrew browser
             $pdf->Output($sPath . $sFilename . '.pdf', 'I');
             break;
         case 1:
             // Donwnload
             $pdf->Output($sPath . $sFilename . '.pdf', 'D');
             break;
         case 2:
             // Save file
             $pdf->Output($sPath . $sFilename . '.pdf', 'F');
             break;
     }
 }
Example #27
0
 /**
  * Save PHPExcel to file
  *
  * @param 	string 		$pFilename    Filename for the saved file
  * @throws 	Exception
  */
 public function save($pFilename = null)
 {
     // garbage collect
     $this->_phpExcel->garbageCollect();
     $saveArrayReturnType = PHPExcel_Calculation::getArrayReturnType();
     PHPExcel_Calculation::setArrayReturnType(PHPExcel_Calculation::RETURN_ARRAY_AS_VALUE);
     // Open file
     $fileHandle = fopen($pFilename, 'w');
     if ($fileHandle === false) {
         throw new Exception("Could not open file {$pFilename} for writing.");
     }
     // Set PDF
     $this->_isPdf = true;
     // Build CSS
     $this->buildCSS(true);
     // Generate HTML
     $html = '';
     //$html .= $this->generateHTMLHeader(false);
     $html .= $this->generateSheetData();
     //$html .= $this->generateHTMLFooter();
     // Default PDF paper size
     $paperSize = 'LETTER';
     //	Letter	(8.5 in. by 11 in.)
     // Check for paper size and page orientation
     if (is_null($this->getSheetIndex())) {
         $orientation = $this->_phpExcel->getSheet(0)->getPageSetup()->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE ? 'L' : 'P';
         $printPaperSize = $this->_phpExcel->getSheet(0)->getPageSetup()->getPaperSize();
         $printMargins = $this->_phpExcel->getSheet(0)->getPageMargins();
     } else {
         $orientation = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE ? 'L' : 'P';
         $printPaperSize = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize();
         $printMargins = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageMargins();
     }
     //	Override Page Orientation
     if (!is_null($this->_orientation)) {
         $orientation = $this->_orientation == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE ? 'L' : 'P';
     }
     //	Override Paper Size
     if (!is_null($this->_paperSize)) {
         $printPaperSize = $this->_paperSize;
     }
     if (isset(self::$_paperSizes[$printPaperSize])) {
         $paperSize = self::$_paperSizes[$printPaperSize];
     }
     // Create PDF
     $pdf = new TCPDF($orientation, 'pt', $paperSize);
     $pdf->setFontSubsetting(false);
     //	Set margins, converting inches to points (using 72 dpi)
     $pdf->SetMargins($printMargins->getLeft() * 72, $printMargins->getTop() * 72, $printMargins->getRight() * 72);
     $pdf->SetAutoPageBreak(true, $printMargins->getBottom() * 72);
     //		$pdf->setHeaderMargin($printMargins->getHeader() * 72);
     //		$pdf->setFooterMargin($printMargins->getFooter() * 72);
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $pdf->AddPage();
     // Set the appropriate font
     $pdf->SetFont($this->_font);
     $pdf->writeHTML($html);
     // Document info
     $pdf->SetTitle($this->_phpExcel->getProperties()->getTitle());
     $pdf->SetAuthor($this->_phpExcel->getProperties()->getCreator());
     $pdf->SetSubject($this->_phpExcel->getProperties()->getSubject());
     $pdf->SetKeywords($this->_phpExcel->getProperties()->getKeywords());
     $pdf->SetCreator($this->_phpExcel->getProperties()->getCreator());
     // Write to file
     fwrite($fileHandle, $pdf->output($pFilename, 'S'));
     // Close file
     fclose($fileHandle);
     PHPExcel_Calculation::setArrayReturnType($saveArrayReturnType);
 }
 function index()
 {
     $this->load->model(array('payment_schedule_customer_model', 'receipt_model'));
     $this->load->library('form_validation');
     $this->load->model('project_model');
     $this->load->helper('csv');
     $this->load->helper('download');
     $data['projects'] = $this->db->get('project')->result();
     $this->form_validation->set_rules('project', 'Date', 'trim|required');
     if ($this->form_validation->run() == FALSE) {
         $data['dues'] = array();
         $this->load->view('reports/sales_report', $data);
     } else {
         $dues = array();
         $project_selected = $this->input->post('project');
         $from_date_db = $this->input->post('from_date');
         $from_date_db = date('Y-m-d', strtotime($from_date_db));
         $to_date_db = $this->input->post('to_date');
         $to_date_db = date('Y-m-d', strtotime($to_date_db));
         $due_report = array();
         $this->db->select('customer_file.id,customer_file.purchase_cost,contact.name,' . 'project.name as project,availability_chart_unit.unit_name as unit_name,' . 'contact.phone,contact.phone_2,contact.phone_3,contact.email,contact.email_2,' . 'customer_file.booking_date,customer_file.area,customer_file.rate,' . 'sales_region.name as sales_region, user.full_name as sales_person');
         $this->db->from('customer_file');
         $this->db->join('contact', 'customer_file.customer_id=contact.id');
         $this->db->join('project', 'customer_file.project_id=project.id');
         $this->db->join('availability_chart_unit', 'availability_chart_unit.id=customer_file.unit_id');
         $this->db->join('sales_region', 'sales_region.id=customer_file.sales_region', 'left');
         $this->db->join('user', 'user.id=customer_file.sales_person', 'left');
         $this->db->where('customer_file.project_id', $project_selected);
         $this->db->where('customer_file.booking_date >=', $from_date_db);
         $this->db->where('customer_file.booking_date <=', $to_date_db);
         $customers = $this->db->get()->result();
         foreach ($customers as $customer) {
             $due_report[$customer->id] = array();
             $due_report[$customer->id]['client_name'] = $customer->name;
             $due_report[$customer->id]['phone'] = implode(array_filter(array($customer->phone, $customer->phone_2, $customer->phone_3)), ', ');
             $due_report[$customer->id]['email'] = implode(array_filter(array($customer->email, $customer->email_2)), ', ');
             $due_report[$customer->id]['project'] = $customer->project . '-' . $customer->unit_name;
             $due_report[$customer->id]['purchase_cost'] = $customer->purchase_cost;
             $due_report[$customer->id]['booking_date'] = $customer->booking_date;
             $due_report[$customer->id]['area'] = $customer->area;
             $due_report[$customer->id]['rate'] = $customer->rate;
             $due_report[$customer->id]['sales_region'] = $customer->sales_region;
             $due_report[$customer->id]['sales_person'] = $customer->sales_person;
             $due_report[$customer->id]['total_tax'] = 0;
             $due_report[$customer->id]['due_amount'] = 0;
             $due_report[$customer->id]['total_pri'] = 0;
             $due_report[$customer->id]['total_tx'] = 0;
             $due_report[$customer->id]['total_amt'] = 0;
             $due_report[$customer->id]['total_units'] = $this->db->where('project_id', $customer->id)->count_all_results('customer_file');
             $customer_file_id = $customer->id;
             $actual_payment_schedule = $this->payment_schedule_customer_model->list_schedule_customer_file_actual_active($customer_file_id);
             $additional_payment_schedule = $this->payment_schedule_customer_model->list_schedule_customer_file_additional_active($customer_file_id);
             $receipts = $this->receipt_model->list_cleared_receipt_customer_file($customer_file_id);
             $this->db->select('tax_type.name,tax_master.id');
             $this->db->from('tax_type');
             $this->db->join('tax_master', 'tax_master.tax_type_id=tax_type.id');
             $this->db->join('customer_file_tax', 'customer_file_tax.tax_id=tax_master.id');
             $this->db->where('customer_file_tax.customer_file_id', $customer_file_id);
             $customer_tax = $this->db->get()->result();
             $total_due_amount = 0;
             // Actual Due
             foreach ($actual_payment_schedule as $schedule) {
                 $total_due_amount += $schedule->due_amount;
                 $ttax = 0;
                 $ttax_bal = 0;
                 foreach ($customer_tax as $cs2) {
                     $tax_amount = 0;
                     $tax_amount_bal = 0;
                     if ($schedule->status == 1) {
                         if ($schedule->due_amount - $schedule->amount_paid == 0) {
                             $this->db->select('SUM(receipt_split_up_tax.tax_amount) as tax_amount');
                             $this->db->from('receipt_split_up_tax');
                             $this->db->join('receipt_split_up', 'receipt_split_up.id=receipt_split_up_tax.receipt_split_up_id');
                             $this->db->where(array('receipt_split_up.installment_id' => $schedule->id, 'receipt_split_up_tax.tax_id' => $cs2->id));
                             $applicale_tax = $this->db->get()->first_row();
                             if ($applicale_tax->tax_amount) {
                                 $ttax += $applicale_tax->tax_amount;
                             }
                         } elseif ($schedule->amount_paid == 0) {
                             $this->db->select('tax_slab.tax_percentage as tax_percentage');
                             $this->db->from('tax_slab');
                             $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id');
                             $this->db->where(array('tax_master_id' => $cs2->id, 'from_date <=' => $to_date_db, 'to_date >=' => $to_date_db, 'tax_slab_cost_head.cost_head_id' => $schedule->payment_type));
                             $applicale_tax = $this->db->get()->first_row();
                             if (!empty($applicale_tax->tax_percentage)) {
                                 $tax_amount = $schedule->due_amount / 100 * $applicale_tax->tax_percentage;
                                 $ttax += $tax_amount;
                             }
                         } else {
                             // tax on paid amount start
                             $this->db->select('SUM(receipt_split_up_tax.tax_amount) as tax_amount');
                             $this->db->from('receipt_split_up_tax');
                             $this->db->join('receipt_split_up', 'receipt_split_up.id=receipt_split_up_tax.receipt_split_up_id');
                             $this->db->where(array('receipt_split_up.installment_id' => $schedule->id, 'receipt_split_up_tax.tax_id' => $cs2->id));
                             $applicale_tax_paid = $this->db->get()->first_row();
                             // tax on paid amount end
                             //tax on balance amount start
                             $this->db->select('tax_slab.tax_percentage as tax_percentage');
                             $this->db->from('tax_slab');
                             $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id');
                             $this->db->where(array('tax_master_id' => $cs2->id, 'from_date <=' => $to_date_db, 'to_date >=' => $to_date_db, 'tax_slab_cost_head.cost_head_id' => $schedule->payment_type));
                             $tax_percentage_balance = $this->db->get()->first_row();
                             //tax on balance amount end
                             $tax_amount_balance = ($schedule->due_amount - $schedule->amount_paid) / 100 * $tax_percentage_balance->tax_percentage;
                             $applicale_tax_amount = $applicale_tax_paid->tax_amount + $tax_amount_balance;
                             $ttax += $applicale_tax_amount;
                         }
                     }
                 }
                 $due_report[$customer->id]['total_tax'] += $ttax;
                 $due_report[$customer->id]['due_amount'] += $schedule->due_amount;
             }
             // Additional Due
             foreach ($additional_payment_schedule as $schedule_additional) {
                 $total_due_amount_additional += $schedule_additional->due_amount;
                 $ttax_additional = 0;
                 $ttax_bal = 0;
                 foreach ($customer_tax as $cs2) {
                     $tax_amount_add = 0;
                     $tax_amount_bal_add = 0;
                     if ($schedule_additional->status == 1) {
                         if ($schedule_additional->due_amount - $schedule_additional->amount_paid == 0) {
                             $this->db->select('SUM(receipt_split_up_tax.tax_amount) as tax_amount');
                             $this->db->from('receipt_split_up_tax');
                             $this->db->join('receipt_split_up', 'receipt_split_up.id=receipt_split_up_tax.receipt_split_up_id');
                             $this->db->where(array('receipt_split_up.installment_id' => $schedule_additional->id, 'receipt_split_up_tax.tax_id' => $cs2->id));
                             $applicale_tax_add = $this->db->get()->first_row();
                             if ($applicale_tax_add->tax_amount) {
                                 $ttax_additional += $applicale_tax_add->tax_amount;
                             }
                         } elseif ($schedule_additional->amount_paid == 0) {
                             $this->db->select('tax_slab.tax_percentage as tax_percentage');
                             $this->db->from('tax_slab');
                             $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id');
                             $this->db->where(array('tax_master_id' => $cs2->id, 'from_date <=' => $to_date_db, 'to_date >=' => $to_date_db, 'tax_slab_cost_head.cost_head_id' => $schedule_additional->payment_type));
                             $applicale_tax_add = $this->db->get()->first_row();
                             if (!empty($applicale_tax_add->tax_percentage)) {
                                 $tax_amount_add = $schedule_additional->due_amount / 100 * $applicale_tax_add->tax_percentage;
                                 $ttax_additional += $tax_amount_add;
                             }
                         } else {
                             // tax on paid amount start
                             $this->db->select('SUM(receipt_split_up_tax.tax_amount) as tax_amount');
                             $this->db->from('receipt_split_up_tax');
                             $this->db->join('receipt_split_up', 'receipt_split_up.id=receipt_split_up_tax.receipt_split_up_id');
                             $this->db->where(array('receipt_split_up.installment_id' => $schedule_additional->id, 'receipt_split_up_tax.tax_id' => $cs2->id));
                             $applicale_tax_paid_bal = $this->db->get()->first_row();
                             // tax on paid amount end
                             //tax on balance amount start
                             $this->db->select('tax_slab.tax_percentage as tax_percentage');
                             $this->db->from('tax_slab');
                             $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id');
                             $this->db->where(array('tax_master_id' => $cs2->id, 'from_date <=' => $to_date_db, 'to_date >=' => $to_date_db, 'tax_slab_cost_head.cost_head_id' => $schedule_additional->payment_type));
                             $tax_percentage_balance = $this->db->get()->first_row();
                             //tax on balance amount end
                             $tax_amount_balance_add = ($schedule_additional->due_amount - $schedule_additional->amount_paid) / 100 * $tax_percentage_balance->tax_percentage;
                             $applicale_tax_amount_add = $applicale_tax_paid_bal->tax_amount + $tax_amount_balance_add;
                             $ttax_additional += $applicale_tax_amount_add;
                         }
                     }
                 }
                 $due_report[$customer->id]['total_tax_additional'] += $ttax_additional;
                 $due_report[$customer->id]['due_amount_additional'] += $schedule_additional->due_amount;
             }
             //Receipts
             foreach ($receipts as $b => $receipt) {
                 $due_report[$customer->id]['total_pri'] += $receipt->principle_amount;
                 $due_report[$customer->id]['total_tx'] += $receipt->amount_paid - $receipt->principle_amount;
                 $due_report[$customer->id]['total_amt'] += $receipt->amount_paid;
             }
         }
         //print_r($due_report);
         //exit();
         if (isset($_POST['generate_pdf'])) {
             $this->load->library('Pdf');
             $this->db->select('company.name,project.project_type');
             $this->db->from('company');
             $this->db->join('project', 'project.company_id=company.id');
             $this->db->join('customer_file', 'customer_file.project_id=project.id');
             $company_details = $this->db->get()->first_row();
             $pdf = new TCPDF('P', PDF_UNIT, 'A4', true, 'UTF-8', false);
             $pdf->SetCreator(PDF_CREATOR);
             $pdf->SetTitle('Receipt');
             //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, '', '', array(0, 64, 255), array(255, 255, 255));
             $pdf->SetPrintFooter(false);
             $pdf->setPrintHeader(false);
             //$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
             //$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
             $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
             $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
             //$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
             //$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
             $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
             $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
             if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
                 require_once dirname(__FILE__) . '/lang/eng.php';
                 $pdf->setLanguageArray($l);
             }
             $pdf->setFontSubsetting(true);
             $pdf->SetFont('dejavusans', '', 7, '', true);
             $pdf->AddPage();
             $pdf->writeHTMLCell(211, 17, '0', 10, '<h2 style="text-align:center;">' . $company_details->name . '</h2>', 0, 1, 0, true, '', true);
             $style = array('width' => 0.1, 'color' => array(0, 0, 0));
             $pdf->Line(0, 25, 220, 25, $style);
             $pdf->writeHTMLCell(0, 0, '', '', '<h2 style="text-align:center;">Sales Report</h2>', 0, 1, 0, true, '', true);
             $style = array('width' => 0.1, 'color' => array(0, 0, 0));
             $pdf->Line(0, 35, 220, 35, $style);
             $pdf->writeHTMLCell(50, 0, 10, 40, '<strong style="text-align:center;">Period : ' . date('M Y', strtotime($from_date_db)) . ' - ' . date('M Y', strtotime($to_date_db)) . '</strong>', 0, 1, 0, true, '', true);
             $pdf->writeHTMLCell(35, 0, 168, 40, '<strong style="text-align:center;">Date : ' . date('d-m-Y') . '</strong>', 0, 1, 0, true, '', true);
             $html .= '<tr><td></td><td><td/></tr></table><br /><br /><br /><br />';
             $html .= '<table  border="1" cellpadding="5" cellspacing = "0" width = "100%" nobr="true"><thead><tr>';
             $html .= '<th width="30">No.</th>';
             $html .= '<th width="65">Booking Date</th>';
             $html .= '<th width="75">Client Name</th>';
             $html .= '<th width="60">Project</th>';
             $html .= '<th width="40">Rate</th>';
             $html .= '<th width="65">Agreement Value</th>';
             $html .= '<th width="65">Due Amount</th>';
             $html .= '<th width="65">Total Collection</th>';
             $html .= '<th width="65">Balance Due</th>';
             $html .= '<th width="60">Sales Region</th>';
             $html .= '<th width="60">Sales Person</th>';
             $html .= '</tr>';
             $html .= '</thead><tbody>';
             $total_sale_amount = 0;
             $total_due_amount = 0;
             $total_due_amount_additional = 0;
             $total_due_tax = 0;
             $total_due_tax_additional = 0;
             $total_collection = 0;
             $total_balance = 0;
             foreach ($due_report as $due) {
                 $total_sale_amount += $due['purchase_cost'];
                 $total_due_amount += $due['due_amount'];
                 $total_due_amount_additional += $due['due_amount_additional'];
                 $total_due_tax += $due['total_tax'];
                 $total_due_tax_additional += $due['total_tax_additional'];
                 $total_collection += $due['total_amt'];
                 $total_balance += $due['due_amount'] + $due['total_tax'] + $due['due_amount_additional'] + $due['total_tax_additional'] - $due['total_amt'];
                 $html .= '<tr>';
                 $html .= '<td width="30">' . ($n + 1) . '</td>';
                 $html .= '<td width="65">' . date('d-m-Y', strtotime($due['booking_date'])) . '</td>';
                 $html .= '<td width="75">' . $due['client_name'] . '</td>';
                 $html .= '<td width="60">' . $due['project'] . '</td>';
                 $html .= ' <td width="40">' . number_format($due['rate']) . '</td>';
                 $html .= ' <td width="65">' . number_format($due['purchase_cost']) . '</td>';
                 $html .= ' <td width="65">' . number_format($due['due_amount_additional'] + $due['total_tax_additional'] + ($due['due_amount'] + $due['total_tax'])) . '</td>';
                 $html .= ' <td width="65">' . number_format($due['total_amt']) . '</td>';
                 $html .= ' <td width="65">' . number_format($due['due_amount'] + $due['total_tax'] + $due['due_amount_additional'] + $due['total_tax_additional'] - $due['total_amt']) . '</td>';
                 $html .= '<td width="60">' . $due['sales_region'] . '</td>';
                 $html .= '<td width="60">' . $due['sales_person'] . '</td>';
                 $html .= '</tr>';
                 $n++;
             }
             $html .= '</tbody>';
             $html .= '<tfoot>';
             $html .= '<tr style="font-weight: bolder">';
             $html .= '<td colspan="5"></td>';
             $html .= '<td>' . number_format($purchase_cost) . '</td>';
             $html .= '<td>' . number_format($due_amount + $due_amount_additional + $total_tax + $total_tax_additional) . '</td>';
             $html .= '<td>' . number_format($total_amt_collected) . '</td>';
             $html .= '<td>' . number_format($due_amount + $due_amount_additional + $total_tax + $total_tax_additional - $total_amt_collected) . '</td>';
             $html .= '<td></td>';
             $html .= '<td></td>';
             $html .= '</tr>';
             $html .= '</tfoot>';
             $html .= '</table><br /><br />';
             //echo $html;
             //exit();
             $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
             $pdf->Output('receipt.pdf', 'I');
         } elseif (isset($_POST['generate_csv'])) {
             $csv_array = array();
             $csv_array_line = array();
             $csv_array_line[] = 'No.';
             $csv_array_line[] = 'Date of Booking';
             $csv_array_line[] = 'Client Name';
             $csv_array_line[] = 'Contact Number';
             $csv_array_line[] = 'Email';
             $csv_array_line[] = 'Area';
             $csv_array_line[] = 'Rate';
             $csv_array_line[] = 'Project';
             $csv_array_line[] = 'Sale Value';
             $csv_array_line[] = 'Prin Amt Due';
             $csv_array_line[] = 'Tax Amt Due';
             $csv_array_line[] = 'Additional Due';
             $csv_array_line[] = 'Additional Due Tax';
             $csv_array_line[] = 'Total Due';
             $csv_array_line[] = 'Total Collection';
             $csv_array_line[] = 'Balance Due';
             $csv_array_line[] = 'Sales Region';
             $csv_array_line[] = 'Sales Person';
             $csv_array[] = $csv_array_line;
             foreach ($due_report as $due) {
                 $csv_array_line = array();
                 $csv_array_line[] = $n + 1;
                 $csv_array_line[] = date('d-m-Y', strtotime($due['booking_date']));
                 $csv_array_line[] = $due['client_name'];
                 $csv_array_line[] = $due['phone'];
                 $csv_array_line[] = $due['email'];
                 $csv_array_line[] = $due['area'];
                 $csv_array_line[] = $due['rate'];
                 $csv_array_line[] = $due['project'];
                 $csv_array_line[] = $due['due_amount'] + $due['due_amount_additional'];
                 $csv_array_line[] = $due['due_amount'];
                 $csv_array_line[] = $due['total_tax'];
                 $csv_array_line[] = $due['due_amount_additional'];
                 $csv_array_line[] = $due['total_tax_additional'];
                 $csv_array_line[] = $due['due_amount_additional'] + $due['total_tax_additional'] + ($due['due_amount'] + $due['total_tax']);
                 $csv_array_line[] = $due['total_amt'];
                 $csv_array_line[] = $due['due_amount'] + $due['total_tax'] + $due['due_amount_additional'] + $due['total_tax_additional'] - $due['total_amt'];
                 $csv_array_line[] = $due['sales_region'];
                 $csv_array_line[] = $due['sales_person'];
                 $csv_array[] = $csv_array_line;
             }
             echo array_to_csv($csv_array, 'due_letter.csv');
             exit;
         } else {
             $data['due_report'] = $due_report;
             $data['from_date_selected'] = $this->input->post('from_date');
             $data['to_date_selected'] = $this->input->post('to_date');
             $data['project_selected'] = $this->input->post('project');
             $this->load->view('reports/sales_report', $data);
         }
     }
 }
    public function make_pdf($order_id, $save_to_file = true)
    {
        // 获取订单记录
        $order = M('loan_order')->find($order_id);
        if (!$order) {
            $this->error = '找不到此订单!';
            return false;
        }
        $order_id = $order['id'];
        // 获取用户协议记录
        $contract = M('loan_user_contract')->find($order['uid']);
        if (!$contract) {
            $this->error = '找不到用户的认证资料!';
            return false;
        }
        $order_auth = M('loan_order_auth')->where(['order_id' => $order['id']])->getField('auth_id,url');
        import('Common.Util.Tcpdf.Tcpdf');
        $pdf = new \TCPDF('P', 'MM', 'A4', true, 'UTF-8', false);
        $pdf->SetCreator('指尖分期');
        $pdf->SetAuthor('广西云尚文化产业投资有限公司');
        $pdf->SetTitle('指尖分期协议-' . $order['realname'] . '-' . $order_id);
        $pdf->SetSubject($order['realname']);
        $pdf->SetKeywords('指尖分期,' . $order['realname'] . ',' . $order_id);
        $pdf->setFooterData(array(0, 0, 0), array(122, 122, 122));
        $pdf->setPrintHeader(false);
        $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
        // set margins
        $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
        $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
        $pdf->SetFooterMargin(8);
        $pdf->SetY(-10);
        $pdf->SetFont('stsongstdlight', 'N', 9);
        // set auto page breaks
        $pdf->SetAutoPageBreak(TRUE, 9);
        // set image scale factor
        $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
        // ---------------------------------------------------------
        // set default font subsetting mode
        $pdf->setFontSubsetting(true);
        // Set font
        // dejavusans is a UTF-8 Unicode font, if you only need to
        // print standard ASCII chars, you can use core fonts like
        // helvetica or times to reduce file size.
        $pdf->SetFont('stsongstdlight', '', 11);
        // Add a page
        // This method has several options, check the source code documentation for more information.
        $pdf->AddPage();
        $cur_month = strtotime(date('Y-m-01', $order['created']));
        $next_month = strtotime('+1 month', $cur_month);
        $first_repay_day = date('Y-m-', $next_month) . date('d', $order['created']);
        $first_repay_day = min($first_repay_day, date('Y-m-t', $next_month));
        if (in_array($order['type'], [2, 3, 4])) {
            // 线下/现金/全网分期
            $html = '<p style="text-align:right;font-weight:bold;">协议编号:<span style="border-bottom:1px solid #000;">' . $order_id . '</span></p>
<h1 style="text-align:center">商品分期服务协议</h1>
<p>甲方:广西云尚文化产业投资有限公司<br>客服电话:400-611-8602</p>
<p>乙方:<span style="border-bottom:1px solid #000;">' . $order['realname'] . '</span><br>身份证:<span style="border-bottom:1px solid #000;">' . $contract['id_card'] . '</span><br>手机号:<span style="border-bottom:1px solid #000;">' . $order['mobile'] . '</span></p>
<p>根据《中华人民共和国合同法》等法律法规,双方本着平等自愿,公平公正,协商一致等原则,达成如下协议:</p>
<h2>第一条 分期服务</h2>
<table border="1">
  <tr><td>商品/服务名称</td><td>' . $order['title'] . '</td><td>乙方分期金额</td><td>' . $order['loan_money'] . '元</td></tr>
  <tr><td>分期月数</td><td>' . $order['month'] . '个月</td><td>每月还款金额[本金+服务费]</td><td>' . $order['month_total'] . '元</td></tr>
  <tr><td>每月还款日</td><td>每月' . date('j', $order['created']) . '日</td><td>首期还款日</td><td>' . $first_repay_day . '</td></tr>
  <tr><td colspan="4">此订单为代购,指尖分期商城只提供分期服务,不对商品/服务质量负责。</td></tr>
</table>
<h2>第二条 甲方权利和义务</h2>
<ol><li>甲方应按照本合同约定为乙方提供指尖分期网站的相关服务。
</li><li>妥善保管乙方在甲方所运营的指尖分期网站上注册登记的个人信息。
</li><li>甲方不承担乙方使用标的物过程中乙方或第三方人身伤亡或者财产损失所引发的责任。
</li></ol>
			
<h2>第三条 乙方权利和义务</h2>
<ol>
  <li>乙方应将本合同第一条所约定的每月还款金额在每月还款日前足额支付给甲方。</li>
  <li>乙方应提供有效期内的本人证件以及其他甲方要求的信息,由甲方工作人员核对。</li>
</ol>
<h2>第四条 违约责任</h2>
<ol><li>乙方若未能依本合同的约定按时支付总价款,则须向甲方支付滞纳金,滞纳金的金额按所有未偿还价款总金额的【1%】为日息进行征收(不到1日按1日计算)。
</li><li>如乙方累计拖欠甲方费用达【10】日或以上则甲方可通过书面、短信、电子邮件、电话等任一形式通知乙方解除本合同,乙方全部未偿还价款必须在自本合同解除日起【3】日内一次付清。同时,乙方必须在自本合同解除【3】日内,另向甲方支付合同未偿还价款总金额的【30%】作为违约金。如乙方延迟支付未偿还价款和违约金,每延迟【1】日,甲方有权加收应付款项(未偿还价款加违约金之和)的【1%】作为滞纳金,甲方已收取的款项(包括但不限于:首付、首期分期款、滞纳金等)不再退回。
</li><li>如乙方于还款期内有逾期还款的行为,甲方将有权免去给予乙方的任何优惠措施(包括但不限于0服务费等),在追款中产生的费用(包括但不限于调查费、诉讼费、律师费、往返路费、餐费、住宿费、电话费等)全部由乙方承担。
</li><li>乙方应保证其向甲方提供的信息真实有效、合法合规且全面,不存在任何虚假、遗漏或重大错误。如甲方发现乙方提供虚假或错误信息,将视为合同欺诈,乙方必须在自甲方发现之日起【3】日内付清全部未偿还价款,并另向甲方支付本合同总价款的【10%】作为赔偿金,已经收取的款项不予退回。如乙方延迟支付未偿还价款和赔偿金,每延迟【1】日,甲方有权向乙方加收应付款项(未偿还价款加赔偿金之和)的【1%】作为滞纳金。
</li><li>乙方如有违约行为,且出现逃避支付、拒绝沟通或者恶意拖欠还款等情形的甲方有权将乙方的个人信息及其信用信息向征信机构披露,并有权在其网站上公布相关信息,在本条所述违约情形下,甲方亦有权将乙方违约的相关信息及乙方信息向所在学校及管理机构如实披露,由此引发的后果,甲方不承担任何法律责任。
</li><li>若在规定期限内乙方无法偿还所欠款项,甲方向乙方提供有偿的兼职劳务岗位帮助乙方实现劳务代偿欠款,如乙方拒绝劳务代偿又无法支付欠款,甲方有权要求乙方一次性还清欠款与及约定的违约金、滞纳金。
</li><li>如果乙方违约,乙方同意甲方或其聘请的第三方催收机构以直接上门、邮件、电话或其他方式向乙方进行追款,乙方不得提出任何异议,由此产生的一切费用由乙方承担。
</li></ol>
<h2>第五条 授权委托</h2>
<ol><li>现乙方委托甲方在第三方平台或机构上向第三方平台或机构出借人(以下简称“出借人”)融资,融资金额即为签订合同时乙方尚未支付的金额(“应付款项”)。融资款项仅限于支付该应付款项,甲方指定乙方作为融资款项的收款人。同时甲方在此过程中为乙方提供咨询、办理融资申请、还款管理等服务。经甲方推荐且前述融资匹配成功后,甲方、乙方、第三方平台、出借人等将以电子文本形式签订《分期服务协议》。
</li><li>乙方同意,甲方作为受托融资人处理如下:<br />
(1)自主决定实现融资的理财平台,并确定有意向的资金提供方(“投资人”);<br />
(2)应理财平台或投资人的要求,在合理范围内向投资人和理财平台披露乙方资信材料,包括但不限于年龄,性别,锁在学校,专业等,并视情况引入增信措施。<br />
(3)代收乙方应向投资人及理财平台的融资款及融资成本费。<br />
(4)代收本条第(3)项的相关费用。<br />
(5)代收乙方从投资人出融到的款项,并向标的物销售方代付款项。<br />
(6)指定接收涉及本条第(3)项及第(5)项的账户。<br />
(7)以乙方名义签署和理财平台、投资人以及甲方作为保证人的《商品分期服务协议》;<br />
(8)代理在第三方平台融资所需的手续。
</li><li>乙方授权甲方及/或第三方平台在约定还款日期代扣应支付给出借人的本金、利息以及支付给第三方平台的费用,并按《商品分期服务协议》约定的还款日代付给相关个人及公司。
</li><li>授权甲方及/或第三方平台及/或相关金融机构在相关机构平台(包括但不限于:金融机构、工商、税务、征信机构、人民法院等)查询、确认乙方相关的征信信息。
</li><li>乙方同意并授权甲方在审核其信用记录、后续风险管理、提供综合化服务的过程中,向依法设立的征信机构及气体相关合法机构了解和查询其资产、资讯、个人信用信息等情况,并保留相关资料。
</li><li>乙方同意采用电子文本形式制作《商品分期服务协议》,且乙方确认已仔细阅读及不可撤销的同意该电子协议的全部条款,一经甲方及/或第三方平台通过该第三方平台账户在第三方平台对《商品分期服务协议》进行确认,相关协议即对乙方形成效力,乙方同意受《商品分期服务协议》相关内容的约束。
</li><li>授权甲方代为接收第三方平台向乙方发送的相关信息(包括但不限于分期服务协议电子文本,债权转让协议通知等),该等信息在发送至甲方时即视为送达乙方。
</li><li>乙方授权甲方可将上述委托事项部分或全部转委托。
</li><li>委托期限:自合同生效之日起至甲方或第三方平台代乙方在第三方平台签署电子文本形式的《商品分期服务协议》项下确认乙方的义务全部履行完毕之日止。
</li><li>特别委托:乙方在此不可撤销的承诺,乙方在《商品分期服务协议》项下乙方未全部履行完毕之前,不得单方面解除或终止上述对甲方及/或第三方平台的委托。
</li><li>若乙方未按照相关融资协议履行偿还义务,甲方进行预期垫付融资款项以及融资利息和理财平台费用,自甲方代偿之日起,乙方应当在【3】个工作日内向甲方偿还上诉款项,并向甲方支付违约金:代偿款项*【1】%*逾期天数,为避免疑义,逾期天数自乙方预期偿还代偿融资款项及融资利息或服务费之日起计算,至乙方向甲方偿还该等代偿融资款项及融资利息或服务费以及违约金之日截止。
</li></ol>
<h2>第六条 争议解决</h2>
<p>本协议在履行过程中如发生争议,双方应协商解决;协商不成,可向仲裁机构提交仲裁申请进行调解,不愿调解的甲乙双方均可向甲乙方所在地的法院起诉。</p>
<h2>第七条 合同的变更和解除</h2>
<p>除合同另有约定外,任何一方均不得单方面变更或解除本合同,对本合同或其他条款内容有任何补充、修改或变更,必须经过双方事先达成书面协议方可作实。
</p>
<h2>第八条 合同的生效</h2>
<ol>
  <li>本协议以电子文本形式生成。
</li><li>本协议的任何修改、补充均须以甲方平台电子文本形式做出。
</li><li>乙方委托甲方保管所有与本协议有关的书面文件或电子信息。
</li><li>双方确认,本协议由乙方通过甲方运营的网站、手机客户端以网络在线点击确认的方式进行签署。
</li><li>乙方下单分期时阅读本协议电子版并点击确认,甲方派工作人员当面与乙方确认订单信息与协议内容,乙方确认所有事项后签署订单确认书并由乙方本人手持订单确认书拍照作为不可抵赖的法律证据由甲方保存。
</li><li>甲方审核完订单信息后完成订单付款操作后本协议自动生效,协议双方不得有异议。
</li>
</ol>
<h2>第九条 银行代扣</h2>
<p>为方便甲、乙双方关于商品分期付款费用的收缴工作,经双方协商,除支付宝支付外也可选用指定银行卡支付,银行卡指定开户行在广西区内为桂林银行,乙方在桂林银行开设预定代扣银行卡,每个月在还款期限达到前将资金划拨到该银行卡,用于支付乙方每月的分期付款费用。
</p>
<br />
<p style="font-weight:bold;">乙方承诺:本人保证所提供的个人资料信息真实,有效。并依据详细了解所填合同章程,业务协议,功能说明及责任条款,同意接受相关业务章程和协议的约束,以上条款本人已经确认并知晓。</p>
<br />';
            $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
            // $pdf->AddPage ();
            $img = $order_auth[9] ? '<img src="' . $order_auth[9] . '?imageMogr2/auto-orient/thumbnail/2000x2000" border="0" />' : '';
            $pdf->writeHTMLCell(0, 0, '', '', '<h2>第十条 附件资料</h2><div style="border:1px solid #000;padding:10px;margin-bottom:10px;"><p style="text-align:center;">(手持确认书)</p>' . $img . '</div>', 0, 1, 0, true, '', true);
        } else {
            // 线上代购
            $html = '<p style="text-align:right;font-weight:bold;">协议编号:<span style="border-bottom:1px solid #000;">' . $order_id . '</span></p>
<h1 style="text-align:center">商品分期服务协议</h1>
<p>甲方:广西云尚文化产业投资有限公司<br>客服电话:400-611-8602</p>
<p>乙方:<span style="border-bottom:1px solid #000;">' . $order['realname'] . '</span><br>身份证:<span style="border-bottom:1px solid #000;">' . $contract['id_card'] . '</span><br>手机号:<span style="border-bottom:1px solid #000;">' . $order['mobile'] . '</span></p>
<p>根据《中华人民共和国合同法》等法律法规,双方本着平等自愿,公平公正,协商一致等原则,达成如下协议:</p>
<h2>第一条 分期服务</h2>
<table border="1">
  <tr><td>商品/服务名称</td><td>' . $order['title'] . '</td><td>乙方分期金额</td><td>' . $order['loan_money'] . '元</td></tr>
  <tr><td>分期月数</td><td>' . $order['month'] . '个月</td><td>每月还款金额[本金+服务费]</td><td>' . $order['month_total'] . '元</td></tr>
  <tr><td>每月还款日</td><td>每月' . date('j', $order['created']) . '日</td><td>首期还款日</td><td>' . $first_repay_day . '</td></tr>
</table>
<h2>第二条 甲方权利和义务</h2>
<ol><li>甲方应按照本合同约定为乙方提供指尖分期网站的相关服务。
</li><li>妥善保管乙方在甲方所运营的指尖分期网站上注册登记的个人信息。
</li><li>甲方不承担乙方使用标的物过程中乙方或第三方人身伤亡或者财产损失所引发的责任。
</li></ol>
			
<h2>第三条 乙方权利和义务</h2>
<ol>
  <li>乙方应将本合同第一条所约定的每月还款金额在每月还款日前足额支付给甲方。</li>
  <li>乙方应提供有效期内的本人证件以及其他甲方要求的信息,由甲方工作人员核对。</li>
</ol>
<h2>第四条 违约责任</h2>
<ol><li>乙方若未能依本合同的约定按时支付总价款,则须向甲方支付滞纳金,滞纳金的金额按所有未偿还价款总金额的【1%】为日息进行征收(不到1日按1日计算)。
</li><li>如乙方累计拖欠甲方费用达【10】日或以上则甲方可通过书面、短信、电子邮件、电话等任一形式通知乙方解除本合同,乙方全部未偿还价款必须在自本合同解除日起【3】日内一次付清。同时,乙方必须在自本合同解除【3】日内,另向甲方支付合同未偿还价款总金额的【30%】作为违约金。如乙方延迟支付未偿还价款和违约金,每延迟【1】日,甲方有权加收应付款项(未偿还价款加违约金之和)的【1%】作为滞纳金,甲方已收取的款项(包括但不限于:首付、首期分期款、滞纳金等)不再退回。
</li><li>如乙方于还款期内有逾期还款的行为,甲方将有权免去给予乙方的任何优惠措施(包括但不限于0服务费等),在追款中产生的费用(包括但不限于调查费、诉讼费、律师费、往返路费、餐费、住宿费、电话费等)全部由乙方承担。
</li><li>乙方应保证其向甲方提供的信息真实有效、合法合规且全面,不存在任何虚假、遗漏或重大错误。如甲方发现乙方提供虚假或错误信息,将视为合同欺诈,乙方必须在自甲方发现之日起【3】日内付清全部未偿还价款,并另向甲方支付本合同总价款的【10%】作为赔偿金,已经收取的款项不予退回。如乙方延迟支付未偿还价款和赔偿金,每延迟【1】日,甲方有权向乙方加收应付款项(未偿还价款加赔偿金之和)的【1%】作为滞纳金。
</li><li>乙方如有违约行为,且出现逃避支付、拒绝沟通或者恶意拖欠还款等情形的甲方有权将乙方的个人信息及其信用信息向征信机构披露,并有权在其网站上公布相关信息,在本条所述违约情形下,甲方亦有权将乙方违约的相关信息及乙方信息向所在学校及管理机构如实披露,由此引发的后果,甲方不承担任何法律责任。
</li><li>若在规定期限内乙方无法偿还所欠款项,甲方向乙方提供有偿的兼职劳务岗位帮助乙方实现劳务代偿欠款,如乙方拒绝劳务代偿又无法支付欠款,甲方有权要求乙方一次性还清欠款与及约定的违约金、滞纳金。
</li><li>如果乙方违约,乙方同意甲方或其聘请的第三方催收机构以直接上门、邮件、电话或其他方式向乙方进行追款,乙方不得提出任何异议,由此产生的一切费用由乙方承担。
</li></ol>
<h2>第五条 授权委托</h2>
<ol><li>现乙方委托甲方在第三方平台或机构上向第三方平台或机构出借人(以下简称“出借人”)融资,融资金额即为签订合同时乙方尚未支付的金额(“应付款项”)。融资款项仅限于支付该应付款项,甲方指定乙方作为融资款项的收款人。同时甲方在此过程中为乙方提供咨询、办理融资申请、还款管理等服务。经甲方推荐且前述融资匹配成功后,甲方、乙方、第三方平台、出借人等将以电子文本形式签订《分期服务协议》。
</li><li>乙方同意,甲方作为受托融资人处理如下:<br />
(1)自主决定实现融资的理财平台,并确定有意向的资金提供方(“投资人”);<br />
(2)应理财平台或投资人的要求,在合理范围内向投资人和理财平台披露乙方资信材料,包括但不限于年龄,性别,锁在学校,专业等,并视情况引入增信措施。<br />
(3)代收乙方应向投资人及理财平台的融资款及融资成本费。<br />
(4)代收本条第(3)项的相关费用。<br />
(5)代收乙方从投资人出融到的款项,并向标的物销售方代付款项。<br />
(6)指定接收涉及本条第(3)项及第(5)项的账户。<br />
(7)以乙方名义签署和理财平台、投资人以及甲方作为保证人的《商品分期服务协议》;<br />
(8)代理在第三方平台融资所需的手续。
</li><li>乙方授权甲方及/或第三方平台在约定还款日期代扣应支付给出借人的本金、利息以及支付给第三方平台的费用,并按《商品分期服务协议》约定的还款日代付给相关个人及公司。
</li><li>授权甲方及/或第三方平台及/或相关金融机构在相关机构平台(包括但不限于:金融机构、工商、税务、征信机构、人民法院等)查询、确认乙方相关的征信信息。
</li><li>乙方同意并授权甲方在审核其信用记录、后续风险管理、提供综合化服务的过程中,向依法设立的征信机构及气体相关合法机构了解和查询其资产、资讯、个人信用信息等情况,并保留相关资料。
</li><li>乙方同意采用电子文本形式制作《商品分期服务协议》,且乙方确认已仔细阅读及不可撤销的同意该电子协议的全部条款,一经甲方及/或第三方平台通过该第三方平台账户在第三方平台对《商品分期服务协议》进行确认,相关协议即对乙方形成效力,乙方同意受《商品分期服务协议》相关内容的约束。
</li><li>授权甲方代为接收第三方平台向乙方发送的相关信息(包括但不限于分期服务协议电子文本,债权转让协议通知等),该等信息在发送至甲方时即视为送达乙方。
</li><li>乙方授权甲方可将上述委托事项部分或全部转委托。
</li><li>委托期限:自合同生效之日起至甲方或第三方平台代乙方在第三方平台签署电子文本形式的《商品分期服务协议》项下确认乙方的义务全部履行完毕之日止。
</li><li>特别委托:乙方在此不可撤销的承诺,乙方在《商品分期服务协议》项下乙方未全部履行完毕之前,不得单方面解除或终止上述对甲方及/或第三方平台的委托。
</li><li>若乙方未按照相关融资协议履行偿还义务,甲方进行预期垫付融资款项以及融资利息和理财平台费用,自甲方代偿之日起,乙方应当在【3】个工作日内向甲方偿还上诉款项,并向甲方支付违约金:代偿款项*【1】%*逾期天数,为避免疑义,逾期天数自乙方预期偿还代偿融资款项及融资利息或服务费之日起计算,至乙方向甲方偿还该等代偿融资款项及融资利息或服务费以及违约金之日截止。
</li></ol>
<h2>第六条 争议解决</h2>
<p>本协议在履行过程中如发生争议,双方应协商解决;协商不成,可向仲裁机构提交仲裁申请进行调解,不愿调解的甲乙双方均可向甲乙方所在地的法院起诉。</p>
<h2>第七条 合同的变更和解除</h2>
<p>除合同另有约定外,任何一方均不得单方面变更或解除本合同,对本合同或其他条款内容有任何补充、修改或变更,必须经过双方事先达成书面协议方可作实。
</p>
<h2>第八条 合同的生效</h2>
<ol>
  <li>本协议以电子文本形式生成。
</li><li>本协议的任何修改、补充均须以甲方平台电子文本形式做出。
</li><li>乙方委托甲方保管所有与本协议有关的书面文件或电子信息。
</li><li>双方确认,本协议由乙方通过甲方运营的网站、手机客户端以网络在线点击确认的方式进行签署。
</li><li>乙方下单分期时阅读本协议电子版并点击确认,甲方派工作人员当面与乙方确认订单信息与协议内容,乙方确认所有事项后签署订单确认书并由乙方本人手持订单确认书拍照作为不可抵赖的法律证据由甲方保存。
</li><li>甲方审核完订单信息后完成订单付款操作后本协议自动生效,协议双方不得有异议。
</li>
</ol>
<h2>第九条 银行代扣</h2>
<p>为方便甲、乙双方关于商品分期付款费用的收缴工作,经双方协商,除支付宝支付外也可选用指定银行卡支付,银行卡指定开户行在广西区内为桂林银行,乙方在桂林银行开设预定代扣银行卡,每个月在还款期限达到前将资金划拨到该银行卡,用于支付乙方每月的分期付款费用。
</p>
<h2>第十条 退换货政策以第三方销售商退换货政策为准。</h2>
<ol>
  <li>因下述原因造成乙方未能预期收到标的物或标的物不符合乙方的预期的,由乙方自行承担相关风险,且不影响乙方在本合同项下履行向甲方支付代理服务费的义务:
(1)乙方提供的购物信息不实或者有误;<br />
(2)乙方未及时签收标的物;<br />
(3)标的物本身的质量、物流、售后等可归咎于销售方、物流公司或者其他第三方的问题等。乙方因本条上述原因退货产生的费用(包含但不限于:对应账单生成到取消期间甲方的服务费、运费、第三方销售商的手续费等)均由乙方承担。乙方退换货成功,相关款项退到甲方账户后,此费用根据甲方网站公布的规定生成新账单,乙方不得因退换货成功而拒绝承担此费用。
</li><li>乙方在签署本合同后应及时接收标的物。如乙方因故不能接收标的物的,应与第三方销售商或相关物流协商延期。如协商不成或乙方延期提取标的物超过【3】日的,应视为放弃,乙方不得要求甲方退还任何款项,并需在甲方处置标的物后的【3】日内向甲方支付本合同总价款的1%作为服务费及因此产生的费用。
</li><li>在标的物交付后【7】日内,乙方应对标的物进行全面检查,如存在非乙方原因引起的产品瑕疵或质量问题,乙方可自行联系第三方销售商处理,甲方在此过程中可给予配合。
</li><li>对于标的物在交付后使用过程中产生的产品瑕疵或质量问题,乙方可按照标的物相关的三包条款处理,如质保期限已过或者乙方要求处理的商品与第三方销售商所售商品的序列号不符(以第三方销售商后台记录为准),乙方应自行承担相关责任。
</li><li>标的物的交付时间,以第三方销售商及相关物流商的签收日期为准。标的物交付后,标的物毁损灭失的风险由乙方承担。如乙方将标的物转交第三方,由此产生的风险一概与甲方无关。以上风险承担的规定不影响各自对违约责任及其他责任的主张。
</li>
</ol>
<br />
<p style="font-weight:bold;margin:0 20px;">乙方承诺:本人保证所提供的个人资料信息真实,有效。并依据详细了解所填合同章程,业务协议,功能说明及责任条款,同意接受相关业务章程和协议的约束,以上条款本人已经确认并知晓。</p>
<br />';
            $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
            // $pdf->AddPage ();
            $img = $order_auth[9] ? '<img src="' . $order_auth[9] . '?imageMogr2/auto-orient/thumbnail/2000x2000" border="0" />' : '';
            $pdf->writeHTMLCell(0, 0, '', '', '<h2>第十一条 附件资料</h2><div style="border:1px solid #000;padding:10px;margin-bottom:10px;"><p style="text-align:center;">(手持确认书)</p>' . $img . '</div>', 0, 1, 0, true, '', true);
        }
        // ---------------------------------------------------------
        $base_dir = THINK_PATH . '../../static.zjfq';
        $save_dir = '/order/contract/' . date('Ymd') . '/';
        $filename = md5('order' . $order_id . 'contract') . '.pdf';
        $save_dir_all = $base_dir . $save_dir;
        is_dir($save_dir_all) or mkdir($save_dir_all, 0777, true);
        if ($save_to_file) {
            $pdf->Output($save_dir_all . $filename, 'F');
            unset($pdf);
            return $save_dir . $filename;
        } else {
            $pdf->Output($save_dir_all . $filename, 'I');
            unset($pdf);
            return;
        }
        unset($pdf);
    }
 /**
  * generate_pdf.
  */
 public function generate_pdf($get_by_order_id = 0)
 {
     if (!isset($_GET['pdf_invoice']) && 0 == $get_by_order_id) {
         return;
     }
     $order_id = 0 == $get_by_order_id ? $_GET['pdf_invoice'] : $get_by_order_id;
     if (!is_user_logged_in() && 0 == $get_by_order_id) {
         return;
     }
     if (!current_user_can('administrator') && !is_shop_manager() && get_current_user_id() != intval(get_post_meta($order_id, '_customer_user', true)) && 0 == $get_by_order_id) {
         return;
     }
     // Include the main TCPDF library (search for installation path).
     //require_once('tcpdf_include.php');
     require_once 'lib/tcpdf_min/tcpdf.php';
     // create new PDF document
     $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     // set document information
     $pdf->SetCreator(PDF_CREATOR);
     //$pdf->SetAuthor( 'Algoritmika Ltd.' );
     $pdf->SetTitle('Invoice');
     $pdf->SetSubject('Invoice PDF');
     $pdf->SetKeywords('invoice, PDF');
     // set default header data
     // TODO 2014.09.21
     //		$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING, array(0,64,255), array(0,64,128));
     //$pdf->SetHeaderData( get_option( 'wcj_pdf_invoices_seller_logo_url' ), 30, get_option( 'wcj_pdf_invoices_header_title' ), get_option( 'wcj_pdf_invoices_header_string' ), array(0,64,255), array(0,64,128));
     $pdf->SetPrintHeader(false);
     $pdf->setFooterData(array(0, 64, 0), array(0, 64, 128));
     //$pdf->SetPrintFooter(false);
     // set header and footer fonts
     $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
     $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
     // set default monospaced font
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     // set margins
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
     $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     // set auto page breaks
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     // set image scale factor
     $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     /*
     // set some language-dependent strings (optional)
     if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
     	require_once(dirname(__FILE__).'/lang/eng.php');
     	$pdf->setLanguageArray($l);
     }
     */
     // ---------------------------------------------------------
     // set default font subsetting mode
     $pdf->setFontSubsetting(true);
     // Set font
     // dejavusans is a UTF-8 Unicode font, if you only need to
     // print standard ASCII chars, you can use core fonts like
     // helvetica or times to reduce file size.
     $pdf->SetFont(apply_filters('wcj_get_option_filter', 'dejavusans', get_option('wcj_pdf_invoices_general_font_family', 'dejavusans')), '', apply_filters('wcj_get_option_filter', 8, get_option('wcj_pdf_invoices_general_font_size')), '', true);
     // Add a page
     // This method has several options, check the source code documentation for more information.
     $pdf->AddPage();
     if ('yes' === get_option('wcj_pdf_invoices_general_font_shadowed', 'yes')) {
         // set text shadow effect
         $pdf->setTextShadow(array('enabled' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 1, 'blend_mode' => 'Normal'));
     }
     $html = $this->get_invoice_html($order_id);
     // Print text using writeHTMLCell()
     $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
     // ---------------------------------------------------------
     // Close and output PDF document
     // This method has several options, check the source code documentation for more information.
     //		$the_order = new WC_Order( $order_id );
     //		$order_number = $the_order->get_order_number();
     /**/
     if ($get_by_order_id > 0) {
         return $pdf->Output('invoice-' . $order_id . '.pdf', 'S');
     } else {
         $file_name = 'invoice-' . $order_id . '.pdf';
         $file_path = sys_get_temp_dir() . '/' . $file_name;
         $result = file_put_contents($file_path, $pdf->Output('', 'S'));
         //echo $pdf->Output( '', 'S' );
         if (isset($_GET['save_pdf_invoice']) && '1' == $_GET['save_pdf_invoice']) {
             //$pdf->Output('invoice-' . $order_id . '.pdf', 'D');
             header("Content-Type: application/octet-stream");
             //$file = $file_name;//$_GET["file"] .".pdf";
             header("Content-Disposition: attachment; filename=" . urlencode($file_name));
             header("Content-Type: application/octet-stream");
             header("Content-Type: application/download");
             header("Content-Description: File Transfer");
         } else {
             //$pdf->Output('invoice-' . $order_id . '.pdf', 'I');
             header("Content-type: application/pdf");
             header("Content-Disposition: inline; filename=" . urlencode($file_name));
         }
         header("Content-Length: " . filesize($file_path));
         flush();
         // this doesn't really matter.
         if (false !== ($fp = fopen($file_path, "r"))) {
             while (!feof($fp)) {
                 echo fread($fp, 65536);
                 flush();
                 // this is essential for large downloads
             }
             fclose($fp);
         } else {
             die(__('Unexpected error', 'woocommerce-jetpack'));
         }
     }
     /**/
     /**
     
     
     		if ( $get_by_order_id > 0 )
     			return $pdf->Output('invoice-' . $order_id . '.pdf', 'S');
     		if ( isset( $_GET['save_pdf_invoice'] ) && '1' == $_GET['save_pdf_invoice'] )
     			$pdf->Output('invoice-' . $order_id . '.pdf', 'D');
     		else
     			$pdf->Output('invoice-' . $order_id . '.pdf', 'I');
     
     			/**/
 }