189 lines
8.4 KiB
PHP
189 lines
8.4 KiB
PHP
<?php
|
|
|
|
/*******************************************************************
|
|
|
|
PHP Class : /Controller/Report/Inv/LabelController
|
|
Description : Cetak Label Harga
|
|
Created By : Siau Pheng ([email protected]).
|
|
Created Date : September 13th, 2014.
|
|
Last Modified : October 16th, 2026.
|
|
|
|
(c) 3FONIA Software; WWW.3FONIA.COM.
|
|
|
|
*******************************************************************/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Controller\Report\Inv;
|
|
|
|
use flight\Engine;
|
|
use flight\database\SimplePdo;
|
|
use flight\Session;
|
|
use Webapp\Web\Form;
|
|
use Webapp\Web\Param;
|
|
use Webapp\Web\Table;
|
|
|
|
class LabelController {
|
|
|
|
private string $mode;
|
|
private string $mode_detail;
|
|
private int $id_grup;
|
|
protected Engine $app;
|
|
protected SimplePdo $db;
|
|
|
|
public function __construct(Engine $app, SimplePdo $db, Session $session) {
|
|
$this->app = $app;
|
|
$this->db = $db;
|
|
$this->mode = Param::Get("mode", "");
|
|
$this->mode_detail = Param::Get("mode_detail", "");
|
|
$this->id_grup = $session->get('APP_INV')['ECERANID'] ?? 0;
|
|
}
|
|
|
|
public function table_detail() {
|
|
if ( $this->mode_detail === "empty" ) {
|
|
$this->db->runQuery("TRUNCATE rep_label");
|
|
} else if ( $this->mode_detail === "update" ) {
|
|
$this->db->runQuery("UPDATE rep_label SET Nama_Produk=? WHERE ID=?", [Param::Get("Nama_Produk"), Param::Int("ID", 0)]);
|
|
} else if ( $this->mode_detail === "delete" ) {
|
|
$this->db->runQuery("DELETE FROM rep_label WHERE ID=?", [Param::Int("ID", 0)]);;
|
|
} else if ( $this->mode_detail === "simpan-produk" ) {
|
|
$list_id = Param::Get("List_CB_InvID", "0");
|
|
if ($list_id !== "0") {
|
|
$alist = explode(",", $list_id);
|
|
$this->db->runQuery("INSERT INTO rep_label (InvID,Nama_Produk,Harga_Jual,UserID) SELECT InvID,LEFT(Nama_Produk,25),Harga_Jual,? FROM inv_produk_join WHERE InvID IN (?) AND Grup_MemberID=?", [$this->app->user()->id(), $alist, $this->id_grup]);
|
|
}
|
|
} else if ( $this->mode_detail === "simpan-grup" ) {
|
|
$id_grup = Param::Int("Grup_InvID", 0);
|
|
if ($id_grup > 0) {
|
|
$this->db->runQuery("INSERT INTO rep_label (InvID,Nama_Produk,Harga_Jual,UserID) SELECT InvID,LEFT(Nama_Produk,25),Harga_Jual,? FROM inv_produk_join WHERE Aktif=1 AND Grup_MemberID=? AND Grup_InvID=? AND Harga_Jual>0", [$this->app->user()->id(), $this->id_grup, $id_grup]);
|
|
}
|
|
}
|
|
|
|
$obj = new Table($this->app);
|
|
$obj->set_table("rep_label", "*", "", []);
|
|
$obj->add_field("ID", "No", "c");
|
|
$obj->add_field("Nama_Produk", "Nama Barang", "awr");
|
|
$obj->add_field("Harga_Jual", "Harga @", "r", "rupiah");
|
|
$obj->set_field_order("ID", "D");
|
|
$obj->add_row_btn("clipboard", "Ubah", "RepoInvLabelJS.detail_ubah");
|
|
$obj->add_row_btn("trash", "Hapus", "RepoInvLabelJS.detail_hapus", "UserID", $this->app->user()->id());
|
|
$obj->set_func_btn("RepoInvLabelJS.produk_brow", '<i class="bi-plus-lg me-1"></i> Barang');
|
|
$obj->set_func_btn("RepoInvLabelJS.grup_brow", '<i class="bi-table me-1"></i> Browse');
|
|
$ajson[] = $obj->json_table("divDetailTabel");
|
|
$this->app->json($ajson);
|
|
}
|
|
|
|
public function brow_grup() {
|
|
$tcari = Param::Get("Cari_Grup");
|
|
$tsql = ''; $asql = [];
|
|
if (!empty($tcari)) {
|
|
$tsql .= " AND CONCAT(Kode_Grup,Nama_Grup) LIKE ?";
|
|
array_push($asql, '%' . $tcari . '%');
|
|
}
|
|
|
|
$obj = new Table($this->app);
|
|
$obj->set_table("inv_produk_grup", "*", "Aktif=1".$tsql, $asql);
|
|
$obj->add_field("Grup_InvID", "ID", "hid");
|
|
$obj->add_field("Kode_Grup", "Kode", "c");
|
|
$obj->add_field("Nama_Grup", "Nama Grup Barang", "awr");
|
|
$obj->set_field_order("Kode_Grup", "A");
|
|
$obj->set_func_select("RepoInvLabelJS.grup_select");
|
|
$this->app->json([ $obj->db_table("divBrowGrup") ]);
|
|
}
|
|
|
|
public function brow_produk() {
|
|
$tcari = Param::Get("Cari_Produk");
|
|
$tsql = ''; $asql = [];
|
|
if (!empty($tcari)) {
|
|
$tsql .= " AND Barcode_Nama LIKE ?";
|
|
array_push($asql, '%' . $tcari . '%');
|
|
}
|
|
|
|
$obj = new Table($this->app);
|
|
$obj->set_table("(SELECT * FROM inv_produk_join WHERE Aktif=1".$tsql." GROUP BY InvID,SatuanID,VarianID) P LEFT JOIN rep_label L ON (L.InvID=P.InvID)", "P.*,IF(IFNULL(L.InvID,0)=0,'N','Y') Pilih", "", $asql);
|
|
$obj->add_field("InvID", "ID", "hid");
|
|
$obj->add_field("SatuanID", "ID", "hid");
|
|
$obj->add_field("VarianID", "ID", "hid");
|
|
$obj->add_field("Kode_SKU", "SKU", "c");
|
|
$obj->add_field("Kode_Barcode", "Barcode", "c");
|
|
$obj->add_field("Nama_Lengkap", "Nama Barang", "awr");
|
|
$obj->set_field_order("Kode_SKU", "A");
|
|
$obj->add_row_checkbox("InvID", "Pilih", ['Y','N']);
|
|
$this->app->json([ $obj->db_table("divBrowProduk") ]);
|
|
}
|
|
|
|
public function form_detail() {
|
|
$id = Param::Int("ID", 0);
|
|
$atabel = [ 'ID'=>$id, 'Nama_Produk'=>"" ];
|
|
if ($id > 0) {
|
|
$_row = $this->db->fetchRow("SELECT * FROM rep_label WHERE ID=?", [$id]);
|
|
if ($_row) $atabel = array_merge($atabel, $_row->getData());
|
|
}
|
|
|
|
$form = new Form($this->app);
|
|
$tproduk = $form->textbox("_", "Nama_Produk", $atabel['Nama_Produk'], true, false, "text");
|
|
$ajson['html'] = '
|
|
<div class="row mb-1">
|
|
<label class="col-sm-4 col-lg-3 col-form-label" for="Nama_Produk">Nama Barang</label>
|
|
<div class="col">'.$tproduk.'</div>
|
|
</div>
|
|
<input type="hidden" id="ID" value="'.$atabel['ID'].'" >
|
|
<input type="hidden" id="mode_detail" value="'.$this->mode_detail.'" >';
|
|
$this->app->json($ajson);
|
|
}
|
|
|
|
public function print() {
|
|
$query = $this->db->runQuery("SELECT * FROM rep_label ORDER BY ID");
|
|
if ($query->rowCount() === 0) return false;
|
|
|
|
$_head = '<table width="100%"><tr>';
|
|
$_line = '<td class="center" style="font-size:16pt;height:100px;width:65mm;padding:10px;border: dashed 1px #000;font-family:verdana;"><div style="font-size:18pt;height:50px;padding-bottom:10px;">%s</div>%s</td>';
|
|
$ni = 1; $nb = 1; $cont = "";
|
|
while ($row = $query->fetch(SimplePdo::FETCH_ASSOC)) {
|
|
if ($ni === 4) {
|
|
if ($nb === 8) {
|
|
$cont .= '</tr></table><p id="linebreak">................ page break ................</p><p id="pagebreak"> </p>' . $_head;
|
|
$nb = 0;
|
|
} else {
|
|
$cont .= '</tr><tr>';
|
|
}
|
|
$ni = 1;
|
|
$nb++;
|
|
}
|
|
$cont .= sprintf($_line, $row['Nama_Produk'], "Rp. ".rupiah($row['Harga_Jual']));
|
|
$ni++;
|
|
}
|
|
if ($ni < 4) {
|
|
while ($ni < 4) {
|
|
$cont .= sprintf($_line, "", "");
|
|
$ni++;
|
|
}
|
|
}
|
|
echo '<p id="autopage"> </p>' . $_head . $cont . "</tr></table>";
|
|
}
|
|
|
|
public function index() {
|
|
$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-printer me-2"></i>Cetak Label Harga</button>
|
|
</li>
|
|
<li class="nav-item ms-auto">
|
|
<button class="btn btn-warning mb-1 ms-2" id="butHapus" type="button"><i class="bi-trash me-2"></i>Hapus</button>
|
|
<button class="btn btn-secondary mb-1 ms-2" id="butPrint" type="button"><i class="bi-printer me-2"></i>Cetak</button>
|
|
<button class="btn btn-secondary mb-1 ms-2" id="butPreview" type="button"><i class="bi-display me-2"></i>Pratinjau</button>
|
|
</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>'
|
|
]);
|
|
}
|
|
}
|