36 parent::__construct($p_cn);
50 $r = parent::display_form($p_hidden);
51 $icard =
new ISelect(
'card_poste');
52 $icard->value = array(
53 array(
'value' => 1,
'label' =>
'Par fiche'),
54 array(
'value' => 2,
'label' =>
'Par poste comptable')
56 $icard->selected = $this->card_poste;
57 $r .= $icard->input();
74 $sql_from =
"oa_date >= to_date('" . $this->
from .
"','DD.MM.YYYY')";
77 if (trim($this->
to) !=
"" &&
isDate($this->
to) != NULL) {
78 $sql_to =
"oa_date <= to_date('" . $this->
to .
"','DD.MM.YYYY')";
81 if ($sql_to !=
"" && $sql_from !=
"") {
84 $sResult = $sWhere . $sql_from . $sql_and . $sql_to;
87 create temporary table table_analytic as
90 po.po_description,sum(
92 WHEN oa1.oa_debit = true THEN oa1.oa_amount * (-1)::numeric
95 coalesce(jrnx.j_poste,fd1.ad_value) as card_account,
97 FROM operation_analytique as oa1
98 JOIN poste_analytique po USING (po_id)
99 left join fiche_detail as fd1 on (oa1.f_id=fd1.f_id and fd1.ad_id=5)
100 left JOIN jrnx USING (j_id)
101 left join tmp_pcmn ON (jrnx.j_poste::text = tmp_pcmn.pcm_val::text)
103 GROUP BY po.po_id, po.po_name, po.pa_id, coalesce(jrnx.j_poste,fd1.ad_value), tmp_pcmn.pcm_lib, po.po_description
106 WHEN oa1.oa_debit = true THEN oa1.oa_amount * (-1)::numeric
108 END) <> 0::numeric ";
109 $this->
db->exec_sql(
$sql);
123 $sql_from =
"oa_date >= to_date('" . $this->
from .
"','DD.MM.YYYY')";
126 if (trim($this->
to) !=
"" &&
isDate($this->
to) != NULL) {
127 $sql_to =
"oa_date <= to_date('" . $this->
to .
"','DD.MM.YYYY')";
130 if ($sql_to !=
"" && $sql_from !=
"") {
133 $sResult = $sWhere . $sql_from . $sql_and . $sql_to;
135 create temporary table table_analytic as
136 with m as (select oa_id,po_id,
137 coalesce(jrnx.f_id,operation_analytique.f_id) as f_id1,
138 case when jrnx.j_qcode is not null then
139 ( SELECT fiche_detail.ad_value
141 WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = jrnx.f_id)
142 when jrnx.f_id is null and operation_analytique.f_id is not null then
143 ( SELECT fiche_detail.ad_value
145 WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = operation_analytique.f_id)
148 case when jrnx.j_qcode is not null then
150 when jrnx.f_id is null then
151 (SELECT fiche_detail.ad_value
153 WHERE fiche_detail.ad_id = 23 AND fiche_detail.f_id = operation_analytique.f_id) end as j_qcode
154 FROM operation_analytique
155 left JOIN jrnx USING (j_id) )
156 SELECT po.po_id, po.pa_id, po.po_name, po.po_description, sum(
158 WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
159 ELSE operation_analytique.oa_amount
163 m.j_qcode as card_account
164 FROM operation_analytique
165 JOIN poste_analytique po USING (po_id)
168 GROUP BY po.po_id, po.po_name, po.pa_id, m.f_id1, m.j_qcode,m.name, po.po_description
171 WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
172 ELSE operation_analytique.oa_amount
174 $this->
db->exec_sql(
$sql);
190 $header =
"select distinct po_id,po_name from table_analytic
192 pa_id=$1 " . $sql_from_poste . $sql_to_poste .
" order by po_name";
193 $this->aheader = $this->
db->get_array(
$header, array($this->
pa_id));
195 $this->arow = $this->
db->get_array(
"select distinct card_account,name
198 pa_id=$1 " . $sql_from_poste . $sql_to_poste .
" order by card_account", array($this->
pa_id));
200 $this->sql =
'select sum_amount from table_analytic where card_account=$1 and po_id=$2 and pa_id=' . $this->
pa_id .
' ' . $sql_from_poste . $sql_to_poste;
213 $header =
"select distinct po_id,po_name from table_analytic
215 pa_id=$1 " . $sql_from_poste . $sql_to_poste .
" order by po_name";
216 $this->aheader = $this->
db->get_array(
$header, array($this->
pa_id));
218 $this->arow = $this->
db->get_array(
"select distinct f_id,card_account,name from table_analytic
220 pa_id=$1 " . $sql_from_poste . $sql_to_poste .
" order by name", array($this->
pa_id));
221 $this->sql =
'select sum_amount from table_analytic where f_id=$1 and po_id=$2 and pa_id=' . $this->
pa_id .
' ' . $sql_from_poste . $sql_to_poste;
232 $r .=
'<form method="GET" action="export.php" style="display:inline">';
241 $r .= dossier::hidden();
250 if ($this->
check() != 0) {
251 alert(_(
"Date invalide"));
255 if ($this->card_poste ==
'1') {
258 echo
'<table class="result">';
261 foreach ($this->aheader as $h) {
262 echo
'<th style="text-align:right">' .
h($h[
'po_name']) .
'</th>';
264 echo
th(
'Total',
' style="text-align:right"');
270 for (
$i = 0;
$i < count($this->arow);
$i++) {
271 $tr = (
$i % 2 == 0) ?
'<tr class="even">' :
'<tr class="odd">';
275 for ($x = 0; $x < count($this->aheader); $x++) {
276 $amount = $this->
db->get_value($this->sql, array($this->arow[
$i][
'f_id'], $this->aheader[$x][
'po_id']));
278 if (isset($tot_col[$x])) {
279 $tot_col[$x] = bcadd($tot_col[$x],
$amount);
286 $tot_row = bcadd($tot_row,
$amount);
288 $side = ($tot_row < 0) ?
'D' :
'C';
290 echo
td(
nbm(abs($tot_row)) .
" " .
$side,
' class="num"');
291 $tot_global = bcadd($tot_global, $tot_row);
296 echo
'<tr class="highlight">';
298 for (
$i = 0;
$i < count($this->aheader);
$i++) {
299 $side = ($tot_col[
$i] < 0) ?
"D" :
"C";
301 echo
td(
nbm(abs($tot_col[
$i])) .
" " .
$side,
' class="num"');
303 $side = ($tot_global > 0) ?
"C" :
"D";
305 echo
td(
nbm($tot_global) .
" " .
$side,
' class="num " ');
309 if ($this->card_poste ==
'2') {
312 echo
'<table class="result">';
314 echo
th(
'poste comptable ');
315 foreach ($this->aheader as $h) {
316 echo
'<th style="text-align:right">' .
h($h[
'po_name']) .
'</th>';
318 echo
th(
'Total',
' style="text-align:right"');
324 for (
$i = 0;
$i < count($this->arow);
$i++) {
325 $tr = (
$i % 2 == 0) ?
'<tr class="even">' :
'<tr class="odd">';
329 for ($x = 0; $x < count($this->aheader); $x++) {
330 $amount = $this->
db->get_value($this->sql, array($this->arow[
$i][
'card_account'], $this->aheader[$x][
'po_id']));
332 if (isset($tot_col[$x])) {
333 $tot_col[$x] = bcadd($tot_col[$x],
$amount);
340 $tot_row = bcadd($tot_row,
$amount);
342 $side = ($tot_row < 0) ?
'D' :
'C';
344 echo
td(
nbm(abs($tot_row)) .
" " .
$side,
' class="num"');
345 $tot_global = bcadd($tot_global, $tot_row);
350 echo
'<tr class="highlight">';
354 for (
$i = 0;
$i < count($this->aheader);
$i++) {
355 $side = ($tot_col[
$i] < 0) ?
"D" :
"C";
356 echo
td(
nbm(abs($tot_col[
$i])) .
" " .
$side,
' class="num"');
358 $side = ($tot_global > 0) ?
"C" :
"D";
361 echo
td(
nbm($tot_global) .
" " .
$side,
' class="num input_text" ');
372 if ($this->
check() != 0) {
373 throw new Exception (
"DATE INVALIDE");
379 if ($this->card_poste ==
'1') {
383 foreach ($this->aheader as $h) {
384 $csv->add($h[
'po_name']);
393 for (
$i = 0;
$i < count($this->arow);
$i++) {
395 $csv->add($this->arow[
$i][
'card_account'] .
' ' . $this->arow[
$i][
'name']);
397 for ($x = 0; $x < count($this->aheader); $x++) {
398 $amount = $this->
db->get_value($this->sql, array($this->arow[
$i][
'f_id'], $this->aheader[$x][
'po_id']));
400 if (isset($tot_col[$x])) {
401 $tot_col[$x] = bcadd($tot_col[$x],
$amount);
406 $tot_row = bcadd($tot_row,
$amount);
408 $csv->add($tot_row,
"number");
417 for ($x = 0; $x < count($this->aheader); $x++) {
418 $csv->add($tot_col[$x],
"number");
419 $sum_col = bcadd($sum_col, $tot_col[$x]);
421 $csv->add($sum_col,
"number");
426 if ($this->card_poste ==
'2') {
429 $csv->add(_(
"Poste"));
430 $csv->add(_(
"Description"));
431 foreach ($this->aheader as $h) {
432 $csv->add($h[
'po_name']);
440 for (
$i = 0;
$i < count($this->arow);
$i++) {
442 $csv->add($this->arow[
$i][
'card_account']);
443 $csv->add($this->arow[
$i][
'name']);
445 for ($x = 0; $x < count($this->aheader); $x++) {
446 $amount = $this->
db->get_value($this->sql, array($this->arow[
$i][
'card_account'], $this->aheader[$x][
'po_id']));
448 if (isset($tot_col[$x])) {
449 $tot_col[$x] = bcadd($tot_col[$x],
$amount);
454 $tot_row = bcadd($tot_row,
$amount);
456 $csv->add($tot_row,
"number");
467 for ($x = 0; $x < count($this->aheader); $x++) {
468 $csv->add($tot_col[$x],
"number");
469 $sum_col = bcadd($sum_col, $tot_col[$x]);
471 $csv->add($sum_col,
"number");
th($p_string, $p_extra='', $raw='')
td($p_string='', $p_extra='')
surround the string with td
nbm($p_number, $p_dec=2)
format the number with a sep.
alert($p_msg, $buffer=false)
alert in javascript
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
h( $row[ 'oa_description'])
$anc_grandlivre from_poste
link between accountancy and analytic, like table but as a listing
printing analytic and accountancy as a table
load_card()
load the data does not return anything but give a value to this->aheader and this->arow
show_button($p_hidden)
display the button export CSV
create_temp_table_account()
create the temporary table TABLE_ANALYTIC to store values for an account.
load_poste()
load the data does not return anything but give a value to this->aheader and this->arow
display_form($p_hidden='')
display form to get the parameter
create_temp_table_card()
create the temporary table TABLE_ANALYTIC to store values for a card
static escape_string($p_string)
wrapper for the function pg_escape_string
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
Manage the CSV : manage files and write CSV record.
if(count($a_accounting)==0) $header