212 lines
9.4 KiB
PHP
212 lines
9.4 KiB
PHP
<?php
|
|
|
|
/*******************************************************************
|
|
|
|
PHP Class : /Controller/Report/Inv/HutangController
|
|
Description : Laporan Hutang Supplier
|
|
Created By : Siau Pheng ([email protected]).
|
|
Created Date : July 17th, 2011.
|
|
Last Modified : October 8th, 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\Data\Xlsx;
|
|
use Webapp\Printer\PrintHTML;
|
|
use Webapp\Web\Form;
|
|
use Webapp\Web\Param;
|
|
|
|
class HutangController {
|
|
|
|
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->id_cab = Param::Int("CabID", 0);
|
|
$this->reg_name = $session->get('WEB_APP')['REG_NAME'];
|
|
}
|
|
|
|
private function prepare() {
|
|
$apre = [
|
|
'tipe' => Param::Get("Tipe", "R"), // R or D
|
|
'id_sup' => Param::Int("SupID", 0),
|
|
'tgl_from' => Param::Get("Tgl_From"),
|
|
'tgl_to' => Param::Get("Tgl_To"),
|
|
];
|
|
|
|
$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']]) ?? '') : '';
|
|
|
|
// 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_cab > 0) {
|
|
$tsql .= " AND CabID=?";
|
|
array_push($asql, $this->id_cab);
|
|
}
|
|
if ($apre['id_sup'] > 0) {
|
|
$tsql .= " AND SupID=?";
|
|
array_push($asql, $apre['id_sup']);
|
|
}
|
|
|
|
if ($apre['tipe'] === "R") {
|
|
$apre['query'] = $this->db->runQuery("SELECT B.*,S.Nama_Sup FROM (SELECT SupID,SUM(Real_Beli) Total_Hutang,SUM(Total_Bayar+Total_Potong) Total_Bayar FROM inv_beli WHERE Lunas=0 AND (Tgl_Beli BETWEEN ? AND ?)".$tsql." GROUP BY SupID) B LEFT JOIN para_supplier S ON (B.SupID=S.SupID) ORDER BY S.Nama_Sup", $asql);
|
|
} else {
|
|
$apre['query'] = $this->db->runQuery("SELECT B.*,CONCAT(S.Nama_Sup,IF(B.Data_Beli=1,'',' <i>(Retur)</i>')) Nama_Sup,B.Real_Beli Total_Hutang,B.Total_Bayar+B.Total_Potong Total_Bayar FROM (SELECT * FROM inv_beli WHERE Lunas=0 AND (Tgl_Beli BETWEEN ? AND ?)".$tsql.") B LEFT JOIN para_supplier S ON (B.SupID=S.SupID) ORDER BY B.No_Beli", $asql);
|
|
}
|
|
return $apre;
|
|
}
|
|
|
|
public function print() {
|
|
$apre = $this->prepare();
|
|
|
|
$pre = new PrintHTML($this->app);
|
|
$pre->add_title([strtoupper($this->reg_name), ($apre['tipe']==="R"?"REKAP":"DETAIL")." HUTANG SUPPLIER", "Periode : ".$apre['periode']]);
|
|
|
|
if ($apre['tipe'] === "R") {
|
|
$pre->add_field("No.",10,"C");
|
|
$pre->add_field("Nama Supplier",50,"L");
|
|
$pre->add_field("Jumlah Faktur",20,"R","rupiah");
|
|
$pre->add_field("Jumlah Bayar",20,"R","rupiah");
|
|
$pre->add_field("Sisa Hutang",20,"R","rupiah");
|
|
|
|
if ($apre['id_sup'] > 0) $pre->add_sub_title("Nama Supplier : ".$apre['nama_sup']);
|
|
|
|
$pre->show_titles();
|
|
$pre->show_headers();
|
|
|
|
$tot_hutang = 0; $tot_bayar = 0; $nomor = 0;
|
|
while ($row = $apre['query']->fetch(SimplePdo::FETCH_ASSOC)) {
|
|
$tot_hutang += $row['Total_Hutang'];
|
|
$tot_bayar += $row['Total_Bayar'];
|
|
$pre->add_row([ ++$nomor, $row['Nama_Sup'], $row['Total_Hutang'], $row['Total_Bayar'], $row['Total_Hutang'] - $row['Total_Bayar'] ]);
|
|
}
|
|
$pre->add_span([ ["GRAND TOTAL",2,"R,B"],[$tot_hutang,1,"R,B","rupiah"],[$tot_bayar,1,"R,B","rupiah"],[$tot_hutang-$tot_bayar,1,"R,B","rupiah"] ]);
|
|
|
|
} else {
|
|
$pre->add_field("No. Nota",30,"C");
|
|
$pre->add_field("Tgl. Nota",30,"C", "tgl_sql2str");
|
|
$pre->add_field("Nama Supplier",50,"L");
|
|
$pre->add_field("Jumlah",20,"R","rupiah");
|
|
$pre->add_field("Bayar",20,"R","rupiah");
|
|
$pre->add_field("Sisa Hutang",20,"R","rupiah");
|
|
|
|
if ($apre['id_sup'] > 0) $pre->add_sub_title("Nama Supplier : ".$apre['nama_sup']);
|
|
|
|
$pre->show_titles();
|
|
$pre->show_headers();
|
|
|
|
$tot_hutang = 0; $tot_bayar = 0;
|
|
while ($row = $apre['query']->fetch(SimplePdo::FETCH_ASSOC)) {
|
|
$tot_hutang += $row['Total_Hutang'];
|
|
$tot_bayar += $row['Total_Bayar'];
|
|
$pre->add_row([ $row['No_Beli'], $row['Tgl_Beli'], $row['Nama_Sup'], $row['Total_Hutang'], $row['Total_Bayar'], $row['Total_Hutang'] - $row['Total_Bayar'] ]);
|
|
}
|
|
$pre->add_span([ ["GRAND TOTAL",3,"R,B"],[$tot_hutang,1,"R,B","rupiah"],[$tot_bayar,1,"R,B","rupiah"],[$tot_hutang-$tot_bayar,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 Hutang Supplier",
|
|
'desc' => "Export Data Hutang Supplier"
|
|
]);
|
|
$xls->add_title([ $this->reg_name, "DATA ".($apre['tipe']==="R"?"REKAP":"DETAIL")." HUTANG SUPPLIER", "Periode : ".$apre['periode'] ]);
|
|
|
|
if ($apre['tipe'] === "R") {
|
|
$xls->add_field("No.", 5, "@integer");
|
|
$xls->add_field("Nama Supplier", 25, "@text");
|
|
$xls->add_field("Jumlah Faktur", 15, "#,##0.00");
|
|
$xls->add_field("Jumlah Bayar", 15, "#,##0.00");
|
|
$xls->add_field("Sisa Hutang", 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']);
|
|
|
|
$xls->show_titles();
|
|
$xls->show_headers();
|
|
|
|
$tot_hutang = 0; $tot_bayar = 0; $nomor = 0;
|
|
while ($row = $apre['query']->fetch(SimplePdo::FETCH_ASSOC)) {
|
|
$tot_hutang += $row['Total_Hutang'];
|
|
$tot_bayar += $row['Total_Bayar'];
|
|
$xls->add_row([ ++$nomor, $row['Nama_Sup'], $row['Total_Hutang'], $row['Total_Bayar'], $row['Total_Hutang'] - $row['Total_Bayar'] ]);
|
|
}
|
|
$xls->add_row_bold([ "", "GRAND TOTAL", $tot_hutang, $tot_bayar, $tot_hutang-$tot_bayar ]);
|
|
|
|
} else {
|
|
$xls->add_field("No. Nota", 15, "@");
|
|
$xls->add_field("Tgl. Nota", 12, "@date");
|
|
$xls->add_field("Nama Supplier", 20, "@text");
|
|
$xls->add_field("Jumlah", 15, "#,##0.00");
|
|
$xls->add_field("Bayar", 15, "#,##0.00");
|
|
$xls->add_field("Sisa Hutang", 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']);
|
|
|
|
$xls->show_titles();
|
|
$xls->show_headers();
|
|
|
|
$tot_hutang = 0; $tot_bayar = 0;
|
|
while ($row = $apre['query']->fetch(SimplePdo::FETCH_ASSOC)) {
|
|
$tot_hutang += $row['Total_Hutang'];
|
|
$tot_bayar += $row['Total_Bayar'];
|
|
$xls->add_row([ $row['No_Beli'], $row['Tgl_Beli'], $row['Nama_Sup'], $row['Total_Hutang'], $row['Total_Bayar'], $row['Total_Hutang'] - $row['Total_Bayar'] ]);
|
|
}
|
|
$xls->add_row_bold([ "", "", "GRAND TOTAL", $tot_hutang, $tot_bayar, $tot_hutang-$tot_bayar ]);
|
|
}
|
|
$xls->add_stamp(1, true);
|
|
$xls->download("Data Hutang Supplier ".str_replace("s/d","-",$apre['periode']).".xlsx");
|
|
unset($xls);
|
|
}
|
|
|
|
public function index() {
|
|
$form = new Form($this->app);
|
|
$ttipe = $form->radio("_", "Tipe", "R", true, false, ["R"=>"Rekap","D"=>"Detail"]);
|
|
$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"]);
|
|
$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="Tipe">Tipe Laporan</label>
|
|
<div class="col">'.$ttipe.'</div>
|
|
</div>
|
|
<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="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);
|
|
}
|
|
|
|
}
|