Example #1
0
        public void AnalyzeOT(ref AtCalculationInfo _store, tatshift curShift, List <tatoridat> _lstOriAtData, bool _isSaveDetail)
        {
            DateTime effOTStart = DateTime.Parse(UtilDatetime.FormatDate1(_store.CurDay) + " " + curShift.eati); // analatBll.CompareTime(_store.CurDay, curShift.eati, curShift.tmin);
            //有效加班时间=第二日最早有效上班打卡时间之前
            DateTime         effOTEnd      = effOTStart.AddDays(1);                                              //analatBll.CompareTime(_store.CurDay, curShift.tmot, curShift.lato);
            DateTime         otStart       = analatBll.CompareTime(_store.CurDay, curShift.tmin, curShift.nots);
            double           othr          = 0;
            double           othrReal      = 0;
            double           totalOthr     = 0;
            double           totalOthrReal = 0;
            List <tatshfott> lstShiftOT    = new List <tatshfott>();

            if (lstOTType == null)
            {
                lstOTType = analatBll.GetOTType();
            }
            lstShiftOT = new BaseBll().GetSelectedRecords <tatshfott>(new List <ColumnInfo>()
            {
            }).OrderBy(p => p.otst).ToList();

            string otType = AnalyzeOTType(_store, lstOTType);

            string           sfid            = _store.EmpInfo.sfid;
            List <tatoridat> lstEmpOriAtData = _lstOriAtData.Where(p => p.sfid == sfid &&
                                                                   p.retm >= effOTStart &&
                                                                   p.retm < effOTEnd)
                                               .OrderBy(p => p.retm)
                                               .ToList();

            if (lstEmpOriAtData.Count < 1)
            {
                //没有加班打卡记录
                othr          = 0;
                othrReal      = 0;
                totalOthr     = 0;
                totalOthrReal = 0;
            }
            else
            {
                otdetailDal dal = new otdetailDal();

                //有上班前加班打卡记录
                //暂时不考虑上班打卡,2009-01-01 by Administrator
                //if (lstEmpOriAtData.First().retm < _store.StdTimeIn)
                //{
                //    TimeSpan diff = _store.StdTimeIn.Value - lstEmpOriAtData.First().retm;
                //    if (diff.TotalMinutes > curShift.miot)
                //    {
                //        othr = (diff.TotalMinutes % curShift.otun.Value) * curShift.otun.Value / 60;
                //        othrReal = diff.TotalMinutes / 60;
                //    }
                //    else
                //    {
                //        othr = 0;
                //        othrReal = 0;
                //    }

                //    if ((_isSaveDetail) && (othr!=0))
                //        dal.SaveOTDetail(_store.EmpInfo.emno, otType, _store.CurDay, lstEmpOriAtData.First().retm, _store.StdTimeIn.Value, othr, othrReal, 0.0);
                //}

                //有下班后加班打卡记录
                if (lstEmpOriAtData.Last().retm > otStart)
                {
                    if (lstShiftOT.Count > 0)
                    {
                        //定义了加班权重
                        DateTime        retm = lstEmpOriAtData.Last().retm;
                        DateTime        otst;
                        List <DateTime> lstDateTime    = new List <DateTime>();
                        List <string>   lstShiftOTType = new List <string>();
                        lstDateTime.Add(otStart);

                        for (int i = 0; i < lstShiftOT.Count; i++)
                        {
                            tatshfott shiftOT = lstShiftOT[i];
                            otst = analatBll.CompareTime(otStart, otStart.ToString("HH:mm:ss"), shiftOT.otst);
                            if (otst > retm)
                            {
                                lstDateTime.Add(retm);
                            }
                            else
                            {
                                if (i == (lstShiftOT.Count - 1))
                                {
                                    lstDateTime.Add(retm);
                                }
                                else
                                {
                                    lstDateTime.Add(otst);
                                }
                            }
                            lstShiftOTType.Add(shiftOT.otcd);
                        }

                        for (int i = 1; i < lstDateTime.Count; i++)
                        {
                            //如果下一个时段的比最小加班时间小,则累计到上一个区间
                            TimeSpan diff1 = new TimeSpan(0, 0, 0);
                            if ((i + 1) <= (lstDateTime.Count - 1))
                            {
                                diff1 = lstDateTime[i + 1] - lstDateTime[i];
                                if (diff1.TotalMinutes > curShift.miot)
                                {
                                    diff1 = new TimeSpan(0, 0, 0);
                                }
                            }

                            TimeSpan diff = lstDateTime[i] - lstDateTime[i - 1] + diff1;
                            if (diff.TotalMinutes > curShift.miot)
                            {
                                othr     = Math.Floor(diff.TotalMinutes / curShift.otun.Value) * curShift.otun.Value / 60;
                                othrReal = diff.TotalMinutes / 60;

                                totalOthr     += othr;
                                totalOthrReal += othrReal;

                                if ((_isSaveDetail) && (othr != 0))
                                {
                                    dal.SaveOTDetail(_store.EmpInfo.emno, lstShiftOTType[i - 1], _store.CurDay, lstDateTime[i - 1], lstDateTime[i], othr, othrReal, 0);
                                }
                            }
                        }
                    }
                    else
                    {
                        //没有定义加班权重
                        TimeSpan diff = lstEmpOriAtData.Last().retm - otStart;
                        if (diff.TotalMinutes > curShift.miot)
                        {
                            othr     = Math.Floor(diff.TotalMinutes / curShift.otun.Value) * curShift.otun.Value / 60;
                            othrReal = diff.TotalMinutes / 60;

                            totalOthr     += othr;
                            totalOthrReal += othrReal;

                            if ((_isSaveDetail) && (othr != 0))
                            {
                                dal.SaveOTDetail(_store.EmpInfo.emno, otType, _store.CurDay, otStart, lstEmpOriAtData.Last().retm, othr, othrReal, 0);
                            }
                        }
                    }
                }
            }

            otcd           = otType;
            _store.OTHours = totalOthr;
        }
Example #2
0
 public otdetailBll()
 {
     dal     = new otdetailDal();
     baseDal = dal;
 }