first commit
This commit is contained in:
@@ -0,0 +1,281 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
PHP Class : /Controller/Member/TukarController
|
||||
Description : Transaksi Penukaran Point Member
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : December 10th, 2017.
|
||||
Last Modified : September 29th, 2026.
|
||||
|
||||
(c) 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Member;
|
||||
|
||||
use App\Utils\Inv;
|
||||
use flight\Engine;
|
||||
use flight\database\SimplePdo;
|
||||
use flight\Session;
|
||||
use Webapp\DB\SQL;
|
||||
use Webapp\Web\Form;
|
||||
use Webapp\Web\Param;
|
||||
use Webapp\Web\Table;
|
||||
|
||||
class TukarController {
|
||||
|
||||
private array $web_app;
|
||||
private int $id_cab;
|
||||
private string $mode;
|
||||
private string $mode_detail;
|
||||
private string $no_tx;
|
||||
private bool $is_baru;
|
||||
private int $id_tipe_point;
|
||||
private Inv $inv;
|
||||
protected Engine $app;
|
||||
protected SimplePdo $db;
|
||||
|
||||
public function __construct(Engine $app, SimplePdo $db, Session $session) {
|
||||
$this->app = $app;
|
||||
$this->db = $db;
|
||||
$this->web_app = (array) $session->get('WEB_APP');
|
||||
$this->id_cab = Param::Int("CabID", $session->get('APP_INV')['CABANGID']);
|
||||
$this->mode = Param::Get("mode", "");
|
||||
$this->mode_detail = Param::Get("mode_detail", "");
|
||||
$this->no_tx = Param::Get("No_TX", "");
|
||||
$this->is_baru = str_contains($this->no_tx, "POIN") === true;
|
||||
$this->id_tipe_point = Param::Int("Point_TipeID", 0);
|
||||
$this->inv = new Inv($app);
|
||||
}
|
||||
|
||||
public function brow_tx() {
|
||||
$tcari = Param::Get("Cari_TX");
|
||||
$tsql = ''; $asql = [];
|
||||
if (!empty($tcari)) {
|
||||
$tsql .= "CONCAT(J.No_TX,B.Nama_Member,DATE_FORMAT(J.Tgl_TX,'%d-%m-%Y')) LIKE ?";
|
||||
array_push($asql, '%' . $tcari . '%');
|
||||
}
|
||||
|
||||
$obj = new Table($this->app);
|
||||
$obj->set_table("(SELECT * FROM inv_point_tx WHERE InvPID>0) J LEFT JOIN para_member B ON (J.MemberID=B.MemberID)", "J.*,B.Nama_Member", $tsql, $asql);
|
||||
$obj->add_field("No_TX", "No. Trans", "c");
|
||||
$obj->add_field("Tgl_TX", "Tgl. Trans", "c", "sqltgl", "", "val-tgl");
|
||||
$obj->add_field("Nama_Member", "Nama Member", "awr");
|
||||
$obj->set_field_order("No_TX", "D");
|
||||
$obj->set_func_select("MemberTukarJS.tx_select");
|
||||
$this->app->json([ $obj->db_table("divBrowTX") ]);
|
||||
}
|
||||
|
||||
public function brow_member() {
|
||||
$tcari = Param::Get("Cari_Member");
|
||||
$tsql = ''; $asql = [1];
|
||||
if (!empty($tcari)) {
|
||||
$tsql .= " AND CONCAT_WS(Kode_Member,Nama_Member,Alamat_Member,Telp_Member) LIKE ?";
|
||||
array_push($asql, '%' . $tcari . '%');
|
||||
}
|
||||
array_push($asql, $this->id_tipe_point);
|
||||
|
||||
$obj = new Table($this->app);
|
||||
$obj->set_table("(SELECT * FROM para_member WHERE Aktif=?".$tsql.") M LEFT JOIN (SELECT MemberID,SUM(Nilai_Point) Sisa_Point FROM inv_point_tx WHERE Point_TipeID=? GROUP BY MemberID) P ON (M.MemberID=P.MemberID)", "M.*,IFNULL(P.Sisa_Point,0) Sisa_Point", "", $asql);
|
||||
$obj->add_field("MemberID", "ID", "hid");
|
||||
$obj->add_field("Grup_MemberID", "Grup ID", "hid");
|
||||
$obj->add_field("Kode_Member", "Kode", "c");
|
||||
$obj->add_field("Nama_Member", "Nama Member", "awr");
|
||||
$obj->add_field("Alamat_Member", "Alamat", "awr");
|
||||
$obj->add_field("Telp_Member", "Telp.", "awr");
|
||||
$obj->add_field("Sisa_Point", "Point.", "hid");
|
||||
$obj->set_field_order("Nama_Member", "A");
|
||||
$obj->set_func_select("MemberTukarJS.member_select");
|
||||
$this->app->json([ $obj->db_table("divBrowMember") ]);
|
||||
}
|
||||
|
||||
public function brow_barang() {
|
||||
$tcari = Param::Get("Cari_Barang");
|
||||
$tsql = ''; $asql = [1, $this->id_tipe_point];
|
||||
if (!empty($tcari)) {
|
||||
$tsql .= " AND Nama_Barang LIKE ?";
|
||||
array_push($asql, '%' . $tcari . '%');
|
||||
}
|
||||
|
||||
$obj = new Table($this->app);
|
||||
$obj->set_table("inv_point_barang", "*", "Aktif=? AND Point_TipeID=?".$tsql, $asql);
|
||||
$obj->add_field("InvPID", "ID", "hid");
|
||||
$obj->add_field("SatuanID", "ID", "hid");
|
||||
$obj->add_field("Nama_Barang", "Nama Barang", "awr");
|
||||
$obj->add_field("Nilai_Barang", "Nilai Barang", "hid");
|
||||
$obj->add_field("Nilai_Point", "Nilai Point", "r", "uang");
|
||||
$obj->set_field_order("Nama_Barang", "A");
|
||||
$obj->set_func_select("MemberTukarJS.barang_select");
|
||||
$this->app->json([ $obj->db_table("divBrowBarang") ]);
|
||||
}
|
||||
|
||||
public function auto_member() {
|
||||
$tcari = Param::Get("Auto_Query", "");
|
||||
$ajson['autodata'] = [];
|
||||
|
||||
$stat = $this->db->runQuery("SELECT M.MemberID,M.Kode_Member,M.Nama_Member,M.Kode_Nama,IFNULL(P.Sisa_Point,0) Sisa_Point FROM (SELECT *,CONCAT(IF(Kode_Member='','',CONCAT(Kode_Member,' - ')),Nama_Member) Kode_Nama FROM para_member WHERE Aktif=1 AND CONCAT(Kode_Member,Nama_Member,Alamat_Member,Telp_Member) LIKE ?) M LEFT JOIN (SELECT MemberID,SUM(Nilai_Point) Sisa_Point FROM inv_point_tx WHERE Point_TipeID=? GROUP BY MemberID) P ON (M.MemberID=P.MemberID) ORDER BY M.Nama_Member LIMIT 50", ['%'.$tcari.'%', $this->id_tipe_point]);
|
||||
while ($row = $stat->fetch(SimplePdo::FETCH_ASSOC)) {
|
||||
$ajson['autodata'][] = ['value'=>$row['MemberID'], 'text'=>$row['Kode_Nama'], 'html'=>'<span class="text-primary">'.$row['Kode_Member'].'</span> '.$row['Nama_Member'], 'data'=>$row['Sisa_Point'], 'bc'=>0];
|
||||
}
|
||||
$this->app->json($ajson);
|
||||
}
|
||||
|
||||
public function auto_barang() {
|
||||
$tcari = Param::Get("Auto_Query", "");
|
||||
$ajson['autodata'] = [];
|
||||
|
||||
$stat = $this->db->runQuery("SELECT P.InvPID,P.Nama_Barang,CONCAT(P.SatuanID,':',P.Nilai_Barang,':',P.Nilai_Point) Data2 FROM inv_point_barang P WHERE P.Aktif=1 AND P.Point_TipeID=? AND P.Nama_Barang LIKE ? ORDER BY P.Nama_Barang LIMIT 50", [$this->id_tipe_point, '%'.$tcari.'%']);
|
||||
while ($row = $stat->fetch(SimplePdo::FETCH_ASSOC)) {
|
||||
$ajson['autodata'][] = ['value'=>$row['InvPID'], 'text'=>$row['Nama_Barang'], 'data'=>$row['Data2'], 'bc'=>0];
|
||||
}
|
||||
$this->app->json($ajson);
|
||||
}
|
||||
|
||||
public function form_master() {
|
||||
$ajson = [ 'error'=>"", 'html'=>"" ];
|
||||
$atabel = [];
|
||||
|
||||
if ($this->mode === "add") {
|
||||
$atabel = $this->Data_Point("", true);
|
||||
} else if ($this->mode === "edit") {
|
||||
$atabel = $this->Data_Point($this->no_tx);
|
||||
} else if ($this->mode === "save") {
|
||||
if ($this->is_baru) {
|
||||
$this->no_tx = $this->inv->Point_Baru("B", Param::Get("Tgl_TX"));
|
||||
}
|
||||
|
||||
$sql = new SQL($this->app);
|
||||
$sql->set_table("inv_point_tx");
|
||||
$sql->add_param_date("Tgl_TX");
|
||||
$sql->add_param("CabID", $this->id_cab);
|
||||
$sql->add_param("Point_TipeID");
|
||||
$sql->add_param("MemberID");
|
||||
$sql->add_param("InvPID");
|
||||
$sql->add_param("Point", Param::Float("Point")*-1);
|
||||
$sql->add_param("Qty");
|
||||
$sql->add_param("Nilai_Point", "Qty*Point", true);
|
||||
$sql->add_param("Nilai_Barang");
|
||||
$sql->add_param_stamp();
|
||||
$sql->add_param_userid();
|
||||
$sql->add_where("No_TX", $this->no_tx);
|
||||
$sql->UpdateDB();
|
||||
|
||||
$atabel = $this->Data_Point($this->no_tx);
|
||||
$this->mode = "view";
|
||||
|
||||
} else if ($this->mode === "cancel") {
|
||||
$atabel = $this->Data_Point();
|
||||
} else {
|
||||
$atabel = $this->Data_Point($this->no_tx);
|
||||
}
|
||||
|
||||
$enable = in_array($this->mode, ["add","edit"]) ? true : false;
|
||||
$form = new Form($this->app);
|
||||
$tnota = $form->textbox("_", "No_TX", $atabel['No_TX'], !$enable, true, "text", "nomor transaksi");
|
||||
$ttgl = $form->datebox("_", "Tgl_TX", $atabel['Tgl_TX'], $enable, true);
|
||||
$ttipe = $form->option_db("_", "Point_TipeID", $atabel['Point_TipeID'], $enable, false, "inv_point_tipe", ["Point_TipeID","Nama_Tipe"], "Aktif=1 ORDER BY Point_TipeID", [0," "], null, "MemberTukarJS.oc_Tipe");
|
||||
$tmemb = $form->textauto("_", "Nama_Member", ['value'=>$atabel['MemberID'],'text'=>$atabel['Nama_Member']], $enable, true, "ketik nama member");
|
||||
$tbarg = $form->textauto("_", "Nama_Barang", ['value'=>$atabel['InvPID'],'text'=>$atabel['Nama_Barang']], $enable, true, "ketik nama barang");
|
||||
$tqty = $form->textbox("_", "Qty", $atabel['Qty'], $enable, true, "double");
|
||||
$tsisa = $form->textbox("_", "Sisa_Point", $atabel['Sisa_Point'], false, false, "double");
|
||||
$tnilai = $form->textbox("_", "Nilai_Point", $atabel['Nilai_Point'], false, false, "double");
|
||||
$tpoint = $form->textbox("_", "Point", $atabel['Point'], false, false, "double");
|
||||
$ajson['html'] = '
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-5 col-lg-3 col-form-label" for="No_TX">Nomor Transaksi</label>
|
||||
<div class="col-sm-7 col-lg-6"><div class="input-group">'.$tnota.'<button id="butBrow" class="btn btn-info" type="button"><i class="bi-search"></i></button></div></div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-5 col-lg-3 col-form-label" for="Tgl_TX">Tanggal Transaksi</label>
|
||||
<div class="col-sm-6 col-lg-3">'.$ttgl.'</div>
|
||||
<div class="col-sm-6 col-lg-6"><div class="input-group"><div class="input-group-text">Tipe Point</div>'.$ttipe.'</div></div>
|
||||
</div>
|
||||
<div class="row mb-1"><div class="col"><hr class="my-1"></div></div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-5 col-lg-3 col-form-label" for="Nama_Member">Nama Member</label>
|
||||
<div class="col"><div class="input-group">'.$tmemb.'<button id="butBrowMember" class="btn btn-info" type="button"><i class="bi-people-fill"></i></button></div></div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-5 col-lg-3 col-form-label">Sisa Point</label>
|
||||
<div class="col-sm-7 col-lg-5">'.$tsisa.'</div>
|
||||
</div>
|
||||
<div class="row mb-1"><div class="col"><hr class="my-1"></div></div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-5 col-lg-3 col-form-label" for="Nama_Barang">Nama Barang</label>
|
||||
<div class="col"><div class="input-group">'.$tbarg.'<button id="butBrowBarang" class="btn btn-info" type="button"><i class="bi-bag"></i></button></div></div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-5 col-lg-3 col-form-label" for="Qty">Qty</label>
|
||||
<div class="col"><div class="input-group">'.$tqty.'<div class="input-group-text">@</div>'.$tpoint.'</div></div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-5 col-lg-3 col-form-label">Nilai Tukar</label>
|
||||
<div class="col-sm-7 col-lg-5">'.$tnilai.'</div>
|
||||
</div>
|
||||
<input type="hidden" id="MemberID" value="'.$atabel['MemberID'].'" >
|
||||
<input type="hidden" id="InvPID" value="'.$atabel['InvPID'].'" >
|
||||
<input type="hidden" id="Nilai_Barang" value="'.$atabel['Nilai_Barang'].'" >
|
||||
<input type="hidden" id="mode" value="'.$this->mode.'" >';
|
||||
$this->app->json($ajson);
|
||||
}
|
||||
|
||||
public function proses_delete() {
|
||||
$this->db->runQuery("DELETE FROM inv_point_tx WHERE No_TX=?", [$this->no_tx]);
|
||||
$this->app->json([ 'status' => true ]);
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$this->app->json(['html' => '
|
||||
<div id="divTXMaster"> </div>
|
||||
<div class="row mb-1"><div class="col"><hr class="my-1"></div></div>
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-auto px-0 text-center text-sm-start">
|
||||
<button class="btn btn-primary mb-2 mb-sm-0 ms-sm-2 col-10 col-sm-auto" id="butTambah" type="button"><i class="bi-plus-lg me-2"></i>Tambah</button>
|
||||
<button class="btn btn-info mb-2 mb-sm-0 ms-sm-2 col-10 col-sm-auto" id="butUbah" type="button"><i class="bi-clipboard me-2"></i>Ubah</button>
|
||||
<button class="btn btn-warning mb-2 mb-sm-0 ms-sm-2 col-10 col-sm-auto" id="butHapus" type="button"><i class="bi-trash me-2"></i>Hapus</button>
|
||||
<button class="btn btn-secondary mb-2 mb-sm-0 ms-sm-2 col-10 col-sm-auto" id="butPrint" type="button"><i class="bi-printer me-2"></i>Cetak</button>
|
||||
</div>
|
||||
<div class="col-12 col-md-auto px-0 text-center text-sm-end ms-auto">
|
||||
<button class="btn btn-danger mb-2 mb-sm-0 me-sm-2 col-10 col-sm-auto" id="butBatal" type="button"><i class="bi-x-lg me-2"></i>Batal</button>
|
||||
<button class="btn btn-success mb-2 mb-sm-0 me-sm-2 col-10 col-sm-auto" id="butSimpan" type="button"><i class="bi-save me-2"></i>Simpan</button>
|
||||
</div>
|
||||
</div>'
|
||||
]);
|
||||
}
|
||||
|
||||
private function Data_Point(string $nomor="", bool $baru=false): array {
|
||||
$aparam = [
|
||||
'No_TX' => $nomor,
|
||||
'Tgl_TX' => tgl_ymd(),
|
||||
'Point_TipeID' => 0,
|
||||
'MemberID' => 0,
|
||||
'Nama_Member' => "",
|
||||
'InvPID' => 0,
|
||||
'Nama_Barang' => "",
|
||||
'Qty' => 0,
|
||||
'Sisa_Point' => 0,
|
||||
'Nilai_Point' => 0,
|
||||
'Point' => 0,
|
||||
'Nilai_Barang' => 0,
|
||||
];
|
||||
if ($baru) $aparam['No_TX'] = "POIN".$this->web_app['SERVER_ID'].(string) $this->id_cab.$this->app->user()->id(3)."#00";
|
||||
if (!empty($nomor)) {
|
||||
$row = $this->db->fetchRow("SELECT * FROM inv_point_tx WHERE InvPID>0 AND No_TX=?", [$nomor]);
|
||||
if ($row) $aparam = array_merge($aparam, $row->getData());
|
||||
if ($aparam['MemberID'] > 0) {
|
||||
$aparam['Nama_Member'] = $this->db->fetchField("SELECT Nama_Member FROM para_member WHERE MemberID=?", [$aparam['MemberID']]) ?? '';
|
||||
$aparam['Sisa_Point'] = (float) $this->db->fetchField("SELECT SUM(Nilai_Point) Sisa_Point FROM inv_point_tx WHERE Point_TipeID=? AND MemberID=?", [$aparam['Point_TipeID'], $aparam['MemberID']]) ?? 0;
|
||||
$aparam['Sisa_Point'] -= $aparam['Nilai_Point'];
|
||||
}
|
||||
if ($aparam['InvPID'] > 0) {
|
||||
$aparam['Nama_Barang'] = $this->db->fetchField("SELECT Nama_Barang FROM inv_point_barang WHERE InvPID=?", [$aparam['InvPID']]) ?? '';
|
||||
}
|
||||
|
||||
}
|
||||
return $aparam;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user