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 ;
2023-01-26 12:55:56 +01:00
using System.Collections.Specialized ;
2021-02-17 16:59:26 +01:00
using System.Linq ;
using System.Text ;
using System.Web.Mvc ;
2023-11-13 11:33:08 +01:00
using BeWo.Service.Plugins ;
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 ;
}
2020-09-21 11:57:10 +02:00
if ( ( ( ReportModel ) Session [ ModelSessionConstants . ReportModelKey ] ) ? . Employee = = null )
2020-09-14 19:07:23 +02:00
{
_Model = new ReportModel { Employee = MobileSessionFacade . LoggedInEmployee } ;
2020-09-21 11:57:10 +02:00
Session [ ModelSessionConstants . ReportModelKey ] = _Model ;
2020-09-14 19:07:23 +02:00
}
else
{
2020-09-21 11:57:10 +02:00
_Model = ( ReportModel ) Session [ ModelSessionConstants . ReportModelKey ] ;
2020-09-14 19:07:23 +02:00
}
return _Model ;
}
}
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
}
2023-05-31 17:54:01 +02:00
if ( ! AbstractModel . HasRightToViewQuittierungsbelege )
2020-10-20 21:07:26 +02:00
{
return RedirectToActionPermanent ( "Main" , "Main" ) ;
}
2020-09-30 19:23:42 +02:00
2023-01-11 17:26:38 +01:00
//CreateServiceOverview(null);
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
{
2023-05-02 13:03:46 +02:00
if ( ! MobileSessionFacade . IsUserLoggedIn ( ) | | Request . Browser . Browser . Equals ( "InternetExplorer" ) )
2023-01-17 00:12:33 +01:00
{
return Logout ( ) ;
}
2023-05-31 17:54:01 +02:00
if ( ! AbstractModel . HasRightToViewQuittierungsbelege )
2023-01-17 00:12:33 +01:00
{
return RedirectToActionPermanent ( "Main" , "Main" ) ;
}
2021-01-14 16:30:28 +01:00
2023-01-17 00:12:33 +01:00
var month = DateTime . Today . Month ;
2023-01-18 13:47:25 +01:00
var year = DateTime . Today . Year ;
2023-01-17 00:12:33 +01:00
var first = new DateTime ( year , month , 1 ) . AddMonths ( - 1 ) ;
2023-01-18 13:47:25 +01:00
var last = first . AddMonths ( 1 ) . AddDays ( - 1 ) ;
2021-01-14 16:30:28 +01:00
2023-01-18 13:47:25 +01:00
Model . SelectedYear = Model . SelectedYear ? ? first . Year ;
Model . SelectedMonth = Model . SelectedMonth ? ? first . Month ;
Model . SelectedStartDay = Model . SelectedStartDay ? ? first . Day ;
Model . SelectedEndDay = Model . SelectedEndDay ? ? last . Day ;
2021-01-14 16:30:28 +01:00
2023-01-17 00:12:33 +01:00
var filterEnums = Enum . GetValues ( typeof ( QBFilterEnum ) ) . Cast < QBFilterEnum > ( ) ;
2021-01-14 16:30:28 +01:00
2023-01-17 00:12:33 +01:00
Model . QbFilters . Clear ( ) ;
2023-05-02 13:03:46 +02:00
foreach ( var filterEnum in filterEnums )
2023-01-17 00:12:33 +01:00
{
Model . QbFilters . AddIfNotIn ( new QbFilterItem ( filterEnum ) ) ;
}
2020-11-09 17:55:01 +01:00
2023-01-17 00:12:33 +01:00
Model . Customers = EmployeeService . GetActiveCompactCustomersForEmployee ( null ) . OrderBy ( d = > d . ToString ( ) ) . ToList ( ) ;
2020-11-09 17:55:01 +01:00
2023-01-17 00:12:33 +01:00
Model . Employees = EmployeeService . GetActiveCompactEmployeesForEmployee ( MobileSessionFacade . LoggedInCompactEmployee . EmployeeOid ) ;
2020-11-09 17:55:01 +01:00
2023-01-17 00:12:33 +01:00
Model . ServiceCategories = OperationsService . GetAllServiceCategories ( ) ;
2020-09-30 19:23:42 +02:00
2023-01-17 00:12:33 +01:00
Model . Organisations = CustomerService . GetAllCostBearerCompact ( ) ;
Model . Organisations . Sort ( ( x , y ) = > x . Name . CompareTo ( y . Name ) ) ;
2020-11-09 17:55:01 +01:00
2023-01-17 00:12:33 +01:00
Model . AllTeams = EmployeeService . GetAllActiveCompactTeamsForEmployee ( MobileSessionFacade . LoggedInEmployee . EmployeeOid ) ;
2023-01-26 12:55:56 +01:00
CreateReport ( null ) ;
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
}
2023-01-26 12:55:56 +01:00
2020-09-14 19:07:23 +02:00
[Authorize]
[HttpPost]
public ActionResult CreateServiceOverview ( FormCollection formCollection )
{
2023-01-11 17:26:38 +01:00
if ( Model ? . Employee ? . EmployeeOid is null )
2020-09-15 16:03:49 +02:00
{
return Logout ( ) ;
}
2023-01-11 17:26:38 +01:00
if ( Model . SelectedFilterItem is null )
2021-02-17 16:59:26 +01:00
{
return RedirectToActionPermanent ( "Report" ) ;
}
2023-01-26 12:55:56 +01:00
CreateReport ( formCollection ) ;
return RedirectToActionPermanent ( "Report" ) ;
}
[Authorize]
private void CreateReport ( NameValueCollection formCollection )
{
if ( Model . SelectedFilterItem ? . FilterEnum = = QBFilterEnum . KlientenAuswahl )
2020-11-09 17:55:01 +01:00
{
2021-02-17 16:59:26 +01:00
var customerOidString = formCollection = = null ? Model . SelectedCustomerOid . ToString ( ) : formCollection [ FormCollectionConstants . SelectedCustomerOidKey ] ;
2020-09-15 16:03:49 +02:00
2020-11-09 17:55:01 +01:00
var isCustomerOidSuccessful = long . TryParse ( customerOidString , out var selectedCustomerOid ) ;
if ( isCustomerOidSuccessful )
{
var selectedCustomer = Model . Customers . FirstOrDefault ( customer = > customer . CustomerOid = = selectedCustomerOid ) ;
2020-09-15 16:03:49 +02:00
2020-11-09 17:55:01 +01:00
Model . SelectedCustomer = selectedCustomer ;
}
}
else
2020-09-15 16:03:49 +02:00
{
2020-11-09 17:55:01 +01:00
Model . SelectedCustomer = null ;
2020-09-15 16:03:49 +02:00
}
2023-01-26 12:55:56 +01:00
if ( Model . SelectedFilterItem ? . FilterEnum = = QBFilterEnum . TeamAuswahl )
2020-11-09 17:55:01 +01:00
{
2021-02-17 16:59:26 +01:00
var teamOidString = formCollection = = null ? Model . SelectedTeamOid . ToString ( ) : formCollection [ FormCollectionConstants . SelectedTeamOidKey ] ;
2020-09-23 16:00:51 +02:00
2020-11-09 17:55:01 +01:00
var isTeamOidSuccessful = long . TryParse ( teamOidString , out var selectedTeamOid ) ;
2020-09-15 16:03:49 +02:00
2020-11-09 17:55:01 +01:00
if ( isTeamOidSuccessful )
{
var selectedTeam = Model . AllTeams . FirstOrDefault ( team = > team . TeamOid = = selectedTeamOid ) ;
2020-09-21 11:57:10 +02:00
2020-11-09 17:55:01 +01:00
Model . SelectedTeam = selectedTeam ;
}
}
else
{
Model . SelectedTeam = null ;
}
2023-01-18 13:43:11 +01:00
// Datumsangaben laden in separater Methode
var reportTimeFrame = GetReportTimeFrame ( ) ;
2020-09-21 11:57:10 +02:00
2020-11-09 17:55:01 +01:00
var reportObjects = new List < ServicesOverviewRO > ( ) ;
2020-09-21 11:57:10 +02:00
2023-01-26 12:55:56 +01:00
var organisationOid = Model . SelectedOrganisationOid ? ? 0 ;
var employeeOid = Model . SelectedEmployeeOid ? ? 0 ;
2020-11-09 17:55:01 +01:00
var serviceCategoryOid = Model . SelectedServiceCategoryOid ;
2023-01-26 12:55:56 +01:00
var teamOid = Model . SelectedTeamOid ;
var customerOid = Model . SelectedCustomerOid ? ? 0 ;
2020-11-09 17:55:01 +01:00
2023-11-13 11:33:08 +01:00
var creator = PluginLoader . FindClass < DefaultReportCreator > ( ) ? ? new DefaultReportCreator ( ) ;
2023-01-26 12:55:56 +01:00
switch ( Model . SelectedFilterItem ? . FilterEnum )
2020-11-09 17:55:01 +01:00
{
case QBFilterEnum . AlleKlienten :
2023-01-18 13:43:11 +01:00
reportObjects = ServicesOverviewRO . Create ( reportTimeFrame . Month , reportTimeFrame . Year , organisationOid , employeeOid , reportTimeFrame . StartDay , reportTimeFrame . EndDay , serviceCategoryOid ) ;
2020-11-09 17:55:01 +01:00
break ;
case QBFilterEnum . NurKlientenMeinesTeams :
2023-11-13 11:33:08 +01:00
var teamRelatedCustomerOids = creator . GetKlientenOidsMeinesTeams ( null ) ;
2023-01-18 13:43:11 +01:00
reportObjects . AddRange ( teamRelatedCustomerOids . Select ( cOid = > ServicesOverviewRO . Create ( cOid , reportTimeFrame . Month , reportTimeFrame . Year , true , organisationOid , employeeOid , reportTimeFrame . StartDay , reportTimeFrame . EndDay , serviceCategoryOid ) ) ) ;
2020-11-09 17:55:01 +01:00
break ;
case QBFilterEnum . MeineKlienten :
2023-11-13 11:33:08 +01:00
var myRelatedCustomerOids = creator . GetMeineKlientenOids ( ) ;
2023-01-18 13:43:11 +01:00
reportObjects . AddRange ( myRelatedCustomerOids . Select ( cOid = > ServicesOverviewRO . Create ( cOid , reportTimeFrame . Month , reportTimeFrame . Year , true , organisationOid , employeeOid , reportTimeFrame . StartDay , reportTimeFrame . EndDay , serviceCategoryOid ) ) ) ;
2020-11-09 17:55:01 +01:00
break ;
case QBFilterEnum . KlientenAuswahl :
2023-01-26 12:55:56 +01:00
reportObjects = new List < ServicesOverviewRO > { ServicesOverviewRO . Create ( customerOid , reportTimeFrame . Month , reportTimeFrame . Year , false , organisationOid , employeeOid , reportTimeFrame . StartDay , reportTimeFrame . EndDay , serviceCategoryOid ) } ;
2020-11-09 17:55:01 +01:00
break ;
case QBFilterEnum . TeamAuswahl :
2023-11-13 11:33:08 +01:00
var customerOids = creator . GetKlientenOidsMeinesTeams ( teamOid ) ;
2023-01-18 13:43:11 +01:00
reportObjects . AddRange ( customerOids . Select ( cOid = > ServicesOverviewRO . Create ( cOid , reportTimeFrame . Month , reportTimeFrame . Year , true , organisationOid , employeeOid , reportTimeFrame . StartDay , reportTimeFrame . EndDay , serviceCategoryOid ) ) ) ;
2020-11-09 17:55:01 +01:00
break ;
default :
2023-01-18 13:43:11 +01:00
reportObjects = ServicesOverviewRO . Create ( reportTimeFrame . Month , reportTimeFrame . Year , organisationOid , employeeOid , reportTimeFrame . StartDay , reportTimeFrame . EndDay , serviceCategoryOid , true , false ) ;
2020-11-09 17:55:01 +01:00
break ;
}
2023-01-26 12:55:56 +01:00
2021-02-17 16:59:26 +01:00
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 ) ;
2021-03-17 18:44:40 +01:00
var customerSignatures = Model . ConfirmationReceiptSignatures . Where ( crs = > crs . SignatureType = = SignatureType . Customer ) . ToList ( ) ;
var employeeSignatures = Model . ConfirmationReceiptSignatures . Where ( crs = > crs . SignatureType = = SignatureType . Employee ) . ToList ( ) ;
2023-01-26 12:55:56 +01:00
2021-02-17 16:59:26 +01:00
Model . ReportServiceRecordOids = new List < long > ( ) ;
reportObjects . DoForEach ( ro = > ro . Services . DoForEach ( s = >
{
Model . ReportServiceRecordOids . AddIfNotIn ( s . ServiceRecordOid ) ;
} ) ) ;
2021-03-17 18:44:40 +01:00
var hasEmployeeSignature = srOids . All (
2023-01-26 12:55:56 +01:00
a = > serviceRecordOidsWithSignature . ContainsKey ( SignatureType . Employee ) & &
2021-03-17 18:44:40 +01:00
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 ;
}
2020-11-09 17:55:01 +01:00
Model . ConfirmationReceiptObject = null ;
2021-03-17 18:44:40 +01:00
Model . ConfirmationReceiptObject = new ConfirmationReceiptObject (
2023-01-26 12:55:56 +01:00
BuildInformationString ( ) ,
new List < QuittierungsbelegResult > ( ) ,
BuildInformationString ( true ) ,
GetTimeSpanString ( ) ,
hasEmployeeSignature ,
employeeSignatures . ToList ( ) ,
2021-03-17 18:44:40 +01:00
employeeSignatureState ) ;
2020-11-09 17:55:01 +01:00
2021-02-17 16:59:26 +01:00
reportObjects . DoForEach ( reportObject = >
2020-11-09 17:55:01 +01:00
{
var quittierungsbelegItems = new List < QuittierungsbelegItem > ( ) ;
2021-02-17 16:59:26 +01:00
reportObject . Services . DoForEach ( serviceDetail = >
{
quittierungsbelegItems . Add ( new QuittierungsbelegItem ( serviceDetail ) ) ;
} ) ;
2020-11-09 17:55:01 +01:00
2021-02-17 16:59:26 +01:00
if ( quittierungsbelegItems . Count = = 0 )
{
return ;
}
2021-03-17 18:44:40 +01:00
var oids = quittierungsbelegItems . Select ( s = > s . ServiceRecordOid ) . ToList ( ) ;
2023-01-26 12:55:56 +01:00
var hasCustomerSignature = oids . All ( a = > serviceRecordOidsWithSignature . ContainsKey ( SignatureType . Customer ) & &
2021-03-17 18:44:40 +01:00
serviceRecordOidsWithSignature [ SignatureType . Customer ] . Contains ( a ) ) ;
var employeeSignatureState2 = GetSignatureState ( oids , serviceRecordOidsWithSignature , SignatureType . Employee ) ;
2021-02-17 16:59:26 +01:00
2021-03-17 18:44:40 +01:00
var customerSignatureState = GetSignatureState ( oids , serviceRecordOidsWithSignature , SignatureType . Customer ) ;
2021-02-17 16:59:26 +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 ;
2021-03-17 18:44:40 +01:00
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 ) ;
}
2021-02-17 16:59:26 +01:00
Model . ConfirmationReceiptObject . ConfirmationReceiptResultList . Add (
2021-03-17 18:44:40 +01:00
item : new QuittierungsbelegResult
2021-02-17 16:59:26 +01:00
(
2023-01-26 12:55:56 +01:00
$"{reportObject.CustomerLastName}, {reportObject.CustomerFirstName}" ,
quittierungsbelegItems ,
reportObject . CustomerOid ,
2021-02-17 16:59:26 +01:00
hasCustomerSignature ,
2021-03-17 18:44:40 +01:00
customerSignatureOid ,
customerSignatureState ,
customerSignatureOids ,
employeeSignatureState2 ,
employeeSignatureOids
2021-02-17 16:59:26 +01:00
)
) ;
2020-11-09 17:55:01 +01:00
} ) ;
2021-02-17 16:59:26 +01:00
if ( Model . ConfirmationReceiptObject . ConfirmationReceiptResultList . All ( qbItem = > qbItem . Items . Count = = 0 ) )
2020-09-21 11:57:10 +02:00
{
TempData [ "HasWarningMessage" ] = true ;
}
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 )
{
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 ;
}
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}" ;
}
2020-09-14 19:07:23 +02:00
[Authorize]
public string SetCustomer ( long customerOid )
{
if ( Model = = null )
{
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 ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
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
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
2021-02-17 16:59:26 +01:00
var isParsingSuccessful2 = long . TryParse ( organisationOidStr , out var organisationOid ) ;
var isParsingSuccessful3 = long . TryParse ( categoryOidStr , out var categoryOid ) ;
2020-10-07 19:42:17 +02:00
2023-01-18 13:43:11 +01:00
Model . SelectedOrganisation = isParsingSuccessful2 ? Model . Organisations . FirstOrDefault ( organisation = > organisation . OrganisationOid . Equals ( organisationOid ) ) : null ;
2021-02-17 16:59:26 +01:00
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 ;
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 ;
2023-02-09 20:47:52 +01:00
return 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 ;
Model . SelectedOrganisation = organisationOid . HasValue ? Model . Organisations . FirstOrDefault ( organisation = > organisation . OrganisationOid . Equals ( organisationOid ) ) : null ;
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 ;
2023-02-09 20:47:52 +01:00
return 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 ;
if ( serviceCategoryOid . HasValue )
{
Model . SelectedServiceCategory = Model . ServiceCategories . FirstOrDefault ( serviceCategory = > serviceCategory . ServiceCategoryOid = = serviceCategoryOid ) ;
}
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 ) ;
}
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>
/// 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>
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
{
2021-02-17 16:59:26 +01:00
if ( Model = = 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
2023-06-18 17:11:35 +02:00
Model . SelectedFilterItem = new QbFilterItem ( selectedFilterEnum ) ;
2023-01-26 12:55:56 +01:00
2023-06-18 17:11:35 +02:00
if ( selectedFilterEnum ! = QBFilterEnum . KlientenAuswahl | | ! ( Model . SelectedCustomer is null ) )
{
return LeerzeichenFuerGetMethoden ;
}
var customer = Model . Customers . FirstOrDefault ( ) ;
if ( ! ( customer is null ) )
{
Model . SelectedCustomer = customer ;
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 ) ) ;
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 ) ;
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 ;
}
foreach ( var signature in dataContracts )
{
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 ;
result . AddIfNotIn ( new ConfirmationReceiptSignatureObject ( img , date , personName , signature . SignatureType = = SignatureType . Employee , signature . ServiceRecords . Count ) ) ;
}
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 )
{
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 ;
}
2023-01-18 13:43:11 +01:00
var reportTimeFrame = GetReportTimeFrame ( ) ;
2023-01-11 17:26:38 +01:00
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 ;
2023-11-13 11:33:08 +01:00
var creator = PluginLoader . FindClass < DefaultReportCreator > ( ) ? ? new DefaultReportCreator ( ) ;
2023-01-11 17:26:38 +01:00
switch ( Model . SelectedFilterItem . FilterEnum )
{
case QBFilterEnum . AlleKlienten :
2023-01-18 13:43:11 +01:00
reportObjects = ServicesOverviewRO . Create ( reportTimeFrame . Month , reportTimeFrame . Year , organisationOid , employeeOid , reportTimeFrame . StartDay , reportTimeFrame . EndDay , serviceCategoryOid ) ;
2023-01-11 17:26:38 +01:00
break ;
case QBFilterEnum . NurKlientenMeinesTeams :
2023-11-13 11:33:08 +01:00
var teamRelatedCustomerOids = creator . GetKlientenOidsMeinesTeams ( null ) ;
2023-01-18 13:43:11 +01:00
reportObjects . AddRange ( teamRelatedCustomerOids . Select ( cOid = > ServicesOverviewRO . Create ( cOid , reportTimeFrame . Month , reportTimeFrame . Year , true , organisationOid , employeeOid , reportTimeFrame . StartDay , reportTimeFrame . EndDay , serviceCategoryOid ) ) ) ;
2023-01-11 17:26:38 +01:00
break ;
case QBFilterEnum . MeineKlienten :
2023-11-13 11:33:08 +01:00
var myRelatedCustomerOids = creator . GetMeineKlientenOids ( ) ;
2023-01-18 13:43:11 +01:00
reportObjects . AddRange ( myRelatedCustomerOids . Select ( cOid = > ServicesOverviewRO . Create ( cOid , reportTimeFrame . Month , reportTimeFrame . Year , true , organisationOid , employeeOid , reportTimeFrame . StartDay , reportTimeFrame . EndDay , serviceCategoryOid ) ) ) ;
2023-01-11 17:26:38 +01:00
break ;
case QBFilterEnum . KlientenAuswahl :
2023-01-18 13:43:11 +01:00
reportObjects = new List < ServicesOverviewRO > { ServicesOverviewRO . Create ( customerOid , reportTimeFrame . Month , reportTimeFrame . Year , false , organisationOid , employeeOid , reportTimeFrame . StartDay , reportTimeFrame . EndDay , serviceCategoryOid ) } ;
2023-01-11 17:26:38 +01:00
break ;
case QBFilterEnum . TeamAuswahl :
2023-11-13 11:33:08 +01:00
var customerOids = creator . GetKlientenOidsMeinesTeams ( teamOid ) ;
2023-01-18 13:43:11 +01:00
reportObjects . AddRange ( customerOids . Select ( cOid = > ServicesOverviewRO . Create ( cOid , reportTimeFrame . Month , reportTimeFrame . Year , true , organisationOid , employeeOid , reportTimeFrame . StartDay , reportTimeFrame . EndDay , serviceCategoryOid ) ) ) ;
2023-01-11 17:26:38 +01:00
break ;
default :
2023-01-18 13:43:11 +01:00
reportObjects = ServicesOverviewRO . Create ( reportTimeFrame . Month , reportTimeFrame . Year , organisationOid , employeeOid , reportTimeFrame . StartDay , reportTimeFrame . EndDay , serviceCategoryOid , true , false ) ;
2023-01-11 17:26:38 +01:00
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 ) ;
2023-11-13 16:40:39 +01:00
var confirmationReceiptResults = new List < QuittierungsbelegResult > ( ) ;
2023-01-11 17:26:38 +01:00
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 ) ;
}
2023-11-13 16:40:39 +01:00
confirmationReceiptResults . Add (
item : new QuittierungsbelegResult
2023-01-11 17:26:38 +01:00
(
$"{reportObject.CustomerLastName}, {reportObject.CustomerFirstName}" ,
quittierungsbelegItems ,
reportObject . CustomerOid ,
hasCustomerSignature ,
customerSignatureOid ,
customerSignatureState ,
customerSignatureOids ,
employeeSignatureState2 ,
employeeSignatureOids
)
) ;
} ) ;
2023-11-13 16:40:39 +01:00
Model . ConfirmationReceiptObject . ConfirmationReceiptResultList . AddRangeIfElementsNotIn ( confirmationReceiptResults . OrderBy ( o = > o . CustomerName ) ) ;
2023-01-11 17:26:38 +01:00
if ( Model . ConfirmationReceiptObject . ConfirmationReceiptResultList . All ( qbItem = > qbItem . Items . Count = = 0 ) )
{
TempData [ "HasWarningMessage" ] = true ;
}
return PartialView ( "QuittierungsbelegsResultPartial" , Model ) ;
}
2023-01-18 13:43:11 +01:00
2023-01-26 12:55:56 +01:00
/// <summary>
/// Erstellt den Zeitraum für die Auswahl
/// </summary>
/// <returns></returns>
2023-01-18 13:43:11 +01:00
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]
2023-01-26 12:55:56 +01:00
public ActionResult DeleteCustomerSignature ( FormCollection formCollection )
2023-01-18 13:43:11 +01:00
{
if ( Model is null )
{
return Logout ( ) ;
}
2023-01-26 12:55:56 +01:00
var info = formCollection [ "deleteCustomerSignaturesInfo" ] ;
if ( AbstractModel . HasRightToDeleteReceiptSignatures )
{
DeleteSignatures ( info , true ) ;
}
2023-01-18 13:43:11 +01:00
2023-05-02 13:03:46 +02:00
return RedirectToActionPermanent ( "InitReports" ) ;
2023-01-18 13:43:11 +01:00
}
[Authorize]
[HttpPost]
2023-01-26 12:55:56 +01:00
public ActionResult DeleteEmployeeSignature ( FormCollection formCollection )
2023-01-18 13:43:11 +01:00
{
2023-01-26 12:55:56 +01:00
if ( Model ? . ConfirmationReceiptObject is null )
2023-01-18 13:43:11 +01:00
{
return Logout ( ) ;
}
2023-01-26 12:55:56 +01:00
var info = formCollection [ "deleteEmployeeSignatureInfo" ] ;
if ( AbstractModel . HasRightToDeleteReceiptSignatures )
{
DeleteSignatures ( info , false ) ;
}
2023-01-18 13:43:11 +01:00
2023-05-02 13:03:46 +02:00
return RedirectToActionPermanent ( "InitReports" ) ;
2023-01-18 13:43:11 +01:00
}
2023-01-26 12:55:56 +01:00
[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 ) ) ;
}
2023-04-24 19:22:09 +02:00
[Authorize]
public ActionResult FetchConfirmationReceiptSignatures ( string identifier , bool isEmployee )
{
if ( Model is null )
{
return Logout ( ) ;
}
if ( ! Guid . TryParse ( identifier , out var resultIdentifier ) )
{
return PartialView ( "ConfirmationReceiptSignaturePartial" , Model ) ;
}
var obj = Model . ConfirmationReceiptObject . ConfirmationReceiptResultList . FirstOrDefault ( f = > f . Identifier . Equals ( resultIdentifier ) ) ;
if ( obj is null )
{
return PartialView ( "ConfirmationReceiptSignaturePartial" , Model ) ;
}
var oids = isEmployee ? obj . EmployeeSignatureOids : obj . CustomerSignatureOids ;
var signatures = Model . GetConfirmationReceitSignaturesByOids ( oids ) ;
Model . SelectedConfirmationReceiptSignatures = ConvertSignatureDCsToSignatureObjects ( signatures ) ;
var customerName = obj . CustomerName ;
var employeeName = MobileSessionFacade . LoggedInCompactEmployee . SimpleDescription ;
2023-05-02 13:03:46 +02:00
var serviceRecordCount = obj . Items . Count ;
2023-04-24 19:22:09 +02:00
var personName = isEmployee ? employeeName : customerName ;
2023-05-02 13:03:46 +02:00
Model . Quittierungsbelegsunterschriftenobjekt = new Quittierungsbelegsunterschriftenobjekt ( isEmployee , personName , Model . ConfirmationReceiptObject . TimeSpanString , customerName , serviceRecordCount , obj . CustomerOid ) ;
2023-04-24 19:22:09 +02:00
return PartialView ( "ConfirmationReceiptSignaturePartial" , Model ) ;
}
}
public class ConfirmationReceiptSignatureObject
{
public string ImageStr { get ; }
public string InsTsStr { get ; }
public string PersonName { get ; }
public bool IsEmployeeSignature { get ; }
public int NumberOfServiceRecords { get ; }
public ConfirmationReceiptSignatureObject ( string imageStr , string insTsStr , string personName , bool isEmployeeSignature , int numberOfServiceRecords )
{
ImageStr = imageStr ;
InsTsStr = insTsStr ;
PersonName = personName ;
IsEmployeeSignature = isEmployeeSignature ;
NumberOfServiceRecords = numberOfServiceRecords ;
}
2020-09-14 19:07:23 +02:00
}
}