|
noalyss
Version-6.7.2
|
group of object operations, used for misc operation More...
Public Member Functions | |
| add () | |
| add several rows | |
| Anc_Group_Operation ($p_cn, $p_id=0) | |
| constructor | |
| form ($p_readonly=0) | |
| show a form for the operation (several rows) | |
| get_from_array ($p_array) | |
| fill row from $_POST data | |
| save () | |
| save the group of operation but only if the amount is balanced | |
| show () | |
| show the form | |
Static Public Member Functions | |
| static | test_me () |
Data Fields | |
| $a_operation | |
| $date | |
| $db | |
| $id | |
| $pa_id | |
group of object operations, used for misc operation
Definition at line 38 of file class_anc_group_operation.php.
add several rows
Definition at line 59 of file class_anc_group_operation.php.
References $amount, $e, $row, db, echo, and exit.
{
$amount=0;
try
{
$this->db->start();
foreach ($this->a_operation as $row)
{
$add=round($row->oa_amount,2);
$add=($row->oa_debit=='t')?$add:$add*(-1);
$amount+=round($add,2);
$row->add();
}
if ( $amount != 0 ) throw new Exception (_('Operation non equilibrée'));
}
catch (Exception $e)
{
echo $e->getTrace();
$this->db->rollback();
exit();
}
$this->db->commit();
}
| Anc_Group_Operation::Anc_Group_Operation | ( | $ | p_cn, |
| $ | p_id = 0 |
||
| ) |
constructor
Definition at line 51 of file class_anc_group_operation.php.
References db.
Referenced by test_me().
{
$this->db=$p_cn;
$this->id=$p_id;
$this->date=date("d.m.Y");
$this->nMaxRow=10;
}
| Anc_Group_Operation::form | ( | $ | p_readonly = 0 | ) |
show a form for the operation (several rows)
Definition at line 87 of file class_anc_group_operation.php.
References $d, $idx, $max, $p_readonly, $ret, $wDate, db, HtmlInput\hidden(), and td().
Referenced by show().
{
$wDate=new IDate("pdate",$this->date);
$wDate->table=1;
$wDate->size=10;
$wDate->readonly=$p_readonly;
$wDescription=new IText("pdesc");
$wDescription->table=0;
$wDescription->size=80;
$wDescription->readonly=$p_readonly;
// Show an existing operation
//
if ( isset ($this->a_operation[0]))
{
$wDate->value=$this->a_operation[0]->oa_date;
$wDescription->value=$this->a_operation[0]->oa_description;
}
$ret="";
$ret.='<table style="result" >';
$ret.="<TR>".$wDate->input()."</tr>";
$ret.='<tr><td>Description</td>'.
'<td colspan="3">'.
$wDescription->input()."</td></tr>";
$Plan=new Anc_Plan($this->db);
$aPlan=$Plan->get_list();
$max=(count($this->a_operation)<$this->nMaxRow)?$this->nMaxRow:count($this->a_operation);
$ret.='</table><table id="ago" style="width: 100%;">';
/* show 10 rows */
$ret.="<tr>";
foreach ($aPlan as $d)
{
$idx=$d['id'];
/* array of possible value for the select */
$aPoste[$idx]=$this->db->make_array("select po_id as value,".
" po_name||':'||coalesce(po_description,'-') as label ".
" from poste_analytique ".
" where pa_id = ".$idx.
" order by po_name ");
$ret.="<th> Poste </th>";
}
$ret.="<th></th>".
"<th> Montant</th>".
"<th>Débit</th>".
"</tr>";
for ($i = 0;$i < $max;$i++)
{
$ret.="<tr>";
foreach ($aPlan as $d)
{
$idx=$d['id'];
// init variable
$wSelect=new ISelect("pop".$i."plan".$idx);
$wSelect->value=$aPoste[$idx];
$wSelect->size=12;
$wSelect->readOnly=$p_readonly;
if ( isset($this->a_operation[$i]))
{
$wSelect->selected=$this->a_operation[$i]->po_id;
}
$ret.=td($wSelect->input());
}
$wAmount=new INum("pamount$i",0.0);
$wAmount->size=12;
$wAmount->table=1;
$wAmount->javascript=" onChange=format_number(this);caod_checkTotal()";
$wAmount->readOnly=$p_readonly;
$wDebit=new ICheckBox("pdeb$i");
$wDebit->readOnly=$p_readonly;
$wDebit->javascript=" onChange=caod_checkTotal()";
if ( isset ($this->a_operation[$i]))
{
$wSelect->selected=$this->a_operation[$i]->po_id;
$wAmount->value=$this->a_operation[$i]->oa_amount;
$wDebit->value=$this->a_operation[$i]->oa_debit;
if ( $wDebit->value=='t')
{
$wDebit->selected=true;
}
}
// build the table
$ret.="<TD></TD>";
$ret.=$wAmount->input();
$ret.=td($wDebit->input());
$ret.="</tr>";
}
$ret.="</table>";
if ( $p_readonly==false)
{
$add_row=new IButton('Ajouter');
$add_row->label=_('Ajouter une ligne');
$add_row->javascript='anc_add_row(\'ago\');';
$ret.=HtmlInput::hidden('nbrow',$max);
$ret.=$add_row->input();
}
return $ret;
}
| Anc_Group_Operation::get_from_array | ( | $ | p_array | ) |
fill row from $_POST data
Definition at line 200 of file class_anc_group_operation.php.
References $d, $idx, $p_array, and db.
{
$Plan=new Anc_Plan($this->db);
$aPlan=$Plan->get_list();
for ( $i = 0;$i <$p_array['nbrow'];$i++)
{
foreach ($aPlan as $d)
{
$idx=$d['id'];
$p=new Anc_Operation($this->db);
$p->oa_amount=$p_array["pamount$i"];
$p->oa_description=$p_array["pdesc"];
$p->oa_date=$p_array['pdate'];
$p->j_id=0;
$p->oa_debit=(isset ($p_array["pdeb$i"]))?'t':'f';
$p->oa_group=0;
$p->po_id=$p_array["pop$i"."plan".$idx];
$p->pa_id=$idx;
$this->a_operation[]=clone $p;
}
}
}
save the group of operation but only if the amount is balanced
Definition at line 228 of file class_anc_group_operation.php.
References $ex, db, echo, and exit.
{
$this->db->start();
try
{
$oa_group=$this->db->get_next_seq('s_oa_group');
for ($i=0;$i<count($this->a_operation);$i++)
{
$this->a_operation[$i]->oa_group=$oa_group;
$this->a_operation[$i]->add();
}
}
catch (Exception $ex)
{
echo '<span class="error">'.
'Erreur dans l\'enregistrement '.
__FILE__.':'.__LINE__.' '.
$ex->getMessage();
$p_cn->rollback();
exit();
}
$this->db->commit();
}
show the form
Definition at line 253 of file class_anc_group_operation.php.
References form().
{
return $this->form(1);
}
| static Anc_Group_Operation::test_me | ( | ) | [static] |
Definition at line 257 of file class_anc_group_operation.php.
References $a, $b, $cn, $dossier, Anc_Group_Operation(), echo, exit, and id.
{
$dossier=dossier::id();
$cn=new Database($dossier);
if ( isset($_POST['go']))
{
$b=new Anc_Group_Operation($cn);
$b->get_from_array($_POST);
exit();
}
$a=new Anc_Group_Operation($cn);
echo '<form method="post">';
echo $a->form();
echo dossier::hidden();
echo '<input type="submit" name="go">';
echo '</form>';
}
| Anc_Group_Operation::$a_operation |
array of operations
Definition at line 46 of file class_anc_group_operation.php.
| Anc_Group_Operation::$date |
date of the operations
Definition at line 47 of file class_anc_group_operation.php.
| Anc_Group_Operation::$db |
database connection
Definition at line 40 of file class_anc_group_operation.php.
| Anc_Group_Operation::$id |
oa_group, a group contains several rows of operation_analytique linked by the group id
Definition at line 41 of file class_anc_group_operation.php.
| Anc_Group_Operation::$pa_id |
the concerned pa_id
Definition at line 48 of file class_anc_group_operation.php.