first commit
This commit is contained in:
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
PHP Class : /Controller/Table/Ppob/ProdukController
|
||||
Description : Master Produk PPOB
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : May 19th, 2010.
|
||||
Last Modified : September 1st, 2026.
|
||||
|
||||
(c) 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Table\Ppob;
|
||||
|
||||
use flight\Engine;
|
||||
use flight\Session;
|
||||
use flight\database\SimplePdo;
|
||||
use Webapp\DB\SQL;
|
||||
use Webapp\Printer\PrintHTML;
|
||||
use Webapp\Web\Form;
|
||||
use Webapp\Web\Param;
|
||||
use Webapp\Web\Table;
|
||||
use App\Utils\Invesa;
|
||||
use App\Utils\PPOBClient;
|
||||
|
||||
class ProdukController {
|
||||
|
||||
private string $reg_name;
|
||||
private string $mode_detail;
|
||||
private int $id_ope;
|
||||
private int $id_kate;
|
||||
private int $id_produk;
|
||||
protected Engine $app;
|
||||
protected SimplePdo $db;
|
||||
|
||||
public function __construct(Engine $app, SimplePdo $db, Session $session) {
|
||||
$this->app = $app;
|
||||
$this->db = $db;
|
||||
$this->reg_name = (string) $session->get('WEB_APP')['REG_NAME'];
|
||||
$this->mode_detail = Param::Get("mode_detail", "");
|
||||
$this->id_kate = (int) Param::Get("KateID", 0);
|
||||
$this->id_ope = (int) Param::Get("OpeID", 0);
|
||||
$this->id_produk = (int) Param::Get("ProdukID", 0);
|
||||
}
|
||||
|
||||
public function table_produk() {
|
||||
if ($this->mode_detail === "update") {
|
||||
$sql = new SQL($this->app);
|
||||
$sql->set_table("ppob_produk");
|
||||
$sql->add_param("OpeID");
|
||||
$sql->add_param("KateID");
|
||||
$sql->add_param("Nama_Produk");
|
||||
$sql->add_param("Harga_Pokok");
|
||||
$sql->add_param("Harga_Jual");
|
||||
$sql->add_param("Status");
|
||||
$sql->add_param_userid();
|
||||
$sql->add_where("ProdukID");
|
||||
$sql->UpdateDB();
|
||||
}
|
||||
|
||||
$tcari = Param::Get("Cari_Produk");
|
||||
$tsql = ''; $asql = [];
|
||||
if (!empty($tcari)) {
|
||||
$tsql = 'Nama_Produk LIKE ?';
|
||||
$asql[] = '%'. $tcari .'%';
|
||||
}
|
||||
|
||||
$obj = new Table($this->app);
|
||||
$obj->set_table("ppob_produk", "*,((Harga_Jual-Harga_Pokok)/Harga_Pokok)*100 Margin", $tsql, $asql);
|
||||
$obj->add_field("ProdukID", "ID", "hid");
|
||||
$obj->add_field("Nama_Produk", "Nama Produk", "awr");
|
||||
$obj->add_field("Harga_Pokok", "Harga Modal", "r", "rupiah");
|
||||
$obj->add_field("Harga_Jual", "Harga Jual", "r", "rupiah");
|
||||
$obj->add_field("Margin", "%", "r", "rupiah2");
|
||||
$obj->add_field("Status", "Status", "c", "checkbox");
|
||||
$obj->set_field_order("Nama_Produk", "A");
|
||||
$obj->set_row_color("Harga_Jual", "0", "rdanger");
|
||||
$obj->add_row_btn("clipboard", "Ubah", "PPOBProdukJS.produk_ubah");
|
||||
$this->app->json([ $obj->json_table("divDetail") ]);
|
||||
}
|
||||
|
||||
public function form_produk() {
|
||||
$atabel = ['ProdukID'=>0, 'Kode'=>"", 'Nama_Produk'=>"", 'OpeID'=>0, 'Harga_Pokok'=>0, 'Harga_Jual'=>0, 'Status'=>1];
|
||||
if ($this->id_produk > 0) {
|
||||
$atabel = $this->db->fetchRow("SELECT * FROM ppob_produk WHERE ProdukID=?", [$this->id_produk]);
|
||||
}
|
||||
|
||||
$form = new Form($this->app);
|
||||
$tkode = $form->textbox("_", "Kode", $atabel['Kode'], false, false, "text");
|
||||
$tnama = $form->textbox("_", "Nama_Produk", $atabel['Nama_Produk'], true, true, "text", "nama produk");
|
||||
$tkate = $form->option_db("_", "KateID", $atabel['KateID'], true, false, "ppob_kategori", ["KateID","N_Kate"], "Status=1 ORDER BY N_Kate");
|
||||
$tope = $form->option_db("_", "OpeID", $atabel['OpeID'], true, false, "ppob_operator", ["OpeID","N_Ope"], "Status=1 ORDER BY N_Ope");
|
||||
$thpp = $form->textbox("_", "Harga_Pokok", $atabel['Harga_Pokok'], true, true, "double", "harga pokok");
|
||||
$tjual = $form->textbox("_", "Harga_Jual", $atabel['Harga_Jual'], true, true, "double", "harga jual");
|
||||
$tstatus = $form->radio("_", "Status", $atabel['Status'], true, true, ['1'=>"Aktif",'0'=>"Tidak"]);
|
||||
$ajson['html'] = '
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-4 col-lg-2 col-form-label" for="KateID">Nama Kategori</label>
|
||||
<div class="col-sm-4 col-lg-5">'.$tkate.'</div>
|
||||
<div class="col d-flex gap-2 justify-content-end"><label class="col-form-label me-2">Status ?</label>'.$tstatus.'</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-4 col-lg-2 col-form-label" for="OpeID">Nama Operator</label>
|
||||
<div class="col-sm-4 col-lg-5">'.$tope.'</div>
|
||||
<div class="col-sm-4 col-lg-5"><div class="input-group"><span class="input-group-text" style="min-width:30%;">Kode Produk</span>'.$tkode.'</div></div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-4 col-lg-2 col-form-label" for="Nama_Produk">Nama Produk</label>
|
||||
<div class="col">'.$tnama.'</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-4 col-lg-2 col-form-label" for="Harga_Pokok">Harga Pokok</label>
|
||||
<div class="col-sm-4 col-lg-3">'.$thpp.'</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-4 col-lg-2 col-form-label" for="Harga_Jual">Harga Jual</label>
|
||||
<div class="col-sm-4 col-lg-3">'.$tjual.'</div>
|
||||
</div>
|
||||
<input type="hidden" id="ProdukID" value="'.$atabel['ProdukID'].'" />
|
||||
<input type="hidden" id="mode_detail" value="'.$this->mode_detail.'" />';
|
||||
$this->app->json($ajson);
|
||||
}
|
||||
|
||||
public function detail_print() {
|
||||
$form = new Form($this->app);
|
||||
$tkate = $form->option_db("_", "KateID", 0, true, false, "ppob_kategori", ["KateID","N_Kate"], "Status=1 ORDER BY N_Kate", [0,"SEMUA KATEGORI"]);
|
||||
$tope = $form->option_db("_", "OpeID", 0, true, false, "ppob_operator", ["OpeID","N_Ope"], "Status=1 ORDER BY N_Ope", [0,"SEMUA OPERATOR"]);
|
||||
$ttgl = $form->datebox("_", "Tgl_Cetak", tgl_ymd(), true, false);
|
||||
$ajson['html'] = '
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-4 col-lg-3 col-form-label" for="KateID">Nama Kategori</label>
|
||||
<div class="col">'.$tkate.'</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-4 col-lg-3 col-form-label" for="OpeID">Nama Operator</label>
|
||||
<div class="col">'.$tope.'</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-4 col-lg-3 col-form-label" for="Tgl_Cetak">Tanggal Cetak</label>
|
||||
<div class="col-sm-4 col-lg-4">'.$ttgl.'</div>
|
||||
</div>';
|
||||
$this->app->json($ajson);
|
||||
}
|
||||
|
||||
public function detail_update() {
|
||||
$form = new Form($this->app);
|
||||
$tkate = $form->option_db("_", "K_Kate", "", true, false, "ppob_kategori", ["K_Kate","N_Kate"], "Status=1 ORDER BY N_Kate", ["","SEMUA KATEGORI"]);
|
||||
$tope = $form->option_db("_", "K_Ope", "", true, false, "ppob_operator", ["K_Ope","N_Ope"], "Status=1 ORDER BY N_Ope", ["","SEMUA OPERATOR"]);
|
||||
$ajson['html'] = '
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-4 col-lg-3 col-form-label" for="K_Kate">Nama Kategori</label>
|
||||
<div class="col">'.$tkate.'</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-4 col-lg-3 col-form-label" for="K_Ope">Nama Operator</label>
|
||||
<div class="col">'.$tope.'</div>
|
||||
</div>';
|
||||
$this->app->json($ajson);
|
||||
}
|
||||
|
||||
public function proses_update() {
|
||||
// PROSES API TRIFONIA PULSA
|
||||
$cppob = new PPOBClient($this->app);
|
||||
$appob = $cppob->Produk(Param::Get("K_Kate"), Param::Get("K_Ope"));
|
||||
if (count($appob) > 0 && (int) $appob['Status'] === 4) {
|
||||
$ajson[] = ['type'=>"msg", 'mode'=>"info", 'wait'=>2000, 'value'=>$appob['Message']];
|
||||
} else {
|
||||
$ajson[] = ['type'=>"msg", 'mode'=>"error", 'wait'=>2000, 'value'=>$appob['Message']];
|
||||
}
|
||||
$this->app->json($ajson);
|
||||
}
|
||||
|
||||
public function print_produk() {
|
||||
$nama_kate = ""; $nama_ope = "";
|
||||
if ($this->id_kate > 0) $nama_kate = $this->db->fetchField("SELECT N_Kate FROM ppob_kategori WHERE KateID=?", [$this->id_kate]);
|
||||
if ($this->id_ope > 0) $nama_ope = $this->db->fetchField("SELECT N_Ope FROM ppob_operator WHERE OpeID=?", [$this->id_ope]);
|
||||
|
||||
// generate report header
|
||||
$tglheader = "Tanggal Cetak : ".Param::Get("Tgl_Cetak");
|
||||
$tsql = ''; $asql = [];
|
||||
if ($this->id_kate > 0) { $tsql .= " AND KateID=?"; $asql[] = $this->id_kate; }
|
||||
if ($this->id_ope > 0) { $tsql .= " AND OpeID=?"; $asql[] = $this->id_ope; }
|
||||
$tsql = (strlen($tsql) > 0) ? ' WHERE '.substr($tsql, 4) : '';
|
||||
|
||||
// query data laporan
|
||||
$stat = $this->db->runQuery("SELECT * FROM ppob_produk".$tsql." ORDER BY KateID,OpeID,ProdukID", $asql);
|
||||
|
||||
$pre = new PrintHTML($this->app);
|
||||
$pre->add_title([strtoupper($this->reg_name), "Laporan Daftar Produk PPOB", $tglheader]);
|
||||
|
||||
$pre->add_field("No",10,"C");
|
||||
$pre->add_field("Nama Produk",80);
|
||||
$pre->add_field("Harga Modal",12, "R", "rupiah");
|
||||
$pre->add_field("Harga Jual",12, "R", "rupiah");
|
||||
$pre->add_field("Margin",12, "R", "rupiah");
|
||||
$pre->add_field("%",5, "R", "rupiah2");
|
||||
|
||||
if ($this->id_kate > 0) $pre->add_sub_title("Nama Kategori : ".$nama_kate);
|
||||
if ($this->id_ope > 0) $pre->add_sub_title("Nama Operator : ".$nama_ope);
|
||||
|
||||
$pre->show_titles();
|
||||
$pre->show_headers();
|
||||
|
||||
$nomor = 0;
|
||||
while ($row = $stat->fetch(SimplePdo::FETCH_ASSOC)) {
|
||||
$pre->add_row([ ++$nomor, $row['Nama_Produk'], $row['Harga_Pokok'], $row['Harga_Jual'], ((float) $row['Harga_Jual']-(float) $row['Harga_Pokok']), ((((float) $row['Harga_Jual']-(float) $row['Harga_Pokok'])*100)/(float) $row['Harga_Pokok']) ]);
|
||||
}
|
||||
$pre->add_stamp(0, true);
|
||||
$pre->show();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$this->app->json(['html' => '
|
||||
<div class="fade-in"><div class="card"><div class="card-header custom-style">Daftar Produk PPOB</div><div class="card-body"><div class="row mb-1"><div class="col-9"><div class="input-group"><input class="form-control" id="Cari_Produk" 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><div class="col-3 btn-group"><button class="btn btn-info shadow-none" type="button" id="butPrint"><i class="bi-printer me-2"></i>Cetak</button><button class="btn btn-warning shadow-none" type="button" id="butUpdate"><i class="bi-download me-2"></i>Update Produk</button></div></div><div id="divDetail"> </div></div></div></div>'
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user