1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00

Set user in send invoice/quote activity

This commit is contained in:
Hillel Coren 2017-04-25 15:05:41 +03:00
parent 5293db2756
commit 430a0edbad
2 changed files with 21 additions and 3 deletions

View File

@ -405,7 +405,8 @@ class InvoiceController extends BaseController
if ($invoice->is_recurring) { if ($invoice->is_recurring) {
$response = $this->emailRecurringInvoice($invoice); $response = $this->emailRecurringInvoice($invoice);
} else { } else {
$this->dispatch(new SendInvoiceEmail($invoice, $reminder, $template)); $userId = Auth::user()->id;
$this->dispatch(new SendInvoiceEmail($invoice, $userId, $reminder, $template));
$response = true; $response = true;
} }
@ -437,7 +438,8 @@ class InvoiceController extends BaseController
if ($invoice->isPaid()) { if ($invoice->isPaid()) {
return true; return true;
} else { } else {
$this->dispatch(new SendInvoiceEmail($invoice)); $userId = Auth::user()->id;
$this->dispatch(new SendInvoiceEmail($invoice, $userId));
return true; return true;
} }
} }

View File

@ -8,6 +8,7 @@ use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Monolog\Logger; use Monolog\Logger;
use Auth;
/** /**
* Class SendInvoiceEmail. * Class SendInvoiceEmail.
@ -31,6 +32,11 @@ class SendInvoiceEmail extends Job implements ShouldQueue
*/ */
protected $template; protected $template;
/**
* @var int
*/
protected $userId;
/** /**
* Create a new job instance. * Create a new job instance.
* *
@ -39,9 +45,10 @@ class SendInvoiceEmail extends Job implements ShouldQueue
* @param bool $reminder * @param bool $reminder
* @param mixed $pdfString * @param mixed $pdfString
*/ */
public function __construct(Invoice $invoice, $reminder = false, $template = false) public function __construct(Invoice $invoice, $userId = false, $reminder = false, $template = false)
{ {
$this->invoice = $invoice; $this->invoice = $invoice;
$this->userId = $userId;
$this->reminder = $reminder; $this->reminder = $reminder;
$this->template = $template; $this->template = $template;
} }
@ -53,7 +60,16 @@ class SendInvoiceEmail extends Job implements ShouldQueue
*/ */
public function handle(ContactMailer $mailer) public function handle(ContactMailer $mailer)
{ {
// send email as user
if ($this->userId) {
Auth::loginUsingId($this->userId);
}
$mailer->sendInvoice($this->invoice, $this->reminder, $this->template); $mailer->sendInvoice($this->invoice, $this->reminder, $this->template);
if ($this->userId) {
Auth::logout();
}
} }
/* /*