2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Ninja\Import\CSV;
|
2016-10-02 09:10:28 +02:00
|
|
|
|
2018-04-15 12:02:40 +02:00
|
|
|
use Utils;
|
2016-10-02 09:10:28 +02:00
|
|
|
use App\Ninja\Import\BaseTransformer;
|
|
|
|
use League\Fractal\Resource\Item;
|
|
|
|
|
|
|
|
/**
|
2017-01-30 20:40:43 +01:00
|
|
|
* Class InvoiceTransformer.
|
2016-10-02 09:10:28 +02:00
|
|
|
*/
|
|
|
|
class ExpenseTransformer extends BaseTransformer
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param $data
|
2017-01-30 20:40:43 +01:00
|
|
|
*
|
2016-10-02 09:10:28 +02:00
|
|
|
* @return bool|Item
|
|
|
|
*/
|
|
|
|
public function transform($data)
|
|
|
|
{
|
|
|
|
return new Item($data, function ($data) {
|
2018-04-15 12:02:40 +02:00
|
|
|
$clientId = isset($data->client) ? $this->getClientId($data->client) : null;
|
|
|
|
|
2016-10-02 09:10:28 +02:00
|
|
|
return [
|
2016-12-22 18:17:45 +01:00
|
|
|
'amount' => $this->getFloat($data, 'amount'),
|
2016-10-02 09:10:28 +02:00
|
|
|
'vendor_id' => isset($data->vendor) ? $this->getVendorId($data->vendor) : null,
|
2018-04-15 12:02:40 +02:00
|
|
|
'client_id' => $clientId,
|
2016-10-02 09:10:28 +02:00
|
|
|
'expense_date' => isset($data->expense_date) ? date('Y-m-d', strtotime($data->expense_date)) : null,
|
|
|
|
'public_notes' => $this->getString($data, 'public_notes'),
|
2018-02-14 21:39:30 +01:00
|
|
|
'private_notes' => $this->getString($data, 'private_notes'),
|
2016-10-05 22:46:15 +02:00
|
|
|
'expense_category_id' => isset($data->expense_category) ? $this->getExpenseCategoryId($data->expense_category) : null,
|
2018-04-15 12:02:40 +02:00
|
|
|
'payment_type_id' => isset($data->payment_type) ? Utils::lookupIdInCache($data->payment_type, 'paymentTypes') : null,
|
|
|
|
'payment_date' => isset($data->payment_date) ? date('Y-m-d', strtotime($data->payment_date)) : null,
|
|
|
|
'transaction_reference' => $this->getString($data, 'transaction_reference'),
|
|
|
|
'should_be_invoiced' => $clientId ? true : false,
|
2016-10-02 09:10:28 +02:00
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|