Files
PowderCoatingLogix/src/PowderCoating.Application/Mappings/InvoiceProfile.cs
T
spouliot 9367e358d9 Add Project Name field to invoice create and edit forms
Stores ProjectName on the Invoice entity (previously only inherited from the
linked job at display time). Pre-fills from the job when creating from a job.
Migration: AddInvoiceProjectName.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-09 08:50:02 -04:00

89 lines
5.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using AutoMapper;
using PowderCoating.Application.DTOs.Invoice;
using PowderCoating.Core.Entities;
namespace PowderCoating.Application.Mappings;
public class InvoiceProfile : Profile
{
public InvoiceProfile()
{
CreateMap<Invoice, InvoiceListDto>()
.ForMember(d => d.JobNumber, o => o.MapFrom(s => s.Job != null ? s.Job.JobNumber : string.Empty))
.ForMember(d => d.CustomerName, o => o.MapFrom(s => s.Customer != null
? (s.Customer.IsCommercial
? s.Customer.CompanyName
: $"{s.Customer.ContactFirstName} {s.Customer.ContactLastName}".Trim())
: string.Empty))
.ForMember(d => d.BalanceDue, o => o.MapFrom(s => s.BalanceDue));
CreateMap<Invoice, InvoiceDto>()
.ForMember(d => d.JobNumber, o => o.MapFrom(s => s.Job != null ? s.Job.JobNumber : string.Empty))
.ForMember(d => d.ProjectName, o => o.MapFrom(s => s.ProjectName ?? (s.Job != null ? s.Job.ProjectName : null)))
.ForMember(d => d.CustomerName, o => o.MapFrom(s => s.Customer != null
? (s.Customer.IsCommercial
? s.Customer.CompanyName
: $"{s.Customer.ContactFirstName} {s.Customer.ContactLastName}".Trim())
: string.Empty))
.ForMember(d => d.CustomerEmail, o => o.MapFrom(s => s.Customer != null
? (s.Customer.BillingEmail ?? s.Customer.Email)
: null))
.ForMember(d => d.CustomerPhone, o => o.MapFrom(s => s.Customer != null ? s.Customer.Phone : null))
.ForMember(d => d.CustomerMobilePhone, o => o.MapFrom(s => s.Customer != null ? s.Customer.MobilePhone : null))
.ForMember(d => d.CustomerAddress, o => o.MapFrom(s => s.Customer != null ? s.Customer.Address : null))
.ForMember(d => d.CustomerCity, o => o.MapFrom(s => s.Customer != null ? s.Customer.City : null))
.ForMember(d => d.CustomerState, o => o.MapFrom(s => s.Customer != null ? s.Customer.State : null))
.ForMember(d => d.CustomerZipCode, o => o.MapFrom(s => s.Customer != null ? s.Customer.ZipCode : null))
.ForMember(d => d.CustomerNotifyByEmail, o => o.MapFrom(s => s.Customer == null || s.Customer.NotifyByEmail))
.ForMember(d => d.CustomerNotifyBySms, o => o.MapFrom(s => s.Customer != null && s.Customer.NotifyBySms))
.ForMember(d => d.PreparedByName, o => o.MapFrom(s => s.PreparedBy != null
? $"{s.PreparedBy.FirstName} {s.PreparedBy.LastName}".Trim()
: null))
.ForMember(d => d.BalanceDue, o => o.MapFrom(s => s.BalanceDue))
.ForMember(d => d.SalesTaxAccountName, o => o.MapFrom(s => s.SalesTaxAccount != null
? $"{s.SalesTaxAccount.AccountNumber} {s.SalesTaxAccount.Name}" : null))
// These three collections are built manually in BuildInvoiceDtoAsync — no AutoMapper element map exists.
// AutoMapper 12+ throws for non-empty collections with no registered element mapping, so Ignore here.
.ForMember(d => d.Refunds, o => o.Ignore())
.ForMember(d => d.CreditApplications, o => o.Ignore())
.ForMember(d => d.GiftCertificateRedemptions, o => o.Ignore());
CreateMap<InvoiceItem, InvoiceItemDto>()
.ForMember(d => d.RevenueAccountName, o => o.MapFrom(s => s.RevenueAccount != null
? $"{s.RevenueAccount.AccountNumber} {s.RevenueAccount.Name}" : null));
CreateMap<InvoiceItemDto, InvoiceItem>()
.ForMember(d => d.RevenueAccount, o => o.Ignore())
.ForMember(d => d.Invoice, o => o.Ignore())
.ForMember(d => d.SourceJobItem, o => o.Ignore());
CreateMap<CreateInvoiceDto, Invoice>()
.ForMember(d => d.InvoiceNumber, o => o.Ignore())
.ForMember(d => d.Status, o => o.Ignore())
.ForMember(d => d.SubTotal, o => o.Ignore())
.ForMember(d => d.TaxAmount, o => o.Ignore())
.ForMember(d => d.Total, o => o.Ignore())
.ForMember(d => d.AmountPaid, o => o.Ignore());
CreateMap<CreateInvoiceItemDto, InvoiceItem>()
.ForMember(d => d.CompanyId, o => o.Ignore())
.ForMember(d => d.RevenueAccount, o => o.Ignore())
.ForMember(d => d.Invoice, o => o.Ignore())
.ForMember(d => d.SourceJobItem, o => o.Ignore());
CreateMap<Payment, PaymentDtos.PaymentDto>()
.ForMember(d => d.RecordedByName, o => o.MapFrom(s => s.RecordedBy != null
? $"{s.RecordedBy.FirstName} {s.RecordedBy.LastName}".Trim()
: null))
.ForMember(d => d.DepositAccountName, o => o.MapFrom(s => s.DepositAccount != null
? $"{s.DepositAccount.AccountNumber} {s.DepositAccount.Name}" : null));
CreateMap<PaymentDtos.RecordPaymentDto, Payment>()
.ForMember(d => d.RecordedById, o => o.Ignore())
.ForMember(d => d.CompanyId, o => o.Ignore())
.ForMember(d => d.DepositAccount, o => o.Ignore())
.ForMember(d => d.Invoice, o => o.Ignore())
.ForMember(d => d.RecordedBy, o => o.Ignore());
}
}