diff --git a/Files/DataStandard/Vault.Custom/addinVault/powerGateMain.ps1 b/Files/DataStandard/Vault.Custom/addinVault/powerGateMain.ps1 index 7aa3320..1612cbc 100644 --- a/Files/DataStandard/Vault.Custom/addinVault/powerGateMain.ps1 +++ b/Files/DataStandard/Vault.Custom/addinVault/powerGateMain.ps1 @@ -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") { @@ -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 @@ -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 @@ -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 } @@ -77,7 +80,8 @@ function ValidateErpMaterialTab { $erpMaterial = $dsWindow.FindName("DataGrid").DataContext if ($erpMaterial.Number) { $entityUnlocked = $true - } else { + } + else { $entityUnlocked = IsEntityUnlocked } @@ -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 @@ -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 = "" @@ -177,7 +185,8 @@ 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) @@ -185,7 +194,8 @@ function RefreshView { $vwCtx = New-Object Connectivity.Explorer.Framework.LocationContext($cItemRevExpObj) $navCtx = New-Object Connectivity.Explorer.Framework.LocationContext($cItemMaster) - } else { + } + else { return } @@ -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 @@ -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' diff --git a/Files/powerEvents/Events/ErpService.Lifecycle.ps1 b/Files/powerEvents/Events/ErpService.Lifecycle.ps1 index e004290..3489084 100644 --- a/Files/powerEvents/Events/ErpService.Lifecycle.ps1 +++ b/Files/powerEvents/Events/ErpService.Lifecycle.ps1 @@ -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 } @@ -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" } @@ -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 @@ -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 diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpBomManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpBomManager.cs index d64cee2..1d55670 100644 --- a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpBomManager.cs +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpBomManager.cs @@ -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().Find(header => header.Number == number).FirstOrDefault(); - if(bomHeader != null) + if (bomHeader != null) bomHeader.BomRows = GetBomRowsByHeaderNumber(bomHeader.Number); return bomHeader; }); @@ -30,7 +30,7 @@ List 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; } diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpItemManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpItemManager.cs index 5d1aab8..8cd0ac5 100644 --- a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpItemManager.cs +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpItemManager.cs @@ -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().Find(material => material.Number == number)).FirstOrDefault(); } @@ -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(); diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/IErpManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/IErpManager.cs index ae51cdf..a814050 100644 --- a/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/IErpManager.cs +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/IErpManager.cs @@ -12,11 +12,11 @@ public interface IErpManager : IDisposable bool Connect(ErpLogin login); // Material functionality - Material GetMaterialByNumber(string number); + Material GetMaterialyByNumber(string number); IEnumerable SearchMaterials(IEnumerable query); Material CreateMaterial(Material material); Material UpdateMaterial(Material material); - + // Documents functionality Document GetDocumentMetadata(string number); Document CreateDocumentMetadata(Document documentMetadata); diff --git a/Files/powerGatePlugin/ErpServices/Metadata/BomHeader.cs b/Files/powerGatePlugin/ErpServices/Metadata/BomHeader.cs index 8f7739d..094ffcb 100644 --- a/Files/powerGatePlugin/ErpServices/Metadata/BomHeader.cs +++ b/Files/powerGatePlugin/ErpServices/Metadata/BomHeader.cs @@ -21,7 +21,7 @@ public string Link set => _ = value; } - public List BomRows { get; set; } + public List BomRows { get; set; } public BomHeader() { diff --git a/Files/powerGatePlugin/ErpServices/Metadata/Material.cs b/Files/powerGatePlugin/ErpServices/Metadata/Material.cs index f87f99f..04b52a9 100644 --- a/Files/powerGatePlugin/ErpServices/Metadata/Material.cs +++ b/Files/powerGatePlugin/ErpServices/Metadata/Material.cs @@ -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 { diff --git a/Files/powerGatePlugin/ErpServices/Services/BomRows.cs b/Files/powerGatePlugin/ErpServices/Services/BomRows.cs index 5b76759..6926713 100644 --- a/Files/powerGatePlugin/ErpServices/Services/BomRows.cs +++ b/Files/powerGatePlugin/ErpServices/Services/BomRows.cs @@ -10,8 +10,10 @@ namespace ErpServices.Services { - public class BomRows : ErpBaseService + public class BomRows : ErpBaseService { + static readonly ILog Log = + LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); public override string Name => "BomRows"; public BomRows(IErpManager erpManager) : base(erpManager) @@ -26,7 +28,7 @@ public override IEnumerable Query(IExpression 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(); } diff --git a/Files/powerGatePlugin/ErpServices/Services/Documents.cs b/Files/powerGatePlugin/ErpServices/Services/Documents.cs index 0ca4aea..4393806 100644 --- a/Files/powerGatePlugin/ErpServices/Services/Documents.cs +++ b/Files/powerGatePlugin/ErpServices/Services/Documents.cs @@ -13,6 +13,8 @@ namespace ErpServices.Services { public class Documents : ErpBaseService, IStreamableServiceMethod { + static readonly ILog Log = + LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); public override string Name => "Documents"; public Documents(IErpManager erpManager) : base(erpManager) diff --git a/Files/powerGatePlugin/ErpServices/Services/ErpBaseService.cs b/Files/powerGatePlugin/ErpServices/Services/ErpBaseService.cs index f23d5a5..9667d20 100644 --- a/Files/powerGatePlugin/ErpServices/Services/ErpBaseService.cs +++ b/Files/powerGatePlugin/ErpServices/Services/ErpBaseService.cs @@ -8,7 +8,7 @@ namespace ErpServices.Services { - public abstract class ErpBaseService : ServiceMethod + public abstract class ErpBaseService : ServiceMethod { protected IErpManager ErpManager; diff --git a/Files/powerGatePlugin/ErpServices/Services/Materials.cs b/Files/powerGatePlugin/ErpServices/Services/Materials.cs index b3e3e5c..e818d4c 100644 --- a/Files/powerGatePlugin/ErpServices/Services/Materials.cs +++ b/Files/powerGatePlugin/ErpServices/Services/Materials.cs @@ -23,7 +23,7 @@ public override IEnumerable Query(IExpression 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 }; diff --git a/Files/powerGatePlugin/ErpServices/WebService.cs b/Files/powerGatePlugin/ErpServices/WebService.cs index a221657..e58c758 100644 --- a/Files/powerGatePlugin/ErpServices/WebService.cs +++ b/Files/powerGatePlugin/ErpServices/WebService.cs @@ -16,7 +16,8 @@ public class WebService : powerGateServer.SDK.WebService { static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - + + public WebService() { var erpStorageConfiguration = GetErpStorageConfiguration(); @@ -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)); @@ -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!");