mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Improve Import Support
* Add support for payment imports * Add support for Wave Invoice import * Add ability to merge invoice line items into a single invoice
This commit is contained in:
parent
dbf2ec5e13
commit
5932a837dd
@ -64,10 +64,22 @@ class BaseTransformer extends TransformerAbstract
|
|||||||
return str_pad($number, 4, '0', STR_PAD_LEFT);
|
return str_pad($number, 4, '0', STR_PAD_LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getInvoiceId($invoiceNumber)
|
||||||
|
{
|
||||||
|
$invoiceNumber = $this->getInvoiceNumber($invoiceNumber);
|
||||||
|
return isset($this->maps[ENTITY_INVOICE][$invoiceNumber]) ? $this->maps[ENTITY_INVOICE][$invoiceNumber] : null;
|
||||||
|
}
|
||||||
|
|
||||||
protected function hasInvoice($invoiceNumber)
|
protected function hasInvoice($invoiceNumber)
|
||||||
{
|
{
|
||||||
$invoiceNumber = $this->getInvoiceNumber($invoiceNumber);
|
$invoiceNumber = $this->getInvoiceNumber($invoiceNumber);
|
||||||
return isset($this->maps[ENTITY_INVOICE][$invoiceNumber]);
|
return isset($this->maps[ENTITY_INVOICE][$invoiceNumber]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getInvoiceClientId($invoiceNumber)
|
||||||
|
{
|
||||||
|
$invoiceNumber = $this->getInvoiceNumber($invoiceNumber);
|
||||||
|
return isset($this->maps[ENTITY_INVOICE.'_'.ENTITY_CLIENT][$invoiceNumber])? $this->maps[ENTITY_INVOICE.'_'.ENTITY_CLIENT][$invoiceNumber] : null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -12,7 +12,7 @@ class PaymentTransformer extends BaseTransformer
|
|||||||
'amount' => $data->paid,
|
'amount' => $data->paid,
|
||||||
'payment_date_sql' => isset($data->invoice_date) ? $data->invoice_date : null,
|
'payment_date_sql' => isset($data->invoice_date) ? $data->invoice_date : null,
|
||||||
'client_id' => $data->client_id,
|
'client_id' => $data->client_id,
|
||||||
'invoice_id' => $data->invoice_id,
|
'invoice_id' => $this->getInvoiceId($data->invoice_id),
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ class PaymentTransformer extends BaseTransformer
|
|||||||
'amount' => $data->paid,
|
'amount' => $data->paid,
|
||||||
'payment_date_sql' => $data->create_date,
|
'payment_date_sql' => $data->create_date,
|
||||||
'client_id' => $data->client_id,
|
'client_id' => $data->client_id,
|
||||||
'invoice_id' => $data->invoice_id,
|
'invoice_id' => $this->getInvoiceId($data->invoice_id),
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ class PaymentTransformer extends BaseTransformer
|
|||||||
'amount' => $data->paid_amount,
|
'amount' => $data->paid_amount,
|
||||||
'payment_date_sql' => $this->getDate($data->last_payment_date, 'm/d/Y'),
|
'payment_date_sql' => $this->getDate($data->last_payment_date, 'm/d/Y'),
|
||||||
'client_id' => $data->client_id,
|
'client_id' => $data->client_id,
|
||||||
'invoice_id' => $data->invoice_id,
|
'invoice_id' => $this->getInvoiceId($data->invoice_id),
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ class PaymentTransformer extends BaseTransformer
|
|||||||
'amount' => $data->paid_total,
|
'amount' => $data->paid_total,
|
||||||
'payment_date_sql' => $this->getDate($data->last_paid_on),
|
'payment_date_sql' => $this->getDate($data->last_paid_on),
|
||||||
'client_id' => $data->client_id,
|
'client_id' => $data->client_id,
|
||||||
'invoice_id' => $data->invoice_id,
|
'invoice_id' => $this->getInvoiceId($data->invoice_id),
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ class PaymentTransformer extends BaseTransformer
|
|||||||
'amount' => $data->paid,
|
'amount' => $data->paid,
|
||||||
'payment_date_sql' => $data->date_paid,
|
'payment_date_sql' => $data->date_paid,
|
||||||
'client_id' => $data->client_id,
|
'client_id' => $data->client_id,
|
||||||
'invoice_id' => $data->invoice_id,
|
'invoice_id' => $this->getInvoiceId($data->invoice_id),
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ class PaymentTransformer extends BaseTransformer
|
|||||||
'amount' => (float) $data->paid_to_date,
|
'amount' => (float) $data->paid_to_date,
|
||||||
'payment_date_sql' => $this->getDate($data->date),
|
'payment_date_sql' => $this->getDate($data->date),
|
||||||
'client_id' => $data->client_id,
|
'client_id' => $data->client_id,
|
||||||
'invoice_id' => $data->invoice_id,
|
'invoice_id' => $this->getInvoiceId($data->invoice_id),
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ class PaymentTransformer extends BaseTransformer
|
|||||||
'amount' => (float) $data->total - (float) $data->balance,
|
'amount' => (float) $data->total - (float) $data->balance,
|
||||||
'payment_date_sql' => $data->date_paid,
|
'payment_date_sql' => $data->date_paid,
|
||||||
'client_id' => $data->client_id,
|
'client_id' => $data->client_id,
|
||||||
'invoice_id' => $data->invoice_id,
|
'invoice_id' => $this->getInvoiceId($data->invoice_id),
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
37
app/Ninja/Import/Wave/InvoiceTransformer.php
Normal file
37
app/Ninja/Import/Wave/InvoiceTransformer.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php namespace App\Ninja\Import\Wave;
|
||||||
|
|
||||||
|
use App\Ninja\Import\BaseTransformer;
|
||||||
|
use League\Fractal\Resource\Item;
|
||||||
|
|
||||||
|
class InvoiceTransformer extends BaseTransformer
|
||||||
|
{
|
||||||
|
public function transform($data)
|
||||||
|
{
|
||||||
|
if ( ! $this->getClientId($data->customer)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->hasInvoice($data->invoice_num)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Item($data, function ($data) {
|
||||||
|
return [
|
||||||
|
'client_id' => $this->getClientId($data->customer),
|
||||||
|
'invoice_number' => $this->getInvoiceNumber($data->invoice_num),
|
||||||
|
'po_number' => $data->po_so,
|
||||||
|
'invoice_date_sql' => $this->getDate($data->invoice_date),
|
||||||
|
'due_date_sql' => $this->getDate($data->due_date),
|
||||||
|
'paid' => 0,
|
||||||
|
'invoice_items' => [
|
||||||
|
[
|
||||||
|
'product_key' => $data->product,
|
||||||
|
'notes' => $data->description,
|
||||||
|
'cost' => (float) $data->amount,
|
||||||
|
'qty' => (float) $data->quantity,
|
||||||
|
]
|
||||||
|
],
|
||||||
|
];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
23
app/Ninja/Import/Wave/PaymentTransformer.php
Normal file
23
app/Ninja/Import/Wave/PaymentTransformer.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php namespace App\Ninja\Import\Wave;
|
||||||
|
|
||||||
|
use App\Ninja\Import\BaseTransformer;
|
||||||
|
use League\Fractal\Resource\Item;
|
||||||
|
|
||||||
|
class PaymentTransformer extends BaseTransformer
|
||||||
|
{
|
||||||
|
public function transform($data, $maps)
|
||||||
|
{
|
||||||
|
if ( ! $this->getInvoiceClientId($data->invoice_num)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Item($data, function ($data) use ($maps) {
|
||||||
|
return [
|
||||||
|
'amount' => (float) $data->amount,
|
||||||
|
'payment_date_sql' => $this->getDate($data->payment_date),
|
||||||
|
'client_id' => $this->getInvoiceClientId($data->invoice_num),
|
||||||
|
'invoice_id' => $this->getInvoiceId($data->invoice_num),
|
||||||
|
];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -73,15 +73,10 @@ class ImportService
|
|||||||
RESULT_FAILURE => [],
|
RESULT_FAILURE => [],
|
||||||
];
|
];
|
||||||
|
|
||||||
Excel::load($file, function ($reader) use ($source, $entityType, &$results) {
|
|
||||||
$this->checkData($entityType, count($reader->all()));
|
$this->checkData($entityType, count($reader->all()));
|
||||||
$maps = $this->createMaps();
|
$maps = $this->createMaps();
|
||||||
|
|
||||||
$reader->each(function ($row) use ($source, $entityType, $maps, &$results) {
|
|
||||||
$result = $this->saveData($source, $entityType, $row, $maps);
|
|
||||||
|
|
||||||
if ($result) {
|
|
||||||
$results[RESULT_SUCCESS][] = $result;
|
|
||||||
} else {
|
} else {
|
||||||
$results[RESULT_FAILURE][] = $row;
|
$results[RESULT_FAILURE][] = $row;
|
||||||
}
|
}
|
||||||
@ -108,7 +103,6 @@ class ImportService
|
|||||||
$invoice = Invoice::createNew();
|
$invoice = Invoice::createNew();
|
||||||
$data['invoice_number'] = $account->getNextInvoiceNumber($invoice);
|
$data['invoice_number'] = $account->getNextInvoiceNumber($invoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->validate($source, $data, $entityType) !== true) {
|
if ($this->validate($source, $data, $entityType) !== true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -240,6 +240,7 @@ return array(
|
|||||||
'deleted_invoices' => 'Successfully deleted :count invoices',
|
'deleted_invoices' => 'Successfully deleted :count invoices',
|
||||||
|
|
||||||
'created_payment' => 'Successfully created payment',
|
'created_payment' => 'Successfully created payment',
|
||||||
|
'created_payments' => 'Successfully created :count payment(s)',
|
||||||
'archived_payment' => 'Successfully archived payment',
|
'archived_payment' => 'Successfully archived payment',
|
||||||
'archived_payments' => 'Successfully archived :count payments',
|
'archived_payments' => 'Successfully archived :count payments',
|
||||||
'deleted_payment' => 'Successfully deleted payment',
|
'deleted_payment' => 'Successfully deleted payment',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user