diff --git a/app/commands/CreateRandomData.php b/app/commands/CreateRandomData.php new file mode 100644 index 000000000000..561f2c856c7e --- /dev/null +++ b/app/commands/CreateRandomData.php @@ -0,0 +1,88 @@ +info(date('Y-m-d') . ' Running CreateRandomData...'); + + $user = User::first(); + + if (!$user) { + $this->error("Error: please create user account by logging in"); + return; + } + + $productNames = ['Arkansas', 'New York', 'Arizona', 'California', 'Colorado', 'Alabama', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'Alaska', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming']; + $clientNames = ['IBM', 'Nestle', 'Mitsubishi UFJ Financial', 'Vodafone', 'Eni', 'Procter & Gamble', 'Johnson & Johnson', 'American International Group', 'Banco Santander', 'BHP Billiton', 'Pfizer', 'Itaú Unibanco Holding', 'Ford Motor', 'BMW Group', 'Commonwealth Bank', 'EDF', 'Statoil', 'Google', 'Siemens', 'Novartis', 'Royal Bank of Canada', 'Sumitomo Mitsui Financial', 'Comcast', 'Sberbank', 'Goldman Sachs Group', 'Westpac Banking Group', 'Nippon Telegraph & Tel', 'Ping An Insurance Group', 'Banco Bradesco', 'Anheuser-Busch InBev', 'Bank of Communications', 'China Life Insurance', 'General Motors', 'Telefónica', 'MetLife', 'Honda Motor', 'Enel', 'BASF', 'Softbank', 'National Australia Bank', 'ANZ', 'ConocoPhillips', 'TD Bank Group', 'Intel', 'UBS', 'Hewlett-Packard', 'Coca-Cola', 'Cisco Systems', 'UnitedHealth Group', 'Boeing', 'Zurich Insurance Group', 'Hyundai Motor', 'Sanofi', 'Credit Agricole', 'United Technologies', 'Roche Holding', 'Munich Re', 'PepsiCo', 'Oracle', 'Bank of Nova Scotia']; + + for ($i=1; $i<=40; $i++) { + $product = Product::createNew($user); + $product->id = $i; + $product->product_key = $productNames[$i-1]; + $product->save(); + } + + for ($i=0; $i<60; $i++) { + $client = Client::createNew($user); + $client->name = $clientNames[$i]; + $client->save(); + + $contact = Contact::createNew($user); + $contact->email = "client@aol.com"; + $contact->is_primary = 1; + $client->contacts()->save($contact); + + $numInvoices = rand(1, 25); + if ($numInvoices == 4 || $numInvoices == 10 || $numInvoices == 25) { + // leave these + } else if ($numInvoices % 3 == 0) { + $numInvoices = 1; + } else if ($numInvoices > 10) { + $numInvoices = $numInvoices % 2; + } + + $paidUp = rand(0, 1) == 1; + + for ($j=1; $j<=$numInvoices; $j++) { + + $price = rand(10, 1000); + if ($price < 900) { + $price = rand(10, 150); + } + + $invoice = Invoice::createNew($user); + $invoice->invoice_number = $user->account->getNextInvoiceNumber(); + $invoice->amount = $invoice->balance = $price; + $invoice->created_at = date('Y-m-d', strtotime(date("Y-m-d") . ' - ' . rand(1, 100) . ' days')); + $client->invoices()->save($invoice); + + $productId = rand(0, 40); + if ($productId > 20) { + $productId = ($productId % 2) + rand(0, 2); + } + + $invoiceItem = InvoiceItem::createNew($user); + $invoiceItem->product_id = $productId+1; + $invoiceItem->product_key = $productNames[$invoiceItem->product_id]; + $invoiceItem->cost = $invoice->amount; + $invoiceItem->qty = 1; + $invoice->invoice_items()->save($invoiceItem); + + if ($paidUp || rand(0,2) > 1) { + $payment = Payment::createNew($user); + $payment->invoice_id = $invoice->id; + $payment->amount = $invoice->amount; + $client->payments()->save($payment); + } + } + } + } +} \ No newline at end of file diff --git a/app/commands/ResetData.php b/app/commands/ResetData.php new file mode 100644 index 000000000000..39150407ea93 --- /dev/null +++ b/app/commands/ResetData.php @@ -0,0 +1,24 @@ +info(date('Y-m-d') . ' Running ResetData...'); + + if (!Utils::isNinjaDev()) { + return; + } + + Artisan::call('migrate:reset'); + Artisan::call('migrate'); + Artisan::call('db:seed'); + } +} \ No newline at end of file diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index 96f82e4dfe9a..20d3986bce53 100755 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -46,9 +46,9 @@ class AccountController extends \BaseController { return Redirect::to('/'); } + /* public function reset() { - /* if (Utils::isNinjaDev()) { Confide::logout(); try { @@ -59,10 +59,11 @@ class AccountController extends \BaseController { Response::make($e->getMessage(), 500); } } - */ + return Redirect::to('/'); } - + */ + public function getStarted() { if (Auth::check()) diff --git a/app/controllers/ReportController.php b/app/controllers/ReportController.php index a4a07aa53e82..05ece2f02e5e 100755 --- a/app/controllers/ReportController.php +++ b/app/controllers/ReportController.php @@ -2,6 +2,23 @@ class ReportController extends \BaseController { + public function d3() + { + $account = Auth::user()->account; + $account = $account->with(['clients.invoices.invoice_items', 'clients.contacts'])->first(); + + $account = $account->hideFieldsForViz(); + $clients = $account->clients; + //dd($clients->toJson()); + + $data = [ + 'feature' => ACCOUNT_DATA_VISUALIZER, + 'clients' => $clients + ]; + + return View::make('reports.d3', $data); + } + public function report() { if (Input::all()) diff --git a/app/lang/de/texts.php b/app/lang/de/texts.php index f2f89bea2d06..86025be7e7a7 100644 --- a/app/lang/de/texts.php +++ b/app/lang/de/texts.php @@ -333,6 +333,13 @@ return array( 'created_product' => 'Produkt erfolgreich erstellt', 'archived_product' => 'Produkt erfolgreich archiviert', 'product_library' => 'Produktbibliothek', + 'pro_plan_custom_fields' => ':link to enable custom fields by joining the Pro Plan', + + 'advanced_settings' => 'Advanced Settings', + 'pro_plan_advanced_settings' => ':link to enable the advanced settings by joining the Pro Plan', + 'invoice_design' => 'Invoice Design', + 'specify_colors' => 'Specify colors', + 'specify_colors_label' => 'Select the colors used in the invoice', 'chart_builder' => 'Diagrammersteller', 'ninja_email_footer' => 'Nutze :site um Kunden eine Rechnung zu stellen und online bezahlt zu werden, kostenlos!', @@ -407,10 +414,12 @@ return array( 'confirm_email_invoice' => 'Are you sure you want to email this invoice?', 'confirm_email_quote' => 'Are you sure you want to email this quote?', - 'confirm_recurring_email_invoice' => 'Are you sure you want this invoice emailed?', + 'confirm_recurring_email_invoice' => 'Recurring is enabled, are you sure you want this invoice emailed?', 'cancel_account' => 'Cancel Account', 'cancel_account_message' => 'Warning: This will permanently erase all of your data, there is no undo.', 'go_back' => 'Go Back', + 'data_visualizer' => 'Data Visualizer', + ); diff --git a/app/lang/en/texts.php b/app/lang/en/texts.php index b8648c28f0be..38acf5da5688 100644 --- a/app/lang/en/texts.php +++ b/app/lang/en/texts.php @@ -422,10 +422,12 @@ return array( 'confirm_email_invoice' => 'Are you sure you want to email this invoice?', 'confirm_email_quote' => 'Are you sure you want to email this quote?', - 'confirm_recurring_email_invoice' => 'Are you sure you want this invoice emailed?', + 'confirm_recurring_email_invoice' => 'Recurring is enabled,re you sure you want this invoice emailed?', 'cancel_account' => 'Cancel Account', 'cancel_account_message' => 'Warning: This will permanently erase all of your data, there is no undo.', 'go_back' => 'Go Back', + 'data_visualizer' => 'Data Visualizer', + ); \ No newline at end of file diff --git a/app/lang/es/texts.php b/app/lang/es/texts.php index 2335ce1c3afd..cdee606660a9 100644 --- a/app/lang/es/texts.php +++ b/app/lang/es/texts.php @@ -332,6 +332,13 @@ return array( 'updated_product' => 'Successfully updated product', 'created_product' => 'Successfully created product', 'archived_product' => 'Successfully archived product', + 'pro_plan_custom_fields' => ':link to enable custom fields by joining the Pro Plan', + + 'advanced_settings' => 'Advanced Settings', + 'pro_plan_advanced_settings' => ':link to enable the advanced settings by joining the Pro Plan', + 'invoice_design' => 'Invoice Design', + 'specify_colors' => 'Specify colors', + 'specify_colors_label' => 'Select the colors used in the invoice', 'chart_builder' => 'Chart Builder', 'ninja_email_footer' => 'Use :site to invoice your clients and get paid online for free!', @@ -405,10 +412,12 @@ return array( 'confirm_email_invoice' => 'Are you sure you want to email this invoice?', 'confirm_email_quote' => 'Are you sure you want to email this quote?', - 'confirm_recurring_email_invoice' => 'Are you sure you want this invoice emailed?', + 'confirm_recurring_email_invoice' => 'Recurring is enabled, are you sure you want this invoice emailed?', 'cancel_account' => 'Cancel Account', 'cancel_account_message' => 'Warning: This will permanently erase all of your data, there is no undo.', 'go_back' => 'Go Back', + 'data_visualizer' => 'Data Visualizer', + ); diff --git a/app/lang/fr/texts.php b/app/lang/fr/texts.php index 462785a93869..5add2301c6da 100644 --- a/app/lang/fr/texts.php +++ b/app/lang/fr/texts.php @@ -333,6 +333,13 @@ return array( 'updated_product' => 'Successfully updated product', 'created_product' => 'Successfully created product', 'archived_product' => 'Successfully archived product', + 'pro_plan_custom_fields' => ':link to enable custom fields by joining the Pro Plan', + + 'advanced_settings' => 'Advanced Settings', + 'pro_plan_advanced_settings' => ':link to enable the advanced settings by joining the Pro Plan', + 'invoice_design' => 'Invoice Design', + 'specify_colors' => 'Specify colors', + 'specify_colors_label' => 'Select the colors used in the invoice', 'chart_builder' => 'Chart Builder', 'ninja_email_footer' => 'Use :site to invoice your clients and get paid online for free!', @@ -407,10 +414,12 @@ return array( 'confirm_email_invoice' => 'Are you sure you want to email this invoice?', 'confirm_email_quote' => 'Are you sure you want to email this quote?', - 'confirm_recurring_email_invoice' => 'Are you sure you want this invoice emailed?', + 'confirm_recurring_email_invoice' => 'Recurring is enabled, are you sure you want this invoice emailed?', 'cancel_account' => 'Cancel Account', 'cancel_account_message' => 'Warning: This will permanently erase all of your data, there is no undo.', 'go_back' => 'Go Back', + 'data_visualizer' => 'Data Visualizer', + ); diff --git a/app/lang/it/texts.php b/app/lang/it/texts.php index c81c33eab1cd..4c1e002d8b70 100644 --- a/app/lang/it/texts.php +++ b/app/lang/it/texts.php @@ -333,6 +333,13 @@ return array( 'updated_product' => 'Prodotto aggiornato con successo', 'created_product' => 'Prodotto creato con successo', 'archived_product' => 'Prodotto archiviato con successo', + 'pro_plan_custom_fields' => ':link to enable custom fields by joining the Pro Plan', + + 'advanced_settings' => 'Advanced Settings', + 'pro_plan_advanced_settings' => ':link to enable the advanced settings by joining the Pro Plan', + 'invoice_design' => 'Invoice Design', + 'specify_colors' => 'Specify colors', + 'specify_colors_label' => 'Select the colors used in the invoice', 'chart_builder' => 'Creatore grafico', 'ninja_email_footer' => 'Usa :site per fatturare ai tuoi clienti e venire pagato online gratis!', @@ -407,10 +414,11 @@ return array( 'confirm_email_invoice' => 'Are you sure you want to email this invoice?', 'confirm_email_quote' => 'Are you sure you want to email this quote?', - 'confirm_recurring_email_invoice' => 'Are you sure you want this invoice emailed?', + 'confirm_recurring_email_invoice' => 'Recurring is enabled, are you sure you want this invoice emailed?', 'cancel_account' => 'Cancel Account', 'cancel_account_message' => 'Warning: This will permanently erase all of your data, there is no undo.', 'go_back' => 'Go Back', - + + 'data_visualizer' => 'Data Visualizer', ); diff --git a/app/lang/lt/texts.php b/app/lang/lt/texts.php index d6e5a05821ba..14d3773f0723 100644 --- a/app/lang/lt/texts.php +++ b/app/lang/lt/texts.php @@ -422,11 +422,13 @@ return array( 'confirm_email_invoice' => 'Are you sure you want to email this invoice?', 'confirm_email_quote' => 'Are you sure you want to email this quote?', - 'confirm_recurring_email_invoice' => 'Are you sure you want this invoice emailed?', + 'confirm_recurring_email_invoice' => 'Recurring is enabled, are you sure you want this invoice emailed?', 'cancel_account' => 'Cancel Account', 'cancel_account_message' => 'Warning: This will permanently erase all of your data, there is no undo.', 'go_back' => 'Go Back', + 'data_visualizer' => 'Data Visualizer', + ); diff --git a/app/lang/nb_NO/texts.php b/app/lang/nb_NO/texts.php index abed26d260a7..47e9155c7efc 100644 --- a/app/lang/nb_NO/texts.php +++ b/app/lang/nb_NO/texts.php @@ -422,10 +422,12 @@ return array( 'confirm_email_invoice' => 'Are you sure you want to email this invoice?', 'confirm_email_quote' => 'Are you sure you want to email this quote?', - 'confirm_recurring_email_invoice' => 'Are you sure you want this invoice emailed?', + 'confirm_recurring_email_invoice' => 'Recurring is enabled, are you sure you want this invoice emailed?', 'cancel_account' => 'Cancel Account', 'cancel_account_message' => 'Warning: This will permanently erase all of your data, there is no undo.', 'go_back' => 'Go Back', + 'data_visualizer' => 'Data Visualizer', + ); \ No newline at end of file diff --git a/app/lang/nl/texts.php b/app/lang/nl/texts.php index 5ad10e249578..060a04cf08a9 100644 --- a/app/lang/nl/texts.php +++ b/app/lang/nl/texts.php @@ -334,6 +334,13 @@ return array( 'updated_product' => 'Successfully updated product', 'created_product' => 'Successfully created product', 'archived_product' => 'Successfully archived product', + 'pro_plan_custom_fields' => ':link to enable custom fields by joining the Pro Plan', + + 'advanced_settings' => 'Advanced Settings', + 'pro_plan_advanced_settings' => ':link to enable the advanced settings by joining the Pro Plan', + 'invoice_design' => 'Invoice Design', + 'specify_colors' => 'Specify colors', + 'specify_colors_label' => 'Select the colors used in the invoice', 'chart_builder' => 'Chart Builder', 'ninja_email_footer' => 'Use :site to invoice your clients and get paid online for free!', @@ -408,10 +415,12 @@ return array( 'confirm_email_invoice' => 'Are you sure you want to email this invoice?', 'confirm_email_quote' => 'Are you sure you want to email this quote?', - 'confirm_recurring_email_invoice' => 'Are you sure you want this invoice emailed?', - + 'confirm_recurring_email_invoice' => 'Recurring is enabled, are you sure you want this invoice emailed?', + 'cancel_account' => 'Cancel Account', 'cancel_account_message' => 'Warning: This will permanently erase all of your data, there is no undo.', 'go_back' => 'Go Back', + 'data_visualizer' => 'Data Visualizer', + ); diff --git a/app/lang/pt_BR/texts.php b/app/lang/pt_BR/texts.php index 5aab09b6b887..3a478d6874d3 100644 --- a/app/lang/pt_BR/texts.php +++ b/app/lang/pt_BR/texts.php @@ -322,6 +322,13 @@ return array( 'updated_product' => 'Successfully updated product', 'created_product' => 'Successfully created product', 'archived_product' => 'Successfully archived product', + 'pro_plan_custom_fields' => ':link to enable custom fields by joining the Pro Plan', + + 'advanced_settings' => 'Advanced Settings', + 'pro_plan_advanced_settings' => ':link to enable the advanced settings by joining the Pro Plan', + 'invoice_design' => 'Invoice Design', + 'specify_colors' => 'Specify colors', + 'specify_colors_label' => 'Select the colors used in the invoice', 'chart_builder' => 'Chart Builder', 'ninja_email_footer' => 'Use :site to invoice your clients and get paid online for free!', @@ -396,10 +403,12 @@ return array( 'confirm_email_invoice' => 'Are you sure you want to email this invoice?', 'confirm_email_quote' => 'Are you sure you want to email this quote?', - 'confirm_recurring_email_invoice' => 'Are you sure you want this invoice emailed?', - + 'confirm_recurring_email_invoice' => 'Recurring is enabled, are you sure you want this invoice emailed?', + 'cancel_account' => 'Cancel Account', 'cancel_account_message' => 'Warning: This will permanently erase all of your data, there is no undo.', 'go_back' => 'Go Back', + 'data_visualizer' => 'Data Visualizer', + ); diff --git a/app/models/Account.php b/app/models/Account.php index d02912827f15..10ada5ec4952 100755 --- a/app/models/Account.php +++ b/app/models/Account.php @@ -252,4 +252,47 @@ class Account extends Eloquent { return Subscription::where('account_id', '=', $this->id)->where('event_id', '=', $eventId)->first(); } + + public function hideFieldsForViz() + { + foreach ($this->clients as $client) + { + $client->setVisible([ + 'name', + 'balance', + 'paid_to_date', + 'invoices', + 'contacts', + ]); + + foreach ($client->invoices as $invoice) + { + $invoice->setVisible([ + 'invoice_number', + 'amount', + 'balance', + 'invoice_status_id', + 'invoice_items', + 'created_at', + ]); + + foreach ($invoice->invoice_items as $invoiceItem) + { + $invoiceItem->setVisible([ + 'product_key', + 'cost', + 'qty', + ]); + } + } + + foreach ($client->contacts as $contact) + { + $contact->setVisible(['public_id']); + } + } + + return $this; + } + } \ No newline at end of file diff --git a/app/models/Activity.php b/app/models/Activity.php index c3a02ee67f5d..2c32c9453316 100755 --- a/app/models/Activity.php +++ b/app/models/Activity.php @@ -51,7 +51,7 @@ class Activity extends Eloquent if ($entity) { - $activity->user_id = $entity->user_id; + $activity->user_id = $entity instanceof User ? $entity->id : $entity->user_id; $activity->account_id = $entity->account_id; } else if (Auth::check()) @@ -272,7 +272,7 @@ class Activity extends Eloquent } else { - $activity = Activity::getBlank(); + $activity = Activity::getBlank($client); $message = $payment->payment_type_id == PAYMENT_TYPE_CREDIT ? 'applied credit for ' : 'entered ' . $payment->getName() . ' for '; $activity->message = Utils::encodeActivity(Auth::user(), $message, $payment->invoice); } diff --git a/app/models/Client.php b/app/models/Client.php index 92b283e36fb0..78d6926cb383 100755 --- a/app/models/Client.php +++ b/app/models/Client.php @@ -204,6 +204,7 @@ class Client extends EntityModel return $this->created_at->format('m/d/y h:i a'); } } + } /* diff --git a/app/models/EntityModel.php b/app/models/EntityModel.php index dc6d46f26d04..614d1eee79fc 100755 --- a/app/models/EntityModel.php +++ b/app/models/EntityModel.php @@ -5,7 +5,7 @@ class EntityModel extends Eloquent protected $softDelete = true; public $timestamps = true; - protected $hidden = ['id', 'created_at', 'deleted_at', 'updated_at']; + protected $hidden = ['id']; public static function createNew($parent = false) { @@ -14,7 +14,7 @@ class EntityModel extends Eloquent if ($parent) { - $entity->user_id = $parent->user_id; + $entity->user_id = $parent instanceof User ? $parent->id : $parent->user_id; $entity->account_id = $parent->account_id; } else if (Auth::check()) diff --git a/app/routes.php b/app/routes.php index bcd098c9058a..e2aed07458ea 100755 --- a/app/routes.php +++ b/app/routes.php @@ -80,6 +80,7 @@ Route::group(array('before' => 'auth'), function() Route::resource('products', 'ProductController'); Route::get('products/{product_id}/archive', 'ProductController@archive'); + Route::get('company/advanced_settings/data_visualizer', 'ReportController@d3'); Route::get('company/advanced_settings/chart_builder', 'ReportController@report'); Route::post('company/advanced_settings/chart_builder', 'ReportController@report'); @@ -170,7 +171,7 @@ define('ACCOUNT_CUSTOM_FIELDS', 'custom_fields'); define('ACCOUNT_INVOICE_DESIGN', 'invoice_design'); define('ACCOUNT_CHART_BUILDER', 'chart_builder'); define('ACCOUNT_USER_MANAGEMENT', 'user_management'); - +define('ACCOUNT_DATA_VISUALIZER', 'data_visualizer'); define('DEFAULT_INVOICE_NUMBER', '0001'); define('RECENTLY_VIEWED_LIMIT', 8); diff --git a/app/start/artisan.php b/app/start/artisan.php index 94d1256f4713..3c073ba61a14 100755 --- a/app/start/artisan.php +++ b/app/start/artisan.php @@ -11,4 +11,6 @@ | */ -Artisan::resolve('SendRecurringInvoices'); \ No newline at end of file +Artisan::resolve('SendRecurringInvoices'); +Artisan::resolve('CreateRandomData'); +Artisan::resolve('ResetData'); diff --git a/app/views/accounts/nav_advanced.blade.php b/app/views/accounts/nav_advanced.blade.php index 8e0e03d79c28..224b5177c803 100644 --- a/app/views/accounts/nav_advanced.blade.php +++ b/app/views/accounts/nav_advanced.blade.php @@ -1,6 +1,7 @@ diff --git a/app/views/reports/d3.blade.php b/app/views/reports/d3.blade.php new file mode 100644 index 000000000000..0dfea6d6c8c2 --- /dev/null +++ b/app/views/reports/d3.blade.php @@ -0,0 +1,300 @@ +@extends('accounts.nav') + +@section('head') + @parent + + + + +@stop + +@section('content') + @parent + @include('accounts.nav_advanced') + + + +
+ Group By    + + +
+ +

 

+ +
+ + + +@stop \ No newline at end of file diff --git a/bower.json b/bower.json index 2c47c577d360..9d42caee9906 100644 --- a/bower.json +++ b/bower.json @@ -17,10 +17,10 @@ "typeahead.js": "~0.9.3", "accounting": "~0.*", "pdfjs": "*", - "spectrum": "~1.3.4" + "spectrum": "~1.3.4", + "d3": "~3.4.11" }, "resolutions": { - "datatables": "~1.*", "jquery": "~1.11" } } diff --git a/public/built.js b/public/built.js index 5fe9e49cd96d..6384f7344228 100644 --- a/public/built.js +++ b/public/built.js @@ -45931,7 +45931,543 @@ var isChrome = !!window.chrome && !isOpera; // Chrome 1+ var isChromium = isChrome && navigator.userAgent.indexOf('Chromium') >= 0; var isIE = /*@cc_on!@*/false || !!document.documentMode; // At least IE6 -function GetReportTemplate4(doc, invoice, layout, checkMath) { + +var invoiceOld; +function generatePDF(invoice, force) { + invoice = calculateAmounts(invoice); + var a = copyInvoice(invoice); + var b = copyInvoice(invoiceOld); + if (!force && _.isEqual(a, b)) { + return; + } + invoiceOld = invoice; + report_id = invoice.invoice_design_id; + doc = GetPdf(invoice, report_id); + return doc; +} + +function copyInvoice(orig) { + if (!orig) return false; + var copy = JSON.stringify(orig); + var copy = JSON.parse(copy); + return copy; +} + + + +function GetPdf(invoice, report_id){ + var layout = { + accountTop: 40, + marginLeft: 50, + marginRight: 550, + headerTop: 150, + headerLeft: 360, + headerRight: 550, + rowHeight: 15, + tableRowHeight: 10, + footerLeft: 420, + tablePadding: 12, + tableTop: 250, + descriptionLeft: 162, + unitCostRight: 410, + qtyRight: 480, + taxRight: 480, + lineTotalRight: 550 + }; + + if (invoice.has_taxes) + { + layout.descriptionLeft -= 20; + layout.unitCostRight -= 40; + layout.qtyRight -= 40; + } + + /* + @param orientation One of "portrait" or "landscape" (or shortcuts "p" (Default), "l") + @param unit Measurement unit to be used when coordinates are specified. One of "pt" (points), "mm" (Default), "cm", "in" + @param format One of 'a3', 'a4' (Default),'a5' ,'letter' ,'legal' + @returns {jsPDF} + */ + var doc = new jsPDF('portrait', 'pt', 'a4'); + + + //Set PDF properities + doc.setProperties({ + title: 'Invoice ' + invoice.invoice_number, + subject: '', + author: 'InvoiceNinja.com', + keywords: 'pdf, invoice', + creator: 'InvoiceNinja.com' + }); + + //set default style for report + doc.setFont('Helvetica',''); + + if (report_id==1) { + return GetReportTemplate1(doc, invoice, layout); + } else if (report_id==2) { + return GetReportTemplate2(doc, invoice, layout); + } else if (report_id==3) { + return GetReportTemplate3(doc, invoice, layout); + } else { + return GetReportTemplate4(doc, invoice, layout); + } +} + +function GetReportTemplate1(doc, invoice, layout) +{ + var GlobalY=0;//Y position of line at current page + + var client = invoice.client; + var account = invoice.account; + var currencyId = client.currency_id; + + layout.headerRight = 550; + layout.rowHeight = 15; + + doc.setFontSize(9); + + if (invoice.image) + { + var left = layout.headerRight - invoice.imageWidth; + doc.addImage(invoice.image, 'JPEG', layout.marginLeft, 30); + } + + if (!invoice.is_pro && logoImages.imageLogo1) + { + pageHeight=820; + y=pageHeight-logoImages.imageLogoHeight1; + doc.addImage(logoImages.imageLogo1, 'JPEG', layout.marginLeft, y, logoImages.imageLogoWidth1, logoImages.imageLogoHeight1); + } + + doc.setFontSize(9); + SetPdfColor('LightBlue', doc, 'primary'); + displayAccount(doc, invoice, 220, layout.accountTop, layout); + + SetPdfColor('LightBlue', doc, 'primary'); + doc.setFontSize('11'); + doc.text(50, layout.headerTop, (invoice.is_quote ? invoiceLabels.quote : invoiceLabels.invoice).toUpperCase()); + + + SetPdfColor('Black',doc); //set black color + doc.setFontSize(9); + + var invoiceHeight = displayInvoice(doc, invoice, 50, 170, layout); + var clientHeight = displayClient(doc, invoice, 220, 170, layout); + var detailsHeight = Math.max(invoiceHeight, clientHeight); + layout.tableTop = Math.max(layout.tableTop, layout.headerTop + detailsHeight + (3 * layout.rowHeight)); + + + + doc.setLineWidth(0.3); + doc.setDrawColor(200,200,200); + doc.line(layout.marginLeft - layout.tablePadding, layout.headerTop + 6, layout.marginRight + layout.tablePadding, layout.headerTop + 6); + doc.line(layout.marginLeft - layout.tablePadding, layout.headerTop + detailsHeight + 14, layout.marginRight + layout.tablePadding, layout.headerTop + detailsHeight + 14); + + + doc.setFontSize(10); + doc.setFontType("bold"); + displayInvoiceHeader(doc, invoice, layout); + var y = displayInvoiceItems(doc, invoice, layout); + + doc.setFontSize(9); + doc.setFontType("bold"); + + GlobalY=GlobalY+25; + + + doc.setLineWidth(0.3); + doc.setDrawColor(241,241,241); + doc.setFillColor(241,241,241); + var x1 = layout.marginLeft - 12; + var y1 = GlobalY-layout.tablePadding; + + var w2 = 510 + 24; + var h2 = doc.internal.getFontSize()*3+layout.tablePadding*2; + + if (invoice.discount) { + h2 += doc.internal.getFontSize()*2; + } + if (invoice.tax_amount) { + h2 += doc.internal.getFontSize()*2; + } + + //doc.rect(x1, y1, w2, h2, 'FD'); + + doc.setFontSize(9); + displayNotesAndTerms(doc, layout, invoice, y); + y += displaySubtotals(doc, layout, invoice, y, layout.unitCostRight); + + + doc.setFontSize(10); + Msg = invoice.is_quote ? invoiceLabels.total : invoiceLabels.balance_due; + var TmpMsgX = layout.unitCostRight-(doc.getStringUnitWidth(Msg) * doc.internal.getFontSize()); + + doc.text(TmpMsgX, y, Msg); + + SetPdfColor('LightBlue', doc, 'primary'); + AmountText = formatMoney(invoice.balance_amount, currencyId); + headerLeft=layout.headerRight+400; + var AmountX = layout.lineTotalRight - (doc.getStringUnitWidth(AmountText) * doc.internal.getFontSize()); + doc.text(AmountX, y, AmountText); + + return doc; +} + + + + +function GetReportTemplate2(doc, invoice, layout) +{ + var GlobalY=0;//Y position of line at current page + + var client = invoice.client; + var account = invoice.account; + var currencyId = client.currency_id; + + layout.headerRight = 150; + layout.rowHeight = 15; + layout.headerTop = 125; + layout.tableTop = 300; + + doc.setLineWidth(0.5); + + if (NINJA.primaryColor) { + setDocHexFill(doc, NINJA.primaryColor); + setDocHexDraw(doc, NINJA.primaryColor); + } else { + doc.setFillColor(46,43,43); + } + + var x1 =0; + var y1 = 0; + var w2 = 595; + var h2 = 100; + doc.rect(x1, y1, w2, h2, 'FD'); + + + if (invoice.image) + { + var left = layout.headerRight - invoice.imageWidth; + doc.addImage(invoice.image, 'JPEG', layout.marginLeft, 30); + } + + Report2AddFooter(invoice,doc); + + doc.setFontSize(7); + doc.setFontType("bold"); + SetPdfColor('White',doc); + + displayAccount(doc, invoice, 300, layout.accountTop, layout); + + + var y = layout.accountTop; + var left = layout.marginLeft; + var headerY = layout.headerTop; + + SetPdfColor('GrayLogo',doc); //set black color + doc.setFontSize(7); + + //show left column + SetPdfColor('Black',doc); //set black color + doc.setFontType("normal"); + + //publish filled box + doc.setDrawColor(200,200,200); + + if (NINJA.secondaryColor) { + setDocHexFill(doc, NINJA.secondaryColor); + } else { + doc.setFillColor(54,164,152); + } + + GlobalY=190; + doc.setLineWidth(0.5); + + var BlockLenght=220; + var x1 =595-BlockLenght; + var y1 = GlobalY-12; + var w2 = BlockLenght; + var h2 = getInvoiceDetailsHeight(invoice, layout) + layout.tablePadding + 2; + + doc.rect(x1, y1, w2, h2, 'FD'); + + SetPdfColor('SomeGreen', doc, 'secondary'); + doc.setFontSize('14'); + doc.setFontType("bold"); + doc.text(50, GlobalY, (invoice.is_quote ? invoiceLabels.your_quote : invoiceLabels.your_invoice).toUpperCase()); + + + var z=GlobalY; + z=z+30; + + doc.setFontSize('8'); + SetPdfColor('Black',doc); + displayClient(doc, invoice, layout.marginLeft, z, layout); + + marginLeft2=395; + + //publish left side information + SetPdfColor('White',doc); + doc.setFontSize('8'); + var detailsHeight = displayInvoice(doc, invoice, marginLeft2, z-25, layout) + 75; + layout.tableTop = Math.max(layout.tableTop, layout.headerTop + detailsHeight + (2 * layout.tablePadding)); + + y=z+60; + x = GlobalY + 100; + doc.setFontType("bold"); + + doc.setFontSize(12); + doc.setFontType("bold"); + SetPdfColor('Black',doc); + displayInvoiceHeader(doc, invoice, layout); + + var y = displayInvoiceItems(doc, invoice, layout); + doc.setLineWidth(0.3); + displayNotesAndTerms(doc, layout, invoice, y); + y += displaySubtotals(doc, layout, invoice, y, layout.unitCostRight); + + doc.setFontType("bold"); + + doc.setFontSize(12); + x += doc.internal.getFontSize()*4; + Msg = invoice.is_quote ? invoiceLabels.total : invoiceLabels.balance_due; + var TmpMsgX = layout.unitCostRight-(doc.getStringUnitWidth(Msg) * doc.internal.getFontSize()); + + doc.text(TmpMsgX, y, Msg); + + //SetPdfColor('LightBlue',doc); + AmountText = formatMoney(invoice.balance_amount , currencyId); + headerLeft=layout.headerRight+400; + var AmountX = headerLeft - (doc.getStringUnitWidth(AmountText) * doc.internal.getFontSize()); + SetPdfColor('SomeGreen', doc, 'secondary'); + doc.text(AmountX, y, AmountText); + + return doc; +} + + +function Report2AddFooter (invoice,doc) +{ + doc.setLineWidth(0.5); + if (NINJA.primaryColor) { + setDocHexFill(doc, NINJA.primaryColor); + setDocHexDraw(doc, NINJA.primaryColor); + } else { + doc.setFillColor(46,43,43); + doc.setDrawColor(46,43,43); + } + + // return doc.setTextColor(240,240,240);//select color Custom Report GRAY Colour + var x1 = 0;//tableLeft-tablePadding ; + var y1 = 750; + var w2 = 596; + var h2 = 94;//doc.internal.getFontSize()*length+length*1.1;//+h;//+tablePadding; + + + doc.rect(x1, y1, w2, h2, 'FD'); + + if (!invoice.is_pro && logoImages.imageLogo2) + { + pageHeight=820; + var left = 250;//headerRight ; + y=pageHeight-logoImages.imageLogoHeight2; + var headerRight=370; + + var left = headerRight - logoImages.imageLogoWidth2; + doc.addImage(logoImages.imageLogo2, 'JPEG', left, y, logoImages.imageLogoWidth2, logoImages.imageLogoHeight2); + } +} + +function Report3AddFooter (invoice, account, doc, layout) +{ + + doc.setLineWidth(0.5); + + if (NINJA.primaryColor) { + setDocHexFill(doc, NINJA.primaryColor); + setDocHexDraw(doc, NINJA.primaryColor); + } else { + doc.setDrawColor(242,101,34); + doc.setFillColor(242,101,34); + } + + var x1 = 0;//tableLeft-tablePadding ; + var y1 = 750; + var w2 = 596; + var h2 = 94;//doc.internal.getFontSize()*length+length*1.1;//+h;//+tablePadding; + + doc.rect(x1, y1, w2, h2, 'FD'); + + if (!invoice.is_pro && logoImages.imageLogo3) + { + pageHeight=820; + // var left = 25;//250;//headerRight ; + y=pageHeight-logoImages.imageLogoHeight3; + //var headerRight=370; + + //var left = headerRight - invoice.imageLogoWidth3; + doc.addImage(logoImages.imageLogo3, 'JPEG', 40, y, logoImages.imageLogoWidth3, logoImages.imageLogoHeight3); + } + + doc.setFontSize(10); + var marginLeft = 340; + displayAccount(doc, invoice, marginLeft, 780, layout); +} + + + +function GetReportTemplate3(doc, invoice, layout) +{ + var client = invoice.client; + var account = invoice.account; + var currencyId = client.currency_id; + + layout.headerRight = 400; + layout.rowHeight = 15; + + + doc.setFontSize(7); + + Report3AddHeader(invoice, layout, doc); + + if (invoice.image) + { + y=130; + var left = layout.headerRight - invoice.imageWidth; + doc.addImage(invoice.image, 'JPEG', layout.marginLeft, y); + } + + Report3AddFooter (invoice, account, doc, layout); + + + SetPdfColor('White',doc); + doc.setFontSize('8'); + var detailsHeight = displayInvoice(doc, invoice, layout.headerRight, layout.accountTop-10, layout); + layout.headerTop = Math.max(layout.headerTop, detailsHeight + 50); + layout.tableTop = Math.max(layout.tableTop, detailsHeight + 150); + + SetPdfColor('Black',doc); //set black color + doc.setFontSize(7); + doc.setFontType("normal"); + displayClient(doc, invoice, layout.headerRight, layout.headerTop, layout); + + + + SetPdfColor('White',doc); + doc.setFontType('bold'); + + doc.setLineWidth(0.3); + if (NINJA.secondaryColor) { + setDocHexFill(doc, NINJA.secondaryColor); + setDocHexDraw(doc, NINJA.secondaryColor); + } else { + doc.setDrawColor(63,60,60); + doc.setFillColor(63,60,60); + } + + var left = layout.marginLeft - layout.tablePadding; + var top = layout.tableTop - layout.tablePadding; + var width = layout.marginRight - (2 * layout.tablePadding); + var height = 20; + doc.rect(left, top, width, height, 'FD'); + + + displayInvoiceHeader(doc, invoice, layout); + SetPdfColor('Black',doc); + var y = displayInvoiceItems(doc, invoice, layout); + + + var height1 = displayNotesAndTerms(doc, layout, invoice, y); + var height2 = displaySubtotals(doc, layout, invoice, y, layout.unitCostRight); + y += Math.max(height1, height2); + + + var left = layout.marginLeft - layout.tablePadding; + var top = y - layout.tablePadding; + var width = layout.marginRight - (2 * layout.tablePadding); + var height = 20; + if (NINJA.secondaryColor) { + setDocHexFill(doc, NINJA.secondaryColor); + setDocHexDraw(doc, NINJA.secondaryColor); + } else { + doc.setDrawColor(63,60,60); + doc.setFillColor(63,60,60); + } + doc.rect(left, top, width, height, 'FD'); + + doc.setFontType('bold'); + SetPdfColor('White', doc); + doc.setFontSize(12); + + var label = invoice.is_quote ? invoiceLabels.total : invoiceLabels.balance_due; + var labelX = layout.unitCostRight-(doc.getStringUnitWidth(label) * doc.internal.getFontSize()); + doc.text(labelX, y+2, label); + + + doc.setFontType('normal'); + var amount = formatMoney(invoice.balance_amount , currencyId); + headerLeft=layout.headerRight+400; + var amountX = layout.lineTotalRight - (doc.getStringUnitWidth(amount) * doc.internal.getFontSize()); + doc.text(amountX, y+2, amount); + + return doc; +} + + + + +function Report3AddHeader (invoice, layout, doc) +{ + doc.setLineWidth(0.5); + + if (NINJA.primaryColor) { + setDocHexFill(doc, NINJA.primaryColor); + setDocHexDraw(doc, NINJA.primaryColor); + } else { + doc.setDrawColor(242,101,34); + doc.setFillColor(242,101,34); + } + + var x1 =0; + var y1 = 0; + var w2 = 595; + var h2 = Math.max(110, getInvoiceDetailsHeight(invoice, layout) + 30); + doc.rect(x1, y1, w2, h2, 'FD'); + + SetPdfColor('White',doc); + + //second column + doc.setFontType('bold'); + var name = invoice.account.name; + if (name) { + doc.setFontSize('30'); + doc.setFontType('bold'); + doc.text(40, 50, name); + } +} + + +function Report1AddNewPage(invoice,account,doc) +{ + doc.addPage(); + if (logoImages.imageLogo1) + { + pageHeight=820; + y=pageHeight-logoImages.imageLogoHeight1; + var left = 20;//headerRight - invoice.imageLogoWidth1; + doc.addImage(logoImages.imageLogo1, 'JPEG', left, y, logoImages.imageLogoWidth1, logoImages.imageLogoHeight1); + + } + + GlobalY = 40; + return GlobalY; +} + + + + +function GetReportTemplate4(doc, invoice, layout) { var client = invoice.client; var account = invoice.account; @@ -45979,29 +46515,10 @@ function GetReportTemplate4(doc, invoice, layout, checkMath) { doc.setFontSize(10); - /* table footer */ - /* - doc.setDrawColor(200,200,200); - doc.setLineWidth(1); - doc.line(layout.marginLeft - layout.tablePadding, x, layout.lineTotalRight+layout.tablePadding, x); - */ - displayNotesAndTerms(doc, layout, invoice, y+20); y += displaySubtotals(doc, layout, invoice, y+20, 480) + 20; - /* - if (checkMath && NINJA.parseFloat(total).toFixed(4) != NINJA.parseFloat(invoice.amount).toFixed(4)) - { - var doc = new jsPDF('p', 'pt'); - doc.setFont('Helvetica',''); - doc.setFontSize(10); - doc.text(100, 100, "An error occurred, please try again later."); - onerror('Failed to generate PDF ' + total + ', ' + invoice.amount ); - return doc; - } - */ - doc.setDrawColor(200,200,200); doc.setFillColor(230,230,230); @@ -46027,26 +46544,51 @@ function GetReportTemplate4(doc, invoice, layout, checkMath) { } -var invoiceOld; -function generatePDF(invoice, force) { - invoice = calculateAmounts(invoice); - var a = copyInvoice(invoice); - var b = copyInvoice(invoiceOld); - if (!force && _.isEqual(a, b)) { - return; +function SetPdfColor(color, doc, role) +{ + if (role === 'primary' && NINJA.primaryColor) { + return setDocHexColor(doc, NINJA.primaryColor); + } else if (role === 'secondary' && NINJA.secondaryColor) { + return setDocHexColor(doc, NINJA.secondaryColor); } - invoiceOld = invoice; - report_id = invoice.invoice_design_id; - doc = GetPdf(invoice, false, report_id); - return doc; + + if (color=='LightBlue') { + return doc.setTextColor(41,156, 194); + } + + if (color=='Black') { + return doc.setTextColor(46,43,43);//select color black + } + if (color=='GrayLogo') { + return doc.setTextColor(207,241, 241);//select color Custom Report GRAY + } + + if (color=='GrayBackground') { + return doc.setTextColor(251,251, 251);//select color Custom Report GRAY + } + + if (color=='GrayText') { + return doc.setTextColor(161,160,160);//select color Custom Report GRAY Colour + } + + if (color=='White') { + return doc.setTextColor(255,255,255);//select color Custom Report GRAY Colour + } + + if (color=='SomeGreen') { + return doc.setTextColor(54,164,152);//select color Custom Report GRAY Colour + } + + if (color=='LightGrayReport2-gray') { + return doc.setTextColor(240,240,240);//select color Custom Report GRAY Colour + } + + if (color=='LightGrayReport2-white') { + return doc.setTextColor(251,251,251);//select color Custom Report GRAY Colour + } + } -function copyInvoice(orig) { - if (!orig) return false; - var copy = JSON.stringify(orig); - var copy = JSON.parse(copy); - return copy; -} /* Handle converting variables in the invoices (ie, MONTH+1) */ function processVariables(str) { @@ -46499,7 +47041,8 @@ function populateInvoiceComboboxes(clientId, invoiceId) { var client = clientMap[invoice.client.public_id]; setComboboxValue($('.client-select'), client.public_id, getClientDisplayName(client)); if (!parseFloat($('#amount').val())) { - $('#amount').val(formatMoney(invoice.balance, invoice.currency_id, true)); + //$('#amount').val(formatMoney(invoice.balance, invoice.currency_id, true)); + $('#amount').val(parseFloat(invoice.balance).toFixed(2)); } } }); @@ -46535,629 +47078,7 @@ $.fn.datepicker.defaults.todayHighlight = true; -//==================================================================================================================== -function GetPdf(invoice,checkMath,report_id){ - var layout = { - accountTop: 40, - marginLeft: 50, - marginRight: 550, - headerTop: 150, - headerLeft: 360, - headerRight: 550, - rowHeight: 15, - tableRowHeight: 10, - footerLeft: 420, - tablePadding: 12, - tableTop: 250, - descriptionLeft: 162, - unitCostRight: 410, - qtyRight: 480, - taxRight: 480, - lineTotalRight: 550 - }; - - if (invoice.has_taxes) - { - layout.descriptionLeft -= 20; - layout.unitCostRight -= 40; - layout.qtyRight -= 40; - } - - /* - @param orientation One of "portrait" or "landscape" (or shortcuts "p" (Default), "l") - @param unit Measurement unit to be used when coordinates are specified. One of "pt" (points), "mm" (Default), "cm", "in" - @param format One of 'a3', 'a4' (Default),'a5' ,'letter' ,'legal' - @returns {jsPDF} - */ - var doc = new jsPDF('portrait', 'pt', 'a4'); - - - //Set PDF properities - doc.setProperties({ - title: 'Invoice ' + invoice.invoice_number, - subject: '', - author: 'InvoiceNinja.com', - keywords: 'pdf, invoice', - creator: 'InvoiceNinja.com' - }); - - //set default style for report - doc.setFont('Helvetica',''); - - if (report_id==1) { - return GetReportTemplate1(doc, invoice, layout, checkMath); - } else if (report_id==2) { - return GetReportTemplate2(doc, invoice, layout, checkMath); - } else if (report_id==3) { - return GetReportTemplate3(doc, invoice, layout, checkMath); - } else { - return GetReportTemplate4(doc, invoice, layout, checkMath); - } -} - -function GetReportTemplate1(doc, invoice, layout, checkMath) -{ - var GlobalY=0;//Y position of line at current page - - var client = invoice.client; - var account = invoice.account; - var currencyId = client.currency_id; - - layout.headerRight = 550; - layout.rowHeight = 15; - - doc.setFontSize(9); - - if (invoice.image) - { - var left = layout.headerRight - invoice.imageWidth; - doc.addImage(invoice.image, 'JPEG', layout.marginLeft, 30); - } - - if (!invoice.is_pro && logoImages.imageLogo1) - { - pageHeight=820; - y=pageHeight-logoImages.imageLogoHeight1; - doc.addImage(logoImages.imageLogo1, 'JPEG', layout.marginLeft, y, logoImages.imageLogoWidth1, logoImages.imageLogoHeight1); - } - - doc.setFontSize(9); - SetPdfColor('LightBlue', doc, 'primary'); - displayAccount(doc, invoice, 220, layout.accountTop, layout); - - SetPdfColor('LightBlue', doc, 'primary'); - doc.setFontSize('11'); - doc.text(50, layout.headerTop, (invoice.is_quote ? invoiceLabels.quote : invoiceLabels.invoice).toUpperCase()); - - //doc.setDrawColor(220,220,220); - //doc.line(30, y, 560, y); // horizontal line - - - SetPdfColor('Black',doc); //set black color - doc.setFontSize(9); - - var invoiceHeight = displayInvoice(doc, invoice, 50, 170, layout); - var clientHeight = displayClient(doc, invoice, 220, 170, layout); - var detailsHeight = Math.max(invoiceHeight, clientHeight); - layout.tableTop = Math.max(layout.tableTop, layout.headerTop + detailsHeight + (3 * layout.rowHeight)); - - - - doc.setLineWidth(0.3); - doc.setDrawColor(200,200,200); - doc.line(layout.marginLeft - layout.tablePadding, layout.headerTop + 6, layout.marginRight + layout.tablePadding, layout.headerTop + 6); - doc.line(layout.marginLeft - layout.tablePadding, layout.headerTop + detailsHeight + 14, layout.marginRight + layout.tablePadding, layout.headerTop + detailsHeight + 14); - - - //doc.setDrawColor(220,220,220); - //doc.line(30, y-8, 560, y-8); // horizontal line - - - doc.setFontSize(10); - doc.setFontType("bold"); - displayInvoiceHeader(doc, invoice, layout); - var y = displayInvoiceItems(doc, invoice, layout); - - //doc.setFontType("normal"); - doc.setFontSize(9); - - doc.setFontType("bold"); - - GlobalY=GlobalY+25; - - - doc.setLineWidth(0.3); - doc.setDrawColor(241,241,241); - doc.setFillColor(241,241,241); - var x1 = layout.marginLeft - 12; - var y1 = GlobalY-layout.tablePadding; - - var w2 = 510 + 24; - var h2 = doc.internal.getFontSize()*3+layout.tablePadding*2; - - if (invoice.discount) { - h2 += doc.internal.getFontSize()*2; - } - if (invoice.tax_amount) { - h2 += doc.internal.getFontSize()*2; - } - - //doc.rect(x1, y1, w2, h2, 'FD'); - - doc.setFontSize(9); - displayNotesAndTerms(doc, layout, invoice, y); - y += displaySubtotals(doc, layout, invoice, y, layout.unitCostRight); - - - doc.setFontSize(10); - Msg = invoice.is_quote ? invoiceLabels.total : invoiceLabels.balance_due; - var TmpMsgX = layout.unitCostRight-(doc.getStringUnitWidth(Msg) * doc.internal.getFontSize()); - - doc.text(TmpMsgX, y, Msg); - - SetPdfColor('LightBlue', doc, 'primary'); - AmountText = formatMoney(invoice.balance_amount, currencyId); - headerLeft=layout.headerRight+400; - var AmountX = layout.lineTotalRight - (doc.getStringUnitWidth(AmountText) * doc.internal.getFontSize()); - doc.text(AmountX, y, AmountText); - - return doc; -} - - - - -function GetReportTemplate2(doc, invoice, layout, checkMath) -{ - var GlobalY=0;//Y position of line at current page - - var client = invoice.client; - var account = invoice.account; - var currencyId = client.currency_id; - - layout.headerRight = 150; - layout.rowHeight = 15; - layout.headerTop = 125; - layout.tableTop = 300; - - doc.setLineWidth(0.5); - - if (NINJA.primaryColor) { - setDocHexFill(doc, NINJA.primaryColor); - setDocHexDraw(doc, NINJA.primaryColor); - } else { - doc.setFillColor(46,43,43); - } - - var x1 =0; - var y1 = 0; - var w2 = 595; - var h2 = 100; - doc.rect(x1, y1, w2, h2, 'FD'); - - - if (invoice.image) - { - var left = layout.headerRight - invoice.imageWidth; - doc.addImage(invoice.image, 'JPEG', layout.marginLeft, 30); - } - - Report2AddFooter (invoice,doc); - - - doc.setFontSize(7); - doc.setFontType("bold"); - SetPdfColor('White',doc); - - displayAccount(doc, invoice, 300, layout.accountTop, layout); - - /* - var spacer = ' '; - var line1 = account.name + spacer + account.work_email + spacer + account.work_phone; - var lineWidth = doc.getStringUnitWidth(line1) * doc.internal.getFontSize(); - var nameWidth = doc.getStringUnitWidth(account.name + spacer) * doc.internal.getFontSize(); - var nameX = lineTotalRight - lineWidth; - var detailsX = lineTotalRight - (lineWidth - nameWidth); - - doc.text(nameX, accountTop, account.name); - doc.setFontType("normal"); - doc.text(detailsX, accountTop, account.work_email + spacer + account.work_phone); - - var line2 = concatStrings(account.address1, account.address2) + spacer + concatStrings(account.city, account.state, account.postal_code); - var lineWidth = doc.getStringUnitWidth(line2) * doc.internal.getFontSize(); - var line2X = lineTotalRight - lineWidth; - - doc.text(line2X, accountTop + 16, line2); - */ - -//-----------------------------Publish Client Details block-------------------------------------------- - - var y = layout.accountTop; - var left = layout.marginLeft; - - var headerY = layout.headerTop; - - - - SetPdfColor('GrayLogo',doc); //set black color - - - doc.setFontSize(7); - - //show left column - SetPdfColor('Black',doc); //set black color - doc.setFontType("normal"); - - - //publish filled box - doc.setDrawColor(200,200,200); - - if (NINJA.secondaryColor) { - setDocHexFill(doc, NINJA.secondaryColor); - } else { - doc.setFillColor(54,164,152); - } - - GlobalY=190; - doc.setLineWidth(0.5); - - var BlockLenght=220; - var x1 =595-BlockLenght; - var y1 = GlobalY-12; - var w2 = BlockLenght; - var h2 = getInvoiceDetailsHeight(invoice, layout) + layout.tablePadding + 2; - - doc.rect(x1, y1, w2, h2, 'FD'); - - - SetPdfColor('SomeGreen', doc, 'secondary'); - doc.setFontSize('14'); - doc.setFontType("bold"); - doc.text(50, GlobalY, (invoice.is_quote ? invoiceLabels.your_quote : invoiceLabels.your_invoice).toUpperCase()); - - - var z=GlobalY; - z=z+30; - - - doc.setFontSize('8'); - SetPdfColor('Black',doc); - displayClient(doc, invoice, layout.marginLeft, z, layout); - - - marginLeft2=395; - - //publish left side information - - SetPdfColor('White',doc); - doc.setFontSize('8'); - var detailsHeight = displayInvoice(doc, invoice, marginLeft2, z-25, layout) + 75; - layout.tableTop = Math.max(layout.tableTop, layout.headerTop + detailsHeight + (2 * layout.tablePadding)); - - y=z+60; - - - x = GlobalY + 100; - - doc.setFontType("bold"); - - - - doc.setFontSize(12); - doc.setFontType("bold"); - SetPdfColor('Black',doc); - displayInvoiceHeader(doc, invoice, layout); - var y = displayInvoiceItems(doc, invoice, layout); - - //GlobalY=600; - - doc.setLineWidth(0.3); - - /* - doc.setDrawColor(251,251,251); - doc.setFillColor(251,251,251); - var x1 = layout.marginLeft-layout.tablePadding*2 +14; - var y1 = GlobalY-layout.tablePadding; - var w2 = 510+layout.tablePadding*2;//lineTotalRight-tablePadding*5; - var h2 = doc.internal.getFontSize()*3+layout.tablePadding*2; - doc.rect(x1, y1, w2, h2, 'FD'); - */ - - displayNotesAndTerms(doc, layout, invoice, y); - y += displaySubtotals(doc, layout, invoice, y, layout.unitCostRight); - - doc.setFontType("bold"); - - doc.setFontSize(12); - x += doc.internal.getFontSize()*4; - Msg = invoice.is_quote ? invoiceLabels.total : invoiceLabels.balance_due; - var TmpMsgX = layout.unitCostRight-(doc.getStringUnitWidth(Msg) * doc.internal.getFontSize()); - - - - doc.text(TmpMsgX, y, Msg); - - - //SetPdfColor('LightBlue',doc); - AmountText = formatMoney(invoice.balance_amount , currencyId); - headerLeft=layout.headerRight+400; - var AmountX = headerLeft - (doc.getStringUnitWidth(AmountText) * doc.internal.getFontSize()); - SetPdfColor('SomeGreen', doc, 'secondary'); - doc.text(AmountX, y, AmountText); - - return doc; -} - - - - - - - -function SetPdfColor(color, doc, role) -{ - if (role === 'primary' && NINJA.primaryColor) { - return setDocHexColor(doc, NINJA.primaryColor); - } else if (role === 'secondary' && NINJA.secondaryColor) { - return setDocHexColor(doc, NINJA.secondaryColor); - } - - if (color=='LightBlue') { - return doc.setTextColor(41,156, 194); - } - - if (color=='Black') { - return doc.setTextColor(46,43,43);//select color black - } - if (color=='GrayLogo') { - return doc.setTextColor(207,241, 241);//select color Custom Report GRAY - } - - if (color=='GrayBackground') { - return doc.setTextColor(251,251, 251);//select color Custom Report GRAY - } - - if (color=='GrayText') { - return doc.setTextColor(161,160,160);//select color Custom Report GRAY Colour - } - - if (color=='White') { - return doc.setTextColor(255,255,255);//select color Custom Report GRAY Colour - } - - if (color=='SomeGreen') { - return doc.setTextColor(54,164,152);//select color Custom Report GRAY Colour - } - - if (color=='LightGrayReport2-gray') { - return doc.setTextColor(240,240,240);//select color Custom Report GRAY Colour - } - - if (color=='LightGrayReport2-white') { - return doc.setTextColor(251,251,251);//select color Custom Report GRAY Colour - } - -} - -function Report2AddFooter (invoice,doc) -{ - doc.setLineWidth(0.5); - if (NINJA.primaryColor) { - setDocHexFill(doc, NINJA.primaryColor); - setDocHexDraw(doc, NINJA.primaryColor); - } else { - doc.setFillColor(46,43,43); - doc.setDrawColor(46,43,43); - } - - // return doc.setTextColor(240,240,240);//select color Custom Report GRAY Colour - var x1 = 0;//tableLeft-tablePadding ; - var y1 = 750; - var w2 = 596; - var h2 = 94;//doc.internal.getFontSize()*length+length*1.1;//+h;//+tablePadding; - - - doc.rect(x1, y1, w2, h2, 'FD'); - - if (!invoice.is_pro && logoImages.imageLogo2) - { - pageHeight=820; - var left = 250;//headerRight ; - y=pageHeight-logoImages.imageLogoHeight2; - var headerRight=370; - - var left = headerRight - logoImages.imageLogoWidth2; - doc.addImage(logoImages.imageLogo2, 'JPEG', left, y, logoImages.imageLogoWidth2, logoImages.imageLogoHeight2); - } -} - -function Report3AddFooter (invoice, account, doc, layout) -{ - - doc.setLineWidth(0.5); - - if (NINJA.primaryColor) { - setDocHexFill(doc, NINJA.primaryColor); - setDocHexDraw(doc, NINJA.primaryColor); - } else { - doc.setDrawColor(242,101,34); - doc.setFillColor(242,101,34); - } - - var x1 = 0;//tableLeft-tablePadding ; - var y1 = 750; - var w2 = 596; - var h2 = 94;//doc.internal.getFontSize()*length+length*1.1;//+h;//+tablePadding; - - doc.rect(x1, y1, w2, h2, 'FD'); - - if (!invoice.is_pro && logoImages.imageLogo3) - { - pageHeight=820; - // var left = 25;//250;//headerRight ; - y=pageHeight-logoImages.imageLogoHeight3; - //var headerRight=370; - - //var left = headerRight - invoice.imageLogoWidth3; - doc.addImage(logoImages.imageLogo3, 'JPEG', 40, y, logoImages.imageLogoWidth3, logoImages.imageLogoHeight3); - } - - doc.setFontSize(10); - var marginLeft = 340; - displayAccount(doc, invoice, marginLeft, 780, layout); -} - - - -function GetReportTemplate3(doc, invoice, layout, checkMath) -{ - var client = invoice.client; - var account = invoice.account; - var currencyId = client.currency_id; - - layout.headerRight = 400; - layout.rowHeight = 15; - - - doc.setFontSize(7); - - Report3AddHeader(invoice, layout, doc); - - if (invoice.image) - { - y=130; - var left = layout.headerRight - invoice.imageWidth; - doc.addImage(invoice.image, 'JPEG', layout.marginLeft, y); - } - - Report3AddFooter (invoice, account, doc, layout); - - - SetPdfColor('White',doc); - doc.setFontSize('8'); - var detailsHeight = displayInvoice(doc, invoice, layout.headerRight, layout.accountTop-10, layout); - layout.headerTop = Math.max(layout.headerTop, detailsHeight + 50); - layout.tableTop = Math.max(layout.tableTop, detailsHeight + 150); - - SetPdfColor('Black',doc); //set black color - doc.setFontSize(7); - doc.setFontType("normal"); - displayClient(doc, invoice, layout.headerRight, layout.headerTop, layout); - - - - SetPdfColor('White',doc); - doc.setFontType('bold'); - - doc.setLineWidth(0.3); - if (NINJA.secondaryColor) { - setDocHexFill(doc, NINJA.secondaryColor); - setDocHexDraw(doc, NINJA.secondaryColor); - } else { - doc.setDrawColor(63,60,60); - doc.setFillColor(63,60,60); - } - - var left = layout.marginLeft - layout.tablePadding; - var top = layout.tableTop - layout.tablePadding; - var width = layout.marginRight - (2 * layout.tablePadding); - var height = 20; - doc.rect(left, top, width, height, 'FD'); - - - displayInvoiceHeader(doc, invoice, layout); - SetPdfColor('Black',doc); - var y = displayInvoiceItems(doc, invoice, layout); - - - var height1 = displayNotesAndTerms(doc, layout, invoice, y); - var height2 = displaySubtotals(doc, layout, invoice, y, layout.unitCostRight); - y += Math.max(height1, height2); - - - var left = layout.marginLeft - layout.tablePadding; - var top = y - layout.tablePadding; - var width = layout.marginRight - (2 * layout.tablePadding); - var height = 20; - if (NINJA.secondaryColor) { - setDocHexFill(doc, NINJA.secondaryColor); - setDocHexDraw(doc, NINJA.secondaryColor); - } else { - doc.setDrawColor(63,60,60); - doc.setFillColor(63,60,60); - } - doc.rect(left, top, width, height, 'FD'); - - doc.setFontType('bold'); - SetPdfColor('White', doc); - doc.setFontSize(12); - - var label = invoice.is_quote ? invoiceLabels.total : invoiceLabels.balance_due; - var labelX = layout.unitCostRight-(doc.getStringUnitWidth(label) * doc.internal.getFontSize()); - doc.text(labelX, y+2, label); - - - doc.setFontType('normal'); - var amount = formatMoney(invoice.balance_amount , currencyId); - headerLeft=layout.headerRight+400; - var amountX = layout.lineTotalRight - (doc.getStringUnitWidth(amount) * doc.internal.getFontSize()); - doc.text(amountX, y+2, amount); - - return doc; -} - - - - -function Report3AddHeader (invoice, layout, doc) -{ - doc.setLineWidth(0.5); - - if (NINJA.primaryColor) { - setDocHexFill(doc, NINJA.primaryColor); - setDocHexDraw(doc, NINJA.primaryColor); - } else { - doc.setDrawColor(242,101,34); - doc.setFillColor(242,101,34); - } - - var x1 =0; - var y1 = 0; - var w2 = 595; - var h2 = Math.max(110, getInvoiceDetailsHeight(invoice, layout) + 30); - doc.rect(x1, y1, w2, h2, 'FD'); - - SetPdfColor('White',doc); - - //second column - doc.setFontType('bold'); - var MaxWidth=594; - var LineOne= invoice.account.name; - var AlignLine = MaxWidth-30- (doc.getStringUnitWidth(LineOne) * doc.internal.getFontSize()); - if (LineOne) { - doc.setFontSize('30'); - doc.setFontType('bold'); - doc.text(40, 50, LineOne); - } -} - - -function Report1AddNewPage(invoice,account,doc) -{ - doc.addPage(); - if (logoImages.imageLogo1) - { - pageHeight=820; - y=pageHeight-logoImages.imageLogoHeight1; - var left = 20;//headerRight - invoice.imageLogoWidth1; - doc.addImage(logoImages.imageLogo1, 'JPEG', left, y, logoImages.imageLogoWidth1, logoImages.imageLogoHeight1); - - } - - GlobalY = 40; - return GlobalY; -} function displayAccount(doc, invoice, x, y, layout) { var account = invoice.account; @@ -47172,7 +47093,7 @@ function displayAccount(doc, invoice, x, y, layout) { account.work_phone ]; - displayGrid(doc, invoice, data, x, y, layout, true); + displayGrid(doc, invoice, data, x, y, layout, {hasHeader:true}); data = [ concatStrings(account.address1, account.address2), @@ -47203,7 +47124,7 @@ function displayClient(doc, invoice, x, y, layout) { client.contacts[0].email ]; - return displayGrid(doc, invoice, data, x, y, layout, true); + return displayGrid(doc, invoice, data, x, y, layout, {hasheader:true}); } function displayInvoice(doc, invoice, x, y, layout, rightAlignX) { @@ -47212,7 +47133,12 @@ function displayInvoice(doc, invoice, x, y, layout, rightAlignX) { } var data = getInvoiceDetails(invoice); - return displayGrid(doc, invoice, data, x, y, layout, true, rightAlignX); + var options = { + hasheader: true, + rightAlignX: rightAlignX, + }; + + return displayGrid(doc, invoice, data, x, y, layout, options); } function getInvoiceDetails(invoice) { @@ -47281,7 +47207,13 @@ function displaySubtotals(doc, layout, invoice, y, rightAlignTitleX) data.push({'paid_to_date': formatMoney(paid, invoice.client.currency_id)}); } - return displayGrid(doc, invoice, data, 300, y, layout, true, 550, rightAlignTitleX) + 10; + var options = { + hasheader: true, + rightAlignX: 550, + rightAlignTitleX: rightAlignTitleX + }; + + return displayGrid(doc, invoice, data, 300, y, layout, options) + 10; } function concatStrings() { @@ -47304,7 +47236,8 @@ function concatStrings() { return data.length ? concatStr : false; } -function displayGrid(doc, invoice, data, x, y, layout, hasheader, rightAlignX, rightAlignTitleX) { +//function displayGrid(doc, invoice, data, x, y, layout, hasheader, rightAlignX, rightAlignTitleX) { +function displayGrid(doc, invoice, data, x, y, layout, options) { var numLines = 0; var origY = y; for (var i=0; i= 0; var isIE = /*@cc_on!@*/false || !!document.documentMode; // At least IE6 -function GetReportTemplate4(doc, invoice, layout, checkMath) { + +var invoiceOld; +function generatePDF(invoice, force) { + invoice = calculateAmounts(invoice); + var a = copyInvoice(invoice); + var b = copyInvoice(invoiceOld); + if (!force && _.isEqual(a, b)) { + return; + } + invoiceOld = invoice; + report_id = invoice.invoice_design_id; + doc = GetPdf(invoice, report_id); + return doc; +} + +function copyInvoice(orig) { + if (!orig) return false; + var copy = JSON.stringify(orig); + var copy = JSON.parse(copy); + return copy; +} + + + +function GetPdf(invoice, report_id){ + var layout = { + accountTop: 40, + marginLeft: 50, + marginRight: 550, + headerTop: 150, + headerLeft: 360, + headerRight: 550, + rowHeight: 15, + tableRowHeight: 10, + footerLeft: 420, + tablePadding: 12, + tableTop: 250, + descriptionLeft: 162, + unitCostRight: 410, + qtyRight: 480, + taxRight: 480, + lineTotalRight: 550 + }; + + if (invoice.has_taxes) + { + layout.descriptionLeft -= 20; + layout.unitCostRight -= 40; + layout.qtyRight -= 40; + } + + /* + @param orientation One of "portrait" or "landscape" (or shortcuts "p" (Default), "l") + @param unit Measurement unit to be used when coordinates are specified. One of "pt" (points), "mm" (Default), "cm", "in" + @param format One of 'a3', 'a4' (Default),'a5' ,'letter' ,'legal' + @returns {jsPDF} + */ + var doc = new jsPDF('portrait', 'pt', 'a4'); + + + //Set PDF properities + doc.setProperties({ + title: 'Invoice ' + invoice.invoice_number, + subject: '', + author: 'InvoiceNinja.com', + keywords: 'pdf, invoice', + creator: 'InvoiceNinja.com' + }); + + //set default style for report + doc.setFont('Helvetica',''); + + if (report_id==1) { + return GetReportTemplate1(doc, invoice, layout); + } else if (report_id==2) { + return GetReportTemplate2(doc, invoice, layout); + } else if (report_id==3) { + return GetReportTemplate3(doc, invoice, layout); + } else { + return GetReportTemplate4(doc, invoice, layout); + } +} + +function GetReportTemplate1(doc, invoice, layout) +{ + var GlobalY=0;//Y position of line at current page + + var client = invoice.client; + var account = invoice.account; + var currencyId = client.currency_id; + + layout.headerRight = 550; + layout.rowHeight = 15; + + doc.setFontSize(9); + + if (invoice.image) + { + var left = layout.headerRight - invoice.imageWidth; + doc.addImage(invoice.image, 'JPEG', layout.marginLeft, 30); + } + + if (!invoice.is_pro && logoImages.imageLogo1) + { + pageHeight=820; + y=pageHeight-logoImages.imageLogoHeight1; + doc.addImage(logoImages.imageLogo1, 'JPEG', layout.marginLeft, y, logoImages.imageLogoWidth1, logoImages.imageLogoHeight1); + } + + doc.setFontSize(9); + SetPdfColor('LightBlue', doc, 'primary'); + displayAccount(doc, invoice, 220, layout.accountTop, layout); + + SetPdfColor('LightBlue', doc, 'primary'); + doc.setFontSize('11'); + doc.text(50, layout.headerTop, (invoice.is_quote ? invoiceLabels.quote : invoiceLabels.invoice).toUpperCase()); + + + SetPdfColor('Black',doc); //set black color + doc.setFontSize(9); + + var invoiceHeight = displayInvoice(doc, invoice, 50, 170, layout); + var clientHeight = displayClient(doc, invoice, 220, 170, layout); + var detailsHeight = Math.max(invoiceHeight, clientHeight); + layout.tableTop = Math.max(layout.tableTop, layout.headerTop + detailsHeight + (3 * layout.rowHeight)); + + + + doc.setLineWidth(0.3); + doc.setDrawColor(200,200,200); + doc.line(layout.marginLeft - layout.tablePadding, layout.headerTop + 6, layout.marginRight + layout.tablePadding, layout.headerTop + 6); + doc.line(layout.marginLeft - layout.tablePadding, layout.headerTop + detailsHeight + 14, layout.marginRight + layout.tablePadding, layout.headerTop + detailsHeight + 14); + + + doc.setFontSize(10); + doc.setFontType("bold"); + displayInvoiceHeader(doc, invoice, layout); + var y = displayInvoiceItems(doc, invoice, layout); + + doc.setFontSize(9); + doc.setFontType("bold"); + + GlobalY=GlobalY+25; + + + doc.setLineWidth(0.3); + doc.setDrawColor(241,241,241); + doc.setFillColor(241,241,241); + var x1 = layout.marginLeft - 12; + var y1 = GlobalY-layout.tablePadding; + + var w2 = 510 + 24; + var h2 = doc.internal.getFontSize()*3+layout.tablePadding*2; + + if (invoice.discount) { + h2 += doc.internal.getFontSize()*2; + } + if (invoice.tax_amount) { + h2 += doc.internal.getFontSize()*2; + } + + //doc.rect(x1, y1, w2, h2, 'FD'); + + doc.setFontSize(9); + displayNotesAndTerms(doc, layout, invoice, y); + y += displaySubtotals(doc, layout, invoice, y, layout.unitCostRight); + + + doc.setFontSize(10); + Msg = invoice.is_quote ? invoiceLabels.total : invoiceLabels.balance_due; + var TmpMsgX = layout.unitCostRight-(doc.getStringUnitWidth(Msg) * doc.internal.getFontSize()); + + doc.text(TmpMsgX, y, Msg); + + SetPdfColor('LightBlue', doc, 'primary'); + AmountText = formatMoney(invoice.balance_amount, currencyId); + headerLeft=layout.headerRight+400; + var AmountX = layout.lineTotalRight - (doc.getStringUnitWidth(AmountText) * doc.internal.getFontSize()); + doc.text(AmountX, y, AmountText); + + return doc; +} + + + + +function GetReportTemplate2(doc, invoice, layout) +{ + var GlobalY=0;//Y position of line at current page + + var client = invoice.client; + var account = invoice.account; + var currencyId = client.currency_id; + + layout.headerRight = 150; + layout.rowHeight = 15; + layout.headerTop = 125; + layout.tableTop = 300; + + doc.setLineWidth(0.5); + + if (NINJA.primaryColor) { + setDocHexFill(doc, NINJA.primaryColor); + setDocHexDraw(doc, NINJA.primaryColor); + } else { + doc.setFillColor(46,43,43); + } + + var x1 =0; + var y1 = 0; + var w2 = 595; + var h2 = 100; + doc.rect(x1, y1, w2, h2, 'FD'); + + + if (invoice.image) + { + var left = layout.headerRight - invoice.imageWidth; + doc.addImage(invoice.image, 'JPEG', layout.marginLeft, 30); + } + + Report2AddFooter(invoice,doc); + + doc.setFontSize(7); + doc.setFontType("bold"); + SetPdfColor('White',doc); + + displayAccount(doc, invoice, 300, layout.accountTop, layout); + + + var y = layout.accountTop; + var left = layout.marginLeft; + var headerY = layout.headerTop; + + SetPdfColor('GrayLogo',doc); //set black color + doc.setFontSize(7); + + //show left column + SetPdfColor('Black',doc); //set black color + doc.setFontType("normal"); + + //publish filled box + doc.setDrawColor(200,200,200); + + if (NINJA.secondaryColor) { + setDocHexFill(doc, NINJA.secondaryColor); + } else { + doc.setFillColor(54,164,152); + } + + GlobalY=190; + doc.setLineWidth(0.5); + + var BlockLenght=220; + var x1 =595-BlockLenght; + var y1 = GlobalY-12; + var w2 = BlockLenght; + var h2 = getInvoiceDetailsHeight(invoice, layout) + layout.tablePadding + 2; + + doc.rect(x1, y1, w2, h2, 'FD'); + + SetPdfColor('SomeGreen', doc, 'secondary'); + doc.setFontSize('14'); + doc.setFontType("bold"); + doc.text(50, GlobalY, (invoice.is_quote ? invoiceLabels.your_quote : invoiceLabels.your_invoice).toUpperCase()); + + + var z=GlobalY; + z=z+30; + + doc.setFontSize('8'); + SetPdfColor('Black',doc); + displayClient(doc, invoice, layout.marginLeft, z, layout); + + marginLeft2=395; + + //publish left side information + SetPdfColor('White',doc); + doc.setFontSize('8'); + var detailsHeight = displayInvoice(doc, invoice, marginLeft2, z-25, layout) + 75; + layout.tableTop = Math.max(layout.tableTop, layout.headerTop + detailsHeight + (2 * layout.tablePadding)); + + y=z+60; + x = GlobalY + 100; + doc.setFontType("bold"); + + doc.setFontSize(12); + doc.setFontType("bold"); + SetPdfColor('Black',doc); + displayInvoiceHeader(doc, invoice, layout); + + var y = displayInvoiceItems(doc, invoice, layout); + doc.setLineWidth(0.3); + displayNotesAndTerms(doc, layout, invoice, y); + y += displaySubtotals(doc, layout, invoice, y, layout.unitCostRight); + + doc.setFontType("bold"); + + doc.setFontSize(12); + x += doc.internal.getFontSize()*4; + Msg = invoice.is_quote ? invoiceLabels.total : invoiceLabels.balance_due; + var TmpMsgX = layout.unitCostRight-(doc.getStringUnitWidth(Msg) * doc.internal.getFontSize()); + + doc.text(TmpMsgX, y, Msg); + + //SetPdfColor('LightBlue',doc); + AmountText = formatMoney(invoice.balance_amount , currencyId); + headerLeft=layout.headerRight+400; + var AmountX = headerLeft - (doc.getStringUnitWidth(AmountText) * doc.internal.getFontSize()); + SetPdfColor('SomeGreen', doc, 'secondary'); + doc.text(AmountX, y, AmountText); + + return doc; +} + + +function Report2AddFooter (invoice,doc) +{ + doc.setLineWidth(0.5); + if (NINJA.primaryColor) { + setDocHexFill(doc, NINJA.primaryColor); + setDocHexDraw(doc, NINJA.primaryColor); + } else { + doc.setFillColor(46,43,43); + doc.setDrawColor(46,43,43); + } + + // return doc.setTextColor(240,240,240);//select color Custom Report GRAY Colour + var x1 = 0;//tableLeft-tablePadding ; + var y1 = 750; + var w2 = 596; + var h2 = 94;//doc.internal.getFontSize()*length+length*1.1;//+h;//+tablePadding; + + + doc.rect(x1, y1, w2, h2, 'FD'); + + if (!invoice.is_pro && logoImages.imageLogo2) + { + pageHeight=820; + var left = 250;//headerRight ; + y=pageHeight-logoImages.imageLogoHeight2; + var headerRight=370; + + var left = headerRight - logoImages.imageLogoWidth2; + doc.addImage(logoImages.imageLogo2, 'JPEG', left, y, logoImages.imageLogoWidth2, logoImages.imageLogoHeight2); + } +} + +function Report3AddFooter (invoice, account, doc, layout) +{ + + doc.setLineWidth(0.5); + + if (NINJA.primaryColor) { + setDocHexFill(doc, NINJA.primaryColor); + setDocHexDraw(doc, NINJA.primaryColor); + } else { + doc.setDrawColor(242,101,34); + doc.setFillColor(242,101,34); + } + + var x1 = 0;//tableLeft-tablePadding ; + var y1 = 750; + var w2 = 596; + var h2 = 94;//doc.internal.getFontSize()*length+length*1.1;//+h;//+tablePadding; + + doc.rect(x1, y1, w2, h2, 'FD'); + + if (!invoice.is_pro && logoImages.imageLogo3) + { + pageHeight=820; + // var left = 25;//250;//headerRight ; + y=pageHeight-logoImages.imageLogoHeight3; + //var headerRight=370; + + //var left = headerRight - invoice.imageLogoWidth3; + doc.addImage(logoImages.imageLogo3, 'JPEG', 40, y, logoImages.imageLogoWidth3, logoImages.imageLogoHeight3); + } + + doc.setFontSize(10); + var marginLeft = 340; + displayAccount(doc, invoice, marginLeft, 780, layout); +} + + + +function GetReportTemplate3(doc, invoice, layout) +{ + var client = invoice.client; + var account = invoice.account; + var currencyId = client.currency_id; + + layout.headerRight = 400; + layout.rowHeight = 15; + + + doc.setFontSize(7); + + Report3AddHeader(invoice, layout, doc); + + if (invoice.image) + { + y=130; + var left = layout.headerRight - invoice.imageWidth; + doc.addImage(invoice.image, 'JPEG', layout.marginLeft, y); + } + + Report3AddFooter (invoice, account, doc, layout); + + + SetPdfColor('White',doc); + doc.setFontSize('8'); + var detailsHeight = displayInvoice(doc, invoice, layout.headerRight, layout.accountTop-10, layout); + layout.headerTop = Math.max(layout.headerTop, detailsHeight + 50); + layout.tableTop = Math.max(layout.tableTop, detailsHeight + 150); + + SetPdfColor('Black',doc); //set black color + doc.setFontSize(7); + doc.setFontType("normal"); + displayClient(doc, invoice, layout.headerRight, layout.headerTop, layout); + + + + SetPdfColor('White',doc); + doc.setFontType('bold'); + + doc.setLineWidth(0.3); + if (NINJA.secondaryColor) { + setDocHexFill(doc, NINJA.secondaryColor); + setDocHexDraw(doc, NINJA.secondaryColor); + } else { + doc.setDrawColor(63,60,60); + doc.setFillColor(63,60,60); + } + + var left = layout.marginLeft - layout.tablePadding; + var top = layout.tableTop - layout.tablePadding; + var width = layout.marginRight - (2 * layout.tablePadding); + var height = 20; + doc.rect(left, top, width, height, 'FD'); + + + displayInvoiceHeader(doc, invoice, layout); + SetPdfColor('Black',doc); + var y = displayInvoiceItems(doc, invoice, layout); + + + var height1 = displayNotesAndTerms(doc, layout, invoice, y); + var height2 = displaySubtotals(doc, layout, invoice, y, layout.unitCostRight); + y += Math.max(height1, height2); + + + var left = layout.marginLeft - layout.tablePadding; + var top = y - layout.tablePadding; + var width = layout.marginRight - (2 * layout.tablePadding); + var height = 20; + if (NINJA.secondaryColor) { + setDocHexFill(doc, NINJA.secondaryColor); + setDocHexDraw(doc, NINJA.secondaryColor); + } else { + doc.setDrawColor(63,60,60); + doc.setFillColor(63,60,60); + } + doc.rect(left, top, width, height, 'FD'); + + doc.setFontType('bold'); + SetPdfColor('White', doc); + doc.setFontSize(12); + + var label = invoice.is_quote ? invoiceLabels.total : invoiceLabels.balance_due; + var labelX = layout.unitCostRight-(doc.getStringUnitWidth(label) * doc.internal.getFontSize()); + doc.text(labelX, y+2, label); + + + doc.setFontType('normal'); + var amount = formatMoney(invoice.balance_amount , currencyId); + headerLeft=layout.headerRight+400; + var amountX = layout.lineTotalRight - (doc.getStringUnitWidth(amount) * doc.internal.getFontSize()); + doc.text(amountX, y+2, amount); + + return doc; +} + + + + +function Report3AddHeader (invoice, layout, doc) +{ + doc.setLineWidth(0.5); + + if (NINJA.primaryColor) { + setDocHexFill(doc, NINJA.primaryColor); + setDocHexDraw(doc, NINJA.primaryColor); + } else { + doc.setDrawColor(242,101,34); + doc.setFillColor(242,101,34); + } + + var x1 =0; + var y1 = 0; + var w2 = 595; + var h2 = Math.max(110, getInvoiceDetailsHeight(invoice, layout) + 30); + doc.rect(x1, y1, w2, h2, 'FD'); + + SetPdfColor('White',doc); + + //second column + doc.setFontType('bold'); + var name = invoice.account.name; + if (name) { + doc.setFontSize('30'); + doc.setFontType('bold'); + doc.text(40, 50, name); + } +} + + +function Report1AddNewPage(invoice,account,doc) +{ + doc.addPage(); + if (logoImages.imageLogo1) + { + pageHeight=820; + y=pageHeight-logoImages.imageLogoHeight1; + var left = 20;//headerRight - invoice.imageLogoWidth1; + doc.addImage(logoImages.imageLogo1, 'JPEG', left, y, logoImages.imageLogoWidth1, logoImages.imageLogoHeight1); + + } + + GlobalY = 40; + return GlobalY; +} + + + + +function GetReportTemplate4(doc, invoice, layout) { var client = invoice.client; var account = invoice.account; @@ -54,29 +590,10 @@ function GetReportTemplate4(doc, invoice, layout, checkMath) { doc.setFontSize(10); - /* table footer */ - /* - doc.setDrawColor(200,200,200); - doc.setLineWidth(1); - doc.line(layout.marginLeft - layout.tablePadding, x, layout.lineTotalRight+layout.tablePadding, x); - */ - displayNotesAndTerms(doc, layout, invoice, y+20); y += displaySubtotals(doc, layout, invoice, y+20, 480) + 20; - /* - if (checkMath && NINJA.parseFloat(total).toFixed(4) != NINJA.parseFloat(invoice.amount).toFixed(4)) - { - var doc = new jsPDF('p', 'pt'); - doc.setFont('Helvetica',''); - doc.setFontSize(10); - doc.text(100, 100, "An error occurred, please try again later."); - onerror('Failed to generate PDF ' + total + ', ' + invoice.amount ); - return doc; - } - */ - doc.setDrawColor(200,200,200); doc.setFillColor(230,230,230); @@ -102,26 +619,51 @@ function GetReportTemplate4(doc, invoice, layout, checkMath) { } -var invoiceOld; -function generatePDF(invoice, force) { - invoice = calculateAmounts(invoice); - var a = copyInvoice(invoice); - var b = copyInvoice(invoiceOld); - if (!force && _.isEqual(a, b)) { - return; +function SetPdfColor(color, doc, role) +{ + if (role === 'primary' && NINJA.primaryColor) { + return setDocHexColor(doc, NINJA.primaryColor); + } else if (role === 'secondary' && NINJA.secondaryColor) { + return setDocHexColor(doc, NINJA.secondaryColor); } - invoiceOld = invoice; - report_id = invoice.invoice_design_id; - doc = GetPdf(invoice, false, report_id); - return doc; + + if (color=='LightBlue') { + return doc.setTextColor(41,156, 194); + } + + if (color=='Black') { + return doc.setTextColor(46,43,43);//select color black + } + if (color=='GrayLogo') { + return doc.setTextColor(207,241, 241);//select color Custom Report GRAY + } + + if (color=='GrayBackground') { + return doc.setTextColor(251,251, 251);//select color Custom Report GRAY + } + + if (color=='GrayText') { + return doc.setTextColor(161,160,160);//select color Custom Report GRAY Colour + } + + if (color=='White') { + return doc.setTextColor(255,255,255);//select color Custom Report GRAY Colour + } + + if (color=='SomeGreen') { + return doc.setTextColor(54,164,152);//select color Custom Report GRAY Colour + } + + if (color=='LightGrayReport2-gray') { + return doc.setTextColor(240,240,240);//select color Custom Report GRAY Colour + } + + if (color=='LightGrayReport2-white') { + return doc.setTextColor(251,251,251);//select color Custom Report GRAY Colour + } + } -function copyInvoice(orig) { - if (!orig) return false; - var copy = JSON.stringify(orig); - var copy = JSON.parse(copy); - return copy; -} /* Handle converting variables in the invoices (ie, MONTH+1) */ function processVariables(str) { @@ -574,7 +1116,7 @@ function populateInvoiceComboboxes(clientId, invoiceId) { var client = clientMap[invoice.client.public_id]; setComboboxValue($('.client-select'), client.public_id, getClientDisplayName(client)); if (!parseFloat($('#amount').val())) { - $('#amount').val(formatMoney(invoice.balance, invoice.currency_id, true)); + $('#amount').val(parseFloat(invoice.balance).toFixed(2)); } } }); @@ -610,629 +1152,7 @@ $.fn.datepicker.defaults.todayHighlight = true; -//==================================================================================================================== -function GetPdf(invoice,checkMath,report_id){ - var layout = { - accountTop: 40, - marginLeft: 50, - marginRight: 550, - headerTop: 150, - headerLeft: 360, - headerRight: 550, - rowHeight: 15, - tableRowHeight: 10, - footerLeft: 420, - tablePadding: 12, - tableTop: 250, - descriptionLeft: 162, - unitCostRight: 410, - qtyRight: 480, - taxRight: 480, - lineTotalRight: 550 - }; - - if (invoice.has_taxes) - { - layout.descriptionLeft -= 20; - layout.unitCostRight -= 40; - layout.qtyRight -= 40; - } - - /* - @param orientation One of "portrait" or "landscape" (or shortcuts "p" (Default), "l") - @param unit Measurement unit to be used when coordinates are specified. One of "pt" (points), "mm" (Default), "cm", "in" - @param format One of 'a3', 'a4' (Default),'a5' ,'letter' ,'legal' - @returns {jsPDF} - */ - var doc = new jsPDF('portrait', 'pt', 'a4'); - - - //Set PDF properities - doc.setProperties({ - title: 'Invoice ' + invoice.invoice_number, - subject: '', - author: 'InvoiceNinja.com', - keywords: 'pdf, invoice', - creator: 'InvoiceNinja.com' - }); - - //set default style for report - doc.setFont('Helvetica',''); - - if (report_id==1) { - return GetReportTemplate1(doc, invoice, layout, checkMath); - } else if (report_id==2) { - return GetReportTemplate2(doc, invoice, layout, checkMath); - } else if (report_id==3) { - return GetReportTemplate3(doc, invoice, layout, checkMath); - } else { - return GetReportTemplate4(doc, invoice, layout, checkMath); - } -} - -function GetReportTemplate1(doc, invoice, layout, checkMath) -{ - var GlobalY=0;//Y position of line at current page - - var client = invoice.client; - var account = invoice.account; - var currencyId = client.currency_id; - - layout.headerRight = 550; - layout.rowHeight = 15; - - doc.setFontSize(9); - - if (invoice.image) - { - var left = layout.headerRight - invoice.imageWidth; - doc.addImage(invoice.image, 'JPEG', layout.marginLeft, 30); - } - - if (!invoice.is_pro && logoImages.imageLogo1) - { - pageHeight=820; - y=pageHeight-logoImages.imageLogoHeight1; - doc.addImage(logoImages.imageLogo1, 'JPEG', layout.marginLeft, y, logoImages.imageLogoWidth1, logoImages.imageLogoHeight1); - } - - doc.setFontSize(9); - SetPdfColor('LightBlue', doc, 'primary'); - displayAccount(doc, invoice, 220, layout.accountTop, layout); - - SetPdfColor('LightBlue', doc, 'primary'); - doc.setFontSize('11'); - doc.text(50, layout.headerTop, (invoice.is_quote ? invoiceLabels.quote : invoiceLabels.invoice).toUpperCase()); - - //doc.setDrawColor(220,220,220); - //doc.line(30, y, 560, y); // horizontal line - - - SetPdfColor('Black',doc); //set black color - doc.setFontSize(9); - - var invoiceHeight = displayInvoice(doc, invoice, 50, 170, layout); - var clientHeight = displayClient(doc, invoice, 220, 170, layout); - var detailsHeight = Math.max(invoiceHeight, clientHeight); - layout.tableTop = Math.max(layout.tableTop, layout.headerTop + detailsHeight + (3 * layout.rowHeight)); - - - - doc.setLineWidth(0.3); - doc.setDrawColor(200,200,200); - doc.line(layout.marginLeft - layout.tablePadding, layout.headerTop + 6, layout.marginRight + layout.tablePadding, layout.headerTop + 6); - doc.line(layout.marginLeft - layout.tablePadding, layout.headerTop + detailsHeight + 14, layout.marginRight + layout.tablePadding, layout.headerTop + detailsHeight + 14); - - - //doc.setDrawColor(220,220,220); - //doc.line(30, y-8, 560, y-8); // horizontal line - - - doc.setFontSize(10); - doc.setFontType("bold"); - displayInvoiceHeader(doc, invoice, layout); - var y = displayInvoiceItems(doc, invoice, layout); - - //doc.setFontType("normal"); - doc.setFontSize(9); - - doc.setFontType("bold"); - - GlobalY=GlobalY+25; - - - doc.setLineWidth(0.3); - doc.setDrawColor(241,241,241); - doc.setFillColor(241,241,241); - var x1 = layout.marginLeft - 12; - var y1 = GlobalY-layout.tablePadding; - - var w2 = 510 + 24; - var h2 = doc.internal.getFontSize()*3+layout.tablePadding*2; - - if (invoice.discount) { - h2 += doc.internal.getFontSize()*2; - } - if (invoice.tax_amount) { - h2 += doc.internal.getFontSize()*2; - } - - //doc.rect(x1, y1, w2, h2, 'FD'); - - doc.setFontSize(9); - displayNotesAndTerms(doc, layout, invoice, y); - y += displaySubtotals(doc, layout, invoice, y, layout.unitCostRight); - - - doc.setFontSize(10); - Msg = invoice.is_quote ? invoiceLabels.total : invoiceLabels.balance_due; - var TmpMsgX = layout.unitCostRight-(doc.getStringUnitWidth(Msg) * doc.internal.getFontSize()); - - doc.text(TmpMsgX, y, Msg); - - SetPdfColor('LightBlue', doc, 'primary'); - AmountText = formatMoney(invoice.balance_amount, currencyId); - headerLeft=layout.headerRight+400; - var AmountX = layout.lineTotalRight - (doc.getStringUnitWidth(AmountText) * doc.internal.getFontSize()); - doc.text(AmountX, y, AmountText); - - return doc; -} - - - - -function GetReportTemplate2(doc, invoice, layout, checkMath) -{ - var GlobalY=0;//Y position of line at current page - - var client = invoice.client; - var account = invoice.account; - var currencyId = client.currency_id; - - layout.headerRight = 150; - layout.rowHeight = 15; - layout.headerTop = 125; - layout.tableTop = 300; - - doc.setLineWidth(0.5); - - if (NINJA.primaryColor) { - setDocHexFill(doc, NINJA.primaryColor); - setDocHexDraw(doc, NINJA.primaryColor); - } else { - doc.setFillColor(46,43,43); - } - - var x1 =0; - var y1 = 0; - var w2 = 595; - var h2 = 100; - doc.rect(x1, y1, w2, h2, 'FD'); - - - if (invoice.image) - { - var left = layout.headerRight - invoice.imageWidth; - doc.addImage(invoice.image, 'JPEG', layout.marginLeft, 30); - } - - Report2AddFooter (invoice,doc); - - - doc.setFontSize(7); - doc.setFontType("bold"); - SetPdfColor('White',doc); - - displayAccount(doc, invoice, 300, layout.accountTop, layout); - - /* - var spacer = ' '; - var line1 = account.name + spacer + account.work_email + spacer + account.work_phone; - var lineWidth = doc.getStringUnitWidth(line1) * doc.internal.getFontSize(); - var nameWidth = doc.getStringUnitWidth(account.name + spacer) * doc.internal.getFontSize(); - var nameX = lineTotalRight - lineWidth; - var detailsX = lineTotalRight - (lineWidth - nameWidth); - - doc.text(nameX, accountTop, account.name); - doc.setFontType("normal"); - doc.text(detailsX, accountTop, account.work_email + spacer + account.work_phone); - - var line2 = concatStrings(account.address1, account.address2) + spacer + concatStrings(account.city, account.state, account.postal_code); - var lineWidth = doc.getStringUnitWidth(line2) * doc.internal.getFontSize(); - var line2X = lineTotalRight - lineWidth; - - doc.text(line2X, accountTop + 16, line2); - */ - -//-----------------------------Publish Client Details block-------------------------------------------- - - var y = layout.accountTop; - var left = layout.marginLeft; - - var headerY = layout.headerTop; - - - - SetPdfColor('GrayLogo',doc); //set black color - - - doc.setFontSize(7); - - //show left column - SetPdfColor('Black',doc); //set black color - doc.setFontType("normal"); - - - //publish filled box - doc.setDrawColor(200,200,200); - - if (NINJA.secondaryColor) { - setDocHexFill(doc, NINJA.secondaryColor); - } else { - doc.setFillColor(54,164,152); - } - - GlobalY=190; - doc.setLineWidth(0.5); - - var BlockLenght=220; - var x1 =595-BlockLenght; - var y1 = GlobalY-12; - var w2 = BlockLenght; - var h2 = getInvoiceDetailsHeight(invoice, layout) + layout.tablePadding + 2; - - doc.rect(x1, y1, w2, h2, 'FD'); - - - SetPdfColor('SomeGreen', doc, 'secondary'); - doc.setFontSize('14'); - doc.setFontType("bold"); - doc.text(50, GlobalY, (invoice.is_quote ? invoiceLabels.your_quote : invoiceLabels.your_invoice).toUpperCase()); - - - var z=GlobalY; - z=z+30; - - - doc.setFontSize('8'); - SetPdfColor('Black',doc); - displayClient(doc, invoice, layout.marginLeft, z, layout); - - - marginLeft2=395; - - //publish left side information - - SetPdfColor('White',doc); - doc.setFontSize('8'); - var detailsHeight = displayInvoice(doc, invoice, marginLeft2, z-25, layout) + 75; - layout.tableTop = Math.max(layout.tableTop, layout.headerTop + detailsHeight + (2 * layout.tablePadding)); - - y=z+60; - - - x = GlobalY + 100; - - doc.setFontType("bold"); - - - - doc.setFontSize(12); - doc.setFontType("bold"); - SetPdfColor('Black',doc); - displayInvoiceHeader(doc, invoice, layout); - var y = displayInvoiceItems(doc, invoice, layout); - - //GlobalY=600; - - doc.setLineWidth(0.3); - - /* - doc.setDrawColor(251,251,251); - doc.setFillColor(251,251,251); - var x1 = layout.marginLeft-layout.tablePadding*2 +14; - var y1 = GlobalY-layout.tablePadding; - var w2 = 510+layout.tablePadding*2;//lineTotalRight-tablePadding*5; - var h2 = doc.internal.getFontSize()*3+layout.tablePadding*2; - doc.rect(x1, y1, w2, h2, 'FD'); - */ - - displayNotesAndTerms(doc, layout, invoice, y); - y += displaySubtotals(doc, layout, invoice, y, layout.unitCostRight); - - doc.setFontType("bold"); - - doc.setFontSize(12); - x += doc.internal.getFontSize()*4; - Msg = invoice.is_quote ? invoiceLabels.total : invoiceLabels.balance_due; - var TmpMsgX = layout.unitCostRight-(doc.getStringUnitWidth(Msg) * doc.internal.getFontSize()); - - - - doc.text(TmpMsgX, y, Msg); - - - //SetPdfColor('LightBlue',doc); - AmountText = formatMoney(invoice.balance_amount , currencyId); - headerLeft=layout.headerRight+400; - var AmountX = headerLeft - (doc.getStringUnitWidth(AmountText) * doc.internal.getFontSize()); - SetPdfColor('SomeGreen', doc, 'secondary'); - doc.text(AmountX, y, AmountText); - - return doc; -} - - - - - - - -function SetPdfColor(color, doc, role) -{ - if (role === 'primary' && NINJA.primaryColor) { - return setDocHexColor(doc, NINJA.primaryColor); - } else if (role === 'secondary' && NINJA.secondaryColor) { - return setDocHexColor(doc, NINJA.secondaryColor); - } - - if (color=='LightBlue') { - return doc.setTextColor(41,156, 194); - } - - if (color=='Black') { - return doc.setTextColor(46,43,43);//select color black - } - if (color=='GrayLogo') { - return doc.setTextColor(207,241, 241);//select color Custom Report GRAY - } - - if (color=='GrayBackground') { - return doc.setTextColor(251,251, 251);//select color Custom Report GRAY - } - - if (color=='GrayText') { - return doc.setTextColor(161,160,160);//select color Custom Report GRAY Colour - } - - if (color=='White') { - return doc.setTextColor(255,255,255);//select color Custom Report GRAY Colour - } - - if (color=='SomeGreen') { - return doc.setTextColor(54,164,152);//select color Custom Report GRAY Colour - } - - if (color=='LightGrayReport2-gray') { - return doc.setTextColor(240,240,240);//select color Custom Report GRAY Colour - } - - if (color=='LightGrayReport2-white') { - return doc.setTextColor(251,251,251);//select color Custom Report GRAY Colour - } - -} - -function Report2AddFooter (invoice,doc) -{ - doc.setLineWidth(0.5); - if (NINJA.primaryColor) { - setDocHexFill(doc, NINJA.primaryColor); - setDocHexDraw(doc, NINJA.primaryColor); - } else { - doc.setFillColor(46,43,43); - doc.setDrawColor(46,43,43); - } - - // return doc.setTextColor(240,240,240);//select color Custom Report GRAY Colour - var x1 = 0;//tableLeft-tablePadding ; - var y1 = 750; - var w2 = 596; - var h2 = 94;//doc.internal.getFontSize()*length+length*1.1;//+h;//+tablePadding; - - - doc.rect(x1, y1, w2, h2, 'FD'); - - if (!invoice.is_pro && logoImages.imageLogo2) - { - pageHeight=820; - var left = 250;//headerRight ; - y=pageHeight-logoImages.imageLogoHeight2; - var headerRight=370; - - var left = headerRight - logoImages.imageLogoWidth2; - doc.addImage(logoImages.imageLogo2, 'JPEG', left, y, logoImages.imageLogoWidth2, logoImages.imageLogoHeight2); - } -} - -function Report3AddFooter (invoice, account, doc, layout) -{ - - doc.setLineWidth(0.5); - - if (NINJA.primaryColor) { - setDocHexFill(doc, NINJA.primaryColor); - setDocHexDraw(doc, NINJA.primaryColor); - } else { - doc.setDrawColor(242,101,34); - doc.setFillColor(242,101,34); - } - - var x1 = 0;//tableLeft-tablePadding ; - var y1 = 750; - var w2 = 596; - var h2 = 94;//doc.internal.getFontSize()*length+length*1.1;//+h;//+tablePadding; - - doc.rect(x1, y1, w2, h2, 'FD'); - - if (!invoice.is_pro && logoImages.imageLogo3) - { - pageHeight=820; - // var left = 25;//250;//headerRight ; - y=pageHeight-logoImages.imageLogoHeight3; - //var headerRight=370; - - //var left = headerRight - invoice.imageLogoWidth3; - doc.addImage(logoImages.imageLogo3, 'JPEG', 40, y, logoImages.imageLogoWidth3, logoImages.imageLogoHeight3); - } - - doc.setFontSize(10); - var marginLeft = 340; - displayAccount(doc, invoice, marginLeft, 780, layout); -} - - - -function GetReportTemplate3(doc, invoice, layout, checkMath) -{ - var client = invoice.client; - var account = invoice.account; - var currencyId = client.currency_id; - - layout.headerRight = 400; - layout.rowHeight = 15; - - - doc.setFontSize(7); - - Report3AddHeader(invoice, layout, doc); - - if (invoice.image) - { - y=130; - var left = layout.headerRight - invoice.imageWidth; - doc.addImage(invoice.image, 'JPEG', layout.marginLeft, y); - } - - Report3AddFooter (invoice, account, doc, layout); - - - SetPdfColor('White',doc); - doc.setFontSize('8'); - var detailsHeight = displayInvoice(doc, invoice, layout.headerRight, layout.accountTop-10, layout); - layout.headerTop = Math.max(layout.headerTop, detailsHeight + 50); - layout.tableTop = Math.max(layout.tableTop, detailsHeight + 150); - - SetPdfColor('Black',doc); //set black color - doc.setFontSize(7); - doc.setFontType("normal"); - displayClient(doc, invoice, layout.headerRight, layout.headerTop, layout); - - - - SetPdfColor('White',doc); - doc.setFontType('bold'); - - doc.setLineWidth(0.3); - if (NINJA.secondaryColor) { - setDocHexFill(doc, NINJA.secondaryColor); - setDocHexDraw(doc, NINJA.secondaryColor); - } else { - doc.setDrawColor(63,60,60); - doc.setFillColor(63,60,60); - } - - var left = layout.marginLeft - layout.tablePadding; - var top = layout.tableTop - layout.tablePadding; - var width = layout.marginRight - (2 * layout.tablePadding); - var height = 20; - doc.rect(left, top, width, height, 'FD'); - - - displayInvoiceHeader(doc, invoice, layout); - SetPdfColor('Black',doc); - var y = displayInvoiceItems(doc, invoice, layout); - - - var height1 = displayNotesAndTerms(doc, layout, invoice, y); - var height2 = displaySubtotals(doc, layout, invoice, y, layout.unitCostRight); - y += Math.max(height1, height2); - - - var left = layout.marginLeft - layout.tablePadding; - var top = y - layout.tablePadding; - var width = layout.marginRight - (2 * layout.tablePadding); - var height = 20; - if (NINJA.secondaryColor) { - setDocHexFill(doc, NINJA.secondaryColor); - setDocHexDraw(doc, NINJA.secondaryColor); - } else { - doc.setDrawColor(63,60,60); - doc.setFillColor(63,60,60); - } - doc.rect(left, top, width, height, 'FD'); - - doc.setFontType('bold'); - SetPdfColor('White', doc); - doc.setFontSize(12); - - var label = invoice.is_quote ? invoiceLabels.total : invoiceLabels.balance_due; - var labelX = layout.unitCostRight-(doc.getStringUnitWidth(label) * doc.internal.getFontSize()); - doc.text(labelX, y+2, label); - - - doc.setFontType('normal'); - var amount = formatMoney(invoice.balance_amount , currencyId); - headerLeft=layout.headerRight+400; - var amountX = layout.lineTotalRight - (doc.getStringUnitWidth(amount) * doc.internal.getFontSize()); - doc.text(amountX, y+2, amount); - - return doc; -} - - - - -function Report3AddHeader (invoice, layout, doc) -{ - doc.setLineWidth(0.5); - - if (NINJA.primaryColor) { - setDocHexFill(doc, NINJA.primaryColor); - setDocHexDraw(doc, NINJA.primaryColor); - } else { - doc.setDrawColor(242,101,34); - doc.setFillColor(242,101,34); - } - - var x1 =0; - var y1 = 0; - var w2 = 595; - var h2 = Math.max(110, getInvoiceDetailsHeight(invoice, layout) + 30); - doc.rect(x1, y1, w2, h2, 'FD'); - - SetPdfColor('White',doc); - - //second column - doc.setFontType('bold'); - var MaxWidth=594; - var LineOne= invoice.account.name; - var AlignLine = MaxWidth-30- (doc.getStringUnitWidth(LineOne) * doc.internal.getFontSize()); - if (LineOne) { - doc.setFontSize('30'); - doc.setFontType('bold'); - doc.text(40, 50, LineOne); - } -} - - -function Report1AddNewPage(invoice,account,doc) -{ - doc.addPage(); - if (logoImages.imageLogo1) - { - pageHeight=820; - y=pageHeight-logoImages.imageLogoHeight1; - var left = 20;//headerRight - invoice.imageLogoWidth1; - doc.addImage(logoImages.imageLogo1, 'JPEG', left, y, logoImages.imageLogoWidth1, logoImages.imageLogoHeight1); - - } - - GlobalY = 40; - return GlobalY; -} function displayAccount(doc, invoice, x, y, layout) { var account = invoice.account; @@ -1247,7 +1167,7 @@ function displayAccount(doc, invoice, x, y, layout) { account.work_phone ]; - displayGrid(doc, invoice, data, x, y, layout, true); + displayGrid(doc, invoice, data, x, y, layout, {hasHeader:true}); data = [ concatStrings(account.address1, account.address2), @@ -1278,7 +1198,7 @@ function displayClient(doc, invoice, x, y, layout) { client.contacts[0].email ]; - return displayGrid(doc, invoice, data, x, y, layout, true); + return displayGrid(doc, invoice, data, x, y, layout, {hasheader:true}); } function displayInvoice(doc, invoice, x, y, layout, rightAlignX) { @@ -1287,7 +1207,12 @@ function displayInvoice(doc, invoice, x, y, layout, rightAlignX) { } var data = getInvoiceDetails(invoice); - return displayGrid(doc, invoice, data, x, y, layout, true, rightAlignX); + var options = { + hasheader: true, + rightAlignX: rightAlignX, + }; + + return displayGrid(doc, invoice, data, x, y, layout, options); } function getInvoiceDetails(invoice) { @@ -1356,7 +1281,13 @@ function displaySubtotals(doc, layout, invoice, y, rightAlignTitleX) data.push({'paid_to_date': formatMoney(paid, invoice.client.currency_id)}); } - return displayGrid(doc, invoice, data, 300, y, layout, true, 550, rightAlignTitleX) + 10; + var options = { + hasheader: true, + rightAlignX: 550, + rightAlignTitleX: rightAlignTitleX + }; + + return displayGrid(doc, invoice, data, 300, y, layout, options) + 10; } function concatStrings() { @@ -1379,7 +1310,8 @@ function concatStrings() { return data.length ? concatStr : false; } -function displayGrid(doc, invoice, data, x, y, layout, hasheader, rightAlignX, rightAlignTitleX) { +//function displayGrid(doc, invoice, data, x, y, layout, hasheader, rightAlignX, rightAlignTitleX) { +function displayGrid(doc, invoice, data, x, y, layout, options) { var numLines = 0; var origY = y; for (var i=0; i