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