Advertisement
cdsatrian

per kelas

Jun 4th, 2014
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.14 KB | None | 0 0
  1. <?php
  2. session_start();
  3. define('FPDF_FONTPATH', 'fpdf/font/');
  4. include "../../conn.php";
  5. include "fpdf/fpdf.php";
  6. $semes = mysql_query("SELECT kode, ket_smstr FROM semester where aktif='aktif'");
  7. $sm = mysql_fetch_array($semes);
  8. $status = $sm['ket_smstr'];
  9. //mencaritahu gasal atau genap
  10. $s      = explode(" ", $status);
  11. $g      = $s[0]; //kalo di echo hasilnya genap/gasal
  12. $bulangasal = array("juli","agustus","september","oktober","nopember","desember");
  13. $index_bln_gasal = array("juli"=>"07","agustus"=>"08","september"=>"09","oktober"=>"10","nopember"=>"11","desember"=>"12");
  14. $bulangenap = array("januari","februari","maret","april","mei","juni");
  15. $index_bln_genap = array("januari"=>"01","februari"=>"02","maret"=>"03","april"=>"04","mei"=>"05","juni"=>"06");
  16. $bulan=$g == 'Gasal'? $bulangasal:$bulangenap;
  17. $index_bln=$g == 'Gasal'? $index_bln_gasal:$index_bln_genap;
  18. class PDF extends FPDF
  19. {
  20.   function Header()
  21.   {
  22.     global $status;
  23.     $this->Image('/home/wiyr1282/public_html/images/logo.jpg',7,1.5,2.5);
  24.     $this->SetFont('Times','B','10');
  25.     $this->Cell(27.5,0.5,'LAPORAN KEUANGAN',0,0,'C');
  26.     $this->Ln();
  27.     $this->SetFont('Times','B','11');
  28.     $this->Cell(27.5,0.5,'SMK PALEBON SEMARANG',0,0,'C');
  29.     $this->Ln();
  30.     $this->Cell(27.5,0.5,'Jalan Palebon Raya No. 30 Pedurungan Semarang (50199)',0,0,'C');
  31.     $this->SetFont('Times','B','10');
  32.     $this->Ln();
  33.     $this->Cell(27.5,0.5,'Semester '.$status,0,0,'C');
  34.     $this->Line(3,4.3,27.5,4.3);
  35.     $this->Line(3,4.4,27.5,4.4);
  36.     $this->Ln();
  37.   }
  38.   public function Footer()
  39.   {  
  40.     $this->SetY(-2,5);
  41.     $this->SetFont('Times','','6');
  42.     $this->Cell(5,0.5,'di cetak oleh '.$_SESSION['login_name'].'  jam:'.date ("H:i:s"),0,false,'C',0,'',0,false,'T','M');
  43.   }
  44. }
  45. $pdf = new PDF('L','cm','a4');
  46. $pdf->SetMargins('2.7','2','2.7');
  47. foreach ($_POST['kelas'] as $kelas)
  48. {
  49.   $no=1;
  50.   //mendapatkan kelas
  51.   $kk = mysql_query("SELECT kelas, jurusan, sub_kelas FROM kelas WHERE id_kelas='$kelas'")or die(mysql_error());
  52.   $k  = mysql_fetch_array($kk);
  53.   //mendapatkan tarif perbulan
  54.   $t = mysql_fetch_array(mysql_query("SELECT tarif FROM tarif WHERE id_kelas='".$kelas."'"));
  55.   $pdf->AddPage();
  56.   $pdf->Ln();
  57.   $pdf->Ln();
  58.   $pdf->SetFont('Times','B','11');
  59.   $pdf->Cell(1.5,0.5,'Kelas',0,0,'L');
  60.   $pdf->Cell(0.5,0.5,':',0,0,'C');
  61.   $pdf->Cell(5,0.5,$k['kelas']." ".$k['jurusan']." ".$k['sub_kelas'],0,1,'L');
  62.   $pdf->Cell(2.5,0.5,'Biaya Perbulan',0,0,'L');
  63.   $pdf->Cell(0.5,0.5,':',0,0,'C');
  64.   $pdf->Cell(5,0.5,$t['tarif'],0,1,'L');
  65.   $pdf->Ln();
  66.   //header
  67.   $pdf->Cell(1,0.5,'No.',1,0,'C');
  68.   $pdf->Cell(2,0.5,'NIS',1,0,'C');
  69.   $pdf->Cell(3.5,0.5,'Nama',1,0,'C');
  70.   for($n=0; $n<=5; $n++){
  71.     $pdf->Cell(3,0.5,ucfirst($bulan[$n]),1,0,'C');
  72.   }
  73.   $pdf->Cell(3,0.5,'',0,1,'C');
  74.   $pdf->SetFont('Times','','11');
  75.   $ss = mysql_query("SELECT * FROM student WHERE id_kelas='$kelas' ORDER BY nis ASC");
  76.   $sum=array();
  77.   foreach($bulan as $val)
  78.     $sum[$val]=0;
  79.   while($s=mysql_fetch_array($ss))
  80.   {
  81.     //isi label
  82.     $masuk=mysql_query("SELECT * FROM keu_".$sm['kode']." WHERE nis='".$s['nis']."'");
  83.     if(mysql_num_rows($masuk) < '1')
  84.     {
  85.       //th tabel
  86.       $pdf->Cell(1,0.5,$no,1,0,'C');
  87.       $pdf->Cell(2,0.5,$s['nis'],1,0,'C');
  88.       $pdf->Cell(3.5,0.5,$s['nama'],1,0,'C');
  89.       $pdf->Cell(18,0.5,'Belum ada data pembayaran SPP',1,1,'C');
  90.     }
  91.     else
  92.     {
  93.       while($m=mysql_fetch_array($masuk))
  94.       {
  95.         //th tabel
  96.         $pdf->Cell(1,0.5,$no,1,0,'C');
  97.         $pdf->Cell(2,0.5,$s['nis'],1,0,'C');
  98.         $pdf->Cell(3.5,0.5,$s['nama'],1,0,'C');
  99.         $month_value = array();
  100.         foreach($bulan as $val)
  101.           $month_value[$val] = $m[$val];    
  102.         $output = array();
  103.         foreach ($month_value as $key => $value)
  104.         {
  105.           if($value != null)
  106.           {
  107.             $bln = date("m",strtotime($value));
  108.             if(isset($output[$bln]))
  109.               $output[$bln][$index_bln[$key]] = $key;
  110.             else
  111.               $output[$bln] = array($index_bln[$key]=>$key);
  112.           }
  113.           else
  114.             $month_value[$key] = "-";
  115.         }
  116.         //idxs mencari bulan yang membayar dalam satu semester
  117.         foreach($output as $bln)
  118.           if(is_array($bln))
  119.             foreach($bln as $idx => $val)
  120.               $idxs[] = $idx ;
  121.         $total=array();
  122.         foreach($index_bln as $bln => $idx)
  123.         {
  124.           $total[$bln] = 0;
  125.           if(array_key_exists($idx,$output))
  126.           {
  127.             foreach($output[$idx] as $nmbulan)
  128.               $total[$bln]+=$t['tarif'];
  129.             $pdf->Cell(3,0.5,$total[$bln],1,0,'C');
  130.           }
  131.           else
  132.           {
  133.             // bandingkan ke bulan membayar.
  134.             if(in_array($idx,$idxs))
  135.               $pdf->Cell(3,0.5,$total[$bln],1,0,'C');
  136.             else
  137.               $pdf->Cell(3,0.5,"-",1,0,'C');
  138.           }
  139.           $sum[$bln]+=$total[$bln];
  140.         }
  141.         $pdf->Cell(3,0.5,'',0,1,'C');
  142.       }
  143.     }
  144.     $no++;
  145.   }
  146.   //total
  147.   $pdf->Cell(3,0.5,'TOTAL',0,0,'C');
  148.   foreach($bulan as $val)
  149.   {
  150.     $pdf->Cell(3,0.5,$sum[$val],0,1,'C');
  151.   }
  152. }
  153. $pdf->Output("Laporan keuangan.pdf","I");
  154. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement