Plugins  LAST
 All Data Structures Files Functions Variables Pages
class_rapav.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of NOALYSS.
5  *
6  * NOALYSS is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * NOALYSS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with NOALYSS; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 
21 
22 /**
23  * Common function to RAPAV_Listing RAPAV_Formulaire and RAPAV_Declaration
24  *
25  * @author dany
26  */
27 class RAPAV
28 {
29 
30  /**
31  * Return the ledger's name of p_jrn
32  * @param $p_jrn jrn_def::jrn_def_id if -1, it means all the ledger
33  * @return string
34  */
35  static function get_ledger_name($p_jrn)
36  {
37  global $cn;
38  $ledger = "";
39  if ($p_jrn == null || $p_jrn == -1)
40  {
41  $ledger = " tous les journaux";
42  } else
43  {
44  $tledger = $cn->get_value('select jrn_def_name from jrn_def where jrn_def_id=$1', array($p_jrn));
45  $ledger.=" le journal " . $tledger;
46  }
47  return $ledger;
48  }
49 
50 
51 
52  /**
53  * Compute the string to display for date
54  * @param $p_type
55  * @return string
56  * @throws Exception
57  */
58  static function str_date_type($p_type)
59  {
60  switch ($p_type)
61  {
62  case 0:
63  return "la date concerne la date d'opération";
64  break;
65  case 1:
66  return "la date concerne la date de paiement, la recherche sera limitée au journaux de type ACH & VEN";
67  break;
68  case 2:
69  return "la date concerne la date d'échéance, la recherche sera limitée au journaux de type ACH & VEN";
70  break;
71  }
72  throw new Exception('str_date_type : type de date inconnu');
73  }
74 
75  /**
76  * Compute the SQL for the date
77  * - 0 given date
78  * - 1 Date of payment
79  * - 2 Limit Date
80  * @param $p_date integer
81  * @return string
82  * @throws Exception if $p_date not valid
83  */
84  static function get_sql_date($p_date,$p_prefix="")
85  {
86  if ($p_prefix != "") {$p_prefix=$p_prefix.".";}
87  switch ($p_date)
88  {
89  case 0:
90  $sql_date = "and (".$p_prefix."j_date >= to_date($2,'DD.MM.YYYY') and ".$p_prefix."j_date <= to_date($3,'DD.MM.YYYY'))";
91  break;
92  case 1:
93  $sql_date = " and ".$p_prefix."j_id in
94  (select j_id from jrnx join jrn on (j_grpt = jr_grpt_id)
95  where
96  coalesce(jr_date_paid,to_date('01.01.1900','DD.MM.YYYY')) >= to_date($2,'DD.MM.YYYY')
97  and coalesce(jr_date_paid,to_date('01.01.1900','DD.MM.YYYY')) <= to_date($3,'DD.MM.YYYY')
98  )
99  ";
100  break;
101  case 2:
102  $sql_date = " and ".$p_prefix."j_id in
103  (select j_id from jrnx join jrn on (j_grpt = jr_grpt_id)
104  where
105  coalesce(jr_ech,to_date('01.01.1900','DD.MM.YYYY')) >= to_date($2,'DD.MM.YYYY')
106  and coalesce(jr_ech,to_date('01.01.1900','DD.MM.YYYY')) <= to_date($3,'DD.MM.YYYY')
107  )
108  ";
109  break;
110 
111  default:
112  throw new Exception('get_sql_date paramètre invalide');
113  break;
114  }
115  return $sql_date;
116  }
117 
118  /**
119  * @brief check if the formula is valid, return 1 for an error
120  * and set errcode to the error msg
121  * errcode is global variable
122  */
123  static function verify_compute($p_formula)
124  {
125  global $errcode;
126  $errcode = "";
127  if (trim($p_formula) == "")
128  {
129  $errcode = " Aucune formule trouvée";
130  return 1;
131  }
132 
133  // copy $this->form->fp_formula to a variable
134  $formula = $p_formula;
135 
136  // remove the valid
137  preg_match_all("/\[([A-Z]*[0-9]*)*([0-9]*[A-Z]*)\]/i", $formula, $e);
138  $formula = preg_replace('/_/', '', $formula);
139  $formula = preg_replace("/\[([A-Z]*[0-9]*)*([0-9]*[A-Z]*)%*s*d*c*\]/i", '', $formula);
140  $formula = preg_replace("/\[([a-z]*[0-9]*)*([0-9]*[A-Z]*)%*s*d*c*\]/i", '', $formula);
141  $formula = preg_replace('/([0-9]+.{0,1}[0.9]*)*(\+|-|\*|\/)*/', '', $formula);
142  $formula = preg_replace('/(\(|\))/', '', $formula);
143  $formula = preg_replace('/\s/', '', $formula);
144  $formula = preg_replace('/</', '', $formula);
145  $formula = preg_replace('/>/', '', $formula);
146  $formula = preg_replace('/=/', '', $formula);
147  $formula = preg_replace('/\?/', '', $formula);
148 
149  // if something remains it should be a mistake
150  if ($formula != '')
151  {
152  $errcode = _(" Erreur dans la formule ") . $formula;
153  return 1;
154  }
155  return 0;
156  }
157 
158  static function verify_formula($p_formula)
159  {
160  global $errcode;
161  $errcode = "";
162  if (Impress::check_formula($p_formula) == false)
163  {
164  $errcode = "Erreur dans votre formule";
165  return 1;
166  }
167  if (trim($p_formula) == "")
168  {
169  $errcode = " Aucune formule trouvée";
170  return 1;
171  }
172  return 0;
173  }
174 
175 }
static verify_compute($p_formula)
check if the formula is valid, return 1 for an error and set errcode to the error msg errcode is glob...
static str_date_type($p_type)
Compute the string to display for date.
Definition: class_rapav.php:58
Common function to RAPAV_Listing RAPAV_Formulaire and RAPAV_Declaration.
Definition: class_rapav.php:27
static get_sql_date($p_date, $p_prefix="")
Compute the SQL for the date.
Definition: class_rapav.php:84
static verify_formula($p_formula)
static get_ledger_name($p_jrn)
Return the ledger's name of p_jrn.
Definition: class_rapav.php:35
global $cn