<?php
$usuario = $_COOKIE["usuario"];
$nivel = $_COOKIE["nivel"];
if($nivel=="Master"){$usuario="";}
if($nivel!="Master"){
	echo "<script>window.location.href='menu2.php'</script>";
}

 include("../header.php");

 include_once("../php/config.php");
 include("graficos.php");
 if($anivel=="administrador"){$usuario="";}

 //@mysql_query("update cuotas set mora=0 where mora<0") or die(mysql_error());
 
//@mysql_query("update cuotas set balance_capital=0 where balance_capital<0") or die(mysql_error());

//@mysql_query("update cuotas set balance_interes=0 where balance_interes<0") or die(mysql_error());

//@mysql_query("update cuotas set balance=mora+balance_capital+balance_interes") or die(@mysql_error());



 $sql = @mysql_query("select * from empresa") or die(mysql_error());
 
 $ventas = @mysql_query("select sum(total) as total from ventas where fecha='$hoy' and estado!='Anulada' and estado='Cerrada'") or die(mysql_error());
 $compras = @mysql_query("select sum(total) as total from compras where fecha='$hoy'") or die(mysql_error());
 $cobros = @mysql_query("select sum(monto) as total from pagos_credito where fecha='$hoy'") or die(mysql_error());
  $ingresos = @mysql_query("select sum(monto) as total from ingresos where fecha='$hoy'") or die(mysql_error());
 $vencidas = @mysql_query("select sum(total) as total from ventas where vence<='$hoy' and vence!='0000-00-00' and estado!='Anulada' and estado='Cerrada' and termino='Credito'") or die(mysql_error());
$cvencidas = @mysql_query("select count(*) as c from ventas where vence<='$hoy' and vence!='0000-00-00' and estado!='Anulada' and estado='Cerrada' and termino='Credito'") or die(mysql_error());

 $devoluciones = @mysql_query("select sum(importe) as total from devoluciones where fecha='$hoy'") or die(mysql_error());
 $gastos = @mysql_query("select sum(monto) as total from egresos where fecha='$hoy'") or die(mysql_error());
 $pedidos = @mysql_query("select sum(total) as total from ventas where fecha='$hoy' and estado='Pedido'") or die(mysql_error());
 $inventario = @mysql_query("select * from productos") or die(mysql_error());
 
 while($r000=mysql_fetch_array($inventario)){
            		if($r000["stock"]>0){
						$costo+=$r000["costo"] * $r000["stock"];
						////$impuesto+=$r["impuesto"];
						$precio+=$r000["precio"] * $r000["stock"];
					}
 }
 
 //$sql_prestamos = @mysql_query("select count(*) as prestamos from prestamos where estado_prestamo!='Anulado' and usuario like '%".$usuario."%'") or die(mysql_error());
 
 //$sql_vencidas = @mysql_query("select count(*) as vencidas from cuotas where vence='$hoy' and balance>0 and usuario like '%".$usuario."%'") or die(mysql_error());
 //$sql_atrasadas =@mysql_query("select  count(distinct(id_prestamo)) as atrasadas from cuotas where vence<'$hoy' and balance>0 and usuario like '%".$usuario."%'") or die(@mysql_error());
 
 //$sql_cobros = @mysql_query("select sum(total) as total from cobros where fecha='$hoy' and usuario like '%".$usuario."%'") or die(@mysql_error());

 $empresa = @mysql_result($sql,0,"nombre");
 $telefono = @mysql_result($sql,0,"telefono");
 $direccion = @mysql_result($sql,0,"direccion");
 $rnc = @mysql_result($sql,0,"rnc");
 
 
  
  $params = mysql_query("select * from parametros") or die(mysql_error());
  $default_menu_pos = @mysql_result($params, 0, "default_menu_pos");

