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 20, 2020
1 parent 091d47e commit d8ebe8d
Show file tree
Hide file tree
Showing 13 changed files with 3,685 additions and 1 deletion.
1 change: 1 addition & 0 deletions Base/Database/Domain.Tests/Order/SalesOrderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2752,6 +2752,7 @@ public void GivenSalesOrder_WhenObjectStateIsProvisional_ThenCheckTransitions()
Assert.True(acl.CanExecute(M.SalesOrder.Hold));
Assert.False(acl.CanExecute(M.SalesOrder.Continue));
Assert.False(acl.CanExecute(M.SalesOrder.Accept));
Assert.True(acl.CanExecute(M.SalesOrder.DoTransfer));
}

[Fact]
Expand Down
3,028 changes: 3,028 additions & 0 deletions Base/Database/Domain.Tests/Order/SalesOrderTransferTests.cs

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions Base/Database/Domain.Tests/Security/EmployeeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,37 @@ public void SalesInvoice()
Assert.False(acl.CanWrite(M.SalesInvoice.Description));
}

[Fact]
public void SalesOrder()
{
var customer = new PersonBuilder(this.Session).WithFirstName("Koen").WithUserName("customer").Build();

new CustomerRelationshipBuilder(this.Session).WithFromDate(this.Session.Now()).WithCustomer(customer).WithInternalOrganisation(this.InternalOrganisation).Build();

var mechelen = new CityBuilder(this.Session).WithName("Mechelen").Build();

this.Session.Derive();

var employee = new Employments(this.Session).Extent().Select(v => v.Employee).First();
this.Session.SetUser(employee);

var order = new SalesOrderBuilder(this.Session)
.WithTakenBy(this.InternalOrganisation)
.WithBillToCustomer(customer)
.WithShipToCustomer(customer)
.WithShipToAddress(new PostalAddressBuilder(this.Session).WithPostalAddressBoundary(mechelen).WithAddress1("Haverwerf 15").Build())
.Build();

this.Session.Derive();

Assert.Equal(new SalesOrderStates(this.Session).Provisional, order.SalesOrderState);

var acl = new AccessControlLists(employee)[order];
Assert.False(acl.CanExecute(M.SalesOrder.DoTransfer));
Assert.False(acl.CanWrite(M.SalesOrder.Description));
Assert.True(acl.CanRead(M.SalesOrder.Description));
}

[Fact]
public void UserGroup()
{
Expand Down
1 change: 0 additions & 1 deletion Base/Database/Domain/Base/Order/SalesOrder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,6 @@ public void BaseSetReadyForPosting(SalesOrderSetReadyForPosting method)
public void BaseContinue(OrderContinue method) => this.SalesOrderState = this.PreviousSalesOrderState;

public void BaseComplete(OrderComplete method) => this.SalesOrderState = new SalesOrderStates(this.Strategy.Session).Completed;

public void BaseShip(SalesOrderShip method)
{
if (this.CanShip)
Expand Down
4 changes: 4 additions & 0 deletions Base/Database/Domain/Base/Order/SalesOrderStates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public partial class SalesOrderStates
internal static readonly Guid OnHoldId = new Guid("f625fb7e-893e-4f68-ab7b-2bc29a644e5b");
internal static readonly Guid CompletedId = new Guid("81F80082-040C-405a-8C01-778868D57C75");
internal static readonly Guid FinishedId = new Guid("DFE75006-81FD-424a-AF58-2528A657155D");
internal static readonly Guid TransferredId = new Guid("37bda4c2-dcc3-4f50-8a67-22da1142c1c8");
internal static readonly Guid CancelledId = new Guid("8AE3813D-7866-4e1c-AB70-EE695154F8F7");
internal static readonly Guid RejectedId = new Guid("AE2AB1DC-0E5E-4061-924C-025AB84769C0");

Expand All @@ -36,6 +37,8 @@ public partial class SalesOrderStates

public SalesOrderState Finished => this.Cache[FinishedId];

public SalesOrderState Transferred => this.Cache[TransferredId];

public SalesOrderState OnHold => this.Cache[OnHoldId];

public SalesOrderState AwaitingAcceptance => this.Cache[AwaitingAcceptanceId];
Expand All @@ -58,6 +61,7 @@ protected override void BaseSetup(Setup setup)
merge(AwaitingAcceptanceId, v => v.Name = "Awaiting customer acceptance");
merge(InProcessId, v => v.Name = "In Process");
merge(FinishedId, v => v.Name = "Finished");
merge(TransferredId, v => v.Name = "Transferred");
}
}
}
153 changes: 153 additions & 0 deletions Base/Database/Domain/Base/Order/SalesOrderTransfer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,159 @@ public void BaseOnDerive(ObjectOnDerive method)
{
var derivation = method.Derivation;
var session = this.Session();

if (this.ExistFrom && this.ExistInternalOrganisation && !this.ExistTo)
{
var acl = new AccessControlLists(session.GetUser())[this.From];
if (acl.CanExecute(M.SalesOrder.DoTransfer))
{
this.To = this.Transfer();
this.From.SalesOrderState = new SalesOrderStates(session).Transferred;
}
}
}

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)
{
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());
}
}

