00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 if ( ! defined('ALLOWED')) define ('ALLOWED',1);
00032
00033 require_once '../include/constant.php';
00034 require_once('class_database.php');
00035 require_once('class_user.php');
00036 require_once('class_acc_operation.php');
00037 require_once('class_acc_ledger.php');
00038 require_once ('class_fiche.php');
00039 require_once('class_acc_reconciliation.php');
00040 require_once('class_anc_operation.php');
00041 require_once('class_idate.php');
00042 require_once 'class_own.php';
00043 require_once 'class_iconcerned.php';
00044
00045
00046
00047 if ( ! isset ($_REQUEST['act'])|| ! isset ($_REQUEST['jr_id'])
00048 || ! isset ($_REQUEST['div']))
00049 {
00050 exit();
00051 }
00052 global $g_user,$cn,$g_parameter;
00053 mb_internal_encoding("UTF-8");
00054
00055
00056 $action=$_REQUEST['act'];
00057 $jr_id=$_REQUEST['jr_id'];
00058 $div=$_REQUEST['div'];
00059 $gDossier=dossier::id();
00060
00061
00062
00063 ajax_disconnected($div);
00064
00065 $cn=new Database(dossier::id());
00066 $g_parameter=new Own($cn);
00067 if ( LOGINPUT)
00068 {
00069 $file_loginput=fopen($_ENV['TMP'].'/scenario-'.$_SERVER['REQUEST_TIME'].'.php','a+');
00070 fwrite ($file_loginput,"<?php \n");
00071 fwrite ($file_loginput,'//@description:'.$action."\n");
00072 fwrite($file_loginput, '$_GET='.var_export($_GET,true));
00073 fwrite($file_loginput,";\n");
00074 fwrite($file_loginput, '$_POST='.var_export($_POST,true));
00075 fwrite($file_loginput,";\n");
00076 fwrite($file_loginput, '$_POST[\'gDossier\']=$gDossierLogInput;');
00077 fwrite($file_loginput,"\n");
00078 fwrite($file_loginput, '$_GET[\'gDossier\']=$gDossierLogInput;');
00079 fwrite($file_loginput,"\n");
00080 fwrite($file_loginput,' $_REQUEST=array_merge($_GET,$_POST);');
00081 fwrite($file_loginput,"\n");
00082 fwrite($file_loginput,"include '".basename(__FILE__)."';\n");
00083 fclose($file_loginput);
00084 }
00085
00086 global $g_user;
00087 $g_user=new User($cn);
00088 $g_user->check();
00089 if ( $g_user->check_dossier(dossier::id(),true)=='X' )
00090 {
00091 ob_start();
00092 require_once ('template/ledger_detail_forbidden.php');
00093 echo HtmlInput::button_close($div);
00094 $html=ob_get_contents();
00095 ob_end_clean();
00096 $html=escape_xml($html);
00097 header('Content-type: text/xml; charset=UTF-8');
00098 echo <<<EOF
00099 <?xml version="1.0" encoding="UTF-8"?>
00100 <data>
00101 <ctl>$div</ctl>
00102 <code>$html</code>
00103 </data>
00104 EOF;
00105 exit();
00106 }
00107
00108
00109
00110
00111 $op=new Acc_Operation($cn);
00112 $op->jr_id=$_REQUEST['jr_id'];
00113 $ledger=$op->get_ledger();
00114 if ($ledger=="")
00115 {
00116
00117 ob_start();
00118 echo HtmlInput::title_box(_("Information"), $div);
00119 require_once ('template/ledger_detail_forbidden.php');
00120 echo HtmlInput::button_close($div);
00121 $html=ob_get_contents();
00122 ob_end_clean();
00123
00124 $html=escape_xml($html);
00125 if ( ! headers_sent()) { header('Content-type: text/xml; charset=UTF-8');} else { echo "HTML".unescape_xml($html);}
00126 echo <<<EOF
00127 <?xml version="1.0" encoding="UTF-8"?>
00128 <data>
00129 <ctl>$div</ctl>
00130 <code>$html</code>
00131 </data>
00132 EOF;
00133 exit();
00134
00135 }
00136 $access=$g_user->get_ledger_access($ledger);
00137 if ( $access == 'X' )
00138 {
00139 ob_start();
00140 echo HtmlInput::title_box(_("Information"), $div);
00141 require_once ('template/ledger_detail_forbidden.php');
00142 echo HtmlInput::button_close($div);
00143 $html=ob_get_contents();
00144 ob_end_clean();
00145 $html=escape_xml($html);
00146 header('Content-type: text/xml; charset=UTF-8');
00147 echo <<<EOF
00148 <?xml version="1.0" encoding="UTF-8"?>
00149 <data>
00150 <ctl>$div</ctl>
00151 <code>$html</code>
00152 </data>
00153 EOF;
00154 exit();
00155 }
00156 $html=var_export($_REQUEST,true);
00157 switch ($action)
00158 {
00159
00160
00161
00162 case 'rmop':
00163 if ( $access=='W')
00164 {
00165 ob_start();
00166
00167 try
00168 {
00169 $cn->start();
00170 $oLedger=new Acc_Ledger($cn,$ledger);
00171 $oLedger->jr_id=$_REQUEST['jr_id'];
00172 $oLedger->delete();
00173 $cn->commit();
00174 echo _("Opération Effacée");
00175 }
00176 catch (Exception $e)
00177 {
00178 $e->getMessage();
00179 $cn->rollback;
00180 }
00181 $html=ob_get_contents();
00182 ob_end_clean();
00183 }
00184 break;
00185
00186
00187
00188 case 'de':
00189 ob_start();
00190
00191 try
00192 {
00193 $op->get();
00194 $obj=$op->get_quant();
00195
00196 $oLedger=new Acc_Ledger($cn,$ledger);
00197 if ( $obj==null || $obj->signature == 'ODS' )
00198 {
00199
00200 require_once('template/ledger_detail_misc.php');
00201 }
00202 elseif ( $obj->signature=='ACH')
00203 {
00204 require_once('template/ledger_detail_ach.php');
00205 }
00206 elseif ($obj->signature=='FIN')
00207 {
00208 require_once('template/ledger_detail_fin.php');
00209 }
00210 elseif ( $obj->signature=='VEN')
00211 {
00212 require_once('template/ledger_detail_ven.php');
00213 }
00214 }
00215 catch (Exception $e)
00216 {
00217 echo HtmlInput::anchor_close($div);
00218 echo '<h2 class="error">'._("Désolé il y a une erreur").'</h2>';
00219 }
00220 $html=ob_get_contents();
00221 ob_end_clean();
00222
00223 break;
00224
00225
00226
00227 case 'file':
00228 $op->get();
00229 $obj=$op->get_quant();
00230
00231 if ( $obj->det->jr_pj_name=='')
00232 {
00233 echo "<html><head>";
00234 $repo=new Database();
00235 $theme=$repo->get_value("select the_filestyle from theme where the_name=$1",array($_SESSION['g_theme']));
00236 echo "<LINK REL=\"stylesheet\" type=\"text/css\" href=\"$theme\" media=\"screen\">";
00237 if ( ! isset($_REQUEST['ajax']) ) {
00238 echo "<body class=\"op_detail_frame\">";
00239 echo '<div class="op_detail_frame">';
00240 }else {
00241 echo "<body>";
00242 echo "<div>";
00243
00244 }
00245 echo "<h1 class=\"legend\">Document</h1>";
00246 if ( $access=='W')
00247 {
00248 echo '<FORM METHOD="POST" ENCTYPE="multipart/form-data" id="form_file">';
00249
00250 $sp=new ISpan('file'.$div);
00251 $sp->style="display:none;background-color:red;color:white;font-size:12px";
00252 $sp->value="Chargement";
00253 echo $sp->input();
00254 echo HtmlInput::hidden('act','loadfile');
00255 echo dossier::hidden();
00256 echo HtmlInput::hidden('jr_id',$jr_id);
00257 echo HtmlInput::hidden('div',$div);
00258
00259 echo '<INPUT TYPE="FILE" name="pj" onchange="getElementById(\'file'.$div.'\').style.display=\'inline\';submit(this);">';
00260 echo '</FORM>';
00261 }
00262 else
00263 {
00264 echo "<html><head>";
00265 if (!isset($_REQUEST['ajax']))
00266 {
00267 echo "<body class=\"op_detail_frame\">";
00268 echo '<div class="op_detail_frame">';
00269 }
00270 else
00271 {
00272 echo "<body>";
00273 echo "<div>";
00274 }
00275 $repo = new Database();
00276 $theme = $repo->get_value("select the_filestyle from theme where the_name=$1", array($_SESSION['g_theme']));
00277 echo " <LINK REL=\"stylesheet\" type=\"text/css\" href=\"$theme\" media=\"screen\">";
00278 echo "</head>";
00279 echo '<div class="op_detail_frame">';
00280
00281 echo _('Aucun fichier');
00282 }
00283 echo '</div>';
00284 echo '</body></html>';
00285 exit();
00286 }
00287 else
00288 {
00289 echo "<html><head>";
00290 $repo=new Database();
00291 $theme=$repo->get_value("select the_filestyle from theme where the_name=$1",array($_SESSION['g_theme']));
00292 echo " <LINK REL=\"stylesheet\" type=\"text/css\" href=\"$theme\" media=\"screen\">";
00293 echo "</head>";
00294 if ( ! isset($_REQUEST['ajax']) ) {
00295 echo "<body class=\"op_detail_frame\">";
00296 echo '<div class="op_detail_frame">';
00297 }else {
00298 echo "<body>";
00299 echo "<div>";
00300
00301 }
00302 echo "<h1 class=\"legend\">"._("Document")."</h1>";
00303 echo '<div class="op_detail_frame">';
00304 $x='';
00305 if ($access=='W')
00306 $x=sprintf('<a class="notice" style="margin-left:12;margin-right:12" href="ajax_ledger.php?gDossier=%d&div=%s&jr_id=%s&act=rmf" onclick="return confirm(\'Effacer le document ?\')">'._('enlever').'</a>',
00307 $gDossier,$div,$jr_id);
00308 echo $x;
00309 $filename= $obj->det->jr_pj_name;
00310 if ( strlen($obj->det->jr_pj_name) > 20 )
00311 {
00312 $filename=mb_substr($obj->det->jr_pj_name,0,23);
00313 }
00314 $h=sprintf('<a class="mtitle" href="show_pj.php?gDossier=%d&jrn=%d&jr_grpt_id=%d">%s</a>',
00315 $gDossier,$ledger,$obj->det->jr_grpt_id,h( $filename));
00316 echo $h;
00317 echo '</div>';
00318 echo '</body></html>';
00319 exit();
00320 }
00321
00322
00323
00324 case 'loadfile':
00325 if ( $access == 'W' && isset ($_FILES))
00326 {
00327 $cn->start();
00328
00329 $grpt=$cn->get_value('select jr_grpt_id from jrn where jr_id=$1',array($jr_id));
00330 $cn->save_upload_document($grpt);
00331 $cn->commit();
00332
00333 $op->get();
00334 $obj=$op->get_quant();
00335
00336 echo "<html><head>";
00337 $repo=new Database();
00338 $theme=$repo->get_value("select the_filestyle from theme where the_name=$1",array($_SESSION['g_theme']));
00339 echo " <LINK REL=\"stylesheet\" type=\"text/css\" href=\"$theme\" media=\"screen\">";
00340 echo "</head>";
00341 if ( ! isset($_REQUEST['ajax']) ) echo "<body class=\"op_detail_frame\">"; else echo "<body>";
00342 echo "<h2>"._("Document")."</h2>";
00343 echo '<div class="op_detail_frame">';
00344 $x=sprintf('<a class="mtitle" class="notice" style="margin-left:12;margin-right:12px" href="ajax_ledger.php?gDossier=%d&div=%s&jr_id=%s&act=rmf" onclick="return confirm(\'Effacer le document ?\')">'._('enlever').'</a>',
00345 $gDossier,$div,$jr_id);
00346 echo $x;
00347 $filename= $obj->det->jr_pj_name;
00348 $h=sprintf('<a class="mtitle" href="show_pj.php?gDossier=%d&jrn=%d&jr_grpt_id=%d">%s</a>',
00349 $gDossier,$ledger,$obj->det->jr_grpt_id,h($filename));
00350 echo $h;
00351 echo '</div>';
00352
00353 }
00354 exit();
00355
00356
00357
00358 case 'rmf':
00359 if ( $access == 'W' )
00360 {
00361 echo "<html><head>";
00362 $repo=new Database();
00363 $theme=$repo->get_value("select the_filestyle from theme where the_name=$1",array($_SESSION['g_theme']));
00364 echo " <LINK REL=\"stylesheet\" type=\"text/css\" href=\"$theme\" media=\"screen\">";
00365 echo "</head><body class=\"op_detail_frame\">";
00366 echo "<h2>"._("Document")."</h2>";
00367 echo '<div class="op_detail_frame">';
00368 echo '<FORM METHOD="POST" ENCTYPE="multipart/form-data" id="form_file">';
00369 $sp=new ISpan('file'.$div);
00370 $sp->style="display:none;width:155;height:15;background-color:red;color:white;font-size:10";
00371 $sp->value=_("Chargement");
00372 echo $sp->input();
00373
00374 echo HtmlInput::hidden('act','loadfile');
00375 echo dossier::hidden();
00376 echo HtmlInput::hidden('jr_id',$jr_id);
00377 echo HtmlInput::hidden('div',$div);
00378
00379 echo '<INPUT TYPE="FILE" name="pj" onchange="getElementById(\'file'.$div.'\').style.display=\'inline\';submit(this);">';
00380 echo '</FORM>';
00381 $ret=$cn->exec_sql("select jr_pj from jrn where jr_id=$1",array($jr_id));
00382 if (Database::num_row($ret) != 0)
00383 {
00384 $r=Database::fetch_array($ret,0);
00385 $old_oid=$r['jr_pj'];
00386 if (strlen($old_oid) != 0)
00387 {
00388
00389 $c=$cn->count_sql("select * from jrn where jr_pj=".$old_oid);
00390 if ( $c == 1 )
00391 $cn->lo_unlink($old_oid);
00392 }
00393 $cn->exec_sql("update jrn set jr_pj=null, jr_pj_name=null, ".
00394 "jr_pj_type=null where jr_id=$1",array($jr_id));
00395 }
00396 }
00397 echo '</div>';
00398 exit();
00399
00400
00401
00402 case 'save':
00403 ob_start();
00404 try
00405 {
00406 $cn->start();
00407 if ( $access=="W")
00408 {
00409 if (isset($_POST['p_ech']) )
00410 {
00411 $ech=$_POST['p_ech'];
00412 if ( trim($ech) != '' && isDate($ech) != null)
00413 {
00414 $cn->exec_sql("update jrn set jr_ech=to_date($1,'DD.MM.YYYY') where jr_id=$2",
00415 array($ech,$jr_id));
00416
00417 }
00418 else
00419 {
00420 $cn->exec_sql("update jrn set jr_ech=null where jr_id=$1",
00421 array($jr_id));
00422
00423 }
00424 }
00425
00426 if (isset($_POST['p_date_paid']) )
00427 {
00428 $ech=$_POST['p_date_paid'];
00429 if ( trim($ech) != '' && isDate($ech) != null)
00430 {
00431 $cn->exec_sql("update jrn set jr_date_paid=to_date($1,'DD.MM.YYYY') where jr_id=$2",
00432 array($ech,$jr_id));
00433
00434 }
00435 else
00436 {
00437 $cn->exec_sql("update jrn set jr_date_paid=null where jr_id=$1",
00438 array($jr_id));
00439
00440 }
00441 }
00442
00443 $cn->exec_sql("update jrn set jr_comment=$1,jr_pj_number=$2,jr_date=to_date($4,'DD.MM.YYYY') where jr_id=$3",
00444 array($_POST['lib'],$_POST['npj'],$jr_id,$_POST['p_date']));
00445 $cn->exec_sql("update jrnx set j_date=to_date($1,'DD.MM.YYYY') where j_grpt in (select jr_grpt_id from jrn where jr_id=$2)",
00446 array($_POST['p_date'],$jr_id));
00447 $cn->exec_sql('update operation_analytique set oa_date=j_date from jrnx
00448 where
00449 operation_analytique.j_id=jrnx.j_id and
00450 operation_analytique.j_id in (select j_id
00451 from jrnx join jrn on (j_grpt=jr_grpt_id)
00452 where jr_id=$1)
00453 ',array($jr_id));
00454 $cn->exec_sql("select comptaproc.jrn_add_note($1,$2)",
00455 array($jr_id,$_POST['jrn_note']));
00456 $rapt=$_POST['rapt'];
00457
00458 if ( $g_parameter->MY_UPDLAB=='Y' && isset ($_POST['j_id']))
00459 {
00460 $a_rowid=$_POST["j_id"];
00461 for ($e=0;$e<count($a_rowid);$e++)
00462 {
00463 $id="e_march".$a_rowid[$e]."_label";
00464 $cn->exec_sql('update jrnx set j_text=$1 where j_id=$2', array(strip_tags($_POST[$id]),$a_rowid[$e]));
00465 }
00466 }
00467 if (trim($rapt) != '')
00468 {
00469 $rec=new Acc_Reconciliation ($cn);
00470 $rec->set_jr_id($jr_id);
00471
00472 if (strpos($rapt,",") != 0 )
00473 {
00474 $aRapt=explode(',',$rapt);
00475
00476 foreach ($aRapt as $rRapt)
00477 {
00478 if ( isNumber($rRapt) == 1 )
00479 {
00480
00481 $rec->insert($rRapt);
00482 }
00483 }
00484 }
00485 else
00486 if ( isNumber($rapt) == 1 )
00487 {
00488 $rec->insert($rapt);
00489 }
00490 }
00491 if ( isset($_POST['ipaid']))
00492 {
00493 $cn->exec_sql("update jrn set jr_rapt='paid' where jr_id=$1",array($jr_id));
00494 }
00495 else
00496 {
00497 $cn->exec_sql("update jrn set jr_rapt=null where jr_id=$1",array($jr_id));
00498 }
00499
00500
00501
00502 $owner = new Own($cn);
00503 if ( $owner->MY_ANALYTIC != "nu" && isset ($_POST['op']) )
00504 {
00505
00506 $opanc=new Anc_Operation($cn);
00507 $opanc->save_update_form($_POST);
00508 }
00509
00510
00511
00512 $op->save_info($_POST['OTHER'],'OTHER');
00513 $op->save_info($_POST['BON_COMMANDE'],'BON_COMMANDE');
00514
00515
00516
00517 $related=HtmlInput::default_value_post("related", "0");
00518 if ($related == "0" ) throw new Exception('Parameter not send -> related'.__FILE__.__LINE__,10);
00519 $op->insert_related_action($related);
00520
00521 }
00522 echo _('Opération sauvée');
00523 $cn->commit();
00524 }
00525 catch (Exception $e)
00526 {
00527 if ( DEBUG ) echo $e->getMessage();
00528 alert(_( "Changement impossible: on ne peut pas changer la date dans une période fermée"));
00529 }
00530 $html=ob_get_contents();
00531 ob_end_clean();
00532
00533 break;
00534
00535
00536
00537 case 'rmr':
00538 if ( $access=='W')
00539 {
00540 $rec=new Acc_Reconciliation($cn);
00541 $rec->set_jr_id($jr_id);
00542 $rec->remove($_GET['jr_id2']);
00543 }
00544 break;
00545
00546
00547 case 'ask_extdate':
00548 $date=new IDate('p_date');
00549 $html.="<form id=\"form_".$div."\" onsubmit=\"return reverseOperation(this);\">";
00550 $html.=HtmlInput::hidden('jr_id',$_REQUEST['jr_id']).HtmlInput::hidden('div',$div).dossier::hidden().HtmlInput::hidden('act','reverseop');
00551 $html.='<h2 class="info">'._('entrez une date').' </H2>'.$date->input();
00552 $html.=HtmlInput::submit('x','accepter');
00553 $html=HtmlInput::button_close($div);
00554 $html.='</form>';
00555 break;
00556
00557
00558
00559 case 'reverseop':
00560 if ( $access=='W')
00561 {
00562 ob_start();
00563 try
00564 {
00565 $cn->start();
00566 $oLedger=new Acc_Ledger($cn,$ledger);
00567 $oLedger->jr_id=$_REQUEST['jr_id'];
00568 $oLedger->reverse($_REQUEST['ext_date']);
00569 $cn->commit();
00570 echo _("Opération extournée");
00571 }
00572 catch (Exception $e)
00573 {
00574 $e->getMessage();
00575 $cn->rollback();
00576 }
00577 }
00578 $html=ob_get_contents();
00579 ob_end_clean();
00580 break;
00581 }
00582 $html=escape_xml($html);
00583 if ( ! headers_sent()) { header('Content-type: text/xml; charset=UTF-8');} else { echo "HTML".unescape_xml($html);}
00584
00585 echo <<<EOF
00586 <?xml version="1.0" encoding="UTF-8"?>
00587 <data>
00588 <ctl>$div</ctl>
00589 <code>$html</code>
00590 </data>
00591 EOF;