1 Commits
Author SHA1 Message Date
siaupheng 17188f6134 reorganize class name 2026-10-06 14:05:52 +07:00
13 changed files with 417 additions and 309 deletions
+85
View File
@@ -0,0 +1,85 @@
/*******************************************************************
Module : /assets/js/download.js
Desc. : Fungsi-fungsi download data & laporan
Created By : Siau Pheng ([email protected]).
Created Date : April 1st, 2011.
Last Modified : October 2nd, 2026.
(c) 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
var Download = function(options) {
var _options = {
'url': '',
'filename': 'file.bin',
'title': '',
'text': 'share dari aplikasi'
};
var _params = [];
this.construct = function(options){
if (typeof options == 'object') {
$.extend(_options, options);
} else _options.url = options;
};
this.set_url = function (url){
_options.url = url;
};
this.add_param = function(par_id, par_val) {
var _getvalue = (par_val) ? par_id + '=' + encodeURIComponent(par_val) : par_id;
_params.push(_getvalue);
};
this._exec = async function(is_share) {
if (!_options.url) {
console.warn('cek url !');
return false;
}
try {
const blob = await $.ajax({
type: 'POST',
url: _options.url,
data: FoniaJS.RequestParam(_params),
xhrFields: {
responseType: 'blob'
},
success: async function (data, status, xhr) {
const disposition = xhr.getResponseHeader('Content-Disposition');
if (disposition && disposition.indexOf('attachment') !== -1) {
const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
const matches = filenameRegex.exec(disposition);
if (matches != null && matches[1]) {
_options.filename = matches[1].replace(/['"]/g, '');
}
}
}
});
const file = new File([blob], _options.filename, { type: blob.type });
if (is_share === true && navigator.canShare && navigator.canShare({ files: [file] })) {
await navigator.share({
files: [file],
title: _options.title ?? _options.filename,
text: _options.text
});
} else {
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = _options.filename;
link.click();
}
} catch (error) {
console.error('Download / sharing gagal :', error);
};
return this;
};
this.share = async function() {
await this._exec(true);
};
this.download = async function() {
await this._exec(false);
};
this.construct(options);
};
-63
View File
@@ -1,63 +0,0 @@
/*******************************************************************
Module : /assets/js/export.js
Desc. : Fungsi-fungsi export data & laporan
Created By : Siau Pheng ([email protected]).
Created Date : April 1st, 2011.
Last Modified : January 19th, 2026.
(c) 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
var cEXPORT = function(url, options){
var _options = {
'url': '',
'filename': ''
};
var _params = [];
this.construct = function(url, options){
if (typeof url == 'object') {
$.extend(_options, url);
} else {
$.extend(_options, options);
_options.url = url;
}
};
this.set_url = function (url){
_options.url = url;
};
this.add_param = function (par_id, par_val){
var _getvalue = (par_val) ? par_id + "=" + escape(par_val) : par_id;
_params.push(_getvalue);
},
this.download = async function(){
if (!_options.url) {
console.warn('cek url !');
return false;
}
var _pro = (window.location.protocol=='https:') ? 'https://' : 'http://';
var _src = _pro+FoniaJS.WEB_HOST + _options.url + '?' + $.param(FoniaJS.RequestParam(_params));
try {
const response = await fetch(_src)
.then(response => {
const cDispo = response.headers.get('Content-Disposition');
if (cDispo && cDispo.indexOf('filename=') !== -1) {
_options.filename = cDispo.split('filename=')[1].split(';')[0].replace(/"/g, '');
}
return response;
})
const blob = await response.blob();
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = _options.filename;
link.click();
} catch (error) {
console.error('Download gagal:', error);
}
return this;
};
this.construct(url, options);
};
+6 -5
View File
@@ -10,15 +10,16 @@
*******************************************************************/ *******************************************************************/
var cPDF = function(url, options){ var Pdf = function(options){
var vars = { var vars = {
'url': '', 'url': '',
'zoom': 80, 'zoom': 80,
'param': [] 'param': []
}; };
this.construct = function(url, options){ this.construct = function(options){
$.extend(vars, options); if (typeof options == 'object') {
vars.url = url; $.extend(vars, options);
} else vars.url = options;
}; };
this.set_url = function (url){ this.set_url = function (url){
vars.url = url; vars.url = url;
@@ -61,5 +62,5 @@ var cPDF = function(url, options){
$(this).remove(); $(this).remove();
}).modal('show'); }).modal('show');
}; };
this.construct(url, options); this.construct(options);
}; };
+1 -1
View File
@@ -9,7 +9,7 @@
*******************************************************************/ *******************************************************************/
var cPOLEDISPLAY = function(port, options){ var PoleDisplay = function(port, options){
var _cd_port = ''; var _cd_port = '';
var _cd_pole = ''; var _cd_pole = '';
var _options = { var _options = {
+12 -10
View File
@@ -10,15 +10,16 @@
*******************************************************************/ *******************************************************************/
var cPRINTER = function(url, options){ var Printer = function(options){
var vars = { var vars = {
'url': '', 'url': '',
'zoom': 90, 'zoom': 90,
'param': [] 'param': []
}; };
this.construct = function(url, options){ this.construct = function(options){
$.extend(vars, options); if (typeof options == 'object') {
vars.url = url; $.extend(vars, options);
} else vars.url = options;
}; };
this.set_url = function (url){ this.set_url = function (url){
vars.url = url; vars.url = url;
@@ -87,10 +88,10 @@ var cPRINTER = function(url, options){
error: (typeof vars.onFailure === "function") ? vars.onFailure : null, error: (typeof vars.onFailure === "function") ? vars.onFailure : null,
}); });
}; };
this.construct(url, options); this.construct(options);
}; };
var cPRINTERPOS = function(url, options) { var PrinterPos = function(options) {
var b_default = false; var b_default = false;
var _options = { var _options = {
'url': '', 'url': '',
@@ -103,9 +104,10 @@ var cPRINTERPOS = function(url, options) {
'chr_sbold': "\x1B\x21\x31", 'chr_sbold': "\x1B\x21\x31",
'chr_uline': "\x1B\x21\x80" 'chr_uline': "\x1B\x21\x80"
}; };
this.construct = function(url, options) { this.construct = function(options) {
$.extend(_options, options); if (typeof options == 'object') {
_options.url = url; $.extend(_options, options);
} else _options.url = options;
if (FoniaJS._def_printer) _options.printer = FoniaJS._def_printer; if (FoniaJS._def_printer) _options.printer = FoniaJS._def_printer;
}; };
this.detectPrinter = function() { this.detectPrinter = function() {
@@ -230,5 +232,5 @@ var cPRINTERPOS = function(url, options) {
} }
return notaout; return notaout;
}; };
this.construct(url, options); this.construct(options);
}; };
-73
View File
@@ -1,73 +0,0 @@
/*******************************************************************
Module : /assets/js/share.js
Desc. : JS Class Share File Cross Browser
Created By : Siau Pheng ([email protected]).
Created Date : May 27th, 2007.
Last Modified : January 19th, 2026.
(c) 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
var cSHARE = function(url, options) {
var _options = {
'url': '',
'filename': '',
'title': '',
'text': 'share dari aplikasi'
};
var _params = [];
this.construct = function(url, options){
if (typeof url == 'object') {
$.extend(_options, url);
} else {
$.extend(_options, options);
_options.url = url;
}
};
this.set_url = function (url){
_options.url = url;
};
this.add_param = function(par_id, par_val) {
var _getvalue = (par_val) ? par_id + '=' + escape(par_val) : par_id;
_params.push(_getvalue);
};
this.share = async function() {
if (!_options.url) {
console.warn('cek url !');
return false;
}
var _pro = (window.location.protocol=='https:') ? 'https://' : 'http://';
var _src = _pro+FoniaJS.WEB_HOST + _options.url + '?' + $.param(FoniaJS.RequestParam(_params));
try {
const response = await fetch(_src)
.then(response => {
const cDispo = response.headers.get('Content-Disposition');
if (cDispo && cDispo.indexOf('filename=') !== -1) {
_options.filename = cDispo.split('filename=')[1].split(';')[0].replace(/"/g, '');
}
return response;
});
const blob = await response.blob();
const file = new File([blob], _options.filename, { type: blob.type });
if (navigator.canShare && navigator.canShare({ files: [file] })) {
await navigator.share({
files: [file],
title: _options.title ?? _options.filename,
text: _options.text
});
} else {
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = _options.filename;
link.click();
}
} catch (error) {
console.error('Sharing gagal:', error);
}
};
this.construct(url, options);
};
+6 -5
View File
@@ -10,14 +10,15 @@
*******************************************************************/ *******************************************************************/
var cSIMULATOR = function(url, options){ var Simulator = function(options){
var vars = { var vars = {
'url': '', 'url': '',
'param': [] 'param': []
}; };
this.construct = function(url, options){ this.construct = function(options){
$.extend(vars, options); if (typeof options == 'object') {
vars.url = url; $.extend(vars, options);
} else vars.url = options;
}; };
this.set_url = function (url){ this.set_url = function (url){
vars.url = url; vars.url = url;
@@ -79,5 +80,5 @@ var cSIMULATOR = function(url, options){
dataType: 'json' dataType: 'json'
}); });
}; };
this.construct(url, options); this.construct(options);
}; };
+1
View File
@@ -21,6 +21,7 @@
"flightphp/core": "^3.18", "flightphp/core": "^3.18",
"flightphp/session": "^0.3", "flightphp/session": "^0.3",
"mpdf/mpdf": ">=8.0", "mpdf/mpdf": ">=8.0",
"avadim/fast-excel-writer": "^6.17",
"matthiasmullie/minify": ">=1.3", "matthiasmullie/minify": ">=1.3",
"endroid/qr-code": ">=4.4" "endroid/qr-code": ">=4.4"
}, },
+4 -4
View File
@@ -2,7 +2,7 @@
/******************************************************************* /*******************************************************************
Module : /Data/CSV.php Module : /Data/Csv.php
Created By : Siau Pheng ([email protected]). Created By : Siau Pheng ([email protected]).
Created Date : April 2rd, 2011. Created Date : April 2rd, 2011.
Last Modified : August 21st, 2026. Last Modified : August 21st, 2026.
@@ -19,9 +19,9 @@ define( DELI_CSV, ";" );
define( CRLF_CSV, "\r\n" ); define( CRLF_CSV, "\r\n" );
/** /**
* Class CSV * Class Csv
* *
* Membuat file CSV. * Membuat file Csv.
* *
* @license MIT, https://www.3fonia.com * @license MIT, https://www.3fonia.com
* @copyright Copyright (c) 2008-2026, Siau Pheng <[email protected]> * @copyright Copyright (c) 2008-2026, Siau Pheng <[email protected]>
@@ -29,7 +29,7 @@ define( CRLF_CSV, "\r\n" );
* @package Webapp\Data * @package Webapp\Data
*/ */
final class CSV { final class Csv {
private $__avalue = []; private $__avalue = [];
private $__atabel = []; private $__atabel = [];
+26 -26
View File
@@ -2,7 +2,7 @@
/******************************************************************* /*******************************************************************
Module : /Data/PDF.php Module : /Data/Pdf.php
Created By : Siau Pheng ([email protected]). Created By : Siau Pheng ([email protected]).
Created Date : April 18th, 2015. Created Date : April 18th, 2015.
Last Modified : August 21st, 2026. Last Modified : August 21st, 2026.
@@ -19,9 +19,9 @@ use \flight\Engine;
use \Mpdf; use \Mpdf;
/** /**
* Class PDF * Class Pdf
* *
* Membuat file PDF. * Membuat file Pdf.
* *
* @license MIT, https://www.3fonia.com * @license MIT, https://www.3fonia.com
* @copyright Copyright (c) 2008-2026, Siau Pheng <[email protected]> * @copyright Copyright (c) 2008-2026, Siau Pheng <[email protected]>
@@ -29,11 +29,11 @@ use \Mpdf;
* @package Webapp\Data * @package Webapp\Data
*/ */
final class PDF { final class Pdf {
private $__avalue = []; private array $avalue = [];
private $__atabel = []; private array $atabel = [];
private $__theader = ""; private string $__theader = "";
private $__tcolname = ""; private string $__tcolname = "";
protected array $webapp; protected array $webapp;
protected array $webuser; 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 { 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 { public function show_fields(): void {
$tmp_out = "<thead><tr>"; $tmp_out = "<thead><tr>";
for ($i=0; $i<count($this->__atabel); $i++) { for ($i=0; $i<count($this->atabel); $i++) {
if ($this->__atabel[$i][4]==0) continue; 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 .= $this->set_align($this->atabel[$i][0], $this->atabel[$i][1], "C", false, true, $this->atabel[$i][4]);
} }
$tmp_out .= "</tr></thead>"; $tmp_out .= "</tr></thead>";
$this->__tcolname = $tmp_out; $this->__tcolname = $tmp_out;
} }
public function clear(): void { public function clear(): void {
$this->__avalue = []; $this->avalue = [];
$this->__theader = ""; $this->__theader = "";
$this->__tcolname = ""; $this->__tcolname = "";
} }
@@ -78,18 +78,18 @@ final class PDF {
$tmp_arr = func_get_args(); $tmp_arr = func_get_args();
if (is_array($tmp_arr[0])) $tmp_arr = $tmp_arr[0]; if (is_array($tmp_arr[0])) $tmp_arr = $tmp_arr[0];
$tmp_out = "<tr>"; $tmp_out = "<tr>";
for ($i=0; $i<count($this->__atabel); $i++) { for ($i=0; $i<count($this->atabel); $i++) {
$tmp_val = $tmp_arr[$i]; $tmp_val = $tmp_arr[$i];
if (is_array($this->__atabel[$i][2]) && trim($tmp_val)<>"") { if (is_array($this->atabel[$i][2]) && trim($tmp_val)<>"") {
$tmp_val = $this->__atabel[$i][2][$tmp_val]; $tmp_val = $this->atabel[$i][2][$tmp_val];
} else if (function_exists($this->__atabel[$i][2]) && trim($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 = 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 .= $tmp_val;
} }
$tmp_out .= "</tr>"; $tmp_out .= "</tr>";
$this->__avalue[] = $tmp_out; $this->avalue[] = $tmp_out;
} }
public function add_span(): void { public function add_span(): void {
@@ -104,15 +104,15 @@ final class PDF {
$tmp_out .= $tmp_val; $tmp_out .= $tmp_val;
} }
$tmp_out .= "</tr>"; $tmp_out .= "</tr>";
$this->__avalue[] = $tmp_out; $this->avalue[] = $tmp_out;
} }
public function add_empty(): void { public function add_empty(): void {
$this->__avalue[] = $this->set_align("&nbsp;", 0, "L,NB", true); $this->avalue[] = $this->set_align("&nbsp;", 0, "L,NB", true);
} }
public function add_stamp(int $ctk_ke=1, bool $tampil_nama=false): void { 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 { public function get_stamp(int $ctk_ke=1, bool $tampil_nama=false): string {
@@ -163,8 +163,8 @@ final class PDF {
$html .= '<tbody>'; $html .= '<tbody>';
// content out // content out
for ($i=0; $i<count($this->__avalue); $i++) { for ($i=0; $i<count($this->avalue); $i++) {
$html .= $this->__avalue[$i]; $html .= $this->avalue[$i];
} }
$html .= '</tbody></table></div></div></body>'; $html .= '</tbody></table></div></div></body>';
$mpdf = new mPDF('c', 'A4'.($orien==="L"?"-L":""), $fontz, '', 5, 5, 5, 10, 5, 5); $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); $tstyle = $this->create_style($dir);
if (strpos(strtolower($text), "<tr>")===false) { if (strpos(strtolower($text), "<tr>")===false) {
if ($line===true) { 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 { } else {
return (($head===true)?"<th":"<td").(($col>1)?' colspan="'.(string)$col.'"':"").' class="'.$tstyle.'" '.(($head===true)?'width="'.(string)$width.'"':"").">".$text.(($head===true)?"</th>":"</td>"); return (($head===true)?"<th":"<td").(($col>1)?' colspan="'.(string)$col.'"':"").' class="'.$tstyle.'" '.(($head===true)?'width="'.(string)$width.'"':"").">".$text.(($head===true)?"</th>":"</td>");
} }
+155
View File
@@ -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);
}
}
+94 -77
View File
@@ -5,7 +5,7 @@
Module : /Printer/PrintHTML.php Module : /Printer/PrintHTML.php
Created By : Siau Pheng ([email protected]). Created By : Siau Pheng ([email protected]).
Created Date : June 15th, 2008. Created Date : June 15th, 2008.
Last Modified : August 26th, 2026. Last Modified : October 2nd, 2026.
(c) 3FONIA Software; WWW.3FONIA.COM. (c) 3FONIA Software; WWW.3FONIA.COM.
@@ -29,10 +29,12 @@ use \flight\Engine;
*/ */
final class PrintHTML { final class PrintHTML {
private $__avalue = []; private array $avalue = [];
private $__atabel = []; private array $atabel = [];
private $__css = "table"; private string $css = "table";
private $__tstamp = ""; private string $stamp = "";
private array $titles = [];
private array $subtitles = [];
protected array $webapp; protected array $webapp;
protected array $webuser; protected array $webuser;
@@ -40,96 +42,114 @@ final class PrintHTML {
* @param Engine $app * @param Engine $app
*/ */
public function __construct(Engine $app) { public function __construct(Engine $app) {
$this->webapp = $app->session()->get('WEB_APP', ['APP_NAME'=>'', 'APP_VER'=>'']); $this->webapp = (array) $app->session()->get('WEB_APP', ['APP_NAME'=>'', 'APP_VER'=>'']);
$this->webuser = $app->session()->get('WEB_USER', ['UserID'=>0, 'Username'=>'']); $this->webuser = (array) $app->session()->get('WEB_USER', ['UserID'=>0, 'Username'=>'']);
} }
public function set_css(string $style): void { 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 { public function add_title(string|array $judul): void {
$this->__atabel[] = [ $nama, $lebar, $func, $align, $kol ]; if (empty($judul)) return;
if (is_array($judul)) {
$this->titles = $judul;
} else array_push($this->titles, $judul);
} }
public function clear(): void { public function add_sub_title(string|array $judul): void {
$this->__avalue = []; if (empty($judul)) return;
if (is_array($judul)) {
$this->subtitles = $judul;
} else array_push($this->subtitles, $judul);
} }
public function add_value(): void { public function add_field(string $nama, int $lebar=0, string $align="L", callable|array|null $func=null, int $kol=1): void {
$tmp_arr = func_get_args(); $this->atabel[] = [ 'n' => $nama, 'l' => $lebar, 'f' => $func, 'a' => $align, 'k' => $kol ];
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_span(): void { public function add_row(array $row): void {
$tmp_arr = func_get_args(); if (!is_array($row) || empty($row)) return;
$tmp_out = "<tr>"; $row_out = "<tr>";
for ($i=0; $i<count($tmp_arr); $i++) { foreach ($this->atabel as $i => $tabel) {
$tmp_val = $tmp_arr[$i];// CONTENT, COLSPAN=1, L, FUNC, EXTRA $col_val = $row[$i] ?? '';
if (!isset($tmp_val[1])) $tmp_val[1] = 1; if (!empty($col_val)) {
if (!isset($tmp_val[2])) $tmp_val[2] = "L"; if (is_array($tabel['f'])) {
if (!isset($tmp_val[4])) $tmp_val[4] = ""; $col_val = $tabel['f'][$col_val];
if (isset($tmp_val[3])) { } else if (is_callable($tabel['f'])) {
if (function_exists($tmp_val[3]) && trim("".$tmp_val[0])<>"") { $col_val = call_user_func($tabel['f'], $col_val);
$tmp_val[0] = call_user_func($tmp_val[3], $tmp_val[0]);
} }
} }
$tmp_val = $this->set_align($tmp_val[0], 0, $tmp_val[2], false, false, $tmp_val[1], $tmp_val[4]); $row_out .= $this->set_align((string) $col_val, $tabel['l'], $tabel['a']);
$tmp_out .= $tmp_val;
} }
$tmp_out .= "</tr>"; $row_out .= "</tr>";
$this->__avalue[] = $tmp_out; echo $row_out;
} }
public function add_stamp(int $ctk_ke=1, bool $cetak_nama=false): void { public function add_span(array $span): void {
$this->__tstamp = $this->get_stamp($ctk_ke, $cetak_nama); if (!is_array($span) || empty($span)) return;
} $row_out = "<tr>";
foreach ($span as $col) {
public function get_stamp(int $ctk_ke=1, bool $cetak_nama=false): string { // CONTENT, COLSPAN=1, L, FUNC, EXTRA
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):""); if (!isset($col[1])) $col[1] = 1;
} if (!isset($col[2])) $col[2] = "L";
if (!isset($col[4])) $col[4] = "";
public function show(int $jumlah_ctk=1) { if (isset($col[3]) && is_callable($col[3])) {
$out = "<table class=\"".$this->__css."\"><thead>"; if (function_exists($col[3]) && !empty($col[0])) {
$col[0] = call_user_func($col[3], $col[0]);
// header out }
$tmp_out = "<tr>"; }
for ($i=0; $i<count($this->__atabel); $i++) { $row_out .= $this->set_align($col[0], 0, $col[2], false, false, $col[1], $col[4]);
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>"; $row_out .= "</tr>";
$out .= "</thead>".$tmp_out."<tbody>"; echo $row_out;
// 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;
} }
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); $tstyle = $this->create_style($dir);
if ($line===true) { 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 { } else {
return (($head===true)?"<th":"<td").(($col>1)?" colspan=\"".(string)$col."\"":"")." class=\"".$tstyle." ".$extra."\" ".(($head===true)?"width=\"".(string)$width."\"":"").">".$text.(($head===true)?"</th>":"</td>"); 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); 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 Module : /Printer/PrintPOS.php
Created By : Siau Pheng ([email protected]). Created By : Siau Pheng ([email protected]).
Created Date : June 15th, 2008. Created Date : June 15th, 2008.
Last Modified : September 21st, 2026. Last Modified : October 3rd, 2026.
(c) 3FONIA Software; WWW.3FONIA.COM. (c) 3FONIA Software; WWW.3FONIA.COM.
@@ -29,12 +29,11 @@ use \flight\Engine;
*/ */
class PrintPOS { class PrintPOS {
private $_header = []; private int $sheet = 0;
private $_avalue = []; private int $maxchr = 40;
private $_astyle = []; private array $header = [];
private $_ncont = 0; private array $acontent = [];
private $_maxchr = 40; private array $config = [
private $_config = [
'fontsize' => 1, 'fontsize' => 1,
'opendraw' => false, 'opendraw' => false,
'cutpaper' => false, 'cutpaper' => false,
@@ -54,53 +53,52 @@ class PrintPOS {
} }
public function set_opendrawer(): void { public function set_opendrawer(): void {
$this->_config['opendraw'] = true; $this->config['opendraw'] = true;
} }
public function set_cutpaper(): void { public function set_cutpaper(): void {
$this->_config['cutpaper'] = true; $this->config['cutpaper'] = true;
} }
public function set_maxchr(int $max = 0): void { 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 { 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 { public function set_header_logo(string $logo_file = ""): void {
if (!empty($logo_file) && file_exists(PROJECT_ROOT."public/assets/images/".$logo_file)) { 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'] = PROJECT_BASE."assets/images/".$logo_file;
$this->_config['logo'] = base64_encode(file_get_contents(PROJECT_ROOT."public/assets/images/".$logo_file)); $this->config['logo'] = base64_encode(file_get_contents(PROJECT_ROOT."public/assets/images/".$logo_file));
} }
} }
public function add_header(): void { public function add_header(): void {
$extra = func_get_args(); $extra = func_get_args();
if (count($extra) > 0) { if (count($extra) > 0) $this->header = $extra;
foreach ($extra as $_val) {
$this->_header[] = $_val;
}
}
} }
public function add_sheet(): void { public function add_sheet(): void {
$this->_ncont++; $this->sheet++;
} }
public function add(): void { public function add(): void {
$val_arr = func_get_args(); $ttext = ""; $tstyle = "L"; $val_arr = func_get_args(); $ttext = ""; $tstyle = "L";
if (is_array($val_arr[0])) { if (is_array($val_arr[0])) {
foreach($val_arr as $aval) { 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)); $ttext .= $this->set_align(($aval[0] ?? ""), ($aval[1] ?? 0), ($aval[2] ?? $tstyle));
} }
} else { } else {
$ttext = (isset($val_arr[0])) ? $val_arr[0] : ""; $ttext = $val_arr[0] ?? "";
$tstyle = (isset($val_arr[1])) ? $val_arr[1] : $tstyle; $tstyle = $val_arr[1] ?? $tstyle;
} }
$this->_avalue[$this->_ncont][] = $ttext; if (str_contains($ttext, "_LINE")) {
$this->_astyle[$this->_ncont][] = $tstyle; $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 { public function addl(string $text = ""): void {
@@ -128,25 +126,11 @@ class PrintPOS {
} }
public function show(int $jumlah_ctk=1): void { public function show(int $jumlah_ctk=1): void {
$acontent = []; $this->config['times'] = $jumlah_ctk;
$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;
$aout = ['type' => "escp"]; $aout = ['type' => "escp"];
$aout['config'] = $this->_config; $aout['config'] = $this->config;
$aout['header'] = $this->_header; $aout['header'] = $this->header;
$aout['content'] = $acontent; $aout['content'] = $this->acontent;
$this->app->json($aout); $this->app->json($aout);
} }
@@ -157,8 +141,6 @@ class PrintPOS {
return str_pad($text, $len, " ", $apad[$dir]); return str_pad($text, $len, " ", $apad[$dir]);
} }
//todo: deprecated
public function set_printnv_logo() {}//delete
} }
?> ?>