<?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());
 $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 inventario") or die(mysql_error());
 
 while($r000=mysql_fetch_array($inventario)){
            		if($r000["cantidad"]>0){
						$costo+=$r000["costo"] * $r000["cantidad"];
						////$impuesto+=$r["impuesto"];
						$precio+=$r000["precio"] * $r000["cantidad"];
					}
 }
 
 
  $params = mysql_query("select * from parametros") or die(mysql_error());
  $default_menu_pos = mysql_result($params, 0, "default_menu_pos");

 
 //$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");
?>  



 <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="panel panel-primary">
		    <div class="panel-heading">
				
				<i class="bi bi-graph-up-arrow " style="font-size: 45px;"></i> 
        <span id="clientes" style="font-size: 25px;"><?php echo @decimal(mysql_result($ventas, 0, "total"))?></span>
        <br><strong>VENTAS DEL DIA</strong>
 <hr>
     <a href="../pos/ventas.php" style="color:white;">Ver ventas</a>
   <a href="../pos/_nueva_venta.php" class="pull-right" style="color:white;">Facturar</a>
  </div>

				
				
				</div>
		
</div>


<div class="col-sm-2">
  <div class="panel panel-success" >
        <div class="panel-heading" style="background: #5EB246;color:white">
        
        <i class="bi bi-cart-check " style="font-size: 45px;"></i> 
        <span id="prestamos" style="font-size: 25px;"><?php echo @decimal(mysql_result($compras, 0, "total"))?></span>
        
        <br> <strong>COMPRAS DEL DIA</strong>
 

 <hr>
     <a href="../compras/compras.php" style="color:white;"> Ver compras
     <i class="glyphicon glyphicon-circle-arrow-right pull-right" style="font-size: 20px;"></i></a>
  
 </div>
        
        
        </div>
</div>

<div class="col-sm-2">
	<div class="panel panel-danger">
        <div class="panel-heading" style="background:  #b10102;color:white">
       
        <i class="bi bi-cash-coin " style="font-size: 45px;"></i> 
        <span id="cobros" style="font-size: 25px;"><?php echo @decimal(mysql_result($cobros, 0, "total"))?></span>
       
        <br><strong>PAGOS DE CREDITO</strong>
<hr>
     <a href="../pos/ingresos.php" style="color:white;"> Ver pagos
     <i class="glyphicon glyphicon-circle-arrow-right pull-right" style="font-size: 20px;"></i></a>
  </div>

        
        
        </div>
</div>

<div class="col-sm-2">
	<div class="panel panel-warning">
        <div class="panel-heading" style="background:   #4f5e6d;color:white">
        
        <i class="bi bi-graph-down-arrow" style="font-size: 45px;"></i> 
        <span id="cuotas" style="font-size: 25px;"><?php echo @decimal(mysql_result($gastos, 0, "total"))?></span>
       
        <br><strong>GASTOS DE HOY</strong>
<hr>
     <a href="../pos/egresos.php" style="color:white;"> Ver gastos
     <i class="glyphicon glyphicon-circle-arrow-right pull-right" style="font-size: 20px;"></i></a>
  </div>

        
        
        </div>
</div>

<div class="col-sm-2">
	<div class="panel panel-warning">
        <div class="panel-heading" style="background:   #4f5e6d;color:white">
        
        <i class="bi bi-box-seam " style="font-size: 45px;"></i> 
        <span id="cuotas" style="font-size: 25px;"><?php echo @decimal($costo)?></span><br>
       <span id="cuotas" style="font-size: 15px;">Valorizado <?php echo @decimal($precio)?></span>

        <br><strong>COSTO DE INVENTARIO</strong>
<hr>
     <a href="../inventario/inventario.php" style="color:white;"> Ir a invnetario
     <i class="glyphicon glyphicon-circle-arrow-right pull-right" style="font-size: 20px;"></i></a>
  </div>

        
        
        </div>
</div>

<div class="col-sm-2">
	<div class="panel panel-warning">
        <div class="panel-heading" style="background:   #4f5e6d;color:white">
        
        <i class="bi bi-save2 " style="font-size: 45px;"></i> 
        <span id="cuotas" style="font-size: 25px;"><?php echo @decimal(mysql_result($pedidos, 0, "total"))?></span>
       
        <br><strong>PEDIDOS</strong>
<hr>
     <a href="../pos/pedidos.php" style="color:white;"> Ver pedidos
     <i class="glyphicon glyphicon-circle-arrow-right pull-right" style="font-size: 20px;"></i></a>
  </div>

        
        
        </div>
</div>

</div>
</div>









<div class="row">
  <div class="col-md-6">
        
            <span class="h5 text-info font-weight-light text-center"><center>Historico de ventas por dia </center></span>

    <canvas id="myChart2" height="210">
        
        
    </canvas>
 </div> 

  <div class="col-md-6">
             <span class="h5 text-info font-weight-light text-center"><center>Operaciones de caja</center></span>

  <canvas id="myChart1" height="250" width="360" class="chartjs-render-monitor" style="display: block;">
  
  </canvas>
  </div>
  
    </div>
<script type="text/javascript">





dias()
cobro(100,200,300)
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: [
                "#0f4c81",
                "#0f4c81",
               "#0f4c81",
                "#0f4c81",
                "#0f4c81",
                "#0f4c81",
                "#5EB246"
            ],
            borderColor: [
                 "#0f4c81",
                "#0f4c81",
               "#0f4c81",
                "#0f4c81",
                "#0f4c81",
                "#0f4c81",
                "#5EB246"
            ],
            borderWidth: 0
        }]
    },
    options: {
        scales: {
            yAxes: [{
                ticks: {
                    beginAtZero: true
                }
            }]
        }
    }
});
}

function cobro(abono,redito,mora){
var ctx = document.getElementById('myChart1').getContext('2d');
var myChart = new Chart(ctx, {
    type: 'pie',
    data: {
        labels: ['Ingresos', 'Egresos', 'Ventas'],
        datasets: [{
            label: '# of Votes',
            data: [abono, redito, mora],
            backgroundColor: [
                "#5EB246",
                '#535b63',
                '#f6cc47'
               
            ],
            borderColor: [
                 "#5EB246",
                '#535b63',
                '#f6cc47'
                
            ],
            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-->


<?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",);

        }

      })
  }
	
</script>


