1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 12:12:48 +01:00

Working on invoice design page

This commit is contained in:
Hillel Coren 2014-10-12 21:11:41 +03:00
parent 4f3e9ee935
commit 9770e6a1d5
17 changed files with 805 additions and 1326 deletions

View File

@ -38,6 +38,16 @@ module.exports = function(grunt) {
dest: 'public/built.js',
nonull: true
},
js_public: {
src: [
'public/js/simpleexpand.js',
'public/js/valign.js',
'public/js/bootstrap.min.js',
'public/js/simpleexpand.js',
],
dest: 'public/js/built.public.js',
nonull: true
},
css: {
src: [
'public/vendor/bootstrap/dist/css/bootstrap.min.css',

View File

@ -251,6 +251,30 @@ class AccountController extends \BaseController {
'feature' => $subSection
];
if ($subSection == ACCOUNT_INVOICE_DESIGN)
{
$invoice = new stdClass();
$client = new stdClass();
$invoiceItem = new stdClass();
$client->name = 'Sample Client';
$invoice->invoice_date = date_create()->format('Y-m-d');
$invoice->account = Auth::user()->account;
$invoice->amount = $invoice->balance = 100;
$invoiceItem->cost = 100;
$invoiceItem->qty = 1;
$invoiceItem->notes = 'Notes';
$invoiceItem->product_key = 'Item';
$invoice->client = $client;
$invoice->invoice_items = [$invoiceItem];
$data['invoice'] = $invoice;
$data['invoiceDesigns'] = InvoiceDesign::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get();
}
return View::make("accounts.{$subSection}", $data);
}
else if ($section == ACCOUNT_PRODUCTS)
@ -348,8 +372,9 @@ class AccountController extends \BaseController {
$account = Auth::user()->account;
$account->hide_quantity = Input::get('hide_quantity') ? true : false;
$account->hide_paid_to_date = Input::get('hide_paid_to_date') ? true : false;
$account->primary_color = Input::get('primary_color');// ? Input::get('primary_color') : null;
$account->secondary_color = Input::get('secondary_color');// ? Input::get('secondary_color') : null;
$account->primary_color = Input::get('primary_color');
$account->secondary_color = Input::get('secondary_color');
$account->invoice_design_id = Input::get('invoice_design_id');
$account->save();
Session::flash('message', trans('texts.updated_settings'));

View File

@ -104,7 +104,7 @@ class InvoiceController extends \BaseController {
}
}
$invoice->load('user', 'invoice_items', 'account.country', 'client.contacts', 'client.country');
$invoice->load('user', 'invoice_items', 'invoice_design', 'account.country', 'client.contacts', 'client.country');
$client = $invoice->client;
@ -244,7 +244,6 @@ class InvoiceController extends \BaseController {
'paymentTerms' => PaymentTerm::remember(DEFAULT_QUERY_CACHE)->orderBy('num_days')->get(['name', 'num_days']),
'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
'invoiceDesigns' => InvoiceDesign::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
'invoiceLabels' => Auth::user()->account->getInvoiceLabels(),
'frequencies' => array(
1 => 'Weekly',
2 => 'Two weeks',

View File

@ -0,0 +1,515 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddInvoiceDesignTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('invoice_designs', function($table)
{
$table->text('javascript')->nullable();
});
Schema::table('accounts', function($table)
{
$table->text('invoice_design')->nullable();
});
DB::table('invoice_designs')->where('id', 1)->update([
'javascript' => "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);"
]);
DB::table('invoice_designs')->where('id', 2)->update([
'javascript' => " 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);
}
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);
}
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);"
]);
DB::table('invoice_designs')->where('id', 3)->update([
'javascript' => " var client = invoice.client;
var account = invoice.account;
var currencyId = client.currency_id;
layout.headerRight = 400;
layout.rowHeight = 15;
doc.setFontSize(7);
// add header
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);
}
if (invoice.image)
{
y=130;
var left = layout.headerRight - invoice.imageWidth;
doc.addImage(invoice.image, 'JPEG', layout.marginLeft, y);
}
// add footer
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);
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);"
]);
DB::table('invoice_designs')->where('id', 4)->update([
'javascript' => " var client = invoice.client;
var account = invoice.account;
var currencyId = client.currency_id;
if (invoice.image)
{
var left = layout.headerRight - invoice.imageWidth;
doc.addImage(invoice.image, 'JPEG', left, 30);
}
/* table header */
doc.setDrawColor(200,200,200);
doc.setFillColor(230,230,230);
var detailsHeight = getInvoiceDetailsHeight(invoice, layout);
var left = layout.headerLeft - layout.tablePadding;
var top = layout.headerTop + detailsHeight - layout.rowHeight - layout.tablePadding;
var width = layout.headerRight - layout.headerLeft + (2 * layout.tablePadding);
var height = layout.rowHeight + 1;
doc.rect(left, top, width, height, 'FD');
doc.setFontSize(10);
doc.setFontType('normal');
displayAccount(doc, invoice, layout.marginLeft, layout.accountTop, layout);
displayClient(doc, invoice, layout.marginLeft, layout.headerTop, layout);
displayInvoice(doc, invoice, layout.headerLeft, layout.headerTop, layout, layout.headerRight);
layout.tableTop = Math.max(layout.tableTop, layout.headerTop + detailsHeight + (2 * layout.tablePadding));
var headerY = layout.headerTop;
var total = 0;
doc.setDrawColor(200,200,200);
doc.setFillColor(230,230,230);
var left = layout.marginLeft - layout.tablePadding;
var top = layout.tableTop - layout.tablePadding;
var width = layout.headerRight - layout.marginLeft + (2 * layout.tablePadding);
var height = layout.rowHeight + 2;
doc.rect(left, top, width, height, 'FD');
displayInvoiceHeader(doc, invoice, layout);
var y = displayInvoiceItems(doc, invoice, layout);
doc.setFontSize(10);
displayNotesAndTerms(doc, layout, invoice, y+20);
y += displaySubtotals(doc, layout, invoice, y+20, 480) + 20;
doc.setDrawColor(200,200,200);
doc.setFillColor(230,230,230);
var left = layout.footerLeft - layout.tablePadding;
var top = y - layout.tablePadding;
var width = layout.headerRight - layout.footerLeft + (2 * layout.tablePadding);
var height = layout.rowHeight + 2;
doc.rect(left, top, width, height, 'FD');
doc.setFontType('bold');
doc.text(layout.footerLeft, y, invoice.is_quote ? invoiceLabels.total : invoiceLabels.balance_due);
total = formatMoney(invoice.balance_amount, currencyId);
var totalX = layout.headerRight - (doc.getStringUnitWidth(total) * doc.internal.getFontSize());
doc.text(totalX, y, total);
if (!invoice.is_pro) {
doc.setFontType('normal');
doc.text(layout.marginLeft, 790, 'Created by InvoiceNinja.com');
}"
]);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('invoice_designs', function($table)
{
$table->dropColumn('javascript');
});
Schema::table('accounts', function($table)
{
$table->dropColumn('invoice_design');
});
}
}

