From f7981a79c9b559ebfa5e57fe4d6bfd00dfb3c358 Mon Sep 17 00:00:00 2001 From: Anders Y Date: Thu, 16 Feb 2023 13:05:37 +0100 Subject: [PATCH 1/2] Small fixes / additions to SalesOrder (#188) Co-authored-by: Anders Yderborg Co-authored-by: Ole Melhus --- Visma.net.Tests/CustomerTest.cs | 2 +- ...erTest.CanDeserializeToEntity.verified.txt | 3 +- ...nTests.CanDeserializeToEntity.verified.txt | 4 +- ...rTests.CanDeserializeToEntity.verified.txt | 1 + ...lierTests.CanDeserializeToDto.verified.txt | 22 ++++++ ...rTests.CanDeserializeToEntity.verified.txt | 4 +- Visma.net/Models/CustomDto/CurrencySummary.cs | 10 +++ .../Models/CustomDto/CustomerGLAccountDto.cs | 50 ++++++++++--- .../Models/CustomDto/GLAccountDetailsDto.cs | 14 +++- Visma.net/Models/CustomDto/IdName.cs | 27 +++++++ Visma.net/Models/CustomDto/InventoryUnit.cs | 22 ++++++ .../Models/CustomDto/SubaccountGlAccount.cs | 75 +++++++++++++++++++ Visma.net/Models/CustomerInvoice.cs | 2 +- Visma.net/Models/Inventory.cs | 52 ++++++++----- Visma.net/Models/Location.cs | 26 +++---- Visma.net/Models/SalesOrder.cs | 6 ++ Visma.net/Models/SalesOrderLine.cs | 1 + Visma.net/Models/Supplier.cs | 5 +- Visma.net/Models/SupplierInvoice.cs | 6 ++ Visma.net/Models/SupplierPayment.cs | 60 +++++++++++++++ Visma.net/Models/SupplierPaymentLine.cs | 54 +++++++++++++ Visma.net/Visma.net.csproj | 9 ++- Visma.net/VismaNet.cs | 8 ++ Visma.net/lib/DAta/SupplierPaymentData.cs | 24 ++++++ Visma.net/lib/Data/InventoryData.cs | 5 ++ Visma.net/lib/Data/LocationData.cs | 2 +- Visma.net/lib/VismaNetApiHelper.cs | 40 ++++++++++ Visma.net/lib/VismaNetControllers.cs | 4 + 28 files changed, 482 insertions(+), 56 deletions(-) create mode 100644 Visma.net/Models/CustomDto/CurrencySummary.cs create mode 100644 Visma.net/Models/CustomDto/InventoryUnit.cs create mode 100644 Visma.net/Models/CustomDto/SubaccountGlAccount.cs create mode 100644 Visma.net/Models/SupplierPayment.cs create mode 100644 Visma.net/Models/SupplierPaymentLine.cs create mode 100644 Visma.net/lib/DAta/SupplierPaymentData.cs diff --git a/Visma.net.Tests/CustomerTest.cs b/Visma.net.Tests/CustomerTest.cs index 74be6a9..399a2b9 100644 --- a/Visma.net.Tests/CustomerTest.cs +++ b/Visma.net.Tests/CustomerTest.cs @@ -221,7 +221,7 @@ public class CustomerTest : EntityBaseTest ""description"": ""string"" }, ""salesSubaccount"": { - ""id"": ""string"", + ""subaccountNumber"": ""string"", ""description"": ""string"" } }, diff --git a/Visma.net.Tests/Snapshots/CustomerTest.CanDeserializeToEntity.verified.txt b/Visma.net.Tests/Snapshots/CustomerTest.CanDeserializeToEntity.verified.txt index 77f1380..049e987 100644 --- a/Visma.net.Tests/Snapshots/CustomerTest.CanDeserializeToEntity.verified.txt +++ b/Visma.net.Tests/Snapshots/CustomerTest.CanDeserializeToEntity.verified.txt @@ -92,7 +92,8 @@ }, salesSubaccount: { description: string, - id: string + subaccountNumber: string, + active: false } }, invoiceAddress: { diff --git a/Visma.net.Tests/Snapshots/LocationTests.CanDeserializeToEntity.verified.txt b/Visma.net.Tests/Snapshots/LocationTests.CanDeserializeToEntity.verified.txt index 4513f46..0b9982a 100644 --- a/Visma.net.Tests/Snapshots/LocationTests.CanDeserializeToEntity.verified.txt +++ b/Visma.net.Tests/Snapshots/LocationTests.CanDeserializeToEntity.verified.txt @@ -19,7 +19,9 @@ } }, addressIsSameAsMain: true, - baccountId: string, + baccount: { + number: string + }, contact: { attention: string, email: string, diff --git a/Visma.net.Tests/Snapshots/SalesOrderTests.CanDeserializeToEntity.verified.txt b/Visma.net.Tests/Snapshots/SalesOrderTests.CanDeserializeToEntity.verified.txt index 0188286..025c433 100644 --- a/Visma.net.Tests/Snapshots/SalesOrderTests.CanDeserializeToEntity.verified.txt +++ b/Visma.net.Tests/Snapshots/SalesOrderTests.CanDeserializeToEntity.verified.txt @@ -233,5 +233,6 @@ description: string, id: string }, + overrideNumberSeries: false, metadata: {} } \ No newline at end of file diff --git a/Visma.net.Tests/Snapshots/SupplierTests.CanDeserializeToDto.verified.txt b/Visma.net.Tests/Snapshots/SupplierTests.CanDeserializeToDto.verified.txt index e6119a7..1822601 100644 --- a/Visma.net.Tests/Snapshots/SupplierTests.CanDeserializeToDto.verified.txt +++ b/Visma.net.Tests/Snapshots/SupplierTests.CanDeserializeToDto.verified.txt @@ -33,6 +33,28 @@ documentLanguage: { Value: string }, + glAccounts: { + Value: { + expenseAccount: { + Value: string + }, + expenseAccountImport: { + Value: string + }, + expenseAccountNonTax: { + Value: string + }, + expenseEUAccount: { + Value: string + }, + expenseSubaccount: { + Value: string + }, + supplierAccount: { + Value: string + } + } + }, mainAddress: { Value: { addressLine1: { diff --git a/Visma.net.Tests/Snapshots/SupplierTests.CanDeserializeToEntity.verified.txt b/Visma.net.Tests/Snapshots/SupplierTests.CanDeserializeToEntity.verified.txt index e812a65..dfc9b1a 100644 --- a/Visma.net.Tests/Snapshots/SupplierTests.CanDeserializeToEntity.verified.txt +++ b/Visma.net.Tests/Snapshots/SupplierTests.CanDeserializeToEntity.verified.txt @@ -45,8 +45,8 @@ type: string }, expenseSubaccount: { - description: string, - id: string + id: string, + description: string } }, lastModifiedDateTime: DateTime_1, diff --git a/Visma.net/Models/CustomDto/CurrencySummary.cs b/Visma.net/Models/CustomDto/CurrencySummary.cs new file mode 100644 index 0000000..d4182d7 --- /dev/null +++ b/Visma.net/Models/CustomDto/CurrencySummary.cs @@ -0,0 +1,10 @@ +namespace ONIT.VismaNetApi.Models.CustomDto +{ + public class CurrencySummary : IdDescription + { + public string symbol { get; set; } + public bool isBaseCurrency { get; set; } + public int decimalPrecision { get; set; } + public bool isUsedForAccounting { get; set; } + } +} \ No newline at end of file diff --git a/Visma.net/Models/CustomDto/CustomerGLAccountDto.cs b/Visma.net/Models/CustomDto/CustomerGLAccountDto.cs index f8bf5f2..ee5c28c 100644 --- a/Visma.net/Models/CustomDto/CustomerGLAccountDto.cs +++ b/Visma.net/Models/CustomDto/CustomerGLAccountDto.cs @@ -1,10 +1,13 @@ using Newtonsoft.Json; +using ONIT.VismaNetApi.Interfaces; +using ONIT.VismaNetApi.Lib; namespace ONIT.VismaNetApi.Models.CustomDto { public class CustomerGLAccountDto { [JsonProperty] public GLAccountDetailsDto customerLedgerAccount { get; private set; } + [JsonProperty] public SubaccountGlAccount customerLedgerSubAccount { get; private set; } [JsonProperty] public GLAccountDetailsDto salesAccount { get; private set; } [JsonProperty] public GLAccountDetailsDto salesEuAccount { get; private set; } @@ -13,21 +16,44 @@ public class CustomerGLAccountDto [JsonProperty] public GLAccountDetailsDto salesNonTaxableAccount { get; private set; } - [JsonProperty] public DescriptiveDto salesSubaccount { get; private set; } + [JsonProperty] public SubaccountGlAccount salesSubaccount { get; private set; } } - public class SupplierGLAccountDto + public class SupplierGLAccountDto : DtoProviderBase { - [JsonProperty] public GLAccountDetailsDto supplierAccount { get; private set; } - - [JsonProperty] public GLAccountDetailsDto expenseAccount { get; private set; } - - [JsonProperty] public GLAccountDetailsDto expenseAccountNonTax { get; private set; } - - [JsonProperty] public GLAccountDetailsDto expenseEUAccount { get; private set; } - [JsonProperty] public GLAccountDetailsDto expenseAccountImport { get; private set; } - - [JsonProperty] public DescriptiveDto expenseSubaccount { get; private set; } + [JsonProperty] public GLAccountDetailsDto supplierAccount { + get => Get(); + private set => Set(value); + } + + [JsonProperty] public GLAccountDetailsDto expenseAccount { + get => Get(); + private set => Set(value); + } + + [JsonProperty] public GLAccountDetailsDto expenseAccountNonTax { + get => Get(); + private set => Set(value); + } + + [JsonProperty] public GLAccountDetailsDto expenseEUAccount { + get => Get(); + private set => Set(value); + } + [JsonProperty] public GLAccountDetailsDto expenseAccountImport { + get => Get(); + private set => Set(value); + } + + [JsonProperty] public IdDescription expenseSubaccount { + get => Get(); + private set => Set(value); + } + + public DtoValue ToDto() + { + return new DtoValue(this); + } } } \ No newline at end of file diff --git a/Visma.net/Models/CustomDto/GLAccountDetailsDto.cs b/Visma.net/Models/CustomDto/GLAccountDetailsDto.cs index 2b5233b..06e7bb0 100644 --- a/Visma.net/Models/CustomDto/GLAccountDetailsDto.cs +++ b/Visma.net/Models/CustomDto/GLAccountDetailsDto.cs @@ -1,13 +1,19 @@ using Newtonsoft.Json; +using ONIT.VismaNetApi.Interfaces; namespace ONIT.VismaNetApi.Models.CustomDto { - public class GLAccountDetailsDto + public class GLAccountDetailsDto : IBecomeDto { - [JsonProperty] public string description { get; private set; } + public string description { get; set; } - [JsonProperty] public string number { get; private set; } + public string number { get; set; } - [JsonProperty] public string type { get; private set; } + public string type { get; set; } + + public DtoValue ToDto() + { + return new DtoValue(number); + } } } \ No newline at end of file diff --git a/Visma.net/Models/CustomDto/IdName.cs b/Visma.net/Models/CustomDto/IdName.cs index bfe847c..9f5298f 100644 --- a/Visma.net/Models/CustomDto/IdName.cs +++ b/Visma.net/Models/CustomDto/IdName.cs @@ -31,6 +31,33 @@ public DtoValue ToDto() } } + public class IdDescription : IBecomeDto + { + public IdDescription() + { + + } + + public IdDescription(string id) + { + this.id = id; + } + + public string id { get; set; } + + public string description { get; set; } + + public static implicit operator IdDescription(string id) + { + return new IdDescription(id); + } + + public DtoValue ToDto() + { + return new DtoValue(id); + } + } + public class IdValue : IBecomeDto { public IdValue() diff --git a/Visma.net/Models/CustomDto/InventoryUnit.cs b/Visma.net/Models/CustomDto/InventoryUnit.cs new file mode 100644 index 0000000..1e296a9 --- /dev/null +++ b/Visma.net/Models/CustomDto/InventoryUnit.cs @@ -0,0 +1,22 @@ +using System; +using Newtonsoft.Json; + +namespace ONIT.VismaNetApi.Models.CustomDto +{ + public class InventoryUnit + { + public int unitType { get; set; } + public ItemClass itemClass { get; set; } + public int inventoryID { get; set; } + public string toUnit { get; set; } + public string sampleToUnit { get; set; } + public string fromUnit { get; set; } + public string unitMultDiv { get; set; } + public decimal unitRate { get; set; } + public decimal priceAdjustmentMultiplier { get; set; } + public int recordID { get; set; } + + + + } +} diff --git a/Visma.net/Models/CustomDto/SubaccountGlAccount.cs b/Visma.net/Models/CustomDto/SubaccountGlAccount.cs new file mode 100644 index 0000000..65c146d --- /dev/null +++ b/Visma.net/Models/CustomDto/SubaccountGlAccount.cs @@ -0,0 +1,75 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using ONIT.VismaNetApi.Lib; +using System.Collections.Generic; +using System.Linq; + +namespace ONIT.VismaNetApi.Models.CustomDto +{ + public class SubaccountGlAccount : IProvideCustomDto + { + private List _segments; + + [JsonProperty] + public string description { get; private set; } + [JsonProperty] + public int subaccountId { get; private set; } + [JsonProperty] + public string lastModifiedDateTime { get; private set; } + + [JsonProperty] public string subaccountNumber { get; private set; } + + [JsonProperty] + public List segments + { + get => _segments ?? (_segments = new List()); + private set => _segments = value; + } + [JsonProperty] + public string errorInfo { get; private set; } + + [JsonProperty] + public bool active { get; private set; } + + [JsonProperty] + public JObject extras { get; private set; } + + [JsonProperty] + public MetaData metadata { get; private set; } + + /// + /// Sets a segment (department, project) for an invoice line. Remember that you have to set ALL segments for a line. + /// + /// + /// + public string this[int segmentId] + { + get + { + if (segments == null || segments.Count == 0 || segments.All(x => x.segmentId != segmentId)) + return string.Empty; + var firstOrDefault = segments.FirstOrDefault(x => x.segmentId == segmentId); + if (firstOrDefault != null) + return firstOrDefault.segmentValue; + return string.Empty; + } + set + { + var firstOrDefault = segments.FirstOrDefault(x => x.segmentId == segmentId); + if (firstOrDefault != null) + { + firstOrDefault.segmentValue = value; + } + else + { + segments.Add(new Segment { segmentId = segmentId, segmentValue = value }); + } + } + } + + public object ToDto() + { + return segments.Select(x => new { x.segmentId, x.segmentValue }); + } + } +} \ No newline at end of file diff --git a/Visma.net/Models/CustomerInvoice.cs b/Visma.net/Models/CustomerInvoice.cs index 450c061..8ff7ddc 100644 --- a/Visma.net/Models/CustomerInvoice.cs +++ b/Visma.net/Models/CustomerInvoice.cs @@ -264,7 +264,7 @@ public DateTime lastModifiedDateTime public LocationSummary location { - get => Get("locationId", new LocationSummary()); + get => Get("locationId"); set => Set(value, "locationId"); } diff --git a/Visma.net/Models/Inventory.cs b/Visma.net/Models/Inventory.cs index 0c4535f..ddea572 100644 --- a/Visma.net/Models/Inventory.cs +++ b/Visma.net/Models/Inventory.cs @@ -24,7 +24,7 @@ public Inventory(string _inventoryNumber) private List _crossReferences; private List _warehouseDetails; private List _supplierDetails; - private List _packaging; + private List _inventoryUnits; [JsonProperty] public List attachments @@ -103,25 +103,25 @@ public PostingClass postingClass set => Set(value); } - public DescriptiveDto defaultWarehouse - { - get => Get(); - set => Set(value); - } + public DescriptiveDto defaultWarehouse + { + get => Get(); + set => Set(value); + } - public DescriptiveDto defaultIssueFrom - { - get => Get(); - set => Set(value); - } + public DescriptiveDto defaultIssueFrom + { + get => Get(); + set => Set(value); + } - public DescriptiveDto defaultReceiptTo - { - get => Get(); - set => Set(value); - } + public DescriptiveDto defaultReceiptTo + { + get => Get(); + set => Set(value); + } - public string purchaseUnit + public string purchaseUnit { get => Get(); set => Set(value); @@ -133,6 +133,18 @@ public string salesUnit set => Set(value); } + public string body + { + get => Get(); + set => Set(value); + } + + public DescriptiveDto priceClass + { + get => Get(); + set => Set(value); + } + public InventoryStatus status { get => Get(); @@ -163,6 +175,12 @@ public List supplierDetails get => _supplierDetails ?? (_supplierDetails = new List()); private set => _supplierDetails = value; } + [JsonProperty] + public List inventoryUnits + { + get => _inventoryUnits ?? (_inventoryUnits = new List()); + private set => _inventoryUnits = value; + } public Packaging packaging { diff --git a/Visma.net/Models/Location.cs b/Visma.net/Models/Location.cs index e7806c0..30eec73 100644 --- a/Visma.net/Models/Location.cs +++ b/Visma.net/Models/Location.cs @@ -10,9 +10,9 @@ public class Location : DtoPaginatedProviderBase, IProvideIdentificator { public Location(string baccountId, string locationId, bool standAloneLocation = false) { - //this.baccount = new Baccount(); - //this.baccount.number = baccountId; - this.baccountId = baccountId; + this.baccount = new Baccount(); + this.baccount.number = baccountId; + //this.baccountId = baccountId; this.locationId = locationId; @@ -51,18 +51,18 @@ public bool addressIsSameAsMain set => Set(value); } - //public Baccount baccount - //{ - // get => Get("baccountId"); - // set => Set(value, "baccountId"); - //} - - public string baccountId + public Baccount baccount { - get => Get(); - set => Set(value); + get => Get("baccountId"); + set => Set(value, "baccountId"); } + //public string baccountId + //{ + // get => Get(); + // set => Set(value); + //} + public ContactInfo contact { get => Get(); @@ -128,7 +128,7 @@ public VatZone vatZone public string GetIdentificator() { - return baccountId;// baccount?.number; + return baccount?.number; } } } \ No newline at end of file diff --git a/Visma.net/Models/SalesOrder.cs b/Visma.net/Models/SalesOrder.cs index 5c630b9..2027f85 100644 --- a/Visma.net/Models/SalesOrder.cs +++ b/Visma.net/Models/SalesOrder.cs @@ -476,6 +476,12 @@ public int contactId set => Set(value); } + public bool overrideNumberSeries + { + get => Get(); + set => Set(value); + } + public string GetIdentificator() { diff --git a/Visma.net/Models/SalesOrderLine.cs b/Visma.net/Models/SalesOrderLine.cs index 97895cd..cb8f7c8 100644 --- a/Visma.net/Models/SalesOrderLine.cs +++ b/Visma.net/Models/SalesOrderLine.cs @@ -275,5 +275,6 @@ public string externalLink get => Get(); set => Set(value); } + } } \ No newline at end of file diff --git a/Visma.net/Models/Supplier.cs b/Visma.net/Models/Supplier.cs index e0ea56c..56c5489 100644 --- a/Visma.net/Models/Supplier.cs +++ b/Visma.net/Models/Supplier.cs @@ -88,7 +88,10 @@ public string documentLanguage [JsonProperty] public JObject extras { get; private set; } - [JsonProperty] public SupplierGLAccountDto glAccounts { get; private set; } + public SupplierGLAccountDto glAccounts { + get => Get(); + set => Set(value); + } [JsonProperty] public int internalId diff --git a/Visma.net/Models/SupplierInvoice.cs b/Visma.net/Models/SupplierInvoice.cs index d01b611..6154442 100644 --- a/Visma.net/Models/SupplierInvoice.cs +++ b/Visma.net/Models/SupplierInvoice.cs @@ -251,6 +251,12 @@ public string referenceNumber set => Set(value); } + public string cashAccount + { + get => Get(); + set => Set(value); + } + [JsonProperty] public decimal roundingDiff { get; private set; } [JsonProperty] public decimal roundingDiffInCurrency { get; private set; } diff --git a/Visma.net/Models/SupplierPayment.cs b/Visma.net/Models/SupplierPayment.cs new file mode 100644 index 0000000..d3acde5 --- /dev/null +++ b/Visma.net/Models/SupplierPayment.cs @@ -0,0 +1,60 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using ONIT.VismaNetApi.Lib; +using ONIT.VismaNetApi.Models.CustomDto; +using ONIT.VismaNetApi.Models.Enums; +using System; +using System.Collections.Generic; + +namespace ONIT.VismaNetApi.Models +{ + public class SupplierPayment : DtoPaginatedProviderBase, IProvideIdentificator + { + public string type { get => Get(); set => Set(value); } + public string refNbr { get => Get("referenceNumber"); set => Set(value, "referenceNumber"); } + public string status { get; set; } + public bool hold { get => Get(); set => Set(value); } + public DateTime applicationDate { get => Get(); set => Set(value); } + public string applicationPeriod { get => Get(); set => Set(value); } + public string paymentRef { get => Get(); set => Set(value); } + public CustomerSummary supplier { get => Get(); set => Set(value); } + public LocationSummary location { get => Get(); set => Set(value); } + public PaymentMethod paymentMethod { get => Get(); set => Set(value); } + public string cashAccount { get => Get(); set => Set(value); } + public CurrencySummary currency { get => Get(); set => Set(value); } + public string description { get => Get(); set => Set(value); } + public decimal paymentAmount { get => Get(); set => Set(value); } + [JsonProperty] + public decimal financeCharges { get => Get(); set => Set(value); } + [JsonProperty] + public decimal unappliedBalance { get => Get(); set => Set(value); } + [JsonProperty] + public decimal appliedAmount { get => Get(); set => Set(value); } + [JsonProperty] + public decimal deductedCharges { get; private set; } + [JsonProperty] + public bool released { get => Get(); set => Set(value); } + [JsonProperty] + public DateTime lastModifiedDateTime { get; private set; } + [JsonProperty] + public List paymentLines + { + get => Get(defaultValue: new List()); + private set => Set(value); + } + [JsonProperty] + public JObject extras { get; private set; } + public string errorInfo { get; set; } + + public string GetIdentificator() + { + return refNbr; + } + + internal override void PrepareForUpdate() + { + foreach (var line in this.paymentLines) + line.operation = ApiOperation.Update; + } + } +} diff --git a/Visma.net/Models/SupplierPaymentLine.cs b/Visma.net/Models/SupplierPaymentLine.cs new file mode 100644 index 0000000..89a07e6 --- /dev/null +++ b/Visma.net/Models/SupplierPaymentLine.cs @@ -0,0 +1,54 @@ +using Newtonsoft.Json; +using ONIT.VismaNetApi.Lib; +using ONIT.VismaNetApi.Models.Enums; +using System; + +namespace ONIT.VismaNetApi.Models +{ + public class SupplierPaymentLine : DtoProviderBase + { + public SupplierPaymentLine() + { + DtoFields.Add("operation", new NotDto(ApiOperation.Insert)); + } + public ApiOperation operation + { + get => Get(defaultValue: new NotDto(ApiOperation.Insert)).Value; + set => Set(new NotDto(value)); + } + public string documentType { get => Get(); set => Set(value); } + [JsonProperty] + public string branch { get; private set; } + [JsonProperty] + public string batchNumber { get; private set; } + public string refNbr { get => Get("invoiceRefNbr"); set => Set(value, "refNbr"); } + public decimal amountPaid { get => Get(); set => Set(value); } + public decimal cashDiscountTaken { get => Get(); set => Set(value); } + [JsonProperty] + public decimal withholdingTax { get => Get(); set => Set(value); } + [JsonProperty] + public DateTime applicationDate { get => Get(); set => Set(value); } + [JsonProperty] + public string applicationPeriod { get => Get(); set => Set(value); } + [JsonProperty] + public DateTime date { get => Get(); set => Set(value); } + [JsonProperty] + public DateTime dueDate { get => Get(); set => Set(value); } + [JsonProperty] + public DateTime cashDiscountDate { get => Get(); set => Set(value); } + [JsonProperty] + public decimal balance { get; private set; } + [JsonProperty] + public decimal cashDiscountBalance { get; private set; } + [JsonProperty] + public string description { get; private set; } + [JsonProperty] + public string currency { get; private set; } + [JsonProperty] + public string postPeriod { get; private set; } + [JsonProperty] + public string supplierRef { get; private set; } + public decimal crossRate { get => Get(); set => Set(value); } + } + +} diff --git a/Visma.net/Visma.net.csproj b/Visma.net/Visma.net.csproj index 065e15a..a010ce5 100644 --- a/Visma.net/Visma.net.csproj +++ b/Visma.net/Visma.net.csproj @@ -1,5 +1,10 @@  + netstandard2.0;net461;net45 + Visma.net + Copyright © ON IT AS 2014 - 2020 + Copyright © ON IT AS 2014 - 2021 + 4.1.0.2 netstandard2.0;net462;net6 Visma.net Copyright © ON IT AS 2014 - 2022 @@ -20,8 +25,8 @@ LICENSE.md on_it_logo.png README.md - 4.0.0 - 4.0.0 + 4.0.3.11 + 4.0.3.11 diff --git a/Visma.net/VismaNet.cs b/Visma.net/VismaNet.cs index 45ad2f4..1093242 100644 --- a/Visma.net/VismaNet.cs +++ b/Visma.net/VismaNet.cs @@ -8,6 +8,7 @@ using System.Collections.Generic; using System.IO; using System.Net.Http; +using System.Net.Sockets; using System.Reflection; using System.Runtime.InteropServices; using System.Threading.Tasks; @@ -33,6 +34,7 @@ public class VismaNet : VismaNetDynamicHandler public readonly DimensionData Dimension; public readonly DiscountData Discount; public readonly SupplierInvoiceData SupplierInvoice; + public readonly SupplierPaymentData SupplierPayment; public readonly SupplierData Supplier; public readonly InventoryData Inventory; public readonly FinAccountData Account; @@ -94,6 +96,7 @@ public VismaNet(int companyId, string token, int branchId = 0, HttpClient httpCl CustomerInvoice = new CustomerInvoiceData(Auth); Supplier = new SupplierData(Auth); SupplierInvoice = new SupplierInvoiceData(Auth); + SupplierPayment = new SupplierPaymentData(Auth); CashSale = new CashSaleData(Auth); CustomerDocument = new CustomerDocumentData(Auth); Dimension = new DimensionData(Auth); @@ -210,6 +213,11 @@ public static async Task GetTokenUsingOAuth(string client_id, string cli { return await VismaNetApiHelper.GetTokenOAuth(client_id, client_secret, code, redirect_uri); } + public static async Task GetTokenFromVismaConnect(string clientId, string secret, string tenant_id, string scope = "vismanet_erp_service_api:create vismanet_erp_service_api:delete vismanet_erp_service_api:read vismanet_erp_service_api:update") + { + return await VismaNetApiHelper.GetTokenFromVismaConnect(clientId,secret,tenant_id,scope); + } + public static async Task> GetContextsForToken(string token) { return await VismaNetApiHelper.GetContextsForToken(token); diff --git a/Visma.net/lib/DAta/SupplierPaymentData.cs b/Visma.net/lib/DAta/SupplierPaymentData.cs new file mode 100644 index 0000000..bc47f77 --- /dev/null +++ b/Visma.net/lib/DAta/SupplierPaymentData.cs @@ -0,0 +1,24 @@ +using ONIT.VismaNetApi.Models; +using System.Threading.Tasks; + +namespace ONIT.VismaNetApi.Lib.Data +{ + public class SupplierPaymentData : BasePaginatedCrudDataClass + { + internal SupplierPaymentData(VismaNetAuthorization auth) : base(auth) + { + ApiControllerUri = VismaNetControllers.SupplierPayment; + } + + protected SupplierPaymentData() : base(null) + { + ApiControllerUri = VismaNetControllers.SupplierPayment; + } + + public async Task Release(SupplierPayment payment) + { + return await VismaNetApiHelper.Action(Authorization, ApiControllerUri, payment.GetIdentificator(), "release", new { type = new DtoValue(payment.type) }); + } + + } +} diff --git a/Visma.net/lib/Data/InventoryData.cs b/Visma.net/lib/Data/InventoryData.cs index 0b2ff44..53d82c0 100644 --- a/Visma.net/lib/Data/InventoryData.cs +++ b/Visma.net/lib/Data/InventoryData.cs @@ -43,5 +43,10 @@ public async Task> GetAllAvailabilityUpdatedSince(DateTime dateT }); } } + + public async Task> GetAllItemClasses() + { + return await VismaNetApiHelper.GetAllItemClasses(Authorization); + } } } \ No newline at end of file diff --git a/Visma.net/lib/Data/LocationData.cs b/Visma.net/lib/Data/LocationData.cs index 24e1730..c9eeaf0 100644 --- a/Visma.net/lib/Data/LocationData.cs +++ b/Visma.net/lib/Data/LocationData.cs @@ -32,7 +32,7 @@ public virtual async Task Add(Location entity) public virtual async Task Update(Location entity) { entity.InternalPrepareForUpdate(); - await VismaNetApiHelper.Update(entity, $"{entity.baccountId.Trim()}/{entity.locationId.Trim()}", ApiControllerUri, Authorization); + await VismaNetApiHelper.Update(entity, $"{entity.baccount.number.Trim()}/{entity.locationId.Trim()}", ApiControllerUri, Authorization); //await VismaNetApiHelper.Update(entity, $"{entity.baccount.number.Trim()}/{entity.locationId.Trim()}", ApiControllerUri, Authorization); } diff --git a/Visma.net/lib/VismaNetApiHelper.cs b/Visma.net/lib/VismaNetApiHelper.cs index 322f8f3..4df637b 100644 --- a/Visma.net/lib/VismaNetApiHelper.cs +++ b/Visma.net/lib/VismaNetApiHelper.cs @@ -81,6 +81,29 @@ public static async Task> FetchContactsForSupplier(string supplier } } + public static async Task> GetAllItemClasses(VismaNetAuthorization authorization) + { + var webclient = GetHttpClient(authorization); + { + var apiUrl = GetApiUrlForController(VismaNetControllers.Inventory); + try + { + var fullUrl = $"{apiUrl}/itemClass"; + return await webclient.Get>(fullUrl); + } + catch (AggregateException e) + { + VismaNetExceptionHandler.HandleException(e); + } + catch (WebException e) + { + VismaNetExceptionHandler.HandleException(e); + } + + return null; + } + } + public static async Task> FetchCustomerSalesPricesForItem(string itemNo, VismaNetAuthorization authorization, PriceType priceType = PriceType.Undefined) { @@ -556,6 +579,23 @@ internal static async Task GetTokenOAuth(string clientId, string secret, return data["token"].Value(); } } + internal static async Task GetTokenFromVismaConnect(string clientId, string secret, string tenant_id, string scope = "vismanet_erp_service_api:create vismanet_erp_service_api:delete vismanet_erp_service_api:read vismanet_erp_service_api:update") + { + var webclient = GetHttpClient(new VismaNetAuthorization()); + { + var url = VismaNetControllers.VismaConnectToken; + var content = new FormUrlEncodedContent(new[] + { + new KeyValuePair("client_id", clientId), + new KeyValuePair("client_secret", secret), + new KeyValuePair("tenant_id", tenant_id), + new KeyValuePair("scope", scope), + new KeyValuePair("grant_type", "client_credentials") + }); + var data = await webclient.PostMessage(url, content); + return data["access_token"].Value(); + } + } internal static async Task InvoiceAction(string invoiceNumber, string action, VismaNetAuthorization authorization) diff --git a/Visma.net/lib/VismaNetControllers.cs b/Visma.net/lib/VismaNetControllers.cs index 4e2e97f..d74c0d5 100644 --- a/Visma.net/lib/VismaNetControllers.cs +++ b/Visma.net/lib/VismaNetControllers.cs @@ -5,6 +5,9 @@ internal static class VismaNetControllers // Security public const string Token = "security/api/v2/token"; + // Visma Connect + public const string VismaConnectToken = "https://connect.visma.com/connect/token"; + // Financials public const string Attribute = "controller/api/v1/attribute"; public const string Attachment = "controller/api/v1/attachment"; @@ -50,6 +53,7 @@ internal static class VismaNetControllers public const string CustomerCreditNoteV2 = "controller/api/v2/customerCreditNote"; public const string CashTransaction = "controller/api/v1/cashTransaction"; public const string Background = "controller/api/v1/background"; + public const string SupplierPayment = "controller/api/v1/supplierpayment"; public const string ProjectTransaction = "/controller/api/v1/projecttransaction"; // Resources From 22e34275fa7ef7a78edc9b2435a05bd034116bf2 Mon Sep 17 00:00:00 2001 From: Sierd Weidema Date: Tue, 11 Jul 2023 12:06:29 +0200 Subject: [PATCH 2/2] Supplier creditTerms (#202) --- Visma.net/Models/Supplier.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Visma.net/Models/Supplier.cs b/Visma.net/Models/Supplier.cs index 56c5489..67f61fd 100644 --- a/Visma.net/Models/Supplier.cs +++ b/Visma.net/Models/Supplier.cs @@ -68,8 +68,8 @@ public string corporateId public CreditTerms creditTerms { - get => Get("creditTermsId", new CreditTerms("30")); - set => Set(value); + get => Get("creditTermsId", new CreditTerms()); + set => Set(value, "creditTermsId"); } public string currencyId @@ -88,7 +88,8 @@ public string documentLanguage [JsonProperty] public JObject extras { get; private set; } - public SupplierGLAccountDto glAccounts { + public SupplierGLAccountDto glAccounts + { get => Get(); set => Set(value); }