[run]
begin
update :TableName T set UseDate=BuildDate where billtag<>1362 and T.OrgID = :CurOrgID :CondSign;
update :TableName T set OrgnValue=0  where JiaZXSID=4 and T.OrgID = :CurOrgID :CondSign;
update :TableName T set QuanSZH='', QuanSZM='', FaZSJ=null,TuDZZMMJ=0 where (billtag=1369 or billtag=1363) and ChanQXSID=2 and T.OrgID = :CurOrgID :CondSign;
update :TableName T set QiZYSWSR=0, QiZCZXJYZJ=0, CaiZXJFLY=0, ShiYSR=0, QiTJFLY=0 where JiaZXSID=4 and T.OrgID = :CurOrgID :CondSign;
update :TableName T set ChuJDW='' where (billtag=1369 or billtag=1363) and (ChuJMJ=0 or ChuJMJ is null) and T.OrgID = :CurOrgID :CondSign;
update :TableName T set ChuZDW='' where (billtag=1369 or billtag=1363) and (ChuZMJ=0 or ChuZMJ is null) and T.OrgID = :CurOrgID :CondSign;
update :TableName T set JiLDWCZB= ( select jldw from JC_AssetCatalog t1 where T.CatalogID=t1.rwid) where T.OrgID = :CurOrgID :CondSign;
update :TableName T set BillStdCode=substr(BillCode, length(BillCode) - 8, 9) where T.OrgID = :CurOrgID :CondSign;
update :TableName T set JunJ=OrgnValue/TuDMJ where billtag=1369 and TuDMJ<> 0 and T.OrgID = :CurOrgID  :CondSign;
update :TableName T set ZiYJZ=ZiYMJ*OrgnValue/TuDMJ where billtag=1369 and TuDMJ<> 0 and T.OrgID = :CurOrgID  :CondSign;
update :TableName T set ChuJJZ=ChuJMJ*OrgnValue/TuDMJ  where billtag=1369 and TuDMJ<> 0 and T.OrgID = :CurOrgID  :CondSign;
update :TableName T set ChuZJZ=ChuZMJ*OrgnValue/TuDMJ where billtag=1369 and TuDMJ<> 0 and T.OrgID = :CurOrgID  :CondSign;
update :TableName T set DuiWTZJZ=DuiWTZMJ*OrgnValue/TuDMJ where billtag=1369 and TuDMJ<> 0 and T.OrgID = :CurOrgID  :CondSign;
update :TableName T set DanBJZ=DuiBMJ*OrgnValue/TuDMJ where billtag=1369 and TuDMJ<> 0 and T.OrgID = :CurOrgID  :CondSign;
update :TableName T set QiTJZ=QiTMJ*OrgnValue/TuDMJ where billtag=1369 and TuDMJ<> 0 and T.OrgID = :CurOrgID :CondSign;
update :TableName T set JunJ=OrgnValue/JianZMJ where billtag=1363 and JianZMJ<> 0 and T.OrgID = :CurOrgID :CondSign;
update :TableName T set ZiYJZ=ZiYMJ*OrgnValue/JianZMJ where billtag=1363 and JianZMJ<> 0 and T.OrgID = :CurOrgID :CondSign;
update :TableName T set ChuJJZ=ChuJMJ*OrgnValue/JianZMJ where billtag=1363 and JianZMJ<> 0 and T.OrgID = :CurOrgID :CondSign;
update :TableName T set ChuZJZ=ChuZMJ*OrgnValue/JianZMJ where billtag=1363 and JianZMJ<> 0 and T.OrgID = :CurOrgID :CondSign;
update :TableName T set DuiWTZJZ=DuiWTZMJ*OrgnValue/JianZMJ where billtag=1363 and JianZMJ<> 0 and T.OrgID = :CurOrgID :CondSign;
update :TableName T set DanBJZ=DuiBMJ*OrgnValue/JianZMJ where billtag=1363  and JianZMJ<> 0 and T.OrgID = :CurOrgID :CondSign;
update :TableName T set QiTJZ=QiTMJ*OrgnValue/JianZMJ where billtag=1363 and JianZMJ<> 0 and T.OrgID = :CurOrgID :CondSign;
update :TableName T set QiTJZ=0, ZiYJZ=0,ChuZJZ=0,ChuJJZ=0,DanBJZ=0, DuiWTZJZ=0 where (billtag=1369 or billtag=1363) and JiaZXSID=4 and T.OrgID = :CurOrgID :CondSign;
update :TableName T set ChuZCJDFDW='' where (billtag=1352 or billtag=1356 or billtag=1362 or billtag=1374 or billtag=1365 or billtag=1358 or billtag=1367 or billtag=1377) and (UsedwayBDID<>3 and UsedwayBDID<>4) and T.OrgID = :CurOrgID :CondSign;
update :TableName T set ShiYRID=0 where (billtag=1352 or billtag=1356 or billtag=1362 or billtag=1374 or billtag=1365 or billtag=1358 or billtag=1367 or billtag=1377 or billtag=1372) and IsUsed=1 and T.OrgID = :CurOrgID :CondSign;
update :TableName T set ZuoLWZ='' where Exists(select * from jc_assetcatalog jc where T.catalogid=jc.rwid and jc.stdcode like '862%' and billtag=1372) and T.OrgID = :CurOrgID :CondSign;
update :TableName T set PlaceID=0 where Exists(select * from jc_assetcatalog jc where catalogid=jc.rwid and jc.stdcode like '861%' and billtag=1372) and T.OrgID = :CurOrgID :CondSign;
end;