?>  
<style>
.card-box {
    position: relative;
    color: #fff;
    padding: 20px 10px 40px;
    margin: 20px 0px;
	height:125px;
}
.card-box:hover {
    text-decoration: none;
    color: #f1f1f1;
}
.card-box:hover .icons i {
    font-size: 100px;
    transition: 1s;
    -webkit-transition: 1s;
}
.card-box .inner {
    padding: 5px 10px 0 10px;
}
.card-box h3 {
    font-size: 27px;
    font-weight: bold;
    margin: 0 0 8px 0;
    white-space: nowrap;
    padding: 0;
    text-align: left;
}
.card-box p {
    font-size: 15px;
}
.card-box .icons {
    position: absolute;
    top: auto;
    bottom: 5px;
    right: 5px;
    z-index: 0;
    font-size: 72px;
    color: rgba(0, 0, 0, 0.15);
}
.card-box .card-box-footer {
    position: absolute;
    left: 0px;
    bottom: 0px;
    text-align: center;
    padding: 8px 0;
    color: rgba(255, 255, 255, 0.8);
    background: rgba(0, 0, 1, 0.1);
    width: 100%;
    text-decoration: none;
}
.card-box:hover .card-box-footer {
    background: rgba(0, 0, 0, 0.3);
}
.bg-blue {
    background-color: #00c0ef !important;
}
.bg-green {
    background-color: #00a65a !important;
}
.bg-orange {
    background-color: #f39c12 !important;
}
.bg-red {
    background-color: #d9534f !important;
}

  body{
      background:#D2D2D2;
  }
  .container-fluid{
    background: white;
  }
  
    .text-verde{
	color:#4ABC06;

}

#lista-entrada::-webkit-scrollbar{
	width:7px;
}

#kardex th, td{
	font-size:9px;
}

a{
    font-size:18px;
    font-weight;bolder;
}
</style> 



 <script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script>

<div class='container-fluid'>
<div class="row">
<div class="col-sm-2">
	<div class="card-box bg-blue">
                    <div class="inner">
                        <h3>  <span id="clientes" style="font-size: 25px;"><?php echo @decimal(mysql_result($ventas, 0, "total"))?></span> </h3>
                        <p><a style="color:white; font-size:20px;" href="../pos/_nueva_venta.php"><i class="bi bi-cash-coin"></i> Venta</a></p>
                    </div>
                    <div class="icons">
                        <i class="bi bi-cash-coin" aria-hidden="true"></i>
                    </div>
                    <a href="../pos/ventas.php" class="card-box-footer">Ver ventas de hoy<i class="fa fa-arrow-circle-right"></i></a>
                </div>
</div>


<div class="col-sm-2">
<div class="card-box bg-orange">
                    <div class="inner">
                     <h3>  <span id="clientes" style="font-size: 25px;"><?php echo @decimal(mysql_result($compras, 0, "total"))?></span> </h3>

                        <p style="font-size:20px;"> Compras de hoy</p>
                    </div>
                    <div class="icons">
                        <i class="bi bi-cart" aria-hidden="true"></i>
                    </div>
                    <a href="../compras/compras.php" class="card-box-footer">Ver detalles<i class="fa fa-arrow-circle-right"></i></a>
                </div>
</div>

<div class="col-sm-2">
<div class="card-box bg-green">
                    <div class="inner">
					  <h3>  <span id="clientes" style="font-size: 25px;"><?php echo @decimal(mysql_result($pedidos, 0, "total"))?></span> </h3>

                         <p style="font-size:20px;">Prefacturas</p>
                    </div>
                    <div class="icons">
                        <i class="bi bi-coin" aria-hidden="true"></i>
                    </div>
                    <a href="../pos/pedidos.php" class="card-box-footer">Ver detalles<i class="fa fa-arrow-circle-right"></i></a>
                </div>
</div>

<div class="col-sm-2">
<div class="card-box bg-green">
                    <div class="inner">
					                     <h3>  <span id="clientes" style="font-size: 25px;"><?php echo @decimal(mysql_result($gastos, 0, "total"))?></span> </h3>

                         <p style="font-size:20px;">Gastos</p>
                    </div>
                    <div class="icons">
                        <i class="bi bi-cash-stack" aria-hidden="true"></i>
                    </div>
                    <a href="../pos/egresos.php" class="card-box-footer">Ver detalles<i class="fa fa-arrow-circle-right"></i></a>
   </div>
</div>

<div class="col-sm-2">


<div class="card-box bg-green">
                    <div class="inner">
					 <p style="font-size:20px;">Inventario</p>
                     <span id="cuotas" style="font-size: 25px;"><?php echo @decimal($costo)?></span><br>
					
                    </div>
                    <div class="icons">
                       <i class="bi bi-box-seam "  aria-hidden="true"></i> 
					
                    </div>
                    <a href="../productos/productos.php" class="card-box-footer"><span id="cuotas" style="font-size: 15px;">Valorizado <?php echo @decimal($precio)?></span></a>
   </div>
 </div>


<div class="col-sm-2">

 
</div>

