diff --git a/VERSION.txt b/VERSION.txt index c9c84322d739..1b88b5827956 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.0.23 +5.0.24 \ No newline at end of file diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index 72c5a94cf767..a3e92c1b7459 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -175,7 +175,7 @@ class CompanySettings extends BaseSettings public $email_template_reminder3 = ''; //@implemented public $email_template_reminder_endless = ''; //@implemented public $email_signature = ''; //@implemented - public $enable_email_markup = true; //@TODO + public $enable_email_markup = true; //@TODO - public $email_subject_custom1 = ''; //@TODO public $email_subject_custom2 = ''; //@TODO @@ -185,35 +185,35 @@ class CompanySettings extends BaseSettings public $email_template_custom2 = ''; //@TODO public $email_template_custom3 = ''; //@TODO - public $enable_reminder1 = false; //@partially implmemented - public $enable_reminder2 = false; //@partially implmemented - public $enable_reminder3 = false; //@partially implmemented - public $enable_reminder_endless = false; //@partially implmemented + public $enable_reminder1 = false; //@implmemented + public $enable_reminder2 = false; //@implmemented + public $enable_reminder3 = false; //@implmemented + public $enable_reminder_endless = false; //@implmemented - public $num_days_reminder1 = 0;//@partially implmemented - public $num_days_reminder2 = 0;//@partially implmemented - public $num_days_reminder3 = 0;//@partially implmemented + public $num_days_reminder1 = 0;//@implmemented + public $num_days_reminder2 = 0;//@implmemented + public $num_days_reminder3 = 0;//@implmemented - public $schedule_reminder1 = ''; // (enum: after_invoice_date, before_due_date, after_due_date) - public $schedule_reminder2 = ''; // (enum: after_invoice_date, before_due_date, after_due_date) - public $schedule_reminder3 = ''; // (enum: after_invoice_date, before_due_date, after_due_date) + public $schedule_reminder1 = ''; // (enum: after_invoice_date, before_due_date, after_due_date) implmemented + public $schedule_reminder2 = ''; // (enum: after_invoice_date, before_due_date, after_due_date) implmemented + public $schedule_reminder3 = ''; // (enum: after_invoice_date, before_due_date, after_due_date) implmemented - public $reminder_send_time = 32400; //number of seconds from UTC +0 to send reminders + public $reminder_send_time = 32400; //number of seconds from UTC +0 to send reminders @TODO - public $late_fee_amount1 = 0; //@TODO - public $late_fee_amount2 = 0; //@TODO - public $late_fee_amount3 = 0; //@TODO + public $late_fee_amount1 = 0; //@implemented + public $late_fee_amount2 = 0; //@implemented + public $late_fee_amount3 = 0; //@implemented - public $late_fee_percent1 = 0; //@TODO - public $late_fee_percent2 = 0; //@TODO - public $late_fee_percent3 = 0; //@TODO + public $late_fee_percent1 = 0; //@implemented + public $late_fee_percent2 = 0; //@implemented + public $late_fee_percent3 = 0; //@implemented public $endless_reminder_frequency_id = '0'; //@implemented - public $late_fee_endless_amount = 0; //@TODO - public $late_fee_endless_percent = 0; //@TODO + public $late_fee_endless_amount = 0; //@implemented + public $late_fee_endless_percent = 0; //@implemented - public $client_online_payment_notification = true; //@todo implement in notifications - public $client_manual_payment_notification = true; //@todo implement in notifications + public $client_online_payment_notification = true; //@todo implement in notifications check this bool prior to sending payment notification to client + public $client_manual_payment_notification = true; //@todo implement in notifications check this bool prior to sending manual payment notification to client /* Company Meta data that we can use to build sub companies*/ @@ -232,26 +232,26 @@ class CompanySettings extends BaseSettings public $id_number = ''; //@implemented public $page_size = 'A4'; //Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6 - public $font_size = 9; + public $font_size = 9; //@implemented public $primary_font = 'Roboto'; public $secondary_font = 'Roboto'; public $primary_color = '#4caf50'; public $secondary_color = '#2196f3'; public $hide_paid_to_date = false; //@TODO where? - public $embed_documents = false; //@TODO + public $embed_documents = false; //@TODO where? public $all_pages_header = false; //@implemented public $all_pages_footer = false; //@implemented public $pdf_variables = ''; //@implemented - public $portal_custom_head = ''; //@TODO - public $portal_custom_css = ''; //@TODO - public $portal_custom_footer = ''; //@TODO - public $portal_custom_js = ''; //@TODO + public $portal_custom_head = ''; //@TODO @BEN + public $portal_custom_css = ''; //@TODO @BEN + public $portal_custom_footer = ''; //@TODO @BEN + public $portal_custom_js = ''; //@TODO @BEN public $client_can_register = false; //@implemented - public $client_portal_terms = ''; //@TODO - public $client_portal_privacy_policy = ''; //@TODO + public $client_portal_terms = ''; //@TODO @BEN + public $client_portal_privacy_policy = ''; //@TODO @BEN public $client_portal_enable_uploads = false; //@implemented public $client_portal_allow_under_payment = false; //@implemented public $client_portal_under_payment_minimum = 0; //@implemented @@ -511,6 +511,7 @@ class CompanySettings extends BaseSettings /** * Provides class defaults on init. + * * @return stdClass */ public static function defaults(): stdClass @@ -543,6 +544,7 @@ class CompanySettings extends BaseSettings * set new properties to the object prior to being returned. * * @param $settings + * * @return stdClass */ public static function setProperties($settings): stdClass @@ -551,14 +553,19 @@ class CompanySettings extends BaseSettings foreach ($company_settings as $key => $value) { if (! property_exists($settings, $key)) { - $settings->{ $key} = self::castAttribute($key, $company_settings->{ $key}); + $settings->{$key} = self::castAttribute($key, $company_settings->{$key}); } } return $settings; } - public static function notificationDefaults() + /** + * Stubs the notification defaults + * + * @return stdClass + */ + public static function notificationDefaults() :stdClass { $notification = new stdClass; $notification->email = ['all_notifications']; @@ -566,7 +573,12 @@ class CompanySettings extends BaseSettings return $notification; } - private static function getEntityVariableDefaults() + /** + * Defines entity variables for PDF generation + * + * @return stdClass The stdClass of PDF variables + */ + private static function getEntityVariableDefaults() :stdClass { $variables = [ 'client_details' => [ diff --git a/app/Events/Payment/PaymentWasEmailed.php b/app/Events/Payment/PaymentWasEmailed.php index 6dec1e9a4c83..5a759b59d2cb 100644 --- a/app/Events/Payment/PaymentWasEmailed.php +++ b/app/Events/Payment/PaymentWasEmailed.php @@ -11,8 +11,15 @@ namespace App\Events\Payment; +use App\Models\Client; use App\Models\Company; use App\Models\Payment; +use Illuminate\Broadcasting\Channel; +use Illuminate\Broadcasting\InteractsWithSockets; +use Illuminate\Broadcasting\PresenceChannel; +use Illuminate\Broadcasting\PrivateChannel; +use Illuminate\Contracts\Broadcasting\ShouldBroadcast; +use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; /** @@ -20,7 +27,7 @@ use Illuminate\Queue\SerializesModels; */ class PaymentWasEmailed { - use SerializesModels; + use Dispatchable, InteractsWithSockets, SerializesModels; /** * @var Payment diff --git a/app/Events/Payment/PaymentWasEmailedAndFailed.php b/app/Events/Payment/PaymentWasEmailedAndFailed.php index 4c0149519f53..bedc6bec85b5 100644 --- a/app/Events/Payment/PaymentWasEmailedAndFailed.php +++ b/app/Events/Payment/PaymentWasEmailedAndFailed.php @@ -11,15 +11,23 @@ namespace App\Events\Payment; +use App\Models\Client; +use App\Models\Company; use App\Models\Payment; +use Illuminate\Broadcasting\Channel; +use Illuminate\Broadcasting\InteractsWithSockets; +use Illuminate\Broadcasting\PresenceChannel; +use Illuminate\Broadcasting\PrivateChannel; +use Illuminate\Contracts\Broadcasting\ShouldBroadcast; +use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; /** - * Class InvoiceWasEmailedAndFailed. + * Class PaymentWasEmailedAndFailed. */ class PaymentWasEmailedAndFailed { - use SerializesModels; + use Dispatchable, InteractsWithSockets, SerializesModels; /** * @var Payment @@ -39,7 +47,7 @@ class PaymentWasEmailedAndFailed * @param array $errors * @param array $event_vars */ - public function __construct(Payment $payment, $company, array $errors, array $event_vars) + public function __construct(Payment $payment, Company $company, array $errors, array $event_vars) { $this->payment = $payment; diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 782677e0e020..869d5a2df8a2 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -46,7 +46,7 @@ class Handler extends ExceptionHandler */ protected $dontReport = [ PDOException::class, - Swift_TransportException::class, + //Swift_TransportException::class, MaxAttemptsExceededException::class, CommandNotFoundException::class, ]; diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index 90a66259d689..bfd4aa3e9a1e 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -218,7 +218,7 @@ class BaseController extends Controller $query->whereNotNull('updated_at'); }, 'company.credits'=> function ($query) use ($updated_at) { - $query->where('updated_at', '>=', $updated_at)->with('invitations', 'documents',); + $query->where('updated_at', '>=', $updated_at)->with('invitations', 'documents'); }, 'company.designs'=> function ($query) use ($updated_at) { $query->where('updated_at', '>=', $updated_at)->with('company'); @@ -227,7 +227,7 @@ class BaseController extends Controller $query->where('updated_at', '>=', $updated_at); }, 'company.expenses'=> function ($query) use ($updated_at) { - $query->where('updated_at', '>=', $updated_at)->with('documents' ); + $query->where('updated_at', '>=', $updated_at)->with('documents'); }, 'company.groups' => function ($query) use ($updated_at) { $query->where('updated_at', '>=', $updated_at); @@ -236,7 +236,7 @@ class BaseController extends Controller $query->where('updated_at', '>=', $updated_at)->with('invitations', 'documents'); }, 'company.payments'=> function ($query) use ($updated_at) { - $query->where('updated_at', '>=', $updated_at)->with('paymentables','documents', ); + $query->where('updated_at', '>=', $updated_at)->with('paymentables','documents'); }, 'company.payment_terms'=> function ($query) use ($updated_at) { $query->where('updated_at', '>=', $updated_at); @@ -248,7 +248,7 @@ class BaseController extends Controller $query->where('updated_at', '>=', $updated_at)->with('documents' ); }, 'company.quotes'=> function ($query) use ($updated_at) { - $query->where('updated_at', '>=', $updated_at)->with('invitations', 'documents',); + $query->where('updated_at', '>=', $updated_at)->with('invitations', 'documents'); }, 'company.recurring_invoices'=> function ($query) use ($updated_at) { $query->where('updated_at', '>=', $updated_at)->with('invitations', 'documents'); @@ -260,7 +260,7 @@ class BaseController extends Controller $query->where('updated_at', '>=', $updated_at); }, 'company.vendors'=> function ($query) use ($updated_at) { - $query->where('updated_at', '>=', $updated_at)->with('contacts','documents' ); + $query->where('updated_at', '>=', $updated_at)->with('contacts','documents'); }, 'company.expense_categories'=> function ($query) use ($updated_at) { $query->where('updated_at', '>=', $updated_at); diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index de858640af54..62092a73bd63 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -729,6 +729,7 @@ class InvoiceController extends BaseController $invoice->service()->touchReminder($this->reminder_template)->save(); $invoice->invitations->load('contact.client.country', 'invoice.client.country', 'invoice.company')->each(function ($invitation) use ($invoice) { + info("firing email"); EmailEntity::dispatch($invitation, $invoice->company, $this->reminder_template); }); diff --git a/app/Http/Requests/Expense/StoreExpenseRequest.php b/app/Http/Requests/Expense/StoreExpenseRequest.php index 398fdf582fb1..f1e7482f5454 100644 --- a/app/Http/Requests/Expense/StoreExpenseRequest.php +++ b/app/Http/Requests/Expense/StoreExpenseRequest.php @@ -39,7 +39,8 @@ class StoreExpenseRequest extends Request { $rules = []; - $rules['number'] = 'unique:expenses,number,'.$this->id.',id,company_id,'.auth()->user()->company()->id; + $rules['number'] = Rule::unique('expenses')->where('company_id', auth()->user()->company()->id); + // $rules['number'] = 'unique:expenses,number,'.$this->id.',id,company_id,'.auth()->user()->company()->id; $rules['contacts.*.email'] = 'nullable|distinct'; //$rules['number'] = new UniqueExpenseNumberRule($this->all()); $rules['client_id'] = 'bail|sometimes|exists:clients,id,company_id,'.auth()->user()->company()->id; diff --git a/app/Http/Requests/Expense/UpdateExpenseRequest.php b/app/Http/Requests/Expense/UpdateExpenseRequest.php index bdda97a3eb09..bbaddc7ad89a 100644 --- a/app/Http/Requests/Expense/UpdateExpenseRequest.php +++ b/app/Http/Requests/Expense/UpdateExpenseRequest.php @@ -42,9 +42,8 @@ class UpdateExpenseRequest extends Request //$rules['id_number'] = 'unique:clients,id_number,,id,company_id,' . auth()->user()->company()->id; $rules['contacts.*.email'] = 'nullable|distinct'; - if ($this->input('number')) { - $rules['number'] = 'unique:expenses,number,'.$this->id.',id,company_id,'.$this->expense->company_id; - } + if(isset($this->number)) + $rules['number'] = Rule::unique('expenses')->where('company_id', auth()->user()->company()->id)->ignore($this->expense->id); return $this->globalRules($rules); } diff --git a/app/Http/Requests/Project/UpdateProjectRequest.php b/app/Http/Requests/Project/UpdateProjectRequest.php index 3e7f06eb7278..48c4e947a140 100644 --- a/app/Http/Requests/Project/UpdateProjectRequest.php +++ b/app/Http/Requests/Project/UpdateProjectRequest.php @@ -33,9 +33,8 @@ class UpdateProjectRequest extends Request { $rules = []; - if ($this->input('number')) { - $rules['number'] = 'unique:projects,number,'.$this->id.',id,company_id,'.$this->project->company_id; - } + if(isset($this->number)) + $rules['number'] = Rule::unique('projects')->where('company_id', auth()->user()->company()->id)->ignore($this->project->id); return $this->globalRules($rules); } @@ -44,6 +43,9 @@ class UpdateProjectRequest extends Request { $input = $this->decodePrimaryKeys($this->all()); + if(isset($input['client_id'])) + unset($input['client_id']); + $this->replace($input); } } diff --git a/app/Jobs/Account/CreateAccount.php b/app/Jobs/Account/CreateAccount.php index 1f69e0e60ebd..98959d5b13fd 100644 --- a/app/Jobs/Account/CreateAccount.php +++ b/app/Jobs/Account/CreateAccount.php @@ -18,6 +18,7 @@ use App\Jobs\Company\CreateCompanyPaymentTerms; use App\Jobs\Company\CreateCompanyTaskStatuses; use App\Jobs\Company\CreateCompanyToken; use App\Jobs\User\CreateUser; +use App\Jobs\Util\VersionCheck; use App\Models\Account; use App\Models\User; use App\Notifications\Ninja\NewAccountCreated; @@ -93,6 +94,8 @@ class CreateAccount $sp035a66->notification(new NewAccountCreated($spaa9f78, $sp035a66))->ninja(); + VersionCheck::dispatchNow(); + LightLogs::create(new AnalyticsAccountCreated()) ->increment() ->batch(); diff --git a/app/Jobs/Entity/EmailEntity.php b/app/Jobs/Entity/EmailEntity.php index a80f148ccdfc..c6ab3c30f197 100644 --- a/app/Jobs/Entity/EmailEntity.php +++ b/app/Jobs/Entity/EmailEntity.php @@ -116,13 +116,13 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue $this->invitation->contact->client ) ); - } catch (Swift_TransportException $e) { + } catch (\Exception $e) { + $this->failed($e); $this->entityEmailFailed($e->getMessage()); + $this->logMailError($e->getMessage(), $this->entity->client); } - if (count(Mail::failures()) > 0) { - $this->logMailError(Mail::failures(), $this->entity->client); - } else { + if (count(Mail::failures()) == 0) { $this->entityEmailSucceeded(); } @@ -130,19 +130,6 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue $this->entity->service()->markSent()->save(); } - public function failed($exception = null) - { - info('the job failed'); - - $job_failure = new EmailInvoiceFailure(); - $job_failure->string_metric5 = $this->entity_string; - $job_failure->string_metric6 = $exception->getMessage(); - - LightLogs::create($job_failure) - ->batch(); - - } - private function resolveEntityString() :string { if($this->invitation instanceof InvoiceInvitation) diff --git a/app/Jobs/Invoice/ZipInvoices.php b/app/Jobs/Invoice/ZipInvoices.php index 11946f323950..ad3619923105 100644 --- a/app/Jobs/Invoice/ZipInvoices.php +++ b/app/Jobs/Invoice/ZipInvoices.php @@ -94,9 +94,15 @@ class ZipInvoices extends BaseMailerJob implements ShouldQueue $this->setMailDriver(); - Mail::to($this->email) - ->send(new DownloadInvoices(Storage::disk(config('filesystems.default'))->url($path.$file_name), $this->company)); + try { + Mail::to($this->email) + ->send(new DownloadInvoices(Storage::disk(config('filesystems.default'))->url($path.$file_name), $this->company)); + } + catch (\Exception $e) { + $this->failed($e); + } + UnlinkFile::dispatch(config('filesystems.default'), $path.$file_name)->delay(now()->addHours(1)); } } diff --git a/app/Jobs/Mail/BaseMailerJob.php b/app/Jobs/Mail/BaseMailerJob.php index 0a03436ace6f..af2c4afc1bf4 100644 --- a/app/Jobs/Mail/BaseMailerJob.php +++ b/app/Jobs/Mail/BaseMailerJob.php @@ -12,8 +12,10 @@ namespace App\Jobs\Mail; use App\DataMapper\Analytics\EmailFailure; +use App\Jobs\Util\SystemLogger; use App\Libraries\Google\Google; use App\Libraries\MultiDB; +use App\Models\SystemLog; use App\Models\User; use App\Providers\MailServiceProvider; use App\Utils\Ninja; @@ -75,7 +77,7 @@ class BaseMailerJob implements ShouldQueue } public function logMailError($errors, $recipient_object) - {info(print_r($errors,1)); + { SystemLogger::dispatch( $errors, SystemLog::CATEGORY_MAIL, diff --git a/app/Jobs/Mail/EntityPaidMailer.php b/app/Jobs/Mail/EntityPaidMailer.php index 62e0d462f8b3..2ca18b4a8916 100644 --- a/app/Jobs/Mail/EntityPaidMailer.php +++ b/app/Jobs/Mail/EntityPaidMailer.php @@ -90,15 +90,9 @@ class EntityPaidMailer extends BaseMailerJob implements ShouldQueue Mail::to($this->user->email) ->send(new EntityNotificationMailer($mail_obj)); - } catch (Swift_TransportException $e) { - $this->failed($e->getMessage()); - //$this->entityEmailFailed($e->getMessage()); - } - - if (count(Mail::failures()) > 0) { - $this->logMailError(Mail::failures(), $this->payment->client); - } else { - // $this->entityEmailSucceeded(); + } catch (\Exception $e) { + $this->failed($e); + $this->logMailError($e->getMessage(), $this->payment->client); } } diff --git a/app/Jobs/Mail/EntitySentMailer.php b/app/Jobs/Mail/EntitySentMailer.php index 062c1d857cbc..88b120913ee4 100644 --- a/app/Jobs/Mail/EntitySentMailer.php +++ b/app/Jobs/Mail/EntitySentMailer.php @@ -88,13 +88,15 @@ class EntitySentMailer extends BaseMailerJob implements ShouldQueue $mail_obj = (new EntitySentObject($this->invitation, $this->entity_type))->build(); $mail_obj->from = [$this->entity->user->email, $this->entity->user->present()->name()]; - //send email - Mail::to($this->user->email) - ->send(new EntityNotificationMailer($mail_obj)); + try { + Mail::to($this->user->email) + ->send(new EntityNotificationMailer($mail_obj)); + }catch(\Exception $e) { + + $this->failed($e); + $this->logMailError($e->getMessage(), $this->entity->client); - //catch errors - if (count(Mail::failures()) > 0) { - return $this->logMailError(Mail::failures(), $this->entity->client); } + } } diff --git a/app/Jobs/Mail/EntityViewedMailer.php b/app/Jobs/Mail/EntityViewedMailer.php index 4dad5c068e1f..ba01dd8b88f1 100644 --- a/app/Jobs/Mail/EntityViewedMailer.php +++ b/app/Jobs/Mail/EntityViewedMailer.php @@ -89,12 +89,15 @@ class EntityViewedMailer extends BaseMailerJob implements ShouldQueue $mail_obj->from = [$this->entity->user->email, $this->entity->user->present()->name()]; //send email - Mail::to($this->user->email) - ->send(new EntityNotificationMailer($mail_obj)); + try{ + Mail::to($this->user->email) + ->send(new EntityNotificationMailer($mail_obj)); + } + catch (\Exception $e) { + + $this->failed($e); + $this->logMailError($e->getMessage(), $this->entity->client); - //catch errors - if (count(Mail::failures()) > 0) { - return $this->logMailError(Mail::failures(), $this->invoice->client); } } } diff --git a/app/Jobs/Mail/MailRouter.php b/app/Jobs/Mail/MailRouter.php index db6ebd423a58..e0dcd4b31020 100644 --- a/app/Jobs/Mail/MailRouter.php +++ b/app/Jobs/Mail/MailRouter.php @@ -22,7 +22,6 @@ use App\Models\Company; use App\Models\SystemLog; use App\Models\User; use App\Providers\MailServiceProvider; -use Dacastro4\LaravelGmail\Services\Message\Mail; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; @@ -77,12 +76,16 @@ class MailRouter extends BaseMailerJob implements ShouldQueue $this->setMailDriver(); //send email - Mail::to($this->to_user->email) - ->send($this->mailable); - - //catch errors - if (count(Mail::failures()) > 0) { - $this->logMailError(Mail::failures(), $this->to_user); + try { + Mail::to($this->to_user->email) + ->send($this->mailable); } + catch (\Exception $e) { + + $this->failed($e); + $this->logMailError($e->getMessage(), $this->to_user); + + } + } } diff --git a/app/Jobs/Mail/PaymentFailureMailer.php b/app/Jobs/Mail/PaymentFailureMailer.php index d06dd7cc994d..1c405d477ce8 100644 --- a/app/Jobs/Mail/PaymentFailureMailer.php +++ b/app/Jobs/Mail/PaymentFailureMailer.php @@ -100,13 +100,17 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue $mail_obj->from = [$this->company->owner()->email, $this->company->owner()->present()->name()]; //send email - Mail::to($company_user->user->email) - ->send(new EntityNotificationMailer($mail_obj)); - - //catch errors - if (count(Mail::failures()) > 0) { - return $this->logMailError(Mail::failures(), $this->client); + try { + Mail::to($company_user->user->email) + ->send(new EntityNotificationMailer($mail_obj)); } + catch(\Exception $e) { + + $this->failed($e); + $this->logMailError($e->getMessage(), $this->client); + + } + } }); } diff --git a/app/Jobs/Payment/EmailPayment.php b/app/Jobs/Payment/EmailPayment.php index e93fc5faaf22..5e751b333f79 100644 --- a/app/Jobs/Payment/EmailPayment.php +++ b/app/Jobs/Payment/EmailPayment.php @@ -1,4 +1,13 @@ company->is_disabled) return true; @@ -76,13 +86,18 @@ class EmailPayment extends BaseMailerJob implements ShouldQueue $email_builder = (new PaymentEmailEngine($this->payment, $this->contact))->build(); - Mail::to($this->contact->email, $this->contact->present()->name()) - ->send(new TemplateEmail($email_builder, $this->contact->user, $this->contact->client)); + try{ - if (count(Mail::failures()) > 0) { - event(new PaymentWasEmailedAndFailed($this->payment, Mail::failures(), Ninja::eventVars())); + $mail = Mail::to($this->contact->email, $this->contact->present()->name()); + $mail->send(new TemplateEmail($email_builder, $this->contact->user, $this->contact->client)); + + }catch(\Exception $e) { + + info("mailing failed with message " . $e->getMessage()); + event(new PaymentWasEmailedAndFailed($this->payment, $this->company, Mail::failures(), Ninja::eventVars())); + $this->failed($e); + return $this->logMailError($e->getMessage(), $this->payment->client); - return $this->logMailError(Mail::failures()); } event(new PaymentWasEmailed($this->payment, $this->payment->company, Ninja::eventVars())); @@ -90,17 +105,5 @@ class EmailPayment extends BaseMailerJob implements ShouldQueue } } - public function failed($exception = null) - { - info('the job failed'); - - $job_failure = new EmailInvoiceFailure(); - $job_failure->string_metric5 = 'payment'; - $job_failure->string_metric6 = $exception->getMessage(); - - LightLogs::create($job_failure) - ->batch(); - - } } diff --git a/app/Jobs/User/UserEmailChanged.php b/app/Jobs/User/UserEmailChanged.php index 02a788a3f1c0..fb3a963d84a6 100644 --- a/app/Jobs/User/UserEmailChanged.php +++ b/app/Jobs/User/UserEmailChanged.php @@ -72,16 +72,21 @@ class UserEmailChanged extends BaseMailerJob implements ShouldQueue $mail_obj->data = $this->getData(); //Send email via a Mailable class + // + try { Mail::to($this->old_email) ->send(new UserNotificationMailer($mail_obj)); Mail::to($this->new_email) ->send(new UserNotificationMailer($mail_obj)); - - //Catch errors and report. - if (count(Mail::failures()) > 0) { - return $this->logMailError(Mail::failures(), $this->company); } + catch (\Exception $e) { + + $this->failed($e); + $this->logMailError($e->getMessage(), $this->company->owner()); + + } + } private function getData() diff --git a/app/Listeners/Activity/PaymentCreatedActivity.php b/app/Listeners/Activity/PaymentCreatedActivity.php index 40266a51beb0..54f92940dfec 100644 --- a/app/Listeners/Activity/PaymentCreatedActivity.php +++ b/app/Listeners/Activity/PaymentCreatedActivity.php @@ -57,15 +57,6 @@ class PaymentCreatedActivity implements ShouldQueue $fields->company_id = $payment->company_id; $fields->activity_type_id = Activity::CREATE_PAYMENT; - /*todo tests fail for this for some reason?*/ - // foreach ($invoices as $invoice) { //todo we may need to add additional logic if in the future we apply payments to other entity Types, not just invoices - // $fields->invoice_id = $invoice->id; - - // InvoiceWorkflowSettings::dispatchNow($invoice); - - // $this->activity_repo->save($fields, $invoice, $event->event_vars); - // } - if (count($invoices) == 0) { $this->activity_repo->save($fields, $payment, $event->event_vars); } diff --git a/app/Listeners/Payment/PaymentEmailFailureActivity.php b/app/Listeners/Payment/PaymentEmailFailureActivity.php new file mode 100644 index 000000000000..78920d20da35 --- /dev/null +++ b/app/Listeners/Payment/PaymentEmailFailureActivity.php @@ -0,0 +1,57 @@ +company->db); + + $payment = $event->payment; + + info("i failed emailing {$payment->number}"); + // info(print_r($event->errors,1)); + + } +} + diff --git a/app/Listeners/Payment/PaymentEmailedActivity.php b/app/Listeners/Payment/PaymentEmailedActivity.php new file mode 100644 index 000000000000..60bc6e8785e1 --- /dev/null +++ b/app/Listeners/Payment/PaymentEmailedActivity.php @@ -0,0 +1,55 @@ +company->db); + + $payment = $event->payment; + + info("i succeeded in emailing payment {$payment->number}"); + } +} + diff --git a/app/Mail/TemplateEmail.php b/app/Mail/TemplateEmail.php index 49d7f5896d28..2f180c365c48 100644 --- a/app/Mail/TemplateEmail.php +++ b/app/Mail/TemplateEmail.php @@ -54,8 +54,15 @@ class TemplateEmail extends Mailable $company = $this->client->company; - $message = $this->from($this->user->email, $this->user->present()->name())//todo this needs to be fixed to handle the hosted version - ->subject($this->build_email->getSubject()) + $this->from($this->user->email, $this->user->present()->name()); + + if(strlen($settings->reply_to_email) > 1) + $this->replyTo($settings->reply_to_email, $settings->reply_to_email); + + if(strlen($settings->bcc_email) > 1) + $this->bcc($settings->bcc_email, $settings->bcc_email); + + $this->subject($this->build_email->getSubject()) ->text('email.template.plain', [ 'body' => $this->build_email->getBody(), 'footer' => $this->build_email->getFooter(), @@ -78,10 +85,10 @@ class TemplateEmail extends Mailable //conditionally attach files if ($settings->pdf_email_attachment !== false && ! empty($this->build_email->getAttachments())) { foreach ($this->build_email->getAttachments() as $file) { - $message->attach($file); + $this->attach($file); } } - return $message; + return $this; } } diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index 73451f44953a..c9a98ef12591 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -41,7 +41,7 @@ class CompanyGateway extends BaseModel 'require_billing_address', 'require_shipping_address', 'require_client_name', - 'require_zip', + 'require_postal_code', 'require_client_phone', 'require_contact_name', 'update_details', diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index c035126c8e4c..3b846892bb5a 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -51,6 +51,8 @@ use App\Events\Misc\InvitationWasViewed; use App\Events\Payment\PaymentWasArchived; use App\Events\Payment\PaymentWasCreated; use App\Events\Payment\PaymentWasDeleted; +use App\Events\Payment\PaymentWasEmailed; +use App\Events\Payment\PaymentWasEmailedAndFailed; use App\Events\Payment\PaymentWasRefunded; use App\Events\Payment\PaymentWasRestored; use App\Events\Payment\PaymentWasUpdated; @@ -129,6 +131,8 @@ use App\Listeners\Invoice\InvoiceViewedActivity; use App\Listeners\Invoice\UpdateInvoiceActivity; use App\Listeners\Invoice\UpdateInvoiceInvitations; use App\Listeners\Misc\InvitationViewedListener; +use App\Listeners\Payment\PaymentEmailFailureActivity; +use App\Listeners\Payment\PaymentEmailedActivity; use App\Listeners\Payment\PaymentNotification; use App\Listeners\Payment\PaymentRestoredActivity; use App\Listeners\Quote\QuoteApprovedActivity; @@ -310,6 +314,12 @@ class EventServiceProvider extends ServiceProvider InvitationWasViewed::class => [ InvitationViewedListener::class, ], + PaymentWasEmailed::class => [ + PaymentEmailedActivity::class, + ], + PaymentWasEmailedAndFailed::class => [ + PaymentEmailFailureActivity::class, + ], CompanyDocumentsDeleted::class => [ DeleteCompanyDocuments::class, ], diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index 63aee8f49ee4..a39d60885723 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -75,7 +75,8 @@ class MarkPaid extends AbstractService ->applyNumber() ->save(); - EmailPayment::dispatch($payment, $payment->company, $payment->client->primary_contact()->first()); + if($this->invoice->client->getSetting('client_manual_payment_notification')) + EmailPayment::dispatch($payment, $payment->company, $payment->client->primary_contact()->first()); /* Update Invoice balance */ event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); diff --git a/app/Transformers/CompanyGatewayTransformer.php b/app/Transformers/CompanyGatewayTransformer.php index 6cc59b8b98f1..c62a54184792 100644 --- a/app/Transformers/CompanyGatewayTransformer.php +++ b/app/Transformers/CompanyGatewayTransformer.php @@ -53,6 +53,7 @@ class CompanyGatewayTransformer extends EntityTransformer 'require_shipping_address' => (bool) $company_gateway->require_shipping_address, 'require_client_name' => (bool) $company_gateway->require_client_name, 'require_zip' => (bool) $company_gateway->require_zip, + 'require_postal_code' => (bool) $company_gateway->require_postal_code, 'require_client_phone' => (bool) $company_gateway->require_client_phone, 'require_contact_name' => (bool) $company_gateway->require_contact_name, 'require_contact_email' => (bool) $company_gateway->require_contact_email, diff --git a/config/ninja.php b/config/ninja.php index 938ad216625e..0ad22ee66c20 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -12,7 +12,7 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/').'/', 'app_domain' => env('APP_DOMAIN', ''), - 'app_version' => '5.0.23', + 'app_version' => '5.0.24', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', false), diff --git a/database/migrations/2020_11_12_104413_company_gateway_rename_column.php b/database/migrations/2020_11_12_104413_company_gateway_rename_column.php new file mode 100644 index 000000000000..5bc05b56b102 --- /dev/null +++ b/database/migrations/2020_11_12_104413_company_gateway_rename_column.php @@ -0,0 +1,30 @@ +renameColumn('require_zip', 'require_postal_code'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +}