|
|
@@ -1,9 +1,11 @@
|
|
|
using DevExpress.Web.Mvc;
|
|
|
+using DevExpress.XtraReports.UI;
|
|
|
using GreenTree.Nachtragsmanagement.Core;
|
|
|
using GreenTree.Nachtragsmanagement.Core.Authentication;
|
|
|
using GreenTree.Nachtragsmanagement.Core.Domain.Appendix;
|
|
|
using GreenTree.Nachtragsmanagement.Core.Domain.Deviation;
|
|
|
using GreenTree.Nachtragsmanagement.Services.Appendix;
|
|
|
+using GreenTree.Nachtragsmanagement.Services.Configuration;
|
|
|
using GreenTree.Nachtragsmanagement.Services.Deviation;
|
|
|
using GreenTree.Nachtragsmanagement.Services.Logging;
|
|
|
using GreenTree.Nachtragsmanagement.Services.Site;
|
|
|
@@ -13,8 +15,10 @@ using GreenTree.Nachtragsmanagement.Web.Models.Appendix;
|
|
|
using GreenTree.Nachtragsmanagement.Web.Models.Deviation;
|
|
|
using GreenTree.Nachtragsmanagement.Web.Models.Global;
|
|
|
using Newtonsoft.Json;
|
|
|
+using Newtonsoft.Json.Linq;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Drawing;
|
|
|
using System.Linq;
|
|
|
using System.Net.Mime;
|
|
|
using System.Web;
|
|
|
@@ -30,19 +34,22 @@ namespace GreenTree.Nachtragsmanagement.Web.Controllers
|
|
|
private readonly ISiteService _siteService;
|
|
|
private readonly IUserHelper _userHelper;
|
|
|
private readonly ILogger _logger;
|
|
|
+ private readonly IConfigurationService _configurationService;
|
|
|
|
|
|
public DeviationController(
|
|
|
IDeviationService deviationService,
|
|
|
IAppendixService appendixService,
|
|
|
ISiteService siteService,
|
|
|
IUserHelper userHelper,
|
|
|
- ILogger logger)
|
|
|
+ ILogger logger,
|
|
|
+ IConfigurationService configurationService)
|
|
|
{
|
|
|
_deviationService = deviationService;
|
|
|
_appendixService = appendixService;
|
|
|
_siteService = siteService;
|
|
|
_userHelper = userHelper;
|
|
|
_logger = logger;
|
|
|
+ _configurationService = configurationService;
|
|
|
|
|
|
ViewData["AllDisturbances"] = _deviationService.GetAllDisturbances();
|
|
|
ViewData["AllStatuses"] = _deviationService.GetAllStatuses();
|
|
|
@@ -61,7 +68,7 @@ namespace GreenTree.Nachtragsmanagement.Web.Controllers
|
|
|
|
|
|
var deviations = _deviationService.GetAllUserAssignedDeviations(currentUser);
|
|
|
var deviationModels = deviations
|
|
|
- .Select(u => DeviationDataModel.FromDeviation(u, false))
|
|
|
+ .Select(u => DeviationDataModel.FromDeviation(u, false, _configurationService))
|
|
|
.ToList();
|
|
|
|
|
|
return View("~/Views/Deviations/View.cshtml", deviationModels);
|
|
|
@@ -81,7 +88,7 @@ namespace GreenTree.Nachtragsmanagement.Web.Controllers
|
|
|
JsonRequestBehavior = JsonRequestBehavior.AllowGet
|
|
|
};
|
|
|
|
|
|
- var deviationModel = DeviationDataModel.FromDeviation(deviation, false);
|
|
|
+ var deviationModel = DeviationDataModel.FromDeviation(deviation, false, _configurationService);
|
|
|
|
|
|
return new JsonResult
|
|
|
{
|
|
|
@@ -94,15 +101,18 @@ namespace GreenTree.Nachtragsmanagement.Web.Controllers
|
|
|
/// Callback result for deviation grid
|
|
|
/// </summary>
|
|
|
/// <param name="scrollHeight">The height of the grid scrollable component.</param>
|
|
|
- public ActionResult PartialDeviations(int scrollHeight = -1)
|
|
|
+ public ActionResult PartialDeviations(string customFilters, int scrollHeight = -1)
|
|
|
{
|
|
|
var currentUser = _userHelper.FromCookies();
|
|
|
|
|
|
var deviations = _deviationService.GetAllUserAssignedDeviations(currentUser);
|
|
|
var deviationModels = deviations
|
|
|
- .Select(u => DeviationDataModel.FromDeviation(u, false))
|
|
|
+ .Select(u => DeviationDataModel.FromDeviation(u, false, _configurationService))
|
|
|
.ToList();
|
|
|
|
|
|
+ if (!String.IsNullOrEmpty(customFilters))
|
|
|
+ UseCustomFilters(customFilters, deviationModels);
|
|
|
+
|
|
|
ViewData["ScrollHeight"] = scrollHeight;
|
|
|
|
|
|
return PartialView("~/Views/Deviations/_DeviationGridPartial.cshtml", deviationModels);
|
|
|
@@ -112,7 +122,7 @@ namespace GreenTree.Nachtragsmanagement.Web.Controllers
|
|
|
/// Export result for deviation grid
|
|
|
/// </summary>
|
|
|
[HttpPost]
|
|
|
- public ActionResult ExportPartialDeviations(string displayMode, string exportformat)
|
|
|
+ public ActionResult ExportPartialDeviations(string customFilters, string displayMode, string exportformat)
|
|
|
{
|
|
|
if (String.IsNullOrEmpty(displayMode))
|
|
|
return new EmptyResult();
|
|
|
@@ -121,9 +131,12 @@ namespace GreenTree.Nachtragsmanagement.Web.Controllers
|
|
|
|
|
|
var deviations = _deviationService.GetAllUserAssignedDeviations(currentUser);
|
|
|
var deviationModels = deviations
|
|
|
- .Select(u => DeviationDataModel.FromDeviation(u, false))
|
|
|
+ .Select(u => DeviationDataModel.FromDeviation(u, false, _configurationService))
|
|
|
.ToList();
|
|
|
|
|
|
+ if (!String.IsNullOrEmpty(customFilters))
|
|
|
+ UseCustomFilters(customFilters, deviationModels);
|
|
|
+
|
|
|
var viewContext = new ViewContext();
|
|
|
var viewPage = new ViewPage();
|
|
|
var htmlHelper = new System.Web.Mvc.HtmlHelper(viewContext, viewPage);
|
|
|
@@ -136,18 +149,35 @@ namespace GreenTree.Nachtragsmanagement.Web.Controllers
|
|
|
{
|
|
|
var generator = new MVCReportGeneratonHelper();
|
|
|
|
|
|
+ generator.CustomizeFormattingRules += new CustomizeFormattingRulesEventHandler(generator_CustomizeFormattingRules);
|
|
|
generator.CustomizeColumnsCollection += new CustomizeColumnsCollectionEventHandler(generator_CustomizeColumnsCollection);
|
|
|
generator.CustomizeGroupColumnSummary += new CustomizeColumnGroupSummaryEventHandler(generator_CustomizeGroupColumnSummary);
|
|
|
generator.CustomizeTotalColumnSummary += new CustomizeColumnTotalSummaryEventHandler(generator_CustomizeTotalColumnSummary);
|
|
|
+ generator.SummaryReset += new SummaryResetEventHandler(generator_SummaryReset);
|
|
|
+ generator.SummaryRowChanged += new SummaryRowChangedEventHandler(generator_SummaryRowChanged);
|
|
|
+ generator.PageSummaryGetResult += new SummaryGetResultHandler(generator_PageSummaryGetResult);
|
|
|
+ generator.TotalSummaryGetResult += new SummaryGetResultHandler(generator_TotalSummaryGetResult);
|
|
|
|
|
|
var report = generator.GenerateMVCReport(gridViewState, deviationModels, "Vertragsabweichungsliste");
|
|
|
|
|
|
if (displayMode == "popup")
|
|
|
+ {
|
|
|
return PartialView("~/Views/Shared/_PrintPopupPartial.cshtml",
|
|
|
- new PrintGridModel(report, "Deviation", "ExportPartialDeviations", "devGridViewDeviation"));
|
|
|
+ new PrintGridModel(report, "devGridViewDeviation",
|
|
|
+ new { Controller = "Deviation", Action = "ExportPartialDeviations",
|
|
|
+ customFilters = customFilters, displayMode = "callback", exportformat = String.Empty },
|
|
|
+ new { Controller = "Deviation", Action = "ExportPartialDeviations",
|
|
|
+ customFilters = customFilters, displayMode = "export", exportformat = String.Empty }));
|
|
|
+ }
|
|
|
else if (displayMode == "callback")
|
|
|
+ {
|
|
|
return PartialView("~/Views/Shared/_PrintDocumentViewerPartial.cshtml",
|
|
|
- new PrintGridModel(report, "Deviation", "ExportPartialDeviations", "devGridViewDeviation"));
|
|
|
+ new PrintGridModel(report, "devGridViewDeviation",
|
|
|
+ new { Controller = "Deviation", Action = "ExportPartialDeviations",
|
|
|
+ customFilters = customFilters, displayMode = "callback", exportformat = String.Empty },
|
|
|
+ new { Controller = "Deviation", Action = "ExportPartialDeviations",
|
|
|
+ customFilters = customFilters, displayMode = "export", exportformat = String.Empty }));
|
|
|
+ }
|
|
|
else if (displayMode == "export")
|
|
|
{
|
|
|
switch (exportformat.ToLower())
|
|
|
@@ -158,12 +188,15 @@ namespace GreenTree.Nachtragsmanagement.Web.Controllers
|
|
|
settings.TotalSummary["PercentageValue"].DisplayFormat = "{0:c2}";
|
|
|
settings.TotalSummary["DaysReceiptToAppendixOffering"].DisplayFormat = "Schnitt = {0:n0}";
|
|
|
settings.TotalSummary["SiteDescription"].DisplayFormat = "Anzahl = {0:n0}";
|
|
|
+ settings.TotalSummary["DisturbanceValuesDescription"].DisplayFormat = "{0:c2}";
|
|
|
return GridViewExtension.ExportToXlsx(settings, deviationModels);
|
|
|
case "xls":
|
|
|
settings.TotalSummary["Value"].DisplayFormat = "{0:c2}";
|
|
|
settings.TotalSummary["Percentage"].DisplayFormat = "{0:p0}";
|
|
|
+ settings.TotalSummary["PercentageValue"].DisplayFormat = "{0:c2}";
|
|
|
settings.TotalSummary["DaysReceiptToAppendixOffering"].DisplayFormat = "Schnitt = {0:n0}";
|
|
|
settings.TotalSummary["SiteDescription"].DisplayFormat = "Anzahl = {0:n0}";
|
|
|
+ settings.TotalSummary["DisturbanceValuesDescription"].DisplayFormat = "{0:c2}";
|
|
|
return GridViewExtension.ExportToXls(settings, deviationModels);
|
|
|
case "pdf":
|
|
|
report.Name = "VA-Liste";
|
|
|
@@ -177,6 +210,134 @@ namespace GreenTree.Nachtragsmanagement.Web.Controllers
|
|
|
return new EmptyResult();
|
|
|
}
|
|
|
|
|
|
+ private decimal totalCustomSummaryValueDaysReceiptToAppendixOffering = 0;
|
|
|
+ private decimal totalCustomSummaryValueDisturbanceValueSum = 0;
|
|
|
+
|
|
|
+ private decimal accumulatedCustomSummaryValueDaysReceiptToAppendixOffering = 0;
|
|
|
+ private decimal accumulatedCustomSummaryValueDisturbanceValueSum = 0;
|
|
|
+ private decimal accumulatedValue = 0;
|
|
|
+ private decimal accumulatedCount = 0;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Reset custom summaries for corresponding group type
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="e"></param>
|
|
|
+ private void generator_SummaryReset(object source, CustomSummaryResetEventArgs e)
|
|
|
+ {
|
|
|
+ totalCustomSummaryValueDaysReceiptToAppendixOffering = 0;
|
|
|
+ totalCustomSummaryValueDisturbanceValueSum = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Get custom summary values
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="e"></param>
|
|
|
+ private void generator_SummaryRowChanged(object source, CustomSummaryRowChangedEventArgs e)
|
|
|
+ {
|
|
|
+ if (e.FieldName == "DaysReceiptToAppendixOffering")
|
|
|
+ totalCustomSummaryValueDaysReceiptToAppendixOffering +=
|
|
|
+ Convert.ToDecimal(((XtraReport)source).GetCurrentColumnValue("DaysReceiptToAppendixOffering"));
|
|
|
+
|
|
|
+ if (e.FieldName == "DisturbanceValuesDescription")
|
|
|
+ {
|
|
|
+ totalCustomSummaryValueDisturbanceValueSum +=
|
|
|
+ Convert.ToDecimal(((XtraReport)source).GetCurrentColumnValue("DisturbanceValueSum"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Set custom summary result for page
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="e"></param>
|
|
|
+ private void generator_PageSummaryGetResult(object source, SummaryGetResultEventArgs e)
|
|
|
+ {
|
|
|
+ var label = (XRLabel)source;
|
|
|
+
|
|
|
+ if (label.Tag.ToString() == "DaysReceiptToAppendixOffering")
|
|
|
+ {
|
|
|
+ accumulatedCustomSummaryValueDaysReceiptToAppendixOffering += e.CalculatedValues.OfType<int>().Sum();
|
|
|
+ e.Result = accumulatedCustomSummaryValueDaysReceiptToAppendixOffering;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (label.Tag.ToString() == "DisturbanceValueSum")
|
|
|
+ {
|
|
|
+ accumulatedCustomSummaryValueDisturbanceValueSum += e.CalculatedValues.OfType<decimal>().Sum();
|
|
|
+ e.Result = accumulatedCustomSummaryValueDisturbanceValueSum;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (label.Tag.ToString() == "Value")
|
|
|
+ {
|
|
|
+ accumulatedValue += e.CalculatedValues.OfType<decimal>().Sum();
|
|
|
+ e.Result = accumulatedValue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (label.Tag.ToString() == "SiteDescription")
|
|
|
+ {
|
|
|
+ accumulatedCount += e.CalculatedValues.Count;
|
|
|
+ e.Result = accumulatedCount;
|
|
|
+ }
|
|
|
+
|
|
|
+ e.Handled = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Set custom summary result for full report
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="e"></param>
|
|
|
+ private void generator_TotalSummaryGetResult(object source, SummaryGetResultEventArgs e)
|
|
|
+ {
|
|
|
+ var label = (XRLabel)source;
|
|
|
+
|
|
|
+ if (label.Tag.ToString() == "DaysReceiptToAppendixOffering")
|
|
|
+ e.Result = totalCustomSummaryValueDaysReceiptToAppendixOffering;
|
|
|
+
|
|
|
+ if (label.Tag.ToString() == "DisturbanceValuesDescription")
|
|
|
+ e.Result = totalCustomSummaryValueDisturbanceValueSum;
|
|
|
+
|
|
|
+ e.Handled = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Customize formatting
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <param name="e"></param>
|
|
|
+ private void generator_CustomizeFormattingRules(object source, CustomFormattingRulesEventArgs e)
|
|
|
+ {
|
|
|
+ var colorLevel1 = _configurationService.TryGetConfigItemValue<string>(
|
|
|
+ "GreenTree.Nachtragsmanagement.DeviationNotificationPlugin.ProcessDeviationReceipt.HexColorLevel1", "#FFD800");
|
|
|
+ var ageDaysLevel1 = _configurationService.TryGetConfigItemValue<int>(
|
|
|
+ "GreenTree.Nachtragsmanagement.DeviationNotificationPlugin.ProcessDeviationReceipt.AgeDaysLevel1", 40);
|
|
|
+
|
|
|
+ var colorLevel2 = _configurationService.TryGetConfigItemValue<string>(
|
|
|
+ "GreenTree.Nachtragsmanagement.DeviationNotificationPlugin.ProcessDeviationReceipt.HexColorLevel2", "#FF6A00");
|
|
|
+ var ageDaysLevel2 = _configurationService.TryGetConfigItemValue<int>(
|
|
|
+ "GreenTree.Nachtragsmanagement.DeviationNotificationPlugin.ProcessDeviationReceipt.AgeDaysLevel2", 60);
|
|
|
+
|
|
|
+ var ageDaysLevel1Rule = new FormattingRule
|
|
|
+ {
|
|
|
+ Condition = String.Format("[DaysReceiptDateToday] >= {0}", ageDaysLevel1),
|
|
|
+ Name = "AgeDaysLevel1BackColor"
|
|
|
+ };
|
|
|
+
|
|
|
+ ageDaysLevel1Rule.Formatting.BackColor = ColorTranslator.FromHtml(colorLevel1);
|
|
|
+
|
|
|
+ var ageDaysLevel2Rule = new FormattingRule
|
|
|
+ {
|
|
|
+ Condition = String.Format("[DaysReceiptDateToday] >= {0}", ageDaysLevel2),
|
|
|
+ Name = "AgeDaysLevel2BackColor"
|
|
|
+ };
|
|
|
+
|
|
|
+ ageDaysLevel2Rule.Formatting.BackColor = ColorTranslator.FromHtml(colorLevel2);
|
|
|
+
|
|
|
+ e.Rules.Add(ageDaysLevel1Rule);
|
|
|
+ e.Rules.Add(ageDaysLevel2Rule);
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Customize created columns
|
|
|
/// </summary>
|
|
|
@@ -202,6 +363,7 @@ namespace GreenTree.Nachtragsmanagement.Web.Controllers
|
|
|
if (e.FieldName == "Percentage") { e.Summary.FormatString = "Bew. Ø = {0:p0}"; }
|
|
|
if (e.FieldName == "PercentageValue") { e.Summary.FormatString = "S. Bew. ∑ = {0:c2}"; }
|
|
|
if (e.FieldName == "DaysReceiptToAppendixOffering") { e.Summary.FormatString = "Tage VA-NT = {0:n0}"; }
|
|
|
+ if (e.FieldName == "DisturbanceValuesDescription") { e.Summary.FormatString = "Kat. ∑ = {0:c2}"; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -214,6 +376,7 @@ namespace GreenTree.Nachtragsmanagement.Web.Controllers
|
|
|
if (e.FieldName == "Percentage") { e.Summary.FormatString = "{0:p0}"; }
|
|
|
if (e.FieldName == "PercentageValue") { e.Summary.FormatString = "{0:c2}"; }
|
|
|
if (e.FieldName == "DaysReceiptToAppendixOffering") { e.Summary.FormatString = "{0:n0}"; }
|
|
|
+ if (e.FieldName == "DisturbanceValuesDescription") { e.Summary.FormatString = "{0:c2}"; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -223,7 +386,7 @@ namespace GreenTree.Nachtragsmanagement.Web.Controllers
|
|
|
public ActionResult EditDeviation(int id = -1)
|
|
|
{
|
|
|
var deviation = _deviationService.GetDeviationById(id);
|
|
|
- var deviationModel = DeviationDataModel.FromDeviation(deviation, true);
|
|
|
+ var deviationModel = DeviationDataModel.FromDeviation(deviation, true, _configurationService);
|
|
|
|
|
|
var defaultKind = _deviationService.GetDefaultKind();
|
|
|
var defaultStatus = _deviationService.GetDefaultStatus();
|
|
|
@@ -863,5 +1026,49 @@ namespace GreenTree.Nachtragsmanagement.Web.Controllers
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
+
|
|
|
+ #region Helper
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Uses a customFilter on a collection of deviation data models
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="customFilters">Custom filter string.</param>
|
|
|
+ /// <param name="models">Model list.</param>
|
|
|
+ private void UseCustomFilters(string customFilters, List<DeviationDataModel> models)
|
|
|
+ {
|
|
|
+ var filters = JsonConvert.DeserializeObject(customFilters) as JObject;
|
|
|
+
|
|
|
+ if (filters["DisturbanceValuesDescription"] != null && !String.IsNullOrEmpty(filters["DisturbanceValuesDescription"].Value<string>()))
|
|
|
+ {
|
|
|
+ var removables = new List<DeviationDataModel>();
|
|
|
+ var filterVal = filters["DisturbanceValuesDescription"].Value<string>();
|
|
|
+
|
|
|
+ foreach (var model in models)
|
|
|
+ {
|
|
|
+ var filterItemExists = model.DisturbanceValueEntities
|
|
|
+ .Any(d => d.Description.ToLower().Contains(filterVal.ToLower()));
|
|
|
+
|
|
|
+ if (!filterItemExists)
|
|
|
+ removables.Add(model);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var removeableValues = model.DisturbanceValueEntities
|
|
|
+ .Where(d => !d.Description.ToLower().Contains(filterVal.ToLower()))
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ foreach (var removeableValue in removeableValues)
|
|
|
+ model.DisturbanceValueEntities.Remove(removeableValue);
|
|
|
+
|
|
|
+ if (removeableValues.Count > 0)
|
|
|
+ model.DisturbanceValueEntities.Add(new DisturbanceValueDataModel { Description = "( ausgefilterte Kategorien )" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach (var removeable in removables)
|
|
|
+ models.Remove(removeable);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
}
|
|
|
}
|