mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
commit
b1ff58d70f
12
Gruntfile.js
12
Gruntfile.js
@ -6,36 +6,34 @@ module.exports = function(grunt) {
|
||||
options: {
|
||||
process: function(src, filepath) {
|
||||
var basepath = filepath.substring(7, filepath.lastIndexOf('/') + 1);
|
||||
|
||||
console.log(filepath);
|
||||
// Fix relative paths for css files
|
||||
if(filepath.indexOf('.css', filepath.length - 4) !== -1) {
|
||||
return src.replace(/(url\s*[\("']+)\s*([^'"\)]+)(['"\)]+;?)/gi, function(match, start, url, end, offset, string) {
|
||||
if(url.indexOf('data:') === 0) {
|
||||
// Skip data urls
|
||||
return match;
|
||||
|
||||
|
||||
} else if(url.indexOf('/') === 0) {
|
||||
// Skip absolute urls
|
||||
return match;
|
||||
|
||||
|
||||
} else {
|
||||
return start + basepath + url + end;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Fix source maps locations
|
||||
} else if(filepath.indexOf('.js', filepath.length - 4) !== -1) {
|
||||
return src.replace(/(\/[*\/][#@]\s*sourceMappingURL=)([^\s]+)/gi, function(match, start, url, offset, string) {
|
||||
if(url.indexOf('/') === 0) {
|
||||
// Skip absolute urls
|
||||
return match;
|
||||
|
||||
|
||||
} else {
|
||||
return start + basepath + url;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Don't do anything for unknown file types
|
||||
} else {
|
||||
return src;
|
||||
|
@ -818,7 +818,8 @@ class AccountController extends \BaseController {
|
||||
{
|
||||
$account = Auth::user()->account;
|
||||
$account->name = trim(Input::get('name'));
|
||||
$account->vat_number = trim(Input::get('vat_number'));
|
||||
$account->id_number = trim(Input::get('id_number'));
|
||||
$account->vat_number = trim(Input::get('vat_number'));
|
||||
$account->work_email = trim(Input::get('work_email'));
|
||||
$account->work_phone = trim(Input::get('work_phone'));
|
||||
$account->address1 = trim(Input::get('address1'));
|
||||
|
@ -199,7 +199,8 @@ class ClientController extends \BaseController {
|
||||
}
|
||||
|
||||
$client->name = trim(Input::get('name'));
|
||||
$client->vat_number = trim(Input::get('vat_number'));
|
||||
$client->id_number = trim(Input::get('id_number'));
|
||||
$client->vat_number = trim(Input::get('vat_number'));
|
||||
$client->work_phone = trim(Input::get('work_phone'));
|
||||
$client->custom_value1 = trim(Input::get('custom_value1'));
|
||||
$client->custom_value2 = trim(Input::get('custom_value2'));
|
||||
|
@ -17,7 +17,7 @@ class AddCompanyVatNumber extends Migration {
|
||||
$table->string('vat_number')->nullable();
|
||||
});
|
||||
|
||||
Schema::table('clients', function($table)
|
||||
Schema::table('clients', function($table)
|
||||
{
|
||||
$table->string('vat_number')->nullable();
|
||||
});
|
||||
@ -34,7 +34,7 @@ class AddCompanyVatNumber extends Migration {
|
||||
{
|
||||
$table->dropColumn('vat_number');
|
||||
});
|
||||
Schema::table('clients', function($table)
|
||||
Schema::table('clients', function($table)
|
||||
{
|
||||
$table->dropColumn('vat_number');
|
||||
});
|
||||
|
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddCompanyIdNumber extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('accounts', function($table)
|
||||
{
|
||||
$table->string('id_number')->nullable();
|
||||
});
|
||||
|
||||
Schema::table('clients', function($table)
|
||||
{
|
||||
$table->string('id_number')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('accounts', function($table)
|
||||
{
|
||||
$table->dropColumn('id_number');
|
||||
});
|
||||
Schema::table('clients', function($table)
|
||||
{
|
||||
$table->dropColumn('id_number');
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -5,7 +5,8 @@ return array(
|
||||
// client
|
||||
'organization' => 'Organisation',
|
||||
'name' => 'Navn',
|
||||
'vat_number' => 'CVR nummer',
|
||||
'id_number' => 'SE/CVR nummer',
|
||||
'vat_number' => 'SE/CVR nummer',
|
||||
'website' => 'Webside',
|
||||
'work_phone' => 'Telefon',
|
||||
'address' => 'Adresse',
|
||||
|
@ -457,8 +457,11 @@ return array(
|
||||
'more_designs_self_host_text' => '',
|
||||
'buy' => 'Buy',
|
||||
'bought_designs' => 'Successfully added additional invoice designs',
|
||||
|
||||
'sent' => 'sent',
|
||||
|
||||
'id_number' => 'ID Number',
|
||||
'vat_number' => 'VAT Number',
|
||||
|
||||
'timesheets' => 'Timesheets',
|
||||
|
||||
'payment_title' => 'Enter Your Billing Address and Credit Card information',
|
||||
|
@ -131,11 +131,23 @@ class Client extends EntityModel
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function getVatNumber()
|
||||
public function getIdNumber()
|
||||
{
|
||||
$str = '';
|
||||
|
||||
if ($this->work_phone)
|
||||
if ($this->id_number)
|
||||
{
|
||||
$str .= '<i class="fa fa-vat-number" style="width: 20px"></i>' . $this->vat_number;
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function getVatNumber()
|
||||
{
|
||||
$str = '';
|
||||
|
||||
if ($this->vat_number)
|
||||
{
|
||||
$str .= '<i class="fa fa-vat-number" style="width: 20px"></i>' . $this->vat_number;
|
||||
}
|
||||
|
@ -95,7 +95,8 @@ class Invoice extends EntityModel
|
||||
|
||||
$this->client->setVisible([
|
||||
'name',
|
||||
'vat_number',
|
||||
'id_number',
|
||||
'vat_number',
|
||||
'address1',
|
||||
'address2',
|
||||
'city',
|
||||
@ -111,7 +112,8 @@ class Invoice extends EntityModel
|
||||
|
||||
$this->account->setVisible([
|
||||
'name',
|
||||
'vat_number',
|
||||
'id_number',
|
||||
'vat_number',
|
||||
'address1',
|
||||
'address2',
|
||||
'city',
|
||||
|
@ -45,7 +45,7 @@ class AccountRepository
|
||||
|
||||
public function getSearchData()
|
||||
{
|
||||
$clients = \DB::table('clients')
|
||||
$clients = \DB::table('clients')
|
||||
->where('clients.deleted_at', '=', null)
|
||||
->where('clients.account_id', '=', \Auth::user()->account_id)
|
||||
->whereRaw("clients.name <> ''")
|
||||
|
@ -62,7 +62,10 @@ class ClientRepository
|
||||
if (isset($data['name'])) {
|
||||
$client->name = trim($data['name']);
|
||||
}
|
||||
if (isset($data['vat_number'])) {
|
||||
if (isset($data['id_number'])) {
|
||||
$client->id_number = trim($data['id_number']);
|
||||
}
|
||||
if (isset($data['vat_number'])) {
|
||||
$client->vat_number = trim($data['vat_number']);
|
||||
}
|
||||
if (isset($data['work_phone'])) {
|
||||
|
@ -29,7 +29,8 @@
|
||||
|
||||
{{ Former::legend('details') }}
|
||||
{{ Former::text('name') }}
|
||||
{{ Former::text('vat_number') }}
|
||||
{{ Former::text('id_number') }}
|
||||
{{ Former::text('vat_number') }}
|
||||
{{ Former::text('work_email') }}
|
||||
{{ Former::text('work_phone') }}
|
||||
{{ Former::file('logo')->max(2, 'MB')->accept('image')->inlineHelp(trans('texts.logo_help')) }}
|
||||
|
@ -4,7 +4,8 @@
|
||||
|
||||
{{ Former::legend('Organization') }}
|
||||
{{ Former::text('name') }}
|
||||
{{ Former::text('vat_number') }}
|
||||
{{ Former::text('id_number') }}
|
||||
{{ Former::text('vat_number') }}
|
||||
{{ Former::text('work_phone')->label('Phone') }}
|
||||
{{ Former::textarea('notes') }}
|
||||
|
||||
|
@ -23,8 +23,9 @@
|
||||
|
||||
{{ Former::legend('organization') }}
|
||||
{{ Former::text('name')->data_bind("attr { placeholder: placeholderName }") }}
|
||||
{{ Former::text('vat_number') }}
|
||||
{{ Former::text('website') }}
|
||||
{{ Former::text('id_number') }}
|
||||
{{ Former::text('vat_number') }}
|
||||
{{ Former::text('website') }}
|
||||
{{ Former::text('work_phone') }}
|
||||
|
||||
@if (Auth::user()->isPro())
|
||||
|
@ -39,8 +39,9 @@
|
||||
|
||||
<div class="col-md-3">
|
||||
<h3>{{ trans('texts.details') }}</h3>
|
||||
<p>{{ $client->getIdNumber() }}</p>
|
||||
<p>{{ $client->getVatNumber() }}</p>
|
||||
<p>{{ $client->getAddress() }}</p>
|
||||
<p>{{ $client->getAddress() }}</p>
|
||||
<p>{{ $client->getCustomFields() }}</p>
|
||||
<p>{{ $client->getPhone() }}</p>
|
||||
<p>{{ $client->getNotes() }}</p>
|
||||
|
@ -341,7 +341,8 @@
|
||||
|
||||
{{ Former::legend('organization') }}
|
||||
{{ Former::text('name')->data_bind("value: name, valueUpdate: 'afterkeydown', attr { placeholder: name.placeholder }") }}
|
||||
{{ Former::text('vat_number')->data_bind("value: vat_number, valueUpdate: 'afterkeydown'") }}
|
||||
{{ Former::text('id_number')->data_bind("value: id_number, valueUpdate: 'afterkeydown'") }}
|
||||
{{ Former::text('vat_number')->data_bind("value: vat_number, valueUpdate: 'afterkeydown'") }}
|
||||
|
||||
{{ Former::text('website')->data_bind("value: website, valueUpdate: 'afterkeydown'") }}
|
||||
{{ Former::text('work_phone')->data_bind("value: work_phone, valueUpdate: 'afterkeydown'") }}
|
||||
@ -1222,7 +1223,8 @@
|
||||
var self = this;
|
||||
self.public_id = ko.observable(0);
|
||||
self.name = ko.observable('');
|
||||
self.vat_number = ko.observable('');
|
||||
self.id_number = ko.observable('');
|
||||
self.vat_number = ko.observable('');
|
||||
self.work_phone = ko.observable('');
|
||||
self.custom_value1 = ko.observable('');
|
||||
self.custom_value2 = ko.observable('');
|
||||
|
184
public/built.js
184
public/built.js
@ -30966,7 +30966,7 @@ var isIE = /*@cc_on!@*/false || !!document.documentMode; // At least IE6
|
||||
|
||||
var invoiceOld;
|
||||
function generatePDF(invoice, javascript, force) {
|
||||
invoice = calculateAmounts(invoice);
|
||||
invoice = calculateAmounts(invoice);
|
||||
var a = copyInvoice(invoice);
|
||||
var b = copyInvoice(invoiceOld);
|
||||
if (!force && _.isEqual(a, b)) {
|
||||
@ -31011,7 +31011,7 @@ function GetPdf(invoice, javascript){
|
||||
layout.descriptionLeft -= 20;
|
||||
layout.unitCostRight -= 40;
|
||||
layout.qtyRight -= 40;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@param orientation One of "portrait" or "landscape" (or shortcuts "p" (Default), "l")
|
||||
@ -31099,24 +31099,24 @@ function processVariables(str) {
|
||||
if (!str) return '';
|
||||
var variables = ['MONTH','QUARTER','YEAR'];
|
||||
for (var i=0; i<variables.length; i++) {
|
||||
var variable = variables[i];
|
||||
var variable = variables[i];
|
||||
var regexp = new RegExp(':' + variable + '[+-]?[\\d]*', 'g');
|
||||
var matches = str.match(regexp);
|
||||
var matches = str.match(regexp);
|
||||
if (!matches) {
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
for (var j=0; j<matches.length; j++) {
|
||||
var match = matches[j];
|
||||
var offset = 0;
|
||||
var offset = 0;
|
||||
if (match.split('+').length > 1) {
|
||||
offset = match.split('+')[1];
|
||||
} else if (match.split('-').length > 1) {
|
||||
offset = parseInt(match.split('-')[1]) * -1;
|
||||
}
|
||||
str = str.replace(match, getDatePart(variable, offset));
|
||||
str = str.replace(match, getDatePart(variable, offset));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
@ -31139,7 +31139,7 @@ function getMonth(offset) {
|
||||
var months = [ "January", "February", "March", "April", "May", "June",
|
||||
"July", "August", "September", "October", "November", "December" ];
|
||||
var month = today.getMonth();
|
||||
month = parseInt(month) + offset;
|
||||
month = parseInt(month) + offset;
|
||||
month = month % 12;
|
||||
if (month < 0) {
|
||||
month += 12;
|
||||
@ -31159,7 +31159,7 @@ function getQuarter(offset) {
|
||||
quarter += offset;
|
||||
quarter = quarter % 4;
|
||||
if (quarter == 0) {
|
||||
quarter = 4;
|
||||
quarter = 4;
|
||||
}
|
||||
return 'Q' + quarter;
|
||||
}
|
||||
@ -31348,7 +31348,7 @@ function enableHoverClick($combobox, $entityId, url) {
|
||||
setAsLink($combobox, false);
|
||||
}).on('click', function() {
|
||||
var clientId = $entityId.val();
|
||||
if ($(combobox).closest('.combobox-container').hasClass('combobox-selected')) {
|
||||
if ($(combobox).closest('.combobox-container').hasClass('combobox-selected')) {
|
||||
if (parseInt(clientId) > 0) {
|
||||
window.open(url + '/' + clientId, '_blank');
|
||||
} else {
|
||||
@ -31362,10 +31362,10 @@ function enableHoverClick($combobox, $entityId, url) {
|
||||
function setAsLink($input, enable) {
|
||||
if (enable) {
|
||||
$input.css('text-decoration','underline');
|
||||
$input.css('cursor','pointer');
|
||||
$input.css('cursor','pointer');
|
||||
} else {
|
||||
$input.css('text-decoration','none');
|
||||
$input.css('cursor','text');
|
||||
$input.css('cursor','text');
|
||||
}
|
||||
}
|
||||
|
||||
@ -31396,45 +31396,45 @@ if (window.ko) {
|
||||
var id = (value && value.public_id) ? value.public_id() : (value && value.id) ? value.id() : value ? value : false;
|
||||
if (id) $(element).val(id);
|
||||
//console.log("combo-init: %s", id);
|
||||
$(element).combobox(options);
|
||||
$(element).combobox(options);
|
||||
|
||||
/*
|
||||
ko.utils.registerEventHandler(element, "change", function () {
|
||||
console.log("change: %s", $(element).val());
|
||||
//var
|
||||
console.log("change: %s", $(element).val());
|
||||
//var
|
||||
valueAccessor($(element).val());
|
||||
//$(element).combobox('refresh');
|
||||
});
|
||||
*/
|
||||
},
|
||||
update: function (element, valueAccessor) {
|
||||
update: function (element, valueAccessor) {
|
||||
var value = ko.utils.unwrapObservable(valueAccessor());
|
||||
var id = (value && value.public_id) ? value.public_id() : (value && value.id) ? value.id() : value ? value : false;
|
||||
//console.log("combo-update: %s", id);
|
||||
if (id) {
|
||||
$(element).val(id);
|
||||
if (id) {
|
||||
$(element).val(id);
|
||||
$(element).combobox('refresh');
|
||||
} else {
|
||||
$(element).combobox('clearTarget');
|
||||
$(element).combobox('clearElement');
|
||||
}
|
||||
}
|
||||
$(element).combobox('clearTarget');
|
||||
$(element).combobox('clearElement');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
ko.bindingHandlers.datePicker = {
|
||||
init: function (element, valueAccessor, allBindingsAccessor) {
|
||||
var value = ko.utils.unwrapObservable(valueAccessor());
|
||||
var value = ko.utils.unwrapObservable(valueAccessor());
|
||||
if (value) $(element).datepicker('update', value);
|
||||
$(element).change(function() {
|
||||
$(element).change(function() {
|
||||
var value = valueAccessor();
|
||||
value($(element).val());
|
||||
})
|
||||
},
|
||||
update: function (element, valueAccessor) {
|
||||
update: function (element, valueAccessor) {
|
||||
var value = ko.utils.unwrapObservable(valueAccessor());
|
||||
if (value) $(element).datepicker('update', value);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -31452,11 +31452,11 @@ function wordWrapText(value, width)
|
||||
while (j++ < lines[i].length) {
|
||||
if (lines[i].charAt(j) === ' ') space = j;
|
||||
}
|
||||
if (space == lines[i].length) space = width/6;
|
||||
if (space == lines[i].length) space = width/6;
|
||||
lines[i + 1] = lines[i].substring(space + 1) + ' ' + (lines[i + 1] || '');
|
||||
lines[i] = lines[i].substring(0, space);
|
||||
}
|
||||
|
||||
|
||||
var newValue = (lines.join("\n")).trim();
|
||||
|
||||
if (value == newValue) {
|
||||
@ -31485,14 +31485,14 @@ function populateInvoiceComboboxes(clientId, invoiceId) {
|
||||
var clientMap = {};
|
||||
var invoiceMap = {};
|
||||
var invoicesForClientMap = {};
|
||||
var $clientSelect = $('select#client');
|
||||
|
||||
var $clientSelect = $('select#client');
|
||||
|
||||
for (var i=0; i<invoices.length; i++) {
|
||||
var invoice = invoices[i];
|
||||
var client = invoice.client;
|
||||
var client = invoice.client;
|
||||
|
||||
if (!invoicesForClientMap.hasOwnProperty(client.public_id)) {
|
||||
invoicesForClientMap[client.public_id] = [];
|
||||
invoicesForClientMap[client.public_id] = [];
|
||||
}
|
||||
|
||||
invoicesForClientMap[client.public_id].push(invoice);
|
||||
@ -31504,28 +31504,28 @@ function populateInvoiceComboboxes(clientId, invoiceId) {
|
||||
clientMap[client.public_id] = client;
|
||||
}
|
||||
|
||||
$clientSelect.append(new Option('', ''));
|
||||
$clientSelect.append(new Option('', ''));
|
||||
for (var i=0; i<clients.length; i++) {
|
||||
var client = clients[i];
|
||||
$clientSelect.append(new Option(getClientDisplayName(client), client.public_id));
|
||||
}
|
||||
}
|
||||
|
||||
if (clientId) {
|
||||
$clientSelect.val(clientId);
|
||||
}
|
||||
|
||||
$clientSelect.combobox();
|
||||
$clientSelect.on('change', function(e) {
|
||||
$clientSelect.on('change', function(e) {
|
||||
var clientId = $('input[name=client]').val();
|
||||
var invoiceId = $('input[name=invoice]').val();
|
||||
var invoiceId = $('input[name=invoice]').val();
|
||||
var invoice = invoiceMap[invoiceId];
|
||||
if (invoice && invoice.client.public_id == clientId) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
setComboboxValue($('.invoice-select'), '', '');
|
||||
setComboboxValue($('.invoice-select'), '', '');
|
||||
$invoiceCombobox = $('select#invoice');
|
||||
$invoiceCombobox.find('option').remove().end().combobox('refresh');
|
||||
$invoiceCombobox.find('option').remove().end().combobox('refresh');
|
||||
$invoiceCombobox.append(new Option('', ''));
|
||||
var list = clientId ? (invoicesForClientMap.hasOwnProperty(clientId) ? invoicesForClientMap[clientId] : []) : invoices;
|
||||
for (var i=0; i<list.length; i++) {
|
||||
@ -31539,11 +31539,11 @@ function populateInvoiceComboboxes(clientId, invoiceId) {
|
||||
$('select#invoice').combobox('refresh');
|
||||
});
|
||||
|
||||
var $invoiceSelect = $('select#invoice').on('change', function(e) {
|
||||
var $invoiceSelect = $('select#invoice').on('change', function(e) {
|
||||
$clientCombobox = $('select#client');
|
||||
var invoiceId = $('input[name=invoice]').val();
|
||||
var invoiceId = $('input[name=invoice]').val();
|
||||
if (invoiceId) {
|
||||
var invoice = invoiceMap[invoiceId];
|
||||
var invoice = invoiceMap[invoiceId];
|
||||
var client = clientMap[invoice.client.public_id];
|
||||
setComboboxValue($('.client-select'), client.public_id, getClientDisplayName(client));
|
||||
if (!parseFloat($('#amount').val())) {
|
||||
@ -31552,7 +31552,7 @@ function populateInvoiceComboboxes(clientId, invoiceId) {
|
||||
}
|
||||
});
|
||||
|
||||
$invoiceSelect.combobox();
|
||||
$invoiceSelect.combobox();
|
||||
|
||||
if (invoiceId) {
|
||||
var invoice = invoiceMap[invoiceId];
|
||||
@ -31567,7 +31567,7 @@ function populateInvoiceComboboxes(clientId, invoiceId) {
|
||||
$clientSelect.trigger('change');
|
||||
} else {
|
||||
$clientSelect.trigger('change');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -31594,6 +31594,7 @@ function displayAccount(doc, invoice, x, y, layout) {
|
||||
|
||||
var data1 = [
|
||||
account.name,
|
||||
account.id_number,
|
||||
account.vat_number,
|
||||
account.work_email,
|
||||
account.work_phone
|
||||
@ -31601,10 +31602,10 @@ function displayAccount(doc, invoice, x, y, layout) {
|
||||
|
||||
var data2 = [
|
||||
concatStrings(account.address1, account.address2),
|
||||
concatStrings(account.city, account.state, account.postal_code),
|
||||
concatStrings(account.city, account.state, account.postal_code),
|
||||
account.country ? account.country.name : false,
|
||||
invoice.account.custom_value1 ? invoice.account['custom_label1'] + ' ' + invoice.account.custom_value1 : false,
|
||||
invoice.account.custom_value2 ? invoice.account['custom_label2'] + ' ' + invoice.account.custom_value2 : false,
|
||||
invoice.account.custom_value1 ? invoice.account['custom_label1'] + ' ' + invoice.account.custom_value1 : false,
|
||||
invoice.account.custom_value2 ? invoice.account['custom_label2'] + ' ' + invoice.account.custom_value2 : false,
|
||||
];
|
||||
|
||||
if (layout.singleColumn) {
|
||||
@ -31620,7 +31621,7 @@ function displayAccount(doc, invoice, x, y, layout) {
|
||||
width = Math.max(emailWidth, nameWidth, 120);
|
||||
x += width;
|
||||
|
||||
displayGrid(doc, invoice, data2, x, y, layout);
|
||||
displayGrid(doc, invoice, data2, x, y, layout);
|
||||
}
|
||||
}
|
||||
|
||||
@ -31629,16 +31630,17 @@ function displayClient(doc, invoice, x, y, layout) {
|
||||
var client = invoice.client;
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
var data = [
|
||||
getClientDisplayName(client),
|
||||
client.id_number,
|
||||
client.vat_number,
|
||||
concatStrings(client.address1, client.address2),
|
||||
concatStrings(client.city, client.state, client.postal_code),
|
||||
client.country ? client.country.name : false,
|
||||
client.contacts && getClientDisplayName(client) != client.contacts[0].email ? client.contacts[0].email : false,
|
||||
invoice.client.custom_value1 ? invoice.account['custom_client_label1'] + ' ' + invoice.client.custom_value1 : false,
|
||||
invoice.client.custom_value2 ? invoice.account['custom_client_label2'] + ' ' + invoice.client.custom_value2 : false,
|
||||
invoice.client.custom_value1 ? invoice.account['custom_client_label1'] + ' ' + invoice.client.custom_value1 : false,
|
||||
invoice.client.custom_value2 ? invoice.account['custom_client_label2'] + ' ' + invoice.client.custom_value2 : false,
|
||||
];
|
||||
return displayGrid(doc, invoice, data, x, y, layout, {hasheader:true});
|
||||
}
|
||||
@ -31664,7 +31666,7 @@ function getInvoiceDetails(invoice) {
|
||||
{'invoice_date': invoice.invoice_date},
|
||||
{'due_date': invoice.due_date},
|
||||
{'balance_due': formatMoney(invoice.balance_amount, invoice.client.currency_id)},
|
||||
];
|
||||
];
|
||||
}
|
||||
|
||||
function getInvoiceDetailsHeight(invoice, layout) {
|
||||
@ -31698,20 +31700,20 @@ function displaySubtotals(doc, layout, invoice, y, rightAlignTitleX)
|
||||
{'discount': invoice.discount_amount > 0 ? formatMoney(invoice.discount_amount, invoice.client.currency_id) : false}
|
||||
];
|
||||
|
||||
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 == '1') {
|
||||
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 == '1') {
|
||||
data.push({'custom_invoice_label1': formatMoney(invoice.custom_value1, invoice.client.currency_id) })
|
||||
}
|
||||
if (NINJA.parseFloat(invoice.custom_value2) && invoice.custom_taxes2 == '1') {
|
||||
data.push({'custom_invoice_label2': formatMoney(invoice.custom_value2, invoice.client.currency_id) })
|
||||
data.push({'custom_invoice_label2': formatMoney(invoice.custom_value2, invoice.client.currency_id) })
|
||||
}
|
||||
|
||||
data.push({'tax': invoice.tax_amount > 0 ? formatMoney(invoice.tax_amount, invoice.client.currency_id) : false});
|
||||
|
||||
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 != '1') {
|
||||
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 != '1') {
|
||||
data.push({'custom_invoice_label1': formatMoney(invoice.custom_value1, invoice.client.currency_id) })
|
||||
}
|
||||
if (NINJA.parseFloat(invoice.custom_value2) && invoice.custom_taxes2 != '1') {
|
||||
data.push({'custom_invoice_label2': formatMoney(invoice.custom_value2, invoice.client.currency_id) })
|
||||
data.push({'custom_invoice_label2': formatMoney(invoice.custom_value2, invoice.client.currency_id) })
|
||||
}
|
||||
|
||||
var paid = invoice.amount - invoice.balance;
|
||||
@ -31722,7 +31724,7 @@ function displaySubtotals(doc, layout, invoice, y, rightAlignTitleX)
|
||||
var options = {
|
||||
hasheader: true,
|
||||
rightAlignX: 550,
|
||||
rightAlignTitleX: rightAlignTitleX
|
||||
rightAlignTitleX: rightAlignTitleX
|
||||
};
|
||||
|
||||
return displayGrid(doc, invoice, data, 300, y, layout, options) + 10;
|
||||
@ -31753,7 +31755,7 @@ function displayGrid(doc, invoice, data, x, y, layout, options) {
|
||||
var origY = y;
|
||||
for (var i=0; i<data.length; i++) {
|
||||
doc.setFontType('normal');
|
||||
|
||||
|
||||
if (invoice.invoice_design_id == 1 && i > 0 && origY === layout.accountTop) {
|
||||
SetPdfColor('GrayText',doc);
|
||||
}
|
||||
@ -31767,7 +31769,7 @@ function displayGrid(doc, invoice, data, x, y, layout, options) {
|
||||
doc.setFontType('bold');
|
||||
}
|
||||
|
||||
if (typeof row === 'object') {
|
||||
if (typeof row === 'object') {
|
||||
for (var key in row) {
|
||||
if (row.hasOwnProperty(key)) {
|
||||
var value = row[key] ? row[key] + '' : false;
|
||||
@ -31775,16 +31777,16 @@ function displayGrid(doc, invoice, data, x, y, layout, options) {
|
||||
}
|
||||
if (!value) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
var marginLeft;
|
||||
if (options.rightAlignX) {
|
||||
marginLeft = options.rightAlignX - (doc.getStringUnitWidth(value) * doc.internal.getFontSize());
|
||||
marginLeft = options.rightAlignX - (doc.getStringUnitWidth(value) * doc.internal.getFontSize());
|
||||
} else {
|
||||
marginLeft = x + 80;
|
||||
}
|
||||
doc.text(marginLeft, y, value);
|
||||
|
||||
doc.text(marginLeft, y, value);
|
||||
|
||||
doc.setFontType('normal');
|
||||
if (invoice.is_quote) {
|
||||
if (key == 'invoice_number') {
|
||||
@ -31810,7 +31812,7 @@ function displayGrid(doc, invoice, data, x, y, layout, options) {
|
||||
marginLeft = x;
|
||||
}
|
||||
|
||||
doc.text(marginLeft, y, key);
|
||||
doc.text(marginLeft, y, key);
|
||||
} else {
|
||||
doc.text(x, y, row);
|
||||
}
|
||||
@ -31829,16 +31831,16 @@ function displayNotesAndTerms(doc, layout, invoice, y)
|
||||
|
||||
if (invoice.public_notes) {
|
||||
doc.text(layout.marginLeft, y, invoice.public_notes);
|
||||
y += 16 + (doc.splitTextToSize(invoice.public_notes, 300).length * doc.internal.getFontSize());
|
||||
y += 16 + (doc.splitTextToSize(invoice.public_notes, 300).length * doc.internal.getFontSize());
|
||||
}
|
||||
|
||||
|
||||
if (invoice.terms) {
|
||||
doc.setFontType("bold");
|
||||
doc.text(layout.marginLeft, y, invoiceLabels.terms);
|
||||
y += 16;
|
||||
doc.setFontType("normal");
|
||||
doc.text(layout.marginLeft, y, invoice.terms);
|
||||
y += 16 + (doc.splitTextToSize(invoice.terms, 300).length * doc.internal.getFontSize());
|
||||
y += 16 + (doc.splitTextToSize(invoice.terms, 300).length * doc.internal.getFontSize());
|
||||
}
|
||||
|
||||
return y - origY;
|
||||
@ -31855,7 +31857,7 @@ function calculateAmounts(invoice) {
|
||||
tax = parseFloat(item.tax.rate);
|
||||
} else if (item.tax_rate && parseFloat(item.tax_rate)) {
|
||||
tax = parseFloat(item.tax_rate);
|
||||
}
|
||||
}
|
||||
|
||||
var lineTotal = NINJA.parseFloat(item.cost) * NINJA.parseFloat(item.qty);
|
||||
if (tax) {
|
||||
@ -31878,11 +31880,11 @@ function calculateAmounts(invoice) {
|
||||
}
|
||||
|
||||
// custom fields with taxes
|
||||
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 == '1') {
|
||||
total += roundToTwo(invoice.custom_value1);
|
||||
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 == '1') {
|
||||
total += roundToTwo(invoice.custom_value1);
|
||||
}
|
||||
if (NINJA.parseFloat(invoice.custom_value2) && invoice.custom_taxes2 == '1') {
|
||||
total += roundToTwo(invoice.custom_value2);
|
||||
total += roundToTwo(invoice.custom_value2);
|
||||
}
|
||||
|
||||
var tax = 0;
|
||||
@ -31898,11 +31900,11 @@ function calculateAmounts(invoice) {
|
||||
}
|
||||
|
||||
// custom fields w/o with taxes
|
||||
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 != '1') {
|
||||
total += roundToTwo(invoice.custom_value1);
|
||||
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 != '1') {
|
||||
total += roundToTwo(invoice.custom_value1);
|
||||
}
|
||||
if (NINJA.parseFloat(invoice.custom_value2) && invoice.custom_taxes2 != '1') {
|
||||
total += roundToTwo(invoice.custom_value2);
|
||||
total += roundToTwo(invoice.custom_value2);
|
||||
}
|
||||
|
||||
invoice.balance_amount = roundToTwo(total) - (roundToTwo(invoice.amount) - roundToTwo(invoice.balance));
|
||||
@ -31919,7 +31921,7 @@ function getInvoiceTaxRate(invoice) {
|
||||
tax = parseFloat(invoice.tax.rate);
|
||||
} else if (invoice.tax_rate && parseFloat(invoice.tax_rate)) {
|
||||
tax = parseFloat(invoice.tax_rate);
|
||||
}
|
||||
}
|
||||
return tax;
|
||||
}
|
||||
|
||||
@ -31960,9 +31962,9 @@ function displayInvoiceItems(doc, invoice, layout) {
|
||||
var line = 1;
|
||||
var total = 0;
|
||||
var shownItem = false;
|
||||
var currencyId = invoice && invoice.client ? invoice.client.currency_id : 1;
|
||||
var currencyId = invoice && invoice.client ? invoice.client.currency_id : 1;
|
||||
var tableTop = layout.tableTop;
|
||||
var hideQuantity = invoice.account.hide_quantity == '1';
|
||||
var hideQuantity = invoice.account.hide_quantity == '1';
|
||||
|
||||
doc.setFontSize(8);
|
||||
for (var i=0; i<invoice.invoice_items.length; i++) {
|
||||
@ -31976,12 +31978,12 @@ function displayInvoiceItems(doc, invoice, layout) {
|
||||
tax = parseFloat(item.tax.rate);
|
||||
} else if (item.tax_rate && parseFloat(item.tax_rate)) {
|
||||
tax = parseFloat(item.tax_rate);
|
||||
}
|
||||
}
|
||||
|
||||
// show at most one blank line
|
||||
if (shownItem && (!cost || cost == '0.00') && !notes && !productKey) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
shownItem = true;
|
||||
|
||||
var numLines = doc.splitTextToSize(item.notes, 200).length + 2;
|
||||
@ -32029,18 +32031,18 @@ function displayInvoiceItems(doc, invoice, layout) {
|
||||
|
||||
|
||||
if (invoice.invoice_design_id == 1) {
|
||||
if (i%2 == 0) {
|
||||
if (i%2 == 0) {
|
||||
doc.setDrawColor(255,255,255);
|
||||
doc.setFillColor(246,246,246);
|
||||
doc.rect(left, top, width-left, newTop-top, 'FD');
|
||||
|
||||
doc.setLineWidth(0.3);
|
||||
doc.setLineWidth(0.3);
|
||||
doc.setDrawColor(200,200,200);
|
||||
doc.line(left, top, width, top);
|
||||
doc.line(left, newTop, width, newTop);
|
||||
doc.line(left, newTop, width, newTop);
|
||||
}
|
||||
} else if (invoice.invoice_design_id == 2) {
|
||||
if (i%2 == 0) {
|
||||
if (i%2 == 0) {
|
||||
left = 0;
|
||||
width = 1000;
|
||||
|
||||
@ -32050,17 +32052,17 @@ function displayInvoiceItems(doc, invoice, layout) {
|
||||
|
||||
}
|
||||
} else if (invoice.invoice_design_id == 5) {
|
||||
if (i%2 == 0) {
|
||||
if (i%2 == 0) {
|
||||
doc.setDrawColor(255,255,255);
|
||||
doc.setFillColor(247,247,247);
|
||||
doc.rect(left, top, width-left+17, newTop-top, 'FD');
|
||||
doc.rect(left, top, width-left+17, newTop-top, 'FD');
|
||||
} else {
|
||||
doc.setDrawColor(255,255,255);
|
||||
doc.setFillColor(232,232,232);
|
||||
doc.rect(left, top, width-left+17, newTop-top, 'FD');
|
||||
doc.rect(left, top, width-left+17, newTop-top, 'FD');
|
||||
}
|
||||
} else if (invoice.invoice_design_id == 6) {
|
||||
if (i%2 == 0) {
|
||||
if (i%2 == 0) {
|
||||
doc.setDrawColor(232,232,232);
|
||||
doc.setFillColor(232,232,232);
|
||||
doc.rect(left, top, width-left, newTop-top, 'FD');
|
||||
@ -32134,7 +32136,7 @@ function displayInvoiceItems(doc, invoice, layout) {
|
||||
|
||||
doc.line(qtyX-45, y-16,qtyX-45, y+55);
|
||||
|
||||
if (invoice.has_taxes) {
|
||||
if (invoice.has_taxes) {
|
||||
doc.line(taxX-15, y-16,taxX-15, y+55);
|
||||
}
|
||||
|
||||
@ -32186,7 +32188,7 @@ function displayInvoiceItems(doc, invoice, layout) {
|
||||
if (tax) {
|
||||
doc.text(taxX, y+2, tax+'%');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
y = tableTop + (line * layout.tableRowHeight) + (3 * layout.tablePadding);
|
||||
|
||||
@ -32460,6 +32462,6 @@ function roundToTwo(num, toString) {
|
||||
return toString ? val.toFixed(2) : val;
|
||||
}
|
||||
|
||||
function truncate(str, length) {
|
||||
function truncate(str, length) {
|
||||
return (str && str.length > length) ? (str.substr(0, length-1) + '...') : str;
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ var isIE = /*@cc_on!@*/false || !!document.documentMode; // At least IE6
|
||||
|
||||
var invoiceOld;
|
||||
function generatePDF(invoice, javascript, force) {
|
||||
invoice = calculateAmounts(invoice);
|
||||
invoice = calculateAmounts(invoice);
|
||||
var a = copyInvoice(invoice);
|
||||
var b = copyInvoice(invoiceOld);
|
||||
if (!force && _.isEqual(a, b)) {
|
||||
@ -54,7 +54,7 @@ function GetPdf(invoice, javascript){
|
||||
layout.descriptionLeft -= 20;
|
||||
layout.unitCostRight -= 40;
|
||||
layout.qtyRight -= 40;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@param orientation One of "portrait" or "landscape" (or shortcuts "p" (Default), "l")
|
||||
@ -142,24 +142,24 @@ function processVariables(str) {
|
||||
if (!str) return '';
|
||||
var variables = ['MONTH','QUARTER','YEAR'];
|
||||
for (var i=0; i<variables.length; i++) {
|
||||
var variable = variables[i];
|
||||
var variable = variables[i];
|
||||
var regexp = new RegExp(':' + variable + '[+-]?[\\d]*', 'g');
|
||||
var matches = str.match(regexp);
|
||||
var matches = str.match(regexp);
|
||||
if (!matches) {
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
for (var j=0; j<matches.length; j++) {
|
||||
var match = matches[j];
|
||||
var offset = 0;
|
||||
var offset = 0;
|
||||
if (match.split('+').length > 1) {
|
||||
offset = match.split('+')[1];
|
||||
} else if (match.split('-').length > 1) {
|
||||
offset = parseInt(match.split('-')[1]) * -1;
|
||||
}
|
||||
str = str.replace(match, getDatePart(variable, offset));
|
||||
str = str.replace(match, getDatePart(variable, offset));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
@ -182,7 +182,7 @@ function getMonth(offset) {
|
||||
var months = [ "January", "February", "March", "April", "May", "June",
|
||||
"July", "August", "September", "October", "November", "December" ];
|
||||
var month = today.getMonth();
|
||||
month = parseInt(month) + offset;
|
||||
month = parseInt(month) + offset;
|
||||
month = month % 12;
|
||||
if (month < 0) {
|
||||
month += 12;
|
||||
@ -202,7 +202,7 @@ function getQuarter(offset) {
|
||||
quarter += offset;
|
||||
quarter = quarter % 4;
|
||||
if (quarter == 0) {
|
||||
quarter = 4;
|
||||
quarter = 4;
|
||||
}
|
||||
return 'Q' + quarter;
|
||||
}
|
||||
@ -391,7 +391,7 @@ function enableHoverClick($combobox, $entityId, url) {
|
||||
setAsLink($combobox, false);
|
||||
}).on('click', function() {
|
||||
var clientId = $entityId.val();
|
||||
if ($(combobox).closest('.combobox-container').hasClass('combobox-selected')) {
|
||||
if ($(combobox).closest('.combobox-container').hasClass('combobox-selected')) {
|
||||
if (parseInt(clientId) > 0) {
|
||||
window.open(url + '/' + clientId, '_blank');
|
||||
} else {
|
||||
@ -405,10 +405,10 @@ function enableHoverClick($combobox, $entityId, url) {
|
||||
function setAsLink($input, enable) {
|
||||
if (enable) {
|
||||
$input.css('text-decoration','underline');
|
||||
$input.css('cursor','pointer');
|
||||
$input.css('cursor','pointer');
|
||||
} else {
|
||||
$input.css('text-decoration','none');
|
||||
$input.css('cursor','text');
|
||||
$input.css('cursor','text');
|
||||
}
|
||||
}
|
||||
|
||||
@ -439,45 +439,45 @@ if (window.ko) {
|
||||
var id = (value && value.public_id) ? value.public_id() : (value && value.id) ? value.id() : value ? value : false;
|
||||
if (id) $(element).val(id);
|
||||
//console.log("combo-init: %s", id);
|
||||
$(element).combobox(options);
|
||||
$(element).combobox(options);
|
||||
|
||||
/*
|
||||
ko.utils.registerEventHandler(element, "change", function () {
|
||||
console.log("change: %s", $(element).val());
|
||||
//var
|
||||
console.log("change: %s", $(element).val());
|
||||
//var
|
||||
valueAccessor($(element).val());
|
||||
//$(element).combobox('refresh');
|
||||
});
|
||||
*/
|
||||
},
|
||||
update: function (element, valueAccessor) {
|
||||
update: function (element, valueAccessor) {
|
||||
var value = ko.utils.unwrapObservable(valueAccessor());
|
||||
var id = (value && value.public_id) ? value.public_id() : (value && value.id) ? value.id() : value ? value : false;
|
||||
//console.log("combo-update: %s", id);
|
||||
if (id) {
|
||||
$(element).val(id);
|
||||
if (id) {
|
||||
$(element).val(id);
|
||||
$(element).combobox('refresh');
|
||||
} else {
|
||||
$(element).combobox('clearTarget');
|
||||
$(element).combobox('clearElement');
|
||||
}
|
||||
}
|
||||
$(element).combobox('clearTarget');
|
||||
$(element).combobox('clearElement');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
ko.bindingHandlers.datePicker = {
|
||||
init: function (element, valueAccessor, allBindingsAccessor) {
|
||||
var value = ko.utils.unwrapObservable(valueAccessor());
|
||||
var value = ko.utils.unwrapObservable(valueAccessor());
|
||||
if (value) $(element).datepicker('update', value);
|
||||
$(element).change(function() {
|
||||
$(element).change(function() {
|
||||
var value = valueAccessor();
|
||||
value($(element).val());
|
||||
})
|
||||
},
|
||||
update: function (element, valueAccessor) {
|
||||
update: function (element, valueAccessor) {
|
||||
var value = ko.utils.unwrapObservable(valueAccessor());
|
||||
if (value) $(element).datepicker('update', value);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -495,11 +495,11 @@ function wordWrapText(value, width)
|
||||
while (j++ < lines[i].length) {
|
||||
if (lines[i].charAt(j) === ' ') space = j;
|
||||
}
|
||||
if (space == lines[i].length) space = width/6;
|
||||
if (space == lines[i].length) space = width/6;
|
||||
lines[i + 1] = lines[i].substring(space + 1) + ' ' + (lines[i + 1] || '');
|
||||
lines[i] = lines[i].substring(0, space);
|
||||
}
|
||||
|
||||
|
||||
var newValue = (lines.join("\n")).trim();
|
||||
|
||||
if (value == newValue) {
|
||||
@ -528,14 +528,14 @@ function populateInvoiceComboboxes(clientId, invoiceId) {
|
||||
var clientMap = {};
|
||||
var invoiceMap = {};
|
||||
var invoicesForClientMap = {};
|
||||
var $clientSelect = $('select#client');
|
||||
|
||||
var $clientSelect = $('select#client');
|
||||
|
||||
for (var i=0; i<invoices.length; i++) {
|
||||
var invoice = invoices[i];
|
||||
var client = invoice.client;
|
||||
var client = invoice.client;
|
||||
|
||||
if (!invoicesForClientMap.hasOwnProperty(client.public_id)) {
|
||||
invoicesForClientMap[client.public_id] = [];
|
||||
invoicesForClientMap[client.public_id] = [];
|
||||
}
|
||||
|
||||
invoicesForClientMap[client.public_id].push(invoice);
|
||||
@ -547,28 +547,28 @@ function populateInvoiceComboboxes(clientId, invoiceId) {
|
||||
clientMap[client.public_id] = client;
|
||||
}
|
||||
|
||||
$clientSelect.append(new Option('', ''));
|
||||
$clientSelect.append(new Option('', ''));
|
||||
for (var i=0; i<clients.length; i++) {
|
||||
var client = clients[i];
|
||||
$clientSelect.append(new Option(getClientDisplayName(client), client.public_id));
|
||||
}
|
||||
}
|
||||
|
||||
if (clientId) {
|
||||
$clientSelect.val(clientId);
|
||||
}
|
||||
|
||||
$clientSelect.combobox();
|
||||
$clientSelect.on('change', function(e) {
|
||||
$clientSelect.on('change', function(e) {
|
||||
var clientId = $('input[name=client]').val();
|
||||
var invoiceId = $('input[name=invoice]').val();
|
||||
var invoiceId = $('input[name=invoice]').val();
|
||||
var invoice = invoiceMap[invoiceId];
|
||||
if (invoice && invoice.client.public_id == clientId) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
setComboboxValue($('.invoice-select'), '', '');
|
||||
setComboboxValue($('.invoice-select'), '', '');
|
||||
$invoiceCombobox = $('select#invoice');
|
||||
$invoiceCombobox.find('option').remove().end().combobox('refresh');
|
||||
$invoiceCombobox.find('option').remove().end().combobox('refresh');
|
||||
$invoiceCombobox.append(new Option('', ''));
|
||||
var list = clientId ? (invoicesForClientMap.hasOwnProperty(clientId) ? invoicesForClientMap[clientId] : []) : invoices;
|
||||
for (var i=0; i<list.length; i++) {
|
||||
@ -582,11 +582,11 @@ function populateInvoiceComboboxes(clientId, invoiceId) {
|
||||
$('select#invoice').combobox('refresh');
|
||||
});
|
||||
|
||||
var $invoiceSelect = $('select#invoice').on('change', function(e) {
|
||||
var $invoiceSelect = $('select#invoice').on('change', function(e) {
|
||||
$clientCombobox = $('select#client');
|
||||
var invoiceId = $('input[name=invoice]').val();
|
||||
var invoiceId = $('input[name=invoice]').val();
|
||||
if (invoiceId) {
|
||||
var invoice = invoiceMap[invoiceId];
|
||||
var invoice = invoiceMap[invoiceId];
|
||||
var client = clientMap[invoice.client.public_id];
|
||||
setComboboxValue($('.client-select'), client.public_id, getClientDisplayName(client));
|
||||
if (!parseFloat($('#amount').val())) {
|
||||
@ -595,7 +595,7 @@ function populateInvoiceComboboxes(clientId, invoiceId) {
|
||||
}
|
||||
});
|
||||
|
||||
$invoiceSelect.combobox();
|
||||
$invoiceSelect.combobox();
|
||||
|
||||
if (invoiceId) {
|
||||
var invoice = invoiceMap[invoiceId];
|
||||
@ -610,7 +610,7 @@ function populateInvoiceComboboxes(clientId, invoiceId) {
|
||||
$clientSelect.trigger('change');
|
||||
} else {
|
||||
$clientSelect.trigger('change');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -637,6 +637,7 @@ function displayAccount(doc, invoice, x, y, layout) {
|
||||
|
||||
var data1 = [
|
||||
account.name,
|
||||
account.id_number,
|
||||
account.vat_number,
|
||||
account.work_email,
|
||||
account.work_phone
|
||||
@ -644,10 +645,10 @@ function displayAccount(doc, invoice, x, y, layout) {
|
||||
|
||||
var data2 = [
|
||||
concatStrings(account.address1, account.address2),
|
||||
concatStrings(account.city, account.state, account.postal_code),
|
||||
concatStrings(account.city, account.state, account.postal_code),
|
||||
account.country ? account.country.name : false,
|
||||
invoice.account.custom_value1 ? invoice.account['custom_label1'] + ' ' + invoice.account.custom_value1 : false,
|
||||
invoice.account.custom_value2 ? invoice.account['custom_label2'] + ' ' + invoice.account.custom_value2 : false,
|
||||
invoice.account.custom_value1 ? invoice.account['custom_label1'] + ' ' + invoice.account.custom_value1 : false,
|
||||
invoice.account.custom_value2 ? invoice.account['custom_label2'] + ' ' + invoice.account.custom_value2 : false,
|
||||
];
|
||||
|
||||
if (layout.singleColumn) {
|
||||
@ -663,7 +664,7 @@ function displayAccount(doc, invoice, x, y, layout) {
|
||||
width = Math.max(emailWidth, nameWidth, 120);
|
||||
x += width;
|
||||
|
||||
displayGrid(doc, invoice, data2, x, y, layout);
|
||||
displayGrid(doc, invoice, data2, x, y, layout);
|
||||
}
|
||||
}
|
||||
|
||||
@ -672,16 +673,17 @@ function displayClient(doc, invoice, x, y, layout) {
|
||||
var client = invoice.client;
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
var data = [
|
||||
getClientDisplayName(client),
|
||||
client.id_number,
|
||||
client.vat_number,
|
||||
concatStrings(client.address1, client.address2),
|
||||
concatStrings(client.city, client.state, client.postal_code),
|
||||
client.country ? client.country.name : false,
|
||||
client.contacts && getClientDisplayName(client) != client.contacts[0].email ? client.contacts[0].email : false,
|
||||
invoice.client.custom_value1 ? invoice.account['custom_client_label1'] + ' ' + invoice.client.custom_value1 : false,
|
||||
invoice.client.custom_value2 ? invoice.account['custom_client_label2'] + ' ' + invoice.client.custom_value2 : false,
|
||||
invoice.client.custom_value1 ? invoice.account['custom_client_label1'] + ' ' + invoice.client.custom_value1 : false,
|
||||
invoice.client.custom_value2 ? invoice.account['custom_client_label2'] + ' ' + invoice.client.custom_value2 : false,
|
||||
];
|
||||
return displayGrid(doc, invoice, data, x, y, layout, {hasheader:true});
|
||||
}
|
||||
@ -707,7 +709,7 @@ function getInvoiceDetails(invoice) {
|
||||
{'invoice_date': invoice.invoice_date},
|
||||
{'due_date': invoice.due_date},
|
||||
{'balance_due': formatMoney(invoice.balance_amount, invoice.client.currency_id)},
|
||||
];
|
||||
];
|
||||
}
|
||||
|
||||
function getInvoiceDetailsHeight(invoice, layout) {
|
||||
@ -741,20 +743,20 @@ function displaySubtotals(doc, layout, invoice, y, rightAlignTitleX)
|
||||
{'discount': invoice.discount_amount > 0 ? formatMoney(invoice.discount_amount, invoice.client.currency_id) : false}
|
||||
];
|
||||
|
||||
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 == '1') {
|
||||
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 == '1') {
|
||||
data.push({'custom_invoice_label1': formatMoney(invoice.custom_value1, invoice.client.currency_id) })
|
||||
}
|
||||
if (NINJA.parseFloat(invoice.custom_value2) && invoice.custom_taxes2 == '1') {
|
||||
data.push({'custom_invoice_label2': formatMoney(invoice.custom_value2, invoice.client.currency_id) })
|
||||
data.push({'custom_invoice_label2': formatMoney(invoice.custom_value2, invoice.client.currency_id) })
|
||||
}
|
||||
|
||||
data.push({'tax': invoice.tax_amount > 0 ? formatMoney(invoice.tax_amount, invoice.client.currency_id) : false});
|
||||
|
||||
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 != '1') {
|
||||
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 != '1') {
|
||||
data.push({'custom_invoice_label1': formatMoney(invoice.custom_value1, invoice.client.currency_id) })
|
||||
}
|
||||
if (NINJA.parseFloat(invoice.custom_value2) && invoice.custom_taxes2 != '1') {
|
||||
data.push({'custom_invoice_label2': formatMoney(invoice.custom_value2, invoice.client.currency_id) })
|
||||
data.push({'custom_invoice_label2': formatMoney(invoice.custom_value2, invoice.client.currency_id) })
|
||||
}
|
||||
|
||||
var paid = invoice.amount - invoice.balance;
|
||||
@ -765,7 +767,7 @@ function displaySubtotals(doc, layout, invoice, y, rightAlignTitleX)
|
||||
var options = {
|
||||
hasheader: true,
|
||||
rightAlignX: 550,
|
||||
rightAlignTitleX: rightAlignTitleX
|
||||
rightAlignTitleX: rightAlignTitleX
|
||||
};
|
||||
|
||||
return displayGrid(doc, invoice, data, 300, y, layout, options) + 10;
|
||||
@ -796,7 +798,7 @@ function displayGrid(doc, invoice, data, x, y, layout, options) {
|
||||
var origY = y;
|
||||
for (var i=0; i<data.length; i++) {
|
||||
doc.setFontType('normal');
|
||||
|
||||
|
||||
if (invoice.invoice_design_id == 1 && i > 0 && origY === layout.accountTop) {
|
||||
SetPdfColor('GrayText',doc);
|
||||
}
|
||||
@ -810,7 +812,7 @@ function displayGrid(doc, invoice, data, x, y, layout, options) {
|
||||
doc.setFontType('bold');
|
||||
}
|
||||
|
||||
if (typeof row === 'object') {
|
||||
if (typeof row === 'object') {
|
||||
for (var key in row) {
|
||||
if (row.hasOwnProperty(key)) {
|
||||
var value = row[key] ? row[key] + '' : false;
|
||||
@ -818,16 +820,16 @@ function displayGrid(doc, invoice, data, x, y, layout, options) {
|
||||
}
|
||||
if (!value) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
var marginLeft;
|
||||
if (options.rightAlignX) {
|
||||
marginLeft = options.rightAlignX - (doc.getStringUnitWidth(value) * doc.internal.getFontSize());
|
||||
marginLeft = options.rightAlignX - (doc.getStringUnitWidth(value) * doc.internal.getFontSize());
|
||||
} else {
|
||||
marginLeft = x + 80;
|
||||
}
|
||||
doc.text(marginLeft, y, value);
|
||||
|
||||
doc.text(marginLeft, y, value);
|
||||
|
||||
doc.setFontType('normal');
|
||||
if (invoice.is_quote) {
|
||||
if (key == 'invoice_number') {
|
||||
@ -853,7 +855,7 @@ function displayGrid(doc, invoice, data, x, y, layout, options) {
|
||||
marginLeft = x;
|
||||
}
|
||||
|
||||
doc.text(marginLeft, y, key);
|
||||
doc.text(marginLeft, y, key);
|
||||
} else {
|
||||
doc.text(x, y, row);
|
||||
}
|
||||
@ -872,16 +874,16 @@ function displayNotesAndTerms(doc, layout, invoice, y)
|
||||
|
||||
if (invoice.public_notes) {
|
||||
doc.text(layout.marginLeft, y, invoice.public_notes);
|
||||
y += 16 + (doc.splitTextToSize(invoice.public_notes, 300).length * doc.internal.getFontSize());
|
||||
y += 16 + (doc.splitTextToSize(invoice.public_notes, 300).length * doc.internal.getFontSize());
|
||||
}
|
||||
|
||||
|
||||
if (invoice.terms) {
|
||||
doc.setFontType("bold");
|
||||
doc.text(layout.marginLeft, y, invoiceLabels.terms);
|
||||
y += 16;
|
||||
doc.setFontType("normal");
|
||||
doc.text(layout.marginLeft, y, invoice.terms);
|
||||
y += 16 + (doc.splitTextToSize(invoice.terms, 300).length * doc.internal.getFontSize());
|
||||
y += 16 + (doc.splitTextToSize(invoice.terms, 300).length * doc.internal.getFontSize());
|
||||
}
|
||||
|
||||
return y - origY;
|
||||
@ -898,7 +900,7 @@ function calculateAmounts(invoice) {
|
||||
tax = parseFloat(item.tax.rate);
|
||||
} else if (item.tax_rate && parseFloat(item.tax_rate)) {
|
||||
tax = parseFloat(item.tax_rate);
|
||||
}
|
||||
}
|
||||
|
||||
var lineTotal = NINJA.parseFloat(item.cost) * NINJA.parseFloat(item.qty);
|
||||
if (tax) {
|
||||
@ -921,11 +923,11 @@ function calculateAmounts(invoice) {
|
||||
}
|
||||
|
||||
// custom fields with taxes
|
||||
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 == '1') {
|
||||
total += roundToTwo(invoice.custom_value1);
|
||||
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 == '1') {
|
||||
total += roundToTwo(invoice.custom_value1);
|
||||
}
|
||||
if (NINJA.parseFloat(invoice.custom_value2) && invoice.custom_taxes2 == '1') {
|
||||
total += roundToTwo(invoice.custom_value2);
|
||||
total += roundToTwo(invoice.custom_value2);
|
||||
}
|
||||
|
||||
var tax = 0;
|
||||
@ -941,11 +943,11 @@ function calculateAmounts(invoice) {
|
||||
}
|
||||
|
||||
// custom fields w/o with taxes
|
||||
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 != '1') {
|
||||
total += roundToTwo(invoice.custom_value1);
|
||||
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 != '1') {
|
||||
total += roundToTwo(invoice.custom_value1);
|
||||
}
|
||||
if (NINJA.parseFloat(invoice.custom_value2) && invoice.custom_taxes2 != '1') {
|
||||
total += roundToTwo(invoice.custom_value2);
|
||||
total += roundToTwo(invoice.custom_value2);
|
||||
}
|
||||
|
||||
invoice.balance_amount = roundToTwo(total) - (roundToTwo(invoice.amount) - roundToTwo(invoice.balance));
|
||||
@ -962,7 +964,7 @@ function getInvoiceTaxRate(invoice) {
|
||||
tax = parseFloat(invoice.tax.rate);
|
||||
} else if (invoice.tax_rate && parseFloat(invoice.tax_rate)) {
|
||||
tax = parseFloat(invoice.tax_rate);
|
||||
}
|
||||
}
|
||||
return tax;
|
||||
}
|
||||
|
||||
@ -1003,9 +1005,9 @@ function displayInvoiceItems(doc, invoice, layout) {
|
||||
var line = 1;
|
||||
var total = 0;
|
||||
var shownItem = false;
|
||||
var currencyId = invoice && invoice.client ? invoice.client.currency_id : 1;
|
||||
var currencyId = invoice && invoice.client ? invoice.client.currency_id : 1;
|
||||
var tableTop = layout.tableTop;
|
||||
var hideQuantity = invoice.account.hide_quantity == '1';
|
||||
var hideQuantity = invoice.account.hide_quantity == '1';
|
||||
|
||||
doc.setFontSize(8);
|
||||
for (var i=0; i<invoice.invoice_items.length; i++) {
|
||||
@ -1019,12 +1021,12 @@ function displayInvoiceItems(doc, invoice, layout) {
|
||||
tax = parseFloat(item.tax.rate);
|
||||
} else if (item.tax_rate && parseFloat(item.tax_rate)) {
|
||||
tax = parseFloat(item.tax_rate);
|
||||
}
|
||||
}
|
||||
|
||||
// show at most one blank line
|
||||
if (shownItem && (!cost || cost == '0.00') && !notes && !productKey) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
shownItem = true;
|
||||
|
||||
var numLines = doc.splitTextToSize(item.notes, 200).length + 2;
|
||||
@ -1072,18 +1074,18 @@ function displayInvoiceItems(doc, invoice, layout) {
|
||||
|
||||
|
||||
if (invoice.invoice_design_id == 1) {
|
||||
if (i%2 == 0) {
|
||||
if (i%2 == 0) {
|
||||
doc.setDrawColor(255,255,255);
|
||||
doc.setFillColor(246,246,246);
|
||||
doc.rect(left, top, width-left, newTop-top, 'FD');
|
||||
|
||||
doc.setLineWidth(0.3);
|
||||
doc.setLineWidth(0.3);
|
||||
doc.setDrawColor(200,200,200);
|
||||
doc.line(left, top, width, top);
|
||||
doc.line(left, newTop, width, newTop);
|
||||
doc.line(left, newTop, width, newTop);
|
||||
}
|
||||
} else if (invoice.invoice_design_id == 2) {
|
||||
if (i%2 == 0) {
|
||||
if (i%2 == 0) {
|
||||
left = 0;
|
||||
width = 1000;
|
||||
|
||||
@ -1093,17 +1095,17 @@ function displayInvoiceItems(doc, invoice, layout) {
|
||||
|
||||
}
|
||||
} else if (invoice.invoice_design_id == 5) {
|
||||
if (i%2 == 0) {
|
||||
if (i%2 == 0) {
|
||||
doc.setDrawColor(255,255,255);
|
||||
doc.setFillColor(247,247,247);
|
||||
doc.rect(left, top, width-left+17, newTop-top, 'FD');
|
||||
doc.rect(left, top, width-left+17, newTop-top, 'FD');
|
||||
} else {
|
||||
doc.setDrawColor(255,255,255);
|
||||
doc.setFillColor(232,232,232);
|
||||
doc.rect(left, top, width-left+17, newTop-top, 'FD');
|
||||
doc.rect(left, top, width-left+17, newTop-top, 'FD');
|
||||
}
|
||||
} else if (invoice.invoice_design_id == 6) {
|
||||
if (i%2 == 0) {
|
||||
if (i%2 == 0) {
|
||||
doc.setDrawColor(232,232,232);
|
||||
doc.setFillColor(232,232,232);
|
||||
doc.rect(left, top, width-left, newTop-top, 'FD');
|
||||
@ -1177,7 +1179,7 @@ function displayInvoiceItems(doc, invoice, layout) {
|
||||
|
||||
doc.line(qtyX-45, y-16,qtyX-45, y+55);
|
||||
|
||||
if (invoice.has_taxes) {
|
||||
if (invoice.has_taxes) {
|
||||
doc.line(taxX-15, y-16,taxX-15, y+55);
|
||||
}
|
||||
|
||||
@ -1229,7 +1231,7 @@ function displayInvoiceItems(doc, invoice, layout) {
|
||||
if (tax) {
|
||||
doc.text(taxX, y+2, tax+'%');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
y = tableTop + (line * layout.tableRowHeight) + (3 * layout.tablePadding);
|
||||
|
||||
@ -1503,6 +1505,6 @@ function roundToTwo(num, toString) {
|
||||
return toString ? val.toFixed(2) : val;
|
||||
}
|
||||
|
||||
function truncate(str, length) {
|
||||
function truncate(str, length) {
|
||||
return (str && str.length > length) ? (str.substr(0, length-1) + '...') : str;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user