mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Working on data import
This commit is contained in:
parent
653394e33f
commit
1783cb5129
@ -443,7 +443,7 @@ class Account extends Eloquent
|
|||||||
|
|
||||||
// confirm the invoice number isn't already taken
|
// confirm the invoice number isn't already taken
|
||||||
do {
|
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();
|
$check = Invoice::scope(false, $this->id)->whereInvoiceNumber($number)->withTrashed()->first();
|
||||||
$counter++;
|
$counter++;
|
||||||
$counterOffset++;
|
$counterOffset++;
|
||||||
|
@ -55,9 +55,15 @@ class BaseTransformer extends TransformerAbstract
|
|||||||
return $name[1];
|
return $name[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getInvoiceNumber($number)
|
||||||
|
{
|
||||||
|
$number = strtolower($number);
|
||||||
|
return str_pad($number, 4, '0', STR_PAD_LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
protected function hasInvoice($invoiceNumber)
|
protected function hasInvoice($invoiceNumber)
|
||||||
{
|
{
|
||||||
$invoiceNumber = strtolower($invoiceNumber);
|
$invoiceNumber = $this->getInvoiceNumber($invoiceNumber);
|
||||||
return isset($this->maps[ENTITY_INVOICE][$invoiceNumber]);
|
return isset($this->maps[ENTITY_INVOICE][$invoiceNumber]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,9 +17,9 @@ class InvoiceTransformer extends BaseTransformer
|
|||||||
|
|
||||||
return new Item($data, function ($data) {
|
return new Item($data, function ($data) {
|
||||||
return [
|
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),
|
'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,
|
'po_number' => isset($data->po_number) ? $data->po_number : null,
|
||||||
'terms' => isset($data->terms) ? $data->terms : null,
|
'terms' => isset($data->terms) ? $data->terms : null,
|
||||||
'public_notes' => isset($data->notes) ? $data->notes : null,
|
'public_notes' => isset($data->notes) ? $data->notes : null,
|
||||||
|
@ -17,9 +17,9 @@ class InvoiceTransformer extends BaseTransformer
|
|||||||
|
|
||||||
return new Item($data, function ($data) {
|
return new Item($data, function ($data) {
|
||||||
return [
|
return [
|
||||||
'invoice_number' => $data->invoice_number,
|
|
||||||
'paid' => (float) $data->paid,
|
|
||||||
'client_id' => $this->getClientId($data->organization),
|
'client_id' => $this->getClientId($data->organization),
|
||||||
|
'invoice_number' => $this->getInvoiceNumber($data->invoice_number),
|
||||||
|
'paid' => (float) $data->paid,
|
||||||
'po_number' => $data->po_number,
|
'po_number' => $data->po_number,
|
||||||
'terms' => $data->terms,
|
'terms' => $data->terms,
|
||||||
'public_notes' => $data->notes,
|
'public_notes' => $data->notes,
|
||||||
|
@ -17,9 +17,9 @@ class InvoiceTransformer extends BaseTransformer
|
|||||||
|
|
||||||
return new Item($data, function ($data) {
|
return new Item($data, function ($data) {
|
||||||
return [
|
return [
|
||||||
'invoice_number' => $data->id,
|
|
||||||
'paid' => (float) $data->paid_amount,
|
|
||||||
'client_id' => $this->getClientId($data->client),
|
'client_id' => $this->getClientId($data->client),
|
||||||
|
'invoice_number' => $this->getInvoiceNumber($data->id),
|
||||||
|
'paid' => (float) $data->paid_amount,
|
||||||
'po_number' => $data->po_number,
|
'po_number' => $data->po_number,
|
||||||
'invoice_date_sql' => $this->getDate($data->issue_date, 'm/d/Y'),
|
'invoice_date_sql' => $this->getDate($data->issue_date, 'm/d/Y'),
|
||||||
'invoice_items' => [
|
'invoice_items' => [
|
||||||
|
@ -17,9 +17,9 @@ class InvoiceTransformer extends BaseTransformer
|
|||||||
|
|
||||||
return new Item($data, function ($data) {
|
return new Item($data, function ($data) {
|
||||||
return [
|
return [
|
||||||
'invoice_number' => $data->statement_no,
|
|
||||||
'paid' => (float) $data->paid_total,
|
|
||||||
'client_id' => $this->getClientId($data->client),
|
'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),
|
'invoice_date_sql' => $this->getDate($data->date),
|
||||||
'due_date_sql' => $this->getDate($data->due_date),
|
'due_date_sql' => $this->getDate($data->due_date),
|
||||||
'invoice_items' => [
|
'invoice_items' => [
|
||||||
|
@ -18,7 +18,7 @@ class InvoiceTransformer extends BaseTransformer
|
|||||||
return new Item($data, function ($data) {
|
return new Item($data, function ($data) {
|
||||||
return [
|
return [
|
||||||
'client_id' => $this->getClientId($data->client_name),
|
'client_id' => $this->getClientId($data->client_name),
|
||||||
'invoice_number' => $data->ref,
|
'invoice_number' => $this->getInvoiceNumber($data->ref),
|
||||||
'po_number' => $data->po_number,
|
'po_number' => $data->po_number,
|
||||||
'invoice_date_sql' => $data->date,
|
'invoice_date_sql' => $data->date,
|
||||||
'due_date_sql' => $data->due_date,
|
'due_date_sql' => $data->due_date,
|
||||||
|
28
app/Ninja/Import/Ronin/ClientTransformer.php
Normal file
28
app/Ninja/Import/Ronin/ClientTransformer.php
Normal 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,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
36
app/Ninja/Import/Ronin/InvoiceTransformer.php
Normal file
36
app/Ninja/Import/Ronin/InvoiceTransformer.php
Normal 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,
|
||||||
|
]
|
||||||
|
],
|
||||||
|
];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
19
app/Ninja/Import/Ronin/PaymentTransformer.php
Normal file
19
app/Ninja/Import/Ronin/PaymentTransformer.php
Normal 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,
|
||||||
|
];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -38,7 +38,7 @@ class ImportService
|
|||||||
IMPORT_HIVEAGE,
|
IMPORT_HIVEAGE,
|
||||||
IMPORT_INVOICEABLE,
|
IMPORT_INVOICEABLE,
|
||||||
//IMPORT_NUTCACHE,
|
//IMPORT_NUTCACHE,
|
||||||
//IMPORT_RONIN,
|
IMPORT_RONIN,
|
||||||
//IMPORT_WAVE,
|
//IMPORT_WAVE,
|
||||||
//IMPORT_ZOHO,
|
//IMPORT_ZOHO,
|
||||||
];
|
];
|
||||||
@ -108,7 +108,7 @@ class ImportService
|
|||||||
$entity = $this->{"{$entityType}Repo"}->save($data);
|
$entity = $this->{"{$entityType}Repo"}->save($data);
|
||||||
|
|
||||||
// if the invoice is paid we'll also create a payment record
|
// 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);
|
$this->createPayment($source, $row, $maps, $data['client_id'], $entity->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user