emprit

rekap_perkelas

Jun 4th, 2014
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.37 KB | None | 0 0
  1. <?php
  2. session_start();
  3. include "../../conn.php";
  4. define('FPDF_FONTPATH', 'fpdf/font/');
  5. include "fpdf/fpdf.php";
  6.  
  7. $semes = mysql_query("SELECT kode, ket_smstr FROM semester where aktif='aktif'");
  8. $sm = mysql_fetch_array($semes);
  9. $status = $sm['ket_smstr'];
  10.  
  11. //mencaritahu gasal atau genap
  12. $s      = explode(" ", $status);
  13. $g      = $s[0]; //kalo di echo hasilnya genap/gasal
  14.  
  15. $bulangasal = array("juli","agustus","september","oktober","nopember","desember");
  16. $index_bln_gasal = array("juli"=>"07","agustus"=>"08","september"=>"09","oktober"=>"10","nopember"=>"11","desember"=>"12");
  17.    
  18. $bulangenap = array("januari","februari","maret","april","mei","juni");
  19. $index_bln_genap = array("januari"=>"01","februari"=>"02","maret"=>"03","april"=>"04","mei"=>"05","juni"=>"06");
  20.    
  21. class PDF extends FPDF
  22. {
  23.     function Header()
  24.     {
  25.         global $status;
  26.         $this->Image('/home/wiyr1282/public_html/images/logo.jpg',7,1.5,2.5);
  27.         $this->SetFont('Times','B','10');
  28.         $this->Cell(27.5,0.5,'LAPORAN KEUANGAN',0,0,'C');
  29.         $this->Ln();
  30.         $this->SetFont('Times','B','11');
  31.         $this->Cell(27.5,0.5,'SMK PALEBON SEMARANG',0,0,'C');
  32.         $this->Ln();
  33.         $this->Cell(27.5,0.5,'Jalan Palebon Raya No. 30 Pedurungan Semarang (50199)',0,0,'C');
  34.         $this->SetFont('Times','B','10');
  35.         $this->Ln();
  36.         $this->Cell(27.5,0.5,'Semester '.$status,0,0,'C');
  37.         $this->Line(3,4.3,27.5,4.3);
  38.         $this->Line(3,4.4,27.5,4.4);
  39.         $this->Ln();
  40.     }
  41.  
  42.     public function Footer()
  43.     {  
  44.         $this->SetY(-2,5);
  45.         $this->SetFont('Times','','6');
  46.         $this->Cell(5,0.5,'di cetak oleh '.$_SESSION['login_name'].'  jam:'.date ("H:i:s"),0,false,'C',0,'',0,false,'T','M');
  47.     }
  48. }
  49.  
  50. $pdf = new PDF('L','cm','a4');
  51. $pdf->SetMargins('2.7','2','2.7');
  52.  
  53.  
  54. foreach ($_POST['kelas'] as $kelas) {
  55. $no=1;
  56. //mendapatkan kelas
  57. $kk = mysql_query("SELECT kelas, jurusan, sub_kelas FROM kelas WHERE id_kelas='$kelas'")or die(mysql_error());
  58. $k  = mysql_fetch_array($kk);
  59. //mendapatkan tarif perbulan
  60. $t = mysql_fetch_array(mysql_query("SELECT tarif FROM tarif WHERE id_kelas='".$kelas."'"));
  61.    
  62. $pdf->AddPage();
  63. $pdf->Ln();
  64. $pdf->Ln();
  65. $pdf->SetFont('Times','B','11');
  66.  
  67.     $pdf->Cell(1.5,0.5,'Kelas',0,0,'L');
  68.     $pdf->Cell(0.5,0.5,':',0,0,'C');
  69.     $pdf->Cell(5,0.5,$k['kelas']." ".$k['jurusan']." ".$k['sub_kelas'],0,1,'L');
  70.     $pdf->Cell(2.5,0.5,'Biaya Perbulan',0,0,'L');
  71.     $pdf->Cell(0.5,0.5,':',0,0,'C');
  72.     $pdf->Cell(5,0.5,$t['tarif'],0,1,'L');
  73.    
  74. $pdf->Ln();
  75.  
  76.     //header
  77.     $pdf->Cell(1,0.5,'No.',1,0,'C');
  78.     $pdf->Cell(2,0.5,'NIS',1,0,'C');
  79.     $pdf->Cell(3.5,0.5,'Nama',1,0,'C');
  80.     if($g == 'Gasal'){
  81.  
  82.         for($n=0; $n<=5; $n++){
  83.             $pdf->Cell(3,0.5,ucfirst($bulangasal[$n]),1,0,'C');
  84.         }
  85.         $pdf->Cell(3,0.5,'',0,1,'C');
  86.  
  87.     }elseif ($g == 'Genap'){
  88.  
  89.         for($n=0; $n<=5; $n++){
  90.             $pdf->Cell(3,0.5,ucfirst($bulangenap[$n]),1,0,'C');
  91.         }
  92.         $pdf->Cell(3,0.5,'',0,1,'C');
  93.  
  94.     }
  95.  
  96. $pdf->SetFont('Times','','11');
  97. $ss = mysql_query("SELECT * FROM student WHERE id_kelas='$kelas' order by nis ASC");
  98. while($s=mysql_fetch_array($ss)){
  99.  
  100.     //isi label
  101.     $masuk=mysql_query("SELECT * FROM keu_".$sm['kode']." where nis='".$s['nis']."'");
  102.     if(mysql_num_rows($masuk) < '1'){
  103.         //th tabel
  104.         $pdf->Cell(1,0.5,$no,1,0,'C');
  105.         $pdf->Cell(2,0.5,$s['nis'],1,0,'C');
  106.         $pdf->Cell(3.5,0.5,$s['nama'],1,0,'C');
  107.            
  108.         $pdf->Cell(18,0.5,'Belum ada data pembayaran SPP',1,1,'C');
  109.     }else{
  110.        
  111.         while($m=mysql_fetch_array($masuk)){
  112.  
  113.             //th tabel
  114.             $pdf->Cell(1,0.5,$no,1,0,'C');
  115.             $pdf->Cell(2,0.5,$s['nis'],1,0,'C');
  116.             $pdf->Cell(3.5,0.5,$s['nama'],1,0,'C');
  117.  
  118.             if($g == 'Gasal'){
  119.      
  120.                     $month_value = array();
  121.                     foreach($bulangasal as $val){
  122.                             $month_value[$val] = $m[$val];                        
  123.                     }
  124.      
  125.                     $output = array();
  126.      
  127.                     foreach ($month_value as $key => $value) {
  128.                             if($value != null){
  129.                             $bulan = date("m",strtotime($value));
  130.                                     if(isset($output[$bulan])){
  131.  
  132.                                             $output[$bulan][$index_bln_gasal[$key]] = $key;
  133.                                     }else{
  134.                                             $output[$bulan] = array($index_bln_gasal[$key]=>$key);
  135.                                     }                              
  136.                             }else{
  137.                                     $month_value[$key] = "-";
  138.                             }
  139.                     }
  140.  
  141.                     //idxs mencari bulan yang membayar dalam satu semester
  142.                     foreach($output as $bln)
  143.                     {
  144.                         if(is_array($bln))
  145.                         {
  146.                             foreach($bln as $idx => $val)
  147.                             {
  148.                                 $idxs[] = $idx ;
  149.                             }
  150.                         }
  151.                     }
  152.  
  153.                     foreach($index_bln_gasal as $bulan => $idx)
  154.                     {
  155.                         $total = 0;
  156.                         if(array_key_exists($idx,$output))
  157.                         {
  158.                      
  159.                             foreach($output[$idx] as $nmbulan)
  160.                             {
  161.                                 $total+=$t['tarif'];
  162.                             }
  163.                             $pdf->Cell(3,0.5,$total,1,0,'C');
  164.                        
  165.                         }else{
  166.                        
  167.                             // bandingkan ke bulan membayar.
  168.                             if(in_array($idx,$idxs))
  169.                             {
  170.                                 $pdf->Cell(3,0.5,$total,1,0,'C');
  171.                             }else{
  172.                                 $pdf->Cell(3,0.5,"-",1,0,'C');
  173.                             }
  174.                         }
  175.                     }
  176.      
  177.                     $pdf->Cell(3,0.5,'',0,1,'C');
  178.                    
  179.                 }else{
  180.      
  181.                     $month_value = array();
  182.                     foreach($bulangenap as $val){
  183.                             $month_value[$val] = $m[$val];                        
  184.                     }
  185.      
  186.                     $output = array();
  187.      
  188.                     foreach ($month_value as $key => $value) {
  189.                             if($value != null){
  190.                             $bulan = date("m",strtotime($value));
  191.                                     if(isset($output[$bulan])){
  192.  
  193.                                             $output[$bulan][$index_bln_genap[$key]] = $key;
  194.                                     }else{
  195.                                             $output[$bulan] = array($index_bln_genap[$key]=>$key);
  196.                                     }                              
  197.                             }else{
  198.                                     $month_value[$key] = "-";
  199.                             }
  200.                     }
  201.  
  202.                     //idxs mencari bulan yang membayar dalam satu semester
  203.                     foreach($output as $bln)
  204.                     {
  205.                         if(is_array($bln))
  206.                         {
  207.                             foreach($bln as $idx => $val)
  208.                             {
  209.                                 $idxs[] = $idx ;
  210.                             }
  211.                         }
  212.                     }
  213.  
  214.                     foreach($index_bln_genap as $bulan => $idx)
  215.                     {
  216.                         $total = 0;
  217.                         if(array_key_exists($idx,$output))
  218.                         {
  219.                      
  220.                             foreach($output[$idx] as $nmbulan)
  221.                             {
  222.                                 $total+=$t['tarif'];
  223.                             }
  224.                             $pdf->Cell(3,0.5,$total,1,0,'C');
  225.                        
  226.                         }else{
  227.                        
  228.                             // bandingkan ke bulan membayar.
  229.                             if(in_array($idx,$idxs))
  230.                             {
  231.                                 $pdf->Cell(3,0.5,$total,1,0,'C');
  232.                             }else{
  233.                                 $pdf->Cell(3,0.5,"-",1,0,'C');
  234.                             }
  235.                         }
  236.                     }
  237.                  
  238.                     $pdf->Cell(3,0.5,'',0,1,'C');
  239.                 }
  240.  
  241.        
  242.         }
  243.     }
  244.     $no++;
  245. }
  246. }
  247. $pdf->Output("Laporan keuangan.pdf","I");
  248. ?>
Advertisement
Add Comment
Please, Sign In to add comment