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

  <script>
$(document).ready(function() {

        $("#divimiz").load("denetle.php");

});

setInterval(function() {$("#divimiz").load('denetle.php');}, 30000);
		 </script>  
<style>
#main {height:350px;}#liste {
        overflow-y:scroll;
        height:324px;
        width:100%;
        overflow:none; }
</style>
  <script>
$(document).ready(function() {

        $("#say").load("say.php");

});

setInterval(function() {$("#say").load('say.php');}, 30000);
		 </script>  
<style>
#main {height:350px;}#liste {
        overflow-y:scroll;
        height:324px;
        width:100%;
        overflow:none; }
</style>
<?php $bugun = date("Y-m-d");
$cevir = strtotime('-1 day',strtotime($bugun));
$tarih =  date("Y-m-d",$cevir); ?>	
<?php 
$ona =odbc_exec($conn," 
  
     select magazalar.magazaadi , ISNULL( SUM(tutar),0) ciro , ISNULL( SUM(case c.belgetipi when  'GPS' THEN 0 ELSE c.belgeadeti end),0) adet from (select kasano , magazaadi from MAGAZAKASA )as magazalar left join CIRO as c 
on c.kasano = magazalar.kasano and c.iptalmi=0 where CAST(tarih AS date) = '$tarih'
group by magazalar.magazaadi  
  ");
  
   while($kay=odbc_fetch_array($ona)){
	   
  $topciro += $kay["ciro"];
  $topadet += $kay["adet"];
  
  $topsepetler = $topciro / $topadet ;

  
  $dun_sepet_ortalama = number_format($topsepetler, 2, ',', '.');
    
  $btoplamciro = number_format($topciro, 2, ',', '.');
  
  }
	?>	
	<?php 
$musteri =odbc_exec($conn," 
  
     select magazalar.magazaadi , ISNULL( SUM(tutar),0) ciro , ISNULL( SUM(case c.belgetipi when  'GPS' THEN 0 ELSE c.belgeadeti end),0) adet from (select kasano , magazaadi from MAGAZAKASA )as magazalar left join CIRO as c 
on c.kasano = magazalar.kasano and c.iptalmi=0 where tarih > '$bugun'
group by magazalar.magazaadi  
  ");
  
   while($ort=odbc_fetch_array($musteri)){
	   
  $ortciro += $ort["ciro"];
  $ortadet += $ort["adet"];
  
  $ortsepetler = $ortciro / $ortadet ;

  $bugun_sepet_ortalama = number_format($ortsepetler, 2, ',', '.');
  $bugun_ciro_ortalama = number_format($ortciro, 2, ',', '.');

  
  }
	?>	

<?php 
$kredi =odbc_exec($conn," 
  
  SELECT  kod, SUM(tutar) AS 'Toplam' FROM [POSNET].[dbo].[ODEME] where CAST(tarih AS date) = '$bugun'
GROUP BY kod HAVING kod > 0 
  ");
  
   while($kart=odbc_fetch_array($kredi)){
	   
  $toplam_kart += $kart["Toplam"];
 
  
 

  
  $bugun_kart_ciro = number_format($toplam_kart, 2, ',', '.');


  
  }
	?>	
<?php 
$nakit =odbc_exec($conn," 
  
SELECT 
      [magazaadi] ,ISNULL (sum (CASE WHEN od.odemetipi = 'KREDI' THEN od.tutar end) - (sum (CASE WHEN od.odemetipi = 'KREDI' and od.belgetipi = 'GPS' THEN od.tutar*2 else 0 end )) ,0) as Kredi,
	 ISNULL( sum (CASE WHEN od.odemetipi = 'NAKIT' THEN od.tutar end ) - (sum (CASE WHEN od.odemetipi = 'NAKIT' and od.belgetipi = 'GPS' THEN od.tutar*2 else 0 end )),0) as Nakit,
	 ISNULL ( sum (CASE  WHEN od.odemetipi = 'CEK' THEN od.tutar end ),0) as Cek,
	  ISNULL ( sum (CASE WHEN od.belgetipi = 'GPS' THEN  od.tutar end ),0) as NetToplam
  FROM [POSNET].[dbo].[MAGAZAKASA] as mk

  INNER JOIN [POSNET].[dbo].[ODEME] AS od on od.kasano=mk.kasano WHERE CAST(od.tarih AS date) = '$bugun'
  group by mk.magazaadi order by mk.magazaadi asc 
  ");
  
   while($para=odbc_fetch_array($nakit)){
	   
  $toplam_nakit += $para["Nakit"];
 
  
 

  
  $bugun_nakit_ciro = number_format($toplam_nakit, 2, ',', '.');


  
  }
	?>	
	
	</head>
	<body>
	
<div class=" row">
    <div class="col-md-3 col-sm-3 col-xs-6">
        <a data-toggle="tooltip" title="" class="well top-block" href="#">
            <i class="glyphicon glyphicon-user blue"></i>

            <div>Müşteri Sayısı</div>
        
          <div class="animated rubberBand"  id="say" >Yükleniyor</div>	
        </a>
    </div>

    <div class="col-md-3 col-sm-3 col-xs-6">
        <a data-toggle="tooltip" title="" class="well top-block" href="ciro.php">
            <i class="glyphicon glyphicon-star green"></i>

            <div >Anlık Ciro</div>
			<div class="animated rubberBand" id="divimiz" >Yükleniyor</div>		
            
        </a>
    </div>

    <div class="col-md-3 col-sm-3 col-xs-6">
        <a data-toggle="tooltip" title="" class="well top-block" href="#">
            <i class="glyphicon glyphicon-shopping-cart yellow"></i>

            <div>Sepet Ortalaması</div>
		
            <div class="yellow"><?php echo  $bugun_sepet_ortalama ?> ₺</div>
            <span class="notification red"><?php echo $bugun_ciro_ortalama; ?> ₺</span>
        </a>
    </div>

	

	
    <div class="col-md-3 col-sm-3 col-xs-6">
        <a data-toggle="tooltip" title="" class="well top-block" href="dciro.php">
            <i class="glyphicon glyphicon-briefcase"></i>

            <div>Dünkü Ciro</div>
            <div class="yellow"><?php echo $btoplamciro; ?> ₺</div>
       
        </a>
    </div>
	 <div class="col-md-3 col-sm-3 col-xs-6">
        <a data-toggle="tooltip" title="" class="well top-block" href="banka.php">
            <i class=" glyphicon glyphicon-home"></i>

            <div>Kredi Kartı Durumu</div>
		
            <div class="yellow"><?php echo $bugun_kart_ciro; ?> ₺</div>

        </a>
    </div>

    <div class="col-md-3 col-sm-3 col-xs-6">
        <a data-toggle="tooltip" title="" class="well top-block" href="#">
            <i class="	glyphicon glyphicon-hand-down"></i>

            <div>Nakit Durumu</div>
            <div class="yellow"><?php echo $bugun_nakit_ciro; ?> ₺</div>
            
        </a>
    </div>
</div>

        

  <div class="row">
        <div class="box col-md-12">
            <div class="box-inner">
                <div class="box-header well" data-original-title="">
                    <h2>Anlık Şube 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">
   <div id="liste">
                <div class="box-content">
				
				
                    <table class="table table-striped table-bordered bootstrap-datatable datatable responsive">
                                  <thead>
                        <tr>
                            <th><center>Şube Adı</center></th>
                            <th><center> Ciro</center></th>
                            <th><center>İşlem</center></th>
                            
                        </tr>
                        </thead>
                        <tbody>
						
						
						<?php /* günlük Faaliyet*/


$onay =odbc_exec($conn," 
select distinct mag.magazaadi,mag.magazano , ISNULL( bugun.ciro,0) as bugunciro , isnull(dun.ciro,0) as dunciro from MAGAZAKASA as mag left join
(select   magazalar.magazaadi , ISNULL( SUM(tutar),0) as ciro , magazalar.magazano  from (select magazano, kasano , magazaadi from MAGAZAKASA )as magazalar 
left join CIRO as c 
on c.kasano = magazalar.kasano and c.iptalmi=0 where tarih >= DATEADD(day, DATEDIFF(day, 0, GETDATE() ), 0)
group by  magazalar.magazano ,magazalar.magazaadi ) as bugun on bugun.magazaadi = mag.magazaadi left join
(select   magazalar.magazaadi , ISNULL( SUM(tutar),0) as ciro , magazalar.magazano  from (select magazano, kasano , magazaadi from MAGAZAKASA )as magazalar 
left join CIRO as c 
on c.kasano = magazalar.kasano and c.iptalmi=0 where tarih >= DATEADD(day, DATEDIFF(day, 0, GETDATE() -1), 0) and tarih < DATEADD(day, DATEDIFF(day, 0, GETDATE() ), 0)
group by  magazalar.magazano ,magazalar.magazaadi ) as dun on dun.magazaadi = mag.magazaadi   ");
 
   while($kayit=odbc_fetch_array($onay))
	{	
$numrows = odbc_num_rows($onay);

  $topciro = $kayit["bugunciro"];

  $kasa = $kayit["magazano"];

$magaza = $kayit["magazaadi"];



  $btoplamciro = number_format($topciro, 2, ',', '.');
  

	
?> 
		<body >
		
						
						
						
                        <tr>
                          <td><center><?php echo $kayit["magazaadi"]; ?> </td>
                         
                            <td>							
	<span class="yellow"><center>  <?php  echo $btoplamciro; ?> ₺</center> </span>
                            </td></center>
							    <td><center>							
                     <a href="detay.php?ck=detay&id=<?php echo utf8_encode($kasa);?>" id="sumbit"  class="btn btn-success">
               Detay</a>
                            </td>
                        </tr>
                      
                      
					  <?php } ?>
					  
					  
                        </tbody>
                    </table>
                   
                </div>
            </div>
        </div>
    </div><!--/span-->
    </div><!--/scroll-->
    </div><!--/scroll-->
    
	
	<div class="row">
    <div class="box col-md-4">
        <div class="box-inner">
            <div class="box-header well" data-original-title="">
                <h2><i class="glyphicon glyphicon-list-alt"></i> Şubelerin Ciro'ya Oranı</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">
               
  <head>
    <script type="text/javascript" src="js/pie.js"></script>
    <script type="text/javascript">
      google.charts.load("current", {packages:["corechart"]});
      google.charts.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
    <?php
	
    // Create a Query
    $sql_query = odbc_exec($conn,"select distinct mag.magazaadi,mag.magazano , ISNULL( bugun.ciro,0) as bugunciro , isnull(dun.ciro,0) as dunciro from MAGAZAKASA as mag left join
(select   magazalar.magazaadi , ISNULL( SUM(tutar),0) as ciro , magazalar.magazano  from (select magazano, kasano , magazaadi from MAGAZAKASA )as magazalar 
left join CIRO as c 
on c.kasano = magazalar.kasano and c.iptalmi=0 where tarih >= DATEADD(day, DATEDIFF(day, 0, GETDATE() ), 0)
group by  magazalar.magazano ,magazalar.magazaadi ) as bugun on bugun.magazaadi = mag.magazaadi left join
(select   magazalar.magazaadi , ISNULL( SUM(tutar),0) as ciro , magazalar.magazano  from (select magazano, kasano , magazaadi from MAGAZAKASA )as magazalar 
left join CIRO as c 
on c.kasano = magazalar.kasano and c.iptalmi=0 where tarih >= DATEADD(day, DATEDIFF(day, 0, GETDATE() -1), 0) and tarih < DATEADD(day, DATEDIFF(day, 0, GETDATE() ), 0) and magazaadi= 'ALIBABA'
group by  magazalar.magazano ,magazalar.magazaadi ) as dun on dun.magazaadi = mag.magazaadi order by bugunciro desc ");
	   while ($row = odbc_fetch_array($sql_query)){
		 
		 $ciro = $row['bugunciro'];
		 $ciroo += $row['bugunciro'];
		 
		 $toplam = number_format($ciro, 0, '', ''); 
		 $toplamciroo = number_format($ciroo, 2, ',', '.'); 
	echo "['".$row['magazaadi']."',".$toplam."],";
	
	} 
	
	
	?>
	
        ]);
 var options = {
	      title: 'Toplam Ciro      <?php echo $toplamciroo. ' ₺'; ?>',
		  
          is3D: true,
 pieSliceText: 'label',
chartArea:{left:20,top:20,width:'100%',height:'100%'}

        };
    

        var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));
        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
    <div id="piechart_3d" ></div>
  </body>
            </div>
        </div>
    </div>	
    </div>	
				
		



    <!-- content ends -->
    </div><!--/#content.col-md-0-->
</div><!--/fluid-row-->





</div><!--/.fluid-container-->
	
    
    <!--/span-->
</div><!--/row-->

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