void departmentCostSummaryView_CommitDepartmentCostEvent(object sender, DepartmentCostEventArgs e)
        {
            // Save the end of period
            // select 5 day nearest
            //IList departmentTimelineList = new ArrayList();
            ObjectCriteria crit = new ObjectCriteria();
            crit.AddOrder("EmployeeMoneyPK.WorkingDay", false);
            crit.MaxResult = 5;
            IList prevList = EmployeeMoneyLogic.FindAll(crit);
            DateTime startTime = DateUtility.ZeroTime(DateTime.Now);
            if (prevList != null && prevList.Count > 0)
            {
                // update end time of nearest 5 timeline for sure transparency
                EmployeeMoney fixEmpMoney = (EmployeeMoney)prevList[0];
                DateTime lastSubmitEndTime = fixEmpMoney.EmployeeMoneyPK.WorkingDay;

                // get days which customer do not submit period
                TimeSpan timeSpan = DateUtility.ZeroTime(DateTime.Now).Subtract(DateUtility.ZeroTime(lastSubmitEndTime));
                // fix those days in order we can sync for today.

                //startTime = lastSubmitEndTime.AddSeconds(1);
                for (int i = 0; i < timeSpan.Days - 1; i++)
                {
                    DateTime nextDateTime = lastSubmitEndTime.AddDays(i + 1);
                    EmployeeMoney fixEmplMoney = new EmployeeMoney();
                    fixEmplMoney.WorkingDay = DateUtility.DateOnly(nextDateTime);
                    fixEmplMoney.CreateDate = DateUtility.MaxTime(nextDateTime);
                    fixEmplMoney.UpdateDate = DateUtility.MaxTime(nextDateTime);
                    fixEmplMoney.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                    fixEmplMoney.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    fixEmplMoney.DateLogin = DateUtility.MaxTime(nextDateTime);
                    fixEmplMoney.DateLogout = DateUtility.MaxTime(nextDateTime);
                    fixEmplMoney.InMoney = 0;
                    fixEmplMoney.OutMoney = 0;
                    EmployeeMoneyPK fixTimelinePK = new EmployeeMoneyPK
                    {
                        DepartmentId = CurrentDepartment.Get().DepartmentId,
                        EmployeeId = ClientInfo.getInstance().LoggedUser.Name,
                        WorkingDay = DateUtility.DateOnly(nextDateTime)
                    };

                    fixEmplMoney.EmployeeMoneyPK = fixTimelinePK;
                    EmployeeMoneyLogic.Add(fixEmplMoney);
                    //startTime = fixEmplMoney.EndTime.AddSeconds(1);
                }

            }
            #region unused code
            // If submit period ( ket so ) then we ' ket so '
            /*DepartmentTimeline timeline = null;
            if (isSubmitPeriod)
            {
                timeline = new DepartmentTimeline();
                timeline.WorkingDay = DateUtility.ZeroTime(DateTime.Now);
                timeline.CreateDate = DateTime.Now;
                timeline.UpdateDate = DateTime.Now;
                timeline.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                timeline.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                timeline.StartTime = startTime;
                timeline.EndTime = DateTime.Now;
                DepartmentTimelinePK timelinePK = new DepartmentTimelinePK
                {
                    DepartmentId = CurrentDepartment.Get().DepartmentId,
                    Period = DateTime.Now.DayOfYear
                };
                var dbTimeline = DepartmentTimelineDAO.FindById(timelinePK);
                if (dbTimeline != null)
                {
                    throw new BusinessException("Ngày hôm nay đã kết sổ");
                }
                timeline.DepartmentTimelinePK = timelinePK;
                DepartmentTimelineDAO.Add(timeline);

                //departmentTimelineList.Add(timeline);
            }*/

            #endregion
            DateTime toDay = DateUtility.DateOnly(DateTime.Now);

            EmployeeMoney employeeMoney = new EmployeeMoney();
            employeeMoney.EmployeeMoneyPK = new EmployeeMoneyPK
                                                {
                                                    DepartmentId = CurrentDepartment.Get().DepartmentId,
                                                    EmployeeId = ClientInfo.getInstance().LoggedUser.Name,
                                                    WorkingDay = toDay
                                                };
            employeeMoney.WorkingDay = toDay;
            employeeMoney.CreateDate = DateTime.Now;
            employeeMoney.UpdateDate = DateTime.Now;
            employeeMoney.CreateId = ClientInfo.getInstance().LoggedUser.Name;
            employeeMoney.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
            employeeMoney.DateLogin = DateTime.Now;
            employeeMoney.DateLogout = DateTime.Now;
            employeeMoney.InMoney = 0;

            DateTime nextDay = toDay.AddDays(1);
            EmployeeMoney nextMoney = new EmployeeMoney();
            nextMoney.EmployeeMoneyPK = new EmployeeMoneyPK
            {
                DepartmentId = CurrentDepartment.Get().DepartmentId,
                EmployeeId = ClientInfo.getInstance().LoggedUser.Name,
                WorkingDay = nextDay
            };
            nextMoney.WorkingDay = nextDay;
            nextMoney.CreateDate = nextDay;
            nextMoney.UpdateDate = nextDay;
            nextMoney.CreateId = ClientInfo.getInstance().LoggedUser.Name;
            nextMoney.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
            nextMoney.DateLogin = DateTime.Now;
            nextMoney.DateLogout = DateTime.Now;
            employeeMoney.InMoney = e.OutMoney;

            EmployeeMoney nextMoneyInDB = EmployeeMoneyLogic.FindById(employeeMoney.EmployeeMoneyPK);
            if (nextMoneyInDB != null)
            {
                throw new BusinessException("Ngày hôm nay đã kết sổ !");
            }

            ObjectCriteria objectCriteria = new ObjectCriteria();
            objectCriteria.AddEqCriteria("EmployeeMoneyPK.WorkingDay", toDay);
            objectCriteria.AddEqCriteria("EmployeeMoneyPK.DepartmentId", CurrentDepartment.Get().DepartmentId);
            IList list = EmployeeMoneyLogic.FindAll(objectCriteria);
            if(list!=null && list.Count == 1)
            {
                employeeMoney = (EmployeeMoney)list[0];
                // count out money
                employeeMoney.OutMoney = e.OutMoney;
                employeeMoney.UpdateDate = DateTime.Now;
                employeeMoney.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                EmployeeMoneyLogic.Update(employeeMoney);
            }
            else
            {
                employeeMoney.OutMoney = e.OutMoney;
                EmployeeMoneyLogic.Add(employeeMoney);
            }

            EmployeeMoneyLogic.Add(nextMoney);
            e.EventResult = "Success";
        }
