noalyss Version-9
Public Member Functions | Data Fields | Private Attributes
Anc_Operation Class Reference

this class is used to show the form for entering an operation only FOR analytic operation to save it, to display or to get a list from a certain period More...

+ Collaboration diagram for Anc_Operation:

Public Member Functions

 __construct ($p_cn, $p_id=0)
 constructor More...
 
 __toString ()
 
 add ($p_seq=0)
 add a row to the table operation_analytique More...
 
 delete ()
 delete a row from the table operation_analytique More...
 
 delete_by_jid ($p_jid)
 delete from operation_analytique More...
 
 display_form_plan ($p_array, $p_null, $p_mode, $p_seq, $p_amount, $p_id='', $p_add_button=true)
 display the form for PA More...
 
 display_table ($p_mode, $p_amount, $p_id)
 Display a table with analytic accounting in detail of operation. More...
 
 get_balance ($p_from, $p_to, $p_plan_id)
 
 get_by_jid ($p_jid)
 retrieve an operation thanks a jrnx.j_id More...
 
 get_currency_rate ()
 
 get_jrid ()
 retrieve the jr_id thanks the oa_group More...
 
 get_list ($p_from, $p_to, $p_from_poste="", $p_to_poste="")
 get a list of row from a certain periode More...
 
 get_list_simple ($p_from, $p_to)
 
 html_table ($p_from)
 
 save_form_plan ($p_array, $p_item, $p_j_id)
 it called for each item, the data are taken from $p_array data and set before in this. Amount will be transformed thanks the $this->currency_rate; More...
 
 save_form_plan_vat_nd ($p_array, $p_item, $p_j_id, $p_nd)
 Save the ND VAT with prorata. More...
 
 save_update_form ($p_array)
 save a whole form from a update box More...
 
 set_currency_rate ($currency_rate)
 
 test_me ()
 
 to_request ($p_array, $p_line)
 
 update_from_jrnx ($p_po_id)
 modify an op from modify_op.php More...
 

Data Fields

 $card
 
 $db
 
 $has_data
 
 $id
 
 $in_div
 
 $j_id
 
 $list
 
 $oa_amount
 
 $oa_date
 
 $oa_debit
 
 $oa_description
 
 $oa_group
 
 $oa_id
 
 $oa_jrnx_id_source
 In the case, the amount comes from a ND VAT, the variable contents the jrnx.j_id of the source which was used to compute the amount. More...
 
 $oa_positive
 signed of the amount More...
 
 $oa_row
 
 $pa_id
 
 $po_id
 
 $row
 

Private Attributes

 $currency_rate
 

Detailed Description

this class is used to show the form for entering an operation only FOR analytic operation to save it, to display or to get a list from a certain period

Definition at line 32 of file anc_operation.class.php.

Constructor & Destructor Documentation

◆ __construct()

Anc_Operation::__construct (   $p_cn,
  $p_id = 0 
)

constructor

Definition at line 100 of file anc_operation.class.php.

101 {
102 $this->db=$p_cn;
103 $this->id=$p_id;
104 $this->oa_jrnx_id_source=null;
105 $this->oa_positive='Y';
106 $this->has_data=0;
107 $this->in_div="";
108 $this->card="";
109 $this->currency_rate=1;
110 }
$SecUser db

References $p_id, and db.

Member Function Documentation

◆ __toString()

Anc_Operation::__toString ( )

Definition at line 63 of file anc_operation.class.php.

63 : string
64 {
65 $r=<<<EOF
66Object Anc_Operation [
67 \$row=>$this->row,
68 \$list=> $this->list,
69 \$id => $this->id,
70 \$po_id => $this->po_id,
71 \$oa_amount $this->oa_amount,
72 \$oa_description => $this->oa_description,
73 \$oa_debit => $this->oa_debit,
74 \$j_id => $this->j_id,
75 \$oa_group => $this->oa_group,
76 \$oa_date => $this->oa_date,
77 \$pa_id => $this->pa_id,
78 \$card => $this->card ,
79 private \$currency_rate => $this->currency_rate,
80 ]
81EOF;
82 return $r;
83
84 }
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
this class is used to show the form for entering an operation only FOR analytic operation to save it,...

References $card, $currency_rate, $id, $j_id, $list, $oa_amount, $oa_date, $oa_debit, $oa_description, $oa_group, $pa_id, $po_id, $r, and $row.

◆ add()

Anc_Operation::add (   $p_seq = 0)

add a row to the table operation_analytique

Note
if $this->oa_group == 0 then a sequence id will be computed for the oa_group, if $this->j_id=0 then it will be null

Definition at line 116 of file anc_operation.class.php.

