26 require_once NOALYSS_INCLUDE.
'/lib/class_ihidden.php';
27 require_once NOALYSS_INCLUDE.
'/lib/class_database.php';
28 require_once NOALYSS_INCLUDE.
'/class/class_dossier.php';
55 if (
$Max == 0 )
return null;
56 for ($i=0;$i<
$Max;$i++)
59 if (
$array[$i][
'j_debit']==
't')
87 $Res=$this->
db->exec_sql(
"select distinct j_id,jr_id,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,j_date,".
88 "case when j_debit='t' then j_montant else 0 end as deb_montant,".
89 "case when j_debit='f' then j_montant else 0 end as cred_montant,".
90 " jr_comment as description,jrn_def_name as jrn_name,".
91 "j_debit, jr_internal,jr_pj_number ".
92 " from jrnx left join jrn_def on jrn_def_id=j_jrn_def ".
93 " left join jrn on jr_grpt_id=j_grpt".
94 " where j_poste=".$this->
id.
" and ".
$periode.
113 $filter_sql=$g_user->get_ledger_sql(
'ALL',3);
120 $sql_let=
' and j_id in (select j_id from letter_cred union select j_id from letter_deb)';
123 $sql_let=
' and j_id not in (select j_id from letter_cred union select j_id from letter_deb) ';
128 $filter=str_replace(
'jrn_def_id',
'jr_def_id',$filter_sql);
129 $bal_sql=
"select sum(amount_deb) as s_deb,sum(amount_cred) as s_cred, j_poste
130 from (select case when j_debit='t' then j_montant else 0 end as amount_deb,
131 case when j_debit='f' then j_montant else 0 end as amount_cred,
133 from jrnx join jrn on (j_grpt = jr_grpt_id)
137 ( to_date($2,'DD.MM.YYYY') <= j_date and
138 to_date($3,'DD.MM.YYYY') >= j_date )) as signed_amount
141 $r=$this->
db->get_array($bal_sql,array($this->
id,$p_from,$p_to));
142 if ( $this->
db->count() == 0 )
return array();
143 if (
$r[0][
's_deb']==
$r[0][
's_cred'])
return array();
145 $Res=$this->
db->exec_sql(
"select jr_id,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,j_date,".
146 "case when j_debit='t' then j_montant else 0 end as deb_montant,".
147 "case when j_debit='f' then j_montant else 0 end as cred_montant,".
148 " case when j_text is null or j_text = '' then jr_comment
149 else jr_comment||' '||j_text end
150 as description,jrn_def_name as jrn_name,".
151 "j_debit, jr_internal,jr_pj_number,
152 coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter ".
154 ",jr_tech_per,p_exercice,jrn_def_name,jrn_def_code".
155 " from jrnx left join jrn_def on (jrn_def_id=j_jrn_def )".
156 " left join jrn on (jr_grpt_id=j_grpt)".
157 " left join tmp_pcmn on (j_poste=pcm_val)".
158 " left join parm_periode on (p_id=jr_tech_per) ".
159 " where j_poste=$1 and ".
160 " ( to_date($2,'DD.MM.YYYY') <= j_date and ".
161 " to_date($3,'DD.MM.YYYY') >= j_date )".
162 " and $filter_sql $sql_let ".
163 " order by j_date,substring(jr_pj_number,'[0-9]+$') asc",array($this->
id,$p_from,$p_to));
175 "select pcm_lib from tmp_pcmn where
176 pcm_val=$1",array($this->
id));
180 $this->
name=
$r[
'pcm_lib'];
184 $this->
name=_(
"Poste inconnu");
193 $sql=
"select pcm_val from tmp_pcmn where pcm_val= $1";
194 $ret=$this->
db->exec_sql(
$sql,array($this->
id));
203 $ret=$this->
db->exec_sql(
"select pcm_lib,pcm_val_parent from
204 tmp_pcmn where pcm_val=$1",array($this->
id));
207 if ( !
$r )
return false;
209 $this->parent=
$r[0][
'pcm_val_parent'];
219 echo
"OBSOLETE Acc_Account_Ledger->get(), a remplacer par Acc_Account_Ledger->load()";
220 return $this->
load();
232 $Res=$this->
db->exec_sql(
"select sum(deb) as sum_deb, sum(cred) as sum_cred from
234 case when j_debit='t' then j_montant else 0 end as deb,
235 case when j_debit='f' then j_montant else 0 end as cred
236 from jrnx join tmp_pcmn on j_poste=pcm_val
238 j_poste::text like ('$this->id'::text) and
242 if (
$Max==0)
return 0;
245 return abs(
$r[
'sum_deb']-
$r[
'sum_cred']);
256 if ( $p_cond !=
"") $p_cond=
" and ".$p_cond;
257 $sql=
"select sum(deb) as sum_deb, sum(cred) as sum_cred from
259 case when j_debit='t' then j_montant else 0 end as deb,
260 case when j_debit='f' then j_montant else 0 end as cred
263 j_poste::text like ('$this->id'::text)
272 return array(
'debit'=>0,
279 if (
$r[
'sum_deb']==
'')
281 if (
$r[
'sum_cred']==
'')
284 return array(
'debit'=>
$r[
'sum_deb'],
285 'credit'=>
$r[
'sum_cred'],
286 'solde'=>abs(bcsub(
$r[
'sum_deb'],
$r[
'sum_cred'])));
298 $a_TVA=$this->
db->get_array(
'select tva_poste
300 foreach ( $a_TVA as $line_tva)
302 if ( $line_tva[
'tva_poste'] ==
'' )
304 list($tva_deb,$tva_cred)=explode(
',',$line_tva[
'tva_poste']);
305 if ( $this->
id == $tva_deb ||
306 $this->
id == $tva_cred )
328 if ( count($this->row ) == 0 )
335 echo
"<TABLE id=\"tbpopup\" class=\"resultfooter\" style=\"border-collapse:separate;margin:1%;width:98%;;border-spacing:0px 5px\">";
337 echo
"<TABLE id=\"tb".$from_div.
"\" class=\"resultfooter\" style=\"border-collapse:separate;margin:1%;width:98%;;border-spacing:0px 2px\">";
340 "<TH style=\"text-align:left\"> Date</TH>".
341 "<TH style=\"text-align:left\"> n° de pièce </TH>".
342 "<TH style=\"text-align:left\"> Code interne </TH>".
343 "<TH style=\"text-align:left\"> Description </TH>".
344 "<TH style=\"text-align:right\"> Débit </TH>".
345 "<TH style=\"text-align:right\"> Crédit </TH>".
346 th(
'Prog.',
'style="text-align:right"').
347 th(
'Let.',
'style="text-align:right"');
354 foreach ( $this->row as
$op )
356 $vw_operation = sprintf(
'<A class="detail" style="text-decoration:underline;color:red" HREF="javascript:modifyOperation(\'%s\',\'%s\')" >%s</A>', $op[
'jr_id'],
dossier::id(), $op[
'jr_internal']);
359 if ($op[
'letter'] != -1)
361 $let = strtoupper(base_convert($op[
'letter'], 10, 36));
364 $tmp_diff=bcsub($op[
'deb_montant'],$op[
'cred_montant']);
369 if ( $old_exercice != $op[
'p_exercice'])
371 if ( $old_exercice !=
'')
375 echo
"<TR class=\"highlight\">".
376 "<TD>$old_exercice</TD>".
380 "<TD style=\"text-align:right\">".nbm($sum_deb).
"</TD>".
381 "<TD style=\"text-align:right\">".nbm($sum_cred).
"</TD>".
393 $sum_cred=bcadd($sum_cred,$op[
'cred_montant']);
394 $sum_deb=bcadd($sum_deb,$op[
'deb_montant']);
398 echo
"<TR $class name=\"tr_" .
$let .
"_" .
$from_div .
"\">" .
399 "<TD>".smaller_date(
format_date($op[
'j_date'])).
"</TD>".
400 td(
h($op[
'jr_pj_number'])).
401 "<TD>".$vw_operation.
"</TD>".
402 "<TD>".h($op[
'description']).
"</TD>".
403 "<TD style=\"text-align:right\">".nbm($op[
'deb_montant']).
"</TD>".
404 "<TD style=\"text-align:right\">".nbm($op[
'cred_montant']).
"</TD>".
407 td($html_let,
' style="color:red;text-align:right"') .
409 $old_exercice=$op[
'p_exercice'];
412 $solde_type=($sum_deb>$sum_cred)?
"solde débiteur":
"solde créditeur";
413 $diff=bcsub($sum_deb,$sum_cred);
415 echo
"<TR class=\"highlight\">".
416 "<TD >Totaux</TD><td></td>".
419 "<TD style=\"text-align:right\">".nbm($sum_deb).
"</TD>".
420 "<TD style=\"text-align:right\">".nbm($sum_cred).
"</TD>".
421 "<TD style=\"text-align:right\">".nbm(abs(
$diff)).$side.
"</TD>".
424 echo
"<tr><TD>$solde_type</TD><td></td>".
425 "<TD style=\"text-align:right\">".nbm(abs(
$diff)).
"</TD>".
455 switch($actiontarget)
458 $action_csv=
'CSV:postedetail';
459 $action_pdf=
'PDF:postedetail';
462 $action_csv=
'CSV:glcompte';
463 $action_pdf=
'PDF:glcompte';
466 throw new Exception(
" Fonction HtmlTableHeader argument actiontarget invalid");
473 if ($actiontarget==
'poste')
475 echo
'<TD><form method="GET" ACTION="">'.
478 $hid->input(
"type",
"poste").$hid->input(
'ac',
$_REQUEST[
'ac']).
"</form></TD>";
482 echo
'<TD><form method="GET" ACTION="export.php">'.
486 $hid->input(
"type",
"poste").$str_ople.
487 $hid->input(
'p_action',
'impress').
505 echo
$hid->input(
'poste_fille',
'on');
507 echo
$hid->input(
'oper_detail',
'on');
511 echo
'<TD><form method="GET" ACTION="export.php">'.
515 $hid->input(
"type",
"poste").$str_ople.
516 $hid->input(
'p_action',
'impress').
533 echo
$hid->input(
'poste_fille',
'on');
535 echo
$hid->input(
'oper_detail',
'on');
540 echo
'<td style="vertical-align:top">';
555 $filter=$this->
db->get_value(
"select jrn_def_class_cred from jrn_def where jrn_def_id=$1", array(
$p_jrn));
556 if (
trim ($filter) ==
'')
559 $valid_cred=explode(
" ",$filter);
560 $sql=
"select count(*) as poste from tmp_pcmn where ";
566 foreach ( $valid_cred as $item_cred)
568 if ( strlen (
trim($item_cred)))
570 if ( strstr($item_cred,
"*") ==
true )
572 $SqlItem=$or .
'pcm_val::text like $' . $SqlArrayN++;
573 array_push($SqlArray, strtr($item_cred,
"*",
"%"));
578 $SqlItem=$or .
'pcm_val::text = $' . $SqlArrayN++;
579 array_push($SqlArray, $item_cred);
582 $SqlFilter=$SqlFilter.$SqlItem;
585 $sql.=$SqlFilter .
' and pcm_val::text=$' . $SqlArrayN++;
586 array_push($SqlArray, $this->
id);
603 if ( strlen(
trim(
$row[
'jrn_def_class_deb'])) == 0 )
return array();
604 $valid_account=explode(
" ",
$row[
'jrn_def_class_deb']);
605 return $valid_account;
620 if ( empty(
$array) )
return "";
622 foreach (
$array as $item_cred)
624 if ( strlen (
trim($item_cred))>0 )
626 if ( strstr($item_cred,
"*") ==
true )
628 $item_cred=strtr($item_cred,
"*",
"%");
629 $sql_tmp=
" pcm_val::text like '$item_cred' or";
633 $sql_tmp=
" pcm_val::text = '$item_cred' or";
649 $sql=
"select f_id from fiche_detail where ad_id=$1 and ad_value=$2";
661 $href=
"export.php?".http_build_query(
664 "poste_id"=>$this->
id,
667 "from_periode"=>$p_from,
669 "act"=>
"CSV:postedetail"
672 return '<a class="smallbutton" style="display:inline" href="'.$href.
'">'._(
"Export CSV").
'</a>';
683 $href=
"export.php?".http_build_query(
686 "poste_id"=>$this->
id,
689 "from_periode"=>$p_from,
691 "act"=>
"PDF:postedetail"
694 return '<a class="smallbutton" style="display:inline" href="'.$href.
'">'._(
"Export PDF").
'</a>';
709 echo
' Journal 4 '.$a->belong_ledger(4);
710 return $a->belong_ledger(4);;
load()
Get all the value for this object from the database the data member are set.
do_exist()
check if the poste exist in the tmp_pcmn
static HtmlTableHeader($actiontarget="poste")
Display HTML Table Header (button)
static fetch_all($ret)
wrapper for the function pg_fetch_all
if($g_user->check_dossier(dossier::id(), true)=='X') $op
button_csv($p_from, $p_to)
Return a string with the HTML code to display a button to export the history in CSV.
get_row_date($p_from, $p_to, $let=0, $solded=0)
Get data for accounting entry between 2 date.
td($p_string='', $p_extra='')
surround the string with td
static num_row($ret)
wrapper for the function pg_NumRows
build_sql_account($p_jrn)
build a sql statement thanks a array found with get_account_ledger
get_amount_side($p_amount)
return the letter C if amount is > 0, D if < 0 or =
get_name()
Return the name of a account it doesn't change any data member.
th($p_string, $p_extra='', $raw='')
nbm($p_number, $p_dec=2)
format the number with a sep.
Manage the account from the table jrn, jrnx or tmp_pcmn.
format_date($p_date, $p_from_format= 'YYYY-MM-DD', $p_to_format='DD.MM.YYYY')
format the date, when taken from the database the format is MM-DD-YYYY
HtmlTable($p_array=null, $let=0, $from_div=0)
HtmlTable, display a HTML of a poste for the asked period.
get_solde($p_cond=" true ")
give the balance of an account
get_solde_detail($p_cond="")
give the balance of an account
static fetch_array($ret, $p_indice=0)
wrapper for the function pg_fetch_array
sql_filter_per($p_cn, $p_from, $p_to, $p_form='p_id', $p_field='jr_tech_per')
Create the condition to filter on the j_tech_per thanks a from and to date.
get_row($p_from, $p_to)
Get data for accounting entry between 2 periode.
global $g_user
Find the default module or the first one.
Class for jrn, class acc_ledger for manipulating the ledger.
function trim(s)
remove trailing and heading space
belong_ledger($p_jrn)
verify that the accounting belong to a ledger
isTVA()
isTva tell is a poste is used for VAT
if(!isset($_REQUEST['p_jrn'])) else $Ledger id
static id()
return the $_REQUEST['gDossier'] after a check
h($p_string)
to protect again bad characters which can lead to a cross scripting attack the string to be diplayed ...
foreach($Fiche->row as $op) $solde_type
button_pdf($p_from, $p_to)
Return a string with the HTML code to display a button to export the history in PDF.
get_row_sql($Res)
get the row thanks the resource
__construct($p_cn, $p_id)
filter_history($p_table_id)
Filter in javascript the table with the history.
get_account_ledger($p_jrn)
With the id of the ledger, get the col jrn_def_class_deb.
find_card()
Find the id of the cards which are using the current account.