Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 require_once("class_idate.php");
00030 require_once("class_itext.php");
00031 require_once("class_iselect.php");
00032 require_once("class_icheckbox.php");
00033 require_once ("class_anc_operation.php");
00034 require_once('class_database.php');
00035 require_once ('class_anc_plan.php');
00036 require_once ('class_dossier.php');
00037
00038 class Anc_Group_Operation
00039 {
00040 var $db;
00041 var $id;
00042
00043
00044
00045
00046 var $a_operation;
00047 var $date;
00048 var $pa_id;
00049
00050
00051 function Anc_Group_Operation($p_cn,$p_id=0)
00052 {
00053 $this->db=$p_cn;
00054 $this->id=$p_id;
00055 $this->date=date("d.m.Y");
00056 $this->nMaxRow=10;
00057 }
00058
00059 function add()
00060 {
00061
00062 $amount=0;
00063 try
00064 {
00065 $this->db->start();
00066 foreach ($this->a_operation as $row)
00067 {
00068 $add=round($row->oa_amount,2);
00069 $add=($row->oa_debit=='t')?$add:$add*(-1);
00070 $amount+=round($add,2);
00071 $row->add();
00072 }
00073 if ( $amount != 0 ) throw new Exception (_('Operation non equilibrée'));
00074 }
00075 catch (Exception $e)
00076 {
00077 echo $e->getTrace();
00078 $this->db->rollback();
00079 exit();
00080 }
00081 $this->db->commit();
00082 }
00083
00084
00085
00086
00087 function form($p_readonly=0)
00088 {
00089 $wDate=new IDate("pdate",$this->date);
00090 $wDate->table=1;
00091 $wDate->size=10;
00092 $wDate->readonly=$p_readonly;
00093
00094 $wDescription=new IText("pdesc");
00095 $wDescription->table=0;
00096 $wDescription->size=80;
00097 $wDescription->readonly=$p_readonly;
00098
00099
00100 if ( isset ($this->a_operation[0]))
00101 {
00102 $wDate->value=$this->a_operation[0]->oa_date;
00103 $wDescription->value=$this->a_operation[0]->oa_description;
00104 }
00105
00106 $ret="";
00107
00108 $ret.='<table style="result" >';
00109
00110 $ret.="<TR>".$wDate->input()."</tr>";
00111 $ret.='<tr><td>Description</td>'.
00112 '<td colspan="3">'.
00113 $wDescription->input()."</td></tr>";
00114 $Plan=new Anc_Plan($this->db);
00115 $aPlan=$Plan->get_list();
00116 $max=(count($this->a_operation)<$this->nMaxRow)?$this->nMaxRow:count($this->a_operation);
00117 $ret.='</table><table id="ago" style="width: 100%;">';
00118
00119 $ret.="<tr>";
00120 foreach ($aPlan as $d)
00121 {
00122 $idx=$d['id'];
00123
00124 $aPoste[$idx]=$this->db->make_array("select po_id as value,".
00125 " po_name||':'||coalesce(po_description,'-') as label ".
00126 " from poste_analytique ".
00127 " where pa_id = ".$idx.
00128 " order by po_name ");
00129
00130 $ret.="<th> Poste </th>";
00131 }
00132 $ret.="<th></th>".
00133 "<th> Montant</th>".
00134 "<th>Débit</th>".
00135 "</tr>";
00136
00137 for ($i = 0;$i < $max;$i++)
00138 {
00139 $ret.="<tr>";
00140
00141 foreach ($aPlan as $d)
00142 {
00143 $idx=$d['id'];
00144
00145 $wSelect=new ISelect("pop".$i."plan".$idx);
00146 $wSelect->value=$aPoste[$idx];
00147 $wSelect->size=12;
00148
00149 $wSelect->readOnly=$p_readonly;
00150 if ( isset($this->a_operation[$i]))
00151 {
00152 $wSelect->selected=$this->a_operation[$i]->po_id;
00153 }
00154 $ret.=td($wSelect->input());
00155 }
00156 $wAmount=new INum("pamount$i",0.0);
00157 $wAmount->size=12;
00158 $wAmount->table=1;
00159 $wAmount->javascript=" onChange=format_number(this);caod_checkTotal()";
00160 $wAmount->readOnly=$p_readonly;
00161
00162 $wDebit=new ICheckBox("pdeb$i");
00163 $wDebit->readOnly=$p_readonly;
00164 $wDebit->javascript=" onChange=caod_checkTotal()";
00165 if ( isset ($this->a_operation[$i]))
00166 {
00167 $wSelect->selected=$this->a_operation[$i]->po_id;
00168 $wAmount->value=$this->a_operation[$i]->oa_amount;
00169 $wDebit->value=$this->a_operation[$i]->oa_debit;
00170 if ( $wDebit->value=='t')
00171 {
00172 $wDebit->selected=true;
00173 }
00174
00175 }
00176
00177
00178
00179 $ret.="<TD></TD>";
00180 $ret.=$wAmount->input();
00181 $ret.=td($wDebit->input());
00182
00183 $ret.="</tr>";
00184 }
00185 $ret.="</table>";
00186 if ( $p_readonly==false)
00187 {
00188 $add_row=new IButton('Ajouter');
00189 $add_row->label=_('Ajouter une ligne');
00190 $add_row->javascript='anc_add_row(\'ago\');';
00191 $ret.=HtmlInput::hidden('nbrow',$max);
00192
00193 $ret.=$add_row->input();
00194 }
00195 return $ret;
00196 }
00197
00198
00199
00200 function get_from_array($p_array)
00201 {
00202 $Plan=new Anc_Plan($this->db);
00203 $aPlan=$Plan->get_list();
00204
00205
00206 for ( $i = 0;$i <$p_array['nbrow'];$i++)
00207 {
00208 foreach ($aPlan as $d)
00209 {
00210 $idx=$d['id'];
00211 $p=new Anc_Operation($this->db);
00212 $p->oa_amount=$p_array["pamount$i"];
00213
00214 $p->oa_description=$p_array["pdesc"];
00215 $p->oa_date=$p_array['pdate'];
00216 $p->j_id=0;
00217 $p->oa_debit=(isset ($p_array["pdeb$i"]))?'t':'f';
00218 $p->oa_group=0;
00219
00220 $p->po_id=$p_array["pop$i"."plan".$idx];
00221 $p->pa_id=$idx;
00222 $this->a_operation[]=clone $p;
00223 }
00224 }
00225 }
00226
00227
00228 function save()
00229 {
00230 $this->db->start();
00231 try
00232 {
00233 $oa_group=$this->db->get_next_seq('s_oa_group');
00234 for ($i=0;$i<count($this->a_operation);$i++)
00235 {
00236 $this->a_operation[$i]->oa_group=$oa_group;
00237 $this->a_operation[$i]->add();
00238 }
00239 }
00240 catch (Exception $ex)
00241 {
00242 echo '<span class="error">'.
00243 'Erreur dans l\'enregistrement '.
00244 __FILE__.':'.__LINE__.' '.
00245 $ex->getMessage();
00246 $p_cn->rollback();
00247 exit();
00248
00249 }
00250 $this->db->commit();
00251 }
00252
00253 function show()
00254 {
00255 return $this->form(1);
00256 }
00257 static function test_me()
00258 {
00259 $dossier=dossier::id();
00260 $cn=new Database($dossier);
00261
00262 if ( isset($_POST['go']))
00263 {
00264 $b=new Anc_Group_Operation($cn);
00265 $b->get_from_array($_POST);
00266 exit();
00267 }
00268
00269 $a=new Anc_Group_Operation($cn);
00270 echo '<form method="post">';
00271 echo $a->form();
00272 echo dossier::hidden();
00273 echo '<input type="submit" name="go">';
00274 echo '</form>';
00275
00276 }
00277
00278 }