799 lines
35 KiB
C#
799 lines
35 KiB
C#
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Accounts.QuickBooks.App;
|
|
using Sarand.Net.Standard.Accounts.Sage.App;
|
|
using Sarand.Net.Standard.Base.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.ReferenceData;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
|
|
namespace Sarand.BusinessMgr.Net.Standard.Base.Bus
|
|
{
|
|
//=======================================================================
|
|
public partial class SbmAccountsDfn : SacsHierarchyItem
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Configuration.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Definitions.
|
|
public class SaInterfaceItemCache
|
|
{
|
|
public SaInterfaceItemCache()
|
|
{
|
|
itemType = Sbm.ItemType.Unknown;
|
|
importedFromSage = false;
|
|
importedFromQBooks = false;
|
|
exportedFromSage = false;
|
|
exportedFromQBooks = false;
|
|
|
|
}
|
|
public Sbm.ItemType itemType;
|
|
public SysId idItem;
|
|
public bool importedFromSage;
|
|
public bool importedFromQBooks;
|
|
public bool exportedFromSage;
|
|
public bool exportedFromQBooks;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private static String OptionGroup_Sage { get; } = "Sage";
|
|
private static String OptionGroup_Data { get; } = "Data";
|
|
private static String OptionGroup_Stock { get; } = "Stock";
|
|
private static String OptionGroup_Process { get; } = "Process";
|
|
private readonly SbmInternals internals;
|
|
private readonly List<TypeCodeDesc> interfaceOptions = new List<TypeCodeDesc>();
|
|
private readonly SaInterfaceItemCache itemCache = new SaInterfaceItemCache();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Static initialisation.
|
|
static SbmAccountsDfn()
|
|
{
|
|
InitialiseStatics_SageLine50();
|
|
InitialiseStatics_QuickBooks();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public SbmAccountsDfn(ISbmUserContext userContext)
|
|
{
|
|
UserContext = userContext;
|
|
internals = new SbmInternals(userContext);
|
|
sageParams = new SageParams(userContext, internals);
|
|
qbkParams = new QBooksParams(userContext);
|
|
interfaceOptions = SbmSystem.GetCodesOfType(userContext, Sbm.SystemCode.InterfaceOption);
|
|
Reset();
|
|
}
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
internals.Dispose();
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
public ISbmUserContext UserContext { get; }
|
|
protected SaInterfaceConsole InterfaceConsole { get { return internals.InterfaceConsole; } }
|
|
protected SaItemOptionConsole ItemOptionConsole { get { return internals.ItemOptionConsole; } }
|
|
|
|
//-------------------------------------------------------------------
|
|
// I n t e r f a c e I t e m O p t i o n s
|
|
//-------------------------------------------------------------------
|
|
public List<SaItemOptionDfn> GetInterfaceItemOptionDfns(Sbm.InterfaceType_Accounts interfaceType)
|
|
{
|
|
switch (interfaceType)
|
|
{
|
|
case Sbm.InterfaceType_Accounts.SageLine50:
|
|
return GetInterfaceItemOptionDfns_SageLine50();
|
|
case Sbm.InterfaceType_Accounts.QuickBooks:
|
|
return GetInterfaceItemOptionDfns_QuickBooks();
|
|
}
|
|
return new List<SaItemOptionDfn>();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// A t t r i b u t e s
|
|
//-------------------------------------------------------------------
|
|
public SysId GetAccountInterfaceId(Sbm.InterfaceType_Accounts accountsType)
|
|
{
|
|
switch (accountsType)
|
|
{
|
|
case Sbm.InterfaceType_Accounts.SageLine50:
|
|
return sageParams.InterfaceId;
|
|
case Sbm.InterfaceType_Accounts.QuickBooks:
|
|
return qbkParams.InterfaceId;
|
|
}
|
|
return new SysId();
|
|
}
|
|
public bool IsUsingAccountsInterface(Sbm.InterfaceType_Accounts accountsType = Sbm.InterfaceType_Accounts.Unknown)
|
|
{
|
|
switch (accountsType)
|
|
{
|
|
case Sbm.InterfaceType_Accounts.Unknown:
|
|
return SysId.IsValid(sageParams.InterfaceId) || SysId.IsValid(qbkParams.InterfaceId);
|
|
case Sbm.InterfaceType_Accounts.SageLine50: return SysId.IsValid(sageParams.InterfaceId);
|
|
case Sbm.InterfaceType_Accounts.QuickBooks: return SysId.IsValid(qbkParams.InterfaceId);
|
|
}
|
|
return false;
|
|
}
|
|
public List<SysId> GetInterfaceIds(bool activeOnly)
|
|
{
|
|
List<SysId> interfaceIds = new List<SysId>();
|
|
if (SysId.IsValid(sageParams.InterfaceId) && (!activeOnly || sageParams.dfnInt_Sage.Active))
|
|
interfaceIds.Add(qbkParams.InterfaceId);
|
|
if (SysId.IsValid(qbkParams.InterfaceId) && (!activeOnly || qbkParams.dfnInt_QBooks.Active))
|
|
interfaceIds.Add(qbkParams.InterfaceId);
|
|
return interfaceIds;
|
|
}
|
|
/*
|
|
public SbmInterfaceDfn GetInterfaceDfn(Sbm.InterfaceType_Accounts accounts)
|
|
{
|
|
switch (accounts)
|
|
{
|
|
case Sbm.InterfaceType_Accounts.SageLine50: return sageParams.dfnInt_Sage;
|
|
case Sbm.InterfaceType_Accounts.QuickBooks: return sageParams.dfnInt_QuickBooks;
|
|
}
|
|
//return SbmInterfaceDfn();
|
|
return null;
|
|
}
|
|
*/
|
|
public bool CanHostProcessAccountsInterface(Sbm.InterfaceType_Accounts accountsType)
|
|
{
|
|
String computerName = SacsSystem.ComputerName;
|
|
if (accountsType == Sbm.InterfaceType_Accounts.SageLine50)
|
|
{
|
|
String hostPcs = GetOptionValue(accountsType, sageStatics.InterfaceOptions.GetCodeForType(SageInterfaceOption.HostPc), "");
|
|
if (StringUtil.IsEmpty(hostPcs) || new List<String>(hostPcs.Split(',')).ContainsCI(computerName))
|
|
return true;
|
|
}
|
|
else if (accountsType == Sbm.InterfaceType_Accounts.QuickBooks)
|
|
{
|
|
String hostPcs = GetOptionValue(accountsType, interfaceOptions.GetCodeForType(Sbm.InterfaceOption.HostPc), "");
|
|
if (StringUtil.IsEmpty(hostPcs) || new List<String>(hostPcs.Split(',')).ContainsCI(computerName))
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// O p t i o n s
|
|
//-------------------------------------------------------------------
|
|
public String GetOptionValue(Sbm.InterfaceType_Accounts accounts, String name, String context)
|
|
{
|
|
InitOptions(accounts);
|
|
switch (accounts)
|
|
{
|
|
case Sbm.InterfaceType_Accounts.SageLine50:
|
|
return GetSageOptionValue(name, context);
|
|
case Sbm.InterfaceType_Accounts.QuickBooks:
|
|
return GetQuickBooksOptionValue(name, context);
|
|
}
|
|
return "";
|
|
}
|
|
public String GetImageFolder(Sbm.InterfaceType_Accounts accounts)
|
|
{
|
|
String imageFolder = "";
|
|
InitOptions(accounts);
|
|
switch (accounts)
|
|
{
|
|
case Sbm.InterfaceType_Accounts.SageLine50:
|
|
if (!sageParams.ImageFolderVerified)
|
|
{
|
|
// ToDo Sage GetImageFolder
|
|
/*
|
|
sageParams.ImageFolder = SaSageConsole.GetImageFolder(GetOptionValue(accounts, Sbm.InterfaceOption.Sage_DataPath, ""));
|
|
sageParams.ImageFolderVerified = true;
|
|
*/
|
|
}
|
|
imageFolder = sageParams.ImageFolder;
|
|
break;
|
|
case Sbm.InterfaceType_Accounts.QuickBooks:
|
|
break;
|
|
}
|
|
return imageFolder.TrimEnd(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar });
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// I t e m I m p o r t e d F r o m A c c o u n t s
|
|
//-------------------------------------------------------------------
|
|
public void PopulateItemCache(Sbm.ItemType itemType, SysId idItem, bool force = false)
|
|
{
|
|
if (force || itemCache.itemType != itemType || itemCache.idItem != idItem)
|
|
{
|
|
itemCache.itemType = itemType;
|
|
itemCache.idItem = idItem;
|
|
itemCache.importedFromSage = false;
|
|
itemCache.importedFromQBooks = false;
|
|
itemCache.exportedFromSage = false;
|
|
itemCache.exportedFromQBooks = false;
|
|
if (InterfaceConsole != null)
|
|
{
|
|
// Retrieve the 'Sage' interface data item for this item.
|
|
if (SysId.IsValid(sageParams.InterfaceId) && sageParams.dfnInt_Sage.Active)
|
|
{
|
|
// Retrieve interface data item for this item.
|
|
List<SaInterfaceDataItem> plIntItm = InterfaceConsole.GetInterfaceDataItemsByItem(sageParams.InterfaceId, SaInterfaceProcessDirection.Unknown, new ItemId((short)itemType, idItem));
|
|
foreach (SaInterfaceDataItem pIntItm in plIntItm)
|
|
{
|
|
if (pIntItm.Direction == SaInterfaceProcessDirection.Inbound || pIntItm.Direction == SaInterfaceProcessDirection.Both) itemCache.importedFromSage = true;
|
|
else if (pIntItm.Direction == SaInterfaceProcessDirection.Outbound || pIntItm.Direction == SaInterfaceProcessDirection.Both) itemCache.exportedFromSage = true;
|
|
}
|
|
}
|
|
// Retrieve the 'QuickBooks' interface data item for this item.
|
|
if (SysId.IsValid(qbkParams.InterfaceId) && qbkParams.dfnInt_QBooks.Active)
|
|
{
|
|
// Retrieve interface data item for this item.
|
|
List<SaInterfaceDataItem> plIntItm = InterfaceConsole.GetInterfaceDataItemsByItem(qbkParams.InterfaceId, SaInterfaceProcessDirection.Unknown, new ItemId((short)itemType, idItem));
|
|
foreach (SaInterfaceDataItem pIntItm in plIntItm)
|
|
{
|
|
if (pIntItm.Direction == SaInterfaceProcessDirection.Inbound || pIntItm.Direction == SaInterfaceProcessDirection.Both) itemCache.importedFromQBooks = true;
|
|
else if (pIntItm.Direction == SaInterfaceProcessDirection.Outbound || pIntItm.Direction == SaInterfaceProcessDirection.Both) itemCache.exportedFromQBooks = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
public bool ItemIsImportedFromAccounts(Sbm.ItemType itemType, SysId idItem, Sbm.InterfaceType_Accounts accounts = Sbm.InterfaceType_Accounts.Unknown)
|
|
{
|
|
if (itemType == Sbm.ItemType.Unknown || !SysId.IsValid(idItem)) return false;
|
|
|
|
PopulateItemCache(itemType, idItem);
|
|
if (itemCache.itemType == itemType && itemCache.idItem == idItem)
|
|
{
|
|
switch (accounts)
|
|
{
|
|
case Sbm.InterfaceType_Accounts.Unknown:
|
|
return (itemCache.importedFromSage || itemCache.importedFromQBooks);
|
|
case Sbm.InterfaceType_Accounts.SageLine50:
|
|
return itemCache.importedFromSage;
|
|
case Sbm.InterfaceType_Accounts.QuickBooks:
|
|
return itemCache.importedFromQBooks;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool ItemIsImportedFromSage(Sbm.ItemType itemType, SysId idItem)
|
|
{
|
|
return ItemIsImportedFromAccounts(itemType, idItem, Sbm.InterfaceType_Accounts.SageLine50);
|
|
}
|
|
|
|
public bool ItemIsImportedFromQBooks(Sbm.ItemType itemType, SysId idItem)
|
|
{
|
|
return ItemIsImportedFromAccounts(itemType, idItem, Sbm.InterfaceType_Accounts.QuickBooks);
|
|
}
|
|
|
|
public bool IsItemExportedToAccounts(Sbm.ItemType itemType, SysId idItem, Sbm.InterfaceType_Accounts accounts = Sbm.InterfaceType_Accounts.Unknown)
|
|
{
|
|
if (itemType == Sbm.ItemType.Unknown || !SysId.IsValid(idItem)) return false;
|
|
PopulateItemCache(itemType, idItem);
|
|
if (itemCache.itemType == itemType && itemCache.idItem == idItem)
|
|
{
|
|
switch (accounts)
|
|
{
|
|
case Sbm.InterfaceType_Accounts.Unknown:
|
|
return (itemCache.exportedFromSage || itemCache.exportedFromQBooks);
|
|
case Sbm.InterfaceType_Accounts.SageLine50:
|
|
return itemCache.exportedFromSage;
|
|
case Sbm.InterfaceType_Accounts.QuickBooks:
|
|
return itemCache.exportedFromQBooks;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// I t e m M a n a g e m e n t
|
|
//-------------------------------------------------------------------
|
|
public bool IsItemTypeManagedByAccounts(Sbm.ItemType itemType)
|
|
{
|
|
if (itemType == Sbm.ItemType.Unknown) return false;
|
|
// Sage Line 50:
|
|
if (IsUsingSageInterface())
|
|
{
|
|
String importProcessItemType = sageStatics.InterfaceOptions.GetCodeForType(SageInterfaceOption.ImportProcessItemType);
|
|
switch (itemType)
|
|
{
|
|
case Sbm.ItemType.Commodity:
|
|
if (GetOptionValue(Sbm.InterfaceType_Accounts.SageLine50, importProcessItemType, GetCodeForSageItemType(Sage.ItemType.Product)).ToBool()) return true;
|
|
break;
|
|
case Sbm.ItemType.PriceSet:
|
|
if (GetOptionValue(Sbm.InterfaceType_Accounts.SageLine50, importProcessItemType, GetCodeForSageItemType(Sage.ItemType.PriceList)).ToBool()) return true;
|
|
break;
|
|
default:
|
|
#if DEBUG
|
|
SaLogger.Warn("IsItemTypeManagedByAccounts Unsupported Sage item type: " + itemType.ToString());
|
|
#endif
|
|
break;
|
|
}
|
|
}
|
|
// Quickbooks:
|
|
if (IsUsingQBooksInterface())
|
|
{
|
|
String importProcessItemType = "";
|
|
importProcessItemType = qbkStatics.InterfaceOptions.GetCodeForType(QuickBooksInterfaceOption.ImportProcessItemType);
|
|
switch (itemType)
|
|
{
|
|
case Sbm.ItemType.Commodity:
|
|
if (GetOptionValue(Sbm.InterfaceType_Accounts.QuickBooks, importProcessItemType, GetCodeForQBooksEntityType(Qbk.EntityType.Item)).ToBool()) return true;
|
|
break;
|
|
case Sbm.ItemType.PriceSet:
|
|
break;
|
|
default:
|
|
#if DEBUG
|
|
SaLogger.Warn("IsItemTypeManagedByAccounts Unsupported QBooks item type: " + itemType.ToString());
|
|
#endif
|
|
break;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool IsAssociationTypeManagedByAccounts(Sbm.AssociationType associationType)
|
|
{
|
|
if (associationType == Sbm.AssociationType.Unknown) return false;
|
|
// Sage Line 50:
|
|
if (IsUsingSageInterface())
|
|
{
|
|
switch (associationType)
|
|
{
|
|
case Sbm.AssociationType.Customer:
|
|
if (GetSageImportOption(Sage.ItemType.Customer)) return true;
|
|
break;
|
|
case Sbm.AssociationType.Supplier:
|
|
if (GetSageImportOption(Sage.ItemType.Supplier)) return true;
|
|
break;
|
|
default:
|
|
#if DEBUG
|
|
SaLogger.Warn("IsAssociationTypeManagedByAccounts Unsupported Sage association type: " + associationType.ToString());
|
|
#endif
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Quickbooks:
|
|
if (IsUsingQBooksInterface())
|
|
{
|
|
switch (associationType)
|
|
{
|
|
case Sbm.AssociationType.Customer:
|
|
if (GetQuickBooksImportOption(Qbk.EntityType.Customer)) return true;
|
|
break;
|
|
case Sbm.AssociationType.Supplier:
|
|
if (GetQuickBooksImportOption(Qbk.EntityType.Vendor)) return true;
|
|
break;
|
|
default:
|
|
#if DEBUG
|
|
SaLogger.Warn("IsAssociationTypeManagedByAccounts Unsupported QBooks association type: " + associationType.ToString());
|
|
#endif
|
|
break;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool IsTransactionTypeManagedByAccounts(Sbm.TransactionType transType)
|
|
{
|
|
if (transType == Sbm.TransactionType.Unknown) return false;
|
|
// Sage Line 50:
|
|
if (IsUsingSageInterface())
|
|
{
|
|
switch (transType)
|
|
{
|
|
case Sbm.TransactionType.SalesOrder:
|
|
{
|
|
if (GetSageImportOption(Sage.ItemType.SalesOrder) || GetSageExportOption(Sage.ItemType.SalesOrder)) return true;
|
|
break;
|
|
}
|
|
case Sbm.TransactionType.SalesInvoice:
|
|
{
|
|
if (GetSageImportOption(Sage.ItemType.Invoice_SalesOrder) || GetSageExportOption(Sage.ItemType.Invoice_SalesOrder)) return true;
|
|
break;
|
|
}
|
|
case Sbm.TransactionType.PurchaseOrder:
|
|
{
|
|
if (GetSageImportOption(Sage.ItemType.PurchaseOrder) || GetSageExportOption(Sage.ItemType.PurchaseOrder)) return true;
|
|
break;
|
|
}
|
|
default:
|
|
#if DEBUG
|
|
SaLogger.Warn("IsTransactionTypeManagedByAccounts Unsupported Sage transaction type: " + transType.ToString());
|
|
#endif
|
|
break;
|
|
}
|
|
}
|
|
// Quickbooks:
|
|
if (IsUsingQBooksInterface())
|
|
{
|
|
switch (transType)
|
|
{
|
|
case Sbm.TransactionType.SalesOrder:
|
|
if (GetQuickBooksImportOption(Qbk.EntityType.SalesOrder) || GetQuickBooksExportOption(Qbk.EntityType.SalesOrder)) return true;
|
|
break;
|
|
case Sbm.TransactionType.PurchaseOrder:
|
|
if (GetQuickBooksImportOption(Qbk.EntityType.PurchaseOrder) || GetQuickBooksExportOption(Qbk.EntityType.PurchaseOrder)) return true;
|
|
break;
|
|
default:
|
|
#if DEBUG
|
|
SaLogger.Warn("IsTransactionTypeManagedByAccounts Unsupported QBooks transaction type: " + transType.ToString());
|
|
#endif
|
|
break;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// I t e m A l l o c a t i o n
|
|
//-------------------------------------------------------------------
|
|
public bool IsAllocationManagedByAccounts(Sbm.TransactionType transType)
|
|
{
|
|
if (transType == Sbm.TransactionType.Unknown) return false;
|
|
if (transType != Sbm.TransactionType.SalesOrder && transType != Sbm.TransactionType.PurchaseOrder) return false;
|
|
// Sage Line 50:
|
|
if (IsUsingSageInterface())
|
|
{
|
|
switch (transType)
|
|
{
|
|
case Sbm.TransactionType.SalesOrder:
|
|
if (!GetSageImportOption(Sage.ItemType.SalesOrder)) return false;
|
|
if (!GetSageImportOption(Sage.ItemType.SopItemAllocation)) return false;
|
|
return true;
|
|
case Sbm.TransactionType.PurchaseOrder:
|
|
if (!GetSageImportOption(Sage.ItemType.PurchaseOrder)) return false;
|
|
if (!GetSageImportOption(Sage.ItemType.SopItemAllocation)) return false;
|
|
return true;
|
|
default:
|
|
#if DEBUG
|
|
SaLogger.Warn("IsAllocationManagedByAccounts Unsupported Sage transaction type: " + transType.ToString());
|
|
#endif
|
|
break;
|
|
}
|
|
}
|
|
// Quickbooks:
|
|
if (IsUsingQBooksInterface())
|
|
{
|
|
switch (transType)
|
|
{
|
|
case Sbm.TransactionType.SalesOrder:
|
|
if (!GetQuickBooksImportOption(Qbk.EntityType.SalesOrder)) return false;
|
|
// NB No allocation import from QuickBooks yet.
|
|
break;
|
|
case Sbm.TransactionType.PurchaseOrder:
|
|
if (!GetQuickBooksImportOption(Qbk.EntityType.PurchaseOrder)) return false;
|
|
// NB No allocation import from QuickBooks yet.
|
|
break;
|
|
default:
|
|
#if DEBUG
|
|
SaLogger.Warn("IsAllocationManagedByAccounts Unsupported QBooks transaction type: " + transType.ToString());
|
|
#endif
|
|
break;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// P r i c i n g
|
|
//-------------------------------------------------------------------
|
|
public bool UseLocalCustomerPricing()
|
|
{
|
|
if (IsUsingSageInterface())
|
|
{
|
|
String flag = sageStatics.InterfaceOptions.GetCodeForType(SageInterfaceOption.Flag);
|
|
return GetOptionValue(Sbm.InterfaceType_Accounts.SageLine50, flag, sageStatics.OptionValues_Flag.GetCodeForType(SageFlag.UseLocalCustomerPricing)).ToBool();
|
|
}
|
|
if (IsUsingQBooksInterface())
|
|
{
|
|
String flag = interfaceOptions.GetCodeForType(Sbm.InterfaceOption.Flag);
|
|
return GetOptionValue(Sbm.InterfaceType_Accounts.QuickBooks, flag, qbkStatics.OptionContexts_Flag.GetCodeForType(QBooksFlag.UseLocalCustomerPricing)).ToBool();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool UseLocalSupplierPricing()
|
|
{
|
|
if (IsUsingSageInterface())
|
|
{
|
|
String flag = sageStatics.InterfaceOptions.GetCodeForType(SageInterfaceOption.Flag);
|
|
return GetOptionValue(Sbm.InterfaceType_Accounts.SageLine50, flag, sageStatics.OptionValues_Flag.GetCodeForType(SageFlag.UseLocalSupplierPricing)).ToBool();
|
|
}
|
|
if (IsUsingQBooksInterface())
|
|
{
|
|
String flag = interfaceOptions.GetCodeForType(Sbm.InterfaceOption.Flag);
|
|
return GetOptionValue(Sbm.InterfaceType_Accounts.QuickBooks, flag, qbkStatics.OptionContexts_Flag.GetCodeForType(QBooksFlag.UseLocalSupplierPricing)).ToBool();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// S a g e L i n e 5 0
|
|
//-------------------------------------------------------------------
|
|
public Sage.DbVersion GetSageDbVersion()
|
|
{
|
|
Sage.DbVersion sageVersion = Sage.DbVersion.Unknown;
|
|
if (IsUsingSageInterface())
|
|
{
|
|
/* ToDo GetSageDbVersion
|
|
if (!sage.pSageCon) GetSageCon(); // Force creation.
|
|
if (sage.pSageCon)
|
|
{
|
|
InitOptions(eSapInterfaceType_Accounts_SageLine50);
|
|
// Extract control configuration options:
|
|
String sSageDataPath = sage.lOption_Sage.GetValueByNameContext(interfaceOptions.GetCodeForType(Sbm.InterfaceOption.Sage_DataPath),"");
|
|
SaSageInstance_Info * pInfo = sage.pSageCon->GetSageInstanceInfo (sSageDataPath);
|
|
if (pInfo)
|
|
sageVersion = pInfo->GetDbVersion();
|
|
_Delete(pInfo);
|
|
}
|
|
*/
|
|
}
|
|
return Sage.DbVersion.Unknown;
|
|
}
|
|
public bool IsUsingSageInterface()
|
|
{
|
|
return SysId.IsValid(sageParams.InterfaceId);
|
|
}
|
|
public static String GetCodeForSageItemType(Sage.ItemType itemType)
|
|
{
|
|
return DataTypes_Sage.GetCodeForType(itemType);
|
|
}
|
|
public static Sage.ItemType GetSageItemTypeForCode(String code)
|
|
{
|
|
return (Sage.ItemType)DataTypes_Sage.GetTypeForCode(code);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
public bool SourcedFromSage(SbmDbDfn.ColumnIdx columnIdx, Sage.ItemType sageItemType)
|
|
{
|
|
return (GetSageDbColumnIdx(columnIdx, sageItemType) != SageDbDfn.ColumnIdx.Unknown);
|
|
}
|
|
public String GetSageColumnName(SbmDbDfn.ColumnIdx columnIdx, Sage.ItemType sageItemType)
|
|
{
|
|
SageDbDfn.ColumnIdx sageDbColumnIdx = GetSageDbColumnIdx(columnIdx, sageItemType);
|
|
return SageDbDfn.GetColumnName(sageDbColumnIdx, false);
|
|
}
|
|
public SageDbDfn.ColumnIdx GetSageDbColumnIdx(SbmDbDfn.ColumnIdx columnIdx, Sage.ItemType sageItemType)
|
|
{
|
|
if (!IsUsingSageInterface()) return SageDbDfn.ColumnIdx.Unknown;
|
|
|
|
// Sage options:
|
|
String itemType_ImportProcess = sageStatics.InterfaceOptions.GetCodeForType(SageInterfaceOption.ImportProcessItemType);
|
|
String itemType_ExportProcess = sageStatics.InterfaceOptions.GetCodeForType(SageInterfaceOption.ExportProcessItemType);
|
|
String colSource_Supplier = sageStatics.InterfaceOptions.GetCodeForType(SageInterfaceOption.PurchaseLedgerColumnSource);
|
|
String colSource_Customer = sageStatics.InterfaceOptions.GetCodeForType(SageInterfaceOption.SalesLedgerColumnSource);
|
|
String colSource_StockColumn = sageStatics.InterfaceOptions.GetCodeForType(SageInterfaceOption.StockColumnSource);
|
|
|
|
// Commodity columns:
|
|
bool importSageSuppliers = StringUtil.ToBool(GetOptionValue(Sbm.InterfaceType_Accounts.SageLine50, itemType_ImportProcess, GetCodeForSageItemType(Sage.ItemType.Supplier)));
|
|
bool importSageCustomers = StringUtil.ToBool(GetOptionValue(Sbm.InterfaceType_Accounts.SageLine50, itemType_ImportProcess, GetCodeForSageItemType(Sage.ItemType.Customer)));
|
|
bool importSageProducts = StringUtil.ToBool(GetOptionValue(Sbm.InterfaceType_Accounts.SageLine50, itemType_ImportProcess, GetCodeForSageItemType(Sage.ItemType.Product)));
|
|
bool exportSageProducts = StringUtil.ToBool(GetOptionValue(Sbm.InterfaceType_Accounts.SageLine50, itemType_ExportProcess, GetCodeForSageItemType(Sage.ItemType.Product)));
|
|
if (SbmDbDfn.GetTableForColumn(columnIdx) == SbmDbDfn.TableIdx.Association || SbmDbDfn.GetTableForColumn(columnIdx) == SbmDbDfn.TableIdx.Affiliate || SbmDbDfn.GetTableForColumn(columnIdx) == SbmDbDfn.TableIdx.Address)
|
|
{
|
|
if (sageItemType == Sage.ItemType.Supplier && importSageSuppliers)
|
|
{
|
|
switch (columnIdx)
|
|
{
|
|
case SbmDbDfn.ColumnIdx.Association_Code: return SageDbDfn.ColumnIdx.PurchaseLedger_AccountRef;
|
|
case SbmDbDfn.ColumnIdx.Association_CreditLimit: return SageDbDfn.ColumnIdx.PurchaseLedger_CreditLimit;
|
|
case SbmDbDfn.ColumnIdx.Association_AccountBalance: return SageDbDfn.ColumnIdx.PurchaseLedger_Balance;
|
|
case SbmDbDfn.ColumnIdx.Association_DiscountRate: return SageDbDfn.ColumnIdx.PurchaseLedger_DiscountRate;
|
|
case SbmDbDfn.ColumnIdx.Association_TaxCodeId: return SageDbDfn.ColumnIdx.PurchaseLedger_DefTaxCode;
|
|
//case SbmDbDfn.ColumnIdx.Association_OverrideTaxCode: return SageDbDfn.ColumnIdx.PurchaseLedger_OverrideTaxCode;
|
|
case SbmDbDfn.ColumnIdx.Affiliate_Name: return SageDbDfn.ColumnIdx.PurchaseLedger_Name;
|
|
case SbmDbDfn.ColumnIdx.Affiliate_Contact: return SageDbDfn.ColumnIdx.PurchaseLedger_ContactName;
|
|
case SbmDbDfn.ColumnIdx.Affiliate_PhoneMain: return SageDbDfn.ColumnIdx.PurchaseLedger_Telephone;
|
|
case SbmDbDfn.ColumnIdx.Affiliate_PhoneAlt: return SageDbDfn.ColumnIdx.PurchaseLedger_Telephone2;
|
|
case SbmDbDfn.ColumnIdx.Affiliate_PhoneFax: return SageDbDfn.ColumnIdx.PurchaseLedger_Fax;
|
|
case SbmDbDfn.ColumnIdx.Affiliate_Email: return SageDbDfn.ColumnIdx.PurchaseLedger_EMail;
|
|
case SbmDbDfn.ColumnIdx.Affiliate_Website: return SageDbDfn.ColumnIdx.PurchaseLedger_WebAddress;
|
|
case SbmDbDfn.ColumnIdx.Affiliate_VatReg: return SageDbDfn.ColumnIdx.PurchaseLedger_VatRegNumber;
|
|
case SbmDbDfn.ColumnIdx.Address_Line1: return SageDbDfn.ColumnIdx.PurchaseLedger_Address1;
|
|
case SbmDbDfn.ColumnIdx.Address_Line2: return SageDbDfn.ColumnIdx.PurchaseLedger_Address2;
|
|
case SbmDbDfn.ColumnIdx.Address_Line3: return SageDbDfn.ColumnIdx.PurchaseLedger_Address3;
|
|
|
|
default:
|
|
// Is this column optionally sourced from a Sage 'Source' fields:
|
|
String colSource = GetOptionValue(Sbm.InterfaceType_Accounts.SageLine50, colSource_Supplier, sageStatics.SalesLedgerColumnSources.GetCodeForType(columnIdx));
|
|
if (!StringUtil.IsEmpty(colSource))
|
|
{
|
|
if (colSource == SageDbDfn.GetColumnName(SageDbDfn.ColumnIdx.PurchaseLedger_Analysis1)) return SageDbDfn.ColumnIdx.PurchaseLedger_Analysis1;
|
|
if (colSource == SageDbDfn.GetColumnName(SageDbDfn.ColumnIdx.PurchaseLedger_Analysis2)) return SageDbDfn.ColumnIdx.PurchaseLedger_Analysis2;
|
|
if (colSource == SageDbDfn.GetColumnName(SageDbDfn.ColumnIdx.PurchaseLedger_Analysis3)) return SageDbDfn.ColumnIdx.PurchaseLedger_Analysis3;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
if (sageItemType == Sage.ItemType.Customer && importSageCustomers)
|
|
{
|
|
switch (columnIdx)
|
|
{
|
|
case SbmDbDfn.ColumnIdx.Association_Code: return SageDbDfn.ColumnIdx.SalesLedger_AccountRef;
|
|
case SbmDbDfn.ColumnIdx.Association_CreditLimit: return SageDbDfn.ColumnIdx.SalesLedger_CreditLimit;
|
|
case SbmDbDfn.ColumnIdx.Association_AccountBalance: return SageDbDfn.ColumnIdx.SalesLedger_Balance;
|
|
case SbmDbDfn.ColumnIdx.Association_DiscountType:
|
|
case SbmDbDfn.ColumnIdx.Association_DiscountRate:
|
|
case SbmDbDfn.ColumnIdx.Association_PriceSetId:
|
|
{
|
|
// These fields are only imported if 'Local Pricing' not in effect.
|
|
if (StringUtil.ToBool(GetOptionValue(Sbm.InterfaceType_Accounts.SageLine50, sageStatics.InterfaceOptions.GetCodeForType(SageInterfaceOption.Flag), sageStatics.OptionValues_Flag.GetCodeForType(SageFlag.UseLocalCustomerPricing))))
|
|
return SageDbDfn.ColumnIdx.Unknown;
|
|
switch (columnIdx)
|
|
{
|
|
case SbmDbDfn.ColumnIdx.Association_DiscountType: return SageDbDfn.ColumnIdx.SalesLedger_DiscountType;
|
|
case SbmDbDfn.ColumnIdx.Association_DiscountRate: return SageDbDfn.ColumnIdx.SalesLedger_DiscountRate;
|
|
case SbmDbDfn.ColumnIdx.Association_PriceSetId: return SageDbDfn.ColumnIdx.SalesLedger_PricingRef;
|
|
}
|
|
break;
|
|
}
|
|
case SbmDbDfn.ColumnIdx.Association_TaxCodeId: return SageDbDfn.ColumnIdx.SalesLedger_DefTaxCode;
|
|
case SbmDbDfn.ColumnIdx.Affiliate_Name: return SageDbDfn.ColumnIdx.SalesLedger_Name;
|
|
case SbmDbDfn.ColumnIdx.Affiliate_Contact: return SageDbDfn.ColumnIdx.SalesLedger_ContactName;
|
|
case SbmDbDfn.ColumnIdx.Affiliate_PhoneMain: return SageDbDfn.ColumnIdx.SalesLedger_Telephone;
|
|
case SbmDbDfn.ColumnIdx.Affiliate_PhoneAlt: return SageDbDfn.ColumnIdx.SalesLedger_Telephone2;
|
|
case SbmDbDfn.ColumnIdx.Affiliate_PhoneFax: return SageDbDfn.ColumnIdx.SalesLedger_Fax;
|
|
case SbmDbDfn.ColumnIdx.Affiliate_Email: return SageDbDfn.ColumnIdx.SalesLedger_EMail;
|
|
case SbmDbDfn.ColumnIdx.Affiliate_Website: return SageDbDfn.ColumnIdx.SalesLedger_WebAddress;
|
|
case SbmDbDfn.ColumnIdx.Affiliate_VatReg: return SageDbDfn.ColumnIdx.PurchaseLedger_VatRegNumber;
|
|
case SbmDbDfn.ColumnIdx.Address_Line1: return SageDbDfn.ColumnIdx.SalesLedger_Address1;
|
|
case SbmDbDfn.ColumnIdx.Address_Line2: return SageDbDfn.ColumnIdx.SalesLedger_Address2;
|
|
case SbmDbDfn.ColumnIdx.Address_Line3: return SageDbDfn.ColumnIdx.SalesLedger_Address3;
|
|
|
|
default:
|
|
// Is this column optionally sourced from a Sage 'Source' fields:
|
|
String colSource = GetOptionValue(Sbm.InterfaceType_Accounts.SageLine50, colSource_Customer, sageStatics.SalesLedgerColumnSources.GetCodeForType(columnIdx));
|
|
if (!StringUtil.IsEmpty(colSource))
|
|
{
|
|
if (colSource == SageDbDfn.GetColumnName(SageDbDfn.ColumnIdx.SalesLedger_Analysis1)) return SageDbDfn.ColumnIdx.SalesLedger_Analysis1;
|
|
if (colSource == SageDbDfn.GetColumnName(SageDbDfn.ColumnIdx.SalesLedger_Analysis2)) return SageDbDfn.ColumnIdx.SalesLedger_Analysis2;
|
|
if (colSource == SageDbDfn.GetColumnName(SageDbDfn.ColumnIdx.SalesLedger_Analysis3)) return SageDbDfn.ColumnIdx.SalesLedger_Analysis3;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (SbmDbDfn.GetTableForColumn(columnIdx) == SbmDbDfn.TableIdx.Commodity && importSageProducts)
|
|
{
|
|
switch (columnIdx)
|
|
{
|
|
case SbmDbDfn.ColumnIdx.Commodity_Code: return SageDbDfn.ColumnIdx.Stock_StockCode;
|
|
case SbmDbDfn.ColumnIdx.Commodity_DescBrief: return SageDbDfn.ColumnIdx.Stock_Description;
|
|
//case SbmDbDfn.ColumnIdx.Commodity_PackQty: return SageDbDfn.ColumnIdx.Stock_UnitOfSale; - Nov13 PackQty no longer derived from Sage Unit of sale (was populated with numeric portion of unit).
|
|
case SbmDbDfn.ColumnIdx.Commodity_Type: return SageDbDfn.ColumnIdx.Stock_IgnoreStkLvlFlag;
|
|
case SbmDbDfn.ColumnIdx.Commodity_ICNTariffCode: return SageDbDfn.ColumnIdx.Stock_CommodityCode;
|
|
case SbmDbDfn.ColumnIdx.Commodity_Location: return SageDbDfn.ColumnIdx.Stock_Location; // Exception where 'Location' is used as the source for anotehr field.
|
|
case SbmDbDfn.ColumnIdx.Commodity_NominalCode: return SageDbDfn.ColumnIdx.Stock_NominalCode;
|
|
case SbmDbDfn.ColumnIdx.Commodity_NominalCodePurchase: return SageDbDfn.ColumnIdx.Stock_PurchaseNominalCode;
|
|
case SbmDbDfn.ColumnIdx.Commodity_Category: return SageDbDfn.ColumnIdx.Stock_StockCat;
|
|
case SbmDbDfn.ColumnIdx.Commodity_Department: return SageDbDfn.ColumnIdx.Stock_DeptNumber;
|
|
case SbmDbDfn.ColumnIdx.Commodity_Weight: return SageDbDfn.ColumnIdx.Stock_UnitWeight;
|
|
case SbmDbDfn.ColumnIdx.Commodity_SalesPrice: return SageDbDfn.ColumnIdx.Stock_SalesPrice;
|
|
case SbmDbDfn.ColumnIdx.Commodity_TaxCodeId: return SageDbDfn.ColumnIdx.Stock_TaxCode;
|
|
case SbmDbDfn.ColumnIdx.Commodity_CostPrice: return SageDbDfn.ColumnIdx.Stock_LastPurchasePrice;
|
|
case SbmDbDfn.ColumnIdx.Commodity_AssIdSupplier: return SageDbDfn.ColumnIdx.Stock_PurchaseRef;
|
|
case SbmDbDfn.ColumnIdx.Commodity_SupplierRef: return SageDbDfn.ColumnIdx.Stock_SupplierPartNumber;
|
|
case SbmDbDfn.ColumnIdx.Commodity_ImagePath: return SageDbDfn.ColumnIdx.Stock_WebImageFile;
|
|
case SbmDbDfn.ColumnIdx.Commodity_DescOrder: return SageDbDfn.ColumnIdx.Stock_WebDescription;
|
|
case SbmDbDfn.ColumnIdx.Commodity_DescDetail: return SageDbDfn.ColumnIdx.Stock_WebDetails;
|
|
case SbmDbDfn.ColumnIdx.Commodity_QtyInStock: return SageDbDfn.ColumnIdx.Stock_QtyInStock;
|
|
case SbmDbDfn.ColumnIdx.Commodity_QtyAllocated: return SageDbDfn.ColumnIdx.Stock_QtyAllocated;
|
|
case SbmDbDfn.ColumnIdx.Commodity_ReorderQty: return SageDbDfn.ColumnIdx.Stock_QtyReorder;
|
|
case SbmDbDfn.ColumnIdx.Commodity_ReorderLevel: return SageDbDfn.ColumnIdx.Stock_QtyReorderLevel;
|
|
|
|
// Columns that are optionally sourced from selected Sage fields:
|
|
case SbmDbDfn.ColumnIdx.Commodity_Dimensions:
|
|
case SbmDbDfn.ColumnIdx.Commodity_RetailPrice:
|
|
case SbmDbDfn.ColumnIdx.Commodity_Volume:
|
|
case SbmDbDfn.ColumnIdx.Commodity_BoxQuantity:
|
|
// Is there a Sage 'Source' column defined for this column:
|
|
String colSource = GetOptionValue(Sbm.InterfaceType_Accounts.SageLine50, colSource_StockColumn, sageStatics.StockColumnSources.GetCodeForType(columnIdx));
|
|
if (!colSource.IsEmpty())
|
|
{
|
|
if (colSource == SageDbDfn.GetColumnName(SageDbDfn.ColumnIdx.Stock_Location)) return SageDbDfn.ColumnIdx.Stock_Location;
|
|
if (colSource == SageDbDfn.GetColumnName(SageDbDfn.ColumnIdx.Stock_WebCategory1)) return SageDbDfn.ColumnIdx.Stock_WebCategory1;
|
|
if (colSource == SageDbDfn.GetColumnName(SageDbDfn.ColumnIdx.Stock_WebCategory2)) return SageDbDfn.ColumnIdx.Stock_WebCategory2;
|
|
if (colSource == SageDbDfn.GetColumnName(SageDbDfn.ColumnIdx.Stock_WebCategory3)) return SageDbDfn.ColumnIdx.Stock_WebCategory3;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
return SageDbDfn.ColumnIdx.Unknown;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// ToDo SaSageConsole GetSageConsole ()
|
|
// ToDo SaSageDataObjectConsole GetSageSdoCon ()
|
|
// ToDo SaSageDataItem CreateSageDataItem ()
|
|
|
|
//-------------------------------------------------------------------
|
|
// U t i l i t i e s
|
|
//-------------------------------------------------------------------
|
|
public void Reset()
|
|
{
|
|
// Clear existing values.
|
|
sageParams.dfnInt_Sage = new SaInterface.Data();
|
|
qbkParams.dfnInt_QBooks = new SaInterface.Data();
|
|
// Retrieve Accounts interface objects.
|
|
if (InterfaceConsole != null)
|
|
{
|
|
// Retrieve accounts interfaces.
|
|
SaInterface.Params prmInterface_Accounts = new SaInterface.Params();
|
|
prmInterface_Accounts.Context = UserContext.Organisation.InterfaceContext;
|
|
prmInterface_Accounts.InterfaceCategory = SaInterfaceCategory.Accounts;
|
|
prmInterface_Accounts.ActiveOnly = true;
|
|
prmInterface_Accounts.StatusCat = SaInterface.StatusCat.ActiveOnly;
|
|
List<SaInterface> interfaces_Accounts = InterfaceConsole.GetInterfaceList(prmInterface_Accounts);
|
|
|
|
// Sage interface.
|
|
SaInterface sageInterface = interfaces_Accounts.Find(item => item.Type == (short)Sbm.InterfaceType_Accounts.SageLine50);
|
|
if (sageInterface != null)
|
|
sageParams.dfnInt_Sage = sageInterface.GetData();
|
|
|
|
// QBooks interface.
|
|
SaInterface qbkInterface = interfaces_Accounts.Find(item => item.Type == (short)Sbm.InterfaceType_Accounts.QuickBooks);
|
|
if (qbkInterface != null)
|
|
qbkParams.dfnInt_QBooks = qbkInterface.GetData();
|
|
}
|
|
// Sage Line 50 accounts.
|
|
sageParams.ItemOptions.Clear();
|
|
//sageParams.SageSdoCon = null;
|
|
//sageParams.SageCon = null;
|
|
// QuickBooks accounts.
|
|
qbkParams.ItemOptions.Clear();
|
|
//qbkParams.QBooksApiCon = null;
|
|
//qbkParams.QBooksCon = null;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// T a x C o d e s
|
|
//-------------------------------------------------------------------
|
|
private List<SaTaxCode> taxCodes = null;
|
|
protected List<CodeDesc> Values_TaxCodes
|
|
{
|
|
get
|
|
{
|
|
if (taxCodes == null)
|
|
{
|
|
SaTaxCode.Params prmTaxCode = new SaTaxCode.Params();
|
|
prmTaxCode.StatusCat = SaTaxCode.StatusCat.ActiveOnly;
|
|
}
|
|
List<CodeDesc> taxCodeValues = new List<CodeDesc>();
|
|
foreach (SaTaxCode taxCode in taxCodes)
|
|
taxCodeValues.Add(taxCode.Code, taxCode.Code);
|
|
return taxCodeValues;
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// I n i t A c c o u n t s I n t e r f a c e
|
|
//-------------------------------------------------------------------
|
|
public void InitOptions(Sbm.InterfaceType_Accounts accountsType)
|
|
{
|
|
switch (accountsType)
|
|
{
|
|
case Sbm.InterfaceType_Accounts.SageLine50:
|
|
InitSageInterfaceOptions();
|
|
break;
|
|
case Sbm.InterfaceType_Accounts.QuickBooks:
|
|
InitQuickBooksInterfaceOptions();
|
|
break;
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|