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 .= '
| No. | Kode | Nama Produk | Jumlah | Satuan |
';
$_line = '| %s | %s | %s | %s | %s |
';
$_sline = '| %s | %s |
';
$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 . "
" . 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("".strtoupper($_SESSION['__WEB_APP']['REG_NAME'])."");
$xls->add_header("LAPORAN REKAP PEMBELIAN PRODUK PER-SUPPLIER");
$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_ ');
}
?>