diff --git a/app/Models/Account.php b/app/Models/Account.php index e8e1e6eac1d5..1e2f8bda1860 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -9,6 +9,7 @@ use App\Models\Traits\GeneratesNumbers; use App\Models\Traits\PresentsInvoice; use App\Models\Traits\SendsEmails; use App\Models\Traits\HasLogo; +use App\Models\Traits\HasCustomMessages; use Cache; use Carbon; use DateTime; @@ -30,6 +31,7 @@ class Account extends Eloquent use GeneratesNumbers; use SendsEmails; use HasLogo; + use HasCustomMessages; /** * @var string @@ -280,7 +282,7 @@ class Account extends Eloquent CUSTOM_MESSAGE_PAID_INVOICE, CUSTOM_MESSAGE_UNAPPROVED_QUOTE, //CUSTOM_MESSAGE_APPROVED_QUOTE, - CUSTOM_MESSAGE_UNAPPROVED_PROPOSAL, + //CUSTOM_MESSAGE_UNAPPROVED_PROPOSAL, //CUSTOM_MESSAGE_APPROVED_PROPOSAL, ]; @@ -548,38 +550,6 @@ class Account extends Eloquent return ! empty($labels->$field) ? $labels->$field : ''; } - /** - * @param $value - */ - public function setCustomMessagesAttribute($data) - { - $fields = []; - - if (! is_array($data)) { - $data = json_decode($data); - } - - foreach ($data as $key => $value) { - if ($value) { - $fields[$key] = $value; - } - } - - $this->attributes['custom_messages'] = count($fields) ? json_encode($fields) : null; - } - - public function getCustomMessagesAttribute($value) - { - return json_decode($value ?: '{}'); - } - - public function customMessage($type) - { - $messages = $this->custom_messages; - - return ! empty($messages->$type) ? $messages->$type : ''; - } - /** * @param int $gatewayId * diff --git a/app/Models/Client.php b/app/Models/Client.php index 24b45e131fc2..9541e4c9dddf 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -6,6 +6,7 @@ use Carbon; use DB; use Illuminate\Database\Eloquent\SoftDeletes; use Laracasts\Presenter\PresentableTrait; +use App\Models\Traits\HasCustomMessages; use Utils; /** @@ -15,6 +16,7 @@ class Client extends EntityModel { use PresentableTrait; use SoftDeletes; + use HasCustomMessages; /** * @var string @@ -61,6 +63,7 @@ class Client extends EntityModel 'shipping_country_id', 'show_tasks_in_portal', 'send_reminders', + 'custom_messages', ]; /** diff --git a/app/Models/Traits/HasCustomMessages.php b/app/Models/Traits/HasCustomMessages.php new file mode 100644 index 000000000000..49472cdf85dc --- /dev/null +++ b/app/Models/Traits/HasCustomMessages.php @@ -0,0 +1,49 @@ + $value) { + if ($value) { + $fields[$key] = $value; + } + } + + $this->attributes['custom_messages'] = count($fields) ? json_encode($fields) : null; + } + + public function getCustomMessagesAttribute($value) + { + return json_decode($value ?: '{}'); + } + + public function customMessage($type) + { + $messages = $this->custom_messages; + + if (! empty($messages->$type)) { + return $messages->$type; + } + + if ($this->account) { + return $this->account->customMessage($type); + } else { + return ''; + } + } +} diff --git a/app/Ninja/Transformers/ClientTransformer.php b/app/Ninja/Transformers/ClientTransformer.php index 24d6161e2c78..7da62cf1a64d 100644 --- a/app/Ninja/Transformers/ClientTransformer.php +++ b/app/Ninja/Transformers/ClientTransformer.php @@ -155,6 +155,7 @@ class ClientTransformer extends EntityTransformer 'show_tasks_in_portal' => (bool) $client->show_tasks_in_portal, 'send_reminders' => (bool) $client->send_reminders, 'credit_number_counter' => (int) $client->credit_number_counter, + 'custom_messages' => json_encode($client->custom_messages), ]); } } diff --git a/database/migrations/2018_03_30_115805_add_more_custom_fields.php b/database/migrations/2018_03_30_115805_add_more_custom_fields.php index 0ce2928a3545..3ec3b2512ba7 100644 --- a/database/migrations/2018_03_30_115805_add_more_custom_fields.php +++ b/database/migrations/2018_03_30_115805_add_more_custom_fields.php @@ -82,6 +82,10 @@ class AddMoreCustomFields extends Migration $table->mediumText('custom_messages')->nullable(); }); + Schema::table('clients', function ($table) { + $table->mediumText('custom_messages')->nullable(); + }); + Schema::table('tasks', function ($table) { $table->text('custom_value1')->nullable(); $table->text('custom_value2')->nullable(); diff --git a/resources/views/accounts/client_portal.blade.php b/resources/views/accounts/client_portal.blade.php index 1528a7ddec1f..1f3a104be2b5 100644 --- a/resources/views/accounts/client_portal.blade.php +++ b/resources/views/accounts/client_portal.blade.php @@ -59,7 +59,7 @@ {{ trans('texts.navigation') }}
  • - {{ trans('texts.messages') }} + {{ trans('texts.messages') }}
  • {{ trans('texts.custom_css') }} diff --git a/resources/views/clients/edit.blade.php b/resources/views/clients/edit.blade.php index 6552f119f57c..dae056332eed 100644 --- a/resources/views/clients/edit.blade.php +++ b/resources/views/clients/edit.blade.php @@ -196,6 +196,9 @@ {{ trans('texts.notes') }}
  • + {{ trans('texts.messages') }} +
  • +
  • {{ trans('texts.classify') }}
  • @@ -232,6 +235,12 @@ {!! Former::textarea('public_notes')->rows(6) !!} {!! Former::textarea('private_notes')->rows(6) !!} +
    + @foreach (App\Models\Account::$customMessageTypes as $type) + {!! Former::textarea('custom_messages[' . $type . ']') + ->label($type) !!} + @endforeach +
    {!! Former::select('size_id')->addOption('','') ->fromQuery($sizes, 'name', 'id') !!} diff --git a/resources/views/invited/dashboard.blade.php b/resources/views/invited/dashboard.blade.php index 63ab3d09e19b..43a989bbf5b2 100644 --- a/resources/views/invited/dashboard.blade.php +++ b/resources/views/invited/dashboard.blade.php @@ -276,7 +276,7 @@
    - @if ($message = $account->customMessage(CUSTOM_MESSAGE_DASHBOARD)) + @if ($message = $client->customMessage(CUSTOM_MESSAGE_DASHBOARD))
    {!! Utils::isNinja() ? HTMLUtils::sanitizeHTML($message) : $message !!}
    @endif diff --git a/resources/views/invited/proposal.blade.php b/resources/views/invited/proposal.blade.php index fdc5ff363a53..20b1fc5e303a 100644 --- a/resources/views/invited/proposal.blade.php +++ b/resources/views/invited/proposal.blade.php @@ -24,7 +24,7 @@
    - @if ($message = $account->customMessage($proposal->getCustomMessageType())) + @if ($message = $proposal->invoice->client->customMessage($proposal->getCustomMessageType()))
    {!! Utils::isNinja() ? HTMLUtils::sanitizeHTML($message) : $message !!}
    @endif diff --git a/resources/views/invoices/view.blade.php b/resources/views/invoices/view.blade.php index 28e9203c0923..28076a87561a 100644 --- a/resources/views/invoices/view.blade.php +++ b/resources/views/invoices/view.blade.php @@ -152,7 +152,7 @@
    - @if ($message = $account->customMessage($invoice->getCustomMessageType())) + @if ($message = $invoice->client->customMessage($invoice->getCustomMessageType()))
    {!! Utils::isNinja() ? HTMLUtils::sanitizeHTML($message) : $message !!}
    @endif