mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixes for CSV import - ensure clients/vendors have a contact
This commit is contained in:
parent
2967392f38
commit
15a9e55fc7
@ -28,6 +28,7 @@ use App\Models\Payment;
|
|||||||
use App\Models\Paymentable;
|
use App\Models\Paymentable;
|
||||||
use App\Models\QuoteInvitation;
|
use App\Models\QuoteInvitation;
|
||||||
use App\Models\RecurringInvoiceInvitation;
|
use App\Models\RecurringInvoiceInvitation;
|
||||||
|
use App\Models\Vendor;
|
||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
@ -295,6 +296,9 @@ class CheckData extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->option('fix') == 'true') {
|
if ($this->option('fix') == 'true') {
|
||||||
|
|
||||||
|
$vendors = Vendor::withTrashed()->doesntHave('contacts')->get();
|
||||||
|
|
||||||
foreach ($vendors as $vendor) {
|
foreach ($vendors as $vendor) {
|
||||||
$this->logMessage("Fixing missing vendor contacts #{$vendor->id}");
|
$this->logMessage("Fixing missing vendor contacts #{$vendor->id}");
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace App\Jobs\Import;
|
namespace App\Jobs\Import;
|
||||||
|
|
||||||
|
use App\Factory\ClientContactFactory;
|
||||||
|
use App\Factory\VendorContactFactory;
|
||||||
use App\Import\Providers\Csv;
|
use App\Import\Providers\Csv;
|
||||||
use App\Import\Providers\Freshbooks;
|
use App\Import\Providers\Freshbooks;
|
||||||
use App\Import\Providers\Invoice2Go;
|
use App\Import\Providers\Invoice2Go;
|
||||||
@ -18,12 +20,15 @@ use App\Import\Providers\Invoicely;
|
|||||||
use App\Import\Providers\Wave;
|
use App\Import\Providers\Wave;
|
||||||
use App\Import\Providers\Zoho;
|
use App\Import\Providers\Zoho;
|
||||||
use App\Libraries\MultiDB;
|
use App\Libraries\MultiDB;
|
||||||
|
use App\Models\Client;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
|
use App\Models\Vendor;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class CSVIngest implements ShouldQueue {
|
class CSVIngest implements ShouldQueue {
|
||||||
|
|
||||||
@ -70,6 +75,33 @@ class CSVIngest implements ShouldQueue {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->checkContacts();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function checkContacts()
|
||||||
|
{
|
||||||
|
$vendors = Vendor::withTrashed()->where('company_id', $this->company->id)->doesntHave('contacts')->get();
|
||||||
|
|
||||||
|
foreach ($vendors as $vendor) {
|
||||||
|
|
||||||
|
$new_contact = VendorContactFactory::create($vendor->company_id, $vendor->user_id);
|
||||||
|
$new_contact->vendor_id = $vendor->id;
|
||||||
|
$new_contact->contact_key = Str::random(40);
|
||||||
|
$new_contact->is_primary = true;
|
||||||
|
$new_contact->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
$clients = Client::withTrashed()->where('company_id', $this->company->id)->doesntHave('contacts')->get();
|
||||||
|
|
||||||
|
foreach ($clients as $client) {
|
||||||
|
|
||||||
|
$new_contact = ClientContactFactory::create($client->company_id, $client->user_id);
|
||||||
|
$new_contact->client_id = $client->id;
|
||||||
|
$new_contact->contact_key = Str::random(40);
|
||||||
|
$new_contact->is_primary = true;
|
||||||
|
$new_contact->save();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function bootEngine(string $import_type)
|
private function bootEngine(string $import_type)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user