Example #2
0
        public void EnterPeriod()
        {
            try
            {
                ((MainForm)GlobalCache.Instance().MainForm).showProgressBar();
                GlobalCache.Instance().IsCostSummary = true;
                ObjectCriteria crit = new ObjectCriteria();
                crit.AddEqCriteria("EmployeeMoneyPK.WorkingDay", DateUtility.ZeroTime(DateTime.Now));
                crit.AddEqCriteria("EmployeeMoneyPK.DepartmentId", CurrentDepartment.Get().DepartmentId);
                IList list = EmployeeMoneyLogic.FindAll(crit);

                if (list != null && list.Count == 1)
                {

                }
                else
                {
                    DateTime toDay = DateUtility.ZeroTime(DateTime.Now);
                    DateTime startToday = toDay.AddHours(3);

                    // get total of yesterday
                    MasterDB masterDB = new MasterDB();
                    DepartmentSumCostReportTableAdapter adapter = new DepartmentSumCostReportTableAdapter();
                    adapter.ClearBeforeFill = true;
                    adapter.Fill(masterDB.DepartmentSumCostReport,
                                 (int)CurrentDepartment.Get().DepartmentId,
                                 startToday.Subtract(new TimeSpan(1, 0, 0, 0)),
                                 startToday
                        );

                    int rowCount = masterDB.DepartmentSumCostReport.Rows.Count;
                    long prevAmount = 0;
                    if (rowCount > 0)
                    {
                        prevAmount = Int64.Parse(masterDB.DepartmentSumCostReport.Rows[0][3].ToString());
                    }

                    EmployeeMoney fixEmplMoney = new EmployeeMoney();
                    fixEmplMoney.WorkingDay = toDay;
                    fixEmplMoney.CreateDate = startToday;
                    fixEmplMoney.UpdateDate = startToday;
                    fixEmplMoney.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                    fixEmplMoney.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    fixEmplMoney.DateLogin = startToday;
                    fixEmplMoney.DateLogout = startToday;
                    fixEmplMoney.InMoney = prevAmount;
                    //fixEmplMoney.OutMoney = 0;
                    EmployeeMoneyPK fixTimelinePK = new EmployeeMoneyPK
                    {
                        DepartmentId = CurrentDepartment.Get().DepartmentId,
                        EmployeeId = ClientInfo.getInstance().LoggedUser.Name,
                        WorkingDay = toDay
                    };

                    fixEmplMoney.EmployeeMoneyPK = fixTimelinePK;
                    EmployeeMoneyLogic.Add(fixEmplMoney);

                    // update last day
                    ObjectCriteria lastDayCrit = new ObjectCriteria();
                    lastDayCrit.AddEqCriteria("EmployeeMoneyPK.WorkingDay", DateUtility.ZeroTime(toDay.Subtract(new TimeSpan(1, 0, 0, 0))));
                    lastDayCrit.AddEqCriteria("EmployeeMoneyPK.DepartmentId", CurrentDepartment.Get().DepartmentId);
                    IList lastList = EmployeeMoneyLogic.FindAll(lastDayCrit);
                    if (lastList != null && lastList.Count > 0)
                    {
                        EmployeeMoney lastDayMoney = (EmployeeMoney)lastList[0];
                        lastDayMoney.OutMoney = prevAmount;
                        lastDayMoney.UpdateDate = startToday;
                        lastDayMoney.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        lastDayMoney.DateLogout = startToday;
                        EmployeeMoneyLogic.Update(lastDayMoney);
                    }

                }
                GlobalCache.Instance().IsCostSummary = true;
            }
            catch (Exception exception)
            {
                GlobalCache.Instance().IsCostSummary = false;
            }
            finally
            {
                ((MainForm)GlobalCache.Instance().MainForm).stopProgressBar();
                GlobalCache.Instance().IsCostSummary = false;
            }
        }
 /// <summary>
 /// Delete EmployeeMoney from database.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public void Delete(EmployeeMoney data)
 {
     HibernateTemplate.Delete(data);
 }
