Исполнитель: уже спит
This commit is contained in:
commit
dc5e918912
@ -10,19 +10,18 @@ using VeterinaryContracts.StorageContracts;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
using VeterinaryContracts.SearchModels;
|
||||
using VeterinaryBusinessLogic.OfficePackage;
|
||||
using VeterinaryBusinessLogic.OfficePackage.HelperModels;
|
||||
|
||||
namespace VeterinaryBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ReportLogicDoctor : IReportLogicDoctor
|
||||
{
|
||||
private readonly IDrugStorage _drugStorage;
|
||||
private readonly IMedicationStorage _medicationStorage;
|
||||
private readonly AbstractSaveToExcelDoctor _saveToExcel;
|
||||
private readonly AbstractSaveToWordDoctor _saveToWord;
|
||||
public ReportLogicDoctor(IPurchaseStorage purchaseStorage, IDrugStorage drugStorage, IMedicationStorage medicationStorage,
|
||||
public ReportLogicDoctor( IMedicationStorage medicationStorage,
|
||||
AbstractSaveToExcelDoctor saveToExcel, AbstractSaveToWordDoctor saveToWord)
|
||||
{
|
||||
_drugStorage = drugStorage;
|
||||
_medicationStorage = medicationStorage;
|
||||
_saveToExcel = saveToExcel;
|
||||
_saveToWord = saveToWord;
|
||||
@ -33,7 +32,7 @@ namespace VeterinaryBusinessLogic.BusinessLogic
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список покупок по медикаментам",
|
||||
PurchaseMedications = GetPurchaseMedications(model.Medications)
|
||||
PurchaseMedications = GetPurchaseMedications(model)
|
||||
});
|
||||
}
|
||||
|
||||
@ -43,45 +42,17 @@ namespace VeterinaryBusinessLogic.BusinessLogic
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список покупок по медикаментам",
|
||||
PurchaseMedications = GetPurchaseMedications(model.Medications)
|
||||
PurchaseMedications = GetPurchaseMedications(model)
|
||||
});
|
||||
}
|
||||
|
||||
public List<ReportPurchaseMedicationViewModel> GetPurchaseMedications(List<int> medications)
|
||||
public List<ReportPurchaseMedicationViewModel> GetPurchaseMedications(ReportPurchaseMedicationBindingModel model)
|
||||
{
|
||||
List<ReportPurchaseMedicationViewModel> servs = new();
|
||||
List<Tuple<MedicationViewModel, List<Tuple<DrugViewModel, List<PurchaseViewModel>>>>> response =
|
||||
_medicationStorage.GetReportInfo(new ListPurchasesSearchModel { medicationsIds = medications });
|
||||
|
||||
foreach (var medication in response)
|
||||
{
|
||||
Dictionary<int, (PurchaseViewModel, int)> counter = new();
|
||||
foreach (var drug in medication.Item2)
|
||||
{
|
||||
foreach (var purchase in drug.Item2)
|
||||
{
|
||||
if (!counter.ContainsKey(purchase.Id))
|
||||
counter.Add(purchase.Id, (purchase, 1));
|
||||
else
|
||||
{
|
||||
counter[purchase.Id] = (counter[purchase.Id].Item1, counter[purchase.Id].Item2 + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<PurchaseViewModel> res = new();
|
||||
foreach (var cont in counter)
|
||||
{
|
||||
if (cont.Value.Item2 != medication.Item2.Count)
|
||||
continue;
|
||||
res.Add(cont.Value.Item1);
|
||||
}
|
||||
servs.Add(new ReportPurchaseMedicationViewModel
|
||||
{
|
||||
MedicationName = medication.Item1.MedicationName,
|
||||
Purchases = res
|
||||
});
|
||||
}
|
||||
return servs;
|
||||
return _medicationStorage.GetReportMedicationPurchasesList(new() { medicationsIds = model.Medications });
|
||||
}
|
||||
public List<ReportDrugsVisitsViewModel> GetVisitsDrugs(ReportDrugsVisitsBindingModel model)
|
||||
{
|
||||
return _medicationStorage.GetReportDrugsVisits(new() { DateFrom = model.DateFrom, DateTo = model.DateTo });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,7 @@
|
||||
namespace VeterinaryBusinessLogic.OfficePackage.HelperModels
|
||||
|
||||
using VeterinaryContracts.ViewModels;
|
||||
|
||||
namespace VeterinaryBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class PdfInfo
|
||||
{
|
||||
@ -6,7 +9,7 @@
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public DateTime DateFrom { get; set; }
|
||||
public DateTime DateTo { get; set; }
|
||||
public List<ReportServicesViewModel> ReportServices { get; set; } = new();
|
||||
public List<ReportPurchasesViewModel> ReportPurchases{ get; set; } = new();
|
||||
public List<ReportDrugsVisitsViewModel> ReportDrugsVisits { get; set; } = new();
|
||||
public List<ReportVisitsDrugsViewModel> ReportVisitsDrugs{ get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VeterinaryContracts.BindingModels
|
||||
{
|
||||
public class ReportDrugsVisitsBindingModel
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public List<int> Medications { get; set; } = new();
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
}
|
||||
}
|
@ -10,8 +10,9 @@ using VeterinaryContracts.ViewModels;
|
||||
namespace VeterinaryContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IReportLogicDoctor
|
||||
{// will be done later
|
||||
List<ReportPurchaseMedicationViewModel> GetPurchaseMedications(List<int> medications);
|
||||
{
|
||||
List<ReportDrugsVisitsViewModel> GetVisitsDrugs(ReportDrugsVisitsBindingModel model);
|
||||
List<ReportPurchaseMedicationViewModel> GetPurchaseMedications(ReportPurchaseMedicationBindingModel model);
|
||||
void SavePurchasesToWordFile(ReportPurchaseMedicationBindingModel model);
|
||||
void SavePurchasesToExcelFile(ReportPurchaseMedicationBindingModel model);
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VeterinaryContracts.SearchModels
|
||||
{
|
||||
public class ReportDrugsVisitsSearchModel
|
||||
{
|
||||
public List<int>? medicationsIds { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
}
|
||||
}
|
@ -13,10 +13,13 @@ namespace VeterinaryContracts.StorageContracts
|
||||
{
|
||||
List<MedicationViewModel> GetFullList();
|
||||
List<MedicationViewModel> GetFilteredList(MedicationSearchModel model);
|
||||
List<Tuple<MedicationViewModel, List<Tuple<DrugViewModel, List<PurchaseViewModel>>>>> GetReportInfo(ListPurchasesSearchModel model);
|
||||
MedicationViewModel? GetElement(MedicationSearchModel model);
|
||||
MedicationViewModel? Insert(MedicationBindingModel model);
|
||||
MedicationViewModel? Update(MedicationBindingModel model);
|
||||
MedicationViewModel? Delete(MedicationBindingModel model);
|
||||
List<ReportPurchaseMedicationViewModel> GetReportMedicationPurchasesList(ListPurchasesSearchModel model);
|
||||
List<ReportDrugsVisitsViewModel> GetReportDrugsVisits(ReportDrugsVisitsSearchModel model);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VeterinaryContracts.ViewModels
|
||||
{
|
||||
public class ReportDrugsVisitsViewModel
|
||||
{
|
||||
public string MedicationName { get; set; } = string.Empty;
|
||||
public List<VisitViewModel> Visits { get; set; }
|
||||
public List<DrugViewModel> Drugs { get; set; }
|
||||
}
|
||||
}
|
@ -2,8 +2,8 @@
|
||||
{
|
||||
public class ReportVisitsDrugsViewModel
|
||||
{
|
||||
string PetName { get; set; } = string.Empty;
|
||||
List<VisitViewModel> Visits { get; set; }
|
||||
List<DrugViewModel> Drugs { get; set; }
|
||||
public string PetName { get; set; } = string.Empty;
|
||||
public List<VisitViewModel> Visits { get; set; }
|
||||
public List<DrugViewModel> Drugs { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace VeterinaryContracts.ViewModels
|
||||
[DisplayName("Хозяин")]
|
||||
public int OwnerId { get; set; }
|
||||
[DisplayName("Врач")]
|
||||
public int? DoctorId { get; set; } = null;
|
||||
public int DoctorId { get; set; }
|
||||
[DisplayName("Название визита")]
|
||||
public string VisitName { get; set; } = string.Empty;
|
||||
[DisplayName("Дата посещения")]
|
||||
|
@ -83,7 +83,7 @@ namespace VeterinaryDatabaseImplement.Implements
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Tuple<MedicationViewModel, List<Tuple<DrugViewModel, List<PurchaseViewModel>>>>> GetReportInfo(ListPurchasesSearchModel model)
|
||||
public List<ReportPurchaseMedicationViewModel> GetReportMedicationPurchasesList(ListPurchasesSearchModel model)
|
||||
{
|
||||
if (model.medicationsIds == null)
|
||||
{
|
||||
@ -91,14 +91,42 @@ namespace VeterinaryDatabaseImplement.Implements
|
||||
}
|
||||
using var context = new VeterinaryDatabase();
|
||||
return context.Medications
|
||||
.Where(pet => model.medicationsIds.Contains(pet.Id))
|
||||
.Select(pet => new Tuple<PetViewModel, List<Tuple<VisitViewModel, List<ServiceViewModel>>>>(pet.GetViewModel,
|
||||
context.VisitPets.Include(visit => visit.Visit)
|
||||
.Include(visit => visit.Pet).Where(visit => pet.Id == visit.PetId).
|
||||
Select(visit => new Tuple<VisitViewModel, List<ServiceViewModel>>(visit.Visit.GetViewModel,
|
||||
context.Services.Include(x => x.Visits).Where(x => x.MedicineId == visit.Medicine.Id).
|
||||
Select(x => x.Animal.GetViewModel).ToList())).ToList())).ToList();
|
||||
.Where(medication => model.medicationsIds == null || model.medicationsIds.Contains(medication.Id))
|
||||
.Select(medication => new ReportPurchaseMedicationViewModel()
|
||||
{
|
||||
MedicationName = medication.MedicationName,
|
||||
Purchases = context.Purchases.Include(purchase => purchase.Drug).ThenInclude(drug => drug.Medications)
|
||||
.Where(purchase => purchase.Drug != null && purchase.Drug.Medications.Select(x => x.MedicationId).ToList().Contains(medication.Id))
|
||||
.Select(purchase => purchase.GetViewModel).ToList()
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public List<ReportDrugsVisitsViewModel> GetReportDrugsVisits(ReportDrugsVisitsSearchModel model)
|
||||
{
|
||||
using var context = new VeterinaryDatabase();
|
||||
|
||||
return context.Medications
|
||||
.Select(pet => new ReportDrugsVisitsViewModel()
|
||||
{
|
||||
MedicationName = pet.MedicationName,
|
||||
Drugs = context.Drugs
|
||||
.Where(drug => drug.Medications
|
||||
.Select(x => x.MedicationId)
|
||||
.ToList()
|
||||
.Contains(pet.Id))
|
||||
.Select(drug => drug.GetViewModel)
|
||||
.ToList(),
|
||||
Visits = context.Services
|
||||
.Include(service => service.Visit)
|
||||
.Where(service => service.Visit!=null&&service.Visit.DateVisit <= model.DateTo &&
|
||||
service.Visit.DateVisit >= model.DateFrom && service.Medications
|
||||
.Select(x => x.MedicationId)
|
||||
.ToList()
|
||||
.Contains(pet.Id))
|
||||
.Select(service => service.Visit.GetViewModel)
|
||||
.ToList(),
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel;
|
||||
using VeterinaryContracts.BindingModels;
|
||||
using VeterinaryContracts.SearchModels;
|
||||
using VeterinaryContracts.StorageContracts;
|
||||
@ -61,7 +62,31 @@ namespace VeterinaryDatabaseImplement.Implements
|
||||
}
|
||||
public List<ReportVisitsDrugsViewModel> GetReportVisitsDrugs(ReportVisitsDrugsSearchModel model)
|
||||
{
|
||||
using var context = new VeterinaryDatabase();
|
||||
|
||||
return context.Pets
|
||||
.Select(pet => new ReportVisitsDrugsViewModel()
|
||||
{
|
||||
PetName = pet.PetName,
|
||||
Visits = context.Visits
|
||||
.Where(visit => visit.DateVisit <= model.DateTo &&
|
||||
visit.DateVisit >= model.DateFrom && visit.Pets
|
||||
.Select(x => x.PetId)
|
||||
.ToList()
|
||||
.Contains(pet.Id))
|
||||
.Select(visit => visit.GetViewModel)
|
||||
.ToList(),
|
||||
Drugs = context.Purchases
|
||||
.Include(purchase => purchase.Drug)
|
||||
.Where(purchase => purchase.DateCreate <= model.DateTo &&
|
||||
purchase.DateCreate >= model.DateFrom && purchase.Pets
|
||||
.Select(x => x.PetId)
|
||||
.ToList()
|
||||
.Contains(pet.Id))
|
||||
.Select(purchase => purchase.Drug.GetViewModel)
|
||||
.ToList(),
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
public PetViewModel? Insert(PetBindingModel model)
|
||||
{
|
||||
|
@ -454,12 +454,20 @@ namespace VeterinaryShowDoctorApp.Controllers
|
||||
[HttpGet]
|
||||
public IActionResult PurchaseMedicationReport()
|
||||
{
|
||||
if (APIDoctor.Doctor == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Medications = APIDoctor.GetRequest<List<MedicationViewModel>>($"api/medication/getmedications?doctorid={APIDoctor.Doctor.Id}");
|
||||
return View();
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Report()
|
||||
{
|
||||
if (APIDoctor.Doctor == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
}
|
||||
|
@ -392,7 +392,7 @@ namespace VeterinaryShowOwnerApp.Controllers
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Pets = APIOwner.GetRequest<List<ServiceViewModel>>($"api/pet/getpets?ownerid={APIOwner.Owner.Id}");
|
||||
ViewBag.Pets = APIOwner.GetRequest<List<PetViewModel>>($"api/pet/getpets?ownerid={APIOwner.Owner.Id}");
|
||||
return View();
|
||||
}
|
||||
[HttpGet]
|
||||
|
@ -6,11 +6,6 @@
|
||||
</div>
|
||||
<div class="text-center">
|
||||
@{
|
||||
if (Model == null)
|
||||
{
|
||||
<h3 class="display-4">Авторизируйтесь</h3>
|
||||
return;
|
||||
}
|
||||
<div class="row mb-5">
|
||||
<div class="col-4">Начальная дата:</div>
|
||||
<div class="col-8">
|
||||
|
Loading…
Reference in New Issue
Block a user