diff --git a/app/views/invoices/edit.blade.php b/app/views/invoices/edit.blade.php index baee61b8e469..e4fac53c3094 100755 --- a/app/views/invoices/edit.blade.php +++ b/app/views/invoices/edit.blade.php @@ -207,10 +207,10 @@ -
+ {{ Former::select('invoice_design_id')->label('Design')->style('display:inline;width:120px')->raw() ->fromQuery($invoiceDesigns, 'name', 'id')->data_bind("value: invoice_design_id") }} -
+ {{ Button::normal('Download PDF', array('onclick' => 'onDownloadClick()')) }} @@ -558,6 +558,15 @@ invoice.imageWidth = {{ $account->getLogoWidth() }}; invoice.imageHeight = {{ $account->getLogoHeight() }}; @endif + + + //define logo images + + + invoice.imageLogo1 = "{{ HTML::image_data('images/report_logo1.jpg') }}"; + invoice.imageLogoWidth1 =120; + invoice.imageLogoHeight1 = 40 + return invoice; } diff --git a/public/images/report_logo1.jpg b/public/images/report_logo1.jpg new file mode 100644 index 000000000000..64fe9c87a8a0 Binary files /dev/null and b/public/images/report_logo1.jpg differ diff --git a/public/js/script.js b/public/js/script.js old mode 100755 new mode 100644 index 9b5c18274603..996a3b200acd --- a/public/js/script.js +++ b/public/js/script.js @@ -7,6 +7,17 @@ var isChromium = isChrome && navigator.userAgent.indexOf('Chromium') >= 0; var isIE = /*@cc_on!@*/false || !!document.documentMode; // At least IE6 function generatePDF(invoice, checkMath) { + + +console.log ('DESIGN:'+invoice.invoice_design_id); + + report_id=invoice.invoice_design_id; + + doc= GetPdf(invoice,checkMath,report_id); + + return doc; + + var client = invoice.client; var account = invoice.account; var currencyId = client.currency_id; @@ -78,7 +89,7 @@ function generatePDF(invoice, checkMath) { var invoiceNumberX = headerRight - (doc.getStringUnitWidth(invoiceNumber, false) * doc.internal.getFontSize()); var invoiceDateX = headerRight - (doc.getStringUnitWidth(invoiceDate) * doc.internal.getFontSize()); var dueDateX = headerRight - (doc.getStringUnitWidth(dueDate) * doc.internal.getFontSize()); - var poNumberX = headerRight - (doc.getStringUnitWidth(invoice.po_number) * doc.internal.getFontSize()); + var poNumberX = headerRight - (doc.getStringUnitWidth(invoice.po_number) * doc.internal.getFontSize()); doc.setFontType("normal"); @@ -463,7 +474,7 @@ $.extend( true, $.fn.dataTable.defaults, { //"sLengthMenu": "_MENU_ records per page" "sLengthMenu": "_MENU_", "sSearch": "" - }, + } //"sScrollY": "500px", } ); @@ -840,7 +851,9 @@ function populateInvoiceComboboxes(clientId, invoiceId) { for (var i=0; i 0) { + + var discount = total * (invoice.discount/100); + total -= discount; + } + + var tax = 0; + if (invoice.tax && parseFloat(invoice.tax.rate)) { + tax = parseFloat(invoice.tax.rate); + } else if (invoice.tax_rate && parseFloat(invoice.tax_rate)) { + tax = parseFloat(invoice.tax_rate); + } + + if (tax) { + var tax = total * (tax/100); + total = parseFloat(total) + parseFloat(tax); + } + + total = formatMoney(total - (invoice.amount - invoice.balance), currencyId); + + var balance = formatMoney(total, currencyId); + // balanceX = headerRight - (doc.getStringUnitWidth(balance) * doc.internal.getFontSize()); +// doc.text(balanceX, headerY, balance); + + //------------------------------ + + + console.log (total); + console.log (tax); + console.log (balance); + console.log (paid_to_date); + + + + + + + + + + + var doc = new jsPDF('p', 'pt'); + + //set default style for report + doc.setFont('Helvetica',''); + doc.setFontSize(7); + +//---------------------------------------------------------------------------------------------------- + //Print header on document + //for now we will put static header + //but later this could be changed to more flexible solution + + if (invoice.image) + { + var left = headerRight - invoice.imageWidth; + doc.addImage(invoice.image, 'JPEG', left, 30, invoice.imageWidth, invoice.imageHeight); + } + + + + if (invoice.imageLogo1) + { + pageHeight=820; + var left = headerRight ; + y=pageHeight-invoice.imageLogoHeight1; + + + var left = headerRight - invoice.imageLogoWidth1; + doc.addImage(invoice.imageLogo1, 'JPEG', left, y, invoice.imageLogoWidth1, invoice.imageLogoHeight1); + + + } + + + var invoiceNumberX = headerRight - (doc.getStringUnitWidth(invoiceNumber, false) * doc.internal.getFontSize()); + var invoiceDateX = headerRight - (doc.getStringUnitWidth(invoiceDate) * doc.internal.getFontSize()); + var dueDateX = headerRight - (doc.getStringUnitWidth(dueDate) * doc.internal.getFontSize()); + var poNumberX = headerRight - (doc.getStringUnitWidth(invoice.po_number) * doc.internal.getFontSize()); + + // doc.setFontType("normal"); + + var y = accountTop; + var left = marginLeft; + + + doc.setFontSize(7); + + SetPdfColor('LightBlue',doc); + if (account.name) { + y += rowHeight; + doc.text(left, y, account.name); + } + + SetPdfColor('GrayText',doc); + doc.setFontSize(6); + +//TODO:NOT AVAILEABLE FROM DATAMOEL + //account.email='email N/A'; + if (account.email) { + y += rowHeight; + doc.text(left, y, account.email); + } + else + { + console.log('account.email NOT DEFINED !'); + } + +//TODO:NOT AVAILEABLE FROM DATAMOEL + //account.phone='phone N/A'; + if (account.phone) { + y += rowHeight; + doc.text(left, y, account.phone); + } + else + { + console.log('account.phone NOT DEFINED !'); + } + + + + var HeaderMarginThirdColumn=70;//should be dynamic and dependent on 1st image and 2nd column width + + var y = accountTop; + var left = marginLeft+HeaderMarginThirdColumn; + + if (account.address1) { + y += rowHeight; + doc.text(left, y, account.address1); + } + if (account.address2) { + y += rowHeight; + doc.text(left, y, account.address2); + } + + if (account.city || account.state || account.postal_code) { + y += rowHeight; + doc.text(left, y, account.city + ', ' + account.state + ' ' + account.postal_code); + } + if (account.country) { + y += rowHeight; + doc.text(left, y, account.country.name); + } + + + + + +//-----------------------------Publish Client Details block-------------------------------------------- + + + var y = accountTop; + var left = marginLeft; + + var headerY = headerTop; + + + + + SetPdfColor('LightBlue',doc); + doc.setFontSize(8); + + //doc.setFontType("bold"); + + doc.text(50, headerTop, 'Invoice'); + + + + + + SetPdfColor('GrayLogo',doc); //set black color + y=130; + doc.line(30, y, 560, y); // horizontal line + + + + var line1=headerTop+16; + var line2=headerTop+16*2; + var line21=headerTop+16*1.6; + var line22=headerTop+16*2.2; + + var line3=headerTop+16*3; + var line31=headerTop+16*3.6; + + var marginLeft1=50; + var marginLeft2=120; + var marginLeft3=180; + + SetPdfColor('Black',doc); //set black color + + doc.setFontSize(6); + doc.text(marginLeft1, line1, 'Invoice Number'); + doc.text(marginLeft1, line2, 'Invoice date'); + doc.text(marginLeft1, line3, 'Amount Due'); + + + + + + // invoiceNumber='12345' + // invoiceDate='12345' + //invoiceAmount='12345' + + doc.setFontType("bold"); + doc.text(marginLeft2, line1, invoiceNumber); + doc.setFontType("normal"); + doc.text(marginLeft2, line2, invoiceDate); + + + SetPdfColor('LightBlue',doc); //set black color + doc.text(marginLeft2, line3, balance); + + ClientCompanyName=client.name; + ClientCompanyEmail='';//client.email;//'22222222'; + ClientCompanyPhone=client.work_phone; + + ClientCompanyAddress1=client.address1; + ClientCompanyAddress2=client.address2+' '+client.postal_code; + + + SetPdfColor('Black',doc); //set black color + + doc.setFontType("bold"); + + doc.text(marginLeft3, line1, ClientCompanyName); + doc.setFontType("normal"); + + + + if(client) + { + ClientCompanyName=getClientDisplayName(client); + ClientCompanyPhone=client.work_phone; + ClientCompanyEmail=client.contacts[0].email; + + } + + + doc.text(marginLeft3, line21, ClientCompanyAddress1); + doc.text(marginLeft3, line22, ClientCompanyAddress2); + + + doc.text(marginLeft3, line3, ClientCompanyEmail); + doc.text(marginLeft3, line31, ClientCompanyPhone); + + + SetPdfColor('GrayLogo',doc); //set black color + y=195; + doc.line(30, y, 560, y); // horizontal line + + +//--------------------------------Publishing Table-------------------------------------------------- + GlobalY=y+30; + + + SetPdfColor('Black',doc); + doc.setFontSize(7); + + var hasTaxes = false; + for (var i=0; i 0) || (item.tax_rate && parseFloat(item.tax_rate) > 0)) { + hasTaxes = true; + break; + } + } + if (hasTaxes) + { + descriptionLeft -= 20; + unitCostRight -= 40; + qtyRight -= 40; + } + + + + var costX = unitCostRight - (doc.getStringUnitWidth('Unit Cost') * doc.internal.getFontSize()); + var qtyX = qtyRight - (doc.getStringUnitWidth('Quantity') * doc.internal.getFontSize()); + var taxX = taxRight - (doc.getStringUnitWidth('Tax') * doc.internal.getFontSize()); + var totalX = lineTotalRight - (doc.getStringUnitWidth('Line Total') * doc.internal.getFontSize()); + + + + tableTop=GlobalY;//redefine this to dynamic value + + doc.setFontSize(9); + + doc.text(tableLeft, tableTop, 'Item'); + doc.text(descriptionLeft, tableTop, 'Description'); + doc.text(costX, tableTop, 'Unit Cost'); + doc.text(qtyX, tableTop, 'Quantity'); + doc.text(totalX, tableTop, 'Line Total'); + + if (hasTaxes) + { + doc.text(taxX, tableTop, 'Tax'); + } + + + doc.setFontSize(7); + + /* line items */ + //doc.setFontType("normal"); + var line = 1; + var total = 0; + var shownItem = false; + + + + +GlobalY=GlobalY+14; //padding from top + + var FontSize=7; + doc.setFontSize(FontSize); + + + var MaxLinesPerPage=40; + + + + for (var i=0; i MaxLinesPerPage) { + line = 0; + + tableTop = 40; + GlobalY=tableTop; + + + + + + + var MaxLinesPerPage=70; + + doc.addPage(); + if (invoice.imageLogo1) + { + pageHeight=820; + var left = headerRight ; + y=pageHeight-invoice.imageLogoHeight1; + + + var left = headerRight - invoice.imageLogoWidth1; + doc.addImage(invoice.imageLogo1, 'JPEG', left, y, invoice.imageLogoWidth1, invoice.imageLogoHeight1); + + + } + } + + + } + + + + + + + + +//-------------------------------Publishing Document balance------------------------------------------ + + + + + // var dueDateX = headerRight - (doc.getStringUnitWidth(dueDate) * doc.internal.getFontSize()); + x += 16+50; + + + MsgRightAlign=400; + + Msg='Total'; + var TmpMsgX = MsgRightAlign-(doc.getStringUnitWidth(Msg) * doc.internal.getFontSize()); + doc.text(TmpMsgX, x, Msg); + + + AmountText = formatMoney(total , currencyId); + headerLeft=headerRight+400; + var AmountX = headerLeft - (doc.getStringUnitWidth(AmountText) * doc.internal.getFontSize()); + doc.text(AmountX, x, AmountText); + + + + + x += doc.internal.getFontSize()*2; + //doc.text(footerLeft, x, ''); + + Msg='Amount Payed'; + var TmpMsgX = MsgRightAlign-(doc.getStringUnitWidth(Msg) * doc.internal.getFontSize()); + doc.text(TmpMsgX, x, Msg); + + + + AmountText = formatMoney(paid_to_date , currencyId); + headerLeft=headerRight+400; + var AmountX = headerLeft - (doc.getStringUnitWidth(AmountText) * doc.internal.getFontSize()); + doc.text(AmountX, x, AmountText); + + + + + + + + x += doc.internal.getFontSize()*4; + //doc.text(footerLeft, x, ''); + Msg='Amount Due'; + var TmpMsgX = MsgRightAlign-(doc.getStringUnitWidth(Msg) * doc.internal.getFontSize()); + doc.text(TmpMsgX, x, Msg); + + + + AmountText = formatMoney(balance , currencyId); + headerLeft=headerRight+400; + var AmountX = headerLeft - (doc.getStringUnitWidth(AmountText) * doc.internal.getFontSize()); + doc.text(AmountX, x, AmountText); + + + + + + + return doc; +} + + +function SetPdfColor(color,doc) +{ + + if (color=='LightBlue') { + return doc.setTextColor(41,156, 194); + } + + if (color=='Black') { + return doc.setTextColor(0,0,0);//select color black + } + if (color=='GrayLogo') { + return doc.setTextColor(207,209, 210);//select color Custom Report GRAY + } + + if (color=='GrayText') { + return doc.setTextColor(161,160,160);//select color Custom Report GRAY Colour + } + + + alert('color is not defined'); + return false; + +} + + + + + + + + + + + +