From: vincent@cubedesigners.com Date: Mon, 17 Jan 2011 10:44:05 +0000 (+0000) Subject: (no commit message) X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=7d8d121b1010b707c66779f4b686fd52e8322881;p=cubeextranet.git --- diff --git a/inc/commons/DAO/_common.php b/inc/commons/DAO/_common.php index d554fefda..37a35d23c 100644 --- a/inc/commons/DAO/_common.php +++ b/inc/commons/DAO/_common.php @@ -1,5 +1,8 @@ \ No newline at end of file diff --git a/inc/commons/DAO/class.common.dao.client.php b/inc/commons/DAO/class.common.dao.client.php new file mode 100644 index 000000000..c39c046ba --- /dev/null +++ b/inc/commons/DAO/class.common.dao.client.php @@ -0,0 +1,108 @@ +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/commons/DAO/class.common.dao.entreprise.php b/inc/commons/DAO/class.common.dao.entreprise.php new file mode 100644 index 000000000..4992314e2 --- /dev/null +++ b/inc/commons/DAO/class.common.dao.entreprise.php @@ -0,0 +1,179 @@ +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