<?php

class Consultazione_fatture_model extends CI_Model {

    public function __construct() {
        $this->load->helper('file');
        parent::__construct();
    }
    
    public function get_articoli($param) {
        $DB2 = $this->load->database('default', TRUE);

        $query = "SELECT *
        FROM   artar00f 
        where ARCA17 = '1'";
        if (!is_null($param) || !empty($param)) {
            $param = strtoupper(trim($param));
            $query .= " AND trim(ARCDA) = '$param' ";
        }

        //echo $query;
        $risultato = $DB2->query($query);
        return $risultato->row();
    }

    public function get_clienti($conto = "", $rag_soc = "", $ind = "", $piva = "", $attivo = "") {
        $DB2 = $this->load->database('default', TRUE);
        $query = "SELECT COCONT,CORAGS, CONCAT(CONCAT(CONCAT(CONCAT(COINDX,COINDY),COLOC1),COLOC2),COPROV) AS INDIRIZZO, COPIVA,COCA17"; //CLSAL,CLSCA
//        $query = "SELECT *";
        $query .= " FROM ANACO00F";
        //$query .= " LEFT JOIN ALISC00F ON CLCLI=COCONT";
        $query .= " WHERE COMAST = " . MASTRO_CLIENTI;
        $query .= " AND COAGEN='" . $this->ion_auth->user()->row()->username . "'";
        $query .= " AND CORAGS not like '*%'";
        if ($conto != '') {
            $query .= " AND COCONT = '" . trim($conto) . "'";
        }
        if ($rag_soc != '') {
            $query .= " AND CORAGS like '%" . trim($rag_soc) . "%'";
        }
        if ($ind != '') {
            $query .= " AND CONCAT(CONCAT(CONCAT(CONCAT(COINDX,COINDY),COLOC1),COLOC2),COPROV) like '%" . trim($ind) . "%'";
        }
        if ($piva != '') {
            $query .= " AND COPIVA = '" . trim($piva) . "'";
        }
        if ($attivo != '') {
            $query .= " AND COCA09 = '' ";
        }
        //$query .= " AND COCA09 <> 'ANN' ";
        $query .= " ORDER BY COCONT ASC";
        //$query .= " FETCH FIRST 5 ROWS ONLY";
        $risultato = $DB2->query($query);
        //echo $DB2->last_query();
        return $risultato->result();
    }

   


}

?>
