<?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> Z raporu Kontrol</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">
				
     	
    <div class="form-group">
    



				           <div class="form-group has-success col-md-4">
                        <input type="date" class="form-control" value="<?php echo $tarih ; ?>" name="date" >
                    </div>
				
				   

                   
               
                   &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["date"];
	$araa=$_POST["date2"];
	$say=$_POST["say"]; 
	
	
	?>
	
</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> Z raporu Kontrol</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>#</th>
                            <th>Kasa No</th>
                            <th>Tip</th>
                            <th>M.Sayısı</th>
                            <th>Nakit</th>                  
                            <th>Kredi</th>                  
                            
                            <th>Toplam</th>
                            <th>Fark</th>
                         
                            
                    
                        </tr>
                        </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;
	}	


	if(empty($ara) && empty($araa)) {
      echo '    <div class="alert alert-danger">
                    <button type="button" class="close" data-dismiss="alert">&times;</button>
                    <strong>Hata</strong> Lütfen Boş Bırakmayınız
                </div>';
	 
   } 
	
	$tarih = date("Y-m-d"); 

function hesapla($x,$y){
    $result=0;
    if($x>$y){
        $result=(($x-$y)/$y)*100;
    }else{
        $result=(($y-$x)/$x)*100;
    }
    return $result;
}


	$sorgu = odbc_exec($db,"
select  count (tip) belgeadet ,sube.adi magaza,   ( case when bt.iptal = 1 then 'IPTAL ' +bt.tip else bt.tip end) tip ,
 bt.kasa_no kasano ,   sum(bt.toplam) toplam  , 
 ISNULL( sum(od.nakit),0) nakit ,ISNULL(sum(od.kredi ),0)kredi , sum(de.indirim + bt.aratoplam_indirim) indirim 
 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 >= '$ara' and tarih <= '$ara' 
 group by  sube.adi, tip , iptal ,kasa_no ,  tarih ,tip order by 
 bt.kasa_no, bt.tarih  ");

        while($kayit=odbc_fetch_array($sorgu))
	{	
$tipp =$kayit["tip"];
$kasano =$kayit["kasano"];
$kasanoo = "00$kasano";
$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, ',', '.');
 $farktoplam = $kayit["toplam"];
 if($kasanoo){
 $sql_checks = odbc_exec($conn,"       
   SELECT 
      sum ([nakitadet]) nakitadet
      ,sum ([nakittoplam]) nakittoplam
      ,sum ([krediliadet]) krediliadet
      ,sum ([kredilitoplam]) kredilitoplam
      ,sum ([geneltoplam]) geneltoplam
	  ,kasano

    
  FROM [online_ciro].[dbo].[profiloz]  where kasano='$kasanoo' and tarih='$ara' 
    group by   
     
      [kasano]
  
  ");
 while($satirs = odbc_fetch_array($sql_checks)) {

	 $nakittop = $satirs["nakittoplam"];
	 $kreditop = $satirs["kredilitoplam"];
	 $geneltop = $satirs["geneltoplam"];
	
	
 }
 $fark = $farktoplam - $geneltop;
 
 $nakittop = number_format($nakittop, 2, ',', '.');
 $kreditop = number_format($kreditop, 2, ',', '.');
 $geneltop = number_format($geneltop, 2, ',', '.');
 $fark = number_format($fark, 2, ',', '.');
 }
  
 
 if ($tip == 'FİŞ'){
?>

                        <tbody>
                        <tr>
									<?php if ($fark == '0,00'){ ?>
		<td class="center"><h4><i class="glyphicon glyphicon-thumbs-up green"></i></td></font>
		<?php }else{ ?>
		<td class="center"><h4><i class="glyphicon glyphicon-thumbs-down red"></i></td></font>
		<?php } ?>
                          <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["belgeadet"].'<br>'.$fistop ; ?></td>
		
		<td class="center"><h4><b><font color='yellow'><?php echo $nakit.'<br>'.$nakittop; ?></td></font>
		<td class="center"><h4><b><font color='#F57F17'><?php echo $kredi.'<br>'.$kreditop; ?></td></font>
		<td class="center">
		<h4><b><font color='00FF00'><?php echo $toplam.'<br>'.$geneltop; ?></font>
		</td>
		<?php if ($fark == '0,00'){ ?>
		<td class="center"><h4><b><font color='green'><?php echo $fark; ?></td></font>
		<?php }else{ ?>
		<td class="center"><h4><b><font color='red'><?php echo $fark; ?></td></font>
		<?php } ?>

		
                            
                        </tr>
					
<?php } } }?>          
                      
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <!--/span-->


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