117 {
118
119 if ( $this->oa_group == 0)
120 {
121 $this->oa_group=$this->db->get_next_seq('s_oa_group');
122 }
123
124 if ( $this->j_id == 0 )
125 {
126 $this->j_id=null;
127 } else {
128 // must be the same side than the operation
129 if ( $this->oa_jrnx_id_source == null)
130 {
131 $side=$this->db->get_value('select j_debit from jrnx where j_id=$1',
132 array($this->j_id));
133 } else
134 {
135 $side=$this->db->get_value('select j_debit from jrnx where j_id=$1',
136 array($this->oa_jrnx_id_source));
137 }
138 $this->oa_debit=$side;
139 }
140
141
142 // we don't save null operations
143 if ( $this->oa_amount == 0 || $this->po_id==-1)
144 return;
145
146 if ( $this->oa_amount< 0)
147 {
148 // if negatif must be oa_positive='N'
149 $this->oa_positive='N';
150 $this->oa_debit=($this->oa_debit=='t')?'f':'t';
151 }
152
153 // Retrieve the f_id of the card
154 $n_fid=0;
155 if ( $this->card != "") {
156 $fiche=new Fiche($this->db);
157 $fiche->get_by_qcode($this->card);
158 $n_fid=$fiche->id;
159 }
160 $n_fid=($n_fid!=0)?$n_fid:NULL;
161 $oa_row=(isset($this->oa_row))?$this->oa_row:null;
162 $sql="insert into operation_analytique (
163 po_id,
164 oa_amount,
165 oa_description,
166 oa_debit,
167 oa_group,
168 j_id,
169 oa_date,
170 oa_row,
171 oa_jrnx_id_source,
172 oa_positive,
173 f_id
174 ) values ($1,$2,$3,$4,$5,$6,to_date($7,'DD.MM.YYYY'),$8,$9,$10,$11)";
175
176 $this->db->exec_sql($sql,array(
177 $this->po_id, // 1
178 abs($this->oa_amount), //2
179 $this->oa_description, //3
180 $this->oa_debit, //4
181 $this->oa_group, //5
182 $this->j_id, //6
183 $this->oa_date, //7
184 $oa_row, //8
185 $this->oa_jrnx_id_source, //8
186 $this->oa_positive,
187 $n_fid // fiche.f_id , can be null
188 ));
189
190 }
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Definition: fiche.class.php:38
$side

References $fiche, $oa_row, $side, $sql, and db.

Referenced by update_from_jrnx().

◆ delete()

Anc_Operation::delete ( )

delete a row from the table operation_analytique

Note
be carefull : do not delete a row when we have a group

Definition at line 194 of file anc_operation.class.php.

195 {
196 $sql="delete from operation_analytique where oa_id=$1";
197
198 $this->db->exec_sql($sql,array($this->oa_id));
199 }

References $sql, and db.

◆ delete_by_jid()

Anc_Operation::delete_by_jid (   $p_jid)

delete from operation_analytique

Parameters
$p_jidthe operation_analytique.j_id field
Returns
none

Definition at line 1045 of file anc_operation.class.php.

1046 {
1047 $sql="delete from operation_analytique where j_id=$1";
1048 $this->db->exec_sql($sql,array($p_jid));
1049 }

References $sql, and db.

◆ display_form_plan()

Anc_Operation::display_form_plan (   $p_array,
  $p_null,
  $p_mode,
  $p_seq,
  $p_amount,
  $p_id = '',
  $p_add_button = true 
)

display the form for PA

Parameters
$p_arraycontains POST (or GET) data (val[] hplan[][] op[])
$p_null= 1 if PA optional otherwise 0 mandatory
$p_mode== form 1 ==> read/write otherwise 0==>readonly
$p_seqnumber of the row
$p_amountamount
$p_idoperation is detailled in a HTML popup, if several are opened, the tableid MUST be different. So we need to use a new parameter
$p_add_buttontrue, show the button, false don't display them
See also
save_form_plan
Note
  • op is an array containing the line number
  • pa_id is an array of the existing array
  • hplan is an array of the POSTE ANALYTIQUE id used, the size of hplan from 0 to x, x can be bigger than the number of plan id
  • val contains the amount by row inside the table. One operation (j_id) you can have several rows
    0 =>
    array
    'op' => int 200
    'pa_id' =>
    array
    0 => string '14' (length=2)
    1 => string '15' (length=2)
    'hplan' =>
    array
    1 =>
    array
    0 => string '25' (length=2)
    1 => string '26' (length=2)
    'val' =>
    array
    1 =>
    array
    0 => string '100.0000' (length=8)

Add a button for distribution key

Add a button to clean the detail

Definition at line 571 of file anc_operation.class.php.

