| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- using System;
- using System.Linq;
- using System.Threading;
- using System.Windows;
- using System.Windows.Controls;
- using Comal.Classes;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- using PRS.Shared;
- using PRSDesktop.Utils;
- namespace PRSDesktop
- {
- internal class InvoiceLineGrid : DynamicDataGrid<InvoiceLine>
- {
- private Job? _job;
- public Job? Job
- {
- get => _job;
- set
- {
- _job = value;
- Reconfigure();
- }
- }
- protected override void Init()
- {
- base.Init();
- AddEditButton("Calculate", PRSDesktop.Resources.costcentre.AsBitmapImage(), CalculateLines,
- isVisible: options => Job is not null && Job.JobType == JobType.Service);
- }
- protected override void DoReconfigure(DynamicGridOptions options)
- {
- base.DoReconfigure(options);
- options.RecordCount = true;
- options.AddRows = true;
- options.DeleteRows = true;
- options.EditRows = true;
- options.SelectColumns = true;
- options.MultiSelect = true;
- }
- public Invoice? Invoice { get; set; }
- private bool CalculateLines(Button sender, CoreRow[] rows)
- {
- if(Invoice is null)
- {
- MessageBox.Show("Please Select or Create an Invoice First!");
- return false;
- }
- InvoiceCalculationSelector selector = new InvoiceCalculationSelector()
- {
- TimeCalculation = InvoiceTimeCalculation.Activity,
- MaterialCalculation = InvoiceMaterialCalculation.Product,
- ExpensesCalculation = InvoiceExpensesCalculation.Detailed
- };
- if (selector.ShowDialog() == true)
- {
- var time = selector.TimeCalculation;
- var materials = selector.MaterialCalculation;
- var expenses = selector.ExpensesCalculation;
- Progress.ShowModal("Calculating Invoice", progress => InvoiceUtilities.GenerateInvoiceLines(Invoice.ID, time, materials, expenses, progress));
- return true;
- }
- else
- {
- return false;
- }
- }
- protected override void Reload(
- Filters<InvoiceLine> criteria, Columns<InvoiceLine> columns, ref SortOrder<InvoiceLine>? sort,
- CancellationToken token, Action<CoreTable?, Exception?> action)
- {
- if(Invoice is null)
- {
- criteria.Add(Filter.None<InvoiceLine>());
- }
- else
- {
- criteria.Add(Filter<InvoiceLine>.Where(x => x.InvoiceLink.ID).IsEqualTo(Invoice.ID));
- }
- base.Reload(criteria, columns, ref sort, token, action);
- }
- protected override bool CanCreateItems()
- {
- return Invoice is not null;
- }
- public override InvoiceLine CreateItem()
- {
- var result = base.CreateItem();
- if(Invoice is not null)
- {
- result.InvoiceLink.CopyFrom(Invoice);
- result.SellGL.ID = Invoice.SellGL.ID;
- }
- return result;
- }
- }
- }
|