Bug fixes

This commit is contained in:
Hillel Coren 2014-04-14 14:33:43 +03:00
parent 8bbe164505
commit 45ed680c77
6 changed files with 125 additions and 71 deletions

View File

@ -24,8 +24,18 @@ App::before(function($request)
if (Input::has('lang')) if (Input::has('lang'))
{ {
$locale = Input::get('lang'); $locale = Input::get('lang');
Session::set(SESSION_LOCALE, $locale);
App::setLocale($locale); App::setLocale($locale);
Session::set(SESSION_LOCALE, $locale);
if (Auth::check())
{
if ($language = Language::whereLocale($locale)->first())
{
$account = Auth::user()->account;
$account->language_id = $language->id;
$account->save();
}
}
} }
else if (Auth::check()) else if (Auth::check())
{ {

View File

@ -24,9 +24,7 @@ class AccountRepository
if (Session::has(SESSION_LOCALE)) if (Session::has(SESSION_LOCALE))
{ {
$locale = Session::get(SESSION_LOCALE); $locale = Session::get(SESSION_LOCALE);
$language = Language::whereLocale($locale)->first(); if ($language = Language::whereLocale($locale)->first())
if ($language)
{ {
$account->language_id = $language->id; $account->language_id = $language->id;
} }

View File

@ -606,17 +606,12 @@
}); });
function applyComboboxListeners() { function applyComboboxListeners() {
$('.invoice-table input, .invoice-table select, .invoice-table textarea').on('blur', function() { var selectorStr = '.invoice-table input, .invoice-table select, .invoice-table textarea';
//if (value != $(this).val()) refreshPDF(); $(selectorStr).off('blur').on('blur', function() {
refreshPDF(); refreshPDF();
}); });
var value; $('.datalist').on('input', function() {
$('.datalist').on('focus', function() {
value = $(this).val();
}).on('blur', function() {
if (value != $(this).val()) refreshPDF();
}).on('input', function() {
var key = $(this).val(); var key = $(this).val();
for (var i=0; i<products.length; i++) { for (var i=0; i<products.length; i++) {
var product = products[i]; var product = products[i];
@ -633,7 +628,7 @@
function createInvoiceModel() { function createInvoiceModel() {
var invoice = ko.toJS(model).invoice; var invoice = ko.toJS(model).invoice;
invoice.is_pro = {{ Auth::user()->isPro() }}; invoice.is_pro = {{ Auth::user()->isPro() ? 'true' : 'false' }};
@if (file_exists($account->getLogoPath())) @if (file_exists($account->getLogoPath()))
invoice.image = "{{ HTML::image_data($account->getLogoPath()) }}"; invoice.image = "{{ HTML::image_data($account->getLogoPath()) }}";
@ -641,17 +636,18 @@
invoice.imageHeight = {{ $account->getLogoHeight() }}; invoice.imageHeight = {{ $account->getLogoHeight() }};
@endif @endif
invoice.imageLogo1 = "{{ HTML::image_data('images/report_logo1.jpg') }}"; window.logoImages = {};
invoice.imageLogoWidth1 =120; logoImages.imageLogo1 = "{{ HTML::image_data('images/report_logo1.jpg') }}";
invoice.imageLogoHeight1 = 40 logoImages.imageLogoWidth1 =120;
logoImages.imageLogoHeight1 = 40
invoice.imageLogo2 = "{{ HTML::image_data('images/report_logo2.jpg') }}"; logoImages.imageLogo2 = "{{ HTML::image_data('images/report_logo2.jpg') }}";
invoice.imageLogoWidth2 =325/2; logoImages.imageLogoWidth2 =325/2;
invoice.imageLogoHeight2 = 81/2; logoImages.imageLogoHeight2 = 81/2;
invoice.imageLogo3 = "{{ HTML::image_data('images/report_logo3.jpg') }}"; logoImages.imageLogo3 = "{{ HTML::image_data('images/report_logo3.jpg') }}";
invoice.imageLogoWidth3 =325/2; logoImages.imageLogoWidth3 =325/2;
invoice.imageLogoHeight3 = 81/2; logoImages.imageLogoHeight3 = 81/2;
return invoice; return invoice;
@ -672,44 +668,48 @@
var isRefreshing = false; var isRefreshing = false;
var needsRefresh = false; var needsRefresh = false;
function getPDFString() { function getPDFString() {
var invoice = createInvoiceModel(); var invoice = createInvoiceModel();
var doc = generatePDF(invoice, invoiceLabels); var doc = generatePDF(invoice, invoiceLabels);
if (!doc) return; if (!doc) return;
return doc.output('datauristring'); return doc.output('datauristring');
} }
function refreshPDF() { function refreshPDF() {
console.log('refreshPDF');
if ({{ Auth::user()->force_pdfjs ? 'false' : 'true' }} && (isFirefox || (isChrome && !isChromium))) { if ({{ Auth::user()->force_pdfjs ? 'false' : 'true' }} && (isFirefox || (isChrome && !isChromium))) {
var string = getPDFString(); var string = getPDFString();
if (!string) return;
$('#theFrame').attr('src', string).show(); $('#theFrame').attr('src', string).show();
} else { } else {
if (isRefreshing) { if (isRefreshing) {
needsRefresh = true; needsRefresh = true;
return; return;
} }
isRefreshing = true;
var string = getPDFString(); var string = getPDFString();
if (!string) return;
isRefreshing = true;
var pdfAsArray = convertDataURIToBinary(string); var pdfAsArray = convertDataURIToBinary(string);
PDFJS.getDocument(pdfAsArray).then(function getPdfHelloWorld(pdf) { PDFJS.getDocument(pdfAsArray).then(function getPdfHelloWorld(pdf) {
pdf.getPage(1).then(function getPageHelloWorld(page) { pdf.getPage(1).then(function getPageHelloWorld(page) {
var scale = 1.5; var scale = 1.5;
var viewport = page.getViewport(scale); var viewport = page.getViewport(scale);
var canvas = document.getElementById('theCanvas'); var canvas = document.getElementById('theCanvas');
var context = canvas.getContext('2d'); var context = canvas.getContext('2d');
canvas.height = viewport.height; canvas.height = viewport.height;
canvas.width = viewport.width; canvas.width = viewport.width;
page.render({canvasContext: context, viewport: viewport}); page.render({canvasContext: context, viewport: viewport});
$('#theCanvas').show(); $('#theCanvas').show();
isRefreshing = false; isRefreshing = false;
if (needsRefresh) { if (needsRefresh) {
needsRefresh = false; needsRefresh = false;
refreshPDF(); refreshPDF();
} }
}); });
}); });
} }
} }

View File

@ -29,18 +29,19 @@
$(function() { $(function() {
window.invoice = {{ $invoice->toJson() }}; window.invoice = {{ $invoice->toJson() }};
window.logoImages = {};
invoice.imageLogo1 = "{{ HTML::image_data('images/report_logo1.jpg') }}"; logoImages.imageLogo1 = "{{ HTML::image_data('images/report_logo1.jpg') }}";
invoice.imageLogoWidth1 =120; logoImages.imageLogoWidth1 =120;
invoice.imageLogoHeight1 = 40 logoImages.imageLogoHeight1 = 40
invoice.imageLogo2 = "{{ HTML::image_data('images/report_logo2.jpg') }}"; logoImages.imageLogo2 = "{{ HTML::image_data('images/report_logo2.jpg') }}";
invoice.imageLogoWidth2 =325/2; logoImages.imageLogoWidth2 =325/2;
invoice.imageLogoHeight2 = 81/2; logoImages.imageLogoHeight2 = 81/2;
invoice.imageLogo3 = "{{ HTML::image_data('images/report_logo3.jpg') }}"; logoImages.imageLogo3 = "{{ HTML::image_data('images/report_logo3.jpg') }}";
invoice.imageLogoWidth3 =325/2; logoImages.imageLogoWidth3 =325/2;
invoice.imageLogoHeight3 = 81/2; logoImages.imageLogoHeight3 = 81/2;
@if (file_exists($invoice->client->account->getLogoPath())) @if (file_exists($invoice->client->account->getLogoPath()))
invoice.image = "{{ HTML::image_data($invoice->client->account->getLogoPath()) }}"; invoice.image = "{{ HTML::image_data($invoice->client->account->getLogoPath()) }}";
@ -50,7 +51,7 @@
var doc = generatePDF(invoice, true); var doc = generatePDF(invoice, true);
if (!doc) return; if (!doc) return;
var string = doc.output('datauristring'); var string = doc.output('datauristring');
if (isFirefox || (isChrome && !isChromium)) { if (isFirefox || (isChrome && !isChromium)) {
$('#theFrame').attr('src', string).show(); $('#theFrame').attr('src', string).show();
} else { } else {

View File

@ -75,7 +75,7 @@ th:last-child {
tr {border: none;} tr {border: none;}
th {border-left: 1px solid #d26b26; } th {border-left: 1px solid #d26b26; }
.table>thead>tr>th, .table>tbody>tr>th, .table>tfoot>tr>th, .table>thead>tr>td, .table>tbody>tr>td, .table>tfoot>tr>td { .table>thead>tr>th, .table>tbody>tr>th, .table>tfoot>tr>th, .table>thead>tr>td, .table>tbody>tr>td, .table>tfoot>tr>td {
vertical-align: top; vertical-align: middle;
border-top: none; border-top: none;
border-bottom: 1px solid #dfe0e1; border-bottom: 1px solid #dfe0e1;
} }

View File

@ -106,13 +106,35 @@ function GetReportTemplate4(doc, invoice, layout, checkMath) {
} }
var invoiceOld;
function generatePDF(invoice, checkMath) { function generatePDF(invoice, checkMath) {
invoice = calculateAmounts(invoice); console.log('generatePDF: %s', (JSON.stringify(invoice) == invoiceOld));
report_id=invoice.invoice_design_id; //console.log(JSON.stringify(invoice));
doc= GetPdf(invoice,checkMath,report_id); //console.log(invoiceOld);
return doc; invoice = calculateAmounts(invoice);
var a = copyInvoice(invoice);
var b = copyInvoice(invoiceOld);
console.log(JSON.stringify(a));
console.log(JSON.stringify(b));
if (_.isEqual(a, b)) {
return;
}
invoiceOld = invoice;
report_id = invoice.invoice_design_id;
doc = GetPdf(invoice, checkMath, report_id);
return doc;
} }
function copyInvoice(orig) {
if (!orig) return false;
var copy = JSON.stringify(orig);
//console.log(copy);
var copy = JSON.parse(copy);
//console.log(copy);
return copy;
}
/* Handle converting variables in the invoices (ie, MONTH+1) */ /* Handle converting variables in the invoices (ie, MONTH+1) */
function processVariables(str) { function processVariables(str) {
@ -689,11 +711,11 @@ function GetReportTemplate1(doc, invoice, layout, checkMath)
doc.addImage(invoice.image, 'JPEG', layout.marginLeft, 30); doc.addImage(invoice.image, 'JPEG', layout.marginLeft, 30);
} }
if (!invoice.is_pro && invoice.imageLogo1) if (!invoice.is_pro && logoImages.imageLogo1)
{ {
pageHeight=820; pageHeight=820;
y=pageHeight-invoice.imageLogoHeight1; y=pageHeight-logoImages.imageLogoHeight1;
doc.addImage(invoice.imageLogo1, 'JPEG', layout.marginLeft, y, invoice.imageLogoWidth1, invoice.imageLogoHeight1); doc.addImage(logoImages.imageLogo1, 'JPEG', layout.marginLeft, y, logoImages.imageLogoWidth1, logoImages.imageLogoHeight1);
} }
@ -1044,15 +1066,15 @@ function Report2AddFooter (invoice,doc)
doc.rect(x1, y1, w2, h2, 'FD'); doc.rect(x1, y1, w2, h2, 'FD');
if (!invoice.is_pro && invoice.imageLogo2) if (!invoice.is_pro && logoImages.imageLogo2)
{ {
pageHeight=820; pageHeight=820;
var left = 250;//headerRight ; var left = 250;//headerRight ;
y=pageHeight-invoice.imageLogoHeight2; y=pageHeight-logoImages.imageLogoHeight2;
var headerRight=370; var headerRight=370;
var left = headerRight - invoice.imageLogoWidth2; var left = headerRight - logoImages.imageLogoWidth2;
doc.addImage(invoice.imageLogo2, 'JPEG', left, y, invoice.imageLogoWidth2, invoice.imageLogoHeight2); doc.addImage(logoImages.imageLogo2, 'JPEG', left, y, logoImages.imageLogoWidth2, logoImages.imageLogoHeight2);
} }
@ -1085,17 +1107,15 @@ function Report3AddFooter (invoice, account, doc, layout)
doc.rect(x1, y1, w2, h2, 'FD'); doc.rect(x1, y1, w2, h2, 'FD');
if (!invoice.is_pro && invoice.imageLogo3) if (!invoice.is_pro && logoImages.imageLogo3)
{ {
pageHeight=820; pageHeight=820;
// var left = 25;//250;//headerRight ; // var left = 25;//250;//headerRight ;
y=pageHeight-invoice.imageLogoHeight3; y=pageHeight-logoImages.imageLogoHeight3;
//var headerRight=370; //var headerRight=370;
//var left = headerRight - invoice.imageLogoWidth3; //var left = headerRight - invoice.imageLogoWidth3;
doc.addImage(invoice.imageLogo3, 'JPEG', 40, y, invoice.imageLogoWidth3, invoice.imageLogoHeight3); doc.addImage(logoImages.imageLogo3, 'JPEG', 40, y, logoImages.imageLogoWidth3, logoImages.imageLogoHeight3);
} }
@ -1227,12 +1247,12 @@ function Report3AddHeader (invoice,account,doc)
function Report1AddNewPage(invoice,account,doc) function Report1AddNewPage(invoice,account,doc)
{ {
doc.addPage(); doc.addPage();
if (invoice.imageLogo1) if (logoImages.imageLogo1)
{ {
pageHeight=820; pageHeight=820;
y=pageHeight-invoice.imageLogoHeight1; y=pageHeight-logoImages.imageLogoHeight1;
var left = 20;//headerRight - invoice.imageLogoWidth1; var left = 20;//headerRight - invoice.imageLogoWidth1;
doc.addImage(invoice.imageLogo1, 'JPEG', left, y, invoice.imageLogoWidth1, invoice.imageLogoHeight1); doc.addImage(logoImages.imageLogo1, 'JPEG', left, y, logoImages.imageLogoWidth1, logoImages.imageLogoHeight1);
} }
@ -1649,4 +1669,29 @@ function displayInvoiceItems(doc, invoice, layout) {
} }
return y; return y;
}
// http://stackoverflow.com/questions/1068834/object-comparison-in-javascript
function objectEquals(x, y) {
// if both are function
if (x instanceof Function) {
if (y instanceof Function) {
return x.toString() === y.toString();
}
return false;
}
if (x === null || x === undefined || y === null || y === undefined) { return x === y; }
if (x === y || x.valueOf() === y.valueOf()) { return true; }
// if one of them is date, they must had equal valueOf
if (x instanceof Date) { return false; }
if (y instanceof Date) { return false; }
// if they are not function or strictly equal, they both need to be Objects
if (!(x instanceof Object)) { return false; }
if (!(y instanceof Object)) { return false; }
var p = Object.keys(x);
return Object.keys(y).every(function (i) { return p.indexOf(i) !== -1; }) ?
p.every(function (i) { return objectEquals(x[i], y[i]); }) : false;
} }