From a48140d3cc5dfeac8c17592aaedc0f3cecfcb168 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Sat, 21 Jun 2025 17:58:22 +0200 Subject: [PATCH] =?UTF-8?q?#2417:=20Op=C3=A9ration=20pay=C3=A9e=20:=20dans?= =?UTF-8?q?=20HISTO=20impress=5Frec.inc.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- html/ajax_misc.php | 2 + html/js/noalyss_script.js | 1 + html/js/operation_payment.js | 144 ++++++++++++++++++++++ include/ajax/ajax_payment_status.php | 65 ++++++++++ include/class/acc_ledger_search.class.php | 1 + include/history_operation.inc.php | 39 +++--- 6 files changed, 229 insertions(+), 23 deletions(-) create mode 100644 html/js/operation_payment.js create mode 100644 include/ajax/ajax_payment_status.php diff --git a/html/ajax_misc.php b/html/ajax_misc.php index ce27ce175..6cf1c689d 100644 --- a/html/ajax_misc.php +++ b/html/ajax_misc.php @@ -365,6 +365,8 @@ $path = array( ,"category_card_definition"=>"ajax_category_card_definition" // activate plugin for a profile ,'activate_plugin'=>'ajax_activate_plugin' + // set the operation paid or unpaid + , 'payment_status'=>'ajax_payment_status' ) ; if (array_key_exists($op, $path)) { diff --git a/html/js/noalyss_script.js b/html/js/noalyss_script.js index 275ca6e5b..e57d46fa1 100644 --- a/html/js/noalyss_script.js +++ b/html/js/noalyss_script.js @@ -4701,6 +4701,7 @@ Widget.prototype.toggle_full_size=function (widget_domid) { }; + /** * EXPERIMENTAL (function(){window.addEventListener("beforeunload", (event) => {waiting_box()});})(); diff --git a/html/js/operation_payment.js b/html/js/operation_payment.js new file mode 100644 index 000000000..4109a230c --- /dev/null +++ b/html/js/operation_payment.js @@ -0,0 +1,144 @@ +/* + * Copyright (C) 2025 dany + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + +/////////////////////////////////////////////////////////////////////// +// Operation payement +// Selection on operation history : payment +var Operation_Payment = function (range_name, dossier_id, ac) { + this.lastcheck = null; + this.endcheck = null; + this.range_name = range_name; + this.dossier_id = dossier_id; + this.ac = ac; +}; + +Operation_Payment.prototype.activate_checkbox_range = function () { + let node_lstCheckBox = document.getElementsByClassName(this.range_name); + var aCheckBox = Array.from(node_lstCheckBox) + if (aCheckBox == undefined) { + console.error("activate_checkbox_range_failed") + } + var here = this; + aCheckBox.forEach(elt => elt.addEventListener('click', function (event) { + here.checkbox_set_range(event, elt); + }, false)); +}; + +Operation_Payment.prototype.checkbox_set_range = function (event, elt) +{ + + if (!event.shiftKey) { + this.lastcheck = elt; + return; + } + waiting_box(); + var aName = document.getElementsByClassName(this.range_name); + + var from = 0; + var end = 0; + for (var i = 0; i < aName.length; i++) { + if (aName[i] == elt) { + this.endcheck = aName[i]; + from = i; + } + if (aName[i] == this.lastcheck) { + end = i; + } + } + if (from > end) { + let a = from; + from = end; + end = a; + } + var check = (aName[from].checked) ? true : false; + for (x = from + 1; x < end; x++) { + if (aName[x].parentNode.parentNode.visible()) { + aName[x].checked=check; + this.check_item(aName[x],true) + } + } + remove_waiting_box(); +}; + +Operation_Payment.prototype.check_item = function (dom_elt,flag_waiting_box) +{ + console.debug(`element = ${dom_elt.name}`); + console.debug(`dossier ${this.dossier_id} ac ${this.ac}`) + try + { + if ( ! flag_waiting_box ) waiting_box(); + var queryString = {op:'payment_status',operation_id:dom_elt.name,gDossier:this.dossier_id,ac:this.ac,state:dom_elt.checked}; + console.debug (`queryString : `) + console.debug (queryString) + + var action = new Ajax.Request( + "ajax_misc.php", + { + method: 'POST', + parameters: queryString, + onFailure: ajax_misc_failure, + onSuccess: function (req) { + if ( ! flag_waiting_box )remove_waiting_box(); + if (req.responseText == 'NOCONX') { + reconnect(); + return; + } + if ( req.responseText == 1) { dom_elt.checked=true} + else + if ( req.responseText == 0) { dom_elt.checked=false} + else { + console.error(req.responseText) + } + + } + } + ); + } catch (e) + { + alert_box(e.message); + } + +}; +//Operation_Payment.prototype.check_all=function() +//{ +// var aName = document.getElementsByClassName(this.range_name); +// for (x = 0; x < aName.lenght; x++) { +// if (aName[x].parentNode.parentNode.visible()) { +// aName[x].checked=true; +// this.check_item(aName[x]); +// } +// } +// +//} +//Operation_Payment.prototype.invert_selection=function() +//{ +// var aName = document.getElementsByClassName(this.range_name); +// for (x = 0; x < aName.lenght; x++) { +// if (aName[x].parentNode.parentNode.visible()) { +// if ( aName[x].checked ) { +// aName[x].checked=false; +// } else { +// aName[x].checked=true; +// } +// this.check_item(aName[x]); +// } +// } +// +//} + diff --git a/include/ajax/ajax_payment_status.php b/include/ajax/ajax_payment_status.php new file mode 100644 index 000000000..ab89d28cd --- /dev/null +++ b/include/ajax/ajax_payment_status.php @@ -0,0 +1,65 @@ +post("ac"); + $operation_id=$http->post("operation_id"); + $state=$http->post("state"); +} catch (Exception $exc) { + record_log($exc); + return; +} +$a_module=explode("/",$ac); + +// stop if user cannot access this module +if ($g_user->check_module($a_module[count($a_module)-1]) == 0) { return ; } + +// var $jr_id must be the JRN.JR_ID +$jr_id=str_replace("rd_paid", "", $operation_id); + +// stop if $jr_id is not a number +if (isNumber($jr_id) == 0 ) { + return; +} + +// User can access this operation in writing +$ledger_id=$cn->get_value("select jr_def_id from jrn where jr_id=$1",[$jr_id]); + +// stop if user cannot access this ledger +if ( $g_user->get_ledger_access($ledger_id) != "W") { return;} + +if ( $state == "true") { + $cn->exec_sql("update jrn set jr_rapt='paid' where jr_id=$1",[$jr_id]); + echo 1; +} elseif( $state == "false") { + $cn->exec_sql("update jrn set jr_rapt=null where jr_id=$1",[$jr_id]); + echo 0; +} else { + echo "ERROR : unknown state [$state]"; +} diff --git a/include/class/acc_ledger_search.class.php b/include/class/acc_ledger_search.class.php index 90e0a72ef..430aaa663 100644 --- a/include/class/acc_ledger_search.class.php +++ b/include/class/acc_ledger_search.class.php @@ -985,6 +985,7 @@ class Acc_Ledger_Search $w->selected=($row['jr_rapt']=='paid')?true:false; // if p_paid == 2 then readonly $w->readonly=( $p_paid==2)?true:false; + $w->javascript='onclick="operation_payment.check_item(this)"'; $h=new IHidden(); $h->name="set_jr_id".$row['jr_id']; $r.=''.$w->input().$h->input().''; diff --git a/include/history_operation.inc.php b/include/history_operation.inc.php index 4a97184c5..b0c6a9105 100644 --- a/include/history_operation.inc.php +++ b/include/history_operation.inc.php @@ -22,11 +22,10 @@ /** * \file - * - * * \brief display history of accountant , and let search into * */ +echo js_include("operation_payment.js"); if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis'); global $g_user,$cn,$http; $p_array = $_GET; @@ -72,16 +71,6 @@ if (isset($_REQUEST['p_jrn']) && $Ledger->id = $p_jrn; -//------------------------------ -// UPdate the payment -//------------------------------ -if (isset($_GET ['paid'])) -{ - $ledger_paid=new Acc_Ledger($cn,$p_jrn); - $ledger_paid->update_paid($_GET); -} - - $msg=""; /* by default we should use the default period */ if (!isset($p_array['date_start'])) @@ -105,12 +94,15 @@ list($sql, $where) = $Ledger->build_search_sql($p_array); $max_line = $cn->count_sql($sql); $step = $_SESSION[SESSION_KEY.'g_pagesize']; -$page = (isset($_GET['offset'])) ? $http->get('page') : 1; -$offset = (isset($_GET['offset'])) ? $http->get('offset') : 0; +try +{ + $page = $http->get('page','string',1); + $offset =$http->get('offset','string',0); +} catch (\Exception $e) +{ + $page=1;$offset=0; +} -// check if number -$page=(isNumber($page)==0)?1:$page; -$offset=(isNumber($offset)==0)?0:$offset; $bar = navigation_bar($offset, $max_line, $step, $page); @@ -162,11 +154,6 @@ if (isset($_GET['search_opr_jrn'])) } echo $r; -if ($ask_pay) { - echo '

' . HtmlInput::submit('paid', _('Mise à jour paiement')) . IButton::select_checkbox('fpaida') . IButton::unselect_checkbox('fpaida') . '

'; - echo ICheckBox::javascript_set_range("paid_operation_ck"); -} - echo ''; /* * Export to csv @@ -205,5 +192,11 @@ echo HtmlInput::hidden('qcode',trim($qcode)); echo ''; echo ''; -return; +if ( $ask_pay){ ?> + +