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

$bugun = date("Y-m-d");
$yenitarih = strtotime('-1 day',strtotime($bugun));
$yenitarih = date('d.m.Y' ,$yenitarih );


?>


<body onload="setTimeout('timeout()', 50)"></body>
<div>
        <ul class="breadcrumb">
            <li>
                <a href="posnet.php">Anasayfa</a>
            </li>
            <li>
                <a href="ciro.php">Şube Bazlı Finansal Detay</a>
            </li>
        </ul>
    </div>
<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  Finansal Dağılım</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">
   <div id="friend_list">
                <div class="box-content">
                    <table class="table table-striped table-bordered bootstrap-datatable datatable responsive">
                        <thead>
                    <th><center>Şube Adı</th>
                    <th><center>Fiş Sayısı</th>
                    <th><center>Nakit</th>
                    <th><center>Kredi Kartı</th>
                    <th><center>Çek</th>
                        </thead>
                        <tbody>
<?php

$gdr =odbc_exec($conn," 
 SELECT SUM(toplam)toplam,st.adi,bt.tip
  FROM 
  
  [online_ciro].[dbo].[belge_tanim] as bt
  inner join kasa_tanim as ks on ks.no = bt.kasa_no
  inner join sube_tanim as st on st.id= ks.sube_id
  where tarih between '$bugun' and '$bugun' and 
  iptal=0 and
  tip like '%DER PUSULAS%' 
  group by st.adi	,tip

 ");

while($ver=odbc_fetch_array($gdr)){
	
	$gider += $ver["toplam"];
	
}

 $onay =odbc_exec($conn,"   

select  sube.adi, bt.iptal ,bt.tarih,count(1)tip_adet, sum(bt.toplam)toplam  , ISNULL( sum(od.nakit),0) nakit ,ISNULL(sum(od.kredi ),0)kredi 
                      , ISNULL(sum(od.nakit + od.kredi), 0) odemetoplam 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 
				  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 bt.iptal = 0
				   group by  sube.adi, iptal  , tarih order by sube.adi, tarih  ");
  
   while($kayit=odbc_fetch_array($onay))
	{	

	
	
  $kredi = $kayit["kredi"];
  $nakit = $kayit["nakit"];
  $cek = $kayit["toplam"];
  $adi = $kayit["adi"];
  $adet = $kayit["tip_adet"];
  $fis_top += $kayit["tip_adet"];
  
  $kredi_t   += $kayit["kredi"];
  $nakit_t   += $kayit["nakit"];
  $cek_t     += $kayit["toplam"];
 
 $dus = $nakit -  $gps ;
 $dus_t = $nakit_t -  $gider ;
 

 
 
 
  $kredi_toplam = number_format($kredi, 2, ',', '.'); 
  $nakit_toplam = number_format($dus, 2, ',', '.'); 
  $cek_toplam = number_format($cek, 2, ',', '.'); 
  
    $kredi_top = number_format($kredi_t, 2, ',', '.'); 
  $nakit_top = number_format($dus_t, 2, ',', '.'); 
  $cek_top = number_format($cek_t, 2, ',', '.'); 

  $geneltoplam = $cek_t - $gider ;
  $geneltoplams = $cek_t - $gider - $gider;
    $geneltoplam = number_format($geneltoplam, 2, ',', '.'); 
    $geneltoplams = number_format($geneltoplams, 2, ',', '.'); 
  ?>
  
  
                        <tr>
                          <td><center> <?php echo $adi; ?> </td>
                          <td><center> <?php echo $adet; ?> </td>
                         
                            <td>							
                                <span class="yellow"><center>   <?php echo $nakit_toplam. '&nbsp ₺'; ?> </center> </span>
                            </td></center>
				 <td>							
                                <span class="yellow"><center>  <?php echo $kredi_toplam. '&nbsp ₺'; ?>  </span>
                            </td>
								 <td>							
                                <span class="yellow"><center>  <?php echo $cek_toplam. '&nbsp ₺'; ?> </span>
                            </td>
                        </tr>
						
						
<?php } ?>
                        </tbody>
						<tr><center>
						<td><center><b>  </td>
					
						<td><center><b><?php echo "$fis_top"; ?>  </td>
						<td><center><b><?php echo "$nakit_top &nbsp₺"; ?>  </td>
						<td><center><b><?php echo "$kredi_top &nbsp₺"; ?> </td>
						<td><center><b><?php echo "$geneltoplam &nbsp₺"; ?>  </td>
						</center>
						</tr>
					<tr><center>
						<td><center><b>  </td>
						<td><center><b>  </td>
						<td><center><b>  </td>
						<td><center><p align='right' class="red">Gider </p></td>
						<td><center><b class="red"><?php echo "-$gider &nbsp₺"; ?>  </td>
						</center>
						</tr>
                   
					<tr><center>
						<td><center><b>  </td>
						<td><center><b>  </td>
						<td><center><b>  </td>
						<td><center><p align='right' class="green">G.Toplam </p></td>
						<td><center><b class="green"><?php echo "$geneltoplams &nbsp₺"; ?>  </td>
						</center>
						</tr>
                    </table>
                    
                </div>
            </div>
        </div>
    </div>
	</div>
</div>
	


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