1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 20:52:56 +01:00

Improvements to CSV import

This commit is contained in:
Hillel Coren 2017-01-15 21:48:31 +02:00
parent dda0ca8a8c
commit 93898e0efe
10 changed files with 26 additions and 20 deletions

View File

@ -1,5 +1,6 @@
<?php namespace App\Ninja\Import;
use Carbon;
use Utils;
use DateTime;
use League\Fractal\TransformerAbstract;
@ -128,10 +129,14 @@ class BaseTransformer extends TransformerAbstract
* @param string $format
* @return null
*/
public function getDate($date, $format = 'Y-m-d')
public function getDate($data, $field)
{
if ( ! $date instanceof DateTime) {
$date = DateTime::createFromFormat($format, $date);
if ($date = data_get($data, $field)) {
try {
$date = new Carbon($date);
} catch (Exception $e) {
// if we fail to parse return blank
}
}
return $date ? $date->format('Y-m-d') : null;

View File

@ -30,7 +30,8 @@ class InvoiceTransformer extends BaseTransformer
'po_number' => $this->getString($data, 'po_number'),
'terms' => $this->getString($data, 'terms'),
'public_notes' => $this->getString($data, 'public_notes'),
'invoice_date_sql' => isset($data->invoice_date) ? $data->invoice_date : null,
'invoice_date_sql' => $this->getDate($data, 'invoice_date'),
'due_date_sql' => $this->getDate($data, 'due_date'),
'invoice_items' => [
[
'product_key' => '',

View File

@ -28,7 +28,7 @@ class InvoiceTransformer extends BaseTransformer
'invoice_number' => $this->getInvoiceNumber($data->id),
'paid' => (float) $data->paid_amount,
'po_number' => $this->getString($data, 'po_number'),
'invoice_date_sql' => $this->getDate($data->issue_date, 'm/d/Y'),
'invoice_date_sql' => $this->getDate($data, 'issue_date'),
'invoice_items' => [
[
'product_key' => '',
@ -40,4 +40,4 @@ class InvoiceTransformer extends BaseTransformer
];
});
}
}
}

View File

@ -17,10 +17,10 @@ class PaymentTransformer extends BaseTransformer
return new Item($data, function ($data) {
return [
'amount' => $data->paid_amount,
'payment_date_sql' => $this->getDate($data->last_payment_date, 'm/d/Y'),
'payment_date_sql' => $this->getDate($data, 'last_payment_date'),
'client_id' => $data->client_id,
'invoice_id' => $data->invoice_id,
];
});
}
}
}

View File

@ -27,8 +27,8 @@ class InvoiceTransformer extends BaseTransformer
'client_id' => $this->getClientId($data->client),
'invoice_number' => $this->getInvoiceNumber($data->statement_no),
'paid' => (float) $data->paid_total,
'invoice_date_sql' => $this->getDate($data->date),
'due_date_sql' => $this->getDate($data->due_date),
'invoice_date_sql' => $this->getDate($data, 'date'),
'due_date_sql' => $this->getDate($data, 'due_date'),
'invoice_items' => [
[
'product_key' => '',
@ -40,4 +40,4 @@ class InvoiceTransformer extends BaseTransformer
];
});
}
}
}

View File

@ -17,7 +17,7 @@ class PaymentTransformer extends BaseTransformer
return new Item($data, function ($data) {
return [
'amount' => $data->paid_total,
'payment_date_sql' => $this->getDate($data->last_paid_on),
'payment_date_sql' => $this->getDate($data, 'last_paid_on'),
'client_id' => $data->client_id,
'invoice_id' => $data->invoice_id,
];

View File

@ -30,8 +30,8 @@ class InvoiceTransformer extends BaseTransformer
'po_number' => $this->getString($data, 'purchase_order'),
'terms' => $this->getString($data, 'terms'),
'public_notes' => $this->getString($data, 'notes'),
'invoice_date_sql' => $this->getDate($data->date),
'due_date_sql' => $this->getDate($data->due_date),
'invoice_date_sql' => $this->getDate($data, 'date'),
'due_date_sql' => $this->getDate($data, 'due_date'),
'invoice_items' => [
[
'product_key' => '',
@ -43,4 +43,4 @@ class InvoiceTransformer extends BaseTransformer
];
});
}
}
}

View File

@ -17,7 +17,7 @@ class PaymentTransformer extends BaseTransformer
return new Item($data, function ($data) {
return [
'amount' => (float) $data->paid_to_date,
'payment_date_sql' => $this->getDate($data->date),
'payment_date_sql' => $this->getDate($data, 'date'),
'client_id' => $data->client_id,
'invoice_id' => $data->invoice_id,
];

View File

@ -27,8 +27,8 @@ class InvoiceTransformer extends BaseTransformer
'client_id' => $this->getClientId($data->customer),
'invoice_number' => $this->getInvoiceNumber($data->invoice_num),
'po_number' => $this->getString($data, 'po_so'),
'invoice_date_sql' => $this->getDate($data->invoice_date),
'due_date_sql' => $this->getDate($data->due_date),
'invoice_date_sql' => $this->getDate($data, 'invoice_date'),
'due_date_sql' => $this->getDate($data, 'due_date'),
'paid' => 0,
'invoice_items' => [
[
@ -41,4 +41,4 @@ class InvoiceTransformer extends BaseTransformer
];
});
}
}
}

View File

@ -21,7 +21,7 @@ class PaymentTransformer extends BaseTransformer
return new Item($data, function ($data) {
return [
'amount' => (float) $data->amount,
'payment_date_sql' => $this->getDate($data->payment_date),
'payment_date_sql' => $this->getDate($data, 'payment_date'),
'client_id' => $this->getInvoiceClientId($data->invoice_num),
'invoice_id' => $this->getInvoiceId($data->invoice_num),
];