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\Expense;
use App\Models\ExpenseCategory; use App\Models\ExpenseCategory;
use App\Models\Invoice; use App\Models\Invoice;
use App\Models\Payment;
use App\Models\Product; use App\Models\Product;
use App\Models\Vendor; use App\Models\Vendor;
use App\Ninja\Import\BaseTransformer; use App\Ninja\Import\BaseTransformer;
@ -376,7 +377,7 @@ class ImportService
if ($entityType == ENTITY_INVOICE) { if ($entityType == ENTITY_INVOICE) {
$data['is_public'] = true; $data['is_public'] = true;
} }
$entity = $this->{"{$entityType}Repo"}->save($data); $entity = $this->{"{$entityType}Repo"}->save($data);
// update the entity maps // update the entity maps
@ -452,16 +453,19 @@ class ImportService
* @param $clientId * @param $clientId
* @param $invoiceId * @param $invoiceId
*/ */
private function createPayment($source, $data, $clientId, $invoiceId) private function createPayment($source, $row, $clientId, $invoiceId)
{ {
$paymentTransformer = $this->getTransformer($source, ENTITY_PAYMENT, $this->maps); $paymentTransformer = $this->getTransformer($source, ENTITY_PAYMENT, $this->maps);
$data->client_id = $clientId; $row->client_id = $clientId;
$data->invoice_id = $invoiceId; $row->invoice_id = $invoiceId;
if ($resource = $paymentTransformer->transform($data)) { if ($resource = $paymentTransformer->transform($row)) {
$data = $this->fractal->createData($resource)->toArray(); $data = $this->fractal->createData($resource)->toArray();
$this->paymentRepo->save($data); $data['amount'] = min($data['amount'], $row->amount);
if (Payment::validate($data) === true) {
$this->paymentRepo->save($data);
}
} }
} }
@ -820,6 +824,11 @@ class ImportService
$this->maps['client'][$name] = $client->id; $this->maps['client'][$name] = $client->id;
$this->maps['client_ids'][$client->public_id] = $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;
}
} }
/** /**