From 07b3fdb30cee2fde4be6c7986db0cedd9d0b85aa Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Fri, 7 Aug 2015 09:14:29 +0300 Subject: [PATCH] Minor improvements --- app/Http/routes.php | 3 +- app/Libraries/Utils.php | 9 +++--- app/Models/Account.php | 1 + app/Ninja/Repositories/AccountRepository.php | 2 +- public/js/built.js | 9 +++--- public/js/pdf.pdfmake.js | 6 ++-- public/js/script.js | 3 -- resources/lang/en/texts.php | 2 ++ resources/views/header.blade.php | 11 ++++--- resources/views/user_account.blade.php | 4 +-- .../views/users/account_management.blade.php | 29 ++++++++++++++++--- 11 files changed, 51 insertions(+), 28 deletions(-) diff --git a/app/Http/routes.php b/app/Http/routes.php index a9c322632db0..706ddbd3bb9e 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -1,5 +1,6 @@ id === 1) { Auth::loginUsingId(1); } -*/ +*/ \ No newline at end of file diff --git a/app/Libraries/Utils.php b/app/Libraries/Utils.php index 1efcf4b229a8..1263b4ed6763 100644 --- a/app/Libraries/Utils.php +++ b/app/Libraries/Utils.php @@ -341,10 +341,11 @@ class Utils return; } - $timezone = Session::get(SESSION_TIMEZONE, DEFAULT_TIMEZONE); + //$timezone = Session::get(SESSION_TIMEZONE, DEFAULT_TIMEZONE); $format = Session::get(SESSION_DATE_FORMAT, DEFAULT_DATE_FORMAT); - $dateTime = DateTime::createFromFormat($format, $date, new DateTimeZone($timezone)); + //$dateTime = DateTime::createFromFormat($format, $date, new DateTimeZone($timezone)); + $dateTime = DateTime::createFromFormat($format, $date); return $formatResult ? $dateTime->format('Y-m-d') : $dateTime; } @@ -355,11 +356,11 @@ class Utils return ''; } - $timezone = Session::get(SESSION_TIMEZONE, DEFAULT_TIMEZONE); + //$timezone = Session::get(SESSION_TIMEZONE, DEFAULT_TIMEZONE); $format = Session::get(SESSION_DATE_FORMAT, DEFAULT_DATE_FORMAT); $dateTime = DateTime::createFromFormat('Y-m-d', $date); - $dateTime->setTimeZone(new DateTimeZone($timezone)); + //$dateTime->setTimeZone(new DateTimeZone($timezone)); return $formatResult ? $dateTime->format($format) : $dateTime; } diff --git a/app/Models/Account.php b/app/Models/Account.php index e8cde5293c09..ee88e2fd1fcb 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -147,6 +147,7 @@ class Account extends Eloquent public function getLogoPath() { $fileName = 'logo/' . $this->account_key; + return file_exists($fileName.'.png') && $this->utf8_invoices ? $fileName.'.png' : $fileName.'.jpg'; } diff --git a/app/Ninja/Repositories/AccountRepository.php b/app/Ninja/Repositories/AccountRepository.php index 5aaa6e8d4d90..d33c08f7abdf 100644 --- a/app/Ninja/Repositories/AccountRepository.php +++ b/app/Ninja/Repositories/AccountRepository.php @@ -298,7 +298,7 @@ class AccountRepository $item->account_id = $user->account->id; $item->account_name = $user->account->getDisplayName(); $item->pro_plan_paid = $user->account->pro_plan_paid; - $item->account_key = file_exists($user->account->getLogoPath()) ? $user->account->account_key : null; + $item->logo_path = file_exists($user->account->getLogoPath()) ? $user->account->getLogoPath() : null; $data[] = $item; } diff --git a/public/js/built.js b/public/js/built.js index a47d137523b7..08fa79b13021 100644 --- a/public/js/built.js +++ b/public/js/built.js @@ -30748,9 +30748,6 @@ function displayGrid(doc, invoice, data, x, y, layout, options) { key = invoice.account[key]; } else if (key === 'tax' && invoice.tax_name) { key = invoice.tax_name + ' ' + (invoice.tax_rate*1).toString() + '%'; - if (invoice.tax_name.toLowerCase().indexOf(invoiceLabels['tax'].toLowerCase()) == -1) { - key = invoiceLabels['tax'] + ': ' + key; - } } else if (key === 'discount' && NINJA.parseFloat(invoice.discount) && !parseInt(invoice.is_amount_discount)) { key = invoiceLabels[key] + ' ' + parseFloat(invoice.discount) + '%'; } else { @@ -31619,7 +31616,7 @@ NINJA.decodeJavascript = function(invoice, javascript) } // search/replace values - var regExp = new RegExp('"\\$\\\w*?Value"', 'g'); + var regExp = new RegExp('"\\$[\\\w\\\.]*?Value"', 'g'); var matches = javascript.match(regExp); if (matches) { @@ -31628,6 +31625,7 @@ NINJA.decodeJavascript = function(invoice, javascript) field = match.substring(2, match.indexOf('Value')); field = toSnakeCase(field); var value = getDescendantProp(invoice, field) || ' '; + if (field.toLowerCase().indexOf('date') >= 0 && value != ' ') { value = moment(value, 'YYYY-MM-DD').format('MMM D YYYY'); } @@ -31760,7 +31758,8 @@ NINJA.subtotals = function(invoice, removeBalance) } if (invoice.tax && invoice.tax.name || invoice.tax_name) { - data.push([{text: invoiceLabels.tax}, {text: formatMoney(invoice.tax_amount, invoice.client.currency_id)}]); + var taxStr = invoice.tax_name + ' ' + (invoice.tax_rate*1).toString() + '%'; + data.push([{text: taxStr}, {text: formatMoney(invoice.tax_amount, invoice.client.currency_id)}]); } if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 != '1') { diff --git a/public/js/pdf.pdfmake.js b/public/js/pdf.pdfmake.js index 168a8733567b..8ec21c1e5b08 100644 --- a/public/js/pdf.pdfmake.js +++ b/public/js/pdf.pdfmake.js @@ -142,7 +142,7 @@ NINJA.decodeJavascript = function(invoice, javascript) } // search/replace values - var regExp = new RegExp('"\\$\\\w*?Value"', 'g'); + var regExp = new RegExp('"\\$[\\\w\\\.]*?Value"', 'g'); var matches = javascript.match(regExp); if (matches) { @@ -151,6 +151,7 @@ NINJA.decodeJavascript = function(invoice, javascript) field = match.substring(2, match.indexOf('Value')); field = toSnakeCase(field); var value = getDescendantProp(invoice, field) || ' '; + if (field.toLowerCase().indexOf('date') >= 0 && value != ' ') { value = moment(value, 'YYYY-MM-DD').format('MMM D YYYY'); } @@ -283,7 +284,8 @@ NINJA.subtotals = function(invoice, removeBalance) } if (invoice.tax && invoice.tax.name || invoice.tax_name) { - data.push([{text: invoiceLabels.tax}, {text: formatMoney(invoice.tax_amount, invoice.client.currency_id)}]); + var taxStr = invoice.tax_name + ' ' + (invoice.tax_rate*1).toString() + '%'; + data.push([{text: taxStr}, {text: formatMoney(invoice.tax_amount, invoice.client.currency_id)}]); } if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 != '1') { diff --git a/public/js/script.js b/public/js/script.js index eabb1be9f671..221b8d0a0d38 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -877,9 +877,6 @@ function displayGrid(doc, invoice, data, x, y, layout, options) { key = invoice.account[key]; } else if (key === 'tax' && invoice.tax_name) { key = invoice.tax_name + ' ' + (invoice.tax_rate*1).toString() + '%'; - if (invoice.tax_name.toLowerCase().indexOf(invoiceLabels['tax'].toLowerCase()) == -1) { - key = invoiceLabels['tax'] + ': ' + key; - } } else if (key === 'discount' && NINJA.parseFloat(invoice.discount) && !parseInt(invoice.is_amount_discount)) { key = invoiceLabels[key] + ' ' + parseFloat(invoice.discount) + '%'; } else { diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 23b684fb2577..1a159cb2c5bb 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -742,6 +742,8 @@ return array( 'outstanding' => 'Outstanding', 'manage_companies' => 'Manage Companies', 'total_revenue' => 'Total Revenue', + + 'current_user' => 'Current User', ); diff --git a/resources/views/header.blade.php b/resources/views/header.blade.php index 9abb87690796..6925992c315f 100644 --- a/resources/views/header.blade.php +++ b/resources/views/header.blade.php @@ -385,7 +385,7 @@ 'user_id' => $item->user_id, 'account_name' => $item->account_name, 'user_name' => $item->user_name, - 'account_key' => $item->account_key, + 'logo_path' => isset($item->logo_path) ? $item->logo_path : "", 'selected' => true, ]) @endif @@ -397,7 +397,7 @@ 'user_id' => $item->user_id, 'account_name' => $item->account_name, 'user_name' => $item->user_name, - 'account_key' => $item->account_key, + 'logo_path' => isset($item->logo_path) ? $item->logo_path : "", 'selected' => false, ]) @endif @@ -406,16 +406,15 @@ @include('user_account', [ 'account_name' => Auth::user()->account->name ?: trans('texts.untitled'), 'user_name' => Auth::user()->getDisplayName(), - 'account_key' => Auth::user()->account->account_key, + 'logo_path' => Auth::user()->account->getLogoPath(), 'selected' => true, ]) @endif
  • - @if (!session(SESSION_USER_ACCOUNTS) || count(session(SESSION_USER_ACCOUNTS)) < 5) -
  • {!! link_to('/login?new_company=true', trans('texts.add_company')) !!}
  • - @endif @if (count(session(SESSION_USER_ACCOUNTS)) > 1)
  • {!! link_to('/manage_companies', trans('texts.manage_companies')) !!}
  • + @elseif (!session(SESSION_USER_ACCOUNTS) || count(session(SESSION_USER_ACCOUNTS)) < 5) +
  • {!! link_to('/login?new_company=true', trans('texts.add_company')) !!}
  • @endif
  • {!! link_to('#', trans('texts.logout'), array('onclick'=>'logout()')) !!}
  • diff --git a/resources/views/user_account.blade.php b/resources/views/user_account.blade.php index 9384f621b498..4848a190e5c9 100644 --- a/resources/views/user_account.blade.php +++ b/resources/views/user_account.blade.php @@ -5,9 +5,9 @@ @endif - @if (file_exists('logo/'.$account_key.'.jpg')) + @if (file_exists($logo_path))
    - +
    @else
     
    diff --git a/resources/views/users/account_management.blade.php b/resources/views/users/account_management.blade.php index 75fa8a500ea7..3839a0bb4377 100644 --- a/resources/views/users/account_management.blade.php +++ b/resources/views/users/account_management.blade.php @@ -2,18 +2,39 @@ @section('content') + +
    + {!! Button::success(trans('texts.add_company'))->asLinkTo('/login?new_company=true') !!} +
    +

     

    +
    +
    +
    +
    +
    - @foreach (Session::get(SESSION_USER_ACCOUNTS) as $account) + @foreach (Session::get(SESSION_USER_ACCOUNTS) as $account) - - - + + + @endforeach
    {{ $account->account_name }}{{ $account->user_name }}{!! Button::primary(trans('texts.unlink'))->small()->withAttributes(['onclick'=>"return showUnlink({$account->id}, {$account->user_id})"]) !!} + @if (isset($account->logo_path)) + {!! HTML::image($account->logo_path.'?no_cache='.time(), 'Logo', ['width' => 100]) !!} + @endif + +

    {{ $account->account_name }}
    + {{ $account->user_name }} + @if ($account->user_id == Auth::user()->id) + | {{ trans('texts.current_user')}} + @endif +

    +
    {!! Button::primary(trans('texts.unlink'))->withAttributes(['onclick'=>"return showUnlink({$account->id}, {$account->user_id})"]) !!}