noalyss Version-9
anc_group_operation.class.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
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*!\file
23 * \brief group of object operations, used for misc operation
24 */
25
26/*! \brief group of object operations, used for misc operation
27 *
28 */
29
31{
32 var $db; /*!< database connection */
33 var $id; /*!< oa_group, a group contains
34 several rows of
35 operation_analytique linked by the
36 group id */
37
38 var $a_operation; /*!< array of operations */
39 var $date; /*!< date of the operations */
40 var $pa_id; /*!< the concerned pa_id */
41
42 /*!\brief constructor */
43 function __construct($p_cn,$p_id=0)
44 {
45 $this->db=$p_cn;
46 $this->id=$p_id;
47 $this->date=date("d.m.Y");
48 $this->nMaxRow=10;
49 }
50 /*!\brief add several rows */
51 function add()
52 {
53
54 $amount=0;
55 try
56 {
57 $this->db->start();
58 foreach ($this->a_operation as $row)
59 {
60 $add=round($row->oa_amount,2);
61 $add=($row->oa_debit=='t')?$add:$add*(-1);
62 $amount+=round($add,2);
63 $row->add();
64 }
65 if ( $amount != 0 ) throw new Exception (_('Operation non equilibrée'));
66 }
67 catch (Exception $e)
68 {
70 echo $e->getTrace();
71 $this->db->rollback();
72 throw new Exception($e);
73 }
74 $this->db->commit();
75 }
76 /*!\brief show a form for the operation (several rows)
77 * \return the string containing the form but without the form tag
78 *
79 */
80 function form($p_readonly=0)
81 {
82 $wDate=new IDate("pdate",$this->date);
83 $wDate->table=1;
84 $wDate->size=10;
85 $wDate->readonly=$p_readonly;
86
87 $wDescription=new IText("pdesc");
88 $wDescription->table=0;
89 $wDescription->size=80;
90 $wDescription->readonly=$p_readonly;
91 // Show an existing operation
92 //
93 if ( isset ($this->a_operation[0]))
94 {
95 $wDate->value=$this->a_operation[0]->oa_date;
96 $wDescription->value=$this->a_operation[0]->oa_description;
97 }
98
99 $ret="";
100
101 $ret.='<table style="result" >';
102
103 $ret.="<TR>".td(_("Date")).td($wDate->input())."</tr>";
104 $ret.='<tr><td>Description</td>'.
105 '<td colspan="3">'.
106 $wDescription->input()."</td></tr>";
107 $Plan=new Anc_Plan($this->db);
108 $aPlan=$Plan->get_list();
109 $this->a_operation=(empty($this->a_operation))?[]:$this->a_operation;
110 $max=(count($this->a_operation)<$this->nMaxRow)?$this->nMaxRow:count($this->a_operation);
111 $ret.='</table><table id="ago" style="width: 100%;">';
112 /* show 10 rows */
113 $ret.="<tr>";
114 $ret.=th(_("Fiche"),'style="text-align:left"').th("");
115 foreach ($aPlan as $d)
116 {
117 $idx=$d['id'];
118 /* array of possible value for the select */
119 $aPoste[$idx]=$this->db->make_array("select 0 as value,'-' as label "
120 . " union select po_id as value,".
121 " po_name||':'||coalesce(po_description,'-') as label ".
122 " from poste_analytique ".
123 " where pa_id = ".$idx.
124 " order by 2 ");
125
126 $ret.="<th style=\"text-align:left\">".$d['name']."</th>";
127 }
128 $ret.="<th></th>".
129 "<th style=\"text-align:left\">"._('Montant') ."</th>".
130 "<th style=\"text-align:left\">"._("Débit")."</th>".
131 "</tr>";
132
133 for ($i = 0;$i < $max;$i++)
134 {
135 if ( $p_readonly == 1 && isset($this->a_operation[$i]) && $this->a_operation[$i]->po_id ==0 ) continue;
136 $ret.="<tr>";
137 $ret.="<td>";
138 $card=new ICard("qcode$i");
139 $card->set_attribute("typecard", sprintf("[sql] fd_id in (select fd_id from jnt_fic_attr where ad_id=%s)",ATTR_DEF_ACCOUNT));
140 $card->set_attribute('label', "qcode{$i}_label");
141 $card->setReadOnly($p_readonly);
142 $card->value=(isset($this->a_operation[$i]->card))?$this->a_operation[$i]->card:"";
143 $ret.=$card->input();
144 $ret.=$card->search();
145
146 $ret.='</td>';
147 $ret.='<td>';
148 $label=new ISpan("qcode{$i}_label");
149 $label->style="vertical-align:top";
150 $ret.=$label->input();
151 $ret.='</td>';
152 foreach ($aPlan as $d)
153 {
154 $idx=$d['id'];
155 // init variable
156 $wSelect=new ISelect("pop".$i."plan".$idx);
157 $wSelect->value=$aPoste[$idx];
158 $wSelect->size=12;
159
160 $wSelect->readOnly=$p_readonly;
161 if ( isset($this->a_operation[$i]))
162 {
163 $wSelect->selected=$this->a_operation[$i]->po_id;
164 }
165 $ret.=td($wSelect->input());
166 }
167 $wAmount=new INum("pamount$i",0.0);
168 $wAmount->size=12;
169 $wAmount->table=1;
170 $wAmount->javascript=" onChange=format_number(this);caod_checkTotal()";
171 $wAmount->readOnly=$p_readonly;
172
173 $wDebit=new ICheckBox("pdeb$i");
174 $wDebit->readOnly=$p_readonly;
175 $wDebit->javascript=" onChange=caod_checkTotal()";
176 if ( isset ($this->a_operation[$i]))
177 {
178 $wSelect->selected=$this->a_operation[$i]->po_id;
179 $wAmount->value=$this->a_operation[$i]->oa_amount;
180 $wDebit->value=$this->a_operation[$i]->oa_debit;
181 if ( $wDebit->value=='t')
182 {
183 $wDebit->selected=true;
184 }
185
186 }
187
188 // build the table
189
190 $ret.="<TD></TD>";
191 $ret.=$wAmount->input();
192 $ret.=td($wDebit->input());
193
194 $ret.="</tr>";
195 }
196 $ret.="</table>";
197 if ( $p_readonly==false)
198 {
199 $add_row=new IButton('Ajouter');
200 $add_row->label=_('Ajouter une ligne');
201 $add_row->javascript='anc_add_row(\'ago\');';
202 $ret.=HtmlInput::hidden('nbrow',$max);
203
204 $ret.=$add_row->input();
205 }
206 return $ret;
207 }
208 /*!\brief fill row from $_POST data
209 *
210 */
212 {
213 $Plan=new Anc_Plan($this->db);
214 $aPlan=$Plan->get_list();
215
216
217 for ( $i = 0;$i <$p_array['nbrow'];$i++)
218 {
219 foreach ($aPlan as $d)
220 {
221 $idx=$d['id'];
222 $p=new Anc_Operation($this->db);
223 $p->oa_amount=$p_array["pamount$i"];
224
225 $p->oa_description=$p_array["pdesc"];
226 $p->oa_row=$i;
227 $p->oa_date=$p_array['pdate'];
228 $p->j_id=0;
229 $p->oa_debit=(isset ($p_array["pdeb$i"]))?'t':'f';
230 $p->oa_group=0;
231 $p->card=(isset($p_array["qcode".$i]))?$p_array["qcode".$i]:"";
232 $p->po_id=$p_array["pop$i"."plan".$idx];
233 $p->pa_id=$idx;
234 $this->a_operation[]=clone $p;
235 }
236 }
237 }
238 /*!\brief save the group of operation but only if the amount is
239 balanced */
240 function save()
241 {
242 $this->db->start();
243 try
244 {
245 $oa_group=$this->db->get_next_seq('s_oa_group');
246 for ($i=0;$i<count($this->a_operation);$i++)
247 {
248 if ( $this->a_operation[$i]->po_id == 0 ) continue;
249 $this->a_operation[$i]->oa_group=$oa_group;
250 $this->a_operation[$i]->add();
251 }
252 }
253 catch (Exception $ex)
254 {
255 record_log($e);
256 echo '<span class="error">'.
257 'Erreur dans l\'enregistrement '.
258 __FILE__.':'.__LINE__.' '.
259 $ex->getMessage();
260 $p_cn->rollback();
261 throw new Exception("Erreur ".$ex->getMessage());
262
263 }
264 $this->db->commit();
265 }
266 /*!\brief show the form */
267 function show()
268 {
269 return $this->form(1);
270 }
271 static function test_me()
272 {
275
276 if ( isset($_POST['go']))
277 {
279 $b->get_from_array($_POST);
280 return;
281 }
282
284 echo '<form method="post">';
285 echo $a->form();
286 echo dossier::hidden();
287 echo '<input type="submit" name="go">';
288 echo '</form>';
289
290 }
291
292}
th($p_string, $p_extra='', $raw='')
Definition: ac_common.php:58
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1342
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
$idx
$p
Definition: array.php:34
$input_from id
Definition: balance.inc.php:63
$ex
Definition: balance.inc.php:45
$dossier
group of object operations, used for misc operation
save()
save the group of operation but only if the amount is balanced
form($p_readonly=0)
show a form for the operation (several rows)
__construct($p_cn, $p_id=0)
constructor
get_from_array($p_array)
fill row from $_POST data
this class is used to show the form for entering an operation only FOR analytic operation to save it,...
Concerns the Analytic plan (table plan_analytique)
static connect()
static hidden($p_name, $p_value, $p_id="")
Html Input.
Input HTML for the card show buttons, in the file, you have to add card.js How to use :
Html Input.
Html Input : Input a date format dd.mm.yyyy The property title should be set to indicate what it is e...
Definition: idate.class.php:34
This class handles only the numeric input, the input will call a javascript to change comma to period...
Definition: inum.class.php:42
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
Html Input.
Definition: ispan.class.php:32
Html Input.
Definition: itext.class.php:30
const ATTR_DEF_ACCOUNT
Definition: constant.php:215
$_POST['ac']
Definition: do.php:310
$SecUser db