1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 07:33:04 +01:00
invoiceninja/app/Ninja/Import/FreshBooks/InvoiceTransformer.php

44 lines
1.3 KiB
PHP
Raw Normal View History

2015-11-18 15:40:50 +01:00
<?php namespace App\Ninja\Import\FreshBooks;
2015-11-17 14:53:14 +01:00
2015-12-08 11:10:20 +01:00
use App\Ninja\Import\BaseTransformer;
2015-11-18 15:40:50 +01:00
use League\Fractal\Resource\Item;
2015-11-17 14:53:14 +01:00
/**
* Class InvoiceTransformer
*/
2015-12-08 11:10:20 +01:00
class InvoiceTransformer extends BaseTransformer
2015-11-17 14:53:14 +01:00
{
/**
* @param $data
* @return bool|Item
*/
2015-12-08 11:10:20 +01:00
public function transform($data)
2015-11-18 15:40:50 +01:00
{
2015-12-08 11:10:20 +01:00
if ( ! $this->getClientId($data->organization)) {
2015-11-18 15:40:50 +01:00
return false;
}
2015-11-17 14:53:14 +01:00
2015-12-08 11:10:20 +01:00
if ($this->hasInvoice($data->invoice_number)) {
2015-11-18 15:40:50 +01:00
return false;
}
2015-11-17 14:53:14 +01:00
2015-12-08 11:10:20 +01:00
return new Item($data, function ($data) {
2015-11-17 14:53:14 +01:00
return [
2015-12-08 11:10:20 +01:00
'client_id' => $this->getClientId($data->organization),
2015-12-10 14:35:40 +01:00
'invoice_number' => $this->getInvoiceNumber($data->invoice_number),
'paid' => (float) $data->paid,
2016-01-06 08:52:26 +01:00
'po_number' => $this->getString($data, 'po_number'),
'terms' => $this->getString($data, 'terms'),
2015-11-18 15:40:50 +01:00
'invoice_date_sql' => $data->create_date,
2015-11-17 14:53:14 +01:00
'invoice_items' => [
[
2015-12-22 13:06:53 +01:00
'product_key' => '',
2016-01-06 08:52:26 +01:00
'notes' => $this->getString($data, 'notes'),
2015-11-18 15:40:50 +01:00
'cost' => (float) $data->amount,
'qty' => 1,
2015-11-17 14:53:14 +01:00
]
],
];
});
}
}