1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-23 09:51:35 +02:00
invoiceninja/app/Ninja/Import/FreshBooks/InvoiceTransformer.php

40 lines
1.2 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
use League\Fractal\TransformerAbstract;
2015-11-18 15:40:50 +01:00
use League\Fractal\Resource\Item;
use App\Models\Client;
2015-11-17 14:53:14 +01:00
class InvoiceTransformer extends TransformerAbstract
{
2015-11-18 15:40:50 +01:00
public function transform($data, $maps)
{
if (isset($maps[ENTITY_INVOICE][$data->invoice_number])) {
return false;
}
2015-11-17 14:53:14 +01:00
2015-11-18 15:40:50 +01:00
if (isset($maps[ENTITY_CLIENT][$data->organization])) {
$data->client_id = $maps[ENTITY_CLIENT][$data->organization];
} else {
return false;
}
2015-11-17 14:53:14 +01:00
2015-11-18 15:40:50 +01:00
return new Item($data, function ($data) use ($maps) {
2015-11-17 14:53:14 +01:00
return [
2015-11-18 15:40:50 +01:00
'invoice_number' => $data->invoice_number,
'paid' => (float) $data->paid,
'client_id' => (int) $data->client_id,
'po_number' => $data->po_number,
'terms' => $data->terms,
'public_notes' => $data->notes,
'invoice_date_sql' => $data->create_date,
2015-11-17 14:53:14 +01:00
'invoice_items' => [
[
2015-11-18 15:40:50 +01:00
'notes' => $data->notes,
'cost' => (float) $data->amount,
'qty' => 1,
2015-11-17 14:53:14 +01:00
]
],
];
});
}
}