26 require_once(
'class_amortissement_sql.php');
27 require_once(
'class_amortissement_detail_sql.php');
28 require_once(
'class_amortissement_histo_sql.php');
53 $ret=$amort->seek(
" join fiche_detail using(f_id) where a_visible = 'Y' and ad_id=1 order by ad_value");
55 require_once(
'template/material_listing.php');
63 $add=
new IButton(
'add_card');
64 $add->label=_(
"Ajout d'un bien à amortir");
65 $add->javascript=sprintf(
"add_material(%d,'%s','bxmat')",
80 $fiche->get_by_qcode($p_array[
'p_card']);
81 $this->amortissement->a_id=(isset($p_array[
'a_id']))?$p_array[
'a_id']:-1;
82 $this->amortissement->f_id=
$fiche->id;
83 $this->amortissement->account_deb=$p_array[
'p_deb'];
84 $this->amortissement->account_cred=$p_array[
'p_cred'];
85 $this->amortissement->a_start=$p_array[
'p_year'];
86 $this->amortissement->a_amount=$p_array[
'p_amount'];
87 $this->amortissement->a_nb_year=$p_array[
'p_number'];
88 $this->amortissement->a_date=$p_array[
'p_date'];
89 $this->amortissement->a_visible=(isset($p_array[
'p_visible']))?$p_array[
'p_visible']:
'Y';
91 if ( $p_array[
'type'] == 1 ) {
92 $fiche_deb=
new Fiche($cn);
93 $fiche_deb->get_by_qcode($p_array[
'p_card_deb'],
false);
94 $this->amortissement->card_deb=($fiche_deb->id != 0 ) ? $fiche_deb->id:null;
96 $fiche_cred=
new Fiche($cn);
97 $fiche_cred->get_by_qcode($p_array[
'p_card_cred'],
false);
98 $this->amortissement->card_cred=($fiche_cred->id != 0 ) ? $fiche_cred->id:null;
99 $this->amortissement->account_deb=null;
100 $this->amortissement->account_cred=null;
102 $this->amortissement->account_deb=$p_array[
'p_deb'];
103 $this->amortissement->account_cred=$p_array[
'p_cred'];
104 $this->amortissement->card_cred=null;
105 $this->amortissement->card_deb=null;
110 if ( isset($p_array[
'ad_id']))
112 for ($i=0;$i<count($p_array[
'ad_id']);$i++)
115 $am->ad_id=$p_array[
'ad_id'][$i];
116 $am->ad_amount=$p_array[
'amount'][$i];
117 $am->ad_amount=$p_array[
'amount'][$i];
118 $am->a_id=$this->amortissement->a_id;
119 $am->ad_percentage=$p_array[
'pct'][$i];
120 $am->ad_year=$p_array[
'ad_year'][$i];
122 $this->amortissement_detail[]=clone(
$am);
130 if ( isset ($p_array[
'h']))
132 for ($i=0;$i<count($p_array[
'h']);$i++)
134 $id=$p_array[
'h'][$i];
137 $am->h_amount=$p_array[
'p_histo'][$i];
138 $am->h_pj=$p_array[
'p_pj'][$i];
140 if ( isset ($p_array[
'op_concerne'][
$id])) {
141 $am->jr_id=$p_array[
'op_concerne'][
$id];
146 $this->amortissement_histo[]=clone(
$am);
156 $this->amortissement->load();
158 $array=$this->amortissement_detail->seek(
' where a_id=$1 order by ad_year asc',array($this->amortissement->a_id));
161 $a_id=HtmlInput::hidden(
'a_id',$this->amortissement->a_id);
162 $value_a_id=$this->amortissement->a_id;
165 $p_year->value=$this->amortissement->a_start;
167 $p_number->value=$this->amortissement->a_nb_year;
170 $p_date->value=$this->amortissement->a_date;
172 $p_visible=
new IText(
'p_visible');
174 $p_visible->value=$this->amortissement->a_visible;
175 $card=
new Fiche($cn,$this->amortissement->f_id);
177 $p_card=HtmlInput::hidden(
'p_card',$card->strAttribut(ATTR_DEF_QUICKCODE));
180 $p_deb=
new IPoste(
'p_deb');
181 $p_deb->set_attribute(
'jrn',0);
182 $p_deb->set_attribute(
'account',
'p_deb');
183 $p_deb->set_attribute(
'label',
'p_deb_label');
184 $p_deb->value=$this->amortissement->account_deb;
188 $p_cred->set_attribute(
'jrn',0);
189 $p_cred->set_attribute(
'account',
'p_cred');
190 $p_cred->set_attribute(
'label',
'p_cred_label');
191 $p_cred->value=$this->amortissement->account_cred;
196 $p_amount->value= $this->amortissement->a_amount;
199 $select_type->value=array(array(
'label'=>
'--Faites un choix --',
'value'=>-1),
200 array(
'label'=>
'Poste comptable',
'value'=>
'0'),
201 array(
'label'=>
'Fiche',
'value'=>
'1')
204 $select_type->selected=HtmlInput::default_value_post(
'type',
'-1');
205 $select_type->javascript=
' onchange = "show_selected_material(this);"';
207 if ( $this->amortissement->card_deb !=
'')
$select_type->selected=1;
208 if ( $this->amortissement->account_deb !=
'')
$select_type->selected=0;
210 $fiche_deb=
new Fiche($cn);
216 if ( $this->amortissement->card_deb !=
'' )
218 $fiche_deb=
new Fiche($cn,$this->amortissement->card_deb);
221 if ( $this->amortissement->card_cred !=
'' )
223 $fiche_cred=
new Fiche($cn,$this->amortissement->card_cred);
226 require_once(
'template/material_detail.php');
235 if ( isNumber($_POST[
'p_year']) == null || $_POST[
'p_year']<1900||$_POST[
'p_year'] > 3000 )
$error_msg.=_(
'Année invalide').
"\n";
236 if ( isNumber($_POST[
'p_number']) == null )
$error_msg.=_ (
'Nombre annuités invalide').
"\n";
237 if ( isNumber($_POST[
'p_amount']) == null || $_POST[
'p_amount']==0)
$error_msg.=_ (
'Montant invalide').
"\n";
238 $p_card = HtmlInput::default_value_post(
'p_card',
'');
239 $visible=HtmlInput::default_value_post(
'p_visible',
'Y');
240 if ( $visible !=
'Y' && $visible !=
'N')
$error_msg.=_(
"Visible Y ou N\n");
241 $_POST[
'p_visible']=$visible;
242 switch ( $_POST[
'type'] )
245 $error_msg .= _(
'Choisissez poste comptable ou fiche');
248 if ( $cn->get_value(
'select count(*) from tmp_pcmn where pcm_val=$1',array($_POST[
'p_deb'])) == 0)
$error_msg.=
" Poste de charge incorrect".
"\n";
249 if ( $cn->get_value(
'select count(*) from tmp_pcmn where pcm_val=$1',array($_POST[
'p_cred'])) == 0)
$error_msg.=
" Poste à créditer incorrect".
"\n";
252 if ( $cn->get_value(
'select j_poste from vw_poste_qcode where j_qcode=trim(upper($1))',array($_POST[
'p_card_deb'])) ==
"")
$error_msg.=
" Fiche de charge incorrect".
"\n";
253 if ( $cn->get_value(
'select j_poste from vw_poste_qcode where j_qcode=trim(upper($1))',array($_POST[
'p_card_cred'])) ==
"")
$error_msg.=
" Fiche contrepartie incorrect".
"\n";
256 $p_new=HtmlInput::default_value_post(
'p_new',-1);
260 if ( $p_new != -1 ) {
261 $f_id=$cn->get_value(
'select f_id from vw_poste_qcode where j_qcode=trim(upper($1))',array(
$p_card));
263 if ( $cn->get_value(
'select count(*) from amortissement.amortissement where f_id = $1',array($f_id)) > 0 )
$error_msg.=_(
'Matériel déjà dans la liste');
270 $nb_histo=count($this->amortissement_histo);
271 for ($i=0;$i<$nb_histo;$i++)
273 $jr_id=$this->amortissement_histo[$i]->jr_id;
274 if (isNumber($jr_id) == 1 && $jr_id != 0 )
276 $this->amortissement_histo[$i]->jr_internal=$cn->get_value(
'select jr_internal from jrn where jr_id=$1',
294 $this->amortissement->update();
295 if (isset($this->amortissement_detail))
297 for ($i=0; $i<count($this->amortissement_detail); $i++)
299 $this->amortissement_detail[$i]->update();
300 if ( $this->amortissement_histo[$i]->
jr_internal ==
"")
301 $this->amortissement_histo[$i]->jr_internal=null;
302 $this->amortissement_histo[$i]->update();
307 $cn->exec_sql(
'delete from amortissement.amortissement_detail where ad_amount=0');
311 echo $e->getMessage();
323 $this->amortissement->save();
330 $this->amortissement->a_id=$cn->get_value(
"select a_id from amortissement.amortissement where f_id=$1",
339 $card=
new Fiche($cn);
340 $card->get_by_qcode($p_code);
342 $amort->a_id=$cn->get_value(
'select a_id from amortissement.amortissement where f_id=$1',array($card->id));
344 if ( $amort->a_id ==
'')
346 echo
'<h2 class="error">Non trouvé</h2>';
352 $p_deb=$amort->account_deb;
353 $deb_span=$cn->get_value(
'select pcm_lib from tmp_pcmn where pcm_val=$1',
356 $cred_span=$cn->get_value(
'select pcm_lib from tmp_pcmn where pcm_val=$1',
361 $array=
$a->seek(
' where a_id=$1 order by ad_year asc',array($amort->a_id));
363 $fiche_deb=
new Fiche($cn);
370 if ( $amort->card_deb !=
'' )
372 $fiche_deb=
new Fiche($cn,$amort->card_deb);
375 if ( $amort->card_cred !=
'' )
377 $fiche_cred=
new Fiche($cn,$amort->card_cred);
381 require_once(
'template/material_display.php');
Manage the table amortissement.amortissement_detail.
input()
show a form to modify data
print_detail($p_code)
Display the detail of a card.
add()
we save into the two tables amortissement and amortissement_detail, the table amortissement_detail is...
if(isset($_POST['remove'])) $array
listing($p_all=false)
display the list of material
add_card()
display a button to add a material
Manage the table amortissement.amortissement_histo.
update()
we save into the two tables amortissement and amortissement_detail
if(isset($_POST['generate'])) if(isset($_POST['save']))
Manage the table amortissement.amortissement.
from_array($p_array)
all the data are in the array : we construct an object with data from the array
if($p_number->value==0) l les annuités seront recalculées et l pct[] ad_year[] select jr_internal
verify_post()
Verify that all data are correct.