572 {
573 if ( $p_array != null)
574 extract ($p_array, EXTR_SKIP);
575 $result="";
576 $plan=new Anc_Plan($this->db);
577 $a_plan=$plan->get_list(" order by pa_id ");
578 if ( empty ($a_plan) ) return "";
579 $table_id="t".$p_seq;
580 $hidden=new IHidden();
581
582 $readonly=($p_mode==1)?false:true;
583
584 if ($p_mode==1)
585 {
586 $result .= sprintf('<input type="HIDDEN" id="amount_%s" class="%s%s-amount" name="amount_%s" value="%s">',
587 $table_id,
588 $this->in_div,
589 $table_id,
590 $table_id,
591 $p_amount
592 );
593
594 $result.='<table id="'.$p_id.$table_id.'">';
595 }
596 else
597 {
598 $result.='<table>';
599 }
600 $result.="<tr>".$plan->header()."<th>"._("montant")."</th></tr>";
601
602 /* compute the number of rows */
603 $nb_row=(isset($val[$p_seq]))?count($val[$p_seq]):1;
604 $count=0;
605
606 $remain=abs($p_amount);
607 $ctrl_remain="remain".$this->in_div.$table_id;
608
609 for ( $i=0; $i < $nb_row;$i++)
610 {
611 $result.='<tr>';
612
613 foreach ($a_plan as $r_plan)
614 {
615 $existing=(isset($hplan[$p_seq][$count]))?$hplan[$p_seq][$count]:-1;
616 $array=$this->db->make_array(
617 "select po_id as value,".
618 " html_quote(po_name) as label from poste_analytique ".
619 " where pa_id = $1 ".
620 " and ( po_state = 1 or po_id = $2) ".
621 " order by po_name",$p_null,[$r_plan['id'],$existing]);
622 $select =new ISelect("hplan[".$p_seq."][]",$array);
623 $select->table=0;
624 // view only or editables
625 if ( $p_mode==1 )
626 {
627 // editable
628 $select->readonly=false;
629 if ( isset($hplan) && isset($hplan[$p_seq][$count]) ){
630 $select->selected=$hplan[$p_seq][$count];
631
632 }
633 }
634 else
635 {
636 if ( isset($hplan) && isset($hplan[$p_seq][$count]) ){
637 $select->selected=$hplan[$p_seq][$count];
638 }
639 // view only
640 $select->readOnly=true;
641 }
642 if ($p_mode==1)
643 {
644 $result.='<td>'.$select->input().'</td>';
645 }
646 else
647 {
648 $result.='<td>'.$select->display().'</td>';
649 }
650 $count++;
651
652
653 }
654 $value=new INum();
655 $value->javascript='onchange="format_number(this);anc_refresh_remain(\''.$this->in_div.$table_id.'\',\''.$p_seq.'\')"';
656 $value->name=($readonly)?"ro"."val[".$p_seq."][]":"val[".$p_seq."][]";
657 $value->size=6;
658 $value->value=(isset($val[$p_seq][$i]))?$val[$p_seq][$i]:abs($p_amount);
659 $value->value=round($value->value,2);
660 $value->style='class="inum '.$this->in_div.$table_id.'-value-'.$p_seq.'"';
661 $value->readOnly=($p_mode==1)?false:true;
662 $remain=bcsub($remain,$value->value);
663 $result.='<td>'.$value->input().'</td>';
664
665 $result.="</tr>";
666 }
667
668 $result.="</table>";
669
670 if ($p_add_button && $p_mode == 1)
671 {
672 $style_remain=($remain==0)?'style="color:green"':' style="color:red"';
673 $result.=" "._("Reste")." = ".
674 '<span class="remain" '.$style_remain.' id="'.$ctrl_remain.'">'.
675 $remain.'</span>';
676 // add a button to add a row
677 $button=new IButton();
678 $button->javascript="add_row('".$p_id."$table_id',$p_seq);";
679 $button->name="js".$p_id.$p_seq;
680 $button->label=_("Nouvelle ligne");
681
682 $result.="<br>".$button->input();
683 /**
684 * Add a button for distribution key
685 *
686 */
687 $http=new HttpInput();
688 $ledger=$http->post("p_jrn", "string",0);
689 if ($ledger==0) {
690 $ledger=$this->db->get_value('select j_jrn_def from jrnx where j_id=$1',array($this->j_id));
691 }
692 $gDossier=Dossier::id();
693 $button_key=new IButton();
694 $button_key->javascript="anc_key_choice(".$gDossier.",'".$p_id."$table_id',$p_amount,'".$ledger."');";
695 $button_key->name="js".$p_id.$p_seq;
696 $button_key->label=_("Clef");
697 $result .= $button_key->input();
698 /**
699 * Add a button to clean the detail
700 */
701 $button_clean=new IButton();
702 $button_clean->javascript=sprintf("anc_key_clean('%s','%s','%s','%s','%s','%s');",
703 $gDossier,
704 $p_id,
705 $p_amount,
706 $ledger,
707 $this->j_id,
708 $p_seq
709 );
710 $button_clean->name=uniqid();
711 $button_clean->label=_("Efface détail");
712 $result.=$button_clean->input();
713
714
715 }
716
717 return $result;
718 }
tr($p_string, $p_extra='')
Definition: ac_common.php:88
Concerns the Analytic plan (table plan_analytique)
Html Input.
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...
$all table
$count

References $a_plan, $array, $count, $hidden, $i, $nb_row, $p_array, $readonly, $result, $select, $table_id, $val, $value, db, js, table, tr(), and value.

+ Here is the call graph for this function:

◆ display_table()

Anc_Operation::display_table (   $p_mode,
  $p_amount,
  $p_id 
)

Display a table with analytic accounting in detail of operation.

Note
$this->j_id must be set
Parameters
$p_mode0 = readonly or 1=writable
$p_amountamount
$p_idunique id
See also
display_form_plan
Returns
string to display

Definition at line 1060 of file anc_operation.class.php.

1061 {
1062 static $seq=-1; /* first seq == 0 */
1063 $seq++;
1064
1065 $array=$this->get_by_jid($this->j_id) ;
1066 if ( $array != null )
1067 {
1068 $request=$this->to_request($array,$seq);
1069 return "<td>".$this->display_form_plan($request,1,$p_mode,$seq,$p_amount,$p_id)."</td>";
1070 }
1071 else
1072 {
1073 return '<td>'.$this->display_form_plan(null,1,$p_mode,$seq,$p_amount,$p_id)."</TD>";
1074 }
1075 return "";
1076
1077 }
get_by_jid($p_jid)
retrieve an operation thanks a jrnx.j_id
to_request($p_array, $p_line)

References $array, $p_id, $seq, get_by_jid(), and to_request().

+ Here is the call graph for this function:

◆ get_balance()

Anc_Operation::get_balance (   $p_from,
  $p_to,
  $p_plan_id 
)

Definition at line 506 of file anc_operation.class.php.

507 {
508 // for the operation connected to jrnx
509 $cond=sql_filter_per($this->db,$p_from,$p_to,'p_id','j_date');
510 $sql="select oa_id, po_id, oa_amount, oa_debit, j_date from jrnx join operation_analytique using (j_id)
511 join poste_analytique using (po_id)
512 where
513 $cond and j_id is not null and pa_id=$p_plan_id";
514
515 // OD
516 $cond=sql_filter_per($this->db,$p_from,$p_to,'p_id','oa_date');
517 $sql="union select oa_id, po_id, oa_amount, oa_debit,oa_date from
518 operation_analytique
519 join poste_analytique using (po_id)
520 where j_id is null and
521 $cond and pa_id=$p_plan_id ";
522 try
523 {
524 $res=$this->db->exec_sql($sql);
526 }
527 catch (Exception $e)
528 {
529 record_log($e);
530 }
531 }
sql_filter_per($p_cn, $p_from, $p_to, $p_form='p_id', $p_field='jr_tech_per')
Create the condition to filter on the j_tech_per thanks a from and to date.
Definition: ac_common.php:682
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1342
static fetch_all($ret)
wrapper for the function pg_fetch_all

