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-10 15:35:40 +02:00
parent 653394e33f
commit 1783cb5129
11 changed files with 102 additions and 13 deletions

View File

@ -443,7 +443,7 @@ class Account extends Eloquent
// confirm the invoice number isn't already taken
do {
$number = $prefix.str_pad($counter, 4, '0', STR_PAD_LEFT);
$number = $prefix . str_pad($counter, 4, '0', STR_PAD_LEFT);
$check = Invoice::scope(false, $this->id)->whereInvoiceNumber($number)->withTrashed()->first();
$counter++;
$counterOffset++;

View File

@ -55,9 +55,15 @@ class BaseTransformer extends TransformerAbstract
return $name[1];
}
protected function getInvoiceNumber($number)
{
$number = strtolower($number);
return str_pad($number, 4, '0', STR_PAD_LEFT);
}
protected function hasInvoice($invoiceNumber)
{
$invoiceNumber = strtolower($invoiceNumber);
$invoiceNumber = $this->getInvoiceNumber($invoiceNumber);
return isset($this->maps[ENTITY_INVOICE][$invoiceNumber]);
}

View File

@ -17,9 +17,9 @@ class InvoiceTransformer extends BaseTransformer
return new Item($data, function ($data) {
return [
'invoice_number' => isset($data->invoice_number) ? $data->invoice_number : null,
'paid' => isset($data->paid) ? (float) $data->paid : null,
'client_id' => $this->getClientId($data->name),
'invoice_number' => isset($data->invoice_number) ? $this->getInvoiceNumber($data->invoice_number) : null,
'paid' => isset($data->paid) ? (float) $data->paid : null,
'po_number' => isset($data->po_number) ? $data->po_number : null,
'terms' => isset($data->terms) ? $data->terms : null,
'public_notes' => isset($data->notes) ? $data->notes : null,

View File

@ -17,9 +17,9 @@ class InvoiceTransformer extends BaseTransformer
return new Item($data, function ($data) {
return [
'invoice_number' => $data->invoice_number,
'paid' => (float) $data->paid,
'client_id' => $this->getClientId($data->organization),
'invoice_number' => $this->getInvoiceNumber($data->invoice_number),
'paid' => (float) $data->paid,
'po_number' => $data->po_number,
'terms' => $data->terms,
'public_notes' => $data->notes,

View File

@ -17,9 +17,9 @@ class InvoiceTransformer extends BaseTransformer
return new Item($data, function ($data) {
return [
'invoice_number' => $data->id,
'paid' => (float) $data->paid_amount,
'client_id' => $this->getClientId($data->client),
'invoice_number' => $this->getInvoiceNumber($data->id),
'paid' => (float) $data->paid_amount,
'po_number' => $data->po_number,
'invoice_date_sql' => $this->getDate($data->issue_date, 'm/d/Y'),
'invoice_items' => [

View File

@ -17,9 +17,9 @@ class InvoiceTransformer extends BaseTransformer
return new Item($data, function ($data) {
return [
'invoice_number' => $data->statement_no,
'paid' => (float) $data->paid_total,
'client_id' => $this->getClientId($data->client),
'invoice_number' => $this->getInvoiceNumber($data->statement_no),
'paid' => (float) $data->paid_total,
'invoice_date_sql' => $this->getDate($data->date),
'due_date_sql' => $this->getDate($data->due_date),
'invoice_items' => [

View File

@ -18,7 +18,7 @@ class InvoiceTransformer extends BaseTransformer
return new Item($data, function ($data) {
return [
'client_id' => $this->getClientId($data->client_name),
'invoice_number' => $data->ref,
'invoice_number' => $this->getInvoiceNumber($data->ref),
'po_number' => $data->po_number,
'invoice_date_sql' => $data->date,
'due_date_sql' => $data->due_date,

View File

@ -0,0 +1,28 @@
<?php namespace App\Ninja\Import\Ronin;
use App\Ninja\Import\BaseTransformer;
use League\Fractal\Resource\Item;
class ClientTransformer extends BaseTransformer
{
public function transform($data)
{
if ($this->hasClient($data->company)) {
return false;
}
return new Item($data, function ($data) {
return [
'name' => $data->company,
'work_phone' => $data->phone,
'contacts' => [
[
'first_name' => $this->getFirstName($data->name),
'last_name' => $this->getLastName($data->name),
'email' => $data->email,
],
],
];
});
}
}

View File

@ -0,0 +1,36 @@
<?php namespace App\Ninja\Import\Ronin;
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->number)) {
return false;
}
return new Item($data, function ($data) {
return [
'client_id' => $this->getClientId($data->client),
'invoice_number' => $this->getInvoiceNumber($data->number),
'paid' => (float) $data->total - (float) $data->balance,
'public_notes' => $data->subject,
'invoice_date_sql' => $data->date_sent,
'due_date_sql' => $data->date_due,
'invoice_items' => [
[
'notes' => $data->line_item,
'cost' => (float) $data->total,
'qty' => 1,
]
],
];
});
}
}

View File

@ -0,0 +1,19 @@
<?php namespace App\Ninja\Import\Ronin;
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->total - (float) $data->balance,
'payment_date_sql' => $data->date_paid,
'client_id' => $data->client_id,
'invoice_id' => $data->invoice_id,
];
});
}
}

View File

@ -38,7 +38,7 @@ class ImportService
IMPORT_HIVEAGE,
IMPORT_INVOICEABLE,
//IMPORT_NUTCACHE,
//IMPORT_RONIN,
IMPORT_RONIN,
//IMPORT_WAVE,
//IMPORT_ZOHO,
];
@ -108,7 +108,7 @@ class ImportService
$entity = $this->{"{$entityType}Repo"}->save($data);
// if the invoice is paid we'll also create a payment record
if ($entityType === ENTITY_INVOICE && isset($data['paid']) && $data['paid']) {
if ($entityType === ENTITY_INVOICE && isset($data['paid']) && $data['paid'] > 0) {
$this->createPayment($source, $row, $maps, $data['client_id'], $entity->id);
}