106 lines
4.4 KiB
C#
106 lines
4.4 KiB
C#
|
|
using Domain.Dtos.Sales;
|
||
|
|
using Domain.Entities;
|
||
|
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
using Models.Helpers;
|
||
|
|
using Models.Interfaces;
|
||
|
|
using Models.Models;
|
||
|
|
|
||
|
|
namespace Models.Repositories
|
||
|
|
{
|
||
|
|
public class PhSSalesDocumentRepository(PhronCareOperationsHubContext context) : IPhSSalesDocumentRepository
|
||
|
|
{
|
||
|
|
private readonly PhronCareOperationsHubContext _context = context;
|
||
|
|
|
||
|
|
public async Task<ESalesDocument> CreateAsync(ESalesDocument entity)
|
||
|
|
{
|
||
|
|
var mapped = EntityMapper.MapEntity<ESalesDocument, PhSSalesDocument>(entity);
|
||
|
|
|
||
|
|
await _context.PhSSalesDocuments.AddAsync(mapped);
|
||
|
|
await _context.SaveChangesAsync();
|
||
|
|
|
||
|
|
return EntityMapper.MapEntity<PhSSalesDocument, ESalesDocument>(mapped);
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task<SalesDocumentDto?> GetDtoByIdAsync(int id)
|
||
|
|
{
|
||
|
|
var entity = await _context.PhSSalesDocuments
|
||
|
|
.Include(x => x.Customer)
|
||
|
|
.Include(x => x.BillToCustomer)
|
||
|
|
.Include(x => x.PhSSalesDocumentDetails)
|
||
|
|
.Include(x => x.PhSSalesDocumentCoverages)
|
||
|
|
.AsNoTracking()
|
||
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
||
|
|
|
||
|
|
if (entity == null)
|
||
|
|
return null;
|
||
|
|
|
||
|
|
return new SalesDocumentDto
|
||
|
|
{
|
||
|
|
Id = entity.Id,
|
||
|
|
FormseriesId = entity.FormseriesId,
|
||
|
|
InternalSequenceNumber = entity.InternalSequenceNumber,
|
||
|
|
InternalDocumentNumber = entity.InternalDocumentNumber,
|
||
|
|
DocumentType = entity.DocumentType,
|
||
|
|
FiscalVoucherType = entity.FiscalVoucherType,
|
||
|
|
FiscalVoucherLetter = entity.FiscalVoucherLetter,
|
||
|
|
Status = entity.Status,
|
||
|
|
QuoteId = entity.QuoteId,
|
||
|
|
CustomerId = entity.CustomerId,
|
||
|
|
CustomerName = entity.Customer?.Name ?? string.Empty,
|
||
|
|
BillToCustomerId = entity.BillToCustomerId,
|
||
|
|
BillToCustomerName = entity.BillToCustomer?.Name ?? string.Empty,
|
||
|
|
IssueDate = entity.IssueDate,
|
||
|
|
Currency = entity.Currency,
|
||
|
|
ExchangeRate = entity.ExchangeRate,
|
||
|
|
NetAmount = entity.NetAmount,
|
||
|
|
TaxAmount = entity.TaxAmount,
|
||
|
|
TotalAmount = entity.TotalAmount,
|
||
|
|
Observations = entity.Observations,
|
||
|
|
ExtraInfoJson = entity.ExtraInfoJson,
|
||
|
|
PeriodFrom = entity.PeriodFrom,
|
||
|
|
PeriodTo = entity.PeriodTo,
|
||
|
|
Createdat = entity.Createdat,
|
||
|
|
Modifiedat = entity.Modifiedat,
|
||
|
|
Details = entity.PhSSalesDocumentDetails.Select(x => new SalesDocumentDetailDto
|
||
|
|
{
|
||
|
|
Id = x.Id,
|
||
|
|
SalesDocumentId = x.SalesdocumentId,
|
||
|
|
LineNumber = x.LineNumber,
|
||
|
|
OriginType = x.OriginType,
|
||
|
|
OriginId = x.OriginId,
|
||
|
|
QuoteDetailId = x.QuoteDetailId,
|
||
|
|
ProductId = x.ProductId,
|
||
|
|
Description = x.Description,
|
||
|
|
Quantity = x.Quantity,
|
||
|
|
AuthorizedUnitPrice = x.AuthorizedUnitPrice,
|
||
|
|
AuthorizedAmount = x.AuthorizedAmount,
|
||
|
|
BilledPercentage = x.BilledPercentage,
|
||
|
|
UnitPrice = x.UnitPrice,
|
||
|
|
NetAmount = x.NetAmount,
|
||
|
|
TaxAmount = x.TaxAmount,
|
||
|
|
TotalAmount = x.TotalAmount,
|
||
|
|
OriginSnapshotJson = x.OriginSnapshotJson,
|
||
|
|
Createdat = x.Createdat,
|
||
|
|
Modifiedat = x.Modifiedat
|
||
|
|
}).ToList(),
|
||
|
|
Coverage = entity.PhSSalesDocumentCoverages.Select(x => new SalesDocumentCoverageDto
|
||
|
|
{
|
||
|
|
Id = x.Id,
|
||
|
|
SalesDocumentId = x.SalesdocumentId,
|
||
|
|
SalesDocumentDetailId = x.SalesdocumentdetailId,
|
||
|
|
QuoteId = x.QuoteId,
|
||
|
|
QuoteDetailId = x.QuoteDetailId,
|
||
|
|
CoverageType = x.CoverageType,
|
||
|
|
CoveragePercentage = x.CoveragePercentage,
|
||
|
|
CoverageAmount = x.CoverageAmount,
|
||
|
|
PeriodFrom = x.PeriodFrom,
|
||
|
|
PeriodTo = x.PeriodTo,
|
||
|
|
Notes = x.Notes,
|
||
|
|
Createdat = x.Createdat,
|
||
|
|
Modifiedat = x.Modifiedat
|
||
|
|
}).ToList()
|
||
|
|
};
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|