Plugins  LAST
 All Data Structures Files Functions Variables Pages
class_ext_tvagen.php
Go to the documentation of this file.
1 <?php
2 /*
3  * This file is part of NOALYSS.
4  *
5  * NOALYSS is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * NOALYSS is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with NOALYSS; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 /* $Revision$ */
20 
21 // Copyright (c) 2002 Author Dany De Bontridder dany@alchimerys.be
22 
23 /*!\file
24  * \brief
25  */
26 
27 require_once('tva_constant.php');
28 require_once NOALYSS_INCLUDE.'/class/class_own.php';
29 /**
30  *@brief transform a string into an arrau without empty element and duplicate
31  * the array is sorted
32  *@param $p_string string containing a comma a separator
33  *@return array
34  *
35  */
36 function get_array_nodup($p_string) {
37  $array=explode(',',$p_string);
38  sort($array);
39  $array=array_unique($array);
40  $result=array();
41  foreach ($array as $val) {
42  if ( $val == '') continue;
43  $result[]=$val;
44  }
45  $r=join(',',$result);
46  return $result;
47 }
48 
50 {
51  function __construct($p_cn) {
52  $this->db=$p_cn;
53  }
54  public function get_parameter($p_string) {
55  if ( array_key_exists($p_string,$this->variable) ) {
56  $idx=$this->variable[$p_string];
57  return $this->$idx;
58  }
59  else
60  throw new Exception (__FILE__.":".__LINE__.'Erreur attribut inexistant');
61  }
62  public function set_parameter($p_string,$p_value) {
63  if ( array_key_exists($p_string,$this->variable) ) {
64  $idx=$this->variable[$p_string];
65  $this->$idx=$p_value;
66  }
67  else
68  throw new Exception (__FILE__.":".__LINE__.'Erreur attribut inexistant');
69 
70 
71  }
72  public function get_info() { return var_export(self::$variable,true); }
73 
74  public function save() {
75  /* please adapt */
76  if ( $this->get_parameter("id") == 0 )
77  $this->insert();
78  else
79  $this->update();
80  }
81 
82  static function choose_periode($by_year=false) {
83  require_once NOALYSS_INCLUDE.'/lib/class_iradio.php';
84  $monthly=new IRadio('periodic');
85  $monthly->value=1;
86 
87  // month
88  $month=new ISelect('bymonth');
89  $array=array ();
90  for ($i=0;$i<12;$i++) {
91  $array[$i]['value']=$i+1; $array[$i]['label']=sprintf('%02d',($i+1));
92  }
93  $month->value=$array;
94  $monthly->selected=true;
95  $str_monthly=$monthly->input();
96  $str_month=$month->input();
97  // year
98  $year = new IText('year');
99  $year->size=4;
100  $str_year=$year->input();
101 
102  // Tri
103  $quater=new ISelect('byquaterly');
104  $array=array();
105  for ($i=0;$i<4;$i++) {
106  $array[$i]['value']=$i+1; $array[$i]['label']=sprintf('%02d',($i+1));
107  }
108  $quater->value=$array;
109  $quaterly=new IRadio('periodic');
110  $quaterly->value=2;
111  $str_quaterly=$quaterly->input();
112  $str_quater=$quater->input();
113 
114  $str_submit=HtmlInput::submit('decl',_('Afficher'));
115  $str_hidden=HtmlInput::extension().dossier::hidden();
116  if (isset($_REQUEST['sa']))
117  $str_hidden.=HtmlInput::hidden('sa',$_REQUEST['sa']);
118  $str_hidden.=HtmlInput::request_to_hidden(array('ac'));
119  $str_byyear='';
120  if ( $by_year == true ) {
121  $yearly=new IRadio('periodic');
122  $yearly->value=3;
123  $str_byyear=$yearly->input();
124  }
125  ob_start();
126  require_once('form_periode.php');
127  $r=ob_get_contents();
128  ob_end_clean();
129  return $r;
130  }
131 
132  function blank($p_year,$p_periode,$p_flag_quaterly) {
133  // load parameter from myown
134  $own=new Own($this->db);
135  $this->set_parameter("name",$own->MY_NAME);
136  $this->set_parameter("num_tva",$own->MY_TVA);
137  $this->set_parameter('adress',$own->MY_STREET.",".$own->MY_NUMBER);
138  $this->set_parameter('country',$own->MY_COUNTRY." ".$own->MY_CP." ".$own->MY_COMMUNE);
139  $this->set_parameter('flag_periode',$p_flag_quaterly);
140  $this->set_parameter('periode_dec',$p_periode);
141  $this->set_parameter('exercice',$p_year);
142 
143  try {
144  $this->verify() ;
145  } catch ( Exception $e) {
146  echo $e->getMessage();
147  throw $e;
148  }
149  // by month
150  if ( $p_flag_quaterly == 1) {
151  // start periode = 01 to 31, $p_periode contains the month
152  $per_start="01.".$p_periode.".".$p_year;
153  $day=31;
154  $per_end="31".".".$p_periode.".".$p_year;
155  while ( checkdate($p_periode,$day,$p_year) == false && $day > 25) {
156  $day--;
157  $per_end=$day.".".$p_periode.".".$p_year;
158  }
159  if ($day < 28 ) { echo __FILE__.__LINE__." Erreur de date $day"; exit;}
160  }
161 
162  if ( $p_flag_quaterly == 2 ) {
163  // compute start periode
164  $per_start=$GLOBALS['quaterly_limit'][$p_periode][0].".".$p_year;
165  $per_end=$GLOBALS['quaterly_limit'][$p_periode][1].".".$p_year;
166 
167  }
168  if ( $p_flag_quaterly == 3 ) {
169  // compute start periode
170  $per_start='01.01.'.$p_year;
171  $per_end='31.12.'.$p_year;
172  }
173 
174  $this->set_parameter('start_periode',$per_start);
175  $this->set_parameter('end_periode',$per_end);
176 
177  }
178 
179  /**
180  *@brief display the information about the company
181  */
182  function display_info(){
183  $itva=new IText('num_tva',$this->num_tva);$str_tva=$itva->input();
184  $iname=new IText('name',$this->tva_name); $str_name=$iname->input();
185  $iadress=new IText('adress',$this->adress);$str_adress=$iadress->input();
186  $icountry=new IText('country',$this->country);$str_country=$icountry->input();
187 
188  /* date */
189 
190  if (isset($this->date_decl)) { $idate=new IText('date',format_date($this->date_decl));$str_date=$idate->input();}
191 
192  /* periode */
193 
194  if ( isset($this->start_date) ){
195  $str_start=format_date($this->start_date);
196  $str_end=format_date($this->end_date);
197 
198  }
199  $ianne=$this->exercice;
200  ob_start();
201  require_once('form_decl_info.php');
202  $r=ob_get_contents();
203  ob_end_clean();
204  return $r;
205  }
206 
207 }
if(isset($_POST['save'])) $exercice
$r
display_info()
display the information about the company
$GLOBALS['quaterly_limit']
set_parameter($p_string, $p_value)
blank($p_year, $p_periode, $p_flag_quaterly)
if(isset($_POST['remove'])) $array
static choose_periode($by_year=false)
get_array_nodup($p_string)
transform a string into an arrau without empty element and duplicate the array is sorted ...
$_REQUEST['sb']
Definition: am_print.php:39
get_parameter($p_string)
switch($sep_field->selected) $str_date