References $array, $e, $res, $sql, db, DatabaseCore\fetch_all(), record_log(), and sql_filter_per().

+ Here is the call graph for this function:

◆ get_by_jid()

Anc_Operation::get_by_jid (   $p_jid)

retrieve an operation thanks a jrnx.j_id

Parameters
thejrnx.j_id
Returns
null if nothing is found other an array

Definition at line 366 of file anc_operation.class.php.

367 {
368 $array=array();
369 $a_plan=$this->db->get_array('select pa_id from plan_analytique order by pa_id');
370 $res=array();
371 /*
372 * For one oa_row
373 */
374 $a_rowcount=$this->db->get_array("select distinct oa_row "
375 ." from operation_analytique where j_id=$1 order by oa_row", array($p_jid));
376
377 for ($i=0; $i<count($a_rowcount); $i++)
378 {
379 /*
380 * Get one row as template for filling the missing
381 */
382 $a_existing=$this->db->get_array('
383 select distinct oa_id,
384 po_id,
385 oa_amount,
386 oa_description,
387 oa_debit,
388 j_id,
389 oa_group,
390 oa_date,
391 pa_id,
392 oa_row,
393 oa_positive
394 from operation_analytique join poste_analytique using (po_id)
395 where
396 j_id=$1 and oa_row = $2
397 order by j_id,oa_row',
398 array($p_jid, $a_rowcount[$i]['oa_row']));
399
400 // the first row we found will be the template
401 $template=$a_existing[0];
402 /*
403 * For each plan
404 */
405 for ($j=0; $j<count($a_plan); $j++)
406 {
407 /*
408 * Fetch the row with this pa_id, oa_row, max : 1 row
409 */
410 $a_fetch=$this->db->get_array('
411 select distinct oa_id,
412 po_id,
413 oa_amount,
414 oa_description,
415 oa_debit,
416 j_id,
417 oa_group,
418 oa_date,
419 pa_id,
420 oa_row,
421 oa_positive
422 from operation_analytique join poste_analytique using (po_id)
423 where
424 j_id=$1 and oa_row = $2 and pa_id=$3', array($p_jid,
425 $a_rowcount[$i]['oa_row'],
426 $a_plan[$j]['pa_id']
427 )
428 );
429 if (count($a_fetch)==0)
430 {
431 $a_fetch=$template;
432 $a_fetch['pa_id']=$a_plan[$j]['pa_id'];
433 $a_fetch['po_id']=-1;
434 $a_fetch['oa_id']='';
435 $res[]=$a_fetch;
436 }
437 else
438 if (count($a_fetch)==1)
439 {
440 $res[]=$a_fetch[0];
441 }
442 }
443 }
444
445 foreach ($res as $row)
446 {
447 $a=new Anc_Operation($this->db);
448 foreach ($row as $attr=> $value)
449 {
450 $a->$attr=$row[$attr];
451 }
452 $array[]=clone $a;
453 }
454
455
456 return $array;
457 }
for($i=0;$i< $count;$i++) $template

References $a, $a_plan, $array, $attr, $i, $res, $row, $template, $value, and db.

Referenced by display_table(), and update_from_jrnx().

◆ get_currency_rate()

Anc_Operation::get_currency_rate ( )

Definition at line 58 of file anc_operation.class.php.

59 {
61 }

References $currency_rate.

◆ get_jrid()

Anc_Operation::get_jrid ( )

retrieve the jr_id thanks the oa_group

Definition at line 493 of file anc_operation.class.php.

494 {
495 $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;
496 $res=$this->db->exec_sql($sql);
497 if ( Database::num_row($res) == 0 ) return 0;
499 return $ret[0]['jr_id'];
500 }
static num_row($ret)
wrapper for the function pg_num_rows

References $res, $ret, $sql, db, DatabaseCore\fetch_all(), and DatabaseCore\num_row().

+ Here is the call graph for this function:

◆ get_list()

Anc_Operation::get_list (   $p_from,
  $p_to,
  $p_from_poste = "",
  $p_to_poste = "" 
)

get a list of row from a certain periode

Definition at line 232 of file anc_operation.class.php.

