00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
00024 require_once ('class_acc_account.php');
00025 include_once ("ac_common.php");
00026 require_once("constant.php");
00027 require_once('class_dossier.php');
00028 require_once('function_javascript.php');
00029
00030 $gDossier=dossier::id();
00031
00032 require_once('class_database.php');
00033
00034
00035 $cn=new Database($gDossier);
00036
00037 include_once ("class_user.php");
00038
00039 include_once ("user_menu.php");
00040
00041 echo '<div id="acc_update" style="border:1px solid blue;width:40%;display:none;background-color:lightgrey;padding:0;position:absolute;text-align:left;z-index:1">';
00042 echo HtmlInput::title_box("Poste comptable", "acc_update", "hide");
00043 echo '<form method="post">';
00044 $val=new IText('p_valu');
00045 $parent=new IText('p_parentu');
00046 $lib=new IText('p_libu');
00047 $lib->css_size="100%";
00048 $type=new ISelect('p_typeu');
00049 $type->value=Acc_Account::$type;
00050 echo '<table>';
00051 $r= td(_('Poste comptable')).td($val->input());
00052 echo tr($r);
00053 $r= td(_('Description')).td($lib->input());
00054 echo tr($r);
00055 $r= td(_('Parent')).td($parent->input());
00056 echo tr($r);
00057 $r= td(_('Type ')).td($type->input());
00058 echo tr($r);
00059 echo '</table>';
00060 echo HtmlInput::hidden('p_oldu','');
00061 echo dossier::hidden();
00062 echo HtmlInput::submit('update',_('Sauve'));
00063 echo HtmlInput::button('hide',_('Annuler'),'onClick="$(\'acc_update\').hide();return true;"');
00064 echo '</form>';
00065 echo '</div>';
00066
00067
00068
00069
00070 if ( ! isset ( $_SESSION['g_start']) )
00071 {
00072 $_SESSION['g_start']="";
00073
00074 }
00075 if ( isset ($_GET['p_start']))
00076 {
00077 $g_start=$_GET['p_start'];
00078 $_SESSION["g_start"]=$g_start;
00079
00080 }
00081
00082 echo '<div class="u_subtmenu">';
00083
00084 echo '</div>';
00085
00086
00087 echo '<div class="lmenu">';
00088 menu_acc_plan($_SESSION['g_start']);
00089 echo '</div>';
00090 echo '<DIV CLASS="redcontent">';
00091
00092
00093 if (isset ($_GET['action']))
00094 {
00095
00096
00097 if ( $_GET['action']=="del" )
00098 {
00099 if ( isset ($_GET['l']) )
00100 {
00101
00102 $R=$cn->exec_sql("select pcm_val from tmp_pcmn where pcm_val_parent=$1",array($_GET['l']));
00103 if ( Database::num_row($R) != 0 )
00104 {
00105 alert("Ne peut pas effacer le poste: d'autres postes en dépendent");
00106 }
00107 else
00108 {
00109
00110 $Res=$cn->exec_sql("select * from jrnx where j_poste=$1",array($_GET['l']));
00111 if ( Database::num_row($Res) != 0 )
00112 {
00113 alert("Ne peut pas effacer le poste: il est utilisé dans les journaux");
00114 }
00115 else
00116 {
00117 $Del=$cn->exec_sql("delete from tmp_pcmn where pcm_val=$1",array($_GET['l']));
00118 }
00119 }
00120 }
00121 }
00122 }
00123
00124
00125
00126 if ( isset ($_POST['update']))
00127 {
00128 $p_val=trim($_POST["p_valu"]);
00129 $p_lib=trim($_POST["p_libu"]);
00130 $p_parent=trim($_POST["p_parentu"]);
00131 $old_line=trim($_POST["p_oldu"]);
00132 $p_type=htmlentities($_POST['p_typeu']);
00133 $acc=new Acc_Account($cn);
00134 $acc->set_parameter('libelle',$p_lib);
00135 $acc->set_parameter('value',$p_val);
00136 $acc->set_parameter('parent',$p_parent);
00137 $acc->set_parameter('type',$p_type);
00138
00139 try
00140 {
00141 $acc->check() ;
00142 }
00143 catch (Exception $e)
00144 {
00145 $message="Valeurs invalides, pas de changement \n ".
00146 $e->getMessage();
00147 echo '<script> alert(\''.$message.'\');
00148 </script>';
00149 }
00150 if ( strlen ($p_val) != 0 && strlen ($p_lib) != 0 && strlen($old_line)!=0 )
00151 {
00152 if (strlen ($p_val) == 1 )
00153 {
00154 $p_parent=0;
00155 }
00156 else
00157 {
00158 if ( strlen($p_parent)==0 )
00159 {
00160 $p_parent=substr($p_val,0,strlen($p_val)-1);
00161 }
00162 }
00163 /* Parent existe */
00164 $Ret=$cn->exec_sql("select pcm_val from tmp_pcmn where pcm_val=$1",array($p_parent));
00165 if ( ($p_parent != 0 && Database::num_row($Ret) == 0) || $p_parent==$old_line )
00166 {
00167 echo '<SCRIPT> alert(" Ne peut pas modifier; aucun poste parent"); </SCRIPT>';
00168 }
00169 else
00170 {
00171 try
00172 {
00173 $acc->update($old_line);
00174 }
00175 catch(Exception $e)
00176 {
00177 alert($e->getMessage());
00178 }
00179 }
00180 }
00181 else
00182 {
00183 echo '<script> alert(\'Update Valeurs invalides\'); </script>';
00184 }
00185 }
00186
00187
00188 if ( isset ( $_POST["Ajout"] ) )
00189 {
00190 extract ($_POST);
00191 $p_val=trim($p_val);
00192 $p_parent=trim($p_parent);
00193
00194 if ( isset ( $p_val) && isset ( $p_lib ) )
00195 {
00196 $p_val=trim($p_val);
00197 $p_parent=$_POST["p_parent"];
00198 if ( strlen ($p_val) != 0 && strlen ($p_lib) != 0 )
00199 {
00200 if (strlen ($p_val) == 1 )
00201 {
00202 $p_parent=0;
00203 }
00204 else
00205 {
00206 if ( strlen(trim($p_parent))==0 &&
00207 (string) $p_parent != (string)(int) $p_parent)
00208 {
00209 $p_parent=substr($p_val,0,strlen($p_val)-1);
00210 }
00211 }
00212
00213 $Ret=$cn->exec_sql("select pcm_val from tmp_pcmn where pcm_val=$1",array($p_parent));
00214 if ( $p_parent != 0 && Database::num_row($Ret) == 0 )
00215 {
00216 alert(" Ne peut pas modifier; aucun poste parent");
00217 }
00218 else
00219 {
00220
00221
00222 $Count=$cn->get_value("select count(*) from tmp_pcmn where pcm_val=$1",array($p_val));
00223 if ( $Count != 0 )
00224 {
00225
00226 alert(" Ce poste existe déjà ");
00227
00228 }
00229 else
00230 {
00231 $Ret=$cn->exec_sql("insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values ($1,$2,$3,$4)",array($p_val,$p_lib,$p_parent,$p_type));
00232 }
00233 }
00234 }
00235 else
00236 {
00237 echo '<H2 class="error"> Valeurs invalides </H3>';
00238 }
00239 }
00240 }
00241
00242 $Ret=$cn->exec_sql("select pcm_val,pcm_lib,pcm_val_parent,pcm_type,array_to_string(array_agg(j_qcode) , ',') as acode
00243 from tmp_pcmn left join vw_poste_qcode on (j_poste=pcm_val) where substr(pcm_val::text,1,1)='".$_SESSION['g_start']."'".
00244 " group by pcm_val,pcm_lib,pcm_val_parent, pcm_type order by pcm_val::text");
00245 $MaxRow=Database::num_row($Ret);
00246
00247 ?>
00248
00249 <FORM METHOD="POST">
00250 <?php
00251 echo HtmlInput::hidden('p_action','pcmn');
00252
00253 echo dossier::hidden();
00254 $limite=MAX_QCODE;
00255 ?>
00256 <TABLE class="result">
00257 <TR>
00258 <TH> Poste comptable </TH>
00259 <TH> Libellé </TH>
00260 <TH> Poste comptable Parent </TH>
00261 <TH> Type </TH>
00262 <TH> Fiche</TH>
00263 </TR>
00264 <?php
00265 $line=new Acc_Account($cn);
00266 echo $line->form(false);
00267 ?>
00268 <td></td>
00269 <TD>
00270 <INPUT TYPE="SUBMIT" class="button" Value="Ajout" Name="Ajout">
00271 </TD>
00272 </TR>
00273 <?php
00274 $str_dossier=dossier::get();
00275 for ($i=0; $i <$MaxRow; $i++)
00276 {
00277 $A=Database::fetch_array($Ret,$i);
00278
00279 if ( $i%2 == 0 )
00280 {
00281 $td ='<TD class="odd">';
00282 $tr ='<TR class="odd">';
00283 }
00284 else
00285 {
00286 $td='<TD class="even">';
00287 $tr='<TR class="even">';
00288 }
00289 echo $tr;
00290 echo "$td";
00291 echo $A['pcm_val'];
00292 echo '</td>';
00293 echo "$td";
00294 printf ("<A HREF=\"javascript:void(0)\" onclick=\"PcmnUpdate('%s','%s','%s','%s',%d)\">",
00295 $A['pcm_val'],
00296 str_replace("'","\'",$A['pcm_lib']),
00297 $A['pcm_val_parent'],
00298 $A['pcm_type'],
00299 dossier::id());
00300 echo h($A['pcm_lib']);
00301
00302 echo $td;
00303 echo $A['pcm_val_parent'];
00304 echo '</TD>';
00305 echo "</td>$td";
00306 echo $A['pcm_type'];
00307 echo "</TD>";
00308
00309 echo $td;
00310 if ( strlen($A['acode']) >0 ) {
00311 if (strpos($A['acode'], ",") >0 ) {
00312 $det_qcode= explode(",", $A['acode']);
00313 echo '<ul style="paddding:0;margin:0px;padding-left:0px;list-style-type:none;padding-start-value:0px">';
00314 $max=(count($det_qcode)>MAX_QCODE)?MAX_QCODE:count($det_qcode);
00315 for ($e=0;$e<$max;$e++) {
00316 echo '<li style="padding-start-value:0">'.HtmlInput::card_detail($det_qcode[$e]).'</li>';
00317 }
00318 echo '</ol>';
00319 if ($max < count($det_qcode)) {
00320 echo "...";
00321 }
00322 } else {
00323 echo HtmlInput::card_detail($A['acode']);
00324 }
00325 }
00326 echo '</td>';
00327
00328 echo $td;
00329 printf ('<A class="input_text" href="?ac='.$_REQUEST['ac'].'&l=%s&action=del&%s">Efface</A>',$A['pcm_val'],$str_dossier);
00330 echo "</TD>";
00331
00332
00333 echo "</TR>";
00334 }
00335 echo "</TABLE>";
00336 echo "</FORM>";
00337 echo "</DIV>";
00338 html_page_stop();
00339 ?>