From bbee51b852ebde9caa847bf1dc6c47d42f459729 Mon Sep 17 00:00:00 2001 From: Casper Bakker Date: Tue, 24 Feb 2015 12:50:56 +0100 Subject: [PATCH] Fix for Xero formatting --- src/KnabToXero/KnabExtractor.php | 2 ++ src/KnabToXero/XeroCsvCreator.php | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/KnabToXero/KnabExtractor.php b/src/KnabToXero/KnabExtractor.php index eab6b85..8654595 100644 --- a/src/KnabToXero/KnabExtractor.php +++ b/src/KnabToXero/KnabExtractor.php @@ -102,6 +102,8 @@ private function cleanCell($cellName, $value) $value = str_replace(',', '.', $value); } + $value = str_replace(',', '', $value); + if ($cellName == 'date' || $cellName == 'currency-date') { $value = date('Y-m-d', strtotime($value)); diff --git a/src/KnabToXero/XeroCsvCreator.php b/src/KnabToXero/XeroCsvCreator.php index e36208b..c57df53 100644 --- a/src/KnabToXero/XeroCsvCreator.php +++ b/src/KnabToXero/XeroCsvCreator.php @@ -4,18 +4,27 @@ class XeroCsvCreator { + private $config = array( + 'csv-delimiter' => ',', + 'csv-enclosure' => '' + ); + public function createCsv(XeroRecordCollection $records) { $csv = []; - $csv[] = '"Date";"Amount";"Payee";"Description";"Reference"'; + $csv[] = $this->config['csv-enclosure'] . 'Date' . $this->config['csv-enclosure'] . $this->config['csv-delimiter'] . + $this->config['csv-enclosure'] . 'Amount' . $this->config['csv-enclosure'] . $this->config['csv-delimiter'] . + $this->config['csv-enclosure'] . 'Payee' . $this->config['csv-enclosure'] . $this->config['csv-delimiter'] . + $this->config['csv-enclosure'] . 'Description' . $this->config['csv-enclosure'] . $this->config['csv-delimiter'] . + $this->config['csv-enclosure'] . 'Reference' . $this->config['csv-enclosure'] . $this->config['csv-delimiter']; foreach ($records as $record) { - $row = '"' . $record->getXeroStyleDate() . '"'; - $row .= ';"' . $record->getAmount() . '"'; - $row .= ';"' . $record->getPayee() . '"'; - $row .= ';"' . $record->getDescription() . '"'; - $row .= ';"' . $record->getReference() . '"'; + $row = $this->config['csv-enclosure'] . $record->getXeroStyleDate() . $this->config['csv-enclosure']; + $row .= $this->config['csv-delimiter'] . $this->config['csv-enclosure'] . $record->getAmount() . $this->config['csv-enclosure']; + $row .= $this->config['csv-delimiter'] . $this->config['csv-enclosure'] . $record->getPayee() . $this->config['csv-enclosure']; + $row .= $this->config['csv-delimiter'] . $this->config['csv-enclosure'] . $record->getDescription() . $this->config['csv-enclosure']; + $row .= $this->config['csv-delimiter'] . $this->config['csv-enclosure'] . $record->getReference() . $this->config['csv-enclosure']; $csv[] = $row; }