1095 lines
46 KiB
C#
1095 lines
46 KiB
C#
using BeWo.Report;
|
|
using BeWo.Report.ReportObjects;
|
|
using BeWoPlanerMobil.Models;
|
|
using BeWoPlanerMobil.Service;
|
|
using BeWoPlanerMobil.Util;
|
|
using BeWoPlanerMobil.Util.ReportUtils;
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Extensions;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Specialized;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Web.Mvc;
|
|
|
|
namespace BeWoPlanerMobil.Controllers
|
|
{
|
|
public class ReportController : AbstractBaseController
|
|
{
|
|
private ReportModel _Model;
|
|
|
|
public ReportModel Model
|
|
{
|
|
get
|
|
{
|
|
if(!MobileSessionFacade.IsUserLoggedIn())
|
|
{
|
|
RedirectToActionPermanent("Index", "Login");
|
|
return null;
|
|
}
|
|
|
|
if(((ReportModel) Session[ModelSessionConstants.ReportModelKey])?.Employee == null)
|
|
{
|
|
_Model = new ReportModel {Employee = MobileSessionFacade.LoggedInEmployee};
|
|
Session[ModelSessionConstants.ReportModelKey] = _Model;
|
|
}
|
|
else
|
|
{
|
|
_Model = (ReportModel) Session[ModelSessionConstants.ReportModelKey];
|
|
}
|
|
|
|
return _Model;
|
|
}
|
|
}
|
|
|
|
// Veraltet, wird nicht mehr benutzt.
|
|
[Authorize]
|
|
public ActionResult Report()
|
|
{
|
|
if(!MobileSessionFacade.IsUserLoggedIn() || Request.Browser.Browser.Equals("InternetExplorer"))
|
|
{
|
|
return Logout();
|
|
}
|
|
|
|
if(!AbstractModel.IsAllowedToSeeBills)
|
|
{
|
|
return RedirectToActionPermanent("Main", "Main");
|
|
}
|
|
|
|
//CreateServiceOverview(null);
|
|
|
|
return View(Model);
|
|
}
|
|
|
|
|
|
// ToDo: Wenn es bereits Einstellungen gibt, den Quittierungsbeleg neuerstellen
|
|
[Authorize]
|
|
public ActionResult InitReports()
|
|
{
|
|
try
|
|
{
|
|
if (!MobileSessionFacade.IsUserLoggedIn() || Request.Browser.Browser.Equals("InternetExplorer"))
|
|
{
|
|
return Logout();
|
|
}
|
|
|
|
if (!AbstractModel.IsAllowedToSeeBills)
|
|
{
|
|
return RedirectToActionPermanent("Main", "Main");
|
|
}
|
|
|
|
var month = DateTime.Today.Month;
|
|
var year = DateTime.Today.Year;
|
|
var first = new DateTime(year, month, 1).AddMonths(-1);
|
|
var last = first.AddMonths(1).AddDays(-1);
|
|
|
|
Model.SelectedYear = Model.SelectedYear ?? first.Year;
|
|
Model.SelectedMonth = Model.SelectedMonth ?? first.Month;
|
|
Model.SelectedStartDay = Model.SelectedStartDay ?? first.Day;
|
|
Model.SelectedEndDay = Model.SelectedEndDay ?? last.Day;
|
|
|
|
var filterEnums = Enum.GetValues(typeof(QBFilterEnum)).Cast<QBFilterEnum>();
|
|
|
|
Model.QbFilters.Clear();
|
|
|
|
foreach (var filterEnum in filterEnums)
|
|
{
|
|
Model.QbFilters.AddIfNotIn(new QbFilterItem(filterEnum));
|
|
}
|
|
|
|
Model.Customers = EmployeeService.GetActiveCompactCustomersForEmployee(null).OrderBy(d => d.ToString()).ToList();
|
|
|
|
Model.Employees = EmployeeService.GetActiveCompactEmployeesForEmployee(MobileSessionFacade.LoggedInCompactEmployee.EmployeeOid);
|
|
|
|
Model.ServiceCategories = OperationsService.GetAllServiceCategories();
|
|
|
|
Model.Organisations = CustomerService.GetAllCostBearerCompact();
|
|
Model.Organisations.Sort((x, y) => x.Name.CompareTo(y.Name));
|
|
|
|
Model.AllTeams = EmployeeService.GetAllActiveCompactTeamsForEmployee(MobileSessionFacade.LoggedInEmployee.EmployeeOid);
|
|
|
|
CreateReport(null);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e.Message, e);
|
|
}
|
|
|
|
return View("Report", Model);
|
|
}
|
|
|
|
|
|
[Authorize]
|
|
[HttpPost]
|
|
public ActionResult CreateServiceOverview(FormCollection formCollection)
|
|
{
|
|
if(Model?.Employee?.EmployeeOid is null)
|
|
{
|
|
return Logout();
|
|
}
|
|
|
|
if(Model.SelectedFilterItem is null)
|
|
{
|
|
return RedirectToActionPermanent("Report");
|
|
}
|
|
|
|
CreateReport(formCollection);
|
|
|
|
return RedirectToActionPermanent("Report");
|
|
}
|
|
|
|
[Authorize]
|
|
private void CreateReport(NameValueCollection formCollection)
|
|
{
|
|
if(Model.SelectedFilterItem?.FilterEnum == QBFilterEnum.KlientenAuswahl)
|
|
{
|
|
var customerOidString = formCollection == null ? Model.SelectedCustomerOid.ToString() : formCollection[FormCollectionConstants.SelectedCustomerOidKey];
|
|
|
|
var isCustomerOidSuccessful = long.TryParse(customerOidString, out var selectedCustomerOid);
|
|
|
|
if(isCustomerOidSuccessful)
|
|
{
|
|
var selectedCustomer = Model.Customers.FirstOrDefault(customer => customer.CustomerOid == selectedCustomerOid);
|
|
|
|
Model.SelectedCustomer = selectedCustomer;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Model.SelectedCustomer = null;
|
|
}
|
|
|
|
if(Model.SelectedFilterItem?.FilterEnum == QBFilterEnum.TeamAuswahl)
|
|
{
|
|
var teamOidString = formCollection == null ? Model.SelectedTeamOid.ToString() : formCollection[FormCollectionConstants.SelectedTeamOidKey];
|
|
|
|
var isTeamOidSuccessful = long.TryParse(teamOidString, out var selectedTeamOid);
|
|
|
|
if(isTeamOidSuccessful)
|
|
{
|
|
var selectedTeam = Model.AllTeams.FirstOrDefault(team => team.TeamOid == selectedTeamOid);
|
|
|
|
Model.SelectedTeam = selectedTeam;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Model.SelectedTeam = null;
|
|
}
|
|
|
|
// Datumsangaben laden in separater Methode
|
|
var reportTimeFrame = GetReportTimeFrame();
|
|
|
|
var reportObjects = new List<ServicesOverviewRO>();
|
|
|
|
var organisationOid = Model.SelectedOrganisationOid ?? 0;
|
|
var employeeOid = Model.SelectedEmployeeOid ?? 0;
|
|
var serviceCategoryOid = Model.SelectedServiceCategoryOid;
|
|
var teamOid = Model.SelectedTeamOid;
|
|
var customerOid = Model.SelectedCustomerOid ?? 0;
|
|
|
|
switch(Model.SelectedFilterItem?.FilterEnum)
|
|
{
|
|
case QBFilterEnum.AlleKlienten:
|
|
reportObjects = ServicesOverviewRO.Create(reportTimeFrame.Month, reportTimeFrame.Year, organisationOid, employeeOid, reportTimeFrame.StartDay, reportTimeFrame.EndDay, serviceCategoryOid);
|
|
break;
|
|
case QBFilterEnum.NurKlientenMeinesTeams:
|
|
var teamRelatedCustomerOids = GetTeamCustomerOids();
|
|
reportObjects.AddRange(teamRelatedCustomerOids.Select(cOid => ServicesOverviewRO.Create(cOid, reportTimeFrame.Month, reportTimeFrame.Year, true, organisationOid, employeeOid, reportTimeFrame.StartDay, reportTimeFrame.EndDay, serviceCategoryOid)));
|
|
break;
|
|
case QBFilterEnum.MeineKlienten:
|
|
var myRelatedCustomerOids = DefaultReportCreator.GetMeineKlientenOids();
|
|
reportObjects.AddRange(myRelatedCustomerOids.Select(cOid => ServicesOverviewRO.Create(cOid, reportTimeFrame.Month, reportTimeFrame.Year, true, organisationOid, employeeOid, reportTimeFrame.StartDay, reportTimeFrame.EndDay, serviceCategoryOid)));
|
|
break;
|
|
case QBFilterEnum.KlientenAuswahl:
|
|
reportObjects = new List<ServicesOverviewRO> { ServicesOverviewRO.Create(customerOid, reportTimeFrame.Month, reportTimeFrame.Year, false, organisationOid, employeeOid, reportTimeFrame.StartDay, reportTimeFrame.EndDay, serviceCategoryOid) };
|
|
break;
|
|
case QBFilterEnum.TeamAuswahl:
|
|
var customerOids = GetTeamCustomerOids(teamOid);
|
|
reportObjects.AddRange(customerOids.Select(cOid => ServicesOverviewRO.Create(cOid, reportTimeFrame.Month, reportTimeFrame.Year, true, organisationOid, employeeOid, reportTimeFrame.StartDay, reportTimeFrame.EndDay, serviceCategoryOid)));
|
|
break;
|
|
default:
|
|
reportObjects = ServicesOverviewRO.Create(reportTimeFrame.Month, reportTimeFrame.Year, organisationOid, employeeOid, reportTimeFrame.StartDay, reportTimeFrame.EndDay, serviceCategoryOid, true, false);
|
|
break;
|
|
}
|
|
|
|
reportObjects = reportObjects.Where(x => x != null).ToList();
|
|
|
|
var srOids = new List<long>();
|
|
|
|
reportObjects.DoForEach(x => x.Services.DoForEach(s => srOids.AddIfNotIn(s.ServiceRecordOid)));
|
|
|
|
Model.ConfirmationReceiptSignatures = OperationsService.LoadAllConfirmationReceiptSignaturesByServiceRecordOids(srOids, out var serviceRecordOidsWithSignature);
|
|
|
|
var customerSignatures = Model.ConfirmationReceiptSignatures.Where(crs => crs.SignatureType == SignatureType.Customer).ToList();
|
|
var employeeSignatures = Model.ConfirmationReceiptSignatures.Where(crs => crs.SignatureType == SignatureType.Employee).ToList();
|
|
|
|
Model.ReportServiceRecordOids = new List<long>();
|
|
reportObjects.DoForEach(ro => ro.Services.DoForEach(s =>
|
|
{
|
|
Model.ReportServiceRecordOids.AddIfNotIn(s.ServiceRecordOid);
|
|
}));
|
|
|
|
var hasEmployeeSignature = srOids.All(
|
|
a => serviceRecordOidsWithSignature.ContainsKey(SignatureType.Employee) &&
|
|
serviceRecordOidsWithSignature[SignatureType.Employee].Contains(a));
|
|
|
|
var anyEmployeeSignatures = srOids.Any(a => serviceRecordOidsWithSignature.ContainsKey(SignatureType.Employee) &&
|
|
serviceRecordOidsWithSignature[SignatureType.Employee].Contains(a));
|
|
|
|
var employeeSignatureState = SignatureState.None;
|
|
|
|
if(anyEmployeeSignatures)
|
|
{
|
|
employeeSignatureState = SignatureState.Some;
|
|
}
|
|
|
|
if(hasEmployeeSignature)
|
|
{
|
|
employeeSignatureState = SignatureState.All;
|
|
}
|
|
|
|
Model.ConfirmationReceiptObject = null;
|
|
Model.ConfirmationReceiptObject = new ConfirmationReceiptObject(
|
|
BuildInformationString(),
|
|
new List<QuittierungsbelegResult>(),
|
|
BuildInformationString(true),
|
|
GetTimeSpanString(),
|
|
hasEmployeeSignature,
|
|
employeeSignatures.ToList(),
|
|
employeeSignatureState);
|
|
|
|
reportObjects.DoForEach(reportObject =>
|
|
{
|
|
var quittierungsbelegItems = new List<QuittierungsbelegItem>();
|
|
|
|
reportObject.Services.DoForEach(serviceDetail =>
|
|
{
|
|
quittierungsbelegItems.Add(new QuittierungsbelegItem(serviceDetail));
|
|
});
|
|
|
|
if(quittierungsbelegItems.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var oids = quittierungsbelegItems.Select(s => s.ServiceRecordOid).ToList();
|
|
|
|
var hasCustomerSignature = oids.All(a => serviceRecordOidsWithSignature.ContainsKey(SignatureType.Customer) &&
|
|
serviceRecordOidsWithSignature[SignatureType.Customer].Contains(a));
|
|
|
|
var employeeSignatureState2 = GetSignatureState(oids, serviceRecordOidsWithSignature, SignatureType.Employee);
|
|
|
|
var customerSignatureState = GetSignatureState(oids, serviceRecordOidsWithSignature, SignatureType.Customer);
|
|
|
|
var customerSignatureOid = hasCustomerSignature ? customerSignatures.FirstOrDefault(cs => cs.ServiceRecords.All(a => a.Customer.CustomerOid.Equals(reportObject.CustomerOid) && a.ServiceRecordOid.HasValue && serviceRecordOidsWithSignature[SignatureType.Customer].Contains(a.ServiceRecordOid.Value)))?.ConfirmationReceiptSignatureOid : null;
|
|
var sigs = customerSignatures.Where(cs => cs.ServiceRecords.All(a => a.Customer.CustomerOid.Equals(reportObject.CustomerOid) && a.ServiceRecordOid.HasValue && serviceRecordOidsWithSignature[SignatureType.Customer].Contains(a.ServiceRecordOid.Value))).ToList();
|
|
|
|
var customerSignatureOids = sigs.Where(signature => signature.ConfirmationReceiptSignatureOid.HasValue).Select(signature => signature.ConfirmationReceiptSignatureOid.Value).ToList();
|
|
|
|
var employeeSignatureOids = new List<long>();
|
|
|
|
if(serviceRecordOidsWithSignature.ContainsKey(SignatureType.Employee))
|
|
{
|
|
foreach(var signature in employeeSignatures.Where(s => s.ConfirmationReceiptSignatureOid.HasValue))
|
|
{
|
|
foreach(var serviceRecord in signature.ServiceRecords)
|
|
{
|
|
var oid = serviceRecord.ServiceRecordOid;
|
|
|
|
if(oid.HasValue && oids.Contains(oid.Value))
|
|
{
|
|
employeeSignatureOids.AddIfNotIn(signature.ConfirmationReceiptSignatureOid.Value);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
var customerSignatureServiceRecordOids = new List<long>();
|
|
var employeeSignatureServiceRecordOids = new List<long>();
|
|
if(serviceRecordOidsWithSignature.ContainsKey(SignatureType.Customer))
|
|
{
|
|
customerSignatureServiceRecordOids = serviceRecordOidsWithSignature[SignatureType.Customer];
|
|
}
|
|
|
|
if(serviceRecordOidsWithSignature.ContainsKey(SignatureType.Employee))
|
|
{
|
|
employeeSignatureServiceRecordOids = serviceRecordOidsWithSignature[SignatureType.Employee];
|
|
}
|
|
|
|
foreach(var quittierungsbelegItem in quittierungsbelegItems)
|
|
{
|
|
var serviceRecordOid = quittierungsbelegItem.ServiceRecordOid;
|
|
|
|
quittierungsbelegItem.HasCustomerSignature = customerSignatureServiceRecordOids.Contains(serviceRecordOid);
|
|
quittierungsbelegItem.HasEmployeeSignature = employeeSignatureServiceRecordOids.Contains(serviceRecordOid);
|
|
}
|
|
|
|
Model.ConfirmationReceiptObject.ConfirmationReceiptResultList.Add(
|
|
item: new QuittierungsbelegResult
|
|
(
|
|
$"{reportObject.CustomerLastName}, {reportObject.CustomerFirstName}",
|
|
quittierungsbelegItems,
|
|
reportObject.CustomerOid,
|
|
hasCustomerSignature,
|
|
customerSignatureOid,
|
|
customerSignatureState,
|
|
customerSignatureOids,
|
|
employeeSignatureState2,
|
|
employeeSignatureOids
|
|
)
|
|
);
|
|
});
|
|
|
|
if(Model.ConfirmationReceiptObject.ConfirmationReceiptResultList.All(qbItem => qbItem.Items.Count == 0))
|
|
{
|
|
TempData["HasWarningMessage"] = true;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ermittelt den Unterschriftenstatus, der besagt, ob für alle ausgewählten Zeiterfassungseinträge eine Unterschrift existiert.
|
|
/// </summary>
|
|
/// <param name="oids">Oids der ausgewählten Zeiterfassungseinträge</param>
|
|
/// <param name="serviceRecordOidsWithSignature">Oids der ausgewählten Zeiterfassungseinträge mit Unterschrift</param>
|
|
/// <param name="signatureType">Typ der Unterschrift; entweder von Mitarbeitern oder von Klienten</param>
|
|
/// <returns></returns>
|
|
private static SignatureState GetSignatureState(List<long> oids, Dictionary<SignatureType, List<long>> serviceRecordOidsWithSignature, SignatureType signatureType)
|
|
{
|
|
var hasSignatures = oids.All(a => serviceRecordOidsWithSignature.ContainsKey(signatureType) &&
|
|
serviceRecordOidsWithSignature[signatureType].Contains(a));
|
|
|
|
var hasSomeSignatures = oids.Any(a => serviceRecordOidsWithSignature.ContainsKey(signatureType) &&
|
|
serviceRecordOidsWithSignature[signatureType].Contains(a));
|
|
|
|
if(hasSignatures)
|
|
{
|
|
return SignatureState.All;
|
|
}
|
|
|
|
return hasSomeSignatures ? SignatureState.Some : SignatureState.None;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Erzeugt den String, der in der Filterauswahl angezeigt wird.
|
|
/// </summary>
|
|
/// <param name="isDativ">Ob es sich um ein Dativ-Objekt handelt</param>
|
|
/// <returns>Grammatikalisch korrekten Satz für die Filterauswahl</returns>
|
|
private string BuildInformationString(bool isDativ = false)
|
|
{
|
|
var stringBuilder = new StringBuilder(isDativ ? string.Empty : "Einträge für ");
|
|
|
|
// Einträge für [alle Klienten/die Klienten meines Teams/meine Klienten/[CustomerName]/[TeamName]] [von [Mitarbeiter] [bei [Kostenträger]] und [Leistungskategorie]] vom 01.10. bis 31.10.2020
|
|
// Einträge für Grube, Clair von Fisher, George bei LWL und face-to-face vom 01.10. bis 31.10.2020
|
|
// Unterschrift für x erbrachte Leistungen von
|
|
|
|
switch(Model.SelectedFilterItem?.FilterEnum)
|
|
{
|
|
case QBFilterEnum.KlientenAuswahl:
|
|
stringBuilder.Append(Model.SelectedCustomer);
|
|
break;
|
|
case QBFilterEnum.MeineKlienten:
|
|
stringBuilder.Append(isDativ ? "meinen" : "meine");
|
|
stringBuilder.Append(" Klienten");
|
|
break;
|
|
case QBFilterEnum.NurKlientenMeinesTeams:
|
|
stringBuilder.Append(isDativ ? "den" : "die");
|
|
stringBuilder.Append(" Klienten meines Teams");
|
|
break;
|
|
case QBFilterEnum.TeamAuswahl:
|
|
stringBuilder.Append(Model.SelectedTeam);
|
|
break;
|
|
default:
|
|
stringBuilder.Append(isDativ ? "allen" : "alle");
|
|
stringBuilder.Append(" Klienten");
|
|
break;
|
|
}
|
|
|
|
stringBuilder.Append(" ");
|
|
|
|
if(Model.SelectedEmployee != null)
|
|
{
|
|
stringBuilder.Append($"von {Model.SelectedEmployee} ");
|
|
}
|
|
|
|
if(Model.SelectedOrganisation != null)
|
|
{
|
|
stringBuilder.Append($"bei {Model.SelectedOrganisation} ");
|
|
}
|
|
|
|
if(Model.SelectedServiceCategory != null)
|
|
{
|
|
if(Model.SelectedEmployee != null || Model.SelectedOrganisation != null)
|
|
{
|
|
stringBuilder.Append("und ");
|
|
}
|
|
|
|
stringBuilder.Append(Model.SelectedServiceCategory.Name);
|
|
}
|
|
|
|
stringBuilder.Append(GetTimeSpanString());
|
|
|
|
return stringBuilder.ToString();
|
|
}
|
|
|
|
private string GetTimeSpanString()
|
|
{
|
|
var month = Model.SelectedMonth < 10 ? $"0{Model.SelectedMonth}" : Model.SelectedMonth.ToString();
|
|
var year = Model.SelectedYear;
|
|
var vom = Model.SelectedStartDay < 10 ? $"0{Model.SelectedStartDay}" : Model.SelectedStartDay.ToString();
|
|
var bis = Model.SelectedEndDay < 10 ? $"0{Model.SelectedEndDay}" : Model.SelectedEndDay.ToString();
|
|
|
|
return $"vom {vom}.{month}. bis {bis}.{month}.{year}";
|
|
}
|
|
|
|
private IEnumerable<long> GetTeamCustomerOids(long? teamOid = null)
|
|
{
|
|
var customerOids = new List<long>();
|
|
|
|
if(MobileSessionFacade.LoggedInEmployee?.EmployeeOid != null)
|
|
{
|
|
customerOids.AddRangeIfElementsNotIn(EmployeeService.GetTeamRelatedCustomerOids(MobileSessionFacade.LoggedInEmployee.EmployeeOid.Value, teamOid));
|
|
}
|
|
|
|
return customerOids;
|
|
}
|
|
|
|
[Authorize]
|
|
public string SetCustomer(long customerOid)
|
|
{
|
|
if(Model == null)
|
|
{
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
Model.SelectedCustomer = Model.Customers.FirstOrDefault(customer => customer.CustomerOid == customerOid);
|
|
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
[Authorize]
|
|
public string ChangeDateSelection(string startDayString, string endDayString, string monthString, string yearString)
|
|
{
|
|
if(Model is null)
|
|
{
|
|
Logout();
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
var isParsingSuccessful1 = int.TryParse(startDayString, out var startDay);
|
|
var isParsingSuccessful2 = int.TryParse(endDayString, out var endDay);
|
|
var isParsingSuccessful3 = int.TryParse(monthString, out var month);
|
|
var isParsingSuccessful4 = int.TryParse(yearString, out var year);
|
|
|
|
if(isParsingSuccessful1 && isParsingSuccessful2 && isParsingSuccessful3 && isParsingSuccessful4)
|
|
{
|
|
var start = new DateTime(year, month, startDay);
|
|
var end = new DateTime(year, month, endDay);
|
|
|
|
Model.SelectedEndDay = end.Day;
|
|
Model.SelectedStartDay = start.Day;
|
|
Model.SelectedMonth = month;
|
|
Model.SelectedYear = year;
|
|
}
|
|
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
[Authorize]
|
|
public string ChangeFilters(string organisationOidStr, string categoryOidStr)
|
|
{
|
|
if(Model is null)
|
|
{
|
|
Logout();
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
var isParsingSuccessful2 = long.TryParse(organisationOidStr, out var organisationOid);
|
|
var isParsingSuccessful3 = long.TryParse(categoryOidStr, out var categoryOid);
|
|
|
|
Model.SelectedOrganisation = isParsingSuccessful2 ? Model.Organisations.FirstOrDefault(organisation => organisation.OrganisationOid.Equals(organisationOid)) : null;
|
|
|
|
Model.SelectedServiceCategory = isParsingSuccessful3 ? OperationsService.LoadServiceCategory(categoryOid) : null;
|
|
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
[Authorize]
|
|
public string ChangeIsForSelectedEmployeesOnly(bool? isForSelectedEmployeeOnly, long? employeeOid)
|
|
{
|
|
if(Model is null)
|
|
{
|
|
Logout();
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
Model.IsForSelectedEmployeesOnly = isForSelectedEmployeeOnly ?? false;
|
|
Model.SelectedEmployee = employeeOid.HasValue ? Model.Employees.FirstOrDefault(employee => employee.EmployeeOid.Equals(employeeOid.Value)) : null;
|
|
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
[Authorize]
|
|
public string SetEmployeeOid(long? employeeOid)
|
|
{
|
|
if(Model is null)
|
|
{
|
|
Logout();
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
Model.SelectedEmployee = employeeOid.HasValue ? Model.Employees.FirstOrDefault(employee => employee.EmployeeOid.Equals(employeeOid)) : null;
|
|
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
[Authorize]
|
|
public string ChangeIsForSelectedOrganisationOnly(bool? isForSelectedOrganisationOnly, long? organisationOid)
|
|
{
|
|
if(Model is null)
|
|
{
|
|
Logout();
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
Model.IsForSelectedCostbearersOnly = isForSelectedOrganisationOnly ?? false;
|
|
Model.SelectedOrganisation = organisationOid.HasValue ? Model.Organisations.FirstOrDefault(organisation => organisation.OrganisationOid.Equals(organisationOid)) : null;
|
|
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
[Authorize]
|
|
public string SetOrganisationOid(long? organisationOid)
|
|
{
|
|
if(Model is null)
|
|
{
|
|
Logout();
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
Model.SelectedOrganisation = organisationOid.HasValue ? Model.Organisations.FirstOrDefault(organisation => organisation.OrganisationOid.Equals(organisationOid)) : null;
|
|
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
[Authorize]
|
|
public string ChangeIsForSelectedServiceCategoryOnly(bool? isForSelectedServiceCategoryOnly, long? serviceCategoryOid)
|
|
{
|
|
if(Model is null)
|
|
{
|
|
Logout();
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
Model.IsForSelectedCategoryOnly = isForSelectedServiceCategoryOnly ?? false;
|
|
if(serviceCategoryOid.HasValue)
|
|
{
|
|
Model.SelectedServiceCategory = Model.ServiceCategories.FirstOrDefault(serviceCategory => serviceCategory.ServiceCategoryOid == serviceCategoryOid);
|
|
}
|
|
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
[Authorize]
|
|
public string SetServiceCategoryOid(long? serviceCategoryOid)
|
|
{
|
|
if(Model is null)
|
|
{
|
|
Logout();
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
if(serviceCategoryOid.HasValue)
|
|
{
|
|
Model.SelectedServiceCategory = Model.ServiceCategories.FirstOrDefault(serviceCategory => serviceCategory.ServiceCategoryOid == serviceCategoryOid);
|
|
}
|
|
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Setzt den Quittierungsbelegsfilter; Alle Klienten, Nur Klienten meines Teams, Meine Klienten, Klient auswählen, oder Team auswählen
|
|
/// </summary>
|
|
/// <param name="filterEnumString">Der Enum, der dem ausgewählten Quittierungsbelegsfilter entspricht</param>
|
|
/// <returns>Das Leerzeichen für Get-Methoden. Ansonsten kann es zu Fehlern im JavaScript kommen.</returns>
|
|
[Authorize]
|
|
public string SetQbFilterEnum(string filterEnumString)
|
|
{
|
|
if(Model == null)
|
|
{
|
|
Logout();
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
var isParsingSuccessful = int.TryParse(filterEnumString, out var filterEnumValue);
|
|
|
|
if(isParsingSuccessful)
|
|
{
|
|
var selectedFilterEnum = (QBFilterEnum) filterEnumValue;
|
|
|
|
Model.SelectedFilterItem = new QbFilterItem(selectedFilterEnum);
|
|
|
|
if(selectedFilterEnum == QBFilterEnum.KlientenAuswahl && Model.SelectedCustomer is null)
|
|
{
|
|
var customer = Model.Customers.FirstOrDefault();
|
|
|
|
if(!(customer is null))
|
|
{
|
|
Model.SelectedCustomer = customer;
|
|
}
|
|
}
|
|
}
|
|
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
[Authorize]
|
|
[HttpPost]
|
|
public string CreateSignatureForServiceOverview(string base64SignatureString, string customerOidString, bool? isCustomerSignature, bool? overwrite)
|
|
{
|
|
if(Model == null)
|
|
{
|
|
Logout();
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
var shouldOverwrite = overwrite.HasValue && overwrite.Value;
|
|
|
|
var isCustomerSig = isCustomerSignature.HasValue && isCustomerSignature.Value;
|
|
|
|
var isSuccessful = long.TryParse(customerOidString, out var customerOid);
|
|
|
|
if(!isSuccessful || customerOid == 0)
|
|
{
|
|
return MobileUtils.SerializeObject("Es ist ein unbekannter Fehler aufgetreten. Bitte wenden Sie sich an den Administrator.");
|
|
}
|
|
|
|
var signatureType = isCustomerSig ? SignatureType.Customer : SignatureType.Employee;
|
|
|
|
var serviceRecordOids = new List<long>();
|
|
|
|
var resultList = Model.ConfirmationReceiptObject.ConfirmationReceiptResultList;
|
|
|
|
if(customerOid > 0L)
|
|
{
|
|
resultList = resultList.Where(item => item.CustomerOid == customerOid).ToList();
|
|
}
|
|
|
|
resultList.DoForEach(result => result.Items.DoForEach(item => serviceRecordOids.AddIfNotIn(item.ServiceRecordOid)));
|
|
|
|
var existingServiceRecordSignatures = OperationsService.LoadConfirmationReceiptSignaturesByServiceRecordOids(serviceRecordOids, signatureType, out var serviceRecordOidsWithSignature);
|
|
|
|
var serviceRecords = OperationsService.GetServiceRecordsByIds(serviceRecordOids);
|
|
|
|
using(var signatureBitmap = SignatureUtils.Base64StringToBitmap(base64SignatureString.Split(',')[1]))
|
|
{
|
|
var isValid = SignatureUtils.ValidateSignature(signatureBitmap);
|
|
|
|
if(!isValid)
|
|
{
|
|
return MobileUtils.SerializeObject("Das Unterschriftenfeld darf nicht leer sein.");
|
|
}
|
|
|
|
if(shouldOverwrite)
|
|
{
|
|
foreach(var csr in existingServiceRecordSignatures)
|
|
{
|
|
var temp = csr.ServiceRecords.Where(sr => sr.ServiceRecordOid.HasValue && !serviceRecordOidsWithSignature.Contains(sr.ServiceRecordOid.Value));
|
|
csr.ServiceRecords.Clear();
|
|
csr.ServiceRecords.AddRangeIfElementsNotIn(temp);
|
|
|
|
if(csr.ServiceRecords.Count == 0 && csr.ConfirmationReceiptSignatureOid.HasValue)
|
|
{
|
|
OperationsService.DeleteConfirmationReceiptSignature(csr.ConfirmationReceiptSignatureOid.Value);
|
|
}
|
|
else
|
|
{
|
|
OperationsService.UpdateConfirmationReceiptSignature(csr);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
serviceRecords = serviceRecords.Where(sr => sr.ServiceRecordOid.HasValue && !serviceRecordOidsWithSignature.Contains(sr.ServiceRecordOid.Value)).ToList();
|
|
}
|
|
|
|
var timeSpanString = GetTimeSpanString();
|
|
if(timeSpanString.Contains("vom"))
|
|
{
|
|
timeSpanString = timeSpanString.Substring(4);
|
|
}
|
|
|
|
var confirmationReceiptSignature = new ConfirmationReceiptSignatureDC
|
|
{
|
|
ServiceRecords = serviceRecords,
|
|
CustomerOid = isCustomerSig ? (long?) customerOid : null,
|
|
Employee = isCustomerSig ? null : MobileSessionFacade.LoggedInCompactEmployee,
|
|
SignatureImage = base64SignatureString,
|
|
SignatureType = signatureType,
|
|
TimeSpanString = timeSpanString
|
|
};
|
|
|
|
OperationsService.InsertConfirmationReceiptSignature(confirmationReceiptSignature);
|
|
}
|
|
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
[Authorize]
|
|
public string LoadConfirmationReceiptSignatures(string oidsAsString)
|
|
{
|
|
try
|
|
{
|
|
if(Model == null)
|
|
{
|
|
Logout();
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
if(!string.IsNullOrWhiteSpace(oidsAsString))
|
|
{
|
|
var oidStrings = oidsAsString.Split(',');
|
|
|
|
var oids = new List<long>();
|
|
|
|
foreach(var oidString in oidStrings)
|
|
{
|
|
if(long.TryParse(oidString, out var oid))
|
|
{
|
|
oids.AddIfNotIn(oid);
|
|
}
|
|
}
|
|
|
|
var signatures = Model.GetConfirmationReceitSignaturesByOids(oids).Where(signature => signature.SignatureImage != null).ToList();
|
|
|
|
var imageStrings = new List<string>();
|
|
|
|
foreach(var signature in signatures)
|
|
{
|
|
imageStrings.AddIfNotIn(MainController.ApplyWatermark(signature.SignatureImage, Server.MapPath("../Content/images/bewoplaner_by_ownsoft_logo_mok.png")));
|
|
}
|
|
|
|
return MobileUtils.SerializeObject(imageStrings);
|
|
}
|
|
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
catch(Exception exception)
|
|
{
|
|
return MobileUtils.SerializeObject("Ein Fehler ist aufgetreten. Bitte wenden Sie sich an Ihren Administrator.");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lädt die Übersicht über bereits geleistete oder fehlende Unterschriften für den ausgewählten Zeitraum
|
|
/// </summary>
|
|
/// <returns>Das QuittierungsbelegsResultPartial, das die Liste enthält</returns>
|
|
[Authorize]
|
|
public ActionResult LoadServiceOverview()
|
|
{
|
|
if(Model is null)
|
|
{
|
|
return Logout();
|
|
}
|
|
|
|
if(Model.SelectedFilterItem is null)
|
|
{
|
|
// ToDo: Warnung einbauen?
|
|
return RedirectToActionPermanent("Report");
|
|
}
|
|
|
|
if(Model.SelectedFilterItem.FilterEnum == QBFilterEnum.KlientenAuswahl)
|
|
{
|
|
var customerOidString = Model.SelectedCustomerOid.ToString();
|
|
|
|
var isCustomerOidSuccessful = long.TryParse(customerOidString, out var selectedCustomerOid);
|
|
|
|
if(isCustomerOidSuccessful)
|
|
{
|
|
var selectedCustomer = Model.Customers.FirstOrDefault(customer => customer.CustomerOid == selectedCustomerOid);
|
|
|
|
Model.SelectedCustomer = selectedCustomer;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Model.SelectedCustomer = null;
|
|
}
|
|
|
|
if(Model.SelectedFilterItem.FilterEnum == QBFilterEnum.TeamAuswahl)
|
|
{
|
|
var teamOidString = Model.SelectedTeamOid.ToString();
|
|
|
|
var isTeamOidSuccessful = long.TryParse(teamOidString, out var selectedTeamOid);
|
|
|
|
if(isTeamOidSuccessful)
|
|
{
|
|
var selectedTeam = Model.AllTeams.FirstOrDefault(team => team.TeamOid == selectedTeamOid);
|
|
|
|
Model.SelectedTeam = selectedTeam;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Model.SelectedTeam = null;
|
|
}
|
|
|
|
var reportTimeFrame = GetReportTimeFrame();
|
|
|
|
var reportObjects = new List<ServicesOverviewRO>();
|
|
|
|
var organisationOid = Model.SelectedOrganisationOid ?? 0;
|
|
var employeeOid = Model.SelectedEmployeeOid ?? 0;
|
|
var serviceCategoryOid = Model.SelectedServiceCategoryOid;
|
|
var teamOid = Model.SelectedTeamOid;
|
|
var customerOid = Model.SelectedCustomerOid ?? 0;
|
|
|
|
switch(Model.SelectedFilterItem.FilterEnum)
|
|
{
|
|
case QBFilterEnum.AlleKlienten:
|
|
reportObjects = ServicesOverviewRO.Create(reportTimeFrame.Month, reportTimeFrame.Year, organisationOid, employeeOid, reportTimeFrame.StartDay, reportTimeFrame.EndDay, serviceCategoryOid);
|
|
break;
|
|
case QBFilterEnum.NurKlientenMeinesTeams:
|
|
var teamRelatedCustomerOids = GetTeamCustomerOids();
|
|
reportObjects.AddRange(teamRelatedCustomerOids.Select(cOid => ServicesOverviewRO.Create(cOid, reportTimeFrame.Month, reportTimeFrame.Year, true, organisationOid, employeeOid, reportTimeFrame.StartDay, reportTimeFrame.EndDay, serviceCategoryOid)));
|
|
break;
|
|
case QBFilterEnum.MeineKlienten:
|
|
var myRelatedCustomerOids = DefaultReportCreator.GetMeineKlientenOids();
|
|
reportObjects.AddRange(myRelatedCustomerOids.Select(cOid => ServicesOverviewRO.Create(cOid, reportTimeFrame.Month, reportTimeFrame.Year, true, organisationOid, employeeOid, reportTimeFrame.StartDay, reportTimeFrame.EndDay, serviceCategoryOid)));
|
|
break;
|
|
case QBFilterEnum.KlientenAuswahl:
|
|
reportObjects = new List<ServicesOverviewRO> { ServicesOverviewRO.Create(customerOid, reportTimeFrame.Month, reportTimeFrame.Year, false, organisationOid, employeeOid, reportTimeFrame.StartDay, reportTimeFrame.EndDay, serviceCategoryOid) };
|
|
break;
|
|
case QBFilterEnum.TeamAuswahl:
|
|
var customerOids = GetTeamCustomerOids(teamOid);
|
|
reportObjects.AddRange(customerOids.Select(cOid => ServicesOverviewRO.Create(cOid, reportTimeFrame.Month, reportTimeFrame.Year, true, organisationOid, employeeOid, reportTimeFrame.StartDay, reportTimeFrame.EndDay, serviceCategoryOid)));
|
|
break;
|
|
default:
|
|
reportObjects = ServicesOverviewRO.Create(reportTimeFrame.Month, reportTimeFrame.Year, organisationOid, employeeOid, reportTimeFrame.StartDay, reportTimeFrame.EndDay, serviceCategoryOid, true, false);
|
|
break;
|
|
}
|
|
|
|
reportObjects = reportObjects.Where(x => x != null).ToList();
|
|
|
|
var srOids = new List<long>();
|
|
|
|
reportObjects.DoForEach(x => x.Services.DoForEach(s => srOids.AddIfNotIn(s.ServiceRecordOid)));
|
|
|
|
Model.ConfirmationReceiptSignatures = OperationsService.LoadAllConfirmationReceiptSignaturesByServiceRecordOids(srOids, out var serviceRecordOidsWithSignature);
|
|
|
|
var customerSignatures = Model.ConfirmationReceiptSignatures.Where(crs => crs.SignatureType == SignatureType.Customer).ToList();
|
|
var employeeSignatures = Model.ConfirmationReceiptSignatures.Where(crs => crs.SignatureType == SignatureType.Employee).ToList();
|
|
|
|
Model.ReportServiceRecordOids = new List<long>();
|
|
reportObjects.DoForEach(ro => ro.Services.DoForEach(s =>
|
|
{
|
|
Model.ReportServiceRecordOids.AddIfNotIn(s.ServiceRecordOid);
|
|
}));
|
|
|
|
var hasEmployeeSignature = srOids.All(
|
|
a => serviceRecordOidsWithSignature.ContainsKey(SignatureType.Employee) &&
|
|
serviceRecordOidsWithSignature[SignatureType.Employee].Contains(a));
|
|
|
|
var anyEmployeeSignatures = srOids.Any(a => serviceRecordOidsWithSignature.ContainsKey(SignatureType.Employee) &&
|
|
serviceRecordOidsWithSignature[SignatureType.Employee].Contains(a));
|
|
|
|
var employeeSignatureState = SignatureState.None;
|
|
|
|
if(anyEmployeeSignatures)
|
|
{
|
|
employeeSignatureState = SignatureState.Some;
|
|
}
|
|
|
|
if(hasEmployeeSignature)
|
|
{
|
|
employeeSignatureState = SignatureState.All;
|
|
}
|
|
|
|
Model.ConfirmationReceiptObject = null;
|
|
Model.ConfirmationReceiptObject = new ConfirmationReceiptObject(
|
|
BuildInformationString(),
|
|
new List<QuittierungsbelegResult>(),
|
|
BuildInformationString(true),
|
|
GetTimeSpanString(),
|
|
hasEmployeeSignature,
|
|
employeeSignatures.ToList(),
|
|
employeeSignatureState);
|
|
|
|
reportObjects.DoForEach(reportObject =>
|
|
{
|
|
var quittierungsbelegItems = new List<QuittierungsbelegItem>();
|
|
|
|
reportObject.Services.DoForEach(serviceDetail =>
|
|
{
|
|
quittierungsbelegItems.Add(new QuittierungsbelegItem(serviceDetail));
|
|
});
|
|
|
|
if(quittierungsbelegItems.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var oids = quittierungsbelegItems.Select(s => s.ServiceRecordOid).ToList();
|
|
|
|
var hasCustomerSignature = oids.All(a => serviceRecordOidsWithSignature.ContainsKey(SignatureType.Customer) &&
|
|
serviceRecordOidsWithSignature[SignatureType.Customer].Contains(a));
|
|
|
|
var employeeSignatureState2 = GetSignatureState(oids, serviceRecordOidsWithSignature, SignatureType.Employee);
|
|
|
|
var customerSignatureState = GetSignatureState(oids, serviceRecordOidsWithSignature, SignatureType.Customer);
|
|
|
|
var customerSignatureOid = hasCustomerSignature ? customerSignatures.FirstOrDefault(cs => cs.ServiceRecords.All(a => a.Customer.CustomerOid.Equals(reportObject.CustomerOid) && a.ServiceRecordOid.HasValue && serviceRecordOidsWithSignature[SignatureType.Customer].Contains(a.ServiceRecordOid.Value)))?.ConfirmationReceiptSignatureOid : null;
|
|
var sigs = customerSignatures.Where(cs => cs.ServiceRecords.All(a => a.Customer.CustomerOid.Equals(reportObject.CustomerOid) && a.ServiceRecordOid.HasValue && serviceRecordOidsWithSignature[SignatureType.Customer].Contains(a.ServiceRecordOid.Value))).ToList();
|
|
|
|
var customerSignatureOids = sigs.Where(signature => signature.ConfirmationReceiptSignatureOid.HasValue).Select(signature => signature.ConfirmationReceiptSignatureOid.Value).ToList();
|
|
|
|
var employeeSignatureOids = new List<long>();
|
|
|
|
if(serviceRecordOidsWithSignature.ContainsKey(SignatureType.Employee))
|
|
{
|
|
foreach(var signature in employeeSignatures.Where(s => s.ConfirmationReceiptSignatureOid.HasValue))
|
|
{
|
|
foreach(var serviceRecord in signature.ServiceRecords)
|
|
{
|
|
var oid = serviceRecord.ServiceRecordOid;
|
|
|
|
if(oid.HasValue && oids.Contains(oid.Value))
|
|
{
|
|
employeeSignatureOids.AddIfNotIn(signature.ConfirmationReceiptSignatureOid.Value);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
var customerSignatureServiceRecordOids = new List<long>();
|
|
var employeeSignatureServiceRecordOids = new List<long>();
|
|
if(serviceRecordOidsWithSignature.ContainsKey(SignatureType.Customer))
|
|
{
|
|
customerSignatureServiceRecordOids = serviceRecordOidsWithSignature[SignatureType.Customer];
|
|
}
|
|
|
|
if(serviceRecordOidsWithSignature.ContainsKey(SignatureType.Employee))
|
|
{
|
|
employeeSignatureServiceRecordOids = serviceRecordOidsWithSignature[SignatureType.Employee];
|
|
}
|
|
|
|
foreach(var quittierungsbelegItem in quittierungsbelegItems)
|
|
{
|
|
var serviceRecordOid = quittierungsbelegItem.ServiceRecordOid;
|
|
|
|
quittierungsbelegItem.HasCustomerSignature = customerSignatureServiceRecordOids.Contains(serviceRecordOid);
|
|
quittierungsbelegItem.HasEmployeeSignature = employeeSignatureServiceRecordOids.Contains(serviceRecordOid);
|
|
}
|
|
|
|
Model.ConfirmationReceiptObject.ConfirmationReceiptResultList.Add(
|
|
item: new QuittierungsbelegResult
|
|
(
|
|
$"{reportObject.CustomerLastName}, {reportObject.CustomerFirstName}",
|
|
quittierungsbelegItems,
|
|
reportObject.CustomerOid,
|
|
hasCustomerSignature,
|
|
customerSignatureOid,
|
|
customerSignatureState,
|
|
customerSignatureOids,
|
|
employeeSignatureState2,
|
|
employeeSignatureOids
|
|
)
|
|
);
|
|
});
|
|
|
|
if(Model.ConfirmationReceiptObject.ConfirmationReceiptResultList.All(qbItem => qbItem.Items.Count == 0))
|
|
{
|
|
TempData["HasWarningMessage"] = true;
|
|
}
|
|
|
|
return PartialView("QuittierungsbelegsResultPartial", Model);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Erstellt den Zeitraum für die Auswahl
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private ReportTimeFrame GetReportTimeFrame()
|
|
{
|
|
var month = DateTime.Today.Month;
|
|
var year = DateTime.Today.Year;
|
|
|
|
var first = new DateTime(year, month, 1).AddMonths(-1);
|
|
var last = first.AddMonths(1).AddDays(-1);
|
|
|
|
return new ReportTimeFrame(Model.SelectedYear ?? year, Model.SelectedMonth ?? month, Model.SelectedStartDay ?? first.Day, Model.SelectedEndDay ?? last.Day);
|
|
}
|
|
|
|
[Authorize]
|
|
[HttpPost]
|
|
public ActionResult DeleteCustomerSignature(FormCollection formCollection)
|
|
{
|
|
if(Model is null)
|
|
{
|
|
return Logout();
|
|
}
|
|
|
|
var info = formCollection["deleteCustomerSignaturesInfo"];
|
|
|
|
if(AbstractModel.HasRightToDeleteReceiptSignatures)
|
|
{
|
|
DeleteSignatures(info, true);
|
|
}
|
|
|
|
return RedirectToActionPermanent("InitReports", Model);
|
|
}
|
|
|
|
[Authorize]
|
|
[HttpPost]
|
|
public ActionResult DeleteEmployeeSignature(FormCollection formCollection)
|
|
{
|
|
if(Model?.ConfirmationReceiptObject is null)
|
|
{
|
|
return Logout();
|
|
}
|
|
|
|
var info = formCollection["deleteEmployeeSignatureInfo"];
|
|
|
|
if(AbstractModel.HasRightToDeleteReceiptSignatures)
|
|
{
|
|
DeleteSignatures(info, false);
|
|
}
|
|
|
|
return RedirectToActionPermanent("InitReports", Model);
|
|
}
|
|
|
|
[Authorize]
|
|
private void DeleteSignatures(string guid, bool isCustomerSignature)
|
|
{
|
|
if(Model is null || !AbstractModel.HasRightToDeleteReceiptSignatures)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if(!Guid.TryParse(guid, out var identifier))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var list = Model.ConfirmationReceiptObject.ConfirmationReceiptResultList;
|
|
|
|
var confirmationReceiptResult = list.FirstOrDefault(obj => obj.Identifier.Equals(identifier));
|
|
|
|
if(confirmationReceiptResult is null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var signatureOids = isCustomerSignature
|
|
? confirmationReceiptResult.CustomerSignatureOids
|
|
: confirmationReceiptResult.EmployeeSignatureOids;
|
|
|
|
var signatures = OperationsService.GetConfirmationReceiptSignatures(signatureOids);
|
|
|
|
OperationsService.DeleteConfirmationReceiptSignatures(signatures.ToDictionary(s => s.ConfirmationReceiptSignatureOid.Value, s => s.ConfirmationReceiptSignatureVersion.Value));
|
|
}
|
|
}
|
|
} |