Skip to content

Commit

Permalink
Pl debit credit notes 1 (#123)
Browse files Browse the repository at this point in the history
* wip

* manage debit notes utility back end

* client

* register facade service

* domain service, tests, etc

* add closedBy

* refresh list on updates

* reinstate auth check

* rename item type, fix route etc
  • Loading branch information
lewisrenfrew authored Mar 1, 2022
1 parent 6ad64f4 commit 4e2bb2f
Show file tree
Hide file tree
Showing 29 changed files with 1,090 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Domain.LinnApps/AuthorisedAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ public class AuthorisedAction
public const string SupplierHoldChange = "purchasing.supplier.hold-change";

public const string PurchaseOrderUpdate = "purchase-order.update";

public const string PlCreditDebitNoteClose = "purchasing.pl-debit-credit-note.close";
}
}
13 changes: 13 additions & 0 deletions src/Domain.LinnApps/PurchaseOrders/IPlCreditDebitNoteService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Linn.Purchasing.Domain.LinnApps.PurchaseOrders
{
using System.Collections.Generic;

public interface IPlCreditDebitNoteService
{
public PlCreditDebitNote CloseDebitNote(
PlCreditDebitNote toClose,
string reason,
int closedBy,
IEnumerable<string> privileges);
}
}
37 changes: 37 additions & 0 deletions src/Domain.LinnApps/PurchaseOrders/PlCreditDebitNote.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace Linn.Purchasing.Domain.LinnApps.PurchaseOrders
{
using System;

using Linn.Purchasing.Domain.LinnApps.Suppliers;

public class PlCreditDebitNote
{
public int NoteNumber { get; set; }

public string NoteType { get; set; }

public string PartNumber { get; set; }

public int OrderQty { get; set; }

public int? OriginalOrderNumber { get; set; }

public int? ReturnsOrderNumber { get; set; }

public decimal NetTotal { get; set; }

public string Notes { get; set; }

public DateTime? DateClosed { get; set; }

public DateTime DateCreated { get; set; }

public int? ClosedBy { get; set; }

public string ReasonClosed { get; set; }

public int? SupplierId { get; set; }

public Supplier Supplier { get; set; }
}
}
35 changes: 35 additions & 0 deletions src/Domain.LinnApps/PurchaseOrders/PlCreditDebitNoteService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace Linn.Purchasing.Domain.LinnApps.PurchaseOrders
{
using System;
using System.Collections.Generic;

using Linn.Common.Authorisation;
using Linn.Purchasing.Domain.LinnApps.Exceptions;

public class PlCreditDebitNoteService : IPlCreditDebitNoteService
{
private readonly IAuthorisationService authService;

public PlCreditDebitNoteService(IAuthorisationService authService)
{
this.authService = authService;
}

public PlCreditDebitNote CloseDebitNote(
PlCreditDebitNote toClose,
string reason,
int closedBy,
IEnumerable<string> privileges)
{
if (!this.authService.HasPermissionFor(AuthorisedAction.PlCreditDebitNoteClose, privileges))
{
throw new UnauthorisedActionException("You are not authorised to close debit notes");
}

toClose.DateClosed = DateTime.Today;
toClose.ReasonClosed = reason;
toClose.ClosedBy = closedBy;
return toClose;
}
}
}
38 changes: 38 additions & 0 deletions src/Facade/ResourceBuilders/PlCreditDebitNoteResourceBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace Linn.Purchasing.Facade.ResourceBuilders
{
using System;
using System.Collections.Generic;

using Linn.Common.Facade;
using Linn.Purchasing.Domain.LinnApps.PurchaseOrders;
using Linn.Purchasing.Resources;

public class PlCreditDebitNoteResourceBuilder : IBuilder<PlCreditDebitNote>
{
public PlCreditDebitNoteResource Build(PlCreditDebitNote note, IEnumerable<string> claims)
{
return new PlCreditDebitNoteResource
{
OrderQty = note.OrderQty,
PartNumber = note.PartNumber,
DateClosed = note.DateClosed?.ToString("o"),
SupplierId = note.SupplierId,
ClosedBy = note.ClosedBy,
NetTotal = note.NetTotal,
NoteNumber = note.NoteNumber,
OriginalOrderNumber = note.OriginalOrderNumber,
ReturnsOrderNumber = note.ReturnsOrderNumber,
Notes = note.Notes,
SupplierName = note.Supplier?.Name,
DateCreated = note.DateCreated.ToShortDateString()
};
}

public string GetLocation(PlCreditDebitNote p)
{
throw new NotImplementedException();
}

object IBuilder<PlCreditDebitNote>.Build(PlCreditDebitNote entity, IEnumerable<string> claims) => this.Build(entity, claims);
}
}
82 changes: 82 additions & 0 deletions src/Facade/Services/PlCreditDebitNoteFacadeService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
namespace Linn.Purchasing.Facade.Services
{
using System;
using System.Collections.Generic;
using System.Linq.Expressions;

using Linn.Common.Facade;
using Linn.Common.Persistence;
using Linn.Purchasing.Domain.LinnApps.PurchaseOrders;
using Linn.Purchasing.Resources;

public class PlCreditDebitNoteFacadeService
: FacadeFilterResourceService<PlCreditDebitNote, int, PlCreditDebitNoteResource, PlCreditDebitNoteResource, PlCreditDebitNoteResource>
{
private readonly IPlCreditDebitNoteService domainService;

public PlCreditDebitNoteFacadeService(
IRepository<PlCreditDebitNote, int> repository,
ITransactionManager transactionManager,
IBuilder<PlCreditDebitNote> builder,
IPlCreditDebitNoteService domainService)
: base(repository, transactionManager, builder)
{
this.domainService = domainService;
}

protected override PlCreditDebitNote CreateFromResource(
PlCreditDebitNoteResource resource,
IEnumerable<string> privileges = null)
{
throw new NotImplementedException();
}

protected override void UpdateFromResource(
PlCreditDebitNote entity,
PlCreditDebitNoteResource updateResource,
IEnumerable<string> privileges = null)
{
if (updateResource.ClosedBy.HasValue && updateResource.Close.HasValue && (bool)updateResource.Close)
{
this.domainService.CloseDebitNote(
entity,
updateResource.ReasonClosed,
(int)updateResource.ClosedBy,
privileges);
}

entity.Notes = updateResource.Notes;
}

protected override Expression<Func<PlCreditDebitNote, bool>> SearchExpression(
string searchTerm)
{
throw new NotImplementedException();
}

protected override void SaveToLogTable(
string actionType,
int userNumber,
PlCreditDebitNote entity,
PlCreditDebitNoteResource resource,
PlCreditDebitNoteResource updateResource)
{
throw new NotImplementedException();
}

protected override void DeleteOrObsoleteResource(
PlCreditDebitNote entity, IEnumerable<string> privileges = null)
{
throw new NotImplementedException();
}

protected override Expression<Func<PlCreditDebitNote, bool>> FilterExpression(
PlCreditDebitNoteResource searchResource)
{
var date = string.IsNullOrEmpty(searchResource.DateClosed)
? (DateTime?)null
: DateTime.Parse(searchResource.DateClosed);
return x => x.DateClosed == date && x.NoteType == searchResource.NoteType;
}
}
}
4 changes: 3 additions & 1 deletion src/IoC/HandlerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public static IServiceCollection AddHandlers(this IServiceCollection services)
.AddTransient<IHandler, JsonResultHandler<IEnumerable<VendorManagerResource>>>()
.AddTransient<IHandler, JsonResultHandler<SupplierGroupResource>>()
.AddTransient<IHandler, JsonResultHandler<IEnumerable<SupplierGroupResource>>>()
.AddTransient<IHandler, JsonResultHandler<IEnumerable<PlannerResource>>>();
.AddTransient<IHandler, JsonResultHandler<IEnumerable<PlannerResource>>>()
.AddTransient<IHandler, JsonResultHandler<IEnumerable<PlCreditDebitNoteResource>>>()
.AddTransient<IHandler, JsonResultHandler<PlCreditDebitNoteResource>>();
}
}
}
3 changes: 2 additions & 1 deletion src/IoC/PersistenceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public static IServiceCollection AddPersistence(this IServiceCollection services
r => new EntityFrameworkRepository<SupplierGroup, int>(r.GetService<ServiceDbContext>()?.SupplierGroups))
.AddTransient<IRepository<SupplierContact, int>, SupplierContactRepository>()
.AddTransient<IRepository<Person, int>, EntityFrameworkRepository<Person, int>>(
r => new EntityFrameworkRepository<Person, int>(r.GetService<ServiceDbContext>()?.Persons));
r => new EntityFrameworkRepository<Person, int>(r.GetService<ServiceDbContext>()?.Persons))
.AddTransient<IRepository<PlCreditDebitNote, int>, PlCreditDebitNoteRepository>();
}
}
}
7 changes: 5 additions & 2 deletions src/IoC/ServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public static IServiceCollection AddBuilders(this IServiceCollection services)
.AddTransient<IBuilder<VendorManager>, VendorManagerResourceBuilder>()
.AddTransient<IBuilder<Planner>, PlannerResourceBuilder>()
.AddTransient<IBuilder<SupplierGroup>, SupplierGroupResourceBuilder>()
.AddTransient<IBuilder<SupplierContact>, SupplierContactResourceBuilder>();
.AddTransient<IBuilder<SupplierContact>, SupplierContactResourceBuilder>()
.AddTransient<IBuilder<PlCreditDebitNote>, PlCreditDebitNoteResourceBuilder>();
}

