Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
christiangessner committed Jul 24, 2020
1 parent 9305088 commit b99494f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#known limitations:
#https://support.coolorange.com/support/solutions/articles/22000243916-same-bomrows-do-not-update-status
function Get-BomRows($entity) {
$bomRows = Get-VaultBomRowsForEntity -Entity $entity
$bomRows = GetVaultBomRows -Entity $entity
return $bomRows
}

Expand Down Expand Up @@ -80,7 +80,7 @@ function Transfer-Items($entities) {
}

function Check-Boms($entityBoms) {
$differences = Get-VaultToErpBomsDifferences -VaultBomHeaders $entityBoms
$differences = CompareErpBoms -entityBoms $entityBoms
foreach($diff in $differences){
if($diff.Status -eq "Remove" -and $diff.Parent) {
$remove = Add-BomWindowEntity -Parent $diff.Parent -Type BomRow -Properties $diff.AffectedObject
Expand Down
54 changes: 33 additions & 21 deletions Files/powerEvents/Events/ErpService.Lifecycle.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@
$supportedPdfExtensions = @("idw", "dwg")
$requiresErpItemExtensions = @("iam", "ipn", "ipt")

function CheckVaultBom {
param(
$bomHeader
)

$bomHeaders = @($bomHeader)
$differences = Get-VaultToErpBomsDifferences -VaultBomHeaders $bomHeaders
function CheckVaultBom($entity) {
$differences = CompareErpBoms -EntityBoms @($entity)
foreach($diff in $differences){
if ($diff.Status -ne "Identical" -and $diff.IsHeader) {
throw $diff.Message
Expand All @@ -43,20 +38,20 @@ function RestrictFileRelease($files) {
continue
}

if ($file._Extension -eq 'iam') {
$bomRows = Get-VaultBomRowsForEntity -Entity $file
if (-not $file.Children) {
Add-Member -InputObject $file -Name "Children" -Value $bomRows -MemberType NoteProperty -Force
} else {
$file.Children = $bomRows
}
try {
CheckVaultBom -bomHeader $file
} catch {
$restrictMessage = "$($_)! Please open the BOM dialog"
Add-VaultRestriction -EntityName $file._Name -Message $restrictMessage
}
$bomRows = GetVaultBomRows -Entity $file
if (-not $bomRows) { continue }

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

try {
CheckVaultBom $file
} catch {
$restrictMessage = "$($_)! Please open the BOM dialog"
Add-VaultRestriction -EntityName $file._Name -Message $restrictMessage
}
}
}
Expand All @@ -82,6 +77,23 @@ function RestrictItemRelease($items) {
if (-not $erpMaterial -or $false -eq $erpMaterial) {
$restrictMessage = "An item with the number '$($item._Number)' does not exist in the ERP system."
Add-VaultRestriction -EntityName ($item._Name) -Message $restrictMessage
continue
}

$bomRows = GetVaultBomRows -Entity $item
if (-not $bomRows) { continue }

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

try {
CheckVaultBom $item
} catch {
$restrictMessage = "$($_)! Please open the BOM dialog"
Add-VaultRestriction -EntityName $item._Number -Message $restrictMessage
}
}
}
Expand Down
21 changes: 10 additions & 11 deletions Files/powerGate/Modules/BomFunctions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ function RemoveErpBomRow($parentNumber, $childNumber, $position) {
#endregion

#region Common Bom comparison logic

function Get-VaultBomRowsForEntity {
function GetVaultBomRows {
param($entity)

if ($null -eq $entity._EntityTypeID) { return @() }
Expand All @@ -124,8 +123,8 @@ function Get-VaultBomRowsForEntity {
#if($entity._FullPath -eq $null) { return @() } #due to a bug in the beta version.
$bomRows = Get-VaultFileBom -File $entity._FullPath -GetChildrenBy LatestVersion
} else {
if ($entity._Category -eq 'Part') { return @() }
$bomRows = Get-VaultItemBom -Number $entity._Number
#if ($entity._Category -eq 'Part') { return @() }
$bomRows = @(Get-VaultItemBom -Number $entity._Number)
}

foreach ($entityBomRow in $bomRows) {
Expand All @@ -141,17 +140,17 @@ function Get-VaultBomRowsForEntity {
return $bomRows
}


function Get-VaultToErpBomsDifferences {
param($vaultBomHeaders)
function CompareErpBoms {
param($entityBoms)

$differences = @()
[array]::Reverse($vaultBomHeaders)
[array]::Reverse($entityBoms)

foreach ($entityBom in $vaultBomHeaders) {
foreach ($entityBom in $entityBoms) {
$number = GetEntityNumber -entity $entityBom
$erpBomHeader = GetErpBomHeader -number $number
if (-not $erBomHeader -or $false -eq $erpBomHeader) {
Show-Inspector
if (-not $erpBomHeader -or $false -eq $erpBomHeader) {
$differences += New-Object -Type PsObject -Property @{AffectedObject = $entityBom; Status = "New"; Message = "BOM does not exist in ERP"; IsHeader = $true}
foreach ($entityBomRow in $entityBom.Children) {
$childNumber = GetEntityNumber -entity $entityBomRow
Expand Down Expand Up @@ -214,4 +213,4 @@ function Get-VaultToErpBomsDifferences {
return ,$differences
}

#endregion
#endregion

0 comments on commit b99494f

Please sign in to comment.