00001 <?
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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
00051
00052
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
00067 if ( isset ($_POST['annul']) ) {
00068
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éro des montants
00076 soit par son é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 }
00096
00097
00098
00099 if ( isset ($_POST['p_id'])) {
00100 $p_id=$_POST['p_id'];
00101
00102 $e_op_date=$_POST['op_date'];
00103
00104
00105
00106 if ( isDate ($e_op_date) == null ) {
00107 $msg='Invalid Date';
00108 echo "<script> alert('$msg');</script>";
00109
00110 $p_id=-1;
00111 }
00112 if ($p_id != -1 ) {
00113
00114 $userPref=$User->GetPeriode($cn);
00115 list ($l_date_start,$l_date_end)=GetPeriode($cn,$userPref);
00116
00117
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
00124 $p_id=-1;
00125 }
00126 if ( $p_id != -1 ) {
00127
00128
00129 $period_id=getPeriodeFromDate($cn,$e_op_date);
00130
00131 if ( PeriodeClosed($cn,$period_id) == 't' ){
00132
00133
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
00151 if ( $Res == false ) { Rollback($cn);exit(-1);}
00152
00153
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
00165 if ( $Res == false ) { Rollback($cn);exit(-1);}
00166
00167
00168
00169 $sql="update jrn set jr_comment='Annule : '||jr_comment where jr_grpt_id=".$_POST['p_id'];
00170 $Res=ExecSql($cn,$sql);
00171
00172 if ( $Res == false ) { Rollback($cn);exit(-1);}
00173
00174
00175
00176 $Res=InsertRapt($cn,$seq,$l_array['jr_id']);
00177
00178 if ( $Res == false ) { Rollback($cn);exit(-1);}
00179
00180
00181
00182
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
00187 if ( $Res == false ) { Rollback($cn);exit(-1);}
00188
00189 Commit($cn);
00190
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
00201
00202 if ( isValid($cn,$p_id) == 1 ) {
00203
00204 StartSql($cn);
00205
00206
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
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
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 }
00234 }
00235 }
00236 }
00237 }
00238 }
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
00245
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
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
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 }
00280 }
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 ?>