diff --git a/app/Http/Controllers/InvoiceApiController.php b/app/Http/Controllers/InvoiceApiController.php index 2a9bae80eab8..b0d7aede0710 100644 --- a/app/Http/Controllers/InvoiceApiController.php +++ b/app/Http/Controllers/InvoiceApiController.php @@ -214,13 +214,13 @@ class InvoiceApiController extends Controller } // if only the product key is set we'll load the cost and notes - if ($item['product_key'] && (!$item['cost'] || !$item['notes'])) { + if ($item['product_key'] && (is_null($item['cost']) || is_null($item['notes']))) { $product = Product::findProductByKey($item['product_key']); if ($product) { - if (!$item['cost']) { + if (is_null($item['cost'])) { $item['cost'] = $product->cost; } - if (!$item['notes']) { + if (is_null($item['notes'])) { $item['notes'] = $product->notes; } } diff --git a/app/Models/Account.php b/app/Models/Account.php index 16cdd8673f13..506f00a6e2d1 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -8,10 +8,14 @@ use Event; use App; use App\Events\UserSettingsChanged; use Illuminate\Database\Eloquent\SoftDeletes; +use Laracasts\Presenter\PresentableTrait; class Account extends Eloquent { + use PresentableTrait; use SoftDeletes; + + protected $presenter = 'App\Ninja\Presenters\AccountPresenter'; protected $dates = ['deleted_at']; protected $hidden = ['ip']; @@ -132,6 +136,15 @@ class Account extends Eloquent return !$this->language_id || $this->language_id == DEFAULT_LANGUAGE; } + public function hasInvoicePrefix() + { + if ( ! $this->invoice_number_prefix && ! $this->quote_number_prefix) { + return false; + } + + return $this->invoice_number_prefix != $this->quote_number_prefix; + } + public function getDisplayName() { if ($this->name) { diff --git a/app/Models/Contact.php b/app/Models/Contact.php index 731900e35840..782a7e47424a 100644 --- a/app/Models/Contact.php +++ b/app/Models/Contact.php @@ -32,20 +32,6 @@ class Contact extends EntityModel return PERSON_CONTACT; } - /* - public function getLastLogin() - { - if ($this->last_login == '0000-00-00 00:00:00') - { - return '---'; - } - else - { - return $this->last_login->format('m/d/y h:i a'); - } - } - */ - public function getName() { return $this->getDisplayName(); diff --git a/app/Ninja/Mailers/ContactMailer.php b/app/Ninja/Mailers/ContactMailer.php index cce2b5fc167b..9858ee66ccfc 100644 --- a/app/Ninja/Mailers/ContactMailer.php +++ b/app/Ninja/Mailers/ContactMailer.php @@ -91,6 +91,7 @@ class ContactMailer extends Mailer 'entityType' => $invoice->getEntityType(), 'invoiceId' => $invoice->id, 'invitation' => $invitation, + 'account' => $account, ]; if ($account->attatchPDF()) { @@ -137,11 +138,12 @@ class ContactMailer extends Mailer 'account' => $account, 'client' => $client, 'invitation' => $invitation, - 'amount' => $payment->amount + 'amount' => $payment->amount, ]; $data = [ - 'body' => $this->processVariables($emailTemplate, $variables) + 'body' => $this->processVariables($emailTemplate, $variables), + 'account' => $account, ]; if ($account->attatchPDF()) { diff --git a/app/Ninja/Presenters/AccountPresenter.php b/app/Ninja/Presenters/AccountPresenter.php new file mode 100644 index 000000000000..a53f9f20c1a6 --- /dev/null +++ b/app/Ninja/Presenters/AccountPresenter.php @@ -0,0 +1,12 @@ +entity->name ?: trans('texts.untitled_account'); + } + +} \ No newline at end of file diff --git a/app/Ninja/Repositories/InvoiceRepository.php b/app/Ninja/Repositories/InvoiceRepository.php index 24e808c3f922..44ce5d4c9a4c 100644 --- a/app/Ninja/Repositories/InvoiceRepository.php +++ b/app/Ninja/Repositories/InvoiceRepository.php @@ -348,19 +348,19 @@ class InvoiceRepository extends BaseRepository $clone = Invoice::createNew($invoice); $clone->balance = $invoice->amount; - // if the invoice prefix is diff than quote prefix, use the same number for the invoice - if (($account->invoice_number_prefix || $account->quote_number_prefix) - && $account->invoice_number_prefix != $account->quote_number_prefix - && $account->share_counter) { - + // if the invoice prefix is diff than quote prefix, use the same number for the invoice (if it's available) + $invoiceNumber = false; + if ($account->hasInvoicePrefix() && $account->share_counter) { $invoiceNumber = $invoice->invoice_number; if ($account->quote_number_prefix && strpos($invoiceNumber, $account->quote_number_prefix) === 0) { $invoiceNumber = substr($invoiceNumber, strlen($account->quote_number_prefix)); } - $clone->invoice_number = $account->invoice_number_prefix.$invoiceNumber; - } else { - $clone->invoice_number = $account->getNextInvoiceNumber($invoice); + $invoiceNumber = $account->invoice_number_prefix . $invoiceNumber; + if (Invoice::scope()->withTrashed()->whereInvoiceNumber($invoiceNumber)->first()) { + $invoiceNumber = false; + } } + $clone->invoice_number = $invoiceNumber ?: $account->getNextInvoiceNumber($clone); foreach ([ 'client_id', diff --git a/app/Ninja/Transformers/AccountTransformer.php b/app/Ninja/Transformers/AccountTransformer.php index b81e8847bd1d..e10938ebe235 100644 --- a/app/Ninja/Transformers/AccountTransformer.php +++ b/app/Ninja/Transformers/AccountTransformer.php @@ -26,7 +26,7 @@ class AccountTransformer extends TransformerAbstract { return [ 'account_key' => $account->account_key, - 'name' => $account->name, + 'name' => $account->present()->name, ]; } } \ No newline at end of file diff --git a/app/Ninja/Transformers/UserAccountTransformer.php b/app/Ninja/Transformers/UserAccountTransformer.php index fee2c14816e8..2b3724a2f601 100644 --- a/app/Ninja/Transformers/UserAccountTransformer.php +++ b/app/Ninja/Transformers/UserAccountTransformer.php @@ -27,7 +27,7 @@ class UserAccountTransformer extends TransformerAbstract { return [ 'account_key' => $user->account->account_key, - 'name' => $user->account->name, + 'name' => $user->account->present()->name, 'token' => $user->account->getToken($this->tokenName), ]; } diff --git a/composer.json b/composer.json index 7ce195f974c1..20c80fd00036 100644 --- a/composer.json +++ b/composer.json @@ -58,7 +58,8 @@ "meebio/omnipay-secure-trading": "dev-master", "justinbusschau/omnipay-secpay": "~2.0", "labs7in0/omnipay-wechat": "dev-master", - "collizo4sky/omnipay-wepay": "~1.0" + "collizo4sky/omnipay-wepay": "~1.0", + "laracasts/presenter": "dev-master" }, "require-dev": { "phpunit/phpunit": "~4.0", diff --git a/database/seeds/UserTableSeeder.php b/database/seeds/UserTableSeeder.php index 2d6c32796d1c..2f27b9479304 100644 --- a/database/seeds/UserTableSeeder.php +++ b/database/seeds/UserTableSeeder.php @@ -14,7 +14,7 @@ class UserTableSeeder extends Seeder Eloquent::unguard(); $account = Account::create([ - 'name' => 'Test Account', + //'name' => 'Test Account', 'account_key' => str_random(RANDOM_KEY_LENGTH), 'timezone_id' => 1, ]); diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 154b23025bce..2a0ffc3986db 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -907,5 +907,6 @@ return array( 'restore_recurring_invoice' => 'Restore Recurring Invoice', 'restored_recurring_invoice' => 'Successfully restored recurring invoice', 'archived' => 'Archived', + 'untitled_account' => 'Untitled Company', ); diff --git a/resources/views/emails/view_action.blade.php b/resources/views/emails/view_action.blade.php index 718af5a5968d..987aa527a02b 100644 --- a/resources/views/emails/view_action.blade.php +++ b/resources/views/emails/view_action.blade.php @@ -5,13 +5,13 @@ "description":"View your {{ $entityType }}", "action": { "@type": "ViewAction", - "url": "{{{ $link }}}", + "url": "{!! $link !!}", "name": "View {{ $entityType }}" - }, + }, "publisher": { "@type": "Organization", "name": "Invoice Ninja", - "url": "{{{ NINJA_WEB_URL }}}" + "url": "{!! NINJA_WEB_URL !!}" } } \ No newline at end of file diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index d4e1ad2055fb..a2c90a1d9d81 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -77,7 +77,8 @@