From a073cb5672eeb430166f199053d258313cc70a3f Mon Sep 17 00:00:00 2001 From: sparkyx Date: Sun, 27 Aug 2006 17:41:07 +0000 Subject: [PATCH] Correction bug 17543, 17544, 17545 --- contrib/csv-tools/analyze.sh | 2 +- html/admin/setup.php | 6 + html/admin/sql/patch/upgrade19.sql | 178 +++++++++++++++++++++++++++++ html/index.php | 2 +- html/style-light.css | 2 + include/class_fiche.php | 2 +- scripts/cleanup.sh | 5 + sql/upgrade.sql | 65 ----------- 8 files changed, 194 insertions(+), 68 deletions(-) create mode 100644 html/admin/sql/patch/upgrade19.sql diff --git a/contrib/csv-tools/analyze.sh b/contrib/csv-tools/analyze.sh index ef13ef966..ec1c4dc82 100644 --- a/contrib/csv-tools/analyze.sh +++ b/contrib/csv-tools/analyze.sh @@ -11,7 +11,7 @@ Help () { Help -FILE=argenta.csv +FILE=file.csv if [ $# -eq 2 ]; then START=$1 diff --git a/html/admin/setup.php b/html/admin/setup.php index 574c391b8..0871355e6 100644 --- a/html/admin/setup.php +++ b/html/admin/setup.php @@ -478,6 +478,9 @@ if ( DEBUG=='false' ) ob_start(); if ( GetVersion($db) == 18 ) { ExecuteScript($db,'sql/patch/upgrade18.sql'); } // version + if ( GetVersion($db) == 19 ) { + ExecuteScript($db,'sql/patch/upgrade19.sql'); + } // version if ( DEBUG == 'false') ob_end_clean(); }//for @@ -569,6 +572,9 @@ if (DEBUG == 'false' ) ob_start(); if ( GetVersion($db) == 18 ) { ExecuteScript($db,'sql/patch/upgrade18.sql'); } // version + if ( GetVersion($db) == 19 ) { + ExecuteScript($db,'sql/patch/upgrade19.sql'); + } // version if ( DEBUG == 'false') ob_end_clean(); } diff --git a/html/admin/sql/patch/upgrade19.sql b/html/admin/sql/patch/upgrade19.sql new file mode 100644 index 000000000..3535895cc --- /dev/null +++ b/html/admin/sql/patch/upgrade19.sql @@ -0,0 +1,178 @@ +begin; +-- bug 1753 +create or replace function correct_sequence ( p_sequence text,p_col text, p_table text ) +returns integer +as +$body$ +declare +-- fonction description +-- Often the primary key is a sequence number and sometimes +-- the value of the sequence is not synchronized with the +-- primary key +-- parameter p_sequence : sequence name +-- parameter p_col : col of the pk +-- parameter p_table : concerned table +-- variable +-- last value of the sequence +last_sequence int8; +-- max value of the pk +max_sequence int8; +-- n integer +n integer; +begin +-- the sequence exist ? + select count(*) into n from pg_class where relkind='S' and relname=lower(p_sequence); + if n = 0 then + raise exception ' Unknow sequence % ',p_sequence; + end if; + select count(*) into n from pg_class where relkind='r' and relname=lower(p_table); + if n = 0 then + raise exception ' Unknow table % ',p_table; + end if; + + execute 'select last_value from '||p_sequence into last_sequence; + raise notice 'Last value of the sequence is %', last_sequence; + + execute 'select max('||p_col||') from '||p_table into max_sequence; + raise notice 'Max value of the sequence is %', max_sequence; + max_sequence:= max_sequence +1; + execute 'alter sequence '||p_sequence||' restart with '||max_sequence; +return 0; + +end; +$body$ language plpgsql; + +comment on function correct_sequence (text,text,text) is ' Often the primary key is a sequence number and sometimes + the value of the sequence is not synchronized with the primary key ( p_sequence : sequence name, p_col : col of the pk,p_table : concerned table'; + +select correct_sequence('s_jnt_fic_att_value','jft_id','jnt_fic_att_value'); + +-- bug 17544 +-- add a pk to the table jnt_fic_attr +alter table jnt_fic_attr add jnt_id int8; +create sequence s_jnt_id; +alter table jnt_fic_attr alter jnt_id set default nextval('s_jnt_id'); +update jnt_fic_attr set jnt_id=nextval('s_jnt_id'); +alter table jnt_fic_attr add constraint pk_jnt_fic_attr primary key (jnt_id); + +-- remove duplicate attr +delete from jnt_fic_attr where jnt_id in ( select a.jnt_id from jnt_fic_attr a join jnt_fic_attr b on (a.fd_id=b.fd_id and a.ad_id=b.ad_id) where a.jnt_id > b.jnt_id); + +-- bug 17543 + +--account_compute +CREATE or replace FUNCTION account_parent(p_account poste_comptable) RETURNS poste_comptable + AS $$ +declare + nParent tmp_pcmn.pcm_val_parent%type; + sParent varchar; + nCount integer; +begin + sParent:=to_char(p_account,'9999999999999999'); + sParent:=trim(sParent); + nParent:=0; + while nParent = 0 loop + select count(*) into nCount + from tmp_pcmn + where + pcm_val = to_number(sParent,'9999999999999999'); + if nCount != 0 then + nParent:=to_number(sParent,'9999999999999999'); + end if; + sParent:= substr(sParent,1,length(sParent)-1); + if length(sParent) <= 0 then + raise exception 'Impossible de trouver le compte parent pour %',p_account; + end if; + end loop; + raise notice 'account_parent : Parent is %',nParent; + return nParent; +end; +$$ + LANGUAGE plpgsql; + + +commit; + + +CREATE or replace FUNCTION account_compute(p_f_id integer) RETURNS poste_comptable + AS $$ +declare + class_base poste_comptable; + maxcode int8; +begin + select fd_class_base into class_base + from + fiche_def join fiche using (fd_id) + where + f_id=p_f_id; + raise notice 'account_compute class base %',class_base; + select max(pcm_val) into maxcode from tmp_pcmn where pcm_val_parent = class_base; + if maxcode = class_base then + maxcode:=class_base*1000; + end if; + maxcode:=maxcode+1; + raise notice 'account_compute Max code %',maxcode; + return maxcode; +end; +$$ + LANGUAGE plpgsql; + + + +-- +-- Name: account_insert(integer, poste_comptable); Type: FUNCTION; Schema: public; Owner: phpcompta +-- + +CREATE or replace FUNCTION account_insert(p_f_id integer, p_account poste_comptable) RETURNS integer + AS $$ +declare +nParent tmp_pcmn.pcm_val_parent%type; +sName varchar; +nNew tmp_pcmn.pcm_val%type; +bAuto bool; +nFd_id integer; +nCount integer; +begin + + if length(trim(p_account)) != 0 then + raise notice 'p_account is not empty'; + select * into nCount from tmp_pcmn where pcm_val=p_account; + if nCount !=0 then + raise notice 'this account exists in tmp_pcmn '; + select av_text into sName from + attr_value join jnt_fic_att_value using (jft_id) + where + ad_id=1 and f_id=p_f_id; + nParent:=account_parent(p_account); + insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent) + values (p_account,sName,nParent); + perform attribut_insert(p_f_id,5,to_char(nNew,'999999999999')); + + end if; + else + raise notice 'p_account is empty'; + select fd_id into nFd_id from fiche where f_id=p_f_id; + bAuto:= account_auto(nFd_id); + if bAuto = true then + raise notice 'account generated automatically'; + nNew:=account_compute(p_f_id); + raise notice 'nNew %', nNew; + select av_text into sName from + attr_value join jnt_fic_att_value using (jft_id) + where + ad_id=1 and f_id=p_f_id; + nParent:=account_parent(nNew); + perform account_add (nNew,sName); + perform attribut_insert(p_f_id,5,to_char(nNew,'999999999999')); + + else + perform attribut_insert(p_f_id,5,null); + end if; + end if; + +return 0; +end; +$$ + LANGUAGE plpgsql; +update version set val=20; +commit; \ No newline at end of file diff --git a/html/index.php b/html/index.php index 1b15b878f..4af9a9bb7 100644 --- a/html/index.php +++ b/html/index.php @@ -76,7 +76,7 @@ BODY { -Version 2.0.3 +Version 2.0.4

Il est conseillé de ne PAS utiliser Internet Explorer.

diff --git a/html/style-light.css b/html/style-light.css index 292e00e58..a812f1e77 100644 --- a/html/style-light.css +++ b/html/style-light.css @@ -394,6 +394,8 @@ div.u_content input.text { color:blue; } + + div.u_redcontent input:focus { background-color:fff6aa; } diff --git a/include/class_fiche.php b/include/class_fiche.php index 1f428f631..071fcc8f3 100644 --- a/include/class_fiche.php +++ b/include/class_fiche.php @@ -578,7 +578,7 @@ class fiche { // account if ( $id == ATTR_DEF_ACCOUNT ) { - echo_debug("Modify ATTR_DEF_ACCOUNT"); + echo_debug("insert ATTR_DEF_ACCOUNT"); $v=FormatString($value); if ( isNumber($v) == 1 ) { diff --git a/scripts/cleanup.sh b/scripts/cleanup.sh index 59c5f2fa8..a5dd61985 100755 --- a/scripts/cleanup.sh +++ b/scripts/cleanup.sh @@ -3,7 +3,12 @@ dropdb -U phpcompta -h localhost account_repository dropdb -U phpcompta -h localhost dossier1 +dropdb -U phpcompta -h localhost dossier3 +dropdb -U phpcompta -h localhost dossier4 +dropdb -U phpcompta -h localhost dossier5 dropdb -U phpcompta -h localhost dossier13 dropdb -U phpcompta -h localhost mod1 dropdb -U phpcompta -h localhost mod2 +dropdb -U phpcompta -h localhost mod3 +dropdb -U phpcompta -h localhost mod7 diff --git a/sql/upgrade.sql b/sql/upgrade.sql index bbbe57920..e69de29bb 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -1,65 +0,0 @@ -begin; - -create or replace function correct_sequence ( p_sequence text,p_col text, p_table text ) -returns integer -as -$body$ -declare --- fonction description --- Often the primary key is a sequence number and sometimes --- the value of the sequence is not synchronized with the --- primary key --- parameter p_sequence : sequence name --- parameter p_col : col of the pk --- parameter p_table : concerned table --- variable --- last value of the sequence -last_sequence int8; --- max value of the pk -max_sequence int8; --- n integer -n integer; -begin --- the sequence exist ? - select count(*) into n from pg_class where relkind='S' and relname=lower(p_sequence); - if n = 0 then - raise exception ' Unknow sequence % ',p_sequence; - end if; - select count(*) into n from pg_class where relkind='r' and relname=lower(p_table); - if n = 0 then - raise exception ' Unknow table % ',p_table; - end if; - - execute 'select last_value from '||p_sequence into last_sequence; - raise notice 'Last value of the sequence is %', last_sequence; - - execute 'select max('||p_col||') from '||p_table into max_sequence; - raise notice 'Max value of the sequence is %', max_sequence; - max_sequence:= max_sequence +1; - execute 'alter sequence '||p_sequence||' restart with '||max_sequence; -return 0; - -end; -$body$ language plpgsql; - -comment on function correct_sequence (text,text,text) is ' Often the primary key is a sequence number and sometimes - the value of the sequence is not synchronized with the primary key ( p_sequence : sequence name, p_col : col of the pk,p_table : concerned table'; - -select correct_sequence('s_jnt_fic_att_value','jft_id','jnt_fic_att_value'); - --- add a pk to the table jnt_fic_attr -alter table jnt_fic_attr add jnt_id int8; -create sequence s_jnt_id; -alter table jnt_fic_attr alter jnt_id set default nextval('s_jnt_id'); -update jnt_fic_attr set jnt_id=nextval('s_jnt_id'); -alter table jnt_fic_attr add constraint pk_jnt_fic_attr primary key (jnt_id); - --- remove duplicate attr -delete from jnt_fic_attr where jnt_id in ( select a.jnt_id from jnt_fic_attr a join jnt_fic_attr b on (a.fd_id=b.fd_id and a.ad_id=b.ad_id) where a.jnt_id > b.jnt_id); - - - - - - -commit; \ No newline at end of file