diff --git a/.idea/.idea.PSCHelpdesk/.idea/.name b/.idea/.idea.PSCHelpdesk/.idea/.name new file mode 100644 index 0000000..6f7d947 --- /dev/null +++ b/.idea/.idea.PSCHelpdesk/.idea/.name @@ -0,0 +1 @@ +PSCHelpdesk \ No newline at end of file diff --git a/.idea/.idea.PSCHelpdesk/.idea/workspace.xml b/.idea/.idea.PSCHelpdesk/.idea/workspace.xml index de88650..41438c6 100644 --- a/.idea/.idea.PSCHelpdesk/.idea/workspace.xml +++ b/.idea/.idea.PSCHelpdesk/.idea/workspace.xml @@ -11,8 +11,16 @@ - + + + + + + + + + @@ -71,40 +79,40 @@ - { - "keyToString": { - ".NET Project.PSCHelpdesk.Desktop ohne plugin.executor": "Run", - ".NET Project.PSCHelpdesk.Desktop.executor": "Run", - "Publish to folder.Build HetznerServer Plugin Debug.executor": "Run", - "Publish to folder.Copy Fastbill.executor": "Run", - "Publish to folder.Copy Hetzner Target.executor": "Run", - "Publish to folder.Copy Hetzner.executor": "Run", - "Publish to folder.Copy NextCloud Target.executor": "Run", - "Publish to folder.Copy NextCloud.executor": "Run", - "Publish to folder.Copy PrinshopCreator.executor": "Run", - "Publish to folder.Publish HetznerServer to folder.executor": "Run", - "Publish to folder.Publish NextCloud to folder.executor": "Run", - "Publish to folder.Publish Nextcloud to folder.executor": "Run", - "RunOnceActivity.ShowReadmeOnStart": "true", - "RunOnceActivity.git.unshallow": "true", - "XThreadsFramesViewSplitterKey": "0.4427131", - "git-widget-placeholder": "master", - "ignore.virus.scanning.warn.message": "true", - "last_opened_file_path": "/home/thomas/RiderProjects/PSCHelpdesk/PSCHelpdesk/PSCHelpdesk.Desktop/bin/Debug/net9.0/plugins", - "node.js.detected.package.eslint": "true", - "node.js.detected.package.tslint": "true", - "node.js.selected.package.eslint": "(autodetect)", - "node.js.selected.package.tslint": "(autodetect)", - "nodejs_package_manager_path": "npm", - "settings.editor.selected.configurable": "preferences.pluginManager", - "vue.rearranger.settings.migration": "true" + +}]]> @@ -204,6 +212,7 @@ + @@ -243,6 +252,7 @@ + @@ -378,33 +388,12 @@ \ No newline at end of file diff --git a/FastBill/Api/Contacts.cs b/FastBill/Api/Contacts.cs new file mode 100644 index 0000000..8993cf4 --- /dev/null +++ b/FastBill/Api/Contacts.cs @@ -0,0 +1,28 @@ +using FastBill.Api.Response; +using FastBill.Models; +using RestSharp; +using RestSharp.Authenticators; +using Contact = FastBill.Models.Contact; + +namespace FastBill.Api; + +public class Contacts +{ + async public Task> GetContacts(Settings settings, string customerId) + { + var customers = new List(); + + var client = new RestClient("https://my.fastbill.com/"); + var request = new RestRequest("api/1.0/api.php"){ + Authenticator = new HttpBasicAuthenticator(settings.EMail, settings.ApiKey) + }; + request.AddJsonBody(new { SERVICE = "contact.get", FILTER = new { CUSTOMER_ID = customerId } }); + var response = await client.ExecuteAsync(request); + if (response.StatusCode == System.Net.HttpStatusCode.OK) + { + return response.Data.Response.Contacts; + } + + return customers; + } +} \ No newline at end of file diff --git a/FastBill/Api/Customers.cs b/FastBill/Api/Customers.cs index 58192b9..df20866 100644 --- a/FastBill/Api/Customers.cs +++ b/FastBill/Api/Customers.cs @@ -1,6 +1,8 @@ -using FastBill.Models; +using FastBill.Api.Response; +using FastBill.Models; using RestSharp; using RestSharp.Authenticators; +using Customer = FastBill.Models.Customer; namespace FastBill.Api; @@ -15,10 +17,10 @@ public class Customers Authenticator = new HttpBasicAuthenticator(settings.EMail, settings.ApiKey) }; request.AddJsonBody(new { SERVICE = "customer.get", FILTER = new { TERM = term } }); - var response = await client.ExecuteAsync>(request); + var response = await client.ExecuteAsync(request); if (response.StatusCode == System.Net.HttpStatusCode.OK) { - return response.Data; + return response.Data.Response.Customers; } return customers; diff --git a/FastBill/Api/Request/GetContacts.cs b/FastBill/Api/Request/GetContacts.cs new file mode 100644 index 0000000..5e3b5f7 --- /dev/null +++ b/FastBill/Api/Request/GetContacts.cs @@ -0,0 +1,6 @@ +namespace FastBill.Api.Request; + +public class GetContacts +{ + public string Service = ""; +} \ No newline at end of file diff --git a/FastBill/Api/Request/SearchCustomer.cs b/FastBill/Api/Request/SearchCustomer.cs new file mode 100644 index 0000000..520c2dd --- /dev/null +++ b/FastBill/Api/Request/SearchCustomer.cs @@ -0,0 +1,6 @@ +namespace FastBill.Api.Request; + +public class SearchCustomer +{ + public string Service = ""; +} \ No newline at end of file diff --git a/FastBill/Api/Response/Contact.cs b/FastBill/Api/Response/Contact.cs new file mode 100644 index 0000000..c69b16e --- /dev/null +++ b/FastBill/Api/Response/Contact.cs @@ -0,0 +1,9 @@ +using System.Text.Json.Serialization; + +namespace FastBill.Api.Response; + +public class Contact +{ + [JsonPropertyName("CONTACTS")] + public List Contacts { get; set; } = new List(); +} \ No newline at end of file diff --git a/FastBill/Api/Response/Customer.cs b/FastBill/Api/Response/Customer.cs new file mode 100644 index 0000000..9edc76a --- /dev/null +++ b/FastBill/Api/Response/Customer.cs @@ -0,0 +1,6 @@ +namespace FastBill.Api.Response; + +public class Customer +{ + public List Customers { get; set; } = new List(); +} \ No newline at end of file diff --git a/FastBill/Api/Response/GetContacts.cs b/FastBill/Api/Response/GetContacts.cs new file mode 100644 index 0000000..2c630f0 --- /dev/null +++ b/FastBill/Api/Response/GetContacts.cs @@ -0,0 +1,9 @@ +namespace FastBill.Api.Response; + +public class GetContacts +{ + public Request.GetContacts Request { get; set; } + public Contact Response { get; set; } + + +} \ No newline at end of file diff --git a/FastBill/Api/Response/SearchCustomer.cs b/FastBill/Api/Response/SearchCustomer.cs new file mode 100644 index 0000000..e410b8c --- /dev/null +++ b/FastBill/Api/Response/SearchCustomer.cs @@ -0,0 +1,9 @@ +namespace FastBill.Api.Response; + +public class SearchCustomer +{ + public Request.SearchCustomer Request { get; set; } + public Customer Response { get; set; } + + +} \ No newline at end of file diff --git a/FastBill/FastBill.csproj b/FastBill/FastBill.csproj index c587c24..11d1d7f 100644 --- a/FastBill/FastBill.csproj +++ b/FastBill/FastBill.csproj @@ -16,4 +16,10 @@ + + + ..\..\..\.nuget\packages\avalonia.controls.datagrid\11.2.0\lib\net8.0\Avalonia.Controls.DataGrid.dll + + + diff --git a/FastBill/Models/Contact.cs b/FastBill/Models/Contact.cs new file mode 100644 index 0000000..b1b884c --- /dev/null +++ b/FastBill/Models/Contact.cs @@ -0,0 +1,29 @@ +using System.Text.Json.Serialization; + +namespace FastBill.Models; + +public class Contact +{ + [JsonPropertyName("CONTACT_ID")] + public string Id { get; set; } + [JsonPropertyName("CUSTOMER_TYPE")] + public string Type { get; set; } + [JsonPropertyName("ORGANIZATION")] + public string Company { get; set; } + [JsonPropertyName("FIRST_NAME")] + public string Firstname { get; set; } + [JsonPropertyName("LAST_NAME")] + public string Lastname { get; set; } + [JsonPropertyName("ADDRESS")] + public string Address { get; set; } + [JsonPropertyName("ZIPCODE")] + public string Zip { get; set; } + [JsonPropertyName("CITY")] + public string City { get; set; } + [JsonPropertyName("PHONE")] + public string Phone { get; set; } + [JsonPropertyName("MOBILE")] + public string Mobile { get; set; } + [JsonPropertyName("EMAIL")] + public string EMail { get; set; } +} \ No newline at end of file diff --git a/FastBill/Models/Customer.cs b/FastBill/Models/Customer.cs index 844ad45..829cfba 100644 --- a/FastBill/Models/Customer.cs +++ b/FastBill/Models/Customer.cs @@ -1,7 +1,35 @@ -namespace FastBill.Models; +using System.Text.Json.Serialization; + +namespace FastBill.Models; public class Customer { - public string CustomerNr { get; set; } - public string CustomerId { get; set; } + [JsonPropertyName("CUSTOMER_NUMBER")] + public string Nr { get; set; } + [JsonPropertyName("CUSTOMER_ID")] + public string Id { get; set; } + [JsonPropertyName("CUSTOMER_TYPE")] + public string Type { get; set; } + [JsonPropertyName("ORGANIZATION")] + public string Company { get; set; } + [JsonPropertyName("FIRST_NAME")] + public string Firstname { get; set; } + [JsonPropertyName("LAST_NAME")] + public string Lastname { get; set; } + [JsonPropertyName("ADDRESS")] + public string Address { get; set; } + [JsonPropertyName("ZIPCODE")] + public string Zip { get; set; } + [JsonPropertyName("CITY")] + public string City { get; set; } + [JsonPropertyName("PHONE")] + public string Phone { get; set; } + [JsonPropertyName("EMAIL")] + public string EMail { get; set; } + [JsonPropertyName("WEBSITE")] + public string Website { get; set; } + [JsonPropertyName("DOCUMENT_HISTORY_URL")] + public string DocumentsUrl { get; set; } + + public List Contacts { get; set; } = new List(); } \ No newline at end of file diff --git a/FastBill/Models/Settings.cs b/FastBill/Models/Settings.cs index 5f04016..91a6b1d 100644 --- a/FastBill/Models/Settings.cs +++ b/FastBill/Models/Settings.cs @@ -4,4 +4,6 @@ public class Settings { public string EMail { get; set; } = string.Empty; public string ApiKey { get; set; } = string.Empty; + + public List Customers { get; set; } = new List(); } \ No newline at end of file diff --git a/FastBill/Services/CustomerService.cs b/FastBill/Services/CustomerService.cs index 0273122..b606e81 100644 --- a/FastBill/Services/CustomerService.cs +++ b/FastBill/Services/CustomerService.cs @@ -9,11 +9,13 @@ public class CustomerService { private readonly SettingsManager? _settingsManager; private readonly Api.Customers _customerApi; + private readonly Api.Contacts _contactApi; public CustomerService() { _settingsManager = (SettingsManager)Ioc.Default.GetService(); _customerApi = new Api.Customers(); + _contactApi = new Api.Contacts(); } public async Task> SearchCustomer(string term) @@ -25,4 +27,14 @@ public class CustomerService customers = await _customerApi.SearchCustomer(settings, term); return customers; } + + public async Task> GetContacts(string customerId) + { + var settings = new Settings(); + _settingsManager.LoadPluginSettings("FastbillSettings", settings); + + List contacts = new List(); + contacts = await _contactApi.GetContacts(settings, customerId); + return contacts; + } } \ No newline at end of file diff --git a/FastBill/ViewModels/CustomerDetailViewModel.cs b/FastBill/ViewModels/CustomerDetailViewModel.cs new file mode 100644 index 0000000..8930e42 --- /dev/null +++ b/FastBill/ViewModels/CustomerDetailViewModel.cs @@ -0,0 +1,8 @@ +using PSCHelpdesk.Shared.ViewModels; + +namespace FastBill.ViewModels; + +public class CustomerDetailViewModel: ViewModelBase, IViewModelBase +{ + +} \ No newline at end of file diff --git a/FastBill/ViewModels/CustomerViewModel.cs b/FastBill/ViewModels/CustomerViewModel.cs index e96895a..dd95c73 100644 --- a/FastBill/ViewModels/CustomerViewModel.cs +++ b/FastBill/ViewModels/CustomerViewModel.cs @@ -1,5 +1,10 @@ using System.Reactive; +using CommunityToolkit.Mvvm.DependencyInjection; +using DynamicData; +using FastBill.Models; using FastBill.Services; +using PSCHelpdesk.Shared.Service; +using PSCHelpdesk.Shared.Setting; using PSCHelpdesk.Shared.ViewModels; using ReactiveUI; @@ -9,14 +14,24 @@ public class CustomerViewModel: ViewModelBase, IViewModelBase { private string _term; + private List _customers; + public string Term { get => _term; set => SetAndRaisePropertyChanged(ref _term, value); } - private CustomerService _customerService; + public List Customers + { + get => _customers; + set => SetAndRaisePropertyChanged(ref _customers, value); + } + + private CustomerService _customerService; + private readonly SettingsManager? _settingsManager; + public ReactiveCommand SearchCustomer { get; } public CustomerViewModel(CustomerService customerService) @@ -24,9 +39,28 @@ public class CustomerViewModel: ViewModelBase, IViewModelBase Term = ""; _customerService = customerService; SearchCustomer = ReactiveCommand.Create(searchTerm); + _settingsManager = (SettingsManager)Ioc.Default.GetService(); } async void searchTerm() { - var list = await _customerService.SearchCustomer(Term); + Customers = await _customerService.SearchCustomer(Term); + var settings = new Settings(); + _settingsManager.LoadPluginSettings("FastbillSettings", settings); + foreach (var customer in Customers) + { + customer.Contacts = await _customerService.GetContacts(customer.Id); + + if (settings.Customers.Count(x => x.Id == customer.Id) > 0) + { + var index = settings.Customers.FindIndex(x => x.Id == customer.Id); + settings.Customers[index] = customer; + } + else + { + settings.Customers.Add(customer); + } + } + + _settingsManager.SavePluginSettings("FastbillSettings", settings); } } \ No newline at end of file diff --git a/FastBill/Views/CustomerDetailView.axaml b/FastBill/Views/CustomerDetailView.axaml new file mode 100644 index 0000000..009353c --- /dev/null +++ b/FastBill/Views/CustomerDetailView.axaml @@ -0,0 +1,8 @@ + + Welcome to Avalonia! + diff --git a/FastBill/Views/CustomerDetailView.axaml.cs b/FastBill/Views/CustomerDetailView.axaml.cs new file mode 100644 index 0000000..3abffb1 --- /dev/null +++ b/FastBill/Views/CustomerDetailView.axaml.cs @@ -0,0 +1,13 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace FastBill.Views; + +public partial class CustomerDetailView : UserControl +{ + public CustomerDetailView() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/FastBill/Views/CustomerView.axaml b/FastBill/Views/CustomerView.axaml index b8c69c1..da38593 100644 --- a/FastBill/Views/CustomerView.axaml +++ b/FastBill/Views/CustomerView.axaml @@ -9,9 +9,47 @@ - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/HetznerServer/Models/Server.cs b/HetznerServer/Models/Server.cs index 5e92470..a90276a 100644 --- a/HetznerServer/Models/Server.cs +++ b/HetznerServer/Models/Server.cs @@ -46,6 +46,14 @@ public class Server : ReactiveObject set => this.RaiseAndSetIfChanged(ref _fastBillId, value); } + private string _fastBillNr; + + public string FastBillNr + { + get => _fastBillNr; + set => this.RaiseAndSetIfChanged(ref _fastBillNr, value); + } + public string Status { get; set; } private MaterialIconKind _isGoodIcon = MaterialIconKind.AlertCircleOutline; diff --git a/HetznerServer/Models/ServerSetting.cs b/HetznerServer/Models/ServerSetting.cs index 71ea3db..d9f3919 100644 --- a/HetznerServer/Models/ServerSetting.cs +++ b/HetznerServer/Models/ServerSetting.cs @@ -5,11 +5,13 @@ public class ServerSetting public long ServerId { get; set; } public string PscApiKey { get; set; } public string FastBillId { get; set; } + public string FastBillNr { get; set; } - public ServerSetting(long serverId, string pscApiKey, string fastBillId) + public ServerSetting(long serverId, string pscApiKey, string fastBillId, string fastBillNr) { ServerId = serverId; PscApiKey = pscApiKey; FastBillId = fastBillId; + FastBillNr = fastBillNr; } } \ No newline at end of file diff --git a/HetznerServer/Service/ServerService.cs b/HetznerServer/Service/ServerService.cs index 4bb21de..19da153 100644 --- a/HetznerServer/Service/ServerService.cs +++ b/HetznerServer/Service/ServerService.cs @@ -81,6 +81,7 @@ public class ServerService: IServerService if (settings.ServerSettings.Count(e => e.ServerId == serv.ServerId) > 0) { serv.FastBillId = settings.ServerSettings.First(e => e.ServerId == serv.ServerId).FastBillId; + serv.FastBillNr = settings.ServerSettings.First(e => e.ServerId == serv.ServerId).FastBillNr; serv.PscApiKey = settings.ServerSettings.First(e => e.ServerId == serv.ServerId).PscApiKey; } @@ -261,10 +262,11 @@ public class ServerService: IServerService { settings.ServerSettings.First(e => e.ServerId == selectedServer.ServerId).FastBillId = selectedServer.FastBillId; settings.ServerSettings.First(e => e.ServerId == selectedServer.ServerId).PscApiKey = selectedServer.PscApiKey; + settings.ServerSettings.First(e => e.ServerId == selectedServer.ServerId).FastBillNr = selectedServer.FastBillNr; } else { - settings.ServerSettings.Add(new ServerSetting(selectedServer.ServerId, selectedServer.PscApiKey, selectedServer.FastBillId)); + settings.ServerSettings.Add(new ServerSetting(selectedServer.ServerId, selectedServer.PscApiKey, selectedServer.FastBillId, selectedServer.FastBillNr)); } _settingsManager.SavePluginSettings("HetznerSettings", settings); } diff --git a/HetznerServer/Views/ServerDetailView.axaml b/HetznerServer/Views/ServerDetailView.axaml index 3f30f7e..1ce8634 100644 --- a/HetznerServer/Views/ServerDetailView.axaml +++ b/HetznerServer/Views/ServerDetailView.axaml @@ -67,6 +67,8 @@ + + diff --git a/_dist/hetzner/HetznerServer.dll b/_dist/hetzner/HetznerServer.dll index 229377d..106a039 100644 Binary files a/_dist/hetzner/HetznerServer.dll and b/_dist/hetzner/HetznerServer.dll differ diff --git a/_dist/hetzner/HetznerServer.pdb b/_dist/hetzner/HetznerServer.pdb index edb8b63..9030b09 100644 Binary files a/_dist/hetzner/HetznerServer.pdb and b/_dist/hetzner/HetznerServer.pdb differ diff --git a/_dist/nextcloud/Nextcloud.dll b/_dist/nextcloud/Nextcloud.dll index e1e228f..9962d60 100644 Binary files a/_dist/nextcloud/Nextcloud.dll and b/_dist/nextcloud/Nextcloud.dll differ diff --git a/_dist/nextcloud/Nextcloud.pdb b/_dist/nextcloud/Nextcloud.pdb index fa6d708..f15be61 100644 Binary files a/_dist/nextcloud/Nextcloud.pdb and b/_dist/nextcloud/Nextcloud.pdb differ