Plugins  LAST
 All Data Structures Files Functions Variables Pages
class_ext_list_intra.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('class_listing.php');
28 require_once(NOALYSS_INCLUDE.'/class/class_fiche.php');
29 require_once('class_tva_parameter.php');
30 class Ext_List_Intra extends Listing {
31  protected $variable = array(
32  "id"=>"i_id",
33  "date"=>"i_date",
34  "date_decl"=>"date_decl",
35  "start_periode"=>"start_periode",
36  "end_periode"=>"end_periode",
37  "xml_file"=>"xml_file",
38  "num_tva"=>"num_tva",
39  "name"=>"tva_name",
40  "adress"=>"adress",
41  "country"=>"country",
42  "flag_periode"=>"flag_periode",
43  "exercice"=>"exercice",
44  "periode_dec"=>"periode_dec"
45  );
46  private $aChild=array();
47 
48  function from_array($p_array){
49  if( isset($p_array['name_child'])) {
50  $name=$p_array['name_child'];
51  $qcode=$p_array['qcode'];
52  $code=$p_array['tvacode'];
53  $tva_num=$p_array['tva_num_child'];
54  $amount=$p_array['amount'];
55  $periode=$p_array['periode'];
56  $array=array();
57  // retrieve missing and compute an array
58  for ($i=0;$i<count($name);$i++){
59  $child=new Ext_List_Intra_Child($this->db);
60  $child->set_parameter('amount',$amount[$i]);
61  $child->set_parameter('periode',$periode[$i]);
62  $child->set_parameter('qcode',$qcode[$i]);
63  $child->set_parameter('code',$code[$i]);
64  $child->set_parameter('name_child',$name[$i]);
65  $child->set_parameter('tva_num',$tva_num[$i]);
66 
67  $array[]=$child;
68  }//end for
69  $this->aChild=$array;
70  } else
71  $this->aChild=array();
72 
73  $this->start_periode=$p_array['start_periode'];
74  $this->end_periode=$p_array['end_periode'];
75  $this->flag_periode=$p_array['flag_periode'];
76  $this->tva_name=$p_array['name'];
77  $this->num_tva=$p_array['num_tva'];
78  $this->adress=$p_array['adress'];
79  $this->country=$p_array['country'];
80  $this->periode_dec=$p_array['periode_dec'];
81  $this->exercice=$p_array['exercice'];
82 
83  }
84  function display() {
85  $r= '<form class="print" id="readonly">';
86  $r.=$this->display_info();
87  $r.=HtmlInput::request_to_hidden(array('ac'));
89  $r.='</form>';
90  $js_remove=sprintf("onclick=\"if ( confirm('%s')){remove_form('%s',%d,%d,'li');}\"",
91  "Vous confirmez vouloir effacer ?",
92  $_REQUEST['plugin_code'],
93  dossier::id(),
94  $this->i_id);
95 
96  $r.=HtmlInput::button('Effacer','Effacer',$js_remove);
97  $r.= create_script("$('readonly').disable();");
98  return $r;
99  }
100  function load() {
101  $sql="select * from tva_belge.intracomm where i_id=$1";
102 
103  $res=$this->db->get_array(
104  $sql,
105  array($this->i_id)
106  );
107  if ( $this->db->count() == 0 ) return 0;
108  foreach ($res[0] as $idx=>$value) { $this->$idx=$value; }
109  // load child
110  $sql="select * from tva_belge.intracomm_chld where i_id=$1";
111  $res=$this->db->get_array(
112  $sql,
113  array($this->i_id)
114  );
115  $nb=$this->db->count();
116  $array=array();
117  // retrieve missing and compute an array
118  for ($i=0;$i<$nb;$i++){
119  $child=new Ext_List_Intra_Child($this->db);
120  foreach ($res[$i] as $idx=>$value){
121  $child->$idx=$value;
122  }
123  $array[]=$child;
124  }//end for
125  $this->aChild=$array;
126 
127  return 1;
128  }
129  function verify() {
130  return 0;
131  }
132  function insert() {
133  $this->db->start();
134 
135  /* insert into the first table */
136  $sql=<<<EOF
137 INSERT INTO tva_belge.intracomm(
138  start_date, end_date, periodicity, tva_name,
139  num_tva, adress, country, periode_dec,exercice)
140  VALUES (to_date($1,'DD.MM.YYYY'),to_date($2,'DD.MM.YYYY'),$3,$4,$5,$6,$7,$8,$9) returning i_id;
141 EOF;
142 $this->i_id=$this->db->get_value($sql,
143  array(
144  $this->start_periode,
145  $this->end_periode,
146  $this->flag_periode,
147  $this->tva_name,
148  $this->num_tva,
149  $this->adress,
150  $this->country,
151  $this->periode_dec,
152  $this->exercice
153  )
154  );
155 /* insert into the child table */
156 for ($e=0;$e<count($this->aChild);$e++){
157  $this->aChild[$e]->set_parameter('depend',$this->i_id);
158  $this->aChild[$e]->insert();
159 }
160  $this->db->commit();
161 
162  }
163  function update() {
164  }
165 
166  function compute(){
167  /* retrieve accounting customer */
168  $code_customer=new Acc_Parm_Code($this->db);
169  $code_customer->p_code='CUSTOMER';
170  $code_customer->load();
171  $a=$this->find_tva_code('CLINTRA');
172 
173  if (trim($a)=='') $a=-1;
174  $sql=<<<EOF
175  select sum(j_montant) as amount,j_qcode
176  from jrnx
177  where j_grpt in (select distinct j_grpt from quant_sold join jrnx using (j_id) where qs_vat_code in ($a) )
178  and j_poste::text like $1||'%'
179  and (j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date($3,'DD.MM.YYYY'))
180  group by j_qcode
181 EOF;
182  // get all of them
183  $all=$this->db->get_array($sql,array($code_customer->p_value,
184  $this->start_periode,
185  $this->end_periode
186  )
187  );
188  $array=array();
189 
190  // retrieve missing and compute an array
191  for ($i=0;$i<count($all);$i++){
192  $child=new Ext_List_Intra_Child($this->db);
193  $child->set_parameter('amount',$all[$i]['amount']);
194  switch ($this->flag_periode) {
195  case 1:
196  // by month
197  $child->set_parameter('periode',sprintf('%02d%s',$this->periode_dec,$this->exercice));
198  break;
199  case 2:
200  /* quaterly */
201  $child->set_parameter('periode',sprintf('3%d%s',$this->periode_dec,$this->exercice));
202  break;
203  case 3:
204  /* yearly */
205  $child->set_parameter('periode',sprintf('00%s',$this->periode_dec,$this->exercice));
206  break;
207  } // end switch
208 
209  $child->set_parameter('qcode',$all[$i]['j_qcode']);
210  $fiche=new Fiche($this->db);
211  $fiche->get_by_qcode($all[$i]['j_qcode'],false);
212  $num_tva=$fiche->strAttribut(ATTR_DEF_NUMTVA);
213 
214  if ( trim($num_tva) === "") {continue;}
215  $child->set_parameter('tva_num',$num_tva);
216 
217  $child->set_parameter('name_child',$fiche->strAttribut(ATTR_DEF_NAME));
218  $child->set_parameter('code','L');
219 
220  $array[]=$child;
221  }//end for
222  $this->aChild=$array;
223  }
224  /**
225  *@todo finish it
226  */
227  function display_declaration_amount($p_readonly=false) {
228  $res='<fieldset><legend>Listing</legend>';
229 
230  $res.= '<table id="tb_dsp" class="result" style="width:80%;">';
231  $clean=new IButton();
232  $clean->label='Efface ligne';
233  $clean->javascript="deleteRow('tb_dsp',this);";
234 
235  $r='';
236  $r.=th('QuickCode');
237  $r.=th('Name');
238  $r.=th('Code Pays et numéro de TVA');
239  $r.=th('Code Pays et numéro de TVA');
240  $r.=th('montant');
241  $r.=th('periode');
242  $r.=th('');
243  $amount=0;
244  $res.=tr($r);
245  for ($i=0;$i<count($this->aChild);$i++) {
246  $a=new IText('qcode[]',$this->aChild[$i]->get_parameter('qcode'));
247  $b=new IText('name_child[]',$this->aChild[$i]->get_parameter('name_child'));
248  $c=new IText('tva_num_child[]',$this->aChild[$i]->get_parameter('tva_num'));
249  $d=new IText('tvacode[]',$this->aChild[$i]->get_parameter('code'));
250  $e=new INum('amount[]',$this->aChild[$i]->get_parameter('amount'));
251  $f=new IText('periode[]',$this->aChild[$i]->get_parameter('periode'));
252 
253  $amount+=round($this->aChild[$i]->get_parameter('amount'),2);
254  $r=td($a->input());
255  $r.=td($b->input());
256  $r.=td($c->input());
257  $r.=td($d->input());
258  $r.=td($e->input());
259  $r.=td($f->input());
260  if (! $p_readonly) $r.=td($clean->input());
261  $res.=tr($r);
262 
263  }
264  if ( $p_readonly)
265  {
266  $r=td('');
267  $r.=td('');
268  $r.=td('');
269  $r.=td(hb('Total'));
270  $r.=td(hb(sprintf('%.02f',$amount)));
271  $r.=td('');
272  $r.=td('');
273  $res.=tr($r);
274  }
275  $res.='</table>';
276  $res.='</fieldset>';
277  return $res;
278  }
279 }
281 class Ext_List_Intra_Child extends Ext_List_Intra {
282  protected $variable=array(
283  "id"=>"ic_id",
284  "tva_num"=>"ic_tvanum",
285  "amount"=>"ic_amount",
286  "code"=>"ic_code",
287  "periode"=>"ic_periode",
288  "depend"=>"i_id",
289  "qcode"=>"ic_qcode",
290  "name_child"=>'ic_name'
291  );
292  function insert() {
293 $sql=<<<EOF
294 INSERT INTO tva_belge.intracomm_chld(
295  i_id, ic_tvanum, ic_amount, ic_code, ic_periode, ic_qcode,
296  ic_name)
297  VALUES ($1, $2, $3, $4, $5, $6, $7) returning ic_id;
298 EOF;
299 $this->ic_id=$this->db->get_value($sql,array(
300  $this->i_id,
301  $this->ic_tvanum,
302  $this->ic_amount,
303  $this->ic_code,
304  $this->ic_periode,
305  $this->ic_qcode,
306  $this->ic_name));
307  }
308 
309 }
$f
Definition: show_field.php:4
$select_type id
$periode
$r
display_info()
display the information about the company
display_declaration_amount($p_readonly=false)
if(isset($_POST['remove'])) $array
find_tva_code($p_array)
$res
$_REQUEST['sb']
Definition: am_print.php:39
$sql
get_parameter($p_string)
$name