99 lines
4.8 KiB
PHP
99 lines
4.8 KiB
PHP
<?php
|
|
|
|
/*******************************************************************
|
|
|
|
App. Name : Inventory Advanced Systems
|
|
Module : /apps/php/repo/beli.php
|
|
Desc. : PHP - Laporan Pembelian
|
|
Created By : Siau Pheng ([email protected]).
|
|
Created Date : April 12th, 2011.
|
|
Last Modified : July 4th, 2023.
|
|
|
|
(c) 2011 - 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" ) {
|
|
$tipe = Param::Get("Tipe"); // R or D
|
|
$id_sup = Param::Get("SupID", 0);
|
|
$tglfrom = Param::Get("Tgl_From");
|
|
$tglto = Param::Get("Tgl_To");
|
|
$asup = [];
|
|
if ($id_sup > 0) {
|
|
$db->Query("SELECT * FROM para_supplier WHERE SupID='".$id_sup."' LIMIT 1");
|
|
if ($db->Next()) $asup = $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."'" : "";
|
|
|
|
// query data laporan
|
|
if ($tipe=="R") {
|
|
$db->Query("SELECT B.*,S.Nama_Sup FROM (SELECT SupID,SUM(Total_Beli) Total_Beli,SUM(Total_Diskon) Total_Diskon,SUM(Total_Beli-Total_Diskon) Total FROM inv_beli WHERE Data_Beli=1 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.*,DATE_FORMAT(B.Tgl_Beli,'%d-%m-%Y') Tgl_Beli2,B.Total_Beli-B.Total_Diskon Total,S.Nama_Sup FROM (SELECT * FROM inv_beli WHERE Data_Beli=1 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("LAPORAN ".($tipe=="R"?"REKAP":"DETAIL")." PEMBELIAN", $tglheader);
|
|
|
|
if ($id_sup>0) $header = "Nama Supplier : ".$asup['Nama_Sup'];
|
|
if ($tipe=="R") {
|
|
$header .= '<table class="garis"><thead><tr><th>No.</th><th>Nama Supplier</th><th>Sub. Total</th><th>Diskon</th><th>Total</th></tr></thead><tbody>';
|
|
$_line = '<tr><td class="c">%s</td><td>%s</td><td class="r">%s</td><td class="r">%s</td><td class="r">%s</td></tr>';
|
|
$_sline = '<tr><td class="c b" colspan="2">%s</td><td class="r b">%s</td><td class="r b">%s</td><td class="r b">%s</td></tr>';
|
|
|
|
$body = ''; $nomor = 1; $subtotal = 0; $diskon = 0;
|
|
while ($db->Next()) {
|
|
$subtotal += $db->Row("Total_Beli");
|
|
$diskon += $db->Row("Total_Diskon");
|
|
$body .= sprintf($_line, $nomor++, $db->Row("Nama_Sup"), rupiah2($db->Row("Total_Beli")), rupiah2($db->Row("Total_Diskon")), rupiah2($db->Row("Total")));
|
|
}
|
|
$body .= sprintf($_sline, "Jumlah", rupiah2($subtotal), rupiah2($diskon), rupiah2($subtotal-$diskon));
|
|
|
|
} else {
|
|
$header .= '<table class="garis"><thead><tr><th>No. Nota</th><th>Tgl. Nota</th><th>No. Faktur</th><th>Nama Supplier</th><th>Sub. Total</th><th>Diskon</th><th>Total</th></tr></thead><tbody>';
|
|
$_line = '<tr><td class="c">%s</td><td class="c">%s</td><td>%s</td><td>%s</td><td class="r">%s</td><td class="r">%s</td><td class="r">%s</td></tr>';
|
|
$_sline = '<tr><td class="c b" colspan="4">%s</td><td class="r b">%s</td><td class="r b">%s</td><td class="r b">%s</td></tr>';
|
|
|
|
$body = ''; $subtotal = 0; $diskon = 0;
|
|
while ($db->Next()) {
|
|
$subtotal += $db->Row("Total_Beli");
|
|
$diskon += $db->Row("Total_Diskon");
|
|
$body .= sprintf($_line, $db->Row("No_Beli"), $db->Row("Tgl_Beli2"), $db->Row("No_Faktur"), $db->Row("Nama_Sup"), rupiah2($db->Row("Total_Beli")), rupiah2($db->Row("Total_Diskon")), rupiah2($db->Row("Total")));
|
|
}
|
|
$body .= sprintf($_sline, "Jumlah", rupiah2($subtotal), rupiah2($diskon), rupiah2($subtotal-$diskon));
|
|
}
|
|
|
|
echo $header . $body . "</tbody></table>" . Report_Stamp(1, true);
|
|
|
|
} else if ( $data == "default") {
|
|
$form = new Form($db);
|
|
$form->radio("Tipe Laporan", "Tipe", "R", true, false, ["R"=>"Rekap","D"=>"Detail"]);
|
|
$form->option_db("Nama Supplier", "SupID", 0, true, false, "para_supplier", ["SupID","Nama_Sup"], "TRUE ORDER BY Nama_Sup", [0,"SEMUA SUPPLIER"]);
|
|
$form->datebox("Dari Tanggal", "Tgl_From", tgl_ymd(), true, false);
|
|
$form->datebox("Sampai Tanggal", "Tgl_To", tgl_ymd(), true, false);
|
|
$form->show(' _Tipe_ _SupID_ _Tgl_From_ _Tgl_To_ ');
|
|
}
|
|
|
|
?>
|