Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
Fix for Xero formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
casperbakker committed Feb 24, 2015
1 parent 3a49af5 commit bbee51b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/KnabToXero/KnabExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
21 changes: 15 additions & 6 deletions src/KnabToXero/XeroCsvCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit bbee51b

Please sign in to comment.