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

@@ -37,6 +37,7 @@ namespace AyaNovaQBI
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
switch (mm.Reason)
@@ -45,6 +46,8 @@ namespace AyaNovaQBI
MessageBox.Show("Nothing to invoice");
break;
case util.MisMatchReason.PriceDifferent:
{
try
{
#region price problem
FixPriceDifference d = new FixPriceDifference();
@@ -63,22 +66,14 @@ namespace AyaNovaQBI
{
//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)
{
if (w == null) break;
foreach (WorkorderItemPart wp in wi.Parts)
{
if (wp.ID == WorkorderItemPartID)
{
wp.PriceOverride = (decimal)e.Cell.Row.Cells["QBPrice"].Value;
w.Save();
w = null;
break;
}
}
}
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;
@@ -126,6 +121,11 @@ namespace AyaNovaQBI
//If all done then close up
if (grid.Rows.Count == 0)
this.Close();
}
catch (Exception ex)
{
await util.CrackDisplayAndIntegrationLogException(ex, "FixInvoiceProblems:PRICE");
}
#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
{

View File

@@ -3603,12 +3603,18 @@ namespace AyaNovaQBI
#region Exception helper
public static string CrackException(Exception ex)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine($"Exception {ex.Message}");
if (ex.InnerException != null)
{
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")
{
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
await IntegrationLog(message);
//display it to the user
@@ -5679,6 +5685,8 @@ namespace AyaNovaQBI
public decimal AyaPrice { get; set; }
public decimal QBPrice { get; set; }
public long WorkOrderItemPartId { get; set; }
public long WorkOrderItemId { get; set; }
public long WorkOrderId { get; set; }
public string QBListID { get; set; }
public string Fix { get; set; }
@@ -5716,6 +5724,8 @@ namespace AyaNovaQBI
AddMisMatch(AyaClientList.FirstOrDefault(z => z.Id == w.CustomerId).Name,
w.CustomerId,
AyaType.Customer,
0,
0,
MisMatchReason.NotLinkedToQB,
MisMatches);
}
@@ -5741,6 +5751,8 @@ namespace AyaNovaQBI
AddMisMatch(AyaServiceRateList.FirstOrDefault(z => z.Id == wl.ServiceRateId).Name,
(long)wl.ServiceRateId,
AyaType.ServiceRate,
wi.WorkOrderId,
wi.Id,
MisMatchReason.NotLinkedToQB,
MisMatches);
}
@@ -5765,6 +5777,8 @@ namespace AyaNovaQBI
AddMisMatch(AyaTravelRateList.FirstOrDefault(z => z.Id == wt.TravelRateId).Name,
(long)wt.TravelRateId,
AyaType.TravelRate,
wi.WorkOrderId,
wi.Id,
MisMatchReason.NotLinkedToQB,
MisMatches); ;
}
@@ -5785,6 +5799,8 @@ namespace AyaNovaQBI
AddMisMatch(AyaPartList.FirstOrDefault(z => z.Id == wp.PartId).Name,
wp.PartId,
AyaType.Part,
wi.WorkOrderId,
wi.Id,
MisMatchReason.NotLinkedToQB,
MisMatches);
@@ -5821,6 +5837,8 @@ namespace AyaNovaQBI
AddMisMatch($"WO: {w.Serial}{disco} Part: {ayaPartRecord.Name}",
wp.PartId,
AyaType.Part,
wi.WorkOrderId,
wi.Id,
MisMatchReason.PriceDifferent,
MisMatches,
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",
0,
AyaType.WorkOrderItemOutsideService,
wi.WorkOrderId,
wi.Id,
MisMatchReason.NotLinkedToQB,
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",
0,
AyaType.WorkOrderItemLoan,
wi.WorkOrderId,
wi.Id,
MisMatchReason.NotLinkedToQB,
MisMatches);
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",
0,
AyaType.WorkOrderItemExpense,
wi.WorkOrderId,
wi.Id,
MisMatchReason.NotLinkedToQB,
MisMatches);
break;
@@ -5929,6 +5953,8 @@ namespace AyaNovaQBI
AddMisMatch("WO: " + w.Serial + " - Nothing chargeable on it, will not be invoiced",
0,
AyaType.NoType,
0,
0,
MisMatchReason.NothingToInvoice,
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,
long ObjectId,
AyaType ObjectType,
long WorkOrderId,
long WorkOrderItemId,
MisMatchReason Reason,
List<MisMatch> Mismatches,
decimal QBPrice,
@@ -6011,6 +6039,8 @@ namespace AyaNovaQBI
AyaPrice = AyaPrice,
QBPrice = QBPrice,
WorkOrderItemPartId = WorkOrderItemPartId,
WorkOrderItemId=WorkOrderItemId,
WorkOrderId=WorkOrderId,
QBListID = QBListID,
Fix = theFix
});