175 lines
7.0 KiB
PHP
175 lines
7.0 KiB
PHP
<?php
|
|
|
|
/*******************************************************************
|
|
|
|
App. Name : INVENTORY AND SALES SYSTEMS
|
|
Module : /apps/php/repo/beli_retur.php
|
|
Desc. : PHP - Laporan Retur Pembelian
|
|
Created By : Siau Pheng ([email protected]).
|
|
Created Date : April 12th, 2011.
|
|
Last Modified : December 12th, 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 CONCAT(Nama_Sup,' (',Kode_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_cab==0) ? "" : " AND CabID='".$id_cab."'";
|
|
$tsql .= ($id_sup==0) ? "" : " AND SupID='".$id_cab."'";
|
|
|
|
if ($tipe=="R") {
|
|
$db->Query("SELECT B.*,S.Nama_Sup FROM (SELECT SupID,SUM(-Total_Hutang) Total_Retur FROM inv_beli WHERE Data_Beli=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.*,S.Nama_Sup,-B.Total_Hutang Retur FROM (SELECT * FROM inv_beli WHERE Data_Beli=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")." RETUR PEMBELIAN", "Periode : ".$tglheader);
|
|
$pre = new \siaupheng\fonia3\Printer\PrintHTML();
|
|
|
|
if ($tipe=="R") {
|
|
$pre->add_field("No.",10,"C");
|
|
$pre->add_field("Nama Supplier",50,"L");
|
|
$pre->add_field("Total",20,"R","rupiah");
|
|
|
|
if ($id_sup>0) $pre->add_span(array("Nama Supplier : ".$nama_sup,3,"L,B"));
|
|
|
|
$tot_retur = 0; $nomor = 0;
|
|
while ($db->Next()) {
|
|
$tot_retur += $db->Row("Total_Retur");
|
|
$pre->add_value(++$nomor, $db->Row("Nama_Sup"), $db->Row("Total_Retur"));
|
|
}
|
|
$pre->add_span(array("GRAND TOTAL",2,"R,B"),array($tot_retur,1,"R,B","rupiah"));
|
|
|
|
} else {
|
|
$pre->add_field("No. Nota",30,"C");
|
|
$pre->add_field("Tgl. Nota",30,"C", "tgl_sql2str");
|
|
$pre->add_field("Nama Supplier",50,"L");
|
|
$pre->add_field("Total",30,"R","rupiah");
|
|
$pre->add_field("Catatan",50,"L");
|
|
|
|
if ($id_sup>0) $pre->add_span(array("Nama Supplier : ".$nama_sup,5,"L,B"));
|
|
|
|
$tot_retur = 0;
|
|
while ($db->Next()) {
|
|
$tot_retur += $db->Row("Retur");
|
|
$pre->add_value($db->Row("No_Beli"), $db->Row("Tgl_Beli"), $db->Row("Nama_Sup"), $db->Row("Retur"), $db->Row("No_Faktur"));
|
|
}
|
|
$pre->add_span(array("GRAND TOTAL",3,"R,B"),array($tot_retur,1,"R,B","rupiah"),[" ",1,"L"]);
|
|
}
|
|
$pre->add_stamp(1, true);
|
|
$pre->show();
|
|
|
|
} else if ( $data == "export" ) {
|
|
$xls = new SimpleXLS([
|
|
'title'=>"Data Retur Pembelian",
|
|
'desc'=>"Export Data Retur Pembelian"
|
|
]);
|
|
|
|
if ($tipe=="R") {
|
|
$xls->add_header("<b>".$_SESSION['__WEB_APP']['REG_NAME']."</b>");
|
|
$xls->add_header("<b>DATA REKAP RETUR PEMBELIAN</b>");
|
|
$xls->add_header("Periode : ".$tglheader);
|
|
|
|
$xls->add_field("No.", 5, "C");
|
|
$xls->add_field("Nama Supplier", 25, "L");
|
|
$xls->add_field("Total", 15, "R,N");
|
|
$xls->add_sheet("".str_replace("S/D","-",$tglheader), true);
|
|
|
|
if ($id_sup>0) $xls->add_span(array("Nama Supplier : ".$nama_sup,3,"L,B"));
|
|
|
|
$tot_retur = 0; $nomor = 0;
|
|
while ($db->Next()) {
|
|
$tot_retur += $db->Row("Total_Retur");
|
|
$xls->add_value(++$nomor, $db->Row("Nama_Sup"), $db->Row("Total_Retur"));
|
|
}
|
|
$xls->add_span(array("GRAND TOTAL",2,"R,B"),array($tot_retur,1,"R,B,N"));
|
|
|
|
} else {
|
|
$xls->add_header("<b>".$_SESSION['__WEB_APP']['REG_NAME']."</b>");
|
|
$xls->add_header("<b>DATA DETAIL RETUR PEMBELIAN</b>");
|
|
$xls->add_header("Periode : ".$tglheader);
|
|
|
|
$xls->add_field("No. Nota", 15, "C");
|
|
$xls->add_field("Tgl. Nota", 12, "C", "tgl_sql2str");
|
|
$xls->add_field("Nama Supplier", 20, "L");
|
|
$xls->add_field("Total", 15, "R,N");
|
|
$xls->add_field("Catatan", 25, "L");
|
|
$xls->add_sheet("".str_replace("S/D","-",$tglheader), true);
|
|
|
|
if ($id_sup>0) $xls->add_span(array("Nama Supplier : ".$nama_sup,5,"L,B"));
|
|
|
|
$tot_retur = 0;
|
|
while ($db->Next()) {
|
|
$tot_retur += $db->Row("Retur");
|
|
$xls->add_value($db->Row("No_Beli"), $db->Row("Tgl_Beli"), $db->Row("Nama_Sup"), $db->Row("Retur"), $db->Row("No_Faktur"));
|
|
}
|
|
$xls->add_span(array("GRAND TOTAL",3,"R,B"),array($tot_retur,1,"R,B,N"),[" ",1,"L"]);
|
|
}
|
|
$xls->add_stamp(1, true);
|
|
$xls->send("Data Retur Pembelian ".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>';
|
|
}
|
|
|
|
?>
|