membuat laporan fpdf berdasarkan tanggal yang dipilih

permisi bang disini saya ingin menanyakan pembuatan laporan fpdf berdasarkan tanggal yang dipilih. sebelumnya saya sudah membuat laporan keseluruhan tapi yang saya bingung gimana membuat laporan fpdf berdasarkan tanggal yang saya pilih karena ketika membuat laporan berdasarkan tanggal yang dipilih otomatis total harga dan total pendapatan seharusnya juga mengikuti tanggal yang dipilih

jadi ketika kita sudah mencari tanggal yang dipilih, ketika cetak laporan hasilnya sesuai sama yang kita cari tadi

sourcode tanggal.php

</head>
<body>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
		<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
		<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
	 	<script>
	  		$( function() {
	    		$( "#datepicker" ).datepicker({ dateFormat: 'yy-mm-dd' });
	    		$( "#datepicker2" ).datepicker({ dateFormat: 'yy-mm-dd' });
	  		} );
	  	</script>
  <center>
  <form action="" method="post">
  <center><p>Dari: <input type="text" id="datepicker" name="tgl1">
  Sampai: <input type="text" id="datepicker2" name="tgl2">
  <input type="submit" value="cari" name="cari"></p></center>
  </form>
  <table border="5" width="1000">
    <tr><td>Kode Penjualan</td><td>Tanggal Penjualan</td>
    <td>Nama Barang</td><td>Customer</td>
    <td>Jumlah</td><td>Harga</td><td>Total Harga</td><td>Keuntungan</td>
    </tr>
<?php
  include "config.php";
  if(isset($_POST['cari'])) {
    $tgl1=$_POST['tgl1'];
    $tgl2=$_POST['tgl2'];
    $query = "SELECT * FROM barang_laku WHERE tanggal BETWEEN '$tgl1' AND '$tgl2'";
  } else {
    $query = "SELECT * FROM barang_laku";
  }
  $result = mysqli_query($connect, $query);
  $pendapatan = 0;
  $laba = 0;
  if(!mysqli_num_rows($result)) {
    echo "<tr><td colspan='7'>Data Tidak ada untuk tanggal ini.</td></tr>";
  } else {
    while($row = mysqli_fetch_array($result)) {
      $pendapatan += $row['total_harga'];
      $laba += $row['laba'];
      echo "<tr>
      <td>".$row['kode']."</td>
      <td>".$row['tanggal']."</td>
      <td>".$row['nama']."</td>
      <td>".$row['customer']."</td>
      <td>".$row['jumlah']."</td>
      <td>Rp. ".$row['harga']."</td>
	  <td>Rp. ".$row['total_harga']."</td>
      <td>Rp. ".$row['laba']."</td>
      </tr>";
    }
    mysqli_free_result($result);
  }
?>
  </table>
<br>
Total Pendapatan: Rp. <?php echo number_format($pendapatan); ?>,-<br>
Total Keuntungan: Rp. <?php echo number_format($laba); ?>,-<br>
</center>
</body>
<a class="btn" href="tanggal.php"><span class="glyphicon glyphicon-arrow-left"></span>  Kembali</a> | |
	<a style="margin-bottom:10px" href="lap_penjualan_tgl.php" target="_blank" class="btn btn-default pull-right"><span class='glyphicon glyphicon-print'></span>  Cetak Laporan</a><br>

</html>

sourcode laporan keseluruhan fpdf

<?php

include 'config.php';
require('../assets/pdf/fpdf.php');

$pdf = new FPDF("L","cm","A4");

