!C99Shell v. 2.0 [PHP 7 Update] [25.02.2019]!

Software: Apache/2.4.18 (Ubuntu). PHP/7.0.33-0ubuntu0.16.04.16 

uname -a: Linux digifus 3.13.0-57-generic #95-Ubuntu SMP Fri Jun 19 09:28:15 UTC 2015 x86_64 

uid=33(www-data) gid=33(www-data) groups=33(www-data) 

Safe-mode: OFF (not secure)

/var/www/html/antonellaServer/application/models/   drwxr-xr-x
Free 10.13 GB of 29.4 GB (34.44%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Feedback    Self remove    Logout    


Viewing file:     Consultas_model.php (78.08 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class 
Consultas_model extends CI_Model
{
    public function 
__construct()
    {
        
parent::__construct();
    }
    
    
    
//get the username & password from tbl_usrs
    
function get_user($usr$pwd)
    {
        
$sql "select * from tbl_usrs where username = '" $usr "' and password = '" md5($pwd) . "' and status = 'active'";

        
$query $this->db->query($sql);
        return 
$query->num_rows();
    }
    
    function 
getProductosTab()
    {
         
         
$sql "select a.id_producto as id_producto,a.nombre_producto as nombre_producto,a.descripcion as descripcion,a.numero as numero, 
a.precio_ingreso as precio_ingreso, a.precio_venta as precio_venta,c.nombre as nombre,b.categoria as categoria,
e.modelo as modelo,d.stock as stock,sum(f.cantidad) as cantidad_vendida,a.imagen as imagen from productos a 
        left join categorias_productos b ON b.id=a.id_categoria 
         left join detalle_pedido f ON f.nombre_producto=a.nombre_producto        
        left join proveedores c ON c.id = a.id_proveedor 
        left join stock_productos d ON d.nombre_producto = a.nombre_producto 
        left join modelos e ON e.id = a.id_modelo
        
        group by 2 order by 2 asc"
;
         
         
$query $this->db->query($sql);
         
  
        
$i=0;
        
$arr = array();
        foreach(
$query->result() as $r){
                
$arr[$i]['id']=$r->id_producto;
                
$arr[$i]['nombre_producto']=$r->nombre_producto ;
                
$arr[$i]['descripcion']=$r->descripcion;
                
$arr[$i]['numero']=$r->numero;
                
$arr[$i]['precio_ingreso']=$r->precio_ingreso;
                
$arr[$i]['precio_venta']=$r->precio_venta;
                
$arr[$i]['proveedor']=$r->nombre;
                
$arr[$i]['categoria']=$r->categoria;
                
$arr[$i]['modelo']=$r->modelo;
                
$arr[$i]['stock']=$r->stock;
                
$arr[$i]['vendidos']=$r->cantidad_vendida;
                
$arr[$i]['imagen']=$r->imagen;
                
$i++;
        }
                    
# JSON-encode the response
        
$json_response json_encode($arr);
        
            
// # Return the response
        
echo $json_response;

    }
    function 
getPedidosTotalesAajax()
    {
    
        
$this->db->join('clientes ''pedidos.id_cliente = clientes.id','left');
        
$this->db->order_by("fecha","desc");
        
$this->db->where('id_estado'"1");
        
$query $this->db->get('pedidos');
    
        
$i=0;
        
$arr = array();
        foreach(
$query->result() as $r){
            
$arr[$i]['id_pedido']=$r->id_pedido;
            
$arr[$i]['vendedor']=$r->vendedor;
            
$arr[$i]['id']=$r->id;
            
$arr[$i]['razon_social']=$r->razon_social;
            
$fechaReal=explode(" ",$r->fecha);
            
$fecha=$fechaReal[0];
            
$fecha=date('d/m/Y',strtotime($fecha));
            
$arr[$i]['fecha']=$fecha;
            
$arr[$i]['descuento']=$r->descuento;
            
$arr[$i]['subtotal']= number_format($r->subtotal0'''.');  ;
            
$arr[$i]['total']=number_format($r->total0'''.');  ;
            
$i++;
        }
        
# JSON-encode the response
        
$json_response json_encode($arr);
    
        
// # Return the response
        
echo $json_response;
    
    }
    function 
getCatalog(){
         
$sql "select a.id_producto as id_producto,a.nombre_producto as nombre_producto,a.descripcion as descripcion,a.numero as numero, a.precio_ingreso as precio_ingreso, a.precio_venta as precio_venta,c.nombre as nombre,b.categoria as categoria, e.modelo as modelo,d.stock as stock,a.cantidad_vendida as cantidad_vendida,a.imagen as imagen from productos a 
        left join categorias_productos b ON b.id=a.id_categoria 
        left join proveedores c ON c.id = a.id_proveedor 
        left join stock_productos d ON d.nombre_producto = a.nombre_producto 
        left join modelos e ON e.id = a.id_modelo"
;
         
         
$query $this->db->query($sql);
        
        
$i=0;
        
$arr = array();
        foreach(
$query->result() as $r){
            
$arr[$i]['id']=$r->id_producto;
            
$arr[$i]['nombre']=$r->nombre_producto ;
            
$arr[$i]['descripcion']=$r->descripcion;
            
$arr[$i]['numero']=$r->numero;
            
$arr[$i]['precio_ingreso']=$r->precio_ingreso;
            
$arr[$i]['precio_venta']=$r->precio_venta;
            
$arr[$i]['proveedor']=$r->nombre;
            
$arr[$i]['categoria']=$r->categoria;
            
$arr[$i]['modelo']=$r->modelo;
            
$arr[$i]['stock']=$r->stock;
            
$arr[$i]['vendidos']=$r->cantidad_vendida;
            
$arr[$i]['imagen']=$r->imagen;
            
$i++;
        }
        
# JSON-encode the response
        
$json_response json_encode($arr);
        
        
// # Return the response
        
echo $json_response;
        
    }
    
    
    function 
getProductosPunt($id)
    {
        
        
$sql "select a.id_producto as id_producto,a.nombre_producto as nombre_producto,a.descripcion as descripcion,a.numero as numero, a.precio_ingreso as precio_ingreso, a.precio_venta as precio_venta,c.nombre as nombre,b.categoria as categoria, e.modelo as modelo,d.stock as stock,a.cantidad_vendida as cantidad_vendida,a.imagen as imagen from productos a
        left join categorias_productos b ON b.id=a.id_categoria
        left join proveedores c ON c.id = a.id_proveedor
        left join stock_productos d ON d.nombre_producto = a.nombre_producto
        left join modelos e ON e.id = a.id_modelo where a.id_producto='"
.$id."'";
        
        
$query $this->db->query($sql);

        
$i=0;
        
$arr = array();
        foreach(
$query->result() as $r){
                
$arr[$i]['id']=$r->id_producto;
                
$arr[$i]['nombre_producto']=$r->nombre_producto ;
                
$arr[$i]['descripcion']=$r->descripcion;
                
$arr[$i]['numero']=$r->numero;
                
$arr[$i]['precio_ingreso']=$r->precio_ingreso;
                
$arr[$i]['precio_venta']=$r->precio_venta;
                
$arr[$i]['proveedor']=$r->nombre;
                
$arr[$i]['categoria']=$r->categoria;
                
$arr[$i]['modelo']=$r->modelo;
                
$arr[$i]['stock']=$r->stock;
                
$arr[$i]['vendidos']=$r->cantidad_vendida;
                
$arr[$i]['imagen']=$r->imagen;
            
$i++;
        }
        
# JSON-encode the response
        
$json_response json_encode($arr);
         
        
// # Return the response
        
echo $json_response;
    
    }
    
    
//obtenemos las entradas de todos o un usuario, dependiendo
    // si le pasamos le id como argument o no
    
public function users_entrys($id false)
    {
        if(
$id === false)
        {
            
$this->db->select('u.username,u.fname,u.lname,u.register_date,e.titulo,e.entrada,e.publish_date');
            
$this->db->from('users u');
            
$this->db->join('entradas e''u.id = e.id_user');
        }else{
            
$this->db->select('u.username,u.fname,u.lname,u.register_date,e.titulo,e.entrada,e.publish_date');
            
$this->db->from('users u');
            
$this->db->join('entradas e''u.id = e.id_user');
            
$this->db->where('u.id',$id);
        }
        
$query $this->db->get();
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
 
    public function 
getcustomers(){
        
$query="select distinct c.customerName, c.addressLine1, c.city, c.state, c.postalCode, c.country, c.creditLimit from customers c order by c.customerNumber";
        
$result $mysqli->query($query) or die($mysqli->error.__LINE__);
        
        
$arr = array();
        if(
$result->num_rows 0) {
            while(
$row $result->fetch_assoc()) {
                
$arr[] = $row;
            }
        }
        
# JSON-encode the response
        
$json_response json_encode($arr);
        
        
// # Return the response
        
echo $json_response;
    }
    
//obtenemos todos los comentarios de un usuario y sus datos si le pasamos
    //un id como argumento, y si no los cogemos todos
    
public function users_coments($id false)
    {
        if(
$id === false)
        {
            
$this->db->select('u.username,c.titulo_comentario,c.comentario,c.comment_date');
            
$this->db->from('comentarios c');
            
$this->db->join('users u''c.id_user = u.id');
        }else{
            
$this->db->select('u.username,c.titulo_comentario,c.comentario,c.comment_date');
            
$this->db->from('comentarios c');
            
$this->db->join('users u''c.id_user = u.id');
            
$this->db->where('u.id',$id);
        }
        
$query $this->db->get();
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
 
    public function 
consulta_encadendada($id)
    {
        
$this->db->select('username')->from('users')->where('id >='$id)->limit(010);
        
$query $this->db->get();
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    

    public function 
registrarRetencion($retencion,$cliente,$recibo,$tipoRetencion)
    {
        
$data = array(
                
'id_cliente' => $cliente,
                
'tipoRetencion' =>$tipoRetencion,
                
'monto' => $retencion,
                
'fecha' => date('Y-m-d'),
                
'nroRecibo' => $recibo,
        );
        
$this->db->insert('retenciones',$data);
    }
    public function 
insertarStock($nombre,$stock)
    {
        
$data = array(
                
'nombre_producto' => $nombre,
                
'stock' =>$stock
        
);
        
$this->db->insert('stock_productos',$data);
    }
    
    
    
    
    public function 
borrarReg($nroPedido,$producto)
    {
        
$query =$this->db->query("delete from detalle_pedido where id_pedido='".$nroPedido."' and nombre_producto='".$producto."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
eliminarCheque($nro){
        
$query =$this->db->query("delete from cheques where nro_cheque='".$nro."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
registrarCheque($nroCheque,$cliente,$estado,$titular,$fechaVenc,$banco,$monto)
    {
        
$data = array(
                
'nro_cheque' => $nroCheque,
                
'id_cliente' => $cliente,
                
'id_estado' => $estado,
                
'titular' => $titular,
                
'fecha_vencimiento' => $fechaVenc,
                
'banco' => $banco,
                
'monto' => $monto,
        );
        
$this->db->insert('cheques',$data);
    }
    
    

    public function 
getCheques($buscador,$num,$offset)
    {

        
$consulta="cheques a left join estadoscheque b ON  a.id_estado=b.id_estado left join clientes c ON a.id_cliente=c.id ";
        
        if(
$buscador !=null){
            
$this->db->where('nro_cheque'$buscador);
        
        }    
        
$query $this->db->get($consulta$num$offset);

        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getRemitosByCliente($id)
    {
        
$query =$this->db->query("select nro_remito from remito where id_cliente='".$id."' and id_estado='1';");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getCodigos($buscador,$num,$offset)
    {
        if(
$buscador !=null){
            
$this->db->like('nombre_producto'$buscador);
        }
        
$this->db->order_by("nombre_producto","asc");
        
$query $this->db->get('productos'$num$offset);
        return 
$query->result();
    }
    
    
    
    
    public function 
getImagenesPendientes($nombreProducto,$descripcion,$categoria,$modelo,$num,$offset)
    {
        if(
$nombreProducto !=null){
            
$this->db->like('productos.nombre_producto'$nombreProducto);
        }
         
        if(
$descripcion !=null){
            
$this->db->like('productos.descripcion'$descripcion);
        }
         
        if(
$categoria !=null){
            
$this->db->like('productos.id_categoria'$categoria);
        }
    
        if(
$modelo !=null){
            
$this->db->like('productos.id_modelo'$modelo);
        }
         
        
$this->db->select('productos.id_producto,productos.nombre_producto,productos.precio_venta,productos.descripcion,stock_productos.stock,productos.imagen');
         
        
$this->db->join('stock_productos''stock_productos.nombre_producto = productos.nombre_producto','left');
        
$this->db->order_by("productos.nombre_producto","asc");
        
$this->db->where('productos.id_estado''1');
        
        
$query $this->db->get('productos'$num$offset);
        return 
$query->result();
    }
    public function 
getImagenes($nombreProducto,$descripcion,$categoria,$modelo,$num,$offset)
    {
        if(
$nombreProducto !=null){
            
$this->db->like('productos.nombre_producto'$nombreProducto);
        }
        
        if(
$descripcion !=null){
            
$this->db->like('productos.descripcion'$descripcion);
        }
        
        if(
$categoria !=null){
            
$this->db->like('productos.id_categoria'$categoria);
        }
         
        if(
$modelo !=null){
            
$this->db->like('productos.id_modelo'$modelo);
        }
        
        
$this->db->select('productos.id_producto,productos.nombre_producto,productos.precio_venta,productos.descripcion,stock_productos.stock,productos.imagen');
        
        
$this->db->join('stock_productos''stock_productos.nombre_producto = productos.nombre_producto','left');
        
$this->db->order_by("productos.nombre_producto","asc");
        
$query $this->db->get('productos'$num$offset);
        return 
$query->result();
    }
    
    public function 
productosSinPag($buscador)
    {
    
        
$this->db->select('nombre_producto');
        
$this->db->like('nombre_producto',$buscador,'after');
        
$resultados $this->db->get('productos',12);
        
//si existe algún resultado lo devolvemos
        
if($resultados->num_rows() > 0)
        {
            foreach (
$resultados->result_array() as $row){
                
$row_set[] = htmlentities(stripslashes($row['nombre_producto'])); //build an array
            
}
            echo 
json_encode($row_set);
             
            
//en otro caso devolvemos false
        
}else{
             
            echo 
"No encontrado";
             
        }
    }
    
    public function 
productosDescripcionSinPag($buscador)
    {
    
        
$this->db->select('descripcion');
        
$this->db->like('descripcion',$buscador,'after');
        
$resultados $this->db->get('productos',12);
        
//si existe algún resultado lo devolvemos
        
if($resultados->num_rows() > 0)
        {
            foreach (
$resultados->result_array() as $row){
                
$row_set[] = htmlentities(stripslashes($row['descripcion'])); //build an array
            
}
            echo 
json_encode($row_set);
             
            
//en otro caso devolvemos false
        
}else{
             
            echo 
"No encontrado";
             
        }
    }
    
    
    public function 
consulta_pedido($id)
    {
        
$query =$this->db->query("select * from pedidos where id_pedido='".$id."';");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getFacturasByCliente($id)
    {
        
$query =$this->db->query("select nro_factura from factura where id_cliente='".$id."' and id_estado='1';");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    public function 
getFacturasBByCliente($id)
    {
        
$query =$this->db->query("select nro_factura from facturaB where id_cliente='".$id."' and id_estado='1';");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    public function 
getFacturasByClienteRemito($id)
    {
        
$query =$this->db->query("select nro_factura from factura where id_cliente='".$id."';");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }

    public function 
getOrdenesCompraByClienteRemito($id)
    {
        
$query =$this->db->query("select nro_ot from ordentrabajo where id_cliente='".$id."' and id_estado='1';");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    public function 
consulta_remitos_vencidas($buscador,$num,$offset)
    {
        
$fechaInicial=date('Y-m-d');
        
$fechaFinal strtotime '-1 month' strtotime $fechaInicial ) ) ;
        
$fechaFinal date 'Y-m-d' $fechaFinal );
        
$fechaFinal="'".$fechaFinal."'";
        if(
$buscador !=null){
            
$this->db->like('nro_remito'$buscador);
        }
    
        
$query =" remito a
                left join clientes b ON a.id_cliente=b.id
                left join estadosfactura c ON c.id_estado=a.id_estado"
;
            
        
$this->db->order_by("a.fecha","asc");
        
$this->db->where('a.id_estado''1');
    
        
$this->db->where('fecha <='.$fechaFinal);
        
$query $this->db->get($query$num$offset);
    
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    
    public function 
consulta_facturas_vencidas($buscador,$num,$offset)
    {
        
$fechaInicial=date('Y-m-d');
        
$fechaFinal strtotime '-1 month' strtotime $fechaInicial ) ) ;
        
$fechaFinal date 'Y-m-d' $fechaFinal );
        
$fechaFinal="'".$fechaFinal."'";
        if(
$buscador !=null){
            
$this->db->like('nro_factura'$buscador);
        }

        
$query =" factura a
                left join clientes b ON a.id_cliente=b.id
                left join estadosfactura c ON c.id_estado=a.id_estado"
;
         
        
$this->db->order_by("a.fecha","asc");
        
$this->db->where('a.id_estado''1');
        
        
$this->db->where('fecha <='.$fechaFinal);
        
$query $this->db->get($query$num$offset);
    
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    public function 
consulta_facturas_vencidas_B($buscador,$num,$offset)
    {
        
$fechaInicial=date('Y-m-d');
        
$fechaFinal strtotime '-1 month' strtotime $fechaInicial ) ) ;
        
$fechaFinal date 'Y-m-d' $fechaFinal );
        
$fechaFinal="'".$fechaFinal."'";
        if(
$buscador !=null){
            
$this->db->like('nro_factura'$buscador);
        }
    
        
$query =" facturaB a
                left join clientes b ON a.id_cliente=b.id
                left join estadosfactura c ON c.id_estado=a.id_estado"
;
            
        
$this->db->order_by("a.fecha","asc");
        
$this->db->where('a.id_estado''1');
    
        
$this->db->where('fecha <='.$fechaFinal);
        
$query $this->db->get($query$num$offset);
    
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }

    public function 
consulta_facturas($buscador,$num,$offset)
    {
        
        if(
$buscador !=null){
            
$this->db->like('nro_factura'$buscador);
        }
         
        
        
$query ="factura a 
                left join clientes b ON a.id_cliente=b.id
                left join estadosfactura c ON c.id_estado=a.id_estado"
;
        
        
$this->db->order_by("a.fecha","desc");
        
        
$query $this->db->get($query$num$offset);

        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    public function 
consulta_nota_Credito_A($buscador,$num,$offset)
    {
         
        if(
$buscador !=null){
            
$this->db->like('nro_nota_credito'$buscador);
        }
    
         
        
$query ="notaCredito a
                left join clientes b ON a.id_cliente=b.id
                left join tipoCredito c ON c.id=a.tipo_credito"
;
         
        
$this->db->order_by("fecha","desc");
         
        
$query $this->db->get($query$num$offset);
    
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
consulta_nota_Credito_B($buscador,$num,$offset)
    {
    
        if(
$buscador !=null){
            
$this->db->like('nro_nota_credito'$buscador);
        }
    
    
        
$query ="notaCreditoB a
                left join clientes b ON a.id_cliente=b.id
                left join tipoCredito c ON c.id=a.tipo_credito"
;
    
        
$this->db->order_by("fecha","desc");
    
        
$query $this->db->get($query$num$offset);
    
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
consulta_facturasB($buscador,$num,$offset)
    {
        if(
$buscador !=null){
            
$this->db->like('nro_factura'$buscador);
        }

        
$query ="facturab a
                left join clientes b ON a.id_cliente=b.id
                left join estadosfactura c ON c.id_estado=a.id_estado"
;
         
        
$this->db->order_by("fecha","desc");
         
        
$query $this->db->get($query$num$offset);
    
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }

    public function 
consulta_remitos($buscador,$num,$offset)
    {
        if(
$buscador !=null){
            
$this->db->like('nro_remito'$buscador);
        }
    
        
$query =" remito a
                left join clientes b ON a.id_cliente=b.id
                left join estadosRemito c ON c.id_estado=a.id_estado"
;
         
        
$this->db->order_by("fecha","desc");
         
        
$query $this->db->get($query$num$offset);
    
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
detallesCuentaCorrienteByCliente($idCliente,$num,$offset)
    {
        
$query ="detalle_movimiento";
        
$this->db->order_by("id","desc");
        
$this->db->where('id_cliente'$idCliente);
        
$query $this->db->get($query$num$offset);
        return 
$query;
    }
    
    
    public function 
detallesCuentaCorrienteByProveedor($idCliente,$num,$offset)
    {
        
$query ="detalle_movimiento_proveedores";
        
$this->db->order_by("id","desc");
        
$this->db->where('id_proveedor'$idCliente);
        
$query $this->db->get($query$num$offset);
        return 
$query;
    }


    
    public function 
eliminarRegA($fra,$id)
    {
        
$query =$this->db->query("delete from detalle_factura where id_factura='".$fra."' and id_producto='".$id."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    public function 
getModelosByCategory($categoria)
    {
        
$this->db->where('idCategoria'$categoria);
        
$query $this->db->get('modelos');
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    public function 
getModelos()
    {
        
$query =$this->db->query("select modelo from modelos");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getCategorias()
    {
        
$query =$this->db->query("select categoria from categorias_productos");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    public function 
getIdCompra($fra)
    {
        
$query =$this->db->query("select idCompras from compras where nro_factura='".$fra."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
eliminarCompra($fra)
    {
        
$id=$this->getIdCompra($fra);
        
$query =$this->db->query("delete from compras where idCompras='".$id[0]->idCompras."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    public function 
eliminarRegB($fra,$id)
    {
        
$query =$this->db->query("delete from detalle_factura_b where id_factura='".$fra."' and id_producto='".$id."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    public function 
getIdDetalleRemito($remito,$id){
        
       
$query =$this->db->query("select id_detalle from detalle_remito where id_remito='".$remito."' and id_producto='".$id."'");
        
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    public function 
eliminarRegRemito($remito,$id)
    {
        
$detalle=$this->getIdDetalleRemito($remito,$id);
        
$query =$this->db->query("delete from detalle_remito where id_detalle='".$detalle[0]->id_detalle."';");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    public function 
eliminarRegOC($OC,$id)
    {
        
$query =$this->db->query("delete from detalle_oc where id_OC='".$OC."' and id_producto='".$id."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    public function 
eliminarContacto($id)
    {
        
$query =$this->db->query("delete from contactos where id='".$id."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    

    
    public function 
search_users($string,$pos_comodin)
    {
        
$this->db->like('username'$string$pos_comodin);
        
$query $this->db->get('users');
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
 
    public function 
consulta_clientes($buscador,$num,$offset)
    {
        if(
$buscador !=null){
            
$this->db->like('nombre'$buscador);
        }
        
$this->db->order_by("nombre","asc");
        
$query $this->db->get('clientes'$num$offset);
        return 
$query;
    }  
    
    public function 
consulta_clientesA($buscador,$num,$offset)
    {
        if(
$buscador !=null){
            
$this->db->like('nombre'$buscador);
        }
        
$this->db->where('iva'"Resp Inscripto");
        
$this->db->order_by("nombre","asc");
        
$query $this->db->get('clientes'$num$offset);
        return 
$query;
    }
    
    public function 
consulta_clientesB($buscador,$num,$offset)
    {
        if(
$buscador !=null){
            
$this->db->like('nombre'$buscador);
        }
        
        
$this->db->where('iva'"Monotributista");
        
$this->db->order_by("nombre","asc");
        
$query $this->db->get('clientes'$num$offset);
        return 
$query;
    }

    
    
    public function 
consulta_pedidos($buscador,$num,$offset)
    {
        if(
$buscador !=null){
            
$this->db->like('id_pedido'$buscador);
        }
        
$this->db->where('pedidos.id_estado'"1");
        
$this->db->join('clientes''clientes.id = pedidos.id_cliente','left');
        
$this->db->order_by("fecha","desc");
        
$query $this->db->get('pedidos'$num$offset);
        return 
$query;
    }
    
    
    public function 
consulta_proveedores($buscador,$num,$offset)
    {
        if(
$buscador !=null){
            
$this->db->like('nombre'$buscador);
        }
        
$this->db->order_by("nombre","asc");
        
$query $this->db->get('proveedores'$num$offset);
        return 
$query;
    }
    


    public function 
getSaldo($id)
    {
        
$query $this->db->get_where('saldos',array('id_cliente' => $id));
        if(
$query->num_rows() > )
        {
            return 
$query->row();
        }
        else{
            
$data = array(
                
'id_cliente' => $id,
                
'valor_saldo' => '0'
            
);
            
$this->db->insert('saldos',$data);
        }
    }
    
    public function 
getSaldoProveedor($id)
    {
        
$query $this->db->get_where('saldosProv',array('id_proveedor' => $id));
        if(
$query->num_rows() > )
        {
            return 
$query->row();
        }
        else{
            
$data = array(
                    
'id_proveedor' => $id,
                    
'valor_saldo' => '0'
            
);
            
$this->db->insert('saldosProv',$data);
        }
    }
    
    function 
consulta_Cantidad_clientes ()
    {
        
$query =$this->db->query("SELECT count(*) as cant FROM clientes");
        if(
$query->num_rows() > )
        {
            return 
$query->result()[0]->cant;
        }
    } 
    function 
cantidadProductosPendientes ()
    {
        
$query =$this->db->query("SELECT count(*) as cant FROM productos where id_estado='1'");
        if(
$query->num_rows() > )
        {
            return 
$query->result()[0]->cant;
        }
    }
    
    function 
cantidadProductos ()
    {
        
$query =$this->db->query("SELECT count(*) as cant FROM productos");
        if(
$query->num_rows() > )
        {
            return 
$query->result()[0]->cant;
        }
    }
    function 
consulta_cantidad_pedidos ()
    {
        
$query =$this->db->query("SELECT count(*) as cant FROM pedidos");
        if(
$query->num_rows() > )
        {
            return 
$query->result()[0]->cant;
        }
    }
    
    
    
    function 
consulta_Cantidad_clientesA ()
    {
        
$query =$this->db->query("SELECT count(*) as cant FROM clientes where iva='Resp Inscripto'");
        if(
$query->num_rows() > )
        {
            return 
$query->result()[0]->cant;
        }
    }
    
    
    
    public function  
registrarComentario($nroPedido,$comentario)
    {
        
$data = array(
                
'observacion' => $comentario,
        );
        
$this->db->where('id_pedido'$nroPedido);
        
$this->db->update('pedidos'$data);
    }
    
    public function  
cambiarEstadoPedido($nroPedido)
    {
        
$data = array(
                
'id_estado' => "2",
        );
        
$this->db->where('id_pedido'$nroPedido);
        
$this->db->update('pedidos'$data);
    }
    
    public function  
borrarPedido($nroPedido)
    {
        
$data = array(
                
'id_estado' => "3",
        );
        
$this->db->where('id_pedido'$nroPedido);
        
$this->db->update('pedidos'$data);
    }
    function 
consulta_Cantidad_proveedores()
    {
        return 
$this->db->count_all('proveedores');
    }
    
    function 
consulta_Cantidad_Transferencias()
    {
        return 
$this->db->count_all('transferencia');
    }
    
    function 
consulta_Cantidad_Cheques()
    {
        return 
$this->db->count_all('cheques');
    }
    
    
    function 
consulta_Cantidad_frasCompras($buscaProv,$filtroTipo,$fechaInicio,$fechaFinal)
    {
        
$consulta="select sum(total) as valor from compras ";
        if((
$fechaInicio!=null)||($fechaFinal != null)||($buscaProv !=null)){
            
$consulta.=" where ";
            
$habia="";
            if((
$fechaInicio!=null) &&($fechaFinal != null)){
                
$habia="1";
                
$consulta.=" fechaFactura >= '".$fechaInicio."' and fechaFactura <= '".$fechaFinal."'";
            }
             
            if(
$buscaProv !=null){
                if(
$habia==""){
                    
$consulta.= " id_proveedor= '"$buscaProv."'";
                }else{
                    
$consulta.= " and id_proveedor= '"$buscaProv."'";
                }
            }
        }
        
$query =$this->db->query($consulta);

        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    function 
getTipoCreditoByDesc($desc)
    {
        
$this->db->like("descripcion"$desc);
        
$query $this->db->get('tipocredito');
           if(
$query->num_rows() > )
        {    
            return 
$query->result();
        }
    }
    
    
    function 
consulta_Cantidad_Retenciones ($tipo,$buscador)
    {
        
$this->db->like($tipo$buscador);
        return 
$this->db->count_all('retenciones');
    }
    
    function 
consulta_cantidad_registros($id)
    {
        
$query=$this->db->query("select count(id) as cantidad from detalle_movimiento where id_cliente='".$id."';");
        if(
$query->num_rows() > )
        {    
            return 
$query->result();
        }
    }
    
    function 
consulta_cantidad_registrosProv($id)
    {
        
$query=$this->db->query("select count(id) as cantidad from detalle_movimiento_proveedores where id_proveedor='".$id."';");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    function 
consulta_Cantidad_movimientos ($cliente)
    {
        
$query =$this->db->query("SELECT count(*) as cant FROM detalle_movimiento where id_cliente='".$cliente."';");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    public function 
getRemitoByOC($nroOrden)
    {
        
$query =$this->db->query("select nro_remito from remito where nro_orden='".$nroOrden."';");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getNroOrdenByOT($nroOrden)
    {
        
$query =$this->db->query("select nro_oc from ordentrabajo where nro_ot='".$nroOrden."';");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    
    
    public function 
getNextFactura()
    {
        
$query =$this->db->query("SELECT MAX(id_factura)+1 as cant FROM factura");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getNextFacturaB()
    {
        
$query =$this->db->query("SELECT MAX(id_factura)+1 as cant FROM facturaB");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getNextRemito()
    {
        
$query =$this->db->query("SELECT MAX(nro_remito)+1 as cant FROM remito");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getClientebyId($id)
    {
        
$query =$this->db->query("SELECT nombre from clientes where id='".$id."';");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getProveedores()
    {
        
$query $this->db->get('proveedores');
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getTipoCompra()
    {
        
$query $this->db->get('tipoCompra');
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    public function 
getTipoRetByName($name)
    {
        
$this->db->like('descripcion'$name);
        
$query $this->db->get('tiporetencion');
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
 
/*   public function getTotal($factura,$cliente)
    {
        $query =$this->db->query("SELECT total FROM totales where nroFactura='".$factura. "' and id_cliente='".$cliente."';");
        if($query->num_rows() > 0 )
        {
            return $query->result();
        }
    
    }*/
    
    
public function getPedidoAbierto()
    {
        
$query =$this->db->query("SELECT id_pedido,id_cliente FROM pedidos where id_estado='4'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    
    }
    
    public function 
getNextRecibo()
    {
        
$query =$this->db->query("SELECT MAX(nro_recibo)+1 as cant FROM recibo");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    
    }
    
    public function 
getLastFactura()
    {
        
$query =$this->db->query("SELECT MAX(id_factura) as cant FROM factura");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getLastFacturaB()
    {
        
$query =$this->db->query("SELECT MAX(id_factura) as cant FROM facturaB");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }

    public function 
getTipoRetencion()
    {
    
        
$query =$this->db->query("SELECT id,descripcion FROM tipoRetencion");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    public function 
getTipoCredito()
    {
    
        
$query =$this->db->query("SELECT id,descripcion FROM tipocredito");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    
    }
    
    
    public function 
getLastCreditoB()
    {
    
        
$query =$this->db->query("SELECT MAX(nro_nota_credito) as cant FROM notaCreditoB");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    
    }
    
    public function 
getLastCredito()
    {
    
        
$query =$this->db->query("SELECT MAX(nro_nota_credito) as cant FROM notaCredito");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    
    }
    
    public function 
getLastOt()
    {
    
        
$query =$this->db->query("SELECT MAX(nro_ot) as cant FROM ordentrabajo");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    
    }
    
    public function  
getDisponible($nroOrdenCompra,$idProducto)
    {
        
$query =$this->db->query("select cant_disponible from detalle_oc where id_OC='".$nroOrdenCompra."' and id_producto='".$idProducto."';");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
actualizarCantidadOC($nroOrdenCompra,$idProducto,$cantidad)
    {

        
$cantidadAnterior=$this->getDisponible($nroOrdenCompra,$idProducto);
        
$cant=$cantidadAnterior[0]->cant_disponible+$cantidad;
        
        
$data = array(
                
'cant_disponible' => $cant,
        );
        
        
$this->db->where('id_OC'$nroOrdenCompra);
        
$this->db->where('id_producto'$idProducto);

        
$this->db->update('detalle_oc'$data);
    }
    
    function 
consulta_Cantidad_clientes_B ()
    {
        
$query =$this->db->query("SELECT count(*) as cant FROM clientes where iva='Monotributista'");
        if(
$query->num_rows() > )
        {
            return 
$query->result()[0]->cant;
        }

    }
    
    
    public function 
cancelarFactura($nro)
    {
        
$data = array(
                
'id_estado' => '3',
        );
         
        
$this->db->where('nro_factura'$nro);
        
$this->db->update('factura'$data);
    }
    
    public function 
getLastOC()
    {
        
$query =$this->db->query("SELECT MAX(nro_oc) as cant FROM ordencompra");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    
    }
    
    public function 
actualizarEstadoOc($nro,$estado)
    {
        
$data = array(
                
'id_estado_OC' => $estado
        
);
         
        
$this->db->where('nro_oc'$nro);
        
$this->db->update('ordencompra'$data);
    }
    
    
    public function 
actualizarPedido($nroPEdido,$iva,$total,$descuento,$vendedor)
    {
        
$data = array(
                
'id_estado' => '1',
                
'iva'=>$iva,
                
'fecha'=>date('Y-m-d H:i:s'),
                
'vendedor'=>$vendedor,
                
'total'=>$total,
        );
    
        
$this->db->where('id_pedido'$nroPEdido);
        
$this->db->update('pedidos'$data);
    }
    
    public function 
actualizarEstadoOR($nro,$estado)
    {
        
$data = array(
                
'id_estado' => $estado
        
);
    
        
$this->db->where('nro_ot'$nro);
        
$this->db->update('ordentrabajo'$data);
    }
    

    public function 
getNextCredito()
    {
        
$query =$this->db->query("SELECT MAX(nro_nota_credito)+1 as cant FROM notaCredito");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getNextCreditoB()
    {
        
$query =$this->db->query("SELECT MAX(nro_nota_credito)+1 as cant FROM notaCreditoB");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }

    public function 
getNextOC()
    {
        
$query =$this->db->query("SELECT MAX(nro_oc)+1 as cant FROM ordencompra");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getNextOT()
    {
        
$query =$this->db->query("SELECT MAX(nro_ot)+1 as cant FROM ordentrabajo");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getRemAcumulado($nro)
    {
        
$query =$this->db->query("SELECT monto_acumulado FROM remito where nro_remito='".$nro."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    public function 
getFraAcumulado($nro)
    {
        
$query =$this->db->query("SELECT monto_acumulado FROM factura where nro_factura='".$nro."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    public function 
getLastRemito()
    {
           
$query =$this->db->query("SELECT MAX(nro_remito) as cant FROM remito");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }

    public function 
actualizarFactura($idFra,$nroFact,$cliente,$monto,$iva,$nroCae,$fechaCae,$descuento)
    {
        
$data = array(
                
'nro_factura' => $nroFact,
                
'total' => $monto,
                
'iva' => $iva,
                
'nro_cae' => $nroCae,
                
'fecha_cae' => $fechaCae,
                
'descuento' => $descuento
        
);
         
        
$this->db->where('id_factura'$idFra);
        
$this->db->update('factura'$data);
    }
    
    public function 
actualizarNotaCredA($idFra,$nroFact,$cliente,$monto,$nroCae,$fechaCae,$descuento)
    {
        
        
$data = array(
                
'nro_nota_credito' => $nroFact,
                
'total' => $monto,
                
'descuento'=>$descuento,
                
'nro_cae' => $nroCae,
                
'fecha_cae' => $fechaCae,
        );
    
        
$this->db->where('id_nota_credito'$idFra);
        
$this->db->update('notacredito'$data);
    }
    
    public function 
actualizarNotaCredB($idFra,$nroFact,$cliente,$monto,$nroCae,$fechaCae,$descuento)
    {
         
        
$data = array(
                
'nro_nota_credito' => $nroFact,
                
'total' => $monto,
                
'nro_cae' => $nroCae,
                
'descuento'=>$descuento,
                
'fecha_cae' => $fechaCae,
        );
    
        
$this->db->where('id_nota_credito'$idFra);
        
$this->db->update('notacreditoB'$data);
    }
    
    
    
    public function 
actualizarFacturaB($idFra,$nroFact,$cliente,$monto,$nroCae,$fechaCae,$descuento)
    {
        
$data = array(
                
'nro_factura' => $nroFact,
                
'total' => $monto,
                
'nro_cae' => $nroCae,
                
'fecha_cae' => $fechaCae
        
);
        
        
$this->db->where('id_factura'$idFra);
        
$this->db->update('facturaB'$data);
    }
    
    public function 
actualizarRecibo($nroRecibo,$cliente,$monto)
    {
        
$data = array(
                
'monto' => $monto
        
);
    
        
$this->db->where('nro_recibo'$nroRecibo);
        
$this->db->update('recibo'$data);
    }
    
    public function 
registrarPagoParcialRemito($remito,$monto)
    {
        
$data = array(
                
'monto_acumulado' => $monto
        
);
    
        
$this->db->where('nro_remito'$remito);
        
$this->db->update('remito'$data);
    }
    
    public function 
registrarPagoParcial($factura,$monto)
    {
        
$data = array(
                
'monto_acumulado' => $monto
        
);
         
        
$this->db->where('nro_factura'$factura);
        
$this->db->update('factura'$data);
    }
    
    public function 
cambiarEstadoFactura($factura,$tipoNuevo)
    {
        
$data = array(
                
'id_estado' => $tipoNuevo
        
);
        
        
$this->db->where('nro_factura'$factura);
        
$this->db->update('factura'$data);
    }
    
    public function 
cambiarEstadoRemito($remito,$tipoNuevo)
    {
        
$data = array(
                
'id_estado' => $tipoNuevo
        
);
         
        
$this->db->where('nro_remito'$factura);
        
$this->db->update('remito'$data);
    }
    
  
/*  public function actualizarTotal($nroFactura,$suma,$cliente,$operacion)
    {
        $totalAnterior=$this->getTotal($nroFactura,$cliente);
        if($totalAnterior!=null){
            if($operacion=='1'){
                $totalActual=($totalAnterior[0]->total + $suma);
            }
            else{
                $totalActual=($totalAnterior[0]->total - $suma);
            }
            
            $data = array(
                    'nroFactura' => $nroFactura,
                    'total' => $totalActual,
                    'id_cliente' => $cliente
            );
            $this->db->where('nroFactura', $nroFactura);
            $this->db->where('id_cliente', $cliente);
            $this->db->update('totales', $data);
        }
        else{     

            $data = array(
                'nroFactura' => $nroFactura,
                 'total'=>$suma,
                'id_cliente' => $cliente
             );
            $this->db->insert('totales',$data);
        }

    }*/
    

    
public function crearProducto()
    {
        
$data = array(
                
'nombre_producto' => '',
                
'descripcion' => '',
                
'numero' => '0',
                
'id_categoria' => '1',
                
'id_modelo' => '1',
                
'cantidad_vendida' => '0',
                
'precio_venta'=>'0'
        
);
        
$this->db->insert('productos',$data);
    }
    
    public function 
crearNuevoPedido()
    {
        
$data = array(
                
'id_estado' => '4',
                
'fecha' => date('Y-m-d H:i:s'),
                
'id_cliente' => '0',
                
'total' => '0',
                
'iva' => '0',
                
'descuento' => '0',
                
'vendedor' => '0',
                
'observacion' => '0',
        );
        
$this->db->insert('pedidos',$data);
    }
    public function 
crearFactura($nroFactura,$cliente)
    {
        
$data = array(
                
'nro_factura' => $nroFactura,
                
'id_estado' => '1',
                
'fecha' => date('Y-m-d'),
                
'id_cliente' => $cliente,
                
'total' => '0',
                
'iva' => '0',
                
'nro_cae' => '0',
                
'fecha_cae' => '0',
                
'descuento' => '0',
                );
         
$this->db->insert('factura',$data);
    }

    
    
    public function 
crearFacturaB($nroFactura,$cliente)
    {
        
$data = array(
                
'nro_factura' => $nroFactura,
                
'id_estado' => '1',
                
'fecha' => date('Y-m-d'),
                
'id_cliente' => $cliente,
                
'nro_cae' => '0',
                
'fecha_cae' => '0',
                
'total' => '0',
        );
        
$this->db->insert('facturaB',$data);
    }
    
    public function 
crearNotaCredito($nroCredito,$cliente,$motivo,$monto)
    {
        
$data = array(
                
'nro_nota_credito' => $nroCredito,
                
'tipo_credito' => $motivo,
                
'id_estado' =>'1',
                
'fecha' => date('Y-m-d'),
                
'id_cliente' => $cliente,
                
'total' => $monto,
        );
        
$this->db->insert('notacredito',$data);
    }
    
    public function 
crearNotaCreditoB($nroCredito,$cliente,$motivo,$monto)
    {
        
$data = array(
                
'nro_nota_credito' => $nroCredito,
                
'tipo_credito' => $motivo,
                
'id_estado' =>'1',
                
'fecha' => date('Y-m-d'),
                
'id_cliente' => $cliente,
                
'descuento' => '',
                
'total' => $monto,
        );
        
$this->db->insert('notacreditoB',$data);
    }
    
    
    public function 
crearOrdenTrabajo($nroOT,$nroOC,$cliente)
    {
        
$data = array(
                
'nro_ot' => $nroOT[0]->cant,
                
'nro_oc' =>$nroOC,
                
'fecha' => date('Y-m-d'),
                
'id_cliente' => $cliente,
                
'id_estado'=>'1',
                
'descuento' => '0',
        );
        
$this->db->insert('ordentrabajo',$data);
    }
    
    
    public function 
insertarOC($nroOC,$cliente,$descuento,$refOC)
    {
        
$data = array(
                
'nro_oc' => $nroOC,
                
'id_estado_oc' => '1',
                
'refOC'=>$refOC,
                
'fecha' => date('Y-m-d'),
                
'id_cliente' => $cliente,
                
'descuento' => $descuento,
        );
        
$this->db->insert('ordencompra',$data);
    }
    
    
    
    function 
consulta_datosComerciales ($cliente)
    {
        
$query =$this->db->query("SELECT * FROM datos_comerciales where id_clientes='".$cliente."';");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    function 
hayDatosCom ($cliente)
    {
        
$query =$this->db->query("SELECT * FROM datos_comerciales where id_clientes='".$cliente."';");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    function 
getProveedores2()
    {
        
$this->db->order_by("nombre","asc");
        
$query =$this->db->get('proveedores');
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    function 
getClientes()
    {
        
$this->db->order_by("nombre","asc");
        
$query =$this->db->get('clientes');
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }

    function 
getMontoCheque($nroCheque)
    {
        
$query =$this->db->query("select monto from cheques where nro_cheque='".$nroCheque."';");
        if(
$query->num_rows() > )
        {
            return 
$query->result()[0];
        }
    }
    
    
    function 
getConfirmacionNro ($cliente)
    {
        
$query =$this->db->query("SELECT * FROM nrosoc where id_cliente='".$cliente."';");
        if(
$query->num_rows() > )
        {
            return 
$query->result()[0];
        }
    }
    
   public function 
insertarOrdenCompraReferencia($cliente,$valor){
           
           
$respuesta=$this->getConfirmacionNro($cliente);
           if(
$respuesta !=null){
               
$data = array(
                       
'id_cliente' => $cliente,
                       
'nroOC' => $valor,
               );
               
$this->db->where('id_cliente'$cliente);
               
$this->db->update('nrosOC',$data);
               
           }else{
               
$data = array(
                       
'id_cliente' => $cliente,
                       
'nroOC' => $valor,
               );
               
$this->db->insert('nrosOC',$data);
           }
   }
    
    public function 
salvarDatosCom($cliente,$cuentaCorriente,$direFact,$direEntrega,$consultaPagos,$respPagos,$respCompras)
    {
        
$datoActualXcliente=$this->hayDatosCom($cliente);
        if(
$datoActualXcliente != null){
            
//actualizo
            
$data = array(
                    
'id_clientes' => $cliente,
                    
'cuentaCorriente' => $cuentaCorriente,
                    
'direccionEntrega' =>$direEntrega ,
                    
'direccionFacturacion' => $direFact,
                    
'responsablePagos' =>$respPagos,
                    
'respCompras' => $respCompras,
            );
            
$this->db->where('id_clientes'$datoActualXcliente[0]->id_clientes);
            
$this->db->update('datos_comerciales'$data);
        }
        else{
            
//ingreso uno nuevo
            
$data = array(
                    
'id_clientes' => $cliente,
                    
'cuentaCorriente' => $cuentaCorriente,
                    
'direccionEntrega' =>$direEntrega ,
                    
'direccionFacturacion' => $direFact,
                    
'responsablePagos' =>$respPagos,
                    
'respCompras' => $respCompras,
            );
            
$this->db->insert('datos_comerciales',$data);
        }
    }
    
    public function 
crearRemito($nroRemito,$estado,$cliente,$monto,$descuento)
    {
        
$data = array(
                
'nro_remito' => $nroRemito,
                
'fecha' => date('Y-m-d'),
                
'id_estado' =>$estado,
                
'id_cliente' => $cliente,
                
'total' =>$monto,
                
'descuento' =>$descuento,
        );
        
$this->db->insert('remito',$data);
    }
    
    public function 
crearRecibo($nroRecibo,$cliente)
    {
        
$data = array(
                
'nro_recibo' => $nroRecibo,
                
'fecha' => date('Y-m-d'),
                
'id_cliente' => $cliente,
                
'monto' => '0',
                
'id_factura' => '0',
        );
        
$this->db->insert('recibo',$data);
    }
    
    
    
//consulta ventas
    
function ventas($filtro){
        
        
$query =$this->db->query("SET lc_time_names = 'es_VE';");
        
$consulta="select mes, sum(cant) as cant from (select DATE_FORMAT(a.fecha,'%M') as mes, a.total as cant from pedidos a  ";
         

    
//    $consulta .="union select DATE_FORMAT(b.fecha,'%M') as mes, b.total as cant from facturab b";
    //    $consulta .=" union select DATE_FORMAT(c.fecha,'%M') as mes, c.total as cant from remito c";
        
        
if($filtro !=null){
            
$consulta .=" where c.id_cliente= '".$filtro."'";
        }
        
        
$consulta .=") t ";
         
        
$consulta .= "group by mes order by mes desc";
        
$query =$this->db->query($consulta);
        
$datos=array();
    
        if(
$query->num_rows() > )
        {    
            foreach (
$query->result() as $cant){
                 
                
$mes            $cant->mes;
                
$datos[$mes]    = $cant->cant;
                
$total            +=$cant->cant;
            }
            
            
$i=0;
            foreach (
$datos as $mes=>$cant){
                
$vDatos[$i]["mes"]        = $mes;
                
$vDatos[$i]["porcentaje"]    = number_format(($cant/$total)*100,2);
                
$vDatos[$i]["cant"]            = $cant;
                
$i++;
            }    
            return 
$vDatos;
        }
    }

    
    
//consulta compras
    
function compras($filtro){
         
        
$query =$this->db->query("SET lc_time_names = 'es_VE';");
        
$consulta=" select DATE_FORMAT(fechaFactura,'%M') as mes, sum(total) as cant from compras ";
    
        if(
$filtro !=null){
            
$consulta .=" where id_proveedor= '".$filtro."'";
        }
    
        
$consulta .= "group by 1 order by 1 desc";
        
$query =$this->db->query($consulta);
        
$datos=array();
    
        if(
$query->num_rows() > )
        {
            foreach (
$query->result() as $cant){
    
                
$mes            $cant->mes;
                
$datos[$mes]    = $cant->cant;
                
$total            +=$cant->cant;
            }
    
            
$i=0;
            foreach (
$datos as $mes=>$cant){
                
$vDatos[$i]["mes"]        = $mes;
                
$vDatos[$i]["porcentaje"]    = number_format(($cant/$total)*100,2);
                
$vDatos[$i]["cant"]            = $cant;
                
$i++;
            }
            return 
$vDatos;
        }
    }
    
    public function 
cantidadPendientesRemito(){
         
        
$fechaInicial=date('Y-m-d');
        
$fechaFinal strtotime '-1 month' strtotime $fechaInicial ) ) ;
        
$fechaFinal date 'Y-m-d' $fechaFinal );
        
$fechaFinal="'".$fechaFinal."'";
    
        
$query =$this->db->query("SELECT count(*) as cant FROM remito where id_estado='1' and fecha <= ".$fechaFinal);
    
        if(
$query->num_rows() > )
        {
            return 
$query->result()[0]->cant;
        }
    }
    
    
    public function 
cantidadPendientes(){
        
        
$fechaInicial=date('Y-m-d');
        
$fechaFinal strtotime '-1 month' strtotime $fechaInicial ) ) ;
        
$fechaFinal date 'Y-m-d' $fechaFinal );
        
$fechaFinal="'".$fechaFinal."'";

        
$query =$this->db->query("SELECT count(*) as cant FROM factura where id_estado='1' and fecha <= ".$fechaFinal);

        if(
$query->num_rows() > )
        {
            return 
$query->result()[0]->cant;
        }
    }
    
    
    public function 
cantidadPendientesB(){
         
        
$fechaInicial=date('Y-m-d');
        
$fechaFinal strtotime '-1 month' strtotime $fechaInicial ) ) ;
        
$fechaFinal date 'Y-m-d' $fechaFinal );
        
$fechaFinal="'".$fechaFinal."'";
    
        
$query =$this->db->query("SELECT count(*) as cant FROM facturab where id_estado='1' and fecha <= ".$fechaFinal);
    
        if(
$query->num_rows() > )
        {
            return 
$query->result()[0]->cant;
        }
    }
    
    public function 
getProductosVenditos($filtro)
    {
   
/*select sum(a.id_producto) as suma,b.nombre from detalle_factura a left join productos b ON a.id_producto=b.id 

select  suma,nombre  from (
select sum(a.cantidad) as suma,a.id_producto as nombre from detalle_factura a  union  
select sum(c.cantidad) as suma,c.id_producto as nombre from detalle_factura_b c union  
select sum(e.cantidad) as suma,e.id_producto as nombre from detalle_remito e 
) t
*/
    
        
$consulta="select b.nombre_producto as nombre_producto,sum(a.cantidad) as suma from detalle_pedido a left join productos b ON a.nombre_producto=b.nombre_producto";
        
        
$consulta .= " GROUP BY 1  desc limit 20";
        
        
$query =$this->db->query($consulta);
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getConstantes(){
        
$query =$this->db->query("SELECT * FROM config;");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    function 
Cobros($filtro){
        
$query =$this->db->query("SET lc_time_names = 'es_VE';");
        
$consulta="select DATE_FORMAT(fecha,'%W%D') as mes, sum(total) as cant from pedidos where id_estado='2' ";

        
$consulta .= "group by 1 order by 1 desc";
        
        
$query =$this->db->query($consulta);
        
$datos=array();
    
        if(
$query->num_rows() > )
        {
            foreach (
$query->result() as $cant){
    
                
$mes            $cant->mes;
                
$datos[$mes]    = $cant->cant;
                
$total            +=$cant->cant;
    
            }
    
            
$i=0;
    
            foreach (
$datos as $mes=>$cant){
                
$vDatos[$i]["mes"]        = $mes;
                
$vDatos[$i]["porcentaje"]    = number_format(($cant/$total)*100,2);
                
$vDatos[$i]["cant"]            = $cant;
                
$i++;
            }
            return 
$vDatos;
        }
    }
    

    
    public function 
getTransferencias($buscador,$num$offset)
    {
        if(
$buscador !=null){
            
$this->db->like('codigo'$buscador);
        }
        
$query ="transferencia a left join clientes b ON a.id_cliente=b.id";
        
        
$this->db->order_by("fecha","desc");
        
        
$query $this->db->get($query$num$offset);

        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
registrarDetallePedido($nroPedido,$nombreProducto,$cant)
    {
        
$data = array(
                
'id_pedido' => $nroPedido,
                
'nombre_producto' => $nombreProducto,
                
'cantidad' => $cant
        
);
        
$this->db->insert('detalle_pedido',$data);
    }
    
    
    public function 
getIdNotaCredA($nro)
    {
        
$this->db->like('nro_nota_credito'$nro);
        
$query $this->db->get('notacredito');
    
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    public function 
getIdNotaCredB($nro)
    {
        
$this->db->like('nro_nota_credito'$nro);
        
$query $this->db->get('notacreditoB');
    
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
     public function 
getCompras($buscaRet,$filtroTipo,$fechaInicio,$fechaFinal)
    {
        
$fechaInicio=$fechaInicio;
        
$fechaFinal=$fechaFinal;

        
$query ="select * from compras a left join proveedores b ON a.id_proveedor=b.id";
    
        if((
$fechaInicio!=null)||($fechaFinal != null)||($buscaRet !=null)){
            
$query.=" where ";
            
$habia="";
            if((
$fechaInicio!=null) &&($fechaFinal != null)){
                
$habia="1";
                
$query.=" fechaFactura >= '".$fechaInicio."' and fechaFactura <= '".$fechaFinal."'";
            }
             
            if(
$buscaRet !=null){
                if(
$habia==""){
                    
$query.= " b.id= '"$buscaRet."'";
                }else{
                    
$query.= " and b.id= '"$buscaRet."'";
                }
                 
            }
        }
    
        
$query =$this->db->query($query);

        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getRetenciones($buscaRet,$fechaInicio,$fechaFinal)
    {
        
$fechaInicio=$fechaInicio;
        
$fechaFinal=$fechaFinal;

        
        
$query ="select * from retenciones a left join clientes b ON a.id_cliente=b.id left join tiporetencion c ON c.id=a.tipoRetencion";
         
        if((
$fechaInicio!=null)||($fechaFinal != null)||($buscaRet !=null)){
            
$query.=" where ";
            
$habia="";
            if((
$fechaInicio!=null) &&($fechaFinal != null)){
                
$habia="1";
                
$query.=" fecha >= '".$fechaInicio."' and fecha <= '".$fechaFinal."'";
            }
             
            if(
$buscaRet !=null){
                if(
$habia==""){
                    
$query.= " c.id= '"$buscaRet."'";
                }else{
                    
$query.= " and c.id= '"$buscaRet."'";
                }
                
            }
        }
 
        
$query =$this->db->query($query);
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    public function 
getTotalRetenciones($buscaRet,$fechaInicio,$fechaFinal)
    {
        
$consulta="select sum(monto) as valor from retenciones ";
        if((
$fechaInicio!=null)||($fechaFinal != null)||($buscaRet !=null)){
            
$consulta.=" where ";
            
$habia="";
            if((
$fechaInicio!=null) &&($fechaFinal != null)){
                
$habia="1";
                
$consulta.=" fecha >= '".$fechaInicio."' and fecha <= '".$fechaFinal."'";
            }
             
            if(
$buscaRet !=null){
                if(
$habia==""){
                    
$consulta.= " tipoRetencion= '"$buscaRet."'";
                }else{
                    
$consulta.= " and tipoRetencion= '"$buscaRet."'";
                }
            }
        }

        
$query =$this->db->query($consulta);

        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    

    
    
    
    public function 
getDescProductoByName($producto)
    {
        
$this->db->like('nombre'$producto);
        
$query $this->db->get('productos');
        
$respuesta="";
        if(
$query->num_rows() > )
        {
            
$respuesta=$query->row()->descripcion;
        }
        return 
$respuesta;
    }
    public function 
getTipoComprabyName($tipo)
    {
        
$this->db->like('descripcion'$tipo);
        
$query $this->db->get('tipoCompra');
        
$respuesta="";
        if(
$query->num_rows() > )
        {
            
$respuesta=$query->row()->id_tipo;
        }
        return 
$respuesta;
    }
    
    
    public function 
registrarCompra($nroFact,$tipoCompra,$comboProveedor,$fechaFacturas,$iva,$monto,$descuento){
        
$data = array(
                
'nro_factura' => $nroFact,
                
'id_estado' => '1',
                
'tipo_compra'=>$tipoCompra,
                
'total' => $monto,
                
'id_proveedor' => $comboProveedor,
                
'ivaC' => $iva,
                
'fechaActual' => date('Y-m-d'),
                
'fechaFactura' => $fechaFacturas,
                
'descuento' => $descuento    
        
);
        
$this->db->insert('compras',$data);
         
    }
    
    public function 
registrarTransferencia($codTransf,$monto,$cliente,$nroRecibo){
        
$data = array(
                
'codigo' => $codTransf,
                
'id_cliente' => $cliente,
                
'monto' => $monto,
                
'fecha' => date('Y-m-d'),
                
'nroRecibo' => $nroRecibo,
        );
        
$this->db->insert('transferencia',$data);
        
    }
    
    public function 
registrarDetalleRecibo($cliente,$descripcion,$monto,$nroRecibo,$saldoAnterior)
    {
        
        
$data = array(
                
'descripcion' => $descripcion,
                
'fecha' => date('Y-m-d'),
                
'id_cliente' => $cliente,
                
'debe' => '',
                
'haber' => $monto,
                
'saldo_anterior' => $saldoAnterior,
        );
        
$this->db->insert('detalle_movimiento',$data);
    }
    
    public function 
registrarDetalleFactura($cliente,$factura,$monto,$saldoAnterior)
    {
         
        
$data = array(
                
'descripcion' => "Venta efectuada factura Nro ".$factura,
                
'fecha' => date('Y-m-d'),
                
'id_cliente' => $cliente,
                
'debe' => $monto,
                
'haber' => '',
                
'saldo_anterior' => $saldoAnterior,
        );
        
$this->db->insert('detalle_movimiento',$data);
    }
    
    public function 
registrarDetalleFacturaB($cliente,$factura,$monto,$saldoAnterior)
    {
    
        
$data = array(
                
'descripcion' => "Venta efectuada factura B Nro ".$factura,
                
'fecha' => date('Y-m-d'),
                
'id_cliente' => $cliente,
                
'debe' => $monto,
                
'haber' => '',
                
'saldo_anterior' => $saldoAnterior,
        );
        
$this->db->insert('detalle_movimiento',$data);
    }
    
    
    public function 
registrarDetalleNotaCredA($cliente,$factura,$monto,$saldoAnterior)
    {
    
        
$data = array(
                
'descripcion' => "Nota de Credito Tipo A ".$factura,
                
'fecha' => date('Y-m-d'),
                
'id_cliente' => $cliente,
                
'debe' => '',
                
'haber' =>$monto,
                
'saldo_anterior' => $saldoAnterior,
        );
        
$this->db->insert('detalle_movimiento',$data);
    }
    
    public function 
registrarDetalleNotaCredB($cliente,$factura,$monto,$saldoAnterior)
    {
    
        
$data = array(
                
'descripcion' => "Nota de Credito Tipo B ".$factura,
                
'fecha' => date('Y-m-d'),
                
'id_cliente' => $cliente,
                
'debe' => '',
                
'haber' =>$monto,
                
'saldo_anterior' => $saldoAnterior,
        );
        
$this->db->insert('detalle_movimiento',$data);
    }
   
    
    public function 
registrarMovRemito($cliente,$remito,$monto,$saldoAnterior)
    {
    
        
$data = array(
                
'descripcion' => "Venta efectuada Remito Nro ".$remito,
                
'fecha' => date('Y-m-d'),
                
'id_cliente' => $cliente,
                
'debe' => $monto,
                
'haber' => '',
                
'saldo_anterior' => $saldoAnterior,
        );
        
$this->db->insert('detalle_movimiento',$data);
    }
    
    public function  
registrarDetalleOrdenReferencia($cantidad,$nroOT,$producto,$cliente,$nuevaCantidad,$orden)
    {
    
        
$data = array(
                
'id_ot' => $nroOT,
                
'id_cliente' => $cliente,
                
'id_producto' => $producto,
                
'cantidad' => $cantidad
        
);
        
$this->db->insert('detalle_orden_trabajo',$data);
        

        
$data = array(
                
'cant_disponible' => $nuevaCantidad
        
);
        
$this->db->where('id_producto'$producto);
        
$this->db->where('id_OC'$orden);
        
$this->db->update('detalle_oc'$data);
    }

    

    public function 
registrarDetalleOC($nroOC,$producto,$cantidad,$cliente)
    {
        
        
$data = array(
                
'id_OC'       =>   $nroOC,
                
'id_producto'         =>   $producto,
                
'id_cliente'          =>   $cliente,
                
'cantidad'          =>   $cantidad,
                
'cant_disponible'          =>   $cantidad
        
);
        
$this->db->insert('detalle_OC',$data);
        
    }
    
    public function 
registrarDetalleRemito($nroRemito,$producto,$cantidad,$cliente,$descuento)
    {
         
        
$data = array(
                
'id_remito'       =>   $nroRemito,
                
'id_producto'         =>   $producto,
                
'id_cliente'          =>   $cliente,
                
'cantidad'          =>   $cantidad,
                
'descuento' =>$descuento
        
);
        
$this->db->insert('detalle_remito',$data);
    }
    
    
    public function 
ingresaContacto($cliente,$nombre,$mail,$interno,$depto)
    {
    
        
$data = array(
                
'id_clientes' => $cliente,
                
'nombre' =>$nombre,
                
'mail' => $mail,
                
'interno' => $interno,
                
'depto' => $depto
        
);
        
$this->db->insert('contactos',$data);
    }

    
    
    
    public function 
actualizarClientePedido($pedido,$cliente)
    {

        
$data = array(
                
'id_cliente' => $cliente
        
);
        
$this->db->where('id_pedido'$pedido);
        
$this->db->update('pedidos'$data);
    }
    
    public function 
actualizarSaldo($cliente,$monto,$operacion)
    {
        
$saldo=$this->getSaldo($cliente);
        if(
$operacion =='1'){
            
$saldoFinal=($saldo->valor_saldo $monto);
        }
        
        if(
$operacion =='2'){
            
$saldoFinal=($saldo->valor_saldo $monto);
        }

        
$data = array(
                
'id_cliente' => $cliente,
                
'valor_saldo' => $saldoFinal
        
);
        
$this->db->where('id_cliente'$cliente);
        
$this->db->update('saldos'$data);
    }
    
    
    public function 
chequearID($cliente)
    {
        
$usuario=$this->get($cliente);
    
        
$saldoFinal=($saldo->valor_saldo-$monto);
         
        
$data = array(
                
'id_cliente' => $cliente,
                
'valor_saldo' => $saldoFinal
        
);
        
$this->db->where('id_cliente'$cliente);
        
$this->db->update('saldos'$data);
    }
    
   public function 
getCliente($id)
    { 
        
$query =$this->db->query("select id_cliente from saldos where id_cliente='".$id."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    public function 
getTotalByIdFactura($factura)
    {
        
$query =$this->db->query("select total from factura where nro_factura='".$factura."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getTotalByIdRemito($remito)
    {
        
$query =$this->db->query("select total from remito where nro_remito='".$remito."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    

    
    public function 
insertarClienteSaldo($id)
    {
         
        
$data = array(
                
'id_cliente'       =>   $id,
                
'valor_saldo'         =>   '0'
        
);
        
$this->db->insert('saldos',$data);
    
    }
    
    
    
    
    public function 
consulta_pedidosById($id)
    {
        
$query =$this->db->query("select * from pedidos where id_pedido='".$id."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    public function 
consulta_clientesById($id)
    {
         
$query =$this->db->query("select * from clientes where id='".$id."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
consulta_ProveedoresById($id)
    {
        
$query =$this->db->query("select * from proveedores where id='".$id."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
consulta_clientesByName($name)
    {
        
$query =$this->db->query("select id from clientes where nombre LIKE '".'%'.$name.'%'."';");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    public function 
consulta_clientesSaldos($id)
    {
        
$cliente=$this->getCliente($id);
        if(
$cliente==null){
            
$this->insertarClienteSaldo($id);
        }
    }
    
    public function 
getSiyaEntro($producto,$ordenRef){
        
$query =$this->db->query("select id_producto,nro_Referencia from detalle_factura where id_producto='".$producto."' and nro_Referencia='".$ordenRef."';");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
registrarDetalleFactaura($nroFactura,$producto,$cantidad,$cliente,$descuento)
    {
        
        
$data = array(
                
'id_factura'       =>   $nroFactura,
                
'id_producto'   =>   $producto,
                
'id_cliente'   =>   $cliente,
                
'cantidad'     =>   $cantidad,
                
'descuento'   =>$descuento
        
);
        
$this->db->insert('detalle_factura',$data);
    }
    
    public function 
registrarDetalleFactauraB($nroFactura,$producto,$cantidad,$cliente,$iva,$descuento)
    {
        
$data = array(
                
'id_factura'       =>   $nroFactura,
                
'id_producto'   =>   $producto,
                
'id_cliente'   =>   $cliente,
                
'cantidad'     =>   $cantidad,
                
'iva'     =>   $iva,
                
'descuento'   =>$descuento
        
);
        
$this->db->insert('detalle_factura_b',$data);
         
    }
    
    
    public function 
getDescByProducto($producto)
    {
        
$query =$this->db->query("select id,descripcion from productos where nombre='".$producto."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    public function 
getTipoMensajeCredito($motivo)
    {
        
$query =$this->db->query("select descripcion from tipocredito where id='".$motivo."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getDescByNameDescByID($id)
    {
        
$query =$this->db->query("select nombre,descripcion from productos where id='".$id."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getDescuentos()
    {
        
$data=array();
        
$query $this->db->get('descuentos');
        if(
$query->num_rows() > )
        {
            
$i=1;
            foreach( 
$query->result() as $fila){
                
$data[$i]=$fila->descripcion;
                
$i++;
            }
        }
        return 
$data;
    }

    
    public function 
getIDByProducto($producto)
    {
    
        
$this->db->like('nombre'$producto);
        
$query $this->db->get('productos');
        
$respuesta="";
        if(
$query->num_rows() > )
        {
            
$respuesta=$query->row()->id;
        }
        return 
$respuesta;
    }
    
    
    public function 
getCategoriabyName($categoria)
    {
    
        
$this->db->like('categoria'$categoria);
        
$query $this->db->get('categorias_productos');
        
$respuesta="";
        if(
$query->num_rows() > )
        {
            
$respuesta=$query->row()->id;
        }
        return 
$respuesta;
    }

    public function 
getModelobyName($modelo)
    {
    
        
$this->db->like('modelo'$modelo);
        
$query $this->db->get('modelos');
        
$respuesta="";
        if(
$query->num_rows() > )
        {
            
$respuesta=$query->row()->id;
        }
        return 
$respuesta;
    }
    
    public function 
getProveedorbyName($proveedor)
    {
    
        
$this->db->like('nombre'$proveedor);
        
$query $this->db->get('proveedores');
        
$respuesta="";
        if(
$query->num_rows() > )
        {
            
$respuesta=$query->row()->id;
        }
        return 
$respuesta;
    }
    
    public function 
getDetallesPedidoById($nroPedido)
    {
        
        
$query =$this->db->query("select b.nombre_producto as nombre,b.descripcion as descripcion,a.cantidad as cantidad ,b.precio_venta as precio from detalle_pedido a left join productos b ON b.nombre_producto =a.nombre_producto where a.id_pedido='".$nroPedido."' order by 2 asc");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    
//FUNCIÓN PARA INSERTAR LOS DATOS DE LA IMAGEN SUBIDA
    
function subir($id,$imagen)
    {
        
$data = array(
                
'imagen' => $imagen
        
);
        
        
$this->db->where('id_producto'$id);
        
$this->db->update('productos'$data);
    }
    
    function 
actualizarProducto($idproducto,$nombre,$descripcion,$precio_compra,$precio_venta,$numero,$idCat,$idMod,$idProv){
        
$data = array(
                
'nombre_producto' => $nombre,
                
'descripcion' => $descripcion,
                
'precio_ingreso' => $precio_compra,
                
'precio_venta' => $precio_venta,
                
'numero' => $numero,
                
'id_categoria' => $idCat,
                
'id_modelo' => $idMod,
                
'id_proveedor' => $idProv
        
);
         
        
$this->db->where('id_producto'$idproducto);
        
$this->db->update('productos'$data);
    }
    
    
    public function 
getNextPedido()
    {
        
$query =$this->db->query("SELECT MAX(id_pedido)+1 as cant FROM pedidos");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getNextProducto()
    {
        
$query =$this->db->query("SELECT MAX(id_producto)+1 as cant FROM productos");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getDetallesByIdB($id)
    {
        
$query =$this->db->query("select * from detalle_pedido a left join productos b ON b.nombre=a.nombre_producto where a.id_pedido='".$id."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    
    public function  
getDetallesByIdOT($nroOT,$idCliente)
    {
        
$query =$this->db->query("select b.id as id,b.nombre as nombre,b.descripcion as descripcion,a.cantidad as cantidad,b.precio_venta as precio from detalle_orden_trabajo a left join productos b ON b.id=a.id_producto where a.id_ot='".$nroOT."' and a.id_cliente='".$idCliente."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }

    public function 
getDetallesRemito($remito)
    {
        
$query =$this->db->query("select a.id_detalle as id,b.nombre as nombre,b.descripcion as descripcion,a.cantidad as cantidad,b.precio_venta as precio from detalle_remito a left join productos b ON b.id=a.id_producto where a.id_remito='".$remito."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    public function 
consulta_OtByEstadoCant($estado){
        
$query =$this->db->query("select count(nro_ot) as cant from ordentrabajo  where id_estado='".$estado."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result()[0]->cant;
        }
         
    }
    
    public function 
getDetallesByIdOC($nroOC,$idCliente)
    {
        
$query =$this->db->query("select b.id as id,b.nombre as nombre,b.descripcion as descripcion,a.cantidad as cantidad,b.precio_venta as precio,a.cant_disponible from detalle_OC a left join productos b ON b.id=a.id_producto where a.id_OC='".$nroOC."' and a.id_cliente='".$idCliente."'");

        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getDetallesRemitoById($nroRemito,$idCliente)
    {
        
$query =$this->db->query("select a.id_detalle as id,b.id as idProducto,b.nombre as nombre,b.precio_venta as precio,a.descuento as descuento,b.descripcion as descripcion,a.cantidad as cantidad from detalle_remito a left join productos b ON b.id=a.id_producto where a.id_remito='".$nroRemito."' and a.id_cliente='".$idCliente."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getDetallesByFra($nroFactura)
    {
        
$query =$this->db->query("select b.id as id,b.nombre as nombre,b.descripcion as descripcion,a.cantidad as cantidad,b.precio_venta as precio from detalle_factura a left join productos b ON b.id=a.id_producto where a.id_factura='".$nroFactura."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getDetallesByFraB($nroFactura)
    {
        
$query =$this->db->query("select b.id as id,b.nombre as nombre,b.descripcion as descripcion,a.cantidad as cantidad,b.precio_venta as precio from detalle_factura_b a left join productos b ON b.id=a.id_producto where a.id_factura='".$nroFactura."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getDetallesByOC($nroFactura)
    {
        
$query =$this->db->query("select b.id as id,b.nombre as nombre,b.descripcion as descripcion,a.cantidad as cantidad from detalle_oc a left join productos b ON b.id=a.id_producto where a.id_oc='".$nroFactura."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
  
    public function 
getDetallesByOT($nroOT)
    {
        
$query =$this->db->query("select b.id as id,b.nombre as nombre,b.descripcion as descripcion,a.cantidad as cantidad from detalle_orden_trabajo a left join productos b ON b.id=a.id_producto where a.id_ot='".$nroOT."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getProductosByPrecio($producto)
    {
        
$this->db->like('nombre'$producto);
        
$query $this->db->get('productos');
        
$respuesta="";
        if(
$query->num_rows() > )
        {
            
$respuesta=$query->row()->precio_venta;
        }
        return 
$respuesta;
    }
    
    public function 
getProductos($buscador,$num,$offset)
    {
        if(
$buscador !=null){
            
$this->db->like('nombre'$buscador);
        }
        
$query $this->db->get('productos',$num,$offset);
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }

    public function 
getClientePedido($buscador)
    {
        if(
$buscador !=null){
            
$this->db->like('razon_social'$buscador);
        }
        
$query $this->db->get('clientes');
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getClientesExistentes($buscador,$num,$offset)
    {
        if(
$buscador !=null){
            
$this->db->like('razon_social'$buscador);
        }
        
$query $this->db->get('clientes',$num,$offset);
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    public function 
getProductosBuscador($buscador)
    {
    
        
$this->db->select('nombre');
        
$this->db->like('nombre',$buscador,'after');
        
$resultados $this->db->get('productos',12);
        
//si existe algún resultado lo devolvemos
        
if($resultados->num_rows() > 0)
        {
            foreach (
$resultados->result_array() as $row){
                
$row_set[] =$row['nombre']; //build an array
            
}
            echo 
json_encode($row_set);
             
            
//en otro caso devolvemos false
        
}else{
             
            echo 
"No encontrado";
             
        }
    }
    

    public function 
consulta_clientesASinPag($buscador)
    {
    
        
$this->db->select('razon_social');
        
$this->db->like('razon_social',$buscador,'after');
        
$resultados $this->db->get('clientes',10);
        
//si existe algún resultado lo devolvemos
        
if($resultados->num_rows() > 0)
        {
            foreach (
$resultados->result_array() as $row){
                
$row_set[] = htmlentities(stripslashes($row['razon_social'])); //build an array
            
}
            echo 
json_encode($row_set);
             
            
//en otro caso devolvemos false
        
}else{
             
            echo 
"No encontrado";
             
        }
    }
    
    public function 
getNameByID($producto)
    {
        
$this->db->where('id'$producto);
        
$query $this->db->get('productos');
        
$respuesta="";
        if(
$query->num_rows() > )
        {
            
$respuesta=$query->row()->nombre;
        }
        return 
$respuesta;
    }
    
    public function 
getDescripcionByPrecio($producto)
    {
        
$this->db->where('id'$producto);
        
$query $this->db->get('productos');
        
$respuesta="";
        if(
$query->num_rows() > )
        {
            return 
$respuesta=$query->row()->descripcion;
        }
    }
    

    public function 
getProductosByName()
    {
        
        
$data=array();
        
$query $this->db->get('productos');
        if(
$query->num_rows() > )
        {
            
$i=1;
            foreach( 
$query->result() as $fila){
                
$data[$i]=$fila->nombre;
                 
$i++;
            }
        }
        return 
$data;
    }
    
    public function 
getDescripcionProductosByName($nombre)
    {
        
$this->db->like('nombre'$producto);
        
$query $this->db->get('productos');
        
$respuesta="";
        if(
$query->num_rows() > )
        {
            
$respuesta=$query->row()->descripcion;
        }
        return 
$respuesta;
    }
    
    public function 
getIdProductosByName($nombre)
    {
        
$this->db->like('nombre'$producto);
        
$query $this->db->get('productos');
        
$respuesta="";
        if(
$query->num_rows() > )
        {
            
$respuesta=$query->row()->id;
        }
        return 
$respuesta;
    }
    
    
//contamos todos los resultados de la tabla
    //que pasemos como argumento
    
public function count_results($table)
    {
        return 
$this->db->count_all_results($table);
    }
    
    public function 
getCantProductos()
    {
        return 
$this->db->count_all_results('productos');
    }
    
    public function 
getCantPedidos()
    {
        return 
$this->db->count_all_results('pedidos');
    }
    
    
//obtenemos un usuario dependiendo del id que le pasemos
    
public function consulta_get_where($id)
    {
        
$query $this->db->get_where('users',array('id' => $id));
        if(
$query->num_rows() > )
        {
            
//veamos que sólo retornamos una fila con row(), no result()
            
return $query->row();
        }
    }
    
    
//insertamos un nuevo usuario en la tabla users
    
public function insert_user()
    {
        
$data = array(
            
'username'       =>   'Juan68',
            
'fname'          =>   'Juan',
            
'lname'          =>   'Pérez',
            
'register_date'  =>    '2013-01-19 10:00:00'
            
);
            
$this->db->insert('users',$data);
    }
   
    
//eliminamos al usuario con id = 1
    
public function delete_user()
    {
        
$this->db->delete('users', array('id' => 1));
    }

    
//actualizamos los datos del usuario con id = 3
    
public function update_user()
    {
        
$data = array(
            
'username' => 'silvia',
            
'fname' => 'madrejo',
            
'lname' => 'sánchez'
        
);
        
$this->db->where('id'3);
        
$this->db->update('users'$data);
    }
}
/*
 * end of application/models/consultas_model.php
 */

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ Read-Only ]

:: Make Dir ::
 
[ Read-Only ]
:: Make File ::
 
[ Read-Only ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.0 [PHP 7 Update] [25.02.2019] maintained by KaizenLouie | C99Shell Github | Generation time: 0.0165 ]--