This commit is contained in:
@@ -215,6 +215,7 @@ namespace AyaNovaQBI
|
|||||||
private DataTable _GridTable = null;
|
private DataTable _GridTable = null;
|
||||||
private List<util.MisMatch> _MisMatches = new List<util.MisMatch>();
|
private List<util.MisMatch> _MisMatches = new List<util.MisMatch>();
|
||||||
private List<long> _PartPriceOverrides = new List<long>();
|
private List<long> _PartPriceOverrides = new List<long>();
|
||||||
|
private List<WorkOrderAccountingListItem> _GridTableSourceList = new List<WorkOrderAccountingListItem>();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initialize invoices dataset
|
/// Initialize invoices dataset
|
||||||
/// from scratch. If a previous
|
/// from scratch. If a previous
|
||||||
@@ -247,12 +248,13 @@ namespace AyaNovaQBI
|
|||||||
_GridTable.Clear();
|
_GridTable.Clear();
|
||||||
}
|
}
|
||||||
_MisMatches.Clear();
|
_MisMatches.Clear();
|
||||||
|
_GridTableSourceList.Clear();
|
||||||
|
|
||||||
//[HttpGet("accounting-list-billable/{workOrderStatusId}")]
|
//[HttpGet("accounting-list-billable/{workOrderStatusId}")]
|
||||||
var r = await util.GetAsync($"workorder/accounting-list-billable/{util.QDat.PreWOStatus}");
|
var r = await util.GetAsync($"workorder/accounting-list-billable/{util.QDat.PreWOStatus}");
|
||||||
var v = r.ObjectResponse["data"].ToObject<List<WorkOrderAccountingListItem>>();
|
_GridTableSourceList = r.ObjectResponse["data"].ToObject<List<WorkOrderAccountingListItem>>();
|
||||||
|
|
||||||
foreach (WorkOrderAccountingListItem z in v)
|
foreach (WorkOrderAccountingListItem z in _GridTableSourceList)
|
||||||
{
|
{
|
||||||
w.Step = "WO: " + z.Serial;
|
w.Step = "WO: " + z.Serial;
|
||||||
DataRow row = _GridTable.NewRow();
|
DataRow row = _GridTable.NewRow();
|
||||||
@@ -291,21 +293,102 @@ namespace AyaNovaQBI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private async Task InvoiceSelected(bool bOneWoPerInvoice)
|
private async Task InvoiceSelected(bool bOneWoPerInvoice)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (grid.SelectedRows.Count < 1)
|
if (grid.SelectedRows.Count < 1)
|
||||||
{
|
{
|
||||||
MessageBox.Show("There are no Work order rows selected\r\nSelect one or more rows to invoice");
|
MessageBox.Show("There are no Work order rows selected\r\nSelect one or more rows to invoice");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//build a list of selected work orders ordered by customer and that have linked=true to process here so that they are in customer order and only good ones that can be billed
|
||||||
|
|
||||||
|
List<WorkOrderAccountingListItem> InvoiceableWorkOrdersList = new List<WorkOrderAccountingListItem>();
|
||||||
|
foreach (DataGridViewRow r in grid.SelectedRows)
|
||||||
|
{
|
||||||
|
if ((bool)r.Cells["Linked"].Value == true)
|
||||||
|
{
|
||||||
|
InvoiceableWorkOrdersList.Add(_GridTableSourceList.First(z => z.Id == (long)r.Cells["id"].Value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (InvoiceableWorkOrdersList.Count < 1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("There are no invoiceable Work order rows selected\r\nSelect one or more rows to invoice");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//We now have a list of work orders from grid selections ready to be invoiced and ordered by customer for grouping purposes
|
||||||
|
|
||||||
//An array list to hold the guid's of workorders being invoiced
|
//An array list to hold the guid's of workorders being invoiced
|
||||||
List<long> al = new List<long>();
|
List<long> al = new List<long>();
|
||||||
this.Refresh();
|
|
||||||
Cursor.Current = Cursors.WaitCursor;
|
Cursor.Current = Cursors.WaitCursor;
|
||||||
ArrayList alErrors = new ArrayList();
|
ArrayList alErrors = new ArrayList();
|
||||||
Waiting w = new Waiting();
|
Waiting w = new Waiting();
|
||||||
w.Show();
|
w.Show();
|
||||||
w.Ops = "Invoicing to QuickBooks...";
|
w.Ops = "Invoicing to QuickBooks...";
|
||||||
|
|
||||||
|
|
||||||
|
if (bOneWoPerInvoice)
|
||||||
|
{
|
||||||
|
foreach(var invwo in InvoiceableWorkOrdersList)
|
||||||
|
{
|
||||||
|
al.Add(invwo.Id);
|
||||||
|
w.Step = "Invoicing single workorder ";
|
||||||
|
await util.Invoice(al, alErrors);
|
||||||
|
al.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
/*
|
||||||
|
var results = persons.GroupBy(
|
||||||
|
p => p.PersonId,
|
||||||
|
p => p.car,
|
||||||
|
(key, g) => new { PersonId = key, Cars = g.ToList() });
|
||||||
|
*/
|
||||||
|
var grouped = InvoiceableWorkOrdersList.GroupBy(z => z.CustomerId, z => z.Id, (Key, g) => new { CustomerId=Key, WorkOrders=g.ToList() });
|
||||||
|
foreach(var vv in grouped)
|
||||||
|
{
|
||||||
|
string sss=vv.CustomerId.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//long currentCustomerId = -1;
|
||||||
|
//int CountOfInvoiceableWorkOrders = InvoiceableWorkOrdersList.Count;
|
||||||
|
//for (int i = 0; i < CountOfInvoiceableWorkOrders; i++)
|
||||||
|
//{
|
||||||
|
// bool finalRecord = CountOfInvoiceableWorkOrders - 1 == i;
|
||||||
|
// WorkOrderAccountingListItem invwo = InvoiceableWorkOrdersList[i];
|
||||||
|
// if (bOneWoPerInvoice)
|
||||||
|
// {
|
||||||
|
// al.Add(invwo.Id);
|
||||||
|
// w.Step = "Invoicing single workorder ";
|
||||||
|
// await util.Invoice(al, alErrors);
|
||||||
|
// //and clear al workorders list
|
||||||
|
// al.Clear();
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// //change of customer or last one in loop?
|
||||||
|
// if ((finalRecord || invwo.CustomerId != currentCustomerId) && al.Count > 0)
|
||||||
|
// {
|
||||||
|
// //invoice out this batch
|
||||||
|
// w.Step = "Batch invoicing " + al.Count.ToString() + ((al.Count > 1) ? " Work Orders" : " Work Order");
|
||||||
|
// await util.Invoice(al, alErrors);
|
||||||
|
// al.Clear();
|
||||||
|
// }
|
||||||
|
// currentCustomerId = invwo.CustomerId;
|
||||||
|
// al.Add(invwo.Id);
|
||||||
|
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
//work through selected items top to bottom
|
//work through selected items top to bottom
|
||||||
foreach (DataGridViewRow r in grid.SelectedRows)
|
foreach (DataGridViewRow r in grid.SelectedRows)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user