00001 <?
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00025 include_once ("ac_common.php");
00026 require_once("class_poste.php");
00027 header('Content-type: application/csv');
00028 header('Content-Disposition: attachment;filename="export_ouv.csv"',FALSE);
00029 if ( ! isset ( $_SESSION['g_dossier'] ) ) {
00030 echo "You must choose a Dossier ";
00031 exit -2;
00032 }
00033 include_once ("postgres.php");
00034
00035 $rep=DbConnect();
00036 include_once ("class_user.php");
00037 $User=new cl_user($rep);
00038 $User->Check();
00039
00040 include_once ("check_priv.php");
00041
00042 include_once ("user_menu.php");
00043
00044 $cn=DbConnect($_SESSION['g_dossier']);
00045
00046 if ( $User->CheckAction($cn,EXP_IMP_ECR) == 0 ) {
00047
00048 NoAccess();
00049 exit -1;
00050 }
00051 if ( !isset ($_GET['p_periode'])) {
00052 echo 'Erreur : aucune periode demandée';
00053 exit(0);
00054 }
00055 $sql_from=GetArray($cn,"select min(p_id) from parm_periode where p_exercice=".$_GET['p_periode']);
00056
00057 $sql_to=GetArray($cn,"select max(p_id) from parm_periode where p_exercice=".$_GET['p_periode']);
00058
00059 $ret=GetArray($cn,"select distinct j_poste::text
00060 from jrnx inner join tmp_pcmn on (pcm_val=j_poste)
00061 where
00062 j_tech_per >= ".$sql_from[0]['min']." and
00063 j_tech_per <= ".$sql_to[0]['max']." and j_poste not like '7%'
00064 and j_poste not like '6%'
00065 order by j_poste::text");
00066 if ( $ret == null ) {echo 'Rien à exporter'; exit();}
00067 printf ("OUVERTURE\n");
00068
00069 $sum=0;
00070 foreach ($ret as $poste_id) {
00071
00072 $Poste=new poste($cn,$poste_id['j_poste']);
00073
00074 $Poste->get();
00075
00076 $sql="j_tech_per >=". $sql_from[0]['min']." and j_tech_per <=".$sql_to[0]['max'];
00077 $result=$Poste->GetSoldeDetail($sql );
00078 $Poste->label=str_replace(';','',$Poste->label);
00079
00080 if ( $result['solde'] == 0 ) continue;
00081 if ( $result['debit'] > $result ['credit'] ) {
00082 printf ("d;%d;%s;%12.4f\n",$Poste->id,$Poste->label,$result['solde']);
00083 $sum+=$result['solde'];
00084 } else {
00085 printf ("c;%d;%s;%12.4f\n",$Poste->id,$Poste->label,$result['solde']);
00086 $sum-=$result['solde'];
00087 }
00088 }
00089
00090
00091
00092 if ( $sum != 0)
00093 {
00094 printf("ATTENTION : COMPTE NON EQUILIBRE\n ");
00095 $msg = ($sum > 0)?" Debit plus grand de $sum":"Credit plus grand de $sum";
00096 printf ("DIFFERENCE = $msg \n");
00097
00098 }
00099 ?>