public static IServiceCollection AddFacades(this IServiceCollection services)
Expand All @@ -80,7 +81,8 @@ public static IServiceCollection AddFacades(this IServiceCollection services)
.AddTransient<IFacadeResourceService<Country, string, CountryResource, CountryResource>, CountryService>()
.AddTransient<IFacadeResourceService<VendorManager, string, VendorManagerResource, VendorManagerResource>, VendorManagerFacadeService>().AddTransient<ISpendsReportFacadeService, SpendsReportFacadeService>()
.AddTransient<IFacadeResourceService<Planner, int, PlannerResource, PlannerResource>, PlannerService>()
.AddTransient<IFacadeResourceService<SupplierGroup, int, SupplierGroupResource, SupplierGroupResource>, SupplierGroupFacadeService>();
.AddTransient<IFacadeResourceService<SupplierGroup, int, SupplierGroupResource, SupplierGroupResource>, SupplierGroupFacadeService>()
.AddTransient<IFacadeResourceFilterService<PlCreditDebitNote, int, PlCreditDebitNoteResource, PlCreditDebitNoteResource, PlCreditDebitNoteResource>, PlCreditDebitNoteFacadeService>();
}

public static IServiceCollection AddServices(this IServiceCollection services)
Expand All @@ -99,6 +101,7 @@ public static IServiceCollection AddServices(this IServiceCollection services)
.AddTransient<IAuthorisationService, AuthorisationService>()
.AddTransient<IDatabaseService, DatabaseService>()
.AddTransient<ISpendsReportService, SpendsReportService>()
.AddTransient<IPlCreditDebitNoteService, PlCreditDebitNoteService>()