return salesOrder;
}
}
}
2 changes: 2 additions & 0 deletions Base/Database/Domain/Base/Order/SalesOrders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ protected override void BaseSecure(Security config)
var rejected = new SalesOrderStates(this.Session).Rejected;
var completed = new SalesOrderStates(this.Session).Completed;
var finished = new SalesOrderStates(this.Session).Finished;
var tranferred = new SalesOrderStates(this.Session).Transferred;

var setReadyForPosting = this.Meta.SetReadyForPosting;
var post = this.Meta.Post;
Expand All @@ -47,6 +48,7 @@ protected override void BaseSecure(Security config)
config.Deny(this.ObjectType, onHold, setReadyForPosting, reject, approve, hold, ship, invoice, post, accept, revise, transfer);
config.Deny(this.ObjectType, rejected, reject, ship, invoice, post, accept, hold, @continue, revise, approve, setReadyForPosting, cancel, transfer);
config.Deny(this.ObjectType, cancelled, cancel, ship, invoice, post, accept, hold, @continue, revise, approve, setReadyForPosting, reject, transfer);
config.Deny(this.ObjectType, tranferred, cancel, ship, invoice, post, accept, hold, @continue, revise, approve, setReadyForPosting, reject, transfer);
config.Deny(this.ObjectType, completed, complete, reject, cancel, approve, hold, @continue, setReadyForPosting, invoice, post, accept, reopen, revise, transfer);

config.Deny(this.ObjectType, awaitingAcceptance, Operations.Write);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<form *ngIf="object" #form="ngForm" (submit)="save()" novalidate>

<h3 mat-dialog-title>{{title}}</h3>

<mat-dialog-content>

<div class="row">
<a-mat-select class="col-md" [object]="object" [roleType]="m.SalesTerm.TermType" [options]="termTypes" display="Name"></a-mat-select>
<a-mat-input class="col-md" [object]="object" [roleType]="m.SalesTerm.TermValue" label="Value"></a-mat-input>
</div>

</mat-dialog-content>

<div mat-dialog-actions>
<button mat-button (click)="dialogRef.close()" type="button">CANCEL</button>
<button mat-button class="ml-2" color="primary" type="submit" [disabled]="!form.form.valid || !allors.context.hasChanges">SAVE</button>
</div>

</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { Component, OnDestroy, OnInit, Self, Inject } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { BehaviorSubject, Subscription, combineLatest } from 'rxjs';

import { Saved, ContextService, MetaService, RefreshService, TestScope } from '../../../../../angular';
import { SalesTerm, TermType } from '../../../../../domain';
import { PullRequest, Sort, Equals, ISessionObject, IObject } from '../../../../../framework';
import { ObjectData, SaveService } from '../../../../../material';
import { Meta } from '../../../../../meta';
import { switchMap, map } from 'rxjs/operators';

@Component({
templateUrl: './salesterm-edit.component.html',
providers: [ContextService]
})
export class SalesTermEditComponent extends TestScope implements OnInit, OnDestroy {

public m: Meta;

public title = 'Edit Term Type';

public container: ISessionObject;
public object: SalesTerm;
public termTypes: TermType[];

private subscription: Subscription;

constructor(
@Self() public allors: ContextService,
@Inject(MAT_DIALOG_DATA) public data: ObjectData,
public dialogRef: MatDialogRef<SalesTermEditComponent>,
public metaService: MetaService,
public refreshService: RefreshService,
private saveService: SaveService,
) {
super();

this.m = this.metaService.m;
}

public ngOnInit(): void {

const { m, pull, x } = this.metaService;

this.subscription = combineLatest(this.refreshService.refresh$)
.pipe(
switchMap(() => {

const create = (this.data as IObject).id === undefined;
const { objectType, associationRoleType } = this.data;

const pulls = [
pull.SalesTerm(
{
object: this.data.id,
include: {
TermType: x,
}
}),
pull.TermType({
predicate: new Equals({ propertyType: m.TermType.IsActive, value: true }),
sort: [
new Sort(m.TermType.Name),
],
})
];

if (create && this.data.associationId) {
pulls.push(
pull.SalesInvoice({ object: this.data.associationId }),
pull.SalesOrder({ object: this.data.associationId }),
);
}

return this.allors.context.load(new PullRequest({ pulls }))
.pipe(
map((loaded) => ({ loaded, create, objectType, associationRoleType }))
);
})
)
.subscribe(({ loaded, create, objectType, associationRoleType }) => {
this.allors.context.reset();

this.container = loaded.objects.SalesInvoice || loaded.objects.SalesOrder;
this.object = loaded.objects.SalesTerm as SalesTerm;
this.termTypes = loaded.collections.TermTypes as TermType[];
this.termTypes = this.termTypes.filter(v => v.objectType.name === `${objectType.name}Type`);

if (create) {
this.title = 'Add Sales Term';
this.object = this.allors.context.create(objectType.name) as SalesTerm;
this.container.add(associationRoleType, this.object);
}

});
}

public ngOnDestroy(): void {
if (this.subscription) {
this.subscription.unsubscribe();
}
}

public save(): void {

this.allors.context.save()
.subscribe((saved: Saved) => {
const data: IObject = {
id: this.object.id,
objectType: this.object.objectType,
};

this.dialogRef.close(data);
this.refreshService.refresh();
},
this.saveService.errorHandler
);
}
}
Loading

0 comments on commit d8ebe8d

Please sign in to comment.