Skip to content

Commit

Permalink
Update for Issue allors#46
Browse files Browse the repository at this point in the history
- Implements SalesOrder Transfer feature (WIP)
  • Loading branch information
jubayerarefin committed Jul 21, 2020
1 parent d8ebe8d commit e7f660f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 151 deletions.
155 changes: 5 additions & 150 deletions Base/Database/Domain/Base/Order/SalesOrderTransfer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@

namespace Allors.Domain
{
using System;
using System.Collections.Generic;
using System.Linq;
using Allors.Meta;
using Allors.Services;
using Microsoft.Extensions.DependencyInjection;
using Resources;

public partial class SalesOrderTransfer
{
Expand Down Expand Up @@ -43,155 +37,16 @@ public void BaseOnDerive(ObjectOnDerive method)
if (this.ExistFrom && this.ExistInternalOrganisation && !this.ExistTo)
{
var acl = new AccessControlLists(session.GetUser())[this.From];
if (acl.CanExecute(M.SalesOrder.DoTransfer))
if (!acl.CanExecute(M.SalesOrder.DoTransfer))
{
this.To = this.Transfer();
this.From.SalesOrderState = new SalesOrderStates(session).Transferred;
derivation.Validation.AddError(this, this.Meta.To, "No rights to transfer salesorder");
}
}
}

private SalesOrder Transfer()
{
var salesOrder = new SalesOrderBuilder(this.Strategy.Session)
.WithTakenBy(this.InternalOrganisation)
.WithShipToCustomer(this.From.ShipToCustomer)
.WithShipToAddress(this.From.ShipToAddress)
.WithShipToContactPerson(this.ShipToContactPerson)
.WithShipToEndCustomer(this.ShipToEndCustomer)
.WithShipToEndCustomerAddress(this.ShipToEndCustomerAddress)
.WithShipToEndCustomerContactPerson(this.ShipToEndCustomerContactPerson)
.WithDescription(this.Description)
.WithStore(this.Store)
.WithInvoiceDate(this.Session().Now())
.WithSalesChannel(this.SalesChannel)
.WithSalesInvoiceType(new SalesInvoiceTypes(this.Strategy.Session).SalesInvoice)
.WithVatRegime(this.VatRegime)
.WithIrpfRegime(this.IrpfRegime)
.WithCustomerReference(this.CustomerReference)
.WithPaymentMethod(this.PaymentMethod)
.WithComment(this.Comment)
.WithInternalComment(this.InternalComment)
.WithMessage(this.Message)
.WithBillingAccount(this.BillingAccount)
.Build();

foreach (OrderAdjustment orderAdjustment in this.OrderAdjustments)
{
OrderAdjustment newAdjustment = null;
if (orderAdjustment.GetType().Name.Equals(typeof(DiscountAdjustment).Name))
{
newAdjustment = new DiscountAdjustmentBuilder(this.Session()).Build();
}

if (orderAdjustment.GetType().Name.Equals(typeof(SurchargeAdjustment).Name))
{
newAdjustment = new SurchargeAdjustmentBuilder(this.Session()).Build();
}

if (orderAdjustment.GetType().Name.Equals(typeof(Fee).Name))
{
newAdjustment = new FeeBuilder(this.Session()).Build();
}

if (orderAdjustment.GetType().Name.Equals(typeof(ShippingAndHandlingCharge).Name))
{
newAdjustment = new ShippingAndHandlingChargeBuilder(this.Session()).Build();
}

if (orderAdjustment.GetType().Name.Equals(typeof(MiscellaneousCharge).Name))
{
newAdjustment = new MiscellaneousChargeBuilder(this.Session()).Build();
}

newAdjustment.Amount ??= orderAdjustment.Amount;
newAdjustment.Percentage ??= orderAdjustment.Percentage;
salesInvoice.AddOrderAdjustment(newAdjustment);
}

foreach (SalesInvoiceItem salesInvoiceItem in this.SalesInvoiceItems)
{
var invoiceItem = new SalesInvoiceItemBuilder(this.Strategy.Session)
.WithInvoiceItemType(salesInvoiceItem.InvoiceItemType)
.WithAssignedUnitPrice(salesInvoiceItem.AssignedUnitPrice)
.WithAssignedVatRegime(salesInvoiceItem.AssignedVatRegime)
.WithAssignedIrpfRegime(salesInvoiceItem.AssignedIrpfRegime)
.WithProduct(salesInvoiceItem.Product)
.WithQuantity(salesInvoiceItem.Quantity)
.WithDescription(salesInvoiceItem.Description)
.WithSerialisedItem(salesInvoiceItem.SerialisedItem)
.WithNextSerialisedItemAvailability(salesInvoiceItem.NextSerialisedItemAvailability)
.WithComment(salesInvoiceItem.Comment)
.WithInternalComment(salesInvoiceItem.InternalComment)
.WithMessage(salesInvoiceItem.Message)
.WithFacility(salesInvoiceItem.Facility)
.Build();

invoiceItem.ProductFeatures = salesInvoiceItem.ProductFeatures;
salesInvoice.AddSalesInvoiceItem(invoiceItem);

foreach (SalesTerm salesTerm in salesInvoiceItem.SalesTerms)
{
if (salesTerm.GetType().Name == typeof(IncoTerm).Name)
{
salesInvoiceItem.AddSalesTerm(new IncoTermBuilder(this.Strategy.Session)
.WithTermType(salesTerm.TermType)
.WithTermValue(salesTerm.TermValue)
.WithDescription(salesTerm.Description)
.Build());
}

if (salesTerm.GetType().Name == typeof(InvoiceTerm).Name)
{
salesInvoiceItem.AddSalesTerm(new InvoiceTermBuilder(this.Strategy.Session)
.WithTermType(salesTerm.TermType)
.WithTermValue(salesTerm.TermValue)
.WithDescription(salesTerm.Description)
.Build());
}

if (salesTerm.GetType().Name == typeof(OrderTerm).Name)
{
salesInvoiceItem.AddSalesTerm(new OrderTermBuilder(this.Strategy.Session)
.WithTermType(salesTerm.TermType)
.WithTermValue(salesTerm.TermValue)
.WithDescription(salesTerm.Description)
.Build());
}
}
}

foreach (SalesTerm salesTerm in this.SalesTerms)
{
if (salesTerm.GetType().Name == typeof(IncoTerm).Name)
{
salesInvoice.AddSalesTerm(new IncoTermBuilder(this.Strategy.Session)
.WithTermType(salesTerm.TermType)
.WithTermValue(salesTerm.TermValue)
.WithDescription(salesTerm.Description)
.Build());
}

if (salesTerm.GetType().Name == typeof(InvoiceTerm).Name)
else
{
salesInvoice.AddSalesTerm(new InvoiceTermBuilder(this.Strategy.Session)
.WithTermType(salesTerm.TermType)
.WithTermValue(salesTerm.TermValue)
.WithDescription(salesTerm.Description)
.Build());
}

if (salesTerm.GetType().Name == typeof(OrderTerm).Name)
{
salesInvoice.AddSalesTerm(new OrderTermBuilder(this.Strategy.Session)
.WithTermType(salesTerm.TermType)
.WithTermValue(salesTerm.TermValue)
.WithDescription(salesTerm.Description)
.Build());
this.To = this.From.Clone(this.From.Meta.SalesOrderItems);
this.From.SalesOrderState = new SalesOrderStates(this.strategy.Session).Transferred;
}
}

return salesOrder;
}
}
}
40 changes: 39 additions & 1 deletion Core/Database/Domain/Core/ObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Allors
{
using System;

using System.Linq;
using Allors.Domain;
using Allors.Meta;

Expand Down Expand Up @@ -52,5 +52,43 @@ public static void CoreOnPostBuild(this Domain.Object @this, ObjectOnPostBuild m
}
}
}


public static T Clone<T>(this T @this, params IRoleType[] deepClone) where T: IObject
{
var strategy = @this.Strategy;
var session = strategy.Session;
var @class = strategy.Class;

var clone = (T)session.Create(@class);
foreach (var roleType in @class.RoleTypes.Where(v => !(v.RelationType.IsDerived || v.RelationType.IsSynced) && !deepClone.Contains(v) && (v.ObjectType.IsUnit || v.AssociationType.IsMany)))
{
var relationType = roleType.RelationType;
var role = @this.Strategy.GetRole(relationType);
clone.Strategy.SetRole(relationType, role);
}

foreach(var roleType in deepClone)
{
var relationType = roleType.RelationType;
if (roleType.IsOne)
{
var role = strategy.GetCompositeRole(relationType);
if (role != null)
{
clone.Strategy.SetCompositeRole(relationType, role.Clone());
}
}
else
{
foreach(IObject role in strategy.GetCompositeRoles(relationType))
{
clone.Strategy.AddCompositeRole(relationType, role.Clone());
}
}
}

return clone;
}
}
}

0 comments on commit e7f660f

Please sign in to comment.