Main Page | Namespace List | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

annulation.php

Go to the documentation of this file.
00001 <?
00002 /*
00003  *   This file is part of PhpCompta.
00004  *
00005  *   PhpCompta is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   PhpCompta is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with PhpCompta; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00020 /* $Revision: 1.37 $ */
00024 include_once ("ac_common.php");
00025 include_once ("poste.php");
00026 include_once("preference.php");
00027 include_once("central_inc.php");
00028 include_once("user_common.php");
00029 include_once("check_priv.php");
00030 include_once ("postgres.php");
00031 include_once("jrn.php");
00032 require_once("class_widget.php");
00033 /* Admin. Dossier */
00034 include_once ("class_user.php");
00035 
00036 if ( ! isset ( $_SESSION['g_dossier'] ) ) {
00037   echo "You must choose a Dossier ";
00038   exit -2;
00039 }
00040 $cn=DbConnect($_SESSION['g_dossier']);
00041 $User=new cl_user($cn);
00042 $User->Check();
00043 
00044 html_page_start($User->theme,"onLoad='window.focus();'");
00045 
00046 if ( isset( $_GET['p_jrn'] )) {
00047   $p_jrn=$_GET['p_jrn'];
00048   }
00049 
00050  // Check privilege
00051  // CheckJrn verify that the user is not an admin
00052  // an admin has all right
00053   if ( CheckJrn($_SESSION['g_dossier'],$_SESSION['g_user'],$_GET['p_jrn']) != 2 )    {
00054        NoAccess();
00055        exit -1;
00056   }
00057 
00058 
00059 
00060 list ($l_array,$max_deb,$max_cred)=GetData($cn,$_GET['jrn_op']);
00061 foreach ($l_array as $key=>$element) {
00062   ${"e_$key"}=$element;
00063   echo_debug('annulation.php',__LINE__,"e_$key =$element");
00064 }
00065 
00066 // cancel an operation
00067 if ( isset ($_POST['annul']) ) {
00068         /* Confirm it first */
00069         if ( ! isset ( $_POST['confirm'])) {
00070 ?>
00071 <p>
00072 <h2 class="info">Confirmation</h2>
00073 <br>
00074 <p>
00075 Voulez-vous vraiment annuler  cette information soit par une remise à z&eacute;ro des montants 
00076 soit par son &eacute;criture inverse ?
00077 </p>
00078 <span>
00079 <FORM METHOD="POST" ACTION="annulation.php?p_jrn=<?echo $_GET['p_jrn'];?>&jrn_op=<?echo $_GET['jrn_op'];?>">
00080 <INPUT TYPE="HIDDEN" NAME="annul">
00081 <INPUT TYPE="HIDDEN" NAME="p_id" value="<? echo $_POST['p_id']; ?>">
00082 <INPUT TYPE="HIDDEN" NAME="op_date" value="<? echo $_POST['op_date']; ?>">
00083 <INPUT TYPE="SUBMIT" NAME="confirm" value="Oui"> 
00084 </FORM>
00085 
00086 <FORM METHOD="GET" ACTION="annulation.php">
00087 <INPUT TYPE="HIDDEN" NAME="p_jrn" value="<? echo $_REQUEST['p_jrn']; ?>">
00088 <INPUT TYPE="HIDDEN" NAME="p_id" value="<? echo $_REQUEST['p_id']; ?>">
00089 <INPUT TYPE="HIDDEN" NAME="jrn_op" value="<? echo $_REQUEST['jrn_op']; ?>">
00090 <INPUT TYPE="SUBMIT" NAME="not_confirm" value="non">
00091 </form>
00092 </span>
00093 <?
00094 return;
00095 } // end confirm
00096 
00097 
00098 // Remove is confirmed
00099   if ( isset ($_POST['p_id'])) {
00100     $p_id=$_POST['p_id'];
00101    // Get the date
00102    $e_op_date=$_POST['op_date'];
00103 
00104 
00105    // Test if date is valid
00106    if ( isDate ($e_op_date) == null ) {
00107      $msg='Invalid Date';
00108      echo "<script> alert('$msg');</script>";
00109      // set an incorrect pid to get out from here
00110      $p_id=-1;
00111    }
00112 if  ($p_id != -1 ) { // A
00113    // userPref contient la periode par default
00114    $userPref=$User->GetPeriode($cn);
00115     list ($l_date_start,$l_date_end)=GetPeriode($cn,$userPref);
00116 
00117     // Periode fermée 
00118     if ( PeriodeClosed ($cn,$userPref)=='t' )
00119       {
00120         $msg="Votre periode par defaut est fermee, changez vos preferences";
00121                 echo_error($msg); 
00122                 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00123                 // set an incorrect pid to get out from here
00124                 $p_id=-1;
00125       }
00126  if ( $p_id != -1 ) { //B
00127     // Test whether date of the operation is in a closed periode
00128     // get the period_id
00129     $period_id=getPeriodeFromDate($cn,$e_op_date);
00130       // Check the period_id
00131     if ( PeriodeClosed($cn,$period_id) == 't' ){
00132       // if the operation is in a closed or centralized period
00133       // the operation is voided thanks the opposite operation
00134    StartSql($cn);
00135    $grp_new=NextSequence($cn,'s_grpt');
00136    $seq=NextSequence($cn,"s_jrn");
00137    $p_internal=SetInternalCode($cn,$seq,$l_array['jr_def_id']);
00138 
00139    $sql= "insert into jrn (
00140                 jr_id,jr_def_id,jr_montant,jr_comment,               
00141                 jr_date,jr_grpt_id,jr_internal                 
00142                 ,jr_tech_per, jr_valid
00143                 ) select $seq,jr_def_id,jr_montant,'Annulation '||jr_comment,
00144                 now(),$grp_new,'$p_internal',
00145                 $userPref, true 
00146           from
00147           jrn
00148           where   jr_grpt_id=".$_POST['p_id'];
00149    $Res=ExecSql($cn,$sql);
00150    // Check return code
00151    if ( $Res == false ) { Rollback($cn);exit(-1);}
00152  
00153   // Make also the change into jrnx
00154    $sql= "insert into jrnx (
00155                 j_date,j_montant,j_poste,j_grpt,               
00156                 j_jrn_def,j_debit,j_text,j_internal,j_tech_user,j_tech_per
00157                 ) select now(),j_montant,j_poste,$grp_new,
00158                   j_jrn_def,not (j_debit),j_text,'$p_internal','".$User->id."',
00159                   $userPref
00160           from
00161           jrnx
00162           where   j_grpt=".$_POST['p_id'];
00163    $Res=ExecSql($cn,$sql);
00164    // Check return code
00165    if ( $Res == false ) { Rollback($cn);exit(-1);}
00166    
00167     // Mark the operation invalid into the ledger
00168     // to avoid to nullify twice the same op.
00169     $sql="update jrn set jr_comment='Annule : '||jr_comment where jr_grpt_id=".$_POST['p_id'];
00170     $Res=ExecSql($cn,$sql);
00171     // Check return code
00172     if ( $Res == false ) { Rollback($cn);exit(-1);}
00173 
00174     // Add a "concerned operation to bound these op.together
00175     //
00176     $Res=InsertRapt($cn,$seq,$l_array['jr_id']);
00177    // Check return code
00178    if ( $Res == false ) { Rollback($cn);exit(-1);}
00179     
00180 
00181    // the table stock must updated
00182    // also in the stock table
00183    $sql="delete from stock_goods where sg_id = any ( select sg_id
00184   from stock_goods natural join jrnx  where j_grpt=".$_POST['p_id'].")";
00185    $Res=ExecSql($cn,$sql);
00186    // Check return code
00187    if ( $Res == false ) { Rollback($cn);exit(-1);}
00188 
00189    Commit($cn);
00190    // close the window
00191    echo '<h2 class="info"> Opération Annulée</h2>';
00192     ?>
00193  <script>
00194     window.close();
00195 self.opener.RefreshMe();
00196 </script>
00197     <?
00198             
00199     } else {
00200         // operation is not in a closed period
00201       // Check only if a line is valid or not
00202       if ( isValid($cn,$p_id) ==  1 ) {
00203         // Start Sql
00204         StartSql($cn);
00205 
00206         // delete from the stock table
00207         $sql="delete from stock_goods where sg_id = any ( select sg_id
00208  from stock_goods natural join jrnx  where j_grpt=".$_POST['p_id'].")";
00209         $Res=ExecSql($cn,$sql);
00210         
00211    if ( $Res == false ) { Rollback($cn);exit(-1);}
00212         // delete from jrnx & jrn
00213         $sql="update jrnx set j_montant = 0 where j_grpt=".$_POST['p_id'];
00214         
00215         $Res=ExecSql($cn,$sql);
00216         
00217    if ( $Res == false ) { Rollback($cn);exit(-1);}
00218         
00219         // build the sql stmt for jrn
00220         $sql= "update  jrn  set jr_montant=0,jr_valid='f',jr_comment='Erreur:'||jr_comment  where   jr_grpt_id=".$_POST['p_id'];
00221         $Res=ExecSql($cn,$sql);
00222         
00223    if ( $Res == false ) { Rollback($cn);exit(-1);}
00224         Commit($cn);
00225         echo '<h2 class="info"> Opération Annulée</h2>';
00226           ?>
00227           <script>
00228              window.close();
00229         self.opener.RefreshMe();
00230         </script>
00231             <?
00232             
00233             }// if isValid
00234     } // else if period is closed
00235     }//B p_id == -1
00236   }//A p_id == -1
00237   } // if Post['p_id']
00238 }// if annul
00239 echo '<div align="center"> Opération '.$l_array['jr_internal'].'</div> 
00240 <div>
00241 <form action="'.$_SERVER['REQUEST_URI'].'" method="post" >';
00242 
00243 $a=new widget("text");
00244 // $a=InputType("Date","text", "op_date",$e_op_date,false);
00245 //echo 'Date : '.$e_op_date;
00246 $a->SetReadOnly(false);
00247 echo $a->IOValue("op_date",$e_op_date,"Date");
00248 
00249 echo '<div style="border-style:solid;border-width:1pt;">';
00250 //$a=InputType("Description:","text_big","comment",$e_comment,false);
00251 $a->size=80;
00252 echo $a->IOValue("comment",$e_comment,"Description");
00253 echo '</DIV>';
00254 
00255 if ( isset ($e_ech) ) {
00256   echo "<DIV> Echeance $e_ech </DIV>";
00257 }
00258 for ( $i = 0; $i < $max_deb;$i++) {
00259   $lib=GetPosteLibelle($_SESSION['g_dossier'],${"e_class_deb$i"}); 
00260   echo '<div style="background-color:#BFC2D5;">';
00261   echo ${"e_class_deb$i"}." $lib    "."<B>".${"e_mont_deb$i"}."</B>";
00262   echo "</div>";
00263 }
00264 for ( $i = 0; $i < $max_cred;$i++) {
00265   $lib=GetPosteLibelle($_SESSION['g_dossier'],${"e_class_cred$i"});
00266   echo '<div style="background-color:#E8F4FF;">';
00267   echo ${"e_class_cred$i"}."  $lib   "."<B>".${"e_mont_cred$i"}."</B>";
00268   echo '</div>';
00269 }
00270 //echo "operation concernée $e_rapt<br><br>
00271 //";
00272 $a=GetConcerned($cn,$e_jr_id);
00273 
00274 if ( $a != null ) {
00275   foreach ($a as $key => $element) {
00276     echo "operation concernée <br>";
00277 
00278     echo "<A HREF=\"jrn_op_detail.php?jrn_op=".GetGrpt($cn,$element)."\"> ".GetInternal($cn,$element)."</A><br>";
00279   }//for
00280 }// if ( $a != null ) {
00281 
00282 echo '
00283 
00284 <input type="hidden" name="p_id" value="'.$_GET['jrn_op'].'">
00285 <input type="submit" name="annul"  value="Mise à zéro">
00286 <input type="button" name="cancel" value="Retour" onClick="window.close();">
00287 </form>';
00288 
00289 html_page_stop();
00290 ?>