Skip to content

Instantly share code, notes, and snippets.

@salgo
Last active June 6, 2017 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save salgo/8604879bd362c25f1c50a9a6f35e62e4 to your computer and use it in GitHub Desktop.
Save salgo/8604879bd362c25f1c50a9a6f35e62e4 to your computer and use it in GitHub Desktop.
Convert Barclaycard commercial to freeagent CSV format
<?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