Skip to content

Instantly share code, notes, and snippets.

@sido
Last active December 15, 2015 09:49
Show Gist options
  • Save sido/5241024 to your computer and use it in GitHub Desktop.
Save sido/5241024 to your computer and use it in GitHub Desktop.
A little script I wrote to import my PayPal transactions into Knab.nl. It ain't pretty, but it works. The account can't be an email address like PayPal uses, so I replaced it with a number. Also the account wil be recognized as ABN, not PayPal.
#!/usr/local/bin/php
<?php
print "Convert Paypal export to Knab readable import\n";
$account = '000000001'; // Can't be an email address
$dataIn = file_get_contents('Downloaden.csv');
$data = array();
$dataOut = "";
foreach (explode("\n", $dataIn) as $row) {
if ( !empty($row) )
array_push($data, str_getcsv($row));
}
unset($data[0]); // remove header
$i = 0;
foreach ($data as $key => $value) {
$date = explode('-', $value[0]);
$date = "{$date[2]}{$date[1]}{$date[0]}";
$start = str_ireplace('.', ',', round(floatval(str_ireplace(',', '.', $value[9])) - floatval(str_ireplace(',', '.', $value[7])), 2).'');
$desc = str_pad($value[3], 65);
$newLine = $key>1?"\n":'';
$dataOut .= "{$newLine}{$account}\t{$value[6]}\t{$date}\t{$start}\t{$value[9]}\t{$date}\t{$value[7]}\t{$desc}";
$i++;
}
file_put_contents('knab-import.txt', $dataOut);
print "Found {$i} transactions.\nDone!\n\n\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment