Files
ayanova7/source/Plugins/AyaNova.Plugin.PTI/FixInvoiceProblems.cs
2018-06-29 19:47:36 +00:00

513 lines
24 KiB
C#

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Infragistics.Win.UltraWinGrid;
using GZTW.AyaNova.BLL;
using System.Text;
namespace AyaNova.PlugIn.PTI
{
/// <summary>
/// Summary description for FixInvoiceProblems.
/// </summary>
public class FixInvoiceProblems : System.Windows.Forms.Form
{
private Infragistics.Win.UltraWinGrid.UltraGrid grid;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public FixInvoiceProblems()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
this.Icon = Resource.PTI16icon;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
Infragistics.Win.Appearance appearance1 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance2 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance3 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance4 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance5 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance6 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance7 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance8 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance9 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance10 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance11 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance12 = new Infragistics.Win.Appearance();
this.grid = new Infragistics.Win.UltraWinGrid.UltraGrid();
((System.ComponentModel.ISupportInitialize)(this.grid)).BeginInit();
this.SuspendLayout();
//
// grid
//
appearance1.BackColor = System.Drawing.SystemColors.Window;
appearance1.BorderColor = System.Drawing.SystemColors.InactiveCaption;
this.grid.DisplayLayout.Appearance = appearance1;
this.grid.DisplayLayout.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
this.grid.DisplayLayout.CaptionVisible = Infragistics.Win.DefaultableBoolean.False;
appearance2.BackColor = System.Drawing.SystemColors.ActiveBorder;
appearance2.BackColor2 = System.Drawing.SystemColors.ControlDark;
appearance2.BackGradientStyle = Infragistics.Win.GradientStyle.Vertical;
appearance2.BorderColor = System.Drawing.SystemColors.Window;
this.grid.DisplayLayout.GroupByBox.Appearance = appearance2;
appearance3.ForeColor = System.Drawing.SystemColors.GrayText;
this.grid.DisplayLayout.GroupByBox.BandLabelAppearance = appearance3;
this.grid.DisplayLayout.GroupByBox.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
this.grid.DisplayLayout.GroupByBox.Hidden = true;
appearance4.BackColor = System.Drawing.SystemColors.ControlLightLight;
appearance4.BackColor2 = System.Drawing.SystemColors.Control;
appearance4.BackGradientStyle = Infragistics.Win.GradientStyle.Horizontal;
appearance4.ForeColor = System.Drawing.SystemColors.GrayText;
this.grid.DisplayLayout.GroupByBox.PromptAppearance = appearance4;
this.grid.DisplayLayout.MaxColScrollRegions = 1;
this.grid.DisplayLayout.MaxRowScrollRegions = 1;
appearance5.BackColor = System.Drawing.SystemColors.Window;
appearance5.ForeColor = System.Drawing.SystemColors.ControlText;
this.grid.DisplayLayout.Override.ActiveCellAppearance = appearance5;
appearance6.BackColor = System.Drawing.SystemColors.Highlight;
appearance6.ForeColor = System.Drawing.SystemColors.HighlightText;
this.grid.DisplayLayout.Override.ActiveRowAppearance = appearance6;
this.grid.DisplayLayout.Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.No;
this.grid.DisplayLayout.Override.AllowDelete = Infragistics.Win.DefaultableBoolean.False;
this.grid.DisplayLayout.Override.AllowUpdate = Infragistics.Win.DefaultableBoolean.False;
this.grid.DisplayLayout.Override.BorderStyleCell = Infragistics.Win.UIElementBorderStyle.Dotted;
this.grid.DisplayLayout.Override.BorderStyleRow = Infragistics.Win.UIElementBorderStyle.Dotted;
appearance7.BackColor = System.Drawing.SystemColors.Window;
this.grid.DisplayLayout.Override.CardAreaAppearance = appearance7;
appearance8.BorderColor = System.Drawing.Color.Silver;
appearance8.TextTrimming = Infragistics.Win.TextTrimming.EllipsisCharacter;
this.grid.DisplayLayout.Override.CellAppearance = appearance8;
this.grid.DisplayLayout.Override.CellClickAction = Infragistics.Win.UltraWinGrid.CellClickAction.EditAndSelectText;
this.grid.DisplayLayout.Override.CellPadding = 0;
appearance9.BackColor = System.Drawing.SystemColors.Control;
appearance9.BackColor2 = System.Drawing.SystemColors.ControlDark;
appearance9.BackGradientAlignment = Infragistics.Win.GradientAlignment.Element;
appearance9.BackGradientStyle = Infragistics.Win.GradientStyle.Horizontal;
appearance9.BorderColor = System.Drawing.SystemColors.Window;
this.grid.DisplayLayout.Override.GroupByRowAppearance = appearance9;
appearance10.TextHAlignAsString = "Left";
this.grid.DisplayLayout.Override.HeaderAppearance = appearance10;
this.grid.DisplayLayout.Override.HeaderClickAction = Infragistics.Win.UltraWinGrid.HeaderClickAction.SortMulti;
this.grid.DisplayLayout.Override.HeaderStyle = Infragistics.Win.HeaderStyle.WindowsXPCommand;
appearance11.BackColor = System.Drawing.SystemColors.Window;
appearance11.BorderColor = System.Drawing.Color.Silver;
this.grid.DisplayLayout.Override.RowAppearance = appearance11;
this.grid.DisplayLayout.Override.RowSelectors = Infragistics.Win.DefaultableBoolean.False;
appearance12.BackColor = System.Drawing.SystemColors.ControlLight;
this.grid.DisplayLayout.Override.TemplateAddRowAppearance = appearance12;
this.grid.DisplayLayout.ScrollBounds = Infragistics.Win.UltraWinGrid.ScrollBounds.ScrollToFill;
this.grid.DisplayLayout.ScrollStyle = Infragistics.Win.UltraWinGrid.ScrollStyle.Immediate;
this.grid.Dock = System.Windows.Forms.DockStyle.Fill;
this.grid.Location = new System.Drawing.Point(0, 0);
this.grid.Name = "grid";
this.grid.Size = new System.Drawing.Size(632, 453);
this.grid.TabIndex = 0;
this.grid.InitializeRow += new Infragistics.Win.UltraWinGrid.InitializeRowEventHandler(this.grid_InitializeRow);
this.grid.ClickCellButton += new Infragistics.Win.UltraWinGrid.CellEventHandler(this.grid_ClickCellButton);
//
// FixInvoiceProblems
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
this.ClientSize = new System.Drawing.Size(632, 453);
this.Controls.Add(this.grid);
this.Name = "FixInvoiceProblems";
this.Text = "FixInvoiceProblems";
this.Load += new System.EventHandler(this.FixInvoiceProblems_Load);
((System.ComponentModel.ISupportInitialize)(this.grid)).EndInit();
this.ResumeLayout(false);
}
#endregion
#region load / class variables
private ArrayList _PartPriceOverrides;
public ArrayList PartPriceOverrides
{
set
{
_PartPriceOverrides=value;
}
}
private ArrayList _MisMatches;
public ArrayList MisMatches
{
set
{
_MisMatches=value;
}
}
private bool _ChangesMade=false;
public bool ChangesMade
{
get
{
return this._ChangesMade;
}
}
private void FixInvoiceProblems_Load(object sender, System.EventArgs e)
{
grid.BeginUpdate();
grid.DisplayLayout.Bands[0].Columns.Add("Fix");
grid.DisplayLayout.Bands[0].Columns["Fix"].Style=Infragistics.Win.UltraWinGrid.ColumnStyle.Button;
this.grid.DataSource=_MisMatches;
grid.DisplayLayout.Bands[0].Columns["RootObjectID"].Hidden=true;
grid.DisplayLayout.Bands[0].Columns["AyaPrice"].Hidden=true;
grid.DisplayLayout.Bands[0].Columns["PTPrice"].Hidden=true;
grid.DisplayLayout.Bands[0].Columns["WorkorderItemPartID"].Hidden=true;
grid.DisplayLayout.Bands[0].Columns["Reason"].Header.Caption="Problem";
grid.DisplayLayout.Bands[0].Columns["PTListID"].Hidden=true;
grid.EndUpdate();
}
#endregion
private void grid_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
{
switch((Util.MisMatchReason)e.Row.Cells["Reason"].Value)
{
case Util.MisMatchReason.NothingToInvoice:
e.Row.ToolTipText = "NOTHING TO INVOICE";
e.Row.Cells["Fix"].Hidden=true;
e.Row.Activation=Activation.Disabled;
break;
case Util.MisMatchReason.PriceDifferent:
e.Row.Cells["Fix"].Value="Fix price";
break;
case Util.MisMatchReason.NotLinkedToPT:
if((RootObjectTypes)e.Row.Cells["ObjectType"].Value==RootObjectTypes.Client)
e.Row.Cells["Fix"].Value="Link / Export";
else
e.Row.Cells["Fix"].Value="Link";
break;
}
}
private void grid_ClickCellButton(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
{
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 Peachtree: " + ((decimal)e.Cell.Row.Cells["PTPrice"].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["PTPrice"].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["PTPrice"].Value;
w.Save();
w = null;
break;
}
}
}
if (PartID != Guid.Empty)
{
Part p = Part.GetItem(PartID);
p.Retail = (decimal)e.Cell.Row.Cells["PTPrice"].Value;
p.Save();
}
}
break;
case "CHANGEQB":
//Change the QB price to use the price on this workorder item part
Util.ChangePTItemPrice(e.Cell.Row.Cells["PTListID"].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.NotLinkedToPT:
{
#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 PTItemName = 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.PTItems = Util.PTClients;
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.SelectedPTItem == null || d.SelectedPTItem == "" || !Util.PTClients.Rows.Contains(d.SelectedPTItem))
return;
PTItemName = d.SelectedPTItemName;
}
break;
case RootObjectTypes.Rate:
d.CanImport = false;
d.PTItems = Util.PTItems;
if (d.ShowDialog() == DialogResult.Cancel) return;
if (d.SelectedPTItem == null || d.SelectedPTItem == "" || !Util.PTItems.Rows.Contains(d.SelectedPTItem))
return;
PTItemName = d.SelectedPTItemName;
break;
case RootObjectTypes.Part:
d.CanImport = false;
d.PTItems = Util.PTItems;
if (d.ShowDialog() == DialogResult.Cancel) return;
if (d.SelectedPTItem == null || d.SelectedPTItem == "" || !Util.PTItems.Rows.Contains(d.SelectedPTItem))
return;
PTItemName = d.SelectedPTItemName;
break;
case RootObjectTypes.WorkorderItemOutsideService:
d.CanImport = false;
d.PTItems = Util.PTItems;
if (d.ShowDialog() == DialogResult.Cancel) return;
if (d.SelectedPTItem == null || d.SelectedPTItem == "" || !Util.PTItems.Rows.Contains(d.SelectedPTItem))
return;
Util.PDat.OutsideServiceChargeAs = d.SelectedPTItem;
//Case 299
Util.PTI.AIObject = Util.PDat.XMLData;
//Util.PTI.AIObject = Util.QDat;
Util.PTI = (Integration)Util.PTI.Save();
Util.PDat.IsDirty = false;
goto REMOVEITEMS;
case RootObjectTypes.WorkorderItemLoan:
d.CanImport = false;
d.PTItems = Util.PTItems;
if (d.ShowDialog() == DialogResult.Cancel) return;
if (d.SelectedPTItem == null || d.SelectedPTItem == "" || !Util.PTItems.Rows.Contains(d.SelectedPTItem))
return;
Util.PDat.WorkorderItemLoanChargeAs = d.SelectedPTItem;
//Case 299
Util.PTI.AIObject = Util.PDat.XMLData;
//Util.PTI.AIObject = Util.QDat;
Util.PTI = (Integration)Util.PTI.Save();
Util.PDat.IsDirty = false;
goto REMOVEITEMS;
case RootObjectTypes.WorkorderItemMiscExpense:
d.CanImport = false;
d.PTItems = Util.PTItems;
if (d.ShowDialog() == DialogResult.Cancel) return;
if (d.SelectedPTItem == null || d.SelectedPTItem == "" || !Util.PTItems.Rows.Contains(d.SelectedPTItem))
return;
Util.PDat.MiscExpenseChargeAs = d.SelectedPTItem;
//Case 299
Util.PTI.AIObject = Util.PDat.XMLData;
//Util.PTI.AIObject = Util.QDat;
Util.PTI = (Integration)Util.PTI.Save();
Util.PDat.IsDirty = false;
goto REMOVEITEMS;
}
//add the new link
IntegrationMap m = Util.PTI.Maps.Add(Util.PTI);
m.RootObjectID = (Guid)e.Cell.Row.Cells["RootObjectID"].Value;
m.RootObjectType = (RootObjectTypes)e.Cell.Row.Cells["ObjectType"].Value;
m.ForeignID = d.SelectedPTItem;
m.Name = PTItemName;
m.LastSync = System.DateTime.Now;
Util.PTI = (Integration)Util.PTI.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;
}
//Changed: 18-Nov-2006, moved from below to switch above
//in order to include nothing to invoice notification
//if ((Util.MisMatchReason)e.Cell.Row.Cells["Reason"].Value == Util.MisMatchReason.PriceDifferent)
//{
//}
//else
//{
//}
}
//--------------------------------------------------------------
}
}