From 91c7211a6819a371bed72ba644074eaf68f8be50 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Tue, 4 Sep 2007 17:08:36 +0000 Subject: [PATCH] Improve CA --- include/ca_imp.inc.php | 102 +++++++++++++++++++++++++++++++++ include/ca_od.inc.php | 35 ++++++++++- include/class_operation.php | 95 ++++++++++++++++++++++-------- include/class_plananalytic.php | 2 +- 4 files changed, 208 insertions(+), 26 deletions(-) diff --git a/include/ca_imp.inc.php b/include/ca_imp.inc.php index 9d08fc545..032b143af 100644 --- a/include/ca_imp.inc.php +++ b/include/ca_imp.inc.php @@ -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 '
'; + 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 '
'; + echo ' Les dates sont en format DD.MM.YYYY'; + //---- result + if ( isset($_GET['result']) ){ + echo '
'; + $submit=new widget(); + $submit->table=0; + //-------------------------------- + // export Buttons + //--------------------------------- + echo '
'; + echo $str_hidden; + echo dossier::hidden(); + echo $submit->Submit('bt_pdf',"Export en PDF"); + echo '
'; + + echo '
'; + echo $str_hidden; + echo dossier::hidden(); + echo $submit->Submit('bt_csv',"Export en CSV"); + echo '
'; + + //---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ée"; return;} + echo ''; + echo ''. + ''. + ''. + ''. + ''. + ''. + ''; + foreach ( $array as $row ) { + echo ''; + echo + ''. + ''. + ''. + ''. + ''; + echo ''; + } + echo '
DateNomDescriptionMontantD/C
'.$row['oa_date'].''.$row['po_name'].''.$row['po_description'].''.$row['oa_amount'].''.(($row['oa_debit']=='f')?'CREDIT':'DEBIT').'
'; + echo '
'; + } + } + +//------------------------------------------------------------------------------ +// Simple balance +if ($sub == 'bs') { + } + +//------------------------------------------------------------------------------ +// crossed balance +if ( $sub == 'bc2') { + } + diff --git a/include/ca_od.inc.php b/include/ca_od.inc.php index 4ddef84d4..4b8fc6ef1 100644 --- a/include/ca_od.inc.php +++ b/include/ca_od.inc.php @@ -89,8 +89,41 @@ if ( isset($_GET['see'])) { echo JS_AJAX_OP; $a=new operation($cn); $a->pa_id=$_REQUEST['pa_id']; +echo ' +
+
+'; + + 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ériode '.$w->IOValue("p_periode",$periode_start).$w->Submit('gl_submit','Valider').'
'; + echo '
'; - echo $a->get_list(); + echo $a->html_table($_GET['p_periode']); echo '
'; exit(); } diff --git a/include/class_operation.php b/include/class_operation.php index da065d896..6e017fc7e 100644 --- a/include/class_operation.php +++ b/include/class_operation.php @@ -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é"; - $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.="".$efface->IOValue().""; + 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é"; + + $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.="".$efface->IOValue().""; + $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.="".$detail->IOValue().""; @@ -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); + } + } } diff --git a/include/class_plananalytic.php b/include/class_plananalytic.php index f25b9f2ae..1a795b244 100644 --- a/include/class_plananalytic.php +++ b/include/class_plananalytic.php @@ -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 (".