void SetItemSource(QueryAPI api) { var prCache = api.GetCache(typeof(Uniconta.DataModel.PrCategory)) ?? api.LoadCache(typeof(Uniconta.DataModel.PrCategory)).GetAwaiter().GetResult(); var cache = new PrCategoryRevenueFilter(prCache); cmbCategory.cacheFilter = new PrCategoryRevenueFilter(prCache); }
static async void FindOnEANVariant(DCOrderLineClient rec, QueryAPI api, Uniconta.API.DebtorCreditor.FindPrices PriceLookup) { if (PriceLookup != null && PriceLookup.UseCustomerPrices) { var found = await PriceLookup.GetCustomerPriceFromEAN(rec); if (found) { return; } } var ap = new Uniconta.API.Inventory.ReportAPI(api); var variant = await ap.GetInvVariantDetail(rec._EAN); if (variant != null) { rec.Item = variant._Item; rec.Variant1 = variant._Variant1; rec.Variant2 = variant._Variant2; rec.Variant3 = variant._Variant3; rec.Variant4 = variant._Variant4; rec.Variant5 = variant._Variant5; rec._EAN = variant._EAN; if (variant._CostPrice != 0d) { rec._CostPrice = variant._CostPrice; } } }
async void SetItemSource(QueryAPI api) { var prCache = api.GetCache(typeof(Uniconta.DataModel.PrCategory)) ?? await api.LoadCache(typeof(Uniconta.DataModel.PrCategory)); // cmbCategory.ItemsSource = new PrCategoryRevenueFilter(prCache); cmbRegCategory.ItemsSource = new PrCategoryRegulationFilter(prCache); }
static public void SetGLNnumber(DCInvoice InvClient, DCAccount client, QueryAPI api) { var Comp = api.CompanyEntity; var installation = (WorkInstallation)Comp.GetCache(typeof(WorkInstallation), api)?.Get(InvClient._Installation); var deliveryAccount = (DCAccount)Comp.GetCache(typeof(Debtor), api)?.Get(InvClient._DeliveryAccount); var debtor = client ?? (DCAccount)Comp.GetCache(typeof(Debtor), api)?.Get(InvClient._DCAccount); var contact = (Contact)Comp.GetCache(typeof(Contact), api)?.Get(InvClient._ContactRef); InvClient._EAN = installation?._GLN ?? deliveryAccount?._EAN ?? contact?._EAN ?? debtor?._EAN; }
static public void SetGLNnumber(DCInvoice InvClient, DCAccount client, QueryAPI api) { var installation = (WorkInstallation)api.GetCache(typeof(WorkInstallation))?.Get(InvClient._Installation); var dctype = InvClient.__DCType(); var dccache = api.GetCache((dctype == 2 || dctype == 9) ? typeof(Uniconta.DataModel.Creditor) : typeof(Uniconta.DataModel.Debtor)); var debtor = client ?? (DCAccount)dccache?.Get(InvClient._DCAccount); var contact = (Contact)api.GetCache(typeof(Contact))?.Get(InvClient._ContactRef); InvClient._EAN = installation?._GLN ?? contact?._EAN ?? debtor?._EAN; }
private static void InstantiateApi() { CAPI = new CrudAPI(Session, Company); QAPI = new QueryAPI(Session, Company); if (CAPI == null) { throw new CoreExceptions.ApiInitializeException("CRUD API is null"); } if (QAPI == null) { throw new CoreExceptions.ApiInitializeException("Query API is null"); } }
static async void FindOnEANVariant(InvItemStorageCount rec, QueryAPI api) { var ap = new Uniconta.API.Inventory.ReportAPI(api); var variant = await ap.GetInvVariantDetail(rec._EAN); if (variant != null) { rec.Item = variant._Item; rec.Variant1 = variant._Variant1; rec.Variant2 = variant._Variant2; rec.Variant3 = variant._Variant3; rec.Variant4 = variant._Variant4; rec.Variant5 = variant._Variant5; rec._EAN = variant._EAN; } }
async Task LoadBaseData(QueryAPI api) { this.comp = api.CompanyEntity; payrollCategoryCache = api.GetCache <Uniconta.DataModel.EmpPayrollCategory>() ?? await api.LoadCache <Uniconta.DataModel.EmpPayrollCategory>().ConfigureAwait(false); projectCache = comp.GetCache(typeof(Uniconta.DataModel.Project)) ?? await api.LoadCache(typeof(Uniconta.DataModel.Project)).ConfigureAwait(false); employeeCache = comp.GetCache(typeof(Uniconta.DataModel.Employee)) ?? await api.LoadCache(typeof(Uniconta.DataModel.Employee)).ConfigureAwait(false); projectGrpCache = comp.GetCache(typeof(Uniconta.DataModel.ProjectGroup)) ?? await api.LoadCache(typeof(Uniconta.DataModel.ProjectGroup)).ConfigureAwait(false); prCategoryCache = comp.GetCache(typeof(Uniconta.DataModel.PrCategory)) ?? await api.LoadCache(typeof(Uniconta.DataModel.PrCategory)).ConfigureAwait(false); prTaskCache = comp.GetCache(typeof(Uniconta.DataModel.ProjectTask)) ?? await api.LoadCache(typeof(Uniconta.DataModel.ProjectTask)).ConfigureAwait(false); LoadingTask = null; // we are done }
static public void FindOnEAN(InvItemStorageCount rec, SQLCache Items, QueryAPI api) { var EAN = rec._EAN; if (string.IsNullOrWhiteSpace(EAN)) { return; } var found = (from item in (InvItem[])Items.GetNotNullArray where string.Compare(item._EAN, EAN, StringComparison.CurrentCultureIgnoreCase) == 0 select item).FirstOrDefault(); if (found != null) { rec._EAN = found._EAN; rec.Item = found._Item; } else { FindOnEANVariant(rec, api); } }
static async void FindOnEANVariant(DCOrderLineClient rec, QueryAPI api) { var ap = new Uniconta.API.Inventory.ReportAPI(api); var variant = await ap.GetInvVariantDetail(rec._EAN); if (variant != null) { rec.Item = variant._Item; rec.Variant1 = variant._Variant1; rec.Variant2 = variant._Variant2; rec.Variant3 = variant._Variant3; rec.Variant4 = variant._Variant4; rec.Variant5 = variant._Variant5; rec._EAN = variant._EAN; if (variant._CostPrice != 0d) { rec._CostPrice = variant._CostPrice; } } }
static public void FindOnEAN(DCOrderLineClient rec, SQLCache Items, QueryAPI api, Uniconta.API.DebtorCreditor.FindPrices PriceLookup) { var EAN = rec._EAN; if (string.IsNullOrWhiteSpace(EAN)) { return; } var found = (from item in (InvItem[])Items.GetNotNullArray where string.Compare(item._EAN, EAN, StringComparison.CurrentCultureIgnoreCase) == 0 select item).FirstOrDefault(); if (found != null) { rec._EAN = found._EAN; rec.Item = found._Item; } else { FindOnEANVariant(rec, api, PriceLookup); } }
public FindPrices(DCOrder order, QueryAPI api) { this.order = order; this.api = api; LoadingTask = LoadBaseData(api); }
private async Task LoadBaseData(QueryAPI api) { var Comp = api.CompanyEntity; this.CompCurrency = (byte)Comp._CurrencyId; this.CustomerPrices = null; if (order == null) { return; } Type MasterType, GroupType, PriceListType; if (order.__DCType() != 2) { MasterType = typeof(Uniconta.DataModel.Debtor); GroupType = typeof(Uniconta.DataModel.DebtorGroup); PriceListType = typeof(Uniconta.DataModel.DebtorPriceList); UseCustomerPrices = Comp.InvPrice; } else { MasterType = typeof(Uniconta.DataModel.Creditor); GroupType = typeof(Uniconta.DataModel.CreditorGroup); PriceListType = typeof(Uniconta.DataModel.CreditorPriceList); UseCustomerPrices = Comp.CreditorPrice; } OrderCurrency = (byte)order._Currency; if (OrderCurrency == 0) { OrderCurrency = CompCurrency; } if (OrderCurrency != CompCurrency) { if (LastOrderCurrency == OrderCurrency) { this.ExchangeRate = LastExchangeRate; } this.ExchangeTask = api.session.ExchangeRate((Currencies)CompCurrency, (Currencies)OrderCurrency, DateTime.Now, Comp); this.ExchangeRate = await this.ExchangeTask.ConfigureAwait(false); LastExchangeRate = this.ExchangeRate; LastOrderCurrency = OrderCurrency; this.ExchangeTask = null; } this.items = Comp.GetCache(typeof(Uniconta.DataModel.InvItem)) ?? await Comp.LoadCache(typeof(Uniconta.DataModel.InvItem), api).ConfigureAwait(false); if (order._DCAccount != null) { var Debs = Comp.GetCache(MasterType) ?? await Comp.LoadCache(MasterType, api).ConfigureAwait(false); var debtor = (Uniconta.DataModel.DCAccount)Debs.Get(order._DCAccount); if (debtor != null) { PriceGrp = Common.Utility.Util.Value(debtor._PriceGroup); this.debtor = debtor; this._PriceList = order._PriceList ?? debtor._PriceList; if (this._PriceList == null) { var DebGrps = Comp.GetCache(GroupType) ?? await Comp.LoadCache(GroupType, api).ConfigureAwait(false); var grp = (Uniconta.DataModel.DCGroup)DebGrps.Get(debtor._Group); if (grp != null) { _PriceList = grp._PriceList; } if (_PriceList == null) { UseCustomerPrices = false; } } } } if (UseCustomerPrices) { this.priceLists = Comp.GetCache(PriceListType) ?? await Comp.LoadCache(PriceListType, api).ConfigureAwait(false); } LoadingTask = null; // we are done }
static public void SetDeliveryAdress(DCInvoice InvClient, DCAccount client, QueryAPI api) { SetGLNnumber(InvClient, client, api); if (InvClient._DeliveryAddress1 != null) { return; } if (InvClient._Installation != null) { var wInsCache = api.GetCache(typeof(WorkInstallation)) ?? api.LoadCache(typeof(WorkInstallation)).GetAwaiter().GetResult(); var installation = (WorkInstallation)wInsCache.Get(InvClient._Installation); if (installation == null) { wInsCache = api.LoadCache(typeof(WorkInstallation), true).GetAwaiter().GetResult(); installation = (WorkInstallation)wInsCache.Get(InvClient._Installation); } if (installation != null) { InvClient._DeliveryName = installation._Name; InvClient._DeliveryAddress1 = installation._Address1; InvClient._DeliveryAddress2 = installation._Address2; InvClient._DeliveryAddress3 = installation._Address3; InvClient._DeliveryZipCode = installation._ZipCode; InvClient._DeliveryCity = installation._City; if (api.CompanyEntity._Country != (byte)installation._Country) { InvClient._DeliveryCountry = installation._Country; } } } else { DCAccount deb = null; string ac; bool UseDebAddress; if (InvClient._DeliveryAccount != null) { ac = InvClient._DeliveryAccount; UseDebAddress = true; } else { UseDebAddress = false; if (client != null) { deb = client; ac = null; } else { ac = InvClient._DCAccount; } } if (ac != null) { var dctype = InvClient.__DCType(); var t = (dctype == 2 || dctype == 9) ? typeof(Uniconta.DataModel.Creditor) : typeof(Uniconta.DataModel.Debtor); var dcCache = api.GetCache(t) ?? api.LoadCache(t).GetAwaiter().GetResult(); deb = (DCAccount)dcCache.Get(ac); if (deb == null) { dcCache = api.LoadCache(t, true).GetAwaiter().GetResult(); deb = (DCAccount)dcCache.Get(ac); } } if (deb != null) { if (deb._DeliveryAddress1 != null) { InvClient._DeliveryName = deb._DeliveryName; InvClient._DeliveryAddress1 = deb._DeliveryAddress1; InvClient._DeliveryAddress2 = deb._DeliveryAddress2; InvClient._DeliveryAddress3 = deb._DeliveryAddress3; InvClient._DeliveryZipCode = deb._DeliveryZipCode; InvClient._DeliveryCity = deb._DeliveryCity; InvClient._DeliveryCountry = deb._DeliveryCountry; } else if (UseDebAddress) { InvClient._DeliveryName = deb._Name; InvClient._DeliveryAddress1 = deb._Address1; InvClient._DeliveryAddress2 = deb._Address2; InvClient._DeliveryAddress3 = deb._Address3; InvClient._DeliveryZipCode = deb._ZipCode; InvClient._DeliveryCity = deb._City; if (api.CompanyEntity._Country != (byte)deb._Country) { InvClient._DeliveryCountry = deb._Country; } } } } }
async void SetItemSource(QueryAPI api) { var prCache = api.CompanyEntity.GetCache(typeof(Uniconta.DataModel.PrCategory)) ?? await api.CompanyEntity.LoadCache(typeof(Uniconta.DataModel.PrCategory), api); cmbCategory.ItemsSource = new PrCategoryRevenueFilter(prCache); }
private async Task FooAsync(QueryAPI queryAPI, CrudAPI crudAPI, SyncSettings syncSettings) { Task <T[]> result = await queryAPI.QueryAsync <T>(); }
static void Main(string[] args) { AskCredentials(out username, out password); #region Create session and log in // Create connection var connection = new UnicontaConnection(APITarget.Live); // Create session var session = new Session(connection); // Login user. The guid required here is the partner API key which you will get when you ask for it as a partner. var apiKey = new Guid("00000000-0000-0000-0000-000000000000"); if (apiKey.Equals(Guid.Empty)) { Console.WriteLine("You need to set the API key"); return; } var logged = session.LoginAsync(username, password, Uniconta.Common.User.LoginType.API, apiKey).Result; if (logged != Uniconta.Common.ErrorCodes.Succes) { Console.WriteLine("Login failed"); return; } #endregion #region Selecting a company for the session // Select the company for session, otherwise it will be default company in Uniconta var companies = session.GetCompanies().Result; var company = session.GetCompany(companies[0].CompanyId).Result; // Getting specific company var defaultCompany = session.User._DefaultCompany; // returns an ID of the company session.OpenCompany(defaultCompany, true); // true sets the default company for the session, not as a default company for the user #endregion #region API examples // Set the API you want to use. Query, Crud and other APIs with different functionality var api = new CrudAPI(session, company); var qapi = new QueryAPI(session, company); #endregion #region Create records // Insert example CrmProspectClient prospect = new CrmProspectClient(); prospect.Name = "UC corp."; prospect.CompanyRegNo = "12315151"; prospect.Address1 = "Tree 1, Branch 2"; // Single record insert var error = api.Insert(prospect).Result; Thread.Sleep(500); // This is just to make sure that insert is done before I request data var tempProspects = api.Query <CrmProspectClient>().Result; // This is without any filters and gets all the entities // This is local LINQ query, instead of using for loop or other loops to find correct entity var master = tempProspects.Where(pr => pr.Name == "UC corp.").FirstOrDefault(); var contacts = new List <ContactClient>(); ContactClient contact = new ContactClient(); contact.Name = "Jane Doe"; contact.Email = "*****@*****.**"; contact.SetMaster(master); contacts.Add(contact); contact = new ContactClient(); contact.Name = "John Doe"; contact.Email = "*****@*****.**"; contact.SetMaster(master); contacts.Add(contact); // Bulk insert, warning, dont insert too many records. Try to do it in batches. error = api.Insert(contacts).Result; #endregion #region Read records // Plain no filter query, gets all the records on this entity in session company. var debtorOrders = api.Query <DebtorOrderClient>().Result; // Just to show, what we got foreach (var creditor in debtorOrders) { Console.WriteLine("Order: " + creditor.OrderNumber + " - " + creditor.Account); } // Querying rows that are all related to master record. var orderLines = api.Query <DebtorOrderLineClient>(debtorOrders[0]).Result; // Setting up a filter DateTime fromDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1); DateTime toDate = DateTime.Today; var filter = new List <PropValuePair> { PropValuePair.GenereteWhereElements("Date", typeof(DateTime), $"{fromDate.ToString("d/M-yyyy", CultureInfo.InvariantCulture)}..{toDate.ToString("d/M-yyyy", CultureInfo.InvariantCulture)}"), PropValuePair.GenereteOrderByElement("Account", true) // This is sorting filter. }; var invoices = api.Query <DebtorInvoiceClient>(filter).Result; // Creating SQL filter filter = new List <PropValuePair>(); filter.Add(PropValuePair.GenereteWhere("Account <= '1234' and Name like 'Something'")); var debtorClients = api.Query <DebtorClient>(filter).Result; // Pagination filter var page = 0; var pageSize = 10; filter = new List <PropValuePair>(); filter.Add(PropValuePair.GenereteOrderByElement("RowId", false)); filter.Add(PropValuePair.GenereteSkipN(pageSize * page)); filter.Add(PropValuePair.GenereteTakeN(pageSize * (page + 1))); debtorClients = api.Query <DebtorClient>(filter).Result; #endregion #region Update records // Update example var prospects = api.Query <CrmProspect>().Result; prospects[0]._Address1 = "Tree 2, Branch 3"; error = api.Update(prospects[0]).Result; // Update example using streamingmanager to make sure only fields you updated will be updated prospects = api.Query <CrmProspect>().Result; var updProspect = prospects[0]; var originalProspect = StreamingManager.Clone(updProspect); updProspect._Address1 = "Tree 2, Branch 3"; error = api.Update(originalProspect, updProspect).Result; // And again, you can update in bulk. #endregion #region Delete records // Delete näide prospects = api.Query <CrmProspect>().Result; error = api.Delete(prospects[0]).Result; #endregion #region Additional possibilities // MultiCrud enables you to insert, update and delete at the same time // api.MultiCrud() // NoResponse if no response is required with these operations // api.InsertNoResponse(); // api.UpdateNoResponse(); // api.DeleteNoResponse(); // Cache SQLCache cache = api.CompanyEntity.GetCache(typeof(InvItemClient)); if (cache == null) { cache = api.CompanyEntity.LoadCache(typeof(InvItemClient), api).Result; } var item = cache.Get("1001"); // Gets all records from cache var invEntities = cache.GetRecords as InvItemClient[]; // Get specific items var specItems = invEntities.Where(i => i.KeyName.Contains("old") && i.Available > 3); #endregion #region UserDocuments // Insert UserDocuments var file = File.ReadAllBytes(@"PATH TO FILE"); UserDocsClient newUserDoc = new UserDocsClient { Created = DateTime.Now, DocumentType = FileextensionsTypes.DOCX, Text = "My file name for UC", _Data = file, }; newUserDoc.SetMaster(prospect); ErrorCodes errorCode = api.Insert(newUserDoc).Result; // Read UserDocuments var prospectDocuments = api.Query <UserDocsClient>(prospect).Result; if (prospectDocuments.Length != 0) { var readResult = api.Read(prospectDocuments[0]).Result; var fileBytes = prospectDocuments[0]._Data; if (prospectDocuments[0].DocumentType == FileextensionsTypes.DOCX) { File.WriteAllBytes(@"PATH TO FILE", fileBytes); } } #endregion /*Other APIs: * * GeneralLedger: * • ReportAPI * • BankStatementAPI * • DocumentAPI * • FinancialYearAPI * • PeriodTotalAPI * • PostingAPI * • StandardGLAccountAPI * DebtorCreditor: * • DebtorOrderAPI * • InvoiceAPI * • ReportAPI * • TransactionAPI * Inventory: * • PostingAPI * • ReportAPI * System: * • CompanyAPI * • NumberSerieAPI * • CompanyAccessAPI * • UserAPI * */ // Always try to close your session when done. session.LogOut(); }
public static async void FindItemFromCustomerItem(DCOrderLineClient rec, DCOrder order, QueryAPI api, string CustomerItemNumber) { var ap = new Uniconta.API.Inventory.ReportAPI(api); var variant = await ap.FindItemFromCustomerItem(order, CustomerItemNumber); if (variant != null) { rec.Item = variant._Item; rec.Variant1 = variant._Variant1; rec.Variant2 = variant._Variant2; rec.Variant3 = variant._Variant3; rec.Variant4 = variant._Variant4; rec.Variant5 = variant._Variant5; } }
static public void SetDeliveryAdress(DCInvoice InvClient, DCAccount client, QueryAPI api) { SetGLNnumber(InvClient, client, api); if (InvClient._DeliveryAddress1 != null) { return; } var Comp = api.CompanyEntity; if (InvClient._Installation != null) { var installation = (WorkInstallation)Comp.GetCache(typeof(WorkInstallation), api)?.Get(InvClient._Installation); if (installation != null) { InvClient._DeliveryName = installation._Name; InvClient._DeliveryAddress1 = installation._Address1; InvClient._DeliveryAddress2 = installation._Address2; InvClient._DeliveryAddress3 = installation._Address3; InvClient._DeliveryZipCode = installation._ZipCode; InvClient._DeliveryCity = installation._City; if (Comp._Country != (byte)installation._Country) { InvClient._DeliveryCountry = installation._Country; } } } else { DCAccount deb; bool UseDebAddress; if (InvClient._DeliveryAccount != null) { deb = (DCAccount)Comp.GetCache(typeof(Debtor), api)?.Get(InvClient._DeliveryAccount); UseDebAddress = true; } else { deb = client ?? (DCAccount)Comp.GetCache(typeof(Debtor), api)?.Get(InvClient._DCAccount); UseDebAddress = false; } if (deb != null) { if (deb._DeliveryAddress1 != null) { InvClient._DeliveryName = deb._DeliveryName; InvClient._DeliveryAddress1 = deb._DeliveryAddress1; InvClient._DeliveryAddress2 = deb._DeliveryAddress2; InvClient._DeliveryAddress3 = deb._DeliveryAddress3; InvClient._DeliveryZipCode = deb._DeliveryZipCode; InvClient._DeliveryCity = deb._DeliveryCity; InvClient._DeliveryCountry = deb._DeliveryCountry; } else if (UseDebAddress) { InvClient._DeliveryName = deb._Name; InvClient._DeliveryAddress1 = deb._Address1; InvClient._DeliveryAddress2 = deb._Address2; InvClient._DeliveryAddress3 = deb._Address3; InvClient._DeliveryZipCode = deb._ZipCode; InvClient._DeliveryCity = deb._City; if (Comp._Country != (byte)deb._Country) { InvClient._DeliveryCountry = deb._Country; } } } } }
static public void FindOnEAN(DCOrderLineClient rec, SQLCache Items, QueryAPI api) { FindOnEAN(rec, Items, api, null); }
public FindPrices(QueryAPI api) { this.api = api; }