mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-29 12:41:10 -04:00
Refactor mail-sender
This commit is contained in:
@ -41,14 +41,6 @@ class MailSenderController extends Controller
|
||||
{
|
||||
$this->authorize('create', MailSender::class);
|
||||
|
||||
$mailConfiguration = MailSender::where('company_id', $request->header('company'))
|
||||
->where('is_default', true)
|
||||
->first();
|
||||
|
||||
if ($mailConfiguration && $request['is_default'] == true) {
|
||||
$mailConfiguration->update(['is_default' => false]);
|
||||
}
|
||||
|
||||
$mailSender = MailSender::createFromRequest($request);
|
||||
|
||||
return new MailSenderResource($mailSender);
|
||||
@ -78,15 +70,6 @@ class MailSenderController extends Controller
|
||||
{
|
||||
$this->authorize('update', $mailSender);
|
||||
|
||||
$mailConfiguration = MailSender::where('company_id', $request->header('company'))
|
||||
->where('is_default', true)
|
||||
->where('id', '<>', $mailSender->id)
|
||||
->first();
|
||||
|
||||
if ($mailConfiguration && $request['is_default'] == true) {
|
||||
$mailConfiguration->update(['is_default' => false]);
|
||||
}
|
||||
|
||||
$mailSender->updateFromRequest($request);
|
||||
|
||||
return new MailSenderResource($mailSender);
|
||||
@ -102,6 +85,10 @@ class MailSenderController extends Controller
|
||||
{
|
||||
$this->authorize('delete', $mailSender);
|
||||
|
||||
if ($mailSender->is_default) {
|
||||
return respondJson('You can\'t remove default mail sender.', 'You can\'t remove default mail sender.');
|
||||
}
|
||||
|
||||
$mailSender->delete();
|
||||
|
||||
return response()->json([
|
||||
|
||||
@ -9,6 +9,7 @@ use Crater\Models\CompanySetting;
|
||||
use Crater\Models\Customer;
|
||||
use Crater\Models\EmailLog;
|
||||
use Crater\Models\Estimate;
|
||||
use Crater\Models\MailSender;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class EstimatePdfController extends Controller
|
||||
@ -27,14 +28,16 @@ class EstimatePdfController extends Controller
|
||||
);
|
||||
|
||||
if ($notifyEstimateViewed == 'YES') {
|
||||
$data['estimate'] = Estimate::findOrFail($estimate->id)->toArray();
|
||||
$data['user'] = Customer::find($estimate->customer_id)->toArray();
|
||||
$notificationEmail = CompanySetting::getSetting(
|
||||
'notification_email',
|
||||
$estimate->company_id
|
||||
);
|
||||
$notificationEmail = CompanySetting::getSetting('notification_email', $estimate->company_id);
|
||||
$mailSender = MailSender::where('company_id', $estimate->company_id)->where('is_default', true)->first();
|
||||
MailSender::setMailConfiguration($mailSender->id);
|
||||
|
||||
\Mail::to($notificationEmail)->send(new EstimateViewedMail($data));
|
||||
$data['from_address'] = $mailSender->from_address;
|
||||
$data['from_name'] = $mailSender->from_name;
|
||||
$data['user'] = Customer::find($estimate->customer_id)->toArray();
|
||||
$data['estimate'] = Estimate::findOrFail($estimate->id)->toArray();
|
||||
|
||||
send_mail(new EstimateViewedMail($data), $mailSender, $notificationEmail);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@ use Crater\Models\CompanySetting;
|
||||
use Crater\Models\Customer;
|
||||
use Crater\Models\EmailLog;
|
||||
use Crater\Models\Invoice;
|
||||
use Crater\Models\MailSender;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class InvoicePdfController extends Controller
|
||||
@ -28,14 +29,16 @@ class InvoicePdfController extends Controller
|
||||
);
|
||||
|
||||
if ($notifyInvoiceViewed == 'YES') {
|
||||
$notificationEmail = CompanySetting::getSetting('notification_email', $invoice->company_id);
|
||||
$mailSender = MailSender::where('company_id', $invoice->company_id)->where('is_default', true)->first();
|
||||
MailSender::setMailConfiguration($mailSender->id);
|
||||
|
||||
$data['from_address'] = $mailSender->from_address;
|
||||
$data['from_name'] = $mailSender->from_name;
|
||||
$data['invoice'] = Invoice::findOrFail($invoice->id)->toArray();
|
||||
$data['user'] = Customer::find($invoice->customer_id)->toArray();
|
||||
$notificationEmail = CompanySetting::getSetting(
|
||||
'notification_email',
|
||||
$invoice->company_id
|
||||
);
|
||||
|
||||
\Mail::to($notificationEmail)->send(new InvoiceViewedMail($data));
|
||||
send_mail(new InvoiceViewedMail($data), $mailSender, $notificationEmail);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user