Invoice

Questa documentazione è superata

La documentazione più completa e aggiornata è quella di Banana Contabilità Plus: Provalo subito

In this article

Create personalized invoice report apps

We have published our templates on github.com/BananaAccounting. In this section you will find different basic examples.

You can save a copy of one template in your computer and make the changes you wish. In order to use your custom template in Banana you have to:

  • select the command Account2 - Customers - Print invoices...
  • In the Print invoices dialog select Manage apps...
  • In the Manage apps dialog select Add from file... and choose your invoice report file you just created

At the moment this function is available only within Banana Accounting Experimental.

Apps attributes

// @id = scriptfilename.js
// @api = 1.0
// @pubdate = yyyy-mm-dd
// @publisher = yourName
// @description = script description
// @task = report.customer.invoice

Report code

The main function is printDocument(jsonInvoice, repDocObj, repStyleObj). The  parameter jsonInvoice object contains the data, repDocObj is the document object and repStyleObj is the stylesheet object where you can add styles.

function printDocument(jsonInvoice, repDocObj, repStyleObj) {
  var param = initParam();
  var savedParam = Banana.document.getScriptSettings();
  if (savedParam.length > 0) {
    param = JSON.parse(savedParam);
    param = verifyParam(param);
  }
  printInvoice(jsonInvoice, repDocObj, repStyleObj, param);
}

The function settingsDialog() is called from Banana when you select the button Params... from dialog Manage apps. You can write any code you need for your script.

/*Update script's parameters*/
function settingsDialog() {
   var param = initParam();
   var savedParam = Banana.document.getScriptSettings();
   if (savedParam.length > 0) {
      param = JSON.parse(savedParam);
   }   
   param = verifyParam(param);
   ...
   var paramToString = JSON.stringify(param);
   var value = Banana.document.setScriptSettings(paramToString);
}

Printing custom data

You can add your own parameters in order to print specific data. For instance printing a reference order number or removing payments information if the invoice has already been paid.

if (invoiceObj.parameters.orderNo) {
    cell1.addParagraph("Reference order: " + invoiceObj.parameters.orderNo);
  }

Printing images

With the command addImage it is possible to add images into the document. For instance

var reportObj = Banana.Report;
var repDocObj = reportObj.newReport();
repDocObj.addImage("documents:logo", "logoStyle");

var logoStyle = repStyleObj.addStyle(".logoStyle");
logoStyle.setAttribute("position", "absolute");
logoStyle.setAttribute("margin-top", "5mm");
logoStyle.setAttribute("margin-left", "20mm");
logoStyle.setAttribute("width", "120px");

If you set the width, the image will be resized to the given width. If the width is not specified the image will be printed with a 72dpi resolution.

Condividi questo articolo: Twitter | Facebook | LinkedIn | Email