using System; using System.Collections.Generic; using System.Linq; using System.Text; using AyaNova.PlugIn; using System.Windows.Forms; using GZTW.AyaNova.BLL; using System.Threading; using System.Collections; namespace AyaNova.PlugIn.QBI { class QBIPlugin : IAyaNovaPlugin { private static bool bLicensed = false; private static bool bPFCDone = false; private static List ObjectsWeCanDealWith = null; #region IAyaNovaPlugin Members #region Interface Properties public string PluginName { get { return "AyaNova QBI"; } } public Guid PluginID { get { return new Guid("{0F8AC430-D304-4726-8361-3FDA33233E68}"); } } public System.Drawing.Image PluginSmallIcon { get { return Resource.QBI16; } } public System.Drawing.Image PluginLargeIcon { get { return Resource.QBI32; } } public string PluginVersion { get { return "7.6 (patch 3)"; }//if patch then 7.3 (patch 1) etc } public string About { get { return "AyaNova QBI plugin"; } } public System.Resources.ResourceManager AyaNovaResourceManager { set { Util.AyaResource = value; } } #endregion interface props #region Initialization and close public bool Initialize(Version AyaNovaVersion, LocalizedTextTable localizedText) { Util.LocaleText = localizedText; //case 1841 //if (AyaBizUtils.Trial) //{ // //case 1031 // //MessageBox.Show("AyaNova QBI can not be used with a trial AyaNova database"); // return false; //} //case 1590 // bLicensed = (!string.IsNullOrEmpty(AyaBizUtils.PluginLicensedVersion("QBI - QuickBooks interface"))); //case 2094 bLicensed = AyaBizUtils.PluginAllowed("QBI - QuickBooks interface", AyaNova.PlugIn.QBI.Timestamp.BuildAt); if (!bLicensed && AyaBizUtils.PluginTooNew("QBI - QuickBooks interface", AyaNova.PlugIn.QBI.Timestamp.BuildAt)) { MessageBox.Show( "NOT LICENSED!\r\n\r\nThis QBI plugin was built " + AyaNova.PlugIn.QBI.Timestamp.BuildAt.ToString() + "\r\n" + "but your license subscription for it ended " + AyaBizUtils.PluginSubscriptionDate("QBI - QuickBooks interface").ToString() + "\r\n" + "\r\nDowngrade back to your previous version or purchase a subscription to use this plugin."); return false; } if (AyaNovaVersion.Major != 7) { MessageBox.Show("This AyaNovaQBI plugin requires AyaNova version 7"); return false; } Util.GlobalSettings = AyaBizUtils.GlobalSettings; ObjectsWeCanDealWith = new List(); //case 976 keep this if not licensed //so we can show a license required message when they take the option ObjectsWeCanDealWith.Add(RootObjectTypes.Nothing); ObjectsWeCanDealWith.Add(RootObjectTypes.Client); ObjectsWeCanDealWith.Add(RootObjectTypes.Part); return true; } public void Close() { ; } #endregion init and close #region Show menu? public bool SingleObjectMenuShow(RootObjectTypes objectType) { return (ObjectsWeCanDealWith.Contains(objectType)); } public bool MultipleObjectsMenuShow(RootObjectTypes objectType) { return (ObjectsWeCanDealWith.Contains(objectType)); } #endregion Show menu #region menu options /// /// SINGLE OBJECT /// /// /// /// public List SingleObjectMenuOptions(RootObjectTypes objectType, object ayaNovaObject) { if (!ObjectsWeCanDealWith.Contains(objectType)) return null; if (!bLicensed) { MessageBox.Show("An AyaNova QBI license is required to use this QuickBooks integration plugin\r\n"); return null; } if (!DoPFC()) return null; List list = new List(); switch (objectType) { case RootObjectTypes.Nothing: list.Add(new AyaNovaPluginMenuItem("MAIN", "QBI Main", Resource.QBI32, Resource.QBI16)); if (bPFCDone) list.Add(new AyaNovaPluginMenuItem("RESCANQB", "Refresh Quick Books connection", null, null)); break; case RootObjectTypes.Client: if (Util.IsLinked(((Client)ayaNovaObject).ID)) { list.Add(new AyaNovaPluginMenuItem("CLIENTSYNCFROMQB", "Refresh AyaNova record", null, null)); list.Add(new AyaNovaPluginMenuItem("CLIENTSYNCFROMAYA", "Refresh QuickBooks record", null, null)); } else { list.Add(new AyaNovaPluginMenuItem("CLIENTEXPORTTOQB", "Export to QuickBooks", null, null)); } break; case RootObjectTypes.Part: if (Util.IsLinked(((Part)ayaNovaObject).ID)) { list.Add(new AyaNovaPluginMenuItem("PARTSYNCFROMQB", "Refresh AyaNova record", null, null)); list.Add(new AyaNovaPluginMenuItem("PARTSYNCFROMAYA", "Refresh QuickBooks record", null, null)); } else { list.Add(new AyaNovaPluginMenuItem("PARTEXPORTTOQB", "Export to QuickBooks", null, null)); } break; } return list; } /// /// LIST OBJECTS /// /// /// public List MultipleObjectsMenuOptions(RootObjectTypes objectType) { if (!ObjectsWeCanDealWith.Contains(objectType)) return null; if (!bLicensed) { MessageBox.Show("An AyaNova QBI license is required to use this QuickBooks integration plugin\r\n"); return null; } if (!DoPFC()) return null; List list = new List(); switch (objectType) { case RootObjectTypes.Client: list.Add(new AyaNovaPluginMenuItem("CLIENTSYNCFROMQB", "Refresh AyaNova record", null, null)); list.Add(new AyaNovaPluginMenuItem("CLIENTSYNCFROMAYA", "Refresh QuickBooks record", null, null)); list.Add(new AyaNovaPluginMenuItem("CLIENTEXPORTTOQB", "Export unlinked items to Quickbooks", null, null)); break; case RootObjectTypes.Part: list.Add(new AyaNovaPluginMenuItem("PARTSYNCFROMQB", "Refresh AyaNova record", null, null)); list.Add(new AyaNovaPluginMenuItem("PARTSYNCFROMAYA", "Refresh QuickBooks record", null, null)); list.Add(new AyaNovaPluginMenuItem("PARTEXPORTTOQB", "Export unlinked items to Quickbooks", null, null)); break; } if (list.Count > 0) return list; else return null; } #endregion menu options #region Commands public bool CommandSelectedForList(string commandKey, RootObjectTypes objectType, List objectIDList, object listObject) { if (!ObjectsWeCanDealWith.Contains(objectType)) return false; if (objectIDList == null || objectIDList.Count < 1) return false; switch (commandKey) { case "CLIENTSYNCFROMQB": { if (Util.AreYouSure("Update selected clients in AyaNova to QuickBook's values?", "Sync from QuickBooks")) { Util.RefreshAyaNovaClientFromQB(objectIDList); MessageBox.Show("Done"); } } break; case "CLIENTSYNCFROMAYA": { if (Util.AreYouSure("Update selected clients in QuickBooks to AyaNova's values?", "Sync from AyaNova")) { Util.RefreshQBClientFromAyaNova(objectIDList); MessageBox.Show("Done"); } } break; case "CLIENTEXPORTTOQB": { if (Util.AreYouSure("Export unlinked selected clients in AyaNova to QuickBooks customers?", "Export to QuickBooks")) { Util.ImportAyaClient(objectIDList); MessageBox.Show("Done"); } } break; case "PARTSYNCFROMQB": { if (Util.AreYouSure("Update selected parts in AyaNova to QuickBook's values?", "Sync from QuickBooks")) { Util.RefreshAyaNovaPartFromQB(objectIDList); MessageBox.Show("Done"); } } break; case "PARTSYNCFROMAYA": { if (Util.AreYouSure("Update selected items in QuickBooks to AyaNova's values?", "Sync from AyaNova")) { Util.RefreshQBPartFromAyaNova(objectIDList); MessageBox.Show("Done"); } } break; case "PARTEXPORTTOQB": { if (Util.AreYouSure("Export unlinked selected parts in AyaNova to QuickBooks items?", "Export to QuickBooks")) { SetQBImportInventoryAccounts s = new SetQBImportInventoryAccounts(); if (s.ShowDialog() == DialogResult.OK) { Util.ImportAyaPart(objectIDList); MessageBox.Show("STUB Done"); } s.Dispose(); } } break; } return true; } public void CommandSelectedForSingleObject(string commandKey, RootObjectTypes objectType, object ayaNovaObject) { if (!ObjectsWeCanDealWith.Contains(objectType)) return; switch (commandKey) { case "MAIN": if (!Util.bMainWindowOpen) { MainForm mMainForm = new MainForm(); mMainForm.Show(); } break; case "RESCANQB": Util.PopulateQBListCache(); Util.PopulateAyaListCache(); break; case "CLIENTSYNCFROMQB": { if (Util.AreYouSure("Update selected client in AyaNova to QuickBook's values?", "Sync from QuickBooks")) { Util.RefreshAyaNovaClientFromQB((Client)ayaNovaObject); MessageBox.Show("Done"); } } break; case "CLIENTSYNCFROMAYA": { if (Util.AreYouSure("Update selected client in QuickBooks to AyaNova's values?", "Sync from AyaNova")) { Util.RefreshQBClientFromAyaNova((Client)ayaNovaObject); MessageBox.Show("Done"); } } break; case "CLIENTEXPORTTOQB": { if (Util.AreYouSure("Export client to QuickBooks customer?", "Export to QuickBooks")) { ArrayList alErrors = new ArrayList(); Util.ImportAyaClient(((Client)ayaNovaObject).ID, alErrors); if (alErrors.Count != 0) { StringBuilder sb = new StringBuilder(); sb.Append("Export completed with some errors:\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(); } MessageBox.Show("Done"); } } break; case "PARTSYNCFROMQB": { if (Util.AreYouSure("Update selected part in AyaNova to QuickBook's values?", "Sync from QuickBooks")) { Util.RefreshAyaNovaPartFromQB((Part)ayaNovaObject); MessageBox.Show("Done"); } } break; case "PARTSYNCFROMAYA": { if (Util.AreYouSure("Update selected part in QuickBooks to AyaNova's values?", "Sync from AyaNova")) { Util.RefreshQBPartFromAyaNova((Part)ayaNovaObject); MessageBox.Show("Done"); } } break; case "PARTEXPORTTOQB": { if (Util.AreYouSure("Export part to QuickBooks item?", "Export to QuickBooks")) { SetQBImportInventoryAccounts s = new SetQBImportInventoryAccounts(); if (s.ShowDialog() != DialogResult.OK) { s.Dispose(); return; } s.Dispose(); ArrayList alErrors = new ArrayList(); Util.ImportAyaPart(((Part)ayaNovaObject).ID, alErrors); if (alErrors.Count != 0) { StringBuilder sb = new StringBuilder(); sb.Append("Export completed with some errors:\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(); } MessageBox.Show("Done"); } } break; } } #endregion commands #endregion #region Pre flight check private bool DoPFC() { if (bPFCDone) return true; if (Util.PreFlightCheck() != Util.pfstat.OK) { IntegrationLog.Log(Util.QBID, "QBI Preflight check failed, shutting down"); bPFCDone = false; return false; } bPFCDone = true; return true; } #endregion } }