var
_pttype,_aid,_vn,ds1,ds2:string;
d1,d2:tdatetime;
procedure GlobalOnCreate;
begin
GetDateRangeDialog(d1, d2);
ds1:=formatdatetime('yyyy-mm-dd',d1);
ds2:=formatdatetime('yyyy-mm-dd',d2);
_pttype:=GetMultipleList('select concat(pttype," : ",name) as wd '+
' from pttype order by pttype');
if _pttype<>'' then
begin
_pttype:=getsqlsubquerydata('select pttype from pttype '+
' where concat(pttype," : ",name) in ('+_pttype+')');
_aid:=GetMultipleList('select distinct concat(if(v.moopart="","-",concat("Á.",abs(v.moopart)))," ",t.full_name) as wd '+
' from vn_stat v '+
' left outer join thaiaddress t on v.aid=t.addressid '+
' where v.vstdate between "'+ds1+'" and "'+ds2+'" '+
' and v.pttype in ('+_pttype+') '+
' order by t.addressid,v.moopart');
if _aid<>'' then
begin
_vn:=getsqlsubquerydata('select v.vn '+
' from vn_stat v '+
' left outer join thaiaddress t on v.aid=t.addressid '+
' where v.vstdate between "'+ds1+'" and "'+ds2+'" '+
' and concat(if(v.moopart="","-",concat("Á.",abs(v.moopart)))," ",t.full_name) in ('+_aid+')');
if _vn<>'' then
ChangeReportSQL('select if(v.income>=700,700,round(v.income,0)) as claim,v.*,p.name as pttype_name,pc.cardno,concat(pa.pname,pa.fname," ",pa.lname) as wd, '+
' concat(h.hosptype,h.name) as wd1, '+
' concat(if(v.moopart="","-",concat("Á.",abs(v.moopart)))) as wd2, '+
' if(v.sex="1","ªÒÂ","Ë­Ô§") as wd3'+
' from vn_stat v '+
' left outer join pttype p on v.pttype=p.pttype '+
' left outer join ptcardno pc on v.hn=pc.hn '+
' left outer join patient pa on v.hn=pa.hn '+
' left outer join hospcode h on v.hospmain=h.hospcode '+
' where v.vn in ('+_vn+') '+
' and v.income>0');
end;
end;
end;