Files
2026-01-22 15:30:17 +07:00

127 lines
5.3 KiB
PHP

<?php
/*******************************************************************
App. Name : Inventory Advanced Systems
Module : /apps/php/repo/rekap_sup.php
Desc. : PHP - Laporan Rekap Pembelian / Supplier
Created By : Siau Pheng ([email protected]).
Created Date : March 5th, 2012.
Last Modified : November 18th, 2023.
(c) 2012 - 2023, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
require_once(__DIR__."/../../../../../vendor/autoload.php");
require_once(__DIR__."/../func/ias.php");
require_once(__DIR__."/../func/report.php");
use siaupheng\fonia3\DB\MySQL;
use siaupheng\fonia3\DB\SQL;
use siaupheng\fonia3\Web\Param;
use siaupheng\fonia3\Web\Form;
use siaupheng\fonia3\Data\SimpleXLS;
$db = (is_resource($db)) ? $db : new MySQL();
$ajson = [];
$data = Param::Get("data");
if ( $data == "print" || $data == "export" ) {
$id_sup = Param::Get("SupID", 0);
$id_grup = Param::Get("Grup_InvID", 0);
$tglfrom = Param::Get("Tgl_From");
$tglto = Param::Get("Tgl_To");
$asup = []; $agrup = [];
if ($id_sup > 0) {
$db->Query("SELECT * FROM para_supplier WHERE SupID='".$id_sup."' LIMIT 1");
if ($db->Next()) $asup = $db->AllRow();
}
if ($id_grup > 0) {
$db->Query("SELECT * FROM inv_produk_grup WHERE Grup_InvID='".$id_grup."' LIMIT 1");
if ($db->Next()) $agrup = $db->AllRow();
}
// generate report header
$tglheader = "Periode : ".$tglfrom;
if ($tglfrom!==$tglto) $tglheader .= " s/d ".$tglto;
$tglfrom = tgl_sql2str($tglfrom);
$tglto = tgl_sql2str($tglto);
$tsql = ($id_sup>0) ? " AND SupID='".$id_sup."'" : "";
$tsql2 = ($id_grup>0) ? " AND P.Grup_InvID='".$id_grup."'" : "";
// query data laporan
$db->Query("SELECT D.*,P.Kode_Produk,P.Nama_Produk,S.Nama_Satuan FROM (SELECT InvID,SatuanID,SUM(Qty) Qty FROM inv_detail WHERE No_Ref IN (SELECT No_Beli FROM inv_beli WHERE Data_Beli=1 AND (Tgl_Beli BETWEEN '".$tglfrom."' AND '".$tglto."')".$tsql.") GROUP BY InvID,SatuanID) D LEFT JOIN inv_produk P ON (D.InvID=P.InvID) LEFT JOIN para_satuan S ON (D.SatuanID=S.SatuanID) ORDER BY P.Nama_Produk");
}
if ( $data == "print" ) {
Report_Header("LAPORAN REKAP PEMBELIAN PRODUK PER-SUPPLIER", $tglheader);
if ($id_sup>0) $header .= "Nama Supplier : ".$asup['Nama_Sup'];
if ($id_grup>0) $header .= "Nama Grup Produk : ".$agrup['Nama_Grup'];
$header .= '<table class="garis"><thead><tr><th>No.</th><th>Kode</th><th>Nama Produk</th><th>Jumlah</th><th>Satuan</th></tr></thead><tbody>';
$_line = '<tr><td class="c">%s</td><td class="c">%s</td><td>%s</td><td class="r">%s</td><td>%s</td></tr>';
$_sline = '<tr><td class="c b" colspan="2">%s</td><td class="r b" colspan="3">%s</td></tr>';
$body = ''; $nomor = 0; $atot = [];
while ($db->Next()) {
$atot[$db->Row("Nama_Satuan")] += $db->Row("Qty");
$body .= sprintf($_line, ++$nomor, $db->Row("Kode_Produk"), $db->Row("Nama_Produk"), rupiah2($db->Row("Qty")), $db->Row("Nama_Satuan"));
}
$ket_tot = "";
foreach ($atot as $key => $val) {
if ($val > 0) $ket_tot .= " / ".rupiah2($val,2)." ".strtoupper($key);
}
$ket_tot = substr($ket_tot, 3);
$body .= sprintf($_sline, "Jumlah", $ket_tot);
echo $header . $body . "</tbody></table>" . Report_Stamp(1, true);
} else if ( $data == "export" ) {
$xls = new SimpleXLS([
'title'=>"Laporan Rekap Pembelian Produk Per-Supplier",
'subject'=>"PT.PMS",
'desc'=>"Export Data dari IAS"
]);
$xls->add_header("<b>".strtoupper($_SESSION['__WEB_APP']['REG_NAME'])."</b>");
$xls->add_header("<b>LAPORAN REKAP PEMBELIAN PRODUK PER-SUPPLIER</b>");
$xls->add_header($tglheader);
$xls->add_field("NO.", 10, "C");
$xls->add_field("KODE", 25, "L");
$xls->add_field("NAMA PRODUK", 80, "L");
$xls->add_field("JUMLAH", 20, "R,N");
$xls->add_field("SATUAN", 12, "L");
$xls->add_sheet("R-BELI-SUP", false);
if ($id_sup>0) $xls->add_span(["Nama Supplier : ".$asup['Nama_Sup'],5,"L"]);
if ($id_grup>0) $xls->add_span(["Nama Grup Produk : ".$agrup['Nama_Grup'],5,"L"]);
$xls->show_headers();
$nomor = 0; $atot = [];
while ($db->Next()) {
$xls->add_value(++$nomor, $db->Row("Kode_Produk"), $db->Row("Nama_Produk"), uang($db->Row("Qty"),2), $db->Row("Nama_Satuan"));
$atot[$db->Row("Nama_Satuan")] += $db->Row("Qty");
}
$ket_tot = "";
foreach ($atot as $key => $val) {
if ($val > 0) $ket_tot .= " / ".uang($val,2)." ".strtoupper($key);
}
$ket_tot = substr($ket_tot, 3);
$xls->add_span(["Jumlah",2,"L,B"],[$ket_tot,3,"C,B"]);
$xls->add_stamp(1, true);
$xls->send("Laporan Rekap Pembelian Produk Per-Supplier.xlsx");
unset($xls);
} else if ( $data == "default") {
$form = new Form($db);
$form->option_db("Nama Supplier", "SupID", 0, true, false, "para_supplier", ["SupID","Nama_Sup"], "TRUE ORDER BY Nama_Sup", [0,"SEMUA SUPPLIER"]);
$form->option_db("Grup Produk", "Grup_InvID", 0, true, false, "inv_produk_grup", ["Grup_InvID","Nama_Grup"], "TRUE ORDER BY Nama_Grup", [0,"SEMUA GRUP PRODUK"]);
$form->datebox("Dari Tanggal", "Tgl_From", tgl_ymd(), true, false);
$form->datebox("Sampai Tanggal", "Tgl_To", tgl_ymd(), true, false);
$form->show(' _SupID_ _Grup_InvID_ _Tgl_From_ _Tgl_To_ ');
}
?>