reorganize class name
This commit is contained in:
+4
-4
@@ -2,7 +2,7 @@
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Data/CSV.php
|
||||
Module : /Data/Csv.php
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : April 2rd, 2011.
|
||||
Last Modified : August 21st, 2026.
|
||||
@@ -19,9 +19,9 @@ define( DELI_CSV, ";" );
|
||||
define( CRLF_CSV, "\r\n" );
|
||||
|
||||
/**
|
||||
* Class CSV
|
||||
* Class Csv
|
||||
*
|
||||
* Membuat file CSV.
|
||||
* Membuat file Csv.
|
||||
*
|
||||
* @license MIT, https://www.3fonia.com
|
||||
* @copyright Copyright (c) 2008-2026, Siau Pheng <[email protected]>
|
||||
@@ -29,7 +29,7 @@ define( CRLF_CSV, "\r\n" );
|
||||
* @package Webapp\Data
|
||||
*/
|
||||
|
||||
final class CSV {
|
||||
final class Csv {
|
||||
private $__avalue = [];
|
||||
private $__atabel = [];
|
||||
|
||||
|
||||
+26
-26
@@ -2,7 +2,7 @@
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Data/PDF.php
|
||||
Module : /Data/Pdf.php
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : April 18th, 2015.
|
||||
Last Modified : August 21st, 2026.
|
||||
@@ -19,9 +19,9 @@ use \flight\Engine;
|
||||
use \Mpdf;
|
||||
|
||||
/**
|
||||
* Class PDF
|
||||
* Class Pdf
|
||||
*
|
||||
* Membuat file PDF.
|
||||
* Membuat file Pdf.
|
||||
*
|
||||
* @license MIT, https://www.3fonia.com
|
||||
* @copyright Copyright (c) 2008-2026, Siau Pheng <[email protected]>
|
||||
@@ -29,11 +29,11 @@ use \Mpdf;
|
||||
* @package Webapp\Data
|
||||
*/
|
||||
|
||||
final class PDF {
|
||||
private $__avalue = [];
|
||||
private $__atabel = [];
|
||||
private $__theader = "";
|
||||
private $__tcolname = "";
|
||||
final class Pdf {
|
||||
private array $avalue = [];
|
||||
private array $atabel = [];
|
||||
private string $__theader = "";
|
||||
private string $__tcolname = "";
|
||||
protected array $webapp;
|
||||
protected array $webuser;
|
||||
|
||||
@@ -47,21 +47,21 @@ final class PDF {
|
||||
}
|
||||
|
||||
public function add_field(string $nama, string|int $lebar=0, string $align="L", string $func="", int $kol=1): void {
|
||||
$this->__atabel[] = [ $nama, (string)$lebar.'%', $func, $align, $kol ];
|
||||
$this->atabel[] = [ $nama, (string)$lebar.'%', $func, $align, $kol ];
|
||||
}
|
||||
|
||||
public function show_fields(): void {
|
||||
$tmp_out = "<thead><tr>";
|
||||
for ($i=0; $i<count($this->__atabel); $i++) {
|
||||
if ($this->__atabel[$i][4]==0) continue;
|
||||
$tmp_out .= $this->set_align($this->__atabel[$i][0], $this->__atabel[$i][1], "C", false, true, $this->__atabel[$i][4]);
|
||||
for ($i=0; $i<count($this->atabel); $i++) {
|
||||
if ($this->atabel[$i][4]==0) continue;
|
||||
$tmp_out .= $this->set_align($this->atabel[$i][0], $this->atabel[$i][1], "C", false, true, $this->atabel[$i][4]);
|
||||
}
|
||||
$tmp_out .= "</tr></thead>";
|
||||
$this->__tcolname = $tmp_out;
|
||||
}
|
||||
|
||||
public function clear(): void {
|
||||
$this->__avalue = [];
|
||||
$this->avalue = [];
|
||||
$this->__theader = "";
|
||||
$this->__tcolname = "";
|
||||
}
|
||||
@@ -78,18 +78,18 @@ final class PDF {
|
||||
$tmp_arr = func_get_args();
|
||||
if (is_array($tmp_arr[0])) $tmp_arr = $tmp_arr[0];
|
||||
$tmp_out = "<tr>";
|
||||
for ($i=0; $i<count($this->__atabel); $i++) {
|
||||
for ($i=0; $i<count($this->atabel); $i++) {
|
||||
$tmp_val = $tmp_arr[$i];
|
||||
if (is_array($this->__atabel[$i][2]) && trim($tmp_val)<>"") {
|
||||
$tmp_val = $this->__atabel[$i][2][$tmp_val];
|
||||
} else if (function_exists($this->__atabel[$i][2]) && trim($tmp_val)<>"") {
|
||||
$tmp_val = call_user_func($this->__atabel[$i][2], $tmp_val);
|
||||
if (is_array($this->atabel[$i][2]) && trim($tmp_val)<>"") {
|
||||
$tmp_val = $this->atabel[$i][2][$tmp_val];
|
||||
} else if (function_exists($this->atabel[$i][2]) && trim($tmp_val)<>"") {
|
||||
$tmp_val = call_user_func($this->atabel[$i][2], $tmp_val);
|
||||
}
|
||||
$tmp_val = $this->set_align($tmp_val, $this->__atabel[$i][1], $this->__atabel[$i][3]);
|
||||
$tmp_val = $this->set_align($tmp_val, $this->atabel[$i][1], $this->atabel[$i][3]);
|
||||
$tmp_out .= $tmp_val;
|
||||
}
|
||||
$tmp_out .= "</tr>";
|
||||
$this->__avalue[] = $tmp_out;
|
||||
$this->avalue[] = $tmp_out;
|
||||
}
|
||||
|
||||
public function add_span(): void {
|
||||
@@ -104,15 +104,15 @@ final class PDF {
|
||||
$tmp_out .= $tmp_val;
|
||||
}
|
||||
$tmp_out .= "</tr>";
|
||||
$this->__avalue[] = $tmp_out;
|
||||
$this->avalue[] = $tmp_out;
|
||||
}
|
||||
|
||||
public function add_empty(): void {
|
||||
$this->__avalue[] = $this->set_align(" ", 0, "L,NB", true);
|
||||
$this->avalue[] = $this->set_align(" ", 0, "L,NB", true);
|
||||
}
|
||||
|
||||
public function add_stamp(int $ctk_ke=1, bool $tampil_nama=false): void {
|
||||
$this->__avalue[] = $this->set_align($this->get_stamp($ctk_ke, $tampil_nama), 0, "L,NB", true);
|
||||
$this->avalue[] = $this->set_align($this->get_stamp($ctk_ke, $tampil_nama), 0, "L,NB", true);
|
||||
}
|
||||
|
||||
public function get_stamp(int $ctk_ke=1, bool $tampil_nama=false): string {
|
||||
@@ -163,8 +163,8 @@ final class PDF {
|
||||
$html .= '<tbody>';
|
||||
|
||||
// content out
|
||||
for ($i=0; $i<count($this->__avalue); $i++) {
|
||||
$html .= $this->__avalue[$i];
|
||||
for ($i=0; $i<count($this->avalue); $i++) {
|
||||
$html .= $this->avalue[$i];
|
||||
}
|
||||
$html .= '</tbody></table></div></div></body>';
|
||||
$mpdf = new mPDF('c', 'A4'.($orien==="L"?"-L":""), $fontz, '', 5, 5, 5, 10, 5, 5);
|
||||
@@ -177,7 +177,7 @@ final class PDF {
|
||||
$tstyle = $this->create_style($dir);
|
||||
if (strpos(strtolower($text), "<tr>")===false) {
|
||||
if ($line===true) {
|
||||
return '<tr><td colspan="'.count($this->__atabel).'" class="'.$tstyle.'">'.$text."</td></tr>";
|
||||
return '<tr><td colspan="'.count($this->atabel).'" class="'.$tstyle.'">'.$text."</td></tr>";
|
||||
} else {
|
||||
return (($head===true)?"<th":"<td").(($col>1)?' colspan="'.(string)$col.'"':"").' class="'.$tstyle.'" '.(($head===true)?'width="'.(string)$width.'"':"").">".$text.(($head===true)?"</th>":"</td>");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
PHP Class : /Data/Xls.php
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : November 18th, 2012.
|
||||
Last Modified : October 1st, 2026.
|
||||
|
||||
(c) 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Webapp\Data;
|
||||
|
||||
use \flight\Engine;
|
||||
use \avadim\FastExcelWriter\Excel;
|
||||
use \avadim\FastExcelWriter\Options;
|
||||
use \avadim\FastExcelWriter\Sheet;
|
||||
use \avadim\FastExcelWriter\Style\Style;
|
||||
|
||||
/**
|
||||
* Class Xlsx
|
||||
*
|
||||
* Membuat file Excel XLSX
|
||||
*
|
||||
* @license MIT, https://www.3fonia.com
|
||||
* @copyright Copyright (c) 2008-2026, Siau Pheng <[email protected]>
|
||||
*
|
||||
* @package Webapp\Data
|
||||
*/
|
||||
|
||||
final class Xlsx {
|
||||
|
||||
private Options $options;
|
||||
private Excel $excel;
|
||||
private Sheet $sheet;
|
||||
private array $webapp;
|
||||
private array $webuser;
|
||||
private array $meta = [];
|
||||
private array $titles = [];
|
||||
private array $subtitles = [];
|
||||
private array $atabel = [];
|
||||
private int $baris = 1;
|
||||
|
||||
/**
|
||||
* @param Engine $app
|
||||
*/
|
||||
|
||||
public function __construct(Engine $app) {
|
||||
$this->webapp = (array) $app->session()->get('WEB_APP', ['REG_NAME'=>'', 'APP_NAME'=>'', 'APP_VER'=>'']);
|
||||
$this->webuser = (array) $app->session()->get('WEB_USER', ['UserID'=>0, 'Username'=>'']);
|
||||
$this->meta = [
|
||||
'company' => $this->webapp['REG_NAME'],
|
||||
'subject' => $this->webapp['REG_NAME'],
|
||||
'author' => $this->webapp['APP_NAME'].' v'.$this->webapp['APP_VER'],
|
||||
];
|
||||
$this->options = Options::create()
|
||||
->DefaultFont([ Style::FONT_NAME => "Calibri", Style::FONT_SIZE => 11 ])
|
||||
->defaultDateFormat('DD-MM-YYYY')
|
||||
->defaultTimeFormat('HH:MM')
|
||||
->defaultDateTimeFormat('DD-MM-YYYY HH:MM');
|
||||
}
|
||||
|
||||
public function set_meta(array $meta): void {
|
||||
if (!empty($meta)) $this->meta = array_merge($this->meta, $meta);
|
||||
}
|
||||
|
||||
public function add_title(string|array $judul): void {
|
||||
if (empty($judul)) return;
|
||||
if (is_array($judul)) {
|
||||
$this->titles = $judul;
|
||||
} else array_push($this->titles, $judul);
|
||||
}
|
||||
|
||||
public function add_sub_title(string|array $judul): void {
|
||||
if (empty($judul)) return;
|
||||
if (is_array($judul)) {
|
||||
$this->subtitles = $judul;
|
||||
} else array_push($this->subtitles, $judul);
|
||||
}
|
||||
|
||||
public function add_field(string $nama="", int $lebar=0, string $style="@text", ?callable $func=null): void {
|
||||
$this->atabel[] = ['n' => $nama, 'l' => $lebar, 's' => $style, 'f' => $func];
|
||||
}
|
||||
|
||||
public function add_sheet(string $nama_sheet="BARU", bool $show_header=false): void {
|
||||
if (empty($this->excel)) {
|
||||
$this->excel = Excel::create([$nama_sheet], $this->options)
|
||||
->setCompany($this->meta['company'] ?? "")
|
||||
->setAuthor($this->meta['author'] ?? "")
|
||||
->setTitle($this->meta['title'] ?? "")
|
||||
->setDescription($this->meta['desc'] ?? "")
|
||||
->setSubject($this->meta['subject'] ?? "");
|
||||
$this->sheet = $this->excel->sheet(); //getSheet();
|
||||
} else {
|
||||
$this->sheet = $this->excel->makeSheet($nama_sheet);
|
||||
}
|
||||
if ($show_header === true) {
|
||||
$this->show_titles();
|
||||
$this->show_headers();
|
||||
}
|
||||
}
|
||||
|
||||
public function add_row(array $row): void {
|
||||
if (is_array($row) && !empty($row)) $this->sheet->writeRow($row);
|
||||
}
|
||||
|
||||
public function add_row_bold(array $row): void {
|
||||
if (is_array($row) && !empty($row)) $this->sheet->writeRow($row)->applyFontStyleBold();
|
||||
}
|
||||
|
||||
public function show_titles(): void {
|
||||
$this->baris = $this->sheet->getCurrentRow();
|
||||
$jum_kolom = count($this->atabel);
|
||||
foreach ($this->titles as $title) {
|
||||
$this->sheet->writeTo('A'.(string) $this->baris.':'.$this->excel->colLetter($jum_kolom).(string) $this->baris, $title)
|
||||
->applyFontStyleBold()
|
||||
->applyTextCenter();
|
||||
$this->baris++;
|
||||
}
|
||||
if (count($this->subtitles) > 0) {
|
||||
$this->baris++;
|
||||
foreach ($this->subtitles as $title) {
|
||||
$this->sheet->writeTo('A'.(string) $this->baris++, $title);
|
||||
}
|
||||
} else
|
||||
$this->sheet->writeTo('A'.(string) $this->baris, '');
|
||||
}
|
||||
|
||||
public function show_headers(): void {
|
||||
$this->sheet->writeHeader(array_column($this->atabel, 'n'))
|
||||
->applyFontStyleBold()
|
||||
->applyTextCenter()
|
||||
->applyBorder(Style::BORDER_STYLE_THIN);
|
||||
$this->sheet->setColFormats(array_column($this->atabel, 's'))
|
||||
->setColWidths(array_column($this->atabel, 'l'));
|
||||
}
|
||||
|
||||
public function add_stamp(int $ctk_ke=1, bool $tampil_nama=false): void {
|
||||
$this->sheet->nextRow();
|
||||
$this->sheet->writeCell($this->get_stamp($ctk_ke, $tampil_nama), ['font-size' => 8, 'font-style' => 'italic']);
|
||||
}
|
||||
|
||||
public function get_stamp(int $ctk_ke=1, bool $tampil_nama=false): string {
|
||||
return $this->webapp['APP_NAME']."v".$this->webapp['APP_VER'].date("\@ymd.His")."-".isi_nol($this->webuser['UserID'], 3).(($tampil_nama)?"/".strtoupper($this->webuser['Username']):"").(($ctk_ke>0)?"#".isi_nol($ctk_ke,2):"");
|
||||
}
|
||||
|
||||
public function download(string $nama_file="File_Excel.xlsx"): void {
|
||||
$this->excel->download($nama_file);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user