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); $tsql = ($id_cab==0) ? "" : " AND CabID='".$id_cab."'"; $tsql .= ($id_sup==0) ? "" : " AND SupID='".$id_sup."'"; //id_grup ? if ($tipe=="R") { $db->Query("SELECT S.Nama_Sup,SUM(B.Total_Hutang+B.Total_Diskon+B.Total_Bulat) Total_Beli,SUM(B.Total_Diskon+B.Total_Bulat) Total_Diskon,SUM(B.Total_Hutang) Total FROM (SELECT * FROM inv_beli WHERE Data_Beli=1 AND (Tgl_Beli BETWEEN '".$tglfrom."' AND '".$tglto."')".$tsql.") B LEFT JOIN para_supplier S ON (B.SupID=S.SupID) GROUP BY B.SupID ORDER BY S.Nama_Sup"); } else { $db->Query("SELECT B.*,DATE_FORMAT(B.Tgl_Beli,'%d-%m-%Y') Tgl_Beli2,S.Nama_Sup,B.Total_Beli-B.Total_Diskon Total FROM (SELECT * FROM inv_beli WHERE Data_Beli=1 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")." 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("Sub. Total",20,"R","rupiah"); $pre->add_field("Diskon",20,"R","rupiah"); $pre->add_field("Total",20,"R","rupiah"); if ($id_sup>0) $pre->add_span(array("Nama Supplier : ".$nama_sup,5,"L,B")); if ($id_grup>0) $pre->add_span(array("Grup Barang : ".$nama_grup,5,"L,B")); $tot_beli = 0; $tot_diskon = 0; $nomor = 0; while ($db->Next()) { //if ($db->RowFloat("Total", 0) == 0) continue; $tot_beli += $db->Row("Total_Beli"); $tot_diskon += $db->Row("Total_Diskon"); $pre->add_value(++$nomor, $db->Row("Nama_Sup"), $db->Row("Total_Beli"), $db->Row("Total_Diskon"), $db->Row("Total")); } $pre->add_span(array("GRAND TOTAL",2,"R,B"),array($tot_beli,1,"R,B","rupiah"),array($tot_diskon,1,"R,B","rupiah"),array($tot_beli-$tot_diskon,1,"R,B","rupiah")); } else { $pre->add_field("No. Nota",30,"C"); $pre->add_field("Tgl. Nota",30,"C", "tgl_sql2str"); $pre->add_field("No. Faktur",30,"L"); $pre->add_field("Nama Supplier",50,"L"); $pre->add_field("Sub. Total",20,"R","rupiah"); $pre->add_field("Diskon",20,"R","rupiah"); $pre->add_field("Total",30,"R","rupiah"); if ($id_sup>0) $pre->add_span(array("Nama Supplier : ".$nama_sup,7,"L,B")); if ($id_grup>0) $pre->add_span(array("Grup Barang : ".$nama_grup,7,"L,B")); $tot_beli = 0; $tot_diskon = 0; while ($db->Next()) { //if ($db->RowFloat("Total", 0) == 0) continue; $tot_beli += $db->Row("Total_Beli"); $tot_diskon += $db->Row("Total_Diskon"); $pre->add_value($db->Row("No_Beli"), $db->Row("Tgl_Beli"), $db->Row("No_Faktur"), $db->Row("Nama_Sup"), $db->Row("Total_Beli"), $db->Row("Total_Diskon"), $db->Row("Total")); } $pre->add_span(array("GRAND TOTAL",4,"R,B"),array($tot_beli,1,"R,B","rupiah"),array($tot_diskon,1,"R,B","rupiah"),array($tot_beli-$tot_diskon,1,"R,B","rupiah")); } $pre->add_stamp(1, true); $pre->show(); } else if ( $data == "export" ) { $xls = new SimpleXLS([ 'title'=>"Data Pembelian", 'desc'=>"Export Data Pembelian" ]); if ($tipe=="R") { $xls->add_header("".$_SESSION['__WEB_APP']['REG_NAME'].""); $xls->add_header("DATA REKAP PEMBELIAN"); $xls->add_header("Periode : ".$tglheader); $xls->add_field("No.", 5, "C"); $xls->add_field("Nama Supplier", 25, "L"); $xls->add_field("Sub. Total", 15, "R,N"); $xls->add_field("Diskon", 15, "R,N"); $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,5,"L,B")); if ($id_grup>0) $xls->add_span(array("Grup Barang : ".$nama_grup,5,"L,B")); $tot_beli = 0; $tot_diskon = 0; $nomor = 0; while ($db->Next()) { if ($db->RowFloat("Total", 0) == 0) continue; $tot_beli += $db->Row("Total_Beli"); $tot_diskon += $db->Row("Total_Diskon"); $xls->add_value(++$nomor, $db->Row("Nama_Sup"), $db->Row("Total_Beli"), $db->Row("Total_Diskon"), $db->Row("Total")); } $xls->add_span(array("GRAND TOTAL",2,"R,B"),array($tot_beli,1,"R,B,N"),array($tot_diskon,1,"R,B,N"),array($tot_beli-$tot_diskon,1,"R,B,N")); } else { $xls->add_header("".$_SESSION['__WEB_APP']['REG_NAME'].""); $xls->add_header("DATA DETAIL PEMBELIAN"); $xls->add_header("Periode : ".$tglheader); $xls->add_field("No. Nota", 15, "C"); $xls->add_field("Tgl. Nota", 12, "C", "tgl_sql2str"); $xls->add_field("No. Faktur", 15, "L"); $xls->add_field("Nama Supplier", 20, "L"); $xls->add_field("Sub. Total", 15, "R,N"); $xls->add_field("Diskon", 15, "R,N"); $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,7,"L,B")); if ($id_grup>0) $xls->add_span(array("Grup Barang : ".$nama_grup,7,"L,B")); $tot_beli = 0; $tot_diskon = 0; while ($db->Next()) { if ($db->RowFloat("Total", 0) == 0) continue; $tot_beli += $db->Row("Total_Beli"); $tot_diskon += $db->Row("Total_Diskon"); $xls->add_value($db->Row("No_Beli"), $db->Row("Tgl_Beli"), $db->Row("No_Faktur"), $db->Row("Nama_Sup"), $db->Row("Total_Beli"), $db->Row("Total_Diskon"), $db->Row("Total")); } $xls->add_span(array("GRAND TOTAL",4,"R,B"),array($tot_beli,1,"R,B,N"),array($tot_diskon,1,"R,B,N"),array($tot_beli-$tot_diskon,1,"R,B,N")); } $xls->add_stamp(1, true); $xls->send("Data 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"]); $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 '