</div>


<?php if($default_menu_pos=="complete"){?>
<div class="row">

<div class="col-md-3">
 <div class="panel panel-default" style="height:250px;">
   <div class="panel-body">
   <center>
     <span class="text-verde h4">PRODUCTOS AGOTADOS</span>
	 <hr>
	<div id="detalle_agotados">
	  <?php 
	  include_once 'productos_agotados.php';
	  echo "<span class='text-primary h1'>".decimal($agotados)."</span><br>";
	  /////echo "<span class='text-primary h4'><b>RD$".decimal($precio_)."</b></span>";
	 ?>
	</div>
	 <br><br>
	 <a class="text-primary" href="../inventario/agotados.php">Verificar</a>
	 
	 
   </center>
   
   </div>
 </div>

</div>




<div class="col-md-3">
 <div class="panel panel-default" style="height:250px;">
   <div class="panel-body">
   <center>
     <span class="text-verde h4">VERIFICADOR DE PRECIOS</span>
	 <hr>
	 <img src="../img/barcode.jpg" width="100" >
	 
	 <br><br>
	 <form action="" method="POST">
	 <input  type="text" id="txt_codigo" name="txt_codigo" class="form-control" placeholder="Codigo de barras..">
	
	
	 </form>
	<div id="detalle_precio">
	  <?php 
	  include_once 'check_precio.php';
	  echo "<span class='text-primary h5'>".($descripcion)."</span><br>";
	  echo "<span class='text-primary h4'><b>RD$".decimal($precio_)."</b></span>";
	 ?>
	</div>
  </center>
   
   </div>
 </div>

</div>



<div class="col-md-3">
 <div class="panel panel-default" style="height:250px;">
   <div class="panel-body">
   <center>
   <img class="icon3" src="../img/stock.jpg">
     <span class="text-verde h5">MERCANCIAS RECIBIDAS HOY</span>
	 
	 <div id="lista-entrada" class="table-responsive" style="overflow-y:scroll; height:120px">
	 
	  <?php 
	  include_once 'mercancias_recibidas.php';
	  
	 ?>
	
	 
	 
	 <br>
	
  
   </div>
   </center>
   
 </div>

</div>
</div>




<div class="col-md-3">
 <div class="panel panel-default" style="height:250px;">
   <div class="panel-body">
   <center>
   
     <span class="text-verde h5">FACTURAS VENCIDAS</span>
	 <hr>
	 <img src="../img/factura_vencida.jpg" width="150" >
	 
	 <br>
	 	<div id="detalle_precio">
	  <?php 
	  ////include_once 'ventas_vencidas.php';
	  
	  echo "<span class='text-success h4'><b>(".@mysql_result($cvencidas, 0, 'c').") RD$: ".decimal(@mysql_result($vencidas, 0, 'total'))."</b></span><br>";
	  echo "<a class='text-primary' href='../pos/vencidas.php'> Ver facturas vencidas</a></span>";
	 ?>
	</div>
	
   </center>
   
   </div>
 </div>

</div>
</div>

<?php }?>





<div class="row">


  <div class="col-md-6">
        <div class="panel panel-default">
		<div class="panel-heading">
            <span class="h5 text-info font-weight-light text-center"><center>Historico de ventas por dia </center></span>
		</div>
<div class="panel-body">
    <canvas id="myChart2" height="210">
        
        
    </canvas>
 </div> 
</div>
</div>
  <div class="col-md-6">
  <div class="panel panel-default">
		<div class="panel-heading">
             <span class="h5 text-info font-weight-light text-center"><center>Operaciones de caja</center></span>
       </div>
<div class="panel-body">  
  <canvas id="myChart1" height="250" width="360" class="chartjs-render-monitor" style="display: block;">
  
  </canvas>
  
  </div>
  
    </div>
	    </div>
		
 </div>
  </div>
<script type="text/javascript">