233 {
234 $cond="";
235 $cond_poste="";
236
237 if ($p_from!="")
238 $cond="and (jr_date >= to_date('$p_from','DD.MM.YYYY') or oa_date >= to_date('$p_from','DD.MM.YYYY') )";
239 if ( $p_to!="" )
240 $cond.="and (jr_date <=to_date('$p_to','DD.MM.YYYY') or oa_date <=to_date('$p_to','DD.MM.YYYY')) ";
241
242 if ($p_from_poste != "" )
243 $cond_poste=" and upper(po_name) >= upper('".$p_from_poste."')";
244 if ($p_to_poste != "" )
245 $cond_poste.=" and upper(po_name) <= upper('".$p_to_poste."')";
246 $pa_id_cond="";
247 if ( isset ( $this->pa_id) && $this->pa_id !='')
248 $pa_id_cond= "pa_id=".$this->pa_id." and";
249 $sql="
250
251 select B.po_id as po_id,
252 oa_id,
253 po_name,
254 oa_description,
255 po_description,
256 oa_debit,
257 (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,
258 (case when jr_date is not null then to_char(jr_date,'YYYYMMDD') else to_char(oa_date,'YYYYMMDD') end ) as str_order_date,
259 oa_amount,
260 oa_group,
261 j_id ,
262 jr_internal,
263 jr_pj_number ,
264 jr_id,
265 coalesce(jr_comment,b.oa_description) as jr_comment,
266 case when j_poste is null and b.f_id is not null then
267 (select ad_value from fiche_detail where fiche_detail.f_id=b.f_id and ad_id=".ATTR_DEF_ACCOUNT.")
268 when j_poste is not null then
269 j_poste
270 end as j_poste
271 ,
272 coalesce(jrnx.f_id,b.f_id) as f_id,
273 case when jrnx.f_id is not null then
274 (select ad_value from fiche_Detail where f_id=jrnx.f_id and ad_id=23)
275 when b.f_id is not null then
276 (select ad_value from fiche_Detail where f_id=b.f_id and ad_id=23)
277 end
278 as qcode,
279 jr_pj_number
280 from operation_analytique as B join poste_analytique using(po_id)
281 left join jrnx using (j_id)
282 left join jrn on (j_grpt=jr_grpt_id)
283 where $pa_id_cond oa_amount <> 0.0 $cond $cond_poste
284 order by jr_date,oa_group,oa_debit desc,oa_id";
285
286 $RetSql=$this->db->exec_sql($sql);
288 return $array;
289 }
$anc pa_id

References $array, $sql, db, DatabaseCore\fetch_all(), and pa_id.

+ Here is the call graph for this function:

◆ get_list_simple()

Anc_Operation::get_list_simple (   $p_from,
  $p_to 
)

Definition at line 201 of file anc_operation.class.php.

202 {
203 $cond="";
204 $where=" where ";
205
206 if ($p_from!="") {
207 $cond="$where (oa_date >= to_date('$p_from','DD.MM.YYYY') or oa_date >= to_date('$p_from','DD.MM.YYYY') )";
208 $where=" and ";
209 }
210 if ( $p_to!="" ) {
211 $cond.="$where (oa_date <=to_date('$p_to','DD.MM.YYYY') or oa_date <=to_date('$p_to','DD.MM.YYYY')) ";
212 $where=" and ";
213 }
214
215 $cond .= $where." j_id is null ";
216
217 $sql="
218 select distinct oa_group,
219 to_char(oa_date,'DD.MM.YYYY') as str_date ,
220 oa_date,
221 oa_description
222 from
223 operation_analytique as oa
224 $cond
225 order by oa_date ";
226 return $this->db->get_array($sql);
227
228 }

References $sql, and db.

Referenced by html_table().

◆ html_table()

Anc_Operation::html_table (   $p_from)

Definition at line 293 of file anc_operation.class.php.

294 {
295 if ($p_from=="")
296 {
297 $from="";
298 $to="";
299 }
300 else
301 {
302 $p=new Periode($this->db);
303 list($from,$to)=$p->get_date_limit($p_from);
304 }
305
307
308 if ( empty($array) )
309 return _("Pas d'enregistrement trouvé");
310
311 // navigation_bar
312 $step=$_SESSION[SESSION_KEY.'g_pagesize'];
313 $page=(isset($_GET['offset']))?$_GET['page']:1;
314 $offset=(isset($_GET['offset']))?$_GET['offset']:0;
316
317 if ( $step !=-1)
318 $view=array_splice($array,$offset,$step);
319 else
320 $view=$array;
321
323 $ret="";
324 $ret.=$bar;
325
326 $count=0;
327 $group=0;
328 $oldgroup=0;
329 $oldjrid=0;
330 $ret.=_("Chercher")." ".HtmlInput::filter_table("anc_operation_list_tb", '0,1,2', 1);
331 $ret.= "<table id=\"anc_operation_list_tb\"class=\"result\">";
332 $ret.=th(_("Date"));
333 $ret.=th(_("Libellé"));
334 $ret.=th("");
335 $ret.=th("");
336 $i=0;
337 foreach ($view as $row)
338 {
339 $class=($i%2 == 0)?'class="even"':' class="odd"';
340 $i++;
341
342 if ( $oldgroup <> $row['oa_group']) {
343 $oldgroup=$row['oa_group'];
344 }
345 $row_id=sprintf('id="tr%s"',$oldgroup);
346
347 $ret.="<tr $row_id $class>";
348 $ret.=td($row['str_date']);
349 $ret.=td(h($row['oa_description']));
350 $js="anc_remove_operation(".$gDossier.",".$oldgroup.")";
351
352 $ret.="<td>".Icon_Action::trash(uniqid(), $js) ."</td>";
353 $js="anc_detail_op({$row['oa_group']},{$gDossier})";
354 $ret .= "<td>". Icon_Action::modify(uniqid(), $js)."</td>";
355 $ret.="</tr>";
356 }
357 $ret.='</table>';
358 $ret.=$bar;
359
360 return $ret;
361 }
th($p_string, $p_extra='', $raw='')
Definition: ac_common.php:58
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
h( $row[ 'oa_description'])
$p
Definition: array.php:34
$from
Definition: balance.inc.php:61
$to
Definition: balance.inc.php:75
$input_from id
Definition: balance.inc.php:63
$_GET['qcode']
$class
get_list_simple($p_from, $p_to)
static filter_table($p_table_id, $p_col, $start_row)
filter the rows in a table and keep the colored row in alternance
static modify($p_id, $p_javascript)
Display the icon to modify a idem.
For the periode tables parm_periode and jrn_periode.
navigation_bar($p_offset, $p_line, $p_size=0, $p_page=1, $p_javascript="")
Create a navigation_bar (pagesize)
Definition: user_common.php:76

References $_GET, $array, $bar, $class, $count, $from, $gDossier, $i, $js, $offset, $p, $page, $ret, $row, $step, $to, db, HtmlInput\filter_table(), get_list_simple(), h, id, Icon_Action\modify(), navigation_bar(), td(), and th().

+ Here is the call graph for this function:

◆ save_form_plan()

Anc_Operation::save_form_plan (   $p_array,
  $p_item,
  $p_j_id 
)

it called for each item, the data are taken from $p_array data and set before in this. Amount will be transformed thanks the $this->currency_rate;

Parameters
$p_itemif the item nb for each item (purchase or selling merchandise)
$p_arraystructure

nb_tx x is the number of the item it contains the number of rows of CA for this card

val double array : amount for the CA row ACC => sub row ANC

here Operation 0 has 2 row for a total of 10.31 and 1 here Operation 1 has 1 row for a total of 430

    [val] => Array
        (
            [0] => Array
                (
                    [0] => 10.31
                    [1] => 1
                )

            [1] => Array
                (
                    [0] => 430
                )

        )

amount_tx the amount for each row

It is the amount to split per accounting, it is possible that it is different from the sum of the given amount ( see val) per row

      [amount_t0] => 11.31
      [amount_t1] => 430

ta_AoCrow_R contains the value of the pa_id and po_id for this row with the form pa_id_po_id d_d

hplan = Double array operation

Double array operation => all the amount but in linear form

Example if the amount of the operation 0 is splitted in 2 rows and 2 cols (because 2 analytic plan, means 2 cols) we have an array of 4 values for operation 0, it gives the poste_analytique.po_id (from DB).

Here is the operation 0 (one row of the accounting) is splitted in po_id = 1 (pa_id see in tables or array pa_id) and po_id=5 (second pa_id) for 10.31 (see array val) and for 1 is set for po_id 1 and 4, p

        [hplan] => Array
        (
            [0] => Array
                (
                    [0] => 1
                    [1] => 5
                    [2] => 1
                    [3] => 4
                )

            [1] => Array
                (
                    [0] => 1
                    [1] => 6
                )

        )

pa_id

pa_id array of plan_analytic.pa_id (1 per column), always ordered by pa_id

    [pa_id] => Array
        (
            [0] => 1
            [1] => 2
        )

     *
Attention
The idea is one j_id matches several oa_id, serveral data must be set before the call :
  • j_id
  • oa_debit
  • oa_group
  • oa_date
  • oa_description

Definition at line 889 of file anc_operation.class.php.

890 {
891 extract($p_array, EXTR_SKIP);
892 if (! isset ($hplan) ) return;
893 /* variable for in array
894 pa_id array of existing pa_id
895 hplan double array with the pa_id (column)
896 val double array by row with amount
897 op contains sequence
898 p_item is used to identify what op is concerned
899 */
900 /* for each row */
901 $idx_pa_id=0;
902 $row=0;
903
904 if ( ! isset ($hplan[$p_item])) return;
905 // foreach col PA
906 for ($e=0;$e<count($hplan[$p_item]);$e++)
907 {
908 if ( $idx_pa_id == count($pa_id))
909 {
910 $idx_pa_id=0;
911 $row++;
912 }
913 if ($hplan[$p_item][$e] != -1 && $val[$p_item][$row] != '')
914 {
915 $op=new Anc_Operation($this->db);
916 $op->po_id=$hplan[$p_item][$e];
917 $op->oa_group=$this->oa_group;
918 $op->j_id=$p_j_id;
919 // convert oa_amount to EUR
920 $op->oa_amount=bcdiv($val[$p_item][$row],$this->currency_rate,2);
921 $op->oa_debit=$this->oa_debit;
922 $op->oa_date=$this->oa_date;
923
924 $op->oa_description=$this->oa_description;
925 $op->oa_row=$row;
926 $op->add();
927 }
928 $idx_pa_id++;
929 }
930 // }
931 }
$op
Definition: ajax_admin.php:38

◆ save_form_plan_vat_nd()

Anc_Operation::save_form_plan_vat_nd (   $p_array,
  $p_item,
  $p_j_id,
  $p_nd 
)

Save the ND VAT with prorata.

Parameters
$p_arrayusually $_POST
$p_itemitem of the form
$p_j_idjrnx.j_id concerned writing
$p_ndamount nd vat
See also
Anc_Operation::save_form_plan_vat_nd
Returns
type

Definition at line 729 of file anc_operation.class.php.

730 {
731 bcscale(4);
732 extract($p_array, EXTR_SKIP);
733 if (! isset ($hplan) ) return;
734
735 if ( ! isset(${'amount_t'.$p_item}) )
736 throw new Exception ('amount not set');
737
738 $tot=0;
739 /* variable for in array
740 pa_id array of existing pa_id
741 hplan double array with the pa_id (column)
742 val double array by row with amount
743 op contains sequence
744 p_item is used to identify what op is concerned
745 */
746 /* echo "j_id = $j_id p_item = $p_item hplan=".var_export($hplan[$p_item],true)." val = ".var_export($val[$p_item],true).'<br>'; */
747 /* for each row */
748 // for ($i=0;$i<count($val[$p_item]);$i++) {
749 $idx_pa_id=0;
750 $row=0;
751 $a_Anc_Operation=array();
752 // foreach col PA
753 for ($e=0;$e<count($hplan[$p_item]);$e++)
754 {
755 if ( $idx_pa_id == count($pa_id))
756 {
757 $idx_pa_id=0;
758 $row++;
759 }
760 if ($hplan[$p_item][$e] != -1 && $val[$p_item][$row] != '')
761 {
762 $op=new Anc_Operation($this->db);
763 $op->po_id=$hplan[$p_item][$e];
764 $op->oa_group=$this->oa_group;
765 $op->j_id=$p_j_id;
766 $ratio=0;
767 if (${"amount_t".$p_item} != 0 ) {
768 $ratio=bcdiv($val[$p_item][$row],${"amount_t".$p_item});
769 }
770 $amount= bcmul($p_nd, $ratio);
771 // convert to euro
772 $amount=bcmul($amount,$this->currency_rate);
773 $op->oa_amount=round($amount,2);
774 $op->oa_debit=$this->oa_debit;
775 $op->oa_date=$this->oa_date;
776
777 $op->oa_description=$this->oa_description;
778 $op->oa_row=$row;
779 $op->oa_jrnx_id_source=$this->oa_jrnx_id_source;
780 $a_Anc_Operation[]=clone $op;
781 }
782 $idx_pa_id++;
783 }
784 $nb_op=count($a_Anc_Operation);
785 bcscale(4);
786 for ($i=0;$i<$nb_op;$i++)
787 {
788 $tot=bcadd($tot,$a_Anc_Operation[$i]->oa_amount);
789 }
790// utilité ???
791// if ( $tot != $p_nd && count($a_Anc_Operation) > 0 )
792// {
793// $diff= bcsub($tot, $p_nd);
794// $a_Anc_Operation[0]->oa_amount=bcsub($a_Anc_Operation[0]->oa_amount,$diff);
795// }
796 for ($i=0;$i<$nb_op;$i++)
797 {
798 $a_Anc_Operation[$i]->add();
799 }
800 }
$oa_jrnx_id_source
In the case, the amount comes from a ND VAT, the variable contents the jrnx.j_id of the source which ...

Referenced by save_update_form().

◆ save_update_form()

Anc_Operation::save_update_form (   $p_array)

save a whole form from a update box

Parameters
$p_arrayfor ALL j_id
Returns
Note
See also
save_form_plan to_request

Definition at line 943 of file anc_operation.class.php.

944 {
945 extract($p_array, EXTR_SKIP);
946 if ( ! isset($opanc)) return;
947 for ($i = 0; $i < count($opanc); $i++)
948 {
949 /* clean operation_analytique */
950 $this->db->exec_sql('delete from operation_analytique where j_id=$1', array($opanc[$i]));
951
952 /* get missing data for adding */
953 $a_missing = $this->db->get_array("select to_char(jr_date,'DD.MM.YYYY')
954 as mdate,j_montant,j_debit,jr_comment ,j_poste
955 from jrnx join jrn on (j_grpt=jr_grpt_id) where j_id=$1", array($opanc[$i]));
956 $missing = $a_missing[0];
957
958 $this->oa_description = $missing['jr_comment'];
959 $this->j_id = $opanc[$i];
960 $group = $this->db->get_next_seq("s_oa_group"); /* for analytic */
961 $this->oa_group = $group;
962 $this->oa_date = $missing['mdate'];
963 $this->save_form_plan($p_array, $i, $opanc[$i]);
964
965 // There is ND VAT amount
966 $a_nd = $this->db->get_array('select j_id from operation_analytique
967 where oa_jrnx_id_source=$1', array($opanc[$i]));
968 if (count($a_nd) > 0)
969 {
970 // for each ND VAT amount
971 for ($e=0;$e<count($a_nd);$e++)
972 {
973 $this->db->exec_sql('delete from operation_analytique where j_id=$1', array($a_nd[$e]['j_id']));
974 /* get missing data for adding */
975 $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']));
976 $missing_vat = $a_missing_vat[0];
977 $this->oa_debit = 't';
978 $this->oa_description = $missing_vat['jr_comment'];
979 $this->j_id = $opanc[$i];
980 $group = $this->db->get_next_seq("s_oa_group"); /* for analytic */
981 $this->oa_group = $group;
982 $this->oa_date = $missing_vat['mdate'];
983 $this->oa_jrnx_id_source=$opanc[$i];
984 $p_array['amount_t'.$i]=$missing['j_montant'];
985 $this->save_form_plan_vat_nd($p_array, $i, $a_nd[$e]['j_id'],$missing_vat['j_montant']);
986 }
987 }
988 }
989 }
save_form_plan($p_array, $p_item, $p_j_id)
it called for each item, the data are taken from $p_array data and set before in this....
save_form_plan_vat_nd($p_array, $p_item, $p_j_id, $p_nd)
Save the ND VAT with prorata.

References $e, $i, $p_array, db, and save_form_plan_vat_nd().

+ Here is the call graph for this function:

◆ set_currency_rate()

Anc_Operation::set_currency_rate (   $currency_rate)

Definition at line 86 of file anc_operation.class.php.

87 {
88 $this->currency_rate=$currency_rate;
89 return $this;
90 }

References $currency_rate.

◆ test_me()

Anc_Operation::test_me ( )

Definition at line 1086 of file anc_operation.class.php.

1087 {
1089 $anco=new Anc_Operation($cn);
1090 $j_id=200;
1091 $anco->j_id=$j_id;
1092 $array=$anco->get_by_jid($j_id);
1093 $a=$anco->to_request($array,1);
1094 echo '<form>';
1095 echo dossier::hidden();
1096 echo HtmlInput::hidden('j_id',$j_id);
1097 echo HtmlInput::hidden('test_select',$_REQUEST['test_select']);
1098 echo $anco->display_table(1,15002,0);
1099 echo '<input type="submit" name="save">';
1100 echo '</form>';
1101 if ( isset($_REQUEST['save']))
1102 {
1103 echo "to_save";
1104 var_dump($_REQUEST);
1105 }
1106 var_dump($a);
1107
1108 }
$_REQUEST['ac']
static connect()
static hidden($p_name, $p_value, $p_id="")

References $_REQUEST, $a, $array, $cn, $j_id, Dossier\connect(), and HtmlInput\hidden().

+ Here is the call graph for this function:

◆ to_request()

Anc_Operation::to_request (   $p_array,
  $p_line 
)

Definition at line 997 of file anc_operation.class.php.

998 {
999 $result=array();
1000 $result[]=array('op'=>$this->j_id);
1001 $pa_id=array();
1002
1003 /* First add the pa_id */
1004 for ($i=0;$i < count($p_array);$i++)
1005 {
1006 if ( in_array($p_array[$i]->pa_id,$pa_id)==false)
1007 $pa_id[]=$p_array[$i]->pa_id;
1008 }
1009 $result['pa_id']=$pa_id;
1010
1011 /* add the hplan */
1012 $seq=0;
1013 for ($i=0;$i < count($p_array);$i++)
1014 {
1015 $hplan[$p_line][$i]=$p_array[$i]->po_id;
1016 }
1017 $result['hplan']=$hplan;
1018 /* Add the amount */
1019 $idx_pa=0;
1020 $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));
1021 for ($i=0;$i < count($p_array);$i++)
1022 {
1023
1024 /*
1025 * For the bank, negatif are always on the debit and positif on the credit
1026 */
1027 if ( $jrn_def != 'FIN')
1028 {
1029 $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));
1030 }
1031 else
1032 {
1033 $val[$p_line][$p_array[$i]->oa_row]=$p_array[$i]->oa_amount;
1034 }
1035 }
1036 $result['val']=$val;
1037 return $result;
1038 }

