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", ' Barang'); $obj->set_func_btn("RepoInvLabelJS.grup_brow", ' 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'] = '
'.$tproduk.'
'; $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 = ''; $_line = ''; $ni = 1; $nb = 1; $cont = ""; while ($row = $query->fetch(SimplePdo::FETCH_ASSOC)) { if ($ni === 4) { if ($nb === 8) { $cont .= '
%s
%s

................ page break ................

 

' . $_head; $nb = 0; } else { $cont .= ''; } $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 '

 

' . $_head . $cont . ""; } public function index() { $this->app->json(['html' => '
 
' ]); } }