$pdf->SetMargins(2,1,1);
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','B',13);
$pdf->Image('https://siva.jsstatic.com/id/4793/images/logo/4793_logo_0.jpg',1,1,2,2);
$pdf->SetX(4);
$pdf->MultiCell(19.5,0.5,'PT GOLD COIN',0,'L');
$pdf->SetX(4);
$pdf->MultiCell(19.5,0.5,'',0,'L');
$pdf->SetFont('Arial','B',10);
$pdf->SetX(4);
$pdf->MultiCell(19.5,0.5,'Jl. Sultan Agung No.31, Medan Satria, Kota Bekasi, Jawa Barat 17132',0,'L');
$pdf->SetX(4);
$pdf->MultiCell(19.5,0.5,'Website : http://www.goldcoin-group.com/',0,'L');
$pdf->Line(1,3.1,28.5,3.1);
$pdf->SetLineWidth(0.1);
$pdf->Line(1,3.2,28.5,3.2);
$pdf->SetLineWidth(0);
$pdf->ln(1);
$pdf->SetFont('Arial','B',14);
$pdf->Cell(0,0.7,'Laporan Data Penjualan Barang',0,0,'C');
$pdf->ln(1);
$pdf->SetFont('Arial','B',10);
$pdf->Cell(5,0.7,"Di cetak pada : ".date("D-d/m/Y"),0,0,'C');
$pdf->ln(1);
$pdf->Cell(6,0.7,"Laporan Penjualan pada : ",0,0,'C');
$pdf->ln(1);
$pdf->Cell(1, 0.8, 'NO', 1, 0, 'C');
$pdf->Cell(3, 0.8, 'Kode Penjualan', 1, 0, 'C');
$pdf->Cell(3, 0.8, 'Tanggal', 1, 0, 'C');
$pdf->Cell(6, 0.8, 'Nama Barang', 1, 0, 'C');
$pdf->Cell(3, 0.8, 'Customer', 1, 0, 'C');
$pdf->Cell(2, 0.8, 'Jumlah', 1, 0, 'C');
$pdf->Cell(3, 0.8, 'harga', 1, 0, 'C');
$pdf->Cell(3, 0.8, 'Total harga', 1, 0, 'C');
$pdf->Cell(3, 0.8, 'Keuntungan', 1, 1, 'C');

$no=1;
$query=mysqli_query($connect,"select * from barang_laku");
while($lihat=mysqli_fetch_array($query)){
	$pdf->Cell(1, 0.8, $no , 1, 0, 'C');
	$pdf->Cell(3, 0.8, $lihat['kode'],1, 0, 'C');
	$pdf->Cell(3, 0.8, $lihat['tanggal'],1, 0, 'C');
	$pdf->Cell(6, 0.8, $lihat['nama'],1, 0, 'C');
	$pdf->Cell(3, 0.8, $lihat['customer'], 1, 0,'C');
	$pdf->Cell(2, 0.8, $lihat['jumlah'], 1, 0,'C');
	$pdf->Cell(3, 0.8, "Rp. ".number_format($lihat['harga'])." ,-", 1, 0,'C');
	$pdf->Cell(3, 0.8, "Rp. ".number_format($lihat['total_harga'])." ,-",1, 0, 'C');
	$pdf->Cell(3, 0.8, "Rp. ".number_format($lihat['laba'])." ,-", 1, 1,'C');

	$no++;
}
$q=mysqli_query($connect,"select sum(total_harga) as total from barang_laku");
// select sum(total_harga) as total from barang_laku where tanggal='$tanggal'
while($total=mysqli_fetch_array($q)){
	$pdf->Cell(21, 0.8, "Total Pendapatan", 1, 0,'C');
	$pdf->Cell(3, 0.8, "Rp. ".number_format($total['total'])." ,-", 1, 0,'C');
}
$qu=mysqli_query($connect,"select sum(laba) as total_laba from barang_laku");
// select sum(total_harga) as total from barang_laku where tanggal='$tanggal'
while($tl=mysqli_fetch_array($qu)){
	$pdf->Cell(3, 0.8, "Rp. ".number_format($tl['total_laba'])." ,-", 1, 1,'C');
}
$pdf->Output("laporan_buku.pdf","I");

?>

solusinya ya bang hehe

avatar ardharafano
@ardharafano

33 Kontribusi 3 Poin

Diperbarui 6 tahun yang lalu

1 Jawaban:

dicetak pdfnya kasih parameter lagi gan.

 <?php

include 'config.php';
require('../assets/pdf/fpdf.php');

$pdf = new FPDF("L","cm","A4");

