| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- 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<Receipt>, IPanel<Receipt>
- {
- 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<string, object[]> Selected()
- {
- return new Dictionary<string, object[]> { { 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<Receipt>(new Filter<Receipt>(x => x.ID).InList(ids));
- }
- public void Refresh()
- {
- Refresh(false, true);
- }
- public void Setup()
- {
- Refresh(true, false);
- }
- public void Shutdown()
- {
- }
- public void Heartbeat(TimeSpan time)
- {
- }
- private void BeforeSave(IDynamicEditorForm editor, BaseObject[] items)
- {
- var receipt = items?.FirstOrDefault() as Receipt;
- if (receipt == null)
- return;
-
- if (!string.IsNullOrWhiteSpace(receipt.Notes))
- return;
- var page =
- editor.Pages.FirstOrDefault(x => x is DynamicManyToManyGrid<InvoiceReceipt, Receipt>) as DynamicManyToManyGrid<InvoiceReceipt, Receipt>;
- if (page != null)
- {
- var numbers = page.Data.Rows.Select(r => r.Get<InvoiceReceipt, int>(c => c.InvoiceLink.Number)).ToArray();
- receipt.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<Receipt> criteria, Columns<Receipt> columns, ref SortOrder<Receipt> sort,
- Action<CoreTable, Exception> action)
- {
- if (Outstanding)
- criteria.Add(new Filter<Receipt>(x => x.Reconciled).IsEqualTo(DateTime.MinValue));
- base.Reload(criteria, columns, ref sort, action);
- }
- }
|