';
-// TODO : add a check for permission
+// \todo add a check for permission
if ( $User->CheckAction($cn,EXP_IMP_ECR) == 0 ) {
/* Cannot Access */
NoAccess();
@@ -60,20 +61,20 @@ echo '';
echo '
';
/////////////////////////// EXPORT ////////////////////////////////////////////
if ( isset ($_GET['export'])) {
-// if the year is not set, ask it
- // ask the exercice and do the export
- $periode=make_array($cn,"select distinct p_exercice,p_exercice from parm_periode order by p_exercice");
- echo '";
- exit(0);
+ // if the year is not set, ask it
+ // ask the exercice and do the export
+ $periode=make_array($cn,"select distinct p_exercice,p_exercice from parm_periode order by p_exercice");
+ echo '";
+ exit(0);
}
/////////////////////////// IMPORT ////////////////////////////////////////////
if ( isset ($_GET['import'])) {
@@ -122,9 +123,10 @@ if ( isset ($_GET['import'])) {
if ( $valid ) {
// skip blank line
if (strlen (trim($line)) == 0 ) continue;
- // put the line into an array
- list($sign,$poste,$amount)=explode(";",$line);
+ // put the line into several array with the same index
+ list($sign,$poste,$label,$amount)=explode(";",$line);
$asign[$idx]=$sign; $aposte[$idx]=$poste;$aamount[$idx]=$amount;
+ $alabel[$idx]=$label;
$idx++;
}
$valid=(($line=="OUVERTURE\n" && $valid==false) || $valid)?true:false;
@@ -142,7 +144,22 @@ if ( isset ($_GET['import'])) {
$n="e_account".$i."_amount";
$array_ods[$n]=$aamount[$i];
}
-
+ // Check if all the poste exist
+ // otherwise create it
+ for ($i=0;$i<$idx;$i++)
+ {
+
+ $p=new Poste($cn,$aposte[$i]);
+
+ // if the poste exists then check the next one
+ if ( $p->get() == true ) continue;
+ echo 'Attention creation de '.$p->id.' '.$alabel[$i].' ';
+ $sql=sprintf("select account_add(%d,'%s')",
+ $p->id,$alabel[$i]);
+
+ ExecSql($cn,$sql);
+ }
+
// submit button in the form
$submit='
';
diff --git a/html/export_ouv.php b/html/export_ouv.php
index 652dec50f..b1fe9839b 100644
--- a/html/export_ouv.php
+++ b/html/export_ouv.php
@@ -65,17 +65,35 @@ $ret=GetArray($cn,"select distinct j_poste::text
order by j_poste::text");
if ( $ret == null ) {echo 'Rien à exporter'; exit();}
printf ("OUVERTURE\n");
+// check if the account are balanced
+$sum=0;
foreach ($ret as $poste_id) {
-//var_dump($poste_id); echo " ";
+
$Poste=new poste($cn,$poste_id['j_poste']);
+ // fill the object
+ $Poste->get();
+ // build sql stmt
$sql="j_tech_per >=". $sql_from[0]['min']." and j_tech_per <=".$sql_to[0]['max'];
$result=$Poste->GetSoldeDetail($sql );
+ $Poste->label=str_replace(';','',$Poste->label);
+
if ( $result['solde'] == 0 ) continue;
if ( $result['debit'] > $result ['credit'] ) {
- printf ("d;%d;%12.4f\n",$Poste->id,$result['solde']);
+ printf ("d;%d;%s;%12.4f\n",$Poste->id,$Poste->label,$result['solde']);
+ $sum+=$result['solde'];
} else {
- printf ("c;%d;%12.4f\n",$Poste->id,$result['solde']);
+ printf ("c;%d;%s;%12.4f\n",$Poste->id,$Poste->label,$result['solde']);
+ $sum-=$result['solde'];
}
}
-
+// $sum must be equal to 0
+// $sum > 0 then deb is too big
+// $sum < 0 then cred is too big
+if ( $sum != 0)
+{
+ printf("ATTENTION : COMPTE NON EQUILIBRE\n ");
+ $msg = ($sum > 0)?" Debit plus grand de $sum":"Credit plus grand de $sum";
+ printf ("DIFFERENCE = $msg \n");
+
+}
?>
\ No newline at end of file
diff --git a/include/class_poste.php b/include/class_poste.php
index ee71ef374..5c75f6081 100644
--- a/include/class_poste.php
+++ b/include/class_poste.php
@@ -26,9 +26,11 @@
*/
class poste {
- var $db;
- var $id;
- var $row;
+ var $db; /*! \enum $db database connection */
+ var $id; /*! \enum $id poste_id */
+ var $label; /*! \enum $label label of the poste */
+ var $parent; /*! \enum $parent parent account */
+ var $row; /*! \enum $row double array see GetRow */
function poste($p_cn,$p_id) {
$this->db=$p_cn;
$this->id=$p_id;
@@ -44,13 +46,13 @@ class poste {
*
*/
function GetRow($p_from,$p_to)
-{
- if ( $p_from == $p_to )
- $periode=" jr_tech_per = $p_from ";
- else
- $periode = "(jr_tech_per >= $p_from and jr_tech_per <= $p_to) ";
-
- $Res=ExecSql($this->db,"select to_char(j_date,'DD.MM.YYYY') as j_date,".
+ {
+ if ( $p_from == $p_to )
+ $periode=" jr_tech_per = $p_from ";
+ else
+ $periode = "(jr_tech_per >= $p_from and jr_tech_per <= $p_to) ";
+
+ $Res=ExecSql($this->db,"select to_char(j_date,'DD.MM.YYYY') as j_date,".
"case when j_debit='t' then j_montant else 0 end as deb_montant,".
"case when j_debit='f' then j_montant else 0 end as cred_montant,".
" jr_comment as description,jrn_def_name as jrn_name,".
@@ -59,23 +61,25 @@ class poste {
" left join jrn on jr_grpt_id=j_grpt".
" where j_poste=".$this->id." and ".$periode.
" order by j_date::date");
- $array=array();
- $tot_cred=0.0;
- $tot_deb=0.0;
- $Max=pg_NumRows($Res);
- if ( $Max == 0 ) return null;
- for ($i=0;$i<$Max;$i++) {
- $array[]=pg_fetch_array($Res,$i);
- if ($array[$i]['j_debit']=='t') {
- $tot_deb+=$array[$i]['deb_montant'] ;
- } else {
- $tot_cred+=$array[$i]['cred_montant'] ;
- }
- }
- $this->row=$array;
+ $array=array();
+ $tot_cred=0.0;
+ $tot_deb=0.0;
+ $Max=pg_NumRows($Res);
+ if ( $Max == 0 ) return null;
+ for ($i=0;$i<$Max;$i++) {
+ $array[]=pg_fetch_array($Res,$i);
+ if ($array[$i]['j_debit']=='t') {
+ $tot_deb+=$array[$i]['deb_montant'] ;
+ } else {
+ $tot_cred+=$array[$i]['cred_montant'] ;
+ }
+ }
+ $this->row=$array;
return array($array,$tot_deb,$tot_cred);
}
/*!\brief Return the name of a account
+ * it doesn't change any data member
+ * \return string with the pcm_lib
*/
function GetName() {
$ret=pg_exec($this->db,
@@ -89,6 +93,22 @@ class poste {
}
return $this->name;
}
+ /*!\brief Get all the value for this object from the database
+ * the data member are set
+ * \return false if this account doesn't exist otherwise true
+ */
+ function get()
+ {
+ $ret=ExecSql($this->db,"select pcm_lib,pcm_val_parent from
+ tmp_pcmn where pcm_val=".$this->id);
+ $r=pg_fetch_all($ret);
+
+ if ( ! $r ) return false;
+ $this->label=$r[0]['pcm_lib'];
+ $this->parent=$r[0]['pcm_val_parent'];
+ return true;
+ }
+
/*!
* \brief give the balance of an account
*
diff --git a/include/user_form_ods.php b/include/user_form_ods.php
index 225c64fa0..d307980b8 100644
--- a/include/user_form_ods.php
+++ b/include/user_form_ods.php
@@ -197,7 +197,7 @@ function FormODS($p_cn,$p_jrn,$p_periode,$p_submit,$p_array=null,$pview_only=tru
// Set correctly the REQUEST param for jrn_type
$h=new widget('hidden');
$h->name='jrn_type';
- $h->value=$_REQUEST['jrn_type'];
+ $h->value='OD';
$r.=$h->IOValue();
$r.=$p_submit;
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index cc5535b88..5eeae600c 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -269,7 +269,7 @@ declare
nCount integer;
begin
select count(*) into nCount from tmp_pcmn where pcm_val=p_id;
- if nCount != 0 then
+ if nCount = 0 then
nParent=account_parent(p_id);
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent)
values (p_id, p_name,nParent);