コード例 #1
0
 protected function footer($objPHPExcel, $start, $file_name, $format, $html_title)
 {
     $start++;
     $jemaat = get_jemaat_from_user_id(Yii::app()->user->getId());
     $objPHPExcel->setActiveSheetIndex(0)->mergeCells("A{$start}:G{$start}")->setCellValue("A{$start}", "Dicetak oleh: " . $jemaat->real_name);
     $start++;
     $objPHPExcel->setActiveSheetIndex(0)->mergeCells("A{$start}:G{$start}")->setCellValue("A{$start}", "Pada tanggal " . get_date_today('dd/MM/yyyy') . " jam " . get_time_now());
     ob_end_clean();
     ob_start();
     if ($format == 'excel') {
         header('Content-Type: application/vnd.ms-excel');
         header("Content-Disposition: attachment;filename={$file_name}.xls");
         header('Cache-Control: max-age=0');
         $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
         $objWriter->save('php://output');
     } else {
         $objPHPExcel->getActiveSheet()->setShowGridlines(false);
         $mPDF1 = Yii::app()->ePdf->mpdf();
         $mPDF1 = Yii::app()->ePdf->mpdf('', 'A4');
         $objWriter = new PHPExcel_Writer_HTML($objPHPExcel);
         $header = $objWriter->generateHTMLHeader(true);
         $header = str_replace("<body>", "<body onload='window.print();'>", $header);
         $header = str_replace("Untitled Spreadsheet", $html_title, $header);
         $html = $header . $objWriter->generateStyles(true) . $objWriter->generateSheetData() . $objWriter->generateHTMLFooter();
         if ($format == 'pdf') {
             $mPDF1->WriteHTML($html);
             $mPDF1->Output('MutasiKasDitangan.pdf', 'D');
         } else {
             echo $html;
         }
     }
 }
コード例 #2
0
 public function view()
 {
     $objWriter = new PHPExcel_Writer_HTML($this->getPHPExcelObj());
     $html['header'] = $objWriter->generateHTMLHeader();
     $html['style'] = $objWriter->generateStyles(true);
     // do not write <style> and </style>
     $html['body'] = $objWriter->generateSheetData();
     $html['footer'] = $objWriter->generateHTMLFooter();
     return $html;
 }
