diff --git a/Labaratory/Labaratory/App.config b/Labaratory/Labaratory/App.config index 5578ff8..27e1bcc 100644 --- a/Labaratory/Labaratory/App.config +++ b/Labaratory/Labaratory/App.config @@ -13,6 +13,6 @@ - + \ No newline at end of file diff --git a/Labaratory/Labaratory/Labaratory.csproj b/Labaratory/Labaratory/Labaratory.csproj index 926f80e..7a41978 100644 --- a/Labaratory/Labaratory/Labaratory.csproj +++ b/Labaratory/Labaratory/Labaratory.csproj @@ -84,10 +84,10 @@ - ..\packages\WPF-UI.4.2.0\lib\net472\Wpf.Ui.dll + ..\packages\WPF-UI.4.2.1\lib\net472\Wpf.Ui.dll - ..\packages\WPF-UI.Abstractions.4.2.0\lib\net462\Wpf.Ui.Abstractions.dll + ..\packages\WPF-UI.Abstractions.4.2.1\lib\net472\Wpf.Ui.Abstractions.dll diff --git a/Labaratory/Labaratory/Models/Model1.edmx b/Labaratory/Labaratory/Models/Model1.edmx index 58feb0d..919771c 100644 --- a/Labaratory/Labaratory/Models/Model1.edmx +++ b/Labaratory/Labaratory/Models/Model1.edmx @@ -163,7 +163,7 @@ - + @@ -175,7 +175,7 @@ - + @@ -187,7 +187,7 @@ - + @@ -199,7 +199,7 @@ - + @@ -211,7 +211,7 @@ - + @@ -223,7 +223,7 @@ - + @@ -235,7 +235,7 @@ - + @@ -247,7 +247,7 @@ - + @@ -259,7 +259,7 @@ - + @@ -271,7 +271,7 @@ - + @@ -283,7 +283,7 @@ - + @@ -295,7 +295,7 @@ - + @@ -307,7 +307,7 @@ - + @@ -319,7 +319,7 @@ - + @@ -331,7 +331,7 @@ - + @@ -343,7 +343,7 @@ - + @@ -355,7 +355,7 @@ - + @@ -367,7 +367,7 @@ - + @@ -396,75 +396,75 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/Labaratory/Labaratory/Models/Model1.edmx.diagram b/Labaratory/Labaratory/Models/Model1.edmx.diagram index deaa12d..41063c1 100644 --- a/Labaratory/Labaratory/Models/Model1.edmx.diagram +++ b/Labaratory/Labaratory/Models/Model1.edmx.diagram @@ -4,7 +4,7 @@ - + diff --git a/Labaratory/Labaratory/Models/Model11.Designer.cs b/Labaratory/Labaratory/Models/Model11.Designer.cs index 4cfa274..0e84e9f 100644 --- a/Labaratory/Labaratory/Models/Model11.Designer.cs +++ b/Labaratory/Labaratory/Models/Model11.Designer.cs @@ -1,4 +1,4 @@ -// Создание кода T4 для модели "C:\Users\usersql\Source\Repos\UP01TASK3\Labaratory\Labaratory\Models\Model1.edmx" включено. +// Создание кода T4 для модели "D:\Projects\TASK3UP01\Labaratory\Labaratory\Models\Model1.edmx" включено. // Чтобы включить формирование кода прежних версий, измените значение свойства "Стратегия создания кода" конструктора // на "Legacy ObjectContext". Это свойство доступно в окне "Свойства", если модель // открыта в конструкторе. diff --git a/Labaratory/Labaratory/ViewModels/ByhalterModel.cs b/Labaratory/Labaratory/ViewModels/ByhalterModel.cs index 1db3410..4ba81fe 100644 --- a/Labaratory/Labaratory/ViewModels/ByhalterModel.cs +++ b/Labaratory/Labaratory/ViewModels/ByhalterModel.cs @@ -1,18 +1,109 @@ -using System; -using System.Collections.Generic; +using Labaratory.Models; +using System; +using System.Collections.ObjectModel; using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Windows; +using System.Windows.Input; +using System.Data.Entity; // Для .Include() в старых версиях EF +using Wpf.Ui.Input; namespace Labaratory.ViewModels { public class ByhalterModel : BaseViewModel { - public Models.User CurrentUser { get; set; } + private readonly LaboratoryDBEntities _db; + public string RoleName => "Бухгалтер"; + + private Models.User _currentUser; + public Models.User CurrentUser + { + get => _currentUser; + set + { + _currentUser = value; + OnPropertyChanged(); + } + } + + public ObservableCollection Invoices { get; set; } + public ObservableCollection InsuranceCompanies { get; set; } + public ObservableCollection Reports { get; set; } + + private Insurance_Companies _selectedCompany; + public Insurance_Companies SelectedCompany + { + get => _selectedCompany; + set + { + _selectedCompany = value; + OnPropertyChanged(); + } + } + public ICommand GenerateRevenueReportCommand { get; } + public ICommand CreateInvoiceCommand { get; } public ByhalterModel(Models.User user) { CurrentUser = user; + _db = new LaboratoryDBEntities(); // Используем ваш контекст + + LoadInitialData(); + + GenerateRevenueReportCommand = new RelayCommand(_ => GenerateRevenueReport()); + CreateInvoiceCommand = new RelayCommand(_ => CreateInvoice()); + } + + private void LoadInitialData() + { + InsuranceCompanies = new ObservableCollection(_db.Insurance_Companies.ToList()); + Invoices = new ObservableCollection(_db.Invoices.Include(i => i.Insurance_Companies).ToList()); + Reports = new ObservableCollection(); + } + + private void GenerateRevenueReport() + { + var data = _db.Rendered_Services + .Include(s => s.OrderItem) + .OrderByDescending(s => s.ExecutionDate) + .ToList(); + + Reports.Clear(); + foreach (var item in data) Reports.Add(item); + } + + private void CreateInvoice() + { + if (SelectedCompany == null) + { + MessageBox.Show("Выберите страховую компанию!"); + return; + } + + decimal totalAmount = (decimal)(_db.Orders + .Where(o => o.Patient1.Company == SelectedCompany.ID_Company) + .SelectMany(o => o.Order_Items) + .Sum(oi => (double?)oi.Service1.Price) ?? 0); + + var newInvoice = new Invoice + { + InvoiceNumber = "INV-" + DateTime.Now.Ticks.ToString().Substring(10), + Accountant = CurrentUser.ID_User, + Company = SelectedCompany.ID_Company, + IssueDate = DateTime.Now, + Amount = totalAmount + }; + + try + { + _db.Invoices.Add(newInvoice); + _db.SaveChanges(); + Invoices.Add(newInvoice); + MessageBox.Show($"Счет сформирован! Сумма: {totalAmount:C}"); + } + catch (Exception ex) + { + MessageBox.Show($"Ошибка сохранения: {ex.InnerException?.Message ?? ex.Message}"); + } } } -} +} \ No newline at end of file diff --git a/Labaratory/Labaratory/ViewModels/Laborant.cs b/Labaratory/Labaratory/ViewModels/Laborant.cs index c3ec1a8..4537c9b 100644 --- a/Labaratory/Labaratory/ViewModels/Laborant.cs +++ b/Labaratory/Labaratory/ViewModels/Laborant.cs @@ -28,6 +28,7 @@ namespace Labaratory.ViewModels CalculateNextNumber(); StartTimer(); ProcessOrderCommand = new RelayCommand(execute => ProcessOrder()); + } private string _barcodeInput; private string _suggestedNumber; @@ -58,7 +59,6 @@ namespace Labaratory.ViewModels set; } = new ObservableCollection(); - public decimal TotalCost { get => _totalCost; @@ -88,7 +88,6 @@ namespace Labaratory.ViewModels _timer.Tick += Timer_Tick; _timer.Start(); } - private void Timer_Tick(object sender, EventArgs e) { if (_timeSpan.TotalSeconds > 0) @@ -139,7 +138,6 @@ namespace Labaratory.ViewModels SaveToPdf(fullCode); SaveOrderToDb(fullCode); } - private string GenerateFullBarcode(string orderId) { string datePart = DateTime.Now.ToString("ddMMyyyy"); @@ -174,7 +172,6 @@ namespace Labaratory.ViewModels MessageBox.Show($"Ошибка при сохранении в БД: {ex.Message}"); } } - private void SaveToPdf(string fullCode) { string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), $"Barcode_{fullCode}.pdf"); @@ -231,7 +228,6 @@ namespace Labaratory.ViewModels MessageBox.Show("Ошибка PDF: " + ex.Message); } } - private void DrawGuardBar(PdfContentByte cb, float x, float y, float height, float mmToPt) { cb.Rectangle(x, y, 0.15f * mmToPt, height * mmToPt); @@ -255,12 +251,10 @@ namespace Labaratory.ViewModels string surname = parts[0]; string firstName = parts.Length > 1 ? parts[1] : ""; - // 1. Ищем в БД var patient = db.Patients.FirstOrDefault(p => p.Surname == surname && p.FirstName == firstName); if (patient == null) { - // 2. Если не нашли — открываем модальное окно var addWin = new Views.AddPatientWindow(); var vm = new AddPatientViewModel { Surname = surname, FirstName = firstName }; addWin.DataContext = vm; @@ -281,26 +275,5 @@ namespace Labaratory.ViewModels TotalCost = SelectedServices.Sum(s => s.Price); OnPropertyChanged(nameof(TotalCost)); } - - private void CheckAndAddPatient(string searchSurname, string searchName) - { - var patient = db.Patients.FirstOrDefault(p => p.Surname == searchSurname && p.FirstName == searchName); - - if (patient == null) - { - var addWin = new AddPatientWindow(); - var vm = new AddPatientViewModel { Surname = searchSurname, FirstName = searchName }; - addWin.DataContext = vm; - - if (addWin.ShowDialog() == true) - { - SelectedPatient = vm.SavedPatient; - } - } - else - { - SelectedPatient = patient; - } - } } } diff --git a/Labaratory/Labaratory/Views/AddPatientWindow.xaml b/Labaratory/Labaratory/Views/AddPatientWindow.xaml index 787eb6f..925c2ce 100644 --- a/Labaratory/Labaratory/Views/AddPatientWindow.xaml +++ b/Labaratory/Labaratory/Views/AddPatientWindow.xaml @@ -18,7 +18,7 @@ - + @@ -27,13 +27,11 @@ - - + - @@ -45,7 +43,6 @@ - diff --git a/Labaratory/Labaratory/Views/ByhalterWindow.xaml b/Labaratory/Labaratory/Views/ByhalterWindow.xaml index 56d31b0..85d55ce 100644 --- a/Labaratory/Labaratory/Views/ByhalterWindow.xaml +++ b/Labaratory/Labaratory/Views/ByhalterWindow.xaml @@ -1,12 +1,82 @@ - + xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" + xmlns:services="clr-namespace:Labaratory.Services" + Title="Рабочее бугхалтера" Height="700" Width="900" + Background="{ui:ThemeResource ApplicationBackgroundBrush}" + Foreground="{ui:ThemeResource TextFillColorPrimaryBrush}"> + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + \ No newline at end of file diff --git a/Labaratory/Labaratory/Views/LaborantWindow.xaml b/Labaratory/Labaratory/Views/LaborantWindow.xaml index 06324ab..af8853b 100644 --- a/Labaratory/Labaratory/Views/LaborantWindow.xaml +++ b/Labaratory/Labaratory/Views/LaborantWindow.xaml @@ -12,9 +12,9 @@ - - - + @@ -83,8 +82,7 @@ - - + @@ -104,30 +102,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Labaratory/Labaratory/packages.config b/Labaratory/Labaratory/packages.config index fe65b39..f782a9a 100644 --- a/Labaratory/Labaratory/packages.config +++ b/Labaratory/Labaratory/packages.config @@ -8,6 +8,6 @@ - - + + \ No newline at end of file