|
|
@@ -0,0 +1,83 @@
|
|
|
+using Comal.Classes;
|
|
|
+using InABox.Core;
|
|
|
+using InABox.Database;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.IO;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using com.sun.org.apache.xpath.@internal.operations;
|
|
|
+using Microsoft.Extensions.Logging;
|
|
|
+using NPOI.HSSF.Util;
|
|
|
+
|
|
|
+namespace PRS.Shared;
|
|
|
+/*
|
|
|
+update script version 8.59.2
|
|
|
+
|
|
|
+ITERATE the table<Stockmovement> WHERE EmployeeID == NULL
|
|
|
+THEN Copy EmployeeId from the StockmovementBatch table into the Stockmovement table WHERE StockmovementBatch.ID == Stockmovement.ID
|
|
|
+
|
|
|
+ */
|
|
|
+
|
|
|
+internal class Update_8_59_2 : DatabaseUpdateScript
|
|
|
+{
|
|
|
+ public override VersionNumber Version => new(8, 59, 2); //define the version number
|
|
|
+
|
|
|
+
|
|
|
+ //overide update
|
|
|
+ public override bool Update()
|
|
|
+ {
|
|
|
+ StockmovementEmployeeUpdate(); //stock movement updates
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void StockmovementEmployeeUpdate()
|
|
|
+ {
|
|
|
+ Logger.Send(LogType.Information, "", "Updating StockMovement EmployeeIDs from StockMovementBatch"); //logger message
|
|
|
+
|
|
|
+ var provider = DbFactory.NewProvider(Logger.Main); //provider database
|
|
|
+
|
|
|
+ // get all movements where EmployeeID is NULL
|
|
|
+ var movements = provider.Query(
|
|
|
+ Filter<StockMovement>.Where(x => x.Employee.ID).IsEqualTo(Guid.Empty)
|
|
|
+ .And(x=> x.Batch.Employee.ID).IsNotEqualTo(Guid.Empty), //guid empty
|
|
|
+ Columns.None<StockMovement>()
|
|
|
+ .Add(x => x.ID)
|
|
|
+ .Add(x => x.Batch.Employee.ID)
|
|
|
+ .Add(x => x.Employee.ID)
|
|
|
+ ).ToList<StockMovement>()
|
|
|
+ .ToQueue();
|
|
|
+
|
|
|
+ Logger.Send(LogType.Information, "", $"Updating {movements.Count} Counts");
|
|
|
+
|
|
|
+ var total = movements.Count; //database entry
|
|
|
+ var processed = 0; //processed counts
|
|
|
+
|
|
|
+
|
|
|
+ //while loop checks if the there is any elements in the Queue
|
|
|
+ while(movements.Any())
|
|
|
+ {
|
|
|
+ Logger.Send(LogType.Information, "", $"Updating {movements.Count} Count:\t; {processed}/{total}"); //updating message
|
|
|
+
|
|
|
+
|
|
|
+ var movementTasks = movements.Dequeue(100).ToArray(); //dequeue into an array
|
|
|
+
|
|
|
+ //now update each movement in the movementTask queue
|
|
|
+ foreach (var movement in movementTasks)
|
|
|
+ {
|
|
|
+ movement.Employee.ID = movement.Batch.Employee.ID; //update the employee id
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ provider.Save(movements); //saves update
|
|
|
+
|
|
|
+ processed += movementTasks.Length; //update the length
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|