



<!DOCTYPE html>
<html>
<head>
	<title>Export Data Ke Excel Dengan PHP - www.mitrakoperasi.com</title>
</head>
<body>
	<style type="text/css">
	body{
		font-family: sans-serif;
	}
	table{
		margin: 20px auto;
		border-collapse: collapse;
	}
	table th,
	table td{
		border: 1px solid #3c3c3c;
		padding: 3px 8px;
 
	}
	a{
		background: blue;
		color: #fff;
		padding: 8px 10px;
		text-decoration: none;
		border-radius: 2px;
	}
	</style>
 
<?php include 'header_excell.php'; ?>
            <?php 
            //////////////////////////////////////////////////////////////////////////// 
            $oleh   =$_SESSION['id_kar'];
            $kdc   =$_SESSION['kdc'];
            $xx     = $oleh ;
            $tabel_tujuan   = "nawal_".$xx; 
            $tabel_asal     = "nawal";
            ////////////////////////////////////////////////////////////////////////////     
                $sql0 = mysqli_query($koneksi, "SELECT tgl_htg,tgl_sd FROM $tabel_tujuan WHERE mutasid>=1 limit 1 ");
                list($tgl_htg,$tgl_sd) = mysqli_fetch_array($sql0);            
              $tgl_d    = $tgl_htg;
              $tgl_s    = $tgl_sd;
              
              $tgl_ke_1 =date('2025-01-01');        
              $tgl_p    =strtotime("$tgl_d");
              $tgl_lalu =date('Y-m-d', strtotime("-1 day", $tgl_p));      
              $now = date('Y-m-d H:i:s');
              ?>
	<?php
	    header("Content-type: application/vnd-ms-excel");
	    header("Content-Disposition: attachment; filename=".$kdc."_phu_all_".$tgl_s."_".$now.".xls");
    ?>

	<table border="0">
            <tr>
                <th Style="text-align:center" colspan="7">PERHITUNGAN HASIL USAHA</th>
            </tr>  
            <tr>
                <th Style="text-align:center" colspan="7">Sampai Dengan Tanggal <?php echo date('d-m-Y', strtotime($tgl_d)); ?> dan s/d tanggal <?php echo date('d-m-Y', strtotime($tgl_s)); ?></th>
            </tr> 
            <tr>
                <th Style="text-align:center" colspan="7"></th>
            </tr>             
            <tr>
                <th Style="text-align:center" colspan="3" bgcolor="#D3D3D3">Akunt Buku Besar</th>
                <th Style="text-align:center" colspan="2" bgcolor="#DCDCDC">Per <?php echo date('d-m-Y', strtotime($tgl_s)); ?></th>
                <th Style="text-align:center" colspan="2" bgcolor="#DCDCDC">Per <?php echo date('d-m-Y', strtotime($tgl_lalu)); ?></th>
            </tr>                 
            <tr>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">No</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Nomor</th>
              <th width="20%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Nama</th>
              <th width="10%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Debet</th>
              <th width="10%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Kredit</th>
              <th width="10%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Debet</th>
              <th width="10%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Kredit</th>
            </tr>
                  </thead>
          <tbody>
            <?php
                $sqlx = mysqli_query($koneksi, "SELECT nama FROM n_kode_1 WHERE kd1='4' limit 1 ");
                list($nama) = mysqli_fetch_array($sqlx);
                $batas_klp_4='40';
                $batas_klp_5='50';
            ?>
                <tr>
                    <td colspan="3" style="font-weight: bold;text-align: center;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo $nama ?></td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo ""?></td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo ""?></td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo ""?></td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo ""?></td>
                </tr>
            <?php 
            $no=1;
            $nol=0;
            //and (awald<>0 and awalk<>0 and mutasid<>0 and mutasik<>0)
            $data = mysqli_query($koneksi,"SELECT * FROM $tabel_tujuan WHERE klp<'$batas_klp_5' and klp>='$batas_klp_4' and kt<>'X' and (awald+awalk+mutasid+mutasik)<>0 order by noperk ASC ");
            while($w = mysqli_fetch_array($data)){
              ?>
                          <tr>
                            <td><?php echo $no++; ?></td>
                            <td style="text-align:left; font-size: 11pt; font-weight:normal;"><?php echo $w['noperk'] ?></td>
                            <td style="text-align:left; font-size: 11pt; font-weight:normal;"><?php echo $w['perk']; ?></td>
                            <td style="text-align:right; font-size: 11pt; font-weight:normal;"><?php echo "" . number_format("$w[akhird]", 0, ",", "."); ?></td>
                            <td style="text-align:right; font-size: 11pt; font-weight:normal;"><?php echo "" . number_format("$w[akhirk]", 0, ",", "."); ?></td>
                            <td style="text-align:right; font-size: 11pt; font-weight:normal;"><?php echo "" . number_format("$w[awald]", 0, ",", "."); ?></td>
                            <td style="text-align:right; font-size: 11pt; font-weight:normal;"><?php echo "" . number_format("$w[awalk]", 0, ",", "."); ?></td>
                            </tr>    
                        </div>
                      </div>
                    </div>
              <?php } ?>
          </tbody>
                        <?php 
                $sql2 = mysqli_query($koneksi, "SELECT sum(awald) AS tawald,sum(awalk) AS tawalk,sum(mutasid) AS tmutd,sum(mutasik) AS tmutk,sum(akhird) AS takhird,sum(akhirk) AS takhirk FROM $tabel_tujuan WHERE kt<>'X' and klp<'$batas_klp_5' and klp>='$batas_klp_4' ");
                list($awald,$awalk,$tmutd,$tmutk,$takhird,$takhirk) = mysqli_fetch_array($sql2);

                $laba_rugi_a=($awald-$awalk);
                $laba_rugi_b=($tmutd-$tmutk);
                $laba_rugi_c=($takhird-$takhirk);
                $nol=0 ;
                $total_balance_a=($awalk+$laba_rugi_a);
                $total_balance_b=($tmutk+$laba_rugi_b);
                $total_balance_c=($takhirk+$laba_rugi_c);
            	        ?>						
							<tr>
						    	<td colspan="3" style="font-weight: bold;text-align: center;">Total <?php echo $nama ?> </td>																																									
								<td style="font-weight: bold;text-align: right;"><?php echo "" . number_format("$takhird", 0, ",", "."); ?></td>    
								<td style="font-weight: bold;text-align: right;"><?php echo "" . number_format("$takhirk", 0, ",", "."); ?></td>
								<td style="font-weight: bold;text-align: right;"><?php echo "" . number_format("$awald", 0, ",", "."); ?></td>    
								<td style="font-weight: bold;text-align: right;"><?php echo "" . number_format("$awalk", 0, ",", "."); ?></td>								
							</tr>             
 

          <tbody>
            <?php
                $sqlx = mysqli_query($koneksi, "SELECT nama FROM n_kode_1 WHERE kd1='5' limit 1 ");
                list($nama) = mysqli_fetch_array($sqlx);
            ?>
                <tr>
                    <td colspan="3" style="font-weight: bold;text-align: center;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo $nama ?></td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo ""?></td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo ""?></td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo ""?></td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo ""?></td>
                </tr>
            <?php 
            $no=1;
            $nol=0;
            //and (awald<>0 and awalk<>0 and mutasid<>0 and mutasik<>0)
            $data = mysqli_query($koneksi,"SELECT * FROM $tabel_tujuan WHERE klp>'$batas_klp_5' and kt<>'X' and (awald+awalk+mutasid+mutasik)<>0 order by noperk ASC ");
            while($w = mysqli_fetch_array($data)){
              ?>
                          <tr>
                            <td><?php echo $no++; ?></td>
                            <td style="text-align:left; font-size: 11pt; font-weight:normal;"><?php echo $w['noperk'] ?></td>
                            <td style="text-align:left; font-size: 11pt; font-weight:normal;"><?php echo $w['perk']; ?></td>
                            <td style="text-align:right; font-size: 11pt; font-weight:normal;"><?php echo "" . number_format("$w[akhird]", 0, ",", "."); ?></td>
                            <td style="text-align:right; font-size: 11pt; font-weight:normal;"><?php echo "" . number_format("$w[akhirk]", 0, ",", "."); ?></td>
                            <td style="text-align:right; font-size: 11pt; font-weight:normal;"><?php echo "" . number_format("$w[awald]", 0, ",", "."); ?></td>
                            <td style="text-align:right; font-size: 11pt; font-weight:normal;"><?php echo "" . number_format("$w[awalk]", 0, ",", "."); ?></td>
                            </tr>    
                        </div>
                      </div>
                    </div>
              <?php } ?>
          </tbody>
                        <?php 
                $sql2 = mysqli_query($koneksi, "SELECT sum(awald) AS tawald,sum(awalk) AS tawalk,sum(mutasid) AS tmutd,sum(mutasik) AS tmutk,sum(akhird) AS takhird,sum(akhirk) AS takhirk FROM $tabel_tujuan WHERE kt<>'X' and klp>'$batas_klp_5'");
                list($awald,$awalk,$tmutd,$tmutk,$takhird,$takhirk) = mysqli_fetch_array($sql2);

                $laba_rugi_a=($awald-$awalk);
                $laba_rugi_b=($tmutd-$tmutk);
                $laba_rugi_c=($takhird-$takhirk);
                $nol=0 ;
                $total_balance_a=($awalk+$laba_rugi_a);
                $total_balance_b=($tmutk+$laba_rugi_b);
                $total_balance_c=($takhirk+$laba_rugi_c);
            	        ?>						
							<tr>
						    	<td colspan="3" style="font-weight: bold;text-align: center;">Total <?php echo $nama ?> </td>																																									
								<td style="font-weight: bold;text-align: right;"><?php echo "" . number_format("$takhird", 0, ",", "."); ?></td>    
								<td style="font-weight: bold;text-align: right;"><?php echo "" . number_format("$takhirk", 0, ",", "."); ?></td>
								<td style="font-weight: bold;text-align: right;"><?php echo "" . number_format("$awald", 0, ",", "."); ?></td>    
								<td style="font-weight: bold;text-align: right;"><?php echo "" . number_format("$awalk", 0, ",", "."); ?></td>								
							</tr>          
		
          <tbody>
                        <?php 
                $sql2 = mysqli_query($koneksi, "SELECT sum(awald) AS tawald,sum(awalk) AS tawalk,sum(mutasid) AS tmutd,sum(mutasik) AS tmutk,sum(akhird) AS takhird,sum(akhirk) AS takhirk FROM $tabel_tujuan WHERE kt<>'X' and klp>'40' ");
                list($awald,$awalk,$tmutd,$tmutk,$takhird,$takhirk) = mysqli_fetch_array($sql2);

                $laba_rugi_a=($awalk-$awald);
                $laba_rugi_b=($tmutd-$tmutk);
                $laba_rugi_c=($takhirk-$takhird);
                $nol=0 ;
                $total_balance_a=($awalk+$laba_rugi_a);
                $total_balance_b=($tmutk+$laba_rugi_b);
                $total_balance_c=($takhirk+$laba_rugi_c);
            	        ?>						
							<tr>
						    	<td colspan="3" style="font-weight: bold;text-align: center;">Total Sisa Hasil Usaha (SHU) </td>																																									
								<td style="font-weight: bold;text-align: right;"><?php echo "" . number_format("$nol", 0, ",", "."); ?></td>    
								<td style="font-weight: bold;text-align: right;"><?php echo "" . number_format("$laba_rugi_c", 0, ",", "."); ?></td>
								<td style="font-weight: bold;text-align: right;"><?php echo "" . number_format("$nol", 0, ",", "."); ?></td>    
								<td style="font-weight: bold;text-align: right;"><?php echo "" . number_format("$laba_rugi_a", 0, ",", "."); ?></td>								
							</tr>     
        </table>
</body>
</html>