mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Import notification
This commit is contained in:
parent
bc06476431
commit
2347b9db7a
@ -21,7 +21,9 @@ use App\Import\Transformers\ClientTransformer;
|
||||
use App\Import\Transformers\InvoiceItemTransformer;
|
||||
use App\Import\Transformers\InvoiceTransformer;
|
||||
use App\Import\Transformers\ProductTransformer;
|
||||
use App\Jobs\Mail\MailRouter;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Mail\Import\ImportCompleted;
|
||||
use App\Models\Client;
|
||||
use App\Models\Company;
|
||||
use App\Models\Currency;
|
||||
@ -98,11 +100,16 @@ class CSVImport implements ShouldQueue
|
||||
|
||||
info("import".ucfirst($this->entity_type));
|
||||
$this->{"import".ucfirst($this->entity_type)}();
|
||||
|
||||
$data = [
|
||||
'entity' => $this->entity_type,
|
||||
'errors' => $this->error_array,
|
||||
'clients' => $this->maps['clients'],
|
||||
'products' => $this->maps['products'],
|
||||
'invoices' => $this->maps['invoices'],
|
||||
];
|
||||
|
||||
|
||||
info("errors");
|
||||
|
||||
info(print_r($this->error_array,1));
|
||||
MailRouter::dispatch(new ImportCompleted($data), $this->company, auth()->user());
|
||||
|
||||
}
|
||||
|
||||
@ -180,7 +187,7 @@ class CSVImport implements ShouldQueue
|
||||
$validator = Validator::make($invoice, (new StoreInvoiceRequest())->rules());
|
||||
|
||||
if ($validator->fails()) {
|
||||
$this->error_array[] = ['invoice' => $invoice, 'error' => json_encode($validator->errors())];
|
||||
$this->error_array['invoices'] = ['invoice' => $invoice, 'error' => json_encode($validator->errors())];
|
||||
} else {
|
||||
|
||||
$invoice = $invoice_repository->save($invoice, InvoiceFactory::create($this->company->id, $this->setUser($record)));
|
||||
@ -248,7 +255,7 @@ class CSVImport implements ShouldQueue
|
||||
$validator = Validator::make($client, (new StoreClientRequest())->rules());
|
||||
|
||||
if ($validator->fails()) {
|
||||
$this->error_array[] = ['client' => $client, 'error' => json_encode($validator->errors())];
|
||||
$this->error_array['clients'] = ['client' => $client, 'error' => json_encode($validator->errors())];
|
||||
} else {
|
||||
$client = $client_repository->save($client, ClientFactory::create($this->company->id, $this->setUser($record)));
|
||||
|
||||
@ -291,7 +298,7 @@ class CSVImport implements ShouldQueue
|
||||
$validator = Validator::make($product, (new StoreProductRequest())->rules());
|
||||
|
||||
if ($validator->fails()) {
|
||||
$this->error_array[] = ['product' => $product, 'error' => json_encode($validator->errors())];
|
||||
$this->error_array['products'] = ['product' => $product, 'error' => json_encode($validator->errors())];
|
||||
} else {
|
||||
$product = $product_repository->save($product, ProductFactory::create($this->company->id, $this->setUser($record)));
|
||||
|
||||
@ -310,6 +317,7 @@ class CSVImport implements ShouldQueue
|
||||
$this->maps['company'] = $this->company;
|
||||
$this->maps['clients'] = [];
|
||||
$this->maps['products'] = [];
|
||||
$this->maps['invoices'] = [];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace App\Jobs\Mail;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Company;
|
||||
use App\Models\User;
|
||||
@ -74,7 +75,9 @@ class MailRouter extends BaseMailerJob implements ShouldQueue
|
||||
->send($this->mailable);
|
||||
} catch (\Exception $e) {
|
||||
$this->failed($e);
|
||||
$this->logMailError($e->getMessage(), $this->to_user);
|
||||
|
||||
if($this->to_user instanceof ClientContact)
|
||||
$this->logMailError($e->getMessage(), $this->to_user->client);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
35
app/Mail/Import/ImportCompleted.php
Normal file
35
app/Mail/Import/ImportCompleted.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail\Import;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class ImportCompleted extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public $data;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the message.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
return $this->from(config('mail.from.address'), config('mail.from.name'))
|
||||
->view('email.import.completed', compact($this->data));
|
||||
}
|
||||
}
|
41
resources/views/email/import/completed.blade
Normal file
41
resources/views/email/import/completed.blade
Normal file
@ -0,0 +1,41 @@
|
||||
@component('email.template.master', ['design' => 'light', 'settings' =>$settings])
|
||||
|
||||
@slot('header')
|
||||
@component('email.components.header')
|
||||
Migration already completed
|
||||
@endcomponent
|
||||
@endslot
|
||||
|
||||
@slot('greeting')
|
||||
Hello,
|
||||
@endslot
|
||||
|
||||
Here is the output of your recent import job.
|
||||
|
||||
Entity Type: {{ $entity_type }}
|
||||
|
||||
@if(count($errors['invoices']) >=1)
|
||||
<ul>
|
||||
@foreach($errors as $error)
|
||||
<li>{{ $error['invoice'] }} - {{ $error['error'] }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
@endif
|
||||
|
||||
@component('email.components.button', ['url' => url('/')])
|
||||
Visit portal
|
||||
@endcomponent
|
||||
|
||||
|
||||
@slot('signature')
|
||||
Thank you, <br>
|
||||
Invoice Ninja
|
||||
@endslot
|
||||
|
||||
@slot('footer')
|
||||
@component('email.components.footer', ['url' => 'https://invoiceninja.com', 'url_text' => '© InvoiceNinja'])
|
||||
For any info, please visit InvoiceNinja.
|
||||
@endcomponent
|
||||
@endslot
|
||||
|
||||
@endcomponent
|
Loading…
x
Reference in New Issue
Block a user