

<!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 
            //////////////////////////////////////////////////////////////////////////// 
            $kdc    =$_SESSION['kdc'];
            $oleh   =$_SESSION['id_kar'];
            $xx     = $oleh ;
            $tabel_tujuan   = "nawal_".$xx; 
            $tabel_asal     = "nawal";
            ////////////////////////////////////////////////////////////////////////////     
                $sql0 = mysqli_query($koneksi, "SELECT tgl_htg,tgl_sd FROM $tabel_tujuan WHERE mutasid+mutasik>=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');

    $sql1 = mysqli_query($koneksi, "SELECT kelurahan,kecamatan,kota FROM kdkanca WHERE kd='01' ");
                list($kelurahan,$kecamatan,$kota) = mysqli_fetch_array($sql1);
                
            ?> 
	<?php
	    header("Content-type: application/vnd-ms-excel");
	    header("Content-Disposition: attachment; filename=".$kdc."_neraca_mutasi_".$tgl_s."_".$now.".xls");
    ?>

	<table border="0">
            <tr>
                <th Style="text-align:center" colspan="9">NERACA MUTASI</th>
            </tr>  
            <tr>
                <th Style="text-align:center" colspan="9">Antara tanggal : <?php echo date('d-m-Y', strtotime($tgl_d)); ?> dan tanggal : <?php echo date('d-m-Y', strtotime($tgl_s)); ?></th>
            </tr> 
            <tr>
                <th Style="text-align:center" colspan="9"></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">Saldo s/d <?php echo date('d-m-Y', strtotime($tgl_lalu)); ?></th>
                <th Style="text-align:center" colspan="2" bgcolor="#DCDCDC">Mutasi <?php echo date('d-m-Y', strtotime($tgl_d)); ?> s/d <?php echo date('d-m-Y', strtotime($tgl_s)); ?></th>
                <th Style="text-align:center" colspan="2" bgcolor="#DCDCDC">Saldo <?php echo date('d-m-Y', strtotime($tgl_s)); ?></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>
              <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>
            <?php 
            $no=1;
            $nol=0;
            //
            $data = mysqli_query($koneksi,"SELECT * FROM $tabel_tujuan WHERE klp<'40' and ap='Y' 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[awald]", 0, ",", "."); ?></td>
                            <td style="text-align:right; font-size: 11pt; font-weight:normal;"><?php echo "" . number_format("$w[awalk]", 0, ",", "."); ?></td>
                            <td style="text-align:right; font-size: 11pt; font-weight:normal;"><?php echo "" . number_format("$w[mutasid]", 0, ",", "."); ?></td>
                            <td style="text-align:right; font-size: 11pt; font-weight:normal;"><?php echo "" . number_format("$w[mutasik]", 0, ",", "."); ?></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>
                            </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 klp<'40' ");
                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 </td>																																									
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$awald", 0, ",", "."); ?>
								</td>    
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$awalk", 0, ",", "."); ?>
								</td>								

								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$tmutd", 0, ",", "."); ?>
								</td>    
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$tmutk", 0, ",", "."); ?>
								</td>	
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$takhird", 0, ",", "."); ?>
								</td>    
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$takhirk", 0, ",", "."); ?>
								</td>		
							</tr>             
				
							<tr>
						    	<td colspan="3" style="font-weight: bold;text-align: center;">LABA (RUGI) </td>																																									
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$nol", 0, ",", "."); ?>
								</td>    
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$laba_rugi_a", 0, ",", "."); ?>
								</td>
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$nol", 0, ",", "."); ?>
								</td>    
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$laba_rugi_b", 0, ",", "."); ?>
								</td>
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$nol", 0, ",", "."); ?>
								</td>    
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$laba_rugi_c", 0, ",", "."); ?>
								</td>								
							</tr>         
							<tr>
						    	<td colspan="3" style="font-weight: bold;text-align: center;">TOTAL BALANCE </td>																																									
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$awald", 0, ",", "."); ?>
								</td>    
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$total_balance_a", 0, ",", "."); ?>
								</td>
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$tmutd", 0, ",", "."); ?>
								</td>    
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$total_balance_b", 0, ",", "."); ?>
								</td>
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$takhird", 0, ",", "."); ?>
								</td>    
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$total_balance_c", 0, ",", "."); ?>
								</td>								
							</tr>							
        </table>
</body>
</html>