302 lines
16 KiB
C#
302 lines
16 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace AyaNovaQBI
|
|
{
|
|
public partial class FixInvoiceProblems : Form
|
|
{
|
|
public List<util.MisMatch> MisMatches { get; set; }
|
|
public List<long> PartPriceOverrides { get; set; }
|
|
public bool ChangesMade { get; set; } = false;
|
|
public FixInvoiceProblems()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void FixInvoiceProblems_Load(object sender, EventArgs e)
|
|
{
|
|
grid.DataSource = MisMatches;
|
|
btnOK.Text = util.AyaTranslations["OK"];
|
|
}
|
|
|
|
private void btnOK_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult = DialogResult.OK;
|
|
Close();
|
|
}
|
|
|
|
private void grid_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
var senderGrid = (DataGridView)sender;
|
|
|
|
if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn )
|
|
{
|
|
//MessageBox.Show($"Row was {e.RowIndex}");
|
|
|
|
switch ((Util.MisMatchReason)e.Cell.Row.Cells["Reason"].Value)
|
|
{
|
|
case Util.MisMatchReason.NothingToInvoice:
|
|
MessageBox.Show("Nothing to invoice");
|
|
break;
|
|
case Util.MisMatchReason.PriceDifferent:
|
|
{
|
|
#region price problem
|
|
FixPriceDifference d = new FixPriceDifference();
|
|
d.PriceDescription = e.Cell.Row.Cells["Name"].Value.ToString() + "\r\n" +
|
|
"Price on work order: " + ((decimal)e.Cell.Row.Cells["AyaPrice"].Value).ToString("c") + "\r\n" +
|
|
"Price in QuickBooks: " + ((decimal)e.Cell.Row.Cells["QBPrice"].Value).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((Guid)e.Cell.Row.Cells["WorkorderItemPartID"].Value);
|
|
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)
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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 (wp.ID == WorkorderItemPartID)
|
|
{
|
|
PartID = wp.PartID;
|
|
wp.PriceOverride = (decimal)e.Cell.Row.Cells["QBPrice"].Value;
|
|
w.Save();
|
|
w = null;
|
|
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
|
|
Util.ChangeQBItemPrice(e.Cell.Row.Cells["QBListID"].Value.ToString(), (decimal)e.Cell.Row.Cells["AyaPrice"].Value);
|
|
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.
|
|
}
|
|
break;
|
|
case Util.MisMatchReason.NotLinkedToQB:
|
|
{
|
|
#region link problem
|
|
LinkOrImportAyaObject d = new LinkOrImportAyaObject();
|
|
try
|
|
{
|
|
d.AyaItem = e.Cell.Row.Cells["Name"].Value.ToString();
|
|
//Default for an import
|
|
//otherwise in a link is just reset to the qb item name selected
|
|
string QBItemName = e.Cell.Row.Cells["Name"].Value.ToString();
|
|
|
|
//Attempt a link or import
|
|
//in any case of failure or new link not required
|
|
//bails inside switch
|
|
switch ((RootObjectTypes)e.Cell.Row.Cells["ObjectType"].Value)
|
|
{
|
|
case RootObjectTypes.Client:
|
|
d.CanImport = true;
|
|
d.QBItems = Util.QBClients;
|
|
if (d.ShowDialog() == DialogResult.Cancel) return;
|
|
if (d.Choice == "IMPORT")
|
|
{
|
|
ArrayList alErrors = new ArrayList();
|
|
Util.ImportAyaClient((Guid)e.Cell.Row.Cells["RootObjectID"].Value, alErrors);
|
|
//display errors if any
|
|
if (alErrors.Count != 0)
|
|
{
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.Append("Import failed with error:\r\n\r\n");
|
|
foreach (object o in alErrors)
|
|
{
|
|
sb.Append((string)o);
|
|
sb.Append("\r\n************\r\n");
|
|
|
|
}
|
|
|
|
CopyableMessageBox cb = new CopyableMessageBox(sb.ToString());
|
|
cb.ShowDialog();
|
|
cb.Dispose();
|
|
return;
|
|
|
|
}
|
|
else
|
|
goto REMOVEITEMS;
|
|
}
|
|
else
|
|
{
|
|
//it's a link by default
|
|
if (d.SelectedQBItem == null || d.SelectedQBItem == "" || !Util.QBClients.Rows.Contains(d.SelectedQBItem))
|
|
return;
|
|
QBItemName = d.SelectedQBItemName;
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
case RootObjectTypes.Rate:
|
|
d.CanImport = false;
|
|
d.QBItems = Util.QBItems;
|
|
if (d.ShowDialog() == DialogResult.Cancel) return;
|
|
|
|
if (d.SelectedQBItem == null || d.SelectedQBItem == "" || !Util.QBItems.Rows.Contains(d.SelectedQBItem))
|
|
return;
|
|
QBItemName = d.SelectedQBItemName;
|
|
break;
|
|
case RootObjectTypes.Part:
|
|
d.CanImport = false;
|
|
d.QBItems = Util.QBItems;
|
|
if (d.ShowDialog() == DialogResult.Cancel) return;
|
|
|
|
if (d.SelectedQBItem == null || d.SelectedQBItem == "" || !Util.QBItems.Rows.Contains(d.SelectedQBItem))
|
|
return;
|
|
QBItemName = d.SelectedQBItemName;
|
|
|
|
break;
|
|
case RootObjectTypes.WorkorderItemOutsideService:
|
|
d.CanImport = false;
|
|
d.QBItems = Util.QBItems;
|
|
if (d.ShowDialog() == DialogResult.Cancel) return;
|
|
|
|
|
|
if (d.SelectedQBItem == null || d.SelectedQBItem == "" || !Util.QBItems.Rows.Contains(d.SelectedQBItem))
|
|
return;
|
|
|
|
Util.QDat.OutsideServiceChargeAs = d.SelectedQBItem;
|
|
|
|
//Case 299
|
|
Util.QBI.AIObject = Util.QDat.XMLData;
|
|
//Util.QBI.AIObject = Util.QDat;
|
|
|
|
Util.QBI = (Integration)Util.QBI.Save();
|
|
Util.QDat.IsDirty = false;
|
|
goto REMOVEITEMS;
|
|
|
|
|
|
case RootObjectTypes.WorkorderItemLoan:
|
|
d.CanImport = false;
|
|
d.QBItems = Util.QBItems;
|
|
if (d.ShowDialog() == DialogResult.Cancel) return;
|
|
|
|
|
|
if (d.SelectedQBItem == null || d.SelectedQBItem == "" || !Util.QBItems.Rows.Contains(d.SelectedQBItem))
|
|
return;
|
|
|
|
Util.QDat.WorkorderItemLoanChargeAs = d.SelectedQBItem;
|
|
//Case 299
|
|
Util.QBI.AIObject = Util.QDat.XMLData;
|
|
//Util.QBI.AIObject = Util.QDat;
|
|
Util.QBI = (Integration)Util.QBI.Save();
|
|
Util.QDat.IsDirty = false;
|
|
goto REMOVEITEMS;
|
|
|
|
|
|
case RootObjectTypes.WorkorderItemMiscExpense:
|
|
d.CanImport = false;
|
|
d.QBItems = Util.QBItems;
|
|
if (d.ShowDialog() == DialogResult.Cancel) return;
|
|
|
|
|
|
if (d.SelectedQBItem == null || d.SelectedQBItem == "" || !Util.QBItems.Rows.Contains(d.SelectedQBItem))
|
|
return;
|
|
|
|
Util.QDat.MiscExpenseChargeAs = d.SelectedQBItem;
|
|
//Case 299
|
|
Util.QBI.AIObject = Util.QDat.XMLData;
|
|
//Util.QBI.AIObject = Util.QDat;
|
|
Util.QBI = (Integration)Util.QBI.Save();
|
|
Util.QDat.IsDirty = false;
|
|
goto REMOVEITEMS;
|
|
|
|
|
|
}
|
|
|
|
|
|
//add the new link
|
|
IntegrationMap m = Util.QBI.Maps.Add(Util.QBI);
|
|
m.RootObjectID = (Guid)e.Cell.Row.Cells["RootObjectID"].Value;
|
|
m.RootObjectType = (RootObjectTypes)e.Cell.Row.Cells["ObjectType"].Value;
|
|
m.ForeignID = d.SelectedQBItem;
|
|
m.Name = QBItemName;
|
|
m.LastSync = System.DateTime.Now;
|
|
Util.QBI = (Integration)Util.QBI.Save();
|
|
|
|
REMOVEITEMS:
|
|
|
|
//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();
|
|
|
|
|
|
|
|
}
|
|
finally
|
|
{
|
|
d.Dispose();
|
|
}
|
|
#endregion link problem
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}//eof
|
|
}//eoc
|
|
}//eons
|