diff --git a/app/Constants.php b/app/Constants.php index 6cd1e0243e6a..41fedbd23f24 100644 --- a/app/Constants.php +++ b/app/Constants.php @@ -469,6 +469,14 @@ if (! defined('APP_NAME')) { define('TEMPLATE_REMINDER3', 'reminder3'); define('TEMPLATE_REMINDER4', 'reminder4'); + define('CUSTOM_MESSAGE_DASHBOARD', 'dashboard'); + define('CUSTOM_MESSAGE_UNPAID_INVOICE', 'unpaid_invoice'); + define('CUSTOM_MESSAGE_PAID_INVOICE', 'paid_invoice'); + define('CUSTOM_MESSAGE_UNAPPROVED_QUOTE', 'unapproved_quote'); + define('CUSTOM_MESSAGE_APPROVED_QUOTE', 'approved_quote'); + define('CUSTOM_MESSAGE_UNAPPROVED_PROPOSAL', 'unapproved_proposal'); + define('CUSTOM_MESSAGE_APPROVED_PROPOSAL', 'approved_proposal'); + define('RESET_FREQUENCY_DAILY', 1); define('RESET_FREQUENCY_WEEKLY', 2); define('RESET_FREQUENCY_MONTHLY', 3); diff --git a/app/Models/Account.php b/app/Models/Account.php index ac7dea62756c..e8e1e6eac1d5 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -173,6 +173,7 @@ class Account extends Eloquent 'custom_fields', 'custom_value1', 'custom_value2', + 'custom_messages', ]; /** @@ -273,6 +274,16 @@ class Account extends Eloquent 'vat_number', ]; + public static $customMessageTypes = [ + CUSTOM_MESSAGE_DASHBOARD, + CUSTOM_MESSAGE_UNPAID_INVOICE, + CUSTOM_MESSAGE_PAID_INVOICE, + CUSTOM_MESSAGE_UNAPPROVED_QUOTE, + //CUSTOM_MESSAGE_APPROVED_QUOTE, + CUSTOM_MESSAGE_UNAPPROVED_PROPOSAL, + //CUSTOM_MESSAGE_APPROVED_PROPOSAL, + ]; + /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ @@ -537,6 +548,38 @@ 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/Invoice.php b/app/Models/Invoice.php index f7af65a6d0ae..8e596489e515 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -529,6 +529,18 @@ class Invoice extends EntityModel implements BalanceAffecting return $this->isType(INVOICE_TYPE_QUOTE); } + /** + * @return string + */ + public function getCustomMessageType() + { + if ($this->isQuote()) { + return $this->quote_invoice_id ? CUSTOM_MESSAGE_APPROVED_QUOTE : CUSTOM_MESSAGE_UNAPPROVED_QUOTE; + } else { + return $this->balance > 0 ? CUSTOM_MESSAGE_UNPAID_INVOICE : CUSTOM_MESSAGE_PAID_INVOICE; + } + } + /** * @return bool */ diff --git a/app/Models/Proposal.php b/app/Models/Proposal.php index b079bf347923..b6e4962fb763 100644 --- a/app/Models/Proposal.php +++ b/app/Models/Proposal.php @@ -115,6 +115,19 @@ class Proposal extends EntityModel return trans('texts.proposal') . '_' . $this->invoice->invoice_number . '.' . $extension; } + + /** + * @return string + */ + public function getCustomMessageType() + { + if ($this->invoice->quote_invoice_id) { + return CUSTOM_MESSAGE_APPROVED_PROPOSAL; + } else { + return CUSTOM_MESSAGE_UNAPPROVED_PROPOSAL; + } + } + } Proposal::creating(function ($project) { diff --git a/app/Ninja/Transformers/AccountTransformer.php b/app/Ninja/Transformers/AccountTransformer.php index 486e15ef9afd..3e9b44815775 100644 --- a/app/Ninja/Transformers/AccountTransformer.php +++ b/app/Ninja/Transformers/AccountTransformer.php @@ -272,6 +272,7 @@ class AccountTransformer extends EntityTransformer 'custom_invoice_taxes1' => $account->custom_invoice_taxes1, 'custom_invoice_taxes2' => $account->custom_invoice_taxes1, 'custom_fields' => json_encode($account->custom_fields), + 'custom_messages' => json_encode($account->custom_messages), 'custom_invoice_label1' => $account->customLabel('invoice1'), 'custom_invoice_label2' => $account->customLabel('invoice2'), 'custom_client_label1' => $account->customLabel('client1'), 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 20ca164b9252..0ce2928a3545 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 @@ -78,6 +78,10 @@ class AddMoreCustomFields extends Migration $table->dropColumn('custom_invoice_item_label2'); }); + Schema::table('accounts', 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/lang/en/texts.php b/resources/lang/en/texts.php index 56988b37cff7..35b5971522df 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2818,6 +2818,12 @@ $LANG = array( 'custom_project_fields_help' => 'Add a field when creating a project.', 'custom_expense_fields_help' => 'Add a field when creating an expense.', 'custom_vendor_fields_help' => 'Add a field when creating a vendor.', + 'messages' => 'Messages', + 'unpaid_invoice' => 'Unpaid Invoice', + 'paid_invoice' => 'Paid Invoice', + 'unapproved_quote' => 'Unapproved Quote', + 'unapproved_proposal' => 'Unapproved Proposal', + ); return $LANG; diff --git a/resources/views/accounts/client_portal.blade.php b/resources/views/accounts/client_portal.blade.php index 509273b60aaa..1528a7ddec1f 100644 --- a/resources/views/accounts/client_portal.blade.php +++ b/resources/views/accounts/client_portal.blade.php @@ -58,6 +58,9 @@
  • {{ trans('texts.navigation') }}
  • +
  • + {{ trans('texts.messages') }} +
  • {{ trans('texts.custom_css') }}
  • @@ -124,6 +127,16 @@ +
    +
    + + @foreach (App\Models\Account::$customMessageTypes as $type) + {!! Former::textarea('custom_messages[' . $type . ']') + ->label($type) !!} + @endforeach + +
    +
    diff --git a/resources/views/invited/dashboard.blade.php b/resources/views/invited/dashboard.blade.php index 02cf0ebe4369..63ab3d09e19b 100644 --- a/resources/views/invited/dashboard.blade.php +++ b/resources/views/invited/dashboard.blade.php @@ -276,6 +276,9 @@
    + @if ($message = $account->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 abaed1b29127..fdc5ff363a53 100644 --- a/resources/views/invited/proposal.blade.php +++ b/resources/views/invited/proposal.blade.php @@ -24,6 +24,10 @@
    + @if ($message = $account->customMessage($proposal->getCustomMessageType())) +
    {!! Utils::isNinja() ? HTMLUtils::sanitizeHTML($message) : $message !!}
    + @endif +
    {!! Button::normal(trans('texts.download'))->asLinkTo(url("/proposal/{$proposalInvitation->invitation_key}/download"))->large() !!} @if (! $proposal->invoice->isApproved()) diff --git a/resources/views/invoices/view.blade.php b/resources/views/invoices/view.blade.php index d5aa7a9306c0..28e9203c0923 100644 --- a/resources/views/invoices/view.blade.php +++ b/resources/views/invoices/view.blade.php @@ -152,6 +152,10 @@
    + @if ($message = $account->customMessage($invoice->getCustomMessageType())) +
    {!! Utils::isNinja() ? HTMLUtils::sanitizeHTML($message) : $message !!}
    + @endif + @if (!empty($partialView)) @include($partialView) @else