Last active
August 29, 2015 14:18
-
-
Save peaeater/6fba1abf5f5454b700b8 to your computer and use it in GitHub Desktop.
Convert Harvest timer CSV export to Quickbooks import format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
Peter Tyrrell, 2015 | |
Convert Harvest time report to Quickbooks import format in Windows-1252. | |
#> | |
param ( | |
[string]$indir = ".", | |
[string]$outdir = $indir | |
) | |
if (!(test-path $outdir)) { | |
mkdir $outdir | |
} | |
$files = ls "$indir\*.*" -include *.csv | |
$header = [ordered]@{ | |
"!TIMERHDR" = "TIMERHDR" | |
"VER" = "6" | |
"REL" = "0" | |
"COMPANYNAME" = "Andornot Consulting Inc." | |
"IMPORTEDBEFORE" = "N" | |
"FROMTIMER" = "Y" | |
"COMPANYCREATETIME" = "1015362067" | |
} | |
foreach ($file in $files) { | |
$rows = @() | |
$row = $null | |
$csv = import-csv $file.FullName | |
foreach ($line in $csv) { | |
# transform incoming properties | |
$timeact = "TIMEACT" | |
$date = $($line.Date) -replace "(\d{2})/(\d{2})/\d{2}(\d{2})", '$1/$2/$3' # MM/dd/yyyy => MM/dd/yy | |
$job = ('{0}: {1} {2}' -f $($line.Client), $($line."Project Code"), $($line.Project)) | |
$employee = ('{0} {1}' -f $($line."First Name"), $($line."Last Name")) | |
$item = $($line.Task) | |
$pitem = "" | |
$duration = $($line."Hours Rounded") | |
$project = $($line.Project) | |
$note = $($line.Notes) | |
$transfer = "" | |
$status = $($line."Billable?") # Yes => 1, No => 0 | |
$status = $status -replace "Yes", '1' | |
$status = $status -replace "No", '0' | |
# create row object | |
$hash = [ordered]@{ | |
"!TIMEACT" = $timeact | |
"DATE" = $date | |
"JOB" = $job | |
"EMP" = $employee | |
"ITEM" = $item | |
"PITEM" = $pitem | |
"DURATION" = $duration | |
"PROJ" = $project | |
"NOTE" = $note | |
"XFERTOPAYROLL" = $transfer | |
"BILLINGSTATUS" = $status | |
} | |
$row = new-object PSObject -Property $hash | |
$rows += $row | |
} | |
$out = ('{0}\{1}.iif' -f $outdir, $file.BaseName) | |
echo $out | |
# write output file | |
$head = convertto-csv (new-object PSObject -Property $header) -NoTypeInformation -Delimiter "`t" | % {$_ -replace '"', ''} | |
$body = $rows | convertto-csv -NoTypeInformation -Delimiter "`t" | % {$_ -replace '"', ''} | |
set-content "$out" $head, $body -Encoding Default | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment