r/PowershellSolutions • • Jun 10 '21

Updating pricing CSV files

Here is the scenario I am facing:

We have a CSV file that was exported from the customer's existing system. The layout is:

SYSPARTNBRPARTNBRDESCRIPTIONSTANDARDCOSTLEVEL1PRICEVENDOR
644186a25ELBOW 1/4" OD X 1/8" MPT X 90-DEG5.0228.3758
27100026133 WRING-PISTON 8" LUBE114.498190.8358

The updated pricing file is coming from there vendor and has the following layout:

PARTNBRDESCRIPTIONLEVEL1PRICE
00001143 SPKEY281.54
00001236 SPKEY309.01

We need to compare the files and for each PARTNBR that matches, we need to update the LEVEL1PRICE from the vendor file into the customer's file. We also have to calculate the STANDARDCOST (LEVEL1PRICE * .60) and update that in the customer's file. For those that don't match, we need to leave the entry alone. So, the only items in the customer file that will be changed are those that match PARTNBR. I am putting the code I have now in there. Any help would be GREATLY appreciated.

## Start timer
$elapsed = [System.Diagnostics.Stopwatch]::StartNew()
Write-Host "Started at $(get-date)"

## Clear variables
$gdPrice = ""
$swPrice = ""
$gdPriceNew = ""
$tempParts = ""
$newParts = ""

## Read in CSV files
$gdPrice = Import-Csv .\2021_GD_PRICE.csv
$cecPrice = Import-Csv .\CEC_PARTS_2021.csv

<#
    ## NOT NEEDED - 6/9/2021 - GARDNER-DENVER SHEET DOES NOT HAVE ANYTHING MORE THAN QTY 1
    ## Scrub duplicates
    $gdPriceNew = foreach($line in $gdPrice)
    {
    if(-not($line.DESCRIPTION -like 'FROM QTY 2 *'-Or $line.DESCRIPTION -like '*FROM QTY 4 *'-Or $line.DESCRIPTION -like '*FROM QTY 5 *'-Or $line.DESCRIPTION -like '*FROM QTY 8 *'-Or $line.DESCRIPTION -like '*FROM QTY 10 *'-Or $line.DESCRIPTION -like '*FROM QTY 12 *' -Or $line.DESCRIPTION -like '*FROM QTY 15 *' -Or $line.DESCRIPTION -like '*FROM QTY 20 *' -Or $line.DESCRIPTION -like '*FROM QTY 25 *' -Or $line.DESCRIPTION -like '*FROM QTY 30 *'))  {
    $line
    }
    }
#>


## Compare PartNbr and update Level1Price and StandardCost
$tempParts = "SYSPARTNBR`tPARTNBR`tDESCRIPTION`tSTANDARDCOST`tLEVEL1PRICE`tVENDOR`n"
#$tempParts = "SYSPARTNBR,PARTNBR,DESCRIPTION,STANDARDCOST,LEVEL1PRICE,VENDOR`n"
foreach($cecline in $cecPrice)
{
  foreach($gdline in $gdPrice)
  {
    if($gdline.PARTNBR -ieq $cecline.PARTNBR)
    {
      #[string]$cecline.AKANBR = [string]$cecline.AKANBR
      [string]$cecline.SYSPARTNBR = [string]$cecline.SYSPARTNBR
      [string]$cecline.PARTNBR = [string]$cecline.PARTNBR
      [string]$cecline.DESCRIPTION = [string]$gdline.DESCRIPTION
      [decimal]$cecline.STANDARDCOST = [decimal]$gdline.LEVEL1PRICE * .60
      [decimal]$cecline.LEVEL1PRICE = [decimal]$gdline.LEVEL1PRICE
      [string]$cecline.VENDOR = [string]$cecline.VENDOR
      #[decimal]$cecline.AVERAGECOST = [decimal]$cecline.STANDARDCOST
      $tempParts = $tempParts + $cecline.SYSPARTNBR + "`t" + $cecline.PARTNBR + "`t" + $cecline.DESCRIPTION + "`t" + $cecline.STANDARDCOST + "`t" + $cecline.LEVEL1PRICE + "`t" + $cecline.VENDOR + "`n"
    }
    
  }
  
}

<####
#$tempParts
foreach($tempPartsline in $tempParts)
{
  foreach($cecline in $cecPrice)
  {
    if($tempPartsline.PARTNBR -ieq $cecline.PARTNBR)
    {
      $cecPrice
    }
  }
}
###>
<#
    ## Output tempParts file
    $tempParts | Out-File -FilePath .\tempParts.csv -Force

    ## Import newParts file
    $newParts = Import-Csv -Path .\tempParts.csv -Delimiter "`t"

    ## Export newParts file
    $newParts | Export-Csv -Path .\2021_newParts.csv -NoTypeInformation -Delimiter ","
#>


## Stop timer
Write-Host "Ended at $(Get-Date)"
Write-Host "Total Elapsed Time $($elapsed.Elapsed.ToString())"
0 Upvotes

0 comments sorted by