protected virtual void StartDateFieldUpdating(PXCache sender, PXFieldUpdatingEventArgs e)
        {
            PMTimeActivityFilter rowFilter = Filter.Current;
            EPActivityApprove    row       = (EPActivityApprove)e.Row;

            if (rowFilter == null || e.NewValue == null)
            {
                return;
            }

            DateTime?newValue = null;
            DateTime valFromString;

            if (e.NewValue is string &&
                DateTime.TryParse((string)e.NewValue, sender.Graph.Culture, System.Globalization.DateTimeStyles.None, out valFromString))
            {
                newValue = valFromString;
            }
            if (e.NewValue is DateTime)
            {
                newValue = (DateTime)e.NewValue;
            }

            if (newValue != null)
            {
                int weekId = PXWeekSelector2Attribute.GetWeekID(this, newValue.Value.Date);

                if (weekId < rowFilter.FromWeek || weekId > rowFilter.TillWeek)
                {
                    sender.RaiseExceptionHandling <EPActivityApprove.date>(row, e.NewValue,
                                                                           new PXSetPropertyException(Messages.StartDateOutOfRange));
                    e.Cancel = true;
                }
            }
        }
 protected virtual void PMTimeActivityFilter_TillWeek_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
 {
     try
     {
         e.NewValue = PXWeekSelector2Attribute.GetWeekID(this, Accessinfo.BusinessDate.GetValueOrDefault(DateTime.Now));
     }
     catch (PXException exception)
     {
         sender.RaiseExceptionHandling <PMTimeActivityFilter.fromWeek>(e.Row, null, exception);
     }
 }
Esempio n. 3
0
        protected virtual DateTime?GetWeekStartDate(PXCache sender, object row)
        {
            DateTime?result = null;

            if (weekID != null)
            {
                int?week = (int?)sender.GetValue(row, weekID.Name);
                if (week != null)
                {
                    result = PXWeekSelector2Attribute.GetWeekStartDate(sender.Graph, week.Value);
                }
            }

            return(result);
        }
Esempio n. 4
0
        public virtual IEnumerable tGTasks()
        {
            List <TGTimecardTask> tasks = new List <TGTimecardTask>();

            EPEmployee employee = Base.Employee.Current;

            if (employee != null)
            {
                DateTime startDate = PXWeekSelector2Attribute.GetWeekStartDate(Base.Document.Current.WeekID.Value);
                DateTime endDate   = PXWeekSelector2Attribute.GetWeekEndDate(this.Base, Base.Document.Current.WeekID.Value);

                TGEPEmployeeExtension employeeExt = PXCache <EPEmployee> .GetExtension <TGEPEmployeeExtension>(employee);

                using (TogglClient client = new TogglClient(employeeExt.UsrTGToken))
                {
                    foreach (TogglMap result in client.TGTimecardTaskList(startDate, endDate))
                    {
                        tasks.Add(TogglMapper.MapFromToggl(this.Base, result));
                    }
                }
            }

            return(tasks);
        }
Esempio n. 5
0
        public static DateTime?GetNextActivityStartDate <Activity>(PXGraph graph, PXResultset <Activity> res, PMTimeActivity row, int?fromWeekId, int?tillWeekId, PXCache tempDataCache, Type tempDataField)
            where Activity : PMTimeActivity, new()
        {
            DateTime?date;

            if (fromWeekId != null || tillWeekId != null)
            {
                date = PXWeekSelector2Attribute.GetWeekStartDate(graph, (int)(fromWeekId ?? tillWeekId));
            }
            else
            {
                date = graph.Accessinfo.BusinessDate.GetValueOrDefault(DateTime.Now).Date;
            }

            EPEmployee employee = PXSelect <EPEmployee, Where <EPEmployee.userID, Equal <Required <EPEmployee.userID> > > > .Select(graph, row.OwnerID);

            EPEmployeeClass employeeClass = PXSelect <EPEmployeeClass, Where <EPEmployeeClass.vendorClassID, Equal <Required <EPEmployee.vendorClassID> > > > .Select(graph, employee != null?employee.VendorClassID : null);

            var calendarId = CRActivityMaint.GetCalendarID(graph, row);

            if (employeeClass != null && EPEmployeeClass.defaultDateInActivity.LastDay == employeeClass.DefaultDateInActivity)
            {
                DateTime?val = tempDataCache.GetValue(tempDataCache.Current, tempDataField.Name) as DateTime?;
                if (val != null)
                {
                    int week = PXWeekSelector2Attribute.GetWeekID(graph, (DateTime)val);
                    if ((fromWeekId == null || week >= fromWeekId) && (tillWeekId == null || tillWeekId >= week))
                    {
                        date = val;
                    }
                }
            }
            else
            {
                DateTime weekDate = (DateTime)date;
                DateTime?newDate  = null;
                date = res != null && res.Count > 0 ? res.Max(_ => ((Activity)_).Date) : null ?? date;
                for (int curentWeek = PXWeekSelector2Attribute.GetWeekID(graph, weekDate); tillWeekId == null || curentWeek <= tillWeekId; curentWeek = PXWeekSelector2Attribute.GetWeekID(graph, weekDate))
                {
                    PXWeekSelector2Attribute.WeekInfo week1 = PXWeekSelector2Attribute.GetWeekInfo(graph,
                                                                                                   PXWeekSelector2Attribute.GetWeekID(graph, weekDate));
                    foreach (KeyValuePair <DayOfWeek, PXWeekSelector2Attribute.DayInfo> pair in week1.Days.OrderBy(_ => _.Value.Date))
                    {
                        if (pair.Value.Date >= date &&
                            (CalendarHelper.IsWorkDay(graph, calendarId, (DateTime)pair.Value.Date) ||
                             string.IsNullOrEmpty(calendarId) && pair.Key != DayOfWeek.Saturday && pair.Key != DayOfWeek.Sunday))
                        {
                            newDate = (DateTime)pair.Value.Date;
                            break;
                        }
                        weekDate = weekDate.AddDays(1D);
                    }
                    if (newDate != null)
                    {
                        date = ((DateTime)newDate).Date;
                        break;
                    }
                }
            }

            if (!string.IsNullOrEmpty(calendarId) && date != null)
            {
                DateTime startDate;
                DateTime endDate;
                CalendarHelper.CalculateStartEndTime(graph, calendarId, (DateTime)date, out startDate, out endDate);
                date = startDate;
            }

            return(date);
        }
Esempio n. 6
0
 protected virtual void TimecardFilter_ToWeekID_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
 {
     e.NewValue = PXWeekSelector2Attribute.GetNextWeekID(this, Accessinfo.BusinessDate.Value);
 }