Improve CA

This commit is contained in:
sparkyx 2007-09-04 17:08:36 +00:00
parent 0473a7f1ec
commit 91c7211a68
4 changed files with 208 additions and 26 deletions

View file

@ -27,3 +27,105 @@
* accountancy.
*
*/
require_once('class_operation.php');
require_once('class_plananalytic.php');
require_once('ac_common.php');
require_once('class_widget.php');
//-- the menu
$menu=array(array("?p_action=ca_imp&sub=listing&$str_dossier","Listing","Listing des opérations","listing"),
array("?p_action=ca_imp&sub=bs&$str_dossier","Balance simple","Balance simple d'un plan analytique","bs"),
array("?p_action=ca_imp&sub=bc2&$str_dossier","Balance croisé","Balance croisé de 2 plans analytiques","bc2")
);
$sub=(isset($_GET['sub']))?$_GET['sub']:0;
echo ShowItem($menu,"H","mtitle","mtitle",$sub);
$hidden=new widget("hidden");
$str_hidden=$hidden->IOValue("p_action","ca_imp");
$str_hidden.=$hidden->IOValue("sub",$sub);
// select following the sub action
//------------------------------------------------------------------------------
// listing
if ( $sub=='listing') {
$from=new widget ('text','from','from');
$from->size=10;
$from->value=(isset($_GET['from']))?$_GET['from']:"";
$to=new widget('text','to','to');
$to->value=(isset($_GET['to']))?$_GET['to']:"";
$to->size=10;
$plan_id=new widget("select","pa_id","pa_id");
$plan_id->selected=(isset($_GET['pa_id']))?$_GET['pa_id']:"Plan 2";
echo '<form method="get">';
echo dossier::hidden();
echo $hidden->IOValue("result","1");
echo $str_hidden;
echo "Depuis : ".$from->IOValue();
echo "jusque : ".$to->IOValue();
$plan=new PlanAnalytic($cn);
$plan_id->value=make_array($cn,"select pa_id, pa_name from plan_analytique order by pa_name");
echo "Plan Analytique :".$plan_id->IOValue();
echo $plan_id->Submit("recherche","recherche");
echo '</form>';
echo '<span class="notice"> Les dates sont en format DD.MM.YYYY</span>';
//---- result
if ( isset($_GET['result']) ){
echo '<div class="u_redcontent">';
$submit=new widget();
$submit->table=0;
//--------------------------------
// export Buttons
//---------------------------------
echo '<form method="GET" action="ca_list_pdf.php" style="display:inline">';
echo $str_hidden;
echo dossier::hidden();
echo $submit->Submit('bt_pdf',"Export en PDF");
echo '</form>';
echo '<form method="GET" action="ca_list_csv.php" style="display:inline">';
echo $str_hidden;
echo dossier::hidden();
echo $submit->Submit('bt_csv',"Export en CSV");
echo '</form>';
//---Html
$op=new operation ($cn);
$op->pa_id=$_GET['pa_id'];
$array=$op->get_list($_GET['from'],$_GET['to']);
if ( empty($array) ) { echo "aucune donn&eacute;e"; return;}
echo '<table>';
echo '<tr>'.
'<th>Date</th>'.
'<th>Nom</th>'.
'<th>Description</th>'.
'<th>Montant</th>'.
'<th>D/C</th>'.
'</tr>';
foreach ( $array as $row ) {
echo '<tr>';
echo
'<td>'.$row['oa_date'].'</td>'.
'<td>'.$row['po_name'].'</td>'.
'<td>'.$row['po_description'].'</td>'.
'<td>'.$row['oa_amount'].'</td>'.
'<td>'.(($row['oa_debit']=='f')?'CREDIT':'DEBIT').'</td>';
echo '</tr>';
}
echo '</table>';
echo '</div>';
}
}
//------------------------------------------------------------------------------
// Simple balance
if ($sub == 'bs') {
}
//------------------------------------------------------------------------------
// crossed balance
if ( $sub == 'bc2') {
}

View file

@ -89,8 +89,41 @@ if ( isset($_GET['see'])) {
echo JS_AJAX_OP;
$a=new operation($cn);
$a->pa_id=$_REQUEST['pa_id'];
echo '
<div class="u_redcontent">
<form method= "get">
';
echo dossier::hidden();
$hid=new widget("hidden");
$hid->name="p_action";
$hid->value="ca_od";
echo $hid->IOValue();
$hid->name="see";
$hid->value="";
echo $hid->IOValue();
$hid->name="pa_id";
$hid->value=$_GET['pa_id'];
echo $hid->IOValue();
$w=new widget("select");
$w->name="p_periode";
// filter on the current year
$filter_year=" where p_exercice='".$User->getExercice()."'";
$periode_start=make_array($cn,"select p_id,to_char(p_start,'DD-MM-YYYY') from parm_periode $filter_year order by p_start,p_end",1);
$User=new cl_user($cn);
$current=(isset($_GET['p_periode']))?$_GET['p_periode']:$User->GetPeriode();
$w->selected=$current;
echo 'P&eacute;riode '.$w->IOValue("p_periode",$periode_start).$w->Submit('gl_submit','Valider').'</form>';
echo '<div class="u_redcontent">';
echo $a->get_list();
echo $a->html_table($_GET['p_periode']);
echo '</div>';
exit();
}

