From 6e532063fd39df04de496f7d4e86f2a927966b37 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 23 Mar 2014 14:53:16 +0200 Subject: [PATCH] Working on multi-language support --- app/controllers/InvoiceController.php | 5 ++-- app/models/Account.php | 33 +++++++++++++++++++++++++++ app/models/User.php | 32 -------------------------- app/views/invoices/view.blade.php | 15 ++++++++++++ public/js/script.js | 4 ++++ 5 files changed, 55 insertions(+), 34 deletions(-) diff --git a/app/controllers/InvoiceController.php b/app/controllers/InvoiceController.php index c4e233e41c..6cd3d2295f 100755 --- a/app/controllers/InvoiceController.php +++ b/app/controllers/InvoiceController.php @@ -143,7 +143,8 @@ class InvoiceController extends \BaseController { $data = array( 'showBreadcrumbs' => false, 'invoice' => $invoice->hidePrivateFields(), - 'invitation' => $invitation + 'invitation' => $invitation, + 'invoiceLabels' => $client->account->getInvoiceLabels(), ); return View::make('invoices.view', $data); @@ -223,7 +224,7 @@ class InvoiceController extends \BaseController { 'paymentTerms' => PaymentTerm::remember(DEFAULT_QUERY_CACHE)->orderBy('num_days')->get(['name', 'num_days']), 'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'invoiceDesigns' => InvoiceDesign::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), - 'invoiceLabels' => Auth::user()->getInvoiceLabels(), + 'invoiceLabels' => Auth::user()->account->getInvoiceLabels(), 'frequencies' => array( 1 => 'Weekly', 2 => 'Two weeks', diff --git a/app/models/Account.php b/app/models/Account.php index 0c73e2fd39..bc74165573 100755 --- a/app/models/Account.php +++ b/app/models/Account.php @@ -168,4 +168,37 @@ class Account extends Eloquent Session::put(SESSION_DATETIME_FORMAT, $this->datetime_format ? $this->datetime_format->format : DEFAULT_DATETIME_FORMAT); Session::put(SESSION_CURRENCY, $this->currency_id ? $this->currency_id : DEFAULT_CURRENCY); } + + public function getInvoiceLabels() + { + $data = []; + $fields = [ + 'invoice', + 'invoice_date', + 'due_date', + 'invoice_number', + 'po_number', + 'dicount', + 'taxes', + 'tax', + 'item', + 'description', + 'unit_cost', + 'quantity', + 'line_total', + 'subtotal', + 'paid_to_date', + 'balance_due', + 'terms', + 'your_invoice', + ]; + + foreach ($fields as $field) + { + $data[$field] = trans("fields.$field"); + } + + return $data; + } + } \ No newline at end of file diff --git a/app/models/User.php b/app/models/User.php index 2d2d03ee2b..f9fb73acb8 100755 --- a/app/models/User.php +++ b/app/models/User.php @@ -110,38 +110,6 @@ class User extends ConfideUser implements UserInterface, RemindableInterface return $language->locale; } - public function getInvoiceLabels() - { - $data = []; - $fields = [ - 'invoice', - 'invoice_date', - 'due_date', - 'invoice_number', - 'po_number', - 'dicount', - 'taxes', - 'tax', - 'item', - 'description', - 'unit_cost', - 'quantity', - 'line_total', - 'subtotal', - 'paid_to_date', - 'balance_due', - 'terms', - 'your_invoice', - ]; - - foreach ($fields as $field) - { - $data[$field] = trans("fields.$field"); - } - - return $data; - } - public function showGreyBackground() { return !$this->theme_id || in_array($this->theme_id, [2, 3, 5, 6, 7, 8, 10, 11, 12]); diff --git a/app/views/invoices/view.blade.php b/app/views/invoices/view.blade.php index 0f5fd53934..628ec4774b 100755 --- a/app/views/invoices/view.blade.php +++ b/app/views/invoices/view.blade.php @@ -29,6 +29,19 @@ $(function() { window.invoice = {{ $invoice->toJson() }}; + + invoice.imageLogo1 = "{{ HTML::image_data('images/report_logo1.jpg') }}"; + invoice.imageLogoWidth1 =120; + invoice.imageLogoHeight1 = 40 + + invoice.imageLogo2 = "{{ HTML::image_data('images/report_logo2.jpg') }}"; + invoice.imageLogoWidth2 =325/2; + invoice.imageLogoHeight2 = 81/2; + + invoice.imageLogo3 = "{{ HTML::image_data('images/report_logo3.jpg') }}"; + invoice.imageLogoWidth3 =325/2; + invoice.imageLogoHeight3 = 81/2; + @if (file_exists($invoice->client->account->getLogoPath())) invoice.image = "{{ HTML::image_data($invoice->client->account->getLogoPath()) }}"; invoice.imageWidth = {{ $invoice->client->account->getLogoWidth() }}; @@ -59,6 +72,8 @@ }); } }); + + var invoiceLabels = {{ json_encode($invoiceLabels) }}; function onDownloadClick() { var doc = generatePDF(invoice); diff --git a/public/js/script.js b/public/js/script.js index 87dfcfb4a3..11a0fc3446 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -1390,11 +1390,15 @@ function displayGrid(doc, invoice, data, x, y, layout, hasheader, rightAlignX, r } doc.text(marginLeft, y, value); + /* if (rightAlignTitleX && i === 0) { doc.setFontType('bold'); } else { doc.setFontType('normal'); } + */ + + doc.setFontType('normal'); key = invoiceLabels[key]; if (rightAlignTitleX) {