Code gestion is now of type card, create a fake stock card category and fill it with existing used code gestion

This commit is contained in:
Dany De Bontridder 2012-06-16 17:35:59 +00:00
parent b4851fae8b
commit 55672defeb
3 changed files with 54 additions and 9 deletions

View file

@ -61,7 +61,7 @@ if ( $d == 'all')
}
else if (strpos($d,'sql]')==true)
{
$filter_card= str_replace('[sql]', "", $d);
$filter_card= str_replace('[sql]', " and ", $d);
} else
$filter_card="and fd_id in ($d)";

View file

@ -337,12 +337,15 @@ class Fiche
* \see constant.php
* \return string
*/
function strAttribut($p_ad_id)
function strAttribut($p_ad_id,$p_return=1)
{
$return=($p_return==1)?NOTFOUND:"";
if ( sizeof ($this->attribut) == 0 )
{
if ($this->id==0) return NOTFOUND;
if ($this->id==0) {
return $return;
}
// object is not in memory we need to look into the database
$sql="select ad_value from fiche_detail
where f_id= $1 and ad_id= $2 ";
@ -350,7 +353,7 @@ class Fiche
$row=Database::fetch_all($Res);
// if not found return error
if ( $row == false )
return NOTFOUND;
return $return;
return $row[0]['ad_value'];
}
@ -360,7 +363,7 @@ class Fiche
if ( $e->ad_id == $p_ad_id )
return $e->av_text;
}
return NOTFOUND;
return $return;
}
/*!\brief make an array of attributes of the category of card (FICHE_DEF.FD_ID)
*The array can be used with the function insert, it will return a struct like this :
@ -660,7 +663,9 @@ class Fiche
$w->value = $r->av_text;
break;
case 'card':
$uniq=rand(0,1000);
$w = new ICard("av_text" . $r->ad_id);
$w->id="card_".$this->id.$uniq;
// filter on ad_extra
$filter = $r->ad_extra;
@ -668,11 +673,22 @@ class Fiche
$w->extra = $filter;
$w->extra2 = 0;
$label = new ISpan();
$label->name = "av_text" . $r->ad_id . "_label";
$label->name = "av_text" .$uniq. $r->ad_id . "_label";
$fiche=new Fiche($this->cn);
$fiche->get_by_qcode($r->av_text);
if ($fiche->id == 0 )
{
$label->value=(trim($r->av_text)=='')?"":" Fiche non trouvé ";
$r->av_text="";
} else
{
$label->value=$fiche->strAttribut(ATTR_DEF_NAME)." ".$fiche->strAttribut(ATTR_DEF_FIRST_NAME,0);
}
$w->set_attribute('ipopup', 'ipopcard');
$w->set_attribute('typecard', $filter);
$w->set_attribute('inp', "av_text" . $r->ad_id);
$w->set_attribute('label', "av_text" . $r->ad_id . "_label");
$w->set_attribute('label', $label->name);
$w->autocomplete=0;
$w->dblclick="fill_ipopcard(this);";
$msg = $w->search();
$msg.=$label->input();
@ -711,7 +727,7 @@ class Fiche
$w->readOnly = $p_readonly;
$ret.="<TR>" . td($r->ad_text . $bulle) . td($w->input()) . td($msg) . " </TR>";
$ret.="<TR>" . td($r->ad_text . $bulle) . td($w->input()." ". $msg) . " </TR>";
}
$ret.="</table>";

View file

@ -286,4 +286,33 @@ insert into profile_menu(me_code,me_code_dep,p_id,p_order,p_type_display) values
delete from stock_goods where sg_code is null or sg_code='' or sg_code not in (select ad_value from fiche_detail as fd where ad_id=19 and ad_value is not null);
CREATE INDEX fki_jrnx_j_grpt ON jrnx (j_grpt );
CREATE INDEX fki_jrn_jr_grpt_id ON jrn (jr_grpt_id );
CREATE INDEX fki_jrn_jr_grpt_id ON jrn (jr_grpt_id );
--
insert into fiche_def (fd_id,frd_id,fd_label) values (500000,15,'Stock');
insert into jnt_fic_attr (fd_id,ad_id,jnt_order) values (500000,1,10);
insert into jnt_fic_attr (fd_id,ad_id,jnt_order) values (500000,9,20);
insert into jnt_fic_attr (fd_id,ad_id,jnt_order) values (500000,23,30);
create or replace function migrate_stock() returns void
as
$body$
declare
rt_row text;
n_fid bigint;
begin
for rt_row in select distinct ad_value from fiche_Detail where ad_id=19 and ad_value is not null and ad_Value <> ''
loop
insert into fiche (fd_id) values(500000) returning f_id into n_fid;
insert into fiche_detail (f_id,ad_id,ad_value) values (n_fid,1,rt_row);
insert into fiche_detail (f_id,ad_id,ad_value) values (n_fid,9,'Code stock '||rt_row);
insert into fiche_detail (f_id,ad_id,ad_value) values (n_fid,23,'STOCK'||n_fid::text);
update fiche_detail set ad_value='STOCK'||n_fid::text where ad_id=19 and ad_value=rt_row;
end loop;
end;
$body$ language plpgsql;
select migrate_stock();
drop function migrate_stock();