Esempio n. 1
0
        private void GenerateReport(TimeCardDataSet1.EmployeesRow employee)
        {
            //get the week range data to add to the employee object
            WeekRangeData weeksForPeriod = new WeekRangeData();

            //get the shift start time based off their employee number
            DateTime shiftStart = ShiftNoToStart[employee.Shift];

            // used to calculate overtime
            var isCalifornia = employee.address.Contains(", CA");

            // create object for employee detail
            var emps = new List<EmployeeDetails>();
            var emp = new EmployeeDetails
            {
                EmployeeID = employee.EmployeeID,
                EmpName = employee.EmpName,
                StartDate = startPick.Value.ToShortDateString(),
                EndDate = endPick.Value.ToShortDateString(),
                PeriodEnd = endPick.Value.ToShortDateString(),
                PeriodStart = startPick.Value.ToShortDateString()
            };
            emps.Add(emp);

            // get the transactions for the report
            var adpt = new TimeCardDataSet1TableAdapters.FlexibleTransactionComTableAdapter();
            adpt.FillByEnrollNo(this.timeCardDataSet1.FlexibleTransactionCom, employee.EmployeeID);

            var transAdpt = new TimeCardDataSet1TableAdapters.TransactionsTableAdapter();
            transAdpt.FillByEnrollNoAndDate(this.timeCardDataSet1.Transactions, employee.EmployeeID, startPick.Value, endPick.Value);

            // build the object
            var report = new List<Joshua>();
            int clockins = 0;

            foreach (var trans in this.timeCardDataSet1.Transactions)
            {
                bool logout = false;
                Joshua toAdd = new Joshua
                {
                    Date = trans.LogDate,
                    //InTime = trans.IsLogInNull() ? "" : trans.LogIn.ToString("hh:mm tt"),
                    //OutTime = trans.IsLogOutNull() ? "" : trans.LogOut.ToString("hh:mm tt"),
                    ActualTime = "",
                    OT = 0,
                    D = 0,
                    PayTime = "",
                    // ScheduledTime = trans.IsLogInNull() ? "" : shiftStart.ToString("hh:mm tt"),
                    Comments = "",
                    isUtah = !isCalifornia,
                    EmployeeID = emp.EmployeeID,
                    EmpName = emp.EmpName
                };

                if (trans.TempInOutMode == "CI")
                {
                    toAdd.InTime = trans.LogTime.ToString("hh:mm tt");
                    toAdd.LowStart = trans.LogTime;
                    clockins++;
                    toAdd.Line = clockins;
                }
                else
                {
                    try
                    {
                        toAdd = (from t in report where t.Date == trans.LogDate && t.Line == clockins select t).First();
                        logout = true;
                    }
                    catch(Exception exp)  {
                        toAdd.LowStart = trans.LogTime;
                        toAdd.InTime = "Missing";
                    }

                    toAdd.OutTime = trans.LogTime.ToString("hh:mm tt");
                }

                try
                {
                    // get the comment
                    if (!trans.IsfldRemarksNull()) { toAdd.Comments += trans.fldRemarks; }
                }
                catch { }

                //these variable will hold a date times for employees paid start and end times
                DateTime LOWStart = new DateTime();
                DateTime LOWEnd = new DateTime();

                //make adjustments to the Joshua's log in time to calculate the pay time
                if (trans.TempInOutMode == "CI")
                {
                    var compareTime = new DateTime(1, 1, 1, trans.LogTime.Hour, trans.LogTime.Minute, 0);
                    //if the employee arrived before their scheduled start time
                    if (shiftStart > compareTime)
                    {
                        toAdd.PayTime += shiftStart.ToString("hh:mm tt");
                        LOWStart = shiftStart;
                    }
                    else // then they are payed from the closest 15 minute interval after they arrived
                    {
                        var roundedStart = roundToNearest15(trans.LogTime);
                        var payStart = roundedStart.ToString("hh:mm tt");
                        toAdd.PayTime += payStart;
                        LOWStart = roundedStart;
                    }
                }
                //make adjustments to the Joshua's log out time to calculate the pay time
                else if (trans.TempInOutMode == "CO")
                {
                    LOWStart = toAdd.LowStart;
                    var roundedEnd = roundToNearest15(trans.LogTime);
                    toAdd.PayTime += "\n" + roundedEnd.ToString("hh:mm tt");
                    LOWEnd = roundedEnd;
                }

                //day shift employees
                if (employee.Shift == 0)
                {
                    toAdd.ScheduledTime = ShiftNoToStart[0].ToString("hh:mm tt");
                    toAdd.ScheduledTime += "\n" + ShiftNoToEnd[0].ToString("hh:mm tt");
                }
                else
                {
                    toAdd.ScheduledTime = toAdd.PayTime;
                }
                TimeSpan LOWSpan = (LOWEnd - LOWStart);
                double LOWPaid = Math.Round(LOWSpan.Hours + (double)LOWSpan.Minutes / 60, 2);
                toAdd.LOW = LOWPaid;
                if (!logout)
                {
                    report.Add(toAdd);
                }
            }

            /*foreach (var trans in this.timeCardDataSet1.FlexibleTransactionCom)
            {
                if (!trans.IsLOWNull())
                {
                    Joshua toAdd = new Joshua
                    {
                        Date = trans.LogDate,
                        InTime = trans.IsLogInNull() ? "" : trans.LogIn.ToString("hh:mm tt"),
                        OutTime = trans.IsLogOutNull() ? "" : trans.LogOut.ToString("hh:mm tt"),
                        ActualTime = "",
                        OT = 0,
                        D = 0,
                        PayTime = "",
                        // ScheduledTime = trans.IsLogInNull() ? "" : shiftStart.ToString("hh:mm tt"),
                        Comments = "",
                        isUtah = !isCalifornia,
                        EmployeeID = emp.EmployeeID,
                        EmpName = emp.EmpName
                    };

                    try
                    {
                        // get the comment
                        var comment = (from t in this.timeCardDataSet1.Transactions where t.LogDate == trans.LogDate && !t.IsfldRemarksNull() select t);
                        if (comment.Count() > 0)
                        {
                            toAdd.Comments = comment.First().fldRemarks;
                        }
                    }
                    catch { }

                    //these variable will hold a date times for employees paid start and end times
                    DateTime LOWStart = new DateTime();
                    DateTime LOWEnd = new DateTime();

                    //make adjustments to the Joshua's log in time to calculate the pay time
                    if (!trans.IsLogInNull())
                    {
                        var compareTime = new DateTime(1, 1, 1, trans.LogIn.Hour, trans.LogIn.Minute, 0);
                        //if the employee arrived before their scheduled start time
                        if (shiftStart > compareTime)
                        {
                            toAdd.PayTime += shiftStart.ToString("hh:mm tt");
                            LOWStart = shiftStart;
                        }
                        else // then they are payed from the closest 15 minute interval after they arrived
                        {
                            var roundedStart = roundToNearest15(trans.LogIn);
                            var payStart = roundedStart.ToString("hh:mm tt");
                            toAdd.PayTime += payStart;
                            LOWStart = roundedStart;
                        }
                    }

                    //make adjustments to the Joshua's log out time to calculate the pay time
                    if (!trans.IsLogOutNull())
                    {
                        var roundedEnd = roundToNearest15(trans.LogOut);
                        toAdd.PayTime += "\n" + roundedEnd.ToString("hh:mm tt");
                        LOWEnd = roundedEnd;
                    }

                    //day shift employees
                    if (employee.Shift == 0)
                    {
                        toAdd.ScheduledTime = ShiftNoToStart[0].ToString("hh:mm tt");
                        toAdd.ScheduledTime += "\n" + ShiftNoToEnd[0].ToString("hh:mm tt");
                    }
                    else
                    {
                        toAdd.ScheduledTime = toAdd.PayTime;
                    }
                    TimeSpan LOWSpan = (LOWEnd - LOWStart);
                    double LOWPaid = Math.Round(LOWSpan.Hours + (double)LOWSpan.Minutes / 60, 2);
                    toAdd.LOW = LOWPaid;
                    report.Add(toAdd);
                }
            }*/

            // check for an empty employee
            if (report.Count <= 0)
            {
                report.Add(new Joshua
                    {
                        Date = DateTime.Now,
                        EmployeeID = emp.EmployeeID,
                        EmpName = emp.EmpName
                    });
            }

            // handle over time depending on california employees
            var dates = (from r in report select r.Date).Distinct();
            //var firstWeek = report.Min(m => m.Week);

            if (isCalifornia)
            {
                foreach (var date in dates)
                {
                    // get the items for that day
                    var items = (from r in report where r.Date == date select r).ToList();
                    var total = items.Sum(m => m.LOW);
                    if (total > 8) { items.Last().OT = total - 8; }
                }
            }
            else
            {
                var weeks = (from r in report select r.Week).Distinct();

                foreach (var week in weeks)
                {
                    var items = (from r in report where r.Week == week select r).ToList();
                    double amt = 0;
                    foreach (var item in items)
                    {
                        amt = amt + item.LOW;
                        if (amt > 40)
                        {
                            item.OT = amt - 40;
                            amt = 40;
                        }
                    }
                }
            }

            this.reportViewer1.LocalReport.DataSources.Clear();

            // add transactions to the report
            this.reportViewer1.LocalReport.DataSources.Add(
                new Microsoft.Reporting.WinForms.ReportDataSource("TransactionSet", report));

            // add the employee detail to the report
            this.reportViewer1.LocalReport.DataSources.Add(
            new Microsoft.Reporting.WinForms.ReportDataSource("EmployeeSet", (object)emps));

            //add the week range detail to the report
            //TODO: Need to figure out how to bind this additional data source to the report
            var weekData = new List<WeekRangeData>();
            this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("WeekSet", (object) weekData));

            System.Drawing.Printing.PageSettings ps = new System.Drawing.Printing.PageSettings();
            ps.Landscape = true;
            ps.PaperSize = new System.Drawing.Printing.PaperSize("A4", 827, 1170);
            ps.PaperSize.RawKind = (int)System.Drawing.Printing.PaperKind.A4;
            reportViewer1.SetPageSettings(ps);

            // refresh the report
            this.reportViewer1.RefreshReport();
        }
 public EmployeeReportObject(TimeCardDataSet1.EmployeesRow employee)
 {
     e_days = new List<Joshua>();
     _employee = employee;
     generateReport(employee);
 }
        /// <summary>
        /// Uses the dbKey to run queries on the database. These queries each create new Joshuas, which are then
        /// added to e_days. edays are the objects used to generate the report
        /// </summary>
        /// <param name="dbKey">employeeID </param>
        public void generateReport(TimeCardDataSet1.EmployeesRow employee)
        {
            //get week one and week two in order to grab transactions for those time periods

            TimeCardDataSet1TableAdapters.WeeklyTotalTableAdapter weeklyAdapter = new TimeCardDataSet1TableAdapters.WeeklyTotalTableAdapter();
            var weeklyTable = weeklyAdapter.GetDistinctWeeks();
            DateTime week1End = weeklyTable[0].Week;
            DateTime week2End = weeklyTable[1].Week;

            //from 1 week prior to 1st week - subtract one week from End of 1st week
            DateTime Week1StartTime = week1End.Subtract(new TimeSpan(7, 0, 0, 0, 0));

            //get entries in transactions table for individual days of first week
            TimeCardDataSet1TableAdapters.TransactionsTableAdapter TransactionAdapter = new TimeCardDataSet1TableAdapters.TransactionsTableAdapter();
            var transactionTable1 = TransactionAdapter.GetDataByEnrollNoAndTimeRange(employee.EmployeeID, Week1StartTime, week1End);

            Joshua currentObject = new Joshua { ActualTime = "" };

            DateTime CurrentObjectDate;
            try
            {
                CurrentObjectDate = transactionTable1[0].LogDate;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return;
            }

            //iterate through the transaction table results
            for (int i = 0; i < transactionTable1.Count; i++)
            {
                DateTime rowDate = transactionTable1[i].LogDate;

                if (rowDate.CompareTo(CurrentObjectDate) != 0) //if it's a new day it should go on the next Joshua
                {
                    currentObject.Date = CurrentObjectDate;
                    e_days.Add(currentObject);

                    currentObject = new Joshua { ActualTime = transactionTable1[i].LogTime.ToShortTimeString() + "\n" };
                    CurrentObjectDate = transactionTable1[i].LogDate; //the new currentobject date is the newest date encountered

                }
                else //add it to the same Joshua
                {
                    currentObject.ActualTime = currentObject.ActualTime + transactionTable1[i].LogTime.ToShortTimeString() + "\n";

                }
            }

              //  currentObject.Date = lastDateHolder.Date.ToString().Substring(0, lastDateHolder.Date.ToString().IndexOf(' '));
            e_days.Add(currentObject); //Add that last day object

               TimeCardDataSet1.WeeklyTotalDataTable weekTB = weeklyAdapter.GetDataByEmployeeID(employee.EmployeeID);

            //display weekly totals for first week
            AddWeekAsEntry(weekTB, 0);

            //TODO: figure out why friday1 & monday2 have wrong date displayed

            /* BUILD SECOND WEEK **********************************************************/

            Joshua currentObject2 = new Joshua { ActualTime = "" };

            try
            {
                CurrentObjectDate = transactionTable1[1].LogDate;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return;
            }
            transactionTable1 = TransactionAdapter.GetDataByEnrollNoAndTimeRange(employee.EmployeeID, week1End, week2End);
            //iterate through the transaction table results
            for (int i = 0; i < transactionTable1.Count; i++)
            {
                DateTime rowDate = transactionTable1[i].LogDate;
                if (rowDate.CompareTo(CurrentObjectDate) != 0) //if it's a new day it should go on the next Joshua
                {
                    currentObject.Date = CurrentObjectDate;
                    e_days.Add(currentObject);

                    currentObject = new Joshua { ActualTime = transactionTable1[i].LogTime.ToShortTimeString() + "\n" };
                    CurrentObjectDate = transactionTable1[i].LogDate; //the new currentobject date is the newest date encountered
                }
                else //add it to the same Joshua
                {
                    currentObject.ActualTime = currentObject.ActualTime + transactionTable1[i].LogTime.ToShortTimeString() + "\n";
                }
            }

            currentObject.Date = transactionTable1[transactionTable1.Count - 1].LogDate;
            e_days.Add(currentObject); //Add that last day object

            //display weekly totals for first week
            AddWeekAsEntry(weekTB, 1);
        }
 private void AddWeekAsEntry(TimeCardDataSet1.WeeklyTotalDataTable tbl, int weekNo)
 {
     var wLow = tbl[weekNo].wLOW;
     var WOT = tbl[weekNo].wOT;
     DateTime week = tbl[weekNo].Week;
     //format week nicely.
     string WeekTrimmed = week.ToString().Substring(0, week.ToString().IndexOf(' '));
     //e_days.Add(new Joshua { Date = "Pay Week Ending: " + WeekTrimmed, OT = WOT, TotalHours = wLow });
 }