dias()
cobro(<?php echo @mysql_result($ingresos,0,"total")?>,<?php echo @mysql_result($gastos,0,"total")?>)
function dias(){
var ctx = document.getElementById('myChart2').getContext('2d');
var myChart = new Chart(ctx, {
    type: 'bar',
    data: {
        labels: ['Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sabado','Domingo'],
        datasets: [{
            label: 'Distribucion ventas diarias en esta semana',
            data: [<?php echo $datos["lunes"]?>, <?php echo $datos["martes"]?>, <?php echo $datos["miercoles"]?>, <?php echo $datos["jueves"]?>, <?php echo $datos["viernes"]?>, <?php echo $datos["sabado"]?>,<?php echo $datos["domingo"]?>],
            backgroundColor: [
                "#00a65a",
                "#00a65a",
               "#00a65a",
                "#00a65a1",
                "#00a65a",
                "#00a65a",
                "#00a65a"
            ],
            borderColor: [
                 "#0f4c81",
                "#0f4c81",
               "#0f4c81",
                "#0f4c81",
                "#0f4c81",
                "#0f4c81",
                "#5EB246"
            ],
            borderWidth: 0
        }]
    },
    options: {
        scales: {
            yAxes: [{
                ticks: {
                    beginAtZero: true
                }
            }]
        }
    }
});
}

function cobro(ingresos, gastos){
var ctx = document.getElementById('myChart1').getContext('2d');
var myChart = new Chart(ctx, {
    type: 'pie',
    data: {
			labels: ['Ingresos', 'Gastos'],
			datasets: [{
            label: '# Operaciones',
            data: [ingresos, gastos],
            backgroundColor: [
                "#5EB246",
                '#535b63',
                
               
            ],
            borderColor: [
                 "#5EB246",
                '#535b63',
                
                
            ],
            borderWidth: 0
        }]
    },
    options: {
        scales: {
            yAxes: [{
                ticks: {
                    beginAtZero: true
                }
            }]
        }
    }
});
}

</script>
  </div>



<!--Modal productos-->

<div class="modal" id="modalLista"  tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg"  role="document" >
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
       <label for="buscar"> Buscar </label>
        <input type="text" id="buscar" onKeyUp="mostrar()" class="form-control form-control-sm mb-2" placeholder="buscar producto...">
       <div class="table-responsive" id="lista">
         

       </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>  
<!--/Modal productos-->






<!--Modal load-->

<div class="modal" id="loading"  tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm"  role="document" >
    <div class="modal-content">

      <div class="modal-body">
       <div id="ld">
         
       </div>
      </div>
      
    </div>
  </div>
</div>  
<!--/Modal load-->


<!--/Modal aviso pago-->
<div class="modal" id="modalPago" style="opacity:3px"  tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" data-backdrop="">

  <div class="modal-dialog modal-lg"  role="document" >

    <div class="modal-content">



      <div class="modal-body">

       <div id="ld">

         <center>

         <img src="../aviso_pago.png"><br>

        

         </center>

       </div>
 <hr>
 <center>
 <a href="#" data-dismiss="modal" class="text-primary"><i class="bi bi-check"></i> De acuerdo</a>
</center>  
  </div>

      

    </div>

  </div>

</div>  

<!--/Modal aviso pago-->



<?php
   include("../footer.php");
  ?> 
</body>

</html>

<script type="text/javascript">
    
 
    $("#lb_usuario_activo").html(myUser);
     $("#lb_fecha").html(fecha_actual_normal());
     localStorage.setItem("empresa","<?php echo $empresa?>");
     localStorage.setItem("direccion","<?php echo $direccion?>");
     localStorage.setItem("telefono","<?php echo $telefono?>");
     localStorage.setItem("rnc","<?php echo $rnc?>");
	 get_compra()
     function get_compra() {
	 var hoy = moment().format('YYYY-MM-DD')
 
    var sql = "select * from compra_factoria where fecha_entrega<='" + hoy + "'"
    _enviar("../php/traer_datos.php", {
        "sql": sql
      })
      .done(function(data) {
        var rs = JSON.parse(data);
	    
        for (var i in rs.data) {

		   noti("info",rs.data[i].productor,"Produccion pendientes de pago",);

        }

      })
  }
//$("#txt_codigo").focus();
///$("#txt_codigo").select();
setTimeout(function(){
	$("#txt_codigo").val("");
	$("#detalle_precio").html("");
},5000)


estado();
 function estado(){
	 var db = localStorage.getItem("db");
   //$("#msg").html("<p>Conectando con el servidor de datos, espere unos segundos...</p>")
   $.get("http://217.71.203.122/App_planes/estado.php?db="+db,function(data,st){

     if(st=="success"){
      var datos = JSON.parse(data); 
      //alert(datos.estado);
      var estado = datos.estado;
	  ///alert(estado);
      if(estado=="inactivo"){
		   $("#modalPago").modal("show");
      }
	  
     }
   })
 }	
</script>


