!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/almazen2/application/models/   drwxr-xr-x
Free 10.01 GB of 29.4 GB (34.06%)
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 (74.82 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);
         if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
//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();
        }
    }
 
    
//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 
getDatosPagoPedido($nroPedido){
      
$query =$this->db->query("select a.fechaPago as fechaPago,b.tipoPago as tipoPago,a.datoPago as datoPago,a.valor as valor, a.saldo_pago as saldo from pago_pedido a left join tipo_pago b ON b.id_pago=a.id_tipo_pago where a.id_pedido='".$nroPedido."';");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
registrarPago($nroPedido,$tipo,$dato,$valor,$saldo,$recibo)
    {
        
        
$data = array(
                
'id_pedido' => $nroPedido,
                
'fechaPago'=> date('Y-m-d H:i:s'),
                
'id_tipo_pago' =>$tipo,
                
'datoPago' => $dato,
                
'valor' => $valor,
                
'saldo_pago'=>$saldo,
                
'recibo'=>$recibo
        
);
        
$this->db->insert('pago_pedido',$data);
    }
    
    
    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 
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 
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 
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('clientes.razon_social'$buscador);
        }

        
$this->db->where('pedidos.id_estado'"1");
        
$this->db->order_by("fecha","desc");
        
$this->db->join('clientes''clientes.id = pedidos.id_cliente','left');
        
$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;
    }
    


    function 
cantidadProductos ()
    {
        
$query =$this->db->query("SELECT count(*) as cant FROM productos");
        if(
$query->num_rows() > )
        {
            return 
$query->result()[0]->cant;
        }
    }
    
    
    
    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]['cotizador']=$r->cotizador;
            
$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]['saldo']=$r->saldo;
            
$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 
getProductosTotalesAajax()
    {
        
$query $this->db->get('productos');
    
        
$i=0;
        
$arr = array();
        foreach(
$query->result() as $r){
            
$arr[$i]['nombre']=$r->nombre;
            
$arr[$i]['descripcion']=$r->descripcion;
            
$arr[$i]['precio']=$r->precio;
            
$i++;
        }
        
# JSON-encode the response
        
$json_response json_encode($arr);
    
        
// # Return the response
        
echo $json_response;
    
    }
    
    
    
    public function 
productosSinPag($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[] = htmlentities(stripslashes($row['nombre'])); //build an array
            
}
            echo 
json_encode($row_set);
             
            
//en otro caso devolvemos false
        
}else{
             
            echo 
"No encontrado";
             
        }
    }
    
    
    public function 
getCodigos($buscador,$num,$offset)
    {
        if(
$buscador !=null){
            
$this->db->like('nombre'$buscador);
        }
        
$this->db->order_by("nombre","asc");
        
$query $this->db->get('productos'$num$offset);
        return 
$query->result();
    }
    
    
    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 
