This commit is contained in:
2022-07-10 22:29:39 +00:00
parent 0f3ad85a45
commit 9bd86523a9
2 changed files with 111 additions and 79 deletions

View File

@@ -35,9 +35,10 @@ namespace AyaNovaQBI
private async void grid_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
var senderGrid = (DataGridView)sender;
if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn )
{
var mm=MisMatches[e.RowIndex];//grid event index is same row as collection index so this saves hassles with rows and accessors
if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn)
{
var mm = MisMatches[e.RowIndex];//grid event index is same row as collection index so this saves hassles with rows and accessors
switch (mm.Reason)
{
@@ -46,86 +47,85 @@ namespace AyaNovaQBI
break;
case util.MisMatchReason.PriceDifferent:
{
#region price problem
FixPriceDifference d = new FixPriceDifference();
d.OptionTitle = mm.Name + "\r\n" +
"Price on work order: " + mm.AyaPrice.ToString("c") + "\r\n" +
"Price in QuickBooks: " + mm.QBPrice.ToString("c");
if (d.ShowDialog() == DialogResult.Cancel) return;
//Fixup price here
switch (d.SelectedResolution)
try
{
case "AYAONCE":
//Add to price override list so price on workorder item part record is used
PartPriceOverrides.Add(mm.WorkOrderItemPartId);
break;
case "QBONCE":
{
//Change the workorder item part price only
//to the quickbooks price, don't touch the default aya part price
Guid WorkorderItemPartID = (Guid)e.Cell.Row.Cells["WorkorderItemPartID"].Value;
Workorder w = Workorder.GetWorkorderByRelative(RootObjectTypes.WorkorderItemPart, WorkorderItemPartID);
foreach (WorkorderItem wi in w.WorkorderItems)
#region price problem
FixPriceDifference d = new FixPriceDifference();
d.OptionTitle = mm.Name + "\r\n" +
"Price on work order: " + mm.AyaPrice.ToString("c") + "\r\n" +
"Price in QuickBooks: " + mm.QBPrice.ToString("c");
if (d.ShowDialog() == DialogResult.Cancel) return;
//Fixup price here
switch (d.SelectedResolution)
{
case "AYAONCE":
//Add to price override list so price on workorder item part record is used
PartPriceOverrides.Add(mm.WorkOrderItemPartId);
break;
case "QBONCE":
{
if (w == null) break;
foreach (WorkorderItemPart wp in wi.Parts)
//Change the workorder item part price only
//to the quickbooks price, don't touch the default aya part price
var a = await util.GetAsync($"workorder/{mm.WorkOrderId}");
WorkOrder w = a.ObjectResponse["data"].ToObject<WorkOrder>();
if (w == null)
throw new Exception($"FixInvoiceProblems:QBONCE:PRICE: WorkOrder with id {mm.WorkOrderId} was not found in AyaNova and may have just been deleted.\r\nUnable to proceed.");
var wip = w.Items.First(z => z.Id == mm.WorkOrderItemId).Parts.First(z => z.Id == mm.WorkOrderItemPartId);
wip.PriceOverride = mm.QBPrice;
await util.PostAsync("workorder", Newtonsoft.Json.JsonConvert.SerializeObject(w));
}
break;
case "CHANGEAYA":
{
//Change this workorder item parts price to the qb price
//and change ayanova's default price for this part to the qb price
Guid WorkorderItemPartID = (Guid)e.Cell.Row.Cells["WorkorderItemPartID"].Value;
Workorder w = Workorder.GetWorkorderByRelative(RootObjectTypes.WorkorderItemPart, WorkorderItemPartID);
Guid PartID = Guid.Empty;
foreach (WorkorderItem wi in w.WorkorderItems)
{
if (wp.ID == WorkorderItemPartID)
if (w == null) break;
foreach (WorkorderItemPart wp in wi.Parts)
{
wp.PriceOverride = (decimal)e.Cell.Row.Cells["QBPrice"].Value;
w.Save();
w = null;
break;
if (wp.ID == WorkorderItemPartID)
{
PartID = wp.PartID;
wp.PriceOverride = (decimal)e.Cell.Row.Cells["QBPrice"].Value;
w.Save();
w = null;
break;
}
}
}
}
}
break;
case "CHANGEAYA":
{
//Change this workorder item parts price to the qb price
//and change ayanova's default price for this part to the qb price
Guid WorkorderItemPartID = (Guid)e.Cell.Row.Cells["WorkorderItemPartID"].Value;
Workorder w = Workorder.GetWorkorderByRelative(RootObjectTypes.WorkorderItemPart, WorkorderItemPartID);
Guid PartID = Guid.Empty;
foreach (WorkorderItem wi in w.WorkorderItems)
{
if (w == null) break;
foreach (WorkorderItemPart wp in wi.Parts)
if (PartID != Guid.Empty)
{
if (wp.ID == WorkorderItemPartID)
{
PartID = wp.PartID;
wp.PriceOverride = (decimal)e.Cell.Row.Cells["QBPrice"].Value;
w.Save();
w = null;
break;
}
Part p = Part.GetItem(PartID);
p.Retail = (decimal)e.Cell.Row.Cells["QBPrice"].Value;
p.Save();
}
}
break;
case "CHANGEQB":
//Change the QB price to use the price on this workorder item part
await util.ChangeQBItemPrice(mm.QBListID, mm.AyaPrice);
break;
}
if (PartID != Guid.Empty)
{
Part p = Part.GetItem(PartID);
p.Retail = (decimal)e.Cell.Row.Cells["QBPrice"].Value;
p.Save();
}
}
break;
case "CHANGEQB":
//Change the QB price to use the price on this workorder item part
await util.ChangeQBItemPrice(mm.QBListID, mm.AyaPrice);
break;
//remove the object from the grid as it's now dealt with
e.Cell.Row.Delete(false);
ChangesMade = true;
//If all done then close up
if (grid.Rows.Count == 0)
this.Close();
}
catch (Exception ex)
{
await util.CrackDisplayAndIntegrationLogException(ex, "FixInvoiceProblems:PRICE");
}
//remove the object from the grid as it's now dealt with
e.Cell.Row.Delete(false);
ChangesMade = true;
//If all done then close up
if (grid.Rows.Count == 0)
this.Close();
#endregion price prob.
}
@@ -283,8 +283,10 @@ namespace AyaNovaQBI
if (grid.Rows.Count == 0)
this.Close();
}
catch (Exception ex)
{
await util.CrackDisplayAndIntegrationLogException(ex, "FixInvoiceProblems:NOTLINKED");
}
finally
{