$pdf->SetMargins(2,1,1);
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','B',13);
$pdf->Image('https://siva.jsstatic.com/id/4793/images/logo/4793_logo_0.jpg',1,1,2,2);
$pdf->SetX(4);
$pdf->MultiCell(19.5,0.5,'PT GOLD COIN',0,'L');
$pdf->SetX(4);
$pdf->MultiCell(19.5,0.5,'',0,'L');
$pdf->SetFont('Arial','B',10);
$pdf->SetX(4);
$pdf->MultiCell(19.5,0.5,'Jl. Sultan Agung No.31, Medan Satria, Kota Bekasi, Jawa Barat 17132',0,'L');
$pdf->SetX(4);
$pdf->MultiCell(19.5,0.5,'Website : http://www.goldcoin-group.com/',0,'L');
$pdf->Line(1,3.1,28.5,3.1);
$pdf->SetLineWidth(0.1);
$pdf->Line(1,3.2,28.5,3.2);
$pdf->SetLineWidth(0);
$pdf->ln(1);
$pdf->SetFont('Arial','B',14);
$pdf->Cell(0,0.7,'Laporan Data Penjualan Barang',0,0,'C');
$pdf->ln(1);
$pdf->SetFont('Arial','B',10);
$pdf->Cell(5,0.7,"Di cetak pada : ".date("D-d/m/Y"),0,0,'C');
$pdf->ln(1);
$pdf->Cell(6,0.7,"Laporan Penjualan pada : ",0,0,'C');
$pdf->ln(1);
$pdf->Cell(1, 0.8, 'NO', 1, 0, 'C');
$pdf->Cell(3, 0.8, 'Kode Penjualan', 1, 0, 'C');
$pdf->Cell(3, 0.8, 'Tanggal', 1, 0, 'C');
$pdf->Cell(6, 0.8, 'Nama Barang', 1, 0, 'C');
$pdf->Cell(3, 0.8, 'Customer', 1, 0, 'C');
$pdf->Cell(2, 0.8, 'Jumlah', 1, 0, 'C');
$pdf->Cell(3, 0.8, 'harga', 1, 0, 'C');
$pdf->Cell(3, 0.8, 'Total harga', 1, 0, 'C');
$pdf->Cell(3, 0.8, 'Keuntungan', 1, 1, 'C');

//ambil paramater tanggal GET/POST
$tglawal = $_POST['tglawal']; //penamaan disesuaikan
$tglakhir = $_POST['tglakhir']; //penamaan disesuaikan

$no=1;
$qy = "select * from barang_laku ";
if (isset($tglawal) and isset($tglakhir)) {
	$qy.=" where tanggal between '$tglawal' and '$tglakhir' "; //kolom disesuaikan
}
$query=mysqli_query($connect,$q);
while($lihat=mysqli_fetch_array($query)){
	$pdf->Cell(1, 0.8, $no , 1, 0, 'C');
	$pdf->Cell(3, 0.8, $lihat['kode'],1, 0, 'C');
	$pdf->Cell(3, 0.8, $lihat['tanggal'],1, 0, 'C');
	$pdf->Cell(6, 0.8, $lihat['nama'],1, 0, 'C');
	$pdf->Cell(3, 0.8, $lihat['customer'], 1, 0,'C');
	$pdf->Cell(2, 0.8, $lihat['jumlah'], 1, 0,'C');
	$pdf->Cell(3, 0.8, "Rp. ".number_format($lihat['harga'])." ,-", 1, 0,'C');
	$pdf->Cell(3, 0.8, "Rp. ".number_format($lihat['total_harga'])." ,-",1, 0, 'C');
	$pdf->Cell(3, 0.8, "Rp. ".number_format($lihat['laba'])." ,-", 1, 1,'C');

	$no++;
}

$qy = "select sum(total_harga) as total from barang_laku";
if (isset($tglawal) and isset($tglakhir)) {
	$qy.=" where tanggal between '$tglawal' and '$tglakhir' "; //kolom disesuaikan
}
$q=mysqli_query($connect,$qy);
// select sum(total_harga) as total from barang_laku where tanggal='$tanggal'
while($total=mysqli_fetch_array($q)){
	$pdf->Cell(21, 0.8, "Total Pendapatan", 1, 0,'C');
	$pdf->Cell(3, 0.8, "Rp. ".number_format($total['total'])." ,-", 1, 0,'C');
}

$qy = "select sum(laba) as total_laba from barang_laku";
if (isset($tglawal) and isset($tglakhir)) {
	$qy.=" where tanggal between '$tglawal' and '$tglakhir' "; //kolom disesuaikan
}
$qu=mysqli_query($connect,$qy);
// select sum(total_harga) as total from barang_laku where tanggal='$tanggal'
while($tl=mysqli_fetch_array($qu)){
	$pdf->Cell(3, 0.8, "Rp. ".number_format($tl['total_laba'])." ,-", 1, 1,'C');
}
$pdf->Output("laporan_buku.pdf","I");

 ?>
avatar dianarifr
@dianarifr

642 Kontribusi 316 Poin

Dipost 6 tahun yang lalu

Login untuk ikut Jawaban