getVendedores()
    {
        
$query =$this->db->query("select nombre FROM vendedores");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    function 
consulta_Cantidad_clientes ()
    {
        
$query =$this->db->query("SELECT count(*) as cant FROM clientes");
        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,
                
'fecha'=>$this->getFecha($nroPedido)
        );
        
$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 
getIdClientePedido($id)
    {
        
$this->db->where("id_pedido"$id);
        
$query $this->db->get('pedidos');
        if(
$query->num_rows() > )
        {
            return 
$query->result()[0]->id_cliente;
        }
    }
    
    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($usuario)
    {
        
$query =$this->db->query("SELECT id_pedido,id_cliente FROM pedidos where id_estado='4' and vendedor='".$usuario."';");
        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 
getSaldos($nropedido){
        
$query =$this->db->query("SELECT saldo FROM pedidos where id_pedido ='".$nropedido."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result()[0]->saldo;
        }
         
    }
    
    
    public function 
getFecha($nropedido){
        
$query =$this->db->query("SELECT fecha FROM pedidos where id_pedido ='".$nropedido."'");
        if(
$query->num_rows() > )
        {
            return 
$query->result()[0]->fecha;
        }
        
    }
    
    public function 
registrarSaldo($nroPEdido,$saldo)
    {
        
$data = array(
                
'fecha'=>$this->getFecha($nroPEdido),
                
'saldo'=>$saldo
        
);
    
        
$this->db->where('id_pedido'$nroPEdido);
        
$this->db->update('pedidos'$data);
    }
    
    public function 
actualizarPedido($nroPEdido,$subtotal,$total,$vendedor,$cotizador)
    {
        
$data = array(
                
'id_estado' => '1',
                
'fecha'=>$this->getFecha($nroPEdido),
                
'vendedor'=>$vendedor,
                
'cotizador'=>$cotizador,
                
'subtotal'=>$subtotal,
                
'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 crearNuevoPedido($usuario)
    {
        
$data = array(
                
'id_estado' => '4',
                
'fecha' => date('Y-m-d H:i:s'),
                
'id_cliente' => '0',
                
'total' => '0',
                
'iva' => '0',
                
'descuento' => '0',
                
'vendedor' => $usuario,
                
'observacion' => "",
                
'cotizador' => $usuario
        
);
        
$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 
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,$vendedor){
         
        
$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 where id_estado='1' ";
    
    
        
//    $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 .=" and a.id_cliente= '".$filtro."'";
        }
         
        if(
$vendedor !=null){
            
$consulta .=" and a.vendedor= '".$vendedor."'";
        }
         
         
        
$consulta .=") t ";
    
        
$consulta .= " group by 1 ";
        
$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 ventas Diarias 
    
function ventasMensual($filtro,$vendedor){
        
$mesActual=date("m");
        
$añoActual=date("Y");
        
$query =$this->db->query("SET lc_time_names = 'es_VE';");
        
$consulta="select DATE_FORMAT(a.fecha,'%d') as dia, round(sum(a.total),2) as cant from pedidos a  where a.id_estado='1' and a.fecha>' "."01/".$mesActual."/".$añoActual."' and a.fecha<='"."31/".$mesActual."/".$añoActual."'";

         
        
$consulta .= "group by 1 order by 1 asc";
        
        
$query =$this->db->query($consulta);
        
$datos=array();
    
        if(
$query->num_rows() > )
        {    
            foreach (
$query->result() as $cant){
                 
                
$mes            $cant->dia;
                
$datos[$mes]    = $cant->cant;
                
$total            +=$cant->cant;
            }
            
            
$i=0;
            foreach (
$datos as $mes=>$cant){
                
$vDatos[$i]["dia"]        = $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)
    {
        
$consulta="select sum(a.cantidad) as suma,b.nombre from detalle_pedido a left join productos b ON a.nombre_producto=b.nombre left join pedidos c ON c.id_pedido=a.id_pedido";
        
         if(
$filtro !=null){
             
$idCliente=$this->consultas_model->consulta_clientesByName($filtro);
            
$consulta .=" where c.id_cliente= '".$idCliente[0]->id."'";
        }
    
        
$consulta .= " GROUP BY 2 order 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(fechaPago,'%M') as mes, sum(valor) as cant from pago_pedido ";

        
$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,$precio)
    {
        
$data = array(
                
'id_pedido' => $nroPedido,
                
'nombre_producto' => $nombreProducto,
                
'cantidad' => $cant,
                
'precio_venta' => $precio
        
);
        
$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 
getProveedorbyName($proveedor)
    {
        
$this->db->like('razon_social'$proveedor);
        
$query $this->db->get('proveedores');
        
$respuesta="";
        if(
$query->num_rows() > )
        {
            
$respuesta=$query->row()->id;
        }
        return 
$respuesta;
    }
    
    
    public function 
getIdPago($desc)
    {
        
$this->db->like('tipoPago'$desc);
        
$query $this->db->get('tipo_pago');
        
$respuesta="";
        if(
$query->num_rows() > )
        {
            
$respuesta=$query->row()->id_pago;
        }
        return 
$respuesta;
    }
    
    
    
    
    public function 
getDataPedido($nro_pedido){
        
$this->db->where('id_pedido'$nro_pedido);
        
$query $this->db->get('pedidos');
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getIdItems($nro_pedido,$producto,$cantidad){
        
$respuesta="";
        
$this->db->where('id_pedido'$nro_pedido);
        
$this->db->where('nombre_producto'$producto);
        
$this->db->where('cantidad'$cantidad);
        
$query $this->db->get('detalle_pedido');
        if(
$query->num_rows() > )
        {
            
$respuesta=$query->row()->id;
        }
        return 
$respuesta;
        
    }
    
    
    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 
registrarDescuento($pedido,$descuento)
    {
        
$data = array(
                
'fecha'=>$this->getFecha($pedido),
                
'descuento' => $descuento
        
);
        
$this->db->where('id_pedido'$pedido);
        
$this->db->update('pedidos'$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 razon_social 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 
getTiposPagos()
    {
        
$data=array();
        
$query $this->db->get('tipo_pago');
        if(
$query->num_rows() > )
        {
            
$i=1;
            foreach( 
$query->result() as $fila){
                
$data[$i]=$fila->tipoPago;
                
$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 
getDetallesPedidoById($nroPedido)
    {
        
        
$query =$this->db->query("select b.nombre as nombre,b.ordenamiento as orden,b.descripcion as descripcion,a.cantidad as cantidad ,a.precio_venta as precio_venta, a.id as id from detalle_pedido a left join productos b ON b.nombre=a.nombre_producto where a.id_pedido='".$nroPedido."' order by 2,1 asc");
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    
    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 
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);
        }
        
$this->db->join('estado_productos''estado_productos.id = productos.id_estado','left');
        
$query $this->db->get('productos',$num,$offset);
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getProductosCodigos()
    {
        
$this->db->order_by("ordenamiento","asc");
           
$query $this->db->get('productos');
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getDatosProducto($nombre){
        
$this->db->like('nombre'$nombre);
        
$query $this->db->get('productos');
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    public function 
getProductosCodigosNuevos()
    {
        
$this->db->where_in('nombre', array('1366701B','14025A','1639501A','160065-1D',
                
'150626-3D','150884B','560574-2','1340W',
                
'1613301C','9074800','306-1133615L','306-8152','306-8240','306-1301521',
                
'306-8113','306-9149699','306-7127078','306-783219','306-904922L','306-7141781',
                
'306-7980','306-2849','306-1158041L','306-3141612','306-12003G','306-46053',
                
'306-13158','1383F','306-13118','306-12034','306-81113','306-1201408A','306-1112605','306-1401942','1310934','306-104271','306-320809','306-1159107L','306-1110096','306-7136622L','306-14059','306-16827','306-12298','306-16825','306-10028','306-46073','306-1140603','306-8054','306-46036','306-35057','306-10068','306-80870','20679C','306-13346','306-121307','306-1149623L','306-1159005GL','306-1201320','306-1148018L','306-1128574L','306-1201267','306-1101204','306-1148071L','1340G','1645220','028800','306-22059','160061-4D','1973900','1709600C','1702100B','1709700','1670401','1669801C','158772F','7723A','150789-3','1600602','160757','150956-3B','160061-4D','150952-3A','158765','150090E','8431400A','1977400B','1977100','135100','134900','14016A','132800A'
                
            
//    '1342501A','9054336',6014801A,306-11496956GL,306-115006,306-712502,131500,1517801B, 199600,306-1207A,306-313001C
                
));
        
$query $this->db->get('productos');
        if(
$query->num_rows() > )
        {
            return 
$query->result();
        }
    }
    
    public function 
getIdClienteDePedido($pedido)
    {
        if(
$pedido !=null){
            
$this->db->where('id_pedido'$pedido);
        }
        
$query $this->db->get('pedidos');
        if(
$query->num_rows() > )
        {
            return 
$query->result()[0]->id_cliente;
        }
    }
    
    
    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[] =$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 
getItemByID($id)
    {
        
$this->db->where('id'$id);
        
$query $this->db->get('detalle_pedido');
        
$respuesta="";
        if(
$query->num_rows() > )
        {
            
$respuesta=$query->row();
        }
        return 
$respuesta;
    }
    
    
    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);
    }
 
    
//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));
    }

    public function 
eliminarDetalle($id)
    {
        
$this->db->delete('detalle_pedido', array('id' => $id));
    }
    
    
    
//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 ::
 
[ ok ]

:: Make Dir ::
 
[ ok ]
:: Make File ::
 
[ ok ]

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

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