1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Insert Clients if none found prior to creating any resources

This commit is contained in:
David Bomba 2023-04-13 15:14:54 +10:00
parent 3a778525c3
commit b75fe1157f
2 changed files with 36 additions and 11 deletions

View File

@ -426,7 +426,9 @@ class BaseImport
$message = $ex->getMessage();
} else {
report($ex);
$message = 'Unknown error';
$message = 'Unknown error ';
nlog($ex->getMessage());
nlog($raw_invoice);
}
$this->error_array['invoice'][] = [

View File

@ -11,24 +11,26 @@
namespace App\Import\Transformer;
use App\Factory\ExpenseCategoryFactory;
use App\Factory\ProjectFactory;
use App\Factory\VendorFactory;
use App\Models\Quote;
use App\Utils\Number;
use App\Models\Client;
use App\Models\ClientContact;
use App\Models\Vendor;
use App\Models\Country;
use App\Models\Expense;
use App\Models\ExpenseCategory;
use App\Models\Invoice;
use App\Models\PaymentType;
use App\Models\Product;
use App\Models\Project;
use App\Models\Quote;
use App\Models\TaxRate;
use App\Models\Vendor;
use App\Utils\Number;
use App\Models\PaymentType;
use App\Models\ClientContact;
use App\Factory\ClientFactory;
use App\Factory\VendorFactory;
use Illuminate\Support\Carbon;
use App\Factory\ProjectFactory;
use App\Models\ExpenseCategory;
use Illuminate\Support\Facades\Cache;
use App\Repositories\ClientRepository;
use App\Factory\ExpenseCategoryFactory;
/**
* Class BaseTransformer.
@ -129,7 +131,28 @@ class BaseTransformer
}
}
return null;
$client_repository = app()->make(ClientRepository::class);
$client_repository->import_mode = true;
$client = $client_repository->save(
[
'name' => $client_name,
'contacts' => [
[
'first_name' => $client_name,
'email' => $client_email,
],
],
],
ClientFactory::create(
$this->company->id,
$this->company->owner()->id
)
);
$client_repository = null;
return $client->id;
}
///////////////////////////////////////////////////////////////////////////////////