234 lines
9.9 KiB
PHP
234 lines
9.9 KiB
PHP
<?php
|
|
|
|
/*******************************************************************
|
|
|
|
PHP Class : /Controller/Report/Stok/AkhirController
|
|
Description : Laporan Stok Akhir Barang
|
|
Created By : Siau Pheng ([email protected]).
|
|
Created Date : January 24th, 2011.
|
|
Last Modified : November 4th, 2026.
|
|
|
|
(c) 3FONIA Software; WWW.3FONIA.COM.
|
|
|
|
*******************************************************************/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Controller\Report\Stok;
|
|
|
|
use App\Utils\Invesa;
|
|
use flight\Engine;
|
|
use flight\database\SimplePdo;
|
|
use flight\Session;
|
|
use Webapp\Data\Xlsx;
|
|
use Webapp\Printer\PrintHTML;
|
|
use Webapp\Printer\PrintPOS;
|
|
use Webapp\Web\Form;
|
|
use Webapp\Web\Param;
|
|
|
|
class AkhirController {
|
|
|
|
private array $app_inv;
|
|
private int $id_cab;
|
|
private string $reg_name;
|
|
protected Engine $app;
|
|
protected SimplePdo $db;
|
|
|
|
public function __construct(Engine $app, SimplePdo $db, Session $session) {
|
|
$this->app = $app;
|
|
$this->db = $db;
|
|
$this->app_inv = (array) $session->get('APP_INV');
|
|
$this->id_cab = Param::Int("CabID", 0);
|
|
$this->reg_name = $session->get('WEB_APP')['REG_NAME'];
|
|
}
|
|
|
|
private function prepare() {
|
|
$apre = [
|
|
'id_sup' => Param::Int("SupID", 0),
|
|
'id_grup_inv' => Param::Int("Grup_InvID", 0),
|
|
'ppn' => Param::Int("PPN", 0),
|
|
'tgl' => Param::Get("Tanggal"),
|
|
'urut' => Param::Get("Urut", "B"),
|
|
'min' => Param::Get("Min_Stok", "N"),
|
|
'qty' => Param::Int("Min_Qty", 0),
|
|
];
|
|
|
|
$apre['nama_sup'] = ($apre['id_sup'] > 0) ? ($this->db->fetchField("SELECT CONCAT(Nama_Sup,' (',Kode_Sup,')') Nama FROM para_supplier WHERE SupID=?", [$apre['id_sup']]) ?? '') : '';
|
|
$apre['nama_grup_inv'] = ($apre['id_grup_inv'] > 0 && $apre['id_sup']===0) ? ($this->db->fetchField("SELECT Nama_Grup FROM inv_produk_grup WHERE Grup_InvID=?", [$apre['id_grup_inv']]) ?? '') : '';
|
|
|
|
// generate report header
|
|
$apre['periode'] = $apre['tgl'];
|
|
|
|
$tsql1 = ''; $tsql2 = '';
|
|
$asql1 = [];
|
|
$asql2 = [];
|
|
|
|
if ($this->id_cab > 0) {
|
|
$tsql1 = " WHERE CabID=?";
|
|
array_push($asql1, $this->id_cab);
|
|
}
|
|
if ($apre['id_sup'] > 0) {
|
|
$tsql2 .= " AND D.InvID IN (SELECT InvID FROM inv_produk_sup WHERE SupID=?)";
|
|
array_push($asql2, $apre['id_sup']);
|
|
}
|
|
if ($apre['id_grup_inv'] > 0) {
|
|
$tsql2 .= " AND P.Grup_InvID=?";
|
|
array_push($asql2, $apre['id_grup_inv']);
|
|
}
|
|
if ($apre['ppn'] > 0) {
|
|
$tsql2 .= " AND P.PPN=?";
|
|
array_push($asql2, $apre['ppn']);
|
|
}
|
|
if ($apre['min'] !== 'N') {
|
|
$tsql2 .= " AND D.Stok<=?";
|
|
array_push($asql2, $apre['qty']);
|
|
}
|
|
$torder = ($apre['urut'] === "B") ? "P.Nama_Produk" : "Total";
|
|
|
|
$apre['query'] = $this->db->runQuery("SELECT P.Nama_Produk,P.Satuan_Normal,P.Satuan_Stok,D.Stok Jumlah,P.Harga_Pokok,D.Stok*P.Harga_Pokok Total,P.Qty Kali FROM (SELECT InvID,SUM(Stok) Stok FROM inv_stok".$tsql1." GROUP BY InvID) D LEFT JOIN vi_inv_produk2 P ON (P.InvID=D.InvID) WHERE (NOT (D.Stok=0 AND P.Aktif=0)) AND (P.InvID IS NOT NULL)".$tsql2." ORDER BY ".$torder, array_merge($asql1, $asql2));
|
|
return $apre;
|
|
}
|
|
|
|
public function pos() {
|
|
$apre = $this->prepare();
|
|
|
|
$pre = new PrintPOS($this->app);
|
|
if (Invesa::Printer_Thermal(Param::Get("Printer", ""))) {
|
|
$pre->set_fontsize(2);
|
|
$pre->set_header_logo("logo-nota.png");
|
|
} else {
|
|
$pre->add_header($this->reg_name);
|
|
}
|
|
if ($this->app_inv['PRINT_AUTOCUT'] === 1) $pre->set_cutpaper();
|
|
$pre->add_empty();
|
|
|
|
$pre->addc("STOK AKHIR BARANG");
|
|
$pre->addc("Periode : ".$apre['periode']);
|
|
$pre->add_line("-");
|
|
while ($row = $apre['query']->fetch(SimplePdo::FETCH_ASSOC)) {
|
|
$stok = Invesa::Format_Stok(($row['Jumlah'] ?? 0), ($row['Kali'] ?? 1), ($row['Satuan_Normal'] ?? ''), ($row['Satuan_Stok'] ?? ''));
|
|
$pre->add([$row['Nama_Produk'],39-strlen($stok),"L"], [" ",1,"L"], [$stok,strlen($stok),"L"]);
|
|
}
|
|
$pre->add_line("-");
|
|
$pre->add_stamp(1, false);
|
|
$pre->add_empty($this->app_inv['PRINT_ROW']);
|
|
$pre->show();
|
|
}
|
|
|
|
public function print() {
|
|
$apre = $this->prepare();
|
|
|
|
$pre = new PrintHTML($this->app);
|
|
$pre->add_title([strtoupper($this->reg_name), "STOK AKHIR BARANG", "Periode : ".$apre['periode']]);
|
|
|
|
$pre->add_field("No.",10,"C");
|
|
$pre->add_field("Nama Barang",50,"L");
|
|
$pre->add_field("Stok",20,"R");
|
|
if ($this->app->user()->is_level(2)) {
|
|
$pre->add_field("Harga",20,"R","rupiah");
|
|
$pre->add_field("Total",20,"R","rupiah");
|
|
}
|
|
|
|
if ($apre['id_sup'] > 0) $pre->add_sub_title("Nama Supplier : ".$apre['nama_sup']);
|
|
if ($apre['id_grup_inv'] > 0) $pre->add_sub_title("Grup Barang : ".$apre['nama_grup_inv']);
|
|
|
|
$pre->show_titles();
|
|
$pre->show_headers();
|
|
|
|
$nomor = 0; $tot_stok = 0;
|
|
while ($row = $apre['query']->fetch(SimplePdo::FETCH_ASSOC)) {
|
|
$tot_stok += $row['Total'];
|
|
$_row = [ ++$nomor, $row['Nama_Produk'], Invesa::Format_Stok(($row['Jumlah'] ?? 0), ($row['Kali'] ?? 1), ($row['Satuan_Normal'] ?? ''), ($row['Satuan_Stok'] ?? '')) ];
|
|
if ($this->app->user()->is_level(2)) array_push($_row, $row['Harga_Pokok'], $row['Total']);
|
|
$pre->add_row($_row);
|
|
}
|
|
if ($this->app->user()->is_level(2)) $pre->add_span([ ["GRAND TOTAL",4,"R,B"], [$tot_stok,1,"R,B","rupiah"] ]);
|
|
|
|
$pre->add_stamp(1, true);
|
|
$pre->show();
|
|
}
|
|
|
|
public function excel() {
|
|
$apre = $this->prepare();
|
|
$xls = new Xlsx($this->app);
|
|
$xls->set_meta([
|
|
'title' => "Data Stok Akhir Barang",
|
|
'desc' => "Export Data Stok Akhir Barang"
|
|
]);
|
|
$xls->add_title([ $this->reg_name, "STOK AKHIR BARANG", "Periode : ".$apre['periode'] ]);
|
|
|
|
$xls->add_field("No.", 10, "@integer");
|
|
$xls->add_field("Nama Barang", 35, "@text");
|
|
$xls->add_field("Stok", 15, "@");
|
|
if ($this->app->user()->is_level(2)) {
|
|
$xls->add_field("Harga", 15, "#,##0.00");
|
|
$xls->add_field("Total", 15, "#,##0.00");
|
|
}
|
|
$xls->add_sheet("".str_replace("s/d","-",$apre['periode']));
|
|
|
|
if ($apre['id_sup'] > 0) $xls->add_sub_title("Nama Supplier : ".$apre['nama_sup']);
|
|
if ($apre['id_grup_inv'] > 0) $xls->add_sub_title("Grup Barang : ".$apre['nama_grup_inv']);
|
|
|
|
$xls->show_titles();
|
|
$xls->show_headers();
|
|
|
|
$nomor = 0; $tot_stok = 0;
|
|
while ($row = $apre['query']->fetch(SimplePdo::FETCH_ASSOC)) {
|
|
$tot_stok += $row['Total'];
|
|
$_row = [ ++$nomor, $row['Nama_Produk'], Invesa::Format_Stok(($row['Jumlah'] ?? 0), ($row['Kali'] ?? 1), ($row['Satuan_Normal'] ?? ''), ($row['Satuan_Stok'] ?? '')) ];
|
|
if ($this->app->user()->is_level(2)) array_push($_row, $row['Harga_Pokok'], $row['Total']);
|
|
$xls->add_row($_row);
|
|
}
|
|
if ($this->app->user()->is_level(2)) $xls->add_row_bold([ "", "GRAND TOTAL", "", "", $tot_stok ]);
|
|
|
|
$xls->add_stamp(1, true);
|
|
$xls->download("Data Stok Akhir Barang ".str_replace("s/d","-",$apre['periode']).".xlsx");
|
|
unset($xls);
|
|
}
|
|
|
|
public function index() {
|
|
$form = new Form($this->app);
|
|
$tcab = $form->option_db("_", "CabID", $this->id_cab, true, false, "para_cabang", ["CabID","Nama_Cab"], "Aktif=1 ORDER BY CabID", [0,"SEMUA CABANG"]);
|
|
$tsup = $form->option_db("_", "SupID", 0, true, false, "para_supplier", ["SupID","Nama_Sup"], "Aktif=1 ORDER BY Nama_Sup", [0,"SEMUA SUPPLIER"]);
|
|
$tgrup_inv = $form->option_db("_", "Grup_InvID", 0, true, false, "inv_produk_grup", ["Grup_InvID","Nama_Grup"], "Aktif=1 ORDER BY Nama_Grup", [0,"SEMUA GRUP"]);
|
|
$tppn = $form->option("_", "PPN", 9, true, false, [0 => "SEMUA STATUS"] + Invesa::PPN_Array());
|
|
$ttgl = $form->datebox("_", "Tanggal", tgl_ymd(), false, false);
|
|
$turut = $form->radio("_", "Urut", "B", true, false, ['B'=>"Nama Barang",'J'=>"Jumlah / Nilai"]);
|
|
$tstok = $form->radio("_", "Min_Stok", "N", true, false, ["Y"=>"Ya","N"=>"Tidak"], null, "RepoStokAkhirJS.oc_MinStok");
|
|
$tqty = $form->textbox("_", "Min_Qty", 0, false, false, "double");
|
|
$ajson['html'] = '
|
|
<div class="row mb-1">
|
|
<label class="col-sm-4 col-lg-3 col-form-label" for="CabID">Nama Cabang</label>
|
|
<div class="col">'.$tcab.'</div>
|
|
</div>
|
|
<div class="row mb-1">
|
|
<label class="col-sm-4 col-lg-3 col-form-label" for="SupID">Nama Supplier</label>
|
|
<div class="col">'.$tsup.'</div>
|
|
</div>
|
|
<div class="row mb-1">
|
|
<label class="col-sm-4 col-lg-3 col-form-label" for="Grup_InvID">Grup Barang</label>
|
|
<div class="col">'.$tgrup_inv.'</div>
|
|
</div>
|
|
<div class="row mb-1">
|
|
<label class="col-sm-4 col-lg-3 col-form-label" for="PPN">Status PPN</label>
|
|
<div class="col">'.$tppn.'</div>
|
|
</div>
|
|
<div class="row mb-1">
|
|
<label class="col-sm-4 col-lg-3 col-form-label" for="Tanggal">Tanggal Stok</label>
|
|
<div class="col-sm-6 col-lg-5">'.$ttgl.'</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-4 col-lg-3 col-form-label" for="Urut">Urut Berdasarkan</label>
|
|
<div class="col">'.$turut.'</div>
|
|
</div>
|
|
<div class="row mb-1">
|
|
<label class="col-sm-4 col-lg-3 col-form-label" for="Min_Stok">Batas Maximum ?</label>
|
|
<div class="col-sm-4 col-lg-3">'.$tstok.'</div>
|
|
<div class="col-sm-4 col-lg-3">'.$tqty.'</div>
|
|
</div>';
|
|
$this->app->json($ajson);
|
|
}
|
|
|
|
}
|