<?php
session_name("AUTHENUSER");
session_start();
$USERNAME = $_SESSION['SES_USERNAME'];
if(!session_name("AUTHENUSER"))
	{
?>
						<script language="javascript">
						 alert("Waktu Login telah habis.Silahkan Login Kembali");
						document.location="index.php";
						</script>
<?php
	}
if(!$USERNAME)
	{
?>
						<script language="javascript">
						 alert("Harap Login Dahulu.");
						document.location="index.php";
						</script>
<?php
	}
	?>
	<?php include "common/config.php";
	include "include/head.php"; ?>
    <?php
	$act  = $_REQUEST['act'];
	$id_branch  = $_REQUEST['id_branch'];
	if($act == 3)
	{
		$delete = mysql_query("update tbl_branch set status_branch = 2,user_update  = '$USERNAME' where id_branch='$id_branch'");
		if($delete)
		{
				?>
				<script language="javascript">
                alert("Delete Branch Success");
                document.location="master_branch.php";
                </script>
				<?php
			}
			else
			{
				?>
				<script language="javascript">
                alert("Delete Branch Failed");
                document.location="master_branch.php";
                </script>
				<?php	
			}
	}
	?>
    
<body>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>

  <h1><i class="icon-cloud"></i> Dashboard</h1>
</div>

<!--<ol class="breadcrumb">
  <li><a href="#">Home</a></li>
  <li><a href="#">Bread</a></li>
  <li><a href="#">Crumbs</a></li>
  <li class="active">Example</li>
