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) private async void grid_CellContentClick(object sender, DataGridViewCellEventArgs e)
{ {
var senderGrid = (DataGridView)sender; var senderGrid = (DataGridView)sender;
if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn ) 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
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) switch (mm.Reason)
{ {
@@ -46,86 +47,85 @@ namespace AyaNovaQBI
break; break;
case util.MisMatchReason.PriceDifferent: case util.MisMatchReason.PriceDifferent:
{ {
#region price problem try
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": #region price problem
//Add to price override list so price on workorder item part record is used FixPriceDifference d = new FixPriceDifference();
PartPriceOverrides.Add(mm.WorkOrderItemPartId); d.OptionTitle = mm.Name + "\r\n" +
break; "Price on work order: " + mm.AyaPrice.ToString("c") + "\r\n" +
case "QBONCE": "Price in QuickBooks: " + mm.QBPrice.ToString("c");
{ if (d.ShowDialog() == DialogResult.Cancel) return;
//Change the workorder item part price only //Fixup price here
//to the quickbooks price, don't touch the default aya part price switch (d.SelectedResolution)
Guid WorkorderItemPartID = (Guid)e.Cell.Row.Cells["WorkorderItemPartID"].Value; {
Workorder w = Workorder.GetWorkorderByRelative(RootObjectTypes.WorkorderItemPart, WorkorderItemPartID); case "AYAONCE":
foreach (WorkorderItem wi in w.WorkorderItems) //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; //Change the workorder item part price only
foreach (WorkorderItemPart wp in wi.Parts) //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; if (wp.ID == WorkorderItemPartID)
w.Save(); {
w = null; PartID = wp.PartID;
break; wp.PriceOverride = (decimal)e.Cell.Row.Cells["QBPrice"].Value;
w.Save();
w = null;
break;
}
} }
} }
}
}
break; if (PartID != Guid.Empty)
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 (wp.ID == WorkorderItemPartID) Part p = Part.GetItem(PartID);
{ p.Retail = (decimal)e.Cell.Row.Cells["QBPrice"].Value;
PartID = wp.PartID; p.Save();
wp.PriceOverride = (decimal)e.Cell.Row.Cells["QBPrice"].Value;
w.Save();
w = null;
break;
}
} }
} }
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) //remove the object from the grid as it's now dealt with
{ e.Cell.Row.Delete(false);
Part p = Part.GetItem(PartID); ChangesMade = true;
p.Retail = (decimal)e.Cell.Row.Cells["QBPrice"].Value; //If all done then close up
p.Save(); if (grid.Rows.Count == 0)
} this.Close();
} }
break; catch (Exception ex)
case "CHANGEQB": {
//Change the QB price to use the price on this workorder item part await util.CrackDisplayAndIntegrationLogException(ex, "FixInvoiceProblems:PRICE");
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();
#endregion price prob. #endregion price prob.
} }
@@ -283,8 +283,10 @@ namespace AyaNovaQBI
if (grid.Rows.Count == 0) if (grid.Rows.Count == 0)
this.Close(); this.Close();
}
catch (Exception ex)
{
await util.CrackDisplayAndIntegrationLogException(ex, "FixInvoiceProblems:NOTLINKED");
} }
finally finally
{ {

View File

@@ -3604,11 +3604,17 @@ namespace AyaNovaQBI
public static string CrackException(Exception ex) public static string CrackException(Exception ex)
{ {
while (ex.InnerException != null) StringBuilder sb = new StringBuilder();
sb.AppendLine($"Exception {ex.Message}");
if (ex.InnerException != null)
{ {
ex = ex.InnerException; while (ex.InnerException != null)
{
ex = ex.InnerException;
sb.AppendLine($"Inner Exception: {ex.Message}");
}
} }
return ex.Message + "\r\n-------TRACE------\r\n" + ex.StackTrace; return $"{sb.ToString()}\r\n-------TRACE------\r\n{ex.StackTrace}";
} }
@@ -3616,7 +3622,7 @@ namespace AyaNovaQBI
public static async Task CrackDisplayAndIntegrationLogException(Exception ex, string methodText = "n/a", string extraText = "n/a") public static async Task CrackDisplayAndIntegrationLogException(Exception ex, string methodText = "n/a", string extraText = "n/a")
{ {
string message = "Exception error\r\nMethod: " + methodText + "\r\nExtra: " + extraText + "\r\n Error:" + CrackException(ex); string message = $"Exception error\r\nMethod: {methodText}\r\nExtra: {extraText}\r\n Error:{CrackException(ex)}";
//Log it so we have it forever in the log //Log it so we have it forever in the log
await IntegrationLog(message); await IntegrationLog(message);
//display it to the user //display it to the user
@@ -5679,6 +5685,8 @@ namespace AyaNovaQBI
public decimal AyaPrice { get; set; } public decimal AyaPrice { get; set; }
public decimal QBPrice { get; set; } public decimal QBPrice { get; set; }
public long WorkOrderItemPartId { get; set; } public long WorkOrderItemPartId { get; set; }
public long WorkOrderItemId { get; set; }
public long WorkOrderId { get; set; }
public string QBListID { get; set; } public string QBListID { get; set; }
public string Fix { get; set; } public string Fix { get; set; }
@@ -5716,6 +5724,8 @@ namespace AyaNovaQBI
AddMisMatch(AyaClientList.FirstOrDefault(z => z.Id == w.CustomerId).Name, AddMisMatch(AyaClientList.FirstOrDefault(z => z.Id == w.CustomerId).Name,
w.CustomerId, w.CustomerId,
AyaType.Customer, AyaType.Customer,
0,
0,
MisMatchReason.NotLinkedToQB, MisMatchReason.NotLinkedToQB,
MisMatches); MisMatches);
} }
@@ -5741,6 +5751,8 @@ namespace AyaNovaQBI
AddMisMatch(AyaServiceRateList.FirstOrDefault(z => z.Id == wl.ServiceRateId).Name, AddMisMatch(AyaServiceRateList.FirstOrDefault(z => z.Id == wl.ServiceRateId).Name,
(long)wl.ServiceRateId, (long)wl.ServiceRateId,
AyaType.ServiceRate, AyaType.ServiceRate,
wi.WorkOrderId,
wi.Id,
MisMatchReason.NotLinkedToQB, MisMatchReason.NotLinkedToQB,
MisMatches); MisMatches);
} }
@@ -5765,6 +5777,8 @@ namespace AyaNovaQBI
AddMisMatch(AyaTravelRateList.FirstOrDefault(z => z.Id == wt.TravelRateId).Name, AddMisMatch(AyaTravelRateList.FirstOrDefault(z => z.Id == wt.TravelRateId).Name,
(long)wt.TravelRateId, (long)wt.TravelRateId,
AyaType.TravelRate, AyaType.TravelRate,
wi.WorkOrderId,
wi.Id,
MisMatchReason.NotLinkedToQB, MisMatchReason.NotLinkedToQB,
MisMatches); ; MisMatches); ;
} }
@@ -5785,6 +5799,8 @@ namespace AyaNovaQBI
AddMisMatch(AyaPartList.FirstOrDefault(z => z.Id == wp.PartId).Name, AddMisMatch(AyaPartList.FirstOrDefault(z => z.Id == wp.PartId).Name,
wp.PartId, wp.PartId,
AyaType.Part, AyaType.Part,
wi.WorkOrderId,
wi.Id,
MisMatchReason.NotLinkedToQB, MisMatchReason.NotLinkedToQB,
MisMatches); MisMatches);
@@ -5821,6 +5837,8 @@ namespace AyaNovaQBI
AddMisMatch($"WO: {w.Serial}{disco} Part: {ayaPartRecord.Name}", AddMisMatch($"WO: {w.Serial}{disco} Part: {ayaPartRecord.Name}",
wp.PartId, wp.PartId,
AyaType.Part, AyaType.Part,
wi.WorkOrderId,
wi.Id,
MisMatchReason.PriceDifferent, MisMatchReason.PriceDifferent,
MisMatches, MisMatches,
qbPrice, qbPrice,
@@ -5851,6 +5869,8 @@ namespace AyaNovaQBI
AddMisMatch("Outside services - can't be billed as not yet mapped to a QB Charge item\r\nSet in Tools->Preferences", AddMisMatch("Outside services - can't be billed as not yet mapped to a QB Charge item\r\nSet in Tools->Preferences",
0, 0,
AyaType.WorkOrderItemOutsideService, AyaType.WorkOrderItemOutsideService,
wi.WorkOrderId,
wi.Id,
MisMatchReason.NotLinkedToQB, MisMatchReason.NotLinkedToQB,
MisMatches); MisMatches);
@@ -5881,6 +5901,8 @@ namespace AyaNovaQBI
AddMisMatch("Workorder item loan - can't be billed as not yet mapped to a QB Charge item\r\nSet in Tools->Preferences", AddMisMatch("Workorder item loan - can't be billed as not yet mapped to a QB Charge item\r\nSet in Tools->Preferences",
0, 0,
AyaType.WorkOrderItemLoan, AyaType.WorkOrderItemLoan,
wi.WorkOrderId,
wi.Id,
MisMatchReason.NotLinkedToQB, MisMatchReason.NotLinkedToQB,
MisMatches); MisMatches);
break; break;
@@ -5908,6 +5930,8 @@ namespace AyaNovaQBI
AddMisMatch("Workorder item expense - can't be billed as not yet mapped to a QB Charge item\r\nSet in Tools->Preferences", AddMisMatch("Workorder item expense - can't be billed as not yet mapped to a QB Charge item\r\nSet in Tools->Preferences",
0, 0,
AyaType.WorkOrderItemExpense, AyaType.WorkOrderItemExpense,
wi.WorkOrderId,
wi.Id,
MisMatchReason.NotLinkedToQB, MisMatchReason.NotLinkedToQB,
MisMatches); MisMatches);
break; break;
@@ -5929,6 +5953,8 @@ namespace AyaNovaQBI
AddMisMatch("WO: " + w.Serial + " - Nothing chargeable on it, will not be invoiced", AddMisMatch("WO: " + w.Serial + " - Nothing chargeable on it, will not be invoiced",
0, 0,
AyaType.NoType, AyaType.NoType,
0,
0,
MisMatchReason.NothingToInvoice, MisMatchReason.NothingToInvoice,
MisMatches); MisMatches);
@@ -5941,14 +5967,16 @@ namespace AyaNovaQBI
private static void AddMisMatch(string Name, long ObjectId, AyaType ObjectType, MisMatchReason Reason, List<MisMatch> Mismatches) private static void AddMisMatch(string Name, long ObjectId, AyaType ObjectType, long WorkOrderId, long WorkOrderItemId, MisMatchReason Reason, List<MisMatch> Mismatches)
{ {
AddMisMatch(Name, ObjectId, ObjectType, Reason, Mismatches, 0m, 0m, 0, ""); AddMisMatch(Name, ObjectId, ObjectType, WorkOrderId, WorkOrderItemId, Reason, Mismatches, 0m, 0m, 0, "");
} }
private static void AddMisMatch(string Name, private static void AddMisMatch(string Name,
long ObjectId, long ObjectId,
AyaType ObjectType, AyaType ObjectType,
long WorkOrderId,
long WorkOrderItemId,
MisMatchReason Reason, MisMatchReason Reason,
List<MisMatch> Mismatches, List<MisMatch> Mismatches,
decimal QBPrice, decimal QBPrice,
@@ -6011,6 +6039,8 @@ namespace AyaNovaQBI
AyaPrice = AyaPrice, AyaPrice = AyaPrice,
QBPrice = QBPrice, QBPrice = QBPrice,
WorkOrderItemPartId = WorkOrderItemPartId, WorkOrderItemPartId = WorkOrderItemPartId,
WorkOrderItemId=WorkOrderItemId,
WorkOrderId=WorkOrderId,
QBListID = QBListID, QBListID = QBListID,
Fix = theFix Fix = theFix
}); });