<?php include('header.php'); ?>

 <head>
  
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  
  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/js/bootstrap-multiselect.js"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/css/bootstrap-multiselect.css" />
 </head>

<div class="row">
    <div class="box col-md-12">
        <div class="box-inner">
            <div class="box-header well" data-original-title="">
                <h2><i class="glyphicon glyphicon-edit"></i> Kar Zarar Raporu</h2>

                <div class="box-icon">
                    
                    <a href="#" class="btn btn-minimize btn-round btn-default"><i
                            class="glyphicon glyphicon-chevron-up"></i></a>
                    <a href="#" class="btn btn-close btn-round btn-default"><i
                            class="glyphicon glyphicon-remove"></i></a>
                </div>
            </div>         <?php
$tarih = date("Y-m-d");
$tarih2 = date("Y-m-d");
			if(isset($_POST['date'])){
$tarih = $_POST['date'];
$tarih2 = $_POST['date2'];
}else if (isset($_SESSION['tarih'])){ 
 
 $tarih = $_SESSION['tarih'];
 $tarih2 = $_SESSION['tarih2'];

 }else{
$tarih = date("Y-m-d");
$tarih2 = date("Y-m-d");

 	
 } ?>
            <div class="box-content">

                <form name="form" method="post" role="form">
				
     	
 					  <td id="icerik" style="color:black;" >
<label for="yil">Yıl Seçiniz:</label>
<select name="yil" id="yil">
	 <option style="font-size:18px; font-weight: bold; color:black;" name="yil" value="2020"><h1>2020</h1></option>
	 <option style="font-size:18px; font-weight: bold; color:black;" name="yil" value="2021"><h1>2021</h1></option>
	 <option style="font-size:18px; font-weight: bold; color:black;" name="yil" value="2022"><h1>2022</h1></option>
	 <option style="font-size:18px; font-weight: bold; color:black;" name="yil" value="2023" selected><h1>2023</h1></option>
	 <option style="font-size:18px; font-weight: bold; color:black;" name="yil" value="2024"><h1>2024</h1></option>
	 <option style="font-size:18px; font-weight: bold; color:black;" name="yil" value="2025"><h1>2025</h1></option>
</select>
				   
</td>
                   
               
                   &nbsp&nbsp&nbsp <button type="submit" class="btn btn-default"> &nbsp&nbsp&nbsp Raporla &nbsp&nbsp&nbsp</button>
                </form>

            </div>
        </div>
  
    <!--/span-->
