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

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
{
private readonly IComponentStorage _componentStorage;
private readonly BuildStorage _buildStorage;
private readonly IPurchaseStorage _purchaseStorage;
private readonly IGoodStorage _goodStorage;
private readonly ICommentStorage _commentStorage;
public WorkerReportLogic(IComponentStorage componentStorage, BuildStorage buildStorage, IPurchaseStorage purchaseStorage, IGoodStorage goodStorage, ICommentStorage commentStorage)
public WorkerReportLogic(IPurchaseStorage purchaseStorage)
{
_componentStorage = componentStorage;
_buildStorage = buildStorage;
_purchaseStorage = purchaseStorage;
_goodStorage = goodStorage;
_commentStorage = commentStorage;
}
/// <summary>
@ -48,7 +38,7 @@ namespace HardwareShopContracts.BusinessLogicsContracts
Id = purchase.Id,
Builds = new List<(string Build, int count, List<(string Component, int count)>)>(),
TotalCount = 0,
TotalCost = 0
TotalCost = purchase.Sum,
};
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.TotalCount += buildTotalCount * build.Value.Item2;
}
list.Add(record);
}
return list;
@ -72,10 +63,10 @@ namespace HardwareShopContracts.BusinessLogicsContracts
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public List<ReportPurchaseViewModel> GetPurchase(ReportBindingModel model)
public List<ReportPurchaseViewModel> GetPurchase(ReportBindingModel model, UserBindingModel userModel)
{
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)
{
@ -98,6 +89,7 @@ namespace HardwareShopContracts.BusinessLogicsContracts
}
record.Builds.Add(new (build.Value.Item1.BuildName, build.Value.Item2, commentList, componentList));
}
list.Add(record);
}
return list;
}

View File

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

View File

@ -14,7 +14,7 @@ namespace HardwareShopContracts.ViewModels
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)
{
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);
}

View File

@ -24,7 +24,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
public List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model)
{
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
.Include(x => x.Builds)
@ -34,7 +34,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
.Include(x => x.Builds)
.ThenInclude(x => x.Build)
.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)
.ToList();
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -12,10 +12,15 @@
</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" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HardwareShopBusinessLogic\HardwareShopBusinessLogic.csproj" />
<ProjectReference Include="..\HardwareShopContracts\HardwareShopContracts.csproj" />
<ProjectReference Include="..\HardwareShopDatabaseImplement\HardwareShopDatabaseImplement.csproj" />
</ItemGroup>