464 lines
12 KiB
C#
464 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Threading;
|
|
using BeWo.Core;
|
|
using BeWo.ServiceProxy;
|
|
using BeWo.Validation;
|
|
using BS.Shared;
|
|
using BS.Shared.DataContracts.GkvAbrechnung;
|
|
using BS.Shared.DataContracts.Light;
|
|
using BS.Shared.Extensions;
|
|
using BS.Shared.Interface;
|
|
using BS.Shared.ReportRequests;
|
|
using DevExpress.Mvvm;
|
|
using DevExpress.Xpf.Core;
|
|
|
|
namespace BeWo.ViewModel.Light
|
|
{
|
|
public class GkvAbrechnungLightVM : AbstractDCMapperVM<GkvAbrechnungLightDC>, IGkvAbrechnung
|
|
{
|
|
public static string PropertyName_AbrechnungsZeitraumStart = "AbrechnungsZeitraumStart";
|
|
public static string PropertyName_AbrechnungsZeitraumEnde = "AbrechnungsZeitraumEnde";
|
|
|
|
public static string PropertyName_ErstelltAm = "ErstelltAm";
|
|
|
|
private string _Notice;
|
|
|
|
private long _OrganisationOid;
|
|
private string _OrganisationName;
|
|
|
|
private DateTime? _AbrechnungsZeitraumStart;
|
|
private DateTime? _AbrechnungsZeitraumEnde;
|
|
|
|
private DateTime _ErstelltAm;
|
|
|
|
private decimal _Betrag;
|
|
private bool _Bezahlt;
|
|
private bool _UrbelegeGesendet;
|
|
private GkvVerfahrensstufe _Verfahrensstufe;
|
|
|
|
internal bool _IsChecked;
|
|
|
|
private bool _IsReady2Send;
|
|
private string _SendTooltip;
|
|
|
|
private List<GkvTransferProtokollLightDC> _Protokolle;
|
|
|
|
public GkvAbrechnungLightVM(GkvAbrechnungLightDC pDC) : base(pDC, false)
|
|
{
|
|
if(InvoiceBases is null)
|
|
InvoiceBases = new BindingList<InvoiceBaseVM>();
|
|
|
|
CheckAllInvoiceBasesCommand = new DelegateCommand(CheckAllInvoiceBases, HasAnyInvoiceBases);
|
|
UncheckAllInvoiceBasesCommand = new DelegateCommand(UncheckAllInvoicesBases, HasAnyInvoiceBases);
|
|
PrintSelectedInvoiceBasesCommand = new DelegateCommand(PrintSelectedInvoiceBases, HasAnySelectedInvoiceBases);
|
|
}
|
|
|
|
public DelegateCommand CheckAllInvoiceBasesCommand { get; set; }
|
|
public DelegateCommand UncheckAllInvoiceBasesCommand { get; set; }
|
|
public DelegateCommand PrintSelectedInvoiceBasesCommand { get; set; }
|
|
|
|
#region
|
|
|
|
public string AbrechnungsZeitraum => $"{AbrechnungsZeitraumStart.Value.ToShortDateString()} - {AbrechnungsZeitraumEnde.Value.ToShortDateString()}";
|
|
|
|
public DateTime? AbrechnungsZeitraumStart
|
|
{
|
|
get { return this._AbrechnungsZeitraumStart; }
|
|
|
|
set
|
|
{
|
|
if (this.AreDifferent(this._AbrechnungsZeitraumStart, value))
|
|
{
|
|
this._AbrechnungsZeitraumStart = value;
|
|
this.StoreDirtyInformation(this.AreDifferent(this.DataContract.AbrechnungsZeitraumStart, value), PropertyName_AbrechnungsZeitraumStart);
|
|
this.FirePropertyChanged(PropertyName_AbrechnungsZeitraumStart);
|
|
|
|
// RE893748923
|
|
// var day = value.Value.Day;
|
|
// AbrechnungsZeitraumEnde = value.Value.AddDays(1 - day).AddMonths(1).AddDays(-1);
|
|
}
|
|
}
|
|
}
|
|
public DateTime? AbrechnungsZeitraumEnde
|
|
{
|
|
get { return this._AbrechnungsZeitraumEnde; }
|
|
|
|
set
|
|
{
|
|
if (this.AreDifferent(this._AbrechnungsZeitraumEnde, value))
|
|
{
|
|
this._AbrechnungsZeitraumEnde = value;
|
|
this.StoreDirtyInformation(this.AreDifferent(this.DataContract.AbrechnungsZeitraumEnde, value), PropertyName_AbrechnungsZeitraumEnde);
|
|
this.FirePropertyChanged(PropertyName_AbrechnungsZeitraumEnde);
|
|
}
|
|
}
|
|
}
|
|
public DateTime ErstelltAm
|
|
{
|
|
get { return this._ErstelltAm; }
|
|
|
|
set
|
|
{
|
|
if (AreDifferent(_ErstelltAm, value))
|
|
{
|
|
_ErstelltAm = value;
|
|
StoreDirtyInformation(AreDifferent(DataContract.ErstelltAm, value), nameof(ErstelltAm));
|
|
FirePropertyChanged(nameof(ErstelltAm));
|
|
FirePropertyChanged(nameof(ErstelltAmDate));
|
|
}
|
|
}
|
|
}
|
|
public DateTime ErstelltAmDate => ErstelltAm.Date;
|
|
public long Oid
|
|
{
|
|
get => DataContract.Oid;
|
|
}
|
|
public long Version
|
|
{
|
|
get => DataContract.Version;
|
|
}
|
|
public string Notice
|
|
{
|
|
get { return this._Notice; }
|
|
|
|
set
|
|
{
|
|
if (this.AreDifferent(this._Notice, value))
|
|
{
|
|
this._Notice = value;
|
|
this.StoreDirtyInformation(this.AreDifferent(this.DataContract.Notice, value), nameof(Notice));
|
|
this.FirePropertyChanged(nameof(Notice));
|
|
}
|
|
}
|
|
}
|
|
public decimal Betrag
|
|
{
|
|
get { return this._Betrag; }
|
|
|
|
set
|
|
{
|
|
if (this.AreDifferent(this._Betrag, value))
|
|
{
|
|
this._Betrag = value;
|
|
this.StoreDirtyInformation(this.AreDifferent(this.DataContract.Betrag, value), nameof(Betrag));
|
|
this.FirePropertyChanged(nameof(Betrag));
|
|
}
|
|
}
|
|
}
|
|
public bool Bezahlt
|
|
{
|
|
get { return _Bezahlt; }
|
|
|
|
set
|
|
{
|
|
if (AreDifferent(this._Bezahlt, value))
|
|
{
|
|
_Bezahlt = value;
|
|
StoreDirtyInformation(AreDifferent(DataContract.Bezahlt, value), nameof(Bezahlt));
|
|
FirePropertyChanged(nameof(Bezahlt));
|
|
FirePropertyChanged(nameof(GkvState));
|
|
FirePropertyChanged(nameof(Fehlermeldung));
|
|
}
|
|
}
|
|
}
|
|
public bool UrbelegeGesendet
|
|
{
|
|
get { return _UrbelegeGesendet; }
|
|
|
|
set
|
|
{
|
|
if (!AreDifferent(_UrbelegeGesendet, value))
|
|
return;
|
|
_UrbelegeGesendet = value;
|
|
StoreDirtyInformation(AreDifferent(DataContract.UrbelegeGesendet, value), nameof(UrbelegeGesendet));
|
|
FirePropertyChanged(nameof(UrbelegeGesendet));
|
|
FirePropertyChanged(nameof(GkvState));
|
|
FirePropertyChanged(nameof(IsBezahltEditEnabled));
|
|
}
|
|
}
|
|
public GkvState GkvState
|
|
{
|
|
get { return this.GetState(); }
|
|
}
|
|
|
|
public bool IsChecked
|
|
{
|
|
get { return _IsChecked; }
|
|
|
|
set
|
|
{
|
|
if (AreDifferent(_IsChecked, value))
|
|
{
|
|
_IsChecked = value;
|
|
FirePropertyChanged(nameof(IsChecked));
|
|
}
|
|
}
|
|
}
|
|
|
|
public BindingList<InvoiceBaseVM> InvoiceBases { get; set; }
|
|
|
|
public List<GkvTransferProtokollLightDC> Protokolle
|
|
{
|
|
get { return _Protokolle; }
|
|
set
|
|
{
|
|
_Protokolle = value;
|
|
FirePropertyChanged(nameof(Protokolle));
|
|
FirePropertyChanged(nameof(GkvState));
|
|
FirePropertyChanged(nameof(Fehlermeldung));
|
|
FirePropertyChanged(nameof(LastTransferDateTime));
|
|
}
|
|
}
|
|
public GkvVerfahrensstufe Verfahrensstufe
|
|
{
|
|
get { return this._Verfahrensstufe; }
|
|
|
|
set
|
|
{
|
|
if (this.AreDifferent(this._Verfahrensstufe, value))
|
|
{
|
|
this._Verfahrensstufe = value;
|
|
this.StoreDirtyInformation(this.AreDifferent(this.DataContract.Verfahrensstufe, (int)value), nameof(Verfahrensstufe));
|
|
this.FirePropertyChanged(nameof(Verfahrensstufe));
|
|
}
|
|
}
|
|
}
|
|
public int VerfahrensstufeInt
|
|
{
|
|
get { return (int)Verfahrensstufe; }
|
|
|
|
set
|
|
{
|
|
if (!AreDifferent(this.VerfahrensstufeInt, value))
|
|
return;
|
|
|
|
Verfahrensstufe = (GkvVerfahrensstufe)value;
|
|
//FirePropertyChanged(nameof(VerfahrensstufeInt));
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
public string RecipientString
|
|
{
|
|
get
|
|
{
|
|
if (InvoiceBases != null && InvoiceBases.Any())
|
|
{
|
|
return InvoiceBases.First().RecipientOrganisation;
|
|
}
|
|
|
|
return "Fehler";
|
|
}
|
|
}
|
|
public string Fehlermeldung
|
|
{
|
|
get
|
|
{
|
|
if (!(LastTransferProtokoll is GkvTransferProtokollLightDC last))
|
|
return null;
|
|
|
|
if (string.IsNullOrWhiteSpace(last.Fehlernachricht))
|
|
return null;
|
|
|
|
if (string.IsNullOrWhiteSpace(last.Fehlertitel))
|
|
return last.Fehlernachricht;
|
|
|
|
return $"{last.Fehlertitel}: {last.Fehlernachricht}";
|
|
}
|
|
}
|
|
public DateTime? LastTransferDateTime
|
|
{
|
|
get
|
|
{
|
|
if (LastTransferProtokoll is GkvTransferProtokollLightDC last)
|
|
return last.ErstelltAm?.Date;
|
|
|
|
return null;
|
|
}
|
|
}
|
|
public bool IsReady2Send
|
|
{
|
|
get { return _IsReady2Send; }
|
|
set
|
|
{
|
|
if (!AreDifferent(IsReady2Send, value))
|
|
return;
|
|
|
|
_IsReady2Send = value;
|
|
FirePropertyChanged(nameof(IsReady2Send));
|
|
}
|
|
}
|
|
public string SendTooltip
|
|
{
|
|
get { return _SendTooltip; }
|
|
set
|
|
{
|
|
if (!AreDifferent(SendTooltip, value))
|
|
return;
|
|
|
|
_SendTooltip = value;
|
|
FirePropertyChanged(nameof(SendTooltip));
|
|
}
|
|
}
|
|
|
|
public IEnumerable<IGkvTransferProtokoll> TransferProtokolle => Protokolle;
|
|
public IGkvTransferProtokoll LastTransferProtokoll => Protokolle?.LastOrDefault();
|
|
|
|
public bool IsFormularEnabled => LastTransferProtokoll is object ;
|
|
public bool IsUrbelegeEditEnabled => LastTransferProtokoll is object;
|
|
public bool IsBezahltEditEnabled => UrbelegeGesendet;
|
|
|
|
public GkvAbrechnungReportRequest ReportRequest
|
|
=> new GkvAbrechnungReportRequest(DataContract.Oid, false);
|
|
public string ReportLink
|
|
=> BeWoApp.SiteOfOrigin + "/ReportView.aspx" + ReportRequest.GetUrlPathString();
|
|
|
|
public GkvAbrechnungReportRequest ReportRequest2
|
|
=> new GkvAbrechnungReportRequest(DataContract.Oid, true);
|
|
public string ReportLink2
|
|
=> BeWoApp.SiteOfOrigin + "/ReportView.aspx" + ReportRequest2.GetUrlPathString();
|
|
|
|
public void FirePropertyIsReady2CreateChanged()
|
|
=> FirePropertyChanged(nameof(IsReady2Create));
|
|
public bool IsReady2Create
|
|
=> InvoiceBases?.Where(x => x.IsChecked).Any() ?? false;
|
|
|
|
public override void UpdateByDataContract(GkvAbrechnungLightDC pDataContract)
|
|
{
|
|
DataContract = pDataContract;
|
|
|
|
Notice = pDataContract.Notice;
|
|
|
|
Betrag = pDataContract.Betrag;
|
|
Bezahlt = pDataContract.Bezahlt;
|
|
|
|
if (pDataContract.InvoiceBases != null)
|
|
{
|
|
var l = pDataContract.InvoiceBases.Select(x => new InvoiceBaseVM(x, true)).ToList();
|
|
InvoiceBases.Clear();
|
|
InvoiceBases.AddRange(l);
|
|
}
|
|
}
|
|
protected override void InitByDataContract(GkvAbrechnungLightDC pDataContract)
|
|
{
|
|
_AbrechnungsZeitraumStart = pDataContract.AbrechnungsZeitraumStart;
|
|
_AbrechnungsZeitraumEnde = pDataContract.AbrechnungsZeitraumEnde;
|
|
|
|
_ErstelltAm = pDataContract.ErstelltAm;
|
|
|
|
_Notice = pDataContract.Notice;
|
|
|
|
_Betrag = pDataContract.Betrag;
|
|
_Bezahlt = pDataContract.Bezahlt;
|
|
_UrbelegeGesendet = pDataContract.UrbelegeGesendet;
|
|
_Verfahrensstufe = (GkvVerfahrensstufe)pDataContract.Verfahrensstufe;
|
|
|
|
if (pDataContract.InvoiceBases != null)
|
|
{
|
|
var l = pDataContract.InvoiceBases.Select(x => new InvoiceBaseVM(x, true)).ToList();
|
|
InvoiceBases = new BindingList<InvoiceBaseVM>(l);
|
|
}
|
|
|
|
if (pDataContract.Protokolle != null)
|
|
{
|
|
_Protokolle = new List<GkvTransferProtokollLightDC>(pDataContract.Protokolle);
|
|
}
|
|
|
|
_OrganisationOid = pDataContract.Organisation.Oid;
|
|
_OrganisationName = pDataContract.Organisation.Name;
|
|
|
|
_IsReady2Send = pDataContract.IsReady2Send;
|
|
_SendTooltip = pDataContract.SendTooltip;
|
|
}
|
|
protected override GkvAbrechnungLightDC MapToDataContract(GkvAbrechnungLightDC pDataContract, bool doCommit)
|
|
{
|
|
pDataContract.Notice = _Notice;
|
|
pDataContract.Betrag = _Betrag;
|
|
pDataContract.Bezahlt = _Bezahlt;
|
|
|
|
return pDataContract;
|
|
}
|
|
|
|
public void UpdateBySendResponse(GkvAbrechnungSendResponseDC cb)
|
|
{
|
|
var dc = cb.GkvAbrechnungDC;
|
|
|
|
if (dc is null)
|
|
{
|
|
MessageBox.Show(Application.Current.MainWindow, cb.Message);
|
|
return;
|
|
}
|
|
|
|
Protokolle = dc.Protokolle.ToList();
|
|
|
|
IsReady2Send = dc.IsReady2Send;
|
|
SendTooltip = dc.SendTooltip;
|
|
|
|
var protokoll = cb.TransferProtokoll;
|
|
|
|
if (protokoll.ResultType == GkvTransferResultType.FailSoft)
|
|
{
|
|
MessageBox.Show(Application.Current.MainWindow, protokoll.Fehlernachricht, protokoll.Fehlertitel);
|
|
}
|
|
else if (protokoll.ResultType == GkvTransferResultType.FailFatal)
|
|
{
|
|
BeWoApp.ShowError(protokoll.Fehlertitel + ": " + protokoll.Fehlernachricht, null, false, false);
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show(Application.Current.MainWindow, "Ihre Sendung wurde korrekt übertragen");
|
|
}
|
|
}
|
|
|
|
public bool HasAnyInvoiceBases()
|
|
{
|
|
return InvoiceBases is object && InvoiceBases.Any();
|
|
}
|
|
|
|
public void CheckAllInvoiceBases()
|
|
{
|
|
if (!HasAnyInvoiceBases())
|
|
return;
|
|
|
|
foreach (var invoice_base in InvoiceBases)
|
|
{
|
|
invoice_base.IsChecked = true;
|
|
}
|
|
}
|
|
|
|
internal void UncheckAllInvoicesBases()
|
|
{
|
|
if (!HasAnyInvoiceBases())
|
|
return;
|
|
|
|
foreach (var invoice_base in InvoiceBases)
|
|
{
|
|
invoice_base.IsChecked = false;
|
|
}
|
|
}
|
|
|
|
public bool HasAnySelectedInvoiceBases()
|
|
{
|
|
return HasAnyInvoiceBases() && getSelectedInvoiceBases().Any();
|
|
}
|
|
|
|
internal void PrintSelectedInvoiceBases()
|
|
{
|
|
var selected = new List<long>(getSelectedInvoiceBases());
|
|
|
|
if (!selected.Any())
|
|
return;
|
|
|
|
ServiceFacade.DoReportServiceAsync(s => s.CreateInvoiceListReport(selected), ms => BeWoApp.MainControl.Dispatch(() => BeWoUtils.ShowReportWindow(ms, "Rechnungen")));
|
|
}
|
|
|
|
private IEnumerable<long> getSelectedInvoiceBases()
|
|
{
|
|
return InvoiceBases.Where(x => x.IsChecked).Select(x => x.DataContract.InvoiceBaseOid.Value);
|
|
}
|
|
}
|
|
} |