<?php\r
+\r
/**\r
* extranetDAOFacture\r
*\r
* @access public\r
*/\r
class extranetDAOFacture extends commonDAO {\r
- protected function singleton($r)\r
- {\r
+\r
+ protected function singleton($r) {\r
$facture = new extranetFacture();\r
$facture->facture_id = $r->facture_id;\r
$facture->nom = $r->nom;\r
return $facture;\r
}\r
\r
- public function cree()\r
- {\r
+ public function cree() {\r
$facture = new extranetFacture();\r
$facture->facture_id = 'new';\r
$facture->nom = '';\r
return $facture;\r
}\r
\r
- public function selectById($facture_id)\r
- {\r
+ public function selectById($facture_id) {\r
$r = $this->con->select('SELECT * FROM factures_vue WHERE facture_id=\'' . $this->con->escape($facture_id) . '\'');\r
return $this->singleton($r);\r
}\r
\r
- public function getListe($orderby = null, $sens = null, $limit = null)\r
- {\r
+ public function getListe($orderby = null, $sens = null, $limit = null) {\r
if (!is_null($this->q)) {\r
$where = '';\r
if ($this->search_id) {\r
$where = $this->makeWhereFromFiltres();\r
}\r
\r
- $orderby = is_null($orderby)?'facture_id':$orderby;\r
- $sens = is_null($sens)?'DESC':$sens;\r
- $limit = is_null($limit)?'':$this->con->limit($limit[0], $limit[1]);\r
+ $orderby = is_null($orderby) ? 'facture_id' : $orderby;\r
+ $sens = is_null($sens) ? 'DESC' : $sens;\r
+ $limit = is_null($limit) ? '' : $this->con->limit($limit[0], $limit[1]);\r
\r
$sql = 'SELECT * FROM factures_vue WHERE ' . $where . ' ORDER BY ' . $orderby . ' ' . $sens . ' ' . $limit;\r
fb($sql);\r
return $this->factory($r);\r
}\r
\r
- public function getListeCompta($orderby = null, $sens = null, $limit = null)\r
- {\r
+ public function getListeCompta($orderby = null, $sens = null, $limit = null) {\r
if (!is_null($this->q)) {\r
$where = '';\r
if ($this->search_id) {\r
$where = $this->makeWhereFromFiltres();\r
}\r
\r
- $orderby = is_null($orderby)?'facture_id':$orderby;\r
- $sens = is_null($sens)?'DESC':$sens;\r
- $limit = is_null($limit)?'':$this->con->limit($limit[0], $limit[1]);\r
+ $orderby = is_null($orderby) ? 'facture_id' : $orderby;\r
+ $sens = is_null($sens) ? 'DESC' : $sens;\r
+ $limit = is_null($limit) ? '' : $this->con->limit($limit[0], $limit[1]);\r
\r
$sql = 'SELECT * FROM factures_vue WHERE (' . $where . ') AND CAST(facture_id AS SIGNED)>0 ORDER BY ' . $orderby . ' ' . $sens . ' ' . $limit;\r
$r = $this->con->select($sql);\r
return $this->factory($r);\r
}\r
\r
- public function getListeForClient($client_id, $orderby, $sens)\r
- {\r
+ public function getListeForClient($client_id, $orderby, $sens) {\r
$sql = 'SELECT * FROM factures_vue WHERE client_id=\'' . $this->con->escape($client_id) . '\' AND status>0 ORDER BY ' . $orderby . ' ' . $sens;\r
$r = $this->con->select($sql);\r
return $this->factory($r);\r
}\r
\r
- public function getListeForEntreprise($entreprise_id, $orderby, $sens)\r
- {\r
+ public function getListeForEntreprise($entreprise_id, $orderby, $sens) {\r
$sql = 'SELECT * FROM factures_vue WHERE client_id IN(SELECT utilisateur_id FROM utilisateurs WHERE entreprise=\'' . $this->con->escape($entreprise_id) . '\') AND status>0 ORDER BY ' . $orderby . ' ' . $sens;\r
$r = $this->con->select($sql);\r
return $this->factory($r);\r
}\r
\r
- public function getImpayesOfClient($client_id)\r
- {\r
+ public function getImpayesOfClient($client_id) {\r
$sql = 'SELECT * FROM factures_vue WHERE client_id=\'' . $this->con->escape($client_id) . '\' AND status=1 ORDER BY date_creation';\r
$r = $this->con->select($sql);\r
return $this->factory($r);\r
}\r
\r
- public function changeStatus($facture_id, $status)\r
- {\r
+ public function changeStatus($facture_id, $status) {\r
if ($status == 3) {\r
$this->annule($facture_id);\r
}\r
return $this->con->execute('UPDATE factures SET status=' . $status . ' WHERE facture_id=\'' . $this->con->escape($facture_id) . '\'');\r
}\r
\r
- public function annule($facture_id)\r
- {\r
+ public function annule($facture_id) {\r
$facture = $this->selectById($facture_id);\r
$avoir = $this->duplique($facture_id, $facture->createur_id, true);\r
$avoir->facture_id = $this->idBrouillonToIdNormal($avoir->facture_id);\r
$this->saveAsPDF($avoir->facture_id);\r
}\r
\r
- public function setLinkAvoir($id1, $id2)\r
- {\r
+ public function setLinkAvoir($id1, $id2) {\r
$c = $this->con->openCursor('factures');\r
$c->avoir = $id1;\r
$c->update('WHERE facture_id=\'' . $this->con->escape($id2) . '\'');\r
$c->update('WHERE facture_id=\'' . $this->con->escape($id1) . '\'');\r
}\r
\r
- public function supprime($facture_id)\r
- {\r
+ public function supprime($facture_id) {\r
return $this->con->execute('DELETE FROM factures WHERE facture_id=\'' . $this->con->escape($facture_id) . '\'');\r
}\r
\r
- public function getNextId($brouillon = true)\r
- {\r
+ public function getNextId($brouillon = true) {\r
if ($brouillon) {\r
$r = $this->con->select('SELECT facture_id AS facture_id FROM factures WHERE status=0 ORDER BY facture_id DESC LIMIT 1');\r
if (!$r->count()) {\r
return 'A';\r
} else {\r
- return ++$r->facture_id;\r
+ return++$r->facture_id;\r
}\r
} else {\r
$r = $this->con->select('SELECT MAX(CAST(facture_id AS SIGNED)) AS facture_id FROM factures WHERE status>0');\r
}\r
}\r
\r
- public function sauve($data, $createur)\r
- {\r
+ public function sauve($data, $createur) {\r
$lignes = array();\r
- foreach($data['montant'] as $i => $montant) {\r
+ foreach ($data['montant'] as $i => $montant) {\r
$ligne = array('titre' => $data['titre'][$i], 'description' => $data['description'][$i], 'montant' => $data['montant'][$i], 'book' => $data['montant'][$i]);\r
if ($ligne['titre'] == '' && $ligne['description'] == '' && $ligne['montant'] == '') {\r
continue;\r
$c->total_ht = 0;\r
$c->texte_complementaire = $data['texte_complementaire'];\r
$c->adresse = $data['adresse'];\r
- foreach($lignes as $k => $d) {\r
+ foreach ($lignes as $k => $d) {\r
$d['montant'] = round(floatval(str_replace(',', '.', $d['montant'])), 2);\r
$lignes[$k]['montant'] = $d['montant'];\r
$c->total_ht += $d['montant'];\r
$daoProjet->changeStatus($projet_id);\r
\r
$daoTache = new extranetDAOTache($this->con);\r
- foreach($lignes as $ligne) {\r
+ foreach ($lignes as $ligne) {\r
$ligne['montant'] = round(floatval(str_replace(',', '.', $ligne['montant'])), 2);\r
$m = $ligne['montant'];\r
if (!$m) {\r
$c->insert();\r
// Marque les fluidbook comme facturés\r
$books = array();\r
- foreach($lignes as $ligne) {\r
+ foreach ($lignes as $ligne) {\r
$books[] = $ligne['book'];\r
}\r
$cb = $this->con->openCursor('ws.book');\r
return $this->selectById($facture_id);\r
}\r
\r
- public function saveAsPDF($facture_id)\r
- {\r
+ public function saveAsPDF($facture_id) {\r
$facture = $this->selectById($facture_id);\r
$daoUtilisateur = new commonDAOUtilisateur($this->con);\r
$facture->client = $daoUtilisateur->selectById($facture->client_id);\r
$pdf->Output(ROOT . '/factures/' . $facture->facture_id . '.pdf');\r
}\r
\r
- public function savePaiement($data)\r
- {\r
+ public function savePaiement($data) {\r
$c = $this->con->openCursor('factures');\r
$c->status = 2;\r
$c->informations_paiement = $data['informations_paiement'];\r
$c->update('WHERE facture_id=\'' . $this->con->escape($data['facture_id']) . '\'');\r
}\r
\r
- public function duplique($facture_id, $createur, $avoir = false)\r
- {\r
+ public function duplique($facture_id, $createur, $avoir = false) {\r
$facture = $this->selectById($facture_id);\r
\r
$c = $this->con->openCursor('factures');\r
$c->total_ht = $facture->total_ht;\r
} else {\r
$lignes = array();\r
- foreach($facture->lignes as $l) {\r
+ foreach ($facture->lignes as $l) {\r
if (is_numeric($l['montant'])) {\r
$l['montant'] *= -1;\r
}\r
return $this->selectById($c->facture_id);\r
}\r
\r
- public function valide($facture_id)\r
- {\r
- $new_id = $this->idBrouillonToIdNormal($facture_id);\r
+ public function valide($facture_id) {\r
+ if (intval($facture_id) == 0) {\r
+ $new_id = $this->idBrouillonToIdNormal($facture_id);\r
+ } else {\r
+ $new_id = $facture_id;\r
+ }\r
+\r
return $this->changeStatus($new_id, 1);\r
}\r
\r
- public function idBrouillonToIdNormal($facture_id)\r
- {\r
+ public function idBrouillonToIdNormal($facture_id) {\r
$c = $this->con->openCursor('factures');\r
$c->facture_id = $this->getNextId(false);\r
$c->status = 1;\r
return $c->facture_id;\r
}\r
\r
- public function count()\r
- {\r
- $filters=$this->makeWhereFromFiltres();\r
- if($filters=='1=1'){\r
- $table='factures';\r
- }else{\r
- $table='factures_vue';\r
+ public function count() {\r
+ $filters = $this->makeWhereFromFiltres();\r
+ if ($filters == '1=1') {\r
+ $table = 'factures';\r
+ } else {\r
+ $table = 'factures_vue';\r
}\r
- $r = $this->con->select('SELECT COUNT(*) AS nb FROM '.$table.' WHERE ' . $filters);\r
+ $r = $this->con->select('SELECT COUNT(*) AS nb FROM ' . $table . ' WHERE ' . $filters);\r
return $r->nb;\r
}\r
\r
- public function countCompta()\r
- {\r
+ public function countCompta() {\r
$r = $this->con->select('SELECT COUNT(*) AS nb FROM factures_vue WHERE (' . $this->makeWhereFromFiltres() . ') AND CAST(facture_id AS SIGNED)>0');\r
return $r->nb;\r
}\r
\r
- protected function makeWhereFromFiltres()\r
- {\r
+ protected function makeWhereFromFiltres() {\r
if (!is_null($this->filtres)) {\r
$w = array('1=1');\r
if (commonFiltre::test('annee_facture', $this->filtres)) {\r
return '1=1';\r
}\r
}\r
+\r
}\r
\r
?>
\ No newline at end of file