View file

@ -116,42 +116,61 @@ class operation
/*!\brief get a list of row from a certain periode
* \todo to be done
*/
function get_list($p_range="") {
function get_list($p_from,$p_to) {
$cond="";
if ($p_from!="")
$cond="and oa_date >= to_date('$p_from','DD.MM.YYYY') and oa_date <=to_date('$p_to','DD.MM.YYYY')";
$sql="select oa_id,po_name,oa_description,".
"oa_debit,oa_date,oa_amount,oa_group,j_id ".
"oa_debit,to_char(oa_date,'DD.MM.YYYY') as oa_date,oa_amount,oa_group,j_id ".
" from operation_analytique as B".
" join poste_analytique using(po_id) ".
"where B.pa_id=".$this->pa_id." and oa_amount <> 0.0 ".
"where B.pa_id=".$this->pa_id." and oa_amount <> 0.0 $cond".
" order by oa_date ,oa_group,oa_debit,oa_id";
$RetSql=ExecSql($this->db,$sql);
if ( pg_NumRows($RetSql) == 0 )
return "Pas d'enregistrement trouv&eacute;";
$gDossier=dossier::id();
$array=pg_fetch_all($RetSql);
return $array;
}
$ret.="";
$ret.=JS_VIEW_JRN_MODIFY;
$count=0;
$group=0;
$oldgroup=0;
$oldjrid=0;
foreach ($array as $row) {
$group=$row['oa_group'];
if ( $group !=$oldgroup ) {
if ( $oldgroup!=0 )
{
/*\brief show the HTML table for the operation
*/
function html_table($p_from){
$efface=new widget('button');
$efface->js="op_remove('".$_REQUEST['PHPSESSID']."',".$gDossier.",".$oldgroup.")";
$efface->name="Efface";
$efface->label="Efface";
$ret.="<td>".$efface->IOValue()."</td>";
if ($p_from=="")
{ $from="";$to="";}
else
list($from,$to)=GetPeriode($this->db,$p_from);
$array=$this->get_list($from,$to);
if ( empty($array) )
return "Pas d'enregistrement trouv&eacute;";
$gDossier=dossier::id();
$ret.="";
$ret.=JS_VIEW_JRN_MODIFY;
$count=0;
$group=0;
$oldgroup=0;
$oldjrid=0;
foreach ($array as $row) {
$group=$row['oa_group'];
if ( $group !=$oldgroup ) {
if ( $oldgroup!=0 )
{
$efface=new widget('button');
$efface->js="op_remove('".$_REQUEST['PHPSESSID']."',".$gDossier.",".$oldgroup.")";
$efface->name="Efface";
$efface->label="Efface";
$ret.="<td>".$efface->IOValue()."</td>";
$this->oa_group=$oldgroup;
$jr_id=$this->get_jrid();
if ( $jr_id != 0) {
// get the old jr_id
$detail=new widget('button');
@ -208,7 +227,7 @@ class operation
$jr_id=$this->get_jrid();
if ( $jr_id != 0 ){
$detail=new widget('button');
$detail->js="viewOperation($jr_id,'".$_REQUEST['PHPSESSID'].",$gDossier')";
$detail->js="viewOperation($jr_id,'".$_REQUEST['PHPSESSID']."',$gDossier)";
$detail->name="Detail";
$detail->label="Detail";
$ret.="<td>".$detail->IOValue()."</td>";
@ -284,5 +303,33 @@ class operation
$ret=pg_fetch_all($res);
return $ret[0]['jr_id'];
}
/*\brief this function get the balance for a certain period
*\param $p_from from date (accountancy period)
*\param $p_to to dat (accountancy period)
*\param $p_plan_id the plan id
*/
function get_balance($p_from,$p_to,$p_plan_id)
{
// for the operation connected to jrnx
$cond=sql_filter_per($this->db,$p_from,$p_to,'p_id','j_date');
$sql="select oa_id, po_id, oa_amount, oa_debit, j_date from jrnx join operation_analytique using (j_id)
join poste_analytique using (pa_id)
where
$cond and j_id is not null and pa_id=$p_plan_id";
// OD
$cond=sql_filter_per($this->db,$p_from,$p_to,'p_id','oa_date');
$sql="union select oa_id, po_id, oa_amount, oa_debit,oa_date from
operation_analytique
join poste_analytique using (pa_id)
where j_id is null and
$cond and pa_id=$p_plan_id ";
try {
$res=ExecSql($this->db,$sql);
$array=pg_fetch_all($res);
echo_debug(__FILE__.":".__LINE__," array =",$array);
} catch (Exception $e) {
var_dump($e);
}
}
}

View file

@ -100,7 +100,7 @@ class PlanAnalytic
$name=FormatString($this->name);
if ( strlen($name) == 0)
return;
if ( $this->isAppend == false) return;
$description=FormatString($this->description);
ExecSql($this->db,"insert into plan_analytique(pa_name,pa_description)".
" values (".