Plugins  LAST
 All Data Structures Files Functions Variables Pages
class_tool_exercice.php
Go to the documentation of this file.
1 <?php
2 
3 //This file is part of NOALYSS and is under GPL
4 //see licence.txt
5 
6 /**
7  * Description of class_tool_exercice
8  *
9  * @author dany
10  */
12 {
13 
14  function __construct($cn)
15  {
16  $this->cn = $cn;
17  }
18 
19  /**
20  * Show form to input data for new exercice
21  */
22  function input()
23  {
24  $exercice = new INum('p_exercice');
25  $exercice->prec = 0;
26  $exercice->value = HtmlInput::default_value_post('p_exercice', '');
27 
28  $year = new INum('year');
29  $year->prec = 0;
30  $year->value = HtmlInput::default_value_post('year', '');
31 
32  $nb_month = new INum('nb_month');
33  $nb_month->prec = 0;
34  $nb_month->value = HtmlInput::default_value_post('nb_month', '');
35 
36  $from = new ISelect('from_month');
37  $from->selected= HtmlInput::default_value_post('from_month', '');
38  $amonth = array();
39  for ($i = 1; $i < 13; $i++)
40  {
41  $amonth[] = array("value" => $i, "label" => $i);
42  }
43  $from->value = $amonth;
44 
45  require_once 'template/tool_exercice_input.php';
46  }
47 
48  function fromPost()
49  {
50  $this->exercice = $_POST['p_exercice'];
51  $this->nb_month = $_POST['nb_month'];
52  $this->from = $_POST['from_month'];
53  $this->year= $_POST['year'];
54  }
55 
56  function verify()
57  {
58  if (isNumber($this->exercice) == 0)
59  throw new Exception("Exercice n'est pas un nombre");
60 
61  if ($this->exercice > COMPTA_MAX_YEAR|| $this->exercice < COMPTA_MIN_YEAR)
62  throw new Exception("Exercice doit être entre ".COMPTA_MAX_YEAR."& ".COMPTA_MIN_YEAR);
63  if (isNumber($this->year) == 0)
64  throw new Exception("Année n'est pas un nombre");
65 
66  if ($this->year > COMPTA_MAX_YEAR|| $this->year < COMPTA_MIN_YEAR)
67  throw new Exception("Année doit être entre ".COMPTA_MAX_YEAR."& ".COMPTA_MIN_YEAR);
68 
69  if (isNumber($this->nb_month) == 0)
70  throw new Exception("Nombre de mois n'est pas un nombre");
71  if ($this->nb_month < 1 || $this->nb_month > 60)
72  throw new Exception("Nombre de mois doit être compris entre 1 & 60 ");
73  if (isNumber($this->from) == 0)
74  throw new Exception("Mois de début n'existe pas ");
75  if ($this->from > 13 || $this->from < 1)
76  throw new Exception("Mois de début n'existe pas ");
77  }
78 
79  function save()
80  {
81  try
82  {
83  $this->verify();
84  }
85  catch (Exception $e)
86  {
87  throw new Exception($e->getMessage());
88  }
89  $this->cn->start();
90  try
91  {
92  $periode = new Periode($this->cn);
95  $month=$this->from;
96  for ($i = 1; $i <= $this->nb_month; $i++)
97  {
98 
99 
100  $date_start = sprintf('01.%02d.%d', $month, $year);
101  $date_end = $this->cn->get_value("select to_char(to_date('$date_start','DD.MM.YYYY')+interval '1 month'-interval '1 day','DD.MM.YYYY')");
102  if ($periode->insert($date_start, $date_end, $this->exercice) != 0)
103  {
104  throw new Exception('Erreur insertion période');
105  }
106  if ($month>11 )
107  {
108  $year++;
109  $month=1;
110  }
111  else
112  {
113  $month++;
114  }
115  }
116  }
117  catch (Exception $e)
118  {
119  var_dump($e->getTraceAsString());
120  return -1;
121  }
122  return 0;
123  }
124 
125 }
126 
127 ?>
input()
Show form to input data for new exercice.
if(isset($_POST['save'])) $exercice
$periode
Description of class_tool_exercice.
$date_end
if(isset($_POST['save'])) if(isset($_GET['compute'])) $date_start
global $cn