47 with total_operation as (
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
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)
56), all_operation as (select jr_id,jra_concerned from jrn_rapt union select jra_concerned,jr_id from jrn_rapt)
58 select j_id,qf_other tiers_id from quant_fin
60 select j_id,qs_client from quant_sold qs
62 select j_id,qp_supplier from quant_purchase
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
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
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 )
106order by jr1.jr_date,jr1.jr_id
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
121join depend_op bs1 on (bo1.jr1_jr_id = bs1.jr1_jr_id)
140 $wConcerned->extra = 0;
156 if (trim($jr_id2) ==
"")
158 if (strpos($jr_id2,
',') !== 0) {
159 $aRapt = explode(
',', $jr_id2);
160 foreach ($aRapt as $rRapt) {
185 if ($this->
jr_id == $jr_id2)
188 if ($this->
db->count_sql(
"select jr_id from jrn where jr_id=$1" ,[ $this->jr_id]) == 0)
190 if ($this->
db->count_sql(
"select jr_id from jrn where jr_id=$1",[$jr_id2]) == 0)
194 if ($this->
db->count_sql(
195 "select jra_id from jrn_rapt where jra_concerned=$1
198 select jra_id from jrn_rapt where jr_id= $1
199 and jra_concerned=$2 " ,[$this->jr_id,$jr_id2]) == 0) {
201 $Res = $this->
db->exec_sql(
"insert into jrn_rapt(jr_id,jra_concerned) values ($1,$2)",
202 array($this->
jr_id, $jr_id2)
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')) {
212 $date = $this->
db->get_value(
'select jr_date from jrn where jr_id=$1', array($jr_id2));
213 if (trim(
$date) ==
'')
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));
217 if (($source_type !=
'A' && $source_type !=
'V') && ($dest_type ==
'A' || $dest_type ==
'V')) {
219 $date = $this->
db->get_value(
'select jr_date from jrn where jr_id=$1', array($this->
jr_id));
220 if (trim(
$date) ==
'')
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));
234 $sql =
"select j1.f_id as fiche ,coalesce(j1.j_id,-1) as jrnx_id1,coalesce(j2.j_id,-1) as jrnx_id2,
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)
268 function remove($jr_id2) {
274 if ($this->
db->count_sql(
"select jra_id from jrn_rapt where " .
275 " jra_concerned=" . $this->jr_id .
" and jr_id=$jr_id2
277 select jra_id from jrn_rapt where jra_concerned=$jr_id2 " .
278 " and jr_id=" . $this->jr_id) != 0) {
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)
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))
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))
300 $this->
db->exec_sql(
$sql, array($jr_id2, $this->
jr_id));
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]);
318 $sql =
" select jr_id as cn from jrn_rapt where jra_concerned=$1
320 select jra_concerned as cn from jrn_rapt where jr_id=$2";
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)
361 with total_operation as (
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
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)
371 select j_id,qf_other tiers_id from quant_fin
373 select j_id,qs_client from quant_sold qs
375 select j_id,qp_supplier from quant_purchase
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
391 ,null str_jr2_jr_date
393 ,null jr2_jr_internal
396 ,null jr2_jr_pj_number
398 ,null jrn2_jrn_def_name
399 ,null jrn2_jrn_def_type
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
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 )
410 and jr1.jr_id not in (select jr_id from jrn_rapt
411 union select jra_concerned from jrn_rapt)
432 if (!empty($this->
a_jrn) && is_array($this->
a_jrn)) {
434 $r =
'and jr_def_id in (';
454 $filter_date = str_replace(
"jr_date",
"jr1.jr_date", $this->
filter_date());
458 $sql_jrn1 = str_replace(
"jr_def_id",
"jr1.jr_def_id", $sql_jrn);
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);
470 $this->
db->exec_sql(
" create temporary table temp_total_operation as $sql_string");
472 }
catch (Exception $exc) {
473 echo $exc->getMessage();
492 $a_row = $this->
db->get_array(
"$sql_amount order by jr1_jr_date");
513 $sql_amount = $sql_amount .
" where bs1.depend_sum_amount = to1_sum_amount ";
515 $sql_amount = $sql_amount .
" where bs1.depend_sum_amount != to1_sum_amount";
517 $a_row = $this->
db->get_array(
"$sql_amount order by jr1_jr_date");
538 $sql =
" (jr_date >= to_date('" . $this->
start_day .
"','DD.MM.YYYY')
539 and jr_date <= to_date('" . $this->
end_day .
"','DD.MM.YYYY'))";
549 echo
'<td colspan="5" style="border:1px solid black;width:auto">';
550 include NOALYSS_TEMPLATE .
'/impress_reconciliation_detail.php';
599 if (
$array[
$i][
'depend_count']>0) {
601 from temp_total_operation
603 jr1_jr_id=$1 and ra1_jra_concerned != jr1_jr_id"
607 for (
$e = 0;
$e < $nb_depend ;
$e++) {
609 $totdepend=bcadd($totdepend,
$x,2);
624 $export->add($totdepend,
"number");
659 echo
"Choix invalid";
660 throw new Exception(
"invalide");
669 $this->
db->prepare(
'detail_quant',
'select * from v_quant_detail where jr_id=$1');
691 $retdb = $this->
db->execute(
"detail_quant", array($p_jrn_id));
693 if ($nb_record > 0) {
694 $total_price = $first_amount = 0;
695 for (
$i = 0;
$i < $nb_record;
$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);
706 $first_amount = $p_default_amount;
708 return $first_amount;
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();
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
_("actif, passif,charge,...")
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
prepare_query_detail_quant()
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
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.
$acc_reconciliation end_day
$acc_reconciliation start_day
$acc_reconciliation a_jrn