From 6ff1c79db35bb4aedb4abb7133b57c776ba42537 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 5 Jan 2017 12:46:03 +0200 Subject: [PATCH] Label reminder activity records --- app/Events/InvoiceInvitationWasEmailed.php | 8 +++++++- app/Events/QuoteInvitationWasEmailed.php | 8 +++++++- app/Http/Controllers/DashboardController.php | 4 ++-- app/Listeners/ActivityListener.php | 6 ++++-- app/Models/Invoice.php | 10 +++++----- app/Models/Traits/GeneratesNumbers.php | 4 +++- app/Ninja/Datatables/ActivityDatatable.php | 8 +++++++- app/Ninja/Mailers/ContactMailer.php | 6 ++++-- app/Ninja/Mailers/Mailer.php | 8 ++------ app/Ninja/Repositories/ActivityRepository.php | 9 ++++----- .../2017_01_01_214241_add_inclusive_taxes.php | 9 +++++++++ resources/lang/en/texts.php | 3 +++ resources/views/invoices/pdf.blade.php | 6 +++--- 13 files changed, 60 insertions(+), 29 deletions(-) diff --git a/app/Events/InvoiceInvitationWasEmailed.php b/app/Events/InvoiceInvitationWasEmailed.php index b51e8af0c10d..8dfffefcd7ce 100644 --- a/app/Events/InvoiceInvitationWasEmailed.php +++ b/app/Events/InvoiceInvitationWasEmailed.php @@ -17,14 +17,20 @@ class InvoiceInvitationWasEmailed extends Event */ public $invitation; + /** + * @var String + */ + public $notes; + /** * Create a new event instance. * * @param Invitation $invitation */ - public function __construct(Invitation $invitation) + public function __construct(Invitation $invitation, $notes) { $this->invitation = $invitation; + $this->notes = $notes; } } diff --git a/app/Events/QuoteInvitationWasEmailed.php b/app/Events/QuoteInvitationWasEmailed.php index 54481ab9e763..a8d8d58ebeb7 100644 --- a/app/Events/QuoteInvitationWasEmailed.php +++ b/app/Events/QuoteInvitationWasEmailed.php @@ -15,14 +15,20 @@ class QuoteInvitationWasEmailed extends Event */ public $invitation; + /** + * @var String + */ + public $notes; + /** * Create a new event instance. * * @param Invitation $invitation */ - public function __construct(Invitation $invitation) + public function __construct(Invitation $invitation, $notes) { $this->invitation = $invitation; + $this->notes = $notes; } } diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index 9ca03d812b9d..641d57c4ef84 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -43,8 +43,8 @@ class DashboardController extends BaseController $expenses = $dashboardRepo->expenses($accountId, $userId, $viewAll); $tasks = $dashboardRepo->tasks($accountId, $userId, $viewAll); - $showBlueVinePromo = ! $account->company->bluevine_status - && env('BLUEVINE_PARTNER_UNIQUE_ID') + $showBlueVinePromo = env('BLUEVINE_PARTNER_UNIQUE_ID') + && ! $account->company->bluevine_status && $account->created_at <= date( 'Y-m-d', strtotime( '-1 month' )); $showWhiteLabelExpired = Utils::isSelfHost() && $account->company->hasExpiredPlan(PLAN_WHITE_LABEL); diff --git a/app/Listeners/ActivityListener.php b/app/Listeners/ActivityListener.php index c2e60b0d587c..55056453eb7b 100644 --- a/app/Listeners/ActivityListener.php +++ b/app/Listeners/ActivityListener.php @@ -196,7 +196,8 @@ class ActivityListener ACTIVITY_TYPE_EMAIL_INVOICE, false, false, - $event->invitation + $event->invitation, + $event->notes ); } @@ -294,7 +295,8 @@ class ActivityListener ACTIVITY_TYPE_EMAIL_QUOTE, false, false, - $event->invitation + $event->invitation, + $event->notes ); } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 62374f885e04..a68a9527c212 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -395,14 +395,14 @@ class Invoice extends EntityModel implements BalanceAffecting /** * @param bool $notify */ - public function markInvitationsSent($notify = false) + public function markInvitationsSent($notify = false, $reminder = false) { if ( ! $this->relationLoaded('invitations')) { $this->load('invitations'); } foreach ($this->invitations as $invitation) { - $this->markInvitationSent($invitation, false, $notify); + $this->markInvitationSent($invitation, false, $notify, $reminder); } } @@ -426,7 +426,7 @@ class Invoice extends EntityModel implements BalanceAffecting * @param bool $messageId * @param bool $notify */ - public function markInvitationSent($invitation, $messageId = false, $notify = true) + public function markInvitationSent($invitation, $messageId = false, $notify = true, $notes = false) { if (!$this->isSent()) { $this->invoice_status_id = INVOICE_STATUS_SENT; @@ -442,9 +442,9 @@ class Invoice extends EntityModel implements BalanceAffecting } if ($this->isType(INVOICE_TYPE_QUOTE)) { - event(new QuoteInvitationWasEmailed($invitation)); + event(new QuoteInvitationWasEmailed($invitation, $notes)); } else { - event(new InvoiceInvitationWasEmailed($invitation)); + event(new InvoiceInvitationWasEmailed($invitation, $notes)); } } diff --git a/app/Models/Traits/GeneratesNumbers.php b/app/Models/Traits/GeneratesNumbers.php index ab75e36d4405..418bc70265d5 100644 --- a/app/Models/Traits/GeneratesNumbers.php +++ b/app/Models/Traits/GeneratesNumbers.php @@ -206,7 +206,9 @@ trait GeneratesNumbers public function incrementCounter($entity) { if ($entity->isEntityType(ENTITY_CLIENT)) { - $this->client_number_counter += 1; + if ($this->client_number_counter) { + $this->client_number_counter += 1; + } } elseif ($entity->isType(INVOICE_TYPE_QUOTE) && ! $this->share_counter) { $this->quote_number_counter += 1; } else { diff --git a/app/Ninja/Datatables/ActivityDatatable.php b/app/Ninja/Datatables/ActivityDatatable.php index 62fdc646d839..0261bfc3bb1d 100644 --- a/app/Ninja/Datatables/ActivityDatatable.php +++ b/app/Ninja/Datatables/ActivityDatatable.php @@ -32,7 +32,13 @@ class ActivityDatatable extends EntityDatatable 'expense' => $model->expense_public_id ? link_to('/expenses/' . $model->expense_public_id, substr($model->expense_public_notes, 0, 30).'...') : null, ]; - return trans("texts.activity_{$model->activity_type_id}", $data); + $str = trans("texts.activity_{$model->activity_type_id}", $data); + + if ($model->notes) { + $str .= ' - ' . trans("texts.notes_{$model->notes}"); + } + + return $str; } ], [ diff --git a/app/Ninja/Mailers/ContactMailer.php b/app/Ninja/Mailers/ContactMailer.php index 1845582ae227..d06fc6433c44 100644 --- a/app/Ninja/Mailers/ContactMailer.php +++ b/app/Ninja/Mailers/ContactMailer.php @@ -107,7 +107,7 @@ class ContactMailer extends Mailer } foreach ($invoice->invitations as $invitation) { - $response = $this->sendInvitation($invitation, $invoice, $emailTemplate, $emailSubject, $pdfString, $documentStrings); + $response = $this->sendInvitation($invitation, $invoice, $emailTemplate, $emailSubject, $pdfString, $documentStrings, $reminder); if ($response === true) { $sent = true; } @@ -142,7 +142,8 @@ class ContactMailer extends Mailer $body, $subject, $pdfString, - $documentStrings + $documentStrings, + $reminder ) { @@ -197,6 +198,7 @@ class ContactMailer extends Mailer 'client' => $client, 'invoice' => $invoice, 'documents' => $documentStrings, + 'notes' => $reminder, ]; if ($account->attachPDF()) { diff --git a/app/Ninja/Mailers/Mailer.php b/app/Ninja/Mailers/Mailer.php index c38a2c8704ad..ea2f9cde77e7 100644 --- a/app/Ninja/Mailers/Mailer.php +++ b/app/Ninja/Mailers/Mailer.php @@ -21,11 +21,6 @@ class Mailer */ public function sendTo($toEmail, $fromEmail, $fromName, $subject, $view, $data = []) { - // check the username is set - if ( ! env('POSTMARK_API_TOKEN') && ! env('MAIL_USERNAME')) { - return trans('texts.invalid_mail_config'); - } - // don't send emails to dummy addresses if (stristr($toEmail, '@example.com')) { return true; @@ -89,7 +84,8 @@ class Mailer $messageId = $json->MessageID; } - $invoice->markInvitationSent($invitation, $messageId); + $notes = isset($data['notes']) ? $data['notes']: false; + $invoice->markInvitationSent($invitation, $messageId, true, $notes); } return true; diff --git a/app/Ninja/Repositories/ActivityRepository.php b/app/Ninja/Repositories/ActivityRepository.php index 2a910707e44b..6a1b1a1740f1 100644 --- a/app/Ninja/Repositories/ActivityRepository.php +++ b/app/Ninja/Repositories/ActivityRepository.php @@ -10,7 +10,7 @@ use App\Models\Invitation; class ActivityRepository { - public function create($entity, $activityTypeId, $balanceChange = 0, $paidToDateChange = 0, $altEntity = null) + public function create($entity, $activityTypeId, $balanceChange = 0, $paidToDateChange = 0, $altEntity = null, $notes = false) { if ($entity instanceof Client) { $client = $entity; @@ -29,6 +29,7 @@ class ActivityRepository $activity->adjustment = $balanceChange; $activity->client_id = $client ? $client->id : 0; $activity->balance = $client ? ($client->balance + $balanceChange) : 0; + $activity->notes = $notes ?: ''; $keyField = $entity->getKeyField(); $activity->$keyField = $entity->id; @@ -53,10 +54,7 @@ class ActivityRepository } else { $activity->user_id = $entity->user_id; $activity->account_id = $entity->account_id; - - if ( ! $entity instanceof Invitation) { - $activity->is_system = true; - } + $activity->is_system = true; } $activity->token_id = session('token_id'); @@ -89,6 +87,7 @@ class ActivityRepository 'activities.is_system', 'activities.balance', 'activities.adjustment', + 'activities.notes', 'users.first_name as user_first_name', 'users.last_name as user_last_name', 'users.email as user_email', diff --git a/database/migrations/2017_01_01_214241_add_inclusive_taxes.php b/database/migrations/2017_01_01_214241_add_inclusive_taxes.php index 7362191045ae..9e0d7f4c8187 100644 --- a/database/migrations/2017_01_01_214241_add_inclusive_taxes.php +++ b/database/migrations/2017_01_01_214241_add_inclusive_taxes.php @@ -35,6 +35,10 @@ class AddInclusiveTaxes extends Migration $table->text('client_number_pattern')->nullable(); }); + Schema::table('activities', function ($table) + { + $table->text('notes')->nullable(); + }); } /** @@ -62,5 +66,10 @@ class AddInclusiveTaxes extends Migration $table->dropColumn('client_number_counter'); $table->dropColumn('client_number_pattern'); }); + + Schema::table('activities', function ($table) + { + $table->dropColumn('notes'); + }); } } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index f3c5349c7198..729043ee6548 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2301,6 +2301,9 @@ $LANG = array( 'client_number_help' => 'Specify a prefix or use a custom pattern to dynamically set the client number.', 'next_client_number' => 'The next client number is :number.', 'generated_numbers' => 'Generated Numbers', + 'notes_reminder1' => 'First Reminder', + 'notes_reminder2' => 'Second Reminder', + 'notes_reminder3' => 'Third Reminder', ); diff --git a/resources/views/invoices/pdf.blade.php b/resources/views/invoices/pdf.blade.php index 1e2142c40be8..521975ecc39d 100644 --- a/resources/views/invoices/pdf.blade.php +++ b/resources/views/invoices/pdf.blade.php @@ -1,6 +1,6 @@ -
- + @if (!Utils::isNinja() || !Utils::isPro()) @@ -144,7 +144,7 @@ page.render({canvasContext: context, viewport: viewport}); $('#theFrame').hide(); - $('#theCanvas').show(); + $('#theCanvasDiv').show(); isRefreshing = false; if (needsRefresh) { needsRefresh = false;