From: vincent@cubedesigners.com Date: Mon, 17 Jan 2011 10:44:14 +0000 (+0000) Subject: (no commit message) X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=df32c18fba2df706802f4b82994a22ef050b6e44;p=cubeextranet.git --- diff --git a/inc/extranet/DAO/class.extranet.dao.client.php b/inc/extranet/DAO/class.extranet.dao.client.php deleted file mode 100644 index b4e922660..000000000 --- a/inc/extranet/DAO/class.extranet.dao.client.php +++ /dev/null @@ -1,108 +0,0 @@ -rs = $r->rs; - $utilisateur->adresse_facturation = $r->adresse_facturation; - $utilisateur->collegues = array(); - return parent::singleton($r, $utilisateur); - } - - public function cree($utilisateur = null) - { - $utilisateur = new extranetClient(); - $utilisateur->rs = ''; - $utilisateur->adresse_facturation = ''; - $utilisateur->collegues = array(); - return parent::cree($utilisateur); - } - - public function selectById($client_id, $table = 'clients') - { - $r = $this->con->select('SELECT * FROM ' . $table . ' WHERE utilisateur_id=' . $this->con->escape($client_id) . ' LIMIT 1'); - $res = $this->factory($r); - - if (!count($res)) { - return null; - } - return $res[0]; - } - - public function selectByProjet($projet_id) - { - $r = $this->con->select('SELECT * FROM clients WHERE utilisateur_id IN(SELECT client FROM projets WHERE projet_id=\'' . $projet_id . '\') LIMIT 1'); - return $this->singleton($r); - } - - public function getListe($orderby = null, $sens = null, $limit = null, $where = null) - { - $sql = $this->getQueryList('clients', $orderby, $sens, $limit, $where); - $r = $this->con->select($sql); - return $this->factory($r); - } - - public function getContactsOfEntreprise($entreprise_id, $return_as_array = false) - { - $r = $this->con->select('SELECT * FROM clients WHERE entreprise=\'' . $this->con->escape($entreprise_id) . '\''); - return $this->factory($r); - } - - public function getCollegues($utilisateur_id) - { - $r = $this->con->select('SELECT * FROM clients WHERE entreprise IN (SELECT entreprise FROM utilisateurs WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\') AND utilisateur_id!=\'' . $this->con->escape($utilisateur_id) . '\''); - return $this->factory($r); - } - - public function getColleguesList($utilisateur_id) - { - $r = $this->con->select('SELECT utilisateur_id FROM clients WHERE entreprise IN (SELECT entreprise FROM utilisateurs WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\') AND utilisateur_id!=\'' . $this->con->escape($utilisateur_id) . '\''); - $res = array(); - while ($r->fetch()) { - $res[] = $r->utilisateur_id; - } - return $res; - } - - public function querySearchByName($q) - { - return 'SELECT utilisateur_id FROM utilisateurs WHERE (' . $this->whereSearchByName($q) . ') AND grade=0'; - } - - public function count() - { - $r = $this->con->select('SELECT COUNT(*) AS nb FROM clients WHERE ' . $this->makeWhereFromFiltres()); - return $r->nb; - } - - protected function makeWhereFromFiltres() - { - if (!is_null($this->filtres)) { - $w = array('1=1'); - if (commonFiltre::test('status_client_projet', $this->filtres)) { - $w[] = 'utilisateur_id IN(SELECT client FROM projets WHERE status IN(' . implode(',', array_keys($this->filtres['status_client_projet'])) . '))'; - } - if (commonFiltre::test('impaye', $this->filtres)) { - if (isset($this->filtres['impaye'][1])) { - $w[] = '(impaye>0 OR impaye IS NOT NULL)'; - } else { - $w[] = '(impaye=0 OR impaye IS NULL)'; - } - } - return implode(' AND ', $w); - } else { - return '1=1'; - } - } - - public function getContactsOfEntreprises($entreprises_ids) - { - if (!count($entreprises_ids)) { - return array(); - } - $r = $this->con->select('SELECT * FROM clients WHERE entreprise IN(' . implode(',', $entreprises_ids) . ')'); - return $this->factory($r); - } -} - -?> \ No newline at end of file diff --git a/inc/extranet/DAO/class.extranet.dao.entreprise.php b/inc/extranet/DAO/class.extranet.dao.entreprise.php deleted file mode 100644 index 64cda70c5..000000000 --- a/inc/extranet/DAO/class.extranet.dao.entreprise.php +++ /dev/null @@ -1,179 +0,0 @@ -entreprise_id = $r->entreprise_id; - $entreprise->nom = $r->nom; - $entreprise->adresse = $r->adresse; - $entreprise->code_postal = $r->code_postal; - $entreprise->ville = $r->ville; - $entreprise->pays = $r->pays; - $entreprise->tva_intra = $r->tva_intra; - $entreprise->notes = $r->notes; - $entreprise->impaye = $r->impaye; - $entreprise->ca = $r->ca; - $entreprise->adresse_facturation = $r->adresse_facturation; - $entreprise->ws_admin = $r->ws_admin; - $entreprise->ws_grade = $r->ws_grade; - - return $entreprise; - } - - public function cree() - { - $entreprise = new extranetEntreprise(); - $entreprise->entreprise_id = 'new'; - $entreprise->date_creation = time(); - $entreprise->pays = 'FR'; - return $entreprise; - } - - protected function getNextId() - { - $r = $this->con->select('SELECT MAX(entreprise_id) AS entreprise_id FROM entreprises'); - return $r->entreprise_id + 1; - } - - public function selectById($entreprise_id = null) - { - if (is_null($entreprise_id)) { - return $this->cree(); - } - - $r = $this->con->select('SELECT * FROM entreprises_vue WHERE entreprise_id=\'' . $this->con->escape($entreprise_id) . '\' LIMIT 1'); - return $this->singleton($r); - } - - public function getWSDatas($entreprise_id) - { - $r = $this->con->select('SELECT * FROM ws_users_tree WHERE utilisateur_id IN(SELECT utilisateur_id FROM utilisateurs WHERE entreprise=\'' . $this->con->escape($entreprise_id) . '\') LIMIT 1'); - if (!$r->count()) { - return null; - } - $daoUtilisateur = new commonDAOUtilisateur($this->con); - - $res = new stdClass(); - $res->administrateur = $daoUtilisateur->selectById($r->administrateur_id, 'utilisateurs_entreprise'); - $res->facturable = $daoUtilisateur->selectById($r->facturable_id, 'utilisateurs_entreprise'); - return $res; - } - - public function getListe($orderby = null, $sens = null, $limit = null) - { - global $core; - if (!is_null($this->q)) { - $daoClients = new extranetDAOClient($this->con); - $where = ''; - $where .= 'entreprise_id=\'' . $this->con->escape($this->q) . '\' OR '; - $where .= 'nom LIKE \'%' . $this->con->escape($this->q) . '%\' OR '; - $where .= 'entreprise_id IN (SELECT entreprise FROM utilisateurs WHERE(' . $daoClients->whereSearchByName($this->q, false) . ') AND grade=0) '; - $limit = null; - } else { - $where = $this->makeWhereFromFiltres(); - } - - $orderby = is_null($orderby)?'entreprise_id':$orderby; - $sens = is_null($sens)?'DESC':$sens; - $limit = is_null($limit)?'':$this->con->limit($limit[0], $limit[1]); - - $sql = 'SELECT * FROM entreprises_vue WHERE ' . $where . ' ORDER BY ' . $orderby . ' ' . $sens . ' ' . $limit; - $r = $this->con->select($sql); - $ids = array(); - while ($r->fetch()) { - $ids[] = $r->entreprise_id; - } - $r->moveStart(); - $liste = $this->factory($r); - $newList = array(); - foreach($liste as $e) { - $newList[$e->entreprise_id] = $e; - } - $liste = $newList; - - $daoClients = new extranetDAOClient($this->con); - $contacts = $daoClients->getContactsOfEntreprises($ids); - $contactSorted = array(); - foreach($contacts as $c) { - if (!isset($contactSorted[$c->entreprise])) { - $contactSorted[$c->entreprise] = array(); - } - $contactSorted[$c->entreprise][] = $c; - } - foreach($contactSorted as $entreprise_id => $c) { - $liste[$entreprise_id]->contacts = $c; - } - return $liste; - } - - public function sauve($data) - { - global $core; - - $c = $this->con->openCursor('entreprises'); - $c->nom = $data['nom']; - $c->date_creation = time(); - $c->adresse = $data['adresse']; - $c->code_postal = $data['code_postal']; - $c->ville = $data['ville']; - $c->pays = $data['pays']; - $c->tva_intra = $data['tva_intra']; - $c->adresse_facturation = $data['adresse_facturation']; - $c->ws_admin = $data['ws_admin']; - $c->ws_grade = $data['ws_grade']; - - if ($data['entreprise_id'] == 'new' || $data['entreprise_id'] == '') { - $entreprise_id = $c->entreprise_id = $this->getNextId(); - $c->insert(); - } else { - $entreprise_id = $data['entreprise_id']; - $c->update('WHERE entreprise_id=\'' . $this->con->escape($data['entreprise_id']) . '\''); - } - - $entreprise = $this->selectById($entreprise_id); - $core->refreshWSUsersTree(); - return $entreprise; - } - - public function supprime($entreprise_id) - { - $this->con->execute('DELETE FROM utilisateurs WHERE entreprise=\'' . $this->con->escape($entreprise_id) . '\''); - $this->con->execute('DELETE FROM entreprises WHERE entreprise_id=\'' . $this->con->escape($entreprise_id) . '\''); - $core->refreshWSUsersTree(); - return true; - } - - public function count() - { - $r = $this->con->select('SELECT COUNT(*) AS nb FROM entreprises_vue WHERE ' . $this->makeWhereFromFiltres()); - return $r->nb; - } - - protected function makeWhereFromFiltres() - { - if (!is_null($this->filtres)) { - $w = array('1=1'); - return implode(' AND ', $w); - } else { - return '1=1'; - } - } - - public function getCaDetails($entreprise_id) - { - $r = $this->con->select('SELECT SUM(f.total_ht) AS ca,YEAR(FROM_UNIXTIME(f.date_creation)) AS annee FROM factures f,projets p WHERE f.projet=p.projet_id AND p.client IN (SELECT utilisateur_id FROM utilisateurs WHERE entreprise=\'' . $this->con->escape($entreprise_id) . '\') GROUP BY annee ORDER BY annee DESC'); - $res = array(); - while ($r->fetch()) { - $res[$r->annee] = $r->ca; - } - return $res; - } - - public function getContacts($entreprise_id) - { - $daoClient = new extranetDAOClient($this->con); - return $daoClient->getContactsOfEntreprise($entreprise_id); - } -} - -?> \ No newline at end of file