This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
@@ -3604,11 +3604,17 @@ namespace AyaNovaQBI
|
||||
|
||||
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")
|
||||
{
|
||||
|
||||
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
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user