2015-12-07 22:41:48 +01:00
|
|
|
<?php namespace App\Ninja\Import\Harvest;
|
|
|
|
|
2015-12-08 11:10:20 +01:00
|
|
|
use App\Ninja\Import\BaseTransformer;
|
2015-12-07 22:41:48 +01:00
|
|
|
use League\Fractal\Resource\Item;
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* Class InvoiceTransformer
|
|
|
|
*/
|
2015-12-08 11:10:20 +01:00
|
|
|
class InvoiceTransformer extends BaseTransformer
|
2015-12-07 22:41:48 +01:00
|
|
|
{
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @param $data
|
|
|
|
* @return bool|Item
|
|
|
|
*/
|
2015-12-08 11:10:20 +01:00
|
|
|
public function transform($data)
|
2015-12-07 22:41:48 +01:00
|
|
|
{
|
2015-12-08 11:10:20 +01:00
|
|
|
if ( ! $this->getClientId($data->client)) {
|
2015-12-07 22:41:48 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-08 11:10:20 +01:00
|
|
|
if ($this->hasInvoice($data->id)) {
|
2015-12-07 22:41:48 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-08 11:10:20 +01:00
|
|
|
return new Item($data, function ($data) {
|
2015-12-07 22:41:48 +01:00
|
|
|
return [
|
2015-12-08 11:10:20 +01:00
|
|
|
'client_id' => $this->getClientId($data->client),
|
2015-12-10 14:35:40 +01:00
|
|
|
'invoice_number' => $this->getInvoiceNumber($data->id),
|
|
|
|
'paid' => (float) $data->paid_amount,
|
2016-01-06 08:52:26 +01:00
|
|
|
'po_number' => $this->getString($data, 'po_number'),
|
2015-12-08 11:10:20 +01:00
|
|
|
'invoice_date_sql' => $this->getDate($data->issue_date, 'm/d/Y'),
|
2015-12-07 22:41:48 +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, 'subject'),
|
2015-12-07 22:41:48 +01:00
|
|
|
'cost' => (float) $data->invoice_amount,
|
|
|
|
'qty' => 1,
|
|
|
|
]
|
|
|
|
],
|
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|