|
@@ -187,6 +187,8 @@ public class StockMovementTimberlineSettings : TimberlinePosterSettings<StockMov
|
|
|
[CheckBoxEditor]
|
|
|
public bool IgnoreNetZeroTransfers { get; set; }
|
|
|
|
|
|
+ public bool IgnoreMovementsWithNoPurchaseGL { get; set; } = true;
|
|
|
+
|
|
|
protected override string DefaultScript()
|
|
|
{
|
|
|
return @"
|
|
@@ -258,7 +260,8 @@ public class StockMovementTimberlinePoster : ITimberlinePoster<StockMovement, St
|
|
|
columns: Columns.None<Product>().Add(x => x.ID)
|
|
|
.Add(x => x.Name)
|
|
|
.Add(x => x.CostCentre.Code)
|
|
|
- .Add(x => x.PurchaseGL.Code));
|
|
|
+ .Add(x => x.PurchaseGL.Code)
|
|
|
+ .Add(x => x.SellGL.Code));
|
|
|
|
|
|
model.AddLookupTable<StockMovement, Job>(x => x.Job.ID, x => x.ID, sourcealias: "FullTransactions",
|
|
|
isdefault: true,
|
|
@@ -335,6 +338,23 @@ public class StockMovementTimberlinePoster : ITimberlinePoster<StockMovement, St
|
|
|
// I think we will fail all the movements if any one movement in the transaction failed. All the successful ones,
|
|
|
// rather than saving them with AddSuccess immediately, we will put here first, and only succeed them if every movement succeeded.
|
|
|
var successful = new List<(StockMovement mvt, IStockMovementTimberlineLine? line)>();
|
|
|
+
|
|
|
+ void AddMovement(StockMovement mvt, IStockMovementTimberlineLine line)
|
|
|
+ {
|
|
|
+ if(Settings.IgnoreMovementsWithNoPurchaseGL && line.CreditAccount.IsNullOrWhiteSpace())
|
|
|
+ {
|
|
|
+ successful.Add((mvt, null));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ successful.Add((mvt, line));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ void IgnoreMovement(StockMovement mvt)
|
|
|
+ {
|
|
|
+ successful.Add((mvt, null));
|
|
|
+ }
|
|
|
+
|
|
|
foreach(var mvt in mvts)
|
|
|
{
|
|
|
switch (mvt.Type)
|
|
@@ -349,7 +369,7 @@ public class StockMovementTimberlinePoster : ITimberlinePoster<StockMovement, St
|
|
|
gl.DebitAccount = product.SellGL.Code.NotWhiteSpaceOr(Settings.StockTakeGL);
|
|
|
if (ProcessGLLine(model, mvt, gl))
|
|
|
{
|
|
|
- successful.Add((mvt, gl));
|
|
|
+ AddMovement(mvt, gl);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -359,40 +379,48 @@ public class StockMovementTimberlinePoster : ITimberlinePoster<StockMovement, St
|
|
|
else
|
|
|
{
|
|
|
// Ignore issues to a job.
|
|
|
- successful.Add((mvt, null));
|
|
|
+ IgnoreMovement(mvt);
|
|
|
}
|
|
|
break;
|
|
|
case StockMovementType.Receive:
|
|
|
- successful.Add((mvt, null));
|
|
|
+ IgnoreMovement(mvt);
|
|
|
break;
|
|
|
case StockMovementType.StockTake:
|
|
|
- if(mvt.Job.ID == Guid.Empty)
|
|
|
+ if (mvt.Units.IsEffectivelyEqual(0.0))
|
|
|
{
|
|
|
- // StockTake in General Stock
|
|
|
- var gl = new StockMovementTimberlineGL { };
|
|
|
- gl = ModifyLine(gl, mvt);
|
|
|
- var product = products[mvt.Product.ID];
|
|
|
- gl.DebitAccount = product.SellGL.Code.NotWhiteSpaceOr(Settings.StockTakeGL);
|
|
|
- if (ProcessGLLine(model, mvt, gl))
|
|
|
- {
|
|
|
- successful.Add((mvt, gl));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- result.AddFailed(mvt, "Failed by script.");
|
|
|
- }
|
|
|
+ // Ignore empty stocktakes
|
|
|
+ IgnoreMovement(mvt);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- // StockTake in Job Holding
|
|
|
- var dc = CreateDirectCost(mvt);
|
|
|
- if (ProcessDirectCostLine(model, mvt, dc))
|
|
|
+ if (mvt.Job.ID == Guid.Empty)
|
|
|
{
|
|
|
- successful.Add((mvt, dc));
|
|
|
+ // StockTake in General Stock
|
|
|
+ var gl = new StockMovementTimberlineGL { };
|
|
|
+ gl = ModifyLine(gl, mvt);
|
|
|
+ var product = products[mvt.Product.ID];
|
|
|
+ gl.DebitAccount = product.SellGL.Code.NotWhiteSpaceOr(Settings.StockTakeGL);
|
|
|
+ if (ProcessGLLine(model, mvt, gl))
|
|
|
+ {
|
|
|
+ AddMovement(mvt, gl);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ result.AddFailed(mvt, "Failed by script.");
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- result.AddFailed(mvt, "Failed by script.");
|
|
|
+ // StockTake in Job Holding
|
|
|
+ var dc = CreateDirectCost(mvt);
|
|
|
+ if (ProcessDirectCostLine(model, mvt, dc))
|
|
|
+ {
|
|
|
+ AddMovement(mvt, dc);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ result.AddFailed(mvt, "Failed by script.");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
@@ -403,7 +431,7 @@ public class StockMovementTimberlinePoster : ITimberlinePoster<StockMovement, St
|
|
|
var directCost = CreateDirectCost(mvt);
|
|
|
if(ProcessDirectCostLine(model, mvt, directCost))
|
|
|
{
|
|
|
- successful.Add((mvt, directCost));
|
|
|
+ AddMovement(mvt, directCost);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -412,7 +440,7 @@ public class StockMovementTimberlinePoster : ITimberlinePoster<StockMovement, St
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- successful.Add((mvt, null));
|
|
|
+ IgnoreMovement(mvt);
|
|
|
}
|
|
|
break;
|
|
|
}
|