Created
January 11, 2011 01:50
-
-
Save tjlytle/773861 to your computer and use it in GitHub Desktop.
Simple script to convert an oDesk export to Outright's expected format.
This file contains hidden or 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
<?php | |
$in = fopen($argv[1], 'r'); | |
$out = fopen('php://output', 'w'); | |
$fields = fgetcsv($in); | |
$map['date'] = 'Date'; | |
$map['description'] = 'Description'; | |
$map['payee'] = 'Employer'; | |
$map['amount'] = 'Amount'; | |
$map['category'] = 'Type'; | |
fputcsv($out, array_keys($map)); | |
$typeFilter = array('withdrawal', 'credit', 'payment'); | |
while($row = fgetcsv($in)){ | |
$row = array_combine($fields, $row); | |
if(in_array(strtolower($row['Type']), $typeFilter)){ | |
continue; | |
} | |
if('referral' == strtolower($row['Type'])){ | |
$row['Employer'] = 'oDesk'; | |
} | |
$row['Type'] = 'Sales'; | |
$row['Date'] = date('m/d/Y' , strtotime($row['Date'])); | |
$data = array(); | |
foreach($map as $name => $field){ | |
$data[] = $row[$field]; | |
} | |
fputcsv($out, $data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment