noalyss Version-9
compta_fin_rec.inc.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * NOALYSS is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * NOALYSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with NOALYSS; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21// Copyright Author Dany De Bontridder danydb@aevalys.eu
22
23/**\file
24 *
25 *
26 * \brief reconcile operation
27 *
28 */
29if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
31bcscale(2);
32?>
33<script>
34 var Bank_Reconciliation =
35 {
36 /**
37 * For each checkbox , add an event on click
38 * @param {string} p_range_name name of the checkbox object
39 * @returns {undefined}
40 */
41 activate_checkbox_range:function (p_range_name) {
42 let node_lstCheckBox = document.getElementsByClassName(p_range_name);
43 var aCheckBox=Array.from(node_lstCheckBox)
44 if (aCheckBox == undefined) {
45 console.error("Bank_Reconciliation.activate_checkbox_range_failed")
46 }
47
48 aCheckBox.forEach(elt => elt.addEventListener ('click',function (event) {
49 Bank_Reconciliation.checkbox_set_range(event, elt, p_range_name);
50 },false));
51 },
52 checkbox_set_range:function (evt, elt, p_name) {
53 if (!evt.shiftKey) {
54 lastcheck = elt;
55 return;
56 }
57 var aName = document.getElementsByClassName(p_name);
58
59 var from = 0;
60 var end = 0;
61 for (var i = 0; i < aName.length; i++) {
62 if (aName[i] == elt) {
63 endcheck = aName[i];
64 from = i;
65 }
66 if (aName[i] == lastcheck) {
67 end = i;
68 }
69 }
70 if (from > end) {
71 let a = from;
72 from = end;
73 end = a;
74 }
75 var check = (aName[from].checked) ? true : false;
76 for (x = from; x <= end; x++) {
77 aName[x].checked = check;
78 if( x < end && x > from ) {
79 Bank_Reconciliation.update_selected(aName[x],aName[x].getAttribute('amount_operation'));
80 Bank_Reconciliation.update_remain(aName[x],aName[x].getAttribute('amount_operation'));
81 }
82 }
83 },
84
85
86 update_selected:function (p_node,p_amount) {
87
88 p_amount=parseFloat(p_amount);
89 try {
90 if (p_node.checked )
91 {
92 var selected=parseFloat($('selected_amount').innerHTML)+p_amount;
93 $('selected_amount').innerHTML=Math.round(selected*100)/100;
94 } else {
95 var selected=parseFloat($('selected_amount').innerHTML)-p_amount;
96 $('selected_amount').innerHTML=Math.round(selected*100)/100;
97
98 }
99 } catch(e) {
100 if (console) {console.error('Bank_Reconciliation.update_selected :'+e.message);}
101 }
102 },
103 update_remain:function (p_node,p_amount) {
104 p_amount=parseFloat(p_amount);
105 try {
106 if ( parseFloat($('delta_amount').innerHTML) == 0) return;
107 if (p_node.checked )
108 {
109 var selected=parseFloat($('remain_amount').innerHTML)-p_amount;
110 $('remain_amount').innerHTML=Math.round(selected*100)/100;
111 } else {
112 var selected=parseFloat($('remain_amount').innerHTML)+p_amount;
113 $('remain_amount').innerHTML=Math.round(selected*100)/100;
114
115 }
116 } catch(e) {
117 if (console) {console.error('Bank_Reconciliation.update_remain :'+e.message);}
118
119 }
120 },
121 update_delta:function () {
122 try {
123 var delta=parseFloat($('end_extrait').value)-parseFloat($('start_extrait').value);
124 delta=Math.round(delta*100)/100;
125 $('delta_amount').innerHTML=delta;
126 var remain=delta-parseFloat($('selected_amount').innerHTML);
127 $('remain_amount').innerHTML=Math.round(remain*100)/100;
128 } catch(e) {
129 if (console) {console.error('Bank_Reconciliation.update_delta :' +e.message);}
130 }
131 },
132 recompute:function (p_form) {
133 try {
134 var form=$(p_form);
135 var i=0;
136 for (i=0;i<form.length;i++) {
137 var e=form.elements[i];
138 if (e.type=='checkbox') {
139 e.click();
140 }
141 }
142 remove_waiting_box();
143 } catch (e) {
144 if (console) {console.error('Bank_Reconciliation.recompute :' +e.message);}
145 }
146 }
147 }
148</script>
149<?php
150echo '<div class="content">';
152if (!isset($_REQUEST['p_jrn']))
153{
154 $a = $Ledger->get_first('fin');
155 if ( isset($a['jrn_def_id'])) {
156 $Ledger->id = $a['jrn_def_id'];
157 } else {
158 $Ledger->id=0;
159 }
160}
161else
162{
163 $Ledger->id =$http->request("p_jrn","number",0);
164}
165$jrn_priv = ($Ledger->id == 0)?"X":$g_user->get_ledger_access($Ledger->id);
166if (isset($_GET["p_jrn"]) && $jrn_priv == "X")
167{
168 NoAccess();
169 return;
170}
171$end_extrait=$http->post("end_extrait", "string",0);
172$start_extrait=$http->post("start_extrait","string", 0);
173if ( isNumber($end_extrait) == 0 )
174{
175 echo '<span class="notice">';
176 echo _('Donnée invalide');
177 echo '</span>';
178 $end_extrait=0;
179}
180if ( isNumber($start_extrait) == 0 )
181{
182 echo '<span class="notice">';
183 echo _('Donnée invalide');
184 echo '</span>';
186}
187//-------------------------
188// save
189//-------------------------
190if (isset($_POST['save']))
191{
192 $receipt_nb=$http->post("ext");
193 if (trim($receipt_nb) == '' && isset($_POST['op'])) {
194 echo_warning(_('Numéro de relevé est obligatoire'));
195 }
196 if (trim($receipt_nb) != '' && isset($_POST['op']))
197 {
198 $array = $_POST['op'];
199 $tot = 0;
200 $cn->start();
201 for ($i = 0; $i < count($array); $i++)
202 {
203 $cn->exec_sql('update jrn set jr_pj_number=$1 where jr_id=$2', array($_POST['ext'], $array[$i]));
204 $tot = bcadd($tot, $cn->get_value('select qf_amount from quant_fin where jr_id=$1', array($array[$i])));
205 }
207 if ($diff != 0 && $diff != $tot)
208 {
209 $remain=bcsub($tot,$diff);
210 $cn->rollback();
211 alert("D'après l'extrait il y aurait du avoir un montant de $diff à rapprocher alors qu'il y a $tot rapprochés, mise à jour annulée, la différence est de $remain");
212 echo '<div class="error">';
213 echo '<p>'.$g_failed._("D'après l'extrait il y aurait du avoir un montant de $diff à rapprocher alors qu'il y a $tot rapprochés, la différence est de $remain <br>mise à jour annulée").'</p>';
214 /* if file : warning that file is not uploaded*/
215 echo '<p>'.
216 _('Attention : Fichier non chargé').
217 '</p>';
218 echo '</div>';
219 }
220 else
221 {
222 echo '<div class="content">'.$g_succeed.' Mise à jour extrait '.$_POST['ext'].'</div>';
223 // -- chargement fichier
224 $oid=$cn->upload('file_receipt');
225
226 if ( $oid != false ) {
227 for ($i = 0; $i < count($array); $i++)
228 {
229 $cn->exec_sql("update jrn set jr_pj=$1 , jr_pj_name=$2,
230 jr_pj_type=$3 where jr_id=$4",
231 array($oid,$_FILES['file_receipt']['name'] ,$_FILES['file_receipt']['type'],$array[$i]));
232 }
233 }
234 }
235
236 $cn->commit();
237 }
238}
239//-------------------------
240// show the operation of this ledger
241// without receipt number
242//-------------------------
243echo '<div class="content">';
244echo '<form method="get">';
245echo HtmlInput::get_to_hidden(array('gDossier', 'ledger_type', 'ac', 'sa'));
246$wLedger = $Ledger->select_ledger('FIN', 3,FALSE);
247if ($wLedger == null)
248 exit('Pas de journal disponible');
249echo '<div id="jrn_name_div">';
250echo '<h1 id="jrn_name" style="display:inline">' . $Ledger->get_name() . '</h1>';
251echo '</div>';
252$wLedger->javascript = "onchange='this.form.submit()';";
253echo $wLedger->input();
254echo HtmlInput::submit('ref', 'Rafraîchir');
255echo '</form>';
256echo '<span id="bkname" style="display:block">' . hb(h($Ledger->get_bank_name())) . '</span>';
257
258echo '<form method="post" id="rec1" enctype="multipart/form-data">';
259
260echo dossier::hidden();
261echo HtmlInput::get_to_hidden(array('sa', 'p_action', 'p_jrn'));
262
263$operation = $cn->get_array("select jr_id,jr_internal,
264 jr_comment,
265 to_char(jr_date,'DD.MM.YYYY') as fmt_date,
266 jr_montant,
267 to_char(jr_date,'YYYYMMDD') as raw_date
268 from jrn where jr_def_id=$1 and (jr_pj_number is null or jr_pj_number='') order by jr_date", array($Ledger->id));
269
270echo '<p>';
271$iextrait = new IText('ext');
272 $iextrait->value=$http->post('ext','string','');
273
274$nstart_extrait = new INum('start_extrait');
276$nstart_extrait->javascript='onchange="format_number(this,2);Bank_Reconciliation.update_delta();"';
277
278$nend_extrait = new INum('end_extrait');
280$nend_extrait->javascript='onchange="format_number(this,2);Bank_Reconciliation.update_delta();"';
281
282echo _("Extrait / relevé :") . $iextrait->input();
283echo _('solde Début') . $nstart_extrait->input();
284echo _('solde Fin') . $nend_extrait->input();
285$take_end=new IButton('select_all');
286$take_end->label=_('Reprendre le solde de fin');
287$take_end->javascript="document.getElementById('start_extrait').value=document.getElementById('end_extrait').value;document.getElementById('end_extrait').focus()";
288echo $take_end->input();
289echo '</p>';
290echo '<p>';
291echo _('Cherche').Icon_Action::infobulle(25);
292echo HtmlInput::filter_table("t_rec_bk", "0,1,2,3","1");
293echo '</p>';
294echo HtmlInput::submit('save', 'Mettre à jour le n° de relevé bancaire');
295echo '<span style="display:block">';
296 echo '</span>';
297$select_all=new IButton('select_all');
298$select_all->label=_('Inverser la sélection');
299$select_all->javascript="Bank_Reconciliation.recompute('rec1')";
300echo '<table id="t_rec_bk" class="sortable" style="width:90%;margin-left:5%">';
301
302$r ='<th class=" sorttable_sorted">'.'Date '.Icon_Action::infobulle(17).'</th>';
303$r.=th('Libellé');
304$r.=th('N° interne');
305$r.=th('Montant', ' style="text-align:right"');
306$r.='<th class="sorttable_nosort" style="text-align:center">'.$select_all->input().'</th>';
307echo tr($r);
308
314for ($i = 0; $i < count($operation); $i++)
315{
316 $iradio = new ICheckBox('op[]');
317 $iradio->set_range("operation_ck");
318 $row = $operation[$i];
319 $r = '';
320 $js = HtmlInput::detail_op($row['jr_id'], $row['jr_internal']);
321 $r.='<td sorttable_customkey="'.$row['raw_date'].'">'.$row['fmt_date'].'</td>';
322 $r.=td($row['jr_comment']);
323 $r.=td($js);
324 $amount=$cn->get_value('select qf_amount from quant_fin where jr_id=$1', array($row['jr_id']));
325 $r.='<td class="num sorttable_numeric" sorttable_customkey="'.$amount.'" style="text-align:right">'.nbm ($amount).'</td>';
326
327 $diff=bcadd($diff,$amount);
328 $tot_not_reconcilied+=$row['jr_montant'];
329 $iradio->value = $row['jr_id'];
330 $iradio->selected=false;
331 $iradio->set_attribute("amount_operation", $amount);
332 $iradio->javascript=sprintf(' onchange = "Bank_Reconciliation.update_selected(this,%s);Bank_Reconciliation.update_remain(this,%s)"',$amount,$amount);
333 if (isset($_POST['op']))
334 {
335 $a_operation=$http->post("op");
337 for ($x=0;$x<$nb_operation;$x++)
338 {
339 if ($row['jr_id']==$a_operation[$x])
340 {
341 $iradio->selected=true;
344 break;
345 }
346 }
347 }
348 $r.=td(HtmlInput::hidden('jrid['.$i.']', $row['jr_id']) . $iradio->input(), 'sorttable_customkey="1" style="text-align:center" ');
349 if ($i % 2 == 0)
350 echo tr($r, ' class="odd" ');
351 else
352 echo tr($r,' class="even" ');
353}
354echo '</table>';
355
357$bk_card->id = $Ledger->get_bank();
358$filter_year = " j_tech_per in (select p_id from parm_periode where p_exercice='" . $g_user->get_exercice() . "')";
359
360/* get saldo for not reconcilied operations */
361$saldo_not_reconcilied = $bk_card->get_solde_detail($filter_year . " and j_grpt in (select jr_grpt_id from jrn where trim(jr_pj_number) ='' or jr_pj_number is null)");
362
363/* get saldo for reconcilied operation */
364$saldo_reconcilied = $bk_card->get_solde_detail($filter_year . " and j_grpt in (select jr_grpt_id from jrn where trim(jr_pj_number) != '' and jr_pj_number is not null)");
365
366/* solde compte */
367$saldo = $bk_card->get_solde_detail($filter_year);
368echo '<div style="float:right;margin-right:100px;font-size:120%;font-weight:bolder">';
369echo '<table id="total_div_id">';
370echo '
371 <tr>
372 <td>'._('Différence relevé').'</td>
373 <td id="delta_amount" class="num" >'.$delta.'</td>
374 </tr>
375 <tr>
376 <td>'._('Montant sélectionné').'</td>
377 <td class="num" id="selected_amount">'.$selected_amount.'</td>
378 </tr>
379 <tr>
380 <td>'._('Reste à selectionner').'</td>
381 <td class="num" id="remain_amount">'.$remain_amount.'</td>
382 </tr>
383
384';
385echo '</table>';
386echo '</div>';
387echo '<table>';
388echo '<tr>';
389echo td("Solde compte ");
390echo td(nbm(bcsub($saldo['debit'] , $saldo['credit'])), ' style="text-align:right"');
391echo '</tr>';
392
393echo '<tr>';
394echo td("Solde non rapproché ");
395echo td(nbm (bcsub($saldo_not_reconcilied['debit'], $saldo_not_reconcilied['credit'])), ' style="text-align:right"');
396echo '</tr>';
397
398echo '<tr>';
399echo td("Solde rapproché ");
400echo td(nbm(bcsub($saldo_reconcilied['debit'] , $saldo_reconcilied['credit'])), ' style="text-align:right"');
401echo '</tr>';
402
403
404echo '<tr>';
405echo td("Total montant ");
406echo td(nbm ($tot_not_reconcilied), ' style="text-align:right"');
407echo '</tr>';
408
409echo '</table>';
410
411$receipt=new IFile('file_receipt');
412echo _("Pièce justificative"),"&nbsp;" ,
413 $receipt->input();
414echo '<p class="text-align:center">';
415echo HtmlInput::submit('save', 'Mettre à jour le n° de relevé bancaire');
416echo '</p>';
417echo '</form>';
418echo '</div>';
419if ( count($operation) >0) {
420 echo <<<EOF
421 <script>
422 (function () {Bank_Reconciliation.activate_checkbox_range('operation_ck');})()
423 </script>
424EOF;
425}
426return;
427?>
428
isNumber($p_int)
Definition: ac_common.php:215
th($p_string, $p_extra='', $raw='')
Definition: ac_common.php:58
hb($p_string)
Definition: ac_common.php:53
echo_warning($p_string)
warns
Definition: ac_common.php:589
NoAccess($js=1)
Echo no access and stop.
Definition: ac_common.php:480
tr($p_string, $p_extra='')
Definition: ac_common.php:88
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
nbm($p_number, $p_dec=2)
format the number with a sep.
Definition: ac_common.php:137
alert($p_msg, $buffer=false)
alert in javascript
Definition: ac_common.php:738
global $g_user
if no group available , then stop
$select selected
h( $row[ 'oa_description'])
$anc_grandlivre from
$_REQUEST['ac']
$_GET['qcode']
the class Acc_Ledger_Fin inherits from Acc_Ledger, this object permit to manage the financial ledger
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Definition: fiche.class.php:38
static detail_op($p_jr_id, $p_mesg)
return a string containing the html code for calling the modifyOperation
static filter_table($p_table_id, $p_col, $start_row)
filter the rows in a table and keep the colored row in alternance
static hidden($p_name, $p_value, $p_id="")
static get_to_hidden($array)
transform $_GET data to hidden
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
Html Input.
Html Input.
Html Input for uploading file, must be in a form with enctype="multipart/form-data".
Definition: ifile.class.php:31
This class handles only the numeric input, the input will call a javascript to change comma to period...
Definition: inum.class.php:42
Html Input.
Definition: itext.class.php:30
static infobulle($p_comment)
Display a info in a bubble, text is in message_javascript.
$selected_amount
global $g_failed
$tot_not_reconcilied
global $http
if(isset($_GET["p_jrn"]) && $jrn_priv=="X") $end_extrait
$saldo_reconcilied
$saldo_not_reconcilied
$iextrait value
global $g_succeed
$_POST['ac']
Definition: do.php:310
for($e=0; $e< count($afiche); $e++) exit
$nb_operation