Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion JobFlow.Business/Services/InvoiceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class InvoiceService : IInvoiceService
private readonly IInvoiceRealtimeNotifier? _realtimeNotifier;
private readonly IOrganizationService _organizationService;
private readonly IUnitOfWork unitOfWork;
private readonly IQuickBooksSyncService? _qbSync;

public InvoiceService(
ILogger<InvoiceService> logger,
Expand All @@ -35,7 +36,8 @@ public InvoiceService(
IInvoiceNumberGenerator numberGenerator,
INotificationService notifications,
IOrganizationClientPortalService clientPortal,
IInvoiceRealtimeNotifier? realtimeNotifier = null)
IInvoiceRealtimeNotifier? realtimeNotifier = null,
IQuickBooksSyncService? qbSync = null)
{
this.logger = logger;
this.unitOfWork = unitOfWork;
Expand All @@ -48,6 +50,7 @@ public InvoiceService(
_notifications = notifications;
_clientPortal = clientPortal;
_realtimeNotifier = realtimeNotifier;
_qbSync = qbSync;
}

public async Task<Result<Invoice>> GetInvoiceByIdAsync(Guid id)
Expand Down Expand Up @@ -256,6 +259,9 @@ await _onboardingService.MarkStepCompleteAsync(
OnboardingStepKeys.CreateInvoice
);

if (_qbSync != null)
await _qbSync.SyncInvoiceAsync(model.OrganizationId, model);

return Result<Invoice>.Success(model);
}

Expand Down Expand Up @@ -315,6 +321,9 @@ public async Task<Result<Invoice>> UpdateInvoiceAsync(Guid id, Guid organization

await unitOfWork.SaveChangesAsync();

if (_qbSync != null)
await _qbSync.SyncInvoiceAsync(invoice.OrganizationId, invoice);

return Result<Invoice>.Success(invoice);
}

Expand Down Expand Up @@ -416,6 +425,9 @@ public async Task<Result<Invoice>> MarkPaidAsync(
await _realtimeNotifier.NotifyInvoicePaidAsync(invoice);
}

if (_qbSync != null)
await _qbSync.SyncPaymentAsync(invoice.OrganizationId, invoice);

return Result.Success(invoice);
}

Expand Down
9 changes: 8 additions & 1 deletion JobFlow.Business/Services/OrganizationClientService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@ public class OrganizationClientService : IOrganizationClientService
private readonly IOrganizationClientPortalService _clientPortal;
private readonly IUnitOfWork unitOfWork;
private readonly IMapper _mapper;
private readonly IQuickBooksSyncService? _qbSync;

public OrganizationClientService(
ILogger<OrganizationClientService> logger,
IUnitOfWork unitOfWork,
IOnboardingService onboardingService,
IOrganizationClientPortalService clientPortal,
IMapper mapper)
IMapper mapper,
IQuickBooksSyncService? qbSync = null)
{
this.logger = logger;
this.unitOfWork = unitOfWork;
this.onboardingService = onboardingService;
_clientPortal = clientPortal;
organizationClient = this.unitOfWork.RepositoryOf<OrganizationClient>();
_mapper = mapper;
_qbSync = qbSync;
}

public async Task<Result> DeleteClient(Guid clientId)
Expand Down Expand Up @@ -241,6 +244,10 @@ await onboardingService.MarkStepCompleteAsync(
}
}
}

if (_qbSync != null)
await _qbSync.SyncClientAsync(model.OrganizationId, model);

return Result.Success(model);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using JobFlow.Domain.Models;

namespace JobFlow.Business.Services.ServiceInterfaces;

public interface IQuickBooksSyncService
{
Task SyncClientAsync(Guid organizationId, OrganizationClient client);
Task SyncInvoiceAsync(Guid organizationId, Invoice invoice);
Task SyncPaymentAsync(Guid organizationId, Invoice invoice);
}
1 change: 1 addition & 0 deletions JobFlow.Domain/Models/Invoice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Invoice : Entity
public PaymentProvider PaymentProvider { get; set; }
public string? ExternalPaymentId { get; set; }
public DateTimeOffset? PaidAt { get; set; }
public string? QuickBooksInvoiceId { get; set; }
public virtual OrganizationClient OrganizationClient { get; set; } = null!;
public virtual Job? Job { get; set; }
public virtual Order Order { get; set; } = null!;
Expand Down
2 changes: 2 additions & 0 deletions JobFlow.Domain/Models/OrganizationClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class OrganizationClient : Entity

public ICollection<CustomerPaymentProfile> PaymentProfiles { get; set; } = new List<CustomerPaymentProfile>();

public string? QuickBooksCustomerId { get; set; }

public string ClientFullName()
{
return $"{FirstName} {LastName}";
Expand Down
Loading
Loading