Исправление отчётов

This commit is contained in:
Николай 2023-04-08 15:51:12 +04:00
parent 0b0e6abcde
commit 923d110e40
11 changed files with 36 additions and 36 deletions

View File

@ -14,23 +14,13 @@ namespace HardwareShopContracts.BusinessLogicsContracts
{ {
public class WorkerReportLogic : IWorkerReportLogic public class WorkerReportLogic : IWorkerReportLogic
{ {
private readonly IComponentStorage _componentStorage;
private readonly BuildStorage _buildStorage;
private readonly IPurchaseStorage _purchaseStorage; private readonly IPurchaseStorage _purchaseStorage;
private readonly IGoodStorage _goodStorage; public WorkerReportLogic(IPurchaseStorage purchaseStorage)
private readonly ICommentStorage _commentStorage;
public WorkerReportLogic(IComponentStorage componentStorage, BuildStorage buildStorage, IPurchaseStorage purchaseStorage, IGoodStorage goodStorage, ICommentStorage commentStorage)
{ {
_componentStorage = componentStorage;
_buildStorage = buildStorage;
_purchaseStorage = purchaseStorage; _purchaseStorage = purchaseStorage;
_goodStorage = goodStorage;
_commentStorage = commentStorage;
} }
/// <summary> /// <summary>
@ -48,7 +38,7 @@ namespace HardwareShopContracts.BusinessLogicsContracts
Id = purchase.Id, Id = purchase.Id,
Builds = new List<(string Build, int count, List<(string Component, int count)>)>(), Builds = new List<(string Build, int count, List<(string Component, int count)>)>(),
TotalCount = 0, TotalCount = 0,
TotalCost = 0 TotalCost = purchase.Sum,
}; };
foreach (var build in purchase.PurchaseBuilds) foreach (var build in purchase.PurchaseBuilds)
{ {
@ -62,6 +52,7 @@ namespace HardwareShopContracts.BusinessLogicsContracts
record.Builds.Add(new(build.Value.Item1.BuildName, build.Value.Item2, componentList)); record.Builds.Add(new(build.Value.Item1.BuildName, build.Value.Item2, componentList));
record.TotalCount += buildTotalCount * build.Value.Item2; record.TotalCount += buildTotalCount * build.Value.Item2;
} }
list.Add(record); list.Add(record);
} }
return list; return list;
@ -72,10 +63,10 @@ namespace HardwareShopContracts.BusinessLogicsContracts
/// </summary> /// </summary>
/// <param name="model"></param> /// <param name="model"></param>
/// <returns></returns> /// <returns></returns>
public List<ReportPurchaseViewModel> GetPurchase(ReportBindingModel model) public List<ReportPurchaseViewModel> GetPurchase(ReportBindingModel model, UserBindingModel userModel)
{ {
var list = new List<ReportPurchaseViewModel>(); var list = new List<ReportPurchaseViewModel>();
var purchases = _purchaseStorage.GetFilteredList(new PurchaseSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo }); var purchases = _purchaseStorage.GetFilteredList(new PurchaseSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo, UserId = userModel.Id });
foreach (var purchase in purchases) foreach (var purchase in purchases)
{ {
@ -98,6 +89,7 @@ namespace HardwareShopContracts.BusinessLogicsContracts
} }
record.Builds.Add(new (build.Value.Item1.BuildName, build.Value.Item2, commentList, componentList)); record.Builds.Add(new (build.Value.Item1.BuildName, build.Value.Item2, commentList, componentList));
} }
list.Add(record);
} }
return list; return list;
} }

View File

@ -17,7 +17,7 @@ namespace HardwareShopContracts.BusinessLogicsContracts
/// </summary> /// </summary>
/// <param name="model"></param> /// <param name="model"></param>
/// <returns></returns> /// <returns></returns>
List<ReportPurchaseViewModel> GetPurchase(ReportBindingModel model); List<ReportPurchaseViewModel> GetPurchase(ReportBindingModel model, UserBindingModel userModel);
/// <summary> /// <summary>
/// Сохранение компонент с указаеним покупок в файл-Word /// Сохранение компонент с указаеним покупок в файл-Word

View File

@ -14,7 +14,7 @@ namespace HardwareShopContracts.ViewModels
public int TotalCount { get; set; } public int TotalCount { get; set; }
public int TotalCost { get; set; } public double TotalCost { get; set; }
} }

