181 lines
9.2 KiB
PHP
181 lines
9.2 KiB
PHP
<?php
|
|
|
|
/*******************************************************************
|
|
|
|
App. Name : Inventory Advanced Systems
|
|
Module : /apps/php/repo/stok_mutasi.php
|
|
Desc. : PHP - Laporan Mutasi Stok Produk
|
|
Created By : Siau Pheng ([email protected]).
|
|
Created Date : July 16th, 2011.
|
|
Last Modified : November 18th, 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\Table;
|
|
use siaupheng\fonia3\Web\Form;
|
|
use siaupheng\fonia3\Printer\PrintHTML;
|
|
use siaupheng\fonia3\Data\SimpleXLS;
|
|
|
|
$db = (is_resource($db)) ? $db : new MySQL();
|
|
$ajson = [];
|
|
$data = Param::Get("data");
|
|
|
|
if ( $data == "print" || $data == "export" ) {
|
|
$tipe = Param::Get("Tipe_Data"); // X:Semua, B:Beli, J:Jual
|
|
$jenis = Param::Get("Nota_Pajak", 1); // 1:No_Faktur, 2:No_Pajak
|
|
$id_gudang = Param::Get("GudangID", 0);
|
|
$id_inv = Param::Get("InvID");
|
|
$tglfrom = Param::Get("Tgl_From");
|
|
$tglto = Param::Get("Tgl_To");
|
|
$agudang = []; $aproduk = [];
|
|
if ($id_gudang > 0) {
|
|
$db->Query("SELECT * FROM para_gudang WHERE GudangID='".$id_gudang."' LIMIT 1");
|
|
if ($db->Next()) $agudang = $db->AllRow();
|
|
}
|
|
if ($id_inv > 0) {
|
|
$db->Query("SELECT CONCAT('[',Kode_Produk,'] ',Nama_Produk,' (',Satuan_Normal,')') Nama_Produk FROM vi_inv_produk WHERE InvID='".$id_inv."' LIMIT 1");
|
|
if ($db->Next()) $aproduk = $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_gudang==0) ? " AND D.NotaID<>2" : " AND D.GudangID='".$id_gudang."'";
|
|
$tord = ($jenis==1) ? ",No_Faktur" : ",No_Pajak";
|
|
|
|
// query ukuran normal produk & stok awal
|
|
$db->Query("SELECT P.Satuan_Stok,P.Satuan_Normal,S.Qty Kali FROM (SELECT * FROM vi_inv_produk WHERE InvID='".$id_inv."') P LEFT JOIN inv_produk_kemasan S ON (S.InvID=P.InvID AND S.SatuanID=P.NormalID)");
|
|
if ($db->Next()) $ainfo = $db->AllRow();
|
|
$stok = 0;
|
|
$db->Query("SELECT SUM(D.Stok) Stok FROM inv_detail D LEFT JOIN inv_jual J ON (J.No_Jual=D.No_Ref) WHERE D.Tgl_Ref<>'0000-00-00' AND D.Tgl_Ref<'".$tglfrom."'".$tsql." AND D.InvID='".$id_inv."' AND (D.NotaID<>5 OR (D.NotaID=5 AND J.Rekap=1 AND D.Promo=0))");
|
|
if ($db->Next()) $stok = $db->Row("Stok", 0);
|
|
|
|
if ($tipe == "X") {
|
|
$tsql .= " AND (D.NotaID<>5 OR (D.NotaID=5 AND J.Rekap=1 AND D.Promo=0))";
|
|
} else {
|
|
$tsql .= ($tipe == "B") ? " AND D.NotaID=3" : " AND (D.NotaID=5 AND J.Rekap=1 AND D.Promo=0)";
|
|
}
|
|
|
|
$db->Query("SELECT DATE_FORMAT(D.Tgl_Ref,'%d-%m-%Y') Tgl_Ref2,D.No_Ref,SUM(IF(D.Stok<0,-D.Stok,0)) Keluar,SUM(IF(D.Stok>0,D.Stok,0)) Masuk, IF(ISNULL(B.No_Faktur),J.No_Faktur,B.No_Faktur) No_Faktur, IF(ISNULL(B.No_Pajak),J.No_Pajak,B.No_Pajak) No_Pajak, IF(ISNULL(S.Nama_Sup),T.Nama_Outlet,S.Nama_Sup) Nama FROM inv_detail D LEFT JOIN inv_beli B ON (B.No_Beli=D.No_Ref) LEFT JOIN inv_jual J ON (J.No_Jual=D.No_Ref) LEFT JOIN inv_opname O ON (O.No_Opname=D.No_Ref) LEFT JOIN inv_mutasi M ON (M.No_Mutasi=D.No_Ref) LEFT JOIN para_supplier S ON (S.SupID=B.SupID) LEFT JOIN para_outlet T ON (T.OutletID=J.OutletID) LEFT JOIN para_nota N ON (D.NotaID=N.NotaID) WHERE (D.Tgl_Ref BETWEEN '".$tglfrom."' AND '".$tglto."')".$tsql." AND D.InvID='".$id_inv."' AND D.Stok<>0 GROUP BY D.No_Ref,D.InvID ORDER BY D.Tgl_Ref,N.Urut,D.No_Ref".$tord);
|
|
}
|
|
|
|
if ( $data == "print" ) {
|
|
Report_Header("LAPORAN MUTASI STOK PRODUK", $tglheader);
|
|
$pre = new PrintHTML();
|
|
$pre->set_css("garis");
|
|
|
|
echo "Nama Produk : ".$aproduk['Nama_Produk']."<br>";
|
|
if ($id_gudang>0) echo "Nama Gudang : ".$agudang['Nama_Gudang']."<br>";
|
|
|
|
$pre->add_field("TANGGAL",20,"C");
|
|
$pre->add_field("NO. NOTA",20);
|
|
$pre->add_field("NO. FAKTUR",100);
|
|
$pre->add_field("NAMA SUPPLIER / OUTLET",300);
|
|
$pre->add_field("MASUK",160,"R");
|
|
$pre->add_field("KELUAR",160,"R");
|
|
$pre->add_field("STOK",160,"R");
|
|
$pre->show_fields();
|
|
|
|
$tot_m = 0; $tot_k = 0;
|
|
$pre->add_span(array("STOK AWAL",4,"R"),array("",1,"R"),array("",1,"R"),array(Format_Stok($stok,$ainfo['Kali'],$ainfo['Satuan_Normal'],$ainfo['Satuan_Stok']),1,"R"));
|
|
while ($db->Next()) {
|
|
$msk = $db->Row("Masuk");
|
|
$klr = $db->Row("Keluar");
|
|
$stok += $msk - $klr;
|
|
$tot_m += $msk;
|
|
$tot_k += $klr;
|
|
$pre->add_value($db->Row("Tgl_Ref2"), $db->Row("No_Ref"), (($jenis==1)?$db->Row("No_Faktur"):$db->Row("No_Pajak")), $db->Row("Nama"), (($msk>0)?Format_Stok($msk,$ainfo['Kali'],$ainfo['Satuan_Normal'],$ainfo['Satuan_Stok']):""), (($klr>0)?Format_Stok($klr,$ainfo['Kali'],$ainfo['Satuan_Normal'],$ainfo['Satuan_Stok']):""), Format_Stok($stok,$ainfo['Kali'],$ainfo['Satuan_Normal'],$ainfo['Satuan_Stok']));
|
|
}
|
|
$pre->add_span(array("STOK AKHIR",4,"R"),array(Format_Stok($tot_m,$ainfo['Kali'],$ainfo['Satuan_Normal'],$ainfo['Satuan_Stok']),1,"R"),array(Format_Stok($tot_k,$ainfo['Kali'],$ainfo['Satuan_Normal'],$ainfo['Satuan_Stok']),1,"R"),array(Format_Stok($stok,$ainfo['Kali'],$ainfo['Satuan_Normal'],$ainfo['Satuan_Stok']),1,"R"));
|
|
$pre->add_stamp(0, true);
|
|
$pre->show();
|
|
|
|
} else if ( $data == "export" ) {
|
|
$xls = new SimpleXLS([
|
|
'title'=>"Laporan Mutasi Stok Produk",
|
|
'subject'=>"PT.PMS",
|
|
'desc'=>"Export Data dari IAS"
|
|
]);
|
|
$xls->add_header("<b>".strtoupper($_SESSION['__WEB_APP']['REG_NAME'])."</b>");
|
|
$xls->add_header("<b>LAPORAN MUTASI STOK PRODUK</b>");
|
|
$xls->add_header($aproduk['Nama_Produk']);
|
|
$xls->add_header($tglheader);
|
|
|
|
$xls->add_field("TANGGAL", 12, "C");
|
|
$xls->add_field("NO. NOTA", 14, "L");
|
|
$xls->add_field("NO. FAKTUR", 14, "L");
|
|
$xls->add_field("NAMA SUPPLIER / OUTLET", 60, "L");
|
|
$xls->add_field("MASUK", 20, "R");
|
|
$xls->add_field("KELUAR", 20, "R");
|
|
$xls->add_field("STOK", 20, "R");
|
|
$xls->add_sheet("MUTASI STOK", false);
|
|
|
|
if ($id_gudang>0) $xls->add_span(["Nama Gudang",3,"L"],[$agudang['Nama_Gudang'],4]);
|
|
$xls->show_headers();
|
|
|
|
$tot_m = 0; $tot_k = 0;
|
|
$xls->add_span(["STOK AWAL",4,"R,B"],["",1,"R,B"],["",1,"R,B"],[Format_Stok($stok,$ainfo['Kali'],$ainfo['Satuan_Normal'],$ainfo['Satuan_Stok']),1,"R,B"]);
|
|
while ($db->Next()) {
|
|
$msk = $db->Row("Masuk");
|
|
$klr = $db->Row("Keluar");
|
|
$stok += $msk - $klr;
|
|
$tot_m += $msk;
|
|
$tot_k += $klr;
|
|
$xls->add_value($db->Row("Tgl_Ref2"), $db->Row("No_Ref"), (($jenis==1)?$db->Row("No_Faktur"):$db->Row("No_Pajak")), $db->Row("Nama"), (($msk>0)?Format_Stok($msk,$ainfo['Kali'],$ainfo['Satuan_Normal'],$ainfo['Satuan_Stok']):""), (($klr>0)?Format_Stok($klr,$ainfo['Kali'],$ainfo['Satuan_Normal'],$ainfo['Satuan_Stok']):""), Format_Stok($stok,$ainfo['Kali'],$ainfo['Satuan_Normal'],$ainfo['Satuan_Stok']));
|
|
}
|
|
$xls->add_span(array("STOK AKHIR",4,"R,B"),array(Format_Stok($tot_m,$ainfo['Kali'],$ainfo['Satuan_Normal'],$ainfo['Satuan_Stok']),1,"R,B"),array(Format_Stok($tot_k,$ainfo['Kali'],$ainfo['Satuan_Normal'],$ainfo['Satuan_Stok']),1,"R,B"),array(Format_Stok($stok,$ainfo['Kali'],$ainfo['Satuan_Normal'],$ainfo['Satuan_Stok']),1,"R,B"));
|
|
$xls->add_stamp(1, true);
|
|
$xls->send("Laporan Mutasi Stok Produk.xlsx");
|
|
unset($xls);
|
|
|
|
} else if ( $data == "default") {
|
|
$form = new Form($db);
|
|
$ttipe = $form->radio("_", "Tipe_Data", "X", true, false, ["X"=>"Semua","B"=>"Pembelian","J"=>"Penjualan"]);
|
|
$tnota = $form->radio("_", "Nota_Pajak", 1, true, false, [1=>"Nota Jual",2=>"Faktur Pajak"]);
|
|
$tgudang = $form->option_db("_", "GudangID", 0, true, false, "para_gudang", ["GudangID","Nama_Gudang"], "TRUE ORDER BY Nama_Gudang", [0,"SEMUA GUDANG"]);
|
|
$tproduk = $form->option_db("_", "InvID", 0, true, false, "inv_produk", ["InvID","Nama_Produk"], "TRUE ORDER BY Nama_Produk");
|
|
$ttglfrom = $form->datebox("_", "Tgl_From", tgl_ymd(), true, false);
|
|
$ttglto = $form->datebox("_", "Tgl_To", tgl_ymd(), true, false);
|
|
echo '
|
|
<div class="row mb-1">
|
|
<label class="col-sm-5 col-lg-3 col-form-label" for="Tipe_Data">Jenis Transaksi</label>
|
|
<div class="col">'.$ttipe.'</div>
|
|
</div>
|
|
<div class="row mb-1">
|
|
<label class="col-sm-5 col-lg-3 col-form-label" for="Nota_Pajak">Jenis Informasi</label>
|
|
<div class="col">'.$tnota.'</div>
|
|
</div>
|
|
<div class="row mb-1">
|
|
<label class="col-sm-5 col-lg-3 col-form-label" for="GudangID">Nama Gudang</label>
|
|
<div class="col">'.$tgud.'</div>
|
|
</div>
|
|
<div class="row mb-1">
|
|
<label class="col-sm-5 col-lg-3 col-form-label" for="InvID">Nama Produk</label>
|
|
<div class="col">'.$tproduk.'</div>
|
|
</div>
|
|
<div class="row mb-1"><div class="col"><hr class="my-1"></div></div>
|
|
<div class="row mb-1">
|
|
<label class="col-sm-5 col-lg-3 col-form-label" for="Tgl_From">Dari Tanggal</label>
|
|
<div class="col">'.$ttglfrom.'</div>
|
|
</div>
|
|
<div class="row mb-1">
|
|
<label class="col-sm-5 col-lg-3 col-form-label" for="Tgl_To">Sampai Tanggal</label>
|
|
<div class="col">'.$ttglto.'</div>
|
|
</div>';
|
|
|
|
}
|
|
|
|
?>
|