implementato modulo HR
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
using Zentral.Domain.Entities.HR;
|
||||
using Zentral.Infrastructure.Data;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Zentral.API.Modules.HR.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/hr/[controller]")]
|
||||
public class AssenzeController : ControllerBase
|
||||
{
|
||||
private readonly ZentralDbContext _context;
|
||||
|
||||
public AssenzeController(ZentralDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<Assenza>>> GetAssenze([FromQuery] int? dipendenteId, [FromQuery] DateTime? from, [FromQuery] DateTime? to)
|
||||
{
|
||||
var query = _context.Assenze.Include(a => a.Dipendente).AsQueryable();
|
||||
|
||||
if (dipendenteId.HasValue)
|
||||
query = query.Where(a => a.DipendenteId == dipendenteId.Value);
|
||||
|
||||
if (from.HasValue)
|
||||
query = query.Where(a => a.DataInizio >= from.Value);
|
||||
|
||||
if (to.HasValue)
|
||||
query = query.Where(a => a.DataFine <= to.Value);
|
||||
|
||||
return await query.OrderByDescending(a => a.DataInizio).ToListAsync();
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<Assenza>> GetAssenza(int id)
|
||||
{
|
||||
var assenza = await _context.Assenze
|
||||
.Include(a => a.Dipendente)
|
||||
.FirstOrDefaultAsync(a => a.Id == id);
|
||||
|
||||
if (assenza == null)
|
||||
return NotFound();
|
||||
|
||||
return assenza;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<Assenza>> CreateAssenza(Assenza assenza)
|
||||
{
|
||||
assenza.CreatedAt = DateTime.UtcNow;
|
||||
_context.Assenze.Add(assenza);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return CreatedAtAction(nameof(GetAssenza), new { id = assenza.Id }, assenza);
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> UpdateAssenza(int id, Assenza assenza)
|
||||
{
|
||||
if (id != assenza.Id)
|
||||
return BadRequest();
|
||||
|
||||
assenza.UpdatedAt = DateTime.UtcNow;
|
||||
_context.Entry(assenza).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!await _context.Assenze.AnyAsync(a => a.Id == id))
|
||||
return NotFound();
|
||||
throw;
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> DeleteAssenza(int id)
|
||||
{
|
||||
var assenza = await _context.Assenze.FindAsync(id);
|
||||
if (assenza == null)
|
||||
return NotFound();
|
||||
|
||||
_context.Assenze.Remove(assenza);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
using Zentral.Domain.Entities.HR;
|
||||
using Zentral.Infrastructure.Data;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Zentral.API.Modules.HR.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/hr/[controller]")]
|
||||
public class ContrattiController : ControllerBase
|
||||
{
|
||||
private readonly ZentralDbContext _context;
|
||||
|
||||
public ContrattiController(ZentralDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<Contratto>>> GetContratti([FromQuery] int? dipendenteId)
|
||||
{
|
||||
var query = _context.Contratti.Include(c => c.Dipendente).AsQueryable();
|
||||
|
||||
if (dipendenteId.HasValue)
|
||||
query = query.Where(c => c.DipendenteId == dipendenteId.Value);
|
||||
|
||||
return await query.OrderByDescending(c => c.DataInizio).ToListAsync();
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<Contratto>> GetContratto(int id)
|
||||
{
|
||||
var contratto = await _context.Contratti
|
||||
.Include(c => c.Dipendente)
|
||||
.FirstOrDefaultAsync(c => c.Id == id);
|
||||
|
||||
if (contratto == null)
|
||||
return NotFound();
|
||||
|
||||
return contratto;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<Contratto>> CreateContratto(Contratto contratto)
|
||||
{
|
||||
contratto.CreatedAt = DateTime.UtcNow;
|
||||
_context.Contratti.Add(contratto);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return CreatedAtAction(nameof(GetContratto), new { id = contratto.Id }, contratto);
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> UpdateContratto(int id, Contratto contratto)
|
||||
{
|
||||
if (id != contratto.Id)
|
||||
return BadRequest();
|
||||
|
||||
contratto.UpdatedAt = DateTime.UtcNow;
|
||||
_context.Entry(contratto).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!await _context.Contratti.AnyAsync(c => c.Id == id))
|
||||
return NotFound();
|
||||
throw;
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> DeleteContratto(int id)
|
||||
{
|
||||
var contratto = await _context.Contratti.FindAsync(id);
|
||||
if (contratto == null)
|
||||
return NotFound();
|
||||
|
||||
_context.Contratti.Remove(contratto);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
using Zentral.Domain.Entities.HR;
|
||||
using Zentral.Infrastructure.Data;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Zentral.API.Modules.HR.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/hr/[controller]")]
|
||||
public class DipendentiController : ControllerBase
|
||||
{
|
||||
private readonly ZentralDbContext _context;
|
||||
|
||||
public DipendentiController(ZentralDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<Dipendente>>> GetDipendenti([FromQuery] string? search)
|
||||
{
|
||||
var query = _context.Dipendenti.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(search))
|
||||
query = query.Where(d => d.Nome.Contains(search) ||
|
||||
d.Cognome.Contains(search) ||
|
||||
(d.CodiceFiscale != null && d.CodiceFiscale.Contains(search)));
|
||||
|
||||
return await query.OrderBy(d => d.Cognome).ThenBy(d => d.Nome).ToListAsync();
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<Dipendente>> GetDipendente(int id)
|
||||
{
|
||||
var dipendente = await _context.Dipendenti
|
||||
.Include(d => d.Contratti)
|
||||
.Include(d => d.Assenze)
|
||||
.Include(d => d.Pagamenti)
|
||||
.Include(d => d.Rimborsi)
|
||||
.FirstOrDefaultAsync(d => d.Id == id);
|
||||
|
||||
if (dipendente == null)
|
||||
return NotFound();
|
||||
|
||||
return dipendente;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<Dipendente>> CreateDipendente(Dipendente dipendente)
|
||||
{
|
||||
dipendente.CreatedAt = DateTime.UtcNow;
|
||||
_context.Dipendenti.Add(dipendente);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return CreatedAtAction(nameof(GetDipendente), new { id = dipendente.Id }, dipendente);
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> UpdateDipendente(int id, Dipendente dipendente)
|
||||
{
|
||||
if (id != dipendente.Id)
|
||||
return BadRequest();
|
||||
|
||||
dipendente.UpdatedAt = DateTime.UtcNow;
|
||||
_context.Entry(dipendente).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!await _context.Dipendenti.AnyAsync(d => d.Id == id))
|
||||
return NotFound();
|
||||
throw;
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> DeleteDipendente(int id)
|
||||
{
|
||||
var dipendente = await _context.Dipendenti.FindAsync(id);
|
||||
if (dipendente == null)
|
||||
return NotFound();
|
||||
|
||||
_context.Dipendenti.Remove(dipendente);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
using Zentral.Domain.Entities.HR;
|
||||
using Zentral.Infrastructure.Data;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Zentral.API.Modules.HR.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/hr/[controller]")]
|
||||
public class PagamentiController : ControllerBase
|
||||
{
|
||||
private readonly ZentralDbContext _context;
|
||||
|
||||
public PagamentiController(ZentralDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<Pagamento>>> GetPagamenti([FromQuery] int? dipendenteId, [FromQuery] DateTime? from, [FromQuery] DateTime? to)
|
||||
{
|
||||
var query = _context.Pagamenti.Include(p => p.Dipendente).AsQueryable();
|
||||
|
||||
if (dipendenteId.HasValue)
|
||||
query = query.Where(p => p.DipendenteId == dipendenteId.Value);
|
||||
|
||||
if (from.HasValue)
|
||||
query = query.Where(p => p.DataPagamento >= from.Value);
|
||||
|
||||
if (to.HasValue)
|
||||
query = query.Where(p => p.DataPagamento <= to.Value);
|
||||
|
||||
return await query.OrderByDescending(p => p.DataPagamento).ToListAsync();
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<Pagamento>> GetPagamento(int id)
|
||||
{
|
||||
var pagamento = await _context.Pagamenti
|
||||
.Include(p => p.Dipendente)
|
||||
.FirstOrDefaultAsync(p => p.Id == id);
|
||||
|
||||
if (pagamento == null)
|
||||
return NotFound();
|
||||
|
||||
return pagamento;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<Pagamento>> CreatePagamento(Pagamento pagamento)
|
||||
{
|
||||
pagamento.CreatedAt = DateTime.UtcNow;
|
||||
_context.Pagamenti.Add(pagamento);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return CreatedAtAction(nameof(GetPagamento), new { id = pagamento.Id }, pagamento);
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> UpdatePagamento(int id, Pagamento pagamento)
|
||||
{
|
||||
if (id != pagamento.Id)
|
||||
return BadRequest();
|
||||
|
||||
pagamento.UpdatedAt = DateTime.UtcNow;
|
||||
_context.Entry(pagamento).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!await _context.Pagamenti.AnyAsync(p => p.Id == id))
|
||||
return NotFound();
|
||||
throw;
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> DeletePagamento(int id)
|
||||
{
|
||||
var pagamento = await _context.Pagamenti.FindAsync(id);
|
||||
if (pagamento == null)
|
||||
return NotFound();
|
||||
|
||||
_context.Pagamenti.Remove(pagamento);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using Zentral.Domain.Entities.HR;
|
||||
using Zentral.Infrastructure.Data;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Zentral.API.Modules.HR.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/hr/[controller]")]
|
||||
public class RimborsiController : ControllerBase
|
||||
{
|
||||
private readonly ZentralDbContext _context;
|
||||
|
||||
public RimborsiController(ZentralDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<Rimborso>>> GetRimborsi([FromQuery] int? dipendenteId, [FromQuery] string? stato)
|
||||
{
|
||||
var query = _context.Rimborsi.Include(r => r.Dipendente).AsQueryable();
|
||||
|
||||
if (dipendenteId.HasValue)
|
||||
query = query.Where(r => r.DipendenteId == dipendenteId.Value);
|
||||
|
||||
if (!string.IsNullOrEmpty(stato))
|
||||
query = query.Where(r => r.Stato == stato);
|
||||
|
||||
return await query.OrderByDescending(r => r.DataSpesa).ToListAsync();
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<Rimborso>> GetRimborso(int id)
|
||||
{
|
||||
var rimborso = await _context.Rimborsi
|
||||
.Include(r => r.Dipendente)
|
||||
.FirstOrDefaultAsync(r => r.Id == id);
|
||||
|
||||
if (rimborso == null)
|
||||
return NotFound();
|
||||
|
||||
return rimborso;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<Rimborso>> CreateRimborso(Rimborso rimborso)
|
||||
{
|
||||
rimborso.CreatedAt = DateTime.UtcNow;
|
||||
_context.Rimborsi.Add(rimborso);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return CreatedAtAction(nameof(GetRimborso), new { id = rimborso.Id }, rimborso);
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> UpdateRimborso(int id, Rimborso rimborso)
|
||||
{
|
||||
if (id != rimborso.Id)
|
||||
return BadRequest();
|
||||
|
||||
rimborso.UpdatedAt = DateTime.UtcNow;
|
||||
_context.Entry(rimborso).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!await _context.Rimborsi.AnyAsync(r => r.Id == id))
|
||||
return NotFound();
|
||||
throw;
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> DeleteRimborso(int id)
|
||||
{
|
||||
var rimborso = await _context.Rimborsi.FindAsync(id);
|
||||
if (rimborso == null)
|
||||
return NotFound();
|
||||
|
||||
_context.Rimborsi.Remove(rimborso);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
@@ -405,9 +405,6 @@ public class ModuleService
|
||||
/// </summary>
|
||||
public async Task SeedDefaultModulesAsync()
|
||||
{
|
||||
if (await _context.AppModules.AnyAsync())
|
||||
return;
|
||||
|
||||
var defaultModules = new List<AppModule>
|
||||
{
|
||||
new AppModule
|
||||
@@ -482,12 +479,46 @@ public class ModuleService
|
||||
RoutePath = "/quality",
|
||||
IsAvailable = true,
|
||||
CreatedAt = DateTime.UtcNow
|
||||
},
|
||||
new AppModule
|
||||
{
|
||||
Code = "events",
|
||||
Name = "Gestione Eventi",
|
||||
Description = "Gestione eventi, pianificazione e controllo avanzamento",
|
||||
Icon = "Event",
|
||||
BasePrice = 2000m,
|
||||
MonthlyMultiplier = 1.2m,
|
||||
SortOrder = 60,
|
||||
IsCore = false,
|
||||
RoutePath = "/events",
|
||||
IsAvailable = true,
|
||||
CreatedAt = DateTime.UtcNow
|
||||
},
|
||||
new AppModule
|
||||
{
|
||||
Code = "hr",
|
||||
Name = "Gestione Personale",
|
||||
Description = "Gestione personale, contratti, pagamenti, assenze, rimborsi e analisi personale",
|
||||
Icon = "People",
|
||||
BasePrice = 1600m,
|
||||
MonthlyMultiplier = 1.2m,
|
||||
SortOrder = 70,
|
||||
IsCore = false,
|
||||
RoutePath = "/hr",
|
||||
IsAvailable = true,
|
||||
CreatedAt = DateTime.UtcNow
|
||||
}
|
||||
};
|
||||
|
||||
_context.AppModules.AddRange(defaultModules);
|
||||
await _context.SaveChangesAsync();
|
||||
var existingCodes = await _context.AppModules.Select(m => m.Code).ToListAsync();
|
||||
var newModules = defaultModules.Where(m => !existingCodes.Contains(m.Code)).ToList();
|
||||
|
||||
_logger.LogInformation("Seed {Count} moduli di default completato", defaultModules.Count);
|
||||
if (newModules.Any())
|
||||
{
|
||||
_context.AppModules.AddRange(newModules);
|
||||
await _context.SaveChangesAsync();
|
||||
_logger.LogInformation("Added {Count} new default modules: {Modules}",
|
||||
newModules.Count, string.Join(", ", newModules.Select(m => m.Code)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user