Added ExpenseUId in expense table
This commit is contained in:
parent
590476a8aa
commit
8f463ce90d
6209
Marco.Pms.DataAccess/Migrations/20251003093145_Added_ExpenceUID_In_Expense_Table.Designer.cs
generated
Normal file
6209
Marco.Pms.DataAccess/Migrations/20251003093145_Added_ExpenceUID_In_Expense_Table.Designer.cs
generated
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1,29 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Marco.Pms.DataAccess.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class Added_ExpenceUID_In_Expense_Table : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "ExpenseUId",
|
||||||
|
table: "Expenses",
|
||||||
|
type: "longtext",
|
||||||
|
nullable: false)
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "ExpenseUId",
|
||||||
|
table: "Expenses");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1832,6 +1832,10 @@ namespace Marco.Pms.DataAccess.Migrations
|
|||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("ExpenseUId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
b.Property<Guid>("ExpensesTypeId")
|
b.Property<Guid>("ExpensesTypeId")
|
||||||
.HasColumnType("char(36)");
|
.HasColumnType("char(36)");
|
||||||
|
|
||||||
|
@ -54,6 +54,7 @@ namespace Marco.Pms.Model.Expenses
|
|||||||
public DateTime CreatedAt { get; set; }
|
public DateTime CreatedAt { get; set; }
|
||||||
public string? TransactionId { get; set; }
|
public string? TransactionId { get; set; }
|
||||||
public string Description { get; set; } = string.Empty;
|
public string Description { get; set; } = string.Empty;
|
||||||
|
public string ExpenseUId { get; set; } = string.Empty;
|
||||||
public string? Location { get; set; }
|
public string? Location { get; set; }
|
||||||
public string? GSTNumber { get; set; }
|
public string? GSTNumber { get; set; }
|
||||||
public string SupplerName { get; set; } = string.Empty;
|
public string SupplerName { get; set; } = string.Empty;
|
||||||
|
@ -20,6 +20,7 @@ namespace Marco.Pms.Model.MongoDBModels.Expenses
|
|||||||
public DateTime ExpireAt { get; set; } = DateTime.UtcNow.Date.AddDays(1);
|
public DateTime ExpireAt { get; set; } = DateTime.UtcNow.Date.AddDays(1);
|
||||||
public string SupplerName { get; set; } = string.Empty;
|
public string SupplerName { get; set; } = string.Empty;
|
||||||
public double Amount { get; set; }
|
public double Amount { get; set; }
|
||||||
|
public string? ExpenseUId { get; set; }
|
||||||
public ExpensesStatusMasterMongoDB Status { get; set; } = new ExpensesStatusMasterMongoDB();
|
public ExpensesStatusMasterMongoDB Status { get; set; } = new ExpensesStatusMasterMongoDB();
|
||||||
public List<ExpensesStatusMasterMongoDB> NextStatus { get; set; } = new List<ExpensesStatusMasterMongoDB>();
|
public List<ExpensesStatusMasterMongoDB> NextStatus { get; set; } = new List<ExpensesStatusMasterMongoDB>();
|
||||||
public bool PreApproved { get; set; } = false;
|
public bool PreApproved { get; set; } = false;
|
||||||
|
@ -26,6 +26,7 @@ namespace Marco.Pms.Model.ViewModels.Expenses
|
|||||||
public string? TransactionId { get; set; }
|
public string? TransactionId { get; set; }
|
||||||
public string Description { get; set; } = string.Empty;
|
public string Description { get; set; } = string.Empty;
|
||||||
public string? Location { get; set; }
|
public string? Location { get; set; }
|
||||||
|
public string? ExpenseUId { get; set; }
|
||||||
public List<BasicDocumentVM> Documents { get; set; } = new List<BasicDocumentVM>();
|
public List<BasicDocumentVM> Documents { get; set; } = new List<BasicDocumentVM>();
|
||||||
public List<ExpenseLogVM> ExpenseLogs { get; set; } = new List<ExpenseLogVM>();
|
public List<ExpenseLogVM> ExpenseLogs { get; set; } = new List<ExpenseLogVM>();
|
||||||
public string? GSTNumber { get; set; }
|
public string? GSTNumber { get; set; }
|
||||||
|
@ -18,6 +18,7 @@ namespace Marco.Pms.Model.ViewModels.Expanses
|
|||||||
public DateTime TransactionDate { get; set; }
|
public DateTime TransactionDate { get; set; }
|
||||||
public DateTime CreatedAt { get; set; }
|
public DateTime CreatedAt { get; set; }
|
||||||
public string SupplerName { get; set; } = string.Empty;
|
public string SupplerName { get; set; } = string.Empty;
|
||||||
|
public string? ExpenseUId { get; set; }
|
||||||
public string Description { get; set; } = string.Empty;
|
public string Description { get; set; } = string.Empty;
|
||||||
public string TransactionId { get; set; } = string.Empty;
|
public string TransactionId { get; set; } = string.Empty;
|
||||||
public double Amount { get; set; }
|
public double Amount { get; set; }
|
||||||
|
@ -23,6 +23,7 @@ using MarcoBMS.Services.Service;
|
|||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using Document = Marco.Pms.Model.DocumentManager.Document;
|
using Document = Marco.Pms.Model.DocumentManager.Document;
|
||||||
|
|
||||||
namespace Marco.Pms.Services.Service
|
namespace Marco.Pms.Services.Service
|
||||||
@ -509,6 +510,15 @@ namespace Marco.Pms.Services.Service
|
|||||||
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||||
return await dbContext.PaymentModeMatser.AsNoTracking().FirstOrDefaultAsync(pm => pm.Id == dto.PaymentModeId);
|
return await dbContext.PaymentModeMatser.AsNoTracking().FirstOrDefaultAsync(pm => pm.Id == dto.PaymentModeId);
|
||||||
});
|
});
|
||||||
|
var expenseUIdTask = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||||
|
var result = await dbContext.Expenses
|
||||||
|
.Where(e => !string.IsNullOrWhiteSpace(e.ExpenseUId)).ToListAsync();
|
||||||
|
return result
|
||||||
|
.Select(e => ExtractNumber(e.ExpenseUId))
|
||||||
|
.OrderByDescending(id => id).FirstOrDefault();
|
||||||
|
});
|
||||||
var statusMappingTask = Task.Run(async () =>
|
var statusMappingTask = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||||
@ -528,10 +538,7 @@ namespace Marco.Pms.Services.Service
|
|||||||
|
|
||||||
|
|
||||||
// Await all prerequisite checks at once.
|
// Await all prerequisite checks at once.
|
||||||
await Task.WhenAll(
|
await Task.WhenAll(hasUploadPermissionTask, projectTask, expenseTypeTask, paymentModeTask, statusMappingTask, paidByTask, expenseUIdTask);
|
||||||
hasUploadPermissionTask,
|
|
||||||
projectTask, expenseTypeTask, paymentModeTask, statusMappingTask, paidByTask
|
|
||||||
);
|
|
||||||
|
|
||||||
// 2. Aggregate and Check Results
|
// 2. Aggregate and Check Results
|
||||||
if (!await hasUploadPermissionTask)
|
if (!await hasUploadPermissionTask)
|
||||||
@ -546,6 +553,7 @@ namespace Marco.Pms.Services.Service
|
|||||||
var paymentMode = await paymentModeTask;
|
var paymentMode = await paymentModeTask;
|
||||||
var statusMapping = await statusMappingTask;
|
var statusMapping = await statusMappingTask;
|
||||||
var paidBy = await paidByTask;
|
var paidBy = await paidByTask;
|
||||||
|
var lastExpenseUId = expenseUIdTask.Result;
|
||||||
|
|
||||||
if (project == null) validationErrors.Add("Project not found.");
|
if (project == null) validationErrors.Add("Project not found.");
|
||||||
if (paidBy == null) validationErrors.Add("Paid by employee not found");
|
if (paidBy == null) validationErrors.Add("Paid by employee not found");
|
||||||
@ -562,8 +570,11 @@ namespace Marco.Pms.Services.Service
|
|||||||
return ApiResponse<object>.ErrorResponse("Invalid input data.", errorMessage, 400);
|
return ApiResponse<object>.ErrorResponse("Invalid input data.", errorMessage, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var currentexpenseUId = lastExpenseUId + 1;
|
||||||
|
|
||||||
// 3. Entity Creation
|
// 3. Entity Creation
|
||||||
var expense = _mapper.Map<Expenses>(dto);
|
var expense = _mapper.Map<Expenses>(dto);
|
||||||
|
expense.ExpenseUId = $"EX_{currentexpenseUId}";
|
||||||
expense.CreatedById = loggedInEmployee.Id;
|
expense.CreatedById = loggedInEmployee.Id;
|
||||||
expense.CreatedAt = DateTime.UtcNow;
|
expense.CreatedAt = DateTime.UtcNow;
|
||||||
expense.TenantId = tenantId;
|
expense.TenantId = tenantId;
|
||||||
@ -1106,6 +1117,14 @@ namespace Marco.Pms.Services.Service
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region =================================================================== Helper Functions ===================================================================
|
#region =================================================================== Helper Functions ===================================================================
|
||||||
|
|
||||||
|
private int ExtractNumber(string id)
|
||||||
|
{
|
||||||
|
// Extract trailing number; handles EX_0001, EX-0001, EX0001
|
||||||
|
var m = Regex.Match(id ?? string.Empty, @"(\d+)$");
|
||||||
|
return m.Success ? int.Parse(m.Value) : int.MinValue; // put invalid IDs at the bottom
|
||||||
|
}
|
||||||
|
|
||||||
private static object ExceptionMapper(Exception ex)
|
private static object ExceptionMapper(Exception ex)
|
||||||
{
|
{
|
||||||
return new
|
return new
|
||||||
|
Loading…
x
Reference in New Issue
Block a user