Invoice totals calculation
If you are setting the payments list of your invoice you must know the total amount of your items list. Luckily for you, you don't have to take the calculator out of your drawer, we got you covered with a specific set of methods to suit your needs, so you won't be seeing the Il totale dei pagamenti non corrisponde al totale da pagare error anymore.
If you use numbers with more than 2 decimal digits when specifying the amounts in the items list and payments list they will automatically be rounded to 2 digits before doing any calculation, so if you do not take this into consideration you probably will get the 'Il totale dei pagamenti non corrisponde al totale da pagare' error.
In this example, we'll suppose you have to manage just one Company, so we simply inserted its ID directly in the code. If instead, you need to be able to manage multiple companies, you'll need to retrieve the ID of the current company in some way. Check the Company-scoped Methods page for more info.
Zapier Actions provide all the fields offered by the APIs, but it does not mean you need to compile all of them!
To follow this guide, you will be required to search the fields used in our example on the Zapier page and insert the related values.
The code of the fields will follow the JSON structure: for example, the "type" field is included in the "data" object, so the Zapier code will be "data.type". You can use the CRTL + F command to search the field's code faster ๐
In this example, we'll insert the values directly, but please remember that Zapier was built to let you select the workflow's previous steps' outputs as input in the Action, for example selecting the values returned by a trigger!
๐ตย Old or new?โ
We got methods for all the cases you would possibly think of, either you are creating a new invoice or editing an old one we have a specific call.
The two methods are:
Invoking these methods will not create or edit your invoice, it will only show you a preview of the totals. You still need to use the appropriate methods to apply the modifications.
๐ย New invoice totalsโ
You can invoke the Get New Issued Document Totals method if you are creating a new invoice and want to know the totals after you added the items list to your invoice body: the response will contain all the info you need to finalize your invoice creation.
Here you can find an example request and response.
- Request
- Response
POST /c/2/issued_document/totals HTTP/1.1
Host: api-v2.fattureincloud.it
Accept: application/json
Content-Type: application/json
Content-Length: 500
{
"data": {
"entity": {
"name": "test"
},
"type": "invoice",
"items_list": [
{
"vat": {
"id": 1
},
"name": "prod1",
"net_price": 35,
"qty": 1
},
{
"vat": {
"id": 1
},
"name": "prod2",
"net_price": 39,
"qty": 1
}
]
}
}
{
"data": {
"amount_net": 74,
"amount_global_cassa_taxable": 74,
"taxable_amount": 74,
"vat_list": {
"21": {
"amount_net": 74,
"amount_vat": 15.54
}
},
"amount_vat": 15.54,
"amount_gross": 89.54,
"amount_enasarco_taxable": 0,
"amount_due": 89.54,
"amount_due_discount": null,
"payments_sum": 0
}
}
And here there are the examples to make this request with our SDKs:
- C#
- Go
- Java
- JavaScript
- PHP
- Python
- Ruby
- TypeScript
- Zapier
using System;
using System.Collections.Generic;
using It.FattureInCloud.Sdk.Api;
using It.FattureInCloud.Sdk.Client;
using It.FattureInCloud.Sdk.Model;
namespace test {
class Program {
static void Main(string[] args) {
Configuration config = new Configuration();
//set your access token
config.AccessToken = "YOUR_ACCESS_TOKEN";
var apiInstance = new IssuedDocumentsApi(config);
//set your company id
var companyId = 12345;
//set your invoice info
IssuedDocument invoice = new IssuedDocument(
type: IssuedDocumentType.Invoice,
entity: new Entity(
name: "test"
),
itemsList: new List < IssuedDocumentItemsListItem > {
new IssuedDocumentItemsListItem(
name: "prod1",
netPrice: 35,
qty: 1,
vat: new VatType(
id: 0
)
),
new IssuedDocumentItemsListItem(
name: "prod2",
netPrice: 39,
qty: 1,
vat: new VatType(
id: 0
)
)
}
);
// Here we put our invoice in the request object
GetNewIssuedDocumentTotalsRequest getNewIssuedDocumentTotalsRequest = new GetNewIssuedDocumentTotalsRequest(
data: invoice
);
// Now we are all set for the final call
// Get new issued documents totals: https://github.com/fattureincloud/fattureincloud-csharp-sdk/blob/master/docs/IssuedDocumentsApi.md#getnewissueddocumenttotals
try {
GetNewIssuedDocumentTotalsResponse result = apiInstance.GetNewIssuedDocumentTotals(companyId, getNewIssuedDocumentTotalsRequest);
Console.WriteLine(result);
} catch (ApiException e) {
Console.WriteLine("Exception when calling IssuedDocumentsApi.GetNewIssuedDocumentTotals: " + e.Message);
Console.WriteLine("Status Code: " + e.ErrorCode);
Console.WriteLine(e.StackTrace);
}
}
}
}
// NOTE: this is a complete request, but please customize it!!!
// In the next step we'll explain how to perform the request to the API.
// in this example we are using our Go SDK
// https://github.com/fattureincloud/fattureincloud-go-sdk
package main
import (
"context"
"encoding/json"
"fmt"
"os"
fattureincloudapi "github.com/fattureincloud/fattureincloud-go-sdk/v2/api"
fattureincloud "github.com/fattureincloud/fattureincloud-go-sdk/v2/model"
)
func main() {
//set your access token
auth := context.WithValue(context.Background(), fattureincloudapi.ContextAccessToken, "YOUR_ACCESS_TOKEN")
configuration := fattureincloudapi.NewConfiguration()
apiClient := fattureincloudapi.NewAPIClient(configuration)
//set your company id
companyId := int32(12345)
//set your invoice info
invoice := *fattureincloud.NewIssuedDocument().
SetEntity(*fattureincloud.NewEntity().
SetId(1)).
SetType(fattureincloud.IssuedDocumentTypes.INVOICE).
SetItemsList([]fattureincloud.IssuedDocumentItemsListItem{
*fattureincloud.NewIssuedDocumentItemsListItem().
SetName("prod1").
SetNetPrice(35).
SetQty(1).
SetVat(*fattureincloud.NewVatType().SetId(0)),
*fattureincloud.NewIssuedDocumentItemsListItem().
SetName("prod2").
SetNetPrice(39).
SetQty(1).
SetVat(*fattureincloud.NewVatType().SetId(0)),
})
// Here we put our invoice in the request object
getNewIssuedDocumentTotalsRequest := *fattureincloud.NewGetNewIssuedDocumentTotalsRequest().SetData(invoice)
// Now we are all set for the final call
// Create the invoice: https://github.com/fattureincloud/fattureincloud-go-sdk/blob/master/docs/IssuedDocumentsApi.md#getnewissueddocumenttotals
resp, r, err := apiClient.IssuedDocumentsAPI.GetNewIssuedDocumentTotals(auth, companyId).GetNewIssuedDocumentTotalsRequest(getNewIssuedDocumentTotalsRequest).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `IssuedDocumentsApi.GetNewIssuedDocumentTotals``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
json.NewEncoder(os.Stdout).Encode(resp)
}
import it.fattureincloud.sdk.ApiClient;
import it.fattureincloud.sdk.ApiException;
import it.fattureincloud.sdk.Configuration;
import it.fattureincloud.sdk.auth.*;
import it.fattureincloud.sdk.model.*;
import it.fattureincloud.sdk.api.IssuedDocumentsApi;
import java.math.BigDecimal;
import java.time.LocalDate;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
//set your access token
OAuth OAuth2AuthenticationCodeFlow = (OAuth) defaultClient.getAuthentication("OAuth2AuthenticationCodeFlow");
OAuth2AuthenticationCodeFlow.setAccessToken("YOUR ACCESS TOKEN");
IssuedDocumentsApi apiInstance = new IssuedDocumentsApi(defaultClient);
//set your company id
Integer companyId = 12345;
//set your invoice info
IssuedDocument invoice = new IssuedDocument()
.type(IssuedDocumentType.INVOICE)
.entity(
new Entity()
.name("test")
)
.addItemsListItem(
new IssuedDocumentItemsListItem()
.name("prod1")
.netPrice(BigDecimal.valueOf(35))
.qty(BigDecimal.valueOf(1))
.vat(new VatType().id(0))
)
.addItemsListItem(
new IssuedDocumentItemsListItem()
.name("prod2")
.netPrice(BigDecimal.valueOf(39))
.qty(BigDecimal.valueOf(1))
.vat(new VatType().id(0))
);
// Here we put our invoice in the request object
GetNewIssuedDocumentTotalsRequest getNewIssuedDocumentTotalsRequest = new GetNewIssuedDocumentTotalsRequest()
.data(invoice);
// Now we are all set for the final call
// Get new issued document totals: https://github.com/fattureincloud/fattureincloud-java-sdk/blob/master/docs/IssuedDocumentsApi.md#getNewIssuedDocumentTotals
try {
GetNewIssuedDocumentTotalsResponse result = apiInstance.getNewIssuedDocumentTotals(companyId, getNewIssuedDocumentTotalsRequest);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling IssuedDocumentsApi#getNewIssuedDocumentTotals");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
var fattureInCloudSdk = require("@fattureincloud/fattureincloud-js-sdk");
let defaultClient = fattureInCloudSdk.ApiClient.instance;
//set your access token
let OAuth2AuthenticationCodeFlow =
defaultClient.authentications["OAuth2AuthenticationCodeFlow"];
OAuth2AuthenticationCodeFlow.accessToken = "YOUR_ACCESS_TOKEN";
let apiInstance = new fattureInCloudSdk.IssuedDocumentsApi();
//set your company id
let companyId = 12345;
//set your invoice info
let invoice = new fattureInCloudSdk.IssuedDocument();
invoice.type = new fattureInCloudSdk.IssuedDocumentType().invoice;
invoice.entity = {
name: "test",
};
invoice.items_list = [
{
name: "prod1",
net_price: 35,
qty: 1,
vat: {
id: 0,
},
},
{
name: "prod2",
net_price: 39,
qty: 1,
vat: {
id: 0,
},
},
];
// Here we put our invoice in the request object
let getNewIssuedDocumentTotalsRequest =
new fattureInCloudSdk.GetNewIssuedDocumentTotalsRequest();
getNewIssuedDocumentTotalsRequest.data = invoice;
let opts = {
getNewIssuedDocumentTotalsRequest: getNewIssuedDocumentTotalsRequest,
};
// Now we are all set for the final call
// Get new issued document totals: https://github.com/fattureincloud/fattureincloud-js-sdk/blob/master/docs/IssuedDocumentsApi.md#getNewIssuedDocumentTotals
apiInstance.getNewIssuedDocumentTotals(companyId, opts).then(
(result) => {
console.log(
"API called successfully. Returned result: " + JSON.stringify(result)
);
},
(error) => {
console.error(error);
}
);
<?php
use FattureInCloud\Model\Entity;
use FattureInCloud\Model\IssuedDocument;
use FattureInCloud\Model\IssuedDocumentItemsList;
use FattureInCloud\Model\IssuedDocumentType;
use FattureInCloud\Model\VatType;
require_once(__DIR__ . '/vendor/autoload.php');
//set your access token
$config = FattureInCloud\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');
$apiInstance = new FattureInCloud\Api\IssuedDocumentsApi(
new GuzzleHttp\Client(),
$config
);
//set your company id
$company_id = 12345;
//set your invoice info
$invoice = new IssuedDocument;
$invoice->setType(IssuedDocumentType::INVOICE);
$entity = new Entity;
$entity->setName("test");
$invoice->setEntity($entity);
$invoice->setItemsList(
array(
new IssuedDocumentItemsListItem(
array(
"name" => "prod1",
"net_price" => 35,
"qty" => 1,
"vat" => new VatType(
array(
"id" => 0
)
)
)
),
new IssuedDocumentItemsListItem(
array(
"name" => "prod2",
"net_price" => 39,
"qty" => 1,
"vat" => new VatType(
array(
"id" => 0
)
)
)
)
)
);
// Here we put our invoice in the request object
$get_new_issued_document_totals_request = new GetNewIssuedDocumentTotalsRequest;
$get_new_issued_document_totals_request->setData($invoice);
// Now we are all set for the final call
// Get new issued document totals: https://github.com/fattureincloud/fattureincloud-php-sdk/blob/master/docs/Api/IssuedDocumentsApi.md#getNewIssuedDocumentTotals
try {
$result = $apiInstance->getNewIssuedDocumentTotals($company_id, $get_new_issued_document_totals_request);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling IssuedDocumentsApi->getNewIssuedDocumentTotals: ', $e->getMessage(), PHP_EOL;
}
import datetime
import fattureincloud_python_sdk
from fattureincloud_python_sdk.api import issued_documents_api
from fattureincloud_python_sdk.models.vat_type import VatType
from fattureincloud_python_sdk.models.entity import Entity
from fattureincloud_python_sdk.models.issued_document import IssuedDocument
from fattureincloud_python_sdk.models.issued_document_type import IssuedDocumentType
from fattureincloud_python_sdk.models.get_new_issued_document_totals_request import GetNewIssuedDocumentTotalsRequest
from fattureincloud_python_sdk.models.get_new_issued_document_totals_response import GetNewIssuedDocumentTotalsResponse
from fattureincloud_python_sdk.models.issued_document_items_list_item import IssuedDocumentItemsListItem
from pprint import pprint
# set your access token
configuration = fattureincloud_python_sdk.Configuration()
configuration.access_token = "YOUR_ACCESS_TOKEN"
# set your company id
company_id = 12345
# set your invoice info
invoice = IssuedDocument(
type = IssuedDocumentType("invoice"),
entity = Entity(
name="test"
),
items_list = [
IssuedDocumentItemsListItem(
name="prod1",
net_price=35.0,
qty=1.0,
vat=VatType(
id=0
)
),
IssuedDocumentItemsListItem(
name="prod2",
net_price=39.0,
qty=1.0,
vat=VatType(
id=0
)
)
]
)
# Here we put our invoice in the request object
get_new_issued_document_totals_request = GetNewIssuedDocumentTotalsRequest(
data = invoice
)
# Now we are all set for the final call
# Get new issued document totals: https://github.com/fattureincloud/fattureincloud-python-sdk/blob/master/docs/IssuedDocumentsApi.md#get_new_issued_document_totals
with fattureincloud_python_sdk.ApiClient(configuration) as api_client:
api_instance = issued_documents_api.IssuedDocumentsApi(api_client)
try:
api_response = api_instance.get_new_issued_document_totals(company_id, get_new_issued_document_totals_request=get_new_issued_document_totals_request)
pprint(api_response)
except fattureincloud_python_sdk.ApiException as e:
print("Exception when calling IssuedDocumentsApi->get_new_issued_document_totals: %s\n" % e)
require 'time'
require 'fattureincloud_ruby_sdk'
FattureInCloud_Ruby_Sdk.configure do |config|
# set your access token
config.access_token = 'YOUR ACCESS TOKEN'
end
api_instance = FattureInCloud_Ruby_Sdk::IssuedDocumentsApi.new
# set your company id
company_id = 12345
# set your invoice info
invoice = FattureInCloud_Ruby_Sdk::IssuedDocument.new(
type: FattureInCloud_Ruby_Sdk::IssuedDocumentType::INVOICE,
entity: FattureInCloud_Ruby_Sdk::Entity.new(
name: "test",
),
items_list: Array(
FattureInCloud_Ruby_Sdk::IssuedDocumentItemsListItem.new(
name: "prod1",
net_price: 35,
qty: 1,
vat: FattureInCloud_Ruby_Sdk::VatType.new(
id: 0
)
),
FattureInCloud_Ruby_Sdk::IssuedDocumentItemsListItem.new(
name: "prod2",
net_price: 39,
qty: 1,
vat: FattureInCloud_Ruby_Sdk::VatType.new(
id: 0
)
)
)
)
# Here we put our invoice in the request object
opts = {
get_new_issued_document_totals_request: FattureInCloud_Ruby_Sdk::GetNewIssuedDocumentTotalsRequest.new(data: invoice)
}
# Now we are all set for the final call
# Get new issued document totals: https://github.com/fattureincloud/fattureincloud-ruby-sdk/blob/master/docs/IssuedDocumentsApi.md#https://github.com/fattureincloud/fattureincloud-ruby-sdk/blob/master/docs/IssuedDocumentsApi.md#get_new_issued_document_totals
begin
result = api_instance.get_new_issued_document_totals(company_id, opts)
p result
rescue FattureInCloud_Ruby_Sdk::ApiError => e
puts "Error when calling IssuedDocumentsApi->get_new_issued_document_totals: #{e}"
end
import {
Configuration,
IssuedDocumentsApi,
IssuedDocument,
IssuedDocumentType,
GetNewIssuedDocumentTotalsRequest,
} from "@fattureincloud/fattureincloud-ts-sdk";
//set your access token
const apiConfig = new Configuration({
accessToken: "YOUR ACCESS TOKEN",
});
let apiInstance = new IssuedDocumentsApi(apiConfig);
//set your company id
let companyId = 12345;
let invoice: IssuedDocument = {
type: IssuedDocumentType.Invoice,
entity: {
name: "test",
},
items_list: [
{
name: "prod1",
net_price: 35,
qty: 1,
vat: {
id: 0,
},
},
{
name: "prod2",
net_price: 39,
qty: 1,
vat: {
id: 0,
},
},
],
};
// Here we put our invoice in the request object
let getNewIssuedDocumentTotalsRequest: GetNewIssuedDocumentTotalsRequest = {
data: invoice,
};
// Now we are all set for the final call
// Get new issued document totals: https://github.com/fattureincloud/fattureincloud-ts-sdk/blob/master/docs/IssuedDocumentsApi.md#getNewIssuedDocumentTotals
apiInstance
.getNewIssuedDocumentTotals(companyId, getNewIssuedDocumentTotalsRequest)
.then(
(data) => {
console.log(data);
},
(error) => {
console.error(error);
}
);
The Zapier Action you need is called Get New Issued Document Totals. After you select the action and log in, you need to select your Company ID. Luckily, our Actions let you select it from a simple dropdown menu.
Next, you must insert a request similar to the one we need for the Create Issued Document request. We suggest you check the Invoice Creation Guide for more info.
You can then use the resulting totals of this request in the creation request.
You can set the Access Token in the dedicated section, for more informations look here.
๐ย Existing invoice totalsโ
If you want to edit an existing invoice instead, for example, to add a new item, you can get the updated totals invoking the Get Existing Issued Document Totals method and passing the updated fields in the request body.
In the following example, we want to a third item to an existing invoice and we want to know what will be the resulting updated totals before making the modify issued document call, using the previously described method:
- Request
- Response
POST /c/2/issued_document/12345/totals HTTP/1.1
Host: api-v2.fattureincloud.it
Accept: application/json
Content-Type: application/json
Content-Length: 500
{
"data": {
"items_list": [
{
"vat": {
"id": 1
},
"name": "prod1",
"net_price": 35,
"qty": 1
},
{
"vat": {
"id": 1
},
"name": "prod2",
"net_price": 39,
"qty": 1
},
{
"vat": {
"id": 1
},
"name": "prod3",
"net_price": 48,
"qty": 1
}
]
}
}
{
"data": {
"amount_net": 122,
"amount_global_cassa_taxable": 122,
"taxable_amount": 122,
"vat_list": {
"21": {
"amount_net": 122,
"amount_vat": 25.62
}
},
"amount_vat": 25.62,
"amount_gross": 147.62,
"amount_enasarco_taxable": 0,
"amount_due": 147.62,
"amount_due_discount": 0,
"payments_sum": 0
}
}
And here there are the examples to make this request with our SDKs:
- C#
- Go
- Java
- JavaScript
- PHP
- Python
- Ruby
- TypeScript
- Zapier
using System;
using System.Collections.Generic;
using It.FattureInCloud.Sdk.Api;
using It.FattureInCloud.Sdk.Client;
using It.FattureInCloud.Sdk.Model;
namespace test {
class Program {
static void Main(string[] args) {
Configuration config = new Configuration();
//set your access token
config.AccessToken = "YOUR_ACCESS_TOKEN";
var apiInstance = new IssuedDocumentsApi(config);
//set your company id
var companyId = 12345;
//set your existing invoice id
var invoiceId = 54321;
//set your invoice info
IssuedDocument invoice = new IssuedDocument(
itemsList: new List < IssuedDocumentItemsListItem > {
new IssuedDocumentItemsListItem(
name: "prod1",
netPrice: 35,
qty: 1,
vat: new VatType(
id: 0
)
),
new IssuedDocumentItemsListItem(
name: "prod2",
netPrice: 39,
qty: 1,
vat: new VatType(
id: 0
)
),
new IssuedDocumentItemsListItem(
name: "prod3",
netPrice: 48,
qty: 1,
vat: new VatType(
id: 0
)
)
}
);
// Here we put our invoice in the request object
GetExistingIssuedDocumentTotalsRequest getExistingIssuedDocumentTotalsRequest = new GetExistingIssuedDocumentTotalsRequest(
data: invoice
);
// Now we are all set for the final call
// Get existing issued documents totals: https://github.com/fattureincloud/fattureincloud-csharp-sdk/blob/master/docs/IssuedDocumentsApi.md#getexistingissueddocumenttotals
try {
GetExistingIssuedDocumentTotalsResponse result = apiInstance.GetExistingIssuedDocumentTotals(companyId, invoiceId, getExistingIssuedDocumentTotalsRequest);
Console.WriteLine(result);
} catch (ApiException e) {
Console.WriteLine("Exception when calling IssuedDocumentsApi.GetExistingIssuedDocumentTotals: " + e.Message);
Console.WriteLine("Status Code: " + e.ErrorCode);
Console.WriteLine(e.StackTrace);
}
}
}
}
// NOTE: this is a complete request, but please customize it!!!
// In the next step we'll explain how to perform the request to the API.
// in this example we are using our Go SDK
// https://github.com/fattureincloud/fattureincloud-go-sdk
package main
import (
"context"
"encoding/json"
"fmt"
"os"
fattureincloudapi "github.com/fattureincloud/fattureincloud-go-sdk/v2/api"
fattureincloud "github.com/fattureincloud/fattureincloud-go-sdk/v2/model"
)
func main() {
//set your access token
auth := context.WithValue(context.Background(), fattureincloudapi.ContextAccessToken, "YOUR_ACCESS_TOKEN")
configuration := fattureincloudapi.NewConfiguration()
apiClient := fattureincloudapi.NewAPIClient(configuration)
//set your company id
companyId := int32(12345)
//set your document id
documentId := int32(54321)
//set your invoice info
invoice := *fattureincloud.NewIssuedDocument().
SetEntity(*fattureincloud.NewEntity().
SetId(1)).
SetType(fattureincloud.IssuedDocumentTypes.INVOICE).
SetItemsList([]fattureincloud.IssuedDocumentItemsListItem{
*fattureincloud.NewIssuedDocumentItemsListItem().
SetName("prod1").
SetNetPrice(35).
SetQty(1).
SetVat(*fattureincloud.NewVatType().SetId(0)),
*fattureincloud.NewIssuedDocumentItemsListItem().
SetName("prod2").
SetNetPrice(39).
SetQty(1).
SetVat(*fattureincloud.NewVatType().SetId(0)),
*fattureincloud.NewIssuedDocumentItemsListItem().
SetName("prod3").
SetNetPrice(48).
SetQty(1).
SetVat(*fattureincloud.NewVatType().SetId(0)),
})
// Here we put our invoice in the request object
getExistingIssuedDocumentTotalsRequest := *fattureincloud.NewGetExistingIssuedDocumentTotalsRequest().SetData(invoice)
// Now we are all set for the final call
// Create the invoice: https://github.com/fattureincloud/fattureincloud-go-sdk/blob/master/docs/IssuedDocumentsApi.md#getexistingissueddocumenttotals
resp, r, err := apiClient.IssuedDocumentsAPI.GetExistingIssuedDocumentTotals(auth, companyId, documentId).GetExistingIssuedDocumentTotalsRequest(getExistingIssuedDocumentTotalsRequest).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `IssuedDocumentsApi.GetNewIssuedDocumentTotals``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
json.NewEncoder(os.Stdout).Encode(resp)
}
import it.fattureincloud.sdk.ApiClient;
import it.fattureincloud.sdk.ApiException;
import it.fattureincloud.sdk.Configuration;
import it.fattureincloud.sdk.auth.*;
import it.fattureincloud.sdk.model.*;
import it.fattureincloud.sdk.api.IssuedDocumentsApi;
import java.math.BigDecimal;
import java.time.LocalDate;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
//set your access token
OAuth OAuth2AuthenticationCodeFlow = (OAuth) defaultClient.getAuthentication("OAuth2AuthenticationCodeFlow");
OAuth2AuthenticationCodeFlow.setAccessToken("YOUR ACCESS TOKEN");
IssuedDocumentsApi apiInstance = new IssuedDocumentsApi(defaultClient);
//set your company id
Integer companyId = 12345;
//set your existing invoice id
Integer invoiceId = 54321;
//set your invoice info
IssuedDocument invoice = new IssuedDocument()
.addItemsListItem(
new IssuedDocumentItemsListItem()
.name("prod1")
.netPrice(BigDecimal.valueOf(35))
.qty(BigDecimal.valueOf(1))
.vat(new VatType().id(0))
)
.addItemsListItem(
new IssuedDocumentItemsListItem()
.name("prod2")
.netPrice(BigDecimal.valueOf(39))
.qty(BigDecimal.valueOf(1))
.vat(new VatType().id(0))
)
.addItemsListItem(
new IssuedDocumentItemsListItem()
.name("prod3")
.netPrice(BigDecimal.valueOf(48))
.qty(BigDecimal.valueOf(1))
.vat(new VatType().id(0))
);
// Here we put our invoice in the request object
GetExistingIssuedDocumentTotalsRequest getExistingIssuedDocumentTotalsRequest = new GetExistingIssuedDocumentTotalsRequest()
.data(invoice);
// Now we are all set for the final call
// Get existing issued document totals: https://github.com/fattureincloud/fattureincloud-java-sdk/blob/master/docs/IssuedDocumentsApi.md#getExistingIssuedDocumentTotals
try {
GetExistingIssuedDocumentTotalsResponse result = apiInstance.getExistingIssuedDocumentTotals(companyId, invoiceId, getExistingIssuedDocumentTotalsRequest);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling IssuedDocumentsApi#getExistingIssuedDocumentTotals");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
var fattureInCloudSdk = require("@fattureincloud/fattureincloud-js-sdk");
let defaultClient = fattureInCloudSdk.ApiClient.instance;
//set your access token
let OAuth2AuthenticationCodeFlow =
defaultClient.authentications["OAuth2AuthenticationCodeFlow"];
OAuth2AuthenticationCodeFlow.accessToken = "YOUR_ACCESS_TOKEN";
let apiInstance = new fattureInCloudSdk.IssuedDocumentsApi();
//set your company id
let companyId = 12345;
//set your invoice id
let invoiceId = 54321;
//set your invoice info
let invoice = new fattureInCloudSdk.IssuedDocument();
invoice.items_list = [
{
name: "prod1",
net_price: 35,
qty: 1,
vat: {
id: 0,
},
},
{
name: "prod2",
net_price: 39,
qty: 1,
vat: {
id: 0,
},
},
{
name: "prod3",
net_price: 48,
qty: 1,
vat: {
id: 0,
},
},
];
// Here we put our invoice in the request object
let getExistingIssuedDocumentTotalsRequest =
new fattureInCloudSdk.GetExistingIssuedDocumentTotalsRequest();
getExistingIssuedDocumentTotalsRequest.data = invoice;
let opts = {
getExistingIssuedDocumentTotalsRequest:
getExistingIssuedDocumentTotalsRequest,
};
// Now we are all set for the final call
// Get existing issued document totals: https://github.com/fattureincloud/fattureincloud-js-sdk/blob/master/docs/IssuedDocumentsApi.md#getExistingIssuedDocumentTotals
apiInstance.getExistingIssuedDocumentTotals(companyId, invoiceId, opts).then(
(result) => {
console.log(
"API called successfully. Returned result: " + JSON.stringify(result)
);
},
(error) => {
console.error(error);
}
);
<?php
use FattureInCloud\Model\Entity;
use FattureInCloud\Model\IssuedDocument;
use FattureInCloud\Model\IssuedDocumentItemsListItem;
use FattureInCloud\Model\VatType;
require_once(__DIR__ . '/vendor/autoload.php');
//set your access token
$config = FattureInCloud\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');
$apiInstance = new FattureInCloud\Api\IssuedDocumentsApi(
new GuzzleHttp\Client(),
$config
);
//set your company id
$company_id = 12345;
//set your existing invoice id
$invoice_id = 54321;
//set your invoice info
$invoice = new IssuedDocument;
$invoice->setItemsList(
array(
new IssuedDocumentItemsListItem(
array(
"name" => "prod1",
"net_price" => 35,
"qty" => 1,
"vat" => new VatType(
array(
"id" => 0
)
)
)
),
new IssuedDocumentItemsListItem(
array(
"name" => "prod2",
"net_price" => 39,
"qty" => 1,
"vat" => new VatType(
array(
"id" => 0
)
)
)
),
new IssuedDocumentItemsListItem(
array(
"name" => "prod3",
"net_price" => 48,
"qty" => 1,
"vat" => new VatType(
array(
"id" => 0
)
)
)
)
)
);
// Here we put our invoice in the request object
$get_existing_issued_document_totals_request = new GetExistingIssuedDocumentTotalsRequest;
$get_existing_issued_document_totals_request->setData($invoice);
// Now we are all set for the final call
// Get existing issued document totals: https://github.com/fattureincloud/fattureincloud-php-sdk/blob/master/docs/Api/IssuedDocumentsApi.md#getExistingIssuedDocumentTotals
try {
$result = $apiInstance->getExistingIssuedDocumentTotals($company_id, $invoice_id, $get_existing_issued_document_totals_request);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling IssuedDocumentsApi->getExistingIssuedDocumentTotals: ', $e->getMessage(), PHP_EOL;
}
import datetime
import fattureincloud_python_sdk
from fattureincloud_python_sdk.api import issued_documents_api
from fattureincloud_python_sdk.models.vat_type import VatType
from fattureincloud_python_sdk.models.issued_document import IssuedDocument
from fattureincloud_python_sdk.models.get_existing_issued_document_totals_request import GetExistingIssuedDocumentTotalsRequest
from fattureincloud_python_sdk.models.get_existing_issued_document_totals_response import GetExistingIssuedDocumentTotalsResponse
from fattureincloud_python_sdk.models.issued_document_items_list_item import IssuedDocumentItemsListItem
from pprint import pprint
# set your access token
configuration = fattureincloud_python_sdk.Configuration()
configuration.access_token = "YOUR_ACCESS_TOKEN"
# set your company id
company_id = 12345
# set your existing invoice id
invoice_id = 54321
# set your invoice info
invoice = IssuedDocument(
items_list = [
IssuedDocumentItemsListItem(
name="prod1",
net_price=35.0,
qty=1.0,
vat=VatType(
id=0
)
),
IssuedDocumentItemsListItem(
name="prod2",
net_price=39.0,
qty=1.0,
vat=VatType(
id=0
)
),
IssuedDocumentItemsListItem(
name="prod3",
net_price=48.0,
qty=1.0,
vat=VatType(
id=0
)
)
]
)
# Here we put our invoice in the request object
get_existing_issued_document_totals_request = GetExistingIssuedDocumentTotalsRequest(
data = invoice
)
# Now we are all set for the final call
# Get existing issued document totals: https://github.com/fattureincloud/fattureincloud-python-sdk/blob/master/docs/IssuedDocumentsApi.md#get_existing_issued_document_totals
with fattureincloud_python_sdk.ApiClient(configuration) as api_client:
api_instance = issued_documents_api.IssuedDocumentsApi(api_client)
try:
api_response = api_instance.get_existing_issued_document_totals(company_id, invoice_id get_existing_issued_document_totals_request=get_existing_issued_document_totals_request)
pprint(api_response)
except fattureincloud_python_sdk.ApiException as e:
print("Exception when calling IssuedDocumentsApi->get_existing_issued_document_totals: %s\n" % e)
require 'time'
require 'fattureincloud_ruby_sdk'
FattureInCloud_Ruby_Sdk.configure do |config|
# set your access token
config.access_token = 'YOUR ACCESS TOKEN'
end
api_instance = FattureInCloud_Ruby_Sdk::IssuedDocumentsApi.new
# set your company id
company_id = 12345
# set your invoice id
invoice_id = 54321
# set your invoice info
invoice = FattureInCloud_Ruby_Sdk::IssuedDocument.new(
items_list: Array(
FattureInCloud_Ruby_Sdk::IssuedDocumentItemsListItem.new(
name: "prod1",
net_price: 35,
qty: 1,
vat: FattureInCloud_Ruby_Sdk::VatType.new(
id: 0
)
),
FattureInCloud_Ruby_Sdk::IssuedDocumentItemsListItem.new(
name: "prod2",
net_price: 39,
qty: 1,
vat: FattureInCloud_Ruby_Sdk::VatType.new(
id: 0
)
),
FattureInCloud_Ruby_Sdk::IssuedDocumentItemsListItem.new(
name: "prod3",
net_price: 48,
qty: 1,
vat: FattureInCloud_Ruby_Sdk::VatType.new(
id: 0
)
)
)
)
# Here we put our invoice in the request object
opts = {
get_existing_issued_document_totals_request: FattureInCloud_Ruby_Sdk::GetExistingIssuedDocumentTotalsRequest.new(data: invoice)
}
# Now we are all set for the final call
# Get existing issued document totals: https://github.com/fattureincloud/fattureincloud-ruby-sdk/blob/master/docs/IssuedDocumentsApi.md#https://github.com/fattureincloud/fattureincloud-ruby-sdk/blob/master/docs/IssuedDocumentsApi.md#get_existing_issued_document_totals
begin
result = api_instance.get_existing_issued_document_totals(company_id, invoice_id, opts)
p result
rescue FattureInCloud_Ruby_Sdk::ApiError => e
puts "Error when calling IssuedDocumentsApi->get_existing_issued_document_totals: #{e}"
end
import {
Configuration,
IssuedDocumentsApi,
IssuedDocument,
IssuedDocumentType,
GetExistingIssuedDocumentTotalsRequest,
} from "@fattureincloud/fattureincloud-ts-sdk";
//set your access token
const apiConfig = new Configuration({
accessToken: "YOUR ACCESS TOKEN",
});
let apiInstance = new IssuedDocumentsApi(apiConfig);
//set your company id
let companyId = 12345;
//set your invoice id
let invoiceId = 54321;
//set your invoice info
let invoice: IssuedDocument = {
type: IssuedDocumentType.Invoice,
entity: {
name: "test",
},
items_list: [
{
name: "prod1",
net_price: 35,
qty: 1,
vat: {
id: 0,
},
},
{
name: "prod2",
net_price: 39,
qty: 1,
vat: {
id: 0,
},
},
{
name: "prod3",
net_price: 48,
qty: 1,
vat: {
id: 0,
},
},
],
};
// Here we put our invoice in the request object
let getExistingIssuedDocumentTotalsRequest: GetExistingIssuedDocumentTotalsRequest =
{
data: invoice,
};
// Now we are all set for the final call
// Get new issued document totals: https://github.com/fattureincloud/fattureincloud-ts-sdk/blob/master/docs/IssuedDocumentsApi.md#getNewIssuedDocumentTotals
apiInstance
.getExistingIssuedDocumentTotals(
companyId,
invoiceId,
getExistingIssuedDocumentTotalsRequest
)
.then(
(data) => {
console.log(data);
},
(error) => {
console.error(error);
}
);
The Zapier Action you need is called Get Existing Issued Document Totals. After you select the action and log in, you need to select your Company ID. Luckily, our Actions let you select it from a simple dropdown menu.
Additionally, you need to select the ID of the existing document, that can be provided by a previous step.
Next, you must insert a request similar to the one we need for the Modify Issued Document request. We suggest you check the Invoice Creation Guide for more info.
You can then use the resulting totals of this request in the modification request.
๐ฉย The magic fieldโ
If you don't mind about the amounts of each payment, but you just want them to match the expected totals, we provide a magic field that could be perfect for you.
The options.fix_payments field, when set to true, adjusts your last payment amount of the payments list to match your document total, incrementing or reducing the amount accordingly. Of course, if you have only one payment it will be modified to match the document total.
The options.fix_payment field must be used in the invoice creation request. Please, notice that this field is not included in the data field that contains the main section of the request, as you can see in the following example.
{
"data": {
...
},
"options": {
"fix_payments": true
}
}
And here there is the example to make this request with our SDKs:
- C#
- Go
- Java
- JavaScript
- PHP
- Python
- Ruby
- TypeScript
- Zapier
using System;
using System.Collections.Generic;
using It.FattureInCloud.Sdk.Api;
using It.FattureInCloud.Sdk.Client;
using It.FattureInCloud.Sdk.Model;
namespace test {
class Program {
static void Main(string[] args) {
Configuration config = new Configuration();
//set your access token
config.AccessToken = "YOUR_ACCESS_TOKEN";
var apiInstance = new IssuedDocumentsApi(config);
//set your company id
var companyId = 12345;
// NOTE: this is not a complete request, for it to work you must set the invoice details!!
IssuedDocument invoice = new IssuedDocument(
// ...
);
// Here we put our invoice in the request object
CreateIssuedDocumentRequest createIssuedDocumentRequest = new CreateIssuedDocumentRequest(
data: invoice,
// And here we set the magic field
options: new IssuedDocumentOptions(
fixPayments: true
)
);
// Now we are all set for the final call
// Create the invoice: https://github.com/fattureincloud/fattureincloud-csharp-sdk/blob/master/docs/IssuedDocumentsApi.md#createissueddocument
try {
CreateIssuedDocumentResponse result = apiInstance.CreateIssuedDocument(companyId, createIssuedDocumentRequest);
Console.WriteLine(result);
} catch (ApiException e) {
Console.WriteLine("Exception when calling IssuedDocumentsApi.CreateIssuedDocument: " + e.Message);
Console.WriteLine("Status Code: " + e.ErrorCode);
Console.WriteLine(e.StackTrace);
}
}
}
}
// in this example we are using our Go SDK
// https://github.com/fattureincloud/fattureincloud-go-sdk
package main
import (
"context"
"encoding/json"
"fmt"
"os"
fattureincloudapi "github.com/fattureincloud/fattureincloud-go-sdk/v2/api"
fattureincloud "github.com/fattureincloud/fattureincloud-go-sdk/v2/model"
)
func main() {
// Configure OAuth2 access token for authorization:
auth := context.WithValue(context.Background(), fattureincloudapi.ContextAccessToken, "YOUR_ACCESS_TOKEN")
configuration := fattureincloudapi.NewConfiguration()
apiClient := fattureincloudapi.NewAPIClient(configuration)
//set your company id
companyId := int32(12345)
// NOTE: this is not a complete request, for it to work you must set the invoice details!!
invoice := *fattureincloud.NewIssuedDocument(
// ...
)
// Here we put our invoice in the request object
createIssuedDocumentRequest := *fattureincloud.NewCreateIssuedDocumentRequest().
SetData(invoice).
// And here we set the magic field
SetOptions(*fattureincloud.NewIssuedDocumentOptions().
SetFixPayments(true),
)
resp, r, err := apiClient.IssuedDocumentsAPI.CreateIssuedDocument(auth, companyId).CreateIssuedDocumentRequest(createIssuedDocumentRequest).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `IssuedDocumentsApi.CreateIssuedDocument``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
json.NewEncoder(os.Stdout).Encode(resp)
}
import it.fattureincloud.sdk.ApiClient;
import it.fattureincloud.sdk.ApiException;
import it.fattureincloud.sdk.Configuration;
import it.fattureincloud.sdk.auth.*;
import it.fattureincloud.sdk.model.*;
import it.fattureincloud.sdk.api.IssuedDocumentsApi;
import java.math.BigDecimal;
import java.time.LocalDate;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
//set your access token
OAuth OAuth2AuthenticationCodeFlow = (OAuth) defaultClient.getAuthentication("OAuth2AuthenticationCodeFlow");
OAuth2AuthenticationCodeFlow.setAccessToken("YOUR ACCESS TOKEN");
IssuedDocumentsApi apiInstance = new IssuedDocumentsApi(defaultClient);
//set your company id
Integer companyId = 12345;
// NOTE: this is not a complete request, for it to work you must set the invoice details!!
IssuedDocument invoice = new IssuedDocument()
// ...
// Here we put our invoice in the request object
CreateIssuedDocumentRequest createIssuedDocumentRequest = new CreateIssuedDocumentRequest()
.data(invoice)
// And here we set the magic field
.options(
new IssuedDocumentOptions()
.fixPayments(true)
);
// Now we are all set for the final call
// Create the invoice: https://github.com/fattureincloud/fattureincloud-java-sdk/blob/master/docs/IssuedDocumentsApi.md#createissueddocument
try {
CreateIssuedDocumentResponse result = apiInstance.createIssuedDocument(companyId, createIssuedDocumentRequest);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling IssuedDocumentsApi#createIssuedDocument");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
var fattureInCloudSdk = require("@fattureincloud/fattureincloud-js-sdk");
let defaultClient = fattureInCloudSdk.ApiClient.instance;
// set your access token
let OAuth2AuthenticationCodeFlow =
defaultClient.authentications["OAuth2AuthenticationCodeFlow"];
OAuth2AuthenticationCodeFlow.accessToken = "YOUR_ACCESS_TOKEN";
let apiInstance = new fattureInCloudSdk.IssuedDocumentsApi();
// set your company id
let companyId = 12345;
// NOTE: this is not a complete request, for it to work you must set the invoice details!!
let invoice = new fattureInCloudSdk.IssuedDocument();
// ...
// Here we put our invoice in the request object
let createIssuedDocumentRequest =
new fattureInCloudSdk.CreateIssuedDocumentRequest();
createIssuedDocumentRequest.data = invoice;
// And here we set the magic field
createIssuedDocumentRequest.options = {
fix_payments: true,
};
let opts = {
createIssuedDocumentRequest: createIssuedDocumentRequest,
};
// Now we are all set for the final call
// Create the invoice: https://github.com/fattureincloud/fattureincloud-js-sdk/blob/master/docs/IssuedDocumentsApi.md#createIssuedDocument
apiInstance.createIssuedDocument(companyId, opts).then(
(result) => {
console.log(
"API called successfully. Returned result: " + JSON.stringify(result)
);
},
(error) => {
console.error(error);
}
);
<?php
use FattureInCloud\Model\IssuedDocument;
use FattureInCloud\Model\IssuedDocumentOptions;
require_once(__DIR__ . '/vendor/autoload.php');
//set your access token
$config = FattureInCloud\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');
$apiInstance = new FattureInCloud\Api\IssuedDocumentsApi(
new GuzzleHttp\Client(),
$config
);
//set your company id
$company_id = 12345;
// NOTE: this is not a complete request, for it to work you must set the invoice details!!
$invoice = new IssuedDocument;
// Here we put our invoice in the request object
$create_issued_document_request = new CreateIssuedDocumentRequest;
$create_issued_document_request->setData($invoice);
// And here we set the magic field
$create_issued_document_request->setOptions(
new IssuedDocumentOptions(
[
"fix_payments" => true
]
)
);
// Now we are all set for the final call
// Create the invoice: https://github.com/fattureincloud/fattureincloud-php-sdk/blob/master/docs/Api/IssuedDocumentsApi.md#createissueddocument
try {
$result = $apiInstance->createIssuedDocument($company_id, $create_issued_document_request);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling IssuedDocumentsApi->createIssuedDocument: ', $e->getMessage(), PHP_EOL;
}
import datetime
import fattureincloud_python_sdk
from fattureincloud_python_sdk.api import issued_documents_api
from fattureincloud_python_sdk.models.issued_document import IssuedDocument
from fattureincloud_python_sdk.models.issued_document import IssuedDocumentOptions
from pprint import pprint
# set your access token
configuration = fattureincloud_python_sdk.Configuration()
configuration.access_token = "YOUR_ACCESS_TOKEN"
# set your company id
company_id = 12345
# NOTE: this is not a complete request, for it to work you must set the invoice details!!
invoice = IssuedDocument(
# ...
)
# Here we put our invoice in the request object
create_issued_document_request = CreateIssuedDocumentRequest(
data = invoice,
# And here we set the magic field
options = IssuedDocumentOptions(
fix_payments=true
)
)
# Now we are all set for the final call
# Create the invoice: https://github.com/fattureincloud/fattureincloud-python-sdk/blob/master/docs/IssuedDocumentsApi.md#create_issued_document
with fattureincloud_python_sdk.ApiClient(configuration) as api_client:
api_instance = issued_documents_api.IssuedDocumentsApi(api_client)
try:
api_response = api_instance.create_issued_document(company_id, create_issued_document_request=create_issued_document_request)
pprint(api_response)
except fattureincloud_python_sdk.ApiException as e:
print("Exception when calling IssuedDocumentsApi->create_issued_document: %s\n" % e)
require 'time'
require 'fattureincloud_ruby_sdk'
FattureInCloud_Ruby_Sdk.configure do |config|
# set your access token
config.access_token = 'YOUR ACCESS TOKEN'
end
api_instance = FattureInCloud_Ruby_Sdk::IssuedDocumentsApi.new
# set your company id
company_id = 12345
# NOTE: this is not a complete request, for it to work you must set the invoice details!!
invoice = FattureInCloud_Ruby_Sdk::IssuedDocument.new(
# ...
)
# Here we put our invoice in the request object
opts = {
create_issued_document_request: FattureInCloud_Ruby_Sdk::CreateIssuedDocumentRequest.new(
data: invoice,
# And here we set the magic field
options: FattureInCloud_Ruby_Sdk::IssuedDocumentOptions.new(
fix_payments: true
)
)
}
# Now we are all set for the final call
# Create the invoice: https://github.com/fattureincloud/fattureincloud-ruby-sdk/blob/master/docs/IssuedDocumentsApi.md#create_issued_document
begin
result = api_instance.create_issued_document(company_id, opts)
p result
rescue FattureInCloud_Ruby_Sdk::ApiError => e
puts "Error when calling IssuedDocumentsApi->create_issued_document: #{e}"
end
import {
Configuration,
IssuedDocumentsApi,
IssuedDocument,
CreateIssuedDocumentRequest,
} from "@fattureincloud/fattureincloud-ts-sdk";
//set your access token
const apiConfig = new Configuration({
accessToken: "YOUR ACCESS TOKEN",
});
let apiInstance = new IssuedDocumentsApi(apiConfig);
//set your company id
let companyId = 12345;
// NOTE: this is not a complete request, for it to work you must set the invoice details!!
let invoice: IssuedDocument = {
// ...
};
// Here we put our invoice in the request object
let createIssuedDocumentRequest: CreateIssuedDocumentRequest = {
data: invoice,
options: {
fix_payments: true,
},
};
// Now we are all set for the final call
// Get new issued document totals: https://github.com/fattureincloud/fattureincloud-ts-sdk/blob/master/docs/IssuedDocumentsApi.md#getNewIssuedDocumentTotals
apiInstance.createIssuedDocument(companyId, createIssuedDocumentRequest).then(
(data) => {
console.log(data);
},
(error) => {
console.error(error);
}
);
In Zapier, the magic field is called Fixes your last payment amount to match your document total, and its code is options.fix_payments; it must be set in the Create Issued Document request, check the Invoice Creation Guide for more details about this request.