Improvements to CSV import

This commit is contained in:
Hillel Coren 2017-03-07 11:09:53 +02:00
parent 72bd5c4aa7
commit 3dee1692c2

View File

@ -7,6 +7,7 @@ use App\Models\EntityModel;
use App\Models\Expense;
use App\Models\ExpenseCategory;
use App\Models\Invoice;
use App\Models\Payment;
use App\Models\Product;
use App\Models\Vendor;
use App\Ninja\Import\BaseTransformer;
@ -452,18 +453,21 @@ class ImportService
* @param $clientId
* @param $invoiceId
*/
private function createPayment($source, $data, $clientId, $invoiceId)
private function createPayment($source, $row, $clientId, $invoiceId)
{
$paymentTransformer = $this->getTransformer($source, ENTITY_PAYMENT, $this->maps);
$data->client_id = $clientId;
$data->invoice_id = $invoiceId;
$row->client_id = $clientId;
$row->invoice_id = $invoiceId;
if ($resource = $paymentTransformer->transform($data)) {
if ($resource = $paymentTransformer->transform($row)) {
$data = $this->fractal->createData($resource)->toArray();
$data['amount'] = min($data['amount'], $row->amount);
if (Payment::validate($data) === true) {
$this->paymentRepo->save($data);
}
}
}
/**
* @param array $files
@ -820,6 +824,11 @@ class ImportService
$this->maps['client'][$name] = $client->id;
$this->maps['client_ids'][$client->public_id] = $client->id;
}
if ($name = strtolower(trim($client->getDisplayName()))) {
$this->maps['client'][$name] = $client->id;
$this->maps['client_ids'][$client->public_id] = $client->id;
}
}
/**