diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 8da02ecec643..8d9fe10e9316 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -4,12 +4,20 @@ namespace App\Models; use Auth; use Eloquent; +use Laracasts\Presenter\PresentableTrait; /** * Class Activity. */ class Activity extends Eloquent { + use PresentableTrait; + + /** + * @var string + */ + protected $presenter = 'App\Ninja\Presenters\ActivityPresenter'; + /** * @var bool */ diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index e2b0c56a3b8b..5cfe168d3a9a 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -9,6 +9,7 @@ use App\Events\QuoteInvitationWasEmailed; use App\Events\QuoteWasCreated; use App\Events\QuoteWasUpdated; use App\Libraries\CurlUtils; +use App\Models\Activity; use DateTime; use Illuminate\Database\Eloquent\SoftDeletes; use Laracasts\Presenter\PresentableTrait; @@ -1441,6 +1442,16 @@ class Invoice extends EntityModel implements BalanceAffecting return $statuses; } + + public function emailHistory() + { + return Activity::scope() + ->with(['contact']) + ->whereInvoiceId($this->id) + ->whereIn('activity_type_id', [ACTIVITY_TYPE_EMAIL_INVOICE, ACTIVITY_TYPE_EMAIL_QUOTE]) + ->orderBy('id', 'desc') + ->get(); + } } Invoice::creating(function ($invoice) { diff --git a/app/Ninja/Presenters/ActivityPresenter.php b/app/Ninja/Presenters/ActivityPresenter.php new file mode 100644 index 000000000000..6978ce8695b0 --- /dev/null +++ b/app/Ninja/Presenters/ActivityPresenter.php @@ -0,0 +1,39 @@ +entity->created_at)); + } + + public function createdAtDate() + { + return Utils::dateToString($this->entity->created_at); + } + + public function user() + { + if ($this->entity->is_system) { + return '' . trans('texts.system') . ''; + } else { + return $this->entity->user->getDisplayName(); + } + } + + public function notes() + { + if ($this->entity->notes) { + return trans('texts.notes_' . $this->entity->notes); + } elseif (in_array($this->entity->activity_type_id, [ACTIVITY_TYPE_EMAIL_INVOICE, ACTIVITY_TYPE_EMAIL_QUOTE])) { + return trans('texts.initial_email'); + } else { + return ''; + } + } +} diff --git a/app/Ninja/Presenters/InvoicePresenter.php b/app/Ninja/Presenters/InvoicePresenter.php index 8449d357231e..8e7cbbf985af 100644 --- a/app/Ninja/Presenters/InvoicePresenter.php +++ b/app/Ninja/Presenters/InvoicePresenter.php @@ -3,6 +3,7 @@ namespace App\Ninja\Presenters; use App\Libraries\Skype\InvoiceCard; +use App\Models\Activity; use Carbon; use DropdownButton; use stdClass; diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 8e02aee15646..97d9c232ee5e 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -494,7 +494,7 @@ $LANG = array( 'email_address' => 'Email address', 'lets_go' => 'Let\'s go', 'password_recovery' => 'Password Recovery', - 'send_email' => 'Send email', + 'send_email' => 'Send Email', 'set_password' => 'Set Password', 'converted' => 'Converted', 'email_approved' => 'Email me when a quote is approved', @@ -2347,6 +2347,13 @@ $LANG = array( 'inactivity_logout' => 'Due to inactivity, you have been automatically logged out.', 'mark_active' => 'Mark Active', 'send_automatically' => 'Send Automatically', + 'template' => 'Template', + 'initial_email' => 'Initial Email', + 'invoice_not_emailed' => 'This invoice hasn\'t been emailed.', + 'quote_not_emailed' => 'This quote hasn\'t been emailed.', + 'days_ago' => ':count day ago|:count days ago', + 'sent_by' => 'Sent by :user', + 'recipients' => 'Recipients', ); diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index 1077001cc728..88af4432f125 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -799,6 +799,8 @@ + @include('invoices.email') + {!! Former::close() !!} @@ -1284,24 +1286,33 @@ return; } - sweetConfirm(function() { - model.invoice().is_public(true); - var accountLanguageId = parseInt({{ $account->language_id ?: '0' }}); - var clientLanguageId = parseInt(model.invoice().client().language_id()) || 0; - var attachPDF = {{ $account->attachPDF() ? 'true' : 'false' }}; - - // if they aren't attaching the pdf no need to generate it - if ( ! attachPDF) { - submitAction('email'); - // if the client's language is different then we can't use the browser version of the PDF - } else if (clientLanguageId && clientLanguageId != accountLanguageId) { - submitAction('email'); - } else { - preparePdfData('email'); - } - }, getSendToEmails()); + $('#recipients').html(getSendToEmails()); + $('#emailModal').modal('show'); } + function onConfirmEmailClick() { + model.invoice().is_public(true); + var accountLanguageId = parseInt({{ $account->language_id ?: '0' }}); + var clientLanguageId = parseInt(model.invoice().client().language_id()) || 0; + var attachPDF = {{ $account->attachPDF() ? 'true' : 'false' }}; + + // if they aren't attaching the pdf no need to generate it + if ( ! attachPDF) { + submitAction('email'); + // if the client's language is different then we can't use the browser version of the PDF + } else if (clientLanguageId && clientLanguageId != accountLanguageId) { + submitAction('email'); + } else { + preparePdfData('email'); + } + } + + @if (Utils::isNinjaDev()) + $(function() { + onEmailClick(); + }) + @endif + function onSaveDraftClick() { model.invoice().is_public(false); onSaveClick(); @@ -1310,7 +1321,7 @@ function onMarkSentClick() { if (model.invoice().is_recurring()) { // warn invoice will be emailed when saving new recurring invoice - var text = getSendToEmails() + '\n' + "{!! trans("texts.confirm_recurring_timing") !!}"; + var text = '\n' + getSendToEmails() + '\n\n' + "{!! trans("texts.confirm_recurring_timing") !!}"; var title = "{!! trans("texts.confirm_recurring_email_$entityType") !!}"; sweetConfirm(function() { model.invoice().is_public(true); diff --git a/resources/views/invoices/email.blade.php b/resources/views/invoices/email.blade.php new file mode 100644 index 000000000000..6b3f01ebb416 --- /dev/null +++ b/resources/views/invoices/email.blade.php @@ -0,0 +1,93 @@ +
+ + diff --git a/resources/views/invoices/knockout.blade.php b/resources/views/invoices/knockout.blade.php index bb9f3d96feaf..3d927d4d2d4f 100644 --- a/resources/views/invoices/knockout.blade.php +++ b/resources/views/invoices/knockout.blade.php @@ -641,13 +641,13 @@ function ContactModel(data) { self.displayName = ko.computed(function() { var str = ''; if (self.first_name() || self.last_name()) { - str += (self.first_name() || '') + ' ' + (self.last_name() || '') + '\n'; + str += (self.first_name() || '') + ' ' + (self.last_name() || '') + ' '; } if (self.email()) { - str += self.email() + '\n'; + str += '<' + self.email() + '>'; } - return str; + return str + '