From fb9bb7e269d8f59214651e857fd419a79751cefe Mon Sep 17 00:00:00 2001 From: = Date: Wed, 24 Mar 2021 09:28:12 +1100 Subject: [PATCH 1/7] Fixes for converting quote to invoice --- app/Http/Controllers/QuoteController.php | 2 +- app/Services/BillingSubscription/BillingSubscriptionService.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/QuoteController.php b/app/Http/Controllers/QuoteController.php index e4cb852c767b..02045ce2897f 100644 --- a/app/Http/Controllers/QuoteController.php +++ b/app/Http/Controllers/QuoteController.php @@ -532,7 +532,7 @@ class QuoteController extends BaseController return response()->json(['message' => ctrans('texts.sent_message')], 200); } - if ($action == 'convert') { + if ($action == 'convert' || $action == 'convert_to_invoice') { $this->entity_type = Quote::class; $this->entity_transformer = QuoteTransformer::class; diff --git a/app/Services/BillingSubscription/BillingSubscriptionService.php b/app/Services/BillingSubscription/BillingSubscriptionService.php index 9cf918d99dc2..8b6591219b73 100644 --- a/app/Services/BillingSubscription/BillingSubscriptionService.php +++ b/app/Services/BillingSubscription/BillingSubscriptionService.php @@ -192,6 +192,7 @@ class BillingSubscriptionService throw new \Exception("Could not match an invoice for payment of billing subscription"); //todo - need to remove the promo code - if it exists + return InvoiceToRecurringInvoiceFactory::create($invoice); } From 89598d44ef8fb5eaf7977c9c3d68288e0fd590e1 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 24 Mar 2021 09:28:42 +1100 Subject: [PATCH 2/7] Fixes for naming PDFs --- app/Http/Controllers/InvoiceController.php | 2 ++ app/Models/BaseModel.php | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index b9e99002f42d..9c037e92286d 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -795,6 +795,8 @@ class InvoiceController extends BaseController $file_path = $invoice->service()->getInvoicePdf($contact); +nlog($file_path); + return response()->download($file_path, basename($file_path)); } diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index 8d818643d6bb..ab0e0ee4b88f 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -191,7 +191,9 @@ class BaseModel extends Model public function numberFormatter() { - $formatted_number = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $this->number); + $number = strlen($this->number) > 1 ? $this->number : class_basename($this); + + $formatted_number = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $number); // Remove any runs of periods (thanks falstro!) $formatted_number = mb_ereg_replace("([\.]{2,})", '', $formatted_number); From 90540d64038b42258b2cc29c56f12eb5f5e115f7 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 24 Mar 2021 09:47:05 +1100 Subject: [PATCH 3/7] Refresh entity prior to sending --- app/Http/Controllers/EmailController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/EmailController.php b/app/Http/Controllers/EmailController.php index f53f47348ef8..cdd13ea89094 100644 --- a/app/Http/Controllers/EmailController.php +++ b/app/Http/Controllers/EmailController.php @@ -131,7 +131,7 @@ class EmailController extends BaseController $entity_obj->service()->markSent()->save(); - EmailEntity::dispatch($invitation, $invitation->company, $template, $data) + EmailEntity::dispatch($invitation->fresh(), $invitation->company, $template, $data) ->delay(now()->addSeconds(5)); } From 946ab58f135ac69fa8cb4fb9a1a7711c73069312 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 24 Mar 2021 10:43:21 +1100 Subject: [PATCH 4/7] Fixes for subscriptions --- .../BillingSubscriptionService.php | 4 +-- .../BillingSubscriptionTransformer.php | 4 ++- ...ble_constraint_to_recurring_invoice_id.php | 29 +++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 database/migrations/2021_03_23_233844_add_nullable_constraint_to_recurring_invoice_id.php diff --git a/app/Services/BillingSubscription/BillingSubscriptionService.php b/app/Services/BillingSubscription/BillingSubscriptionService.php index 8b6591219b73..acb39acf4635 100644 --- a/app/Services/BillingSubscription/BillingSubscriptionService.php +++ b/app/Services/BillingSubscription/BillingSubscriptionService.php @@ -46,7 +46,7 @@ class BillingSubscriptionService public function completePurchase(PaymentHash $payment_hash) { - if (!property_exists($payment_hash, 'billing_context')) { + if (!property_exists($payment_hash->data, 'billing_context')) { throw new \Exception("Illegal entrypoint into method, payload must contain billing context"); } @@ -79,7 +79,7 @@ class BillingSubscriptionService $cs->subscription_id = $this->billing_subscription->id; $cs->company_id = $this->billing_subscription->company_id; $cs->trial_started = time(); - $cs->trial_duration = time() + $this->billing_subscription->trial_duration; + $cs->trial_ends = time() + $this->billing_subscription->trial_duration; $cs->quantity = $data['quantity']; $cs->client_id = $contact->client->id; $cs->save(); diff --git a/app/Transformers/BillingSubscriptionTransformer.php b/app/Transformers/BillingSubscriptionTransformer.php index 3dc50cd78235..919889dd96a6 100644 --- a/app/Transformers/BillingSubscriptionTransformer.php +++ b/app/Transformers/BillingSubscriptionTransformer.php @@ -34,6 +34,8 @@ class BillingSubscriptionTransformer extends EntityTransformer public function transform(BillingSubscription $billing_subscription): array { + $std = new stdClass; + return [ 'id' => $this->encodePrimaryKey($billing_subscription->id), 'user_id' => $this->encodePrimaryKey($billing_subscription->user_id), @@ -56,7 +58,7 @@ class BillingSubscriptionTransformer extends EntityTransformer 'allow_plan_changes' => (bool)$billing_subscription->allow_plan_changes, 'plan_map' => (string)$billing_subscription->plan_map, 'refund_period' => (int)$billing_subscription->refund_period, - 'webhook_configuration' => (string)$billing_subscription->webhook_configuration, + 'webhook_configuration' => $billing_subscription->webhook_configuration ?: $std, 'purchase_page' => (string)route('client.subscription.purchase', $billing_subscription->hashed_id), 'is_deleted' => (bool)$billing_subscription->is_deleted, 'created_at' => (int)$billing_subscription->created_at, diff --git a/database/migrations/2021_03_23_233844_add_nullable_constraint_to_recurring_invoice_id.php b/database/migrations/2021_03_23_233844_add_nullable_constraint_to_recurring_invoice_id.php new file mode 100644 index 000000000000..f1224c7cdb1a --- /dev/null +++ b/database/migrations/2021_03_23_233844_add_nullable_constraint_to_recurring_invoice_id.php @@ -0,0 +1,29 @@ +unsignedInteger('recurring_invoice_id')->nullable()->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + } +} From db4f8946e4f0c11d1b528164da183cb6a0b9ba9e Mon Sep 17 00:00:00 2001 From: = Date: Wed, 24 Mar 2021 12:12:37 +1100 Subject: [PATCH 5/7] Add in required use --- app/Transformers/BillingSubscriptionTransformer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Transformers/BillingSubscriptionTransformer.php b/app/Transformers/BillingSubscriptionTransformer.php index 919889dd96a6..74ac5484ffe3 100644 --- a/app/Transformers/BillingSubscriptionTransformer.php +++ b/app/Transformers/BillingSubscriptionTransformer.php @@ -34,7 +34,7 @@ class BillingSubscriptionTransformer extends EntityTransformer public function transform(BillingSubscription $billing_subscription): array { - $std = new stdClass; + $std = new \stdClass; return [ 'id' => $this->encodePrimaryKey($billing_subscription->id), From 41de6a4062944e6e93a4547688d2ffc244acef84 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 24 Mar 2021 14:20:51 +1100 Subject: [PATCH 6/7] Fixes for notifications --- app/DataMapper/CompanySettings.php | 3 ++- .../Traits/Notifications/UserNotifies.php | 22 +++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index ce9b344e323e..ea342769bd7e 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -574,7 +574,8 @@ class CompanySettings extends BaseSettings public static function notificationDefaults() :stdClass { $notification = new stdClass; - $notification->email = ['all_notifications']; + $notification->email = []; + // $notification->email = ['all_notifications']; return $notification; } diff --git a/app/Utils/Traits/Notifications/UserNotifies.php b/app/Utils/Traits/Notifications/UserNotifies.php index 91455c16ea5c..9710ee0282b7 100644 --- a/app/Utils/Traits/Notifications/UserNotifies.php +++ b/app/Utils/Traits/Notifications/UserNotifies.php @@ -30,14 +30,22 @@ trait UserNotifies $notifications = $company_user->notifications; //if a user owns this record or is assigned to it, they are attached the permission for notification. - if ($invitation->{$entity_name}->user_id == $company_user->_user_id || $invitation->{$entity_name}->assigned_user_id == $company_user->user_id) { - array_push($required_permissions, 'all_user_notifications'); - } + // if ($invitation->{$entity_name}->user_id == $company_user->_user_id || $invitation->{$entity_name}->assigned_user_id == $company_user->user_id) { + // array_push($required_permissions, 'all_user_notifications'); + // } +nlog($notifications); +nlog($required_permissions); +nlog($notifications->email); +nlog(count(array_intersect($required_permissions, $notifications->email))); +nlog(count(array_intersect(['all_user_notifications'], $notifications->email))); +nlog(count(array_intersect(['all_notifications'],$notifications->email))); - if (count(array_intersect($required_permissions, $notifications->email)) >= 1 || count(array_intersect($required_permissions, ['all_user_notifications'])) >= 1 || count(array_intersect($required_permissions, ['all_notifications'])) >= 1) { + if (count(array_intersect($required_permissions, $notifications->email)) >= 1 || count(array_intersect(['all_user_notifications'],$notifications->email)) >= 1 || count(array_intersect(['all_notifications'],$notifications->email)) >= 1) { array_push($notifiable_methods, 'mail'); } +nlog($notifiable_methods); + // if(count(array_intersect($required_permissions, $notifications->slack)) >=1) // array_push($notifiable_methods, 'slack'); @@ -57,9 +65,9 @@ trait UserNotifies return []; } - if ($entity->user_id == $company_user->_user_id || $entity->assigned_user_id == $company_user->user_id) { - array_push($required_permissions, 'all_user_notifications'); - } + // if ($entity->user_id == $company_user->_user_id || $entity->assigned_user_id == $company_user->user_id) { + // array_push($required_permissions, 'all_user_notifications'); + // } if (count(array_intersect($required_permissions, $notifications->email)) >= 1 || count(array_intersect($required_permissions, ['all_user_notifications'])) >= 1 || count(array_intersect($required_permissions, ['all_notifications'])) >= 1) { array_push($notifiable_methods, 'mail'); From f1ced66226e551f85841bd2e4872d39b4e0d15aa Mon Sep 17 00:00:00 2001 From: = Date: Wed, 24 Mar 2021 14:26:51 +1100 Subject: [PATCH 7/7] Fixes for notifications --- .../Credit/CreditEmailedNotification.php | 2 +- .../Invoice/InvoiceEmailedNotification.php | 2 +- .../InvoiceFailedEmailNotification.php | 2 +- .../Quote/QuoteEmailedNotification.php | 2 +- .../Traits/Notifications/UserNotifies.php | 20 +++++++------------ 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/app/Listeners/Credit/CreditEmailedNotification.php b/app/Listeners/Credit/CreditEmailedNotification.php index dd7f3bd5e06f..48dcf314623e 100644 --- a/app/Listeners/Credit/CreditEmailedNotification.php +++ b/app/Listeners/Credit/CreditEmailedNotification.php @@ -54,7 +54,7 @@ class CreditEmailedNotification implements ShouldQueue // $notification = new EntitySentNotification($event->invitation, 'credit'); - $methods = $this->findUserNotificationTypes($event->invitation, $company_user, 'credit', ['all_notifications', 'credit_sent']); + $methods = $this->findUserNotificationTypes($event->invitation, $company_user, 'credit', ['all_notifications', 'credit_sent', 'credit_sent_all']); if (($key = array_search('mail', $methods)) !== false && $first_notification_sent === true) { unset($methods[$key]); diff --git a/app/Listeners/Invoice/InvoiceEmailedNotification.php b/app/Listeners/Invoice/InvoiceEmailedNotification.php index 1bffd1d37649..4a3b7f77e64f 100644 --- a/app/Listeners/Invoice/InvoiceEmailedNotification.php +++ b/app/Listeners/Invoice/InvoiceEmailedNotification.php @@ -60,7 +60,7 @@ class InvoiceEmailedNotification implements ShouldQueue // $notification = new EntitySentNotification($event->invitation, 'invoice'); /* Returns an array of notification methods */ - $methods = $this->findUserNotificationTypes($event->invitation, $company_user, 'invoice', ['all_notifications', 'invoice_sent']); + $methods = $this->findUserNotificationTypes($event->invitation, $company_user, 'invoice', ['all_notifications', 'invoice_sent', 'invoice_sent_all']); /* If one of the methods is email then we fire the EntitySentMailer */ if (($key = array_search('mail', $methods)) !== false && $first_notification_sent === true) { diff --git a/app/Listeners/Invoice/InvoiceFailedEmailNotification.php b/app/Listeners/Invoice/InvoiceFailedEmailNotification.php index aeda48fbfb62..d235b4a95cc2 100644 --- a/app/Listeners/Invoice/InvoiceFailedEmailNotification.php +++ b/app/Listeners/Invoice/InvoiceFailedEmailNotification.php @@ -56,7 +56,7 @@ class InvoiceFailedEmailNotification // $notification = new EntitySentNotification($event->invitation, 'invoice'); - $methods = $this->findUserNotificationTypes($event->invitation, $company_user, 'invoice', ['all_notifications', 'invoice_sent']); + $methods = $this->findUserNotificationTypes($event->invitation, $company_user, 'invoice', ['all_notifications', 'invoice_sent', 'invoice_sent_all']); if (($key = array_search('mail', $methods)) !== false && $first_notification_sent === true) { unset($methods[$key]); diff --git a/app/Listeners/Quote/QuoteEmailedNotification.php b/app/Listeners/Quote/QuoteEmailedNotification.php index 7cb0995f638d..43ec02df255c 100644 --- a/app/Listeners/Quote/QuoteEmailedNotification.php +++ b/app/Listeners/Quote/QuoteEmailedNotification.php @@ -55,7 +55,7 @@ class QuoteEmailedNotification implements ShouldQueue // $notification = new EntitySentNotification($event->invitation, 'quote'); - $methods = $this->findUserNotificationTypes($event->invitation, $company_user, 'quote', ['all_notifications', 'quote_sent']); + $methods = $this->findUserNotificationTypes($event->invitation, $company_user, 'quote', ['all_notifications', 'quote_sent', 'quote_sent_all']); if (($key = array_search('mail', $methods)) !== false && $first_notification_sent === true) { unset($methods[$key]); diff --git a/app/Utils/Traits/Notifications/UserNotifies.php b/app/Utils/Traits/Notifications/UserNotifies.php index 9710ee0282b7..efff7001004f 100644 --- a/app/Utils/Traits/Notifications/UserNotifies.php +++ b/app/Utils/Traits/Notifications/UserNotifies.php @@ -30,17 +30,11 @@ trait UserNotifies $notifications = $company_user->notifications; //if a user owns this record or is assigned to it, they are attached the permission for notification. - // if ($invitation->{$entity_name}->user_id == $company_user->_user_id || $invitation->{$entity_name}->assigned_user_id == $company_user->user_id) { - // array_push($required_permissions, 'all_user_notifications'); - // } -nlog($notifications); -nlog($required_permissions); -nlog($notifications->email); -nlog(count(array_intersect($required_permissions, $notifications->email))); -nlog(count(array_intersect(['all_user_notifications'], $notifications->email))); -nlog(count(array_intersect(['all_notifications'],$notifications->email))); + if ($invitation->{$entity_name}->user_id == $company_user->_user_id || $invitation->{$entity_name}->assigned_user_id == $company_user->user_id) { + array_push($required_permissions, 'all_user_notifications'); + } - if (count(array_intersect($required_permissions, $notifications->email)) >= 1 || count(array_intersect(['all_user_notifications'],$notifications->email)) >= 1 || count(array_intersect(['all_notifications'],$notifications->email)) >= 1) { + if (count(array_intersect($required_permissions, $notifications->email)) >= 1 || count(array_intersect(['all_user_notifications'], $notifications->email)) >= 1 || count(array_intersect(['all_notifications'],$notifications->email)) >= 1) { array_push($notifiable_methods, 'mail'); } @@ -65,9 +59,9 @@ nlog($notifiable_methods); return []; } - // if ($entity->user_id == $company_user->_user_id || $entity->assigned_user_id == $company_user->user_id) { - // array_push($required_permissions, 'all_user_notifications'); - // } + if ($entity->user_id == $company_user->_user_id || $entity->assigned_user_id == $company_user->user_id) { + array_push($required_permissions, 'all_user_notifications'); + } if (count(array_intersect($required_permissions, $notifications->email)) >= 1 || count(array_intersect($required_permissions, ['all_user_notifications'])) >= 1 || count(array_intersect($required_permissions, ['all_notifications'])) >= 1) { array_push($notifiable_methods, 'mail');