<?php if ($_POST){
    $ara=$_POST["yil"];
	
	
	?>
	
</div><!--/row-->
</div><!--/row-->

<div class="row">
        <div class="box col-md-12">
            <div class="box-inner">
                <div class="box-header well" data-original-title="">
                    <h2><i class="glyphicon glyphicon-user"></i> Ay Bazlı Satış Raporu</h2>

                    <div class="box-icon">
                        <a href="#" class="btn btn-minimize btn-round btn-default"><i
                                class="glyphicon glyphicon-chevron-up"></i></a>
                        <a href="#" class="btn btn-close btn-round btn-default"><i
                                class="glyphicon glyphicon-remove"></i></a>
                    </div>
                </div>
                <div class="box-content">
                    <table class="table table-striped table-bordered responsive">
                        <thead>
                        <tr>
                            <th>Dönem ( Ay )</th>
                            <th>Toplam Satış </th>
                            
                    
                        </tr>
                        </thead>
						

<?php

	$sql_check = odbc_exec($db,"
SELECT
Ay,
SUM(Toplam * BaslikKur) AS Toplam,
SUM(ToplamIskonto * BaslikKur) AS ToplamIskonto,
SUM(AraToplam * BaslikKur) AS AraToplam,
SUM(KDVToplam * BaslikKur) AS KDVToplam,
SUM(OTVToplam * BaslikKur) AS OTVToplam,
SUM(TevkifatToplam * BaslikKur) AS TevkifatToplam,
SUM((KDVToplam + OTVToplam) * BaslikKur) AS ToplamVergi,
SUM(GenelToplam * BaslikKur) AS GenelToplam,
SUM(ToplamMiktar) AS ToplamMiktar,
SUM(SatirSayisi) AS SatirSayisi
FROM (
SELECT
MONTH(FL.Tarih) as Ay, BaslikKur, C.ParaBirimi,
CASE WHEN BelgeTipi IN (28,40,58, 29,38,11,13,53,59) THEN -Toplam ELSE Toplam END Toplam,
CASE WHEN BelgeTipi IN (28,40,58, 29,38,11,13,53,59) THEN -ToplamIskonto ELSE ToplamIskonto END ToplamIskonto,
CASE WHEN BelgeTipi IN (28,40,58, 29,38,11,13,53,59) THEN -AraToplam ELSE AraToplam END AraToplam,
CASE WHEN BelgeTipi IN (28,40,58, 29,38,11,13,53,59) THEN -KDVToplam ELSE KDVToplam END KDVToplam,
CASE WHEN BelgeTipi IN (28,40,58, 29,38,11,13,53,59) THEN -OTVToplam ELSE OTVToplam END OTVToplam,
CASE WHEN BelgeTipi IN (28,40,58, 29,38,11,13,53,59) THEN -TevkifatToplam ELSE TevkifatToplam END TevkifatToplam,
CASE WHEN BelgeTipi IN (28,40,58, 29,38,11,13,53,59) THEN -GenelToplam ELSE GenelToplam END GenelToplam,
CASE WHEN BelgeTipi IN (28,40,58, 29,38,11,13,53,59) THEN -ToplamMiktar ELSE ToplamMiktar END ToplamMiktar,
CASE WHEN BelgeTipi IN (28,40,58, 29,38,11,13,53,59) THEN -SatirSayisi ELSE SatirSayisi END SatirSayisi
FROM FaturaListesi FL
LEFT JOIN Cariler C ON FL.BelgeTipi NOT IN (37,38,39,40,41,42) AND C.Id = FL.CariId
LEFT JOIN PesinCariler PC ON FL.BelgeTipi IN (37,38,39,40) AND PC.Id = FL.CariId
WHERE BelgeTipi NOT IN (42, 41,57)
AND FL.Tarih BETWEEN { ts '$ara-01-01 00:00:00.000'} AND { ts '$ara-12-31 23:59:59.998'}
 AND FL.BelgeTipi IN (23,37,63,61,65,232,52,54,10,12,21, 29,38,11,13,59, 53) AND FL.BelgeTipi IN (52,54,53)
) AS R
GROUP BY Ay ORDER BY Ay
  ");

 while($satir = odbc_fetch_array($sql_check)) { 


$ay = $satir['Ay'];

$geneltoplam = $satir["GenelToplam"];



$aylar = array(

		1=>"Ocak",

		2=>"Şubat",

		3=>"Mart",

		4=>"Nisan",

		5=>"Mayıs",

		6=>"Haziran",

		7=>"Temmuz",

		8=>"Ağustos",

		9=>"Eylül",

		10=>"Ekim",

		11=>"Kasım",

		12=>"Aralık"

);

  $geneltoplam = number_format($geneltoplam, 2, ',', '.');
  


?>
                        <tbody>
                        <tr>
                          
                            <td class="center"><b> <span class="yellow"><?php echo $ara.' - '.$aylar[$ay]; ?> </span></td>
                            <td class="center"><b><span class="green"><?php echo $geneltoplam.'  '.'₺'; ?> </span></td>
                           

                          
                        
                            
                        </tr>
 <?php $gtoplam += $satir["GenelToplam"]; }
 
 
 
 $gstoplam = number_format($gtoplam, 2, ',', '.');
 
 
  ?>
<td></td>
       <td class="center"><b><span class="blue"><?php echo $gstoplam.'  '.'₺'; } ?> </span></td>
                      
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <!--/span-->


<?php require('footer.php'); ?>