예제 #1
0
        protected override void StartJob(JobInfo info, JobSegment segment)
        {
            var options = new DefaultJobOptions("ExperienceGenerator-" + info.Id + "/" + segment.Id, "ExperienceGenerator", Context.Site.Name, this, "Run",
                                                new object[] { segment });

            JobManager.Start(options);
        }
예제 #2
0
        private void GetJobSegments()
        {
            // to do - these will be added when someone starts/stops
            // so, no need to go to JobSegment
            //curSegments = JobSegment.SegmentsForJob(curJob);
            if (curJob.JobSegments != null)
            {
                curSegments = curJob.JobSegments.ToList();
            }

            if (curSegments != null)
            {
                curSegments = curSegments.OrderByDescending(s => s.StartDate).ToList();

                curSegment = curSegments.Where(s => s.Employee.Equals(curEmployee)
                                               &&
                                               s.EndDate == DateTime.MinValue)
                             .FirstOrDefault();
            }
            isWorkingNow = curSegment != null;
        }
예제 #3
0
        private void InsertSegment()
        {
            DateTime nowUtc = DateTime.UtcNow;
            string   notes  = this.txtSegmentNotesForStart.Text.Trim();

            // insert job segment
            JobSegment segment = JobSegment.InsertJobSegment(curJob, curEmployee, nowUtc, notes);

            if (segment == null)
            {
                throw new Exception(SiteUtils.ExceptionMessageForCustomer("Failed to add job segment to database."));
            }

            // insert job status change
            JobStatusChange change = JobStatusChange.InsertJobStatusChange(curJob, JobStatus.InProgress, nowUtc);

            if (change == null)
            {
                throw new Exception(SiteUtils.ExceptionMessageForCustomer("Failed to add job status change."));
            }
        }
예제 #4
0
 // extension method for job segment
 public static DateTime DateTimeForClient(this JobSegment segment, Client client, DateTime utcDate)
 {
     return(DateForClient(client, utcDate));
 }
예제 #5
0
 public void Run(JobSegment job)
 {
     Process(job);
 }
예제 #6
0
        private void UpdateSegment()
        {
            if (curSegment == null)
            {
                throw new Exception(SiteUtils.ExceptionMessageForCustomer("Current segment is null."));
            }

            DateTime startTime = DateTime.Parse(this.txtTimeStarted.Text);

            startTime = AdminUtils.UtcOfEmployeeDate(startTime, curEmployee);

            DateTime stopTime = DateTime.Parse(this.txtTimeStopped.Text);

            stopTime = AdminUtils.UtcOfEmployeeDate(stopTime, curEmployee);

            int minutesWorked = Convert.ToInt32(Convert.ToDecimal(this.txtHoursWorked.Text) * 60m);
            //(int) Math.Round(nowUtc.Subtract(curSegment.StartDate).TotalMinutes);

            // make new segment, so we can test for null -- necessary ??
            JobSegment newSegment = curSegment.UpdateJobSegment(startTime, stopTime, minutesWorked, this.txtSegmentNotesForStop.Text.Trim());

            if (newSegment == null)
            {
                throw new Exception(SiteUtils.ExceptionMessageForCustomer("Failed to update job segment."));
            }

            // assign successful result
            curSegment = newSegment;

            // update job status
            JobStatus newStatus = JobStatus.JobStatusFromId(Convert.ToInt32(this.ddStatuses.SelectedValue));

            bool statusChanged = !newStatus.Equals(curJob.JobStatus);

            if (statusChanged)
            {
                JobStatusChange change = JobStatusChange.InsertJobStatusChange(curJob, newStatus, DateTime.UtcNow);
                if (change == null)
                {
                    throw new Exception(SiteUtils.ExceptionMessageForCustomer("Failed to add job status change."));
                }

                if (newStatus.IsAClosedStatus())
                {
                    // update the job to insert completion date
                    Job newJob = curJob.ShallowCopy();

                    DateTime dateCompleted = Convert.ToDateTime(this.txtTimeStopped.Text);
                    dateCompleted = AdminUtils.UtcOfEmployeeDate(dateCompleted, curEmployee);

                    newJob.DateCompleted = dateCompleted;

                    bool ret = ClientData.Current.UpdateJob(newJob.BillingReference, newJob.JobType.JobTypeId, newJob.ToApplication, newJob.Formatted, newJob.Proofread, newJob.DateDue, newJob.DateCompleted, newJob.Instructions, newJob.Estimate, newJob.FinalCharge, newJob.Taxes, newJob.DeliveryNotes, newJob.IsArchived, newJob.JobId);

                    if (!ret)
                    {
                        throw new Exception(SiteUtils.ExceptionMessageForCustomer("Failed to update job in database."));
                    }

                    // update cached job
                    List <Job> jobsInCache = CacheLayer.RecentJobs();
                    int        index       = jobsInCache.IndexOf(curJob);
                    if (index != -1)
                    {
                        jobsInCache.Remove(curJob);
                        jobsInCache.Insert(index, newJob);
                    }

                    // replace global ref
                    curJob = newJob;
                }
            }
        }
