/* 	差旅报销单历史数据升级：根据2019.4.1日及以后已报销的机票订单，插入对应差旅报销单发票分录 wenyue_chi**/

DELETE from t_er_invoiceinfo where FENTRYID in( SELECT  LEFT(FID,17)  from t_er_planebill where ftakeofftime >={ts'2019-04-01 00:00:00'}  and FISREIMBURSE=1);
insert into t_er_invoiceinfo (fid,FENTRYID,finvoiceno,finvoicetype,finvoicecode,finvoicedate,ftotalamount,falltaxrate,ftaxamount,fpassengername,foffset,foffsetamount,fcount,ffrominvoicecloud,fairportconstructionfee,finvoicefrom) SELECT rm.FID as FID ,LEFT(p.FID,17) as fentryid,p.fticketNum,'10',IFNULL(DATE_FORMAT(p.fitinerarydate,'%Y%m%d'),0),p.fitinerarydate,p.ftotalAmount-p.fserviceFee,'9',(p.FTICKETPRICE+p.FFUELPRICE)*0.09/1.09,p.ftravelerName,1,(p.FTICKETPRICE+p.FFUELPRICE)*0.09/1.09,1,0,p.fairportPrice,'3' from T_ER_PLANEBILL p,t_er_reqbill r,T_ER_REIMBURSEBILL rm where r.FBILLNO=p.FOABILLNUM and  rm.FSOURCEBILLID = r.fid and p.ftakeofftime >={ts'2019-04-01 00:00:00'} and p.FISREIMBURSE=1 and rm.fbillstatus NOT IN('H') and p.FORDERSORT='1';