|
@@ -0,0 +1,179 @@
|
|
|
+using Comal.Classes;
|
|
|
+using InABox.Clients;
|
|
|
+using InABox.Core;
|
|
|
+using InABox.DynamicGrid;
|
|
|
+using Syncfusion.Windows.Shared;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using System.Windows;
|
|
|
+using System.Windows.Controls;
|
|
|
+using System.Windows.Forms;
|
|
|
+using System.Windows.Media;
|
|
|
+
|
|
|
+namespace PRSDesktop.Panels.Invoices;
|
|
|
+
|
|
|
+public class ProgressClaim : BaseObject
|
|
|
+{
|
|
|
+ public JobScopeLink JobScope { get; set; }
|
|
|
+
|
|
|
+ public double PreviouslyClaimed { get; set; }
|
|
|
+
|
|
|
+ public double PreviouslyClaimedPercent { get; set; }
|
|
|
+
|
|
|
+ [DoubleEditor]
|
|
|
+ public double PercentCost { get; set; }
|
|
|
+
|
|
|
+ [CurrencyEditor(Editable = Editable.Disabled)]
|
|
|
+ public double Cost { get; set; }
|
|
|
+}
|
|
|
+
|
|
|
+public class ProgressClaimGrid : DynamicItemsListGrid<ProgressClaim>
|
|
|
+{
|
|
|
+ private DynamicGridCustomColumnsComponent<ProgressClaim> ColumnsComponent;
|
|
|
+
|
|
|
+ public Guid JobID { get; set; }
|
|
|
+
|
|
|
+ protected override void Init()
|
|
|
+ {
|
|
|
+ base.Init();
|
|
|
+ ColumnsComponent = new(this, nameof(ProgressClaimGrid));
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void DoReconfigure(DynamicGridOptions options)
|
|
|
+ {
|
|
|
+ base.DoReconfigure(options);
|
|
|
+
|
|
|
+ options.SelectColumns = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool _loadedData = false;
|
|
|
+ private void LoadData()
|
|
|
+ {
|
|
|
+ var columns =
|
|
|
+ Columns.None<JobScope>()
|
|
|
+ .Add(x => x.ID)
|
|
|
+ .Add(x => x.Number)
|
|
|
+ .Add(x => x.ExTax).Add(x => x.InvoiceExTax)
|
|
|
+ .Add(x => x.TaxCode.ID).Add(x => x.TaxCode.Rate)
|
|
|
+ .Add(x => x.Description);
|
|
|
+
|
|
|
+ var scopeColumn = new Column<ProgressClaim>(x => x.JobScope).Property + ".";
|
|
|
+ foreach(var column in DataColumns().Where(x => x.Property.StartsWith(scopeColumn)))
|
|
|
+ {
|
|
|
+ columns.Add(column.Property[scopeColumn.Length..]);
|
|
|
+ }
|
|
|
+
|
|
|
+ var scopes = Client.Query<JobScope>(
|
|
|
+ new Filter<JobScope>(x => x.Job.ID).IsEqualTo(JobID)
|
|
|
+ .And(x => x.Status.Approved).IsEqualTo(true), columns)
|
|
|
+ .ToArray<JobScope>();
|
|
|
+
|
|
|
+ var items = new List<ProgressClaim>();
|
|
|
+ foreach(var scope in scopes)
|
|
|
+ {
|
|
|
+ var newItem = new ProgressClaim();
|
|
|
+ newItem.JobScope.CopyFrom(scope);
|
|
|
+ newItem.PreviouslyClaimed = scope.InvoiceExTax;
|
|
|
+ newItem.PreviouslyClaimedPercent = scope.ExTax.IsEffectivelyEqual(0.0) ? 0.0 : scope.InvoiceExTax / scope.ExTax * 100;
|
|
|
+ newItem.PercentCost = newItem.PreviouslyClaimedPercent;
|
|
|
+ newItem.Cost = 0;
|
|
|
+ items.Add(newItem);
|
|
|
+ }
|
|
|
+ Items = items;
|
|
|
+
|
|
|
+ _loadedData = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void Reload(Filters<ProgressClaim> criteria, Columns<ProgressClaim> columns, ref SortOrder<ProgressClaim>? sort, CancellationToken token, Action<CoreTable?, Exception?> action)
|
|
|
+ {
|
|
|
+ LoadData();
|
|
|
+ base.Reload(criteria, columns, ref sort, token, action);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void SaveColumns(DynamicGridColumns columns)
|
|
|
+ {
|
|
|
+ ColumnsComponent.SaveColumns(columns);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void LoadColumnsMenu(ContextMenu menu)
|
|
|
+ {
|
|
|
+ ColumnsComponent.LoadColumnsMenu(menu);
|
|
|
+ }
|
|
|
+
|
|
|
+ public override DynamicGridColumns GenerateColumns()
|
|
|
+ {
|
|
|
+ var columns = new DynamicGridColumns();
|
|
|
+
|
|
|
+ columns.Add<ProgressClaim, string>(x => x.JobScope.Number, 80, "Number", "", Alignment.MiddleCenter);
|
|
|
+ columns.Add<ProgressClaim, string>(x => x.JobScope.Description, 0, "Description", "", Alignment.MiddleCenter);
|
|
|
+ columns.Add<ProgressClaim, double>(x => x.JobScope.ExTax, 100, "Quote $", "", Alignment.MiddleCenter);
|
|
|
+ columns.Add<ProgressClaim, double>(x => x.PreviouslyClaimed, 100, "Prev $", "C2", Alignment.MiddleCenter);
|
|
|
+ columns.Add<ProgressClaim, double>(x => x.PreviouslyClaimedPercent, 80, "Prev %", "", Alignment.MiddleCenter);
|
|
|
+
|
|
|
+ return columns;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override DynamicGridColumns LoadColumns()
|
|
|
+ {
|
|
|
+ var columns = ColumnsComponent.LoadColumns();
|
|
|
+
|
|
|
+ ActionColumns.Clear();
|
|
|
+
|
|
|
+ ActionColumns.Add(new DynamicTemplateColumn(row =>
|
|
|
+ {
|
|
|
+ var item = LoadItem(row);
|
|
|
+ var editor = new DoubleTextBox
|
|
|
+ {
|
|
|
+ VerticalAlignment = VerticalAlignment.Stretch,
|
|
|
+ HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center,
|
|
|
+ HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
|
|
|
+ Background = new SolidColorBrush(Colors.LightYellow),
|
|
|
+ BorderThickness = new Thickness(0.0),
|
|
|
+ MinValue = 0.0,
|
|
|
+ MaxValue = 100.0,
|
|
|
+ Value = item.PercentCost
|
|
|
+ };
|
|
|
+ editor.ValueChanged += (o, e) =>
|
|
|
+ {
|
|
|
+ var maxValue = 100.0;
|
|
|
+ var value = (double?)e.NewValue ?? default;
|
|
|
+ if(value > maxValue)
|
|
|
+ {
|
|
|
+ Dispatcher.BeginInvoke(() => editor.Value = maxValue);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ item.PercentCost = value;
|
|
|
+ item.Cost = item.JobScope.ExTax * item.PercentCost / 100 - item.PreviouslyClaimed;
|
|
|
+ UpdateRow(row, item);
|
|
|
+ InvalidateRow(row);
|
|
|
+ DoChanged();
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ return editor;
|
|
|
+ })
|
|
|
+ {
|
|
|
+ HeaderText = "Cur %",
|
|
|
+ Width = 80
|
|
|
+ });
|
|
|
+ ActionColumns.Add(new DynamicTextColumn(row =>
|
|
|
+ {
|
|
|
+ if (row is null) return null;
|
|
|
+
|
|
|
+ var item = LoadItem(row);
|
|
|
+ return item.Cost;
|
|
|
+ })
|
|
|
+ {
|
|
|
+ Format = "C2",
|
|
|
+ HeaderText = "Claim $",
|
|
|
+ Width = 100
|
|
|
+ });
|
|
|
+
|
|
|
+ return columns;
|
|
|
+ }
|
|
|
+}
|