Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using iBoris.Broadcapp.DailyPlannings;
- using iBoris.Broadcapp.Exports.Npoi;
- using iBoris.Unicorn;
- using NPOI.HSSF.Util;
- using NPOI.SS.UserModel;
- using iBoris.Broadcapp.CentralPlan;
- using iBoris.Broadcapp.Resources;
- using iBoris.Broadcapp.PlanningDepartments;
- using iBoris.Broadcapp.Contacts;
- using iBoris.Broadcapp.Programs;
- using iBoris.Broadcapp.Security;
- using iBoris.Unicorn.Security;
- using NPOI.HSSF.UserModel;
- namespace iBoris.Broadcapp.Exports
- {
- public class ExportPlanBoardDetailsExcelReportService : IExportPlanBoardDetailsExcelReportService
- {
- public ExportPlanBoardDetailsExcelReportService(
- ICentralPlanDataProvider centralPlanDataProvider,
- ICentralPlanDateProvider centralPlanDateProvider)
- {
- this.centralPlanDataProvider = centralPlanDataProvider;
- this.centralPlanDateProvider = centralPlanDateProvider;
- }
- public byte[] ExportExcelReport(CentralPlanFilter filter, bool showManagementDetails)
- {
- //Create Report
- List<NpoiSheet> npoiSheets = new List<NpoiSheet>();
- npoiSheets.Add(new NpoiSheet("Plan Board Details", 0, false));
- NpoiReport report = new NpoiReport(npoiSheets);
- Person person = SecurityContext.User as Person;
- SecurityMarker securityMarker = new SecurityMarkerManager(person).Read();
- bool canSeeBudgetSales = securityMarker.HasFlag(SecurityMarker.Management) ||
- securityMarker.HasFlag(SecurityMarker.Sales) ||
- securityMarker.HasFlag(SecurityMarker.Financials);
- bool canSeeCosts = securityMarker.HasFlag(SecurityMarker.Budget); // TODO: check
- CreateCellStyles(report);
- InitializeColumns(report, showManagementDetails, canSeeCosts);
- // Render Header
- AddHeaderRow(report, canSeeBudgetSales, showManagementDetails, canSeeCosts);
- // Load Data
- IList<CategoryValue> categoryValues = ExtractCategoryValues(filter, person, securityMarker);
- List<int> resourceIds = categoryValues.Select(cv => cv.Resource.Id).ToList();
- List<Contact> contacts = new List<Contact>();
- ContactFilter cFilter = new ContactFilter()
- {
- SkipDzjitoContributors = false
- };
- cFilter.JointAssociations.Add("Nominal");
- Dictionary<int, List<int>> resourceIdDict = resourceIds.GroupIds<int, List<int>>();
- for (int i = 0; i < resourceIdDict.Count(); i++)
- {
- cFilter.ResourceIds = resourceIdDict[i].ToArray();
- contacts.AddRange(Persistence.GetLoader<Contact, ContactFilter>(cFilter).List());
- }
- // Render Data
- GenerateReport(categoryValues, contacts, canSeeBudgetSales, canSeeCosts, showManagementDetails, report);
- return report.GetBinaryData();
- }
- #region Private members
- private IList<CategoryValue> ExtractCategoryValues(CentralPlanFilter filter, Person person, SecurityMarker marker)
- {
- ResourceFilter resourceFilter = GetResourceFilter(filter);
- IEnumerable<Resource> resources = Persistence.GetLoader<Resource, ResourceFilter>(resourceFilter).List();
- List<int> resourceIds = resources.Select(x => x.Id).ToList();
- List<CategoryValue> categoryValues = new List<CategoryValue>();
- if (resourceIds.Count > 0)
- {
- List<PlanningItemType> piTypes = new List<PlanningItemType>();
- piTypes.Add(PlanningItemType.Booking);
- piTypes.Add(PlanningItemType.Absence);
- CategoryValueFilter categoryValueFilter = centralPlanDataProvider.GetCategoryValueFilter(
- filter,
- null,
- piTypes,
- false,
- true,
- true,
- fetchAssociationsForMapping: true);
- if (!marker.HasFlag(SecurityMarker.Management))
- {
- categoryValueFilter.HasDepartmentOrProgramRightsUserId = person.Id;
- }
- categoryValueFilter.JointAssociations.Add("PlanningItem.Program.SalesBudget");
- Dictionary<int, List<int>> resourceIdDict = resourceIds.GroupIds<int, List<int>>();
- for (int i = 0; i < resourceIdDict.Count(); i++)
- {
- categoryValueFilter.ResourceIds = resourceIdDict[i].ToArray();
- categoryValues.AddRange(Persistence.GetLoader<CategoryValue, CategoryValueFilter>(categoryValueFilter).List());
- }
- }
- return categoryValues;
- }
- private ResourceFilter GetResourceFilter(CentralPlanFilter filter)
- {
- bool hasGroupFilter = filter.PlanningDepartmentGroupIds != null && filter.PlanningDepartmentGroupIds.Count() > 0;
- ResourceFilter resourceFilter = new ResourceFilter();
- if (hasGroupFilter)
- {
- DepartmentGroupResourceFilter groupResourceFilter = centralPlanDataProvider.GetDepartmentGroupResourceFilter(filter);
- List<DepartmentGroupResource> departmentGroupResources = Persistence.GetLoader<DepartmentGroupResource, DepartmentGroupResourceFilter>(groupResourceFilter).List().ToList();
- List<int> ids = departmentGroupResources.Select(x => x.Id).ToList();
- ids.Add(-1); // if departmentGroupResources.Count = 0 ->> not show anything;
- resourceFilter.DepartmentGroupResourcesIds = ids.ToArray();
- }
- else
- {
- resourceFilter = centralPlanDataProvider.GetResourceFilter(filter);
- }
- return resourceFilter;
- }
- private void CreateCellStyles(NpoiReport report)
- {
- IFont normalFont10 = new NpoiFont(report.GetWorkbook(), HSSFColor.BLACK.index, 10).GetFont();
- IFont boldFont10 = new NpoiFont(report.GetWorkbook(), HSSFColor.BLACK.index, 10, true).GetFont();
- HSSFPalette palette = ((HSSFWorkbook)report.GetWorkbook()).GetCustomPalette();
- palette.SetColorAtIndex(HSSFColor.LIGHT_GREEN.index,
- (byte)198,
- (byte)224,
- (byte)164
- );
- columnHeaderBorderedLeftAlignedStyle = new NpoiStyle(report.GetWorkbook(), HSSFColor.LIGHT_GREEN.index, FillPatternType.SOLID_FOREGROUND, HorizontalAlignment.LEFT, boldFont10, BorderStyle.THIN, null);
- columnHeaderBorderedRightAlignedStyle = new NpoiStyle(report.GetWorkbook(), HSSFColor.LIGHT_GREEN.index, FillPatternType.SOLID_FOREGROUND, HorizontalAlignment.RIGHT, boldFont10, BorderStyle.THIN, null);
- columnNormalLeftNonBorderedStyle = new NpoiStyle(report.GetWorkbook(), 0, FillPatternType.NO_FILL, HorizontalAlignment.LEFT, normalFont10, BorderStyle.NONE, null);
- columnNormalRightNonBorderedStyle = new NpoiStyle(report.GetWorkbook(), 0, FillPatternType.NO_FILL, HorizontalAlignment.RIGHT, normalFont10, BorderStyle.NONE, null);
- columnDateRightNonBorderedStyle = new NpoiStyle(report.GetWorkbook(), 0, FillPatternType.NO_FILL, HorizontalAlignment.RIGHT, normalFont10, BorderStyle.NONE, "dd/MM/yyyy");
- rightAligned2Decimals = new NpoiStyle(report.GetWorkbook(), horizontalAlignment: HorizontalAlignment.RIGHT, dataFormat: "β¬ * #,##0.00");
- rightAlignedPercentage = new NpoiStyle(report.GetWorkbook(), horizontalAlignment: HorizontalAlignment.RIGHT, dataFormat: "% * #,##0.00");
- rightAligned = new NpoiStyle(report.GetWorkbook(), horizontalAlignment: HorizontalAlignment.RIGHT);
- }
- private void InitializeColumns(NpoiReport report, bool showManagementDetails, bool canSeeCosts)
- {
- // Planning Department
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- // Department Group
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- // Production Name
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- // Title
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- //Date From
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- // Date To
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- // Company
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- // Category Type
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- // Category/Role
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- // Resource
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- // Actual Start
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- //Actual End
- report.AddColumn(0, String.Empty, 30, CellType.STRING);
- //Actual Break
- report.AddColumn(0, String.Empty, 30, CellType.NUMERIC);
- if (canSeeCosts)
- {
- // Cost
- report.AddColumn(0, String.Empty, 20, CellType.NUMERIC);
- }
- // Number of Days
- report.AddColumn(0, String.Empty, 20, CellType.NUMERIC);
- // Kilometers
- report.AddColumn(0, String.Empty, 20, CellType.NUMERIC);
- // Production Cost Center
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- // Analytical Code
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- // Planning Department Cost Center
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- // Shift Name
- report.AddColumn(0, String.Empty, 40, CellType.STRING);
- // Shift Start Time
- report.AddColumn(0, String.Empty, 40, CellType.STRING);
- // Shift End Time
- report.AddColumn(0, String.Empty, 40, CellType.STRING);
- // Shift Break
- report.AddColumn(0, String.Empty, 40, CellType.NUMERIC);
- // Planning Type
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- // Status
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- // Actual Overtime
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- // Actual Workingtime
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- // Shift Workingtime
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- if (showManagementDetails)
- {
- // Production Internal Company
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- // Production Status
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- // Production Total Sales Budget
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- // Production Is Internal
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- // Production Company
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- // Person Contact Type
- report.AddColumn(0, String.Empty, 20, CellType.STRING);
- // Person Contact Hours
- report.AddColumn(0, String.Empty, 20, CellType.NUMERIC);
- }
- report.SetLastDataRowIndex(0, 0);
- }
- private void AddHeaderRow(NpoiReport report, bool canSeeBudgetSales, bool showManagementDetails, bool canSeeCosts)
- {
- List<RowCell> rowCells = new List<RowCell>();
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_PlanningDepartment, columnHeaderBorderedLeftAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_DepartmentGroup, columnHeaderBorderedLeftAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_Production, columnHeaderBorderedLeftAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_Title, columnHeaderBorderedLeftAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_DateFrom, columnHeaderBorderedRightAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_DateTo, columnHeaderBorderedRightAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_Company, columnHeaderBorderedLeftAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_CategoryType, columnHeaderBorderedLeftAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_CategoryRole, columnHeaderBorderedLeftAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_Resource, columnHeaderBorderedLeftAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_ActualStart, columnHeaderBorderedRightAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_ActualEnd, columnHeaderBorderedRightAlignedStyle));
- rowCells.Add(new RowCell(CellType.NUMERIC, Strings.ExportPlanBoardDetailsExcelReportService_ActualBreak, columnHeaderBorderedRightAlignedStyle));
- if (canSeeCosts)
- {
- rowCells.Add(new RowCell(CellType.NUMERIC, Strings.ExportPlanBoardDetailsExcelReportService_Cost, columnHeaderBorderedRightAlignedStyle));
- }
- rowCells.Add(new RowCell(CellType.NUMERIC, Strings.CostType, columnHeaderBorderedRightAlignedStyle));
- rowCells.Add(new RowCell(CellType.NUMERIC, Strings.ExportPlanBoardDetailsExcelReportService_NumberOfDays, columnHeaderBorderedRightAlignedStyle));
- rowCells.Add(new RowCell(CellType.NUMERIC, Strings.ExportPlanBoardDetailsExcelReportService_Kilometers, columnHeaderBorderedRightAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_ProductionCostCenter, columnHeaderBorderedLeftAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_AnalyticalCode, columnHeaderBorderedLeftAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_PlanningDepartmentCostCenter, columnHeaderBorderedLeftAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_ShiftName, columnHeaderBorderedLeftAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_ShiftStartTime, columnHeaderBorderedRightAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_ShiftEndTime, columnHeaderBorderedRightAlignedStyle));
- rowCells.Add(new RowCell(CellType.NUMERIC, Strings.ExportPlanBoardDetailsExcelReportService_ShiftBreak, columnHeaderBorderedRightAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_PlanningType, columnHeaderBorderedLeftAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_Status, columnHeaderBorderedLeftAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_ActualOvertime, columnHeaderBorderedRightAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_ActualWorkingtime, columnHeaderBorderedRightAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_ShiftWorkingtime, columnHeaderBorderedRightAlignedStyle));
- if (showManagementDetails)
- {
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_ProductionInternalCompany, columnHeaderBorderedLeftAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_ProductionStatus, columnHeaderBorderedLeftAlignedStyle));
- if (canSeeBudgetSales)
- {
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_ProductionTotalSalesBudget, columnHeaderBorderedLeftAlignedStyle));
- }
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_ProductionIsInternal, columnHeaderBorderedLeftAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_ProductionCompany, columnHeaderBorderedLeftAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_PersonContractType, columnHeaderBorderedLeftAlignedStyle));
- rowCells.Add(new RowCell(CellType.STRING, Strings.ExportPlanBoardDetailsExcelReportService_PersonContractHours, columnHeaderBorderedRightAlignedStyle));
- }
- report.AddRowWithTypes(0, rowCells.ToArray());
- }
- #region Generation Logic
- private void GenerateReport(IList<CategoryValue> categoryValues, IEnumerable<Contact> contacts, bool canSeeBudgetSales, bool canSeeCosts, bool showManagementDetails, NpoiReport report)
- {
- foreach (var categoryValue in categoryValues)
- {
- if (categoryValue.PlanningItem == null)
- {
- continue;
- }
- List<RowCell> cells = new List<RowCell>();
- cells.AddRange(GeneratePlanningItemCells(categoryValue.PlanningItem, categoryValue, contacts, canSeeBudgetSales, canSeeCosts, showManagementDetails));
- report.AddRowWithTypes(0, cells.ToArray());
- }
- }
- private IEnumerable<RowCell> GeneratePlanningItemCells(PlanningItem planningItem, CategoryValue categoryValue, IEnumerable<Contact> contacts, bool canSeeBudgetSales, bool canSeeCosts, bool showManagementDetails)
- {
- List<RowCell> rowCells = new List<RowCell>();
- // Planning Department
- string planningDepartmentName = (planningItem.PlanningDepartment != null ? planningItem.PlanningDepartment.Name : string.Empty);
- rowCells.Add(new RowCell(CellType.STRING, planningDepartmentName, columnNormalLeftNonBorderedStyle));
- // Department Group
- string planningDepartmentGroupName = (planningItem.DepartmentGroup != null ? planningItem.DepartmentGroup.Name : string.Empty);
- rowCells.Add(new RowCell(CellType.STRING, planningDepartmentGroupName, columnNormalLeftNonBorderedStyle));
- // Production Name
- string planningItemProgramName = (planningItem.Program != null ? planningItem.Program.Name : string.Empty);
- rowCells.Add(new RowCell(CellType.STRING, planningItemProgramName, columnNormalLeftNonBorderedStyle));
- // Title
- rowCells.Add(new RowCell(CellType.STRING, planningItem.Title, columnNormalLeftNonBorderedStyle));
- // Date From
- rowCells.Add(new RowCell(CellType.STRING, GetTextOrEmpty(planningItem.Date.ToShortDateString()), columnDateRightNonBorderedStyle));
- // Date To
- rowCells.Add(new RowCell(CellType.STRING, GetTextOrEmpty(planningItem.ToDate.ToShortDateString()), columnDateRightNonBorderedStyle));
- // Company
- string categoryValueCompanyName = (categoryValue.Company != null ? categoryValue.Company.Name : string.Empty);
- rowCells.Add(new RowCell(CellType.STRING, categoryValueCompanyName, columnNormalLeftNonBorderedStyle));
- // Category Type
- string categoryValueCategoryTypeName = (categoryValue.CategoryType != null ? categoryValue.CategoryType.Name : string.Empty);
- rowCells.Add(new RowCell(CellType.STRING, categoryValueCategoryTypeName, columnNormalLeftNonBorderedStyle));
- // Category/Role
- string categoryValueCategoryName = (categoryValue.Category != null ? categoryValue.Category.Name : string.Empty);
- rowCells.Add(new RowCell(CellType.STRING, categoryValueCategoryName, columnNormalLeftNonBorderedStyle));
- // Resource
- string categoryValueResourceName = (categoryValue.Resource != null ? categoryValue.Resource.Name : string.Empty);
- rowCells.Add(new RowCell(CellType.STRING, categoryValueResourceName, columnNormalLeftNonBorderedStyle));
- // Actual Start
- rowCells.Add(new RowCell(CellType.STRING, GetTextOrEmpty(categoryValue.ActualStart.ToTimeString()), columnNormalRightNonBorderedStyle));
- // Actual End
- rowCells.Add(new RowCell(CellType.STRING, GetTextOrEmpty(categoryValue.ActualEnd.ToTimeString()), columnNormalRightNonBorderedStyle));
- // Actual Break
- rowCells.Add(new RowCell(CellType.NUMERIC, categoryValue.ActualBreak, columnNormalRightNonBorderedStyle));
- if (canSeeCosts)
- {
- // Cost
- rowCells.Add(new RowCell(CellType.NUMERIC, categoryValue.CostPerDay, columnNormalRightNonBorderedStyle));
- }
- // Cost Type
- rowCells.Add(new RowCell(CellType.NUMERIC, Enum.GetName(typeof(CostType), categoryValue.CostType), columnNormalRightNonBorderedStyle));
- // Number of Days
- if (planningItem.ToDate != null || planningItem.Date != null)
- {
- double days = (planningItem.ToDate.Value - planningItem.Date).TotalDays;
- days = Math.Round((days == 0 ? 1 : days));
- rowCells.Add(new RowCell(CellType.NUMERIC, days, columnNormalRightNonBorderedStyle));
- }
- else
- {
- // Empty cells
- rowCells.Add(new RowCell(CellType.STRING, String.Empty, columnNormalLeftNonBorderedStyle));
- }
- // Kilometers
- rowCells.Add(new RowCell(CellType.NUMERIC, categoryValue.Kilometers, columnNormalRightNonBorderedStyle));
- // Production Cost Center
- if (planningItem.Program != null)
- {
- string planningItemProgramCostCenterName = (planningItem.Program.CostCenter != null ? planningItem.Program.CostCenter.Name : string.Empty);
- rowCells.Add(new RowCell(CellType.STRING, planningItemProgramCostCenterName, columnNormalLeftNonBorderedStyle));
- }
- else
- {
- // Empty cells
- rowCells.Add(new RowCell(CellType.STRING, String.Empty, columnNormalLeftNonBorderedStyle));
- }
- // Analytical Code
- string analyticalCode = (planningItem.Program != null ? planningItem.Program.AnalyticalCode : string.Empty);
- rowCells.Add(new RowCell(CellType.STRING, analyticalCode, columnNormalLeftNonBorderedStyle));
- // Planning Department Cost Center
- if (planningItem.PlanningDepartment != null)
- {
- string planningItemProgramCostCenterName = (planningItem.PlanningDepartment.CostCenter != null ? planningItem.PlanningDepartment.CostCenter.Name : string.Empty);
- rowCells.Add(new RowCell(CellType.STRING, planningItemProgramCostCenterName, columnNormalLeftNonBorderedStyle));
- }
- else
- {
- // Empty cells
- rowCells.Add(new RowCell(CellType.STRING, String.Empty, columnNormalLeftNonBorderedStyle));
- }
- // Shift Name
- string planningItemShiftName = (planningItem.Shift != null ? planningItem.Shift.Name : string.Empty);
- rowCells.Add(new RowCell(CellType.STRING, planningItemShiftName, columnNormalLeftNonBorderedStyle));
- // Shift Start Time
- string planningItemShiftStartTime = (planningItem.Shift != null ? planningItem.Shift.StartTime.ToTimeString() : string.Empty);
- rowCells.Add(new RowCell(CellType.STRING, planningItemShiftStartTime, columnNormalRightNonBorderedStyle));
- // Shift End Time
- string planningItemShiftEndTime = (planningItem.Shift != null ? planningItem.Shift.EndTime.ToTimeString() : string.Empty);
- rowCells.Add(new RowCell(CellType.STRING, planningItemShiftEndTime, columnNormalRightNonBorderedStyle));
- // Shift Break
- if (planningItem.Shift != null)
- {
- rowCells.Add(new RowCell(CellType.NUMERIC, planningItem.Shift.BreakTime, columnNormalRightNonBorderedStyle));
- }
- else
- {
- // Empty cells
- rowCells.Add(new RowCell(CellType.NUMERIC, String.Empty, columnNormalRightNonBorderedStyle));
- }
- // Planning Type
- string planningItemPlanningTypeName = (planningItem.PlanningType != null ? planningItem.PlanningType.Name : string.Empty);
- rowCells.Add(new RowCell(CellType.STRING, planningItemPlanningTypeName, columnNormalLeftNonBorderedStyle));
- // Status
- rowCells.Add(new RowCell(CellType.STRING, Enum.GetName(typeof(BookingStatus), categoryValue.Confirmed), columnNormalLeftNonBorderedStyle));
- // Actual Overtime
- double? overtime = null;
- if (categoryValue.Overtime.HasValue)
- {
- double overtimeDec = new TimeSpan(0, categoryValue.Overtime.Value, 0).TotalHours;
- overtime = Math.Round(overtimeDec, 2);
- }
- rowCells.Add(new RowCell(CellType.NUMERIC, overtime, columnNormalRightNonBorderedStyle));
- // Actual Working Time
- double workingtimeDec = centralPlanDateProvider.GetBookingDuration(categoryValue).TotalHours;
- double workingtime = Math.Round(workingtimeDec, 2);
- rowCells.Add(new RowCell(CellType.NUMERIC, workingtime, columnNormalRightNonBorderedStyle));
- // Shift Working Time
- double? shiftWorkingtime = null;
- if (categoryValue.PlanningItem.Shift != null)
- {
- Shift shift = categoryValue.PlanningItem.Shift;
- double shiftWorkingtimeDec = centralPlanDateProvider.GetDuration(shift.StartTime, shift.EndTime, shift.BreakTime).TotalHours;
- shiftWorkingtime = Math.Round(shiftWorkingtimeDec, 2);
- }
- rowCells.Add(new RowCell(CellType.NUMERIC, shiftWorkingtime, columnNormalRightNonBorderedStyle));
- if (showManagementDetails)
- {
- // Production Internal Company
- rowCells.Add(new RowCell(CellType.STRING, planningItem.Program?.InternalCompany?.Name, columnNormalLeftNonBorderedStyle));
- // Production Status
- string status = planningItem.Program?.Status != null ? Enum.GetName(typeof(ProgramStatus), planningItem.Program?.Status) : string.Empty;
- rowCells.Add(new RowCell(CellType.STRING, status, columnNormalLeftNonBorderedStyle));
- // Production Total Sales Budget
- if (canSeeBudgetSales)
- {
- rowCells.Add(new RowCell(CellType.NUMERIC, categoryValue.PlanningItem.Program?.SalesBudget?.Total, columnNormalRightNonBorderedStyle));
- }
- // Production Is Internal
- string isInternal;
- if (planningItem.Program != null)
- {
- isInternal = planningItem.Program?.IsInternal == true ? Strings.Yes : Strings.No;
- }
- else
- {
- isInternal = string.Empty;
- }
- rowCells.Add(new RowCell(CellType.STRING, isInternal, columnNormalLeftNonBorderedStyle));
- // Production Company
- rowCells.Add(new RowCell(CellType.STRING, planningItem.Program?.Company?.Name, columnNormalLeftNonBorderedStyle));
- // Person Contact Type
- Contact currentContact = contacts.Where(c => c.Resource.Id == categoryValue.Resource.Id).FirstOrDefault();
- string contactType = currentContact != null ? Enum.GetName(typeof(ContactType), currentContact?.ContactType) : string.Empty;
- rowCells.Add(new RowCell(CellType.STRING, contactType, columnNormalLeftNonBorderedStyle));
- // Person Contact Hours
- string contactHours = currentContact != null ? GetPersonContactHours(currentContact, planningItem).ToString() : String.Empty;
- rowCells.Add(new RowCell(CellType.NUMERIC, contactHours, columnNormalRightNonBorderedStyle));
- }
- return rowCells;
- }
- #endregion
- private string GetTextOrEmpty(string value)
- {
- return value ?? string.Empty;
- }
- private decimal GetPersonContactHours(Contact contact, PlanningItem pi)
- {
- decimal hours = 0;
- int piDuration = (pi.ToDate - pi.Date).Value.Days + 1;
- foreach (var nominal in contact.Nominals)
- {
- var piDate = pi.Date.Date;
- if (piDate >= nominal.DateFrom.Date && (!nominal.DateTo.HasValue || piDate <= nominal.DateTo.Value.Date))
- {
- if (nominal.NominalSchemeType == NominalSchemeType.Variable)
- {
- hours = nominal.DailyNominal != null ? nominal.DailyNominal.Value : 0;
- hours = hours * piDuration;
- }
- else if (nominal.NominalSchemeType == NominalSchemeType.Fixed)
- {
- for (int i = 0; i < piDuration; i++)
- {
- DayOfWeek dayofWeek = pi.Date.DayOfWeek + i;
- hours += GetPlanningItemFixedNominalHours(nominal, dayofWeek);
- }
- }
- break;
- }
- }
- return hours;
- }
- private decimal GetPlanningItemFixedNominalHours(Nominal n, DayOfWeek dayOfWeek)
- {
- decimal hours = 0;
- switch (dayOfWeek)
- {
- case DayOfWeek.Sunday:
- hours = n.SundayNominal.Value;
- break;
- case DayOfWeek.Monday:
- hours = n.MondayNominal.Value;
- break;
- case DayOfWeek.Tuesday:
- hours = n.TuesdayNominal.Value;
- break;
- case DayOfWeek.Wednesday:
- hours = n.WednesdayNominal.Value;
- break;
- case DayOfWeek.Thursday:
- hours = n.ThursdayNominal.Value;
- break;
- case DayOfWeek.Friday:
- hours = n.FridayNominal.Value;
- break;
- case DayOfWeek.Saturday:
- hours = n.SaturdayNominal.Value;
- break;
- default:
- break;
- }
- return hours;
- }
- private NpoiStyle columnHeaderBorderedLeftAlignedStyle;
- private NpoiStyle columnHeaderBorderedRightAlignedStyle;
- private NpoiStyle columnNormalLeftNonBorderedStyle;
- private NpoiStyle columnNormalRightNonBorderedStyle;
- private NpoiStyle columnDateRightNonBorderedStyle;
- private NpoiStyle rightAligned2Decimals;
- private NpoiStyle rightAlignedPercentage;
- private NpoiStyle rightAligned;
- private ICentralPlanDataProvider centralPlanDataProvider;
- private ICentralPlanDateProvider centralPlanDateProvider;
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement