invoiceninja/app/Ninja/Import/Harvest/InvoiceTransformer.php

47 lines
1.2 KiB
PHP
Raw Normal View History

2017-01-30 21:40:43 +02:00
<?php
namespace App\Ninja\Import\Harvest;
2015-12-08 12:10:20 +02:00
use App\Ninja\Import\BaseTransformer;
use League\Fractal\Resource\Item;
/**
2017-01-30 21:40:43 +02:00
* Class InvoiceTransformer.
*/
2015-12-08 12:10:20 +02:00
class InvoiceTransformer extends BaseTransformer
{
/**
* @param $data
2017-01-30 21:40:43 +02:00
*
* @return bool|Item
*/
2015-12-08 12:10:20 +02:00
public function transform($data)
{
2017-01-30 18:05:31 +02:00
if (! $this->getClientId($data->client)) {
return false;
}
2015-12-08 12:10:20 +02:00
if ($this->hasInvoice($data->id)) {
return false;
}
2015-12-08 12:10:20 +02:00
return new Item($data, function ($data) {
return [
2015-12-08 12:10:20 +02:00
'client_id' => $this->getClientId($data->client),
2015-12-10 15:35:40 +02:00
'invoice_number' => $this->getInvoiceNumber($data->id),
'paid' => (float) $data->paid_amount,
2016-01-06 09:52:26 +02:00
'po_number' => $this->getString($data, 'po_number'),
2017-01-15 21:48:31 +02:00
'invoice_date_sql' => $this->getDate($data, 'issue_date'),
'invoice_items' => [
[
2015-12-22 14:06:53 +02:00
'product_key' => '',
2016-01-06 09:52:26 +02:00
'notes' => $this->getString($data, 'subject'),
'cost' => (float) $data->invoice_amount,
'qty' => 1,
2017-01-30 21:40:43 +02:00
],
],
];
});
}
2017-01-15 21:48:31 +02:00
}