예제 #7
0
        private string SegmentsTable()
        {
            StringBuilder sbSegments = new StringBuilder();

            sbSegments.Append("<table class=\"clientSegmentsTable\">");
            sbSegments.Append("<tr>");
            sbSegments.Append("<th>Staff</th>");
            sbSegments.Append("<th>Date</th>");
            sbSegments.Append("<th class=\"right\">Hours</th>");
            sbSegments.Append("</tr>");

            // copy segments to new list of segments in ***Client's time***
            List <JobSegment> clientSegments = new List <JobSegment>();

            foreach (JobSegment segment in curJob.JobSegments)
            {
                JobSegment clientSegment = segment.ShallowCopy();
                clientSegment.StartDate = ClientUtils.DateForClient(curClient, segment.StartDate);
                clientSegment.EndDate   = ClientUtils.DateForClient(curClient, segment.EndDate);
                clientSegments.Add(clientSegment);
                //Debug.WriteLine("for me (real segment): " + TimeZoneInfo.ConvertTimeFromUtc(segment.StartDate, TimeZoneInfo.Local).ToString());
                //Debug.WriteLine("for client (copy): " + clientSegment.StartDate.ToString());
            }

            // group segments by date
            var segmentGroups = clientSegments
                                .GroupBy(cs => new { cs.Employee, cs.StartDate.Date })                                                               // grouping on ee and startdate
                                .Select(gs => new { Employee = gs.Key.Employee, Date = gs.Key.Date, TotalMinutes = gs.Sum(cs => cs.MinutesWorked) }) // getting sum of minutes
                                .ToList();

            decimal totalHoursForCompare = 0m;

            foreach (var segmentGroup in segmentGroups)
            {
                sbSegments.Append("<tr>");

                string eeName = segmentGroup.Employee.FirstName.Substring(0, 1) + ". "
                                + segmentGroup.Employee.LastName;
                sbSegments.Append("<td>" + eeName + "</td>");

                // already did this:
                //DateTime startDate = ClientUtils.DateForClient(curClient, segmentGroup.Date);

                // to do - not this way. aggregate hours by day
                string strDate = segmentGroup.Date.ToString("M/d/yyyy");
                sbSegments.Append("<td>" + strDate + "</td>");

                int     minutes = segmentGroup.TotalMinutes;
                decimal hours   = decimal.Round((decimal)minutes / 60m, 1);

                // keep running total of displayed
                totalHoursForCompare += hours;

                sbSegments.Append("<td class=\"right\">" + hours.ToString("#,##0.0") + "</td>");
                sbSegments.Append("</tr>");
            }

            sbSegments.Append("</table>");

            int     totalMinutes         = curJob.JobSegments.Sum(s => s.MinutesWorked);
            decimal totalHoursForSegment = decimal.Round((decimal)totalMinutes / 60m, 1);

            sbSegments.Append("<div class=\"marginTop20px\">Total hours: " + totalHoursForSegment.ToString("#,##0.0") + "</div>");

            // note if they don't add up
            if (totalHoursForCompare != totalHoursForSegment)
            {
                sbSegments.Append("<div><span class=\"asterisk\">*</span> Total hours may not exactly equal the sum of the hours shown in the history table, due to rounding. Our time records are kept in minutes, and converted to hours in this display for your convenience.</div>");
            }

            return(sbSegments.ToString());
        }