emprit

perkelas

Jun 4th, 2014
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.30 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.                    
  126.      
  127.                     $output = array();
  128.      
  129.                     foreach ($month_value as $key => $value) {
  130.                             if($value != null){
  131.                             $bulan = date("m",strtotime($value));
  132.                                     if(isset($output[$bulan])){
  133.  
  134.                                             $output[$bulan][$index_bln_gasal[$key]] = $key;
  135.                                     }else{
  136.                                             $output[$bulan] = array($index_bln_gasal[$key]=>$key);
  137.                                     }                              
  138.                             }else{
  139.                                     $month_value[$key] = "-";
  140.                             }
  141.                     }
  142.  
  143.                     //idxs mencari bulan yang membayar dalam satu semester
  144.                     foreach($output as $bln)
  145.                     {
  146.                         if(is_array($bln))
  147.                         {
  148.                             foreach($bln as $idx => $val)
  149.                             {
  150.                                 $idxs[] = $idx ;
  151.                             }
  152.                         }
  153.                     }
  154.  
  155.                     foreach($index_bln_gasal as $bulan => $idx)
  156.                     {
  157.                         $total = 0;
  158.                         if(array_key_exists($idx,$output))
  159.                         {
  160.                      
  161.                             foreach($output[$idx] as $nmbulan)
  162.                             {
  163.                                 $total+=$t['tarif'];
  164.                             }
  165.                             $pdf->Cell(3,0.5,$total,1,0,'C');
  166.                        
  167.                         }else{
  168.                        
  169.                             // bandingkan ke bulan membayar.
  170.                             if(in_array($idx,$idxs))
  171.                             {
  172.                                 $pdf->Cell(3,0.5,$total,1,0,'C');
  173.                             }else{
  174.                                 $pdf->Cell(3,0.5,"-",1,0,'C');
  175.                             }
  176.                         }
  177.                     }
  178.      
  179.                     $pdf->Cell(3,0.5,'',0,1,'C');
  180.                    
  181.                 }else{
  182.      
  183.                     $month_value = array();
  184.                     foreach($bulangenap as $val){
  185.                             $month_value[$val] = $m[$val];                        
  186.                     }
  187.      
  188.                     $output = array();
  189.      
  190.                     foreach ($month_value as $key => $value) {
  191.                             if($value != null){
  192.                             $bulan = date("m",strtotime($value));
  193.                                     if(isset($output[$bulan])){
  194.  
  195.                                             $output[$bulan][$index_bln_genap[$key]] = $key;
  196.                                     }else{
  197.                                             $output[$bulan] = array($index_bln_genap[$key]=>$key);
  198.                                     }                              
  199.                             }else{
  200.                                     $month_value[$key] = "-";
  201.                             }
  202.                     }
  203.  
  204.                     //idxs mencari bulan yang membayar dalam satu semester
  205.                     foreach($output as $bln)
  206.                     {
  207.                         if(is_array($bln))
  208.                         {
  209.                             foreach($bln as $idx => $val)
  210.                             {
  211.                                 $idxs[] = $idx ;
  212.                             }
  213.                         }
  214.                     }
  215.  
  216.                     foreach($index_bln_genap as $bulan => $idx)
  217.                     {
  218.                         $total = 0;
  219.                         if(array_key_exists($idx,$output))
  220.                         {
  221.                      
  222.                             foreach($output[$idx] as $nmbulan)
  223.                             {
  224.                                 $total+=$t['tarif'];
  225.                             }
  226.                             $pdf->Cell(3,0.5,$total,1,0,'C');
  227.                        
  228.                         }else{
  229.                        
  230.                             // bandingkan ke bulan membayar.
  231.                             if(in_array($idx,$idxs))
  232.                             {
  233.                                 $pdf->Cell(3,0.5,$total,1,0,'C');
  234.                             }else{
  235.                                 $pdf->Cell(3,0.5,"-",1,0,'C');
  236.                             }
  237.                         }
  238.                     }
  239.                  
  240.                     $pdf->Cell(3,0.5,'',0,1,'C');
  241.                 }
  242.  
  243.        
  244.         }
  245.     }
  246.     $no++;
  247. }
  248.  
  249. //total
  250.     $pdf->Cell(3,0.5,'TOTAL',0,0,'C');
  251.                 if($g == 'Gasal'){
  252.                
  253.                     $sum = array();
  254.                     foreach($bulangasal as $val){
  255.                             $sum[$val] = 0;    
  256.                     }
  257.                    
  258.                     function getTotalAll($array){
  259.                         $sum = 0;
  260.                         foreach($array as $t){
  261.                             $sum += $t;
  262.                         }
  263.                         return $sum;
  264.                     }
  265.                    
  266.                     foreach($bulangasal as $val){
  267.                         $pdf->Cell(3,0.5,getTotalAll($sum['$val']),0,1,'C');
  268.                     }
  269.                    
  270.                 }else{
  271.                
  272.                     $sum = array();
  273.                     foreach($bulangenap as $val){
  274.                             $sum[$val] = 0;    
  275.                     }
  276.                    
  277.                     function getTotalAll($array){
  278.                         $sum = 0;
  279.                         foreach($array as $t){
  280.                             $sum += $t;
  281.                         }
  282.                         return $sum;
  283.                     }
  284.                    
  285.                     foreach($bulangenap as $val){
  286.                         $pdf->Cell(3,0.5,getTotalAll($sum['$val']),0,1,'C');
  287.                     }
  288.                    
  289.                 }
  290.                 }
  291.                
  292.                
  293.                
  294. $pdf->Output("Laporan keuangan.pdf","I");
  295. ?>
Advertisement
Add Comment
Please, Sign In to add comment