This commit is contained in:
Maciej Maciejewski 2024-12-27 11:06:14 +01:00
parent ba4f8a717c
commit b9dd32ee4d
10 changed files with 146 additions and 31 deletions

View File

@ -2,8 +2,8 @@
{
public class AuthenticationSettings
{
public string JwtSecKey { get; set; }
public string JwtSecKey { get; set; }
public int JwtExpireDays { get; set; }
public string JwtIssuer { get; set; }
public string JwtIssuer { get; set; }
}
}

View File

@ -20,11 +20,13 @@ namespace FirmTracker_Server.Controllers
{
private readonly IExpenseRepository _expenseRepository;
private readonly ITransactionRepository _transactionRepository;
private readonly IProductRepository _productRepository;
public PdfController(IExpenseRepository expenseRepository, ITransactionRepository transactionRepository)
public PdfController(IExpenseRepository expenseRepository, ITransactionRepository transactionRepository, IProductRepository productRepository)
{
_expenseRepository = expenseRepository;
_transactionRepository = transactionRepository;
_productRepository = productRepository;
}
[HttpGet("download")]
@ -112,8 +114,9 @@ namespace FirmTracker_Server.Controllers
// Main header
page.Header()
.Text("Raport transakcji")
.FontSize(20)
.FontSize(22)
.SemiBold()
.FontColor(Colors.Blue.Medium)
.AlignCenter();
// Summary section
@ -122,16 +125,18 @@ namespace FirmTracker_Server.Controllers
column.Spacing(10);
column.Item().Text($"Transakcje od ({startDate:yyyy-MM-dd} do {endDate:yyyy-MM-dd})")
.FontSize(16).Underline();
.FontSize(16)
.Underline()
.FontColor(Colors.Grey.Medium);
// Add table header
column.Item().Row(row =>
{
row.RelativeItem().Text("Data").SemiBold();
row.RelativeItem().Text("Typ płatności").SemiBold();
row.RelativeItem().Text("Kwota razem").SemiBold();
row.RelativeItem().Text("Rabat").SemiBold();
row.RelativeItem().Text("Opis").SemiBold();
row.RelativeItem().Text("Data").SemiBold().FontColor(Colors.Blue.Darken1);
row.RelativeItem().Text("Typ płatności").SemiBold().FontColor(Colors.Blue.Darken1);
row.RelativeItem().Text("Kwota razem").SemiBold().FontColor(Colors.Blue.Darken1);
row.RelativeItem().Text("Rabat").SemiBold().FontColor(Colors.Blue.Darken1);
row.RelativeItem().Text("Opis").SemiBold().FontColor(Colors.Blue.Darken1);
});
// Populate table rows with transaction data
@ -153,13 +158,15 @@ namespace FirmTracker_Server.Controllers
if (products.Any())
{
column.Item().Text("Produkty:").SemiBold();
column.Item().Text("Produkty:").SemiBold().FontColor(Colors.Blue.Medium);
foreach (var product in products)
{
var productQuery = _productRepository.GetProduct(product.Id);
column.Item().Row(productRow =>
{
productRow.RelativeItem().Text($"Nazwa produktu: {product.ProductName}");
productRow.RelativeItem().Text($"Nazwa produktu: {productQuery.Name}");
productRow.RelativeItem().Text($"Ilość: {product.Quantity}");
productRow.RelativeItem().Text($"Cena 1 szt. bez rabatu: {productQuery.Price.ToString("F2")}");
});
}
}
@ -171,8 +178,8 @@ namespace FirmTracker_Server.Controllers
.AlignCenter()
.Text(text =>
{
text.Span("Wygenerowano przez automat FT: ");
text.Span(DateTime.Now.ToString("yyyy-MM-dd")).SemiBold();
text.Span("Wygenerowano przez automat FT: ").FontColor(Colors.Grey.Medium);
text.Span(DateTime.Now.ToString("yyyy-MM-dd")).SemiBold().FontColor(Colors.Grey.Medium);
});
});
}).GeneratePdf(ms);
@ -200,8 +207,9 @@ namespace FirmTracker_Server.Controllers
// Main header
page.Header()
.Text("Raport wydatków")
.FontSize(20)
.FontSize(22)
.SemiBold()
.FontColor(Colors.Green.Medium)
.AlignCenter();
// Summary section
@ -211,18 +219,20 @@ namespace FirmTracker_Server.Controllers
column.Item().Row(row =>
{
row.RelativeItem().Text($"Łączne wydatki: {totalExpenses:C}").FontSize(14).Bold();
row.RelativeItem().Text($"Średnie wydatki dzienne: {averageExpense:C}").FontSize(14).Bold();
row.RelativeItem().Text($"Łączne wydatki: {totalExpenses:C}").FontSize(14).Bold().FontColor(Colors.Green.Darken1);
row.RelativeItem().Text($"Średnie wydatki dzienne: {averageExpense:C}").FontSize(14).Bold().FontColor(Colors.Green.Darken1);
});
column.Item().Text($"Szczegóły wydatków od ({startDate:yyyy-MM-dd} do {endDate:yyyy-MM-dd})")
.FontSize(16).Underline();
.FontSize(16)
.Underline()
.FontColor(Colors.Grey.Medium);
column.Item().Row(row =>
{
row.RelativeItem().Text("Data").SemiBold();
row.RelativeItem().Text("Kwota").SemiBold();
row.RelativeItem().Text("Opis").SemiBold();
row.RelativeItem().Text("Data").SemiBold().FontColor(Colors.Green.Darken1);
row.RelativeItem().Text("Kwota").SemiBold().FontColor(Colors.Green.Darken1);
row.RelativeItem().Text("Opis").SemiBold().FontColor(Colors.Green.Darken1);
});
foreach (var expense in expenses)
@ -236,12 +246,13 @@ namespace FirmTracker_Server.Controllers
}
});
// Footer with generation date
page.Footer()
.AlignCenter()
.Text(text =>
{
text.Span("Wygenerowano przez automat FT: ");
text.Span(DateTime.Now.ToString("yyyy-MM-dd")).SemiBold();
text.Span("Wygenerowano przez automat FT: ").FontColor(Colors.Grey.Medium);
text.Span(DateTime.Now.ToString("yyyy-MM-dd")).SemiBold().FontColor(Colors.Grey.Medium);
});
});
}).GeneratePdf(ms);
@ -249,5 +260,7 @@ namespace FirmTracker_Server.Controllers
return ms.ToArray();
}
}
}
}

