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