<?php require('header.php');
$bugun = date("Y-m-d");
$yenitarih = strtotime('-1 day',strtotime($bugun));
$dun = date('Y-m-d' ,$yenitarih );
date_default_timezone_set('Europe/Istanbul');
					
@session_start();
header('Content-type: text/html; charset=utf-8');
?>
<!DOCTYPE html>
<html lang="tr">
<head>
 <meta charset="UTF-8">
</head>

<?php 

if($_GET["ck"]){
	$ad = $_GET["ck"];
	$_SESSION["ad"] = $_GET["ck"];
}else{

$ad = $_SESSION["ad"];
}

	
	
	


 ?>
<?php
$kayit = 25;
$sor=odbc_exec($conn,"
SELECT count (id)say
  FROM belge_tanim where tarih='$bugun' and kasa_no='$ad'
");
 while($ver=odbc_fetch_array($sor))
    {
		$say = $ver['say'];
	}
$sayfa = $_GET['sayfa'] ? $_GET['sayfa'] : 1;
$limit = $kayit; 
$toplam_icerik_sayisi = $say;
$sonSayfa = ceil($toplam_icerik_sayisi/$limit);
$baslangic = ($sayfa-1)*$limit;

?>
<div class="row">
        <div class="box col-md-12">
            <div class="box-inner">
                <div class="box-header well" data-original-title="">
                    <h2><?php echo $bugun; ?> &nbsp  Kasa Bazlı Satış Durum</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 id="main_fb">
				<script language="javascript">
onchange='this.form.submit()'
</script >

   <div id="friend_list">
                <div class="box-content">
                    <table class="table table-striped table-bordered bootstrap-datatable datatable responsive">
                        <thead>
                    <th>Kasa No</th>
        <th>Belge Tipi</th>
        <th>Belge No</th>
		 <th>Saat</th>
		 <th>İndirim</th>
		 <th>Nakit</th>
		 <th>Kredi Kartı</th>
		<th>Tutar</th>
		<th>Tutar</th>
       
               
               
                    
                        </thead>

						<?php 
function turkcelestir($yazi) {
	$yazi = trim($yazi);
	$bul = array('Ç','ç','Ğ','ğ','ı','İ','Ö','ö','Ş','ş','Ü','ü',' ');
	$degis = array('c','c','g','g','i','i','o','o','s','s','u','u',' ');
	$hatasiz = str_replace($bul, $degis, $yazi);
	return $hatasiz;
	}	

	$ck = @$_GET["ck"];

   	

						
	$sorgu=odbc_exec($conn,"
	 select  sube.adi magaza,  ( case when bt.iptal = 1 then 'İPTAL ' +bt.tip else bt.tip end) tip , 
 bt.kasa_no kasano , bt.belge_no belgeno , bt.tarih,bt.saat, sum(bt.toplam) toplam  , 
 ISNULL( sum(od.nakit),0) nakit ,ISNULL(sum(od.kredi ),0)kredi , sum(de.indirim + bt.aratoplam_indirim) 
 indirim , bt.id  from [online_ciro].dbo.[belge_tanim] as bt  OUTER APPLY (select tanim_id,
 sum(  case when no = 0 then odeme else 0 end ) nakit , sum(  case when no <> 0 then odeme else 0 end ) 
 kredi  from[online_ciro].dbo.[belge_odeme] where tanim_id = bt.id group by tanim_id ) as od  OUTER  APPLY
 (select tanim_id, sum( indirim  ) indirim  from[online_ciro].dbo.[belge_detay] 
 where tanim_id = bt.id and tutar >= 0   group by tanim_id ) as de 
 inner join [online_ciro].dbo.[kasa_tanim] as kasa on kasa.no = bt.kasa_no  
 inner join [online_ciro].dbo.[sube_tanim] as sube on sube.id = kasa.sube_id 
 where tarih >= '$bugun' and tarih <= '$bugun'   and kasa_no=$ad
 
 group by bt.id, sube.adi, tip , iptal ,kasa_no , bt.belge_no , tarih ,bt.saat  
 order by  sube.adi, bt.kasa_no,bt.belge_no, bt.tarih , bt.saat
    OFFSET $baslangic ROWS
FETCH NEXT $limit ROWS ONLY      
");
  
       while($kayit=odbc_fetch_array($sorgu))
	{	
$tipp =$kayit["tip"];
$tips =   turkcelestir($tipp);
							
$tip =  mb_convert_encoding($tips  , "UTF-8", "ISO-8859-9");
 $indirim = number_format($kayit["indirim"], 2, ',', '.');
 $nakit = number_format($kayit["nakit"], 2, ',', '.');
 $kredi = number_format($kayit["kredi"], 2, ',', '.');
 $toplam = number_format($kayit["toplam"], 2, ',', '.');
	$saat =substr($kayit["saat"] ,'0','8'); 
?> 


                        <tbody>
                        <tr>
 <td class="center"><h4><b>Kasa - <?php echo $kayit["kasano"]; ?></td>
        <td class="center"><h4><b><?php echo $tip; ?></td>
		<td class="center"><h4><b><?php echo $kayit["belgeno"]; ?></td>
		<td class="center"><h4><b><?php echo $saat; ?></td>
		<td class="center"><h4><b><?php echo $indirim.' '.'₺'; ?></td>
		<td class="center"><h4><b><font color='yellow'><?php echo $nakit.' '.'₺'; ?></td></font>
		<td class="center"><h4><b><font color='yellow'><?php echo $kredi.' '.'₺'; ?></td></font>
		<td class="center"><h4><b><font color='yellow'><?php echo $toplam.' '.'₺'; ?></td></font>
		    <td><center>							
                     <a href="detayfis.php?ck=detay&id=<?php echo utf8_encode($kayit["id"]);?>" id="sumbit"  class="btn btn-success">
               Fiş Detay</a>
                            </td>
                        </tr>
<?php } ?>

                      <tr>
					  <td ><center></center></td>
					  <td><center></center></td>
					
					  
					  </tr>
                        </tbody>

                    </table>

						<div align="center" >  <ul class="pagination pagination-centered " align="center">
<?php if($toplam_icerik_sayisi > $limit){	
	echo '<br><br>';

	$x = 3; //kısaltma limiti 
	if($sayfa > 1){	
		$onceki = $sayfa-1;	
		echo '<li><a href="?sayfa='.$onceki.'"><font size="3" >« Önceki </font></a></li>'; 
	}		 
	if($sayfa==1){ 
		echo '<li><a class="btn btn-default btn-primary btn-sm"><font size="3" color="ffffff">1</font></a></li>'; 
	}
	else{ 
		echo '<li><a href="?sayfa=1"><font size="3"  >1</font></a></li>'; 
	}
	
	if($sayfa-$x > 2){ 
	
		$i = $sayfa-$x; 
	}else { 			
		$i = 2; 		  
	}
	
	
	for($i; $i<=$sayfa+$x; $i++) { 
		if($i==$sayfa){ 
			echo '&nbsp;<li><a class="btn btn-default btn-primary btn-sm "><font size="3" color="ffffff">'. $i .'</font></a></li>&nbsp;'; 
		}
		else{
			echo ' <li><a href="?sayfa=' .$i. '"><font size="3" >' . " ".$i . '</font></a></li>' ; 
		}
		if($i==$sonSayfa) break;  
	}
	
	
	if($sayfa+$x < $sonSayfa-1) { 
	 
		echo '<li><a href="?sayfa='. $sonSayfa.'"><font size="3" >'. $sonSayfa.'</font></a></li>'; 
	}elseif($sayfa+$x == $sonSayfa-1) { 			
		echo '<li><a href="?sayfa='. $sonSayfa.'"><font size="2" >'. $sonSayfa.'</font></a></li>'; 		 
	}

	
	if($sayfa < $sonSayfa){	
		$sonraki = $sayfa+1; 
		echo '<li><a href="?sayfa='.$sonraki.'"><font size="3" > Sonraki » </font></a></li>'; 
	}	
}
?>        

   
                  
                    </ul></div>                  <br>            <?php
$url = htmlspecialchars($_SERVER['HTTP_REFERER']);  // hangi sayfadan gelindigi degerini verir.
echo "<a href='$url' class='btn btn-success'>Önceki Sayfa</a>"; // dugmeye o degeri atiyoruz.
?><a href='excel.php' class='btn btn-info'>Excel'e Aktar</a>
                </div>
            </div>
        </div>
    </div><!--/span-->
	</div>
</div>
<head>

<script type="text/javascript">
$(function () {
$("#top").click(function () {

$("html,body").stop(

).animate({ scrollTop: "0" }, 100);
});
});
$(window).scroll(function () {
var uzunluk = $(document).scrollTop();
if (uzunluk > 500) $("#top").fadeIn(700);
else { $("#top").fadeOut(500); }
});
</script>



<script type="text/javascript" src="js/datatables.min.js"></script>

<script>
        $('#myTable').DataTable({
            language: {
                info: "_TOTAL_ kayıttan _START_ - _END_ kayıt gösteriliyor.",
                infoEmpty:      "Gösterilecek hiç kayıt yok.",
                loadingRecords: "Kayıtlar yükleniyor.",
                zeroRecords: "Tablo boş",
                search: "Arama:",
                infoFiltered:   "(toplam _MAX_ kayıttan filtrelenenler)",
                buttons: {
                    copyTitle: "Panoya kopyalandı.",
                    copySuccess:"Panoya %d satır kopyalandı",
                    copy: "Kopyala",
                    print: "Yazdır",
                },

                paginate: {
                    first: "",
                    previous: "",
                    next: "",
                    last: ""
                },
            },
            dom: 'Bfrtip',
            buttons: [
                'copy', 'excel', 'pdf', 'print'
            ],
            responsive: true
        });
</script>


</head>
<head>
<script type="text/javascript">
$(function () {
$("#top").click(function () {

$("html,body").stop(

).animate({ scrollTop: "0" }, 1000);
});
});
$(window).scroll(function () {
var uzunluk = $(document).scrollTop();
if (uzunluk > 500) $("#top").fadeIn(700);
else { $("#top").fadeOut(500); }
});
</script>
<style type="text/css">
#top {
bottom: 5px;
bottom: 20px;
display: none;
height: 100px;
position: fixed;
right: 20px;
}
</style>
</head>
<body>
<div id="top">
<br />
<img width="50" height="50" src="img/yukari.png" />
</div>
</body>
<?php require('footer.php'); ?>

</html>























