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 require_once("class_ibutton.php");
00026 require_once("class_ihidden.php");
00027 require_once("class_iselect.php");
00028 require_once("class_itext.php");
00029 require_once("class_anc_plan.php");
00030 require_once ("user_common.php");
00031
00032
00033
00034
00035
00036
00037 class Anc_Operation
00038 {
00039 var $db;
00040 var $row;
00041 var $list;
00042 var $id;
00043 var $po_id;
00044 var $oa_amount;
00045 var $oa_description;
00046 var $oa_debit;
00047 var $j_id;
00048
00049 var $oa_group;
00050 var $oa_date;
00051 var $pa_id;
00052
00053
00054
00055
00056
00057 var $oa_jrnx_id_source;
00058
00059
00060
00061 var $oa_positive;
00062 var $in_div;
00063
00064
00065
00066 function Anc_Operation ($p_cn,$p_id=0)
00067 {
00068 $this->db=$p_cn;
00069 $this->id=$p_id;
00070 $this->oa_jrnx_id_source=null;
00071 $this->oa_positive='Y';
00072 $this->has_data=0;
00073 $this->in_div="";
00074 }
00075
00076
00077
00078
00079
00080 function add($p_seq=0)
00081 {
00082
00083 if ( $this->oa_group == 0)
00084 {
00085 $this->oa_group=$this->db->get_next_seq('s_oa_group');
00086 }
00087
00088 if ( $this->j_id == 0 )
00089 {
00090 $this->j_id=null;
00091 }
00092
00093
00094
00095 if ( $this->oa_amount == 0 || $this->po_id==-1)
00096 return;
00097
00098 if ( $this->oa_amount< 0)
00099 {
00100 $this->oa_debit=($this->oa_debit=='t')?'f':'t';
00101 $this->oa_positive='N';
00102 }
00103
00104 $oa_row=(isset($this->oa_row))?$this->oa_row:null;
00105 $sql="insert into operation_analytique (
00106 po_id,
00107 oa_amount,
00108 oa_description,
00109 oa_debit,
00110 oa_group,
00111 j_id,
00112 oa_date,
00113 oa_row,
00114 oa_jrnx_id_source,
00115 oa_positive
00116 ) values ($1,$2,$3,$4,$5,$6,to_date($7,'DD.MM.YYYY'),$8,$9,$10)";
00117
00118 $this->db->exec_sql($sql,array(
00119 $this->po_id,
00120 abs($this->oa_amount),
00121 $this->oa_description,
00122 $this->oa_debit,
00123 $this->oa_group,
00124 $this->j_id,
00125 $this->oa_date,
00126 $oa_row,
00127 $this->oa_jrnx_id_source,
00128 $this->oa_positive
00129 ));
00130
00131 }
00132
00133
00134
00135 function delete()
00136 {
00137 $sql="delete from operation_analytique where oa_id=$1";
00138
00139 $this->db->exec_sql($sql,array($this->oa_id));
00140 }
00141
00142
00143
00144 function get_list($p_from,$p_to,$p_from_poste="",$p_to_poste="")
00145 {
00146 $cond="";
00147 $cond_poste="";
00148
00149 if ($p_from!="")
00150 $cond="and (jr_date >= to_date('$p_from','DD.MM.YYYY') or oa_date >= to_date('$p_from','DD.MM.YYYY') )";
00151 if ( $p_to!="" )
00152 $cond.="and (jr_date <=to_date('$p_to','DD.MM.YYYY') or oa_date <=to_date('$p_to','DD.MM.YYYY')) ";
00153
00154 if ($p_from_poste != "" )
00155 $cond_poste=" and upper(po_name) >= upper('".$p_from_poste."')";
00156 if ($p_to_poste != "" )
00157 $cond_poste.=" and upper(po_name) <= upper('".$p_to_poste."')";
00158 $pa_id_cond="";
00159 if ( isset ( $this->pa_id) && $this->pa_id !='')
00160 $pa_id_cond= "pa_id=".$this->pa_id." and";
00161 $sql="
00162
00163 select oa_id,
00164 po_name,
00165 oa_description,
00166 po_description,
00167 oa_debit,
00168 (case when jr_date is not null then to_char(jr_date,'DD.MM.YYYY') else to_char(oa_date,'DD.MM.YYYY') end ) as oa_date,
00169 oa_amount,
00170 oa_group,
00171 j_id ,
00172 jr_internal,
00173 jr_id,
00174 jr_comment,
00175 j_poste,
00176 jrnx.f_id,
00177 ( select ad_value from fiche_Detail where f_id=jrnx.f_id and ad_id=23) as qcode,
00178 jr_pj_number
00179 from operation_analytique as B join poste_analytique using(po_id)
00180 left join jrnx using (j_id)
00181 left join jrn on (j_grpt=jr_grpt_id)
00182 where $pa_id_cond oa_amount <> 0.0 $cond $cond_poste
00183 order by jr_date,oa_group,oa_debit desc,oa_id";
00184
00185 $RetSql=$this->db->exec_sql($sql);
00186 $array=Database::fetch_all($RetSql);
00187 return $array;
00188 }
00189
00190
00191
00192 function html_table($p_from)
00193 {
00194 if ($p_from=="")
00195 {
00196 $from="";
00197 $to="";
00198 }
00199 else
00200 {
00201 $p=new Periode($this->db);
00202 list($from,$to)=$p->get_date_limit($p_from);
00203 }
00204
00205 $array=$this->get_list($from,$to);
00206 if ( empty($array) )
00207 return "Pas d'enregistrement trouvé";
00208
00209
00210 $step=$_SESSION['g_pagesize'];
00211 $page=(isset($_GET['offset']))?$_GET['page']:1;
00212 $offset=(isset($_GET['offset']))?$_GET['offset']:0;
00213 $bar=navigation_bar($offset+1,count($array),$step,$page);
00214
00215 if ( $step !=-1)
00216 $view=array_splice($array,$offset,$step);
00217 else
00218 $view=$array;
00219
00220 $gDossier=dossier::id();
00221 $ret="";
00222 $ret.=$bar;
00223
00224 $count=0;
00225 $group=0;
00226 $oldgroup=0;
00227 $oldjrid=0;
00228
00229 foreach ($view as $row)
00230 {
00231 $group=$row['oa_group'];
00232 if ( $group !=$oldgroup )
00233 {
00234 if ( $oldgroup!=0 )
00235 {
00236
00237 $efface=new IButton();
00238 $efface->javascript="anc_remove_operation(".$gDossier.",".$oldgroup.")";
00239 $efface->name="Efface";
00240 $efface->label="Efface";
00241 $ret.="<td>".$efface->input()."</td>";
00242
00243 $this->oa_group=$oldgroup;
00244 $jr_id=$this->get_jrid();
00245
00246 if ( $jr_id != 0)
00247 {
00248
00249 $detail=new IButton();
00250 $detail->javascript="viewOperation($jr_id,$gDossier)";
00251 $detail->name="Detail";
00252 $detail->label="Detail";
00253 $ret.="<td>".$detail->input()."</td>";
00254 }
00255 $ret.='</table>';
00256
00257 }
00258 $ret.='<table id="'.$row['oa_group'].'" class="result">';
00259
00260 $ret.="<tr class=\"highlight\">".
00261 td($row['oa_date']).
00262 "<td>".
00263 HtmlInput::detail_op($row['jr_id'], h($row['oa_description']." ".$row['jr_pj_number'])).
00264 "</td>".
00265 td();
00266
00267 $ret.="<td>".
00268 "Groupe id : ".$row['oa_group'].
00269 "</td>".
00270
00271 $oldgroup=$group;
00272
00273 }
00274
00275 $class=($count%2==0)?"odd":"even";
00276 $count++;
00277 $cred= ( $row['oa_debit'] == 'f')?"CREDIT":"DEBIT";
00278 $ret.="<tr class=\"$class\">";
00279 $ret.= "<td>".
00280 h($row['po_name']).
00281 "</td>";
00282
00283 $ret.=td(h($row['po_description']));
00284
00285 $ret.='<td class="num">'. nbm($row['oa_amount']).
00286 "</td>".
00287 "<td>".
00288 $cred.
00289 "</td>".
00290
00291 "</tr>";
00292 }
00293
00294
00295 $efface=new IButton();
00296 $efface->javascript="anc_remove_operation("."$gDossier,".$oldgroup.")";
00297 $efface->name="Efface";
00298 $efface->label="Efface";
00299 $ret.="<td>".$efface->input()."</td>";
00300
00301 $this->oa_group=$oldgroup;
00302 $jr_id=$this->get_jrid();
00303 if ( $jr_id != 0 )
00304 {
00305 $detail=new IButton();
00306 $detail->javascript="modifyOperation($jr_id,'".$gDossier."')";
00307 $detail->name="Detail";
00308 $detail->label="Detail";
00309 $ret.="<td>".$detail->input()."</td>";
00310 }
00311 $ret.='</table>';
00312 $ret.=$bar;
00313 return $ret;
00314 }
00315
00316
00317
00318
00319 function get_by_jid($p_jid)
00320 {
00321 $array=array();
00322 $a_plan=$this->db->get_array('select pa_id from plan_analytique order by pa_id');
00323 $res=array();
00324
00325
00326
00327 $a_rowcount=$this->db->get_array("select distinct oa_row "
00328 ." from operation_analytique where j_id=$1 order by oa_row", array($p_jid));
00329
00330 for ($i=0; $i<count($a_rowcount); $i++)
00331 {
00332
00333
00334
00335 $a_existing=$this->db->get_array('
00336 select distinct oa_id,
00337 po_id,
00338 oa_amount,
00339 oa_description,
00340 oa_debit,
00341 j_id,
00342 oa_group,
00343 oa_date,
00344 pa_id,
00345 oa_row,
00346 oa_positive
00347 from operation_analytique join poste_analytique using (po_id)
00348 where
00349 j_id=$1 and oa_row = $2
00350 order by j_id,oa_row',
00351 array($p_jid, $a_rowcount[$i]['oa_row']));
00352
00353
00354 $template=$a_existing[0];
00355
00356
00357
00358 for ($j=0; $j<count($a_plan); $j++)
00359 {
00360
00361
00362
00363 $a_fetch=$this->db->get_array('
00364 select distinct oa_id,
00365 po_id,
00366 oa_amount,
00367 oa_description,
00368 oa_debit,
00369 j_id,
00370 oa_group,
00371 oa_date,
00372 pa_id,
00373 oa_row,
00374 oa_positive
00375 from operation_analytique join poste_analytique using (po_id)
00376 where
00377 j_id=$1 and oa_row = $2 and pa_id=$3', array($p_jid,
00378 $a_rowcount[$i]['oa_row'],
00379 $a_plan[$j]['pa_id']
00380 )
00381 );
00382 if (count($a_fetch)==0)
00383 {
00384 $a_fetch=$template;
00385 $a_fetch['pa_id']=$a_plan[$j]['pa_id'];
00386 $a_fetch['po_id']=-1;
00387 $a_fetch['oa_id']='';
00388 $res[]=$a_fetch;
00389 }
00390 else
00391 if (count($a_fetch)==1)
00392 {
00393 $res[]=$a_fetch[0];
00394 }
00395 }
00396 }
00397
00398 foreach ($res as $row)
00399 {
00400 $a=new Anc_Operation($this->db);
00401 foreach ($row as $attr=> $value)
00402 {
00403 $a->$attr=$row[$attr];
00404 }
00405 $array[]=clone $a;
00406 }
00407
00408
00409 return $array;
00410 }
00411
00412
00413
00414
00415 function update_from_jrnx($p_po_id)
00416 {
00417 $a=$this->get_by_jid($this->j_id);
00418 if ( $a == null )
00419 {
00420
00421 $sql="select jr_date,j_montant,j_debit from jrnx ".
00422 " join jrn on (jr_grpt_id = j_grpt) ".
00423 "where j_id=".$this->j_id;
00424 $res=$this->db->exec_sql($sql);
00425 if (Database::num_row($res) == 0 ) return;
00426 $row=Database::fetch_array($res,0);
00427 $this->oa_amount=$row['j_amount'];
00428 $this->oa_date=$row['jr_date'];
00429 $this->oa_debit=$row['j_debit'];
00430 $this->oa_description=$row['jr_comment'];
00431 $this->add();
00432 }
00433 else
00434 {
00435 foreach ($a as $row )
00436 {
00437 if ( $row->pa_id == $this->pa_id )
00438 {
00439 $row->po_id=$p_po_id;
00440 $row->update();
00441 }
00442 }
00443 }
00444 }
00445
00446 function get_jrid()
00447 {
00448 $sql="select distinct jr_id from jrn join jrnx on (j_grpt=jr_grpt_id) join operation_analytique using (j_id) where j_id is not null and oa_group=".$this->oa_group;
00449 $res=$this->db->exec_sql($sql);
00450 if ( Database::num_row($res) == 0 ) return 0;
00451 $ret=Database::fetch_all($res);
00452 return $ret[0]['jr_id'];
00453 }
00454
00455
00456
00457
00458
00459 function get_balance($p_from,$p_to,$p_plan_id)
00460 {
00461
00462 $cond=sql_filter_per($this->db,$p_from,$p_to,'p_id','j_date');
00463 $sql="select oa_id, po_id, oa_amount, oa_debit, j_date from jrnx join operation_analytique using (j_id)
00464 join poste_analytique using (po_id)
00465 where
00466 $cond and j_id is not null and pa_id=$p_plan_id";
00467
00468
00469 $cond=sql_filter_per($this->db,$p_from,$p_to,'p_id','oa_date');
00470 $sql="union select oa_id, po_id, oa_amount, oa_debit,oa_date from
00471 operation_analytique
00472 join poste_analytique using (po_id)
00473 where j_id is null and
00474 $cond and pa_id=$p_plan_id ";
00475 try
00476 {
00477 $res=$this->db->exec_sql($sql);
00478 $array=Database::fetch_all($res);
00479 }
00480 catch (Exception $e)
00481 {
00482 var_dump($e);
00483 }
00484 }
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523 function display_form_plan($p_array,$p_null,$p_mode,$p_seq,$p_amount,$p_id='',$p_add_button=true)
00524 {
00525 if ( $p_array != null)
00526 extract ($p_array);
00527 $result="";
00528 $plan=new Anc_Plan($this->db);
00529 $a_plan=$plan->get_list(" order by pa_id ");
00530 if ( empty ($a_plan) ) return "";
00531 $table_id="t".$p_seq;
00532 $hidden=new IHidden();
00533
00534 $readonly=($p_mode==1)?false:true;
00535
00536 $result.=$hidden->input('amount_'.$table_id,$p_amount);
00537 if ( $p_mode==1 )
00538 $result.='<table id="'.$p_id.$table_id.'">';
00539 else
00540 $result.='<table>';
00541 $result.="<tr>".$plan->header()."<th>montant</th></tr>";
00542
00543
00544 $nb_row=(isset($val[$p_seq]))?count($val[$p_seq]):1;
00545 $count=0;
00546
00547 $remain=$p_amount;
00548 $ctrl_remain="remain".$this->in_div.$table_id;
00549
00550 for ( $i=0; $i < $nb_row;$i++)
00551 {
00552 $result.='<tr>';
00553
00554 foreach ($a_plan as $r_plan)
00555 {
00556
00557 $array=$this->db->make_array(
00558 "select po_id as value,".
00559 " html_quote(po_name) as label from poste_analytique ".
00560 " where pa_id = ".$r_plan['id'].
00561 " order by po_name",$p_null);
00562 $select =new ISelect("hplan[".$p_seq."][]",$array);
00563 $select->table=0;
00564
00565 if ( $p_mode==1 )
00566 {
00567
00568 $select->readonly=false;
00569 if ( isset($hplan) && isset($hplan[$p_seq][$count]) ){
00570 $select->selected=$hplan[$p_seq][$count];
00571
00572 }
00573 }
00574 else
00575 {
00576 if ( isset($hplan) && isset($hplan[$p_seq][$count]) ){
00577 $select->selected=$hplan[$p_seq][$count];
00578 }
00579
00580 $select->readOnly=true;
00581 }
00582 if ($p_mode==1)
00583 $result.='<td>'.$select->input().'</td>';
00584 else
00585 $result.='<td>'.$select->display().'</td>';
00586 $count++;
00587
00588
00589 }
00590 $value=new INum();
00591 $value->javascript='onchange="format_number(this);anc_refresh_remain(\''.$this->in_div.$table_id.'\',\''.$p_seq.'\')"';
00592 $value->name="val[".$p_seq."][]";
00593 $value->size=6;
00594 $value->value=(isset($val[$p_seq][$i]))?$val[$p_seq][$i]:$p_amount;
00595 $value->readOnly=($p_mode==1)?false:true;
00596 $remain=bcsub($remain,$value->value);
00597 $result.='<td>'.$value->input().'</td>';
00598
00599 $result.="</tr>";
00600 }
00601
00602 $result.="</table>";
00603
00604 if ($p_add_button && $p_mode == 1)
00605 {
00606 $style_remain=($remain==0)?'style="color:green"':' style="color:red"';
00607 $result.=" Reste à imputer = ".
00608 '<span class="remain" '.$style_remain.' id="'.$ctrl_remain.'">'.
00609 $remain.'</span>';
00610 // add a button to add a row
00611 $button=new IButton();
00612 $button->javascript="add_row('".$p_id."$table_id',$p_seq);";
00613 $button->name="js".$p_id.$p_seq;
00614 $button->label=_("Nouvelle ligne");
00615
00616 $result.="<br>".$button->input();
00617
00618
00619
00620
00621 $ledger=HtmlInput::default_value_post("p_jrn", 0);
00622 if ($ledger==0) {
00623 $ledger=$this->db->get_value('select j_jrn_def from jrnx where j_id=$1',array($this->j_id));
00624 }
00625 $gDossier=Dossier::id();
00626 $button_key=new IButton();
00627 $button_key->javascript="anc_key_choice(".$gDossier.",'".$p_id."$table_id',$p_amount,'".$ledger."');";
00628 $button_key->name="js".$p_id.$p_seq;
00629 $button_key->label=_("Clef");
00630 $result .= $button_key->input();
00631
00632 }
00633
00634 return $result;
00635 }
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646 function save_form_plan_vat_nd($p_array,$p_item,$p_j_id,$p_nd)
00647 {
00648 bcscale(4);
00649 extract($p_array);
00650 if (! isset ($hplan) ) return;
00651
00652 if ( ! isset(${'amount_t'.$p_item}) )
00653 throw new Exception ('amount not set');
00654
00655 $tot=0;
00656 /* variable for in array
00657 pa_id array of existing pa_id
00658 hplan double array with the pa_id (column)
00659 val double array by row with amount
00660 op contains sequence
00661 p_item is used to identify what op is concerned
00662 */
00663 /* echo "j_id = $j_id p_item = $p_item hplan=".var_export($hplan[$p_item],true)." val = ".var_export($val[$p_item],true).'<br>'; */
00664 /* for each row */
00665 // for ($i=0;$i<count($val[$p_item]);$i++) {
00666 $idx_pa_id=0;
00667 $row=0;
00668 $a_Anc_Operation=array();
00669 // foreach col PA
00670 for ($e=0;$e<count($hplan[$p_item]);$e++)
00671 {
00672 if ( $idx_pa_id == count($pa_id))
00673 {
00674 $idx_pa_id=0;
00675 $row++;
00676 }
00677 if ($hplan[$p_item][$e] != -1 && $val[$p_item][$row] != '')
00678 {
00679 $op=new Anc_Operation($this->db);
00680 $op->po_id=$hplan[$p_item][$e];
00681 $op->oa_group=$this->oa_group;
00682 $op->j_id=$p_j_id;
00683 $ratio=bcdiv($val[$p_item][$row],${"amount_t".$p_item});
00684 $amount= bcmul($p_nd, $ratio);
00685 $op->oa_amount=abs(round($amount,2));
00686 $op->oa_debit=$this->oa_debit;
00687 $op->oa_date=$this->oa_date;
00688
00689 $op->oa_description=$this->oa_description;
00690 $op->oa_row=$row;
00691 $op->oa_jrnx_id_source=$this->oa_jrnx_id_source;
00692 $a_Anc_Operation[]=clone $op;
00693 }
00694 $idx_pa_id++;
00695 }
00696 $nb_op=count($a_Anc_Operation);
00697 bcscale(2);
00698 for ($i=0;$i<$nb_op;$i++)
00699 {
00700 $tot=bcadd($tot,$a_Anc_Operation[$i]->oa_amount);
00701 }
00702 if ( $tot != $p_nd )
00703 {
00704 $diff= bcsub($tot, $p_nd);
00705 $a_Anc_Operation[0]->oa_amount=bcsub($a_Anc_Operation[0]->oa_amount,$diff);
00706 }
00707 for ($i=0;$i<$nb_op;$i++)
00708 {
00709 $a_Anc_Operation[$i]->add();
00710 }
00711 }
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733 function save_form_plan($p_array,$p_item,$p_j_id)
00734 {
00735 extract($p_array);
00736 if (! isset ($hplan) ) return;
00737 /* variable for in array
00738 pa_id array of existing pa_id
00739 hplan double array with the pa_id (column)
00740 val double array by row with amount
00741 op contains sequence
00742 p_item is used to identify what op is concerned
00743 */
00744 /* echo "j_id = $j_id p_item = $p_item hplan=".var_export($hplan[$p_item],true)." val = ".var_export($val[$p_item],true).'<br>'; */
00745 /* for each row */
00746 // for ($i=0;$i<count($val[$p_item]);$i++) {
00747 $idx_pa_id=0;
00748 $row=0;
00749 // foreach col PA
00750 for ($e=0;$e<count($hplan[$p_item]);$e++)
00751 {
00752 if ( $idx_pa_id == count($pa_id))
00753 {
00754 $idx_pa_id=0;
00755 $row++;
00756 }
00757 if ($hplan[$p_item][$e] != -1 && $val[$p_item][$row] != '')
00758 {
00759 $op=new Anc_Operation($this->db);
00760 $op->po_id=$hplan[$p_item][$e];
00761 $op->oa_group=$this->oa_group;
00762 $op->j_id=$p_j_id;
00763 $op->oa_amount=$val[$p_item][$row];
00764 $op->oa_debit=$this->oa_debit;
00765 $op->oa_date=$this->oa_date;
00766
00767 $op->oa_description=$this->oa_description;
00768 $op->oa_row=$row;
00769 $op->add();
00770 }
00771 $idx_pa_id++;
00772 }
00773 // }
00774 }
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786 function save_update_form($p_array)
00787 {
00788 extract($p_array);
00789 for ($i = 0; $i < count($op); $i++)
00790 {
00791 /* clean operation_analytique */
00792 $this->db->exec_sql('delete from operation_analytique where j_id=$1', array($op[$i]));
00793
00794 /* get missing data for adding */
00795 $a_missing = $this->db->get_array("select to_char(jr_date,'DD.MM.YYYY')
00796 as mdate,j_montant,j_debit,jr_comment ,j_poste
00797 from jrnx join jrn on (j_grpt=jr_grpt_id) where j_id=$1", array($op[$i]));
00798 $missing = $a_missing[0];
00799 $poste=substr(trim($missing['j_poste']),0,1);
00800 if ( $poste == 6 || $poste == 7) {
00801 $this->oa_debit = ($poste == 6) ?'t':'f';
00802 }else {
00803 $this->oa_debit=$missing['j_debit'];
00804 }
00805 $this->oa_description = $missing['jr_comment'];
00806 $this->j_id = $op[$i];
00807 $group = $this->db->get_next_seq("s_oa_group");
00808 $this->oa_group = $group;
00809 $this->oa_date = $missing['mdate'];
00810 $this->save_form_plan($p_array, $i, $op[$i]);
00811
00812
00813 $a_nd = $this->db->get_array('select j_id from operation_analytique
00814 where oa_jrnx_id_source=$1', array($op[$i]));
00815 if (count($a_nd) > 0)
00816 {
00817
00818 for ($e=0;$e<count($a_nd);$e++)
00819 {
00820 $this->db->exec_sql('delete from operation_analytique where j_id=$1', array($a_nd[$e]['j_id']));
00821
00822 $a_missing_vat = $this->db->get_array("select to_char(jr_date,'DD.MM.YYYY') as mdate,j_montant,j_debit,jr_comment from jrnx join jrn on (j_grpt=jr_grpt_id) where j_id=$1", array($a_nd[$e]['j_id']));
00823 $missing_vat = $a_missing_vat[0];
00824 $this->oa_debit = 't';
00825 $this->oa_description = $missing_vat['jr_comment'];
00826 $this->j_id = $op[$i];
00827 $group = $this->db->get_next_seq("s_oa_group");
00828 $this->oa_group = $group;
00829 $this->oa_date = $missing_vat['mdate'];
00830 $this->oa_jrnx_id_source=$op[$i];
00831 $p_array['amount_t'.$i]=$missing['j_montant'];
00832 $this->save_form_plan_vat_nd($p_array, $i, $a_nd[$e]['j_id'],$missing_vat['j_montant']);
00833 }
00834 }
00835 }
00836 }
00837
00838
00839
00840
00841
00842
00843
00844 function to_request ($p_array,$p_line)
00845 {
00846 $result=array();
00847 $result[]=array('op'=>$this->j_id);
00848 $pa_id=array();
00849
00850
00851 for ($i=0;$i < count($p_array);$i++)
00852 {
00853 if ( in_array($p_array[$i]->pa_id,$pa_id)==false)
00854 $pa_id[]=$p_array[$i]->pa_id;
00855 }
00856 $result['pa_id']=$pa_id;
00857
00858
00859 $seq=0;
00860 for ($i=0;$i < count($p_array);$i++)
00861 {
00862 $hplan[$p_line][$i]=$p_array[$i]->po_id;
00863 }
00864 $result['hplan']=$hplan;
00865
00866 $idx_pa=0;
00867 $jrn_def=$this->db->get_value('select jrn_def_type from jrnx join jrn_def on (j_jrn_def=jrn_def_id) where j_id=$1',array($this->j_id));
00868 for ($i=0;$i < count($p_array);$i++)
00869 {
00870
00871
00872
00873
00874 if ( $jrn_def != 'FIN')
00875 {
00876 $val[$p_line][$p_array[$i]->oa_row]=($p_array[$i]->oa_positive=='Y')?$p_array[$i]->oa_amount:($p_array[$i]->oa_amount*(-1));
00877 }
00878 else
00879 {
00880 $val[$p_line][$p_array[$i]->oa_row]=$p_array[$i]->oa_amount;
00881 }
00882 }
00883 $result['val']=$val;
00884 return $result;
00885 }
00886
00887
00888
00889
00890
00891
00892 function delete_by_jid($p_jid)
00893 {
00894 $sql="delete from operation_analytique where j_id=$p_jid";
00895 $this->db->exec_sql($sql);
00896 }
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906 function display_table($p_mode,$p_amount,$p_id)
00907 {
00908 static $seq=-1;
00909 $seq++;
00910
00911 $array=$this->get_by_jid($this->j_id) ;
00912 if ( $array != null )
00913 {
00914 $request=$this->to_request($array,$seq);
00915 return "<td>".$this->display_form_plan($request,1,$p_mode,$seq,$p_amount,$p_id)."</td>";
00916 }
00917 else
00918 {
00919 return '<td>'.$this->display_form_plan(null,1,$p_mode,$seq,$p_amount,$p_id)."</TD>";
00920 }
00921 return "";
00922
00923 }
00924
00925
00926
00927
00928
00929
00930
00931
00932 function test_me()
00933 {
00934 $cn=new Database(dossier::id());
00935 $anco=new Anc_Operation($cn);
00936 $j_id=200;
00937 $anco->j_id=$j_id;
00938 $array=$anco->get_by_jid($j_id);
00939 $a=$anco->to_request($array,1);
00940 echo '<form>';
00941 echo dossier::hidden();
00942 echo HtmlInput::hidden('j_id',$j_id);
00943 echo HtmlInput::hidden('test_select',$_REQUEST['test_select']);
00944 echo $anco->display_table(1,15002,0);
00945 echo '<input type="submit" name="save">';
00946 echo '</form>';
00947 if ( isset($_REQUEST['save']))
00948 {
00949 echo "to_save";
00950 var_dump($_REQUEST);
00951 }
00952 var_dump($a);
00953
00954 }
00955
00956 }