References $i, $p_array, $pa_id, $result, $seq, $val, db, and pa_id.

Referenced by display_table().

◆ update_from_jrnx()

Anc_Operation::update_from_jrnx (   $p_po_id)

modify an op from modify_op.php

Definition at line 462 of file anc_operation.class.php.

463 {
464 $a=$this->get_by_jid($this->j_id);
465 if ( $a == null )
466 {
467 // retrieve data from jrnx
468 $sql="select jr_date,j_montant,j_debit from jrnx ".
469 " join jrn on (jr_grpt_id = j_grpt) ".
470 "where j_id=".$this->j_id;
471 $res=$this->db->exec_sql($sql);
472 if (Database::num_row($res) == 0 ) return;
474 $this->oa_amount=$row['j_amount'];
475 $this->oa_date=$row['jr_date'];
476 $this->oa_debit=$row['j_debit'];
477 $this->oa_description=$row['jr_comment'];
478 $this->add();
479 }
480 else
481 {
482 foreach ($a as $row )
483 {
484 if ( $row->pa_id == $this->pa_id )
485 {
486 $row->po_id=$p_po_id;
487 $row->update();
488 }
489 }
490 }
491 }
add($p_seq=0)
add a row to the table operation_analytique
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array

References $a, $res, $row, $sql, add(), db, DatabaseCore\fetch_array(), get_by_jid(), and DatabaseCore\num_row().