// external services
.AddTransient<IPurchaseOrdersPack, PurchaseOrdersPack>()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace Linn.Purchasing.Persistence.LinnApps.Repositories
{
using System;
using System.Linq;
using System.Linq.Expressions;

using Linn.Common.Persistence.EntityFramework;
using Linn.Purchasing.Domain.LinnApps.PurchaseOrders;

using Microsoft.EntityFrameworkCore;

public class PlCreditDebitNoteRepository : EntityFrameworkRepository<PlCreditDebitNote, int>
{
public PlCreditDebitNoteRepository(ServiceDbContext serviceDbContext)
: base(serviceDbContext.PlCreditDebitNotes)
{
}

public override IQueryable<PlCreditDebitNote> FilterBy(Expression<Func<PlCreditDebitNote, bool>> expression)
{
return base.FilterBy(expression).Include(n => n.Supplier);
}
}
}
23 changes: 23 additions & 0 deletions src/Persistence.LinnApps/ServiceDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public class ServiceDbContext : DbContext

public DbSet<Person> Persons { get; set; }

public DbSet<PlCreditDebitNote> PlCreditDebitNotes { get; set; }

protected override void OnModelCreating(ModelBuilder builder)
{
builder.Model.AddAnnotation("MaxIdentifierLength", 30);
Expand Down Expand Up @@ -121,6 +123,7 @@ protected override void OnModelCreating(ModelBuilder builder)
this.BuildSupplierGroups(builder);
this.BuildSupplierContacts(builder);
this.BuildPersons(builder);
this.BuildPlCreditDebitNotes(builder);
}

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
Expand Down Expand Up @@ -654,5 +657,25 @@ private void BuildSupplierGroups(ModelBuilder builder)
entity.Property(e => e.Id).HasColumnName("ID");
entity.Property(e => e.Name).HasColumnName("NAME");
}

