0) { $db->Query("SELECT Nama_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_sup>0) ? " AND SupID='".$id_sup."'" : ""; // query data laporan if ($tipe=="R") { $db->Query("SELECT B.*,S.Nama_Sup FROM (SELECT SupID,SUM(Total_Hutang) Total_Hutang,SUM(Total_Bayar+Total_Potong) Total_Bayar FROM inv_beli WHERE Lunas=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.*,CONCAT(S.Nama_Sup,IF(B.Data_Beli=1,'',' (Retur)')) Nama_Sup,B.Total_Hutang Total_Hutang,B.Total_Bayar+B.Total_Potong Total_Bayar FROM (SELECT * FROM inv_beli WHERE Lunas=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")." HUTANG SUPPLIER", "Periode : ".$tglheader); $pre = new \siaupheng\fonia3\Printer\PrintHTML(); if ($tipe=="R") { $pre->add_field("No.",10,"C"); $pre->add_field("Nama Supplier",120,"L"); $pre->add_field("Jumlah Faktur",50,"R","rupiah2"); $pre->add_field("Jumlah Bayar",50,"R","rupiah2"); $pre->add_field("Sisa Hutang",50,"R","rupiah2"); if ($id_sup>0) $pre->add_span(array("Nama Supplier : ".$nama_sup,5,"L,B")); $tot_hut = 0; $tot_bayar = 0; $nomor = 0; while ($db->Next()) { $tot_hut += $db->Row("Total_Hutang"); $tot_bayar += $db->Row("Total_Bayar"); $pre->add_value(++$nomor, $db->Row("Nama_Sup"), $db->Row("Total_Hutang"), $db->Row("Total_Bayar"), $db->Row("Total_Hutang")-$db->Row("Total_Bayar")); } $pre->add_span(array("GRAND TOTAL",2,"R,B"),array($tot_hut,1,"R,B","rupiah2"),array($tot_bayar,1,"R,B","rupiah2"),array($tot_hut-$tot_bayar,1,"R,B","rupiah2")); } else { $pre->add_field("No. Nota",10,"C"); $pre->add_field("Tgl. Nota",10,"C","sqltgl"); $pre->add_field("Nama Supplier",120,"L"); $pre->add_field("Jumlah",50,"R","rupiah2"); $pre->add_field("Bayar",50,"R","rupiah2"); $pre->add_field("Sisa Hutang",50,"R","rupiah2"); if ($id_sup>0) $pre->add_span(array("Nama Supplier : ".$nama_sup,6,"L,B")); $tot_hut = 0; $tot_bayar = 0; while ($db->Next()) { $tot_hut += $db->Row("Total_Hutang"); $tot_bayar += $db->Row("Total_Bayar"); $pre->add_value($db->Row("No_Beli"), $db->Row("Tgl_Beli"), $db->Row("Nama_Sup"), $db->Row("Total_Hutang"), $db->Row("Total_Bayar"), $db->Row("Total_Hutang")-$db->Row("Total_Bayar")); } $pre->add_span(array("GRAND TOTAL",3,"R,B"),array($tot_hut,1,"R,B","rupiah2"),array($tot_bayar,1,"R,B","rupiah2"),array($tot_hut-$tot_bayar,1,"R,B","rupiah2")); } $pre->add_stamp(1, true); $pre->show(); } else if ( $data == "export" ) { $xls = new SimpleXLS([ 'title'=>"Data Hutang Supplier", 'desc'=>"Export Data Hutang Supplier" ]); if ($tipe=="R") { $xls->add_header($_SESSION['__WEB_APP']['REG_NAME']); $xls->add_header("DATA REKAP HUTANG SUPPLIER"); $xls->add_header("Periode : ".$tglheader); $xls->add_field("No.", 10, "C"); $xls->add_field("Nama Supplier", 80, "L"); $xls->add_field("Jumlah Faktur", 20, "R,N"); $xls->add_field("Jumlah Bayar", 20, "R,N"); $xls->add_field("Sisa Hutang", 20, "R,N"); $xls->add_sheet("".str_replace("S/D","-",$tglheader), true); if ($id_sup>0) $xls->add_span(["Nama Supplier : ".$nama_sup,5,"L"]); $tot_hut = 0; $tot_bayar = 0; $nomor = 0; while ($db->Next()) { $tot_hut += $db->Row("Total_Hutang"); $tot_bayar += $db->Row("Total_Bayar"); $xls->add_value(++$nomor, $db->Row("Nama_Sup"), $db->Row("Total_Hutang"), $db->Row("Total_Bayar"), $db->Row("Total_Hutang")-$db->Row("Total_Bayar")); } $xls->add_span(array("GRAND TOTAL",2,"R,B"),array($tot_hut,1,"R,B,N"),array($tot_bayar,1,"R,B,N"),array($tot_hut-$tot_bayar,1,"R,B,N")); } else { $xls->add_header($_SESSION['__WEB_APP']['REG_NAME']); $xls->add_header("DATA DETAIL HUTANG SUPPLIER"); $xls->add_header("Periode : ".$tglheader); $xls->add_field("No. Nota", 10, "C"); $xls->add_field("Tgl. Nota", 10, "C", "sqltgl"); $xls->add_field("Nama Supplier", 80, "L"); $xls->add_field("Jumlah", 20, "R,N"); $xls->add_field("Bayar", 20, "R,N"); $xls->add_field("Sisa Hutang", 20, "R,N"); $xls->add_sheet("".str_replace("S/D","-",$tglheader), true); if ($id_sup>0) $xls->add_span(["Nama Supplier : ".$nama_sup,6,"L"]); $tot_hut = 0; $tot_bayar = 0; while ($db->Next()) { $tot_hut += $db->Row("Total_Hutang"); $tot_bayar += $db->Row("Total_Bayar"); $xls->add_value($db->Row("No_Beli"), $db->Row("Tgl_Beli"), $db->Row("Nama_Sup"), $db->Row("Total_Hutang"), $db->Row("Total_Bayar"), $db->Row("Total_Hutang")-$db->Row("Total_Bayar")); } $xls->add_span(array("GRAND TOTAL",3,"R,B"),array($tot_hut,1,"R,B,N"),array($tot_bayar,1,"R,B,N"),array($tot_hut-$tot_bayar,1,"R,B,N")); } $xls->add_stamp(1, true); $xls->send("Data Hutang Supplier ".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 '