View File

@ -10,7 +10,7 @@ namespace HardwareShopDatabaseImplement
{ {
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {
optionsBuilder.UseNpgsql("Host=localhost;Port=5433;Database=Computer_Hardware_Store;Username=user;Password=12345"); optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=Computer_Hardware_Store3;Username=postgres;Password=1234");
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
} }

View File

@ -24,7 +24,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
public List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model) public List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model)
{ {
using var context = new HardwareShopDatabase(); using var context = new HardwareShopDatabase();
if (!model.UserId.HasValue && !model.PurchaseStatus.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue) if (model.UserId.HasValue && !model.PurchaseStatus.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue)
{ {
return context.Purchases return context.Purchases
.Include(x => x.Builds) .Include(x => x.Builds)
@ -34,7 +34,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
.Include(x => x.Builds) .Include(x => x.Builds)
.ThenInclude(x => x.Build) .ThenInclude(x => x.Build)
.ThenInclude(x => x.Comments) .ThenInclude(x => x.Comments)
.Where(x => x.DatePurchase >= model.DateFrom && x.DatePurchase <= model.DateTo) .Where(x => x.UserId == model.UserId && x.DatePurchase >= model.DateFrom && x.DatePurchase <= model.DateTo )
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }

View File

@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace HardwareShopDatabaseImplement.Migrations namespace HardwareShopDatabaseImplement.Migrations
{ {
[DbContext(typeof(HardwareShopDatabase))] [DbContext(typeof(HardwareShopDatabase))]
[Migration("20230406172812_InitMigration")] [Migration("20230408110229_Init")]
partial class InitMigration partial class Init
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -113,7 +113,7 @@ namespace HardwareShopDatabaseImplement.Migrations
.HasColumnType("double precision"); .HasColumnType("double precision");
b.Property<DateTime>("DateCreate") b.Property<DateTime>("DateCreate")
.HasColumnType("timestamp with time zone"); .HasColumnType("timestamp without time zone");
b.Property<int>("UserId") b.Property<int>("UserId")
.HasColumnType("integer"); .HasColumnType("integer");
@ -162,10 +162,10 @@ namespace HardwareShopDatabaseImplement.Migrations
.HasColumnType("integer"); .HasColumnType("integer");
b.Property<DateTime>("DateCreate") b.Property<DateTime>("DateCreate")
.HasColumnType("timestamp with time zone"); .HasColumnType("timestamp without time zone");
b.Property<DateTime?>("DateImplement") b.Property<DateTime?>("DateImplement")
.HasColumnType("timestamp with time zone"); .HasColumnType("timestamp without time zone");
b.Property<int>("GoodId") b.Property<int>("GoodId")
.HasColumnType("integer"); .HasColumnType("integer");
@ -283,7 +283,7 @@ namespace HardwareShopDatabaseImplement.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime?>("DatePurchase") b.Property<DateTime?>("DatePurchase")
.HasColumnType("timestamp with time zone"); .HasColumnType("timestamp without time zone");
b.Property<int>("PurchaseStatus") b.Property<int>("PurchaseStatus")
.HasColumnType("integer"); .HasColumnType("integer");

View File

@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace HardwareShopDatabaseImplement.Migrations namespace HardwareShopDatabaseImplement.Migrations
{ {
/// <inheritdoc /> /// <inheritdoc />
public partial class InitMigration : Migration public partial class Init : Migration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
@ -58,7 +58,7 @@ namespace HardwareShopDatabaseImplement.Migrations
ComponentName = table.Column<string>(type: "text", nullable: false), ComponentName = table.Column<string>(type: "text", nullable: false),
Cost = table.Column<double>(type: "double precision", nullable: false), Cost = table.Column<double>(type: "double precision", nullable: false),
UserId = table.Column<int>(type: "integer", nullable: false), UserId = table.Column<int>(type: "integer", nullable: false),
DateCreate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false) DateCreate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
@ -100,7 +100,7 @@ namespace HardwareShopDatabaseImplement.Migrations
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Sum = table.Column<double>(type: "double precision", nullable: false), Sum = table.Column<double>(type: "double precision", nullable: false),
PurchaseStatus = table.Column<int>(type: "integer", nullable: false), PurchaseStatus = table.Column<int>(type: "integer", nullable: false),
DatePurchase = table.Column<DateTime>(type: "timestamp with time zone", nullable: true), DatePurchase = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
UserId = table.Column<int>(type: "integer", nullable: false) UserId = table.Column<int>(type: "integer", nullable: false)
}, },
constraints: table => constraints: table =>
@ -202,8 +202,8 @@ namespace HardwareShopDatabaseImplement.Migrations
Count = table.Column<int>(type: "integer", nullable: false), Count = table.Column<int>(type: "integer", nullable: false),
Sum = table.Column<double>(type: "double precision", nullable: false), Sum = table.Column<double>(type: "double precision", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false), Status = table.Column<int>(type: "integer", nullable: false),
DateCreate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false), DateCreate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
DateImplement = table.Column<DateTime>(type: "timestamp with time zone", nullable: true) DateImplement = table.Column<DateTime>(type: "timestamp without time zone", nullable: true)
}, },
constraints: table => constraints: table =>
{ {

View File

@ -110,7 +110,7 @@ namespace HardwareShopDatabaseImplement.Migrations
.HasColumnType("double precision"); .HasColumnType("double precision");
b.Property<DateTime>("DateCreate") b.Property<DateTime>("DateCreate")
.HasColumnType("timestamp with time zone"); .HasColumnType("timestamp without time zone");
b.Property<int>("UserId") b.Property<int>("UserId")
.HasColumnType("integer"); .HasColumnType("integer");
@ -159,10 +159,10 @@ namespace HardwareShopDatabaseImplement.Migrations
.HasColumnType("integer"); .HasColumnType("integer");
b.Property<DateTime>("DateCreate") b.Property<DateTime>("DateCreate")
.HasColumnType("timestamp with time zone"); .HasColumnType("timestamp without time zone");
b.Property<DateTime?>("DateImplement") b.Property<DateTime?>("DateImplement")
.HasColumnType("timestamp with time zone"); .HasColumnType("timestamp without time zone");
b.Property<int>("GoodId") b.Property<int>("GoodId")
.HasColumnType("integer"); .HasColumnType("integer");
@ -280,7 +280,7 @@ namespace HardwareShopDatabaseImplement.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime?>("DatePurchase") b.Property<DateTime?>("DatePurchase")
.HasColumnType("timestamp with time zone"); .HasColumnType("timestamp without time zone");
b.Property<int>("PurchaseStatus") b.Property<int>("PurchaseStatus")
.HasColumnType("integer"); .HasColumnType("integer");

View File

@ -102,6 +102,8 @@ namespace HardwareShopDatabaseImplement.Models.Worker
Price = Price, Price = Price,
UserId = UserId, UserId = UserId,
BuildPurchases = BuildPurchases, BuildPurchases = BuildPurchases,
BuildComponents = BuildComponents,
BuildComments = BuildComments
}; };
public void UpdatePurchases(HardwareShopDatabase context, BuildBindingModel model) public void UpdatePurchases(HardwareShopDatabase context, BuildBindingModel model)

View File

@ -93,7 +93,8 @@ namespace HardwareShopDatabaseImplement.Models.Worker
PurchaseStatus = PurchaseStatus, PurchaseStatus = PurchaseStatus,
DatePurchase = DatePurchase, DatePurchase = DatePurchase,
UserId = UserId, UserId = UserId,
PurchaseGoods = PurchaseGoods PurchaseGoods = PurchaseGoods,
PurchaseBuilds = PurchaseBuilds
}; };
public void UpdateGoods(HardwareShopDatabase context, PurchaseBindingModel model) public void UpdateGoods(HardwareShopDatabase context, PurchaseBindingModel model)

View File

@ -12,10 +12,15 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\HardwareShopBusinessLogic\HardwareShopBusinessLogic.csproj" />
<ProjectReference Include="..\HardwareShopContracts\HardwareShopContracts.csproj" /> <ProjectReference Include="..\HardwareShopContracts\HardwareShopContracts.csproj" />
<ProjectReference Include="..\HardwareShopDatabaseImplement\HardwareShopDatabaseImplement.csproj" /> <ProjectReference Include="..\HardwareShopDatabaseImplement\HardwareShopDatabaseImplement.csproj" />
</ItemGroup> </ItemGroup>