private void BuildPlCreditDebitNotes(ModelBuilder builder)
{
var entity = builder.Entity<PlCreditDebitNote>().ToTable("PL_CREDIT_DEBIT_NOTES");
entity.HasKey(a => a.NoteNumber);
entity.Property(a => a.NoteNumber).HasColumnName("CDNOTE_ID");
entity.Property(a => a.PartNumber).HasColumnName("PART_NUMBER").HasMaxLength(14);
entity.Property(a => a.OrderQty).HasColumnName("ORDER_QTY");
entity.Property(a => a.ClosedBy).HasColumnName("CLOSED_BY");
entity.Property(a => a.DateClosed).HasColumnName("DATE_CLOSED");
entity.Property(a => a.NetTotal).HasColumnName("NET_TOTAL");
entity.Property(a => a.NoteType).HasColumnName("CDNOTE_TYPE").HasMaxLength(1);
entity.Property(a => a.OriginalOrderNumber).HasColumnName("ORIGINAL_ORDER_NUMBER");
entity.Property(a => a.ReturnsOrderNumber).HasColumnName("RETURNS_ORDER_NUMBER");
entity.Property(a => a.Notes).HasColumnName("NOTES").HasMaxLength(200);
entity.Property(a => a.ReasonClosed).HasColumnName("REASON_CLOSED").HasMaxLength(2000);
entity.Property(a => a.SupplierId).HasColumnName("SUPPLIER_ID");
entity.HasOne(a => a.Supplier).WithMany().HasForeignKey(a => a.SupplierId);
entity.Property(a => a.DateCreated).HasColumnName("DATE_CREATED");
}
}
}
39 changes: 39 additions & 0 deletions src/Resources/PlCreditDebitNoteResource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace Linn.Purchasing.Resources
{
using System.Collections.Generic;

public class PlCreditDebitNoteResource
{
public int NoteNumber { get; set; }

public string NoteType { get; set; }

public string PartNumber { get; set; }

public int OrderQty { get; set; }

public int? OriginalOrderNumber { get; set; }

public int? ReturnsOrderNumber { get; set; }

public decimal NetTotal { get; set; }

public string Notes { get; set; }

public string DateClosed { get; set; }

public int? ClosedBy { get; set; }

public string ReasonClosed { get; set; }

public int? SupplierId { get; set; }

public string SupplierName { get; set; }

public IEnumerable<string> UserPrivileges { get; set; }

public string DateCreated { get; set; }

public bool? Close { get; set; }
}
}
4 changes: 4 additions & 0 deletions src/Service.Host/client/src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,7 @@ export const spendByPartReportActionTypes = makeActionTypes(
reportTypes.spendByPartReport.actionType,
false
);

export const plCreditDebitNoteActionTypes = makeActionTypes(itemTypes.plCreditDebitNote.actionType);

export const openDebitNotesActionTypes = makeActionTypes(itemTypes.openDebitNotes.actionType);
12 changes: 12 additions & 0 deletions src/Service.Host/client/src/actions/openDebitNotesActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { FetchApiActions } from '@linn-it/linn-form-components-library';
import { openDebitNotesActionTypes as actionTypes } from './index';
import * as itemTypes from '../itemTypes';
import config from '../config';

export default new FetchApiActions(
itemTypes.openDebitNotes.item,
itemTypes.openDebitNotes.actionType,
itemTypes.openDebitNotes.uri,
actionTypes,
config.appRoot
);
Loading

0 comments on commit 4e2bb2f

Please sign in to comment.