Skip to content

Commit

Permalink
Ajout de la prise en charge de l'adresse de facturation sur les legals
Browse files Browse the repository at this point in the history
  • Loading branch information
noelmugnier committed Oct 12, 2021
1 parent 73c99d0 commit 0dc6d3f
Show file tree
Hide file tree
Showing 21 changed files with 6,084 additions and 45 deletions.
7 changes: 7 additions & 0 deletions Sheaft.Application/Models/BillingAddressDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Sheaft.Application.Models
{
public class BillingAddressDto : AddressDto
{
public string Name { get; set; }
}
}
1 change: 1 addition & 0 deletions Sheaft.Application/Models/BusinessLegalInputDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class BusinessLegalInputDto
public string Siret { get; set; }
public string VatIdentifier { get; set; }
public AddressDto Address { get; set; }
public BillingAddressDto Billing { get; set; }
public OwnerInputDto Owner { get; set; }
}
}
19 changes: 19 additions & 0 deletions Sheaft.Domain/BillingAddress.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Sheaft.Domain.Enum;

namespace Sheaft.Domain
{
public class BillingAddress : Address
{
protected BillingAddress()
{
}

public BillingAddress(string line1, string line2, string zipcode, string city, CountryIsoCode country, string name) :
base(line1, line2, zipcode, city, country)
{
Name = name;
}

public string Name { get; set; }
}
}
4 changes: 2 additions & 2 deletions Sheaft.Domain/Business.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ public void RemoveClosing(Guid id)
ClosingsCount = Closings?.Count ?? 0;
}

public BusinessLegal SetLegals(LegalKind kind, string name, string email, string siret, string vatIdentifier, LegalAddress address, Owner owner, string registrationCity = null, string registrationCode = null, RegistrationKind? registrationKind = null)
public BusinessLegal SetLegals(LegalKind kind, string name, string email, string siret, string vatIdentifier, LegalAddress address, BillingAddress billingAddress, Owner owner, string registrationCity = null, string registrationCode = null, RegistrationKind? registrationKind = null)
{
if (Legal?.Id != null)
throw SheaftException.AlreadyExists("Les informations légales de cette société existent déjà.");

var legals = new BusinessLegal(Guid.NewGuid(),this, kind, name, email, siret, vatIdentifier, address, owner);
var legals = new BusinessLegal(Guid.NewGuid(),this, kind, name, email, siret, vatIdentifier, address, owner, billingAddress);
if(registrationKind.HasValue)
legals.SetRegistrationKind(registrationKind.Value, registrationCity, registrationCode);

Expand Down
9 changes: 8 additions & 1 deletion Sheaft.Domain/BusinessLegal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ protected BusinessLegal()
{
}

public BusinessLegal(Guid id, Business business, LegalKind kind, string name, string email, string siret, string vatIdentifier, LegalAddress address, Owner owner)
public BusinessLegal(Guid id, Business business, LegalKind kind, string name, string email, string siret, string vatIdentifier, LegalAddress address, Owner owner, BillingAddress billingAddress)
: base(id, kind, business, owner)
{
SetName(name);
SetEmail(email);
SetAddress(address);
SetBillingAddress(billingAddress);
SetSiret(siret);
SetVatIdentifier(vatIdentifier);
}
Expand All @@ -28,6 +29,7 @@ public BusinessLegal(Guid id, Business business, LegalKind kind, string name, st
public string VatIdentifier { get; private set; }
public Guid? DeclarationId { get; private set; }
public LegalAddress Address { get; private set; }
public BillingAddress BillingAddress { get; private set; }
public virtual Declaration Declaration { get; private set; }

public void SetDeclaration()
Expand Down Expand Up @@ -65,6 +67,11 @@ public void SetAddress(LegalAddress legalAddress)
Address = legalAddress;
}

public void SetBillingAddress(BillingAddress billingAddress)
{
BillingAddress = billingAddress;
}

public void SetEmail(string email)
{
if (string.IsNullOrWhiteSpace(email))
Expand Down
11 changes: 2 additions & 9 deletions Sheaft.Domain/UserAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,11 @@ public static string GetDepartmentCode(string code)
if (corsicaRegex.Match(code).Success)
{
var departmentCode = int.Parse(code);
if (departmentCode < 20200)
return "2A";

if (departmentCode >= 20200)
return "2B";
return departmentCode < 20200 ? "2A" : "2B";
}

var regex = new Regex("(^([2[A-B]{2})|^([0-9]{2}))([0-9]{0,3})");
if (regex.Match(code).Success)
return code.Substring(0, 2);

return null;
return regex.Match(code).Success ? code.Substring(0, 2) : null;
}
}
}
43 changes: 43 additions & 0 deletions Sheaft.GraphQL/Types/Inputs/BillingAddressInputType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using HotChocolate.Types;
using Sheaft.Application.Models;

