noalyss Version-9
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 */
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';
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';
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 $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)",
388 array($date, $jr_id));
389 $cn->exec_sql('update operation_analytique set oa_date=j_date from jrnx
390 where
391 operation_analytique.j_id=jrnx.j_id and
392 operation_analytique.j_id in (select j_id
393 from jrnx join jrn on (j_grpt=jr_grpt_id)
394 where jr_id=$1)
395 ', array($jr_id));
396 $cn->exec_sql("select comptaproc.jrn_add_note($1,$2)",
397 array($jr_id, $http->post('jrn_note')));
398 $rapt = $_POST['rapt'];
399
400 if ($g_parameter->MY_UPDLAB == 'Y' && isset ($_POST['j_id'])) {
401 $a_rowid = $http->post("j_id");
402 for ($e = 0; $e < count($a_rowid); $e++) {
403 $id = "e_march" . $a_rowid[$e] . "_label";
404 $cn->exec_sql('update jrnx set j_text=$1 where j_id=$2', array($http->post($id), $a_rowid[$e]));
405 }
406 }
407 if (trim($rapt) != '') {
408 $rec = new Acc_Reconciliation ($cn);
409 $rec->set_jr_id($jr_id);
410
411 if (strpos($rapt, ",") != 0) {
412 $aRapt = explode(',', $rapt);
413 /* reconcialition */
414 foreach ($aRapt as $rRapt) {
415 if (isNumber($rRapt) == 1) {
416 // Add a "concerned operation to bound these op.together
417 $rec->insert($rRapt);
418 }
419 }
420 } else
421 if (isNumber($rapt) == 1) {
422 $rec->insert($rapt);
423 }
424 }
425 if (isset($_POST['ipaid'])) {
426 $cn->exec_sql("update jrn set jr_rapt='paid' where jr_id=$1", array($jr_id));
427 } else {
428 $cn->exec_sql("update jrn set jr_rapt=null where jr_id=$1", array($jr_id));
429 }
430 ////////////////////////////////////////////////////
431 // CA
432 //////////////////////////////////////////////////
434 if ($owner->MY_ANALYTIC != "nu" && isset ($_POST['op'])) {
435 // for each item, insert into operation_analytique */
436 $opanc = new Anc_Operation($cn);
437 $opanc->save_update_form($_POST);
438 }
439 //////////////////////////////////////////////////////////////////
440 //Save other info
441 //////////////////////////////////////////////////////////////////
442 $op->save_info($http->post('OTHER'), 'OTHER');
443 $op->save_info($http->post('BON_COMMANDE'), 'BON_COMMANDE');
444
445 ///////////////////////////////////////////////////////////////////
446 // Save related
447 //////////////////////////////////////////////////////////////////
448 $related = $http->post("related", "string");
449 if ($related == "0") {
450 throw new Exception('Parameter not send -> related' . __FILE__ . __LINE__, 10);
451 }
452 $op->insert_related_action($related);
453
454 }
455 echo 'OK';
456 $cn->commit();
457 } catch (Exception $e) {
458 $html = ob_get_contents();
459 ob_end_clean();
460 record_log($e);
462
463 if (DEBUGNOALYSS > 0) echo $e->getMessage();
464 echo _("Changement impossible: on ne peut pas changer la date dans une période fermée");
465 return;
466 }
467 $html = ob_get_contents();
468 ob_end_clean();
469
470 break;
471 ////////////////////////////////////////////////////////////////////////////
472 // remove a reconciliation
473 ////////////////////////////////////////////////////////////////////////////
474 case 'rmr':
475 if ($access == 'W') {
476 $rec = new Acc_Reconciliation($cn);
477 $rec->set_jr_id($jr_id);
478 $rec->remove($_GET['jr_id2']);
479 }
480 break;
481 ////////////////////////////////////////////////////////////////////////////
482 // ask for a date for reversing the operation
483 ////////////////////////////////////////////////////////////////////////////
484 case 'ask_extdate':
485 $date = new IDate('p_date');
486 $html .= "<form id=\"form_" . $div . "\" onsubmit=\"return reverseOperation(this);\">";
487 $html .= HtmlInput::hidden('jr_id', $_REQUEST['jr_id']) .
488 HtmlInput::hidden('div', $div) .
489 dossier::hidden() .
490 HtmlInput::hidden('act', 'reverseop');
491
492 $html .= '<h2 class="info">' . _('entrez une date') . ' </H2>' . $date->input();
493 $html .= HtmlInput::submit('x', 'accepter');
495 $html .= '</form>';
496 break;
497 ////////////////////////////////////////////////////////////////////////////
498 // Reverse an operation
499 ////////////////////////////////////////////////////////////////////////////
500 case 'reverseop':
501 if ($access == 'W') {
502 ob_start();
503 try {
504 $ext_date = $http->request("ext_date", "date");
505 $ext_label = $http->request("ext_label");
506 $cn->start();
507 $oLedger = new Acc_Ledger($cn, $ledger);
508 $oLedger->jr_id = $jr_id;
509 if (trim($ext_label) == "") {
510 $ext_label = _("Extourne") . $cn->get_value("select jr_comment from jrn where jr_id=$1", [$jr_id]);
511 }
512 $oLedger->reverse($ext_date, $ext_label);
513 $cn->commit();
514 echo _("Opération extournée");
515 } catch (Exception $e) {
516 record_log($e);
517 echo $e->getMessage();
518 $cn->rollback();
519 }
520 }
521 $html = ob_get_contents();
522 ob_end_clean();
523 break;
524
525 case 'duplicateop':
526 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
527 // Duplicate operation
528 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
530 $operation->jr_id = $jr_id;
531 ob_start();
532 echo HtmlInput::title_box(_("Dupliquer une opération"), $div);
533 echo $operation->form_clone_operation("cloneit");
534
535 $html = ob_get_contents();
536 ob_end_clean();
537
538
539 break;
540}
542if (!headers_sent()) {
543 header('Content-type: text/xml; charset=UTF-8');
544} else {
545 echo "HTML" . unescape_xml($html);
546}
547
548echo <<<EOF
549<?xml version="1.0" encoding="UTF-8"?>
550<data>
551<ctl>$div</ctl>
552<code>$html</code>
553</data>
554EOF;
isNumber($p_int)
Definition: ac_common.php:215
isDate($p_date)
Definition: ac_common.php:236
html_min_page_start($p_theme="", $p_script="", $p_script2="")
Minimal page header for each page, used for small popup window.
Definition: ac_common.php:408
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1342
$action
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
h( $row[ 'oa_description'])
if($ledger=="") $access
$gDossier
Definition: ajax_ledger.php:46
$ledger
Definition: ajax_ledger.php:84
if($g_user->check_dossier(dossier::id(), true)=='X') $op
Definition: ajax_ledger.php:82
global $g_user
Check if we receive the needed data (jr_id...)
Definition: ajax_ledger.php:39
$http
Definition: ajax_ledger.php:34
$jr_id
Definition: ajax_ledger.php:44
global $g_parameter
Definition: ajax_ledger.php:39
$div
Definition: ajax_ledger.php:45
global $cn
if $_SESSION[SESSION_KEY.
Definition: ajax_ledger.php:39
if($access=='X') $html
if(isset($_REQUEST['gDossier']) && $http->request("gDossier","number", 0) !=0) $repo
$_REQUEST['ac']
$input_from id
Definition: balance.inc.php:63
$_GET['qcode']
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')
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...
Definition: idate.class.php:34
Html Input.
Definition: ispan.class.php:32
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...)
const RMRECEIPT
const UPDDATE
const UPDRECEIPT
const RMOPER
$_POST['ac']
Definition: do.php:310
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)