Importing payments.csv from Wave fails #1717

This commit is contained in:
Hillel Coren 2017-10-20 15:04:52 +03:00
parent f6d8ae4326
commit e62213d221
4 changed files with 18 additions and 3 deletions

View File

@ -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();

View File

@ -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
*

View File

@ -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),
];
});
}

View File

@ -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;