2021-02-17 16:59:26 +01:00
using BeWo.Report ;
2020-09-21 11:57:10 +02:00
using BeWo.Report.ReportObjects ;
2020-09-14 19:07:23 +02:00
using BeWoPlanerMobil.Models ;
using BeWoPlanerMobil.Service ;
2020-09-21 11:57:10 +02:00
using BeWoPlanerMobil.Util ;
2020-11-09 17:55:01 +01:00
using BeWoPlanerMobil.Util.ReportUtils ;
using BS.Shared ;
2020-09-23 16:00:51 +02:00
using BS.Shared.Core ;
2020-09-30 19:23:42 +02:00
using BS.Shared.DataContracts ;
2020-09-21 11:57:10 +02:00
using BS.Shared.Extensions ;
2021-02-17 16:59:26 +01:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
using System.Web.Mvc ;
2023-11-13 11:33:08 +01:00
using BeWo.Service.Plugins ;
2025-06-11 22:56:25 +02:00
using DevExpress.XtraReports.UI ;
2025-03-25 17:36:15 +01:00
// Controller des Quittierungsbelegsmoduls
2020-09-14 19:07:23 +02:00
namespace BeWoPlanerMobil.Controllers
{
public class ReportController : AbstractBaseController
{
private ReportModel _Model ;
public ReportModel Model
{
get
{
if ( ! MobileSessionFacade . IsUserLoggedIn ( ) )
{
RedirectToActionPermanent ( "Index" , "Login" ) ;
return null ;
}
2025-06-11 22:56:25 +02:00
if ( _Model = = null )
2020-09-14 19:07:23 +02:00
{
2025-06-11 22:56:25 +02:00
_Model = new ReportModel { ReportCreator = GetReportCreator ( ) } ;
InitModel ( _Model ) ;
InitViewModel ( ) ;
2020-09-14 19:07:23 +02:00
}
2025-06-11 22:56:25 +02:00
//if (((ReportModel) Session[ModelSessionConstants.ReportModelKey])?.LoggedInEmployee is null)
//{
// _Model = new ReportModel {ReportCreator = GetReportCreator()};
// InitModel(_Model);
// Session[ModelSessionConstants.ReportModelKey] = _Model;
//}
//else
//{
// _Model = (ReportModel) Session[ModelSessionConstants.ReportModelKey];
//}
2020-09-14 19:07:23 +02:00
return _Model ;
}
}
2025-06-11 22:56:25 +02:00
private void InitViewModel ( )
{
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 ;
InitFilterCombo ( ) ;
Model . Customers . Clear ( ) ;
Model . Customers = CustomerService . GetAllActiveCustomersForEmployee ( ) ;
Model . Employees = EmployeeService . GetActiveCompactEmployeesForEmployee ( LoggedInEmployee . EmployeeOid . Value ) ;
Model . ServiceCategories = OperationsService . GetAllServiceCategories ( ) ;
Model . Organisations = CustomerService . GetAllCostBearerCompact ( ) ;
Model . Organisations . Sort ( ( x , y ) = > string . Compare ( x . Name , y . Name , StringComparison . CurrentCulture ) ) ;
Model . AllTeams = EmployeeService . GetAllActiveCompactTeamsForEmployee ( LoggedInEmployee . EmployeeOid . Value ) ;
Model . Dokutypes = ValueListService . GetAllValueListEntrysByType ( ValueListEntryType . DocumentType ) ;
if ( Model . Dokutypes ! = null )
{
Model . Dokutypes = Model . Dokutypes . OrderBy ( s = > s . ValueListEntryOid ) . ToArray ( ) ;
}
if ( Model . SelectedCustomerOid . HasValue )
{
Model . SelectedCustomer = Model . Customers . FirstOrDefault ( customer = > customer . CustomerOid = = Model . SelectedCustomerOid . Value ) ;
}
if ( Model . SelectedEmployeeOid . HasValue )
{
Model . SelectedEmployee = Model . Employees . FirstOrDefault ( employee = > employee . EmployeeOid . Equals ( Model . SelectedEmployeeOid . Value ) ) ;
}
if ( Model . SelectedTeamOid . HasValue )
{
Model . SelectedTeam = Model . AllTeams . FirstOrDefault ( team = > team . TeamOid = = Model . SelectedTeamOid . Value ) ;
}
if ( Model . SelectedOrganisationOid . HasValue )
{
Model . SelectedOrganisation = Model . Organisations . FirstOrDefault ( organisation = > organisation . OrganisationOid . Equals ( Model . SelectedOrganisationOid . Value ) ) ;
}
if ( Model . SelectedServiceCategoryOid . HasValue )
{
Model . SelectedServiceCategory = Model . ServiceCategories . FirstOrDefault ( serviceCategory = > serviceCategory . ServiceCategoryOid = = Model . SelectedServiceCategoryOid . Value ) ;
}
}
2023-11-27 19:03:39 +01:00
private static AbstractReportCreator GetReportCreator ( )
{
var creator = PluginLoader . FindClass < DefaultReportCreator > ( ) ;
#if DEBUG
creator . TempPath = BS . Shared . Core . Utils . CreateSavePath ( AppDomain . CurrentDomain . BaseDirectory , @"demo\temp" ) ;
#else
creator . TempPath = BS . Shared . Core . Utils . CreateSavePath ( AppDomain . CurrentDomain . BaseDirectory , PluginLoader . Tenant + @"\temp" ) ;
#endif
return creator ;
}
2023-01-26 12:55:56 +01:00
// Veraltet, wird nicht mehr benutzt.
2020-09-14 19:07:23 +02:00
[Authorize]
public ActionResult Report ( )
{
2023-02-09 15:17:33 +01:00
if ( ! MobileSessionFacade . IsUserLoggedIn ( ) | | Request . Browser . Browser . Equals ( "InternetExplorer" ) )
2020-09-14 19:07:23 +02:00
{
2020-10-07 19:42:17 +02:00
return Logout ( ) ;
2020-09-14 19:07:23 +02:00
}
2025-06-11 22:56:25 +02:00
if ( ! _Model . HasRightToViewQuittierungsbelege )
2020-10-20 21:07:26 +02:00
{
return RedirectToActionPermanent ( "Main" , "Main" ) ;
}
2020-09-30 19:23:42 +02:00
2021-01-14 16:30:28 +01:00
return View ( Model ) ;
}
2023-01-26 12:55:56 +01:00
2021-01-14 16:30:28 +01:00
[Authorize]
public ActionResult InitReports ( )
{
2023-01-17 00:12:33 +01:00
try
2021-01-14 16:30:28 +01:00
{
2025-06-11 22:56:25 +02:00
if ( ! MobileSessionFacade . IsUserLoggedIn ( ) | | Request . Browser . Browser . Equals ( "InternetExplorer" ) | | Model ? . LoggedInEmployee ? . EmployeeOid is null )
2023-01-17 00:12:33 +01:00
{
return Logout ( ) ;
}
2025-06-11 22:56:25 +02:00
if ( ! Model . HasRightToViewQuittierungsbelege )
2023-01-17 00:12:33 +01:00
{
return RedirectToActionPermanent ( "Main" , "Main" ) ;
}
2021-01-14 16:30:28 +01:00
2024-06-26 12:29:22 +02:00
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return Logout ( ) ;
}
2025-06-11 22:56:25 +02:00
2023-01-17 00:12:33 +01:00
}
2023-05-02 13:03:46 +02:00
catch ( Exception e )
2023-01-17 00:12:33 +01:00
{
Log . Error ( e . Message , e ) ;
}
2020-09-23 16:00:51 +02:00
2021-01-14 16:30:28 +01:00
return View ( "Report" , Model ) ;
2020-09-14 19:07:23 +02:00
}
2025-03-25 17:36:15 +01:00
private void InitFilterCombo ( )
{
Model . QbFilters . Clear ( ) ;
var filterList = new List < QbFilterItem > ( ) ;
2025-06-11 22:56:25 +02:00
var hasRightToViewCustomers = Model . CheckForAtLeastOneRight ( new [ ] { UserRightType . CustomerView_View , UserRightType . ViewAll } ) ;
2025-03-25 17:36:15 +01:00
2025-06-11 22:56:25 +02:00
var hasRightToViewMyTeams = Model . CheckForAtLeastOneRight ( new [ ] { UserRightType . Customer_ViewMyTeams , UserRightType . ViewAll } ) ;
2025-03-25 17:36:15 +01:00
if ( hasRightToViewCustomers )
{
filterList . Add ( new QbFilterItem ( QBFilterEnum . AlleKlienten ) ) ;
}
2023-01-26 12:55:56 +01:00
2025-03-25 17:36:15 +01:00
if ( hasRightToViewMyTeams )
{
filterList . Add ( new QbFilterItem ( QBFilterEnum . NurKlientenMeinesTeams ) ) ;
}
filterList . Add ( new QbFilterItem ( QBFilterEnum . MeineKlienten ) ) ;
filterList . Add ( new QbFilterItem ( QBFilterEnum . KlientenAuswahl ) ) ;
2025-06-11 22:56:25 +02:00
if ( Model . CheckRight ( UserRightType . TeamView_ViewMyTeams ) & & false = = Model . CheckRight ( UserRightType . TeamView_ViewAll ) )
2025-03-25 17:36:15 +01:00
{
if ( hasRightToViewMyTeams )
{
filterList . Add ( new QbFilterItem ( QBFilterEnum . TeamAuswahl ) ) ;
}
}
2025-06-11 22:56:25 +02:00
else if ( Model . CheckRight ( UserRightType . TeamView_ViewAll ) )
2025-03-25 17:36:15 +01:00
{
if ( hasRightToViewCustomers )
{
filterList . Add ( new QbFilterItem ( QBFilterEnum . TeamAuswahl ) ) ;
}
}
Model . QbFilters = filterList ;
}
2020-09-14 19:07:23 +02:00
2023-01-26 12:55:56 +01:00
/// <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>
2021-03-17 18:44:40 +01:00
private static SignatureState GetSignatureState ( List < long > oids , Dictionary < SignatureType , List < long > > serviceRecordOidsWithSignature , SignatureType signatureType )
{
2023-11-27 19:03:39 +01:00
var hasSignatures = oids . All ( signatureOid = > serviceRecordOidsWithSignature . ContainsValueAtKey ( signatureType , signatureOid ) ) ;
var hasSomeSignatures = oids . Any ( signatureOid = > serviceRecordOidsWithSignature . ContainsValueAtKey ( signatureType , signatureOid ) ) ;
2021-03-17 18:44:40 +01:00
if ( hasSignatures )
{
return SignatureState . All ;
}
return hasSomeSignatures ? SignatureState . Some : SignatureState . None ;
}
2023-01-26 12:55:56 +01:00
/// <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>
2021-02-17 16:59:26 +01:00
private string BuildInformationString ( bool isDativ = false )
2020-11-09 17:55:01 +01:00
{
2021-02-17 16:59:26 +01:00
var stringBuilder = new StringBuilder ( isDativ ? string . Empty : "Einträge für " ) ;
2020-11-09 17:55:01 +01:00
2021-02-17 16:59:26 +01:00
// 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
2020-11-09 17:55:01 +01:00
// Einträge für Grube, Clair von Fisher, George bei LWL und face-to-face vom 01.10. bis 31.10.2020
2021-02-17 16:59:26 +01:00
// Unterschrift für x erbrachte Leistungen von
2023-01-26 12:55:56 +01:00
switch ( Model . SelectedFilterItem ? . FilterEnum )
2020-11-09 17:55:01 +01:00
{
case QBFilterEnum . KlientenAuswahl :
stringBuilder . Append ( Model . SelectedCustomer ) ;
break ;
case QBFilterEnum . MeineKlienten :
2021-02-17 16:59:26 +01:00
stringBuilder . Append ( isDativ ? "meinen" : "meine" ) ;
stringBuilder . Append ( " Klienten" ) ;
2020-11-09 17:55:01 +01:00
break ;
case QBFilterEnum . NurKlientenMeinesTeams :
2021-02-17 16:59:26 +01:00
stringBuilder . Append ( isDativ ? "den" : "die" ) ;
stringBuilder . Append ( " Klienten meines Teams" ) ;
2020-11-09 17:55:01 +01:00
break ;
case QBFilterEnum . TeamAuswahl :
stringBuilder . Append ( Model . SelectedTeam ) ;
break ;
default :
2021-02-17 16:59:26 +01:00
stringBuilder . Append ( isDativ ? "allen" : "alle" ) ;
stringBuilder . Append ( " Klienten" ) ;
2020-11-09 17:55:01 +01:00
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 ) ;
}
2021-02-17 16:59:26 +01:00
stringBuilder . Append ( GetTimeSpanString ( ) ) ;
2020-11-09 17:55:01 +01:00
return stringBuilder . ToString ( ) ;
}
2021-02-17 16:59:26 +01:00
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}" ;
}
2024-11-12 18:37:23 +01:00
[Authorize]
public string CheckForSelectedOrganization ( )
{
return Model ? . SelectedOrganisation ! = null ? $"{Model.SelectedOrganisation.DetailDescription}_{Model.SelectedOrganisation.OrganisationOid}" : LeerzeichenFuerGetMethoden ;
}
[Authorize]
public string CheckForSelectedEmployee ( )
{
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return LeerzeichenFuerGetMethoden ;
}
2025-06-11 22:56:25 +02:00
if ( Model . SelectedEmployee is null & & ( Model . LoggedInEmployee ? . EmployeeOid . HasValue ? ? false ) )
2024-11-12 18:37:23 +01:00
{
2025-06-11 22:56:25 +02:00
return $"{Model.LoggedInEmployee.LastNameFirstName}_{Model.LoggedInEmployee.EmployeeOid.Value}" ;
2024-11-12 18:37:23 +01:00
}
return $"{Model.SelectedEmployee.DetailDescription}_{Model.SelectedEmployee.EmployeeOid}" ;
}
2020-09-14 19:07:23 +02:00
[Authorize]
public string SetCustomer ( long customerOid )
{
2024-09-12 14:55:35 +02:00
if ( Model is null )
2020-09-14 19:07:23 +02:00
{
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2020-09-14 19:07:23 +02:00
}
Model . SelectedCustomer = Model . Customers . FirstOrDefault ( customer = > customer . CustomerOid = = customerOid ) ;
2025-06-11 22:56:25 +02:00
Model . SelectedCustomerOid = customerOid ;
2020-09-14 19:07:23 +02:00
2024-11-12 18:37:23 +01:00
return Model . SelectedCustomer ? . DetailDescription ? ? LeerzeichenFuerGetMethoden ;
2024-09-12 14:55:35 +02:00
}
[Authorize]
public string SetTeam ( long teamOid )
{
if ( Model is null )
{
return LeerzeichenFuerGetMethoden ;
}
Model . SelectedTeam = Model . AllTeams . FirstOrDefault ( team = > team . TeamOid = = teamOid ) ;
2025-06-11 22:56:25 +02:00
Model . SelectedTeamOid = teamOid ;
2024-09-12 14:55:35 +02:00
return Model . SelectedTeam ? . DetailDescription ? ? string . Empty ;
2020-09-14 19:07:23 +02:00
}
2020-09-23 16:00:51 +02:00
[Authorize]
2021-02-17 16:59:26 +01:00
public string ChangeDateSelection ( string startDayString , string endDayString , string monthString , string yearString )
2020-09-23 16:00:51 +02:00
{
2023-01-18 13:43:11 +01:00
if ( Model is null )
2020-10-07 19:42:17 +02:00
{
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2020-10-07 19:42:17 +02:00
}
2020-09-23 16:00:51 +02:00
2021-02-17 16:59:26 +01:00
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 ) ;
2020-11-09 17:55:01 +01:00
2021-02-17 16:59:26 +01:00
if ( isParsingSuccessful1 & & isParsingSuccessful2 & & isParsingSuccessful3 & & isParsingSuccessful4 )
{
var start = new DateTime ( year , month , startDay ) ;
var end = new DateTime ( year , month , endDay ) ;
2020-10-07 19:42:17 +02:00
2021-02-17 16:59:26 +01:00
Model . SelectedEndDay = end . Day ;
Model . SelectedStartDay = start . Day ;
Model . SelectedMonth = month ;
Model . SelectedYear = year ;
}
2020-10-07 19:42:17 +02:00
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2021-02-17 16:59:26 +01:00
}
2020-11-09 17:55:01 +01:00
2025-03-25 17:36:15 +01:00
[Authorize]
public string ChangeIntervalSelection ( int selectedInterval , int month , int year )
{
Model . SelectedIntervalSelection = ( QbSignatureIntervalSelection ) selectedInterval ;
Model . SelectedMonth = month ;
Model . SelectedYear = year ;
var lastDayOfMonth = new DateTime ( year , month , 1 ) . GetLastOfMonth ( ) ;
switch ( Model . SelectedIntervalSelection )
{
case QbSignatureIntervalSelection . FirstHalf :
Model . SelectedStartDay = 1 ;
Model . SelectedEndDay = 15 ;
break ;
case QbSignatureIntervalSelection . SecondHalf :
Model . SelectedStartDay = 16 ;
Model . SelectedEndDay = lastDayOfMonth . Day ;
break ;
default :
Model . SelectedStartDay = 1 ;
Model . SelectedEndDay = lastDayOfMonth . Day ;
break ;
}
return LeerzeichenFuerGetMethoden ;
}
2021-02-17 16:59:26 +01:00
[Authorize]
2023-01-18 13:43:11 +01:00
public string ChangeFilters ( string organisationOidStr , string categoryOidStr )
2021-02-17 16:59:26 +01:00
{
2023-01-12 19:47:14 +01:00
if ( Model is null )
2020-10-07 19:42:17 +02:00
{
2021-02-17 16:59:26 +01:00
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2021-02-17 16:59:26 +01:00
}
2020-10-07 19:42:17 +02:00
2025-06-11 22:56:25 +02:00
Model . SelectedOrganisationOid = null ;
Model . SelectedServiceCategoryOid = null ;
2020-10-07 19:42:17 +02:00
2025-06-11 22:56:25 +02:00
if ( long . TryParse ( organisationOidStr , out var organisationOid ) )
{
Model . SelectedOrganisationOid = organisationOid ;
}
if ( long . TryParse ( categoryOidStr , out var categoryOid ) )
{
Model . SelectedServiceCategoryOid = categoryOid ;
}
2021-02-17 16:59:26 +01:00
2025-06-11 22:56:25 +02:00
//Model.SelectedOrganisation = isParsingSuccessful2 ? Model.Organisations.FirstOrDefault(organisation => organisation.OrganisationOid.Equals(organisationOid)) : null;
//Model.SelectedServiceCategory = isParsingSuccessful3 ? OperationsService.LoadServiceCategory(categoryOid) : null;
2020-10-07 19:42:17 +02:00
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2020-09-23 16:00:51 +02:00
}
2020-11-09 17:55:01 +01:00
2023-01-12 19:47:14 +01:00
[Authorize]
2023-01-18 13:43:11 +01:00
public string ChangeIsForSelectedEmployeesOnly ( bool? isForSelectedEmployeeOnly , long? employeeOid )
2023-01-12 19:47:14 +01:00
{
if ( Model is null )
{
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2023-01-12 19:47:14 +01:00
}
2023-01-18 13:43:11 +01:00
Model . IsForSelectedEmployeesOnly = isForSelectedEmployeeOnly ? ? false ;
Model . SelectedEmployee = employeeOid . HasValue ? Model . Employees . FirstOrDefault ( employee = > employee . EmployeeOid . Equals ( employeeOid . Value ) ) : null ;
2025-06-11 22:56:25 +02:00
Model . SelectedEmployeeOid = employeeOid ;
2023-01-18 13:43:11 +01:00
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2023-01-18 13:43:11 +01:00
}
[Authorize]
public string SetEmployeeOid ( long? employeeOid )
{
if ( Model is null )
{
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2023-01-18 13:43:11 +01:00
}
Model . SelectedEmployee = employeeOid . HasValue ? Model . Employees . FirstOrDefault ( employee = > employee . EmployeeOid . Equals ( employeeOid ) ) : null ;
2025-06-11 22:56:25 +02:00
Model . SelectedEmployeeOid = employeeOid ;
2023-01-18 13:43:11 +01:00
2024-11-12 18:37:23 +01:00
return Model . SelectedEmployee ? . DetailDescription ? ? LeerzeichenFuerGetMethoden ;
2023-01-18 13:43:11 +01:00
}
[Authorize]
public string ChangeIsForSelectedOrganisationOnly ( bool? isForSelectedOrganisationOnly , long? organisationOid )
{
if ( Model is null )
{
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2023-01-18 13:43:11 +01:00
}
Model . IsForSelectedCostbearersOnly = isForSelectedOrganisationOnly ? ? false ;
2025-03-25 17:36:15 +01:00
Model . SelectedOrganisation = organisationOid . HasValue & & Model . IsForSelectedCostbearersOnly ?
Model . Organisations . FirstOrDefault ( organisation = > organisation . OrganisationOid . Equals ( organisationOid ) ) :
null ;
2025-06-11 22:56:25 +02:00
Model . SelectedOrganisationOid = organisationOid ;
2023-01-18 13:43:11 +01:00
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2023-01-18 13:43:11 +01:00
}
[Authorize]
public string SetOrganisationOid ( long? organisationOid )
{
if ( Model is null )
{
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2023-01-18 13:43:11 +01:00
}
Model . SelectedOrganisation = organisationOid . HasValue ? Model . Organisations . FirstOrDefault ( organisation = > organisation . OrganisationOid . Equals ( organisationOid ) ) : null ;
2025-06-11 22:56:25 +02:00
Model . SelectedOrganisationOid = organisationOid ;
2023-01-18 13:43:11 +01:00
2024-11-12 18:37:23 +01:00
return Model . SelectedOrganisation ? . DetailDescription ? ? LeerzeichenFuerGetMethoden ;
2023-01-18 13:43:11 +01:00
}
[Authorize]
public string ChangeIsForSelectedServiceCategoryOnly ( bool? isForSelectedServiceCategoryOnly , long? serviceCategoryOid )
{
if ( Model is null )
{
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2023-01-18 13:43:11 +01:00
}
Model . IsForSelectedCategoryOnly = isForSelectedServiceCategoryOnly ? ? false ;
2024-09-12 14:55:35 +02:00
Model . SelectedServiceCategory = serviceCategoryOid . HasValue & & Model . IsForSelectedCategoryOnly ? Model . ServiceCategories . FirstOrDefault ( serviceCategory = > serviceCategory . ServiceCategoryOid = = serviceCategoryOid ) : null ;
2025-06-11 22:56:25 +02:00
Model . SelectedServiceCategoryOid = serviceCategoryOid ;
2023-01-18 13:43:11 +01:00
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2023-01-18 13:43:11 +01:00
}
[Authorize]
public string SetServiceCategoryOid ( long? serviceCategoryOid )
{
if ( Model is null )
{
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2023-01-18 13:43:11 +01:00
}
if ( serviceCategoryOid . HasValue )
{
Model . SelectedServiceCategory = Model . ServiceCategories . FirstOrDefault ( serviceCategory = > serviceCategory . ServiceCategoryOid = = serviceCategoryOid ) ;
}
2025-06-11 22:56:25 +02:00
Model . SelectedServiceCategoryOid = serviceCategoryOid ;
2023-01-12 19:47:14 +01:00
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2023-01-12 19:47:14 +01:00
}
2023-01-26 12:55:56 +01:00
/// <summary>
2025-03-25 17:36:15 +01:00
/// Setzt den Quittierungsbelegsfilter; alle Klienten, nur Klienten meines Teams, Meine Klienten, Klient auswählen, oder Team auswählen
2023-01-26 12:55:56 +01:00
/// </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>
2020-11-09 17:55:01 +01:00
[Authorize]
2021-02-17 16:59:26 +01:00
public string SetQbFilterEnum ( string filterEnumString )
2020-11-09 17:55:01 +01:00
{
2024-11-12 18:37:23 +01:00
if ( Model is null )
2020-11-09 17:55:01 +01:00
{
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2020-11-09 17:55:01 +01:00
}
2021-02-17 16:59:26 +01:00
var isParsingSuccessful = int . TryParse ( filterEnumString , out var filterEnumValue ) ;
2020-11-09 17:55:01 +01:00
2023-06-18 17:11:35 +02:00
if ( ! isParsingSuccessful )
2020-11-09 17:55:01 +01:00
{
2023-06-18 17:11:35 +02:00
return LeerzeichenFuerGetMethoden ;
}
2020-11-09 17:55:01 +01:00
2023-06-18 17:11:35 +02:00
var selectedFilterEnum = ( QBFilterEnum ) filterEnumValue ;
2023-01-26 12:55:56 +01:00
2025-06-11 22:56:25 +02:00
Model . SelectedFilterItemId = selectedFilterEnum ;
2023-01-26 12:55:56 +01:00
2024-11-12 18:37:23 +01:00
if ( selectedFilterEnum ! = QBFilterEnum . KlientenAuswahl | | Model . SelectedCustomer ! = null )
2023-06-18 17:11:35 +02:00
{
return LeerzeichenFuerGetMethoden ;
}
var customer = Model . Customers . FirstOrDefault ( ) ;
if ( ! ( customer is null ) )
{
2025-06-11 22:56:25 +02:00
Model . SelectedCustomerOid = customer . CustomerOid ;
2021-02-17 16:59:26 +01:00
}
2020-11-09 17:55:01 +01:00
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2020-11-09 17:55:01 +01:00
}
[Authorize]
2021-02-17 16:59:26 +01:00
[HttpPost]
public string CreateSignatureForServiceOverview ( string base64SignatureString , string customerOidString , bool? isCustomerSignature , bool? overwrite )
2020-11-09 17:55:01 +01:00
{
2023-06-18 17:11:35 +02:00
if ( Model is null )
2020-11-09 17:55:01 +01:00
{
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2020-11-09 17:55:01 +01:00
}
2021-02-17 16:59:26 +01:00
var shouldOverwrite = overwrite . HasValue & & overwrite . Value ;
2021-01-14 16:30:28 +01:00
2021-02-17 16:59:26 +01:00
var isCustomerSig = isCustomerSignature . HasValue & & isCustomerSignature . Value ;
2021-01-14 16:30:28 +01:00
2021-03-17 18:44:40 +01:00
var isSuccessful = long . TryParse ( customerOidString , out var customerOid ) ;
2021-02-17 16:59:26 +01:00
2021-03-17 18:44:40 +01:00
if ( ! isSuccessful | | customerOid = = 0 )
{
return MobileUtils . SerializeObject ( "Es ist ein unbekannter Fehler aufgetreten. Bitte wenden Sie sich an den Administrator." ) ;
2021-01-14 16:30:28 +01:00
}
2021-02-17 16:59:26 +01:00
var signatureType = isCustomerSig ? SignatureType . Customer : SignatureType . Employee ;
2021-01-14 16:30:28 +01:00
2021-02-17 16:59:26 +01:00
var serviceRecordOids = new List < long > ( ) ;
2021-01-14 16:30:28 +01:00
2021-02-17 16:59:26 +01:00
var resultList = Model . ConfirmationReceiptObject . ConfirmationReceiptResultList ;
2020-11-09 17:55:01 +01:00
2021-03-17 18:44:40 +01:00
if ( customerOid > 0L )
2021-02-17 16:59:26 +01:00
{
resultList = resultList . Where ( item = > item . CustomerOid = = customerOid ) . ToList ( ) ;
2020-11-09 17:55:01 +01:00
}
2021-02-17 16:59:26 +01:00
resultList . DoForEach ( result = > result . Items . DoForEach ( item = > serviceRecordOids . AddIfNotIn ( item . ServiceRecordOid ) ) ) ;
2020-11-09 17:55:01 +01:00
2021-02-17 16:59:26 +01:00
var existingServiceRecordSignatures = OperationsService . LoadConfirmationReceiptSignaturesByServiceRecordOids ( serviceRecordOids , signatureType , out var serviceRecordOidsWithSignature ) ;
2020-11-09 17:55:01 +01:00
2021-02-17 16:59:26 +01:00
var serviceRecords = OperationsService . GetServiceRecordsByIds ( serviceRecordOids ) ;
2020-11-09 17:55:01 +01:00
2021-02-17 16:59:26 +01:00
using ( var signatureBitmap = SignatureUtils . Base64StringToBitmap ( base64SignatureString . Split ( ',' ) [ 1 ] ) )
2020-11-09 17:55:01 +01:00
{
2021-02-17 16:59:26 +01:00
var isValid = SignatureUtils . ValidateSignature ( signatureBitmap ) ;
2020-11-09 17:55:01 +01:00
2021-02-17 16:59:26 +01:00
if ( ! isValid )
{
return MobileUtils . SerializeObject ( "Das Unterschriftenfeld darf nicht leer sein." ) ;
}
2020-11-09 17:55:01 +01:00
2021-02-17 16:59:26 +01:00
if ( shouldOverwrite )
{
foreach ( var csr in existingServiceRecordSignatures )
{
var temp = csr . ServiceRecords . Where ( sr = > sr . ServiceRecordOid . HasValue & & ! serviceRecordOidsWithSignature . Contains ( sr . ServiceRecordOid . Value ) ) ;
2023-11-27 19:03:39 +01:00
2025-06-11 22:56:25 +02:00
if ( ! Model . HasRightToProvideEmployeeSignatureForOthers )
2023-11-27 19:03:39 +01:00
{
2025-06-11 22:56:25 +02:00
temp = temp . Where ( sr = > sr . Employee . Equals ( LoggedInUser . Employee ) ) ;
2023-11-27 19:03:39 +01:00
}
2021-02-17 16:59:26 +01:00
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 ) ;
}
2023-11-27 19:03:39 +01:00
var filteredServiceRecords = new List < ServiceRecordDC > ( ) ;
2025-06-11 22:56:25 +02:00
if ( ! isCustomerSig & & ! Model . HasRightToProvideEmployeeSignatureForOthers )
2023-11-27 19:03:39 +01:00
{
2025-06-11 22:56:25 +02:00
filteredServiceRecords = serviceRecords . Where ( sr = > sr . Employee . Equals ( LoggedInUser . Employee ) ) . ToList ( ) ;
2023-11-27 19:03:39 +01:00
}
else
{
filteredServiceRecords = serviceRecords ;
}
2021-02-17 16:59:26 +01:00
var confirmationReceiptSignature = new ConfirmationReceiptSignatureDC
{
2023-11-27 19:03:39 +01:00
ServiceRecords = filteredServiceRecords ,
2021-02-17 16:59:26 +01:00
CustomerOid = isCustomerSig ? ( long? ) customerOid : null ,
2025-06-11 22:56:25 +02:00
Employee = isCustomerSig ? null : LoggedInUser . Employee ,
2021-02-17 16:59:26 +01:00
SignatureImage = base64SignatureString ,
SignatureType = signatureType ,
TimeSpanString = timeSpanString
} ;
OperationsService . InsertConfirmationReceiptSignature ( confirmationReceiptSignature ) ;
2020-11-09 17:55:01 +01:00
}
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2020-11-09 17:55:01 +01:00
}
[Authorize]
2021-03-17 18:44:40 +01:00
public string LoadConfirmationReceiptSignatures ( string oidsAsString )
2020-11-09 17:55:01 +01:00
{
2021-02-17 16:59:26 +01:00
try
2020-11-09 17:55:01 +01:00
{
2023-04-24 19:22:09 +02:00
if ( Model is null )
2021-02-17 16:59:26 +01:00
{
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2021-02-17 16:59:26 +01:00
}
2020-11-09 17:55:01 +01:00
2021-03-17 18:44:40 +01:00
if ( ! string . IsNullOrWhiteSpace ( oidsAsString ) )
2021-02-17 16:59:26 +01:00
{
2021-03-17 18:44:40 +01:00
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 ( ) ;
2023-04-24 19:22:09 +02:00
return MobileUtils . SerializeObject ( ConvertSignatureDCsToSignatureObjects ( signatures ) ) ;
2021-02-17 16:59:26 +01:00
}
2020-11-09 17:55:01 +01:00
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2020-11-09 17:55:01 +01:00
}
2021-02-17 16:59:26 +01:00
catch ( Exception exception )
2020-11-09 17:55:01 +01:00
{
2021-02-17 16:59:26 +01:00
return MobileUtils . SerializeObject ( "Ein Fehler ist aufgetreten. Bitte wenden Sie sich an Ihren Administrator." ) ;
2020-11-09 17:55:01 +01:00
}
}
2023-01-11 17:26:38 +01:00
2023-04-24 19:22:09 +02:00
private List < ConfirmationReceiptSignatureObject > ConvertSignatureDCsToSignatureObjects ( List < ConfirmationReceiptSignatureDC > dataContracts )
{
var result = new List < ConfirmationReceiptSignatureObject > ( ) ;
if ( dataContracts is null )
{
return result ;
}
2023-11-27 19:03:39 +01:00
foreach ( var signature in dataContracts . OrderBy ( o = > o . InsTs ) )
2023-04-24 19:22:09 +02:00
{
var img = MainController . ApplyWatermark ( signature . SignatureImage , Server . MapPath ( "../Content/images/bewoplaner_by_ownsoft_logo_mok.png" ) ) ;
2023-05-02 13:03:46 +02:00
var date = signature . InsTs ? . ToString ( "dd.MM.yyyy HH:mm:ss" ) ? ? "unbekannt" ;
2023-04-24 19:22:09 +02:00
var personName =
signature . SignatureType = = SignatureType . Customer ?
( Model . Customers . FirstOrDefault ( f = > f . CustomerOid . Equals ( signature . CustomerOid ) ) ? . LastNameFirstName ? ? "unbekannt" ) :
signature . Employee . SimpleDescription ;
2025-04-11 18:02:24 +02:00
result . AddIfNotIn ( new ConfirmationReceiptSignatureObject ( img , date , personName , signature . SignatureType = = SignatureType . Employee , signature . ServiceRecords ) ) ;
2023-04-24 19:22:09 +02:00
}
return result ;
}
2023-01-26 12:55:56 +01:00
/// <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>
2023-01-11 17:26:38 +01:00
[Authorize]
public ActionResult LoadServiceOverview ( )
{
if ( Model is null )
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return PartialView ( "QuittierungsbelegsResultPartial" ) ;
2023-01-11 17:26:38 +01:00
}
if ( Model . SelectedFilterItem is null )
{
// ToDo: Warnung einbauen?
return RedirectToActionPermanent ( "Report" ) ;
}
2024-11-12 18:37:23 +01:00
LoadPaginatedQbEntries ( 1 ) ;
2023-11-27 19:03:39 +01:00
return PartialView ( "QuittierungsbelegsResultPartial" , Model ) ;
}
2024-11-12 18:37:23 +01:00
/// <summary>
/// Erstellt den Zeitraum für die Auswahl
/// </summary>
/// <returns></returns>
private ReportTimeFrame GetReportTimeFrame ( )
2023-11-27 19:03:39 +01:00
{
2024-11-12 18:37:23 +01:00
var month = DateTime . Today . Month ;
var year = DateTime . Today . Year ;
2023-01-11 17:26:38 +01:00
2024-11-12 18:37:23 +01:00
var first = new DateTime ( year , month , 1 ) . AddMonths ( - 1 ) ;
var last = first . AddMonths ( 1 ) . AddDays ( - 1 ) ;
2023-01-11 17:26:38 +01:00
2024-11-12 18:37:23 +01:00
return new ReportTimeFrame ( Model . SelectedYear ? ? year , Model . SelectedMonth ? ? month , Model . SelectedStartDay ? ? first . Day , Model . SelectedEndDay ? ? last . Day ) ;
}
2023-01-11 17:26:38 +01:00
2024-11-12 18:37:23 +01:00
[Authorize]
[HttpPost]
public ActionResult DeleteCustomerSignature ( FormCollection formCollection )
{
if ( Model is null )
2023-01-11 17:26:38 +01:00
{
2024-11-12 18:37:23 +01:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return Logout ( ) ;
2023-01-11 17:26:38 +01:00
}
2024-11-12 18:37:23 +01:00
var info = formCollection [ "deleteCustomerSignaturesInfo" ] ;
2025-06-11 22:56:25 +02:00
if ( Model . HasRightToDeleteReceiptSignatures )
2023-01-11 17:26:38 +01:00
{
2024-11-12 18:37:23 +01:00
DeleteSignatures ( info , true ) ;
}
2023-01-11 17:26:38 +01:00
2024-11-12 18:37:23 +01:00
LoadPaginatedQbEntries ( Model . CurrentQbEntryPage ) ;
2023-01-11 17:26:38 +01:00
2025-06-11 22:56:25 +02:00
return RedirectToAction ( "InitReports" ) ;
2024-11-12 18:37:23 +01:00
}
2023-01-11 17:26:38 +01:00
2024-11-12 18:37:23 +01:00
[Authorize]
[HttpPost]
public ActionResult DeleteEmployeeSignature ( FormCollection formCollection )
{
if ( Model ? . ConfirmationReceiptObject is null )
2023-01-11 17:26:38 +01:00
{
2024-11-12 18:37:23 +01:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return Logout ( ) ;
2023-01-11 17:26:38 +01:00
}
2024-11-12 18:37:23 +01:00
var info = formCollection [ "deleteEmployeeSignatureInfo" ] ;
2023-01-11 17:26:38 +01:00
2025-06-11 22:56:25 +02:00
if ( Model . HasRightToDeleteReceiptSignatures )
2024-11-12 18:37:23 +01:00
{
DeleteSignatures ( info , false ) ;
}
2023-01-11 17:26:38 +01:00
2024-11-12 18:37:23 +01:00
LoadPaginatedQbEntries ( Model . CurrentQbEntryPage ) ;
2023-01-11 17:26:38 +01:00
2025-06-11 22:56:25 +02:00
return RedirectToAction ( "InitReports" ) ;
2024-11-12 18:37:23 +01:00
}
2023-11-13 11:33:08 +01:00
2024-11-12 18:37:23 +01:00
[Authorize]
private void DeleteSignatures ( string guid , bool isCustomerSignature )
{
2025-06-11 22:56:25 +02:00
if ( Model is null | | ! Model . HasRightToDeleteReceiptSignatures )
2023-01-11 17:26:38 +01:00
{
2024-11-12 18:37:23 +01:00
return ;
2023-01-11 17:26:38 +01:00
}
2024-11-12 18:37:23 +01:00
if ( ! Guid . TryParse ( guid , out var identifier ) )
{
return ;
}
2023-01-11 17:26:38 +01:00
2024-11-12 18:37:23 +01:00
var list = Model . ConfirmationReceiptObject . ConfirmationReceiptResultList ;
2023-01-11 17:26:38 +01:00
2024-11-12 18:37:23 +01:00
var confirmationReceiptResult = list . FirstOrDefault ( obj = > obj . Identifier . Equals ( identifier ) ) ;
2023-01-11 17:26:38 +01:00
2024-11-12 18:37:23 +01:00
if ( confirmationReceiptResult is null )
{
return ;
}
2023-01-11 17:26:38 +01:00
2024-11-12 18:37:23 +01:00
var signatureOids = isCustomerSignature
? confirmationReceiptResult . CustomerSignatureOids
: confirmationReceiptResult . EmployeeSignatureOids ;
2023-01-11 17:26:38 +01:00
2024-11-12 18:37:23 +01:00
var signatures = OperationsService . GetConfirmationReceiptSignatures ( signatureOids ) ;
2023-01-11 17:26:38 +01:00
2024-11-12 18:37:23 +01:00
OperationsService . DeleteConfirmationReceiptSignatures ( signatures . ToDictionary ( s = > s . ConfirmationReceiptSignatureOid . Value , s = > s . ConfirmationReceiptSignatureVersion . Value ) ) ;
}
2023-01-11 17:26:38 +01:00
2024-11-12 18:37:23 +01:00
[Authorize]
public ActionResult FetchConfirmationReceiptSignatures ( string identifier , bool isEmployee )
{
if ( Model is null )
2023-01-11 17:26:38 +01:00
{
2024-11-12 18:37:23 +01:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
PartialView ( "ConfirmationReceiptSignaturePartial" ) ;
2023-01-11 17:26:38 +01:00
}
2024-11-12 18:37:23 +01:00
if ( ! Guid . TryParse ( identifier , out var resultIdentifier ) )
2023-01-11 17:26:38 +01:00
{
2024-11-12 18:37:23 +01:00
return PartialView ( "ConfirmationReceiptSignaturePartial" , Model ) ;
2023-01-11 17:26:38 +01:00
}
2024-11-12 18:37:23 +01:00
var obj = Model . ConfirmationReceiptObject . ConfirmationReceiptResultList . FirstOrDefault ( f = > f . Identifier . Equals ( resultIdentifier ) ) ;
if ( obj is null )
2023-11-27 19:03:39 +01:00
{
2024-11-12 18:37:23 +01:00
return PartialView ( "ConfirmationReceiptSignaturePartial" , Model ) ;
}
var oids = isEmployee ? obj . EmployeeSignatureOids : obj . CustomerSignatureOids ;
2023-11-27 19:03:39 +01:00
2024-11-12 18:37:23 +01:00
var signatures = Model . GetConfirmationReceitSignaturesByOids ( oids ) ;
2023-11-27 19:03:39 +01:00
2024-11-12 18:37:23 +01:00
Model . SelectedConfirmationReceiptSignatures = ConvertSignatureDCsToSignatureObjects ( signatures ) ;
2023-11-27 19:03:39 +01:00
2024-11-12 18:37:23 +01:00
var customerName = obj . CustomerName ;
2025-06-11 22:56:25 +02:00
var employeeName = LoggedInUser . Employee . SimpleDescription ;
2024-11-12 18:37:23 +01:00
var serviceRecordCount = 0 ;
if ( isEmployee )
{
2025-06-11 22:56:25 +02:00
serviceRecordCount = Model . HasRightToProvideEmployeeSignatureForOthers ? obj . Items . Count : obj . Items . Count ( x = > x . EmployeeOid . Equals ( LoggedInEmployee . EmployeeOid ) ) ;
2024-11-12 18:37:23 +01:00
}
else
{
serviceRecordCount = obj . Items . Count ( ) ;
2023-11-27 19:03:39 +01:00
}
2024-11-12 18:37:23 +01:00
var personName = isEmployee ? employeeName : customerName ;
2023-01-11 17:26:38 +01:00
2024-11-12 18:37:23 +01:00
Model . Quittierungsbelegsunterschriftenobjekt = new Quittierungsbelegsunterschriftenobjekt ( isEmployee , personName , Model . ConfirmationReceiptObject . TimeSpanString , customerName , serviceRecordCount , obj . CustomerOid ) ;
2023-11-13 16:40:39 +01:00
2024-11-12 18:37:23 +01:00
return PartialView ( "ConfirmationReceiptSignaturePartial" , Model ) ;
}
2025-06-11 22:56:25 +02:00
//[Authorize]
//public ActionResult LoadReportToModel()
//{
// if(Model is null)
// {
// TempData[TempDataConstants.DoLogoutKey] = true;
// return PartialView("QuittierungsbelegsPreviewPartial");
// }
2023-01-11 17:26:38 +01:00
2025-06-11 22:56:25 +02:00
// var month = Model.SelectedMonth ?? DateTime.Now.AddMonths(-1).Month;
// var year = Model.SelectedYear ?? DateTime.Now.Year;
// var customerOid = Model.SelectedCustomerOid;
// var teamOid = Model.SelectedTeamOid;
// var employeeOid = Model.SelectedEmployeeOid;
// var organisationOid = Model.SelectedOrganisationOid;
// var serviceCategoryOid = Model.SelectedServiceCategoryOid;
// var startDate = Model.SelectedStartDay ?? 1;
2023-01-11 17:26:38 +01:00
2025-06-11 22:56:25 +02:00
// var date = new DateTime(year, month, startDate);
2023-01-11 17:26:38 +01:00
2025-06-11 22:56:25 +02:00
// var endDate = Model.SelectedEndDay ?? date.GetLastOfMonth().Day;
// var filterType = Model.SelectedFilterItem;
2023-01-11 17:26:38 +01:00
2025-06-11 22:56:25 +02:00
// Model.QuittierungsbelegsReportObject = Model.ReportCreator.CreateServiceOverviewReportNew(month, year, filterType.FilterEnum, customerOid, teamOid, employeeOid, organisationOid, serviceCategoryOid, startDate, endDate, false);
2023-01-11 17:26:38 +01:00
2025-06-11 22:56:25 +02:00
// return PartialView("QuittierungsbelegsPreviewPartial", Model);
//}
2023-01-11 17:26:38 +01:00
2024-11-12 18:37:23 +01:00
[Authorize]
public string ResetQuittierungsbeleg ( )
{
2025-06-11 22:56:25 +02:00
Model . QuittierungsbelegsReportSettings = null ;
Model . QuittierungsbelegsReport = null ;
2023-01-11 17:26:38 +01:00
2024-11-12 18:37:23 +01:00
return LeerzeichenFuerGetMethoden ;
}
2023-01-11 17:26:38 +01:00
2024-11-12 18:37:23 +01:00
[Authorize]
[HttpPost]
public ActionResult LoadQuittierungsbeleg ( )
{
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return Logout ( ) ;
}
2023-01-11 17:26:38 +01:00
2025-06-11 22:56:25 +02:00
var reportSettings = new QuittierungsbelegsReportSettings ( ) ;
2023-01-11 17:26:38 +01:00
2025-06-11 22:56:25 +02:00
reportSettings . Month = Model . SelectedMonth ? ? DateTime . Now . AddMonths ( - 1 ) . Month ;
reportSettings . Year = Model . SelectedYear ? ? DateTime . Now . Year ;
reportSettings . CustomerOid = Model . SelectedCustomerOid ;
reportSettings . TeamOid = Model . SelectedTeamOid ;
reportSettings . EmployeeOid = Model . SelectedEmployeeOid ;
reportSettings . OrganisationOid = Model . SelectedOrganisationOid ;
reportSettings . ServiceCategoryOid = Model . SelectedServiceCategoryOid ;
reportSettings . StartDay = Model . SelectedStartDay ? ? 1 ;
2023-01-11 17:26:38 +01:00
2025-06-11 22:56:25 +02:00
var date = new DateTime ( reportSettings . Year , reportSettings . Month , reportSettings . StartDay ) ;
2023-01-11 17:26:38 +01:00
2025-06-11 22:56:25 +02:00
reportSettings . EndDay = Model . SelectedEndDay ? ? date . GetLastOfMonth ( ) . Day ;
reportSettings . FilterEnum = Model . SelectedFilterItem . FilterEnum ;
Model . QuittierungsbelegsReportSettings = reportSettings ;
//var report = Model.ReportCreator.CreateServiceOverviewReportNew(month, year, filterType.FilterEnum, customerOid, teamOid, employeeOid, organisationOid, serviceCategoryOid, startDate, endDate, false);
//report.ExportOptions.PrintPreview.DefaultFileName = CreateFileName();
//report.DisplayName = CreateFileName();
return RedirectToAction ( "InitReports" ) ;
}
[Authorize]
public ActionResult CreateQuittierungsbelegsReport ( )
{
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return PartialView ( "QuittierungsbelegsPreviewPartial" ) ;
}
Model . QuittierungsbelegsReport = CreateQuittierungsbelegsReportFromSettings ( ) ;
return PartialView ( "QuittierungsbelegsPreviewPartial" , Model ) ;
}
private XtraReport CreateQuittierungsbelegsReportFromSettings ( )
{
if ( Model . QuittierungsbelegsReportSettings = = null )
{
return null ;
}
var s = Model . QuittierungsbelegsReportSettings ;
var report = Model . ReportCreator . CreateServiceOverviewReportNew ( s . Month , s . Year , s . FilterEnum , s . CustomerOid , s . TeamOid , s . EmployeeOid , s . OrganisationOid , s . ServiceCategoryOid , s . StartDay , s . EndDay , false ) ;
2023-01-11 17:26:38 +01:00
2024-11-12 18:37:23 +01:00
report . ExportOptions . PrintPreview . DefaultFileName = CreateFileName ( ) ;
report . DisplayName = CreateFileName ( ) ;
2023-01-11 17:26:38 +01:00
2025-06-11 22:56:25 +02:00
return report ;
2024-11-12 18:37:23 +01:00
}
2023-11-27 19:03:39 +01:00
2024-11-12 18:37:23 +01:00
private string CreateFileName ( )
{
var fileName = "Quittierungsbeleg_" ;
2023-11-27 19:03:39 +01:00
2024-11-12 18:37:23 +01:00
var selectedFilter = Model . SelectedFilterItem . FilterEnum ;
var filterText = string . Empty ;
switch ( selectedFilter )
{
case QBFilterEnum . AlleKlienten :
filterText = "AlleKlienten" ;
break ;
case QBFilterEnum . NurKlientenMeinesTeams :
filterText = "KlientenMeinerTeams" ;
break ;
case QBFilterEnum . MeineKlienten :
filterText = "MeineKlienten" ;
break ;
case QBFilterEnum . KlientenAuswahl :
filterText = "KlientenAuswahl" ;
break ;
case QBFilterEnum . TeamAuswahl :
filterText = "TeamAuswahl" ;
break ;
}
2023-11-27 19:03:39 +01:00
2024-11-12 18:37:23 +01:00
fileName + = $"{filterText}_" ;
2023-11-27 19:03:39 +01:00
2024-11-12 18:37:23 +01:00
if ( Model . IsForSelectedEmployeesOnly )
{
var selectedEmployee = Model . SelectedEmployee ;
var employeeName = $"{selectedEmployee.LastName}-{selectedEmployee.FirstName}_" ;
2023-01-11 17:26:38 +01:00
2024-11-12 18:37:23 +01:00
fileName + = $"{employeeName}_" ;
}
2023-11-13 16:40:39 +01:00
2024-11-12 18:37:23 +01:00
if ( Model . IsForSelectedCostbearersOnly )
2023-01-11 17:26:38 +01:00
{
2024-11-12 18:37:23 +01:00
var selectedCostbearer = Model . SelectedOrganisation ;
fileName + = $"{selectedCostbearer.Name}_" ;
2023-01-11 17:26:38 +01:00
}
2023-01-18 13:43:11 +01:00
2024-11-12 18:37:23 +01:00
if ( Model . IsForSelectedCategoryOnly )
{
var selectedServiceCategory = Model . SelectedServiceCategory ;
fileName + = $"{selectedServiceCategory.Name}_" ;
}
2023-01-18 13:43:11 +01:00
2024-11-12 18:37:23 +01:00
if ( ! Model . SelectedMonth . HasValue | | ! Model . SelectedYear . HasValue | | ! Model . SelectedStartDay . HasValue | | ! Model . SelectedEndDay . HasValue )
{
return fileName ;
}
2023-01-18 13:43:11 +01:00
2024-11-12 18:37:23 +01:00
var start = new DateTime ( Model . SelectedYear . Value , Model . SelectedMonth . Value , Model . SelectedStartDay . Value ) ;
var end = new DateTime ( Model . SelectedYear . Value , Model . SelectedMonth . Value , Model . SelectedEndDay . Value ) ;
fileName + = $"{start:MMMM}-{start:dd}-{end:dd}-{start:yyyy}" ;
return fileName ;
2023-01-18 13:43:11 +01:00
}
[Authorize]
2024-11-12 18:37:23 +01:00
public ActionResult GoToFirstServiceOverviewPage ( )
2023-01-18 13:43:11 +01:00
{
2024-11-12 18:37:23 +01:00
LoadPaginatedQbEntries ( 1 ) ;
2023-01-26 12:55:56 +01:00
2024-11-12 18:37:23 +01:00
return PartialView ( "QuittierungsbelegsResultPartial" , Model ) ;
}
2023-01-18 13:43:11 +01:00
2024-11-12 18:37:23 +01:00
[Authorize]
public ActionResult GoToLastServiceOverviewPage ( )
{
LoadPaginatedQbEntries ( Model . QbEntryPageCount ) ;
2023-11-27 19:03:39 +01:00
2024-11-12 18:37:23 +01:00
return PartialView ( "QuittierungsbelegsResultPartial" , Model ) ;
2023-01-18 13:43:11 +01:00
}
[Authorize]
2024-11-12 18:37:23 +01:00
public ActionResult LoadServiceOverviewPage ( int selectedPage )
2023-01-18 13:43:11 +01:00
{
2024-11-12 18:37:23 +01:00
LoadPaginatedQbEntries ( selectedPage ) ;
2023-01-18 13:43:11 +01:00
2024-11-12 18:37:23 +01:00
return PartialView ( "QuittierungsbelegsResultPartial" , Model ) ;
}
2023-01-26 12:55:56 +01:00
2024-11-12 18:37:23 +01:00
private void LoadPaginatedQbEntries ( int selectedPage )
{
if ( selectedPage < 1 )
2023-01-26 12:55:56 +01:00
{
2024-11-12 18:37:23 +01:00
selectedPage = 1 ;
2023-01-26 12:55:56 +01:00
}
2023-01-18 13:43:11 +01:00
2024-11-12 18:37:23 +01:00
if ( Model . SelectedFilterItem . FilterEnum = = QBFilterEnum . KlientenAuswahl )
{
var customerOidString = Model . SelectedCustomerOid . ToString ( ) ;
2023-11-27 19:03:39 +01:00
2024-11-12 18:37:23 +01:00
var isCustomerOidSuccessful = long . TryParse ( customerOidString , out var selectedCustomerOid ) ;
2023-01-26 12:55:56 +01:00
2024-11-12 18:37:23 +01:00
if ( isCustomerOidSuccessful )
{
var selectedCustomer = Model . Customers . FirstOrDefault ( customer = > customer . CustomerOid = = selectedCustomerOid ) ;
Model . SelectedCustomer = selectedCustomer ;
}
}
else
2023-01-26 12:55:56 +01:00
{
2024-11-12 18:37:23 +01:00
Model . SelectedCustomer = null ;
2025-06-11 22:56:25 +02:00
Model . SelectedCustomerOid = null ;
2023-01-26 12:55:56 +01:00
}
2024-11-12 18:37:23 +01:00
if ( Model . SelectedFilterItem . FilterEnum = = QBFilterEnum . TeamAuswahl )
2023-01-26 12:55:56 +01:00
{
2024-11-12 18:37:23 +01:00
var teamOidString = Model . SelectedTeamOid . ToString ( ) ;
2023-01-26 12:55:56 +01:00
2024-11-12 18:37:23 +01:00
var isTeamOidSuccessful = long . TryParse ( teamOidString , out var selectedTeamOid ) ;
2023-01-26 12:55:56 +01:00
2024-11-12 18:37:23 +01:00
if ( isTeamOidSuccessful )
{
var selectedTeam = Model . AllTeams . FirstOrDefault ( team = > team . TeamOid = = selectedTeamOid ) ;
2023-01-26 12:55:56 +01:00
2024-11-12 18:37:23 +01:00
Model . SelectedTeam = selectedTeam ;
}
}
else
2023-01-26 12:55:56 +01:00
{
2024-11-12 18:37:23 +01:00
Model . SelectedTeam = null ;
2025-06-11 22:56:25 +02:00
Model . SelectedTeamOid = null ;
2023-01-26 12:55:56 +01:00
}
2024-11-12 18:37:23 +01:00
var reportTimeFrame = GetReportTimeFrame ( ) ;
2023-01-26 12:55:56 +01:00
2024-11-12 18:37:23 +01:00
var reportObjects = new List < ServicesOverviewRO > ( ) ;
2023-01-26 12:55:56 +01:00
2024-11-12 18:37:23 +01:00
var organisationOid = Model . SelectedOrganisationOid ? ? 0 ;
var employeeOid = Model . SelectedEmployeeOid ? ? 0 ;
var serviceCategoryOid = Model . SelectedServiceCategoryOid ;
var teamOid = Model . SelectedTeamOid ;
var customerOid = Model . SelectedCustomerOid ? ? 0 ;
2023-04-24 19:22:09 +02:00
2024-11-12 18:37:23 +01:00
var creator = PluginLoader . FindClass < DefaultReportCreator > ( ) ? ? new DefaultReportCreator ( ) ;
2023-04-24 19:22:09 +02:00
2024-11-12 18:37:23 +01:00
Model . CurrentQbEntryPage = selectedPage ;
2023-04-24 19:22:09 +02:00
2024-11-12 18:37:23 +01:00
var firstResult = ( selectedPage - 1 ) * Model . MaxResults ;
var rowCount = 1 ;
switch ( Model . SelectedFilterItem . FilterEnum )
2023-04-24 19:22:09 +02:00
{
2024-11-12 18:37:23 +01:00
case QBFilterEnum . AlleKlienten :
reportObjects = ServicesOverviewRO . CreatePaginated ( firstResult , Model . MaxResults , reportTimeFrame . Month , reportTimeFrame . Year , organisationOid , employeeOid , reportTimeFrame . StartDay , reportTimeFrame . EndDay , out rowCount , serviceCategoryOid ) ;
break ;
case QBFilterEnum . NurKlientenMeinesTeams :
var teamRelatedCustomerOids = creator . GetKlientenOidsMeinesTeams ( null ) ;
var rOs = ServicesOverviewRO . CreatePaginated ( firstResult , Model . MaxResults , teamRelatedCustomerOids . ToArray ( ) , reportTimeFrame . Month , reportTimeFrame . Year , true , organisationOid , employeeOid , reportTimeFrame . StartDay , reportTimeFrame . EndDay , out rowCount , serviceCategoryOid ) ;
reportObjects . AddRange ( rOs ) ;
break ;
case QBFilterEnum . MeineKlienten :
var myRelatedCustomerOids = creator . GetMeineKlientenOids ( ) ;
var myCustomersReportObject = ServicesOverviewRO . CreatePaginated ( firstResult , Model . MaxResults , myRelatedCustomerOids . ToArray ( ) , reportTimeFrame . Month , reportTimeFrame . Year , true , organisationOid , employeeOid , reportTimeFrame . StartDay , reportTimeFrame . EndDay , out rowCount , serviceCategoryOid ) ;
reportObjects . AddRange ( myCustomersReportObject ) ;
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 = creator . GetKlientenOidsMeinesTeams ( teamOid ) ;
var teamCustomersReportObjects = ServicesOverviewRO . CreatePaginated ( firstResult , Model . MaxResults , customerOids . ToArray ( ) , reportTimeFrame . Month , reportTimeFrame . Year , true , organisationOid , employeeOid , reportTimeFrame . StartDay , reportTimeFrame . EndDay , out rowCount , serviceCategoryOid ) ;
reportObjects . AddRange ( teamCustomersReportObjects ) ;
break ;
default :
reportObjects = ServicesOverviewRO . CreatePaginated ( firstResult , Model . MaxResults , reportTimeFrame . Month , reportTimeFrame . Year , organisationOid , employeeOid , reportTimeFrame . StartDay , reportTimeFrame . EndDay , out rowCount , serviceCategoryOid ) ;
break ;
2023-04-24 19:22:09 +02:00
}
2024-11-12 18:37:23 +01:00
var pageCount = Math . DivRem ( rowCount , Model . MaxResults , out var remainder ) ;
2023-04-24 19:22:09 +02:00
2024-11-12 18:37:23 +01:00
if ( remainder > 0 )
2023-04-24 19:22:09 +02:00
{
2024-11-12 18:37:23 +01:00
pageCount + + ;
2023-04-24 19:22:09 +02:00
}
2024-11-12 18:37:23 +01:00
Model . QbEntryPageCount = pageCount ;
Model . QbEntryCount = rowCount ;
reportObjects = reportObjects . Where ( x = > x ! = null ) . ToList ( ) ;
2023-04-24 19:22:09 +02:00
2024-11-12 18:37:23 +01:00
var srOids = new List < long > ( ) ;
2023-04-24 19:22:09 +02:00
2024-11-12 18:37:23 +01:00
reportObjects . DoForEach ( x = > x . Services . DoForEach ( s = > srOids . AddIfNotIn ( s . ServiceRecordOid ) ) ) ;
2023-11-27 19:03:39 +01:00
2024-11-12 18:37:23 +01:00
Model . ConfirmationReceiptSignatures = OperationsService . LoadAllConfirmationReceiptSignaturesByServiceRecordOids ( srOids , out var serviceRecordOidsWithSignature ) ;
2023-12-13 16:13:07 +01:00
2024-11-12 18:37:23 +01:00
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 = >
2023-12-13 16:13:07 +01:00
{
2024-11-12 18:37:23 +01:00
Model . ReportServiceRecordOids . AddIfNotIn ( s . ServiceRecordOid ) ;
} ) ) ;
2023-12-13 16:13:07 +01:00
2024-11-12 18:37:23 +01:00
var hasEmployeeSignature = srOids . All ( a = > serviceRecordOidsWithSignature . ContainsValueAtKey ( SignatureType . Employee , a ) ) ;
2023-04-24 19:22:09 +02:00
2024-11-12 18:37:23 +01:00
var anyEmployeeSignatures = srOids . Any ( a = > serviceRecordOidsWithSignature . ContainsValueAtKey ( SignatureType . Employee , a ) ) ;
2023-04-24 19:22:09 +02:00
2024-11-12 18:37:23 +01:00
var employeeSignatureState = SignatureState . None ;
2023-11-27 19:03:39 +01:00
2024-11-12 18:37:23 +01:00
if ( anyEmployeeSignatures )
2024-06-26 12:29:22 +02:00
{
2024-11-12 18:37:23 +01:00
employeeSignatureState = SignatureState . Some ;
2024-06-26 12:29:22 +02:00
}
2024-11-12 18:37:23 +01:00
if ( hasEmployeeSignature )
{
employeeSignatureState = SignatureState . All ;
}
2023-11-27 19:03:39 +01:00
2025-06-11 22:56:25 +02:00
if ( ! Model . HasRightToProvideEmployeeSignatureForOthers )
2024-11-12 18:37:23 +01:00
{
// Prüfen, ob alle eigenen ServiceRecords unterschrieben sind
var ownServiceRecordOids = new List < long > ( ) ;
2025-06-11 22:56:25 +02:00
reportObjects . DoForEach ( reportObject = > ownServiceRecordOids . AddRangeIfElementsNotIn ( reportObject . Services . Where ( serviceDetail = > serviceDetail . EmployeeOid . Equals ( LoggedInEmployee . EmployeeOid ) ) . Select ( serviceDetail = > serviceDetail . ServiceRecordOid ) ) ) ;
2023-11-27 19:03:39 +01:00
2024-11-12 18:37:23 +01:00
// Prüfen, ob Einträge von anderen Mitarbeitern existieren
var serviceRecordOidsFromOtherEmployees = new List < long > ( ) ;
2025-06-11 22:56:25 +02:00
reportObjects . DoForEach ( reportObject = > serviceRecordOidsFromOtherEmployees . AddRangeIfElementsNotIn ( reportObject . Services . Where ( serviceDetail = > ! serviceDetail . EmployeeOid . Equals ( LoggedInEmployee . EmployeeOid ) ) . Select ( serviceDetail = > serviceDetail . ServiceRecordOid ) ) ) ;
2023-11-27 19:03:39 +01:00
2024-11-12 18:37:23 +01:00
var areAllForeignEntriesSigned = serviceRecordOidsFromOtherEmployees . All ( srOid = > serviceRecordOidsWithSignature . ContainsValueAtKey ( SignatureType . Employee , srOid ) ) ;
var areAllOwnEntriesSigned = ownServiceRecordOids . All ( srOid = > serviceRecordOidsWithSignature . ContainsValueAtKey ( SignatureType . Employee , srOid ) ) ;
2023-11-27 19:03:39 +01:00
2024-11-12 18:37:23 +01:00
employeeSignatureState = ! areAllForeignEntriesSigned & & areAllOwnEntriesSigned ? SignatureState . AllOwnServiceRecords : employeeSignatureState ;
}
2023-11-27 19:03:39 +01:00
2024-11-12 18:37:23 +01:00
Model . ConfirmationReceiptObject = null ;
Model . ConfirmationReceiptObject = new ConfirmationReceiptObject (
BuildInformationString ( ) ,
new List < QuittierungsbelegResult > ( ) ,
BuildInformationString ( true ) ,
GetTimeSpanString ( ) ,
hasEmployeeSignature ,
employeeSignatures . ToList ( ) ,
employeeSignatureState ) ;
2023-11-27 19:03:39 +01:00
2024-11-12 18:37:23 +01:00
var confirmationReceiptResults = new List < QuittierungsbelegResult > ( ) ;
2023-11-27 19:03:39 +01:00
2024-11-12 18:37:23 +01:00
reportObjects . DoForEach ( reportObject = >
2023-11-27 19:03:39 +01:00
{
2024-11-12 18:37:23 +01:00
var quittierungsbelegItems = new List < QuittierungsbelegItem > ( ) ;
2023-11-27 19:03:39 +01:00
2024-11-12 18:37:23 +01:00
reportObject . Services . DoForEach ( serviceDetail = >
{
quittierungsbelegItems . Add ( new QuittierungsbelegItem ( serviceDetail ) ) ;
} ) ;
2023-11-27 19:03:39 +01:00
2024-11-12 18:37:23 +01:00
if ( quittierungsbelegItems . Count = = 0 )
{
return ;
}
2023-11-27 19:03:39 +01:00
2024-11-12 18:37:23 +01:00
var oids = quittierungsbelegItems . Select ( s = > s . ServiceRecordOid ) . ToList ( ) ;
2023-11-27 19:03:39 +01:00
2024-11-12 18:37:23 +01:00
var hasCustomerSignature = oids . All ( a = > serviceRecordOidsWithSignature . ContainsValueAtKey ( SignatureType . Customer , a ) ) ;
2023-11-27 19:03:39 +01:00
2024-11-12 18:37:23 +01:00
var employeeSignatureState2 = GetSignatureState ( oids , serviceRecordOidsWithSignature , SignatureType . Employee ) ;
2023-11-27 19:03:39 +01:00
2024-11-12 18:37:23 +01:00
var customerSignatureState = GetSignatureState ( oids , serviceRecordOidsWithSignature , SignatureType . Customer ) ;
2023-11-27 19:03:39 +01:00
2024-11-12 18:37:23 +01:00
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 ( ) ;
2023-12-06 18:14:34 +01:00
2024-11-12 18:37:23 +01:00
var customerSignatureOids = sigs . Where ( signature = > signature . ConfirmationReceiptSignatureOid . HasValue ) . Select ( signature = > signature . ConfirmationReceiptSignatureOid . Value ) . ToList ( ) ;
2023-12-06 18:14:34 +01:00
2024-11-12 18:37:23 +01:00
var employeeSignatureOids = new List < long > ( ) ;
2023-12-06 18:14:34 +01:00
2024-11-12 18:37:23 +01:00
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 ;
2023-12-06 18:14:34 +01:00
2024-11-12 18:37:23 +01:00
if ( oid . HasValue & & oids . Contains ( oid . Value ) )
{
employeeSignatureOids . AddIfNotIn ( signature . ConfirmationReceiptSignatureOid . Value ) ;
}
}
}
}
2023-12-06 18:14:34 +01:00
2024-11-12 18:37:23 +01:00
var customerSignatureServiceRecordOids = new List < long > ( ) ;
var employeeSignatureServiceRecordOids = new List < long > ( ) ;
if ( serviceRecordOidsWithSignature . ContainsKey ( SignatureType . Customer ) )
{
customerSignatureServiceRecordOids = serviceRecordOidsWithSignature [ SignatureType . Customer ] ;
}
2023-12-06 18:14:34 +01:00
2024-11-12 18:37:23 +01:00
if ( serviceRecordOidsWithSignature . ContainsKey ( SignatureType . Employee ) )
{
employeeSignatureServiceRecordOids = serviceRecordOidsWithSignature [ SignatureType . Employee ] ;
}
2023-12-06 18:14:34 +01:00
2024-11-12 18:37:23 +01:00
foreach ( var quittierungsbelegItem in quittierungsbelegItems )
{
var serviceRecordOid = quittierungsbelegItem . ServiceRecordOid ;
2023-12-06 18:14:34 +01:00
2024-11-12 18:37:23 +01:00
quittierungsbelegItem . HasCustomerSignature = customerSignatureServiceRecordOids . Contains ( serviceRecordOid ) ;
quittierungsbelegItem . HasEmployeeSignature = employeeSignatureServiceRecordOids . Contains ( serviceRecordOid ) ;
}
2023-12-06 18:14:34 +01:00
2024-11-12 18:37:23 +01:00
var employeeOids = new List < long > ( ) ;
foreach ( var serviceDetail in reportObject . Services )
{
employeeOids . AddIfNotIn ( serviceDetail . EmployeeOid ) ;
}
2023-12-06 18:14:34 +01:00
2025-06-11 22:56:25 +02:00
if ( ! Model . HasRightToProvideEmployeeSignatureForOthers )
2024-11-12 18:37:23 +01:00
{
2025-06-11 22:56:25 +02:00
var serviceRecordOidsFromOtherEmployees = reportObject . Services . Where ( serviceDetail = > ! serviceDetail . EmployeeOid . Equals ( LoggedInEmployee . EmployeeOid ) ) . Select ( serviceDetail = > serviceDetail . ServiceRecordOid ) . ToList ( ) ;
var ownServiceRecordOids = reportObject . Services . Where ( serviceDetail = > serviceDetail . EmployeeOid . Equals ( LoggedInEmployee . EmployeeOid ) ) . Select ( serviceDetail = > serviceDetail . ServiceRecordOid ) . ToList ( ) ;
2023-12-06 18:14:34 +01:00
2024-11-12 18:37:23 +01:00
var areAllForeignEntriesSigned = serviceRecordOidsFromOtherEmployees . All ( srOid = > serviceRecordOidsWithSignature . ContainsValueAtKey ( SignatureType . Employee , srOid ) ) ;
var areAllOwnEntriesSigned = ownServiceRecordOids . All ( srOid = > serviceRecordOidsWithSignature . ContainsValueAtKey ( SignatureType . Employee , srOid ) ) ;
employeeSignatureState2 = ! areAllForeignEntriesSigned & & areAllOwnEntriesSigned ? SignatureState . AllOwnServiceRecords : employeeSignatureState2 ;
}
confirmationReceiptResults . Add (
item : new QuittierungsbelegResult
(
$"{reportObject.CustomerLastName}, {reportObject.CustomerFirstName}" ,
quittierungsbelegItems ,
reportObject . CustomerOid ,
hasCustomerSignature ,
customerSignatureOid ,
customerSignatureState ,
customerSignatureOids ,
employeeSignatureState2 ,
employeeSignatureOids ,
employeeOids . Count
)
) ;
} ) ;
Model . ConfirmationReceiptObject . ConfirmationReceiptResultList . AddRangeIfElementsNotIn ( confirmationReceiptResults . OrderBy ( o = > o . CustomerName ) ) ;
2025-05-16 19:24:16 +02:00
if ( Model . ConfirmationReceiptObject . ConfirmationReceiptResultList . Any ( ) )
{
Model . GoalRatingTypes = OperationsService . GetAllRatingTypes ( ) . OrderBy ( o = > o . Position ) . ToList ( ) ;
}
2024-11-12 18:37:23 +01:00
if ( Model . ConfirmationReceiptObject . ConfirmationReceiptResultList . All ( qbItem = > qbItem . Items . Count = = 0 ) )
{
TempData [ TempDataConstants . HasWarningMessageKey ] = true ;
}
2023-12-06 18:14:34 +01:00
}
2025-03-25 17:36:15 +01:00
[Authorize]
public override string SaveCollapsibleStatus ( bool isOpen , string identifier )
{
Model . Collapsibles2IsShown [ identifier ] = isOpen ;
return LeerzeichenFuerGetMethoden ;
}
2023-04-24 19:22:09 +02:00
}
public class ConfirmationReceiptSignatureObject
{
2025-05-16 19:24:16 +02:00
public Guid Identifier { get ; }
2023-04-24 19:22:09 +02:00
public string ImageStr { get ; }
public string InsTsStr { get ; }
public string PersonName { get ; }
public bool IsEmployeeSignature { get ; }
public int NumberOfServiceRecords { get ; }
2025-04-11 18:02:24 +02:00
public List < ServiceRecordDC > ServiceRecords { get ; }
2023-04-24 19:22:09 +02:00
2025-04-11 18:02:24 +02:00
public ConfirmationReceiptSignatureObject ( string imageStr , string insTsStr , string personName , bool isEmployeeSignature , List < ServiceRecordDC > serviceRecords )
2023-04-24 19:22:09 +02:00
{
2025-05-16 19:24:16 +02:00
Identifier = Guid . NewGuid ( ) ;
2023-04-24 19:22:09 +02:00
ImageStr = imageStr ;
InsTsStr = insTsStr ;
PersonName = personName ;
IsEmployeeSignature = isEmployeeSignature ;
2025-04-11 18:02:24 +02:00
NumberOfServiceRecords = serviceRecords . Count ;
ServiceRecords = serviceRecords ;
2023-04-24 19:22:09 +02:00
}
2020-09-14 19:07:23 +02:00
}
}