1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 00:11:35 +02:00
invoiceninja/app/Ninja/Import/CSV/InvoiceTransformer.php

38 lines
1.4 KiB
PHP
Raw Normal View History

2015-11-24 20:45:38 +01:00
<?php namespace App\Ninja\Import\CSV;
2015-12-08 11:10:20 +01:00
use App\Ninja\Import\BaseTransformer;
2015-11-24 20:45:38 +01:00
use League\Fractal\Resource\Item;
2015-12-08 11:10:20 +01:00
class InvoiceTransformer extends BaseTransformer
2015-11-24 20:45:38 +01:00
{
2015-12-08 11:10:20 +01:00
public function transform($data)
2015-11-24 20:45:38 +01:00
{
2015-12-08 11:10:20 +01:00
if ( ! $this->getClientId($data->name)) {
2015-11-24 20:45:38 +01:00
return false;
}
2015-11-24 21:41:08 +01:00
2015-12-08 11:10:20 +01:00
if (isset($data->invoice_number) && $this->hasInvoice($data->invoice_number)) {
2015-11-24 20:45:38 +01:00
return false;
}
2015-12-08 11:10:20 +01:00
return new Item($data, function ($data) {
2015-11-24 20:45:38 +01:00
return [
2015-12-08 11:10:20 +01:00
'client_id' => $this->getClientId($data->name),
2015-12-10 14:35:40 +01:00
'invoice_number' => isset($data->invoice_number) ? $this->getInvoiceNumber($data->invoice_number) : null,
'paid' => isset($data->paid) ? (float) $data->paid : null,
2015-11-24 20:45:38 +01:00
'po_number' => isset($data->po_number) ? $data->po_number : null,
'terms' => isset($data->terms) ? $data->terms : null,
'public_notes' => isset($data->notes) ? $data->notes : null,
2015-11-24 21:41:08 +01:00
'invoice_date_sql' => isset($data->invoice_date) ? $data->invoice_date : null,
2015-11-24 20:45:38 +01:00
'invoice_items' => [
[
2015-12-22 13:06:53 +01:00
'product_key' => '',
2015-11-24 20:45:38 +01:00
'notes' => isset($data->notes) ? $data->notes : null,
'cost' => isset($data->amount) ? (float) $data->amount : null,
'qty' => 1,
]
],
];
});
}
}