View File

@ -147,7 +147,7 @@ namespace FirmTracker_Server.Controllers
{
try
{
var userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value ;
var userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
var dayDetails = _workdayCRUD.GetDayDetailsForLoggedUser(int.Parse(userId), date);
return Ok(dayDetails);

View File

@ -2,10 +2,10 @@
{
public class CreateUserDto
{
public string Login { get; set; }
public string Password { get; set; }
public string Email { get; set; }
public string Role { get; set; }
public required string Login { get; set; }
public required string Password { get; set; }
public required string Email { get; set; }
public required string Role { get; set; }
public bool NewEncryption { get; set; } = true;
}
}

View File

@ -4,9 +4,9 @@ namespace FirmTracker_Server.Models
{
public class DayDetailsDto
{
public string Email { get; set; }
public required string Email { get; set; }
public DateTime Date { get; set; }
public string TotalWorkedHours { get; set; }
public List<Workday> WorkdayDetails { get; set; }
public required string TotalWorkedHours { get; set; }
public required List<Workday> WorkdayDetails { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace FirmTracker_Server.Models
{
public class UpdatePasswordDto
{
public string Email { get; set; }
public string Password { get; set; }
}
}

View File

@ -179,6 +179,7 @@ namespace FirmTracker_Server
services.AddScoped<IPasswordHasher<User>, PasswordHasher<User>>();
services.AddScoped<IExpenseRepository, ExpenseRepository>();
services.AddScoped<ITransactionRepository, TransactionRepository>();
services.AddScoped<IProductRepository, ProductRepository>();
// services.AddScoped<IWorkdayRepository, WorkdayRepository>();
services.AddMvc();
}

View File

@ -15,6 +15,8 @@ using szyfrowanie;
using FirmTracker_Server.nHibernate;
using NHibernate;
using NHibernate.Criterion;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using NHibernate.Type;
namespace FirmTracker_Server.Services
{
@ -24,6 +26,7 @@ namespace FirmTracker_Server.Services
int AddUser(CreateUserDto dto);
string CreateTokenJwt(LoginDto dto);
IEnumerable<string> GetAllUserEmails();
bool UpdatePassword(UpdatePasswordDto dto);
}
public class UserService : IUserService
@ -44,6 +47,10 @@ namespace FirmTracker_Server.Services
SimplerAES = new SimplerAES();
//SessionFactory = sessionFactory;
}
public bool UpdatePassword(UpdatePasswordDto dto)
{
return true;
}
public IEnumerable<string> GetAllUserEmails()
{
using (var session = SessionFactory.OpenSession())

View File

@ -237,6 +237,73 @@ namespace FirmTracker_Server
expenseCrud.AddExpense(expense1);
expenseCrud.AddExpense(expense2);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
expenseCrud.AddExpense(expense3);
List<TransactionProduct> testTransactionProducts = new List<TransactionProduct> {
new TransactionProduct { ProductID =17, Quantity = 3 },

View File

@ -1,11 +1,19 @@
using System.Collections.Generic;
using System.Linq;
using System.Transactions;
using FirmTracker_Server.nHibernate.Expenses;
using FirmTracker_Server.nHibernate.Products;
using FirmTracker_Server.nHibernate.Transactions;
using NHibernate;
using Transaction = FirmTracker_Server.nHibernate.Transactions.Transaction;
namespace FirmTracker_Server.nHibernate
{
public interface IProductRepository
{
Product GetProduct(int id);
}
public interface IExpenseRepository
{
List<Expense> GetAllExpenses();
@ -25,6 +33,17 @@ namespace FirmTracker_Server.nHibernate
void DeleteTransaction(int transactionId);
List<TransactionProduct> GetTransactionProductsForTransactions(List<int> transactionIds);
}
public class ProductRepository : IProductRepository
{
public Product GetProduct(int id)
{
using (var session = SessionFactory.OpenSession())
{
return session.Get<Product>(id);
}
}
}
public class TransactionRepository : ITransactionRepository
{
// Retrieve all transactions