コード例 #3
0
 public function actionMutasiKasDiTangan()
 {
     if (Yii::app()->request->isAjaxRequest) {
         return;
     }
     if (isset($_POST) && !empty($_POST)) {
         $format = $_POST['format'];
         $start_date = $_POST['trans_date_mulai'];
         $end_date = $_POST['trans_date_sampai'];
         $start = 1;
         $file_name = 'MutasiKas';
         $worksheet_name = 'Mutasi Kas';
         $objPHPExcel = new PHPExcel();
         $objPHPExcel->getDefaultStyle()->getFont()->setSize(10);
         $objPHPExcel->setActiveSheetIndex(0)->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
         $objPHPExcel->setActiveSheetIndex(0)->getPageMargins()->setLeft(0.1 / 2.54);
         $objPHPExcel->setActiveSheetIndex(0)->getPageMargins()->setRight(0.1 / 2.54);
         $objPHPExcel->setActiveSheetIndex(0)->mergeCells("A{$start}:G{$start}")->setCellValue("A{$start}", "MUTASI KAS DI TANGAN")->getStyle("A{$start}")->getFont()->setSize(18)->setBold(true);
         $start++;
         $objPHPExcel->setActiveSheetIndex(0)->mergeCells("A{$start}:G{$start}")->setCellValue("A{$start}", "PONDOK ASUH HARAPAN")->getStyle("A{$start}")->getFont()->setSize(14)->setBold(true);
         $start++;
         $objPHPExcel->setActiveSheetIndex(0)->mergeCells("A{$start}:G{$start}")->setCellValue("A{$start}", "PERIODE: " . sql2long_date($start_date) . " - " . sql2long_date($end_date))->getStyle("A{$start}")->getFont()->setSize(12)->setBold(true);
         $objPHPExcel->getActiveSheet()->setTitle($worksheet_name);
         $start++;
         $start++;
         $start_body = $start;
         $objPHPExcel->setActiveSheetIndex(0)->setCellValue("A{$start}", "Doc. Ref")->setCellValue("B{$start}", "Tanggal")->setCellValue("C{$start}", "Payee/Payor")->setCellValue("D{$start}", "Nama Rekening")->setCellValue("E{$start}", "Kas Masuk")->setCellValue("F{$start}", "Kas Keluar")->setCellValue("G{$start}", "Saldo Kas")->getStyle("A{$start}:G{$start}")->getFont()->setBold(true);
         $start++;
         $rows = Pah::get_mutasi_kas_ditangan($start_date, $end_date);
         $nomer = 1;
         $saldo = 0;
         foreach ($rows as $row) {
             $saldo += $row['saldo'];
             //                $kas_masuk = $row['kas_masuk'] == 0 ? '' : ($format == 'excel' ? $row['kas_masuk'] : number_format($row['kas_masuk']));
             //                $kas_keluar = $row['kas_keluar'] == 0 ? '' : ($format == 'excel' ? -$row['kas_keluar'] : number_format(-$row['kas_keluar']));
             $objPHPExcel->setActiveSheetIndex(0)->setCellValue("A{$start}", $nomer)->setCellValue("B{$start}", sql2date($row['trans_date']))->setCellValue("C{$start}", Pah::get_payee_payoor($row['type'], $row['trans_no']))->setCellValue("D{$start}", $row['nama_rekening'])->setCellValue("E{$start}", $kas_masuk)->setCellValue("F{$start}", $kas_keluar)->setCellValue("G{$start}", $format == 'excel' ? $saldo : number_format($saldo));
             $nomer++;
             $start++;
         }
         $end_body = $start - 1;
         $styleArray = array('borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN)));
         $objPHPExcel->setActiveSheetIndex(0)->getStyle("A{$start_body}:G{$end_body}")->applyFromArray($styleArray);
         $start_row = $start_body + 1;
         if ($format == 'excel') {
             $objPHPExcel->setActiveSheetIndex(0)->getStyle("E{$start_row}:G{$end_body}")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_ACCOUNTING);
         } else {
             $objPHPExcel->setActiveSheetIndex(0)->getStyle("E{$start_body}:G{$end_body}")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
         }
         $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension("A")->setAutoSize(true);
         $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension("B")->setAutoSize(true);
         $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension("C")->setAutoSize(true);
         $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension("D")->setAutoSize(true);
         $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension("E")->setAutoSize(true);
         $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension("F")->setAutoSize(true);
         $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension("G")->setAutoSize(true);
         $start++;
         $jemaat = get_jemaat_from_user_id(Yii::app()->user->getId());
         $objPHPExcel->setActiveSheetIndex(0)->mergeCells("A{$start}:G{$start}")->setCellValue("A{$start}", "Dicetak oleh: " . $jemaat->real_name);
         $start++;
         $objPHPExcel->setActiveSheetIndex(0)->mergeCells("A{$start}:G{$start}")->setCellValue("A{$start}", "Pada tanggal " . get_date_today('dd/MM/yyyy') . " jam " . get_time_now());
         ob_end_clean();
         ob_start();
         if ($format == 'excel') {
             header('Content-Type: application/vnd.ms-excel');
             header("Content-Disposition: attachment;filename={$file_name}.xls");
             header('Cache-Control: max-age=0');
             $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
             $objWriter->save('php://output');
         } else {
             $objPHPExcel->getActiveSheet()->setShowGridlines(false);
             $mPDF1 = Yii::app()->ePdf->mpdf();
             $mPDF1 = Yii::app()->ePdf->mpdf('', 'A4');
             $objWriter = new PHPExcel_Writer_HTML($objPHPExcel);
             $header = $objWriter->generateHTMLHeader(true);
             $header = str_replace("<body>", "<body onload='window.print();'>", $header);
             $header = str_replace("Untitled Spreadsheet", "Mutasi Kas di Tangan", $header);
             $html = $header . $objWriter->generateStyles(true) . $objWriter->generateSheetData() . $objWriter->generateHTMLFooter();
             if ($format == 'pdf') {
                 $mPDF1->WriteHTML($html);
                 $mPDF1->Output('MutasiKasDitangan.pdf', 'D');
             } else {
                 echo $html;
             }
             //                header('Content-Type: application/pdf');
             //                header("Content-Disposition: attachment;filename='$file_name.pdf'");
             //                header('Cache-Control: max-age=0');
             //                $objPHPExcel->getActiveSheet()->setShowGridlines(false);
             //                $rendererName = PHPExcel_Settings::PDF_RENDERER_MPDF;
             //                $rendererLibraryPath = Yii::app()->basePath . '/vendors/mpdf';
             //                if (!PHPExcel_Settings::setPdfRenderer($rendererName,$rendererLibraryPath)) {
             //                    die(
             //                        'Please set the $rendererName and $rendererLibraryPath values' .
             //                            PHP_EOL .
             //                            ' as appropriate for your directory structure'
             //                    );
             //                }
             //
             //                $objWriter = new PHPExcel_Writer_PDF($objPHPExcel);
             //                $objWriter->save('php://output');
         }
         Yii::app()->end();
     }
 }