232 lines
9.8 KiB
PHP
232 lines
9.8 KiB
PHP
<?php
|
|
|
|
/*******************************************************************
|
|
|
|
App. Name : INVENTORY AND SALES SYSTEMS
|
|
Module : /apps/php/repo/beli_analisa.php
|
|
Desc. : PHP - Laporan Analisa Pembelian
|
|
Created By : Siau Pheng ([email protected]).
|
|
Created Date : August 4th, 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"])) {
|
|
$tipe = Param::Get("Tipe", "V"); // V or R
|
|
$id_sup = Param::Get("SupID", 0);
|
|
$id_grup = Param::Get("Grup_InvID", 0);
|
|
$tglfrom = Param::Get("Tgl_From");
|
|
$tglto = Param::Get("Tgl_To");
|
|
$jum_hari = tgl_range_hari($tglfrom, $tglto, true);
|
|
|
|
$nama_sup = ""; $nama_grup = "";
|
|
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");
|
|
}
|
|
if ($id_grup > 0) {
|
|
$db->Query("SELECT Nama_Grup Nama FROM inv_produk_grup WHERE Grup_InvID='".$id_grup."' LIMIT 1");
|
|
if ($db->Next()) $nama_grup = $db->Row("Nama");
|
|
}
|
|
|
|
// generate report header
|
|
$tglheader = $tglfrom;
|
|
if ($tglfrom!==$tglto) $tglheader .= " S/D ".$tglto;
|
|
$tglfrom = tgl_sql2str($tglfrom);
|
|
$tglto = tgl_sql2str($tglto);
|
|
|
|
$tsql1 = ($id_cab==0) ? "" : " AND CabID='".$id_cab."'";
|
|
$tsql1 .= ($id_sup==0) ? "" : " AND No_Ref IN (SELECT No_Beli FROM inv_beli WHERE SupID='".$id_cab."' AND (Tgl_Beli BETWEEN '".$tglfrom."' AND '".$tglto."'))";
|
|
$tsql2 = ($id_grup==0) ? "" : " WHERE P.Grup_InvID='".$id_grup."'";
|
|
|
|
if ($tipe=="V") {
|
|
$db->Query("SELECT P.*,D.Volume FROM (SELECT InvID,SUM(Stok) Volume FROM inv_detail WHERE Stok>0 AND NotaID IN (3,4) AND (Tgl_Ref BETWEEN '".$tglfrom."' AND '".$tglto."')".$tsql1." GROUP BY InvID) D LEFT JOIN vi_inv_produk2 P ON (D.InvID=P.InvID)".$tsql2." ORDER BY P.Nama_Produk");
|
|
} else if ($tipe=="R") {
|
|
$db->Query("SELECT P.*,D.Rupiah FROM (SELECT InvID,SUM(Qty*Harga_Beli) Rupiah FROM inv_detail WHERE Stok>0 AND NotaID IN (3,4) AND (Tgl_Ref BETWEEN '".$tglfrom."' AND '".$tglto."')".$tsql1." GROUP BY InvID) D LEFT JOIN inv_produk P ON (D.InvID=P.InvID)".$tsql2." ORDER BY P.Nama_Produk");
|
|
}
|
|
}
|
|
|
|
if ( $data == "print" ) {
|
|
Report_Header("REKAP ".($tipe=="V"?"VOLUME":"RUPIAH")." PEMBELIAN", "Periode : ".$tglheader);
|
|
$pre = new \siaupheng\fonia3\Printer\PrintHTML();
|
|
|
|
if ($tipe=="V") {
|
|
$pre->add_field("No.",10,"C");
|
|
$pre->add_field("Nama Barang",50,"L");
|
|
$pre->add_field("Jumlah",20,"R");
|
|
$pre->add_field("Mingguan",20,"R");
|
|
|
|
if ($id_sup>0) $pre->add_span(array("Nama Supplier : ".$nama_sup,4,"L,B"));
|
|
if ($id_grup>0) $pre->add_span(array("Grup Barang : ".$nama_grup,4,"L,B"));
|
|
|
|
$nomor = 0;
|
|
while ($db->Next()) {
|
|
$total = $db->Row("Volume",0);
|
|
$mg_total = $total / ($jum_hari/7);
|
|
$kali = $db->Row("Qty",0);
|
|
if ($kali > 0) {
|
|
$norm = floor($total / $kali);
|
|
$sisa = $total - ($norm * $kali);
|
|
$mg_norm = floor($mg_total / $kali);
|
|
$mg_sisa = $mg_total - ($mg_norm * $kali);
|
|
} else {
|
|
$norm = 0;
|
|
$sisa = $total;
|
|
$mg_norm = 0;
|
|
$mg_sisa = $mg_total;
|
|
}
|
|
$stok = rupiah($norm,0)." ".$db->Row("Satuan_Normal");
|
|
$mg_stok = rupiah($mg_norm,0)." ".$db->Row("Satuan_Normal");
|
|
if ($db->Row("Satuan_Normal")<>$db->Row("Satuan_Stok")) {
|
|
$stok .= ", ".rupiah($sisa,0)." ".$db->Row("Satuan_Stok");
|
|
$mg_stok .= ", ".rupiah($mg_sisa,0)." ".$db->Row("Satuan_Stok");
|
|
}
|
|
$pre->add_value(++$nomor, $db->Row("Nama_Produk"), $stok, $mg_stok);
|
|
}
|
|
|
|
} else {
|
|
$pre->add_field("No.",10,"C");
|
|
$pre->add_field("Nama Barang",50,"L");
|
|
$pre->add_field("Jumlah",20,"R","rupiah");
|
|
$pre->add_field("Mingguan",20,"R","rupiah");
|
|
|
|
if ($id_sup>0) $pre->add_span(array("Nama Supplier : ".$nama_sup,4,"L,B"));
|
|
if ($id_grup>0) $pre->add_span(array("Grup Barang : ".$nama_grup,4,"L,B"));
|
|
|
|
$nomor = 0; $tot_rup = 0; $tot_mg = 0;
|
|
while ($db->Next()) {
|
|
$mg_avg = ($db->Row("Rupiah",0)>0) ? $db->Row("Rupiah",0) / ($jum_hari/7) : 0;
|
|
$tot_rup += $db->Row("Rupiah");
|
|
$tot_mg += $mg_avg;
|
|
$pre->add_value(++$nomor, $db->Row("Nama_Produk"), $db->Row("Rupiah"), $mg_avg);
|
|
}
|
|
$pre->add_span(array("TOTAL",2,"R,B"),array(rupiah($tot_rup),1,"R,B"),array(rupiah($tot_mg),1,"R,B"));
|
|
}
|
|
$pre->add_stamp(1, true);
|
|
$pre->show();
|
|
|
|
} else if ( $data == "export" ) {
|
|
$xls = new SimpleXLS([
|
|
'title'=>"Data Analisa Pembelian",
|
|
'desc'=>"Export Data Analisa Pembelian"
|
|
]);
|
|
|
|
if ($tipe=="V") {
|
|
$xls->add_header("<b>".$_SESSION['__WEB_APP']['REG_NAME']."</b>");
|
|
$xls->add_header("<b>DATA REKAP VOLUME PEMBELIAN</b>");
|
|
$xls->add_header("Periode : ".$tglheader);
|
|
|
|
$xls->add_field("No.", 5, "C");
|
|
$xls->add_field("Nama Barang", 25, "L");
|
|
$xls->add_field("Jumlah", 15, "R");
|
|
$xls->add_field("Mingguan", 15, "R");
|
|
|
|
$xls->add_sheet("".str_replace("S/D","-",$tglheader), true);
|
|
|
|
if ($id_sup>0) $xls->add_span(array("Nama Supplier : ".$nama_sup,4,"L,B"));
|
|
if ($id_grup>0) $xls->add_span(array("Grup Barang : ".$nama_grup,4,"L,B"));
|
|
|
|
$nomor = 0;
|
|
while ($db->Next()) {
|
|
$total = $db->Row("Volume",0);
|
|
$mg_total = $total / ($jum_hari/7);
|
|
$kali = $db->Row("Qty",0);
|
|
if ($kali > 0) {
|
|
$norm = floor($total / $kali);
|
|
$sisa = $total - ($norm * $kali);
|
|
$mg_norm = floor($mg_total / $kali);
|
|
$mg_sisa = $mg_total - ($mg_norm * $kali);
|
|
} else {
|
|
$norm = 0;
|
|
$sisa = $total;
|
|
$mg_norm = 0;
|
|
$mg_sisa = $mg_total;
|
|
}
|
|
$stok = rupiah($norm,0)." ".$db->Row("Satuan_Normal");
|
|
$mg_stok = rupiah($mg_norm,0)." ".$db->Row("Satuan_Normal");
|
|
if ($db->Row("Satuan_Normal")<>$db->Row("Satuan_Stok")) {
|
|
$stok .= ", ".rupiah($sisa,0)." ".$db->Row("Satuan_Stok");
|
|
$mg_stok .= ", ".rupiah($mg_sisa,0)." ".$db->Row("Satuan_Stok");
|
|
}
|
|
$xls->add_value(++$nomor, $db->Row("Nama_Produk"), $stok, $mg_stok);
|
|
}
|
|
|
|
} else {
|
|
$xls->add_header("<b>".$_SESSION['__WEB_APP']['REG_NAME']."</b>");
|
|
$xls->add_header("<b>DATA REKAP RUPIAH PEMBELIAN</b>");
|
|
$xls->add_header("Periode : ".$tglheader);
|
|
|
|
$xls->add_field("No.", 5, "C");
|
|
$xls->add_field("Nama Barang", 25, "L");
|
|
$xls->add_field("Jumlah", 15, "R,N");
|
|
$xls->add_field("Mingguan", 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"));
|
|
if ($id_grup>0) $xls->add_span(array("Grup Barang : ".$nama_grup,4,"L,B"));
|
|
|
|
$nomor = 0; $tot_rup = 0; $tot_mg = 0;
|
|
while ($db->Next()) {
|
|
$mg_avg = ($db->Row("Rupiah",0)>0) ? $db->Row("Rupiah",0) / ($jum_hari/7) : 0;
|
|
$tot_rup += $db->Row("Rupiah");
|
|
$tot_mg += $mg_avg;
|
|
$xls->add_value(++$nomor, $db->Row("Nama_Produk"), $db->Row("Rupiah"), $mg_avg);
|
|
}
|
|
$xls->add_span(array("TOTAL",2,"R,B"),array($tot_rup,1,"R,B,N"),array($tot_mg,1,"R,B,N"));
|
|
}
|
|
$xls->add_stamp(1, true);
|
|
$xls->send("Data Analisa Pembelian ".str_replace("S/D","-",$tglheader).".xlsx");
|
|
unset($xls);
|
|
|
|
} else if ( $data == "default") {
|
|
$form = new Form($db);
|
|
$ttipe = $form->radio("_", "Tipe", "V", true, false, ["V"=>"Volume","R"=>"Rupiah"]);
|
|
$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"]);
|
|
$tgrup = $form->option_db("_", "Grup_InvID", 0, true, false, "inv_produk_grup", ["Grup_InvID","Nama_Grup"], "Aktif=1 ORDER BY Nama_Grup", [0,"SEMUA GRUP"]);
|
|
$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="Grup_InvID">Grup Barang</label>
|
|
<div class="col">'.$tgrup.'</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>';
|
|
}
|
|
|
|
?>
|