noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
acc_reconciliation.class.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/**
24 * \file
25 * \brief class acc_reconciliation, this class is new and the code
26 * must use it
27 *
28 */
29
30/**
31 * \brief new class for managing the reconciliation it must be used
32 * instead of the function InsertRapt, ...
33 *
34 */
36
37 var $db; /*!< database connection */
38 var $jr_id; /*!< jr_id */
39 var $a_jrn; /*!< $a_jrn array of ledgers id (JRN_DEF.JRN_DEF_ID) */
40 var $start_day; /*!< $start_day (text DD.MM.YYYY) first day */
41 var $end_day;/*!< $end_day (text DD.MM.YYYY) last day */
42
43 /**
44 * query for building the temporary table TEMP_TOTAL_OPERATION
45 */
47 with total_operation as (
48 select
49 jn2.jr_id,coalesce(sum(qs_price+qs_vat-qs_vat_sided),0)+coalesce(sum(qp_price+qp_vat-qp_vat_sided+qp.qp_nd_tva + qp.qp_nd_tva_recup),0) sum_amount
50 from
51 jrnx jx1
52 join jrn jn2 on (jn2.jr_grpt_id =jx1.j_grpt )
53 left join quant_sold qs on (jx1.j_id=qs.j_id)
54 left join quant_purchase qp on (qp.j_id =jx1.j_id)
55 group by jn2.jr_id
56), all_operation as (select jr_id,jra_concerned from jrn_rapt union select jra_concerned,jr_id from jrn_rapt)
57,tiers as (
58 select j_id,qf_other tiers_id from quant_fin
59 union
60 select j_id,qs_client from quant_sold qs
61 union
62 select j_id,qp_supplier from quant_purchase
63)
64select distinct
65 jr1.jr_id jr1_jr_id
66 ,ra1.jra_concerned ra1_jra_concerned
67 ,jr1.jr_date jr1_jr_date
68 ,to_char(jr1.jr_date,'DD.MM.YY') as str_jr1_jr_date
69 ,jr1.jr_comment jr1_jr_comment
70 ,jr1.jr_internal jr1_jr_internal
71 ,jr1.jr_montant jr1_jr_montant
72 ,case when to1.sum_amount=0 then jr1.jr_montant else to1.sum_amount end to1_sum_amount
73 ,jr1.jr_pj_number jr1_jr_pj_number
74 ,jr1.jr_def_id jr1_jr_def_id
75 ,jrn1.jrn_def_name jrn1_jrn_def_name
76 ,jrn1.jrn_def_type jrn1_jrn_def_type
77 ,jr2.jr_date jr2_jr_date
78 ,to_char(jr2.jr_date,'DD.MM.YY') as str_jr2_jr_date
79 ,jr2.jr_comment jr2_jr_comment
80 ,jr2.jr_internal jr2_jr_internal
81 ,jr2.jr_montant jr2_jr_montant
82 ,to2.sum_amount to2_sum_amount
83 ,jr2.jr_pj_number jr2_jr_pj_number
84 ,jr2.jr_def_id jr2_jr_def_id
85 ,jrn2.jrn_def_name jrn2_jrn_def_name
86 ,jrn2.jrn_def_type jrn2_jrn_def_type
87 ,t3.tiers_id
88 ,(select fd1.ad_value from fiche_detail fd1 where fd1.ad_id=1 and fd1.f_id=t3.tiers_id) as tiers_name
89 ,(select fd1.ad_value from fiche_detail fd1 where fd1.ad_id=23 and fd1.f_id=t3.tiers_id) as tiers_qcode
90 ,t5.tiers_id tiers_id_2
91 ,(select fd1.ad_value from fiche_detail fd1 where fd1.ad_id=1 and fd1.f_id=t5.tiers_id) as tiers_name_2
92 ,(select fd1.ad_value from fiche_detail fd1 where fd1.ad_id=23 and fd1.f_id=t5.tiers_id) as tiers_qcode_2
93from jrn jr1
94join total_operation to1 on (to1.jr_id=jr1.jr_id)
95join jrn_def jrn1 on (jrn1.jrn_def_id=jr1.jr_def_id)
96join all_operation ra1 on (ra1.jra_concerned=jr1.jr_id or ra1.jr_id=jr1.jr_id)
97join jrn jr2 on (ra1.jra_concerned =jr2.jr_id)
98join total_operation to2 on (to2.jr_id=jr2.jr_id)
99join jrn_def jrn2 on (jrn2.jrn_def_id=jr2.jr_def_id)
100left join (select t2.tiers_id,j2.j_grpt from tiers t2 join jrnx j2 on (t2.j_id=j2.j_id) ) as t3 on (t3.j_grpt=jr1.jr_grpt_id )
101left join (select t4.tiers_id,j2.j_grpt from tiers t4 join jrnx j2 on (t4.j_id=j2.j_id) ) as t5 on (t5.j_grpt=jr2.jr_grpt_id )
102where
103FILTER_DATE
104and LEDGER_FILTER1
105and LEDGER_FILTER2
106order by jr1.jr_date,jr1.jr_id
107 ";
108 // Get the data to display
109 const SQL_QUERY = "
110with base_op as (select *
111 from temp_total_operation tm1
112 where tm1.jr1_jr_id = tm1.ra1_jra_concerned )
113, depend_op as (select jr1_jr_id
114 , sum(case when to2_sum_amount != 0 then to2_sum_amount else jr2_jr_montant end) depend_sum_amount
115 ,count(*) depend_count
116 from temp_total_operation tm1
117 where tm1.jr1_jr_id != tm1.ra1_jra_concerned
118 group by jr1_jr_id )
119select *
120from base_op bo1
121join depend_op bs1 on (bo1.jr1_jr_id = bs1.jr1_jr_id)
122";
123
124 function __construct($cn) {
125 $this->db = $cn;
126 $this->jr_id = 0;
127 $this->a_jrn = null;
128 }
129
130 function set_jr_id($jr_id) {
131 $this->jr_id = $jr_id;
132 }
133
134 /**
135 * \brief return a widget of type js_concerned
136 */
137
138 function widget() {
139 $wConcerned = new IConcerned();
140 $wConcerned->extra = 0; // with 0 javascript search from e_amount... field (see javascript)
141
142 return $wConcerned;
143 }
144
145 /**
146 * \brief Insert into jrn_rapt the concerned operations
147 *
148 * \param $jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned or a string
149 * like "jr_id2,jr_id3,jr_id4..."
150 *
151 * \return none
152 *
153 */
154
155 function insert($jr_id2) {
156 if (trim($jr_id2) == "")
157 return;
158 if (strpos($jr_id2, ',') !== 0) {
159 $aRapt = explode(',', $jr_id2);
160 foreach ($aRapt as $rRapt) {
161 if (isNumber($rRapt) == 1) {
162 $this->insert_rapt($rRapt);
163 }
164 }
165 } else
166 if (isNumber($jr_id2) == 1) {
167 $this->insert_rapt($jr_id2);
168 }
169 }
170
171 /**
172 * \brief Insert into jrn_rapt the concerned operations
173 * should not be called directly, use insert instead
174 *
175 * \param $jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned
176 *
177 * \return none
178 *
179 */
180
181 function insert_rapt($jr_id2) {
182 if (isNumber($this->jr_id) == 0 || isNumber($jr_id2) == 0) {
183 return false;
184 }
185 if ($this->jr_id == $jr_id2)
186 return true;
187
188 if ($this->db->count_sql("select jr_id from jrn where jr_id=$1" ,[ $this->jr_id]) == 0)
189 return false;
190 if ($this->db->count_sql("select jr_id from jrn where jr_id=$1",[$jr_id2]) == 0)
191 return false;
192
193 // verify if exists
194 if ($this->db->count_sql(
195 "select jra_id from jrn_rapt where jra_concerned=$1
196 and jr_id=$2
197 union
198 select jra_id from jrn_rapt where jr_id= $1
199 and jra_concerned=$2 " ,[$this->jr_id,$jr_id2]) == 0) {
200 // Ok we can insert
201 $Res = $this->db->exec_sql("insert into jrn_rapt(jr_id,jra_concerned) values ($1,$2)",
202 array($this->jr_id, $jr_id2)
203 );
204 // try to letter automatically same account from both operation
205 $this->auto_letter($jr_id2);
206
207 // update date of paiement -----------------------------------------------------------------------
208 $source_type = $this->db->get_value("select substr(jr_internal,1,1) from jrn where jr_id=$1", array($this->jr_id));
209 $dest_type = $this->db->get_value("select substr(jr_internal,1,1) from jrn where jr_id=$1", array($jr_id2));
210 if (($source_type == 'A' || $source_type == 'V') && ($dest_type != 'A' && $dest_type != 'V')) {
211 // set the date on source
212 $date = $this->db->get_value('select jr_date from jrn where jr_id=$1', array($jr_id2));
213 if (trim($date) == '')
214 $date = null;
215 $this->db->exec_sql('update jrn set jr_date_paid=$1 where jr_id=$2 and jr_date_paid is null ', array($date, $this->jr_id));
216 }
217 if (($source_type != 'A' && $source_type != 'V') && ($dest_type == 'A' || $dest_type == 'V')) {
218 // set the date on dest
219 $date = $this->db->get_value('select jr_date from jrn where jr_id=$1', array($this->jr_id));
220 if (trim($date) == '')
221 $date = null;
222 $this->db->exec_sql('update jrn set jr_date_paid=$1 where jr_id=$2 and jr_date_paid is null ', array($date, $jr_id2));
223 }
224 }
225 return true;
226 }
227
228 /**
229 * @brief try to letter same card between $p_jrid and $this->jr_id
230 * @param jrn.jr_id $p_jrid the operation to reconcile
231 */
232 function auto_letter($p_jrid) {
233 // Try to find same card from both operation
234 $sql = "select j1.f_id as fiche ,coalesce(j1.j_id,-1) as jrnx_id1,coalesce(j2.j_id,-1) as jrnx_id2,
235j1.j_poste as poste
236 from jrnx as j1
237 join jrn as jr1 on (j1.j_grpt=jr1.jr_grpt_id)
238 join jrnx as j2 on (coalesce(j1.f_id,-1)=coalesce(j2.f_id,-1) and j1.j_poste=j2.j_poste)
239 join jrn as jr2 on (j2.j_grpt=jr2.jr_grpt_id)
240 where
241 jr1.jr_id=$1
242 and
243 jr2.jr_id= $2";
244 $result = $this->db->get_array($sql, array($this->jr_id, $p_jrid));
245 if (count($result) == 0) {
246 return;
247 }
248 for ($i = 0; $i < count($result); $i++) {
249 if ($result[$i]['fiche'] != -1) {
250 $letter = new Lettering_Card($this->db);
251 $letter->insert_couple($result[$i]['jrnx_id1'], $result[$i]['jrnx_id2']);
252 } else {
253 $letter = new Lettering_Account($this->db);
254 $letter->insert_couple($result[$i]['jrnx_id1'], $result[$i]['jrnx_id2']);
255 }
256 }
257 }
258
259 /**
260 * \brief Insert into jrn_rapt the concerned operations
261 *
262 * \param $this->jr_id (jrn.jr_id) => jrn_rapt.jr_id
263 * \param $jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned
264 *
265 * \return none
266 */
267
268 function remove($jr_id2) {
269 if (isNumber($this->jr_id) == 0 or
270 isNumber($jr_id2) == 0) {
271 return;
272 }
273 // verify if exists
274 if ($this->db->count_sql("select jra_id from jrn_rapt where " .
275 " jra_concerned=" . $this->jr_id . " and jr_id=$jr_id2
276 union
277 select jra_id from jrn_rapt where jra_concerned=$jr_id2 " .
278 " and jr_id=" . $this->jr_id) != 0) {
279 /**
280 * remove also lettering between both operation
281 */
282 $sql = "
283delete from
284 jnt_letter
285where jl_id in ( select jl_id from jnt_letter
286 join letter_cred as lc using(jl_id)
287 join letter_deb as ld using (jl_id)
288where
289 lc.j_id in (select j_id
290 from jrnx join jrn on (j_grpt=jr_grpt_id)
291 where jr_id in ($1,$2))
292 or
293 ld.j_id in (select j_id
294 from jrnx join jrn on (j_grpt=jr_grpt_id)
295 where jr_id in ($1,$2))
296
297
298
299 )";
300 $this->db->exec_sql($sql, array($jr_id2, $this->jr_id));
301 // Ok we can delete
302 $Res = $this->db->exec_sql("delete from jrn_rapt where
303 (jra_concerned=$1 and jr_id= $2) or
304 (jra_concerned=$2 and jr_id=$1) ",
305 [$jr_id2,$this->jr_id]);
306 }
307 }
308
309 /**
310 * \brief Return an array of the concerned operation
311 *
312 *
313 * \param database connection
314 * \return array if something is found or null
315 */
316
317 function get() {
318 $sql = " select jr_id as cn from jrn_rapt where jra_concerned=$1
319 union
320 select jra_concerned as cn from jrn_rapt where jr_id=$2";
321 $Res = $this->db->exec_sql($sql, array($this->jr_id, $this->jr_id));
322
323 // If nothing is found return null
325
326 if ($n == 0)
327 return [];
328
329 // put everything in an array
330 for ($i = 0; $i < $n; $i++) {
332 $r[$i] = $l['cn'];
333 }
334 return $r;
335 }
336
337 /**
338 * @deprecated since version 9307
339 * @brief retrieve row from JRN
340 * @return type
341 */
342 function fill_info() {
343 $sql = "select jr_id,jr_date,jr_comment,jr_internal,jr_montant,jr_pj_number,jr_def_id,jrn_def_name,jrn_def_type
344 from jrn join jrn_def on (jrn_def_id=jr_def_id)
345 where jr_id=$1";
346 $a = $this->db->get_array($sql, array($this->jr_id));
347 return $a[0];
348 }
349
350 /**
351 * @brief return array of not-reconciled operation
352 * Prepare and put in memory the SQL detail_quant
353 */
356 $filter_date = $this->filter_date();
357 /* create ledger filter */
358 $sql_jrn = $this->ledger_filter();
359
360 $array = $this->db->get_array("
361 with total_operation as (
362 select
363 jn2.jr_id,coalesce(sum(qs_price+qs_vat-qs_vat_sided),0)+coalesce(sum(qp_price+qp_vat-qp_vat_sided+qp.qp_nd_tva + qp.qp_nd_tva_recup),0) sum_amount
364 from
365 jrnx jx1
366 join jrn jn2 on (jn2.jr_grpt_id =jx1.j_grpt )
367 left join quant_sold qs on (jx1.j_id=qs.j_id)
368 left join quant_purchase qp on (qp.j_id =jx1.j_id)
369 group by jn2.jr_id)
370,tiers as (
371 select j_id,qf_other tiers_id from quant_fin
372 union
373 select j_id,qs_client from quant_sold qs
374 union
375 select j_id,qp_supplier from quant_purchase
376)
377 select distinct
378 jr1.jr_id jr1_jr_id
379 ,null ra1_jra_concerned
380 ,jr1.jr_date jr1_jr_date
381 ,to_char(jr1.jr_date,'DD.MM.YY') as str_jr1_jr_date
382 ,jr1.jr_comment jr1_jr_comment
383 ,jr1.jr_internal jr1_jr_internal
384 ,jr1.jr_montant jr1_jr_montant
385 ,case when to1.sum_amount=0 then jr1.jr_montant else to1.sum_amount end to1_sum_amount
386 ,jr1.jr_pj_number jr1_jr_pj_number
387 ,jr1.jr_def_id jr1_jr_def_id
388 ,jrn1.jrn_def_name jrn1_jrn_def_name
389 ,jrn1.jrn_def_type jrn1_jrn_def_type
390 ,null jr2_jr_date
391 ,null str_jr2_jr_date
392 ,null jr2_jr_comment
393 ,null jr2_jr_internal
394 ,null jr2_jr_montant
395 ,null to2_sum_amount
396 ,null jr2_jr_pj_number
397 ,null jr2_jr_def_id
398 ,null jrn2_jrn_def_name
399 ,null jrn2_jrn_def_type
400 ,0 depend_count
401 ,(select fd1.ad_value from fiche_detail fd1 where fd1.ad_id=1 and fd1.f_id=t3.tiers_id) as tiers_name
402 ,(select fd1.ad_value from fiche_detail fd1 where fd1.ad_id=23 and fd1.f_id=t3.tiers_id) as tiers_qcode
403from jrn jr1
404join total_operation to1 on (to1.jr_id=jr1.jr_id)
405join jrn_def jrn1 on (jrn1.jrn_def_id=jr1.jr_def_id)
406left join (select t2.tiers_id,j2.j_grpt from tiers t2 join jrnx j2 on (t2.j_id=j2.j_id) ) as t3 on (t3.j_grpt=jr1.jr_grpt_id )
407where
408 $filter_date
409 and $sql_jrn
410 and jr1.jr_id not in (select jr_id from jrn_rapt
411 union select jra_concerned from jrn_rapt)
412 order by jr_date
413");
414
415
416 return $array;
417 }
418
419 /**
420 * @brief Create a sql condition to filter by security and by asked ledger
421 * based on $this->a_jrn
422 * @return a valid sql stmt to include
423 * @see get_not_reconciled get_reconciled
424 */
425 function ledger_filter() {
426 global $g_user;
427 /* get the available ledgers for current user */
428 $sql = $g_user->get_ledger_sql('ALL', 3);
429 $sql = noalyss_str_replace('jrn_def_id', 'jr_def_id', $sql);
430 $r = '';
431 /* filter by this->r_jrn */
432 if (!empty($this->a_jrn) && is_array($this->a_jrn)) {
433 $sep = '';
434 $r = 'and jr_def_id in (';
435 foreach ($this->a_jrn as $key => $value) {
436 $r .= $sep . $value;
437 $sep = ',';
438 }
439 $r .= ')';
440 }
441 return $sql . ' ' . $r;
442 }
443
444 /**
445 * @brief build a temporary table with all operation + dependencies
446 * @return type
447 */
449 static $done=false;
450 if ( $done ) {
451 return;
452 }
453 global $g_user;
454 $filter_date = str_replace("jr_date", "jr1.jr_date", $this->filter_date());
455
456 /* create ledger filters */
457 $sql_jrn = $this->ledger_filter();
458 $sql_jrn1 = str_replace("jr_def_id", "jr1.jr_def_id", $sql_jrn);
459
460 /* security on the ledger */
461 $sql = $g_user->get_ledger_sql('ALL', 3);
462 $sql_jrn2 = noalyss_str_replace('jrn_def_id', 'jr2.jr_def_id', $sql);
463
465 $sql_string = str_replace("FILTER_DATE", $filter_date, $sql_string);
466 $sql_string = str_replace("LEDGER_FILTER1", $sql_jrn1, $sql_string);
467 $sql_string = str_replace("LEDGER_FILTER2", $sql_jrn2, $sql_string);
468 try {
469
470 $this->db->exec_sql(" create temporary table temp_total_operation as $sql_string");
471 $done=true;
472 } catch (Exception $exc) {
473 echo $exc->getMessage();
474 return;
475 }
476 }
477
478 /**
479 * @brief return array of reconciled operation
480 * Prepare and put in memory the SQL detail_quant
481 * @return
482 * @note
483 * @see
484 @code
485
486 @endcode
487 */
488 function get_reconciled() {
490 $sql_amount = Acc_Reconciliation::SQL_QUERY;
491
492 $a_row = $this->db->get_array("$sql_amount order by jr1_jr_date");
493 return $a_row;
494 }
495
496 /**
497 * @brief
498 * Prepare and put in memory the SQL detail_quant
499 * @param
500 * @return
501 * @note
502 * @see
503 @code
504
505 @endcode
506 */
507 function get_reconciled_amount($p_equal = false) {
508 // build temporary table temp_total_operation
510 // SQL with different amount
511 $sql_amount = Acc_Reconciliation::SQL_QUERY;
512 if ($p_equal) {
513 $sql_amount = $sql_amount . " where bs1.depend_sum_amount = to1_sum_amount ";
514 } else {
515 $sql_amount = $sql_amount . " where bs1.depend_sum_amount != to1_sum_amount";
516 }
517 $a_row = $this->db->get_array("$sql_amount order by jr1_jr_date");
518 return $a_row;
519 }
520
521 /**
522 * @brief create a string to filter thanks the date
523 * @return a sql string like jr_date > ... and jr_date < ....
524 * @note use the data member start_day and end_day
525 * @see get_reconciled get_not_reconciled
526 */
527 function filter_date() {
528 global $g_user;
529 $g_user->db=$this->db;
530 list($start, $end) = $g_user->get_limit_current_exercice();
531
532 if (isDate($this->start_day) == null) {
533 $this->start_day = $start;
534 }
535 if (isDate($this->end_day) == null) {
536 $this->end_day = $end;
537 }
538 $sql = " (jr_date >= to_date('" . $this->start_day . "','DD.MM.YYYY')
539 and jr_date <= to_date('" . $this->end_day . "','DD.MM.YYYY'))";
540 return $sql;
541 }
542 /**
543 * @deprecated since version 9307
544 */
545 function show_detail($p_ret) {
546 if (Database::num_row($p_ret) > 0) {
547 echo '<tr >';
548 echo '<td></td>';
549 echo '<td colspan="5" style="border:1px solid black;width:auto">';
550 include NOALYSS_TEMPLATE . '/impress_reconciliation_detail.php';
551 echo '</td>';
552 echo '</tr>';
553 }
554 }
555
556 /**
557 * @brief Export to CSV
558 * @param type $p_choice
559 *
560 * @note must be set before calling
561 * - $this->a_jrn array of ledger
562 * - $this->start_day start date
563 * - $this->end_day end date
564 * @see Acc_Reconciliation::get_data
565 */
566 function export_csv($p_choice) {
567 $export = new Noalyss_Csv(_('rapprochement'));
568 $export->send_header();
569
570 $array = $this->get_data($p_choice);
571 for ($i = 0; $i < count($array); $i++) {
572 if ( $i == 0)
573 {
574 $title[] = _('n°');
575 $title[] = _('Date');
576 $title[] = _('pièce');
577 $title[] = _('internal');
578 $title[] = _('Qcode');
579 $title[] = _('Nom');
580 $title[] = _('libellé');
581 $title[] = _('journal');
582 $title[] = _('type journal');
583 $title[] = _('montant');
584 $export->write_header($title);
585 }
586 $export->add($i, "number");
587 $export->add($array[$i]['str_jr1_jr_date']);
588 $export->add($array[$i]['jr1_jr_pj_number']);
589 $export->add($array[$i]['jr1_jr_internal']);
590 $export->add($array[$i]['tiers_qcode']);
591 $export->add($array[$i]['tiers_name']);
592 $export->add($array[$i]['jr1_jr_comment']);
593 $export->add($array[$i]['jrn1_jrn_def_name']);
594 $export->add($array[$i]['jrn1_jrn_def_type']);
595 $x=($array[$i]['to1_sum_amount']!=0)?$array[$i]['to1_sum_amount']:$array[$i]['jr1_jr_montant'];
596 $export->add($x, "number");
597 $export->write();
598
599 if ( $array[$i]['depend_count']>0) {
600 $depend=$this->db->get_array("select *
601 from temp_total_operation
602 where
603 jr1_jr_id=$1 and ra1_jra_concerned != jr1_jr_id"
604 ,[$array[$i]['jr1_jr_id']]);
605 $nb_depend = count($depend);
606 $totdepend=0;$delta=$x;
607 for ($e = 0; $e < $nb_depend ; $e++) {
608 $x=($depend[$e]['to2_sum_amount']!=0)?$depend[$e]['to2_sum_amount']:$depend[$e]['jr2_jr_montant'];
609 $totdepend=bcadd($totdepend,$x,2);
610 $delta=bcsub($delta,$x,2);
611 $export->add($i, "number");
612 $export->add($depend[$e]["str_jr2_jr_date"]);
613 $export->add($depend[$e]["jr2_jr_internal"]);
614 $export->add($array[$i]['tiers_name_2']);
615 $export->add($array[$i]['tiers_qcode_2']);
616 $export->add($depend[$e]["jr2_jr_pj_number"]);
617 $export->add($depend[$e]["jr2_jr_comment"]);
618 $export->add($depend[$e]['jrn2_jrn_def_name']);
619 $export->add($depend[$e]['jrn2_jrn_def_type']);
620 $export->add($x, "number");
621 $export->write();
622 }
623 $export->add("Total");
624 $export->add($totdepend,"number");
625 $export->add("Différence");
626 $export->add($delta,"number");
627 $export->write();
628
629 }
630
631
632 }
633 }
634
635 /**
636 * @brief retrieve data
637 * @param type $p_choice
638 * - 0 : operation reconcilied
639 * - 1 : reconcilied with different amount
640 * - 2 : reconcilied with same amount
641 * - 3 : not reconcilied
642 * @return $array
643 */
644 function get_data($p_choice) {
645 switch ($p_choice) {
646 case 0:
647 $array = $this->get_reconciled();
648 break;
649 case 1:
650 $array = $this->get_reconciled_amount(false);
651 break;
652 case 2:
653 $array = $this->get_reconciled_amount(true);
654 break;
655 case 3:
656 $array = $this->get_not_reconciled();
657 break;
658 default:
659 echo "Choix invalid";
660 throw new Exception("invalide");
661 }
662 return $array;
663 }
664
666 static $seen = 0;
667 if ($seen == 1)
668 return;
669 $this->db->prepare('detail_quant', 'select * from v_quant_detail where jr_id=$1');
670 // $this->db->prepare('detail_depend',' ');
671 $seen = 1;
672 }
673
674 /**
675 * @brief Retrieve the amount VAT included and autoreversed VAT excluded thanks
676 * the view v_quant_detail and return it.
677 * If the operation is not a sale or a purchase , it doesn't exist in the
678 * view then the function just returns the default amount
679 * @param type $p_jrn_id jrn.jr_id
680 * @param type $p_default_amount amount to return if not found in the view
681 * v_quant_detail
682 * @return number
683 */
684 function get_amount_noautovat($p_jrn_id, $p_default_amount) {
685 static $p = 0;
686 if ($p == 0) {
688 $p = 1;
689 }
690 bcscale(2);
691 $retdb = $this->db->execute("detail_quant", array($p_jrn_id));
692 $nb_record = Database::num_row($retdb);
693 if ($nb_record > 0) {
694 $total_price = $first_amount = 0;
695 for ($i = 0; $i < $nb_record; $i++) {
696 // then second_amount takes in account the vat_sided
697 $row = Database::fetch_array($retdb, $i);
698 $total_price = bcadd($row['price'], $row['vat_amount']);
699 $total_price = bcsub($total_price, $row['vat_sided']);
700 $total_price = bcadd($total_price, $row['nd_tva']);
701 $total_price = bcadd($total_price, $row['nd_tva_recup']);
702 $first_amount = bcadd($total_price, $first_amount);
703 }
704 } else {
705 // else take the amount from jrn
706 $first_amount = $p_default_amount;
707 }
708 return $first_amount;
709 }
710
711 static function test_me() {
712 $cn = Dossier::connect();
714 var_dump($rap->get_reconciled_amount(false));
715 $rap->build_temp_total_operation();
716 $rap->build_temp_total_operation();
717 $rap->build_temp_total_operation();
718 }
719}
isNumber($p_int)
isDate($p_date)
Verifie qu'une date est bien formaté en d.m.y et est valable.
noalyss_str_replace($search, $replace, $string)
global $g_user
if no group available , then stop
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$op jr_id
_("actif, passif,charge,...")
$p
Definition calendar.php:9
new class for managing the reconciliation it must be used instead of the function InsertRapt,...
get_amount_noautovat($p_jrn_id, $p_default_amount)
Retrieve the amount VAT included and autoreversed VAT excluded thanks the view v_quant_detail and ret...
get_data($p_choice)
retrieve data
const SQL_ALL_OPERATION_RECONCILIED
query for building the temporary table TEMP_TOTAL_OPERATION
export_csv($p_choice)
Export to CSV.
get_not_reconciled()
return array of not-reconciled operation Prepare and put in memory the SQL detail_quant
get_reconciled()
return array of reconciled operation Prepare and put in memory the SQL detail_quant
widget()
return a widget of type js_concerned
build_temp_total_operation()
build a temporary table with all operation + dependencies
get_reconciled_amount($p_equal=false)
Prepare and put in memory the SQL detail_quant.
auto_letter($p_jrid)
try to letter same card between $p_jrid and $this->jr_id
fill_info()
retrieve row from JRN
insert_rapt($jr_id2)
Insert into jrn_rapt the concerned operations should not be called directly, use insert instead.
ledger_filter()
Create a sql condition to filter by security and by asked ledger based on $this->a_jrn.
filter_date()
create a string to filter thanks the date
insert($jr_id2)
Insert into jrn_rapt the concerned operations.
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
Html Input.
only for operation retrieved thanks a account (jrnx.j_poste) manage the accounting entries for a give...
only for operation retrieved thanks a quick_code manage the accounting entries for a given card
Manage the CSV : manage files and write CSV record.
$n
Definition compute.php:54
$acc_reconciliation end_day
$acc_reconciliation start_day
$acc_reconciliation a_jrn
$SecUser db