namespace Sheaft.GraphQL.Types.Inputs
{
public class BillingAddressInputType : SheaftInputType<BillingAddressDto>
{
protected override void Configure(IInputObjectTypeDescriptor<BillingAddressDto> descriptor)
{
base.Configure(descriptor);

descriptor.Name("BillingAddressInput");

descriptor
.Field(c => c.Name)
.Name("name")
.Type<NonNullType<StringType>>();

descriptor
.Field(c => c.Line1)
.Name("line1")
.Type<NonNullType<StringType>>();

descriptor
.Field(c => c.Line2)
.Name("line2");

descriptor
.Field(c => c.Zipcode)
.Name("zipcode")
.Type<NonNullType<StringType>>();

descriptor
.Field(c => c.City)
.Name("city")
.Type<NonNullType<StringType>>();

descriptor
.Field(c => c.Country)
.Name("country");
}
}
}
5 changes: 5 additions & 0 deletions Sheaft.GraphQL/Types/Inputs/BusinessLegalInputType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ protected override void Configure(IInputObjectTypeDescriptor<BusinessLegalInputD
.Field(c => c.Address)
.Name("address")
.Type<NonNullType<AddressInputType>>();

descriptor
.Field(c => c.Billing)
.Name("billing")
.Type<BillingAddressInputType>();
}
}
}
39 changes: 39 additions & 0 deletions Sheaft.GraphQL/Types/Outputs/BillingAddressDtoType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using HotChocolate.Types;
using Sheaft.Application.Models;

namespace Sheaft.GraphQL.Types.Outputs
{
public class BillingAddressDtoType : SheaftOutputType<BillingAddressDto>
{
protected override void Configure(IObjectTypeDescriptor<BillingAddressDto> descriptor)
{
base.Configure(descriptor);

descriptor.Name("BillingAddress");

descriptor
.Field(c => c.Name)
.Name("name");

descriptor
.Field(c => c.Line1)
.Name("line1");

descriptor
.Field(c => c.Line2)
.Name("line2");

descriptor
.Field(c => c.Zipcode)
.Name("zipcode");

descriptor
.Field(c => c.City)
.Name("city");

descriptor
.Field(c => c.Country)
.Name("country");
}
}
}
37 changes: 37 additions & 0 deletions Sheaft.GraphQL/Types/Outputs/BillingAddressType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using HotChocolate.Types;
using Sheaft.Domain;

namespace Sheaft.GraphQL.Types.Outputs
{
public class BillingAddressType : SheaftOutputType<BillingAddress>
{
protected override void Configure(IObjectTypeDescriptor<BillingAddress> descriptor)
{
base.Configure(descriptor);

descriptor
.Field(c => c.Name)
.Name("name");

descriptor
.Field(c => c.Line1)
.Name("line1");

descriptor
.Field(c => c.Line2)
.Name("line2");

descriptor
.Field(c => c.Zipcode)
.Name("zipcode");

descriptor
.Field(c => c.City)
.Name("city");

descriptor
.Field(c => c.Country)
.Name("country");
}
}
}
4 changes: 4 additions & 0 deletions Sheaft.GraphQL/Types/Outputs/BusinessLegalType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ protected override void Configure(IObjectTypeDescriptor<BusinessLegal> descripto
.Field(c => c.Address)
.Name("address");

descriptor
.Field(c => c.BillingAddress)
.Name("billing");

descriptor
.Field(c => c.Owner)
.Name("owner");
Expand Down
2 changes: 1 addition & 1 deletion Sheaft.GraphQL/Types/Outputs/ConsumerProfileType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected override void Configure(IObjectTypeDescriptor<Consumer> descriptor)
.Name("legals")
.UseDbContext<QueryDbContext>()
.ResolveWith<ConsumerProfileResolvers>(c => c.GetLegals(default!, default!, default!, default))
.Type<ListType<ConsumerLegalType>>();
.Type<ConsumerLegalType>();
}

private class ConsumerProfileResolvers
Expand Down
2 changes: 1 addition & 1 deletion Sheaft.GraphQL/Types/Outputs/ProducerProfileType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected override void Configure(IObjectTypeDescriptor<Producer> descriptor)
.Name("legals")
.UseDbContext<QueryDbContext>()
.ResolveWith<ProducerProfileResolvers>(c => c.GetLegals(default!, default!, default!, default))
.Type<ListType<BusinessLegalType>>();
.Type<BusinessLegalType>();

descriptor
.Field(c => c.Closings)
Expand Down
2 changes: 1 addition & 1 deletion Sheaft.GraphQL/Types/Outputs/StoreProfileType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected override void Configure(IObjectTypeDescriptor<Store> descriptor)
.Name("legals")
.UseDbContext<QueryDbContext>()
.ResolveWith<StoreProfileResolvers>(c => c.GetLegals(default!, default!, default!, default))
.Type<ListType<BusinessLegalType>>();
.Type<BusinessLegalType>();
}

private class StoreProfileResolvers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public void Configure(EntityTypeBuilder<BusinessLegal> entity)
entity.Property(c => c.VatIdentifier);

entity.OwnsOne(c => c.Address);
entity.OwnsOne(c => c.BillingAddress);

entity.HasOne(c => c.Declaration).WithOne().HasForeignKey<BusinessLegal>(c => c.DeclarationId)
.OnDelete(DeleteBehavior.Cascade);
}
Expand Down
Loading

0 comments on commit 0dc6d3f

Please sign in to comment.