142 lines
5.6 KiB
PHP
142 lines
5.6 KiB
PHP
<?php
|
|
|
|
/*******************************************************************
|
|
|
|
App. Name : Inventory Advanced Systems
|
|
Module : /apps/php/repo/produk.php
|
|
Desc. : PHP - Laporan Daftar Produk
|
|
Created By : Siau Pheng ([email protected]).
|
|
Created Date : May 26th, 2010.
|
|
Last Modified : March 21st, 2023.
|
|
|
|
(c) 2010 - 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;
|
|
|
|
$db = (is_resource($db)) ? $db : new MySQL();
|
|
$ajson = [];
|
|
$data = Param::Get("data");
|
|
|
|
if ( $data == "print" || $data == "export") {
|
|
$id_grup = Param::Get("Grup_InvID", 0); $agrup = [];
|
|
if ($id_grup>0) {
|
|
$db->Query("SELECT * FROM inv_produk_grup WHERE Grup_InvID='".$id_grup."'");
|
|
if ($db->Next()) $agrup = $db->AllRow();
|
|
}
|
|
|
|
// generate report header
|
|
$tglheader = "Tanggal Cetak : ".Param::Get("Tgl_Cetak");
|
|
$tsql = ($id_grup==0) ? "" : " WHERE Grup_InvID='".$id_grup."'";
|
|
|
|
// query data laporan
|
|
$db->Query("SELECT * FROM vi_inv_produk".$tsql." ORDER BY Nama_Produk");
|
|
}
|
|
|
|
if ( $data == "print" ) {
|
|
Report_Header("LAPORAN DAFTAR PRODUK", $tglheader);
|
|
|
|
if ($id_grup>0) $header = '<p>Nama Grup Produk : '.$agrup['Nama_Grup'].'</p>';
|
|
$header .= '<table class="garis"><thead><tr><th>No.</th><th>Kode</th><th>Nama Produk</th><th>Satuan</th></tr></thead><tbody>';
|
|
$_line = '<tr><td class="c">%s</td><td>%s</td><td>%s</td><td>%s</td></tr>';
|
|
|
|
$body = ''; $nomor = 1;
|
|
while ($db->Next()) {
|
|
$body .= sprintf($_line, $nomor, $db->Row("Kode_Produk"), $db->Row("Nama_Produk"), $db->Row("Satuan_Stok"));
|
|
$nomor++;
|
|
}
|
|
|
|
echo $header . $body . "</tbody></table>" . Report_Stamp(1, true);
|
|
|
|
} else if ( $data == "export" ) {
|
|
\PhpOffice\PhpSpreadsheet\Cell\Cell::setValueBinder( new \PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder() );
|
|
|
|
$styleTxt = [
|
|
'numberFormat' => ['formatCode' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT]
|
|
];
|
|
$styleNum = [
|
|
'numberFormat' => ['formatCode' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2]
|
|
];
|
|
|
|
$ssheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
|
$ssheet->getProperties()
|
|
->setCreator($_SESSION['__WEB_APP']['APP_NAME']." v".$_SESSION['__WEB_APP']['APP_VER'])
|
|
->setLastModifiedBy($_SESSION['__WEB_APP']['APP_NAME']." v".$_SESSION['__WEB_APP']['APP_VER'])
|
|
->setTitle("Daftar Produk")
|
|
->setCompany($_SESSION['__WEB_APP']['REG_NAME']);
|
|
$sheet = $ssheet->getActiveSheet();
|
|
$sheet->setTitle("Daftar Produk");
|
|
|
|
// header
|
|
$styleHeader = [
|
|
'font' => ['bold' => true],
|
|
'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER]
|
|
];
|
|
$sheet->setCellValue("A1", strtoupper($_SESSION['__WEB_APP']['REG_NAME']));
|
|
$sheet->mergeCells('A1:D1');
|
|
$sheet->setCellValue("A2", "LAPORAN DAFTAR PRODUK");
|
|
$sheet->mergeCells('A2:D2');
|
|
$sheet->setCellValue("A3", $tglheader);
|
|
$sheet->mergeCells('A3:D3');
|
|
$sheet->getStyle('A1:D3')->applyFromArray($styleHeader);
|
|
|
|
// table header
|
|
$sheet->getColumnDimension('A')->setWidth(8);
|
|
$sheet->getColumnDimension('B')->setWidth(25);
|
|
$sheet->getColumnDimension('C')->setWidth(80);
|
|
$sheet->getColumnDimension('D')->setWidth(15);
|
|
|
|
$baris = 5;
|
|
if ($id_grup>0) {
|
|
$sheet->setCellValue("A".$baris, "Nama Grup Outlet : ".$agrup['Nama_Grup']);
|
|
$baris++;
|
|
}
|
|
|
|
$styleTableH = [
|
|
'font' => ['bold' => true],
|
|
'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER, 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER, 'wrapText' => true],
|
|
'fill' => ['fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID, 'startColor' => ['rgb'=>"D0D0D0"]],
|
|
'borders' => ['allBorders' => ['borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, 'color' => ['rgb'=>"C0C0C0"]]]
|
|
];
|
|
$sheet->setCellValue("A".$baris, "No.");
|
|
$sheet->setCellValue("B".$baris, "Kode");
|
|
$sheet->setCellValue("C".$baris, "Nama Produk");
|
|
$sheet->setCellValue("D".$baris, "Satuan");
|
|
$sheet->getStyle('A'.$baris.':D'.$baris)->applyFromArray($styleTableH);
|
|
|
|
$baris++; $nomor = 1;
|
|
while ($db->Next()) {
|
|
$sheet->setCellValue("A".$baris, $nomor++);
|
|
$sheet->setCellValue("B".$baris, $db->Row("Kode_Produk"));
|
|
$sheet->setCellValue("C".$baris, $db->Row("Nama_Produk"));
|
|
$sheet->setCellValue("D".$baris, $db->Row("Satuan_Stok"));
|
|
$baris++;
|
|
}
|
|
|
|
$sheet->getSheetView()->setZoomScale(75);
|
|
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
|
header('Content-Disposition: attachment;filename="Daftar Produk.xlsx"');
|
|
header('Cache-Control: max-age=0');
|
|
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($ssheet, 'Xlsx');
|
|
$writer->save('php://output');
|
|
$ssheet->disconnectWorksheets();
|
|
unset($ssheet);
|
|
unset($writer);
|
|
|
|
} else if ( $data == "default") {
|
|
$form = new Form($db);
|
|
$form->option_db("Grup Produk", "Grup_InvID", 0, true, true, "inv_produk_grup", array("Grup_InvID","Nama_Grup"), "Aktif=1 ORDER BY Nama_Grup", [0,"SEMUA GRUP PRODUK"]);
|
|
$form->datebox("Tanggal Cetak", "Tgl_Cetak", tgl_ymd(), true, true);
|
|
$form->show(' _Grup_InvID_ _Tgl_Cetak_ ');
|
|
}
|
|
|
|
?>
|