134 lines
3.7 KiB
C#
134 lines
3.7 KiB
C#
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using BeWo.ServiceProxy;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Extensions;
|
|
using DevExpress.DataAccess.Native.Web;
|
|
using DevExpress.Mvvm;
|
|
using DevExpress.Xpf.Editors;
|
|
using DevExpress.Xpf.Layout.Core;
|
|
|
|
namespace BeWo.ViewModel.ListViewModel
|
|
{
|
|
public class InvoiceBaseListVM : AbstractDCListMapperVM<InvoiceBaseDC, InvoiceBaseVM>
|
|
{
|
|
public static string PropertyName_DateTimeSpanFilter = "DateTimeSpanFilter";
|
|
|
|
public static string PropertyName_FilterResultAmountSum = "FilterResultAmountSum";
|
|
public static string PropertyName_FilterResultAmountNotPaidSum = "FilterResultAmountNotPaidSum";
|
|
|
|
private DateTimeSpan _DateTimeSpanFilter;
|
|
private BindingList<InvoiceBaseVM> _FilteredInvoices;
|
|
|
|
public InvoiceBaseListVM(List<InvoiceBaseDC> pDCs) : base(pDCs)
|
|
{
|
|
VMList.ListChanged += (s, e) => FirePropertyChanged(PropertyName_FilterResultAmountSum);
|
|
VMList.ListChanged += (s, e) => FirePropertyChanged(PropertyName_FilterResultAmountNotPaidSum);
|
|
|
|
bool canExecute(InvoiceBaseVM invoice_vm) => invoice_vm is object && true;
|
|
ShowXRechnungCommand = new DelegateCommand<InvoiceBaseVM>(ShowXRechnung, canExecute);
|
|
}
|
|
|
|
public DelegateCommand<InvoiceBaseVM> ShowXRechnungCommand { get; set; }
|
|
|
|
public DateTimeSpan DateTimeSpanFilter
|
|
{
|
|
get
|
|
{
|
|
return _DateTimeSpanFilter;
|
|
}
|
|
|
|
set
|
|
{
|
|
if (AreDifferent(_DateTimeSpanFilter, value))
|
|
{
|
|
_DateTimeSpanFilter = value;
|
|
FirePropertyChanged(PropertyName_DateTimeSpanFilter);
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
public decimal? FilterResultAmountSum
|
|
{
|
|
get
|
|
{
|
|
return VMList.Sum(e => e.TotalAmount);
|
|
}
|
|
}
|
|
public decimal? FilterResultAmountNotPaidSum
|
|
{
|
|
get
|
|
{
|
|
decimal? sum = 0.0m;
|
|
foreach (var item in VMList)
|
|
sum += item.IsPaid ? item.TotalAmount : 0;
|
|
|
|
return FilterResultAmountSum - sum;
|
|
}
|
|
}
|
|
|
|
public void ShowXRechnung(InvoiceBaseVM invoice_vm)
|
|
{
|
|
var invoice_base = invoice_vm;
|
|
|
|
// Holt bereits geladene
|
|
if (invoice_base.XRechnungStoredFileVM is StoredFileVM vm && vm.Data is byte[] bytes)
|
|
{
|
|
BeWoApp.MainControl.WindowService.ShowERechnungWindow(new MemoryStream(bytes));
|
|
return;
|
|
}
|
|
|
|
// Noch nicht geladen
|
|
var invoice_base_dc = invoice_base.DataContract;
|
|
var invoice_base_oid = invoice_base_dc.InvoiceBaseOid ?? -1;
|
|
var invoice_type = (int)invoice_base_dc.Type;
|
|
var report_link = invoice_base.ReportLink;
|
|
ServiceFacade.DoAccountingEnhancedServiceAsnyc(
|
|
x => x.GetXRechnung(invoice_base_oid, invoice_type, report_link),
|
|
response =>
|
|
{
|
|
if (response.Success)
|
|
{
|
|
if (response.Data.Item1 is StoredFileDC dc)
|
|
{
|
|
invoice_base.XRechnungStoredFileVM.UpdateByDataContract(dc);
|
|
}
|
|
|
|
bytes = response.Data.Item2;
|
|
|
|
invoice_base.XRechnungStoredFileVM.Data = bytes;
|
|
|
|
BeWoApp.MainControl.WindowService.ShowERechnungWindow(new MemoryStream(bytes));
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show(response.ToErrorString());
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
internal void UpdateList(IList<InvoiceBaseDC> dcList)
|
|
{
|
|
VMList.Clear();
|
|
VMList.AddRange(dcList.Select(CreateVM));
|
|
|
|
FirePropertyChanged(PropertyName_FilterResultAmountSum);
|
|
FirePropertyChanged(PropertyName_FilterResultAmountNotPaidSum);
|
|
}
|
|
|
|
internal void UpdateList(IList<InvoiceBaseVM> vmList)
|
|
{
|
|
VMList.Clear();
|
|
VMList.AddRange(vmList);
|
|
|
|
FirePropertyChanged(PropertyName_FilterResultAmountSum);
|
|
FirePropertyChanged(PropertyName_FilterResultAmountNotPaidSum);
|
|
}
|
|
}
|
|
} |