184 lines
8.1 KiB
PHP
184 lines
8.1 KiB
PHP
<?php
|
|
|
|
/*******************************************************************
|
|
|
|
App. Name : INVENTORY AND SALES SYSTEMS
|
|
Module : /apps/php/repo/hutang.php
|
|
Desc. : PHP - Laporan Hutang Supplier
|
|
Created By : Siau Pheng ([email protected]).
|
|
Created Date : July 17th, 2011.
|
|
Last Modified : October 16th, 2025.
|
|
|
|
(c) 2011 - 2025, 3FONIA Software; WWW.3FONIA.COM.
|
|
|
|
*******************************************************************/
|
|
|
|
require_once(__DIR__."/../../../../../vendor/autoload.php");
|
|
require_once(__DIR__."/../func.iss.php");
|
|
|
|
use siaupheng\fonia3\DB\MySQL;
|
|
use siaupheng\fonia3\Web\Param;
|
|
use siaupheng\fonia3\Web\Form;
|
|
use siaupheng\fonia3\Data\SimpleXLS;
|
|
|
|
$db = $db ?? new MySQL();
|
|
$ajson = [];
|
|
$data = Param::Get("data");
|
|
$id_cab = Param::Get("CabID", 0);
|
|
|
|
if (in_array($data, ["print","export"])) {
|
|
$tipe = Param::Get("Tipe", "R"); // R or D
|
|
$id_sup = Param::Get("SupID", 0);
|
|
$tglfrom = Param::Get("Tgl_From");
|
|
$tglto = Param::Get("Tgl_To");
|
|
|
|
$nama_sup = "";
|
|
if ($id_sup>0) {
|
|
$db->Query("SELECT Nama_Sup Nama FROM para_supplier WHERE SupID='".$id_sup."' LIMIT 1");
|
|
if ($db->Next()) $nama_sup = $db->Row("Nama");
|
|
}
|
|
|
|
// generate report header
|
|
$tglheader = $tglfrom;
|
|
if ($tglfrom!==$tglto) $tglheader .= " S/D ".$tglto;
|
|
$tglfrom = tgl_sql2str($tglfrom);
|
|
$tglto = tgl_sql2str($tglto);
|
|
|
|
$tsql = ($id_sup>0) ? " AND SupID='".$id_sup."'" : "";
|
|
|
|
// query data laporan
|
|
if ($tipe=="R") {
|
|
$db->Query("SELECT B.*,S.Nama_Sup FROM (SELECT SupID,SUM(Total_Hutang) Total_Hutang,SUM(Total_Bayar+Total_Potong) Total_Bayar FROM inv_beli WHERE Lunas=0 AND (Tgl_Beli BETWEEN '".$tglfrom."' AND '".$tglto."')".$tsql." GROUP BY SupID) B LEFT JOIN para_supplier S ON (B.SupID=S.SupID) ORDER BY S.Nama_Sup");
|
|
} else {
|
|
$db->Query("SELECT B.*,CONCAT(S.Nama_Sup,IF(B.Data_Beli=1,'',' <i>(Retur)</i>')) Nama_Sup,B.Total_Hutang Total_Hutang,B.Total_Bayar+B.Total_Potong Total_Bayar FROM (SELECT * FROM inv_beli WHERE Lunas=0 AND (Tgl_Beli BETWEEN '".$tglfrom."' AND '".$tglto."')".$tsql.") B LEFT JOIN para_supplier S ON (B.SupID=S.SupID) ORDER BY B.No_Beli");
|
|
}
|
|
}
|
|
|
|
if ( $data == "print" ) {
|
|
Report_Header(($tipe=="R"?"REKAP":"DETAIL")." HUTANG SUPPLIER", "Periode : ".$tglheader);
|
|
$pre = new \siaupheng\fonia3\Printer\PrintHTML();
|
|
|
|
if ($tipe=="R") {
|
|
$pre->add_field("No.",10,"C");
|
|
$pre->add_field("Nama Supplier",120,"L");
|
|
$pre->add_field("Jumlah Faktur",50,"R","rupiah2");
|
|
$pre->add_field("Jumlah Bayar",50,"R","rupiah2");
|
|
$pre->add_field("Sisa Hutang",50,"R","rupiah2");
|
|
|
|
if ($id_sup>0) $pre->add_span(array("Nama Supplier : ".$nama_sup,5,"L,B"));
|
|
|
|
$tot_hut = 0; $tot_bayar = 0; $nomor = 0;
|
|
while ($db->Next()) {
|
|
$tot_hut += $db->Row("Total_Hutang");
|
|
$tot_bayar += $db->Row("Total_Bayar");
|
|
$pre->add_value(++$nomor, $db->Row("Nama_Sup"), $db->Row("Total_Hutang"), $db->Row("Total_Bayar"), $db->Row("Total_Hutang")-$db->Row("Total_Bayar"));
|
|
}
|
|
$pre->add_span(array("GRAND TOTAL",2,"R,B"),array($tot_hut,1,"R,B","rupiah2"),array($tot_bayar,1,"R,B","rupiah2"),array($tot_hut-$tot_bayar,1,"R,B","rupiah2"));
|
|
} else {
|
|
$pre->add_field("No. Nota",10,"C");
|
|
$pre->add_field("Tgl. Nota",10,"C","sqltgl");
|
|
$pre->add_field("Nama Supplier",120,"L");
|
|
$pre->add_field("Jumlah",50,"R","rupiah2");
|
|
$pre->add_field("Bayar",50,"R","rupiah2");
|
|
$pre->add_field("Sisa Hutang",50,"R","rupiah2");
|
|
|
|
if ($id_sup>0) $pre->add_span(array("Nama Supplier : ".$nama_sup,6,"L,B"));
|
|
|
|
$tot_hut = 0; $tot_bayar = 0;
|
|
while ($db->Next()) {
|
|
$tot_hut += $db->Row("Total_Hutang");
|
|
$tot_bayar += $db->Row("Total_Bayar");
|
|
$pre->add_value($db->Row("No_Beli"), $db->Row("Tgl_Beli"), $db->Row("Nama_Sup"), $db->Row("Total_Hutang"), $db->Row("Total_Bayar"), $db->Row("Total_Hutang")-$db->Row("Total_Bayar"));
|
|
}
|
|
$pre->add_span(array("GRAND TOTAL",3,"R,B"),array($tot_hut,1,"R,B","rupiah2"),array($tot_bayar,1,"R,B","rupiah2"),array($tot_hut-$tot_bayar,1,"R,B","rupiah2"));
|
|
}
|
|
$pre->add_stamp(1, true);
|
|
$pre->show();
|
|
|
|
} else if ( $data == "export" ) {
|
|
$xls = new SimpleXLS([
|
|
'title'=>"Data Hutang Supplier",
|
|
'desc'=>"Export Data Hutang Supplier"
|
|
]);
|
|
|
|
if ($tipe=="R") {
|
|
$xls->add_header($_SESSION['__WEB_APP']['REG_NAME']);
|
|
$xls->add_header("DATA REKAP HUTANG SUPPLIER");
|
|
$xls->add_header("Periode : ".$tglheader);
|
|
|
|
$xls->add_field("No.", 10, "C");
|
|
$xls->add_field("Nama Supplier", 80, "L");
|
|
$xls->add_field("Jumlah Faktur", 20, "R,N");
|
|
$xls->add_field("Jumlah Bayar", 20, "R,N");
|
|
$xls->add_field("Sisa Hutang", 20, "R,N");
|
|
$xls->add_sheet("".str_replace("S/D","-",$tglheader), true);
|
|
|
|
if ($id_sup>0) $xls->add_span(["Nama Supplier : ".$nama_sup,5,"L"]);
|
|
|
|
$tot_hut = 0; $tot_bayar = 0; $nomor = 0;
|
|
while ($db->Next()) {
|
|
$tot_hut += $db->Row("Total_Hutang");
|
|
$tot_bayar += $db->Row("Total_Bayar");
|
|
$xls->add_value(++$nomor, $db->Row("Nama_Sup"), $db->Row("Total_Hutang"), $db->Row("Total_Bayar"), $db->Row("Total_Hutang")-$db->Row("Total_Bayar"));
|
|
}
|
|
$xls->add_span(array("GRAND TOTAL",2,"R,B"),array($tot_hut,1,"R,B,N"),array($tot_bayar,1,"R,B,N"),array($tot_hut-$tot_bayar,1,"R,B,N"));
|
|
} else {
|
|
$xls->add_header($_SESSION['__WEB_APP']['REG_NAME']);
|
|
$xls->add_header("DATA DETAIL HUTANG SUPPLIER");
|
|
$xls->add_header("Periode : ".$tglheader);
|
|
|
|
$xls->add_field("No. Nota", 10, "C");
|
|
$xls->add_field("Tgl. Nota", 10, "C", "sqltgl");
|
|
$xls->add_field("Nama Supplier", 80, "L");
|
|
$xls->add_field("Jumlah", 20, "R,N");
|
|
$xls->add_field("Bayar", 20, "R,N");
|
|
$xls->add_field("Sisa Hutang", 20, "R,N");
|
|
$xls->add_sheet("".str_replace("S/D","-",$tglheader), true);
|
|
|
|
if ($id_sup>0) $xls->add_span(["Nama Supplier : ".$nama_sup,6,"L"]);
|
|
|
|
$tot_hut = 0; $tot_bayar = 0;
|
|
while ($db->Next()) {
|
|
$tot_hut += $db->Row("Total_Hutang");
|
|
$tot_bayar += $db->Row("Total_Bayar");
|
|
$xls->add_value($db->Row("No_Beli"), $db->Row("Tgl_Beli"), $db->Row("Nama_Sup"), $db->Row("Total_Hutang"), $db->Row("Total_Bayar"), $db->Row("Total_Hutang")-$db->Row("Total_Bayar"));
|
|
}
|
|
$xls->add_span(array("GRAND TOTAL",3,"R,B"),array($tot_hut,1,"R,B,N"),array($tot_bayar,1,"R,B,N"),array($tot_hut-$tot_bayar,1,"R,B,N"));
|
|
}
|
|
$xls->add_stamp(1, true);
|
|
$xls->send("Data Hutang Supplier ".str_replace("S/D","-",$tglheader).".xlsx");
|
|
unset($xls);
|
|
|
|
} else if ( $data == "default") {
|
|
$form = new Form($db);
|
|
$ttipe = $form->radio("_", "Tipe", "R", true, false, ["R"=>"Rekap","D"=>"Detail"]);
|
|
$tcab = $form->option_db("_", "CabID", $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);
|
|
echo '
|
|
<div class="row mb-1">
|
|
<label class="col-sm-4 col-lg-3 col-form-label" for="Tipe">Tipe Laporan</label>
|
|
<div class="col col-form-label">'.$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>';
|
|
|
|
}
|
|
|
|
?>
|