[save]
select
	T.RwID,
	T.BillCode,
	T.StdName,
	'ChePH' FName1,
	0 FType1,
	case when ChePH<>'' and (ChangPXH='' or ChangPXH is null or CheJH='' or CheJH is null or PaiQL=0 or PaiQL is null ) and billtag=1362 then '如果填写车牌号，建议补全厂牌型号、车架号和排气量的信息！' else '' end FDes1,
	'ExptMonth' FName2, 
	2 FType2, 
	case when T.ExptMonth<0 and billtag<>1372 then'使用年限不能为负' else '' end FDes2,
	'OrgnValue' FName3,
	2 FType3,
	case when billtag=1369 and JiaZXSID<>4 and OrgnValue<=0 then '请填写资产价值且价值不能为负数！'  else '' end FDes3,
	'QuanSZM' FName4,
	2 FType4,
	case when (billtag=1369 or billtag=1363) and ChanQXSID=1 and (QuanSZM is null or QuanSZM='') then '当产权形式是有产权的时候，请输入权属证明' else '' end FDes4,
	'QuanSZH' FName5,
	2 FType5,
	case when (billtag=1369 or billtag=1363) and ChanQXSID=1 and (QuanSZH is null or QuanSZH='') then '当产权形式是有产权的时候，请输入权属证号' else '' end FDes5,
	'FaZSJ' FName6,
	2 FType6, 
	case when (billtag=1369 or billtag=1363) and ChanQXSID=1 and To_Char(FaZSJ, 'YYYY')='1899' then '当产权形式是有产权的时候，请输入发证时间！' else '' end FDes6,
	'TuDZZMMJ' FName7,
	2 FType7,
	case when billtag=1369 and ChanQXSID=1 and (TuDZZMMJ is null or TuDZZMMJ=0) then '当产权形式是有产权的时候，土地证载明面积不能为空！' else '' end FDes7,
	'ZiYMJ' FName8,
	2 FType8,
	case when (billtag=1369 or billtag=1363) and ZiYMJ<0 then '自用面积不能为负数，请重新录入！' else '' end FDes8,
	'DuiBMJ' FName9,
	2 FType9,
	case when (billtag=1369 or billtag=1363) and DuiBMJ<0 then '担保面积不能为负数，请重新录入！' else '' end FDes9,
	'ChuJMJ' FName10,
	2 FType10,
	case when (billtag=1369 or billtag=1363) and ChuJMJ<0 then '出借面积不能为负数，请重新录入！' else '' end FDes10,
	'ChuZMJ' FName11,
	2 FType11,
	case when (billtag=1369 or billtag=1363) and ChuZMJ<0 then '出租面积不能为负数，请重新录入！' else '' end FDes11,
	'DuiWTZMJ' FName12,
	2 FType12,
	case when (billtag=1369 or billtag=1363) and DuiWTZMJ<0 then '对外面积不能为负数，请重新录入！' else '' end FDes12,
	'QiTMJ' FName13,
	2 FType13,
	case when (billtag=1369 or billtag=1363) and QiTMJ<0 then '其他面积不能为负数，请重新录入！' else '' end FDes13,
	'CaiZXJFLY' FName14,
	2 FType14,
	case when (OrgnValue<>CaiZXJFLY+QiTJFLY+ShiYSR) and BillTag <> 1592 and BillTag <> 13 then '价值必须等于经费来源中财政拨款、事业收入、其他资金之和'  else '' end FDes14,
	'QiZYSWSR' FName15,
	2 FType15,
	case when QiZYSWSR>ShiYSR then '经费来源中的其中预算外收入不能大于事业收入，请重新录入!'  else '' end FDes15,
	'QiZCZXJYZJ' FName16,
	2 FType16,
	case when QiZCZXJYZJ>QiTJFLY then '经费来源中的其中财政性结余资金不能大于其他资金，请重新录入!' else '' end FDes16,
	'JiLDWCZB' FName17,
	2 FType17,
	case when (JiLDWCZB is null or JiLDWCZB='') and BillTag <> 1592 and BillTag <> 13 then '请填写计量单位'  else '' end FDes17,
	'CaiZXJFLY' FName18,
	2 FType18,
	case when CaiZXJFLY<0 then '财政拨款不能为负，请重新录入！'  else '' end FDes18,
	'QiTJFLY' FName19,
	2 FType19,
	case when QiTJFLY<0 then '其他资金不能为负，请重新录入！'  else '' end FDes19,
	'ShiYSR' FName20,
	2 FType20, 
	case when ShiYSR<0 then '事业收入不能为负'  else '' end FDes20,
	'QiZYSWSR' FName21,
	2 FType21, 
	case when QiZYSWSR<0  then '其中预算外资金不能为负' else '' end FDes21,
	'QiZCZXJYZJ' FName22,
	2 FType22, 
	case when QiZCZXJYZJ<0  then '其中财政性结余资金不能为负'  else '' end FDes22,
	'QTY' FName23,
	2 FType23, 
	case when (billtag=1369 or billtag=1363 or billtag=1352 or billtag=1356 or billtag=1362 or billtag=1374 or billtag=1365 or billtag=1358 or billtag=1592) and QTY<>1 then '请填写数量且必须为1！'  else '' end FDes23,
	'QTY' FName24,
	2 FType24, 
	case when (billtag=1367 or billtag=1372 or billtag=1377) and QTY<0  then '资产数量必须为大于零的整数' else '' end FDes24,
	'TuDMJ' FName25,
	2 FType25,
	case when billtag=1369 and TuDMJ<0  then '土地面积不能为负' else '' end FDes25,
	'DPRCTState' FName26,
	2 FType26,  
	case when (billtag=1363 or billtag=1352 or billtag=1356 or billtag=1362 or billtag=1374 or billtag=1365 or billtag=1358 or billtag=1367 or billtag=1377) and DPRCTState=182 and (T.ExptMonth<0 or T.ExptMonth is null) then '请填写折旧信息中的使用年限(月份)！' else '' end FDes26,
	'DPRCTState' FName27,
	2 FType27,  
	case when (billtag=1363 or billtag=1352 or billtag=1356 or billtag=1362 or billtag=1374 or billtag=1365 or billtag=1358 or billtag=1367 or billtag=1377)  and DPRCTState=182 and (DPRCTWayID=0 or DPRCTWayID is null) then '请填写折旧信息中的折旧方法！' else '' end FDes27,
	'ZiYJZ' FName28,
	2 FType28,
	case when billtag=1369 and OrgnValue<>QiTJZ+ZiYJZ+ChuJJZ+ChuZJZ+DanBJZ+DuiWTZJZ then '价值必须等于自用价值、出租价值、出借价值、对外投资价值、担保价值和其他价值之和' else '' end FDes28,
	'ZiYJZ' FName29,
	2 FType29,
	case when (billtag=1369 or billtag=1363) and ZiYJZ<0 then '自用价值不能为负，请重新录入！'  else '' end FDes29,
	'ChuZJZ' FName30,
	2 FType30,  
	case when (billtag=1369 or billtag=1363) and ChuZJZ<0  then '出租价值不能为负，请重新录入！'  else '' end FDes30,
	'ChuJJZ' FName31,
	2 FType31, 
	case when (billtag=1369 or billtag=1363) and ChuJJZ<0  then '出借价值不能为负，请重新录入！'  else '' end FDes31,
	'DanBJZ' FName32,
	2 FType32,
	case when (billtag=1369 or billtag=1363) and DanBJZ<0  then '担保价值不能为负，请重新录入！'  else '' end FDes32,
	'DuiWTZJZ' FName33,
	2 FType33,  
	case when (billtag=1369 or billtag=1363) and DuiWTZJZ<0 then '对外投资价值不能为负，请重新录入！'  else '' end FDes33,
	'QiTJZ' FName34,
	2 FType34,  
	case when (billtag=1369 or billtag=1363) and QiTJZ<0 then '其他价值不能为负，请重新录入！' else '' end FDes34,
	'TuDMJ' FName35,
	2 FType35,
	case when billtag=1369 and TuDMJ <> ZiYMJ+ChuJMJ+ChuZMJ+DuiWTZMJ+DuiBMJ+QiTMJ then '使用方向的面积之和必须等于土地面积，请重新录入！'  else '' end FDes35,
	'BanGSMJ' FName36,
	2 FType36,
	case when billtag=1363 and BanGSMJ<0 then '办公室面积不能为负数，请重新录入！' else '' end FDes36,
	'HuiYSMJ' FName37,
	2 FType37,
	case when billtag=1363 and HuiYSMJ<0 then '会议室面积不能为负数，请重新录入！'  else '' end FDes37,
	'CheKMJ' FName38,
	2 FType38,  
	case when billtag=1363 and CheKMJ<0 then '车库面积不能为负数，请重新录入！'  else '' end FDes38,
	'ShiTMJ！' FName39,
	2 FType39,  
	case when billtag=1363 and ShiTMJ<0  then '食堂面积不能为负数，请重新录入！'  else '' end FDes39,
	'PeiDSMJ' FName40,
	2 FType40,  
	case when billtag=1363 and PeiDSMJ<0 then '配电室面积不能为负数，请重新录入！'  else '' end FDes40,
	'JiFMJ' FName41,
	2 FType41,  
	case when billtag=1363 and JiFMJ<0 then '机房面积不能为负数，请重新录入！'  else '' end FDes41,
	'ShiYMJ' FName42,
	2 FType42,  
	case when billtag=1363 and ShiYMJ<0 then '使用面积不能为负数，请重新录入！'  else '' end FDes42,
	'DiaXMJ' FName43,
	2 FType43,  
	case when billtag=1363 and DiaXMJ<0 then '地下面积不能为负数，请重新录入！'  else '' end FDes43,
	'JianZMJ' FName44,
	2 FType44,  
	case when billtag=1363 and JianZMJ<HuiYSMJ+CheKMJ+ShiTMJ+PeiDSMJ+JiFMJ+BanGSMJ then '建筑面积大于等于各个面积之和，请重新录入！'  else '' end FDes44,
	'JianZMJ' FName45,
	2 FType45,   
	case when billtag=1363 and JianZMJ<>ZiYMJ+ChuJMJ+ChuZMJ+DuiWTZMJ+DuiBMJ+QiTMJ  then '建筑面积必须等于使用方向及面积之和' else '' end FDes45,
	'JianZMJ' FName46,
	2 FType46,  
	case when billtag=1363 and JianZMJ<ShiYMJ then '使用面积应小于等于建筑面积，请确认！'  else '' end FDes46,
	'JianZMJ' FName47,
	2 FType47,  
	case when billtag=1363 and JianZMJ<DiaXMJ  then '地下面积应小于等于建筑面积，请确认！'  else '' end FDes47,
	'Remark' FName48,
	2 FType48,
	case when ((UsedwayBDID=8 and (billtag<>1369 and billtag<>1363)) or (billtag=1363 and JianZJGID=5) or (CGZZXSID=4 or UsedStateBDID=7) or (billtag=1369 or billtag=1363) and QiTMJ>0  or SrcID=8) and (Remark='' or Remark is null) then '所选项有其他，备注不可为空'  else '' end FDes48,
	'UsedwayBDID' FName53,
	2 FType53,  
	case when (billtag=1352 or billtag=1356 or billtag=1362 or billtag=1374 or billtag=1365 or billtag=1358 or billtag=1367 or billtag=1377) and (UsedwayBDID=3 or UsedwayBDID=4) and (ChuZCJDFDW='' or ChuZCJDFDW is null) then '请输入出租出借单位'  else '' end FDes53,
	'UsedStateBDID' FName54,
	2 FType54,  
	case when UsedStateBDID=0 or UsedStateBDID is null then '使用状况不能为空！' else '' end FDes54,
	'ZhuanLH' FName55,
	2 FType55,  
	case when (ZhuanLH='' or ZhuanLH is null) and CatalogID=8535 and billtag=1592 then '当资产类别为“专利权”时，“专利号”必须填写！'  else '' end FDes55,
	'PingGJZ' FName56,
	2 FType56,  
	case when  (PingGJZ<0 or PingGJZ is null) and billtag=1592 then '评估价值不能为负，请重新输入！'  else '' end FDes56,
	'CatalogID' FName57,
	2 FType57,  
	case when (CatalogID=0 or CatalogID is null) then '资产分类代码必填！'  else '' end FDes57,
	'StdName' FName58,
	2 FType58,   
	case when (T.StdName='' or T.StdName is null)  then '资产名称必填！'  else '' end FDes58,
	'JiLDWCZB' FName59,
	2 FType59,  
	case when (JiLDWCZB='' or JiLDWCZB is null) and BillTag <> 1592 and BillTag <> 13  then '计量单位必填！'  else '' end FDes59,
	'SrcID' FName60,
	2 FType60,  
	case when (SrcID=0 or SrcID is null) then '取得方式必填！' else '' end FDes60,
	'BuildDate' FName61,
	2 FType61,  
	case when To_Char(BuildDate, 'YYYY')='1899' or BuildDate is null then '取得日期必填！'  else '' end FDes61,
	'ChanQXSID' FName62,
	2 FType62,  
	case when (ChanQXSID=0 or ChanQXSID is null) and (billtag=1369 or billtag=1363) then '产权形式必填！'  else '' end FDes62, 
	'QuanSXZID' FName63,
	2 FType63,  
	case when (QuanSXZID=0 or QuanSXZID is null) and billtag=1369  then '权属性质必填！' else '' end FDes63,
	'ZuoLWZ' FName64,
	2 FType64,  
	case when (ZuoLWZ='' or ZuoLWZ is null) and (billtag=1369 or billtag=1363)  then '坐落位置必填！' else '' end FDes64,
	'JiaZXSID' FName65,
	2 FType65,  
	case when JiaZXSID=0 or JiaZXSID is null  then '价值类型必填！'  else '' end FDes65,
	'TuDMJ' FName66,
	2 FType66,   
	case when (TuDMJ=0 or TuDMJ is null) and billtag=1369  then '土地面积必填！' else '' end FDes66,
	'BMID' FName67,
	2 FType67,  
	case when (BMID=0 or BMID is null) and BillTag <> 1592 and BillTag <> 13 then '使用/管理部门必填！'  else '' end FDes67,
	'DPRCTState' FName68,
	2 FType68,  
	case when (DPRCTState=0 or DPRCTState is null) and (billtag=1363 or billtag=1352 or billtag=1356 or billtag=1362 or billtag=1374 or billtag=1365 or billtag=1358 or billtag=1367 or billtag=1377) then '折旧状态必填！'  else '' end FDes68,
	'UsedwayBDID' FName69,
	2 FType69,  
	case when (UsedwayBDID=0 or UsedwayBDID is null) and (billtag=1352 or billtag=1356 or billtag=1362 or billtag=1374 or billtag=1365 or billtag=1358 or billtag=1367 or billtag=1372 or billtag=1377 or billtag=1592) then '使用方向必填！'  else '' end FDes69,
	'BianZQKID' FName70,
	2 FType70,  
	case when  (BianZQKID=0 or BianZQKID is null) and billtag=1362  then '编制情况必填！'  else '' end FDes70,
	'GuoZWJL' FName71,
	2 FType71,
	case when T.catalogid=jc.rwid and jc.stdcode like '03%' and (T.GuoZWJL=0 or T.GuoZWJL is null) and T.billtag=1363 then '当资产分类属于构筑物时，请填写构筑物计量！'  else '' end FDes71,
	'YongTFLID' FName72,
	2 FType72,
	case when jc.stdcode like '53%' and (T.YongTFLID=0 or T.YongTFLID is null) and T.billtag=1362  then '资产分类选择汽车、电车（含地铁车辆）、摩托车及非机动车辆，用途分类必填'  else '' end FDes72,
	'PlaceID' FName73,
	2 FType73,
	case when jc.stdcode like '862%' and (T.PlaceID=0 or T.PlaceID is null) and T.billtag=1372  then '请输入存放地点'  else '' end FDes73,
	'ZuoLWZ' FName74,
	2 FType74,
	case when jc.stdcode like '861%' and (ZuoLWZ='' or ZuoLWZ is null) and T.billtag=1372 then '请输入坐落位置'  else '' end FDes74,
	'RMValueRate' FName75,
	2 FType75, 
	case when T.DPRCTState=182 and T.billtag<>1592 and T.billtag <> 1369 and (T.RMValueRate < 0 or T.RMValueRate > 1) then'残值率不能为负数或者大于1！' else '' end FDes75,
	'DeValue' FName76,
	2 FType76, 
	case when T.DPRCTState=182 and T.billtag<>1592 and T.billtag <> 1369 and (T.DeValue< 0 or T.DeValue> T.OrgnValue) then'减值准备不能为负数或者大于价值！' else '' end FDes76,
	'UsedMonth' FName77,
	2 FType77, 
	case when T.DPRCTState=182 and T.billtag<>1592 and T.billtag <> 1369 and T.UsedMonth> T.ExptMonth  then'已提折旧月数应小于等于使用年限（月份）！' else '' end FDes77,
	'RMValue' FName78,
	2 FType78, 
	case when T.DPRCTState=182 and T.billtag<>1592 and T.billtag <> 1369 and (round(isnull(T.RMValue,0),2) <> round(T.OrgnValue*T.RMValueRate,2)) then '预计残值不等于原值*残值率，请修改！' else '' end FDes78,
	'DPRCTTotal' FName79,
	2 FType79, 
	case when T.DPRCTState=182 and T.billtag<>1592 and T.billtag <> 1369 and (T.DPRCTTotal> T.OrgnValue) then '累计折旧大于原值，请修改！' else '' end FDes79,
	'RMValue' FName80,
	2 FType80, 
	case when T.DPRCTState=182 and T.billtag<>1592 and T.billtag <> 1369 and T.RMValue> (T.OrgnValue-isnull(T.DPRCTTotal,0)) then '预计残值不能大于原值减累计折旧，请修改！' else '' end FDes80