Example #4
0
 void mainView_ProcessEmployeeMoneyEvent(object sender, EmployeeManagementEventArgs e)
 {
     try
     {
         if (e.InMoney > 0)
         {
             EmployeeMoney employeeMoney = new EmployeeMoney();
             employeeMoney.EmployeeMoneyPK = new EmployeeMoneyPK
             {
                 DepartmentId = e.DepartmentManagement.DepartmentManagementPK.DepartmentId,
                 EmployeeId = e.DepartmentManagement.DepartmentManagementPK.EmployeeId,
                 WorkingDay = DateUtility.DateOnly(e.DepartmentManagement.DepartmentManagementPK.WorkingDay)
             };
             employeeMoney.DateLogin = e.DepartmentManagement.StartTime;
             employeeMoney.InMoney = e.InMoney;
             employeeMoney.CreateDate = e.DepartmentManagement.CreateDate;
             employeeMoney.CreateId = e.DepartmentManagement.CreateId;
             employeeMoney.UpdateDate = e.DepartmentManagement.UpdateDate;
             employeeMoney.UpdateId = e.DepartmentManagement.UpdateId;
             EmployeeMoneyLogic.Add(employeeMoney);
         }
     }
     catch (Exception exception)
     {
         e.HasErrors = true;
     }
 }
 /// <summary>
 /// Add EmployeeMoney to database.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public EmployeeMoney Add(EmployeeMoney data)
 {
     HibernateTemplate.Save(data);
     return data;
 }
 /// <summary>
 /// Update EmployeeMoney to database.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public void Update(EmployeeMoney data)
 {
     HibernateTemplate.Update(data);
 }
 public void Delete(EmployeeMoney data)
 {
     EmployeeMoneyDAO.Delete(data);
 }
 public EmployeeMoney Add(EmployeeMoney data)
 {
     EmployeeMoneyDAO.Add(data);
     return data;
 }
 public void Update(EmployeeMoney data)
 {
     EmployeeMoneyDAO.Update(data);
 }