This commit is contained in:
@@ -98,6 +98,7 @@
|
||||
<Compile Include="NameIdItem.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="QBIIntegrationData.cs" />
|
||||
<Compile Include="tfa.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
||||
379
AyaNovaQBI/QBIIntegrationData.cs
Normal file
379
AyaNovaQBI/QBIIntegrationData.cs
Normal file
@@ -0,0 +1,379 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AyaNovaQBI
|
||||
{
|
||||
internal class QBIIntegrationData
|
||||
{
|
||||
/*
|
||||
|
||||
{"IsDirty":false,"QBInventoryIncomeAccountReference":"","QBInventoryCOGSAccountRef":"","QBInventoryAssetAccountRef":"","QBServiceIncomeAccountRef":"",
|
||||
"TermsDefault":"","PreWOStatus":"00000000-0000-0000-0000-000000000000","PostWOStatus":"00000000-0000-0000-0000-000000000000","OutsideServiceChargeAs":"",
|
||||
"MiscExpenseChargeAs":"","WorkorderItemLoanChargeAs":"","QBInvoiceTemplate":"","SetMemoField":true,"TransactionClass":"","ToBePrinted":true,"InvoiceHeaderTemplate":"",
|
||||
"InvoiceFooterTemplate":"","InvoiceUnitTemplate":"","InvoiceServiceTemplate":"","InvoiceTravelTemplate":"","InvoiceOutsideServiceTemplate":"","InvoiceMiscExpenseTemplate":"",
|
||||
"InvoiceLoanItemTemplate":"","HasInvoiceHeaderTemplate":false,"HasAnyInvoiceFooterTemplateFields":false,"AutoClose":true,"NothingSet":true}
|
||||
*/
|
||||
#region fields
|
||||
private Guid _PreWOStatus = Guid.Empty;
|
||||
private Guid _PostWOStatus = Guid.Empty;
|
||||
private string _OutsideServiceChargeAs = "";
|
||||
private string _WorkorderItemLoanChargeAs = "";
|
||||
private string _MiscExpenseChargeAs = "";
|
||||
private string _QBInvoiceTemplate = "";
|
||||
private bool _SetMemoField = true;
|
||||
private string _TransactionClass = "";
|
||||
private bool _ToBePrinted = true;
|
||||
private string _InvoiceHeaderTemplate = "";
|
||||
private string _InvoiceFooterTemplate = "";
|
||||
private string _InvoiceUnitTemplate = "";
|
||||
private string _InvoiceServiceTemplate = "";
|
||||
private string _InvoiceTravelTemplate = "";
|
||||
private string _InvoiceOutsideServiceTemplate = "";
|
||||
private string _InvoiceMiscExpenseTemplate = "";
|
||||
private string _InvoiceLoanItemTemplate = "";
|
||||
|
||||
//Case 7
|
||||
private bool _AutoClose = true;
|
||||
|
||||
#region Case 632
|
||||
//Default qb accounts to use when importing inventory and service items
|
||||
//from ayanova to QuickBooks
|
||||
private string _QBInventoryIncomeAccountReference = "";
|
||||
public string QBInventoryIncomeAccountReference
|
||||
{
|
||||
get { return _QBInventoryIncomeAccountReference; }
|
||||
set { if (_QBInventoryIncomeAccountReference != value) { _QBInventoryIncomeAccountReference = value; IsDirty = true; } }
|
||||
}
|
||||
|
||||
private string _QBInventoryCOGSAccountRef = "";
|
||||
public string QBInventoryCOGSAccountRef
|
||||
{
|
||||
get { return _QBInventoryCOGSAccountRef; }
|
||||
set { if (_QBInventoryCOGSAccountRef != value) { _QBInventoryCOGSAccountRef = value; IsDirty = true; } }
|
||||
}
|
||||
|
||||
private string _QBInventoryAssetAccountRef = "";
|
||||
public string QBInventoryAssetAccountRef
|
||||
{
|
||||
get { return _QBInventoryAssetAccountRef; }
|
||||
set { if (_QBInventoryAssetAccountRef != value) { _QBInventoryAssetAccountRef = value; IsDirty = true; } }
|
||||
}
|
||||
|
||||
|
||||
private string _QBServiceIncomeAccountRef = "";
|
||||
public string QBServiceIncomeAccountRef
|
||||
{
|
||||
get { return _QBServiceIncomeAccountRef; }
|
||||
set { if (_QBServiceIncomeAccountRef != value) { _QBServiceIncomeAccountRef = value; IsDirty = true; } }
|
||||
}
|
||||
#endregion
|
||||
|
||||
//Case 519
|
||||
private string _TermsDefault = "";
|
||||
public string TermsDefault
|
||||
{
|
||||
get { return _TermsDefault; }
|
||||
set { if (_TermsDefault != value) { _TermsDefault = value; IsDirty = true; } }
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool IsDirty = false;
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
public Guid PreWOStatus
|
||||
{
|
||||
get { return _PreWOStatus; }
|
||||
set
|
||||
{
|
||||
if (_PreWOStatus != value)
|
||||
{
|
||||
_PreWOStatus = value;
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Guid PostWOStatus
|
||||
{
|
||||
get { return _PostWOStatus; }
|
||||
set
|
||||
{
|
||||
if (_PostWOStatus != value)
|
||||
{
|
||||
_PostWOStatus = value;
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string OutsideServiceChargeAs
|
||||
{
|
||||
get { return _OutsideServiceChargeAs; }
|
||||
set
|
||||
{
|
||||
if (_OutsideServiceChargeAs != value)
|
||||
{
|
||||
_OutsideServiceChargeAs = value;
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
public string MiscExpenseChargeAs
|
||||
{
|
||||
get { return _MiscExpenseChargeAs; }
|
||||
set
|
||||
{
|
||||
if (_MiscExpenseChargeAs != value)
|
||||
{
|
||||
_MiscExpenseChargeAs = value;
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string WorkorderItemLoanChargeAs
|
||||
{
|
||||
get { return _WorkorderItemLoanChargeAs; }
|
||||
set
|
||||
{
|
||||
if (_WorkorderItemLoanChargeAs != value)
|
||||
{
|
||||
_WorkorderItemLoanChargeAs = value;
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
public string QBInvoiceTemplate
|
||||
{
|
||||
get { return _QBInvoiceTemplate; }
|
||||
set
|
||||
{
|
||||
if (_QBInvoiceTemplate != value)
|
||||
{
|
||||
_QBInvoiceTemplate = value;
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
public bool SetMemoField
|
||||
{
|
||||
get { return _SetMemoField; }
|
||||
set
|
||||
{
|
||||
if (_SetMemoField != value)
|
||||
{
|
||||
_SetMemoField = value;
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string TransactionClass
|
||||
{
|
||||
get { return _TransactionClass; }
|
||||
set
|
||||
{
|
||||
if (_TransactionClass != value)
|
||||
{
|
||||
_TransactionClass = value;
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ToBePrinted
|
||||
{
|
||||
get { return _ToBePrinted; }
|
||||
set
|
||||
{
|
||||
if (_ToBePrinted != value)
|
||||
{
|
||||
_ToBePrinted = value;
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string InvoiceHeaderTemplate
|
||||
{
|
||||
get { return _InvoiceHeaderTemplate; }
|
||||
set
|
||||
{
|
||||
if (_InvoiceHeaderTemplate != value)
|
||||
{
|
||||
_InvoiceHeaderTemplate = value;
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string InvoiceFooterTemplate
|
||||
{
|
||||
get { return _InvoiceFooterTemplate; }
|
||||
set
|
||||
{
|
||||
if (_InvoiceFooterTemplate != value)
|
||||
{
|
||||
_InvoiceFooterTemplate = value;
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string InvoiceUnitTemplate
|
||||
{
|
||||
get { return _InvoiceUnitTemplate; }
|
||||
set
|
||||
{
|
||||
if (_InvoiceUnitTemplate != value)
|
||||
{
|
||||
_InvoiceUnitTemplate = value;
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string InvoiceServiceTemplate
|
||||
{
|
||||
get { return _InvoiceServiceTemplate; }
|
||||
set
|
||||
{
|
||||
if (_InvoiceServiceTemplate != value)
|
||||
{
|
||||
_InvoiceServiceTemplate = value;
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string InvoiceTravelTemplate
|
||||
{
|
||||
get { return _InvoiceTravelTemplate; }
|
||||
set
|
||||
{
|
||||
if (_InvoiceTravelTemplate != value)
|
||||
{
|
||||
_InvoiceTravelTemplate = value;
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string InvoiceOutsideServiceTemplate
|
||||
{
|
||||
get { return _InvoiceOutsideServiceTemplate; }
|
||||
set
|
||||
{
|
||||
if (_InvoiceOutsideServiceTemplate != value)
|
||||
{
|
||||
_InvoiceOutsideServiceTemplate = value;
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string InvoiceMiscExpenseTemplate
|
||||
{
|
||||
get { return _InvoiceMiscExpenseTemplate; }
|
||||
set
|
||||
{
|
||||
if (_InvoiceMiscExpenseTemplate != value)
|
||||
{
|
||||
_InvoiceMiscExpenseTemplate = value;
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string InvoiceLoanItemTemplate
|
||||
{
|
||||
get { return _InvoiceLoanItemTemplate; }
|
||||
set
|
||||
{
|
||||
if (_InvoiceLoanItemTemplate != value)
|
||||
{
|
||||
_InvoiceLoanItemTemplate = value;
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public bool HasInvoiceHeaderTemplate
|
||||
{
|
||||
get
|
||||
{
|
||||
return _InvoiceHeaderTemplate != "";
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAnyInvoiceFooterTemplateFields
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._InvoiceFooterTemplate != "" ||
|
||||
this._InvoiceUnitTemplate != "" ||
|
||||
this._InvoiceServiceTemplate != "" ||
|
||||
this._InvoiceTravelTemplate != "" ||
|
||||
this._InvoiceLoanItemTemplate != "" ||
|
||||
this._InvoiceMiscExpenseTemplate != "" ||
|
||||
this._InvoiceOutsideServiceTemplate != ""
|
||||
)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//Case 7
|
||||
public bool AutoClose
|
||||
{
|
||||
get { return _AutoClose; }
|
||||
set
|
||||
{
|
||||
if (_AutoClose != value)
|
||||
{
|
||||
_AutoClose = value;
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Flag indicating whether user has configured
|
||||
/// QBI at all yet, this is used to present a description
|
||||
/// of the configuration that is about to take place to the user
|
||||
///
|
||||
/// If this is false then any missing option is considered a one-off
|
||||
/// and no general initial description is given to the user about setting
|
||||
/// up QBI
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public bool NothingSet
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_PreWOStatus == Guid.Empty &&
|
||||
_PostWOStatus == Guid.Empty &&
|
||||
_OutsideServiceChargeAs == "" &&
|
||||
_WorkorderItemLoanChargeAs == "" &&
|
||||
_MiscExpenseChargeAs == "" &&
|
||||
_TransactionClass == "" &&
|
||||
_QBInvoiceTemplate == "") return true;
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
#endregion props
|
||||
|
||||
}
|
||||
}
|
||||
@@ -564,15 +564,11 @@ namespace AyaNovaQBI
|
||||
await IntegrationLog($"PFC: QB Company name= {QCompanyName}, QB Country version={QCountry}, QBVersion={QVersion}, Companyfile={QCompanyFile}");
|
||||
await PopulateQBListCache();
|
||||
await PopulateAyaListCache();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(QBIntegration.IntegrationData) || QBIntegration.Items.Count == 0)
|
||||
return true;//nothing mapped or set to validate return to mainform for initial setup to be triggered
|
||||
|
||||
//PFC - verify integration mapped objects still exist in QB
|
||||
if (!await ValidateQuickBooksHasMappedItems(initErrors))
|
||||
return false;
|
||||
|
||||
//DONE
|
||||
await IntegrationLog("PFC: QBI initialized and ready for use");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -582,10 +578,6 @@ namespace AyaNovaQBI
|
||||
return false;
|
||||
}
|
||||
|
||||
await IntegrationLog("PFC: QBI initialized and ready for use");
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -608,6 +600,7 @@ namespace AyaNovaQBI
|
||||
QBIntegration.IntegrationAppId = QBI_INTEGRATION_ID;
|
||||
QBIntegration.Active = true;
|
||||
QBIntegration.Name = "QBI - QuickBooks Desktop integration";
|
||||
QBIntegration.IntegrationData = Newtonsoft.Json.JsonConvert.SerializeObject(new QBIIntegrationData());//default empty integration data object
|
||||
r = await PostAsync("integration", Newtonsoft.Json.JsonConvert.SerializeObject(QBIntegration));
|
||||
QBIntegration.Id = IdFromResponse(r);
|
||||
await IntegrationLog("AyaNova QBI Integration installed to AyaNova");
|
||||
@@ -618,6 +611,12 @@ namespace AyaNovaQBI
|
||||
r = await GetAsync($"integration/{QBI_INTEGRATION_ID}");
|
||||
QBIntegration = r.ObjectResponse["data"].ToObject<Integration>();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(QBIntegration.IntegrationData))
|
||||
{
|
||||
initErrors.AppendLine("QBI Integration data is empty which should not happen normally and indicates corruption of some kind with the QBI setttings data stored in AyaNova.\r\nThe QBI settings should be removed and re-created by deleting the QBI Integration object in AyaNova\r\nSee the Administration section -> Integrations -> QuickBooks Desktop integration record in AyaNova\r\nThis record should be deleted then restart QBI to start setup again and create a fresh QBI integration settings object in AyaNova");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!QBIntegration.Active)
|
||||
{
|
||||
initErrors.AppendLine("QBI Integration is currently deactivated and can not be used\r\nThis setting can be changed in AyaNova in the Administration section -> Integrations -> QuickBooks Desktop integration record\r\nSet to active and save to enable QBI");
|
||||
@@ -645,7 +644,7 @@ namespace AyaNovaQBI
|
||||
{
|
||||
//Missing links table:
|
||||
DataTable dtTemp = new DataTable();
|
||||
dtTemp.Columns.Add("MAPID", typeof(Guid));
|
||||
dtTemp.Columns.Add("MAPID", typeof(long));
|
||||
dtTemp.Columns.Add("Name", typeof(string));
|
||||
|
||||
bool present = true;
|
||||
@@ -694,7 +693,7 @@ namespace AyaNovaQBI
|
||||
if (dr == DialogResult.Yes)
|
||||
{
|
||||
await IntegrationLog("PFC: User opted to remove all mappings after double warning.");
|
||||
QBIntegration.Items.Clear();
|
||||
QBIntegration.Items.Clear();
|
||||
//Exists, fetch it check if active then we're done here
|
||||
ApiResponse r = await PostAsync($"integration/{QBI_INTEGRATION_ID}", Newtonsoft.Json.JsonConvert.SerializeObject(QBIntegration));
|
||||
QBIntegration = r.ObjectResponse["data"].ToObject<Integration>();
|
||||
|
||||
Reference in New Issue
Block a user