noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
ajax_ledger.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*!\file
23 * \brief answer to the ajax request for the ledger
24 * it means :
25 - detail of an operation (expert, user and analytic view)
26 - removal of an operation
27 - load a receipt document
28 - for reconcialiation
29 - update of analytic content
30*
31*/
32if (!defined('ALLOWED')) die(_('Non authorisé'));
33
35
36/**
37 * Check if we receive the needed data (jr_id...)
38 */
40mb_internal_encoding("UTF-8");
41
42try {
43 $action = $http->request('act');
44 $jr_id = $http->request('jr_id');
45 $div = $http->request('div'); /* the div source and target for javascript */
46 $gDossier = dossier::id();
47
48} catch (Exception $exc) {
49 error_log($exc->getTraceAsString());
50 return;
51}
52
53/**
54 *if $_SESSION[SESSION_KEY.'g_user'] is not set : echo a warning
55 */
56
59
60$g_user->check();
61if ($g_user->check_dossier(dossier::id(), true) == 'X') {
62 ob_start();
63 require_once NOALYSS_TEMPLATE . '/ledger_detail_forbidden.php';
65 $html = ob_get_contents();
66 ob_end_clean();
68 header('Content-type: text/xml; charset=UTF-8');
69 echo <<<EOF
70<?xml version="1.0" encoding="UTF-8"?>
71<data>
72<ctl>$div</ctl>
73<code>$html</code>
74</data>
75EOF;
76 exit();
77}
78
79
80// check if the user can access the ledger where the operation is (view) and
81// if he can modify it
83$op->jr_id = $jr_id;
84$ledger = $op->get_ledger();
85if ($ledger == "") {
86
87 ob_start();
88 echo HtmlInput::title_box(_("Information"), $div);
89 require_once NOALYSS_TEMPLATE . '/ledger_detail_forbidden.php';
90 echo HtmlInput::button_close($div);
91 $html = ob_get_contents();
92 ob_end_clean();
93
95 if (!headers_sent()) {
96 header('Content-type: text/xml; charset=UTF-8');
97 } else {
98 echo "HTML" . unescape_xml($html);
99 }
100 echo <<<EOF
101<?xml version="1.0" encoding="UTF-8"?>
102<data>
103<ctl>$div</ctl>
104<code>$html</code>
105</data>
106EOF;
107 exit();
108
109}
110$access = $g_user->get_ledger_access($ledger);
111if ($access == 'X') {
112 ob_start();
113 echo HtmlInput::title_box(_("Information"), $div);
114 require_once NOALYSS_TEMPLATE . '/ledger_detail_forbidden.php';
115 echo HtmlInput::button_close($div);
116 $html = ob_get_contents();
117 ob_end_clean();
119 header('Content-type: text/xml; charset=UTF-8');
120 echo <<<EOF
121<?xml version="1.0" encoding="UTF-8"?>
122<data>
123<ctl>$div</ctl>
124<code>$html</code>
125</data>
126EOF;
127 exit();
128}
129$html = var_export($_REQUEST, true);
130switch ($action) {
131 ///////////////////////////////////////////////////////////////////////////
132 // remove op
133 ///////////////////////////////////////////////////////////////////////////
134 case 'rmop':
135 if ($access == 'W' && $g_user->check_action(RMOPER) == 1 && $g_parameter->MY_STRICT=='N') {
136 ob_start();
137 /* get the ledger */
138 try {
139 $cn->start();
140 $oLedger = new Acc_Ledger($cn, $ledger);
141 $oLedger->jr_id = $jr_id = $http->request('jr_id', "number");
142 $oLedger->delete();
143 $cn->commit();
144 echo _("Opération Effacée");
145 } catch (Exception $e) {
146 record_log($e);
147 $e->getMessage();
148 $cn->rollback();
149 }
150 $html = ob_get_contents();
151 ob_end_clean();
152 } else {
153 $html = _("Effacement refusé");
154 }
155 break;
156 //////////////////////////////////////////////////////////////////////
157 // DE Detail
158 //////////////////////////////////////////////////////////////////////
159 case 'de':
160 ob_start();
161
162 try {
163 /* get detail op (D/C) */
164 $op->get();
165 /* return an obj. ACH / FIN or VEN or null if nothing is found*/
166 $obj = $op->get_quant();
167
168 $oLedger = new Acc_Ledger($cn, $ledger);
169 if ($obj == null || $obj->signature == 'ODS') {
170 /* only the details */
171 require_once NOALYSS_TEMPLATE . '/ledger_detail_misc.php';
172 } elseif ($obj->signature == 'ACH') {
173 require_once NOALYSS_TEMPLATE . '/ledger_detail_ach.php';
174 } elseif ($obj->signature == 'FIN') {
175 require_once NOALYSS_TEMPLATE . '/ledger_detail_fin.php';
176 } elseif ($obj->signature == 'VEN') {
177 require_once NOALYSS_TEMPLATE . '/ledger_detail_ven.php';
178 }
179 } catch (Exception $e) {
180 record_log($e);
182 echo '<h2 class="error">' . _("Désolé il y a une erreur") . '</h2>';
183 }
184 $html = ob_get_contents();
185 ob_end_clean();
186
187 break;
188 /////////////////////////////////////////////////////////////////////////////
189 // form for the file
190 /////////////////////////////////////////////////////////////////////////////
191 case 'file':
192 $op->get();
193 $obj = $op->get_quant(); /* return an obj. ACH / FIN or VEN or null if nothing is found*/
194
195 $repo = new Database();
196 html_min_page_start($_SESSION[SESSION_KEY . 'g_theme']);
197
198 // if there is a receipt document
199 if ($obj->det->jr_pj_name == '') {
200 if (!isset($_REQUEST['ajax'])) {
201 echo '<div class="op_detail_frame">';
202 } else {
203 echo "<div>";
204
205 }
206 if ($access == 'W') {
207 $check_receipt = sprintf("check_receipt_size('%s','file%s')",
208 MAX_FILE_SIZE, $div);
209 echo '<FORM METHOD="POST" ENCTYPE="multipart/form-data" id="form_file" >';
210
211 $sp = new ISpan('file' . $div);
212 $sp->style = "display:none;background-color:red;color:white;font-size:12px";
213 $sp->value = _("Chargement");
214 echo $sp->input();
215 echo HtmlInput::hidden('act', 'loadfile');
216 echo dossier::hidden();
217 echo HtmlInput::hidden('jr_id', $jr_id);
218 echo HtmlInput::hidden('div', $div);
219 echo '<INPUT TYPE="FILE" id="receipt_id" name="pj" onchange="' . $check_receipt . '">';
220
221 echo '<p id="receipt_info_id" class="error"></p>';
222
223 echo '</FORM>';
224 } else {
225 if (!isset($_REQUEST['ajax'])) {
226 echo '<div class="op_detail_frame">';
227 } else {
228 echo "<div>";
229 }
230
231
232 echo _('Aucun fichier');
233 }
234 echo '</div>';
235 exit();
236 } else {
237 // There is no document attached to this writing
238 //
239 if (!isset($_REQUEST['ajax'])) {
240 echo '<div class="op_detail_frame">';
241 } else {
242 echo "<div>";
243
244 }
245 echo '<div class="op_detail_frame">';
246 $x = '';
247 if ($access == 'W' && $g_user->check_action(RMRECEIPT) == 1) {
248 // Not possible to remove the file thanks a modal dialog box,
249 // because of the frameset
250
251 $x = Icon_Action::trash(uniqid(),
252 sprintf("if (confirm(content[47])) {document.location.href='ajax_misc.php?op=ledger&gDossier=%d&div=%s&jr_id=%s&act=rmf'}",
254
255 }
256 $filename = $obj->det->jr_pj_name;
257 if (strlen($obj->det->jr_pj_name) > 60) {
258 $filename = mb_substr($obj->det->jr_pj_name, 0, 60);
259 }
260 echo HtmlInput::show_receipt_document($jr_id, h($filename));
261 echo $x;
262 echo '<p id="receipt_info_id" class="error"></p>';
263 echo '</div>';
264 echo '</body></html>';
265 exit();
266 }
267/////////////////////////////////////////////////////////////////////////////
268// load a file
269/////////////////////////////////////////////////////////////////////////////
270 case 'loadfile':
271 if ($access == 'W' && isset ($_FILES)) {
272 $cn->start();
273 // remove the file
274 $grpt = $cn->get_value('select jr_grpt_id from jrn where jr_id=$1', array($jr_id));
275 $cn->save_receipt($grpt);
276 $cn->commit();
277 // Show a link to the new file
278 $op->get();
279 $obj = $op->get_quant(); /* return an obj. ACH / FIN or VEN or null if nothing is found*/
280 html_min_page_start($_SESSION[SESSION_KEY . 'g_theme']);
281 if (!isset($_REQUEST['ajax'])) echo "<body class=\"op_detail_frame\">"; else echo "<body>";
282 echo '<div class="op_detail_frame">';
283 $x = "";
284 // check if the user can remove a document
285 if ($g_user->check_action(RMRECEIPT) == 1) {
286 // Not possible to remove the file thanks a modal dialog box,
287 // because of the frameset
288 $x = Icon_Action::trash(uniqid(),
289 sprintf("if (confirm(content[47])) {document.location.href='ajax_misc.php?op=ledger&gDossier=%d&div=%s&jr_id=%s&act=rmf'}",
291 }
292 $filename = $obj->det->jr_pj_name;
293 echo HtmlInput::show_receipt_document($jr_id, h($filename));
294 echo $x;
295
296 echo '</div>';
297 echo '</body></html>';
298 }
299 exit();
300/////////////////////////////////////////////////////////////////////////////
301// remove a file
302/////////////////////////////////////////////////////////////////////////////
303 case 'rmf':
304 if ($access == 'W' && $g_user->check_action(RMRECEIPT) == 1) {
305 $repo = new Database();
306 html_min_page_start($_SESSION[SESSION_KEY . 'g_theme']);
307 echo '<div class="op_detail_frame">';
308 $check_receipt = sprintf("check_receipt_size('%s','file%s')",
309 MAX_FILE_SIZE, $div);
310 echo '<FORM METHOD="POST" ENCTYPE="multipart/form-data" id="form_file">';
311 $sp = new ISpan('file' . $div);
312 $sp->style = "display:none;width:155px;height:15px;background-color:red;color:white;font-size:10px";
313 $sp->value = _("Chargement");
314 echo $sp->input();
315
316 echo HtmlInput::hidden('act', 'loadfile');
317 echo dossier::hidden();
318 echo HtmlInput::hidden('jr_id', $jr_id);
319 echo HtmlInput::hidden('div', $div);
320
321 echo '<INPUT TYPE="FILE" id="receipt_id" name="pj" onchange="' . $check_receipt . '">';
322 echo '<p id="receipt_info_id" class="error"></p>';
323 echo '</FORM>';
324 $ret = $cn->exec_sql("select jr_pj from jrn where jr_id=$1", array($jr_id));
325 if (Database::num_row($ret) != 0) {
327 $old_oid = $r['jr_pj'];
328 if (strlen($old_oid) != 0) {
329 // check if this pj is used somewhere else
330 $c = $cn->count_sql("select * from jrn where jr_pj=" . $old_oid);
331 if ($c == 1)
332 $cn->lo_unlink($old_oid);
333 }
334 $cn->exec_sql("update jrn set jr_pj=null, jr_pj_name=null, " .
335 "jr_pj_type=null where jr_id=$1", array($jr_id));
336 }
337 }
338 echo '</div>';
339 exit();
340/////////////////////////////////////////////////////////////////////////////
341// Save operation detail
342/////////////////////////////////////////////////////////////////////////////
343 case 'save':
344 ob_start();
345 $http = new HttpInput();
346 try {
347 $cn->start();
348 if ($access == "W" ) {
349 if (isset($_POST['p_ech'])) {
350 $ech = $http->post('p_ech');
351 if (trim($ech) != '' && isDate($ech) != null) {
352 $cn->exec_sql("update jrn set jr_ech=to_date($1,'DD.MM.YYYY') where jr_id=$2",
353 array($ech, $jr_id));
354
355 } else {
356 $cn->exec_sql("update jrn set jr_ech=null where jr_id=$1",
357 array($jr_id));
358
359 }
360 }
361
362 if (isset($_POST['p_date_paid'])) {
363 $ech = $http->post('p_date_paid');
364 if (trim($ech) != '' && isDate($ech) != null) {
365 $cn->exec_sql("update jrn set jr_date_paid=to_date($1,'DD.MM.YYYY') where jr_id=$2",
366 array($ech, $jr_id));
367
368 } else {
369 $cn->exec_sql("update jrn set jr_date_paid=null where jr_id=$1",
370 array($jr_id));
371
372 }
373 }
374 $oLedger=new Acc_Ledger($cn,$ledger);
375 $npj=$http->post('npj');
376 // protect receipt number
377 if ( ($g_parameter->MY_PJ_SUGGEST == 'A'||$g_user->check_action(UPDRECEIPT)==0) && $oLedger->get_type() !='FIN') {
378 $npj=$cn->get_value("select jr_pj_number from jrn where jr_id=$1",[$jr_id]);
379 }
380 // protect date in strict mode
381 $date=$http->post("p_date");
382 if ( $g_parameter->MY_STRICT=='Y' && $g_user->check_action(UPDDATE)==0) {
383 $date=$cn->get_value("select to_char(jr_date,'DD.MM.YYYY') from jrn where jr_id=$1",[$jr_id]);
384 }
385 $cn->exec_sql("update jrn set jr_comment=$1,jr_pj_number=$2,jr_date=to_date($4,'DD.MM.YYYY'),jr_optype=$5 where jr_id=$3",
386 array($http->post('lib'), $npj, $jr_id,$date, $http->post('jr_optype')));
387 $find_periode = $cn->get_value("select comptaproc.find_periode($1)",[$date]);
388
389 $cn->exec_sql("update jrnx set j_date=to_date($1,'DD.MM.YYYY'),j_tech_per=$3 where j_grpt in (select jr_grpt_id from jrn where jr_id=$2)",
390 array($date, $jr_id,$find_periode));
391 $cn->exec_sql('update operation_analytique set oa_date=j_date from jrnx
392 where
393 operation_analytique.j_id=jrnx.j_id and
394 operation_analytique.j_id in (select j_id
395 from jrnx join jrn on (j_grpt=jr_grpt_id)
396 where jr_id=$1)
397 ', array($jr_id));
398 $cn->exec_sql("select comptaproc.jrn_add_note($1,$2)",
399 array($jr_id, $http->post('jrn_note')));
400 $rapt = $_POST['rapt'];
401
402 if ($g_parameter->MY_UPDLAB == 'Y' && isset ($_POST['j_id'])) {
403 $a_rowid = $http->post("j_id");
404 for ($e = 0; $e < count($a_rowid); $e++) {
405 $id = "e_march" . $a_rowid[$e] . "_label";
406 $cn->exec_sql('update jrnx set j_text=$1 where j_id=$2', array($http->post($id), $a_rowid[$e]));
407 }
408 }
409 if (trim($rapt) != '') {
410 $rec = new Acc_Reconciliation ($cn);
411 $rec->set_jr_id($jr_id);
412
413 if (strpos($rapt, ",") != 0) {
414 $aRapt = explode(',', $rapt);
415 /* reconcialition */
416 foreach ($aRapt as $rRapt) {
417 if (isNumber($rRapt) == 1) {
418 // Add a "concerned operation to bound these op.together
419 $rec->insert($rRapt);
420 }
421 }
422 } else
423 if (isNumber($rapt) == 1) {
424 $rec->insert($rapt);
425 }
426 }
427 if (isset($_POST['ipaid'])) {
428 $cn->exec_sql("update jrn set jr_rapt='paid' where jr_id=$1", array($jr_id));
429 } else {
430 $cn->exec_sql("update jrn set jr_rapt=null where jr_id=$1", array($jr_id));
431 }
432 ////////////////////////////////////////////////////
433 // CA
434 //////////////////////////////////////////////////
436 if ($owner->MY_ANALYTIC != "nu" && isset ($_POST['op'])) {
437 // for each item, insert into operation_analytique */
438 $opanc = new Anc_Operation($cn);
439 $opanc->save_update_form($_POST);
440 }
441 //////////////////////////////////////////////////////////////////
442 //Save other info
443 //////////////////////////////////////////////////////////////////
444 $op->save_info($http->post('OTHER'), 'OTHER');
445 $op->save_info($http->post('BON_COMMANDE'), 'BON_COMMANDE');
446
447 ///////////////////////////////////////////////////////////////////
448 // Save related
449 //////////////////////////////////////////////////////////////////
450 $related = $http->post("related", "string");
451 if ($related == "0") {
452 throw new Exception('Parameter not send -> related' . __FILE__ . __LINE__, 10);
453 }
454 $op->insert_related_action($related);
455
456 }
457 echo 'OK';
458 $cn->commit();
459 } catch (Exception $e) {
460 $html = ob_get_contents();
461 ob_end_clean();
462 record_log($e);
464
465 if (DEBUGNOALYSS > 0) echo $e->getMessage();
466 echo _("Changement impossible: on ne peut pas changer la date dans une période fermée");
467 return;
468 }
469 $html = ob_get_contents();
470 ob_end_clean();
471
472 break;
473 ////////////////////////////////////////////////////////////////////////////
474 // remove a reconciliation
475 ////////////////////////////////////////////////////////////////////////////
476 case 'rmr':
477 if ($access == 'W') {
478 $rec = new Acc_Reconciliation($cn);
479 $rec->set_jr_id($jr_id);
480 $rec->remove($_GET['jr_id2']);
481 }
482 break;
483 ////////////////////////////////////////////////////////////////////////////
484 // ask for a date for reversing the operation
485 ////////////////////////////////////////////////////////////////////////////
486 case 'ask_extdate':
487 $date = new IDate('p_date');
488 $html .= "<form id=\"form_" . $div . "\" onsubmit=\"return reverseOperation(this);\">";
489 $html .= HtmlInput::hidden('jr_id', $_REQUEST['jr_id']) .
490 HtmlInput::hidden('div', $div) .
491 dossier::hidden() .
492 HtmlInput::hidden('act', 'reverseop');
493
494 $html .= '<h2 class="info">' . _('entrez une date') . ' </H2>' . $date->input();
495 $html .= HtmlInput::submit('x', 'accepter');
497 $html .= '</form>';
498 break;
499 ////////////////////////////////////////////////////////////////////////////
500 // Reverse an operation
501 ////////////////////////////////////////////////////////////////////////////
502 case 'reverseop':
503 if ($access == 'W') {
504 ob_start();
505 try {
506 $ext_date = $http->request("ext_date", "date");
507 $ext_label = $http->request("ext_label");
508 $cn->start();
509 $oLedger = new Acc_Ledger($cn, $ledger);
510 $oLedger->jr_id = $jr_id;
511 if (trim($ext_label) == "") {
512 $ext_label = _("Extourne") . $cn->get_value("select jr_comment from jrn where jr_id=$1", [$jr_id]);
513 }
514 $oLedger->reverse($ext_date, $ext_label);
515 $cn->commit();
516 echo _("Opération extournée");
517 } catch (Exception $e) {
518 record_log($e);
519 echo $e->getMessage();
520 $cn->rollback();
521 }
522 }
523 $html = ob_get_contents();
524 ob_end_clean();
525 break;
526
527 case 'duplicateop':
528 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
529 // Duplicate operation
530 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
532 $operation->jr_id = $jr_id;
533 ob_start();
534 echo HtmlInput::title_box(_("Dupliquer une opération"), $div);
535 echo $operation->form_clone_operation("cloneit");
536
537 $html = ob_get_contents();
538 ob_end_clean();
539
540
541 break;
542}
544if (!headers_sent()) {
545 header('Content-type: text/xml; charset=UTF-8');
546} else {
547 echo "HTML" . unescape_xml($html);
548}
549
550echo <<<EOF
551<?xml version="1.0" encoding="UTF-8"?>
552<data>
553<ctl>$div</ctl>
554<code>$html</code>
555</data>
556EOF;
isNumber($p_int)
isDate($p_date)
html_min_page_start($p_theme="", $p_script="", $p_script2="")
Minimal page header for each page, used for small popup window.
record_log($p_message)
Record an error message into the log file of the server or in the log folder of NOALYSS Record also t...
global $g_parameter
global $g_user
if no group available , then stop
if(headers_sent() &&DEBUGNOALYSS > 0) $html
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$op
h( $row[ 'oa_description'])
if($ledger=="") $access
$jr_id
if(isset($_REQUEST['gDossier']) && $http->request("gDossier","number", 0) !=0) $repo
$_REQUEST['ac']
_("actif, passif,charge,...")
$_GET['qcode']
Class for jrn, class acc_ledger for manipulating the ledger AND some acc.
this file match the tables jrn & jrnx the purpose is to remove or save accountant writing to these ta...
new class for managing the reconciliation it must be used instead of the function InsertRapt,...
this class is used to show the form for entering an operation only FOR analytic operation to save it,...
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static num_row($ret)
wrapper for the function pg_num_rows
contains the class for connecting to Noalyss
static connect()
static button_close($div_name, $class='smallbutton')
close button for the HTML popup
static show_receipt_document($p_jr_id, $p_name="")
Returns HTML code for displaying a icon with a link to a receipt document from the ledger.
static hidden($p_name, $p_value, $p_id="")
static title_box($p_name, $p_div, $p_mod="close", $p_js="", $p_draggable="n", $p_enlarge='n', $raw="")
Title for boxes, you can customize the symbol thanks symbol with the mode "custom".
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
manage the http input (get , post, request) and extract from an array
Html Input : Input a date format dd.mm.yyyy The property title should be set to indicate what it is e...
Html Input.
static close($p_div)
Return a html string with an anchor which close the inside popup.
static trash($p_id, $p_javascript)
Display the icon of a trashbin.
Class to manage the company parameter (address, name...)
$c
Definition compute.php:48
const RMRECEIPT
const UPDDATE
const UPDRECEIPT
const RMOPER
$_POST['ac']
Definition do.php:312
for($e=0; $e< count($afiche); $e++) exit
escape_xml($p_xml)
When data are transfered thanks ajax in a xml document, the xml can not contains some character,...
unescape_xml($p_xml)
replace special char
if( $delta< 0) elseif( $delta==0)