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)
59 ,ra1.jra_concerned ra1_jra_concerned
60 ,jr1.jr_date jr1_jr_date
61 ,to_char(jr1.jr_date,'DD.MM.YY') as str_jr1_jr_date
62 ,jr1.jr_comment jr1_jr_comment
63 ,jr1.jr_internal jr1_jr_internal
64 ,jr1.jr_montant jr1_jr_montant
65 ,case when to1.sum_amount=0 then jr1.jr_montant else to1.sum_amount end to1_sum_amount
66 ,jr1.jr_pj_number jr1_jr_pj_number
67 ,jr1.jr_def_id jr1_jr_def_id
68 ,jrn1.jrn_def_name jrn1_jrn_def_name
69 ,jrn1.jrn_def_type jrn1_jrn_def_type
70 ,jr2.jr_date jr2_jr_date
71 ,to_char(jr2.jr_date,'DD.MM.YY') as str_jr2_jr_date
72 ,jr2.jr_comment jr2_jr_comment
73 ,jr2.jr_internal jr2_jr_internal
74 ,jr2.jr_montant jr2_jr_montant
75 ,to2.sum_amount to2_sum_amount
76 ,jr2.jr_pj_number jr2_jr_pj_number
77 ,jr2.jr_def_id jr2_jr_def_id
78 ,jrn2.jrn_def_name jrn2_jrn_def_name
79 ,jrn2.jrn_def_type jrn2_jrn_def_type
81join total_operation to1 on (to1.jr_id=jr1.jr_id)
82join jrn_def jrn1 on (jrn1.jrn_def_id=jr1.jr_def_id)
83join all_operation ra1 on (ra1.jra_concerned=jr1.jr_id or ra1.jr_id=jr1.jr_id)
84join jrn jr2 on (ra1.jra_concerned =jr2.jr_id)
85join total_operation to2 on (to2.jr_id=jr2.jr_id)
86join jrn_def jrn2 on (jrn2.jrn_def_id=jr2.jr_def_id)
91order by jr1.jr_date,jr1.jr_id
95with base_op as (select *
96 from temp_total_operation tm1
97 where tm1.jr1_jr_id = tm1.ra1_jra_concerned )
98, depend_op as (select jr1_jr_id
99 , sum(case when to2_sum_amount != 0 then to2_sum_amount else jr2_jr_montant end) depend_sum_amount
100 ,count(*) depend_count
101 from temp_total_operation tm1
102 where tm1.jr1_jr_id != tm1.ra1_jra_concerned
106join depend_op bs1 on (bo1.jr1_jr_id = bs1.jr1_jr_id)
125 $wConcerned->extra = 0;
141 if (trim($jr_id2) ==
"")
143 if (strpos($jr_id2,
',') !== 0) {
144 $aRapt = explode(
',', $jr_id2);
145 foreach ($aRapt as $rRapt) {
170 if ($this->
jr_id == $jr_id2)
173 if ($this->
db->count_sql(
"select jr_id from jrn where jr_id=$1" ,[ $this->jr_id]) == 0)
175 if ($this->
db->count_sql(
"select jr_id from jrn where jr_id=$1",[$jr_id2]) == 0)
179 if ($this->
db->count_sql(
180 "select jra_id from jrn_rapt where jra_concerned=$1
183 select jra_id from jrn_rapt where jr_id= $1
184 and jra_concerned=$2 " ,[$this->jr_id,$jr_id2]) == 0) {
186 $Res = $this->
db->exec_sql(
"insert into jrn_rapt(jr_id,jra_concerned) values ($1,$2)",
187 array($this->
jr_id, $jr_id2)
193 $source_type = $this->
db->get_value(
"select substr(jr_internal,1,1) from jrn where jr_id=$1", array($this->
jr_id));
194 $dest_type = $this->
db->get_value(
"select substr(jr_internal,1,1) from jrn where jr_id=$1", array($jr_id2));
195 if (($source_type ==
'A' || $source_type ==
'V') && ($dest_type !=
'A' && $dest_type !=
'V')) {
197 $date = $this->
db->get_value(
'select jr_date from jrn where jr_id=$1', array($jr_id2));
198 if (trim(
$date) ==
'')
200 $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));
202 if (($source_type !=
'A' && $source_type !=
'V') && ($dest_type ==
'A' || $dest_type ==
'V')) {
204 $date = $this->
db->get_value(
'select jr_date from jrn where jr_id=$1', array($this->
jr_id));
205 if (trim(
$date) ==
'')
207 $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));
219 $sql =
"select j1.f_id as fiche ,coalesce(j1.j_id,-1) as jrnx_id1,coalesce(j2.j_id,-1) as jrnx_id2,
222 join jrn as jr1 on (j1.j_grpt=jr1.jr_grpt_id)
223 join jrnx as j2 on (coalesce(j1.f_id,-1)=coalesce(j2.f_id,-1) and j1.j_poste=j2.j_poste)
224 join jrn as jr2 on (j2.j_grpt=jr2.jr_grpt_id)
253 function remove($jr_id2) {
259 if ($this->
db->count_sql(
"select jra_id from jrn_rapt where " .
260 " jra_concerned=" . $this->jr_id .
" and jr_id=$jr_id2
262 select jra_id from jrn_rapt where jra_concerned=$jr_id2 " .
263 " and jr_id=" . $this->jr_id) != 0) {
270where jl_id in ( select jl_id from jnt_letter
271 join letter_cred as lc using(jl_id)
272 join letter_deb as ld using (jl_id)
274 lc.j_id in (select j_id
275 from jrnx join jrn on (j_grpt=jr_grpt_id)
276 where jr_id in ($1,$2))
278 ld.j_id in (select j_id
279 from jrnx join jrn on (j_grpt=jr_grpt_id)
280 where jr_id in ($1,$2))
285 $this->
db->exec_sql(
$sql, array($jr_id2, $this->
jr_id));
287 $Res = $this->
db->exec_sql(
"delete from jrn_rapt where
288 (jra_concerned=$1 and jr_id= $2) or
289 (jra_concerned=$2 and jr_id=$1) ",
290 [$jr_id2,$this->
jr_id]);
303 $sql =
" select jr_id as cn from jrn_rapt where jra_concerned=$1
305 select jra_concerned as cn from jrn_rapt where jr_id=$2";
328 $sql =
"select jr_id,jr_date,jr_comment,jr_internal,jr_montant,jr_pj_number,jr_def_id,jrn_def_name,jrn_def_type
329 from jrn join jrn_def on (jrn_def_id=jr_def_id)
348 ,null ra1_jra_concerned
349 ,jr1.jr_date jr1_jr_date
350 ,to_char(jr1.jr_date,'DD.MM.YY') as str_jr1_jr_date
351 ,jr1.jr_comment jr1_jr_comment
352 ,jr1.jr_internal jr1_jr_internal
353 ,jr1.jr_montant jr1_jr_montant
354 ,jr1.jr_montant to1_sum_amount
355 ,jr1.jr_pj_number jr1_jr_pj_number
356 ,jr1.jr_def_id jr1_jr_def_id
357 ,jrn1.jrn_def_name jrn1_jrn_def_name
358 ,jrn1.jrn_def_type jrn1_jrn_def_type
360 ,null str_jr2_jr_date
362 ,null jr2_jr_internal
365 ,null jr2_jr_pj_number
367 ,null jrn2_jrn_def_name
368 ,null jrn2_jrn_def_type
371join jrn_def jrn1 on (jrn1.jrn_def_id=jr1.jr_def_id)
375 and jr1.jr_id not in (select jr_id from jrn_rapt
376 union select jra_concerned from jrn_rapt)
397 if (!empty($this->
a_jrn) && is_array($this->
a_jrn)) {
399 $r =
'and jr_def_id in (';
419 $filter_date = str_replace(
"jr_date",
"jr1.jr_date", $this->
filter_date());
423 $sql_jrn1 = str_replace(
"jr_def_id",
"jr1.jr_def_id", $sql_jrn);
430 $sql_string = str_replace(
"FILTER_DATE", $filter_date, $sql_string);
431 $sql_string = str_replace(
"LEDGER_FILTER1", $sql_jrn1, $sql_string);
432 $sql_string = str_replace(
"LEDGER_FILTER2", $sql_jrn2, $sql_string);
435 $this->
db->exec_sql(
" create temporary table temp_total_operation as $sql_string");
437 }
catch (Exception $exc) {
438 echo $exc->getMessage();
457 $a_row = $this->
db->get_array(
"$sql_amount order by jr1_jr_date");
478 $sql_amount = $sql_amount .
" where bs1.depend_sum_amount = to1_sum_amount ";
480 $sql_amount = $sql_amount .
" where bs1.depend_sum_amount != to1_sum_amount";
482 $a_row = $this->
db->get_array(
"$sql_amount order by jr1_jr_date");
503 $sql =
" (jr_date >= to_date('" . $this->
start_day .
"','DD.MM.YYYY')
504 and jr_date <= to_date('" . $this->
end_day .
"','DD.MM.YYYY'))";
514 echo
'<td colspan="5" style="border:1px solid black;width:auto">';
515 include NOALYSS_TEMPLATE .
'/impress_reconciliation_detail.php';
560 if (
$array[
$i][
'depend_count']>0) {
562 from temp_total_operation
564 jr1_jr_id=$1 and ra1_jra_concerned != jr1_jr_id"
568 for (
$e = 0;
$e < $nb_depend ;
$e++) {
570 $totdepend=bcadd($totdepend,$x,2);
583 $export->add($totdepend,
"number");
618 echo
"Choix invalid";
619 throw new Exception(
"invalide");
628 $this->
db->prepare(
'detail_quant',
'select * from v_quant_detail where jr_id=$1');
650 $retdb = $this->
db->execute(
"detail_quant", array($p_jrn_id));
652 if ($nb_record > 0) {
653 $total_price = $first_amount = 0;
654 for (
$i = 0;
$i < $nb_record;
$i++) {
657 $total_price = bcadd(
$row[
'price'],
$row[
'vat_amount']);
658 $total_price = bcsub($total_price,
$row[
'vat_sided']);
659 $total_price = bcadd($total_price,
$row[
'nd_tva']);
660 $total_price = bcadd($total_price,
$row[
'nd_tva_recup']);
661 $first_amount = bcadd($total_price, $first_amount);
665 $first_amount = $p_default_amount;
667 return $first_amount;
671 $cn = Dossier::connect();
673 var_dump(
$rap->get_reconciled_amount(
false));
674 $rap->build_temp_total_operation();
675 $rap->build_temp_total_operation();
676 $rap->build_temp_total_operation();
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