mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-09 20:52:56 +01:00
Fixes for import
This commit is contained in:
parent
4c03b24283
commit
1f587203a4
@ -136,7 +136,7 @@ class Client extends EntityModel
|
||||
'email' => 'email',
|
||||
'mobile|phone' => 'phone',
|
||||
'name|organization' => 'name',
|
||||
'street2|address2' => 'address2',
|
||||
'apt|street2|address2' => 'address2',
|
||||
'street|address|address1' => 'address1',
|
||||
'city' => 'city',
|
||||
'state|province' => 'state',
|
||||
@ -145,7 +145,7 @@ class Client extends EntityModel
|
||||
'note' => 'notes',
|
||||
'site|website' => 'website',
|
||||
'vat' => 'vat_number',
|
||||
'id|number' => 'id_number',
|
||||
'number' => 'id_number',
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -325,6 +325,13 @@ class ImportService
|
||||
private function transformRow($source, $entityType, $row)
|
||||
{
|
||||
$transformer = $this->getTransformer($source, $entityType, $this->maps);
|
||||
$resource = $transformer->transform($row);
|
||||
|
||||
if (! $resource) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = $this->fractal->createData($resource)->toArray();
|
||||
|
||||
// Create expesnse category
|
||||
if ($entityType == ENTITY_EXPENSE) {
|
||||
@ -333,24 +340,18 @@ class ImportService
|
||||
if (! $categoryId) {
|
||||
$category = $this->expenseCategoryRepo->save(['name' => $row->expense_category]);
|
||||
$this->addExpenseCategoryToMaps($category);
|
||||
$data['expense_category_id'] = $category->id;
|
||||
}
|
||||
}
|
||||
if (! empty($row->vendor) && ($vendorName = trim($row->vendor))) {
|
||||
if (! $transformer->getVendorId($vendorName)) {
|
||||
$vendor = $this->vendorRepo->save(['name' => $vendorName, 'vendor_contact' => []]);
|
||||
$this->addVendorToMaps($vendor);
|
||||
$data['vendor_id'] = $vendor->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$resource = $transformer->transform($row);
|
||||
|
||||
if (! $resource) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = $this->fractal->createData($resource)->toArray();
|
||||
|
||||
// if the invoice number is blank we'll assign it
|
||||
if ($entityType == ENTITY_INVOICE && ! $data['invoice_number']) {
|
||||
$account = Auth::user()->account;
|
||||
@ -404,7 +405,7 @@ class ImportService
|
||||
|
||||
// if the invoice is paid we'll also create a payment record
|
||||
if ($entityType === ENTITY_INVOICE && isset($data['paid']) && $data['paid'] > 0) {
|
||||
$this->createPayment($source, $row, $data['client_id'], $entity->id);
|
||||
$this->createPayment($source, $row, $data['client_id'], $entity->id, $entity->public_id);
|
||||
}
|
||||
|
||||
return $entity;
|
||||
@ -471,7 +472,7 @@ class ImportService
|
||||
* @param $clientId
|
||||
* @param $invoiceId
|
||||
*/
|
||||
private function createPayment($source, $row, $clientId, $invoiceId)
|
||||
private function createPayment($source, $row, $clientId, $invoiceId, $invoicePublicId)
|
||||
{
|
||||
$paymentTransformer = $this->getTransformer($source, ENTITY_PAYMENT, $this->maps);
|
||||
|
||||
@ -481,7 +482,9 @@ class ImportService
|
||||
if ($resource = $paymentTransformer->transform($row)) {
|
||||
$data = $this->fractal->createData($resource)->toArray();
|
||||
$data['amount'] = min($data['amount'], Utils::parseFloat($row->amount));
|
||||
$data['invoice_id'] = $invoicePublicId;
|
||||
if (Payment::validate($data) === true) {
|
||||
$data['invoice_id'] = $invoiceId;
|
||||
$this->paymentRepo->save($data);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user