View File

@ -27,6 +27,11 @@ class Invoice extends EntityModel
return $this->belongsTo('InvoiceStatus');
}
public function invoice_design()
{
return $this->belongsTo('InvoiceDesign');
}
public function invitations()
{
return $this->hasMany('Invitation');
@ -79,6 +84,7 @@ class Invoice extends EntityModel
'tax_name',
'tax_rate',
'account',
'invoice_design',
'invoice_design_id',
'is_pro',
'is_quote',

View File

@ -1,48 +1,102 @@
@extends('accounts.nav')
@section('head')
@parent
<script src="{{ asset('js/pdf_viewer.js') }}" type="text/javascript"></script>
<script src="{{ asset('js/compatibility.js') }}" type="text/javascript"></script>
@stop
@section('content')
@parent
@include('accounts.nav_advanced')
{{ Former::open()->addClass('col-md-8 col-md-offset-2 warn-on-exit') }}
{{ Former::populate($account) }}
{{ Former::populateField('hide_quantity', intval($account->hide_quantity)) }}
{{ Former::populateField('hide_paid_to_date', intval($account->hide_paid_to_date)) }}
<div class="row">
<div class="col-md-6">
{{ Former::legend('invoice_options') }}
{{ Former::checkbox('hide_quantity')->text(trans('texts.hide_quantity_help')) }}
{{ Former::checkbox('hide_paid_to_date')->text(trans('texts.hide_paid_to_date_help')) }}
<p>&nbsp;</p>
{{ Former::open()->addClass('warn-on-exit')->onchange('refreshPDF()') }}
{{ Former::populate($account) }}
{{ Former::populateField('hide_quantity', intval($account->hide_quantity)) }}
{{ Former::populateField('hide_paid_to_date', intval($account->hide_paid_to_date)) }}
{{ Former::legend('invoice_design') }}
{{ Former::text('primary_color') }}
{{ Former::text('secondary_color') }}
{{ Former::legend('invoice_options') }}
{{ Former::checkbox('hide_quantity')->text(trans('texts.hide_quantity_help')) }}
{{ Former::checkbox('hide_paid_to_date')->text(trans('texts.hide_paid_to_date_help')) }}
@if (Auth::user()->isPro())
{{ Former::actions( Button::lg_success_submit(trans('texts.save'))->append_with_icon('floppy-disk') ) }}
@else
<script>
$(function() {
$('form.warn-on-exit input').prop('disabled', true);
});
</script>
@endif
<p>&nbsp;</p>
<p>&nbsp;</p>
{{ Former::legend('invoice_design') }}
{{ Former::select('invoice_design_id')->style('display:inline;width:120px')
->fromQuery($invoiceDesigns, 'name', 'id') }}
{{ Former::text('primary_color') }}
{{ Former::text('secondary_color') }}
<p>&nbsp;</p>
<p>&nbsp;</p>
@if (Auth::user()->isPro())
{{ Former::actions( Button::lg_success_submit(trans('texts.save'))->append_with_icon('floppy-disk') ) }}
@else
<script>
$(function() {
$('form.warn-on-exit input').prop('disabled', true);
});
</script>
@endif
{{ Former::close() }}
</div>
<div class="col-md-6">
@include('invoices.pdf', ['account' => Auth::user()->account, 'pdfHeight' => 800])
</div>
</div>
{{ Former::close() }}
<script>
$(function() {
var options = {
preferredFormat: "hex",
disabled: {{ Auth::user()->isPro() ? 'false' : 'true' }},
showInitial: false,
showInput: true,
allowEmpty: true,
clickoutFiresChange: true,
};
$('#primary_color').spectrum(options);
$('#secondary_color').spectrum(options);
});
var invoiceDesigns = {{ $invoiceDesigns }};
function getDesignJavascript() {
var id = $('#invoice_design_id').val();
return invoiceDesigns[id-1].javascript;
}
function getPDFString() {
var invoice = {{ json_encode($invoice) }};
invoice.is_pro = {{ Auth::user()->isPro() ? 'true' : 'false' }};
invoice.account.hide_quantity = $('#hide_quantity').is(":checked");
invoice.account.hide_paid_to_date = $('#hide_paid_to_date').is(":checked");
invoice.invoice_design_id = $('#invoice_design_id').val();
NINJA.primaryColor = $('#primary_color').val();
NINJA.secondaryColor = $('#secondary_color').val();
var doc = generatePDF(invoice, getDesignJavascript(), true);
if (!doc) {
return;
}
return doc.output('datauristring');
}
$(function() {
var options = {
preferredFormat: 'hex',
disabled: {{ Auth::user()->isPro() ? 'false' : 'true' }},
showInitial: false,
showInput: true,
allowEmpty: true,
clickoutFiresChange: true,
};
$('#primary_color').spectrum(options);
$('#secondary_color').spectrum(options);
refreshPDF();
});
</script>

View File

@ -2,40 +2,8 @@
@section('head')
<meta name="csrf-token" content="<?= csrf_token() ?>">
<link href="{{ asset('built.css') }}" rel="stylesheet" type="text/css"/>
<!--
<script src="{{ asset('vendor/jquery/dist/jquery.js') }}" type="text/javascript"></script>
<script src="{{ asset('vendor/jquery-ui/ui/minified/jquery-ui.min.js') }}" type="text/javascript"></script>
<script src="{{ asset('vendor/bootstrap/dist/js/bootstrap.min.js') }}" type="text/javascript"></script>
<script src="{{ asset('vendor/datatables/media/js/jquery.dataTables.js') }}" type="text/javascript"></script>
<script src="{{ asset('vendor/datatables-bootstrap3/BS3/assets/js/datatables.js') }}" type="text/javascript"></script>
<script src="{{ asset('vendor/knockout.js/knockout.js') }}" type="text/javascript"></script>
<script src="{{ asset('vendor/knockout-mapping/build/output/knockout.mapping-latest.js') }}" type="text/javascript"></script>
<script src="{{ asset('vendor/knockout-sortable/build/knockout-sortable.min.js') }}" type="text/javascript"></script>
<script src="{{ asset('vendor/underscore/underscore.js') }}" type="text/javascript"></script>
<script src="{{ asset('vendor/bootstrap-datepicker/js/bootstrap-datepicker.js') }}" type="text/javascript"></script>
<script src="{{ asset('vendor/typeahead.js/dist/typeahead.min.js') }}" type="text/javascript"></script>
<script src="{{ asset('vendor/accounting/accounting.min.js') }}" type="text/javascript"></script>
<script src="{{ asset('vendor/spectrum/spectrum.js') }}" type="text/javascript"></script>
<script src="{{ asset('js/bootstrap-combobox.js') }}" type="text/javascript"></script>
<script src="{{ asset('js/jspdf.source.js') }}" type="text/javascript"></script>
<script src="{{ asset('js/jspdf.plugin.split_text_to_size.js') }}" type="text/javascript"></script>
<script src="{{ asset('js/script.js') }}" type="text/javascript"></script>
-->
<!--
<link href="{{ asset('vendor/bootstrap/dist/css/bootstrap.min.css') }}" rel="stylesheet" type="text/css"/>
<link href="{{ asset('vendor/datatables/media/css/jquery.dataTables.css') }}" rel="stylesheet" type="text/css">
<link href="{{ asset('vendor/datatables-bootstrap3/BS3/assets/css/datatables.css') }}" rel="stylesheet" type="text/css">
<link href="{{ asset('vendor/font-awesome/css/font-awesome.min.css') }}" rel="stylesheet" type="text/css"/>
<link href="{{ asset('vendor/bootstrap-datepicker/css/datepicker.css') }}" rel="stylesheet" type="text/css"/>
<link href="{{ asset('vendor/spectrum/spectrum.css') }}" rel="stylesheet" type="text/css"/>
<link href="{{ asset('css/bootstrap-combobox.css') }}" rel="stylesheet" type="text/css"/>
<link href="{{ asset('css/typeahead.js-bootstrap.css') }}" rel="stylesheet" type="text/css"/>
<link href="{{ asset('css/style.css') }}" rel="stylesheet" type="text/css"/>
-->
<link href="{{ asset('built.css') }}?no_cache={{ NINJA_VERSION }}" rel="stylesheet" type="text/css"/>
<style type="text/css">

View File

@ -317,11 +317,8 @@
</div>
<p>&nbsp;</p>
<!-- <textarea rows="20" cols="120" id="pdfText" onkeyup="runCode()"></textarea> -->
<!-- <iframe frameborder="1" width="100%" height="600" style="display:block;margin: 0 auto"></iframe> -->
<iframe id="theFrame" style="display:none" frameborder="1" width="100%" height="1180"></iframe>
<canvas id="theCanvas" style="display:none;width:100%;border:solid 1px #CCCCCC;"></canvas>
@include('invoices.pdf', ['account' => Auth::user()->account])
@if (!Auth::user()->account->isPro())
<div style="font-size:larger">
@ -643,76 +640,20 @@
invoice.imageHeight = {{ $account->getLogoHeight() }};
@endif
window.logoImages = {};
logoImages.imageLogo1 = "{{ HTML::image_data('images/report_logo1.jpg') }}";
logoImages.imageLogoWidth1 =120;
logoImages.imageLogoHeight1 = 40
logoImages.imageLogo2 = "{{ HTML::image_data('images/report_logo2.jpg') }}";
logoImages.imageLogoWidth2 =325/2;
logoImages.imageLogoHeight2 = 81/2;
logoImages.imageLogo3 = "{{ HTML::image_data('images/report_logo3.jpg') }}";
logoImages.imageLogoWidth3 =325/2;
logoImages.imageLogoHeight3 = 81/2;
return invoice;
}
/*
function refreshPDF() {
setTimeout(function() {
_refreshPDF();
}, 100);
}
*/
var isRefreshing = false;
var needsRefresh = false;
function getPDFString() {
var invoice = createInvoiceModel();
var doc = generatePDF(invoice);
var design = getDesignJavascript();
var doc = generatePDF(invoice, design);
if (!doc) return;
return doc.output('datauristring');
}
function refreshPDF() {
if ({{ Auth::user()->force_pdfjs ? 'false' : 'true' }} && (isFirefox || (isChrome && !isChromium))) {
var string = getPDFString();
if (!string) return;
$('#theFrame').attr('src', string).show();
} else {
if (isRefreshing) {
needsRefresh = true;
return;
}
var string = getPDFString();
if (!string) return;
isRefreshing = true;
var pdfAsArray = convertDataURIToBinary(string);
PDFJS.getDocument(pdfAsArray).then(function getPdfHelloWorld(pdf) {
pdf.getPage(1).then(function getPageHelloWorld(page) {
var scale = 1.5;
var viewport = page.getViewport(scale);
var canvas = document.getElementById('theCanvas');
var context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
page.render({canvasContext: context, viewport: viewport});
$('#theCanvas').show();
isRefreshing = false;
if (needsRefresh) {
needsRefresh = false;
refreshPDF();
}
});
});
}
function getDesignJavascript() {
var id = $('#invoice_design_id').val();
return invoiceDesigns[id-1].javascript;
}
function onDownloadClick() {
@ -1561,10 +1502,11 @@
var products = {{ $products }};
var clients = {{ $clients }};
var invoiceLabels = {{ json_encode($invoiceLabels) }};
var clientMap = {};
var $clientSelect = $('select#client');
var invoiceDesigns = {{ $invoiceDesigns }};
for (var i=0; i<clients.length; i++) {
var client = clients[i];
for (var j=0; j<client.contacts.length; j++) {

View File

@ -0,0 +1,72 @@
<iframe id="theFrame" style="display:none" frameborder="1" width="100%" height="{{ isset($pdfHeight) ? $pdfHeight : 1180 }}px"></iframe>
<canvas id="theCanvas" style="display:none;width:100%;border:solid 1px #CCCCCC;"></canvas>
<script type="text/javascript">
window.logoImages = {};
logoImages.imageLogo1 = "{{ HTML::image_data('images/report_logo1.jpg') }}";
logoImages.imageLogoWidth1 =120;
logoImages.imageLogoHeight1 = 40
logoImages.imageLogo2 = "{{ HTML::image_data('images/report_logo2.jpg') }}";
logoImages.imageLogoWidth2 =325/2;
logoImages.imageLogoHeight2 = 81/2;
logoImages.imageLogo3 = "{{ HTML::image_data('images/report_logo3.jpg') }}";
logoImages.imageLogoWidth3 =325/2;
logoImages.imageLogoHeight3 = 81/2;
@if (file_exists($account->getLogoPath()))
invoice.image = "{{ HTML::image_data($account->getLogoPath()) }}";
invoice.imageWidth = {{ $invoice->client->account->getLogoWidth() }};
invoice.imageHeight = {{ $invoice->client->account->getLogoHeight() }};
@endif
var NINJA = NINJA || {};
NINJA.primaryColor = "{{ $account->primary_color }}";
NINJA.secondaryColor = "{{ $account->secondary_color }}";
var invoiceLabels = {{ json_encode($account->getInvoiceLabels()) }};
var isRefreshing = false;
var needsRefresh = false;
function refreshPDF() {
console.log('refreshPDF');
if ({{ Auth::check() && Auth::user()->force_pdfjs ? 'false' : 'true' }} && (isFirefox || (isChrome && !isChromium))) {
var string = getPDFString();
if (!string) return;
$('#theFrame').attr('src', string).show();
} else {
if (isRefreshing) {
needsRefresh = true;
return;
}
var string = getPDFString();
if (!string) return;
isRefreshing = true;
var pdfAsArray = convertDataURIToBinary(string);
PDFJS.getDocument(pdfAsArray).then(function getPdfHelloWorld(pdf) {
pdf.getPage(1).then(function getPageHelloWorld(page) {
var scale = 1.5;
var viewport = page.getViewport(scale);
var canvas = document.getElementById('theCanvas');
var context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
page.render({canvasContext: context, viewport: viewport});
$('#theCanvas').show();
isRefreshing = false;
if (needsRefresh) {
needsRefresh = false;
refreshPDF();
}
});
});
}
}
</script>

View File

@ -36,72 +36,29 @@
<div class="clearfix"></div><p>&nbsp;</p>
<iframe id="theFrame" frameborder="1" width="100%" height="1180" style="display:none;margin: 0 auto"></iframe>
<canvas id="theCanvas" style="display:none;width:100%;border:solid 1px #CCCCCC;"></canvas>
@include('invoices.pdf', ['account' => $invoice->client->account])
<p>&nbsp;</p>
<p>&nbsp;</p>
</div>
</div>
<script type="text/javascript">
$(function() {
window.invoice = {{ $invoice->toJson() }};
window.logoImages = {};
logoImages.imageLogo1 = "{{ HTML::image_data('images/report_logo1.jpg') }}";
logoImages.imageLogoWidth1 =120;
logoImages.imageLogoHeight1 = 40
window.invoice = {{ $invoice->toJson() }};
invoice.is_pro = {{ $invoice->client->account->isPro() ? 'true' : 'false' }};
invoice.is_quote = {{ $invoice->is_quote ? 'true' : 'false' }};
logoImages.imageLogo2 = "{{ HTML::image_data('images/report_logo2.jpg') }}";
logoImages.imageLogoWidth2 =325/2;
logoImages.imageLogoHeight2 = 81/2;
logoImages.imageLogo3 = "{{ HTML::image_data('images/report_logo3.jpg') }}";
logoImages.imageLogoWidth3 =325/2;
logoImages.imageLogoHeight3 = 81/2;
@if (file_exists($invoice->client->account->getLogoPath()))
invoice.image = "{{ HTML::image_data($invoice->client->account->getLogoPath()) }}";
invoice.imageWidth = {{ $invoice->client->account->getLogoWidth() }};
invoice.imageHeight = {{ $invoice->client->account->getLogoHeight() }};
@endif
invoice.is_quote = {{ $invoice->is_quote ? 'true' : 'false' }};
var NINJA = NINJA || {};
NINJA.primaryColor = "{{ $invoice->client->account->primary_color }}";
NINJA.secondaryColor = "{{ $invoice->client->account->secondary_color }}";
var doc = generatePDF(invoice);
function getPDFString() {
var doc = generatePDF(invoice, invoice.invoice_design.javascript);
if (!doc) return;
var string = doc.output('datauristring');
if (isFirefox || (isChrome && !isChromium)) {
$('#theFrame').attr('src', string).show();
} else {
var pdfAsArray = convertDataURIToBinary(string);
PDFJS.getDocument(pdfAsArray).then(function getPdfHelloWorld(pdf) {
return doc.output('datauristring');
}
pdf.getPage(1).then(function getPageHelloWorld(page) {
var scale = 1.5;
var viewport = page.getViewport(scale);
var canvas = document.getElementById('theCanvas');
var context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
page.render({canvasContext: context, viewport: viewport});
$('#theCanvas').show();
});
});
}
$(function() {
refreshPDF();
});
var invoiceLabels = {{ json_encode($invoiceLabels) }};
function onDownloadClick() {
var doc = generatePDF(invoice, true);
doc.save('Invoice-' + invoice.invoice_number + '.pdf');

View File

@ -15,6 +15,7 @@
<meta property="og:description" content="Simple, Intuitive Invoicing."></meta>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="csrf-token" content="<?= csrf_token() ?>">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href='//fonts.googleapis.com/css?family=Roboto:400,700,900,100' rel='stylesheet' type='text/css'>
@ -25,7 +26,7 @@
<link rel="canonical" href="https://www.invoiceninja.com"></link>
@endif
<script src="{{ asset('built.js') }}" type="text/javascript"></script>
<script src="{{ asset('built.js') }}?no_cache={{ NINJA_VERSION }}" type="text/javascript"></script>
<script type="text/javascript">
var NINJA = NINJA || {};
@ -94,7 +95,6 @@
</script>
@endif
@yield('body')
<script type="text/javascript">

View File

@ -1,24 +1,9 @@
@extends('master')
@section('head')
<meta name="csrf-token" content="<?= csrf_token() ?>">
<link href="{{ asset('built.public.css') }}" rel="stylesheet" type="text/css"/>
<!--
<link href="{{ asset('vendor/bootstrap/dist/css/bootstrap.min.css') }}" rel="stylesheet" type="text/css"/>
<link href="{{ asset('css/bootstrap.splash.css') }}" rel="stylesheet" type="text/css"/>
<link href="{{ asset('css/splash.css') }}" rel="stylesheet" type="text/css"/>
-->
<!--
<link href="{{ asset('images/apple-touch-icon-114x114-precomposed.png') }}" rel="apple-touch-icon-precomposed" sizes="114x114">
<link href="{{ asset('images/apple-touch-icon-72x72-precomposed.png') }}" rel="apple-touch-icon-precomposed" sizes="72x72">
<link href="{{ asset('images/apple-touch-icon-57x57-precomposed.png') }}" rel="apple-touch-icon-precomposed">
-->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="{{ asset('js/simpleexpand.js') }}" type="text/javascript"></script>
<script src="{{ asset('js/valign.js') }}" type="text/javascript"></script>
<script src="{{ asset('js/bootstrap.min.js') }}" type="text/javascript"></script>
<link href="{{ asset('built.public.css') }}?no_cache={{ NINJA_VERSION }}" rel="stylesheet" type="text/css"/>
<script src="{{ asset('js/built.public.js') }}?no_cache={{ NINJA_VERSION }}" type="text/javascript"></script>
<style>
.hero {

View File

@ -53,7 +53,7 @@
<option>Invoices</option>
<option>Products</option>
</select>
&nbsp;&nbsp; {{ $message }}
&nbsp;&nbsp; <b>{{ $message }}</b>
</form>
<p>&nbsp;</p>
@ -169,7 +169,7 @@
var svg = d3.select(".svg-div").append("svg")
.attr("width", "100%")
.attr("height", "100%")
.attr("height", "1140px")
.attr("class", "bubble");
svg.append("rect")

View File

@ -16,7 +16,6 @@
"bootstrap-datepicker": "~1.*",
"typeahead.js": "~0.9.3",
"accounting": "~0.*",
"pdfjs": "*",
"spectrum": "~1.3.4",
"d3": "~3.4.11"
},

View File

@ -45933,7 +45933,7 @@ var isIE = /*@cc_on!@*/false || !!document.documentMode; // At least IE6
var invoiceOld;
function generatePDF(invoice, force) {
function generatePDF(invoice, javascript, force) {
invoice = calculateAmounts(invoice);
var a = copyInvoice(invoice);
var b = copyInvoice(invoiceOld);
@ -45942,7 +45942,7 @@ function generatePDF(invoice, force) {
}
invoiceOld = invoice;
report_id = invoice.invoice_design_id;
doc = GetPdf(invoice, report_id);
doc = GetPdf(invoice, javascript);
return doc;
}
@ -45954,8 +45954,7 @@ function copyInvoice(orig) {
}
function GetPdf(invoice, report_id){
function GetPdf(invoice, javascript){
var layout = {
accountTop: 40,
marginLeft: 50,
@ -45990,6 +45989,7 @@ function GetPdf(invoice, report_id){
*/
var doc = new jsPDF('portrait', 'pt', 'a4');
//doc.getStringUnitWidth = function(param) { console.log('getStringUnitWidth: %s', param); return 0};
//Set PDF properities
doc.setProperties({
@ -46003,547 +46003,12 @@ function GetPdf(invoice, report_id){
//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);
eval(javascript);
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;
var currencyId = client.currency_id;
if (invoice.image)
{
var left = layout.headerRight - invoice.imageWidth;
doc.addImage(invoice.image, 'JPEG', left, 30);
}
/* table header */
doc.setDrawColor(200,200,200);
doc.setFillColor(230,230,230);
var detailsHeight = getInvoiceDetailsHeight(invoice, layout);
var left = layout.headerLeft - layout.tablePadding;
var top = layout.headerTop + detailsHeight - layout.rowHeight - layout.tablePadding;
var width = layout.headerRight - layout.headerLeft + (2 * layout.tablePadding);
var height = layout.rowHeight + 1;
doc.rect(left, top, width, height, 'FD');
doc.setFontSize(10);
doc.setFontType("normal");
displayAccount(doc, invoice, layout.marginLeft, layout.accountTop, layout);
displayClient(doc, invoice, layout.marginLeft, layout.headerTop, layout);
displayInvoice(doc, invoice, layout.headerLeft, layout.headerTop, layout, layout.headerRight);
layout.tableTop = Math.max(layout.tableTop, layout.headerTop + detailsHeight + (2 * layout.tablePadding));
var headerY = layout.headerTop;
var total = 0;
doc.setDrawColor(200,200,200);
doc.setFillColor(230,230,230);
var left = layout.marginLeft - layout.tablePadding;
var top = layout.tableTop - layout.tablePadding;
var width = layout.headerRight - layout.marginLeft + (2 * layout.tablePadding);
var height = layout.rowHeight + 2;
doc.rect(left, top, width, height, 'FD');
displayInvoiceHeader(doc, invoice, layout);
var y = displayInvoiceItems(doc, invoice, layout);
doc.setFontSize(10);
displayNotesAndTerms(doc, layout, invoice, y+20);
y += displaySubtotals(doc, layout, invoice, y+20, 480) + 20;
doc.setDrawColor(200,200,200);
doc.setFillColor(230,230,230);
var left = layout.footerLeft - layout.tablePadding;
var top = y - layout.tablePadding;
var width = layout.headerRight - layout.footerLeft + (2 * layout.tablePadding);
var height = layout.rowHeight + 2;
doc.rect(left, top, width, height, 'FD');
doc.setFontType("bold");
doc.text(layout.footerLeft, y, invoice.is_quote ? invoiceLabels.total : invoiceLabels.balance_due);
total = formatMoney(invoice.balance_amount, currencyId);
var totalX = layout.headerRight - (doc.getStringUnitWidth(total) * doc.internal.getFontSize());
doc.text(totalX, y, total);
if (!invoice.is_pro) {
doc.setFontType("normal");
doc.text(layout.marginLeft, 790, "Created by InvoiceNinja.com");
}
return doc;
}
function SetPdfColor(color, doc, role)
{
if (role === 'primary' && NINJA.primaryColor) {
@ -46960,21 +46425,21 @@ function wordWrapText(value, width)
}
}
function getClientDisplayName(client)
{
var contact = client.contacts[0];
var contact = client.contacts ? client.contacts[0] : false;
if (client.name) {
return client.name;
} else if (contact.first_name || contact.last_name) {
return contact.first_name + ' ' + contact.last_name;
} else {
return contact.email;
} else if (contact) {
if (contact.first_name || contact.last_name) {
return contact.first_name + ' ' + contact.last_name;
} else {
return contact.email;
}
}
return '';
}
function populateInvoiceComboboxes(clientId, invoiceId) {
var clientMap = {};
var invoiceMap = {};
@ -47120,9 +46585,8 @@ function displayClient(doc, invoice, x, y, layout) {
concatStrings(client.address1, client.address2),
concatStrings(client.city, client.state, client.postal_code),
client.country ? client.country.name : false,
client.contacts[0].email
client.contacts ? client.contacts[0].email : false
];
return displayGrid(doc, invoice, data, x, y, layout, {hasheader:true});
}
@ -47430,7 +46894,7 @@ function displayInvoiceHeader(doc, invoice, layout) {
}
}
function displayInvoiceItems(doc, invoice, layout) {
function displayInvoiceItems(doc, invoice, layout) {
doc.setFontType("normal");
var line = 1;
@ -47439,10 +46903,10 @@ function displayInvoiceItems(doc, invoice, layout) {
var currencyId = invoice && invoice.client ? invoice.client.currency_id : 1;
var tableTop = layout.tableTop;
var hideQuantity = invoice.account.hide_quantity == '1';
doc.setFontSize(8);
for (var i=0; i<invoice.invoice_items.length; i++) {
var item = invoice.invoice_items[i];
var item = invoice.invoice_items[i];
var numLines = doc.splitTextToSize(item.notes, 200).length + 2;
//console.log('num lines %s', numLines);
@ -47498,10 +46962,8 @@ function displayInvoiceItems(doc, invoice, layout) {
var qtyX = layout.qtyRight - (doc.getStringUnitWidth(qty) * doc.internal.getFontSize());
var taxX = layout.taxRight - (doc.getStringUnitWidth(tax+'%') * doc.internal.getFontSize());
var totalX = layout.lineTotalRight - (doc.getStringUnitWidth(lineTotal) * doc.internal.getFontSize());
//if (i==0) y -= 4;
line += numLines;
if (invoice.invoice_design_id == 1) {
if (i%2 == 0) {
@ -47531,7 +46993,7 @@ function displayInvoiceItems(doc, invoice, layout) {
}
y += 4;
if (invoice.invoice_design_id == 1) {
SetPdfColor('LightBlue', doc, 'primary');
} else if (invoice.invoice_design_id == 2) {

23
public/js/built.public.js Normal file
View File

@ -0,0 +1,23 @@
/* Copyright (C) 2012 Sylvain Hamel
Project: https://github.com/redhotsly/simple-expand
MIT Licence: https://raw.github.com/redhotsly/simple-expand/master/licence-mit.txt */
(function($){"use strict";function SimpleExpand(){var that=this;that.defaults={hideMode:"fadeToggle",defaultSearchMode:"parent",defaultTarget:".content",throwOnMissingTarget:true,keepStateInCookie:false,cookieName:"simple-expand"};that.settings={};$.extend(that.settings,that.defaults);that.findLevelOneDeep=function(parent,filterSelector,stopAtSelector){return parent.find(filterSelector).filter(function(){return!$(this).parentsUntil(parent,stopAtSelector).length})};that.setInitialState=function(expander,targets){var isExpanded=that.readState(expander);if(isExpanded){expander.removeClass("collapsed").addClass("expanded");that.show(targets)}else{expander.removeClass("expanded").addClass("collapsed");that.hide(targets)}};that.hide=function(targets){if(that.settings.hideMode==="fadeToggle"){targets.hide()}else if(that.settings.hideMode==="basic"){targets.hide()}};that.show=function(targets){if(that.settings.hideMode==="fadeToggle"){targets.show()}else if(that.settings.hideMode==="basic"){targets.show()}};that.checkKeepStateInCookiePreconditions=function(){if(that.settings.keepStateInCookie&&$.cookie===undefined){throw new Error("simple-expand: keepStateInCookie option requires $.cookie to be defined.")}};that.readCookie=function(){var jsonString=$.cookie(that.settings.cookieName);if(jsonString===null||jsonString===""){return{}}else{return JSON.parse(jsonString)}};that.readState=function(expander){if(!that.settings.keepStateInCookie){return expander.hasClass("expanded")}var id=expander.attr("Id");if(id===undefined){return}var cookie=that.readCookie();var cookieValue=cookie[id];if(typeof cookieValue!=="undefined"){return cookie[id]===true}else{return expander.hasClass("expanded")}};that.saveState=function(expander,isExpanded){if(!that.settings.keepStateInCookie){return}var id=expander.attr("Id");if(id===undefined){return}var cookie=that.readCookie();cookie[id]=isExpanded;$.cookie(that.settings.cookieName,JSON.stringify(cookie),{raw:true,path:window.location.pathname})};that.toggle=function(expander,targets){var isExpanded=that.toggleCss(expander);if(that.settings.hideMode==="fadeToggle"){targets.fadeToggle(150)}else if(that.settings.hideMode==="basic"){targets.toggle()}else if($.isFunction(that.settings.hideMode)){that.settings.hideMode(expander,targets,isExpanded)}that.saveState(expander,isExpanded);return false};that.toggleCss=function(expander){if(expander.hasClass("expanded")){expander.toggleClass("collapsed expanded");return false}else{expander.toggleClass("expanded collapsed");return true}};that.findTargets=function(expander,searchMode,targetSelector){var targets=[];if(searchMode==="absolute"){targets=$(targetSelector)}else if(searchMode==="relative"){targets=that.findLevelOneDeep(expander,targetSelector,targetSelector)}else if(searchMode==="parent"){var parent=expander.parent();do{targets=that.findLevelOneDeep(parent,targetSelector,targetSelector);if(targets.length===0){parent=parent.parent()}}while(targets.length===0&&parent.length!==0)}return targets};that.activate=function(jquery,options){$.extend(that.settings,options);that.checkKeepStateInCookiePreconditions();jquery.each(function(){var expander=$(this);var targetSelector=expander.attr("data-expander-target")||that.settings.defaultTarget;var searchMode=expander.attr("data-expander-target-search")||that.settings.defaultSearchMode;var targets=that.findTargets(expander,searchMode,targetSelector);if(targets.length===0){if(that.settings.throwOnMissingTarget){throw"simple-expand: Targets not found"}return this}that.setInitialState(expander,targets);expander.click(function(){return that.toggle(expander,targets)})})}}window.SimpleExpand=SimpleExpand;$.fn.simpleexpand=function(options){var instance=new SimpleExpand;instance.activate(this,options);return this}})(jQuery);
(function ($) {
$.fn.vAlign = function() {
return this.each(function(i){
$(this).children().wrapAll('<div class="nitinh-vAlign" style="position:relative;"></div>');
var div = $(this).children('div.nitinh-vAlign');
var ph = $(this).innerHeight();
var dh = div.height();
var mh = (ph - dh) / 2;
div.css('top', mh);
});
};
})(jQuery);
/*!
* Bootstrap v3.1.1 (http://getbootstrap.com)
* Copyright 2011-2014 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/
+function(a){"use strict";var b=function(c,d){this.$element=a(c),this.options=a.extend({},b.DEFAULTS,d),this.transitioning=null,this.options.parent&&(this.$parent=a(this.options.parent)),this.options.toggle&&this.toggle()};b.DEFAULTS={toggle:!0},b.prototype.dimension=function(){var a=this.$element.hasClass("width");return a?"width":"height"},b.prototype.show=function(){if(this.transitioning||this.$element.hasClass("in"))return;var b=a.Event("show.bs.collapse");this.$element.trigger(b);if(b.isDefaultPrevented())return;var c=this.$parent&&this.$parent.find("> .panel > .in");if(c&&c.length){var d=c.data("bs.collapse");if(d&&d.transitioning)return;c.collapse("hide"),d||c.data("bs.collapse",null)}var e=this.dimension();this.$element.removeClass("collapse").addClass("collapsing")[e](0),this.transitioning=1;var f=function(){this.$element.removeClass("collapsing").addClass("collapse in")[e]("auto"),this.transitioning=0,this.$element.trigger("shown.bs.collapse")};if(!a.support.transition)return f.call(this);var g=a.camelCase(["scroll",e].join("-"));this.$element.one(a.support.transition.end,a.proxy(f,this)).emulateTransitionEnd(350)[e](this.$element[0][g])},b.prototype.hide=function(){if(this.transitioning||!this.$element.hasClass("in"))return;var b=a.Event("hide.bs.collapse");this.$element.trigger(b);if(b.isDefaultPrevented())return;var c=this.dimension();this.$element[c](this.$element[c]())[0].offsetHeight,this.$element.addClass("collapsing").removeClass("collapse").removeClass("in"),this.transitioning=1;var d=function(){this.transitioning=0,this.$element.trigger("hidden.bs.collapse").removeClass("collapsing").addClass("collapse")};if(!a.support.transition)return d.call(this);this.$element[c](0).one(a.support.transition.end,a.proxy(d,this)).emulateTransitionEnd(350)},b.prototype.toggle=function(){this[this.$element.hasClass("in")?"hide":"show"]()};var c=a.fn.collapse;a.fn.collapse=function(c){return this.each(function(){var d=a(this),e=d.data("bs.collapse"),f=a.extend({},b.DEFAULTS,d.data(),typeof c=="object"&&c);!e&&f.toggle&&c=="show"&&(c=!c),e||d.data("bs.collapse",e=new b(this,f)),typeof c=="string"&&e[c]()})},a.fn.collapse.Constructor=b,a.fn.collapse.noConflict=function(){return a.fn.collapse=c,this},a(document).on("click.bs.collapse.data-api","[data-toggle=collapse]",function(b){var c=a(this),d,e=c.attr("data-target")||b.preventDefault()||(d=c.attr("href"))&&d.replace(/.*(?=#[^\s]+$)/,""),f=a(e),g=f.data("bs.collapse"),h=g?"toggle":c.data(),i=c.attr("data-parent"),j=i&&a(i);if(!g||!g.transitioning)j&&j.find('[data-toggle=collapse][data-parent="'+i+'"]').not(c).addClass("collapsed"),c[f.hasClass("in")?"addClass":"removeClass"]("collapsed");f.collapse(h)})}(jQuery),+function(a){function b(){var a=document.createElement("bootstrap"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var c in b)if(a.style[c]!==undefined)return{end:b[c]};return!1}"use strict",a.fn.emulateTransitionEnd=function(b){var c=!1,d=this;a(this).one(a.support.transition.end,function(){c=!0});var e=function(){c||a(d).trigger(a.support.transition.end)};return setTimeout(e,b),this},a(function(){a.support.transition=b()})}(jQuery)

View File

@ -8,7 +8,7 @@ var isIE = /*@cc_on!@*/false || !!document.documentMode; // At least IE6
var invoiceOld;
function generatePDF(invoice, force) {
function generatePDF(invoice, javascript, force) {
invoice = calculateAmounts(invoice);
var a = copyInvoice(invoice);
var b = copyInvoice(invoiceOld);
@ -17,7 +17,7 @@ function generatePDF(invoice, force) {
}
invoiceOld = invoice;
report_id = invoice.invoice_design_id;
doc = GetPdf(invoice, report_id);
doc = GetPdf(invoice, javascript);
return doc;
}
@ -29,8 +29,7 @@ function copyInvoice(orig) {
}
function GetPdf(invoice, report_id){
function GetPdf(invoice, javascript){
var layout = {
accountTop: 40,
marginLeft: 50,
@ -65,6 +64,7 @@ function GetPdf(invoice, report_id){
*/
var doc = new jsPDF('portrait', 'pt', 'a4');
//doc.getStringUnitWidth = function(param) { console.log('getStringUnitWidth: %s', param); return 0};
//Set PDF properities
doc.setProperties({
@ -78,547 +78,12 @@ function GetPdf(invoice, report_id){
//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);
eval(javascript);
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;
var currencyId = client.currency_id;
if (invoice.image)
{
var left = layout.headerRight - invoice.imageWidth;
doc.addImage(invoice.image, 'JPEG', left, 30);
}
/* table header */
doc.setDrawColor(200,200,200);
doc.setFillColor(230,230,230);
var detailsHeight = getInvoiceDetailsHeight(invoice, layout);
var left = layout.headerLeft - layout.tablePadding;
var top = layout.headerTop + detailsHeight - layout.rowHeight - layout.tablePadding;
var width = layout.headerRight - layout.headerLeft + (2 * layout.tablePadding);
var height = layout.rowHeight + 1;
doc.rect(left, top, width, height, 'FD');
doc.setFontSize(10);
doc.setFontType("normal");
displayAccount(doc, invoice, layout.marginLeft, layout.accountTop, layout);
displayClient(doc, invoice, layout.marginLeft, layout.headerTop, layout);
displayInvoice(doc, invoice, layout.headerLeft, layout.headerTop, layout, layout.headerRight);
layout.tableTop = Math.max(layout.tableTop, layout.headerTop + detailsHeight + (2 * layout.tablePadding));
var headerY = layout.headerTop;
var total = 0;
doc.setDrawColor(200,200,200);
doc.setFillColor(230,230,230);
var left = layout.marginLeft - layout.tablePadding;
var top = layout.tableTop - layout.tablePadding;
var width = layout.headerRight - layout.marginLeft + (2 * layout.tablePadding);
var height = layout.rowHeight + 2;
doc.rect(left, top, width, height, 'FD');
displayInvoiceHeader(doc, invoice, layout);
var y = displayInvoiceItems(doc, invoice, layout);
doc.setFontSize(10);
displayNotesAndTerms(doc, layout, invoice, y+20);
y += displaySubtotals(doc, layout, invoice, y+20, 480) + 20;
doc.setDrawColor(200,200,200);
doc.setFillColor(230,230,230);
var left = layout.footerLeft - layout.tablePadding;
var top = y - layout.tablePadding;
var width = layout.headerRight - layout.footerLeft + (2 * layout.tablePadding);
var height = layout.rowHeight + 2;
doc.rect(left, top, width, height, 'FD');
doc.setFontType("bold");
doc.text(layout.footerLeft, y, invoice.is_quote ? invoiceLabels.total : invoiceLabels.balance_due);
total = formatMoney(invoice.balance_amount, currencyId);
var totalX = layout.headerRight - (doc.getStringUnitWidth(total) * doc.internal.getFontSize());
doc.text(totalX, y, total);
if (!invoice.is_pro) {
doc.setFontType("normal");
doc.text(layout.marginLeft, 790, "Created by InvoiceNinja.com");
}
return doc;
}
function SetPdfColor(color, doc, role)
{
if (role === 'primary' && NINJA.primaryColor) {
@ -1035,21 +500,21 @@ function wordWrapText(value, width)
}
}
function getClientDisplayName(client)
{
var contact = client.contacts[0];
var contact = client.contacts ? client.contacts[0] : false;
if (client.name) {
return client.name;
} else if (contact.first_name || contact.last_name) {
return contact.first_name + ' ' + contact.last_name;
} else {
return contact.email;
} else if (contact) {
if (contact.first_name || contact.last_name) {
return contact.first_name + ' ' + contact.last_name;
} else {
return contact.email;
}
}
return '';
}
function populateInvoiceComboboxes(clientId, invoiceId) {
var clientMap = {};
var invoiceMap = {};
@ -1195,9 +660,8 @@ function displayClient(doc, invoice, x, y, layout) {
concatStrings(client.address1, client.address2),
concatStrings(client.city, client.state, client.postal_code),
client.country ? client.country.name : false,
client.contacts[0].email
client.contacts ? client.contacts[0].email : false
];
return displayGrid(doc, invoice, data, x, y, layout, {hasheader:true});
}
@ -1505,7 +969,7 @@ function displayInvoiceHeader(doc, invoice, layout) {
}
}
function displayInvoiceItems(doc, invoice, layout) {
function displayInvoiceItems(doc, invoice, layout) {
doc.setFontType("normal");
var line = 1;
@ -1514,10 +978,10 @@ function displayInvoiceItems(doc, invoice, layout) {
var currencyId = invoice && invoice.client ? invoice.client.currency_id : 1;
var tableTop = layout.tableTop;
var hideQuantity = invoice.account.hide_quantity == '1';
doc.setFontSize(8);
for (var i=0; i<invoice.invoice_items.length; i++) {
var item = invoice.invoice_items[i];
var item = invoice.invoice_items[i];
var numLines = doc.splitTextToSize(item.notes, 200).length + 2;
//console.log('num lines %s', numLines);
@ -1573,10 +1037,8 @@ function displayInvoiceItems(doc, invoice, layout) {
var qtyX = layout.qtyRight - (doc.getStringUnitWidth(qty) * doc.internal.getFontSize());
var taxX = layout.taxRight - (doc.getStringUnitWidth(tax+'%') * doc.internal.getFontSize());
var totalX = layout.lineTotalRight - (doc.getStringUnitWidth(lineTotal) * doc.internal.getFontSize());
//if (i==0) y -= 4;
line += numLines;
if (invoice.invoice_design_id == 1) {
if (i%2 == 0) {
@ -1606,7 +1068,7 @@ function displayInvoiceItems(doc, invoice, layout) {
}
y += 4;
if (invoice.invoice_design_id == 1) {
SetPdfColor('LightBlue', doc, 'primary');
} else if (invoice.invoice_design_id == 2) {