diff --git a/app/Models/Account.php b/app/Models/Account.php index 8dd1f3d0a4..2a156c4b3c 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -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++; diff --git a/app/Ninja/Import/BaseTransformer.php b/app/Ninja/Import/BaseTransformer.php index 541dd84ff8..375f489e8f 100644 --- a/app/Ninja/Import/BaseTransformer.php +++ b/app/Ninja/Import/BaseTransformer.php @@ -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]); } diff --git a/app/Ninja/Import/CSV/InvoiceTransformer.php b/app/Ninja/Import/CSV/InvoiceTransformer.php index e85adf9049..d9c1228572 100644 --- a/app/Ninja/Import/CSV/InvoiceTransformer.php +++ b/app/Ninja/Import/CSV/InvoiceTransformer.php @@ -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, diff --git a/app/Ninja/Import/FreshBooks/InvoiceTransformer.php b/app/Ninja/Import/FreshBooks/InvoiceTransformer.php index de8c0a0520..d2389beaf8 100644 --- a/app/Ninja/Import/FreshBooks/InvoiceTransformer.php +++ b/app/Ninja/Import/FreshBooks/InvoiceTransformer.php @@ -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, diff --git a/app/Ninja/Import/Harvest/InvoiceTransformer.php b/app/Ninja/Import/Harvest/InvoiceTransformer.php index 216d074695..c8c5a3b9d9 100644 --- a/app/Ninja/Import/Harvest/InvoiceTransformer.php +++ b/app/Ninja/Import/Harvest/InvoiceTransformer.php @@ -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' => [ diff --git a/app/Ninja/Import/Hiveage/InvoiceTransformer.php b/app/Ninja/Import/Hiveage/InvoiceTransformer.php index e1a110698f..b13dc3d056 100644 --- a/app/Ninja/Import/Hiveage/InvoiceTransformer.php +++ b/app/Ninja/Import/Hiveage/InvoiceTransformer.php @@ -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' => [ diff --git a/app/Ninja/Import/Invoiceable/InvoiceTransformer.php b/app/Ninja/Import/Invoiceable/InvoiceTransformer.php index 078ce7956e..dc16a9352a 100644 --- a/app/Ninja/Import/Invoiceable/InvoiceTransformer.php +++ b/app/Ninja/Import/Invoiceable/InvoiceTransformer.php @@ -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, diff --git a/app/Ninja/Import/Ronin/ClientTransformer.php b/app/Ninja/Import/Ronin/ClientTransformer.php new file mode 100644 index 0000000000..0dbf6eb519 --- /dev/null +++ b/app/Ninja/Import/Ronin/ClientTransformer.php @@ -0,0 +1,28 @@ +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, + ], + ], + ]; + }); + } +} diff --git a/app/Ninja/Import/Ronin/InvoiceTransformer.php b/app/Ninja/Import/Ronin/InvoiceTransformer.php new file mode 100644 index 0000000000..9829774ffd --- /dev/null +++ b/app/Ninja/Import/Ronin/InvoiceTransformer.php @@ -0,0 +1,36 @@ +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, + ] + ], + ]; + }); + } +} \ No newline at end of file diff --git a/app/Ninja/Import/Ronin/PaymentTransformer.php b/app/Ninja/Import/Ronin/PaymentTransformer.php new file mode 100644 index 0000000000..c041014562 --- /dev/null +++ b/app/Ninja/Import/Ronin/PaymentTransformer.php @@ -0,0 +1,19 @@ + (float) $data->total - (float) $data->balance, + 'payment_date_sql' => $data->date_paid, + 'client_id' => $data->client_id, + 'invoice_id' => $data->invoice_id, + ]; + }); + } +} \ No newline at end of file diff --git a/app/Services/ImportService.php b/app/Services/ImportService.php index 818f4abc7f..960ce2dc0b 100644 --- a/app/Services/ImportService.php +++ b/app/Services/ImportService.php @@ -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); }