public Boolean Post(sheet s) { if (s != null) { DateTime dt = DateTime.Now; string folder = HostingEnvironment.MapPath("~/timesheets"); try { string pdfName = String.Format("SHSWelding_{0:u}.pdf", dt).Replace(":", ""); string pdfPath = Path.Combine(folder, pdfName); string imgName = String.Format("signature_{0:u}.jpg", dt).Replace(":", ""); string imgPath = Path.Combine(folder, imgName); if (!String.IsNullOrEmpty(s.signatureImage) && s.signatureImage.StartsWith("data:image/jpeg;base64,/")) { byte[] bytes = Convert.FromBase64String(s.signatureImage.Replace("data:image/jpeg;base64,", "")); Image image; using (MemoryStream ms = new MemoryStream(bytes)) { image = Image.FromStream(ms); image.Save(imgPath); } } else { imgPath = String.Empty; } TimeSheetReport rpt = new TimeSheetReport(); rpt.GenerateTimeSheet(s, pdfPath, imgPath); return(true); } catch (Exception ex) { string errName = String.Format("error_{0:u}.log", dt).Replace(":", ""); string errPath = Path.Combine(folder, errName); LogData(errPath, ex.Message); LogData(errPath, ex.StackTrace); } } return(false); }
private void GenerateTimeSheet(DateTime monthOfSheet) { var beginDate = new DateTime(monthOfSheet.Year, monthOfSheet.Month, 1); var endDate = beginDate.AddMonths(1).AddDays(-1); var list = GetReportList(beginDate, endDate); TimeSheetGenerator generator = new TimeSheetGenerator(list.ToList()); generator.Generate(); var sheetRecords = generator.SheetRecords; FilterOptions filterOptions = new FilterOptions(beginDate.Date, endDate.Date); ExcelReport <TimeSheetRecord> report = new TimeSheetReport(sheetRecords, nameof(TimeSheetReport), filterOptions); Task.Run(() => { report.CreateReport(); report.ShowReport(); }); }
private void GeneratePDF(ReportPackage myReportPackage) { if (myReportPackage.TimeSheets.Count > 0) { #region Table Header Collection List <string> ColList = new List <string>(); ColList.Add("Prj No."); ColList.Add("SAP"); ColList.Add("Cost Code"); ColList.Add("Project Name"); for (DateTime dt = myReportPackage.DateFrom; dt < myReportPackage.DateTo.AddDays(1); dt = dt.AddDays(1)) { ColList.Add(dt.ToString("ddd\ndd\nMMM")); } ColList.Add("Total"); #endregion #region Detail Collection List <ReportRow> rows = new List <ReportRow>(); int colcount = 0; int rowcount = 1; foreach (var r in myReportPackage.TimeSheets) { colcount = 0; List <ReportCell> cells = new List <ReportCell>(); cells.Add(new ReportCell() { colnum = colcount, rownum = rowcount, colspan = 1, type = CellType.String, value = r.Project_Number.ToString() }); cells.Add(new ReportCell() { colnum = colcount++, rownum = rowcount, colspan = 1, type = CellType.String, value = r.SAP }); cells.Add(new ReportCell() { colnum = colcount++, rownum = rowcount, colspan = 1, type = CellType.String, value = r.WBS }); cells.Add(new ReportCell() { colnum = colcount++, rownum = rowcount, colspan = 1, type = CellType.String, value = r.Project_Name }); foreach (var d in r.Days) { cells.Add(new ReportCell() { colnum = colcount++, rownum = rowcount, colspan = 1, type = CellType.Number, value = (!d.HoursWorked.HasValue) ? string.Empty : d.HoursWorked.Value.ToString("#0.00") }); } cells.Add(new ReportCell() { colnum = colcount++, rownum = rowcount, colspan = 1, type = CellType.Number, value = r.Total.ToString() }); rows.Add(new ReportRow() { row = cells }); rowcount++; } #endregion #region Footer Collection List <string> FooterList = new List <string>(); FooterList.Add(""); FooterList.Add(""); FooterList.Add(""); FooterList.Add(""); foreach (var d in myReportPackage.DayTotals) { FooterList.Add((String.IsNullOrEmpty(d.HoursWorked.ToString())) ? string.Empty : (d.HoursWorked.Value == 0) ? string.Empty : d.HoursWorked.Value.ToString("#0.00")); } FooterList.Add(myReportPackage.GrandTotal.ToString()); #endregion #region Saco Collection List <string> SacoList = new List <string>(); SacoList.Add(""); SacoList.Add(""); SacoList.Add(""); SacoList.Add(""); foreach (var d in myReportPackage.DaySacoTotals) { SacoList.Add((String.IsNullOrEmpty(d.HoursWorked.ToString())) ? string.Empty : (d.HoursWorked.Value == 0) ? string.Empty : d.HoursWorked.Value.ToString("#0.00")); } decimal sacototal = myReportPackage.DaySacoTotals.Sum(s => (decimal)s.HoursWorked); SacoList.Add(sacototal.ToString("#0.00")); #endregion #region Set the Column Widths float[] HeaderWidths = new float[colcount + 1]; HeaderWidths[0] = 26f; HeaderWidths[1] = 30f; HeaderWidths[2] = 30f; HeaderWidths[3] = 60f; for (int col = 4; col < colcount; col++) { HeaderWidths[col] = 20f; } HeaderWidths[colcount] = 22f; #endregion //Create New PDF Timesheet Report IPDFReport myReport = new TimeSheetReport(true); //Assgin Column, Row and Footer collections to MyReport Object myReport.ColList = ColList; myReport.FooterList = FooterList; myReport.ReportRows = rows; myReport.SacoList = SacoList; //Set Report Properties myReport.Start = myReportPackage.DateFrom; myReport.End = myReportPackage.DateTo; myReport.filename = "TSD_TimeSheets_" + myReportPackage.User_CAI + "_" + myReportPackage.DateFrom.ToString("dd-MMM-yyyy") + "_" + myReportPackage.DateTo.ToString("dd-MMM-yyyy"); myReport.PageHeight = 595; myReport.LogoImagePath = "~/images/img_hallmark.gif"; myReport.ReportDescription = "TimeSheet"; //Assign Column Widths to myReport myReport.Headerwidths = HeaderWidths; //Write myReport myReport.GenerateXMLReport(); //Open Report and browswer myReport.OpenPDF(); } }
public async Task <bool> AddWorkDayAsync(WorkDay newWorkDay, User currentUser) { DateTime recentPayPeriodStart = _context.PayPeriods.OrderBy(e => e.Id).Last().PeriodStartDate; DateTime recentPayPeriodEnd = _context.PayPeriods.OrderBy(e => e.Id).Last().PeriodEndDate; // Creates new Pay Period and TimeSheet for that period if current date is past previous period end date if (DateTime.Now > recentPayPeriodEnd) { PayPeriod newPayPeriod = new PayPeriod() { PeriodStartDate = recentPayPeriodEnd.AddSeconds(1), PeriodEndDate = recentPayPeriodEnd.AddDays(14) }; _context.PayPeriods.Add(newPayPeriod); TimeSheetReport newTimeSheetReport = new TimeSheetReport() { TotalRegHours = 0, TotalOTHours = 0, TotalPeriodPay = 0, UserId = currentUser.Id, PayPeriodId = newPayPeriod.Id }; _context.TimeSheetReports.Add(newTimeSheetReport); _context.SaveChanges(); } // creates TimeSheet if user has none if (_context.TimeSheetReports.Where(e => e.UserId == currentUser.Id).Count() < 1) { TimeSheetReport newTimeSheetReport = new TimeSheetReport() { TotalRegHours = 0, TotalOTHours = 0, TotalPeriodPay = 0, UserId = currentUser.Id, PayPeriodId = _context.PayPeriods.OrderBy(e => e.Id).ToList().Last().Id }; _context.TimeSheetReports.Add(newTimeSheetReport); _context.SaveChanges(); } // Creates new instance of workDay newWorkDay.Date = newWorkDay.ClockIn; newWorkDay.HoursWorked = calculateTotalHours(newWorkDay); var currentReport = _context.TimeSheetReports.Where(e => e.UserId == currentUser.Id).OrderBy(e => e.Id).ToList().Last(); newWorkDay.TimeSheetReportId = currentReport.Id; // Updates TimeSheet currentReport.TotalRegHours += newWorkDay.HoursWorked; currentReport.TotalOTHours = (currentReport.TotalRegHours > 40 && !currentUser.Exempt) ? currentReport.TotalRegHours - 40 : 0; currentReport.TotalPeriodPay = (currentReport.TotalRegHours * currentUser.HourlyWage) + (currentReport.TotalOTHours * currentUser.HourlyWage * 1.5); _context.WorkDays.Add(newWorkDay); var saveResult = await _context.SaveChangesAsync(); return(saveResult == 1); }