diff --git a/dev/manage-code/create-file/create_phpclass.py b/dev/manage-code/create-file/create_phpclass.py index db7efdce9..970ada521 100755 --- a/dev/manage-code/create-file/create_phpclass.py +++ b/dev/manage-code/create-file/create_phpclass.py @@ -14,6 +14,8 @@ # second line = pk import sys, getopt +import pdb + def help(): print """ option are -h for help @@ -77,7 +79,7 @@ class @class_name@ @mother_class@ if ( $p_id == -1 ) { /* Initialize an empty object */ - foreach ($this->variable as $key=>$value) $this->$value='DEFAULT'; + foreach ($this->variable as $key=>$value) $this->$value=null; $this->@id@=$p_id; } else { /* load it */ @@ -543,6 +545,7 @@ class @class_name@ (col_id,col_type,default)=e.split('|') col_id=col_id.strip() col_type=col_type.strip() + verify_data_type+=" if ( trim($this->"+col_id+") == '') $this->"+col_id+"=null;\n" if col_type in ('float','integer','numeric','bigint') : verify_data_type+="if ( $this->"+col_id+"!== null && settype($this->"+col_id+",'float') == false )\n \ throw new Exception('DATATYPE "+col_id+" $this->"+col_id+" non numerique');\n" diff --git a/html/admin/sql/patch/upgrade95.sql b/html/admin/sql/patch/upgrade95.sql new file mode 100644 index 000000000..a58278a42 --- /dev/null +++ b/html/admin/sql/patch/upgrade95.sql @@ -0,0 +1,147 @@ +begin; + +delete from fiche_detail where jft_id in ( + select a.jft_id +from fiche_detail as a ,fiche_detail as b +where +a.f_id=b.f_id +and a.ad_id = b.ad_id +and a.jft_id > b.jft_id); + + +create unique index fiche_Detail_f_id_ad_id on fiche_detail (f_id,ad_id); + +CREATE OR REPLACE FUNCTION comptaproc.account_insert(p_f_id integer, p_account text) + RETURNS integer AS +$BODY$ +declare + nParent tmp_pcmn.pcm_val_parent%type; + sName varchar; + nNew tmp_pcmn.pcm_val%type; + bAuto bool; + nFd_id integer; + sClass_Base fiche_def.fd_class_base%TYPE; + nCount integer; + first text; + second text; +begin + + if p_account is not null and length(trim(p_account)) != 0 then + -- if there is coma in p_account, treat normally + if position (',' in p_account) = 0 then + raise info 'p_account is not empty'; + select count(*) into nCount from tmp_pcmn where pcm_val=p_account::account_type; + raise notice 'found in tmp_pcm %',nCount; + if nCount !=0 then + raise info 'this account exists in tmp_pcmn '; + perform attribut_insert(p_f_id,5,p_account); + else + -- account doesn't exist, create it + select ad_value into sName from + fiche_detail + where + ad_id=1 and f_id=p_f_id; + + nParent:=account_parent(p_account::account_type); + insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent) values (p_account::account_type,sName,nParent); + perform attribut_insert(p_f_id,5,p_account); + + end if; + else + raise info 'presence of a comma'; + -- there is 2 accounts separated by a comma + first := split_part(p_account,',',1); + second := split_part(p_account,',',2); + -- check there is no other coma + raise info 'first value % second value %', first, second; + + if position (',' in first) != 0 or position (',' in second) != 0 then + raise exception 'Too many comas, invalid account'; + end if; + perform attribut_insert(p_f_id,5,p_account); + end if; + else + raise info 'p_account is empty'; + select fd_id into nFd_id from fiche where f_id=p_f_id; + bAuto:= account_auto(nFd_id); + + select fd_class_base into sClass_base from fiche_def where fd_id=nFd_id; +raise info 'sClass_Base : %',sClass_base; + if bAuto = true and sClass_base similar to '[[:digit:]]*' then + raise info 'account generated automatically'; + nNew:=account_compute(p_f_id); + raise info 'nNew %', nNew; + select ad_value into sName from + fiche_detail + 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,nNew); + + else + -- if there is an account_base then it is the default + select fd_class_base::account_type into nNew from fiche_def join fiche using (fd_id) where f_id=p_f_id; + if nNew is null or length(trim(nNew)) = 0 then + raise notice 'count is null'; + perform attribut_insert(p_f_id,5,null); + else + perform attribut_insert(p_f_id,5,nNew); + end if; + end if; + end if; + +return 0; +end; +$BODY$ + LANGUAGE plpgsql; + +CREATE OR REPLACE FUNCTION comptaproc.account_update(p_f_id integer, p_account account_type) + RETURNS integer AS +$BODY$ +declare + nMax fiche.f_id%type; + nCount integer; + nParent tmp_pcmn.pcm_val_parent%type; + sName varchar; + first text; + second text; +begin + + if p_account is not null and length(trim(p_account)) != 0 then + if position (',' in p_account) = 0 then + select count(*) into nCount from tmp_pcmn where pcm_val=p_account; + if nCount = 0 then + select ad_value into sName from + fiche_detail + 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); + end if; + else + raise info 'presence of a comma'; + -- there is 2 accounts separated by a comma + first := split_part(p_account,',',1); + second := split_part(p_account,',',2); + -- check there is no other coma + raise info 'first value % second value %', first, second; + + if position (',' in first) != 0 or position (',' in second) != 0 then + raise exception 'Too many comas, invalid account'; + end if; + end if; + end if; + + update fiche_detail set ad_value=p_account where f_id=p_f_id and ad_id=5 ; + +return 0; +end; +$BODY$ + LANGUAGE plpgsql; + +update operation_analytique set oa_debit=j_debit from jrnx where jrnx.j_id = operation_analytique.j_id; + +update version set val=96; + +commit; \ No newline at end of file diff --git a/html/admin/sql/patch/upgrade96.sql b/html/admin/sql/patch/upgrade96.sql new file mode 100644 index 000000000..c7d680fb1 --- /dev/null +++ b/html/admin/sql/patch/upgrade96.sql @@ -0,0 +1,7 @@ +begin; + +drop function if exists public.account_insert(integer,text); + +update version set val=97; + +commit; \ No newline at end of file diff --git a/html/style-color.css b/html/style-color.css index 9b3a3d53d..c4b0778ab 100644 --- a/html/style-color.css +++ b/html/style-color.css @@ -911,4 +911,9 @@ div#search_form width:50%; display:none; background-color:#e4e7ed; -} \ No newline at end of file +} +table.result td +{ + padding-left:5px; + padding-right:5px; +} diff --git a/html/style-light.css b/html/style-light.css index 21bd55901..1b33217c2 100644 --- a/html/style-light.css +++ b/html/style-light.css @@ -34,7 +34,7 @@ table.result th { color:#25238F; text-align: left; - background-color:#EDF3FF; + background-color:#bdbaba; font-style: italic; @@ -941,4 +941,9 @@ div#search_form width:50%; display:none; background-color:#e4e7ed; -} \ No newline at end of file +} +table.result td +{ + padding-left:5px; + padding-right:5px; +} diff --git a/html/style-print.css b/html/style-print.css index 50d7d237a..fc69170f8 100644 --- a/html/style-print.css +++ b/html/style-print.css @@ -240,4 +240,8 @@ a.detail:hover .ipop_card_fond { display:none; } +.num { + text-align:right; +} + /* */ diff --git a/html/style-test.css b/html/style-test.css index bdbc57081..f0492c94e 100644 --- a/html/style-test.css +++ b/html/style-test.css @@ -60,3 +60,8 @@ H2 { color:blue; background-color:white; } +table.result td +{ + padding-left:5px; + padding-right:5px; +} diff --git a/html/style.css b/html/style.css index a8eef46de..c06cdf463 100644 --- a/html/style.css +++ b/html/style.css @@ -34,7 +34,7 @@ table.result th { color:#25238F; text-align: left; - background-color:#EDF3FF; + // background-color:#EDF3FF; font-style: italic; @@ -941,4 +941,10 @@ div#search_form width:50%; display:none; background-color:#e4e7ed; -} \ No newline at end of file +} + +table.result td +{ + padding-left:5px; + padding-right:5px; +} diff --git a/include/class_anc_operation.php b/include/class_anc_operation.php index 70f3de5da..a039947eb 100644 --- a/include/class_anc_operation.php +++ b/include/class_anc_operation.php @@ -536,6 +536,7 @@ class Anc_Operation function save_form_plan($p_array,$p_item,$j_id) { extract($p_array); + if (! isset ($hplan) ) return; /* variable for in array pa_id array of existing pa_id hplan double array with the pa_id (column) diff --git a/include/class_fiche.php b/include/class_fiche.php index 5014ec90b..eb5bc7e44 100644 --- a/include/class_fiche.php +++ b/include/class_fiche.php @@ -728,10 +728,11 @@ class Fiche foreach ($p_array as $name=>$value ) { /* avoid the button for searching an accounting item */ - if ( $name=='av_text5_bt') continue; - list ($id) = sscanf ($name,"av_text%d"); - if ( $id == null ) continue; + if ( preg_match('/^av_text[0-9]+$/',$name) == 0) continue; + list ($id) = sscanf ($name,"av_text%d"); + if ( $id == null ) continue; + // Special traitement // quickcode if ( $id == ATTR_DEF_QUICKCODE) @@ -831,18 +832,21 @@ class Fiche // parse the $p_array array foreach ($p_array as $name=>$value ) { + if ( preg_match('/^av_text[0-9]+$/',$name) == 0) continue; + list ($id) = sscanf ($name,"av_text%d"); + if ( $id == null ) continue; // retrieve jft_id to update table attr_value $sql=" select jft_id from fiche_detail where ad_id=$id and f_id=$this->id"; $Ret=$this->cn->exec_sql($sql); - if ( Database::num_row($Ret) != 1 ) + if ( Database::num_row($Ret) == 0 ) { // we need to insert this new attribut $jft_id=$this->cn->get_next_seq('s_jnt_fic_att_value'); - $sql2=sprintf("insert into fiche_detail(jft_id,ad_id,f_id,ad_value) values ($1,$2,$3,NULL)"); + $sql2="insert into fiche_detail(jft_id,ad_id,f_id,ad_value) values ($1,$2,$3,NULL)"; $ret2=$this->cn->exec_sql($sql2,array($jft_id,$id,$this->id)); @@ -956,23 +960,22 @@ class Fiche } if ( $id == ATTR_DEF_COMPANY ) { - $exist=$this->cn->count_sql("select f_id from fiche join fiche_def using (fd_id) ". + $exist=$this->cn->exec_sql("select f_id from fiche join fiche_def using (fd_id) ". " join fiche_detail using (f_id) ". - " where frd_id in (8,9,14) and ad_id=".ATTR_DEF_QUICKCODE. - " and ad_value='".FormatString($value)."'"); + " where frd_id in (8,9,14) and ad_id=$1 ". + " and ad_value=upper($2)", + array(ATTR_DEF_QUICKCODE,$value)); - if ( $exist == 0 && FormatString($value) != null ) + if ( Database::num_row($exist) == 0 && FormatString($value) != null ) { $value="Attention : pas de société "; } } // Normal traitement - $value2=FormatString($value); - $sql=sprintf("update fiche_detail set ad_value='%s' where jft_id=%d", - trim($value2),$jft_id); - $this->cn->exec_sql($sql); + $sql="update fiche_detail set ad_value=upper($1) where jft_id=$2"; + $this->cn->exec_sql($sql,array($value,$jft_id)); } } catch (Exception $e ) diff --git a/include/class_html_table.php b/include/class_html_table.php index 2d2eb4a39..31a3803ae 100644 --- a/include/class_html_table.php +++ b/include/class_html_table.php @@ -73,10 +73,10 @@ class Html_Table } @endcode */ - static function sql2table($cn,$a_col,$sql,$table_style="result",$a_sql_var=null) + static function sql2table($cn,$a_col,$sql,$table_style='class="result"',$a_sql_var=null) { $r=''; - $r=sprintf('