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.='
' . 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){ ?> + +