Fix bug with date in ANC_LIST

This commit is contained in:
Dany De Bontridder 2011-05-16 16:57:33 +00:00
parent 87f0122a3f
commit f65c24569e
5 changed files with 290 additions and 30 deletions

View file

@ -0,0 +1,122 @@
begin;
alter table operation_analytique drop column pa_id;
ALTER TABLE operation_analytique ADD CONSTRAINT operation_analytique_oa_amount_check CHECK (oa_amount >= 0::numeric);
create type anc_table_card_type as (po_id bigint,pa_id bigint,PO_NAME TEXT,po_description text,sum_amount numeric(25,4),f_id bigint,card_account text,name text);
drop function comptaproc.table_analytic_card (p_from text,p_to text);
create or replace function comptaproc.table_analytic_card (p_from text,p_to text)
returns setof anc_table_card_type
as
$BODY$
declare
ret ANC_table_card_type%ROWTYPE;
sql_from text:='';
sql_to text:='';
sWhere text:='';
sAnd text:='';
sResult text:='';
begin
if p_from <> '' and p_from is not null then
sql_from:='oa_date >= to_date('''||p_from::text||''',''DD.MM.YYYY'')';
sWhere:=' where ';
end if;
if p_to <> '' and p_to is not null then
sql_to=' oa_date <= to_date('''||p_to::text||''',''DD.MM.YYYY'')';
sWhere := ' where ';
end if;
if sql_to <> '' and sql_from <> '' then
sAnd :=' and ';
end if;
sResult := sWhere || sql_from || sAnd || sql_to;
for ret in EXECUTE ' SELECT po.po_id, po.pa_id, po.po_name, po.po_description, sum(
CASE
WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
ELSE operation_analytique.oa_amount
END) AS sum_amount, jrnx.f_id, jrnx.j_qcode, ( SELECT fiche_detail.ad_value
FROM fiche_detail
WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = jrnx.f_id) AS name
FROM operation_analytique
JOIN poste_analytique po USING (po_id)
JOIN jrnx USING (j_id)'|| sResult ||'
GROUP BY po.po_id, po.po_name, po.pa_id, jrnx.f_id, jrnx.j_qcode, ( SELECT fiche_detail.ad_value
FROM fiche_detail
WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = jrnx.f_id), po.po_description
HAVING sum(
CASE
WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
ELSE operation_analytique.oa_amount
END) <> 0::numeric;'
loop
return next ret;
end loop;
end;
$BODY$ language plpgsql;
create type anc_table_account_type as (po_id bigint,pa_id bigint,PO_NAME TEXT,po_description text,sum_amount numeric(25,4),card_account text,name text);
drop function comptaproc.table_analytic_account (p_from text,p_to text);
create or replace function comptaproc.table_analytic_account (p_from text,p_to text)
returns setof anc_table_account_type
as
$BODY$
declare
ret ANC_table_account_type%ROWTYPE;
sql_from text:='';
sql_to text:='';
sWhere text:='';
sAnd text:='';
sResult text:='';
begin
if p_from <> '' and p_from is not null then
sql_from:='oa_date >= to_date('''||p_from::text||''',''DD.MM.YYYY'')';
sWhere:=' where ';
end if;
if p_to <> '' and p_to is not null then
sql_to=' oa_date <= to_date('''||p_to::text||''',''DD.MM.YYYY'')';
sWhere := ' where ';
end if;
if sql_to <> '' and sql_from <> '' then
sAnd:=' and ';
end if;
sResult := sWhere || sql_from || sAnd || sql_to;
for ret in EXECUTE 'SELECT po.po_id,
po.pa_id, po.po_name,
po.po_description,sum(
CASE
WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
ELSE operation_analytique.oa_amount
END) AS sum_amount, jrnx.j_poste, tmp_pcmn.pcm_lib AS name
FROM operation_analytique
JOIN poste_analytique po USING (po_id)
JOIN jrnx USING (j_id)
JOIN tmp_pcmn ON jrnx.j_poste::text = tmp_pcmn.pcm_val::text
'|| sResult ||'
GROUP BY po.po_id, po.po_name, po.pa_id, jrnx.j_poste, tmp_pcmn.pcm_lib, po.po_description
HAVING sum(
CASE
WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
ELSE operation_analytique.oa_amount
END) <> 0::numeric '
loop
return next ret;
end loop;
end;
$BODY$ language plpgsql;
update version set val=94;
commit;

View file

@ -63,10 +63,25 @@ class Anc_Acc_List extends Anc_Acc_Link
$date=($date != '')?" $date":'';
$sql_from_poste=($this->from_poste!='')?" and po.po_name >= upper('".Database::escape_string($this->from_poste)."')":'';
$sql_to_poste=($this->to_poste!='')?" and po.po_name <= upper('".Database::escape_string($this->to_poste)."')":'';
$this->arow=$this->db->get_array(" SELECT po_id, pa_id, po_name, po_description, sum_amount, j_poste, name
FROM v_table_analytic_account
where
pa_id=$1 ".$date.$sql_from_poste.$sql_to_poste." order by po_id,j_poste",array($this->pa_id));
$this->arow=$this->db->get_array("
SELECT po.po_id, po.pa_id, po.po_name, po.po_description, sum(
CASE
WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
ELSE operation_analytique.oa_amount
END) AS sum_amount, jrnx.j_poste, tmp_pcmn.pcm_lib AS name
FROM operation_analytique
JOIN poste_analytique po USING (po_id)
JOIN jrnx USING (j_id)
JOIN tmp_pcmn ON jrnx.j_poste::text = tmp_pcmn.pcm_val::text ".
" where
pa_id=$1 ".$date.$sql_from_poste.$sql_to_poste."
GROUP BY po.po_id, po.po_name, po.pa_id, jrnx.j_poste, tmp_pcmn.pcm_lib, po.po_description
HAVING sum(
CASE
WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
ELSE operation_analytique.oa_amount
END) <> 0::numeric order by po_id,j_poste",array($this->pa_id));
}
/**
@ -79,12 +94,26 @@ class Anc_Acc_List extends Anc_Acc_Link
$date=($date != '')?" $date":'';
$sql_from_poste=($this->from_poste!='')?" and po.po_name >= upper('".Database::escape_string($this->from_poste)."')":'';
$sql_to_poste=($this->to_poste!='')?" and po.po_name <= upper('".Database::escape_string($this->to_poste)."')":'';
$this->arow=$this->db->get_array(" SELECT po_id, pa_id, po_name, po_description, oa_date, sum_amount, f_id,
j_qcode, name
FROM v_table_analytic_card
where
pa_id=$1 ".$date.$sql_from_poste.$sql_to_poste." order by po_id,name",array($this->pa_id));
$this->arow=$this->db->get_array(" SELECT po.po_id, po.pa_id, po.po_name, po.po_description, sum(
CASE
WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
ELSE operation_analytique.oa_amount
END) AS sum_amount, jrnx.f_id, jrnx.j_qcode, ( SELECT fiche_detail.ad_value
FROM fiche_detail
WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = jrnx.f_id) AS name
FROM operation_analytique
JOIN poste_analytique po USING (po_id)
JOIN jrnx USING (j_id) ".
" where pa_id=$1 ".$date.$sql_from_poste.$sql_to_poste
."
GROUP BY po.po_id, po.po_name, po.pa_id, jrnx.f_id, jrnx.j_qcode, ( SELECT fiche_detail.ad_value
FROM fiche_detail
WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = jrnx.f_id), po.po_description
HAVING sum(
CASE
WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
ELSE operation_analytique.oa_amount
END) <> 0::numeric order by po_name,name",array($this->pa_id));
}
@ -98,10 +127,24 @@ class Anc_Acc_List extends Anc_Acc_Link
$date=($date != '')?" $date":'';
$sql_from_poste=($this->from_poste!='')?" and po.po_name >= upper('".Database::escape_string($this->from_poste)."')":'';
$sql_to_poste=($this->to_poste!='')?" and po.po_name <= upper('".Database::escape_string($this->to_poste)."')":'';
$this->arow=$this->db->get_array(" SELECT po_id, pa_id, po_name, po_description, sum_amount, j_poste, name
FROM v_table_analytic_account
where
pa_id=$1 ".$date.$sql_from_poste.$sql_to_poste." order by j_poste,po_name",array($this->pa_id));
$this->arow=$this->db->get_array("SELECT po.po_id, po.pa_id, po.po_name, po.po_description, sum(
CASE
WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
ELSE operation_analytique.oa_amount
END) AS sum_amount, jrnx.j_poste, tmp_pcmn.pcm_lib AS name
FROM operation_analytique
JOIN poste_analytique po USING (po_id)
JOIN jrnx USING (j_id)
JOIN tmp_pcmn ON jrnx.j_poste::text = tmp_pcmn.pcm_val::text ".
" where
pa_id=$1 ".$date.$sql_from_poste.$sql_to_poste."
GROUP BY po.po_id, po.po_name, po.pa_id, jrnx.j_poste, tmp_pcmn.pcm_lib, po.po_description
HAVING sum(
CASE
WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
ELSE operation_analytique.oa_amount
END) <> 0::numeric order by j_poste,po_name",array($this->pa_id));
}
@ -116,12 +159,26 @@ class Anc_Acc_List extends Anc_Acc_Link
$sql_from_poste=($this->from_poste!='')?" and po.po_name >= upper('".Database::escape_string($this->from_poste)."')":'';
$sql_to_poste=($this->to_poste!='')?" and po.po_name <= upper('".Database::escape_string($this->to_poste)."')":'';
$this->arow=$this->db->get_array(" SELECT po_id, pa_id, po_name, po_description, oa_date, sum_amount, f_id,
j_qcode, name
FROM v_table_analytic_card
where
pa_id=$1 ".$date.$sql_from_poste.$sql_to_poste." order by name,po_name",array($this->pa_id));
$this->arow=$this->db->get_array(" SELECT po.po_id, po.pa_id, po.po_name, po.po_description, sum(
CASE
WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
ELSE operation_analytique.oa_amount
END) AS sum_amount, jrnx.f_id, jrnx.j_qcode, ( SELECT fiche_detail.ad_value
FROM fiche_detail
WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = jrnx.f_id) AS name
FROM operation_analytique
JOIN poste_analytique po USING (po_id)
JOIN jrnx USING (j_id) ".
" where pa_id=$1 ".$date.$sql_from_poste.$sql_to_poste
."
GROUP BY po.po_id, po.po_name, po.pa_id, jrnx.f_id, jrnx.j_qcode, ( SELECT fiche_detail.ad_value
FROM fiche_detail
WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = jrnx.f_id), po.po_description
HAVING sum(
CASE
WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
ELSE operation_analytique.oa_amount
END) <> 0::numeric order by name,po_name",array($this->pa_id));
}
/**
*@brief display the button export CSV
@ -297,7 +354,7 @@ class Anc_Acc_List extends Anc_Acc_Link
$tot_card=bcadd($tot_card,$amount);
$tot_glob=bcadd($tot_glob,$amount);
echo '<td style="padding-left:10">'.HtmlInput::history_card ($this->arow[$i]['f_id'],$this->arow[$i]['f_id'].' '.$this->arow[$i]['name'],' display:inline').'</td>';
echo '<td style="padding-left:10">'.HtmlInput::history_card ($this->arow[$i]['f_id'],$this->arow[$i]['j_qcode'].' '.$this->arow[$i]['name'],' display:inline').'</td>';
echo td(nbm($amount),' class="num" ');
echo '</tr>';

View file

@ -25,7 +25,7 @@
*/
header('Pragma: public');
header('Content-type: application/csv');
header('Content-type: application/csv');
header('Content-Disposition: attachment;filename="anc-table-export.csv"',FALSE);
require_once('class_anc_table.php');

4
sql/downgrade.sql Normal file
View file

@ -0,0 +1,4 @@
alter table operation_analytique add column pa_id bigint;
ALTER TABLE operation_analytique DROP CONSTRAINT operation_analytique_oa_amount_check;
drop type anc_table_card_type cascade;
drop type anc_table_account_type cascade;

View file

@ -1,8 +1,39 @@
alter table operation_analytique drop column pa_id;
ALTER TABLE operation_analytique ADD CONSTRAINT operation_analytique_oa_amount_check CHECK (oa_amount >= 0::numeric);
CREATE OR REPLACE VIEW v_table_analytic_card AS
SELECT po.po_id, po.pa_id, po.po_name, po.po_description, sum(
create type anc_table_card_type as (po_id bigint,pa_id bigint,PO_NAME TEXT,po_description text,sum_amount numeric(25,4),f_id bigint,card_account text,name text);
drop function comptaproc.table_analytic_card (p_from text,p_to text);
create or replace function comptaproc.table_analytic_card (p_from text,p_to text)
returns setof anc_table_card_type
as
$BODY$
declare
ret ANC_table_card_type%ROWTYPE;
sql_from text:='';
sql_to text:='';
sWhere text:='';
sAnd text:='';
sResult text:='';
begin
if p_from <> '' and p_from is not null then
sql_from:='oa_date >= to_date('''||p_from::text||''',''DD.MM.YYYY'')';
sWhere:=' where ';
end if;
if p_to <> '' and p_to is not null then
sql_to=' oa_date <= to_date('''||p_to::text||''',''DD.MM.YYYY'')';
sWhere := ' where ';
end if;
if sql_to <> '' and sql_from <> '' then
sAnd :=' and ';
end if;
sResult := sWhere || sql_from || sAnd || sql_to;
for ret in EXECUTE ' SELECT po.po_id, po.pa_id, po.po_name, po.po_description, sum(
CASE
WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
ELSE operation_analytique.oa_amount
@ -11,7 +42,7 @@ CREATE OR REPLACE VIEW v_table_analytic_card AS
WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = jrnx.f_id) AS name
FROM operation_analytique
JOIN poste_analytique po USING (po_id)
JOIN jrnx USING (j_id)
JOIN jrnx USING (j_id)'|| sResult ||'
GROUP BY po.po_id, po.po_name, po.pa_id, jrnx.f_id, jrnx.j_qcode, ( SELECT fiche_detail.ad_value
FROM fiche_detail
WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = jrnx.f_id), po.po_description
@ -19,11 +50,50 @@ CREATE OR REPLACE VIEW v_table_analytic_card AS
CASE
WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
ELSE operation_analytique.oa_amount
END) <> 0::numeric;
END) <> 0::numeric;'
CREATE OR REPLACE VIEW v_table_analytic_account AS
SELECT po.po_id, po.pa_id, po.po_name, po.po_description, sum(
loop
return next ret;
end loop;
end;
$BODY$ language plpgsql;
create type anc_table_account_type as (po_id bigint,pa_id bigint,PO_NAME TEXT,po_description text,sum_amount numeric(25,4),card_account text,name text);
drop function comptaproc.table_analytic_account (p_from text,p_to text);
create or replace function comptaproc.table_analytic_account (p_from text,p_to text)
returns setof anc_table_account_type
as
$BODY$
declare
ret ANC_table_account_type%ROWTYPE;
sql_from text:='';
sql_to text:='';
sWhere text:='';
sAnd text:='';
sResult text:='';
begin
if p_from <> '' and p_from is not null then
sql_from:='oa_date >= to_date('''||p_from::text||''',''DD.MM.YYYY'')';
sWhere:=' where ';
end if;
if p_to <> '' and p_to is not null then
sql_to=' oa_date <= to_date('''||p_to::text||''',''DD.MM.YYYY'')';
sWhere := ' where ';
end if;
if sql_to <> '' and sql_from <> '' then
sAnd:=' and ';
end if;
sResult := sWhere || sql_from || sAnd || sql_to;
for ret in EXECUTE 'SELECT po.po_id,
po.pa_id, po.po_name,
po.po_description,sum(
CASE
WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
ELSE operation_analytique.oa_amount
@ -32,11 +102,18 @@ CREATE OR REPLACE VIEW v_table_analytic_account AS
JOIN poste_analytique po USING (po_id)
JOIN jrnx USING (j_id)
JOIN tmp_pcmn ON jrnx.j_poste::text = tmp_pcmn.pcm_val::text
'|| sResult ||'
GROUP BY po.po_id, po.po_name, po.pa_id, jrnx.j_poste, tmp_pcmn.pcm_lib, po.po_description
HAVING sum(
CASE
WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
ELSE operation_analytique.oa_amount
END) <> 0::numeric;
END) <> 0::numeric '
loop
return next ret;
end loop;
end;
$BODY$ language plpgsql;
commit;