PayrollComputation.cs 134 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394
  1. using OASystem.API.OAMethodLib.QiYeWeChatAPI;
  2. using OASystem.Domain.Entities.PersonnelModule;
  3. using OASystem.Domain.ViewModels.PersonnelModule;
  4. using OASystem.Domain.ViewModels.QiYeWeChat;
  5. namespace OASystem.API.OAMethodLib
  6. {
  7. /// <summary>
  8. /// 工资计算
  9. /// </summary>
  10. public static class PayrollComputation
  11. {
  12. private static Result _result = new Result();
  13. private static readonly IQiYeWeChatApiService _qiYeWeChatApiService = AutofacIocManager.Instance.GetService<IQiYeWeChatApiService>();
  14. private static readonly UsersRepository _usersRep = AutofacIocManager.Instance.GetService<UsersRepository>();
  15. private static readonly IMapper _mapper = AutofacIocManager.Instance.GetService<IMapper>();
  16. private static readonly decimal _chengDuMinimumWage = 2100.00M * 0.80M; //员工在病假医疗期限内的病假工资按照成都市最低工资标准的 80%发放
  17. /// <summary>
  18. /// 计算工资
  19. /// </summary>
  20. /// <param name="pm_WageSheetDattaSources"></param>
  21. /// <param name="userNames"></param>
  22. /// <param name="userId"></param>
  23. /// <param name="thisYearMonth"></param>
  24. /// <param name="startDt"></param>
  25. /// <param name="endDt"></param>
  26. /// <returns></returns>
  27. public static async Task<Result> SalaryCalculatorAsync(
  28. List<Pm_WageSheet> pm_WageSheetDattaSources, List<UserNameView> userNames, int userId, string thisYearMonth, DateTime startDt, DateTime endDt)
  29. {
  30. if (pm_WageSheetDattaSources.Count <= 0)
  31. {
  32. _result.Msg = "计算工资传入数据为空!";
  33. return _result;
  34. }
  35. //计算时间段内工作日
  36. int work_days = await GetWorkDays(thisYearMonth);
  37. if (work_days <= 0)
  38. {
  39. _result.Msg = $"{thisYearMonth} 工作日未设置,请前往《工作日管理页面》设置!";
  40. return _result;
  41. }
  42. UserIdListView userIdListView = await _qiYeWeChatApiService.GetUserIdListAsync();
  43. if (userIdListView.errcode != 0)
  44. {
  45. _result.Msg = $"【企业微信】【打卡】【获取员工ID】【Msg】{userIdListView.errmsg}";
  46. return _result;
  47. }
  48. //Task<QYWX_UserInfosView> GetUserInfosAsync()
  49. //QYWX_UserInfosView usersView = await _qiYeWeChatApiService.GetUserInfosAsync();
  50. //if (usersView.errcode != 0)
  51. //{
  52. // _result.Msg = $"【企业微信】【打卡】【获取员工基础信息】【Msg】{userIdListView.errmsg}";
  53. // return _result;
  54. //}
  55. List<string> qyWhchatIdList = new List<string>();
  56. qyWhchatIdList = userIdListView.dept_user.Select(it => it.userid).ToList();
  57. CheckInDayDataView checkInDayDataView = await _qiYeWeChatApiService.GetCheckInDayDataAsync(qyWhchatIdList, startDt, endDt);
  58. if (checkInDayDataView.errcode != 0)
  59. {
  60. _result.Msg = $"【企业微信】【打卡】【获取时间段内所有日打卡】【Msg】{checkInDayDataView.errmsg}";
  61. return _result;
  62. }
  63. //获取所有打卡记录 外出
  64. CheckInDataView checkInDataView = new CheckInDataView();
  65. checkInDataView = await _qiYeWeChatApiService.GetCheckinDataAsync(qyWhchatIdList, 3, startDt, endDt);
  66. if (checkInDataView.errcode != 0)
  67. {
  68. _result.Msg = $"【企业微信】【打卡】【获取时间段内所有日打卡记录】【Msg】{checkInDataView.errmsg}";
  69. return _result;
  70. }
  71. //查询工作日
  72. List<Sys_Calendar> sys_Calendars = new List<Sys_Calendar>();
  73. string sys_sql = string.Format("Select * From Sys_Calendar Where Isdel = 0 And Dt between '{0}' And '{1}'",
  74. startDt.ToString("yyyy-MM-dd"), endDt.ToString("yyyy-MM-dd"));
  75. sys_Calendars = await _usersRep._sqlSugar.SqlQueryable<Sys_Calendar>(sys_sql).ToListAsync();
  76. //筛选出工作日日报
  77. List<Root> workday_userRoots = checkInDayDataView.datas.Where(it => it.base_info.day_type == 0 && it.base_info.record_type == 1).ToList();
  78. //工作日日报
  79. workday_userRoots = workday_userRoots.OrderBy(it => it.base_info.date).ToList();
  80. #region 特殊日期-不用打卡日期信息
  81. //获取企业打卡规则
  82. CorpCheckInRuleView corpCheckInRole = await _qiYeWeChatApiService.GetCheckIn_CorpCheckInOptionAsync();
  83. if (corpCheckInRole.errcode != 0)
  84. {
  85. _result.Msg = $"【企业微信】【打卡】【获取企业打卡规则】【Msg】{corpCheckInRole.errmsg}";
  86. return _result;
  87. }
  88. int spe_offdays = 0;
  89. GroupItem group = corpCheckInRole.group.Where(it => it.groupid == 4).FirstOrDefault();
  90. if (group != null)
  91. {
  92. foreach (var item in group.spe_offdays)
  93. {
  94. if (item.begtime_dt >= startDt && item.endtime_dt <= endDt)
  95. {
  96. if (item.endtime_dt > startDt)
  97. {
  98. TimeSpan ts = item.endtime_dt - item.begtime_dt;
  99. spe_offdays = (ts.Days + 1);
  100. }
  101. }
  102. }
  103. }
  104. #endregion
  105. //获取 请假类型 Sp_Detail.template_id
  106. string leave_template_id = "C4NzTJCh1onCUK915rRkvy7Fh5Vqz4YbiEV9jrBY1";
  107. List<VacationLeaveTypeView> vacationLeaveTypes = await GetVacationLeaveTypes(leave_template_id);
  108. if (vacationLeaveTypes.Count <= 0)
  109. {
  110. _result.Msg = $"【企业微信】【审批】【获取审批类型】【Msg】{startDt} - {endDt}请假 类型数据 获取失败!";
  111. return _result;
  112. }
  113. string _name = "";
  114. try
  115. {
  116. #region 手动配置企业员工userid,通过userid 去匹配打卡数据
  117. //Dictionary<string, string> wx_useridDic = new Dictionary<string, string>();
  118. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  119. //wx_useridDic.Add("罗诗怡", "lsyyyy");
  120. //wx_useridDic.Add("赖红燕", "LaiHongYan");
  121. //wx_useridDic.Add("刘一茹", "liuyiru");
  122. //wx_useridDic.Add("李雯琪", "LiWenQi");
  123. //wx_useridDic.Add("罗聪惠", "LuoCongHui");
  124. //wx_useridDic.Add("肖俊杰", "20230410");
  125. //wx_useridDic.Add("朱成梅", "amy.zhu@pan-american-intl.com");
  126. //wx_useridDic.Add("伏虹瑾", "FuHongJin");
  127. //wx_useridDic.Add("曾艳", "judy.zeng@pan-american-intl.com");
  128. //wx_useridDic.Add("舒庆", "cilina.shu@pan-american-intl.com");
  129. //wx_useridDic.Add("高媛媛", "GaoYuanYuan");
  130. //wx_useridDic.Add("龙畑恬", "longtiantian");
  131. //wx_useridDic.Add("叶琪琪", "YeQiQi");
  132. //wx_useridDic.Add("王鸽", "ellisa.wang@pan-american-intl.com");
  133. //wx_useridDic.Add("赵雅琪", "ZhaoYaQi");
  134. //wx_useridDic.Add("陈思帆", "ChenSiFan");
  135. //wx_useridDic.Add("廖文雅", "LiaoWenYa");
  136. //wx_useridDic.Add("李敏", "annie.li@pan-american-intl.com");
  137. //wx_useridDic.Add("李明华", "LiMingHua");
  138. //wx_useridDic.Add("李文婷", "LiWenTing");
  139. //wx_useridDic.Add("仇久龙", "rf");
  140. //wx_useridDic.Add("宋夏雨", "songxiayu");
  141. //wx_useridDic.Add("王思雨", "ysw");
  142. //wx_useridDic.Add("汪燕平", "yime");
  143. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  144. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  145. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  146. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  147. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  148. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  149. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  150. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  151. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  152. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  153. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  154. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  155. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  156. #endregion
  157. foreach (var pm_wsInfo in pm_WageSheetDattaSources)
  158. {
  159. _name = userNames.Find(it => it.Id == pm_wsInfo.UserId)?.CnName ?? "Unknown";
  160. //补贴 金额
  161. decimal meal_subsidy = 0.00M; // 午餐(午餐10元/天) 补贴 * 计算方式:单日上午请假时长(小时)大于或者等于三小时 没有餐补
  162. //事假 病假 总金额
  163. decimal personalLeaveTotal = 0.00M, // 事假 日薪 *计算方式:日平均工资 = 月工资/当月应出勤天数。
  164. sickLeaveTotal = 0.00M; // 病假 日薪 *计算方式:日平均工资 = 成都市最低工资标准的80%/当月应出勤天数。 短期病假=当月15天内
  165. //扣款金额
  166. decimal beLate_deduction = 0.00M, // 迟到 扣款金额 *计算方式:
  167. // 一个自然月内,不足 10 分钟的迟到/早退,不超过 2 次的部分,不做处罚;3 次及以上,按50元 / 次处罚;
  168. // 超过 10 分钟(含 10 分钟),不足 60 分钟的迟到/早退,按 50 元/次处罚;
  169. // 超过 60 分钟(含 60 分钟),不足 3 小时的迟到/早退,且无请假者,按旷工半日处理;超过3 小时的迟到 / 早退,且无请假者,按旷工一日处理。
  170. early_deduction = 0.00M, // 早退 扣款金额
  171. absenteeism_deduction = 0.00M, // 旷工 扣款金额 *计算方式:旷工扣发当日工资
  172. unprinted_deduction = 0.00M, // 未打卡 扣款金额 *计算方式:
  173. // 试用期员工每月有 2 次 补卡机会,超过 2 次不足 5 次的部分,按 10 元 / 次处罚,5 次及以上的漏卡,按 50 元 / 次处罚;
  174. // 正式员工每月 3 次以内的补卡,按 10 元 / 次处罚,3 次及以上的漏卡,按 50 元 / 次处罚。
  175. sickLeave_deduction = 0.00M, // 病假
  176. other_deduction = 0.00M; // 其他 扣款金额
  177. decimal meal_deduction = 0.00M; // 餐补 扣款金额
  178. //decimal reissuecard_deduction = 0.00M; // 补卡 扣款金额
  179. #region 计算日工资 正常日薪 事假日薪 病假日薪
  180. //月 - 应发工资
  181. decimal amountPayable = pm_wsInfo.Basic + pm_wsInfo.Floats + pm_wsInfo.PostAllowance + pm_wsInfo.InformationSecurityFee +
  182. pm_wsInfo.OtherSubsidies;
  183. // 日薪 = *计算方式:日平均工资 = 月工资/当月应出勤天数。
  184. decimal dailyWage = amountPayable / work_days;
  185. // 病假日薪 *计算方式:日平均工资 = 成都市最低工资标准的80%/当月应出勤天数。 短期病假=当月15天内
  186. decimal sickLeave_dailywage = _chengDuMinimumWage / work_days;
  187. //病假 一天扣款
  188. sickLeave_deduction = dailyWage - sickLeave_dailywage;
  189. List<Ex_Items> ex_Items = new List<Ex_Items>();//假勤 And 打卡备注集合
  190. Ex_Items ex_Items_dk = new Ex_Items() { Type = "打卡" }; //打卡
  191. Ex_Items ex_Items_jq = new Ex_Items() { Type = "假勤" }; //假勤
  192. Ex_Items ex_Items_cc = new Ex_Items() { Type = "出差" }; //出差
  193. #endregion
  194. List<Root> userRoots = new List<Root>();
  195. //string wx_userid = "";
  196. if (_name == "蔡雯")
  197. {
  198. userRoots = workday_userRoots.Where(it => it.base_info.name == "蔡蔡" || it.base_info.name == "蔡雯").ToList(); //工作日日报 1-固定上下班;
  199. }
  200. else
  201. {
  202. userRoots = workday_userRoots.Where(it => it.base_info.name == _name || it.base_info.name.Contains(_name)).ToList(); //工作日日报 1-固定上下班;
  203. }
  204. //userRoots = userRoots.Distinct().ToList();
  205. userRoots = userRoots.OrderBy(it => it.base_info.date).ToList();
  206. int dk_work_days = userRoots.Count; //应出勤天数
  207. if (dk_work_days > work_days)
  208. {
  209. dk_work_days = work_days;
  210. }
  211. meal_subsidy = dk_work_days * 10; //应发放餐补
  212. if (!_name.Equals("张海麟"))
  213. {
  214. if (userRoots.Count <= 0)
  215. {
  216. _result.Msg = $"【{_name}】【企业微信】【打卡】【获取打卡数据】【Msg】{startDt} - {endDt} 打卡日数据 获取失败!";
  217. continue;
  218. }
  219. string acctid = userRoots[0].base_info.acctid;
  220. List<Ex_Item> ex_reissuecard_Items = new List<Ex_Item>(); //打卡类型 数据
  221. List<Sp_items> acc_sp_items = new List<Sp_items>(); //审批数据
  222. //int user_probationary_bk_num = 0;
  223. decimal user_probationary_bk_decimal = pm_wsInfo.Floats; //绩效工资为0 则为试用员工
  224. //处理外出打卡记录
  225. List<CheckInDataInfo> checkInData1 = new List<CheckInDataInfo>();
  226. checkInData1 = checkInDataView.checkindata;
  227. List<CheckInDataInfo> checkInDatas = new List<CheckInDataInfo>();
  228. checkInDatas = checkInData1.Where(it => it.userid == acctid).ToList();
  229. //找出外出的打卡记录
  230. List<CheckInDataInfo> checkInData2 = new List<CheckInDataInfo>();
  231. checkInData2 = checkInDatas.Where(it => it.exception_type.Equals("未打卡")).ToList();
  232. //外出打卡
  233. List<CheckInDataInfo> checkInData_outPunch = new List<CheckInDataInfo>();
  234. checkInData_outPunch = checkInDatas.Where(it => it.checkin_type.Equals("外出打卡")).ToList();
  235. #region 迟到 早退 旷工
  236. int user_cd_zt_num = 0; //早退/迟到 次数 10分钟内 2次以内不记处罚 三次及以上50一次
  237. foreach (var root in userRoots)
  238. {
  239. List<Holiday_infos> holiday_Infos = root.holiday_infos; //当天假勤信息
  240. List<Exception_infos> exception_infos = root.exception_infos; //当天校准状态信息
  241. List<Sp_items> sp_Items = root.sp_items;//当天假勤统计信息
  242. if (sp_Items.Count > 0)
  243. {
  244. sp_Items = sp_Items.Where(it => it.count > 0).ToList();
  245. acc_sp_items.AddRange(sp_Items);
  246. }
  247. foreach (var exception_info in exception_infos)
  248. {
  249. decimal timelength = ConvertToDecimal((Convert.ToDecimal(exception_info.duration) / 3600.00M) * 60.00M); //时长 分钟
  250. if (timelength == 9) timelength = 7.50M;
  251. int exception = exception_info.exception; //异常类型
  252. decimal day_miner_unit = dailyWage / 15; //以0.5小时为单位
  253. //1:一个自然月内,不足 10 分钟的迟到/早退,不超过 2 次的部分,不做处罚;3 次及以上,按50 元 / 次处罚;
  254. //2:超过 10 分钟(含 10 分钟),不足 60 分钟的迟到 / 早退,按 50 元 / 次处罚;
  255. //3:超过 60 分钟(含 60 分钟),不足 3 小时的迟到 / 早退,且无请假者,按旷工半日处理;超过 3 小时的迟到 / 早退,且无请假者,按旷工一日处理。
  256. long date = root.base_info.date; //当日工作日期
  257. long earliest_time = root.summary_info.earliest_time; //最早打卡时间
  258. long lastest_time = root.summary_info.lastest_time; //最晚打卡时间
  259. long this_date = date + earliest_time;
  260. DateTime thisDt = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddTicks(this_date * 10000000);
  261. string thisDtStr = thisDt.ToString("yyyy-MM-dd");
  262. Ex_Item beLate_belate_ex = new Ex_Item()
  263. {
  264. SubTypeId = 4,
  265. SubType = "旷工",
  266. Duration = timelength,
  267. StartTimeDt = Convert.ToDateTime(root.base_info.dateDt.ToString("yyyy-MM-dd HH:mm:ss")),
  268. Unit = "分钟",
  269. };
  270. decimal day_deduction = 0.00M;
  271. //1 - 迟到;2 - 早退;3 - 缺卡;4 - 旷工;5 - 地点异常;6 - 设备异常
  272. if (exception == 1) //迟到
  273. {
  274. if (timelength < 10)
  275. {
  276. user_cd_zt_num++;
  277. beLate_belate_ex.SubTypeId = 1;
  278. beLate_belate_ex.SubType = "迟到";
  279. string thisStartDt = (TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddTicks((date + earliest_time) * 10000000))
  280. .ToString("yyyy-MM-dd HH:mm:ss");
  281. beLate_belate_ex.StartTimeDt = Convert.ToDateTime(thisStartDt);
  282. if (user_cd_zt_num >= 3)
  283. {
  284. day_deduction = 50.00M;
  285. }
  286. else
  287. {
  288. day_deduction = 0.00M;
  289. }
  290. beLate_deduction += day_deduction; //迟到扣款 总额
  291. }
  292. else if (timelength >= 10 && timelength < 60)
  293. {
  294. string thisStartDt = (TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1))
  295. .AddTicks((date + earliest_time) * 10000000))
  296. .ToString("yyyy-MM-dd HH:mm:ss");
  297. beLate_belate_ex.StartTimeDt = Convert.ToDateTime(thisStartDt);
  298. day_deduction = 50.00M;
  299. beLate_deduction += day_deduction; //迟到扣款 总额
  300. beLate_belate_ex.SubTypeId = 1;
  301. beLate_belate_ex.SubType = "迟到";
  302. }
  303. else if (timelength >= 60 && timelength <= 180)
  304. {
  305. day_deduction = ConvertToDecimal(dailyWage / 2); //3小时 按半天计算
  306. meal_deduction += 10.00M; //餐补扣款
  307. absenteeism_deduction += day_deduction; //矿工半日
  308. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)缺卡/未打卡视为旷工半天";
  309. }
  310. else
  311. {
  312. day_deduction = ConvertToDecimal(dailyWage);
  313. absenteeism_deduction += day_deduction; //矿工一日
  314. meal_deduction += 10.00M;
  315. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)-下午(18:00) 缺卡/未打视为旷工一天(7.5小时)";
  316. }
  317. beLate_belate_ex.Deduction = day_deduction;
  318. ex_reissuecard_Items.Add(beLate_belate_ex);
  319. }
  320. else if (exception == 2) //早退
  321. {
  322. if (timelength < 10)
  323. {
  324. user_cd_zt_num++;
  325. beLate_belate_ex.SubTypeId = 2;
  326. beLate_belate_ex.SubType = "早退";
  327. string thisEndDt = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1))
  328. .AddTicks((date + lastest_time) * 10000000)
  329. .ToString("yyyy-MM-dd HH:mm:ss");
  330. beLate_belate_ex.StartTimeDt = Convert.ToDateTime(thisEndDt);
  331. if (user_cd_zt_num >= 3)
  332. {
  333. day_deduction = 50.00M;
  334. }
  335. else
  336. {
  337. day_deduction = 0.00M;
  338. }
  339. early_deduction += day_deduction; //早退扣款 总计
  340. }
  341. else if (timelength >= 10 && timelength < 60)
  342. {
  343. day_deduction = 50.00M;
  344. early_deduction += day_deduction; //早退扣款 总计
  345. beLate_belate_ex.SubTypeId = 2;
  346. beLate_belate_ex.SubType = "早退";
  347. string thisEndDt = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1))
  348. .AddTicks((date + lastest_time) * 10000000)
  349. .ToString("yyyy-MM-dd HH:mm:ss");
  350. beLate_belate_ex.StartTimeDt = Convert.ToDateTime(thisEndDt);
  351. }
  352. else if (timelength >= 60 && timelength <= 180)
  353. {
  354. day_deduction = ConvertToDecimal(dailyWage / 2); //3小时 按半天计算
  355. meal_deduction += 10.00M;
  356. absenteeism_deduction += day_deduction; //矿工半日
  357. }
  358. else
  359. {
  360. day_deduction = ConvertToDecimal(dailyWage);
  361. meal_deduction += 10.00M;
  362. absenteeism_deduction += day_deduction; //矿工一日
  363. }
  364. beLate_belate_ex.Deduction = day_deduction;
  365. ex_reissuecard_Items.Add(beLate_belate_ex);
  366. }
  367. else if (exception == 3) //缺卡
  368. {
  369. if (root.exception_infos.Count == 2)
  370. {
  371. if (ex_reissuecard_Items.Where(it => it.StartTimeDt.ToString("yyyy-MM-dd").Equals(thisDtStr)).Count() > 0)
  372. {
  373. if (earliest_time == lastest_time)
  374. {
  375. DateTime thisDt1 = Convert.ToDateTime(thisDtStr + " 12:00");
  376. if (thisDt >= thisDt1) //旷工 下午
  377. {
  378. day_deduction = ConvertToDecimal(dailyWage / 2); //4.5小时 按半天计算
  379. meal_deduction += 10.00M;
  380. beLate_belate_ex.Duration = 270;
  381. absenteeism_deduction += day_deduction; //矿工半日
  382. beLate_belate_ex.Reason = thisDtStr + " 下午(18:00)缺卡/未打卡视为旷工半天";
  383. beLate_belate_ex.Deduction = day_deduction;
  384. ex_reissuecard_Items.Add(beLate_belate_ex);
  385. }
  386. else if (thisDt <= thisDt1) //旷工 上午
  387. {
  388. day_deduction = ConvertToDecimal(dailyWage / 2); //3小时 按半天计算
  389. meal_deduction += 10.00M;
  390. absenteeism_deduction += day_deduction; //矿工半日
  391. beLate_belate_ex.Duration = 180;
  392. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)缺卡/未打卡视为旷工半天";
  393. beLate_belate_ex.Deduction = day_deduction;
  394. ex_reissuecard_Items.Add(beLate_belate_ex);
  395. }
  396. else //矿工一日
  397. {
  398. day_deduction = ConvertToDecimal(dailyWage);
  399. meal_deduction += 10.00M;
  400. absenteeism_deduction += day_deduction;
  401. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)-下午(18:00) 缺卡/未打视为旷工一天(7.5小时)";
  402. beLate_belate_ex.Deduction = day_deduction;
  403. ex_reissuecard_Items.Add(beLate_belate_ex);
  404. }
  405. }
  406. }
  407. else
  408. {
  409. day_deduction = dailyWage;
  410. meal_deduction += 10.00M;
  411. absenteeism_deduction += day_deduction;
  412. beLate_belate_ex.Reason = "上午-下午 缺卡/未打卡为旷工一天";
  413. beLate_belate_ex.Deduction = day_deduction;
  414. ex_reissuecard_Items.Add(beLate_belate_ex);
  415. }
  416. }
  417. else if (root.exception_infos.Count == 1)
  418. {
  419. if (earliest_time == lastest_time)
  420. {
  421. DateTime thisDt1 = Convert.ToDateTime(thisDtStr + " 12:00");
  422. if (thisDt <= thisDt1) //旷工 下午
  423. {
  424. day_deduction = ConvertToDecimal(dailyWage / 2); //4.5小时
  425. meal_deduction += 10.00M;
  426. beLate_belate_ex.Duration = 270;
  427. absenteeism_deduction += day_deduction; //矿工半日
  428. beLate_belate_ex.Reason = thisDtStr + " 下午(18:00)缺卡/未打卡视为下午旷工(4.5小时)";
  429. beLate_belate_ex.Deduction = day_deduction;
  430. ex_reissuecard_Items.Add(beLate_belate_ex);
  431. }
  432. else if (thisDt >= thisDt1) //旷工 上午
  433. {
  434. day_deduction = ConvertToDecimal(dailyWage / 2); //3小时
  435. meal_deduction += 10.00M;
  436. absenteeism_deduction += day_deduction; //矿工半日
  437. beLate_belate_ex.Duration = 180;
  438. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)缺卡/未打卡视为上午旷工(3小时)";
  439. beLate_belate_ex.Deduction = day_deduction;
  440. ex_reissuecard_Items.Add(beLate_belate_ex);
  441. }
  442. else //矿工一日
  443. {
  444. day_deduction = ConvertToDecimal(dailyWage);
  445. meal_deduction += 10.00M;
  446. absenteeism_deduction += day_deduction;
  447. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)-下午(18:00) 缺卡/未打视为旷工一天(7.5小时)";
  448. beLate_belate_ex.Deduction = day_deduction;
  449. ex_reissuecard_Items.Add(beLate_belate_ex);
  450. }
  451. }
  452. }
  453. }
  454. else if (exception == 4) //旷工
  455. {
  456. if (timelength >= 60 && timelength <= 180)
  457. {
  458. day_deduction = ConvertToDecimal(dailyWage / 2); //3小时
  459. beLate_belate_ex.Reason = thisDtStr + " 缺卡/未打视为旷工半天";
  460. meal_deduction += 10.00M;
  461. absenteeism_deduction += day_deduction; //矿工半日
  462. }
  463. else if (timelength > 180 && timelength <= 270)
  464. {
  465. day_deduction = ConvertToDecimal(dailyWage / 2); //3小时
  466. beLate_belate_ex.Reason = thisDtStr + " 缺卡/未打视为旷工半天";
  467. meal_deduction += 10.00M;
  468. absenteeism_deduction += day_deduction; //矿工半日
  469. }
  470. else
  471. {
  472. day_deduction = ConvertToDecimal(dailyWage);
  473. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)-下午(18:00) 缺卡/未打视为旷工一天(7.5小时)";
  474. meal_deduction += 10.00M;
  475. absenteeism_deduction += day_deduction; //矿工一日
  476. }
  477. beLate_belate_ex.Deduction = day_deduction;
  478. ex_reissuecard_Items.Add(beLate_belate_ex);
  479. }
  480. }
  481. }
  482. #endregion
  483. #region 外出打卡 迟到 早退 旷工
  484. if (checkInData_outPunch.Count > 0)
  485. {
  486. List<Sp_Detail> sp_gooutpunch_details = new List<Sp_Detail>();
  487. sp_gooutpunch_details = await _qiYeWeChatApiService.GetApprovalDetailsAsync(startDt, endDt, acctid, 2, 4); //时间段内所有 已同意的 外出打卡 审批数据
  488. if (sp_gooutpunch_details.Count <= 0)
  489. {
  490. _result.Msg += $"{_name}:{startDt} - {endDt} 外出打卡 审批数据获取未获取到!\r\n";
  491. }
  492. List<LeaveDetails> goOutPunchDetails = new List<LeaveDetails>();
  493. foreach (Sp_Detail sp_item in sp_gooutpunch_details)
  494. {
  495. Apply_data? apply_data = sp_item.apply_data;
  496. if (apply_data != null)
  497. {
  498. List<ContentsItem> contents = apply_data.contents;
  499. ContentsItem content_Attendance = contents.Where(it => it.control == "Attendance").FirstOrDefault(); //请假类型
  500. ContentsItem content_Textarea = contents.Where(it => it.control == "Textarea").FirstOrDefault(); //多行文本
  501. if (content_Attendance != null)
  502. {
  503. Attendance attendance = content_Attendance.value.attendance; //假勤组件
  504. string goOutText = string.Empty;
  505. if (content_Textarea != null)
  506. {
  507. goOutText = content_Textarea.value.text;
  508. }
  509. Date_range date_Range = attendance.date_range;
  510. //筛选 不在工作日内的假勤申请
  511. if (Convert.ToDateTime(date_Range.new_begin_dt) < startDt || Convert.ToDateTime(date_Range.new_end_dt.ToString("yyyy-MM-dd")) > endDt)
  512. {
  513. continue;
  514. }
  515. LeaveDetails leaveDetails1 = new LeaveDetails()
  516. {
  517. TypeId = 0,
  518. TypeName = "外出打卡",
  519. StartDt = date_Range.new_begin_dt,
  520. EndDt = date_Range.new_end_dt,
  521. DtType = date_Range.type,
  522. New_Duration = date_Range.new_duration
  523. };
  524. goOutPunchDetails.Add(leaveDetails1);
  525. }
  526. }
  527. }
  528. foreach (var goOutPunchItem in goOutPunchDetails)
  529. {
  530. string thisDay = goOutPunchItem.StartDt.ToString("yyyy-MM-dd");
  531. TimeSpan sp_gooutpunchStartTime = goOutPunchItem.StartDt.TimeOfDay;
  532. TimeSpan sp_gooutpunchEndTime = goOutPunchItem.EndDt.TimeOfDay;
  533. List<CheckInDataInfo> goOut_checkInDataInfos = checkInData_outPunch.Where(it => it.checkin_time_dt.ToString("yyyy-MM-dd").Equals(thisDay)).ToList();
  534. //单天
  535. if (goOut_checkInDataInfos.Count > 1)
  536. {
  537. DateTime gooutStartDt = goOut_checkInDataInfos[0].checkin_time_dt;
  538. DateTime gooutendDt = goOut_checkInDataInfos[goOut_checkInDataInfos.Count - 1].checkin_time_dt;
  539. Ex_Item beLate_belate_ex = new Ex_Item()
  540. {
  541. SubTypeId = 4,
  542. SubType = "旷工",
  543. Duration = 0,
  544. StartTimeDt = Convert.ToDateTime(goOutPunchItem.StartDt),
  545. Unit = "分钟",
  546. Reason = "数据来源【外出打卡】"
  547. };
  548. decimal day_deduction = 0.00M;
  549. //迟到
  550. if (gooutStartDt.TimeOfDay > sp_gooutpunchStartTime)
  551. {
  552. int timeLong = gooutStartDt.Subtract(goOutPunchItem.StartDt).Minutes;
  553. beLate_belate_ex.Duration = timeLong;
  554. if (timeLong > 0 && timeLong < 10)
  555. {
  556. user_cd_zt_num++;
  557. beLate_belate_ex.SubTypeId = 1;
  558. beLate_belate_ex.SubType = "迟到";
  559. if (user_cd_zt_num >= 3)
  560. {
  561. day_deduction = 50.00M;
  562. }
  563. else
  564. {
  565. day_deduction = 0.00M;
  566. }
  567. beLate_deduction += day_deduction; //迟到扣款 总额
  568. }
  569. else if (timeLong >= 10 && timeLong < 60)
  570. {
  571. day_deduction = 50.00M;
  572. beLate_deduction += day_deduction; //迟到扣款 总额
  573. beLate_belate_ex.SubTypeId = 1;
  574. beLate_belate_ex.SubType = "迟到";
  575. }
  576. else if (timeLong >= 60 && timeLong <= 180)
  577. {
  578. day_deduction = ConvertToDecimal(dailyWage / 2); //3小时 按半天计算
  579. meal_deduction += 10.00M; //餐补扣款
  580. absenteeism_deduction += day_deduction; //矿工半日
  581. beLate_belate_ex.Reason = "数据来源【外出打卡】" + thisDay + " 上午(09:00)缺卡/未打卡视为旷工半天";
  582. }
  583. else
  584. {
  585. day_deduction = ConvertToDecimal(dailyWage);
  586. absenteeism_deduction += day_deduction; //矿工一日
  587. meal_deduction += 10.00M;
  588. beLate_belate_ex.Reason = "数据来源【外出打卡】" + thisDay + " 上午(09:00)-下午(18:00) 缺卡/未打视为旷工一天(7.5小时)";
  589. }
  590. beLate_belate_ex.Deduction = day_deduction;
  591. ex_reissuecard_Items.Add(beLate_belate_ex);
  592. }
  593. //早退
  594. if (gooutendDt.TimeOfDay < sp_gooutpunchEndTime)
  595. {
  596. int timeLong = goOutPunchItem.EndDt.Subtract(gooutendDt).Minutes;
  597. beLate_belate_ex.Duration = timeLong;
  598. if (timeLong > 0 && timeLong < 10)
  599. {
  600. user_cd_zt_num++;
  601. beLate_belate_ex.SubTypeId = 1;
  602. beLate_belate_ex.SubType = "早退";
  603. if (user_cd_zt_num >= 3)
  604. {
  605. day_deduction = 50.00M;
  606. }
  607. else
  608. {
  609. day_deduction = 0.00M;
  610. }
  611. early_deduction += day_deduction; //迟到扣款 总额
  612. }
  613. else if (timeLong >= 10 && timeLong < 60)
  614. {
  615. day_deduction = 50.00M;
  616. early_deduction += day_deduction; //迟到扣款 总额
  617. beLate_belate_ex.SubTypeId = 1;
  618. beLate_belate_ex.SubType = "早退";
  619. }
  620. else if (timeLong >= 60 && timeLong <= 180)
  621. {
  622. day_deduction = ConvertToDecimal(dailyWage / 2); //3小时 按半天计算
  623. meal_deduction += 10.00M; //餐补扣款
  624. absenteeism_deduction += day_deduction; //矿工半日
  625. beLate_belate_ex.Reason = "数据来源【外出打卡】" + thisDay + " 上午(09:00)缺卡/未打卡视为旷工半天";
  626. }
  627. else
  628. {
  629. day_deduction = ConvertToDecimal(dailyWage);
  630. absenteeism_deduction += day_deduction; //矿工一日
  631. meal_deduction += 10.00M;
  632. beLate_belate_ex.Reason = "数据来源【外出打卡】" + thisDay + " 上午(09:00)-下午(18:00) 缺卡/未打视为旷工一天(7.5小时)";
  633. }
  634. beLate_belate_ex.Deduction = day_deduction;
  635. ex_reissuecard_Items.Add(beLate_belate_ex);
  636. }
  637. }
  638. //多天
  639. }
  640. }
  641. #endregion
  642. #region 迟到早团旷工 日期排序
  643. if (ex_reissuecard_Items.Count > 0)
  644. {
  645. ex_reissuecard_Items = ex_reissuecard_Items.OrderBy(it => it.StartTimeDt).ToList();
  646. }
  647. #endregion
  648. #region 假勤/补卡次数 审批
  649. int leaveNum = 0; //请假次数
  650. int reissuecardNum = 0; //补卡次数
  651. int evectionNum = 0; //出差次数
  652. //类型:1 - 请假;2 - 补卡;3 - 出差;4 - 外出;100 - 外勤
  653. leaveNum = acc_sp_items.Where(it => it.type == 1).ToList().Count();
  654. reissuecardNum = acc_sp_items.Where(it => it.type == 2).ToList().Count();
  655. List<Sp_items> acc_sp_items_evection = new List<Sp_items>();
  656. acc_sp_items_evection = acc_sp_items.Where(it => it.type == 3).ToList();
  657. evectionNum = acc_sp_items_evection.Count();
  658. //请假审批
  659. if (leaveNum > 0)
  660. {
  661. List<Sp_Detail> sp_leave_details = new List<Sp_Detail>();
  662. sp_leave_details = await _qiYeWeChatApiService.GetApprovalDetailsAsync(startDt, endDt, acctid, 2, 1); //时间段内所有 已同意的 请假 审批数据
  663. if (sp_leave_details.Count <= 0)
  664. {
  665. _result.Msg += $"{_name}: {startDt} - {endDt} 请假 审批数据获取未获取到!\r\n";
  666. //continue;
  667. }
  668. List<Ex_Item> ex_ItemInfos = new List<Ex_Item>();
  669. List<LeaveDetails> leaveDetails = new List<LeaveDetails>();
  670. foreach (Sp_Detail sp_item in sp_leave_details)
  671. {
  672. Apply_data? apply_data = sp_item.apply_data;
  673. if (apply_data != null)
  674. {
  675. List<ContentsItem> contents = apply_data.contents;
  676. ContentsItem content_Vacation = contents.Where(it => it.control == "Vacation").FirstOrDefault(); //请假类型
  677. ContentsItem content_Textarea = contents.Where(it => it.control == "Textarea").FirstOrDefault(); //多行文本
  678. if (content_Vacation != null)
  679. {
  680. Vacation vacation = content_Vacation.value.vacation;
  681. Attendance attendance = vacation.attendance; //假勤组件
  682. Selector selector = vacation.selector; //请假类型
  683. List<OptionsItem> optionsItems = selector.options; //key 请假类型 id
  684. List<TitleItem> value = optionsItems[0].value; // value 文本描述值
  685. int leaveType = int.Parse(optionsItems[0].key); //key 请假子类型 id
  686. Date_range date_Range = attendance.date_range;
  687. //筛选 不在工作日内的假勤申请
  688. //if (Convert.ToDateTime(date_Range.new_begin_dt) < startDt || Convert.ToDateTime(date_Range.new_end_dt.ToString("yyyy-MM-dd")) > endDt)
  689. //{
  690. // continue;
  691. //}
  692. //假期只要开始时间,结束时间在计算时间范围 即纳入计算
  693. if ((Convert.ToDateTime(date_Range.new_begin_dt) < startDt || Convert.ToDateTime(date_Range.new_begin_dt) > endDt) &&
  694. (Convert.ToDateTime(date_Range.new_end_dt) < startDt || Convert.ToDateTime(date_Range.new_end_dt) > endDt))
  695. {
  696. continue;
  697. }
  698. string leave_starttime = date_Range.new_begin_dt.ToString("HH:mm");
  699. string leave_endtime = date_Range.new_end_dt.ToString("HH:mm");
  700. string typeName = string.Empty;
  701. string unit = string.Empty;
  702. int leaveTypeId = leaveType;
  703. var leaveTypeData = vacationLeaveTypes.Where(it => it.id == leaveTypeId).FirstOrDefault();
  704. if (leaveTypeData != null) { typeName = leaveTypeData.name; }
  705. string startTime = string.Empty;
  706. string endTime = string.Empty;
  707. string startTime1 = string.Empty;
  708. string endTime1 = string.Empty;
  709. Slice_info slice_info = new Slice_info();
  710. //2事假;3病假;
  711. if (leaveTypeId == 2 || leaveTypeId == 3)
  712. {
  713. slice_info = vacation.attendance.slice_info;
  714. }
  715. DateTime date_Range_new_begin_dt = date_Range.new_begin_dt;
  716. DateTime date_Range_new_end_dt = date_Range.new_end_dt;
  717. //计算请假类型扣款金额
  718. decimal new_duration = 0.00M;
  719. if (date_Range.type == "halfday")
  720. {
  721. new_duration = Convert.ToDecimal(date_Range.new_duration) / 86400.00M;
  722. if (date_Range.new_begin_dt < startDt)
  723. {
  724. decimal new_duration_count = new_duration;
  725. new_duration = 0.00M;
  726. for (int i = 0; i < new_duration_count; i++)
  727. {
  728. DateTime thisDt = date_Range.new_begin_dt.AddDays(i);
  729. Sys_Calendar sys_Calendar = new Sys_Calendar();
  730. sys_Calendar = sys_Calendars.Where(it => it.Dt == thisDt.ToString("yyyy-MM-dd")).FirstOrDefault();
  731. if (sys_Calendar != null)
  732. {
  733. if (sys_Calendar.IsWorkDay)
  734. {
  735. new_duration++;
  736. }
  737. }
  738. }
  739. }
  740. unit = "天";
  741. startTime = date_Range_new_begin_dt.ToString("yyyy-MM-dd") + " 09:00";
  742. endTime = date_Range_new_end_dt.ToString("yyyy-MM-dd") + " 18:00";
  743. if (new_duration > 0.50M)
  744. {
  745. if (slice_info != null)
  746. {
  747. if (slice_info.day_items != null)
  748. {
  749. if (slice_info.day_items.Count > 1)
  750. {
  751. date_Range_new_begin_dt = slice_info.day_items[0].daytimeDt;
  752. date_Range_new_end_dt = slice_info.day_items[slice_info.day_items.Count - 1].daytimeDt;
  753. decimal startTime11 = slice_info.day_items[0].duration;
  754. decimal startTime11_11 = startTime11 / 3600.00M;
  755. decimal endTime11 = slice_info.day_items[slice_info.day_items.Count - 1].duration;
  756. decimal endTime11_11 = endTime11 / 3600.00M;
  757. if (startTime11_11 == 3.00M)
  758. {
  759. startTime1 = "09:00";
  760. }
  761. else if (startTime11_11 == 4.50M)
  762. {
  763. startTime1 = "12:00";
  764. }
  765. else if (startTime11_11 == 7.50M)
  766. {
  767. startTime1 = "09:00";
  768. }
  769. if (endTime11_11 == 3.00M)
  770. {
  771. endTime1 = "12:00";
  772. }
  773. else if (endTime11_11 == 4.50M)
  774. {
  775. endTime1 = "18:00";
  776. }
  777. else if (endTime11_11 == 7.50M)
  778. {
  779. endTime1 = "18:00";
  780. }
  781. }
  782. else
  783. {
  784. decimal qjLongTime = slice_info.duration / 3600.00M;
  785. if (qjLongTime == 4.50M)
  786. {
  787. startTime1 = "12:00";
  788. endTime1 = "18:00:00";
  789. }
  790. else if (qjLongTime == 3.00M)
  791. {
  792. startTime1 = "09:00";
  793. endTime1 = "12:00:00";
  794. }
  795. else if (qjLongTime % 7.50M == 0)
  796. {
  797. startTime1 = "09:00";
  798. endTime1 = "18:00:00";
  799. }
  800. }
  801. }
  802. else
  803. {
  804. if (new_duration % 1 == 0)
  805. {
  806. startTime1 = "09:00";
  807. endTime1 = "18:00";
  808. }
  809. }
  810. }
  811. else
  812. {
  813. if (new_duration % 1 == 0)
  814. {
  815. startTime1 = "09:00";
  816. endTime1 = "18:00";
  817. }
  818. }
  819. }
  820. else
  821. {
  822. if (new_duration % 1 == 0)
  823. {
  824. startTime1 = "09:00";
  825. endTime1 = "18:00";
  826. }
  827. else
  828. {
  829. startTime1 = date_Range_new_begin_dt.ToString("HH:mm:ss");
  830. endTime1 = date_Range_new_end_dt.ToString("HH:mm:ss");
  831. }
  832. }
  833. }
  834. else if (date_Range.type == "hour")
  835. {
  836. new_duration = Convert.ToDecimal(date_Range.new_duration) / 3600.00M;
  837. unit = "小时";
  838. startTime = date_Range_new_begin_dt.ToString("yyyy-MM-dd HH:mm:ss");
  839. endTime = date_Range_new_end_dt.ToString("yyyy-MM-dd HH:mm:ss");
  840. startTime1 = date_Range_new_begin_dt.ToString("HH:mm:ss");
  841. endTime1 = date_Range_new_end_dt.ToString("HH:mm:ss");
  842. }
  843. LeaveDetails leaveDetails1 = new LeaveDetails()
  844. {
  845. TypeId = leaveType,
  846. TypeName = typeName,
  847. StartDt = Convert.ToDateTime(date_Range_new_begin_dt.ToString("yyyy-MM-dd") + " " + startTime1),
  848. EndDt = Convert.ToDateTime(date_Range_new_end_dt.ToString("yyyy-MM-dd") + " " + endTime1),
  849. DtType = date_Range.type,
  850. Unit = unit,
  851. New_Duration = new_duration,
  852. SliceInfo = slice_info
  853. };
  854. leaveDetails.Add(leaveDetails1);
  855. }
  856. }
  857. }
  858. #region 年假测试数据
  859. //leaveDetails.Add(new LeaveDetails() {
  860. // TypeId = 1,
  861. // TypeName = "年假",
  862. // StartDt = Convert.ToDateTime("2023-11-21 09:00:00"),
  863. // EndDt = Convert.ToDateTime("2023-11-21 12:00:00"),
  864. // DtType = "halfday",
  865. // Unit = "天",
  866. // New_Duration = 0.50M
  867. //});
  868. //leaveDetails.Add(new LeaveDetails()
  869. //{
  870. // TypeId = 1,
  871. // TypeName = "年假",
  872. // StartDt = Convert.ToDateTime("2023-11-21 12:00:00"),
  873. // EndDt = Convert.ToDateTime("2023-11-23 18:00:00"),
  874. // DtType = "halfday",
  875. // Unit = "天",
  876. // New_Duration = 2.50M
  877. //});
  878. #endregion
  879. if (leaveDetails.Count > 0)
  880. {
  881. leaveDetails = leaveDetails.OrderBy(it => it.StartDt).OrderBy(it => it.EndDt).ToList();
  882. foreach (LeaveDetails leave_item in leaveDetails)
  883. {
  884. decimal leave_meals = 0.00M;
  885. decimal thisTypeDeduction = 0.00M;//当前类型扣款
  886. int leaveType = leave_item.TypeId;
  887. decimal new_duration = leave_item.New_Duration;
  888. #region 处理跨月天数
  889. if (leave_item.EndDt > endDt)
  890. {
  891. DateTime dt1 = Convert.ToDateTime(leave_item.StartDt.ToString("yyyy-MM-dd") + " 12:00");
  892. DateTime dt2 = Convert.ToDateTime(leave_item.StartDt.ToString("yyyy-MM-dd") + " 09:00");
  893. TimeSpan ts = Convert.ToDateTime(endDt.ToString("yyyy-MM-dd") + " 18:00") - Convert.ToDateTime(leave_item.StartDt.ToString("yyyy-MM-dd"));
  894. if (dt2 >= leave_item.StartDt && leave_item.StartDt <= dt1)
  895. {
  896. new_duration = ts.Days + 1;
  897. }
  898. else
  899. {
  900. new_duration = ts.Days + 1.00M + 0.50M;
  901. }
  902. }
  903. #endregion
  904. //计算餐补 假勤类型扣款
  905. CalculateTypeFee1(leaveDetails, leaveType, leave_item.DtType, leave_item.StartDt, leave_item.EndDt, amountPayable, work_days,
  906. new_duration, out leave_meals, out thisTypeDeduction);
  907. if (leave_meals != 0)
  908. {
  909. leave_item.IsDeduction = true;
  910. }
  911. #region 累计类型扣款
  912. //1年假;2事假;3病假;4调休假;5婚假;6产假;7陪产假;8其他;9丧假
  913. if (leaveType == 2) //事假
  914. {
  915. personalLeaveTotal += thisTypeDeduction;
  916. }
  917. else if (leaveType == 3) //病假
  918. {
  919. sickLeaveTotal += thisTypeDeduction;
  920. }
  921. #endregion
  922. meal_deduction += leave_meals;
  923. Ex_Item ex_Item = new Ex_Item()
  924. {
  925. SubTypeId = leaveType,
  926. SubType = leave_item.TypeName,
  927. StartTimeDt = leave_item.StartDt,
  928. EndTimeDt = leave_item.EndDt,
  929. Duration = new_duration,
  930. Unit = leave_item.Unit,
  931. Deduction = thisTypeDeduction,
  932. //Reason = apply_data.reason,
  933. Apply_time_dt = leave_item.ApplyDt,
  934. //Approval_name = sp_item.approval_name,
  935. };
  936. ex_ItemInfos.Add(ex_Item);
  937. }
  938. }
  939. if (ex_ItemInfos.Count > 0)
  940. {
  941. ex_Items_jq.Ex_ItemInfo = ex_ItemInfos.OrderBy(it => it.StartTimeDt).ThenBy(it => it.Apply_time_dt).ToList();
  942. ex_Items.Add(ex_Items_jq);
  943. }
  944. }
  945. //打卡补卡
  946. //补卡:员工发现自己漏打卡时,需及时提起补卡申请,并说明情况。
  947. //试用期员工每月有 2 次补卡机会,超过 2 次不足 5 次的部分,按 10 元/次处罚,5 次及以上的漏卡,按 50 元/次处罚;
  948. //正式员工每月 3 次以内的补卡,按 10 元/次处罚,3 次及以上的漏卡,按 50 元/次处罚。
  949. if (reissuecardNum > 0)
  950. {
  951. List<Sp_Detail> sp_buka_details = new List<Sp_Detail>();
  952. sp_buka_details = await _qiYeWeChatApiService.GetApprovalDetailsAsync(startDt, endDt, acctid, 2, 2); //时间段内所有 已同意的 请假 审批数据
  953. //外出审批 已通过的数据 且 外出未打卡
  954. List<Sp_Detail> sp_goout_details = new List<Sp_Detail>();
  955. sp_goout_details = await _qiYeWeChatApiService.GetApprovalDetailsAsync(startDt, endDt, acctid, 2, 4); //时间段内所有 已同意的 外出 审批数据
  956. //打卡记录-未打卡 处理日期范围内的数据
  957. List<CheckInDataInfo> filtratePrefix_checkInData = new List<CheckInDataInfo>();
  958. //打卡记录-未打卡 扣款
  959. if (sp_goout_details.Count > 0)
  960. {
  961. //找出外出的具体日期
  962. List<string> goOutDts = new List<string>();
  963. foreach (var goOutItem in sp_goout_details)
  964. {
  965. Apply_data? apply_data = goOutItem.apply_data;
  966. if (apply_data != null)
  967. {
  968. List<ContentsItem> contents = apply_data.contents;
  969. ContentsItem content_Vacation = contents.Where(it => it.control == "Attendance").FirstOrDefault(); //请假类型
  970. ContentsItem content_Textarea = contents.Where(it => it.control == "Textarea").FirstOrDefault(); //多行文本
  971. if (content_Vacation != null)
  972. {
  973. var attendance = content_Vacation.value.attendance;
  974. DateTime goOutDt = attendance.date_range.new_begin_dt;
  975. DateTime goOutDtJudge = Convert.ToDateTime(goOutDt.ToString("yyyy-MM-dd"));
  976. //筛选 不在工作日内的假勤申请
  977. if (startDt >= goOutDtJudge || goOutDtJudge > endDt)
  978. {
  979. continue;
  980. }
  981. goOutDts.Add(goOutDt.ToString("yyyy-MM-dd"));
  982. }
  983. }
  984. }
  985. if (goOutDts.Count > 0)
  986. {
  987. foreach (var goOutDtItem in goOutDts)
  988. {
  989. List<CheckInDataInfo> filtrate_checkInData = new List<CheckInDataInfo>();
  990. filtrate_checkInData = checkInData2.Where(it => it.checkin_time_dt.ToString("yyyy-MM-dd").Equals(goOutDtItem)).ToList();
  991. if (filtrate_checkInData.Count > 0)
  992. {
  993. filtratePrefix_checkInData.AddRange(filtrate_checkInData);
  994. }
  995. }
  996. }
  997. }
  998. int bukaNum = 1;
  999. foreach (var item in sp_buka_details)
  1000. {
  1001. Apply_data? apply_data = item.apply_data;
  1002. if (apply_data != null)
  1003. {
  1004. List<ContentsItem> contents = apply_data.contents;
  1005. ContentsItem content_Vacation = contents.Where(it => it.control == "PunchCorrection").FirstOrDefault(); //请假类型
  1006. ContentsItem content_Textarea = contents.Where(it => it.control == "Textarea").FirstOrDefault(); //多行文本
  1007. if (content_Vacation != null)
  1008. {
  1009. var punch_correction = content_Vacation.value.punch_correction;
  1010. DateTime bukaDt = punch_correction.time_dt;
  1011. DateTime bukaDtJudge = Convert.ToDateTime(bukaDt.ToString("yyyy-MM-dd"));
  1012. //筛选 不在工作日内的假勤申请
  1013. if (startDt > bukaDtJudge || bukaDtJudge > endDt)
  1014. {
  1015. continue;
  1016. }
  1017. decimal bukaPrice = 0.00M;
  1018. if (user_probationary_bk_decimal == 0) //计算试用员工补卡次数
  1019. {
  1020. if (bukaNum <= 2) bukaPrice = 0.00M;
  1021. else if (bukaNum <= 4 && bukaNum > 2) bukaPrice = 10.00M;
  1022. else bukaPrice = 50.00M;
  1023. }
  1024. else //计算正式员工补卡次数
  1025. {
  1026. if (bukaNum <= 2) bukaPrice = 10.00M;
  1027. else bukaPrice = 50.00M;
  1028. }
  1029. var app_data = item.apply_data;
  1030. var punch_correction1 = app_data.contents[0].value.punch_correction; //未打卡时间
  1031. var punch_correction2 = app_data.contents[1].value;
  1032. #region 处理未打卡记录表数据 已补卡的数据
  1033. if (filtratePrefix_checkInData.Count > 0)
  1034. {
  1035. var filtratePrefix_checkInItems = filtratePrefix_checkInData.Where(it => it.sch_checkin_time_dt.ToString("yyyy-MM-dd")
  1036. .Equals(punch_correction1.time_dt.ToString("yyyy-MM-dd"))).ToList();
  1037. if (filtratePrefix_checkInItems.Count > 0)
  1038. {
  1039. //按时间段移除 上午补卡时间段 09:00 - 12:00 下午补卡时间段 12:00 - 18:00
  1040. TimeSpan _strWorkingDayAM = DateTime.Parse("09:00").TimeOfDay;
  1041. TimeSpan _endWorkingDayAM = DateTime.Parse("12:00").TimeOfDay;
  1042. TimeSpan _strWorkingDayPM = DateTime.Parse("13:30").TimeOfDay;
  1043. TimeSpan _endWorkingDayPM = DateTime.Parse("18:00").TimeOfDay;
  1044. TimeSpan _dspNow = punch_correction1.time_dt.TimeOfDay;
  1045. //上午时间段 打卡记录数据
  1046. var filtratePrefix_checkInItemAMs = filtratePrefix_checkInItems.Where(it => it.sch_checkin_time_dt.TimeOfDay >= _strWorkingDayAM &&
  1047. it.sch_checkin_time_dt.TimeOfDay <= _endWorkingDayAM).ToList();
  1048. if (filtratePrefix_checkInItemAMs.Count > 0)
  1049. {
  1050. foreach (var filtratePrefix_checkInItem1 in filtratePrefix_checkInItemAMs)
  1051. {
  1052. filtratePrefix_checkInData.Remove(filtratePrefix_checkInItem1);
  1053. }
  1054. }
  1055. //下午时间段 打卡记录数据
  1056. var filtratePrefix_checkInItemPMs = filtratePrefix_checkInItems.Where(it => it.sch_checkin_time_dt.TimeOfDay >= _strWorkingDayPM &&
  1057. it.sch_checkin_time_dt.TimeOfDay <= _endWorkingDayPM).ToList();
  1058. if (filtratePrefix_checkInItemPMs.Count > 0)
  1059. {
  1060. foreach (var filtratePrefix_checkInItem1 in filtratePrefix_checkInItemPMs)
  1061. {
  1062. filtratePrefix_checkInData.Remove(filtratePrefix_checkInItem1);
  1063. }
  1064. }
  1065. }
  1066. }
  1067. #endregion
  1068. Ex_Item ex_reissueCard = new Ex_Item()
  1069. {
  1070. SubTypeId = 7,
  1071. SubType = "打卡补卡",
  1072. StartTimeDt = Convert.ToDateTime(punch_correction1.time_dt.ToString("yyyy-MM-dd HH:mm:ss")), //未打卡时间
  1073. Deduction = bukaPrice,
  1074. Reason = punch_correction2.text,
  1075. Unit = string.Empty
  1076. };
  1077. unprinted_deduction += bukaPrice;
  1078. ex_reissuecard_Items.Add(ex_reissueCard);
  1079. bukaNum++;
  1080. }
  1081. }
  1082. }
  1083. //打卡记录里抓取的未打卡数据 扣款
  1084. foreach (var item in filtratePrefix_checkInData)
  1085. {
  1086. decimal bukaPrice = 0.00M;
  1087. if (user_probationary_bk_decimal == 0) //计算试用员工补卡次数
  1088. {
  1089. if (bukaNum <= 2) bukaPrice = 0.00M;
  1090. else if (bukaNum <= 4 && bukaNum > 2) bukaPrice = 10.00M;
  1091. else bukaPrice = 50.00M;
  1092. }
  1093. else //计算正式员工补卡次数
  1094. {
  1095. if (bukaNum <= 2) bukaPrice = 10.00M;
  1096. else bukaPrice = 50.00M;
  1097. }
  1098. Ex_Item ex_reissueCard = new Ex_Item()
  1099. {
  1100. SubTypeId = 7,
  1101. SubType = "打卡补卡",
  1102. StartTimeDt = Convert.ToDateTime(item.checkin_time_dt.ToString("yyyy-MM-dd HH:mm:ss")), //未打卡时间
  1103. Deduction = bukaPrice,
  1104. Reason = "[打卡记录]抓取到的未打卡数据!",
  1105. Unit = string.Empty
  1106. };
  1107. unprinted_deduction += bukaPrice;
  1108. ex_reissuecard_Items.Add(ex_reissueCard);
  1109. bukaNum++;
  1110. }
  1111. }
  1112. if (ex_reissuecard_Items.Count > 0)
  1113. {
  1114. ex_Items_dk.Ex_ItemInfo = ex_reissuecard_Items;
  1115. ex_Items_dk.Ex_ItemInfo = ex_reissuecard_Items.OrderBy(it => it.SubTypeId).ThenBy(it => it.StartTimeDt).ToList();
  1116. ex_Items.Add(ex_Items_dk);
  1117. }
  1118. //出差申请
  1119. if (evectionNum > 0)
  1120. {
  1121. List<Sp_Detail> sp_leave_details = new List<Sp_Detail>();
  1122. sp_leave_details = await _qiYeWeChatApiService.GetApprovalDetailsAsync(startDt, endDt, acctid, 2, 3); //时间段内所有 已同意的 出差 审批数据
  1123. if (sp_leave_details.Count <= 0)
  1124. {
  1125. _result.Msg += $"{_name}: {startDt} - {endDt} 请假 审批数据获取未获取到!\r\n";
  1126. //continue;
  1127. }
  1128. List<Ex_Item> cc_ex_ItemInfos = new List<Ex_Item>();
  1129. foreach (Sp_Detail sp_item in sp_leave_details)
  1130. {
  1131. Apply_data? apply_data = sp_item.apply_data;
  1132. if (apply_data != null)
  1133. {
  1134. List<ContentsItem> contents = apply_data.contents;
  1135. ContentsItem content_Vacation = contents.Where(it => it.control == "Attendance").FirstOrDefault(); //出差类型
  1136. ContentsItem content_Textarea = contents.Where(it => it.control == "Textarea").FirstOrDefault(); //多行文本
  1137. if (content_Vacation != null)
  1138. {
  1139. //Vacation vacation = content_Vacation.value.vacation;
  1140. Attendance attendance = content_Vacation.value.attendance; //假勤组件
  1141. //Selector selector = vacation.selector; //请假类型
  1142. //List<OptionsItem> optionsItems = selector.options; //key 请假类型 id
  1143. //List<TitleItem> value = optionsItems[0].value; // value 文本描述值
  1144. int leaveType = int.Parse("3"); //key 请假子类型 id
  1145. Date_range date_Range = attendance.date_range;
  1146. //筛选 不在工作日内的假勤申请
  1147. if (date_Range.new_begin_dt < startDt || date_Range.new_end_dt > endDt)
  1148. {
  1149. continue;
  1150. }
  1151. string leave_starttime = date_Range.new_begin_dt.ToString("HH:mm");
  1152. string leave_endtime = date_Range.new_end_dt.ToString("HH:mm");
  1153. string typeName = string.Empty;
  1154. string unit = string.Empty;
  1155. int leaveTypeId = leaveType;
  1156. typeName = "出差";
  1157. string startTime = string.Empty;
  1158. string endTime = string.Empty;
  1159. string startTime1 = string.Empty;
  1160. string endTime1 = string.Empty;
  1161. //计算请假类型扣款金额
  1162. decimal new_duration = 0.00M;
  1163. if (date_Range.type == "halfday")
  1164. {
  1165. new_duration = Convert.ToDecimal(date_Range.new_duration) / 86400.00M;
  1166. unit = "天";
  1167. startTime = date_Range.new_begin_dt.ToString("yyyy-MM-dd") + " 00:00";
  1168. endTime = date_Range.new_end_dt.ToString("yyyy-MM-dd") + " 00:00";
  1169. startTime1 = "00:00:00";
  1170. endTime1 = "00:00:00";
  1171. }
  1172. else if (date_Range.type == "hour")
  1173. {
  1174. new_duration = Convert.ToDecimal(date_Range.new_duration) / 3600.00M;
  1175. unit = "小时";
  1176. startTime = date_Range.new_begin_dt.ToString("yyyy-MM-dd HH:mm:ss");
  1177. endTime = date_Range.new_end_dt.ToString("yyyy-MM-dd HH:mm:ss");
  1178. startTime1 = date_Range.new_begin_dt.ToString("HH:mm:ss");
  1179. endTime1 = date_Range.new_end_dt.ToString("HH:mm:ss");
  1180. }
  1181. //出差扣款
  1182. decimal cckk = 0.00M;
  1183. int days = (int)(Convert.ToDateTime(date_Range.new_end_dt.ToString("yyyy-MM-dd")) -
  1184. Convert.ToDateTime(date_Range.new_begin_dt.ToString("yyyy-MM-dd"))).TotalDays + 1;
  1185. for (int i = 0; i < days; i++)
  1186. {
  1187. DateTime thisDt = date_Range.new_begin_dt.AddDays(i);
  1188. //处理开始时间 是否在当天工作时间内
  1189. if (i == 0) //开始时间
  1190. {
  1191. if (!date_Range.type.Equals("halfday"))
  1192. {
  1193. string ccStartTime = thisDt.ToString("HH:mm:ss");
  1194. if (!IsWorkTime(ccStartTime))
  1195. {
  1196. continue;
  1197. }
  1198. }
  1199. }
  1200. //处理结束时间 是否在当天工作时间内
  1201. if (i == days - 1)
  1202. {
  1203. if (!date_Range.type.Equals("halfday"))
  1204. {
  1205. string ccStartTime = date_Range.new_end_dt.ToString("HH:mm:ss");
  1206. if (!IsWorkTime(ccStartTime))
  1207. {
  1208. continue;
  1209. }
  1210. }
  1211. }
  1212. Sys_Calendar sys_Calendar = new Sys_Calendar();
  1213. sys_Calendar = sys_Calendars.Where(it => it.Dt == thisDt.ToString("yyyy-MM-dd")).FirstOrDefault();
  1214. if (sys_Calendar != null)
  1215. {
  1216. if (sys_Calendar.IsWorkDay)
  1217. {
  1218. cckk += 10.00M;
  1219. }
  1220. }
  1221. }
  1222. meal_deduction += cckk;
  1223. Ex_Item ex_Item = new Ex_Item()
  1224. {
  1225. SubTypeId = leaveType,
  1226. SubType = typeName,
  1227. StartTimeDt = Convert.ToDateTime(date_Range.new_begin_dt.ToString("yyyy-MM-dd") + " " + startTime1),
  1228. EndTimeDt = Convert.ToDateTime(date_Range.new_end_dt.ToString("yyyy-MM-dd") + " " + endTime1),
  1229. Duration = new_duration,
  1230. Unit = unit,
  1231. Deduction = 0.00M,
  1232. //Reason = apply_data.reason,
  1233. Apply_time_dt = Convert.ToDateTime(sp_item.apply_time_dt.ToString("yyyy-MM-dd HH:mm:ss"))
  1234. //Approval_name = sp_item.approval_name,
  1235. };
  1236. cc_ex_ItemInfos.Add(ex_Item);
  1237. }
  1238. }
  1239. }
  1240. if (cc_ex_ItemInfos.Count > 0)
  1241. {
  1242. //ex_Items_cc.Ex_ItemInfo = cc_ex_ItemInfos.OrderBy(it => it.StartTimeDt).ThenBy(it => it.Apply_time_dt).ToList();
  1243. //;
  1244. //ex_Items.Add(ex_Items_cc);
  1245. List<Ex_Item> ex_jq_Items = new List<Ex_Item>();
  1246. List<Ex_Item> ex_Items1 = new List<Ex_Item>();
  1247. ex_Items1 = (List<Ex_Item>)ex_Items_jq.Ex_ItemInfo;
  1248. if (ex_Items1 != null && ex_Items1.Count > 0)
  1249. {
  1250. ex_jq_Items = ex_Items1;
  1251. }
  1252. ex_jq_Items.AddRange(cc_ex_ItemInfos);
  1253. ex_Items.Remove(ex_Items_jq);
  1254. ex_Items.Add(
  1255. new Ex_Items()
  1256. {
  1257. Type = "假勤",
  1258. Ex_ItemInfo = ex_jq_Items.OrderBy(it => it.StartTimeDt).ThenBy(it => it.Apply_time_dt).ToList()
  1259. }
  1260. );
  1261. }
  1262. }
  1263. #endregion
  1264. }
  1265. else
  1266. {
  1267. meal_subsidy = work_days * 10.00M;
  1268. }
  1269. #region 应发合计 实发合计 扣款合计(假勤扣款,其他扣款,社保扣款,公积金代扣,个税扣款)
  1270. int workDays = dk_work_days + spe_offdays;
  1271. decimal mealTotal = meal_subsidy - meal_deduction; //餐补
  1272. decimal salaryTotal = 0.00M;
  1273. if (dk_work_days >= work_days)
  1274. {
  1275. dk_work_days = work_days;
  1276. salaryTotal = amountPayable + mealTotal + pm_wsInfo.OtherHandle; //应发合计
  1277. }
  1278. else
  1279. {
  1280. if (_name.Equals("张海麟"))
  1281. {
  1282. salaryTotal = amountPayable + mealTotal + pm_wsInfo.OtherHandle; //应发合计
  1283. }
  1284. else
  1285. {
  1286. salaryTotal = (workDays * dailyWage) + mealTotal + pm_wsInfo.OtherHandle; //应发合计
  1287. }
  1288. }
  1289. //扣款合计 不含个税
  1290. decimal eductionTotal = sickLeaveTotal + personalLeaveTotal + beLate_deduction + early_deduction + absenteeism_deduction + unprinted_deduction + other_deduction +
  1291. pm_wsInfo.WithholdingInsurance + pm_wsInfo.ReservedFunds + pm_wsInfo.OtherDeductions;
  1292. decimal actualReleaseTotal = salaryTotal - eductionTotal; //实发合计 * 不含个税
  1293. #endregion
  1294. #region 处理当月工资数据
  1295. pm_wsInfo.YearMonth = thisYearMonth;
  1296. pm_wsInfo.StartDate = startDt.ToString("yyyy-MM-dd");
  1297. pm_wsInfo.EndDate = endDt.ToString("yyyy-MM-dd");
  1298. pm_wsInfo.WorkDays = work_days; //当月应出勤天数
  1299. pm_wsInfo.RegularDays = workDays; //当月正常出勤天数
  1300. pm_wsInfo.SickLeave = sickLeaveTotal; //病假
  1301. pm_wsInfo.SomethingFalse = personalLeaveTotal; //事假
  1302. pm_wsInfo.LateTo = beLate_deduction; //迟到
  1303. pm_wsInfo.LeaveEarly = early_deduction; //早退
  1304. pm_wsInfo.Absenteeism = absenteeism_deduction; //旷工
  1305. pm_wsInfo.NotPunch = unprinted_deduction; //未打卡
  1306. pm_wsInfo.OtherDeductions = other_deduction; //其他
  1307. pm_wsInfo.Ex_ItemsRemark = JsonConvert.SerializeObject(ex_Items); //
  1308. pm_wsInfo.Mealsupplement = mealTotal; //餐补
  1309. pm_wsInfo.Should = ConvertToDecimal(salaryTotal); //应发合计
  1310. pm_wsInfo.TotalDeductions = ConvertToDecimal(eductionTotal); //扣款合计
  1311. pm_wsInfo.TotalRealHair = ConvertToDecimal(actualReleaseTotal - pm_wsInfo.WithholdingTax); //实发合计
  1312. pm_wsInfo.AfterTax = ConvertToDecimal(actualReleaseTotal - pm_wsInfo.WithholdingTax); //税后工资
  1313. pm_wsInfo.LastUpdateUserId = userId;
  1314. pm_wsInfo.LastUpdateDt = DateTime.Now;
  1315. pm_wsInfo.CreateUserId = userId;
  1316. pm_wsInfo.CreateTime = DateTime.Now;
  1317. pm_wsInfo.DeleteUserId = null;
  1318. pm_wsInfo.DeleteTime = string.Empty;
  1319. #endregion
  1320. }
  1321. }
  1322. catch (Exception ex)
  1323. {
  1324. _result.Msg = $"【{_name}】【Msg:{ex.Message}】";
  1325. return _result;
  1326. }
  1327. _result.Code = 0;
  1328. _result.Data = pm_WageSheetDattaSources;
  1329. return _result;
  1330. }
  1331. /// <summary>
  1332. /// 是否在工作时间内
  1333. /// </summary>
  1334. /// <param name="timeStr"></param>
  1335. /// <returns></returns>
  1336. public static bool IsWorkTime(string timeStr)
  1337. {
  1338. string thisDayWorkStartTime = "09:00:00";
  1339. string thisDayWorkEndTime = "18:00:00";
  1340. TimeSpan dspWorkingDayAM = DateTime.Parse(thisDayWorkStartTime).TimeOfDay;
  1341. TimeSpan dspWorkingDayPM = DateTime.Parse(thisDayWorkEndTime).TimeOfDay;
  1342. DateTime dt = Convert.ToDateTime(timeStr);
  1343. TimeSpan dspNow = dt.TimeOfDay;
  1344. if (dspNow >= dspWorkingDayAM && dspNow <= dspWorkingDayPM)
  1345. {
  1346. return true;
  1347. }
  1348. return false;
  1349. }
  1350. /// <summary>
  1351. /// decimal 保留两位小数 不四舍五入
  1352. /// </summary>
  1353. /// <param name="myDecimal"></param>
  1354. /// <returns></returns>
  1355. public static decimal ConvertToDecimal(decimal myDecimal)
  1356. {
  1357. var subDecimal = Math.Floor(myDecimal * 100) / 100;//保留两位小数,直接截取
  1358. return subDecimal;
  1359. }
  1360. /// <summary>
  1361. /// decimal 保留两位小数 不四舍五入
  1362. /// </summary>
  1363. /// <param name="myDecimal"></param>
  1364. /// <returns></returns>
  1365. public static decimal ConvertToDecimal1(this decimal myDecimal)
  1366. {
  1367. var subDecimal = Math.Floor(myDecimal * 100) / 100;//保留两位小数,直接截取
  1368. return subDecimal;
  1369. }
  1370. /// <summary>
  1371. /// 列表的成员移动到列表的前面
  1372. /// </summary>
  1373. /// <typeparam name="T"></typeparam>
  1374. /// <param name="list"></param>
  1375. /// <param name="index"></param>
  1376. public static void MoveItemAtIndexToFront<T>(this List<T> list, int index)
  1377. {
  1378. T item = list[index];
  1379. list.RemoveAt(index);
  1380. list.Insert(0, item);
  1381. }
  1382. /// <summary>
  1383. /// 获取请假类型
  1384. /// </summary>
  1385. /// <param name="template_id"></param>
  1386. /// <returns></returns>
  1387. public static async Task<List<VacationLeaveTypeView>> GetVacationLeaveTypes(string template_id)
  1388. {
  1389. List<VacationLeaveTypeView> vacationLeaveTypes = new List<VacationLeaveTypeView>();
  1390. TemplateDetailView templateDetailView = new TemplateDetailView();
  1391. templateDetailView = await _qiYeWeChatApiService.GetTemplateDetailAsync(template_id);
  1392. if (templateDetailView.errcode != 0)
  1393. {
  1394. Serilog.Log.Error("【企业微信】【审批】【获取假勤类型的审批】【Msg】" + templateDetailView.errmsg);
  1395. return vacationLeaveTypes;
  1396. }
  1397. List<VacationItemInfo> VacationItemInfos = templateDetailView.vacation_list.item;
  1398. foreach (var item in VacationItemInfos)
  1399. {
  1400. ValueItem valueInfo = item.name.Where(it => it.lang == "zh_CN").FirstOrDefault();
  1401. if (valueInfo != null)
  1402. {
  1403. vacationLeaveTypes.Add(
  1404. new VacationLeaveTypeView()
  1405. {
  1406. id = item.id,
  1407. name = valueInfo.text
  1408. });
  1409. }
  1410. }
  1411. return vacationLeaveTypes;
  1412. }
  1413. /// <summary>
  1414. /// 计算类型费用
  1415. /// 病假 事假 计算 按天计算
  1416. /// </summary>
  1417. /// <param name="leaveDetails"></param>
  1418. /// <param name="leaveType">1年假;2事假;3病假;4调休假;5婚假;6产假;7陪产假;8其他;9丧假</param>
  1419. /// <param name="date_Range_type"></param>
  1420. /// <param name="startTime"></param>
  1421. /// <param name="endTime"></param>
  1422. /// <param name="amountPayable"></param>
  1423. /// <param name="work_days"></param>
  1424. /// <param name="duration"></param>
  1425. /// <param name="mealDeduction"></param>
  1426. /// <param name="typeDeduction"></param>
  1427. public static void CalculateTypeFee1(List<LeaveDetails> leaveDetails, int leaveType, string date_Range_type, DateTime startTime, DateTime endTime,
  1428. decimal amountPayable, int work_days, decimal duration, out decimal mealDeduction, out decimal typeDeduction)
  1429. {
  1430. typeDeduction = 0;
  1431. mealDeduction = 0;
  1432. decimal personalkLeave_dailywage_day = amountPayable / work_days; //日薪 = 事假日薪 *计算方式:日平均工资 = 当月应发工资 /当月应出勤天数。
  1433. //半小时单位
  1434. //decimal halfHour = 7.50M / 0.50M;
  1435. switch (leaveType)
  1436. {
  1437. case 1: //年假
  1438. if (date_Range_type == "halfday")
  1439. {
  1440. if (duration >= 0.5M && duration <= 1M) //一天
  1441. {
  1442. var njItem = leaveDetails.Where(it => it.StartDt.ToString("yyyy-MM-dd") == startTime.ToString("yyyy-MM-dd") &&
  1443. it.EndDt.ToString("yyyy-MM-dd") == endTime.ToString("yyyy-MM-dd")).ToList();
  1444. if (njItem.Count > 1)
  1445. {
  1446. if (njItem[0].StartDt == startTime)
  1447. {
  1448. mealDeduction = 10; //餐补扣款
  1449. }
  1450. }
  1451. else
  1452. {
  1453. mealDeduction = 10; //餐补扣款
  1454. }
  1455. }
  1456. else // 多天
  1457. {
  1458. var njManyDaysItem = leaveDetails.Where(it => it.StartDt.ToString("yyyy-MM-dd") == startTime.ToString("yyyy-MM-dd")).ToList();
  1459. if (njManyDaysItem.Count > 1)
  1460. {
  1461. var njManyDaysItem1 = njManyDaysItem.Where(it => it.StartDt != startTime).ToList();
  1462. if (njManyDaysItem1.Count > 0)
  1463. {
  1464. if (njManyDaysItem1[0].Unit.Equals("天"))
  1465. {
  1466. mealDeduction = 10 * Math.Floor(duration);
  1467. }
  1468. else if (njManyDaysItem1[0].Unit.Equals("小时") && njManyDaysItem1[0].New_Duration >= 3)
  1469. {
  1470. mealDeduction = 10 * Math.Floor(duration);
  1471. }
  1472. else
  1473. {
  1474. mealDeduction = 10 * Math.Ceiling(duration);
  1475. }
  1476. }
  1477. }
  1478. else
  1479. {
  1480. mealDeduction = 10 * Math.Ceiling(duration);
  1481. }
  1482. }
  1483. }
  1484. break;
  1485. case 2: //2事假
  1486. // 事假日薪 *计算方式:日平均工资 = 当月应发工资 /当月应出勤天数。
  1487. decimal personalkLeave_dailywage_halfhour = personalkLeave_dailywage_day / 7.50M; //事假单位 0.5小时
  1488. if (date_Range_type == "halfday")
  1489. {
  1490. #region 处理当天是否扣除餐补
  1491. string formatDt_begin = startTime.ToString("yyyy-MM-dd");
  1492. List<LeaveDetails> leaveDetails1 = leaveDetails.Where(it => it.IsDeduction && it.EndDt.ToString("yyyy-MM-dd") == formatDt_begin).ToList();
  1493. if (leaveDetails1.Count > 0) mealDeduction = 10.00M * Math.Floor(duration); //餐补扣款
  1494. else mealDeduction = 10.00M * Math.Ceiling(duration); //餐补扣款
  1495. #endregion
  1496. if (duration % 1 == 0) //整天
  1497. {
  1498. typeDeduction = ConvertToDecimal(personalkLeave_dailywage_day * duration);
  1499. }
  1500. else //多含 半天 另外处理
  1501. {
  1502. decimal sj_wholeDay = Math.Floor(duration); //整天
  1503. decimal sj_halfDay = duration % 1; //半天
  1504. if (duration % 1 > 0)
  1505. {
  1506. typeDeduction = (personalkLeave_dailywage_day / 2.00M) * (duration / 0.50M);
  1507. }
  1508. else
  1509. {
  1510. typeDeduction = (personalkLeave_dailywage_day / 2.00M);
  1511. }
  1512. typeDeduction = ConvertToDecimal(typeDeduction);
  1513. }
  1514. }
  1515. else if (date_Range_type == "hour")
  1516. {
  1517. decimal leave_halfHour = Convert.ToDecimal(duration) / Convert.ToDecimal(0.5);
  1518. typeDeduction = ConvertToDecimal(personalkLeave_dailywage_halfhour * leave_halfHour);
  1519. //duration = 11M;
  1520. if (duration >= 3 && duration < 7.5M) //单天请假三小时
  1521. {
  1522. mealDeduction = 10; //餐补扣款
  1523. }
  1524. else if (duration >= 7.5M) //多天计算
  1525. {
  1526. decimal leave_halfHour1 = Convert.ToDecimal(duration) / Convert.ToDecimal(0.5);
  1527. decimal leaveDays = duration / 7.5M;
  1528. if (leaveDays % 1 == 0)
  1529. {
  1530. typeDeduction = ConvertToDecimal(personalkLeave_dailywage_day * leaveDays);
  1531. mealDeduction = 10 * leaveDays; //餐补扣款
  1532. }
  1533. else
  1534. {
  1535. typeDeduction = personalkLeave_dailywage_day * Convert.ToInt32(leaveDays);
  1536. decimal sy_shijiaunit = leave_halfHour1 - Convert.ToDecimal(15.00M * Convert.ToInt32(leaveDays));
  1537. if (sy_shijiaunit > 0)
  1538. {
  1539. typeDeduction += ConvertToDecimal(personalkLeave_dailywage_halfhour * sy_shijiaunit);
  1540. }
  1541. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  1542. //得到最后一天的请假时间 是否有餐补
  1543. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  1544. if (lastHours >= 3)
  1545. {
  1546. mealDeduction += 10; //餐补扣款
  1547. }
  1548. }
  1549. }
  1550. }
  1551. break;
  1552. case 3: //3病假
  1553. // 病假日薪 *计算方式:日平均工资 = 成都市最低工资标准的80% /当月应出勤天数。 短期病假=当月15天内
  1554. decimal chengDuMinimumWage_Day = _chengDuMinimumWage / work_days;
  1555. decimal chengDuMinimumWage_halrHour = chengDuMinimumWage_Day / 7.50M;
  1556. decimal sickLeave_dailywage_halfhour_deduction1 = (personalkLeave_dailywage_day / 7.50M) - chengDuMinimumWage_halrHour; //病假单位 0.5小时 扣款金额
  1557. if (date_Range_type == "halfday")
  1558. {
  1559. mealDeduction = 10.00M * Math.Ceiling(duration); //餐补扣款
  1560. decimal pl_dailywage_day = personalkLeave_dailywage_day - chengDuMinimumWage_Day;
  1561. if (duration % 1 == 0) //整天
  1562. {
  1563. typeDeduction = ConvertToDecimal(pl_dailywage_day * duration);
  1564. }
  1565. else //多含 半天 另外处理
  1566. {
  1567. #region 处理当天是否扣除餐补
  1568. string formatDt_begin = startTime.ToString("yyyy-MM-dd");
  1569. List<LeaveDetails> leaveDetails1 = leaveDetails.Where(it => it.IsDeduction && it.EndDt.ToString("yyyy-MM-dd") == formatDt_begin).ToList();
  1570. if (leaveDetails1.Count > 0) mealDeduction = 10.00M * Math.Floor(duration); //餐补扣款
  1571. else mealDeduction = 10.00M * Math.Ceiling(duration); //餐补扣款
  1572. #endregion
  1573. if (duration % 1 > 0)
  1574. {
  1575. typeDeduction = (pl_dailywage_day / 2.00M) * (duration / 0.50M); ;
  1576. }
  1577. else
  1578. {
  1579. typeDeduction = (pl_dailywage_day / 2.00M);
  1580. }
  1581. typeDeduction = ConvertToDecimal(typeDeduction);
  1582. }
  1583. }
  1584. else if (date_Range_type == "hour")
  1585. {
  1586. decimal sickLeave_halfHour = duration / 0.5M;
  1587. typeDeduction = ConvertToDecimal(sickLeave_dailywage_halfhour_deduction1 * sickLeave_halfHour);
  1588. if (duration >= 3 && duration < 7.5M) //单天请假三小时 && 请假时间在上午 则没有餐补
  1589. {
  1590. mealDeduction = 10; //餐补扣款
  1591. }
  1592. else if (duration >= 7.5M) //多天计算
  1593. {
  1594. decimal sickLeave_halfHour1 = duration / 0.5M;
  1595. decimal leaveDays = Convert.ToDecimal(duration / 7.5M);
  1596. typeDeduction = ConvertToDecimal(sickLeave_dailywage_halfhour_deduction1 * sickLeave_halfHour1);
  1597. if (leaveDays % 1 == 0)
  1598. {
  1599. mealDeduction = 10 * leaveDays; //餐补扣款
  1600. }
  1601. else
  1602. {
  1603. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  1604. typeDeduction = ConvertToDecimal(sickLeave_dailywage_halfhour_deduction1 * Convert.ToInt32(leaveDays));
  1605. decimal sy_bingjiaunit = sickLeave_halfHour1 - Convert.ToDecimal(15.00M * Convert.ToInt32(leaveDays));
  1606. if (sy_bingjiaunit > 0)
  1607. {
  1608. typeDeduction += ConvertToDecimal(sickLeave_dailywage_halfhour_deduction1 * sy_bingjiaunit);
  1609. }
  1610. //得到最后一天的请假时间 是否有餐补
  1611. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  1612. if (lastHours >= 3)
  1613. {
  1614. mealDeduction += 10; //餐补扣款
  1615. }
  1616. }
  1617. }
  1618. }
  1619. break;
  1620. case 4: //4调休假
  1621. CalculateTypeFeeSub(leaveDetails, date_Range_type, startTime, endTime, duration, out mealDeduction);
  1622. break;
  1623. case 5: //5婚假
  1624. CalculateTypeFeeSub(leaveDetails, date_Range_type, startTime, endTime, duration, out mealDeduction);
  1625. break;
  1626. case 6: //6产假
  1627. CalculateTypeFeeSub(leaveDetails, date_Range_type, startTime, endTime, duration, out mealDeduction);
  1628. break;
  1629. case 7: //7陪产假
  1630. CalculateTypeFeeSub(leaveDetails, date_Range_type, startTime, endTime, duration, out mealDeduction);
  1631. break;
  1632. case 8: //8其他
  1633. CalculateTypeFeeSub(leaveDetails, date_Range_type, startTime, endTime, duration, out mealDeduction);
  1634. break;
  1635. case 9: //9丧假
  1636. if (date_Range_type == "halfday")
  1637. {
  1638. if (duration >= 0.5M && duration <= 1M) //一天
  1639. {
  1640. var njItem = leaveDetails.Where(it => it.StartDt.ToString("yyyy-MM-dd") == startTime.ToString("yyyy-MM-dd") &&
  1641. it.EndDt.ToString("yyyy-MM-dd") == endTime.ToString("yyyy-MM-dd")).ToList();
  1642. if (njItem.Count > 1)
  1643. {
  1644. if (njItem[0].StartDt == startTime)
  1645. {
  1646. mealDeduction = 10; //餐补扣款
  1647. }
  1648. }
  1649. else
  1650. {
  1651. mealDeduction = 10; //餐补扣款
  1652. }
  1653. }
  1654. else // 多天
  1655. {
  1656. var njManyDaysItem = leaveDetails.Where(it => it.StartDt.ToString("yyyy-MM-dd") == startTime.ToString("yyyy-MM-dd")).ToList();
  1657. if (njManyDaysItem.Count > 1)
  1658. {
  1659. var njManyDaysItem1 = njManyDaysItem.Where(it => it.StartDt != startTime).ToList();
  1660. if (njManyDaysItem1.Count > 0)
  1661. {
  1662. if (njManyDaysItem1[0].Unit.Equals("天"))
  1663. {
  1664. mealDeduction = 10 * Math.Floor(duration);
  1665. }
  1666. else if (njManyDaysItem1[0].Unit.Equals("小时") && njManyDaysItem1[0].New_Duration >= 3)
  1667. {
  1668. mealDeduction = 10 * Math.Floor(duration);
  1669. }
  1670. else
  1671. {
  1672. mealDeduction = 10 * Math.Ceiling(duration);
  1673. }
  1674. }
  1675. }
  1676. else
  1677. {
  1678. mealDeduction = 10 * Math.Ceiling(duration);
  1679. }
  1680. }
  1681. }
  1682. break;
  1683. }
  1684. }
  1685. /// <summary>
  1686. /// 计算类型费用
  1687. /// 病假 事假 计算 按小时计算
  1688. /// </summary>
  1689. /// <param name="leaveDetails"></param>
  1690. /// <param name="leaveType">1年假;2事假;3病假;4调休假;5婚假;6产假;7陪产假;8其他;9丧假</param>
  1691. /// <param name="date_Range_type"> halfday 全天 hour 小时</param>
  1692. /// <param name="startTime"></param>
  1693. /// <param name="endTime"></param>
  1694. /// <param name="amountPayable"></param>
  1695. /// <param name="work_days"></param>
  1696. /// <param name="duration"></param>
  1697. /// <param name="mealDeduction"></param>
  1698. /// <param name="typeDeduction"></param>
  1699. public static void CalculateTypeFee2(List<LeaveDetails> leaveDetails, int leaveType, string date_Range_type, DateTime startTime, DateTime endTime,
  1700. decimal amountPayable, int work_days, decimal duration, out decimal mealDeduction, out decimal typeDeduction)
  1701. {
  1702. typeDeduction = 0;
  1703. mealDeduction = 0;
  1704. //string am_starttime = "08:59";
  1705. //string am_endtime = "13:01";
  1706. decimal personalkLeave_dailywage_day = amountPayable / work_days; //日薪 = 事假日薪 *计算方式:日平均工资 = 当月应发工资 /当月应出勤天数。
  1707. //半小时单位
  1708. //decimal halfHour = 7.50M / 0.50M;
  1709. switch (leaveType)
  1710. {
  1711. case 1: //年假
  1712. if (date_Range_type == "halfday")
  1713. {
  1714. if (duration >= 0.5M && duration <= 1M) //一天
  1715. {
  1716. var njItem = leaveDetails.Where(it => it.StartDt.ToString("yyyy-MM-dd") == startTime.ToString("yyyy-MM-dd") &&
  1717. it.EndDt.ToString("yyyy-MM-dd") == endTime.ToString("yyyy-MM-dd")).ToList();
  1718. if (njItem.Count > 1)
  1719. {
  1720. if (njItem[0].StartDt == startTime)
  1721. {
  1722. mealDeduction = 10; //餐补扣款
  1723. }
  1724. }
  1725. else
  1726. {
  1727. mealDeduction = 10; //餐补扣款
  1728. }
  1729. }
  1730. else // 多天
  1731. {
  1732. var njManyDaysItem = leaveDetails.Where(it => it.StartDt.ToString("yyyy-MM-dd") == startTime.ToString("yyyy-MM-dd")).ToList();
  1733. if (njManyDaysItem.Count > 1)
  1734. {
  1735. var njManyDaysItem1 = njManyDaysItem.Where(it => it.StartDt != startTime).ToList();
  1736. if (njManyDaysItem1.Count > 0)
  1737. {
  1738. if (njManyDaysItem1[0].Unit.Equals("天"))
  1739. {
  1740. mealDeduction = 10 * Math.Floor(duration);
  1741. }
  1742. else if (njManyDaysItem1[0].Unit.Equals("小时") && njManyDaysItem1[0].New_Duration >= 3)
  1743. {
  1744. mealDeduction = 10 * Math.Floor(duration);
  1745. }
  1746. else
  1747. {
  1748. mealDeduction = 10 * Math.Ceiling(duration);
  1749. }
  1750. }
  1751. }
  1752. else
  1753. {
  1754. mealDeduction = 10 * Math.Ceiling(duration);
  1755. }
  1756. }
  1757. }
  1758. break;
  1759. case 2: //2事假
  1760. // 事假日薪 *计算方式:日平均工资 = 当月应发工资 /当月应出勤天数。
  1761. decimal personalkLeave_dailywage_halfhour = personalkLeave_dailywage_day / 7.50M; //事假单位 0.5小时
  1762. if (date_Range_type == "halfday")
  1763. {
  1764. mealDeduction = 10.00M * Math.Floor(duration); //餐补扣款
  1765. if (duration % 1 == 0) //整天
  1766. {
  1767. typeDeduction = ConvertToDecimal(personalkLeave_dailywage_day * duration);
  1768. }
  1769. else //多含 半天 另外处理
  1770. {
  1771. decimal sj_wholeDay = Math.Floor(duration); //整天
  1772. decimal sj_halfDay = duration % 1; //半天
  1773. if (sj_halfDay > 0)
  1774. {
  1775. LeaveDetails sjDetails = leaveDetails.Where(it => it.StartDt == startTime && it.EndDt == endTime).FirstOrDefault();
  1776. //decimal sjPrice = 0.00M;
  1777. if (sjDetails != null)
  1778. {
  1779. Slice_info sj_slice_Info = sjDetails.SliceInfo;
  1780. if (sj_slice_Info != null)
  1781. {
  1782. decimal sjLongTime = (sj_slice_Info.duration / 3600.00M);
  1783. typeDeduction = (personalkLeave_dailywage_day / 7.50M) * sjLongTime;
  1784. }
  1785. }
  1786. LeaveDetails sjDetailsMeal = leaveDetails.Where(it => it.EndDt == startTime).FirstOrDefault();
  1787. if (sjDetailsMeal == null)
  1788. {
  1789. mealDeduction += 10.00M;
  1790. }
  1791. }
  1792. else
  1793. {
  1794. typeDeduction = personalkLeave_dailywage_day * sj_wholeDay;
  1795. }
  1796. typeDeduction = ConvertToDecimal(typeDeduction);
  1797. }
  1798. }
  1799. else if (date_Range_type == "hour")
  1800. {
  1801. decimal leave_halfHour = Convert.ToDecimal(duration) / Convert.ToDecimal(0.5);
  1802. typeDeduction = ConvertToDecimal(personalkLeave_dailywage_halfhour * leave_halfHour);
  1803. //duration = 11M;
  1804. if (duration >= 3 && duration < 7.5M) //单天请假三小时
  1805. {
  1806. mealDeduction = 10; //餐补扣款
  1807. }
  1808. else if (duration >= 7.5M) //多天计算
  1809. {
  1810. decimal leave_halfHour1 = Convert.ToDecimal(duration) / Convert.ToDecimal(0.5);
  1811. decimal leaveDays = duration / 7.5M;
  1812. if (leaveDays % 1 == 0)
  1813. {
  1814. typeDeduction = ConvertToDecimal(personalkLeave_dailywage_day * leaveDays);
  1815. mealDeduction = 10 * leaveDays; //餐补扣款
  1816. }
  1817. else
  1818. {
  1819. typeDeduction = personalkLeave_dailywage_day * Convert.ToInt32(leaveDays);
  1820. decimal sy_shijiaunit = leave_halfHour1 - Convert.ToDecimal(15.00M * Convert.ToInt32(leaveDays));
  1821. if (sy_shijiaunit > 0)
  1822. {
  1823. typeDeduction += ConvertToDecimal(personalkLeave_dailywage_halfhour * sy_shijiaunit);
  1824. }
  1825. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  1826. //得到最后一天的请假时间 是否有餐补
  1827. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  1828. if (lastHours >= 3)
  1829. {
  1830. mealDeduction += 10; //餐补扣款
  1831. }
  1832. }
  1833. }
  1834. }
  1835. break;
  1836. case 3: //3病假
  1837. // 病假日薪 *计算方式:日平均工资 = 成都市最低工资标准的80% /当月应出勤天数。 短期病假=当月15天内
  1838. decimal chengDuMinimumWage_Day = _chengDuMinimumWage / work_days;
  1839. decimal chengDuMinimumWage_halrHour = chengDuMinimumWage_Day / 7.50M;
  1840. decimal sickLeave_dailywage_halfhour_deduction1 = (personalkLeave_dailywage_day / 7.50M) - chengDuMinimumWage_halrHour; //病假单位 0.5小时 扣款金额
  1841. if (date_Range_type == "halfday")
  1842. {
  1843. mealDeduction = 10.00M * Math.Ceiling(duration); //餐补扣款
  1844. decimal pl_dailywage_day = personalkLeave_dailywage_day - chengDuMinimumWage_Day;
  1845. if (duration % 1 == 0) //整天
  1846. {
  1847. typeDeduction = ConvertToDecimal(pl_dailywage_day * duration);
  1848. }
  1849. else //多含 半天 另外处理
  1850. {
  1851. decimal bj_wholeDay = Math.Floor(duration); //整天
  1852. decimal bj_halfDay = duration % 1; //半天
  1853. decimal bj_wholeDayWage = pl_dailywage_day * bj_wholeDay;
  1854. decimal bj_halfDayWage = 0.00M;
  1855. if (bj_halfDay > 0)
  1856. {
  1857. LeaveDetails bjDetails = leaveDetails.Where(it => it.StartDt == startTime && it.EndDt == endTime).FirstOrDefault();
  1858. //decimal bjPrice = 0.00M;
  1859. if (bjDetails != null)
  1860. {
  1861. Slice_info bj_slice_Info = bjDetails.SliceInfo;
  1862. decimal bjLongTime = bj_slice_Info.duration / 3600.00M;
  1863. if (bjLongTime == 3.00M)
  1864. {
  1865. bj_halfDayWage = (pl_dailywage_day / 7.50M) * 3.00M;
  1866. }
  1867. else if (bjLongTime == 4.50M)
  1868. {
  1869. bj_halfDayWage = (pl_dailywage_day / 7.50M) * 4.50M;
  1870. }
  1871. }
  1872. }
  1873. typeDeduction = ConvertToDecimal(bj_wholeDayWage + bj_halfDayWage);
  1874. }
  1875. }
  1876. else if (date_Range_type == "hour")
  1877. {
  1878. decimal sickLeave_halfHour = duration / 0.5M;
  1879. typeDeduction = ConvertToDecimal(sickLeave_dailywage_halfhour_deduction1 * sickLeave_halfHour);
  1880. if (duration >= 3 && duration < 7.5M) //单天请假三小时 && 请假时间在上午 则没有餐补
  1881. {
  1882. mealDeduction = 10; //餐补扣款
  1883. }
  1884. else if (duration >= 7.5M) //多天计算
  1885. {
  1886. decimal sickLeave_halfHour1 = duration / 0.5M;
  1887. decimal leaveDays = Convert.ToDecimal(duration / 7.5M);
  1888. typeDeduction = ConvertToDecimal(sickLeave_dailywage_halfhour_deduction1 * sickLeave_halfHour1);
  1889. if (leaveDays % 1 == 0)
  1890. {
  1891. mealDeduction = 10 * leaveDays; //餐补扣款
  1892. }
  1893. else
  1894. {
  1895. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  1896. typeDeduction = ConvertToDecimal(sickLeave_dailywage_halfhour_deduction1 * Convert.ToInt32(leaveDays));
  1897. decimal sy_bingjiaunit = sickLeave_halfHour1 - Convert.ToDecimal(15.00M * Convert.ToInt32(leaveDays));
  1898. if (sy_bingjiaunit > 0)
  1899. {
  1900. typeDeduction += ConvertToDecimal(sickLeave_dailywage_halfhour_deduction1 * sy_bingjiaunit);
  1901. }
  1902. //得到最后一天的请假时间 是否有餐补
  1903. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  1904. if (lastHours >= 3)
  1905. {
  1906. mealDeduction += 10; //餐补扣款
  1907. }
  1908. }
  1909. }
  1910. }
  1911. break;
  1912. case 4: //4调休假
  1913. CalculateTypeFeeSub(leaveDetails, date_Range_type, startTime, endTime, duration, out mealDeduction);
  1914. break;
  1915. case 5: //5婚假
  1916. CalculateTypeFeeSub(leaveDetails, date_Range_type, startTime, endTime, duration, out mealDeduction);
  1917. break;
  1918. case 6: //6产假
  1919. CalculateTypeFeeSub(leaveDetails, date_Range_type, startTime, endTime, duration, out mealDeduction);
  1920. break;
  1921. case 7: //7陪产假
  1922. CalculateTypeFeeSub(leaveDetails, date_Range_type, startTime, endTime, duration, out mealDeduction);
  1923. break;
  1924. case 8: //8其他
  1925. CalculateTypeFeeSub(leaveDetails, date_Range_type, startTime, endTime, duration, out mealDeduction);
  1926. break;
  1927. case 9: //9丧假
  1928. CalculateTypeFeeSub(leaveDetails, date_Range_type, startTime, endTime, duration, out mealDeduction);
  1929. break;
  1930. }
  1931. }
  1932. /// <summary>
  1933. /// 计算类型费用
  1934. /// </summary>
  1935. /// <param name="leaveDetails"></param>
  1936. /// <param name="date_Range_type"></param>
  1937. /// <param name="startTime1"></param>
  1938. /// <param name="endTime1"></param>
  1939. /// <param name="duration"></param>
  1940. /// <param name="mealDeduction"></param>
  1941. public static void CalculateTypeFeeSub(List<LeaveDetails> leaveDetails, string date_Range_type, DateTime startTime1, DateTime endTime1,
  1942. decimal duration, out decimal mealDeduction)
  1943. {
  1944. mealDeduction = 0;
  1945. //string am_starttime = "09:00";
  1946. //string am_endtime = "11:59";
  1947. string startTime = startTime1.ToString("HH:mm:ss");
  1948. string endTime = endTime1.ToString("HH:mm:ss");
  1949. if (date_Range_type == "halfday")
  1950. {
  1951. mealDeduction = Math.Ceiling(duration) * 10; //餐补扣款
  1952. }
  1953. else if (date_Range_type == "hour")
  1954. {
  1955. List<LeaveDetails> leaveDetails1 = new List<LeaveDetails>();
  1956. leaveDetails1 = leaveDetails.Where(it => it.StartDt.ToString("yyyy-MM-dd").Equals(startTime1.ToString("yyyy-MM-dd")))
  1957. .OrderBy(it => it.StartDt).ToList();
  1958. if (leaveDetails1.Count > 1)
  1959. {
  1960. decimal timelenTatoal = leaveDetails1.Sum(it => it.New_Duration);
  1961. if (timelenTatoal >= 3.00M)
  1962. {
  1963. if (leaveDetails1[0].StartDt == startTime1)
  1964. {
  1965. mealDeduction = 10; //餐补扣款
  1966. }
  1967. }
  1968. }
  1969. else
  1970. {
  1971. if (duration >= 3 && duration < 7) //单天请假三小时 && 请假时间在上午 则没有餐补
  1972. {
  1973. mealDeduction = 10; //餐补扣款
  1974. }
  1975. else if (duration >= 7 && duration <= 7.50M)
  1976. {
  1977. mealDeduction = 10; //餐补扣款
  1978. }
  1979. else if (duration >= 7.50M) //多天计算
  1980. {
  1981. decimal leaveDays = Convert.ToDecimal(duration / 7.50M);
  1982. if (leaveDays % 1 == 0)
  1983. {
  1984. mealDeduction = 10 * leaveDays; //餐补扣款
  1985. }
  1986. else
  1987. {
  1988. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  1989. //得到最后一天的请假时间 是否有餐补
  1990. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  1991. if (lastHours >= 3)
  1992. {
  1993. mealDeduction += 10; //餐补扣款
  1994. ////处理结束时间
  1995. //if (endTime.CompareTo(am_starttime) > 0 && endTime.CompareTo(am_endtime) < 0)
  1996. //{
  1997. // mealDeduction += 10; //餐补扣款
  1998. //}
  1999. }
  2000. }
  2001. }
  2002. }
  2003. }
  2004. }
  2005. /// <summary>
  2006. /// 获取打卡补卡类型
  2007. /// </summary>
  2008. /// <param name="template_id"></param>
  2009. /// <returns></returns>
  2010. public static async Task<List<VacationLeaveTypeView>> GetVacationReissueCardTypes(string template_id)
  2011. {
  2012. List<VacationLeaveTypeView> vacationLeaveTypes = new List<VacationLeaveTypeView>();
  2013. TemplateDetailView templateDetailView = new TemplateDetailView();
  2014. templateDetailView = await _qiYeWeChatApiService.GetTemplateDetailAsync(template_id);
  2015. if (templateDetailView.errcode != 0)
  2016. {
  2017. return vacationLeaveTypes;
  2018. }
  2019. List<VacationItemInfo> VacationItemInfos = templateDetailView.vacation_list.item;
  2020. foreach (var item in VacationItemInfos)
  2021. {
  2022. ValueItem valueInfo = item.name.Where(it => it.lang == "zh_CN").FirstOrDefault();
  2023. if (valueInfo != null)
  2024. {
  2025. vacationLeaveTypes.Add(
  2026. new VacationLeaveTypeView()
  2027. {
  2028. id = item.id,
  2029. name = valueInfo.text
  2030. });
  2031. }
  2032. }
  2033. return vacationLeaveTypes;
  2034. }
  2035. /// <summary>
  2036. /// 打卡数据
  2037. /// 假勤数据 统计
  2038. /// </summary>
  2039. /// <param name="datas">数据源</param>
  2040. /// <param name="type">
  2041. /// 1-请假;2-补卡;3-出差;4-外出;100-外勤;
  2042. /// </param>
  2043. /// <param name="subTypeName">
  2044. /// 年假 事假 病假 调休假 婚嫁 产假 陪产假 丧假 补卡次数 出差 外出数 外勤 其他
  2045. /// </param>
  2046. /// <returns></returns>
  2047. private static int Fallibilitydispose(List<Sp_Item> datas, int type, string? subTypeName)
  2048. {
  2049. int num = 0;
  2050. Sp_Item _Info = datas.Where(it => it.type == type && it.name == subTypeName).FirstOrDefault();
  2051. if (_Info != null) { num = _Info.count; }
  2052. return num;
  2053. }
  2054. /// <summary>
  2055. /// 打卡数据
  2056. /// 异常数据 统计
  2057. /// </summary>
  2058. /// <returns></returns>
  2059. private static int ExceptionStatistics(List<Exception_Info> datas, int type)
  2060. {
  2061. int num = 0;
  2062. Exception_Info _Info = datas.Where(it => it.exception == type).FirstOrDefault();
  2063. if (_Info != null) { num = _Info.count; }
  2064. return num;
  2065. }
  2066. /// <summary>
  2067. /// 获取时间段内除周末 节假日外的 工作日
  2068. /// </summary>
  2069. /// <param name="yearMonth"></param>
  2070. /// <returns></returns>
  2071. public static async Task<int> GetWorkDays(string yearMonth)
  2072. {
  2073. int workdays = 0;
  2074. string sql = string.Format(@"Select * From Pm_WageIssueWorkingDay
  2075. Where Isdel = 0 And YearMonth = '{0}' ", yearMonth);
  2076. var data = await _usersRep._sqlSugar.SqlQueryable<WageYearMonthView>(sql).FirstAsync();
  2077. if (data != null)
  2078. {
  2079. workdays = data.Workdays;
  2080. }
  2081. return workdays;
  2082. }
  2083. /// <summary>
  2084. /// 获取一个类指定的属性值
  2085. /// </summary>
  2086. /// <param name="info">object对象</param>
  2087. /// <param name="field">属性名称</param>
  2088. /// <returns></returns>
  2089. public static object GetPropertyValue(object info, string field)
  2090. {
  2091. if (info == null) return null;
  2092. System.Type t = info.GetType();
  2093. IEnumerable<System.Reflection.PropertyInfo> property = from pi in t.GetProperties() where pi.Name.ToLower() == field.ToLower() select pi;
  2094. return property.First().GetValue(info, null);
  2095. }
  2096. }
  2097. }