Added the UID in job ticket table and view model

This commit is contained in:
ashutosh.nehete 2025-11-17 14:34:21 +05:30
parent bd14424062
commit 863f0ce8e2
9 changed files with 8875 additions and 4 deletions

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,40 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Marco.Pms.DataAccess.Migrations
{
/// <inheritdoc />
public partial class Added_UID_In_JobTicket_Table : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "UIDPostfix",
table: "JobTickets",
type: "int",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<string>(
name: "UIDPrefix",
table: "JobTickets",
type: "longtext",
nullable: false)
.Annotation("MySql:CharSet", "utf8mb4");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "UIDPostfix",
table: "JobTickets");
migrationBuilder.DropColumn(
name: "UIDPrefix",
table: "JobTickets");
}
}
}

View File

@ -5506,6 +5506,13 @@ namespace Marco.Pms.DataAccess.Migrations
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("UIDPostfix")
.HasColumnType("int");
b.Property<string>("UIDPrefix")
.IsRequired()
.HasColumnType("longtext");
b.Property<DateTime?>("UpdatedAt")
.HasColumnType("datetime(6)");

View File

@ -10,6 +10,8 @@ namespace Marco.Pms.Model.ServiceProject
public Guid Id { get; set; }
public string Title { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public string UIDPrefix { get; set; } = default!;
public int UIDPostfix { get; set; }
public Guid ProjectId { get; set; }
[ValidateNever]

View File

@ -5,6 +5,7 @@
public Guid Id { get; set; }
public string? Title { get; set; }
public string? Description { get; set; }
public string? JobTicketUId { get; set; }
public string? StatusName { get; set; }
}
}

View File

@ -9,6 +9,7 @@ namespace Marco.Pms.Model.ViewModels.ServiceProject
public Guid Id { get; set; }
public string? Title { get; set; }
public string? Description { get; set; }
public string? JobTicketUId { get; set; }
public BasicServiceProjectVM? Project { get; set; }
public List<BasicEmployeeVM>? Assignees { get; set; }
public JobStatus? Status { get; set; }

View File

@ -9,6 +9,7 @@ namespace Marco.Pms.Model.ViewModels.ServiceProject
public Guid Id { get; set; }
public string? Title { get; set; }
public string? Description { get; set; }
public string? JobTicketUId { get; set; }
public BasicServiceProjectVM? Project { get; set; }
public List<BasicEmployeeVM>? Assignees { get; set; }
public JobStatus? Status { get; set; }

View File

@ -203,12 +203,21 @@ namespace Marco.Pms.Services.MappingProfiles
CreateMap<CreateJobTicketDto, JobTicket>();
CreateMap<UpdateJobTicketDto, JobTicket>();
CreateMap<JobTicket, UpdateJobTicketDto>();
CreateMap<JobTicket, JobTicketVM>();
CreateMap<JobTicket, JobTicketDetailsVM>();
CreateMap<JobTicket, JobTicketVM>()
.ForMember(
dest => dest.JobTicketUId,
opt => opt.MapFrom(src => $"{src.UIDPrefix}/{src.UIDPostfix:D5}"));
CreateMap<JobTicket, JobTicketDetailsVM>()
.ForMember(
dest => dest.JobTicketUId,
opt => opt.MapFrom(src => $"{src.UIDPrefix}/{src.UIDPostfix:D5}"));
CreateMap<JobTicket, BasicJobTicketVM>()
.ForMember(
dest => dest.StatusName,
opt => opt.MapFrom(src => src.Status != null ? src.Status.Name : null));
opt => opt.MapFrom(src => src.Status != null ? src.Status.Name : null))
.ForMember(
dest => dest.JobTicketUId,
opt => opt.MapFrom(src => $"{src.UIDPrefix}/{src.UIDPostfix:D5}"));
CreateMap<JobComment, JobCommentVM>();

View File

@ -1074,10 +1074,20 @@ namespace Marco.Pms.Services.Service
var hasAssignees = model.Assignees?.Any(a => a.IsActive) ?? false;
string uIDPrefix = $"JT/{DateTime.Now:MMyy}";
// Generate unique UID postfix based on existing requests for the current prefix
var lastPR = await _context.JobTickets.Where(pr => pr.UIDPrefix == uIDPrefix)
.OrderByDescending(pr => pr.UIDPostfix)
.FirstOrDefaultAsync();
int uIDPostfix = lastPR == null ? 1 : (lastPR.UIDPostfix + 1);
// Map DTO to entity
var jobTicket = _mapper.Map<JobTicket>(model);
jobTicket.Id = Guid.NewGuid();
jobTicket.StatusId = hasAssignees ? AssignedStatus : NewStatus;
jobTicket.UIDPrefix = uIDPrefix;
jobTicket.UIDPostfix = uIDPostfix;
jobTicket.CreatedAt = DateTime.UtcNow;
jobTicket.CreatedById = loggedInEmployee.Id;
jobTicket.TenantId = tenantId;
@ -2149,7 +2159,6 @@ namespace Marco.Pms.Services.Service
return ApiResponse<object>.ErrorResponse("An unexpected error occurred.", ex.Message, 500);
}
}
public async Task<ApiResponse<object>> GetAttendanceForJobTeamAsync(Guid jobTicketId, DateTime? startDate, DateTime? endDate, Employee loggedInEmployee, Guid tenantId)
{
_logger.LogInfo("GetAttendanceForJobTeamAsync called for JobTicketId: {JobTicketId}, TenantId: {TenantId}, EmployeeId: {EmployeeId}", jobTicketId, tenantId, loggedInEmployee.Id);