1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 00:11:35 +02:00

Working on data import

This commit is contained in:
Hillel Coren 2015-12-14 22:07:48 +02:00
parent 5547f222e1
commit c5c5ff3458
8 changed files with 131 additions and 5 deletions

View File

@ -45,7 +45,10 @@ class BaseTransformer extends TransformerAbstract
protected function getDate($date, $format = 'Y-m-d')
{
$date = DateTime::createFromFormat($format, $date);
if ( ! $date instanceof DateTime) {
$date = DateTime::createFromFormat($format, $date);
}
return $date ? $date->format('Y-m-d') : null;
}

View File

@ -0,0 +1,35 @@
<?php namespace App\Ninja\Import\Nutcache;
use App\Ninja\Import\BaseTransformer;
use League\Fractal\Resource\Item;
class ClientTransformer extends BaseTransformer
{
public function transform($data)
{
if ($this->hasClient($data->name)) {
return false;
}
return new Item($data, function ($data) {
return [
'name' => $data->name,
'city' => isset($data->city) ? $data->city : '',
'state' => isset($data->city) ? $data->stateprovince : '',
'id_number' => isset($data->registration_number) ? $data->registration_number : '',
'postal_code' => isset($data->postalzip_code) ? $data->postalzip_code : '',
'private_notes' => isset($data->notes) ? $data->notes : '',
'work_phone' => isset($data->phone) ? $data->phone : '',
'contacts' => [
[
'first_name' => isset($data->contact_name) ? $this->getFirstName($data->contact_name) : '',
'last_name' => isset($data->contact_name) ? $this->getLastName($data->contact_name) : '',
'email' => $data->email,
'phone' => isset($data->mobile) ? $data->mobile : '',
],
],
'country_id' => isset($data->country) ? $this->getCountryId($data->country) : null,
];
});
}
}

View File

@ -0,0 +1,38 @@
<?php namespace App\Ninja\Import\Nutcache;
use App\Ninja\Import\BaseTransformer;
use League\Fractal\Resource\Item;
class InvoiceTransformer extends BaseTransformer
{
public function transform($data)
{
if ( ! $this->getClientId($data->client)) {
return false;
}
if ($this->hasInvoice($data->document_no)) {
return false;
}
return new Item($data, function ($data) {
return [
'client_id' => $this->getClientId($data->client),
'invoice_number' => $this->getInvoiceNumber($data->document_no),
'paid' => (float) $data->paid_to_date,
'po_number' => $data->purchase_order,
'terms' => $data->terms,
'public_notes' => $data->notes,
'invoice_date_sql' => $this->getDate($data->date),
'due_date_sql' => $this->getDate($data->due_date),
'invoice_items' => [
[
'notes' => $data->description,
'cost' => (float) $data->total,
'qty' => 1,
]
],
];
});
}
}

View File

@ -0,0 +1,19 @@
<?php namespace App\Ninja\Import\Nutcache;
use App\Ninja\Import\BaseTransformer;
use League\Fractal\Resource\Item;
class PaymentTransformer extends BaseTransformer
{
public function transform($data, $maps)
{
return new Item($data, function ($data) use ($maps) {
return [
'amount' => (float) $data->paid_to_date,
'payment_date_sql' => $this->getDate($data->date),
'client_id' => $data->client_id,
'invoice_id' => $data->invoice_id,
];
});
}
}

View File

@ -0,0 +1,29 @@
<?php namespace App\Ninja\Import\FreshBooks;
use App\Ninja\Import\BaseTransformer;
use League\Fractal\Resource\Item;
/*
class TaskTransformer extends BaseTransformer
{
public function transform($data)
{
// start by converting to seconds
$seconds = ($data->hours * 3600);
$timeLogFinish = strtotime($data->date);
$timeLogStart = intval($timeLogFinish - $seconds);
$timeLog[] = [];
$timelog[] = $timeLogStart;
$timelog[] = $timeLogFinish;
$timeLog = json_encode(array($timelog));
return [
'action' => 'stop',
'time_log' => $timeLog,
'description' => $data->task,
];
}
}
*/

View File

@ -6,11 +6,13 @@ class ArraySerializer extends FractalArraySerializer
{
public function collection($resourceKey, array $data)
{
return ($resourceKey && $resourceKey !== 'data') ? array($resourceKey => $data) : $data;
return $data;
//return ($resourceKey && $resourceKey !== 'data') ? array($resourceKey => $data) : $data;
}
public function item($resourceKey, array $data)
{
return ($resourceKey && $resourceKey !== 'data') ? array($resourceKey => $data) : $data;
return $data;
//return ($resourceKey && $resourceKey !== 'data') ? array($resourceKey => $data) : $data;
}
}

View File

@ -37,7 +37,7 @@ class ImportService
IMPORT_HARVEST,
IMPORT_HIVEAGE,
IMPORT_INVOICEABLE,
//IMPORT_NUTCACHE,
IMPORT_NUTCACHE,
IMPORT_RONIN,
IMPORT_WAVE,
IMPORT_ZOHO,

View File

@ -113,7 +113,7 @@ class PaymentLibrariesSeeder extends Seeder
['name' => 'Hong Kong Dollar', 'code' => 'HKD', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['name' => 'Indonesian Rupiah', 'code' => 'IDR', 'symbol' => 'Rp', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['name' => 'Mexican Peso', 'code' => 'MXN', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['name' => 'Egyptian Pound', 'code' => 'EGP', 'symbol' => '£', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['name' => 'Egyptian Pound', 'code' => 'EGP', 'symbol' => 'E£', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['name' => 'Colombian Peso', 'code' => 'COP', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','],
['name' => 'West African Franc', 'code' => 'XOF', 'symbol' => 'CFA ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['name' => 'Chinese Renminbi', 'code' => 'CNY', 'symbol' => 'RMB ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],