113 lines
3.4 KiB
C#
113 lines
3.4 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.Mvvm;
|
|
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() => SelectedVM is object && true;
|
|
ShowXRechnungCommand = new DelegateCommand(ShowXRechnung, canExecute);
|
|
}
|
|
|
|
public DelegateCommand 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()
|
|
{
|
|
var invoice_base_oid = SelectedVM.DataContract.InvoiceBaseOid ?? -1;
|
|
var invoice_type = (int)SelectedVM.DataContract.Type;
|
|
var report_link = SelectedVM.ReportLink;
|
|
|
|
ServiceFacade.DoAccountingEnhancedServiceAsnyc(
|
|
x => x.GetXRechnung(invoice_base_oid, invoice_type, report_link),
|
|
response =>
|
|
{
|
|
if (response.Success)
|
|
{
|
|
BeWoApp.MainControl.WindowService.ShowERechnungWindow(new MemoryStream(response.Data));
|
|
}
|
|
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);
|
|
}
|
|
}
|
|
} |