Files
cmasa/app/Controller/Table/SupplierController.php
T
2026-10-29 13:34:31 +07:00

136 lines
6.0 KiB
PHP

<?php
/*******************************************************************
PHP Class : /Controller/Table/SupplierController
Description : Master Supplier
Created By : Siau Pheng ([email protected]).
Created Date : December 7th, 2010.
Last Modified : August 31st, 2026.
(c) 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace App\Controller\Table;
use flight\Engine;
use flight\database\SimplePdo;
use Webapp\DB\SQL;
use Webapp\Web\Form;
use Webapp\Web\Param;
use Webapp\Web\Table;
class SupplierController {
private string $mode_detail;
private int $id_sup;
protected Engine $app;
protected SimplePdo $db;
public function __construct(Engine $app, SimplePdo $db) {
$this->app = $app;
$this->db = $db;
$this->mode_detail = Param::Get("mode_detail", "");
$this->id_sup = (int) Param::Get("SupID", 0);
}
public function table_detail() {
if (in_array($this->mode_detail, ["insert","update","delete"])) {
$sql = new SQL($this->app);
$sql->set_table("para_supplier");
$sql->add_param("Kode_Sup");
$sql->add_param("Nama_Sup");
$sql->add_param("Alamat_Sup");
$sql->add_param("Telp_Sup");
$sql->add_param("No_NPWP");
$sql->add_param("No_NITKU");
$sql->add_param("Aktif");
$sql->add_param_userid();
$sql->add_where("SupID");
if ($this->mode_detail === "insert") {
$sql->InsertDB();
} else if ($this->mode_detail === "update") {
$sql->UpdateDB();
} else if ($this->mode_detail === "delete") {
$sql->DeleteDB();
}
}
$tcari = Param::Get("Cari_Sup");
$tsql = ''; $asql = [];
if (!empty($tcari)) {
$tsql = 'CONCAT(Kode_Sup,Nama_Sup,Telp_Sup) LIKE ?';
$asql[] = '%'. $tcari .'%';
}
$obj = new Table($this->app);
$obj->set_table("para_supplier", "*", $tsql, $asql);
$obj->add_field("SupID", "ID", "hid");
$obj->add_field("Kode_Sup", "Kode Supplier");
$obj->add_field("Nama_Sup", "Nama Supplier", "awr");
$obj->add_field("Telp_Sup", "No. Telp", "l");
$obj->add_field("Aktif", "Aktif", "c", "checkbox");
$obj->set_field_order("Kode_Sup", "A");
$obj->add_row_btn("clipboard", "Ubah", "SupplierJS.detail_ubah");
$obj->add_row_btn("trash", "Hapus", "SupplierJS.detail_hapus");
$obj->set_func_btn("SupplierJS.detail_tambah", "+ Supplier");
$this->app->json([ $obj->json_table("divDetail") ]);
}
public function form_supplier() {
$atabel = ['SupID'=>0, 'Kode_Sup'=>"", 'Nama_Sup'=>"", 'Alamat_Sup', 'Telp_Sup'=>"", 'No_NPWP'=>"", 'No_NITKU'=>"", 'Aktif'=>1];
if ($this->id_sup > 0) {
$atabel = $this->db->fetchRow("SELECT * FROM para_supplier WHERE SupID=?", [$this->id_sup]);
}
$form = new Form($this->app);
$tkode = $form->textbox("_", "Kode_Sup", $atabel['Kode_Sup'], true, true, "text", "kode supplier");
$tnama = $form->textbox("_", "Nama_Sup", $atabel['Nama_Sup'], true, true, "text", "nama supplier");
$talamat = $form->textarea("_", "Alamat_Sup", $atabel['Alamat_Sup'], true, true, 3, "alamat supplier");
$ttelp = $form->textbox("_", "Telp_Sup", $atabel['Telp_Sup'], true, true, "text", "telp supplier");
$tnpwp = $form->textbox("NPWP Supplier", "No_NPWP", $atabel['No_NPWP'], true, true, "text", "0000000000000000", 16);
$tnitku = $form->textbox("NITKU Supplier", "No_NITKU", $atabel['No_NITKU'], true, true, "text", "000000", 6);
$taktif = $form->radio("_", "Aktif", $atabel['Aktif'], true, true, ['1'=>"Aktif",'0'=>"Tidak"]);
$ajson['html'] = '
<div class="row mb-1">
<label class="col-sm-5 col-lg-2 col-form-label" for="Kode_Sup">Kode Supplier</label>
<div class="col-sm-7 col-lg-4">'.$tkode.'</div>
<label class="col-sm-5 col-lg-2 col-form-label" for="Aktif">Status Aktif ?</label>
<div class="col d-flex gap-2">'.$taktif.'</div>
</div>
<div class="row mb-1">
<label class="col-sm-5 col-lg-2 col-form-label" for="Nama_Sup">Nama Supplier</label>
<div class="col-sm-7 col-lg-10">'.$tnama.'</div>
</div>
<div class="row mb-1">
<label class="col-sm-5 col-lg-2 col-form-label" for="Alamat_Sup">Alamat Supplier</label>
<div class="col-sm-7 col-lg-10">'.$talamat.'</div>
</div>
<div class="row mb-1">
<label class="col-sm-5 col-lg-2 col-form-label" for="Telp_Sup">Telpon Supplier</label>
<div class="col-sm-7 col-lg-10">'.$ttelp.'</div>
</div>
<div class="row mb-1">
<label class="col-sm-5 col-lg-2 col-form-label" for="No_NPWP">NPWP Member</label>
<div class="col-sm-7 col-lg-4">'.$tnpwp.'</div>
<label class="col-sm-5 col-lg-2 col-form-label" for="No_NITKU">NITKU Member</label>
<div class="col-sm-7 col-lg-4">'.$tnitku.'</div>
</div>
<input type="hidden" id="SupID" value="'.$atabel['SupID'].'" />
<input type="hidden" id="mode_detail" value="'.$this->mode_detail.'" />';
$this->app->json($ajson);
}
public function index() {
$this->app->json(['html' => '
<div class="fade-in">
<div class="card"><div class="card-header custom-style">Daftar Supplier</div><div class="card-body"><div class="row mb-1"><div class="col"><div class="input-group"><input class="form-control" id="Cari_Sup" 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><div id="divDetail">&nbsp;</div></div></div>
</div>'
]);
}
}