</ol>-->
          <div class="main-content">
            <div class="widget">
              <div class="alert alert-warning alert-dismissable">
                <!--<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>-->
                <i class="icon-exclamation-sign"></i> <strong>Welcome <?php echo $USERNAME; ?>!</strong>
              </div>
            </div>
            <div class="widget">
              <div class="widget-controls pull-right">
                <a href="#" class="widget-link-remove"><i class="icon-minus-sign"></i></a>
                <a href="#" class="widget-link-remove"><i class="icon-remove-sign"></i></a>
              </div>
              <h3 class="section-title first-title"><i class="icon-tasks"></i> Statistics</h3>
              <div class="row">
               <div class="col-lg-3 col-md-411 col-sm-6 text-center">
                  <div class="widget-content-blue-wrapper changed-up">
                    <div class="widget-content-blue-inner padded">
                       <div class="pre-value-block"><i class="icon-signin"></i> Sold Item</div>
                       
                       
                      <div class="value-block">
                        
                        <?php
																								$cabang1=mysql_query("SELECT kode_branch, nama_branch FROM tbl_branch WHERE status_branch='1'");
																								while($cabang11=mysql_fetch_array($cabang1))
																								{
																								?>
                        <b><?php echo $cabang11['nama_branch']; ?></b> <br>
                        <div class="value-self">
																									<?php $bulan = date('m'); $tahun = date('Y'); 
                         $sql = mysql_fetch_array(mysql_query("select count(a.id_sales) as jumlah 
																									from sales a 
																									WHERE  SUBSTRING_INDEX(a.invoice,  '/', 1)='".$cabang11['kode_branch']."'
																									AND month(a.date_update) = '$bulan' and year(a.date_update) = '$tahun' AND day(a.date_update)='".date("d")."' 
																									and a.status_sales = 1"));
                         $jumlah = $sql['jumlah'];
                         echo $jumlah;
                         ?>
                         </div>
                        <div class="value-sub">Today</div>
                        
                        <br>
                        
                        <div class="value-self">
																									<?php $bulan = date('m'); $tahun = date('Y');
                         $sql2 = mysql_fetch_array(mysql_query("select count(a.id_sales) as jumlah 
																									from sales a 
																									WHERE  SUBSTRING_INDEX(a.invoice,  '/', 1)='".$cabang11['kode_branch']."'
																									AND month(a.date_update) = '$bulan' and year(a.date_update) = '$tahun'  
																									and a.status_sales = 1"));
                         $jumlah2 = $sql2['jumlah'];
                         echo $jumlah2;
                         ?>
                         </div>
                        <div class="value-sub">This Month</div>
                        <hr>
                        <?php 
																								}
																								?>
                        
                      </div>
                     <!-- <span class="dynamicsparkline">Loading..</span>-->
                    </div>
                  </div>
                </div>
                <div class="col-lg-3 col-md-411 col-sm-6 text-center">
                  <div class="widget-content-blue-wrapper changed-up">
                    <div class="widget-content-blue-inner padded">
                       <div class="pre-value-block"><i class="icon-money"></i> Sales (USD)</div>
                      <div class="value-block">
                        <div class="value-self"><?php $bulan = date('m'); $tahun = date('Y');
						$sql = mysql_fetch_array(mysql_query("select sum(price) as jumlah from salesdetails where month(tanggal) = '$bulan' and year(tanggal) = '$tahun' and status = 1 and  	currency = 'USD'"));
						$sql1 = mysql_fetch_array(mysql_query("select IFNULL((sum(price)/IDR),0) as jumlah from salesdetails where month(tanggal) = '$bulan' and year(tanggal) = '$tahun' and status = 1 and  	currency = 'IDR'"));
						$jumlah = $sql['jumlah']+$sql1['jumlah'];
						echo number_format($jumlah, 0, ',', ',');
						
						?></div>
                        <div class="value-sub">This Month</div>
                      </div>
                     <!-- <span class="dynamicsparkline">Loading..</span>-->
                    </div>
                  </div>
                </div>
                
                <div class="col-lg-3 col-md-4 col-sm-6 text-center">
                  <div class="widget-content-blue-wrapper changed-up">
                    <div class="widget-content-blue-inner padded">
                      <div class="pre-value-block"><i class="icon-money"></i> Sales IDR</div>
                      <div class="value-block">
                        <div class="value-self"><?php $bulan = date('m'); $tahun = date('Y');
						$sql = mysql_fetch_array(mysql_query("select sum(price) as jumlah from salesdetails where month(tanggal) = '$bulan' and year(tanggal) = '$tahun' and status = 1 and  	currency = 'IDR'"));
						$sql1 = mysql_fetch_array(mysql_query("select IFNULL((sum(price)*IDR),0) as jumlah from salesdetails where month(tanggal) = '$bulan' and year(tanggal) = '$tahun' and status = 1 and  	currency = 'USD'"));
						$jumlah = $sql['jumlah']+$sql1['jumlah'];
						echo number_format($jumlah, 0, ',', ',');
						?></div>
                        <div class="value-sub">This Month</div>
                      </div>
                      <!--<span class="dynamicsparkline">Loading..</span>-->
                    </div>
                  </div>
                </div>
                <div class="col-lg-3 col-md-4 col-sm-6 text-center hidden-md">
                  <div class="widget-content-blue-wrapper changed-up">
                    <div class="widget-content-blue-inner padded">
                      <div class="pre-value-block"><i class="icon-money"></i> Gross Profit (USD)</div>
                      <div class="value-block">
                        <div class="value-self"><?php $bulan = date('m'); $tahun = date('Y');
						$sql = mysql_fetch_array(mysql_query("select sum(price)-sum(cbprice) as jumlah from salesdetails where month(tanggal) = '$bulan' and year(tanggal) = '$tahun' and status = 1 and  	currency = 'USD'"));
						$sql1 = mysql_fetch_array(mysql_query("select IFNULL((sum(price)-sum(cbprice)/IDR),0) as jumlah from salesdetails where month(tanggal) = '$bulan' and year(tanggal) = '$tahun' and status = 1 and  	currency = 'IDR'"));
						$jumlah = $sql['jumlah']+$sql1['jumlah'];
						echo number_format($jumlah, 0, ',', ',');
						?></div>
                        <div class="value-sub">This Month</div>
                      </div>
                      <!--<span class="dynamicsparkline">Loading..</span>-->
                    </div>
                  </div>
                </div>
                <div class="col-lg-3 col-md-4 col-sm-6 text-center">
                  <div class="widget-content-blue-wrapper changed-up">
                    <div class="widget-content-blue-inner padded">
                      <div class="pre-value-block"><i class="icon-money"></i>  Gross Profit (IDR)</div>
                      <div class="value-block">
                        <div class="value-self"><?php $bulan = date('m'); $tahun = date('Y');
						$sql = mysql_fetch_array(mysql_query("select sum(price)-sum(cbprice) as jumlah from salesdetails where month(tanggal) = '$bulan' and year(tanggal) = '$tahun' and status = 1 and  	currency = 'IDR'"));
						$sql1 = mysql_fetch_array(mysql_query("select IFNULL(((sum(price)-sum(cbprice))*IDR),0) as jumlah from salesdetails where month(tanggal) = '$bulan' and year(tanggal) = '$tahun' and status = 1 and  	currency = 'USD'"));
						$jumlah = $sql['jumlah']+$sql1['jumlah'];
						echo number_format($jumlah, 0, ',', ',');
						?></div>
                        <div class="value-sub">This Month</div>
                      </div>
                     <!-- <span class="dynamicbars">Loading..</span>-->
                    </div>
                  </div>
                </div>
              </div>
            </div>   
    
           <div class="row">
                <h3 class="section-title first-title"><i class="icon-table"></i> TOP Suppliers</h3>
                  <div class="widget-content-white padded glossed">
                    <div class="padded">
                      <div id="piechart"></div>
                    </div>
                    </div>
                 <h3 class="section-title first-title"><i class="icon-table"></i> Indicator Inventory</h3>
                  <div class="widget-content-white padded glossed">
                    <div class="padded">
                      <div id="piechart1"></div>
                    </div>
                    </div>
                  <h3 class="section-title first-title"><i class="icon-table"></i> Range Price Inventory</h3>
                  <div class="widget-content-white padded glossed">
                    <div id="topsellers_barchart"> 
   					</div>
                      </div>
                       <h3 class="section-title first-title"><i class="icon-table"></i> Sales Chart Monthly</h3>
                  <div class="widget-content-white padded glossed">
                    <div id="topsellers_barchart1">
                   
   					</div>
                    
                      </div>
  				</div>
			</div>

<?php include "include/foot.php"; ?>
<!-- <script src='assets/js/for_pages/dashboard.js'></script> -->

<script language="javascript">
$(function() {

  $('.dynamicsparkline').sparkline([10, 8, 5, 7, 5, 4, 1, 10, 8, 12, 7, 7, 4, 5, 8, 8, 7, 7, 11, 5, 9, 12, 7, 7, 4, 5, 8, 8], {
    type: 'line',
    lineColor: '#89b1e4',
    fillColor: '#d7e8fc'
  });

  $('.dynamicbars').sparkline([5, 6, 7, 2, 0, -4, -2, 4, 1, 10, 8, 12, 7, -2, 4, 8], {
    type: 'bar',
    barColor: '#89b1e4',
    negBarColor: '#c76868'
  });

  $(".knob").knob({
    thickness: '.05',
    font: "Open Sans",
    bgColor: "#f3eee7",
    readOnly: true
  });


  Morris.Donut({
    element: 'piechart',
    data: [
	  <?php 
	  $rangeharga="select count(*) as jumlah, nama_supplier   from (
									select id_supplier,kode_stock,barcodeno,description from inventory_diamond where status_stock=1 and id_status = 4
									union all
									select id_supplier,kode_stock,barcodeno,description from inventory_gold where status_stock=1 and id_status = 4
									union all
									select id_supplier,kode_stock,barcodeno,description from  inventory_logam where status_stock=1 and id_status = 4
									union all
									select id_supplier,kode_stock,barcodeno,description from inventory_readyitem where status_stock=1 and id_status = 4
									union all
									select id_supplier,kode_stock,barcodeno,description from inventory_cincin where status_stock=1 and id_status = 4 
									union all
									select id_supplier,kode_stock,barcodeno,description from inventory_mastura where status_stock=1 and id_status = 4
									union all
									select id_supplier,kode_stock,barcodeno,description from inventory_liontin where status_stock=1 and id_status = 4
									union all
									select id_supplier,kode_stock,barcodeno,description from inventory_kerabu where status_stock=1 and id_status = 4 
									union all
									select id_supplier,kode_stock,barcodeno,description from inventory_gkgr where status_stock=1 and id_status = 4
									union all
									select id_supplier,kode_stock,barcodeno,description from inventory_rangka where status_stock=1 and id_status = 4) a
									inner join tbl_supplier b on a.id_supplier = b.id_supplier
									group by a.id_supplier";
	  $rangeharga2=mysql_query($rangeharga);
	  while($rangeharga3=mysql_fetch_array($rangeharga2))
	  {
		  $nama_supplier  = $rangeharga3['nama_supplier'];
		  $jumlah  = $rangeharga3['jumlah'];
	  ?>
      {label: '<?php echo $nama_supplier; ?>', value: <?php echo $jumlah; ?> },
	  <?php
	  }
	  ?>
    ],
    colors: ["#3498db", "#34495e", "#1abc9c", "#34495e", "#9b59b6", "#95a5a6"],
    formatter: function (y) { return y + "%" }
  });

 Morris.Donut({
    element: 'piechart1',
    data: [
	 <?php 
	  $rangeharga="select *   from (
									select id_supplier,kode_stock,barcodeno,datediff(now(),date_update) as hari from inventory_diamond where status_stock=1 and id_status = 3
									union all
									select id_supplier,kode_stock,barcodeno,datediff(now(),date_update) as hari from inventory_gold where status_stock=1 and id_status = 3
									union all
									select id_supplier,kode_stock,barcodeno,datediff(now(),date_update) as hari from  inventory_logam where status_stock=1 and id_status = 3
									union all
									select id_supplier,kode_stock,barcodeno,datediff(now(),date_update) as hari from inventory_readyitem where status_stock=1 and id_status = 3
									union all
									select id_supplier,kode_stock,barcodeno,datediff(now(),date_update) as hari from inventory_cincin where status_stock=1 and id_status = 3
									union all
									select id_supplier,kode_stock,barcodeno,datediff(now(),date_update) as hari from inventory_mastura where status_stock=1 and id_status = 3
									union all
									select id_supplier,kode_stock,barcodeno,datediff(now(),date_update) as hari from inventory_liontin where status_stock=1 and id_status = 3
									union all
									select id_supplier,kode_stock,barcodeno,datediff(now(),date_update) as hari from inventory_kerabu where status_stock=1 and id_status = 3 
									union all
									select id_supplier,kode_stock,barcodeno,datediff(now(),date_update) as hari from inventory_gkgr where status_stock=1 and id_status = 3
									union all
									select id_supplier,kode_stock,barcodeno,datediff(now(),date_update) as hari from inventory_rangka where status_stock=1 and id_status = 3) a";
		
		$green = 1;
		$yellow = 1;
		$red = 1;
		$rangeharga2=mysql_query($rangeharga);
		while($rangeharga3=mysql_fetch_array($rangeharga2))
		{	
		$hari  = $rangeharga3['hari'];
		$fetch = mysql_fetch_array(mysql_query("select * from tbl_indicator"));
		$colorgreen = $fetch['green'];
		$colorred = $fetch['red'];
								if($hari <= $colorgreen)
								{
									
									$green = $green+1;
								}
								elseif(($hari > $colorgreen) and ($hari < $colorred))
								{
									
									$yellow = $yellow+1;
								}
								elseif($hari >= $colorred)
								{
									
									$red = $red+1;
								}
		}
		?>
       {label: 'Green', value: <?php echo $green; ?> },
	   {label: 'Yellow', value: <?php echo $yellow; ?> },
	   {label: 'Red', value: <?php echo $red; ?> },
	 
    ],
    colors: ["#2d7610", "#ddd222", "#dd2222"],
    formatter: function (y) { return y + "%" }
  });


  Morris.Bar({
    element: 'topsellers_barchart',
     data: [
	<?php
	$year = date('Y');
	$month = date('m');
	$test11 = mysql_query("select inventory, price from (select inventory, price from salesdetails where status = 1 and currency = 'USD' and month(tanggal) = '$month' and year(tanggal) = '$year'
						union all
						select inventory, (price/idr) as price from salesdetails where status = 1 and currency = 'IDR' and month(tanggal) = '$month' and year(tanggal) = '$year')a group by inventory");
	while($test22 = mysql_fetch_array($test11))
	{
		$inventory  = $test22['inventory'];
		$price  = $test22['price'];
	?>
		  {device: '<?php echo $inventory; ?>', geekbench: <?php echo $price; ?>},
	<?php
	}
	?>

    ],
	
	
    xkey: 'device',
    ykeys: ['geekbench'],
    labels: ['Geekbench'],
    barRatio: 0.4,
    xLabelAngle: 35,
    hideHover: 'auto'
  });
  
   Morris.Bar({
    element: 'topsellers_barchart1',
    data: [
	<?php
	$year = date('Y');
	$month = date('m');
	$test1 = mysql_query("select user_update, sum(price) as price from (select user_update, price from salesdetails where status = 1 and currency = 'USD' and month(tanggal) = '$month' and year(tanggal) = '$year'
						union all
						select user_update, (price/idr) as price from salesdetails where status = 1 and currency = 'IDR' and month(tanggal) = '$month' and year(tanggal) = '$year')a group by user_update");
	while($test2 = mysql_fetch_array($test1))
	{
		$user_update  = $test2['user_update'];
		$price  = $test2['price'];
	?>
		   {device: '<?php echo $user_update; ?>', geekbench: <?php echo $price; ?>},
	<?php
	}
	?>

    ],
	
	
    xkey: 'device',
    ykeys: ['geekbench'],
    labels: ['Geekbench'],
    barRatio: 0.4,
    xLabelAngle: 35,
    hideHover: 'auto'
  });

});
</script>

</body>

</html>