183 lines
6.5 KiB
C#
183 lines
6.5 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using VetClinicBusinessLogic.BindingModels;
|
|||
|
using VetClinicBusinessLogic.BusinessLogic.OfficePackage;
|
|||
|
using VetClinicBusinessLogic.BusinessLogic.OfficePackage.Models;
|
|||
|
using VetClinicBusinessLogic.Interfaces;
|
|||
|
using VetClinicBusinessLogic.ViewModels;
|
|||
|
|
|||
|
namespace VetClinicBusinessLogic.BusinessLogic
|
|||
|
{
|
|||
|
public class ReportLogic
|
|||
|
{
|
|||
|
private readonly IServiceStorage _serviceStorage;
|
|||
|
private readonly IVisitStorage _VisitStorage;
|
|||
|
private readonly ReportToExcel _saveToExcel;
|
|||
|
private readonly ReportToWord _saveToWord;
|
|||
|
private readonly ReportToPdf _saveToPdf;
|
|||
|
private readonly IPaymentStorage paymentStorage;
|
|||
|
public ReportLogic(IVisitStorage VisitStorage, IPaymentStorage paymentStorage, IServiceStorage serviceStorage,
|
|||
|
ReportToExcel saveToExcel, ReportToWord saveToWord, ReportToPdf saveToPdf)
|
|||
|
{
|
|||
|
this.paymentStorage = paymentStorage;
|
|||
|
_VisitStorage = VisitStorage;
|
|||
|
_serviceStorage = serviceStorage;
|
|||
|
_saveToExcel = saveToExcel;
|
|||
|
_saveToWord = saveToWord;
|
|||
|
_saveToPdf = saveToPdf;
|
|||
|
}
|
|||
|
public List<ReportVisitServiceViewModel> GetVisitService(int UserId)
|
|||
|
{
|
|||
|
var Visits = _VisitStorage.GetFilteredList(new VisitBindingModel()
|
|||
|
{
|
|||
|
ClientId = UserId
|
|||
|
});
|
|||
|
var list = new List<ReportVisitServiceViewModel>();
|
|||
|
foreach (var Visit in Visits)
|
|||
|
{
|
|||
|
var record = new ReportVisitServiceViewModel
|
|||
|
{
|
|||
|
VisitDate = Visit.VisitsDate,
|
|||
|
Services = new List<string>(),
|
|||
|
TotalCount = 0
|
|||
|
};
|
|||
|
foreach (var service in Visit.VisitServices)
|
|||
|
{
|
|||
|
record.Services.Add(service.Value);
|
|||
|
record.TotalCount += 1;
|
|||
|
}
|
|||
|
list.Add(record);
|
|||
|
}
|
|||
|
return list;
|
|||
|
}
|
|||
|
public List<ReportServiceVisitViewModel> GetServiceVisit(int UserId)
|
|||
|
{
|
|||
|
var services = _serviceStorage.GetFullList();
|
|||
|
var list = new List<ReportServiceVisitViewModel>();
|
|||
|
foreach (var service in services)
|
|||
|
{
|
|||
|
var record = new ReportServiceVisitViewModel
|
|||
|
{
|
|||
|
Name = service.Name,
|
|||
|
Visits = new List<DateTime>(),
|
|||
|
TotalCount = 0
|
|||
|
};
|
|||
|
foreach (var visit in service.VisitServices)
|
|||
|
{
|
|||
|
record.Visits.Add(visit.Value);
|
|||
|
record.TotalCount += 1;
|
|||
|
}
|
|||
|
list.Add(record);
|
|||
|
}
|
|||
|
return list;
|
|||
|
}
|
|||
|
public void SaveVisitServiceToExcelFile(ReportBindingModel model)
|
|||
|
{
|
|||
|
_saveToExcel.CreateReportVisitService(new ExcelInfoVisitService
|
|||
|
{
|
|||
|
FileName = model.FileName,
|
|||
|
Title = "Список визитов",
|
|||
|
VisitServices = GetVisitService(model.UserId)
|
|||
|
});
|
|||
|
}
|
|||
|
public void SaveServiceVisitToExcelFile(ReportBindingModel model)
|
|||
|
{
|
|||
|
_saveToExcel.CreateReportServiceVisit(new ExcelInfoServiceVisit
|
|||
|
{
|
|||
|
FileName = model.FileName,
|
|||
|
Title = "Список услуг",
|
|||
|
VisitServices = GetServiceVisit(model.UserId)
|
|||
|
});
|
|||
|
}
|
|||
|
public void SaveVisitServiceToWordFile(ReportBindingModel model)
|
|||
|
{
|
|||
|
_saveToWord.CreateDocVisitService(new WordInfoVisitService
|
|||
|
{
|
|||
|
FileName = model.FileName,
|
|||
|
Title = "Визиты по услугам",
|
|||
|
VisitServices = GetVisitService(model.UserId)
|
|||
|
});
|
|||
|
}
|
|||
|
public void SaveServiceVisitToWordFile(ReportBindingModel model)
|
|||
|
{
|
|||
|
_saveToWord.CreateDocServiceVisit(new WordInfoServiceVisit
|
|||
|
{
|
|||
|
FileName = model.FileName,
|
|||
|
Title = "Услуги по визитам",
|
|||
|
VisitServices = GetServiceVisit(model.UserId)
|
|||
|
});
|
|||
|
}
|
|||
|
public List<ReportVisitViewModel> GetOrders(ReportBindingModel model)
|
|||
|
{
|
|||
|
return _VisitStorage.GetFilteredListDate(new VisitBindingModel
|
|||
|
{
|
|||
|
DateFrom =
|
|||
|
model.DateFrom,
|
|||
|
DateTo = model.DateTo
|
|||
|
})
|
|||
|
.Select(x => new ReportVisitViewModel
|
|||
|
{
|
|||
|
DateCreate = x.VisitsDate,
|
|||
|
ClientName = x.ClientName,
|
|||
|
Sum = x.Sum
|
|||
|
})
|
|||
|
.ToList();
|
|||
|
}
|
|||
|
public ReportServiceViewModel GetServices(ReportBindingModel model)
|
|||
|
{
|
|||
|
var list = _VisitStorage.GetFilteredListDate(new VisitBindingModel
|
|||
|
{
|
|||
|
DateFrom =
|
|||
|
model.DateFrom,
|
|||
|
DateTo = model.DateTo
|
|||
|
});
|
|||
|
Dictionary<string, int> dic = new Dictionary<string, int>();
|
|||
|
foreach (var item in list)
|
|||
|
{
|
|||
|
foreach (var item2 in item.VisitServices)
|
|||
|
{
|
|||
|
if (dic.ContainsKey(item2.Value))
|
|||
|
{
|
|||
|
dic[item2.Value]++;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
dic[item2.Value] = 1;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
return new ReportServiceViewModel()
|
|||
|
{
|
|||
|
Sum = paymentStorage.GetElementFirstLast(new PaymentDateBindingModel()).Remains,
|
|||
|
Services = dic
|
|||
|
};
|
|||
|
}
|
|||
|
public void SaveOrdersToPdfFileVisit(ReportBindingModel model)
|
|||
|
{
|
|||
|
_saveToPdf.CreateDoc(new PdfInfo
|
|||
|
{
|
|||
|
FileName = model.FileName,
|
|||
|
Title = "Список визитов",
|
|||
|
DateFrom = model.DateFrom.Value,
|
|||
|
DateTo = model.DateTo.Value,
|
|||
|
Visits = GetOrders(model)
|
|||
|
});
|
|||
|
}
|
|||
|
public void SaveOrdersToPdfFileService(ReportBindingModel model)
|
|||
|
{
|
|||
|
_saveToPdf.CreateDocService(new PdfInfoService
|
|||
|
{
|
|||
|
FileName = model.FileName,
|
|||
|
Title = "Список визитов",
|
|||
|
DateFrom = model.DateFrom.Value,
|
|||
|
DateTo = model.DateTo.Value,
|
|||
|
Services = GetServices(model)
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
}
|