first commit
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
PHP Class : /Controller/Report/Stok/CabangController
|
||||
Description : Laporan Stok Barang per Cabang
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : July 16th, 2011.
|
||||
Last Modified : October 13th, 2026.
|
||||
|
||||
(c) 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Report\Stok;
|
||||
|
||||
use flight\Engine;
|
||||
use flight\database\SimplePdo;
|
||||
use flight\Session;
|
||||
use Webapp\Data\Xlsx;
|
||||
use Webapp\Printer\PrintHTML;
|
||||
use Webapp\Web\Form;
|
||||
use Webapp\Web\Param;
|
||||
|
||||
class CabangController {
|
||||
|
||||
private int $id_cab1;
|
||||
private int $id_cab2;
|
||||
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->id_cab1 = Param::Int("Cab1ID", 0);
|
||||
$this->id_cab2 = Param::Int("Cab2ID", 0);
|
||||
$this->reg_name = $session->get('WEB_APP')['REG_NAME'];
|
||||
}
|
||||
|
||||
private function prepare() {
|
||||
$apre = [
|
||||
'tgl_from' => Param::Get("Tgl_From"),
|
||||
'tgl_to' => Param::Get("Tgl_To"),
|
||||
'cab_from' => "Semua Cabang",
|
||||
'cab_to' => "Semua Cabang",
|
||||
];
|
||||
|
||||
if ($this->id_cab1 > 0) $apre['cab_from'] = $this->db->fetchField("SELECT Nama_Cab FROM para_cabang WHERE CabID=?", [$this->id_cab1]);
|
||||
if ($this->id_cab2 > 0) $apre['cab_to'] = $this->db->fetchField("SELECT Nama_Cab FROM para_cabang WHERE CabID=?", [$this->id_cab2]);
|
||||
|
||||
// generate report header
|
||||
$apre['periode'] = $apre['tgl_from'] . ($apre['tgl_from'] !== $apre['tgl_to'] ? ' s/d '.$apre['tgl_to'] : '');
|
||||
|
||||
$tsql = ''; $asql = [tgl_sql2str($apre['tgl_from']), tgl_sql2str($apre['tgl_to'])];
|
||||
if ($this->id_cab1 > 0) {
|
||||
$tsql .= " AND Dari_CabID=?";
|
||||
array_push($asql, $this->id_cab1);
|
||||
}
|
||||
if ($this->id_cab2 > 0) {
|
||||
$tsql .= " AND Ke_CabID=?";
|
||||
array_push($asql, $this->id_cab2);
|
||||
}
|
||||
|
||||
$apre['query'] = $this->db->runQuery("SELECT M.*,C1.Nama_Cab Nama1,C2.Nama_Cab Nama2 FROM (SELECT * FROM inv_mutasi WHERE (Tgl_Mutasi BETWEEN ? AND ?)".$tsql.") M LEFT JOIN para_cabang C1 ON (M.Dari_CabID=C1.CabID) LEFT JOIN para_cabang C2 ON (M.Ke_CabID=C2.CabID) ORDER BY M.Tgl_Mutasi,M.No_Mutasi", $asql);
|
||||
return $apre;
|
||||
}
|
||||
|
||||
public function print() {
|
||||
$apre = $this->prepare();
|
||||
|
||||
$pre = new PrintHTML($this->app);
|
||||
$pre->add_title([strtoupper($this->reg_name), "MUTASI STOK CABANG", "Periode : ".$apre['periode']]);
|
||||
|
||||
$pre->add_field("Tanggal",30,"C", "tgl_sql2str");
|
||||
$pre->add_field("No. Mutasi",30,"L");
|
||||
$pre->add_field("Dari Cabang",20,"L");
|
||||
$pre->add_field("Ke Cabang",20,"L");
|
||||
$pre->add_field("Total",20,"R","rupiah");
|
||||
$pre->add_field("Catatan",50,"L");
|
||||
|
||||
$pre->add_sub_title("Cari Cabang : ".$apre['cab_from']);
|
||||
$pre->add_sub_title("Ke Cabang : ".$apre['cab_to']);
|
||||
|
||||
$pre->show_titles();
|
||||
$pre->show_headers();
|
||||
|
||||
$tot_m = 0;
|
||||
while ($row = $apre['query']->fetch(SimplePdo::FETCH_ASSOC)) {
|
||||
$tot_m += $row['Total_Mutasi'];
|
||||
$pre->add_row([ $row['Tgl_Mutasi'], $row['No_Mutasi'], $row['Nama1'], $row['Nama2'], $row['Total_Mutasi'], $row['Catatan'] ]);
|
||||
}
|
||||
$pre->add_span([ ["GRAND TOTAL",4,"R,B"],[$tot_m,1,"R,B","rupiah"],["",1,"L,B"] ]);
|
||||
|
||||
$pre->add_stamp(1, true);
|
||||
$pre->show();
|
||||
}
|
||||
|
||||
public function excel() {
|
||||
$apre = $this->prepare();
|
||||
$xls = new Xlsx($this->app);
|
||||
$xls->set_meta([
|
||||
'title' => "Data Mutasi Stok Cabang",
|
||||
'desc' => "Export Data Mutasi Stok Cabang"
|
||||
]);
|
||||
$xls->add_title([ $this->reg_name, "DATA MUTASI STOK CABANG", "Periode : ".$apre['periode'] ]);
|
||||
|
||||
$xls->add_field("Tanggal", 12, "@date");
|
||||
$xls->add_field("No. Mutasi", 15, "@text");
|
||||
$xls->add_field("Dari Cabang", 10, "@text");
|
||||
$xls->add_field("Ke Cabang", 10, "@text");
|
||||
$xls->add_field("Total", 15, "#,##0.00");
|
||||
$xls->add_field("Catatan", 30, "@text");
|
||||
$xls->add_sheet("".str_replace("s/d","-",$apre['periode']));
|
||||
|
||||
$xls->add_sub_title("Dari Cabang : ".$apre['cab_from']);
|
||||
$xls->add_sub_title("Ke Cabang : ".$apre['cab_to']);
|
||||
|
||||
$xls->show_titles();
|
||||
$xls->show_headers();
|
||||
|
||||
$tot_m = 0;
|
||||
while ($row = $apre['query']->fetch(SimplePdo::FETCH_ASSOC)) {
|
||||
$tot_m += $row['Total_Mutasi'];
|
||||
$xls->add_row([ $row['Tgl_Mutasi'], $row['No_Mutasi'], $row['Nama1'], $row['Nama2'], $row['Total_Mutasi'], $row['Catatan'] ]);
|
||||
}
|
||||
$xls->add_row_bold([ "", "", "Stok Akhir", "", $tot_m, "" ]);
|
||||
|
||||
$xls->add_stamp(1, true);
|
||||
$xls->download("Data Mutasi Stok Cabang ".str_replace("s/d","-",$apre['periode']).".xlsx");
|
||||
unset($xls);
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$form = new Form($this->app);
|
||||
$tcab1 = $form->option_db("_", "Cab1ID", $this->id_cab1, true, false, "para_cabang", ["CabID","Nama_Cab"], "Aktif=1 ORDER BY CabID", [0,"SEMUA CABANG"]);
|
||||
$tcab2 = $form->option_db("_", "Cab2ID", $this->id_cab2, true, false, "para_cabang", ["CabID","Nama_Cab"], "Aktif=1 ORDER BY CabID", [0,"SEMUA CABANG"]);
|
||||
$tfrom = $form->datebox("_", "Tgl_From", tgl_ymd(), true, false);
|
||||
$tto = $form->datebox("_", "Tgl_To", tgl_ymd(), true, false);
|
||||
$ajson['html'] = '
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-4 col-lg-3 col-form-label" for="Cab1ID">Dari Cabang</label>
|
||||
<div class="col">'.$tcab1.'</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-4 col-lg-3 col-form-label" for="Cab2ID">Ke Cabang</label>
|
||||
<div class="col">'.$tcab2.'</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-4 col-lg-3 col-form-label" for="Tgl_From">Dari Tanggal</label>
|
||||
<div class="col-sm-6 col-lg-5">'.$tfrom.'</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-4 col-lg-3 col-form-label" for="Tgl_To">Sampai Tanggal</label>
|
||||
<div class="col-sm-6 col-lg-5">'.$tto.'</div>
|
||||
</div>';
|
||||
$this->app->json($ajson);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user