209 lines
11 KiB
PHP
209 lines
11 KiB
PHP
<?php
|
|
|
|
/*******************************************************************
|
|
|
|
PHP Class : /Controller/Ppob/PpobtxController
|
|
Description : Transaksi PPOB
|
|
Created By : Siau Pheng ([email protected]).
|
|
Created Date : October 6th, 2017.
|
|
Last Modified : September 16th, 2026.
|
|
|
|
(c) 3FONIA Software; WWW.3FONIA.COM.
|
|
|
|
*******************************************************************/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Controller\Ppob;
|
|
|
|
use App\Utils\PPOBClient;
|
|
use flight\Engine;
|
|
use flight\Session;
|
|
use flight\database\SimplePdo;
|
|
use Webapp\Web\Form;
|
|
use Webapp\Web\Param;
|
|
use Webapp\Web\Table;
|
|
|
|
class PpobtxController {
|
|
|
|
private int $id_cab;
|
|
private int $id_agen;
|
|
private string $mode_detail;
|
|
private string $tgl_from;
|
|
private string $tgl_to;
|
|
private string $no_tx;
|
|
private PPOBClient $ppob;
|
|
protected Engine $app;
|
|
protected SimplePdo $db;
|
|
|
|
public function __construct(Engine $app, SimplePdo $db, Session $session) {
|
|
$this->app = $app;
|
|
$this->db = $db;
|
|
$this->id_cab = Param::Int("CabID", (int) $session->get('APP_INV')['CABANGID']);
|
|
$this->id_agen = (int) $session->get('APP_PPOB')['API_AGENID'];
|
|
$this->mode_detail = Param::Get("mode_detail", "");
|
|
$this->tgl_from = Param::Get("Tgl_From", tgl_dmy());
|
|
$this->tgl_to = Param::Get("Tgl_To", tgl_dmy());
|
|
$this->no_tx = Param::Get("No_TX", "");
|
|
$this->ppob = new PPOBClient($app);
|
|
}
|
|
|
|
public function table_tx() {
|
|
$ajson = [];
|
|
if (in_array($this->mode_detail, ["reproc","delete"])) {
|
|
$adetail = $this->db->fetchRow("SELECT * FROM ppob_tx WHERE No_TX=?", [$this->no_tx]) ?? [];
|
|
if ($this->mode_detail === "delete") {
|
|
if (count($adetail) > 0 && (int) $adetail['Status'] === 0) {
|
|
$this->db->runQuery("DELETE FROM ppob_tx WHERE No_TX=? AND Status=0 LIMIT 1", [$this->no_tx]);
|
|
$ajson[] = ['type'=>"msg", 'mode'=>"info", 'wait'=>2000, 'value'=>"Proses Hapus sukses !"];
|
|
} else {
|
|
$ajson[] = ['type'=>"msg", 'mode'=>"error", 'wait'=>2000, 'value'=>"Ada masalah dalam Proses Hapus !"];
|
|
}
|
|
} else if ($this->mode_detail === "reproc") {
|
|
if (count($adetail) > 0 && (int) $adetail['Proses'] === 0) {
|
|
// PROSES API TRIFONIA PULSA
|
|
$appob = $this->ppob->TopUp($adetail['Kode'], $adetail['Tujuan'], $adetail['No_TX'], $adetail['No_HP']);
|
|
if (count($appob) > 0) {
|
|
$ajson[] = ['type'=>"msg", 'mode'=>"info", 'wait'=>2000, 'value'=>$appob['Message']];
|
|
}
|
|
} else {
|
|
$ajson[] = ['type'=>"msg", 'mode'=>"error", 'wait'=>2000, 'value'=>"Ada masalah dalam Proses !"];
|
|
}
|
|
}
|
|
}
|
|
|
|
$saldo_ppob = (float) $this->db->fetchField("SELECT API_SALDO FROM ppob_config WHERE API_AGENID=?", [$this->id_agen]) ?? 0;
|
|
|
|
$cari = Param::Get("Cari_TX", "");
|
|
$tsql = 'CabID=?'; $asql = [$this->id_cab];
|
|
if (empty($cari)) {
|
|
$tgl_from = tgl_sql2str($this->tgl_from);
|
|
$tgl_to = tgl_sql2str($this->tgl_to);
|
|
$tsql .= " AND (Tgl_TX BETWEEN ? AND ?)";
|
|
array_push($asql, $tgl_from, $tgl_to);
|
|
} else {
|
|
$tsql .= " AND CONCAT(No_TX,DATE_FORMAT(Tgl_TX,'%d-%m-%Y'),Tujuan,No_HP) LIKE ?";
|
|
$asql[] = '%' . $cari . '%';
|
|
}
|
|
|
|
$obj = new Table($this->app);
|
|
$obj->set_table("(SELECT *,CONCAT(DATE_FORMAT(DateStamp,'%d-%m-%Y %H:%i:%s'),' - ',Kode,'<br><b>',Tujuan,'</b>',IF(No_HP='','',CONCAT('<br><i>HP : ',No_HP,'</i>'))) Info_TX FROM ppob_tx WHERE ".$tsql.") T LEFT JOIN (SELECT ProdukID, KateID FROM ppob_produk) P ON (P.ProdukID=T.ProdukID)", "T.*,IFNULL(P.KateID,0) KateID", "", $asql);
|
|
$obj->set_footer("SUM(Harga_Jual) Harga_Jual");
|
|
$obj->add_field("No_TX", "No. TX", "c");
|
|
$obj->add_field("KateID", "Kate", "c", "App\Utils\PPOBClient::Icon_Kate");
|
|
$obj->add_field("Info_TX", "Informasi Transaksi", "l");
|
|
$obj->add_field("Harga_Jual", "Harga", "r", "rupiah", "rupiah");
|
|
$obj->add_field("Proses", "P", "c", "checkbox");
|
|
$obj->add_field("Status", "Status", "c", "App\Utils\PPOBClient::Badge_Status");
|
|
$obj->set_field_order("No_TX", "D");
|
|
$obj->add_row_btn("printer", "Cetak Nota", "PPOBTXJS.nota_print", "Proses", 1);
|
|
$obj->add_row_btn("arrow-left-right", "Proses Ulang", "PPOBTXJS.nota_reproc", "Proses", 0);
|
|
$obj->add_row_btn("clipboard", "Detail", "PPOBTXJS.nota_detail", "Proses", 1);
|
|
if ($this->app->user()->is_level(1)) $obj->add_row_btn("trash", "Hapus", "PPOBTXJS.nota_delete", "Status", 0);
|
|
$obj->set_func_btn("PPOBTXJS.saldo_ppob", '<i class="bi-coin me-2"></i>Saldo Rp. '.rupiah($saldo_ppob));
|
|
$ajson[] = $obj->db_table("divDetailTabel");
|
|
$this->app->json($ajson);
|
|
}
|
|
|
|
public function form_tx() {
|
|
$ainfo = $this->db->fetchRow("SELECT T.*,DATE_FORMAT(T.DateStamp,'%d-%m-%Y %H:%i:%s') Tgl_TX1,IFNULL(P.KateID,0) KateID,P.Nama_Produk FROM (SELECT * FROM ppob_tx WHERE No_TX=? LIMIT 1) T LEFT JOIN ppob_produk P ON (P.ProdukID=T.ProdukID)", [$this->no_tx]) ?? [];
|
|
$atoken = $this->ppob->SN_PLN($ainfo['SN']);
|
|
|
|
$ajson['html'] = '
|
|
<div class="row text-start">
|
|
<label class="col-sm-12 col-lg-5 col-form-label">Nomor TX</label>
|
|
<label class="col-sm-12 col-lg-7 col-form-label"><strong>'.$ainfo['No_TX'].'</strong></label>
|
|
</div>
|
|
<div class="row text-start">
|
|
<label class="col-sm-12 col-lg-5 col-form-label">Tanggal TX</label>
|
|
<label class="col-sm-12 col-lg-7 col-form-label"><strong>'.$ainfo['Tgl_TX1'].'</strong></label>
|
|
</div>
|
|
<div class="row text-start">
|
|
<label class="col-sm-12 col-lg-5 col-form-label">Nomor Tujuan</label>
|
|
<label class="col-sm-12 col-lg-7 col-form-label"><strong>'.$ainfo['Tujuan'].'</strong></label>
|
|
</div>
|
|
<div class="row text-start'.((int) $ainfo['KateID'] === 5?'':' d-none').'">
|
|
<label class="col-sm-12 col-lg-5 col-form-label">Nomor HP</label>
|
|
<label class="col-sm-12 col-lg-7 col-form-label">'.($ainfo['No_HP']==""?"<i>tidak tersedia</i>":$ainfo['No_HP']).'</label>
|
|
</div>
|
|
<div class="row text-start">
|
|
<label class="col-sm-12 col-lg-5 col-form-label">Nama Produk</label>
|
|
<label class="col-sm-12 col-lg-7 col-form-label">'.$ainfo['Nama_Produk'].'</label>
|
|
</div>
|
|
<div class="row text-start">
|
|
<label class="col-sm-12 col-lg-5 col-form-label">Harga Jual</label>
|
|
<label class="col-sm-12 col-lg-7 col-form-label"><strong>Rp. '.rupiah($ainfo['Harga_Jual']).'</strong></label>
|
|
</div>
|
|
<div class="row text-start">
|
|
<label class="col-sm-12 col-lg-5 col-form-label">Status TX</label>
|
|
<label class="col-sm-12 col-lg-7 col-form-label">'.$this->ppob->Badge_Status($ainfo['Status']).'</label>
|
|
</div>';
|
|
if ((int) $ainfo['Status'] === 4) {
|
|
$ajson['html'] .= '<div class="row mt-1"><div class="col"><hr class="my-2"></div></div>';
|
|
if ((int) $ainfo['KateID'] === 5) {
|
|
$ajson['html'] .= '
|
|
<div class="row text-start">
|
|
<label class="col-sm-12 col-lg-5 col-form-label">Nama Pelanggan</label>
|
|
<label class="col-sm-12 col-lg-7 col-form-label">'.$atoken['Nama'].'</label>
|
|
</div>
|
|
<div class="row text-start">
|
|
<label class="col-sm-12 col-lg-5 col-form-label">Tarif / Daya</label>
|
|
<label class="col-sm-12 col-lg-7 col-form-label">'.$atoken['Daya'].'</label>
|
|
</div>
|
|
<div class="row text-start">
|
|
<label class="col-sm-12 col-lg-5 col-form-label">Nilai Token</label>
|
|
<label class="col-sm-12 col-lg-7 col-form-label">'.$atoken['Kwh'].'</label>
|
|
</div>
|
|
<div class="row text-start">
|
|
<label class="col-sm-12 col-lg-5 col-form-label">Kode Token</label>
|
|
<label class="col-sm-12 col-lg-7 col-form-label"><strong>'.$atoken['Token'].'</strong></label>
|
|
</div>';
|
|
} else {
|
|
$ajson['html'] .= '
|
|
<div class="row text-start">
|
|
<label class="col-sm-12 col-lg-5 col-form-label">SN / Informasi</label>
|
|
<label class="col-sm-12 col-lg-7 col-form-label">'.$ainfo['SN'].'</label>
|
|
</div>';
|
|
}
|
|
}
|
|
$this->app->json($ajson);
|
|
}
|
|
|
|
public function form_saldo() {
|
|
$asaldo = $this->ppob->Balance();
|
|
$ajson['Saldo'] = (count($asaldo) > 0 && (int) $asaldo['Status'] === 4) ? rupiah($asaldo['Saldo']) : 0;
|
|
$this->app->json($ajson);
|
|
}
|
|
|
|
public function index() {
|
|
$hari_ini = tgl_dmy();
|
|
$this->app->json(['html' => '
|
|
<div class="fade-in">
|
|
<div class="card"><div class="card-body">
|
|
<ul class="nav nav-tabs" role="tablist">
|
|
<li class="nav-item" role="presentation">
|
|
<button class="nav-link active" id="tx-tab" data-bs-toggle="tab" data-bs-target="#tx" type="button" role="tab" aria-controls="tx" aria-selected="true"><i class="bi-database me-2"></i>Daftar Transaksi PPOB</button>
|
|
</li>
|
|
<li class="nav-item ms-auto">
|
|
<div class="d-flex">
|
|
<div class="d-flex">
|
|
<div class="input-group date"><input type="text" class="form-control pickdate" id="Tgl_From" name="Tgl_From" value="'.$hari_ini.'" placeholder="dd-mm-yyyy" size="22"><span class="input-group-text input-group-addon"><i class="bi-calendar4"></i></span></div>
|
|
<span class="input-group-text">~</span>
|
|
<div class="input-group date"><input type="text" class="form-control pickdate" id="Tgl_To" name="Tgl_To" value="'.$hari_ini.'" placeholder="dd-mm-yyyy" size="22"><span class="input-group-text input-group-addon"><i class="bi-calendar4"></i></span></div>
|
|
</div>
|
|
<div class="input-group ms-2"><input class="form-control" id="Cari_TX" placeholder="Kunci Pencarian" type="text"><button class="btn btn-info shadow-none" type="button" id="butSearch">Cari</button><button class="btn btn-secondary shadow-none" type="button" id="butAll">Semua</button></div>
|
|
</div>
|
|
</li>
|
|
</ul>
|
|
<div class="tab-content border border-top-0 p-3">
|
|
<div class="tab-pane fade active show" id="tx" role="tabpanel" aria-labelledby="tx-tab">
|
|
<div id="divDetailTabel"> </div>
|
|
</div>
|
|
</div>
|
|
</div></div>
|
|
</div>'
|
|
]);
|
|
}
|
|
|
|
}
|