Last active
June 6, 2017 14:24
-
-
Save salgo/8604879bd362c25f1c50a9a6f35e62e4 to your computer and use it in GitHub Desktop.
Convert Barclaycard commercial to freeagent CSV 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 | |
$row = 0; | |
if ($argc != 4) { | |
die('Expected 3 arguments: php convert.php $input_file $output_file $after_date' . "\n"); | |
} | |
date_default_timezone_set('Europe/London'); | |
$input = $argv[1]; | |
$output = $argv[2]; | |
$after_date = DateTime::createFromFormat('d/m/Y|', $argv[3]); | |
if (($handle = fopen($input, 'r')) !== FALSE && ($ohandle = fopen($output, 'w'))) { | |
while (($data = fgetcsv($handle, 2000, ",")) !== FALSE) { | |
if (count($data) != 21) { | |
die('Expected 21 columns'); | |
} | |
$row++; | |
if ($row == 1) { | |
continue; | |
} | |
$date = DateTime::createFromFormat('d/m/Y|', $data[2]); | |
if ($date < $after_date) { | |
echo "Skipping because " . $date->format('d/m/Y') . " is before " . $after_date->format('d/m/Y') . "\n"; | |
continue; | |
} | |
$value = $data[4] * -1; | |
$new = [ | |
$date->format('d/m/Y'), $value, $data[3] | |
]; | |
fputcsv($ohandle, $new); | |
} | |
fclose($handle); | |
fclose($ohandle); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment