Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 126: Introduce .Net ERP Interface #165

Merged
merged 11 commits into from
Feb 1, 2021
42 changes: 27 additions & 15 deletions Files/DataStandard/Vault.Custom/addinVault/powerGateMain.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function GetSelectedObject {
$entity = $null

$selectedObject = $VaultContext.SelectedObject
if(-not $selectedObject) {
if (-not $selectedObject) {
$selectedObject = $VaultContext.CurrentSelectionSet | Select-Object -First 1
}
if ($selectedObject.TypeId.SelectionContext -eq "FileMaster") {
Expand All @@ -38,7 +38,8 @@ function InitBomTab {
$bom = GetErpBomHeader -number $number
if (-not $bom -or $false -eq $bom) {
$goToEnabled = $false
} else {
}
else {
$goToEnabled = $true
}
$dswindow.FindName("DataGrid").DataContext = $bom
Expand All @@ -53,7 +54,8 @@ function InitMaterialTab {
$erpMaterial = NewErpMaterial
$erpMaterial = PrepareErpMaterial -erpMaterial $erpMaterial -vaultEntity $entity
$goToEnabled = $false
} else {
}
else {
$goToEnabled = $true
}
$dswindow.FindName("DataGrid").DataContext = $erpMaterial
Expand All @@ -66,7 +68,8 @@ function IsEntityUnlocked {
if ($entity._EntityTypeID -eq "ITEM") {
$item = $vault.ItemService.GetLatestItemByItemMasterId($entity.MasterId)
$entityUnlocked = $item.Locked -ne $true
} else {
}
else {
$entityUnlocked = $entity._VaultStatus.Status.LockState -ne "Locked" -and $entity.IsCheckedOut -ne $true
}

Expand All @@ -77,7 +80,8 @@ function ValidateErpMaterialTab {
$erpMaterial = $dsWindow.FindName("DataGrid").DataContext
if ($erpMaterial.Number) {
$entityUnlocked = $true
} else {
}
else {
$entityUnlocked = IsEntityUnlocked
}

Expand All @@ -100,15 +104,18 @@ function CreateOrUpdateErpMaterial {
$erpMaterial = UpdateErpMaterial -erpMaterial $erpMaterial
if (-not $erpMaterial -or $false -eq $erpMaterial) {
ShowMessageBox -Message $erpMaterial._ErrorMessage -Icon "Error" -Title "powerGate ERP - Update Material" | Out-Null
} else {
}
else {
ShowMessageBox -Message "$($erpMaterial.Number) successfully updated" -Title "powerGate ERP - Update Material" -Icon "Information" | Out-Null
}
InitMaterialTab
} else {
}
else {
$erpMaterial = CreateErpMaterial -erpMaterial $erpMaterial
if (-not $erpMaterial -or $false -eq $erpMaterial) {
ShowMessageBox -Message $erpMaterial._ErrorMessage -Icon "Error" -Title "powerGate ERP - Create Material" | Out-Null
} else {
}
else {
ShowMessageBox -Message "$($erpMaterial.Number) successfully created" -Title "powerGate ERP - Create Material" -Icon "Information" | Out-Null
$vaultEntity = GetSelectedObject
SetEntityProperties -erpMaterial $erpMaterial -vaultEntity $vaultEntity
Expand Down Expand Up @@ -141,9 +148,10 @@ function LinkErpMaterial {
return
}
}
} elseif ($vaultEntity._EntityTypeID -eq "FILE") {
}
elseif ($vaultEntity._EntityTypeID -eq "FILE") {
#TODO: Rename "Part Number" on a german system to "Teilenummer"
$existingEntities = Get-VaultFiles -Properties @{"Part Number" = $erpMaterial.Number}
$existingEntities = Get-VaultFiles -Properties @{"Part Number" = $erpMaterial.Number }
if ($existingEntities) {
$existingEntities = $existingEntities | Where-Object { $_.MasterId -ne $vaultEntity.MasterId }
$message = ""
Expand Down Expand Up @@ -177,15 +185,17 @@ function RefreshView {

$vwCtx = New-Object Connectivity.Explorer.Framework.LocationContext($cFileExplorerObject, $cDocFolder)
$navCtx = New-Object Connectivity.Explorer.Framework.LocationContext($cDocFolder)
} elseif ($entity._EntityTypeID -eq "ITEM") {
}
elseif ($entity._EntityTypeID -eq "ITEM") {
$item = $vault.ItemService.GetLatestItemByItemMasterId($entity.MasterId)
$cItemRev = New-Object Connectivity.Services.Item.ItemRevision($vaultConnection, $item)
$cItemRevExpObj = New-Object Connectivity.Explorer.Item.ItemRevisionExplorerObject($cItemRev)
$cItemMaster = New-Object Connectivity.Explorer.Item.ItemMaster

$vwCtx = New-Object Connectivity.Explorer.Framework.LocationContext($cItemRevExpObj)
$navCtx = New-Object Connectivity.Explorer.Framework.LocationContext($cItemMaster)
} else {
}
else {
return
}

Expand All @@ -206,9 +216,10 @@ function SetEntityProperties($erpMaterial, $vaultEntity) {
"_Description(Item,CO)" = $erpMaterial.Description
}
$vaultEntity._Number = $erpMaterial.Number
} elseif ($vaultEntity._EntityTypeID -eq "FILE") {
}
elseif ($vaultEntity._EntityTypeID -eq "FILE") {
Update-VaultFile -File $vaultEntity._FullPath -Properties @{
"_PartNumber" = $erpMaterial.Number
"_PartNumber" = $erpMaterial.Number
"_Description" = $erpMaterial.Description
}
$vaultEntity._PartNumber = $erpMaterial.Number
Expand Down Expand Up @@ -275,7 +286,8 @@ function PrepareErpBomRow($erpBomRow, $parentNumber, $vaultEntity) {
$erpBomRow.Position = [int]$vaultEntity.'Bom_PositionNumber'
if ($vaultEntity.Children) {
$erpBomRow.Type = "Assembly"
} else {
}
else {
$erpBomRow.Type = "Part"
}
$erpBomRow.Quantity = [double]$vaultEntity.'Bom_Quantity'
Expand Down
33 changes: 20 additions & 13 deletions Files/powerEvents/Events/ErpService.Lifecycle.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ $supportedPdfExtensions = @("idw", "dwg")
$requiresErpItemExtensions = @("iam", "ipn", "ipt")

function CheckVaultBom($entity) {
$differences = CompareErpBom -EntityBom @($entity)
foreach($diff in $differences){
$differences = CompareErpBom -EntityBom @($entity)
foreach ($diff in $differences) {
if ($diff.Status -ne "Identical" -and $diff.IsHeader) {
throw $diff.Message
}
Expand Down Expand Up @@ -43,19 +43,22 @@ function RestrictFileRelease($files) {

if (-not $file.Children) {
Add-Member -InputObject $file -Name "Children" -Value $bomRows -MemberType NoteProperty -Force
} else {
}
else {
$file.Children = $bomRows
}

try {
CheckVaultBom $file | Out-Null
} catch {
}
catch {
$restrictMessage = "$($_)! Please open the BOM dialog"
Add-VaultRestriction -EntityName $file._Name -Message $restrictMessage
}
}
}
} catch {
}
catch {
#Show-Inspector
Log -Message $_.Exception.Message -MessageBox -LogLevel "ERROR"
}
Expand Down Expand Up @@ -85,19 +88,22 @@ function RestrictItemRelease($items) {

if (-not $item.Children) {
Add-Member -InputObject $item -Name "Children" -Value $bomRows -MemberType NoteProperty -Force
} else {
}
else {
$item.Children = $bomRows
}

try {
CheckVaultBom $item | Out-Null
} catch {
}
catch {
$restrictMessage = "$($_)! Please open the BOM dialog"
Add-VaultRestriction -EntityName $item._Number -Message $restrictMessage
}
}
}
} catch {
}
catch {
Log -Message $_.Exception.Message -MessageBox -LogLevel "ERROR"
}
Log -End
Expand All @@ -107,17 +113,18 @@ Register-VaultEvent -EventName UpdateFileStates_Post -Action 'AddPdfJob'
function AddPdfJob($files, $successful) {
Log -Begin
try {
if(-not $successful) { return }
if (-not $successful) { return }
$releasedFiles = @($files | Where-Object { $supportedPdfExtensions -contains $_._Extension -and $_._ReleasedRevision -eq $true })
foreach($file in $releasedFiles) {
foreach ($file in $releasedFiles) {
$material = GetErpMaterial -Number $file._PartNumber
if ($false -ne $material -and $material) {
$jobType = "ErpService.Create.PDF"
Log -Message "Adding job '$jobType' for file '$($file._Name)' to queue."
Add-VaultJob -Name $jobType -Parameters @{ "EntityId"=$file.Id; "EntityClassId"="FILE" } -Description "Create PDF for file '$($file._Name)' and upload to ERP system"
Add-VaultJob -Name $jobType -Parameters @{ "EntityId" = $file.Id; "EntityClassId" = "FILE" } -Description "Create PDF for file '$($file._Name)' and upload to ERP system"
}
}
} catch {
}
}
catch {
Log -Message $_.Exception.Message -MessageBox
}
Log -End
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ public partial class ErpManager : IErpManager
{
public BomHeader GetBomWithChildrenByNumber(string number)
{
return ExecuteOnDatabase(delegate(LiteDatabase database)
return ExecuteOnDatabase(delegate (LiteDatabase database)
{
var bomHeader = database.GetCollection<BomHeader>().Find(header => header.Number == number).FirstOrDefault();
if(bomHeader != null)
if (bomHeader != null)
bomHeader.BomRows = GetBomRowsByHeaderNumber(bomHeader.Number);
return bomHeader;
});
Expand All @@ -30,7 +30,7 @@ List<BomRow> GetBomRowsByHeaderNumber(string parentNumber)

foreach (var bomRow in bomRows)
{
var material = GetMaterialByNumber(bomRow.ChildNumber);
var material = GetMaterialyByNumber(bomRow.ChildNumber);
bomRow.Description = material.Description;
bomRow.UnitOfMeasure = material.UnitOfMeasure;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace ErpServices.ErpManager.Implementation
{
public partial class ErpManager : IErpManager
{
public Material GetMaterialByNumber(string number)
public Material GetMaterialyByNumber(string number)
{
return ExecuteOnDatabase(database => database.GetCollection<Material>().Find(material => material.Number == number)).FirstOrDefault();
}
Expand All @@ -34,7 +34,7 @@ string GetNextNumber()
Log.Info(">> GetNextNumber >>");
var nextNumber = "500000";

return ExecuteOnDatabase(delegate(LiteDatabase database)
return ExecuteOnDatabase(delegate (LiteDatabase database)
{
var collection = database.GetCollection<Material>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public interface IErpManager : IDisposable
bool Connect(ErpLogin login);

// Material functionality
Material GetMaterialByNumber(string number);
Material GetMaterialyByNumber(string number);
IEnumerable<Material> SearchMaterials(IEnumerable<ErpMaterialSearchSettings> query);
Material CreateMaterial(Material material);
Material UpdateMaterial(Material material);

// Documents functionality
Document GetDocumentMetadata(string number);
Document CreateDocumentMetadata(Document documentMetadata);
Expand Down
2 changes: 1 addition & 1 deletion Files/powerGatePlugin/ErpServices/Metadata/BomHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public string Link
set => _ = value;
}

public List<BomRow> BomRows { get; set; }
public List<BomRow> BomRows { get; set; }

public BomHeader()
{
Expand Down
12 changes: 12 additions & 0 deletions Files/powerGatePlugin/ErpServices/Metadata/Material.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ public class Material
public bool IsBlocked { get; set; }
public string Category { get; set; }
public string Shelf { get; set; }
public double Weight { get; set; }
public string Dimensions { get; set; }
[BsonIgnore]
public bool IsVendorSpecified
{
get => !string.IsNullOrEmpty(VendorNumber);
set => _ = value;
}
public string VendorNumber { get; set; }
public string VendorName { get; set; }
public string VendorItemNumber { get; set; }
public decimal Cost { get; set; }
public string SearchDescription { get; set; }
public string Link
{
Expand Down
6 changes: 4 additions & 2 deletions Files/powerGatePlugin/ErpServices/Services/BomRows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

namespace ErpServices.Services
{
public class BomRows : ErpBaseService<BomRow>
public class BomRows : ErpBaseService<BomRow>
{
static readonly ILog Log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public override string Name => "BomRows";

public BomRows(IErpManager erpManager) : base(erpManager)
Expand All @@ -26,7 +28,7 @@ public override IEnumerable<BomRow> Query(IExpression<BomRow> expression)
var childNumber = expression.GetWhereValuesAsString("ChildNumber");
Log.InfoFormat("Single query for bom row, header number {0} and child number", parentNumber, childNumber);
var bomRow = ErpManager.GetBomRowByNumber(parentNumber, childNumber);
if(bomRow != null)
if (bomRow != null)
return new[] { bomRow };
return Enumerable.Empty<BomRow>();
}
Expand Down
2 changes: 2 additions & 0 deletions Files/powerGatePlugin/ErpServices/Services/Documents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace ErpServices.Services
{
public class Documents : ErpBaseService<Document>, IStreamableServiceMethod<Document>
{
static readonly ILog Log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public override string Name => "Documents";

public Documents(IErpManager erpManager) : base(erpManager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace ErpServices.Services
{
public abstract class ErpBaseService<T> : ServiceMethod<T>
public abstract class ErpBaseService<T> : ServiceMethod<T>
{
protected IErpManager ErpManager;

Expand Down
2 changes: 1 addition & 1 deletion Files/powerGatePlugin/ErpServices/Services/Materials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public override IEnumerable<Material> Query(IExpression<Material> expression)
{
var number = expression.GetWhereValuesAsString("Number");
Log.InfoFormat("Single query for item number {0}", number);
var material = ErpManager.GetMaterialByNumber(number);
var material = ErpManager.GetMaterialyByNumber(number);

if (material != null)
return new[] { material };
Expand Down
8 changes: 5 additions & 3 deletions Files/powerGatePlugin/ErpServices/WebService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public class WebService : powerGateServer.SDK.WebService
{
static readonly ILog Log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);



public WebService()
{
var erpStorageConfiguration = GetErpStorageConfiguration();
Expand All @@ -33,12 +34,13 @@ public WebService()
};
Log.Info("Connecting to ERP...");
var connected = erpManager.Connect(erpLogin);
if(!connected)
if (!connected)
throw new Exception(string.Format("Failed to connect to ERP with Connection-String: {0}", erpLogin.ConnectionString));

AddMethod(new Materials(erpManager));
AddMethod(new BomHeaders(erpManager));
AddMethod(new BomRows(erpManager));
AddMethod(new Documents(erpManager));
AddMethod(new Categories(erpManager));
AddMethod(new Documents(erpManager));

Expand All @@ -56,7 +58,7 @@ AppSettingsSection GetErpStorageConfiguration()
var fileMap = new ExeConfigurationFileMap { ExeConfigFilename = configFullName };
var configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
var section = configuration.GetSection("ErpStorage") as AppSettingsSection;
if (section == null)
if (section == null)
throw new Exception("Failed to find 'ErpStorage' section inside the config file!");

Log.Info(".config file successfully parsed!");
Expand Down