138 lines
5.8 KiB
PHP
138 lines
5.8 KiB
PHP
<?php
|
|
|
|
/*******************************************************************
|
|
|
|
App. Name : INVENTORY AND SALES SYSTEMS
|
|
Module : /apps/php/repo/beli_mutasi.php
|
|
Desc. : PHP - Laporan Mutasi Pembelian
|
|
Created By : Siau Pheng ([email protected]).
|
|
Created Date : April 3rd, 2013.
|
|
Last Modified : December 12th, 2025.
|
|
|
|
(c) 2013 - 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"])) {
|
|
$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."'";
|
|
|
|
$n_saldo = 0;
|
|
$db->Query("SELECT SUM(Total_Hutang) Total FROM inv_beli WHERE Data_Beli=1 AND Tgl_Beli<'".$tglfrom."'".$tsql);
|
|
if ($db->Next()) $n_saldo = $db->RowFloat("Total", 0);
|
|
$db->Query("SELECT SUM(Total_Bayar+Total_Potong) Bayar FROM inv_beli_lunas WHERE No_Beli IN (SELECT No_Beli FROM inv_beli WHERE Data_Beli=1".$tsql.") AND Tgl_Bayar<'".$tglfrom."'");
|
|
if ($db->Next()) $b_saldo -= $db->RowFloat("Bayar", 0);
|
|
|
|
$db->Query("(SELECT Tgl_Beli,SUM(Total_Hutang) Total,0 Bayar FROM inv_beli WHERE Data_Beli=1 AND (Tgl_Beli BETWEEN '".$tglfrom."' AND '".$tglto."')".$tsql." GROUP BY Tgl_Beli) UNION ALL (SELECT Tgl_Bayar Tgl_Beli,0 Total,SUM(Total_Bayar+Total_Potong) Bayar FROM inv_beli_lunas WHERE No_Beli IN (SELECT No_Beli FROM inv_beli WHERE Data_Beli=1".$tsql.") AND (Tgl_Bayar BETWEEN '".$tglfrom."' AND '".$tglto."') GROUP BY Tgl_Bayar) ORDER BY Tgl_Beli,Total DESC");
|
|
}
|
|
|
|
if ( $data == "print" ) {
|
|
Report_Header("MUTASI PEMBELIAN", "Periode : ".$tglheader);
|
|
$pre = new \siaupheng\fonia3\Printer\PrintHTML();
|
|
$pre->add_field("Tanggal",10,"C","tgl_sql2str");
|
|
$pre->add_field("Nota / Bon",20,"R","rupiah");
|
|
$pre->add_field("Bayar",20,"R","rupiah");
|
|
$pre->add_field("Sisa",20,"R","rupiah");
|
|
|
|
if ($id_sup>0) $pre->add_span(array("Nama Supplier : ".$nama_sup,4,"L,B"));
|
|
|
|
$tot_sub = 0; $tot_bayar = 0;
|
|
$pre->add_span(["SALDO AWAL",1,"R,B"],["",1,"L"],["",1,"L"],[$n_saldo,1,"R,B","rupiah"]);
|
|
while ($db->Next()) {
|
|
$tot_sub += $db->Row("Total");
|
|
$tot_bayar += $db->Row("Bayar");
|
|
$n_saldo += $db->Row("Total") - $db->Row("Bayar");
|
|
$pre->add_value($db->Row("Tgl_Beli"), $db->Row("Total"), $db->Row("Bayar"), $n_saldo);
|
|
}
|
|
$pre->add_span(["SALDO AKHIR",1,"R,B"],[$tot_sub,1,"R,B","rupiah"],[$tot_bayar,1,"R,B","rupiah"],[$n_saldo,1,"R,B","rupiah"]);
|
|
$pre->add_stamp(1, true);
|
|
$pre->show();
|
|
|
|
} else if ( $data == "export" ) {
|
|
$xls = new SimpleXLS([
|
|
'title'=>"Data Mutasi Pembelian",
|
|
'desc'=>"Export Data Mutasi Pembelian"
|
|
]);
|
|
|
|
$xls->add_header("<b>".$_SESSION['__WEB_APP']['REG_NAME']."</b>");
|
|
$xls->add_header("<b>DATA MUTASI PEMBELIAN</b>");
|
|
$xls->add_header("Periode : ".$tglheader);
|
|
|
|
$xls->add_field("Tanggal", 10, "C");
|
|
$xls->add_field("Nota / Bon", 15, "R,N");
|
|
$xls->add_field("Bayar", 15, "R,N");
|
|
$xls->add_field("Sisa", 15, "R,N");
|
|
$xls->add_sheet("".str_replace("S/D","-",$tglheader), true);
|
|
|
|
if ($id_sup>0) $xls->add_span(array("Nama Supplier : ".$nama_sup,4,"L,B"));
|
|
|
|
$tot_sub = 0; $tot_bayar = 0;
|
|
$xls->add_span(["SALDO AWAL",1,"R,B"],["",1,"L"],["",1,"L"],[$n_saldo,1,"R,B","rupiah"]);
|
|
while ($db->Next()) {
|
|
$tot_sub += $db->Row("Total");
|
|
$tot_bayar += $db->Row("Bayar");
|
|
$n_saldo += $db->Row("Total") - $db->Row("Bayar");
|
|
$xls->add_value($db->Row("Tgl_Beli"), $db->Row("Total"), $db->Row("Bayar"), $n_saldo);
|
|
}
|
|
$xls->add_span(["SALDO AKHIR",1,"R,B"],[$tot_sub,1,"R,B","rupiah"],[$tot_bayar,1,"R,B","rupiah"],[$n_saldo,1,"R,B","rupiah"]);
|
|
|
|
$xls->add_stamp(1, true);
|
|
$xls->send("Data Mutasi Pembelian ".str_replace("S/D","-",$tglheader).".xlsx");
|
|
unset($xls);
|
|
|
|
} else if ( $data == "default") {
|
|
$form = new Form($db);
|
|
$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="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>';
|
|
}
|
|
|
|
?>
|