+ Here is the call graph for this function:

Field Documentation

◆ $card

Anc_Operation::$card

Card linked to the operation

Definition at line 47 of file anc_operation.class.php.

Referenced by __toString().

◆ $currency_rate

Anc_Operation::$currency_rate
private

currency rate

Definition at line 48 of file anc_operation.class.php.

Referenced by __toString(), get_currency_rate(), and set_currency_rate().

◆ $db

Anc_Operation::$db

database connection

Definition at line 34 of file anc_operation.class.php.

◆ $has_data

Anc_Operation::$has_data

Definition at line 55 of file anc_operation.class.php.

◆ $id

Anc_Operation::$id

= oa_id (one row)

Definition at line 37 of file anc_operation.class.php.

Referenced by __toString().

◆ $in_div

Anc_Operation::$in_div

Definition at line 96 of file anc_operation.class.php.

◆ $j_id

Anc_Operation::$j_id

foreign key to a jrnx operation (or null if none

Definition at line 42 of file anc_operation.class.php.

Referenced by __toString(), and test_me().

◆ $list

Anc_Operation::$list

array of all operation

Definition at line 36 of file anc_operation.class.php.

Referenced by __toString().

◆ $oa_amount

Anc_Operation::$oa_amount

amount for one row

Definition at line 39 of file anc_operation.class.php.

Referenced by __toString().

◆ $oa_date

Anc_Operation::$oa_date

equal to j_date if j_id is not null

Definition at line 45 of file anc_operation.class.php.

Referenced by __toString().

◆ $oa_debit

Anc_Operation::$oa_debit

true for debit or false

Definition at line 41 of file anc_operation.class.php.

Referenced by __toString().

◆ $oa_description

Anc_Operation::$oa_description

comment for one row

Definition at line 40 of file anc_operation.class.php.

Referenced by __toString().

◆ $oa_group

Anc_Operation::$oa_group

group of operation

Definition at line 44 of file anc_operation.class.php.

Referenced by __toString().

◆ $oa_id

Anc_Operation::$oa_id

Definition at line 56 of file anc_operation.class.php.

◆ $oa_jrnx_id_source

Anc_Operation::$oa_jrnx_id_source

In the case, the amount comes from a ND VAT, the variable contents the jrnx.j_id of the source which was used to compute the amount.

Definition at line 54 of file anc_operation.class.php.

◆ $oa_positive

Anc_Operation::$oa_positive

signed of the amount

Definition at line 95 of file anc_operation.class.php.

◆ $oa_row

Anc_Operation::$oa_row

Definition at line 57 of file anc_operation.class.php.

Referenced by add().

◆ $pa_id

Anc_Operation::$pa_id

the plan analytique id

Definition at line 46 of file anc_operation.class.php.

Referenced by __toString(), and to_request().

◆ $po_id

Anc_Operation::$po_id

poste analytique

Definition at line 38 of file anc_operation.class.php.

Referenced by __toString().

◆ $row

Anc_Operation::$row

array of row for one operation

Definition at line 35 of file anc_operation.class.php.

Referenced by __toString(), get_by_jid(), html_table(), and update_from_jrnx().


The documentation for this class was generated from the following file: