using System; using System.Collections.Generic; using System.Linq; using System.Windows.Controls; using Comal.Classes; using InABox.Core; using InABox.DynamicGrid; using InABox.WPF; namespace PRSDesktop; public class CustomerReceipts : DynamicDataGrid, IPanel { private bool Outstanding = true; public CustomerReceipts() { Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.FilterRows, DynamicGridOption.SelectColumns, DynamicGridOption.MultiSelect); AddButton("Show All", PRSDesktop.Resources.view.AsBitmapImage(), ToggleView); OnBeforeSave += BeforeSave; } public bool IsReady { get; set; } public event DataModelUpdateEvent OnUpdateDataModel; public void CreateToolbarButtons(IPanelHost host) { // } public Dictionary Selected() { return new Dictionary { { typeof(Receipt).EntityName(), SelectedRows } }; } public string SectionName => "Customer Receipts"; public DataModel DataModel(Selection selection) { var ids = ExtractValues(x => x.ID, selection).ToArray(); return new BaseDataModel(new Filter(x => x.ID).InList(ids)); } public bool Focus() { return true; } public void Refresh() { Refresh(false, true); } public void Setup() { Refresh(true, false); } public void Shutdown() { } public void Heartbeat(TimeSpan time) { } private void BeforeSave(DynamicEditorForm editor, Receipt[] items) { if (items == null || items.Length != 1) return; if (!string.IsNullOrWhiteSpace(items[0].Notes)) return; var page = editor.Pages.FirstOrDefault(x => x is DynamicManyToManyGrid) as DynamicManyToManyGrid; if (page != null) { var numbers = page.Data.Rows.Select(r => r.Get(c => c.InvoiceLink.Number)).ToArray(); items[0].Notes = string.Format("Invoice{0} {1}", numbers.Length > 1 ? "s" : "", string.Join(", ", numbers)); } } private bool ToggleView(Button sender, CoreRow[] rows) { Outstanding = !Outstanding; UpdateButton(sender, PRSDesktop.Resources.view.AsBitmapImage(), Outstanding ? "Show All" : "Outstanding"); return true; } protected override void Reload(Filters criteria, Columns columns, ref SortOrder sort, Action action) { if (Outstanding) criteria.Add(new Filter(x => x.Reconciled).IsEqualTo(DateTime.MinValue)); base.Reload(criteria, columns, ref sort, action); } }