Layout Preferences Json Object

Documentation •
Dans cet article

The function getPrintPreferences() returns a list of user-selectable preferences for printing an invoice in Json format.

Banana takes care of checking whether the getPrintPreferences() function exists in the script and whether it returns the available choices. If found, the layout preferences are displayed within the dialogue for printing invoices, if not, no choices are displayed.

Layout preferences depend on the selected layout type, currently, the returning layouts of the preferences are:

This feature is available only with the Advanced plan, those who own another plan still see the layout preference box but the choices are disabled.

The layout preferences the user can choose from are:

  • Print as: The user can decide the type of document to print:
    • Automatic (default, depends on invoice status).
    • Invoice.
    • Delivery note.
    • Delivery note without amounts.
    • Reminder (number 1,2 or 3).

Print invoice with preferences dialog
 

Complete Json structure

This is the layout preferences structure with multiple elements, that serve as a reference for future implementation:

  • version: JSON structure version
  • id: Id of the structure.
  • text: Name of the structure.
  • base_options: Array of objects, each object represents a basic customization option, like the 'print as' options.
  • advanced_options_function: Object that contains advanced customization options.

The script defines the language in which to return the Json object, the structure remains the same, only the texts in the 'text' fields change.

The Json code include comments that should not be present in the code.


{
  "version" : "1.0",
  "id": "invoice_available_layout_preferences",
  "text":"Layout Preferences",
  "base_options" : [
  {
// first combo box
    "id": "invoice_available_print_as",
    "text": "Print as",
    "print_as": [
      {
        "id":"automatic",
        "text":"Automatic"
      },
      {
        "id":"invoice",
        "text": "Invoice"
      },
      {
        "id":"delivery_note" ,
        "text": "Delivery Note"
      },
      {
        "id":"reminder_1",
        "text": "Reminder 1"
      },
      {
        "id":"reminder_2",
        "text":"Reminder 2"
      },
      {
        "id":"reminder_3",
        "text": "Reminder 3"
      }
    ],
    "default": "automatic"
  },
],
// button.
//  When clicked the "function_name" is called
// Not yet implemented
"advanced_options_function" :{
  "text": "Print options",
  "function_name": "dialog_print_options"
}
}

Base preferences JSON structure example

The basic layout preferences concern more basic customisations, such as the document type (invoice status). The Json for the basic options is structured as follows:

  • id: Id of the structure.
  • text: Name of the structure.
  • print_as: Array of objects, each object represents an available document type (or invoice status). Each element  has an id and a text that is displayed in the combo box.


{
  "version" : "1.0",
  "id": "invoice_available_layout_preferences",
  "text":"Layout Preferences",
  "base_options" : [
  {
    "id": "invoice_available_print_as",
    "text": "Print as",
    "print_as": [
      {
        "id":"automatic",
        "text":"Automatic"
      },
      {
        "id":"invoice",
        "text": "Invoice"
      },
      {
        "id":"delivery_note" ,
        "text": "Delivery Note"
      },
      {
        "id":"reminder_1",
        "text": "Reminder 1"
      },
      {
        "id":"reminder_2",
        "text":"Reminder 2"
      },
      {
        "id":"reminder_3",
        "text": "Reminder 3"
      }
    ],
    "default": "automatic"
  }],
}

Advanced preferences JSON structure example

The advanced print options concern more detailed customisations. (to define)



{
  "version" : "1.0",
  "id": "invoice_available_print_preferences",
  "text":"Layout Preferences",
  "base_options" : [{/*Base options*/}],
  "advanced_options_function" :{
    "text": "Print options",
    "function_name": "dialog_print_options"
}

Returned JSON structure example

Banana returns a Json with user-selected layout preferences to the invoice layout script.

This structure is passed to the script through printDocument function.

  • version: JSON structure version
  • id: Id of the structure.
  • print_choices: Object that contains the print choices selected by the user. We send to the script the id of the preference choosed by the user.

In the following example, the user chose to print the third reminder, the value returned to the script, in this case 'reminder_3'.



{
    "version" : "1.0",
    "id": "invoice_available_layout_preferences",
    "print_choices" : {
        "print_as":"reminder_3",
        //other preferences
    },
}
Dites-nous comment nous pouvons mieux vous aider
Si les informations contenues dans cette page ne correspondent pas à ce que vous recherchez, ne sont pas suffisamment claires ou ne sont pas à jour, faites-nous savoir.

Partager cet article: Twitter | Facebook | LinkedIn | Email