mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-08-05 11:10:16 -04:00
Working on data import
This commit is contained in:
parent
5547f222e1
commit
c5c5ff3458
@ -45,7 +45,10 @@ class BaseTransformer extends TransformerAbstract
|
|||||||
|
|
||||||
protected function getDate($date, $format = 'Y-m-d')
|
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;
|
return $date ? $date->format('Y-m-d') : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
35
app/Ninja/Import/Nutcache/ClientTransformer.php
Normal file
35
app/Ninja/Import/Nutcache/ClientTransformer.php
Normal 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,
|
||||||
|
];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
38
app/Ninja/Import/Nutcache/InvoiceTransformer.php
Normal file
38
app/Ninja/Import/Nutcache/InvoiceTransformer.php
Normal 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,
|
||||||
|
]
|
||||||
|
],
|
||||||
|
];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
19
app/Ninja/Import/Nutcache/PaymentTransformer.php
Normal file
19
app/Ninja/Import/Nutcache/PaymentTransformer.php
Normal 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,
|
||||||
|
];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
29
app/Ninja/Import/Nutcache/TaskTransformer.php
Normal file
29
app/Ninja/Import/Nutcache/TaskTransformer.php
Normal 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,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
@ -6,11 +6,13 @@ class ArraySerializer extends FractalArraySerializer
|
|||||||
{
|
{
|
||||||
public function collection($resourceKey, array $data)
|
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)
|
public function item($resourceKey, array $data)
|
||||||
{
|
{
|
||||||
return ($resourceKey && $resourceKey !== 'data') ? array($resourceKey => $data) : $data;
|
return $data;
|
||||||
|
//return ($resourceKey && $resourceKey !== 'data') ? array($resourceKey => $data) : $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ class ImportService
|
|||||||
IMPORT_HARVEST,
|
IMPORT_HARVEST,
|
||||||
IMPORT_HIVEAGE,
|
IMPORT_HIVEAGE,
|
||||||
IMPORT_INVOICEABLE,
|
IMPORT_INVOICEABLE,
|
||||||
//IMPORT_NUTCACHE,
|
IMPORT_NUTCACHE,
|
||||||
IMPORT_RONIN,
|
IMPORT_RONIN,
|
||||||
IMPORT_WAVE,
|
IMPORT_WAVE,
|
||||||
IMPORT_ZOHO,
|
IMPORT_ZOHO,
|
||||||
|
@ -113,7 +113,7 @@ class PaymentLibrariesSeeder extends Seeder
|
|||||||
['name' => 'Hong Kong Dollar', 'code' => 'HKD', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
|
['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' => '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' => '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' => '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' => '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' => '.'],
|
['name' => 'Chinese Renminbi', 'code' => 'CNY', 'symbol' => 'RMB ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user