74 lines
3.5 KiB
C#
74 lines
3.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Headers;
|
|
|
|
namespace AyaNovaQBI
|
|
{
|
|
internal class util
|
|
{
|
|
public const string TEST_ROUTE = "notify/hello";
|
|
public const string API_BASE_ROUTE = "api/v8/";
|
|
private const int MAX_TRIES = 3;//max times to retry an api call before giving up
|
|
private const int API_RETRY_DELAY = 3000;//pause in ms before retrying api call
|
|
public static int HTTPCLIENT_TIMEOUT_SECONDS = 100;//changed by the setting in ops anyway, just a in-case sensible default here
|
|
public static HttpClient client = null;
|
|
internal static string SERVER_URL { get; set; } = Properties.Settings.Default.serverurl;
|
|
|
|
public static List<InvoiceableItem> GetInvoiceableItems()
|
|
{
|
|
var random = new Random();
|
|
var l = new List<InvoiceableItem>();
|
|
for (int i = 1; i < random.Next(25, 100); i++)
|
|
l.Add(new InvoiceableItem { Customer = $"Customer {random.Next(1, 5)}", Linked = random.Next(2) == 1, Project = $"project {i}", ServiceDate = DateTime.Now.ToString("g"), ServiceNumber = (40 + i).ToString(), Status = $"Waiting to be invoiced", StatusColor = "FF00FFAA", WorkorderId = 4 });
|
|
|
|
return l.OrderBy(x => x.Customer)
|
|
.ThenBy(x => x.ServiceNumber)
|
|
.ThenBy(x => x.ServiceDate)
|
|
.ToList();
|
|
|
|
}
|
|
|
|
|
|
public static async Task<bool> InitializeQBI()
|
|
{
|
|
//COPY most of this code from qbi v7 becuase it has a lot of edge cases in it and it's complex and thorough, but break it into abstracted bits so can be replicated in other accounting add-on's more easily
|
|
|
|
//This is pre-pfc block of stuff that doesn't map well from v7 qbi plugin to here so replicate it in spirit here but not much is copyable just the concepts
|
|
//LOGIN to v8 first
|
|
auth d = new auth();
|
|
if (d.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
|
|
return false;
|
|
|
|
//Fetch AyaNova license
|
|
//Check if licensed
|
|
//check if build date is within licensed date (how did I do that automated build date thing?)
|
|
// copy timestamp.cs and the createtimestamp.exe utility from v7 qbi and create build event to run it here and do same thing
|
|
//check that AyaNova version matches required minimum for this QBI (
|
|
|
|
//PFC - Util.QBValidate stuff:
|
|
//Validate QB connection can be made and open connection and start session with QB (see Util.QBValidate in v7
|
|
//once connected collect the country, version we are dealing with (Util.qbValidate)
|
|
//confirm qb is 2008 or newer and bail if not (util.qbvalidate)
|
|
//cache company name and other qb info
|
|
//PFC - PopulateQBListCache()
|
|
//PFC - PopulateAyaListCache()
|
|
//PFC - integration object check (fetch or create if not present) (Util.integrationObjectCheck())
|
|
//PFC - Validate settings, create if necessary (Util.ValidateSettings()) and save
|
|
//PFC - verify integration mapped objects still exist at each end (Util.PreFlightCheck() line 199)
|
|
//DONE
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|