diff --git a/app/Http/Requests/CreatePaymentAPIRequest.php b/app/Http/Requests/CreatePaymentAPIRequest.php index 2292c5212e24..3c773b9450c6 100644 --- a/app/Http/Requests/CreatePaymentAPIRequest.php +++ b/app/Http/Requests/CreatePaymentAPIRequest.php @@ -30,7 +30,7 @@ class CreatePaymentAPIRequest extends PaymentRequest ]; } - $this->invoice = $invoice = Invoice::scope($this->invoice_id) + $this->invoice = $invoice = Invoice::scope($this->invoice_public_id ?: $this->invoice_id) ->withArchived() ->invoices() ->first(); diff --git a/app/Ninja/Import/BaseTransformer.php b/app/Ninja/Import/BaseTransformer.php index 63435b45d3bb..8018685a585b 100644 --- a/app/Ninja/Import/BaseTransformer.php +++ b/app/Ninja/Import/BaseTransformer.php @@ -259,10 +259,21 @@ class BaseTransformer extends TransformerAbstract { $invoiceNumber = $this->getInvoiceNumber($invoiceNumber); $invoiceNumber = strtolower($invoiceNumber); - return isset($this->maps[ENTITY_INVOICE][$invoiceNumber]) ? $this->maps[ENTITY_INVOICE][$invoiceNumber] : null; } + /** + * @param $invoiceNumber + * + * @return null + */ + public function getInvoicePublicId($invoiceNumber) + { + $invoiceNumber = $this->getInvoiceNumber($invoiceNumber); + $invoiceNumber = strtolower($invoiceNumber); + return isset($this->maps['invoices'][$invoiceNumber]) ? $this->maps['invoices'][$invoiceNumber]->public_id : null; + } + /** * @param $invoiceNumber * diff --git a/app/Ninja/Import/Wave/PaymentTransformer.php b/app/Ninja/Import/Wave/PaymentTransformer.php index 95ece47c7c2c..4b94a3b7fcda 100644 --- a/app/Ninja/Import/Wave/PaymentTransformer.php +++ b/app/Ninja/Import/Wave/PaymentTransformer.php @@ -27,6 +27,7 @@ class PaymentTransformer extends BaseTransformer 'payment_date_sql' => $this->getDate($data, 'payment_date'), 'client_id' => $this->getInvoiceClientId($data->invoice_num), 'invoice_id' => $this->getInvoiceId($data->invoice_num), + 'invoice_public_id' => $this->getInvoicePublicId($data->invoice_num), ]; }); } diff --git a/app/Services/ImportService.php b/app/Services/ImportService.php index 017ffe398b11..43366f2bfb9d 100644 --- a/app/Services/ImportService.php +++ b/app/Services/ImportService.php @@ -443,7 +443,9 @@ class ImportService // update the entity maps if ($entityType != ENTITY_CUSTOMER) { $mapFunction = 'add' . ucwords($entity->getEntityType()) . 'ToMaps'; - $this->$mapFunction($entity); + if (method_exists($this, $mapFunction)) { + $this->$mapFunction($entity); + } } // if the invoice is paid we'll also create a payment record @@ -926,6 +928,7 @@ class ImportService private function addInvoiceToMaps(Invoice $invoice) { if ($number = strtolower(trim($invoice->invoice_number))) { + $this->maps['invoices'][$number] = $invoice; $this->maps['invoice'][$number] = $invoice->id; $this->maps['invoice_client'][$number] = $invoice->client_id; $this->maps['invoice_ids'][$invoice->public_id] = $invoice->id;