FrmAttendanceReport.xml 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <Forms>
  3. <Form Name="FrmAttendanceReport">
  4. <Client>
  5. <Events>
  6. <Load>
  7. <![CDATA[
  8. @Title="考勤报告";
  9. GetSchema();
  10. txtCoNo.CValue=GetCurrentCompanyNo();
  11. txtCoName.CValue=GetCurrentCompanyShortName();
  12. ChangeMode("Search");
  13. ]]>
  14. </Load>
  15. <Closing>
  16. ;
  17. </Closing>
  18. <Closed>
  19. ;
  20. </Closed>
  21. </Events>
  22. <Mode>
  23. <Search>
  24. <Lable name="Search"/>
  25. </Search>
  26. </Mode>
  27. <Controls>
  28. <IKDateTimePicker name="dtStart" DataSource="UI.StartDate">
  29. <Events>
  30. <ValueChanged>
  31. dtEnd.CValue = dtStart.CValue;
  32. </ValueChanged>
  33. </Events>
  34. </IKDateTimePicker>
  35. <IKDateTimePicker name="dtEnd" DataSource="UI.EndDate"/>
  36. <IKTextButton name="tbEmployee1" DataSource="UI.StartNo_Employee">
  37. <Events>
  38. <Click>
  39. <![CDATA[
  40. @temp = ShowSearchBox("EmployeeSearch","INFOMATION",tbEmployee1.CValue);
  41. if( @temp == "" )
  42. return;
  43. tbEmployee1.CValue = @temp;
  44. ]]>
  45. </Click>
  46. <TextBoxButtonTextChanged>
  47. tbEmployee2.CValue = tbEmployee1.CValue;
  48. </TextBoxButtonTextChanged>
  49. </Events>
  50. </IKTextButton>
  51. <IKTextButton name="tbEmployee2" DataSource="UI.EndNo_Employee" >
  52. <Events>
  53. <Click>
  54. <![CDATA[
  55. @temp = ShowSearchBox("EmployeeSearch","INFOMATION",tbEmployee2.CValue);
  56. if( @temp == "" )
  57. return;
  58. tbEmployee2.CValue = @temp;
  59. ]]>
  60. </Click>
  61. </Events>
  62. </IKTextButton>
  63. <IKButton name="btnView">
  64. <Events>
  65. <Click>
  66. @ClickType="View";
  67. <Lable name="Action"/>
  68. </Click>
  69. </Events>
  70. </IKButton>
  71. <IKButton name="btnExcel">
  72. <Events>
  73. <Click>
  74. @ClickType="Excel";
  75. <Lable name="Action"/>
  76. </Click>
  77. </Events>
  78. </IKButton>
  79. <IKButton name="btnWord">
  80. <Events>
  81. <Click>
  82. @ClickType="Word";
  83. <Lable name="Action"/>
  84. </Click>
  85. </Events>
  86. </IKButton>
  87. <IKButton name="btnPrint">
  88. <Events>
  89. <Click>
  90. @ClickType="PrintToPrinter";
  91. <Lable name="Action"/>
  92. </Click>
  93. </Events>
  94. </IKButton>
  95. </Controls>
  96. <ChildForms>
  97. <ChildForm name="EmployeeSearch" DataSource="Employee" SearchFunction="SearchAllEmployee" SearchFunctionByNo="" MappingName="员工" >
  98. <DataColumn Index="0" MappingName="#Employee.No_Employee" HeaderText="员工编号" Width="90" ColumnType="IKDataGridTextBoxColumn" />
  99. <DataColumn Index="1" MappingName="#Employee.Name_Employee" HeaderText="员工名称" Width="90" ColumnType="IKDataGridTextBoxColumn"/>
  100. </ChildForm>
  101. </ChildForms>
  102. </Client>
  103. <Server>
  104. <Tables>
  105. <Table name="UI" Type="Parent">
  106. <GetSchema CmdType="Text" CmdText="SELECT TOP 0 convert(datetime,0) As StartDate,convert(datetime,0) As EndDate,Convert(nvarchar(64),'') As StartNo_Employee,Convert(nvarchar(64),'') As EndNo_Employee
  107. ,convert(nvarchar(64),'') As Name_Creator,convert(datetime,0) As CreateDate, Convert(bit,1) As Combine"/>
  108. </Table>
  109. </Tables>
  110. <Search>
  111. <SearchAttendanceReport CmdType="Text" CmdText="
  112. --CREATE FUNCTION dbo.TimeDiff(@date1 as datetime, @date2 as datetime)
  113. --RETURNS int
  114. --BEGIN
  115. -- return (DatePart(hour,@date2)-DatePart(hour,@date1))*60.0+DatePart(minute,@date2)-DatePart(minute,@date1)
  116. --end
  117. -- CREATE FUNCTION dbo.GetAttendanceHour
  118. --(@OnStuffOne as datetime
  119. --,@OffStuffOne as datetime
  120. --,@OnStuffTwo as datetime
  121. --,@OffStuffTwo as datetime
  122. --,@OnAttendance as datetime
  123. --,@OffAttendance as datetime
  124. --)
  125. --RETURNS decimal(14,1)
  126. --BEGIN
  127. -- Declare @AttendanceHour decimal(14,1)
  128. -- IF(dbo.TimeDiff(@OnAttendance,@OnStuffOne)>0)
  129. -- BEGIN
  130. -- IF(dbo.TimeDiff(@OffAttendance,@OnStuffOne)>0)
  131. -- Set @AttendanceHour=0
  132. -- Else IF (dbo.TimeDiff(@OffAttendance,@OffStuffOne)>0)
  133. -- Set @AttendanceHour=Convert(decimal(14,1),dbo.TimeDiff(@OnStuffOne,@OffAttendance)/60.0)
  134. -- Else if (dbo.TimeDiff(@OffAttendance,@OnStuffTwo)>0)
  135. -- Set @AttendanceHour=Convert(decimal(14,1),dbo.TimeDiff(@OnStuffOne,@OffStuffOne))
  136. -- else if(dbo.TimeDiff(@OffAttendance,@OffStuffTwo)>0)
  137. -- Set @AttendanceHour=Convert(decimal(14,1),(dbo.TimeDiff(@OnStuffOne,@OffStuffOne)+dbo.TimeDiff(@OnStuffTwo,@OffAttendance))/60.0)
  138. -- else
  139. -- Set @AttendanceHour=Convert(decimal(14,1),(dbo.TimeDiff(@OnStuffOne,@OffStuffOne)+dbo.TimeDiff(@OnStuffTwo,@OffStuffTwo))/60.0)
  140. -- END
  141. -- Else IF(dbo.TimeDiff(@OnAttendance,@OffStuffOne)>0)
  142. -- BEGIN
  143. -- IF (dbo.TimeDiff(@OffAttendance,@OffStuffOne)>0)
  144. -- Set @AttendanceHour=Convert(decimal(14,1),dbo.TimeDiff(@OnAttendance,@OffAttendance)/60.0)
  145. -- Else if (dbo.TimeDiff(@OffAttendance,@OnStuffTwo)>0)
  146. -- Set @AttendanceHour=Convert(decimal(14,1),dbo.TimeDiff(@OnAttendance,@OffStuffOne)/60.0)
  147. -- else if(dbo.TimeDiff(@OffAttendance,@OffStuffTwo)>0)
  148. -- Set @AttendanceHour=Convert(decimal(14,1),(dbo.TimeDiff(@OnAttendance,@OffStuffOne)+dbo.TimeDiff(@OnStuffTwo,@OffAttendance))/60.0)
  149. -- else
  150. -- Set @AttendanceHour=Convert(decimal(14,1),(dbo.TimeDiff(@OnAttendance,@OffStuffOne)+dbo.TimeDiff(@OnStuffTwo,@OffStuffTwo))/60.0)
  151. -- END
  152. -- else if(dbo.TimeDiff(@OnAttendance,@OnStuffTwo)>0)
  153. -- BEGIN
  154. -- IF (dbo.TimeDiff(@OffAttendance,@OnStuffTwo)>0)
  155. -- Set @AttendanceHour=0
  156. -- Else if (dbo.TimeDiff(@OffAttendance,@OffStuffTwo)>0)
  157. -- Set @AttendanceHour=Convert(decimal(14,1),dbo.TimeDiff(@OnStuffTwo,@OffAttendance)/60.0)
  158. -- else
  159. -- Set @AttendanceHour=Convert(decimal(14,1),dbo.TimeDiff(@OnStuffTwo,@OffStuffTwo)/60.0)
  160. -- END
  161. -- else if(dbo.TimeDiff(@OnAttendance,@OffStuffTwo)>0)
  162. -- BEGIN
  163. -- IF (dbo.TimeDiff(@OffAttendance,@OffStuffTwo)>0)
  164. -- Set @AttendanceHour=Convert(decimal(14,1),dbo.TimeDiff(@OnAttendance,@OffAttendance)/60.0)
  165. -- else
  166. -- Set @AttendanceHour=Convert(decimal(14,1),dbo.TimeDiff(@OnAttendance,@OffStuffTwo)/60.0)
  167. -- END
  168. -- else
  169. -- Set @AttendanceHour=0
  170. -- return @AttendanceHour
  171. --end
  172. --Declare @StartDate datetime
  173. --Declare @EndDate datetime
  174. --Declare @StartNo_Employee nvarchar(64)
  175. --Declare @EndNo_Employee nvarchar(64)
  176. Declare @ID_Applicant uniqueidentifier
  177. Declare @No_ApplicationBill nvarchar(64)
  178. Declare @Item_ApplicationBill nvarchar(64)
  179. Declare @StartDate_ApplicationBill datetime
  180. Declare @EndDate_ApplicationBill datetime
  181. Declare @OnStuffOne datetime
  182. Declare @OffStuffOne datetime
  183. Declare @OnStuffTwo datetime
  184. Declare @OffStuffTwo datetime
  185. Declare @AppHour decimal(14,1)
  186. Declare @LoopDate datetime
  187. IF Exists (Select * From tempdb.dbo.sysobjects Where id=Object_ID(N'tempdb.dbo.#TempApp'))
  188. DROP TABLE #TempApp
  189. Create Table #TempApp
  190. (
  191. ID_Applicant uniqueidentifier,
  192. Date varchar(10),
  193. OvertimeHour decimal(14,1),
  194. BusinessHour decimal(14,1),
  195. CompassionateHour decimal(14,1),
  196. SickHour decimal(14,1),
  197. SalaryHour decimal(14,1),
  198. exception bit,
  199. Comment nvarchar(256)
  200. )
  201. Declare cur cursor
  202. for
  203. Select ApplicationBillEmployee.ID_Employee As ID_Applicant,No_ApplicationBill,Item_ApplicationBill,StartDate_ApplicationBill,EndDate_ApplicationBill
  204. ,OnStuffOne,OffStuffOne,OnStuffTwo,OffStuffTwo
  205. From dbo.ApplicationBill
  206. Join dbo.ApplicationBillEmployee On ApplicationBillEmployee.ID_ApplicationBill=ApplicationBill.ID_ApplicationBill
  207. Join dbo.AttendanceRuleEmployee On ApplicationBillEmployee.ID_Employee=dbo.AttendanceRuleEmployee.ID_Employee
  208. Join dbo.AttendanceRule On AttendanceRuleEmployee.ID_AttendanceRule=AttendanceRule.ID_AttendanceRule
  209. Join Employee ON Employee.ID_Employee=dbo.AttendanceRuleEmployee.ID_Employee
  210. Where ApplicationBill.ID_Assessor Is Not Null
  211. And No_Employee Between IsNull(@StartNo_Employee,No_Employee) And IsNull(@EndNo_Employee,No_Employee)
  212. And DateDiff(day,@StartDate,EndDate_ApplicationBill)&gt;=0 And DateDiff(day,@EndDate,StartDate_ApplicationBill)&lt;=0
  213. Open cur
  214. Fetch Next From cur Into @ID_Applicant,@No_ApplicationBill,@Item_ApplicationBill,@StartDate_ApplicationBill,@EndDate_ApplicationBill
  215. ,@OnStuffOne,@OffStuffOne,@OnStuffTwo,@OffStuffTwo
  216. while @@fetch_status=0
  217. BEGIN
  218. Set @LoopDate=@StartDate_ApplicationBill
  219. while(DateDiff(day,@LoopDate,@EndDate_ApplicationBill)&gt;=0)
  220. BEGIN
  221. IF(DateDiff(day,@StartDate,@LoopDate)&gt;=0 and DateDiff(day,@EndDate,@LoopDate)&lt;=0)
  222. BEGIN
  223. IF(DateDiff(day,@StartDate_ApplicationBill,@LoopDate)&gt;0 and DateDiff(day,@EndDate_ApplicationBill,@LoopDate)&lt;0)
  224. Set @AppHour=Convert(decimal(14,1),(dbo.TimeDiff(@OnStuffOne,@OffStuffOne)+dbo.TimeDiff(@OnStuffTwo,@OffStuffTwo))/60.0)
  225. Else IF(DateDiff(day,@StartDate_ApplicationBill,@LoopDate)=0)
  226. BEGIN
  227. IF(DateDiff(day,@EndDate_ApplicationBill,@LoopDate)&lt;0)
  228. BEGIN
  229. IF(dbo.TimeDiff(@LoopDate,@OnStuffOne)&gt;0)
  230. Set @AppHour=Convert(decimal(14,1),(dbo.TimeDiff(@OnStuffOne,@OffStuffOne)+dbo.TimeDiff(@OnStuffTwo,@OffStuffTwo))/60.0)
  231. Else IF(dbo.TimeDiff(@StartDate_ApplicationBill,@OffStuffOne)&gt;0)
  232. Set @AppHour=Convert(decimal(14,1),(dbo.TimeDiff(@StartDate_ApplicationBill,@OffStuffOne)+dbo.TimeDiff(@OnStuffTwo,@OffStuffTwo))/60.0)
  233. else if(dbo.TimeDiff(@StartDate_ApplicationBill,@OnStuffTwo)&gt;0)
  234. Set @AppHour=dbo.TimeDiff(@OnStuffTwo,@OffStuffTwo)
  235. else if(dbo.TimeDiff(@StartDate_ApplicationBill,@OffStuffTwo)&gt;0)
  236. Set @AppHour=dbo.TimeDiff(@StartDate_ApplicationBill,@OffStuffTwo)/60.0
  237. else
  238. Set @AppHour=0
  239. END
  240. Else
  241. BEGIN
  242. IF(dbo.TimeDiff(@StartDate_ApplicationBill,@OnStuffOne)&gt;0)
  243. BEGIN
  244. IF(dbo.TimeDiff(@EndDate_ApplicationBill,@OnStuffOne)&gt;0)
  245. Set @AppHour=0
  246. Else IF (dbo.TimeDiff(@EndDate_ApplicationBill,@OffStuffOne)&gt;0)
  247. Set @AppHour=Convert(decimal(14,1),dbo.TimeDiff(@OnStuffOne,@EndDate_ApplicationBill)/60.0)
  248. Else if (dbo.TimeDiff(@EndDate_ApplicationBill,@OnStuffTwo)&gt;0)
  249. Set @AppHour=Convert(decimal(14,1),dbo.TimeDiff(@OnStuffOne,@OffStuffOne))
  250. else if(dbo.TimeDiff(@EndDate_ApplicationBill,@OffStuffTwo)&gt;0)
  251. Set @AppHour=Convert(decimal(14,1),(dbo.TimeDiff(@OnStuffOne,@OffStuffOne)+dbo.TimeDiff(@OnStuffTwo,@EndDate_ApplicationBill))/60.0)
  252. else
  253. Set @AppHour=Convert(decimal(14,1),(dbo.TimeDiff(@OnStuffOne,@OffStuffOne)+dbo.TimeDiff(@OnStuffTwo,@OffStuffTwo))/60.0)
  254. END
  255. Else IF(dbo.TimeDiff(@StartDate_ApplicationBill,@OffStuffOne)&gt;0)
  256. BEGIN
  257. IF (dbo.TimeDiff(@EndDate_ApplicationBill,@OffStuffOne)&gt;0)
  258. Set @AppHour=Convert(decimal(14,1),dbo.TimeDiff(@StartDate_ApplicationBill,@EndDate_ApplicationBill)/60.0)
  259. Else if (dbo.TimeDiff(@EndDate_ApplicationBill,@OnStuffTwo)&gt;0)
  260. Set @AppHour=Convert(decimal(14,1),dbo.TimeDiff(@StartDate_ApplicationBill,@OffStuffOne)/60.0)
  261. else if(dbo.TimeDiff(@EndDate_ApplicationBill,@OffStuffTwo)&gt;0)
  262. Set @AppHour=Convert(decimal(14,1),(dbo.TimeDiff(@StartDate_ApplicationBill,@OffStuffOne)+dbo.TimeDiff(@OnStuffTwo,@EndDate_ApplicationBill))/60.0)
  263. else
  264. Set @AppHour=Convert(decimal(14,1),(dbo.TimeDiff(@StartDate_ApplicationBill,@OffStuffOne)+dbo.TimeDiff(@OnStuffTwo,@OffStuffTwo))/60.0)
  265. END
  266. else if(dbo.TimeDiff(@StartDate_ApplicationBill,@OnStuffTwo)&gt;0)
  267. BEGIN
  268. IF (dbo.TimeDiff(@EndDate_ApplicationBill,@OnStuffTwo)&gt;0)
  269. Set @AppHour=0
  270. Else if (dbo.TimeDiff(@EndDate_ApplicationBill,@OffStuffTwo)&gt;0)
  271. Set @AppHour=Convert(decimal(14,1),dbo.TimeDiff(@OnStuffTwo,@EndDate_ApplicationBill)/60.0)
  272. else
  273. Set @AppHour=Convert(decimal(14,1),dbo.TimeDiff(@OnStuffTwo,@OffStuffTwo)/60.0)
  274. END
  275. else if(dbo.TimeDiff(@StartDate_ApplicationBill,@OffStuffTwo)&gt;0)
  276. BEGIN
  277. IF (dbo.TimeDiff(@EndDate_ApplicationBill,@OffStuffTwo)&gt;0)
  278. Set @AppHour=Convert(decimal(14,1),dbo.TimeDiff(@StartDate_ApplicationBill,@EndDate_ApplicationBill)/60.0)
  279. else
  280. Set @AppHour=Convert(decimal(14,1),dbo.TimeDiff(@StartDate_ApplicationBill,@OffStuffTwo)/60.0)
  281. END
  282. else
  283. Set @AppHour=0
  284. END
  285. END
  286. ELSE
  287. BEGIN
  288. IF(dbo.TimeDiff(@EndDate_ApplicationBill,@OnStuffOne)&gt;0)
  289. Set @AppHour=0
  290. Else IF(dbo.TimeDiff(@EndDate_ApplicationBill,@OffStuffOne)&gt;0)
  291. Set @AppHour=dbo.TimeDiff(@OnStuffOne,@EndDate_ApplicationBill)/60.0
  292. else if(dbo.TimeDiff(@EndDate_ApplicationBill,@OnStuffTwo)&gt;0)
  293. Set @AppHour=dbo.TimeDiff(@OnStuffOne,@OffStuffOne)/60.0
  294. else if(dbo.TimeDiff(@EndDate_ApplicationBill,@OffStuffTwo)&gt;0)
  295. Set @AppHour=Convert(decimal(14,1),(dbo.TimeDiff(@OnStuffOne,@OffStuffOne)+dbo.TimeDiff(@OnStuffTwo,@EndDate_ApplicationBill))/60.0)
  296. else
  297. Set @AppHour=Convert(decimal(14,1),(dbo.TimeDiff(@OnStuffOne,@OffStuffOne)+dbo.TimeDiff(@OnStuffTwo,@OffStuffTwo))/60.0)
  298. END
  299. IF(Not Exists (Select * From #TempApp Where ID_Applicant=@ID_Applicant And Date=convert(varchar(10),@LoopDate,120)))
  300. BEGIN
  301. IF(@Item_ApplicationBill='加班')
  302. Insert Into #TempApp(ID_Applicant,Date,OvertimeHour,Comment)
  303. Values(@ID_Applicant,convert(varchar(10),@LoopDate,120),@AppHour,'加班:'+@No_ApplicationBill)
  304. else if(@Item_ApplicationBill='出差')
  305. Insert Into #TempApp(ID_Applicant,Date,BusinessHour,Comment)
  306. Values(@ID_Applicant,convert(varchar(10),@LoopDate,120),@AppHour,'出差:'+@No_ApplicationBill)
  307. else if(@Item_ApplicationBill='事假')
  308. Insert Into #TempApp(ID_Applicant,Date,CompassionateHour,Comment)
  309. Values(@ID_Applicant,convert(varchar(10),@LoopDate,120),@AppHour,'事假:'+@No_ApplicationBill)
  310. else if(@Item_ApplicationBill='病假')
  311. Insert Into #TempApp(ID_Applicant,Date,SickHour,Comment)
  312. Values(@ID_Applicant,convert(varchar(10),@LoopDate,120),@AppHour,'病假:'+@No_ApplicationBill)
  313. else if(@Item_ApplicationBill='带薪假')
  314. Insert Into #TempApp(ID_Applicant,Date,SalaryHour,Comment)
  315. Values(@ID_Applicant,convert(varchar(10),@LoopDate,120),@AppHour,'带薪假:'+@No_ApplicationBill)
  316. else if(@Item_ApplicationBill='打卡异常')
  317. Insert Into #TempApp(ID_Applicant,Date,exception,Comment)
  318. Values(@ID_Applicant,convert(varchar(10),@LoopDate,120),1,'打卡异常:'+@No_ApplicationBill)
  319. END
  320. else
  321. Begin
  322. IF(@Item_ApplicationBill='加班')
  323. Update #TempApp Set OvertimeHour=IsNull(OvertimeHour,0)+@AppHour,Comment=Comment+' 加班:'+@No_ApplicationBill Where ID_Applicant=@ID_Applicant And Date=convert(varchar(10),@LoopDate,120)
  324. else if(@Item_ApplicationBill='出差')
  325. Update #TempApp Set BusinessHour=IsNull(BusinessHour,0)+@AppHour,Comment=Comment+' 出差:'+@No_ApplicationBill Where ID_Applicant=@ID_Applicant And Date=convert(varchar(10),@LoopDate,120)
  326. else if(@Item_ApplicationBill='事假')
  327. Update #TempApp Set CompassionateHour=IsNull(CompassionateHour,0)+@AppHour,Comment=Comment+' 事假:'+@No_ApplicationBill Where ID_Applicant=@ID_Applicant And Date=convert(varchar(10),@LoopDate,120)
  328. else if(@Item_ApplicationBill='病假')
  329. Update #TempApp Set SickHour=IsNull(SickHour,0)+@AppHour,Comment=Comment+' 病假:'+@No_ApplicationBill Where ID_Applicant=@ID_Applicant And Date=convert(varchar(10),@LoopDate,120)
  330. else if(@Item_ApplicationBill='带薪假')
  331. Update #TempApp Set SalaryHour=IsNull(SalaryHour,0)+@AppHour,Comment=Comment+' 带薪假:'+@No_ApplicationBill Where ID_Applicant=@ID_Applicant And Date=convert(varchar(10),@LoopDate,120)
  332. else if(@Item_ApplicationBill='打卡异常')
  333. Update #TempApp Set exception=1,Comment=Comment+' 打卡异常:'+@No_ApplicationBill Where ID_Applicant=@ID_Applicant And Date=convert(varchar(10),@LoopDate,120)
  334. End
  335. END
  336. Set @LoopDate=DateAdd(day,1,@LoopDate)
  337. END
  338. Fetch Next From cur Into @ID_Applicant,@No_ApplicationBill,@Item_ApplicationBill,@StartDate_ApplicationBill,@EndDate_ApplicationBill
  339. ,@OnStuffOne,@OffStuffOne,@OnStuffTwo,@OffStuffTwo
  340. END
  341. Close cur
  342. Deallocate cur
  343. ---------------------------------------------------------------------------------------------------
  344. Select No_Employee,Name_Employee,Name_Department,EmployeeInfo.Date,case WeekDay_HolidaySetting when 1 then '日' when 2 then '一' when 3 then '二' when 4 then '三' when 5 then '四' when 6 then '五' else '六' end As WeekDay,Type_HolidaySetting,Name_AttendanceRule,StuffHour
  345. ,OnAttendance,OffAttendance
  346. --,OnAttendanceTwo,OffAttendanceTwo
  347. ,case Type_HolidaySetting when '工作日' then
  348. case when exception=1 then StuffHour
  349. else AttendanceHour end
  350. else null end As AttendanceHour
  351. ,case when #TempApp.OvertimeHour&gt;StuffHour then StuffHour
  352. else #TempApp.OvertimeHour end As OvertimeHour
  353. ,case when #TempApp.BusinessHour&gt;StuffHour then StuffHour
  354. else #TempApp.BusinessHour end As BusinessHour
  355. ,case when Type_HolidaySetting='工作日' then
  356. case when #TempApp.CompassionateHour&gt;StuffHour then StuffHour
  357. else #TempApp.CompassionateHour end
  358. else null end As CompassionateHour
  359. ,case when Type_HolidaySetting='工作日' then
  360. case when #TempApp.SickHour&gt;StuffHour then StuffHour
  361. else #TempApp.SickHour end
  362. else null end As SickHour
  363. ,case when Type_HolidaySetting='工作日' then
  364. case when #TempApp.SalaryHour&gt;StuffHour then StuffHour
  365. else #TempApp.SalaryHour end
  366. else null end As SalaryHour
  367. ,case when Type_HolidaySetting='工作日' then
  368. case when exception=1 then null
  369. else
  370. case when (StuffHour-IsNull(AttendanceHour,0)-IsNull(BusinessHour,0)-IsNull(CompassionateHour,0)-IsNull(SickHour,0)-IsNull(SalaryHour,0)
  371. -case when dbo.TimeDiff(OnStuffOne,OnAttendance) &lt;=30 and dbo.TimeDiff(OnStuffOne,OnAttendance)&gt;0 then dbo.TimeDiff(OnStuffOne,OnAttendance) else 0 end
  372. -case when dbo.TimeDiff(OffAttendance,OffStuffTwo)&lt;30 and dbo.TimeDiff(OffAttendance,OffStuffTwo)&gt;0 then dbo.TimeDiff(OffAttendance,OffStuffTwo) else 0 end ) &gt;0 then
  373. (StuffHour-IsNull(AttendanceHour,0)-IsNull(BusinessHour,0)-IsNull(CompassionateHour,0)-IsNull(SickHour,0)-IsNull(SalaryHour,0)
  374. -case when dbo.TimeDiff(OnStuffOne,OnAttendance) &lt;=30 and dbo.TimeDiff(OnStuffOne,OnAttendance)&gt;0 then dbo.TimeDiff(OnStuffOne,OnAttendance) else 0 end
  375. -case when dbo.TimeDiff(OffAttendance,OffStuffTwo)&lt;30 and dbo.TimeDiff(OffAttendance,OffStuffTwo)&gt;0 then dbo.TimeDiff(OffAttendance,OffStuffTwo) else 0 end )
  376. else null end
  377. end
  378. else null end As AbsentHour
  379. ,case when Type_HolidaySetting='工作日' And OnAttendance Is Not Null then
  380. case when exception=1 then null
  381. else
  382. case when dbo.TimeDiff(OnStuffOne,OnAttendance)&lt;=ArriveLate_AttendanceRule or dbo.TimeDiff(OnStuffOne,OnAttendance)&gt;30 then null
  383. else (dbo.TimeDiff(OnStuffOne,OnAttendance)-ArriveLate_AttendanceRule) end
  384. end
  385. else null end As ArriveLateMinute
  386. ,case when Type_HolidaySetting='工作日' And OnAttendance Is Not Null then
  387. case when exception=1 then null
  388. else
  389. case when dbo.TimeDiff(OffAttendance,OffStuffTwo)&lt;=LeaveEarly_AttendanceRule or dbo.TimeDiff(OffAttendance,OffStuffTwo)&gt;30 then null
  390. else dbo.TimeDiff(OffAttendance,OffStuffTwo)-LeaveEarly_AttendanceRule end
  391. end
  392. else null end As LeaveEarlyMinute
  393. ,Comment
  394. From
  395. (
  396. Select a.*,dbo.GetAttendanceHour(OnStuffOne,OffStuffOne,OnStuffTwo,OffStuffTwo,OnAttendance,OffAttendance) As AttendanceHour
  397. From
  398. (
  399. Select EmployeeCalendar.ID_Employee,No_Employee,Name_Employee,Name_Department,convert(varchar(10),Date_HolidaySetting,120) As Date,WeekDay_HolidaySetting,Type_HolidaySetting,Name_AttendanceRule
  400. ,(Select Top 1 Date_AttendanceRecord From dbo.AttendanceRecord Join Employee On Employee.CardNo_Employee=AttendanceRecord.No_Card Where Employee.ID_Employee=EmployeeCalendar.ID_Employee And DateDiff(day,Date_AttendanceRecord,EmployeeCalendar.Date_HolidaySetting)=0 Order By Date_AttendanceRecord) As OnAttendance
  401. ,(Select Top 1 Date_AttendanceRecord From dbo.AttendanceRecord Join Employee On Employee.CardNo_Employee=AttendanceRecord.No_Card Where Employee.ID_Employee=EmployeeCalendar.ID_Employee And DateDiff(day,Date_AttendanceRecord,EmployeeCalendar.Date_HolidaySetting)=0 Order By Date_AttendanceRecord desc) As OffAttendance
  402. ,OnStuffOne,OffStuffOne,OnStuffTwo,OffStuffTwo,ArriveLate_AttendanceRule,LeaveEarly_AttendanceRule,TakeOff_AttendanceRule
  403. ,Convert(decimal(14,1),(dbo.TimeDiff(OnStuffOne,OffStuffOne)+dbo.TimeDiff(OnStuffTwo,OffStuffTwo))/60.0) As StuffHour
  404. From
  405. (
  406. Select *
  407. From Employee,HolidaySetting
  408. Where No_Employee Between IsNull(@StartNo_Employee,No_Employee) And IsNull(@EndNo_Employee,No_Employee)
  409. And DateDiff(day,@StartDate,Date_HolidaySetting)&gt;=0 And DateDiff(day,@EndDate,Date_HolidaySetting)&lt;=0
  410. )EmployeeCalendar
  411. Left Join Department On Department.ID_Department=EmployeeCalendar.ID_Department
  412. Join dbo.AttendanceRuleEmployee On AttendanceRuleEmployee.ID_Employee=EmployeeCalendar.ID_Employee
  413. Left Join dbo.AttendanceRule On AttendanceRule.ID_AttendanceRule=dbo.AttendanceRuleEmployee.ID_AttendanceRule
  414. )a
  415. )EmployeeInfo
  416. Left Join #TempApp On #TempApp.ID_Applicant=EmployeeInfo.ID_Employee And #TempApp.Date=EmployeeInfo.Date
  417. Order By No_Employee,EmployeeInfo.Date
  418. ">
  419. <Params>
  420. <Param name="@StartDate" type="SaleBill.Date_SaleBill" Index="0" />
  421. <Param name="@EndDate" type="SaleBill.Date_SaleBill" Index="1" />
  422. <Param name="@StartNo_Employee" type="Product.No_Product" Index="2" />
  423. <Param name="@EndNo_Employee" type="Product.No_Product" Index="3" />
  424. </Params>
  425. <Tables>
  426. <Table name="AttendanceReport"/>
  427. </Tables>
  428. </SearchAttendanceReport>
  429. <SearchAllEmployee CmdType="Text" CmdText="SELECT Employee.No_Employee,Employee.Name_Employee FROM Employee ">
  430. <Tables>
  431. <Table name="AllEmployee" />
  432. </Tables>
  433. </SearchAllEmployee>
  434. </Search>
  435. </Server>
  436. <Lables>
  437. <Search>
  438. Empty();
  439. NewInstance();
  440. </Search>
  441. <Action>
  442. <![CDATA[
  443. UpdateForm(false,"");
  444. #UI.Name_Creator = GetCurrentUser();
  445. #UI.CreateDate = GetCurrentTime();
  446. #UI.Combine=ckCombine.Checked;
  447. @StartNo_Employee=tbEmployee1.CValue==""?DBNull():tbEmployee1.CValue;
  448. @EndNo_Employee=tbEmployee2.CValue==""?DBNull():tbEmployee2.CValue;
  449. Search("SearchAttendanceReport",dtStart.Value,dtEnd.Value,@StartNo_Employee,@EndNo_Employee);
  450. if(RowCount("#AttendanceReport")==0)
  451. {
  452. MessageBox("没有查找到与此相匹配的纪录,未产生报表!",@Title);
  453. }
  454. else
  455. {
  456. switch(@ClickType)
  457. {
  458. case "View":
  459. PrintReport("UIFrmAttendanceReport","UI","AttendanceReport");
  460. break;
  461. default:
  462. ExportReport(@ClickType,"UIFrmAttendanceReport","UI","AttendanceReport");
  463. break;
  464. }
  465. }
  466. ]]>
  467. </Action>
  468. </Lables>
  469. </Form>
  470. </Forms>