noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
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 if ( window.getComputedStyle(aName[x].parentNode.parentNode).display == "none" ) { continue; }
78 aName[x].checked = check;
79 if( x < end && x > from ) {
80 Bank_Reconciliation.update_selected(aName[x],aName[x].getAttribute('amount_operation'));
81 Bank_Reconciliation.update_remain(aName[x],aName[x].getAttribute('amount_operation'));
82 }
83 }
84 },
85
86
87 update_selected:function (p_node,p_amount) {
88
89 p_amount=parseFloat(p_amount);
90 try {
91 if (p_node.checked )
92 {
93 var selected=parseFloat($('selected_amount').innerHTML)+p_amount;
94 $('selected_amount').innerHTML=Math.round(selected*100)/100;
95 } else {
96 var selected=parseFloat($('selected_amount').innerHTML)-p_amount;
97 $('selected_amount').innerHTML=Math.round(selected*100)/100;
98
99 }
100 } catch(e) {
101 if (console) {console.error('Bank_Reconciliation.update_selected :'+e.message);}
102 }
103 },
104 update_remain:function (p_node,p_amount) {
105 p_amount=parseFloat(p_amount);
106 try {
107 if ( parseFloat($('delta_amount').innerHTML) == 0) return;
108 if (p_node.checked )
109 {
110 var selected=parseFloat($('remain_amount').innerHTML)-p_amount;
111 $('remain_amount').innerHTML=Math.round(selected*100)/100;
112 } else {
113 var selected=parseFloat($('remain_amount').innerHTML)+p_amount;
114 $('remain_amount').innerHTML=Math.round(selected*100)/100;
115
116 }
117 } catch(e) {
118 if (console) {console.error('Bank_Reconciliation.update_remain :'+e.message);}
119
120 }
121 },
122 update_delta:function () {
123 try {
124 var delta=parseFloat($('end_extrait').value)-parseFloat($('start_extrait').value);
125 delta=Math.round(delta*100)/100;
126 $('delta_amount').innerHTML=delta;
127 var remain=delta-parseFloat($('selected_amount').innerHTML);
128 $('remain_amount').innerHTML=Math.round(remain*100)/100;
129 } catch(e) {
130 if (console) {console.error('Bank_Reconciliation.update_delta :' +e.message);}
131 }
132 },
133 recompute:function (p_form) {
134 try {
135 var form=$(p_form);
136 var i=0;
137 for (i=0;i<form.length;i++) {
138 var e=form.elements[i];
139 if (e.type=='checkbox' && window.getComputedStyle(e.parentNode.parentNode).display != "none" )
140 {
141 e.click();
142 }
143 }
144 remove_waiting_box();
145 } catch (e) {
146 if (console) {console.error('Bank_Reconciliation.recompute :' +e.message);}
147 }
148 }
149 }
150</script>
151<?php
152echo '<div class="content">';
154if (!isset($_REQUEST['p_jrn']))
155{
156 $a = $Ledger->get_first('fin');
157 if ( isset($a['jrn_def_id'])) {
158 $Ledger->id = $a['jrn_def_id'];
159 } else {
160 $Ledger->id=0;
161 }
162}
163else
164{
165 $Ledger->id =$http->request("p_jrn","number",0);
166}
167$jrn_priv = ($Ledger->id == 0)?"X":$g_user->get_ledger_access($Ledger->id);
168if (isset($_GET["p_jrn"]) && $jrn_priv == "X")
169{
170 NoAccess();
171 return;
172}
173$end_extrait=$http->post("end_extrait", "string",0);
174$start_extrait=$http->post("start_extrait","string", 0);
175if ( isNumber($end_extrait) == 0 )
176{
177 echo '<span class="notice">';
178 echo _('Donnée invalide');
179 echo '</span>';
180 $end_extrait=0;
181}
182if ( isNumber($start_extrait) == 0 )
183{
184 echo '<span class="notice">';
185 echo _('Donnée invalide');
186 echo '</span>';
188}
189//-------------------------
190// save
191//-------------------------
192if (isset($_POST['save']))
193{
194 $receipt_nb=$http->post("ext");
195 if (trim($receipt_nb) == '' && isset($_POST['op'])) {
196 echo_warning(_('Numéro de relevé est obligatoire'));
197 }
198 if (trim($receipt_nb) != '' && isset($_POST['op']))
199 {
200 $array = $_POST['op'];
201 $tot = 0;
202 $cn->start();
203 for ($i = 0; $i < count($array); $i++)
204 {
205 $cn->exec_sql('update jrn set jr_pj_number=$1 where jr_id=$2', array($_POST['ext'], $array[$i]));
206 $tot = bcadd($tot, $cn->get_value('select qf_amount from quant_fin where jr_id=$1', array($array[$i])));
207 }
209 if ($diff != 0 && $diff != $tot)
210 {
211 $remain=bcsub($tot,$diff);
212 $cn->rollback();
213 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");
214 echo '<div class="error">';
215 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>';
216 /* if file : warning that file is not uploaded*/
217 echo '<p>'.
218 _('Attention : Fichier non chargé').
219 '</p>';
220 echo '</div>';
221 }
222 else
223 {
224 echo '<div class="content">'.$g_succeed.' Mise à jour extrait '.$_POST['ext'].'</div>';
225 // -- chargement fichier
226 $oid=$cn->upload('file_receipt',true);
227
228 if ( $oid != false ) {
229 for ($i = 0; $i < count($array); $i++)
230 {
231 $cn->exec_sql("update jrn set jr_pj=$1 , jr_pj_name=$2,
232 jr_pj_type=$3 where jr_id=$4",
233 array($oid,$_FILES['file_receipt']['name'] ,$_FILES['file_receipt']['type'],$array[$i]));
234 }
235 }
236 }
237
238 $cn->commit();
239 }
240}
241//-------------------------
242// show the operation of this ledger
243// without receipt number
244//-------------------------
245echo '<div class="content">';
246echo '<form method="get">';
247echo HtmlInput::get_to_hidden(array('gDossier', 'ledger_type', 'ac', 'sa'));
248$wLedger = $Ledger->select_ledger('FIN', 3,FALSE);
249if ($wLedger == null)
250 exit('Pas de journal disponible');
251echo '<div id="jrn_name_div">';
252echo '<h1 id="jrn_name" style="display:inline">' . $Ledger->get_name() . '</h1>';
253echo '</div>';
254$wLedger->javascript = "onchange='this.form.submit()';";
255echo $wLedger->input();
256echo HtmlInput::submit('ref', 'Rafraîchir');
257echo '</form>';
258echo '<span id="bkname" style="display:block">' . hb(h($Ledger->get_bank_name())) . '</span>';
259
260echo '<form method="post" id="rec1" enctype="multipart/form-data">';
261
262echo dossier::hidden();
263echo HtmlInput::get_to_hidden(array('sa', 'p_action', 'p_jrn'));
264
265$operation = $cn->get_array("select jr_id,jr_internal,
266 jr_comment,
267 to_char(jr_date,'DD.MM.YYYY') as fmt_date,
268 jr_montant,
269 to_char(jr_date,'YYYYMMDD') as raw_date
270 from jrn where jr_def_id=$1 and (jr_pj_number is null or jr_pj_number='') order by jr_date", array($Ledger->id));
271
272echo '<p>';
273$iextrait = new IText('ext');
274 $iextrait->value=$http->post('ext','string','');
275
276$nstart_extrait = new INum('start_extrait');
278$nstart_extrait->javascript='onchange="format_number(this,2);Bank_Reconciliation.update_delta();"';
279
280$nend_extrait = new INum('end_extrait');
282$nend_extrait->javascript='onchange="format_number(this,2);Bank_Reconciliation.update_delta();"';
283
284echo _("Extrait / relevé :") . $iextrait->input();
285echo _('solde Début') . $nstart_extrait->input();
286echo _('solde Fin') . $nend_extrait->input();
287$take_end=new IButton('select_all');
288$take_end->label=_('Reprendre le solde de fin');
289$take_end->javascript="document.getElementById('start_extrait').value=document.getElementById('end_extrait').value;document.getElementById('end_extrait').focus()";
290echo $take_end->input();
291echo '</p>';
292echo '<p>';
293echo _('Cherche').Icon_Action::infobulle(25);
294echo HtmlInput::filter_table("t_rec_bk", "0,1,2,3","1");
295echo '</p>';
296echo HtmlInput::submit('save', 'Mettre à jour le n° de relevé bancaire');
297echo '<span style="display:block">';
298 echo '</span>';
299$select_all=new IButton('select_all');
300$select_all->label=_('Inverser la sélection');
301$select_all->javascript="Bank_Reconciliation.recompute('rec1')";
302echo '<table id="t_rec_bk" class="sortable" style="width:90%;margin-left:5%">';
303
304$r ='<th class=" sorttable_sorted">'.'Date '.Icon_Action::infobulle(17).'</th>';
305$r.=th('Libellé');
306$r.=th('N° interne');
307$r.=th('Montant', ' style="text-align:right"');
308$r.='<th class="sorttable_nosort" style="text-align:center">'.$select_all->input().'</th>';
309echo tr($r);
310
316for ($i = 0; $i < count($operation); $i++)
317{
318 $iradio = new ICheckBox('op[]');
319 $iradio->set_range("operation_ck");
320 $row = $operation[$i];
321 $r = '';
322 $js = HtmlInput::detail_op($row['jr_id'], $row['jr_internal']);
323 $r.='<td sorttable_customkey="'.$row['raw_date'].'">'.$row['fmt_date'].'</td>';
324 $r.=td($row['jr_comment']);
325 $r.=td($js);
326 $amount=$cn->get_value('select qf_amount from quant_fin where jr_id=$1', array($row['jr_id']));
327 $r.='<td class="num sorttable_numeric" sorttable_customkey="'.$amount.'" style="text-align:right">'.nbm ($amount).'</td>';
328
329 $diff=bcadd($diff,$amount);
330 $tot_not_reconcilied+=$row['jr_montant'];
331 $iradio->value = $row['jr_id'];
332 $iradio->selected=false;
333 $iradio->set_attribute("amount_operation", $amount);
334 $iradio->javascript=sprintf(' onchange = "Bank_Reconciliation.update_selected(this,%s);Bank_Reconciliation.update_remain(this,%s)"',$amount,$amount);
335 if (isset($_POST['op']))
336 {
337 $a_operation=$http->post("op");
339 for ($x=0;$x<$nb_operation;$x++)
340 {
341 if ($row['jr_id']==$a_operation[$x])
342 {
343 $iradio->selected=true;
346 break;
347 }
348 }
349 }
350 $r.=td(HtmlInput::hidden('jrid['.$i.']', $row['jr_id']) . $iradio->input(), 'sorttable_customkey="1" style="text-align:center" ');
351 if ($i % 2 == 0)
352 echo tr($r, ' class="odd" ');
353 else
354 echo tr($r,' class="even" ');
355}
356echo '</table>';
357
359$bk_card->id = $Ledger->get_bank();
360$filter_year = " j_tech_per in (select p_id from parm_periode where p_exercice='" . $g_user->get_exercice() . "')";
361
362/* get saldo for not reconcilied operations */
363$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)");
364
365/* get saldo for reconcilied operation */
366$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)");
367
368/* solde compte */
369$saldo = $bk_card->get_solde_detail($filter_year);
370echo '<div style="float:right;margin-right:100px;font-size:120%;font-weight:bolder">';
371echo '<table id="total_div_id">';
372echo '
373 <tr>
374 <td>'._('Différence relevé').'</td>
375 <td id="delta_amount" class="num" >'.$delta.'</td>
376 </tr>
377 <tr>
378 <td>'._('Montant sélectionné').'</td>
379 <td class="num" id="selected_amount">'.$selected_amount.'</td>
380 </tr>
381 <tr>
382 <td>'._('Reste à selectionner').'</td>
383 <td class="num" id="remain_amount">'.$remain_amount.'</td>
384 </tr>
385
386';
387echo '</table>';
388echo '</div>';
389echo '<table>';
390echo '<tr>';
391echo td("Solde compte ");
392echo td(nbm(bcsub($saldo['debit'] , $saldo['credit'])), ' style="text-align:right"');
393echo '</tr>';
394
395echo '<tr>';
396echo td("Solde non rapproché ");
397echo td(nbm (bcsub($saldo_not_reconcilied['debit'], $saldo_not_reconcilied['credit'])), ' style="text-align:right"');
398echo '</tr>';
399
400echo '<tr>';
401echo td("Solde rapproché ");
402echo td(nbm(bcsub($saldo_reconcilied['debit'] , $saldo_reconcilied['credit'])), ' style="text-align:right"');
403echo '</tr>';
404
405
406echo '<tr>';
407echo td("Total montant ");
408echo td(nbm ($tot_not_reconcilied), ' style="text-align:right"');
409echo '</tr>';
410
411echo '</table>';
412
413$receipt=new IFile('file_receipt');
414echo _("Pièce justificative"),"&nbsp;" ,
415 $receipt->input();
416echo '<p class="text-align:center">';
417echo HtmlInput::submit('save', 'Mettre à jour le n° de relevé bancaire');
418echo '</p>';
419echo '</form>';
420echo '</div>';
421if ( count($operation) >0) {
422 echo <<<EOF
423 <script>
424 (function () {Bank_Reconciliation.activate_checkbox_range('operation_ck');})()
425 </script>
426EOF;
427}
428return;
429?>
430
isNumber($p_int)
th($p_string, $p_extra='', $raw='')
Definition ac_common.php:58
hb($p_string)
Definition ac_common.php:53
echo_warning($p_string)
warns
NoAccess($js=1)
Echo no access and stop.
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.
alert($p_msg, $buffer=false)
alert in javascript
global $g_user
if no group available , then stop
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$select selected
h( $row[ 'oa_description'])
foreach(array( 'l', 'gDossier') as $a) if(is_numeric($l)==false) $Ledger
$anc_grandlivre from
$_REQUEST['ac']
$input_from id
_("actif, passif,charge,...")
$_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...
static get_to_hidden($array)
transform $_GET data to hidden
Html Input.
Html Input.
Html Input for uploading file, must be in a form with enctype="multipart/form-data".
This class handles only the numeric input, the input will call a javascript to change comma to period...
Html Input Text member :
static infobulle($p_comment)
Display a info in a bubble, text is in message_javascript.
$jrn_priv
global $g_failed
$tot_not_reconcilied
if(isset($_GET["p_jrn"]) && $jrn_priv=="X") $end_extrait
$saldo_not_reconcilied
global $g_succeed
$_POST['ac']
Definition do.php:323
for($e=0; $e< count($afiche); $e++) exit
$nb_operation