341 lines
19 KiB
C#
341 lines
19 KiB
C#
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Accounts.QuickBooks.App;
|
|
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Interfaces;
|
|
using Sarand.Net.Standard.Base.ItemOptions;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Sarand.BusinessMgr.Net.Standard.Base.Consoles
|
|
{
|
|
//=======================================================================
|
|
// A c c o u n t s - Q u i c k B o o k s
|
|
//=======================================================================
|
|
partial class SbmAccountsConsole
|
|
{
|
|
//-------------------------------------------------------------------
|
|
/// <summary>QuickBooks Interface Item Options.</summary>
|
|
protected enum QuickBooksInterfaceOption
|
|
{
|
|
HostPc,
|
|
Value,
|
|
Flag,
|
|
ConnectionType,
|
|
OnlineInstance,
|
|
ImportProcessItemType,
|
|
ExportProcessItemType,
|
|
TransactionImportMode,
|
|
TaxCodeColumn,
|
|
}
|
|
/// <summary>QuickBooks interface option flags.</summary>
|
|
public enum QBooksFlag
|
|
{
|
|
AllowCreateSupplier,
|
|
AllowCreateCustomer,
|
|
AllowCreateCommodity,
|
|
DisableUnrecognisedSuppliers,
|
|
DisableUnrecognisedCustomers,
|
|
DisableUnrecognisedCommodities,
|
|
UseLocalCustomerPricing,
|
|
UseLocalSupplierPricing,
|
|
InvoiceExportAppendProductCodeToDesc,
|
|
};
|
|
/// <summary>QuickBooks interface option values.</summary>
|
|
public enum QBooksValue
|
|
{
|
|
Unknown = 0,
|
|
CompanyDataPath = 1,
|
|
CompanyId,
|
|
AppToken,
|
|
AppTokenSecret,
|
|
SupplierNameSuffixesToIgnore,
|
|
CustomerNameSuffixesToIgnore,
|
|
InvoiceExportEarliestDate,
|
|
InvoiceExportMax,
|
|
InvoiceExportProductCode,
|
|
};
|
|
/// <summary>QuickBooks interface directions.</summary>
|
|
public enum QBooksInterfaceDirection
|
|
{
|
|
Unknown = 0,
|
|
Import = 1,
|
|
Export,
|
|
};
|
|
/// <summary>QuickBooks interface transaction import modes.</summary>
|
|
public enum QBooksTransactionImportMode
|
|
{
|
|
Unknown = 0,
|
|
CreateNew = 1,
|
|
LoadOpen,
|
|
LoadOpenCreateComplete,
|
|
LoadOpenComplete,
|
|
Default = LoadOpen,
|
|
};
|
|
|
|
//-------------------------------------------------------------------
|
|
// QuickBooks accounts.
|
|
private class QBooksStatics
|
|
{
|
|
// Code lists.
|
|
public List<TypeCodeDesc> InterfaceOptions { get; } = new List<TypeCodeDesc>();
|
|
public List<TypeCodeDesc> OptionContexts_Flag = new List<TypeCodeDesc>();
|
|
public List<TypeCodeDesc> OptionContexts_Values = new List<TypeCodeDesc>();
|
|
public List<TypeCodeDesc> InterfaceOption_QBooksInterfaceDirections = new List<TypeCodeDesc>();
|
|
public List<TypeCodeDesc> OptionValues_TransactionImportMode = new List<TypeCodeDesc>();
|
|
public List<TypeCodeDesc> OptionValues_ConnectionType = new List<TypeCodeDesc>();
|
|
public List<TypeCodeDesc> OptionValues_OnlineInstance = new List<TypeCodeDesc>();
|
|
public List<CodeDesc> OptionContexts_ImportItemType = new List<CodeDesc>();
|
|
public List<CodeDesc> OptionContexts_ExportItemType = new List<CodeDesc>();
|
|
public List<CodeDesc> OptionContexts_TransactionImportType = new List<CodeDesc>();
|
|
public QBooksStatics()
|
|
{
|
|
// Interface Options.
|
|
InterfaceOptions.Add(QuickBooksInterfaceOption.HostPc, "HostPC", "Host PC");
|
|
InterfaceOptions.Add(QuickBooksInterfaceOption.Value, "Value", "Value");
|
|
InterfaceOptions.Add(QuickBooksInterfaceOption.Flag, "Flag", "Flag");
|
|
InterfaceOptions.Add(QuickBooksInterfaceOption.ConnectionType, "ConnectType", "Connection type");
|
|
InterfaceOptions.Add(QuickBooksInterfaceOption.OnlineInstance, "OnlineInstance", "Online instance");
|
|
InterfaceOptions.Add(QuickBooksInterfaceOption.ImportProcessItemType, "ImportItemType", "Items to import");
|
|
InterfaceOptions.Add(QuickBooksInterfaceOption.ExportProcessItemType, "ExportItemType", "Items to export");
|
|
InterfaceOptions.Add(QuickBooksInterfaceOption.TransactionImportMode, "TransImpMode", "Transaction import mode");
|
|
InterfaceOptions.Add(QuickBooksInterfaceOption.TaxCodeColumn, "TaxCodeCol", "Equivalent tax code column", "To convert tax codes between systems.");
|
|
// Flags.
|
|
OptionContexts_Flag.Add(QBooksFlag.AllowCreateSupplier, "AllowCreateSupplier", "Allow creation of suppliers", "Do not import: Price sets; Customer price set and discount rates");
|
|
OptionContexts_Flag.Add(QBooksFlag.AllowCreateCustomer, "AllowCreateCustomer", "Allow creation of customers", "Do not import: Price sets; Customer price set and discount rates");
|
|
//OptionContexts_Flag.Add(QBooksFlag.AllowCreateCommodity, "AllowCreateCommodity", "Allow creation of commodities", "Do not import: Price sets; Customer price set and discount rates");
|
|
OptionContexts_Flag.Add(QBooksFlag.DisableUnrecognisedSuppliers, "DisableUnrecognisedSuppliers", "Disable unrecognised suppliers", "");
|
|
OptionContexts_Flag.Add(QBooksFlag.DisableUnrecognisedCustomers, "DisableUnrecognisedCustomers", "Disable unrecognised customers", "");
|
|
OptionContexts_Flag.Add(QBooksFlag.DisableUnrecognisedCommodities, "DisableUnrecognisedCommodities", "Disable unrecognised commodities", "");
|
|
//OptionContexts_Flag.Add(QBooksFlag.UseLocalCustomerPricing, "LocalCustPricing", "Use local customer pricing", "Do not import: Price sets; Customer price set and discount rates");
|
|
//OptionContexts_Flag.Add(QBooksFlag.UseLocalSupplierPricing, "LocalSuppPricing", "Use local supplier pricing", "Do not import: Price sets; Supplier price set and discount rates");
|
|
OptionContexts_Flag.Add(QBooksFlag.InvoiceExportAppendProductCodeToDesc, "InvExpAppendPrdCodeDesc", "Append product code to item description", "");
|
|
// Value.
|
|
OptionContexts_Values.Add(QBooksValue.CompanyDataPath, "CompanyDataPath", "Company data path", "Desktop API");
|
|
OptionContexts_Values.Add(QBooksValue.CompanyId, "CompanyId", "Company Id", "Online API");
|
|
OptionContexts_Values.Add(QBooksValue.AppToken, "AppToken", "App token", "Online API");
|
|
OptionContexts_Values.Add(QBooksValue.AppTokenSecret, "AppTokenSecret", "App token (secret)", "Online API");
|
|
OptionContexts_Values.Add(QBooksValue.SupplierNameSuffixesToIgnore, "SupplierNameSuffixesToIgnore", "Supplier name suffixes to ignore", "");
|
|
OptionContexts_Values.Add(QBooksValue.CustomerNameSuffixesToIgnore, "CustomerNameSuffixesToIgnore", "Customer name suffixes to ignore", "");
|
|
OptionContexts_Values.Add(QBooksValue.InvoiceExportEarliestDate, "InvExpEarliestDate", "Invoice export - Earliest date", "'dd/mm/yyyy'");
|
|
OptionContexts_Values.Add(QBooksValue.InvoiceExportMax, "InvExpMax", "Invoice export - max number", "Default: 1");
|
|
OptionContexts_Values.Add(QBooksValue.InvoiceExportProductCode, "InvExpProdCode", "Invoice export - Product code", "Default to use for all items");
|
|
// InterfaceOption_QBooksInterfaceDirection.
|
|
InterfaceOption_QBooksInterfaceDirections.Add(QBooksInterfaceDirection.Import, "Import", "Import from QuickBooks");
|
|
InterfaceOption_QBooksInterfaceDirections.Add(QBooksInterfaceDirection.Export, "Export", "Export to QuickBooks");
|
|
// InterfaceOption_QBooksImportTransaction.
|
|
OptionValues_TransactionImportMode.Add(QBooksTransactionImportMode.CreateNew, "CrNew", "Create new only");
|
|
OptionValues_TransactionImportMode.Add(QBooksTransactionImportMode.LoadOpen, "LdOpn", "Load open only");
|
|
OptionValues_TransactionImportMode.Add(QBooksTransactionImportMode.LoadOpenCreateComplete, "LdOpnCrCom", "Load open & create complete");
|
|
OptionValues_TransactionImportMode.Add(QBooksTransactionImportMode.LoadOpenComplete, "LcOpnCom", "Load open and complete");
|
|
// Connection Types.
|
|
OptionValues_ConnectionType.Add(Qbk.ConnectionType.LocalQBD, "LocalQBD", "Local QuickBooks");
|
|
OptionValues_ConnectionType.Add(Qbk.ConnectionType.RemoteQBD, "RemoteQBD", "Remote connection", "Remote data sharing (RDS) connection");
|
|
OptionValues_ConnectionType.Add(Qbk.ConnectionType.LocalQBDLaunchUI, "LocalQBDLaunchUI", "Launch local QuickBooks in interactive mode", "SDK application launched QuickBooks in interactive mode");
|
|
OptionValues_ConnectionType.Add(Qbk.ConnectionType.RemoteQBOE, "RemoteQBOE", "Online edition");
|
|
// Online Instances.
|
|
OptionValues_OnlineInstance.Add(Qbk.OnlineInstance.Sandbox, "Sandbox", "Sandbox");
|
|
OptionValues_OnlineInstance.Add(Qbk.OnlineInstance.Production, "Production", "Production");
|
|
// Import item types.
|
|
List<TypeCodeDesc> entityTypeCodes = SaQuickBooksConsole.EntityTypeCodes;
|
|
OptionContexts_ImportItemType.Add(entityTypeCodes.GetCodeDescForType(Qbk.EntityType.Customer));
|
|
OptionContexts_ImportItemType.Add(entityTypeCodes.GetCodeDescForType(Qbk.EntityType.Vendor));
|
|
OptionContexts_ImportItemType.Add(entityTypeCodes.GetCodeDescForType(Qbk.EntityType.PurchaseOrder));
|
|
OptionContexts_ImportItemType.Add(entityTypeCodes.GetCodeDescForType(Qbk.EntityType.SalesOrder));
|
|
OptionContexts_ImportItemType.Add(entityTypeCodes.GetCodeDescForType(Qbk.EntityType.Invoice_Product));
|
|
// Export item types.
|
|
OptionContexts_ExportItemType.Add(entityTypeCodes.GetCodeDescForType(Qbk.EntityType.Invoice_Product));
|
|
// Transaction import types.
|
|
OptionContexts_TransactionImportType.Add(entityTypeCodes.GetCodeDescForType(Qbk.EntityType.PurchaseOrder));
|
|
OptionContexts_TransactionImportType.Add(entityTypeCodes.GetCodeDescForType(Qbk.EntityType.SalesOrder));
|
|
OptionContexts_TransactionImportType.Add(entityTypeCodes.GetCodeDescForType(Qbk.EntityType.Invoice_Product));
|
|
}
|
|
}
|
|
private class QBooksParams
|
|
{
|
|
public QBooksParams(SbmInternals internals)
|
|
{
|
|
this.Internals = internals;
|
|
}
|
|
private SbmInternals Internals { get; }
|
|
// QuickBooks interface definitions.
|
|
public SaInterface.Data dfnInt_QBooks { get; set; } = new SaInterface.Data();
|
|
public SysId InterfaceId { get { return dfnInt_QBooks != null ? dfnInt_QBooks.Id : new SysId(); } }
|
|
//public SaQBooksConsole QBooksCon { get; set; }
|
|
//public SaQBooksApiConsole QBooksApiCon { get; set; }
|
|
public List<SaItemOption> ItemOptions { get; set; } = new List<SaItemOption>();
|
|
}
|
|
private readonly QBooksStatics qbkStatics = new QBooksStatics();
|
|
private readonly QBooksParams qbkParams;
|
|
private static List<TypeCodeDesc> DataTypes_QBooks { get; } = new List<TypeCodeDesc>();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Static intiialisation.
|
|
private static void InitialiseStatics_QuickBooks()
|
|
{
|
|
// QuickBooks entity types.
|
|
DataTypes_QBooks.AddRange(SaQuickBooksConsole.EntityTypeCodes);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Q u i c k B o o k s
|
|
//-------------------------------------------------------------------
|
|
public bool IsUsingQBooksInterface()
|
|
{
|
|
return SysId.IsValid(qbkParams.InterfaceId);
|
|
}
|
|
public static String GetCodeForQBooksEntityType(Qbk.EntityType itemType)
|
|
{
|
|
return DataTypes_QBooks.GetCodeForType(itemType);
|
|
}
|
|
public static Qbk.EntityType GetQBooksItemTypeForCode(String code)
|
|
{
|
|
return (Qbk.EntityType)DataTypes_QBooks.GetTypeForCode(code);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// O p t i o n s
|
|
//-------------------------------------------------------------------
|
|
private void InitQuickBooksInterfaceOptions()
|
|
{
|
|
if (qbkParams.ItemOptions.Count == 0 && SysId.IsValid(qbkParams.InterfaceId))
|
|
qbkParams.ItemOptions.AddRange(ItemOptionConsole.GetItemOptionsForItem(new SbmItemId(Sbm.ItemType.Interface, qbkParams.InterfaceId)));
|
|
}
|
|
protected String GetQuickBooksOptionValue(QuickBooksInterfaceOption option, String context)
|
|
{
|
|
return GetQuickBooksOptionValue(qbkStatics.InterfaceOptions.GetCodeForType(option), context);
|
|
}
|
|
public String GetQuickBooksOptionValue(String name, String context)
|
|
{
|
|
InitQuickBooksInterfaceOptions();
|
|
return qbkParams.ItemOptions.GetOptionValue(name, context);
|
|
}
|
|
public bool GetQuickBooksImportOption(Qbk.EntityType entityType)
|
|
{
|
|
return StringUtil.ToBool(GetQuickBooksOptionValue(QuickBooksInterfaceOption.ImportProcessItemType, GetCodeForQBooksEntityType(entityType)));
|
|
}
|
|
public bool GetQuickBooksExportOption(Qbk.EntityType entityType)
|
|
{
|
|
return StringUtil.ToBool(GetQuickBooksOptionValue(QuickBooksInterfaceOption.ExportProcessItemType, GetCodeForQBooksEntityType(entityType)));
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// I n t e r f a c e I t e m O p t i o n s
|
|
//-------------------------------------------------------------------
|
|
public List<SaItemOptionDfn> GetInterfaceItemOptionDfns_QuickBooks()
|
|
{
|
|
List<SaItemOptionDfn> interfaceItemOptionDfns = new List<SaItemOptionDfn>();
|
|
SaItemOptionDfn itemOption = null;
|
|
|
|
// Host PC.
|
|
itemOption = new SaItemOptionDfn();
|
|
itemOption.DisplayOptions.Group = OptionGroup_Process;
|
|
itemOption.Name = sageStatics.InterfaceOptions.GetCodeForType(QuickBooksInterfaceOption.HostPc);
|
|
itemOption.DisplayOptions.Caption = sageStatics.InterfaceOptions.GetDescForType(QuickBooksInterfaceOption.HostPc);
|
|
interfaceItemOptionDfns.Add(itemOption);
|
|
|
|
// Flag.
|
|
itemOption = new SaItemOptionDfn();
|
|
itemOption.DisplayOptions.Group = OptionGroup_Process;
|
|
itemOption.Name = qbkStatics.InterfaceOptions.GetCodeForType(QuickBooksInterfaceOption.Flag);
|
|
itemOption.DisplayOptions.Caption = qbkStatics.InterfaceOptions.GetDescForType(QuickBooksInterfaceOption.Flag);
|
|
itemOption.DisplayOptions.Contexts.AddRange(qbkStatics.OptionContexts_Flag);
|
|
itemOption.DisplayOptions.RequiresContext = true;
|
|
itemOption.DisplayOptions.NonDisplayTemplate = true;
|
|
itemOption.DisplayOptions.CanAddOption = true;
|
|
itemOption.DisplayOptions.CanRemoveOption = true;
|
|
interfaceItemOptionDfns.Add(itemOption);
|
|
|
|
// Values.
|
|
itemOption = new SaItemOptionDfn();
|
|
itemOption.DisplayOptions.Group = OptionGroup_Process;
|
|
itemOption.Name = qbkStatics.InterfaceOptions.GetCodeForType(QuickBooksInterfaceOption.Value);
|
|
itemOption.DisplayOptions.Caption = qbkStatics.InterfaceOptions.GetDescForType(QuickBooksInterfaceOption.Value);
|
|
itemOption.DisplayOptions.Contexts.AddRange(qbkStatics.OptionContexts_Values);
|
|
itemOption.DisplayOptions.RequiresContext = true;
|
|
itemOption.DisplayOptions.NonDisplayTemplate = true;
|
|
itemOption.DisplayOptions.CanAddOption = true;
|
|
itemOption.DisplayOptions.CanRemoveOption = true;
|
|
interfaceItemOptionDfns.Add(itemOption);
|
|
|
|
// Connection type.
|
|
itemOption = new SaItemOptionDfn();
|
|
itemOption.DisplayOptions.Group = OptionGroup_Process;
|
|
itemOption.Name = qbkStatics.InterfaceOptions.GetCodeForType(QuickBooksInterfaceOption.ConnectionType);
|
|
itemOption.DisplayOptions.Caption = qbkStatics.InterfaceOptions.GetDescForType(QuickBooksInterfaceOption.ConnectionType);
|
|
itemOption.DisplayOptions.Values.AddRange(qbkStatics.OptionValues_ConnectionType);
|
|
itemOption.DefaultValue = qbkStatics.OptionValues_ConnectionType.GetCodeForType(Qbk.ConnectionType.RemoteQBD);
|
|
interfaceItemOptionDfns.Add(itemOption);
|
|
|
|
// Online Instance.
|
|
itemOption = new SaItemOptionDfn();
|
|
itemOption.DisplayOptions.Group = OptionGroup_Process;
|
|
itemOption.Name = qbkStatics.InterfaceOptions.GetCodeForType(QuickBooksInterfaceOption.OnlineInstance);
|
|
itemOption.DisplayOptions.Caption = qbkStatics.InterfaceOptions.GetDescForType(QuickBooksInterfaceOption.OnlineInstance);
|
|
itemOption.DisplayOptions.Values.AddRange(qbkStatics.OptionValues_OnlineInstance);
|
|
itemOption.DefaultValue = qbkStatics.OptionValues_OnlineInstance.GetCodeForType(Qbk.OnlineInstance.Production);
|
|
interfaceItemOptionDfns.Add(itemOption);
|
|
|
|
// Import Process Item Type.
|
|
itemOption = new SaItemOptionDfn();
|
|
itemOption.DisplayOptions.Group = OptionGroup_Data;
|
|
itemOption.Name = qbkStatics.InterfaceOptions.GetCodeForType(QuickBooksInterfaceOption.ImportProcessItemType);
|
|
itemOption.DisplayOptions.Caption = qbkStatics.InterfaceOptions.GetDescForType(QuickBooksInterfaceOption.ImportProcessItemType);
|
|
itemOption.DisplayOptions.Contexts.AddRange(qbkStatics.OptionContexts_ImportItemType);
|
|
itemOption.DisplayOptions.Values.AddRange(Sbm.ValuesYesNo);
|
|
itemOption.DefaultValue = Sbm.ValueNo;
|
|
itemOption.DisplayOptions.RequiresContext = true;
|
|
itemOption.DisplayOptions.NonDisplayTemplate = true;
|
|
itemOption.DisplayOptions.CanAddOption = true;
|
|
itemOption.DisplayOptions.CanRemoveOption = true;
|
|
interfaceItemOptionDfns.Add(itemOption);
|
|
|
|
// Export Process Item Type.
|
|
itemOption = new SaItemOptionDfn();
|
|
itemOption.DisplayOptions.Group = OptionGroup_Data;
|
|
itemOption.Name = qbkStatics.InterfaceOptions.GetCodeForType(QuickBooksInterfaceOption.ExportProcessItemType);
|
|
itemOption.DisplayOptions.Caption = qbkStatics.InterfaceOptions.GetDescForType(QuickBooksInterfaceOption.ExportProcessItemType);
|
|
itemOption.DisplayOptions.Contexts.AddRange(qbkStatics.OptionContexts_ExportItemType);
|
|
itemOption.DisplayOptions.Values.AddRange(Sbm.ValuesYesNo);
|
|
itemOption.DefaultValue = Sbm.ValueNo;
|
|
itemOption.DisplayOptions.RequiresContext = true;
|
|
itemOption.DisplayOptions.NonDisplayTemplate = true;
|
|
itemOption.DisplayOptions.CanAddOption = true;
|
|
itemOption.DisplayOptions.CanRemoveOption = true;
|
|
interfaceItemOptionDfns.Add(itemOption);
|
|
|
|
// Transaction Import modes.
|
|
itemOption = new SaItemOptionDfn();
|
|
itemOption.DisplayOptions.Group = OptionGroup_Data;
|
|
itemOption.Name = qbkStatics.InterfaceOptions.GetCodeForType(QuickBooksInterfaceOption.TransactionImportMode);
|
|
itemOption.DisplayOptions.Caption = qbkStatics.InterfaceOptions.GetDescForType(QuickBooksInterfaceOption.TransactionImportMode);
|
|
itemOption.DisplayOptions.Contexts.AddRange(qbkStatics.OptionContexts_TransactionImportType);
|
|
itemOption.DisplayOptions.Values.AddRange(qbkStatics.OptionValues_TransactionImportMode);
|
|
itemOption.DefaultValue = qbkStatics.OptionValues_TransactionImportMode.GetCodeForType(QBooksTransactionImportMode.Default);
|
|
itemOption.DefaultNotes = "Value is reset after each import";
|
|
itemOption.DisplayOptions.RequiresContext = true;
|
|
itemOption.DisplayOptions.NonDisplayTemplate = true;
|
|
itemOption.DisplayOptions.CanAddOption = true;
|
|
itemOption.DisplayOptions.CanRemoveOption = true;
|
|
interfaceItemOptionDfns.Add(itemOption);
|
|
|
|
// Tax Code Column
|
|
itemOption = new SaItemOptionDfn();
|
|
itemOption.DisplayOptions.Group = OptionGroup_Data;
|
|
itemOption.Name = sageStatics.InterfaceOptions.GetCodeForType(QuickBooksInterfaceOption.TaxCodeColumn);
|
|
itemOption.DisplayOptions.Caption = sageStatics.InterfaceOptions.GetDescForType(QuickBooksInterfaceOption.TaxCodeColumn);
|
|
itemOption.DisplayOptions.Values.AddRange(Internals.GetSystemCodes(Sbm.SystemCode.OrgOption_TaxCodeColumn));
|
|
//itemOption.DefaultValue = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.TaxCode_CodeAlt1);
|
|
interfaceItemOptionDfns.Add(itemOption);
|
|
|
|
return interfaceItemOptionDfns;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|