reorganize class name

This commit is contained in:
2026-10-06 14:05:52 +07:00
parent 8a758e5875
commit 17188f6134
13 changed files with 417 additions and 309 deletions
+94 -77
View File
@@ -5,7 +5,7 @@
Module : /Printer/PrintHTML.php
Created By : Siau Pheng ([email protected]).
Created Date : June 15th, 2008.
Last Modified : August 26th, 2026.
Last Modified : October 2nd, 2026.
(c) 3FONIA Software; WWW.3FONIA.COM.
@@ -29,10 +29,12 @@ use \flight\Engine;
*/
final class PrintHTML {
private $__avalue = [];
private $__atabel = [];
private $__css = "table";
private $__tstamp = "";
private array $avalue = [];
private array $atabel = [];
private string $css = "table";
private string $stamp = "";
private array $titles = [];
private array $subtitles = [];
protected array $webapp;
protected array $webuser;
@@ -40,96 +42,114 @@ final class PrintHTML {
* @param Engine $app
*/
public function __construct(Engine $app) {
$this->webapp = $app->session()->get('WEB_APP', ['APP_NAME'=>'', 'APP_VER'=>'']);
$this->webuser = $app->session()->get('WEB_USER', ['UserID'=>0, 'Username'=>'']);
$this->webapp = (array) $app->session()->get('WEB_APP', ['APP_NAME'=>'', 'APP_VER'=>'']);
$this->webuser = (array) $app->session()->get('WEB_USER', ['UserID'=>0, 'Username'=>'']);
}
public function set_css(string $style): void {
if (!empty($style)) $this->__css = $style;
if (!empty($style)) $this->css = $style;
}
public function add_field(string $nama, int $lebar=0, string $align="L", string $func="", int $kol=1): void {
$this->__atabel[] = [ $nama, $lebar, $func, $align, $kol ];
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 clear(): void {
$this->__avalue = [];
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_value(): void {
$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++) {
$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);
}
$tmp_val = $this->set_align((string) $tmp_val, $this->__atabel[$i][1], $this->__atabel[$i][3]);
$tmp_out .= $tmp_val;
}
$tmp_out .= "</tr>";
$this->__avalue[] = $tmp_out;
public function add_field(string $nama, int $lebar=0, string $align="L", callable|array|null $func=null, int $kol=1): void {
$this->atabel[] = [ 'n' => $nama, 'l' => $lebar, 'f' => $func, 'a' => $align, 'k' => $kol ];
}
public function add_span(): void {
$tmp_arr = func_get_args();
$tmp_out = "<tr>";
for ($i=0; $i<count($tmp_arr); $i++) {
$tmp_val = $tmp_arr[$i];// CONTENT, COLSPAN=1, L, FUNC, EXTRA
if (!isset($tmp_val[1])) $tmp_val[1] = 1;
if (!isset($tmp_val[2])) $tmp_val[2] = "L";
if (!isset($tmp_val[4])) $tmp_val[4] = "";
if (isset($tmp_val[3])) {
if (function_exists($tmp_val[3]) && trim("".$tmp_val[0])<>"") {
$tmp_val[0] = call_user_func($tmp_val[3], $tmp_val[0]);
public function add_row(array $row): void {
if (!is_array($row) || empty($row)) return;
$row_out = "<tr>";
foreach ($this->atabel as $i => $tabel) {
$col_val = $row[$i] ?? '';
if (!empty($col_val)) {
if (is_array($tabel['f'])) {
$col_val = $tabel['f'][$col_val];
} else if (is_callable($tabel['f'])) {
$col_val = call_user_func($tabel['f'], $col_val);
}
}
$tmp_val = $this->set_align($tmp_val[0], 0, $tmp_val[2], false, false, $tmp_val[1], $tmp_val[4]);
$tmp_out .= $tmp_val;
$row_out .= $this->set_align((string) $col_val, $tabel['l'], $tabel['a']);
}
$tmp_out .= "</tr>";
$this->__avalue[] = $tmp_out;
$row_out .= "</tr>";
echo $row_out;
}
public function add_stamp(int $ctk_ke=1, bool $cetak_nama=false): void {
$this->__tstamp = $this->get_stamp($ctk_ke, $cetak_nama);
}
public function get_stamp(int $ctk_ke=1, bool $cetak_nama=false): string {
return $this->webapp['APP_NAME']."v".$this->webapp['APP_VER'].date("\@ymd.His")."-".isi_nol($this->webuser['UserID'], 3).(($cetak_nama)?"/".strtoupper($this->webuser['Username']):"").(($ctk_ke>0)?"#".isi_nol($ctk_ke,2):"");
}
public function show(int $jumlah_ctk=1) {
$out = "<table class=\"".$this->__css."\"><thead>";
// header out
$tmp_out = "<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]);
public function add_span(array $span): void {
if (!is_array($span) || empty($span)) return;
$row_out = "<tr>";
foreach ($span as $col) {
// CONTENT, COLSPAN=1, L, FUNC, EXTRA
if (!isset($col[1])) $col[1] = 1;
if (!isset($col[2])) $col[2] = "L";
if (!isset($col[4])) $col[4] = "";
if (isset($col[3]) && is_callable($col[3])) {
if (function_exists($col[3]) && !empty($col[0])) {
$col[0] = call_user_func($col[3], $col[0]);
}
}
$row_out .= $this->set_align($col[0], 0, $col[2], false, false, $col[1], $col[4]);
}
$tmp_out .= "</tr>";
$out .= "</thead>".$tmp_out."<tbody>";
// content out
for ($i=0; $i<count($this->__avalue); $i++) {
$tmp_str = $this->__avalue[$i];
if (strpos($tmp_str, "_LINE")>0) $tmp_str = "<hr />";
$out .= $tmp_str;
}
$out .= "</tbody></table>";
$out .= $this->__tstamp;
for ($i=1; $i<=$jumlah_ctk; $i++) echo $out;
$row_out .= "</tr>";
echo $row_out;
}
public function set_align(string $text, int $width=0, string $dir="L", bool $line=false, bool $head=false, int $col=1, string $extra=""): string {
public function show_titles(): void {
$_afs = [0=>"4", 1=>"5", 2=>"6"];
foreach ($this->titles as $i => $title) {
vprintf('<div class="fs-%s text-center">%s</div>', [($_afs[$i] ?? '6'), $title]);
}
if (count($this->subtitles) > 0) {
foreach ($this->subtitles as $title) {
vprintf('<div>%s</div>', [$title]);
}
} else
echo '<br />';
}
public function show_headers(): void {
vprintf('<table class="%s"><thead>', [$this->css]);
// 0-n, 1=l, 2-f, 3-a, 4-k
$head_out = "<tr>";
foreach ($this->atabel as $tabel) {
if ($tabel['k'] === 0) continue;
$head_out .= $this->set_align($tabel['n'], $tabel['l'], "C", false, true, $tabel['k']);
}
$head_out .= "</tr>";
echo "</thead>".$head_out."<tbody>";
// start content row
}
public function add_stamp(int $ctk_ke=1, bool $tampil_nama=false): void {
$this->stamp = $this->get_stamp($ctk_ke, $tampil_nama);
}
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 show() {
// end content row
echo "</tbody></table>";
if (!empty($this->stamp)) vprintf('<span class="small fst-italic">%s</span>', [$this->stamp]);
}
public function set_align(mixed $text, int $width=0, string $dir="L", bool $line=false, bool $head=false, int $col=1, string $extra=""): string {
$tstyle = $this->create_style($dir);
if ($line===true) {
return "<tr><td colspan=\"".count($this->__atabel)."\" class=\"".$tstyle." ".$extra."\">".$text."</td></tr>";
return "<tr><td colspan=\"".count($this->atabel)."\" class=\"".$tstyle." ".$extra."\">".$text."</td></tr>";
} else {
return (($head===true)?"<th":"<td").(($col>1)?" colspan=\"".(string)$col."\"":"")." class=\"".$tstyle." ".$extra."\" ".(($head===true)?"width=\"".(string)$width."\"":"").">".$text.(($head===true)?"</th>":"</td>");
}
@@ -146,9 +166,6 @@ final class PrintHTML {
return implode(' ', $ahasil);
}
//todo: deprecated
public function show_fields() {}
public function add_pagebreak() {}
}
?>
+27 -45
View File
@@ -5,7 +5,7 @@
Module : /Printer/PrintPOS.php
Created By : Siau Pheng ([email protected]).
Created Date : June 15th, 2008.
Last Modified : September 21st, 2026.
Last Modified : October 3rd, 2026.
(c) 3FONIA Software; WWW.3FONIA.COM.
@@ -29,12 +29,11 @@ use \flight\Engine;
*/
class PrintPOS {
private $_header = [];
private $_avalue = [];
private $_astyle = [];
private $_ncont = 0;
private $_maxchr = 40;
private $_config = [
private int $sheet = 0;
private int $maxchr = 40;
private array $header = [];
private array $acontent = [];
private array $config = [
'fontsize' => 1,
'opendraw' => false,
'cutpaper' => false,
@@ -54,53 +53,52 @@ class PrintPOS {
}
public function set_opendrawer(): void {
$this->_config['opendraw'] = true;
$this->config['opendraw'] = true;
}
public function set_cutpaper(): void {
$this->_config['cutpaper'] = true;
$this->config['cutpaper'] = true;
}
public function set_maxchr(int $max = 0): void {
if ($max > 0) $this->_maxchr = $max;
if ($max > 0) $this->maxchr = $max;
}
public function set_fontsize(int $size = 1): void {
if ($size > 0) $this->_config['fontsize'] = $size;
if ($size > 0) $this->config['fontsize'] = $size;
}
public function set_header_logo(string $logo_file = ""): void {
if (!empty($logo_file) && file_exists(PROJECT_ROOT."public/assets/images/".$logo_file)) {
//$this->_config['logo'] = PROJECT_BASE."assets/images/".$logo_file;
$this->_config['logo'] = base64_encode(file_get_contents(PROJECT_ROOT."public/assets/images/".$logo_file));
//$this->config['logo'] = PROJECT_BASE."assets/images/".$logo_file;
$this->config['logo'] = base64_encode(file_get_contents(PROJECT_ROOT."public/assets/images/".$logo_file));
}
}
public function add_header(): void {
$extra = func_get_args();
if (count($extra) > 0) {
foreach ($extra as $_val) {
$this->_header[] = $_val;
}
}
if (count($extra) > 0) $this->header = $extra;
}
public function add_sheet(): void {
$this->_ncont++;
$this->sheet++;
}
public function add(): void {
$val_arr = func_get_args(); $ttext = ""; $tstyle = "L";
if (is_array($val_arr[0])) {
foreach($val_arr as $aval) {
$ttext .= $this->set_align((isset($aval[0])?$aval[0]:""), (isset($aval[1])?$aval[1]:0), (isset($aval[2])?$aval[2]:$tstyle));
foreach ($val_arr as $aval) {
$ttext .= $this->set_align(($aval[0] ?? ""), ($aval[1] ?? 0), ($aval[2] ?? $tstyle));
}
} else {
$ttext = (isset($val_arr[0])) ? $val_arr[0] : "";
$tstyle = (isset($val_arr[1])) ? $val_arr[1] : $tstyle;
$ttext = $val_arr[0] ?? "";
$tstyle = $val_arr[1] ?? $tstyle;
}
$this->_avalue[$this->_ncont][] = $ttext;
$this->_astyle[$this->_ncont][] = $tstyle;
if (str_contains($ttext, "_LINE")) {
$tmp_arr = explode(" ", $ttext);
$ttext = str_pad($tmp_arr[1], $this->maxchr, $tmp_arr[1]);
}
$this->acontent[$this->sheet][] = ($tstyle === "X") ? $ttext : $this->set_align($ttext, $this->maxchr, $tstyle);
}
public function addl(string $text = ""): void {
@@ -128,25 +126,11 @@ class PrintPOS {
}
public function show(int $jumlah_ctk=1): void {
$acontent = [];
$nmax = $this->_maxchr;
for ($s=0; $s<count($this->_avalue); $s++) {
for ($i=0; $i<count($this->_avalue[$s]); $i++) {
$tmp_str = $this->_avalue[$s][$i];
if (strpos($tmp_str, "_LINE")>0) {
$tmp_arr = explode(" ", $tmp_str);
$tmp_str = str_pad($tmp_arr[1], $nmax, $tmp_arr[1]);
}
$acontent[$s][] = ($this->_astyle[$s][$i]=="X") ? $tmp_str : $this->set_align($tmp_str, $nmax, $this->_astyle[$s][$i]);
}
}
$this->_config['times'] = $jumlah_ctk;
$this->config['times'] = $jumlah_ctk;
$aout = ['type' => "escp"];
$aout['config'] = $this->_config;
$aout['header'] = $this->_header;
$aout['content'] = $acontent;
$aout['config'] = $this->config;
$aout['header'] = $this->header;
$aout['content'] = $this->acontent;
$this->app->json($aout);
}
@@ -157,8 +141,6 @@ class PrintPOS {
return str_pad($text, $len, " ", $apad[$dir]);
}
//todo: deprecated
public function set_printnv_logo() {}//delete
}
?>