from :TableName T
left join jc_assetcatalog jc on T.catalogid=jc.rwid
where T.OrgID = :CurOrgID :CondSign
order by T.RwID

[billcode]
begin
  update :TableName h
     set billstdcode = substr(cast((nvl(:CardPipeNum, 1) + H.rwid + 1000000000) as varchar(10)), 2, 9);
  update :TableName h
     set billcode = (select Max(nvl(s.orgunitcode, '000000000')) || h.billstdcode from sys_orgunit s where h.orgid = s.rwid)
   where exists (select 1 from sys_orgunit s2 where h.orgid = s2.rwid);
end;

[cfmExec]
begin
  Update :TableName T set ConfirmFlag=1, Confirmer=':CurUserName', ConfirmDate= to_date(to_char(sysdate, 'YYYY-MM-DD'), 'yyyy-mm-dd') where T.OrgID = :CurOrgID :CondSign;
  insert into "GD_ASSETOPTSERIES"("BILLDATE","BILLTAG","BILLRWID","CARDID","OPTTYPE","OPTDESCRIP","OPERATER","REMARK","ORGID","ZTYEAR","ISSCRAP")
    select confirmdate, billtag, rwid, rwid, '新增卡片','新增卡片',':CurUserName',remark,OrgID,ZTYear, Isscrap from gd_assetcard_h where OrgID = :CurOrgID :CondSign;
  Update DCT_BillTranRec set BillState=3, RwVrsn = RwVrsn +1 where billguid in (select g_id from :TableName where OrgID = :CurOrgID :CondSign);
end;

