Skip to main content

Invoice List on the Extranet

How to Download an Invoice Statement from the Extranet

Written by Lenka Haringerová

On our website, in the section dedicated to customers, you can find a list of invoices we have issued. We display basic information about them, such as the invoice number, date of issue, and payment status. The final invoice can be downloaded as a PDF file.

In the following guide, we will show you how to implement the same functionality on your own website.

Brief description

The web server queries Flexi (with a password) and lists all invoices issued to a specific VAT number. We assume that during installation you will handle user authentication, retrieval of the correct VAT number, and visual integration with your website.

First, Flexi sends a request to http://demo.flexibee.eu/c/demo/faktura-vydana/(dic='CZ7002051235′).js in JSON format and displays the resulting data in a table. When the user requests the PDF version, the data is retrieved from http://demo.flexibee.eu/c/demo/faktura-vydana/21.json.

The web application acts as a proxy. The accessing user therefore does not need to have a Flexi account.

For easier development, we recommend using the Httpful library, which handles the correct construction of CURL requests.

Detailed guide

The complete script package for download faktury-extranet.zip:

You need to create a configuration file:

$host = "https://demo.flexibee.eu:443";
$firma = "demo";
$user = "winstrom";
$password = "winstrom";

The important part is the section that specifies the company's VAT number. Here we assume integration with your website, which will handle user identification and retrieval of the corresponding company.


Next, it is time to load the invoice list in index.php:

<?php
include('httpful.phar');
include('config.php');

$evidence = 'faktura-vydana';
$limit = 30; // 0 = unlimited

$dic = '"CZ7002051235"';

$suffix = "/".$evidence."/(dic=".urlencode($dic).").json?order=datVyst@D&detail=detail&limit=".$limit;

$uri = $host.'/c/'.$firma.$suffix;

$response = \Httpful\Request::get($uri)
->authenticateWith($user, $password)
->send();

if($response->hasErrors())
{
echo '<html><body><h1 style="color:red">'.$response->body->winstrom->message.'</h1>';
die;
}
header('Content-Type: text/html; charset=utf-8');
?>
<html>
<head>
<title>Vystavené faktury</title>
</head>
<body>
<h1>Vystavené faktury</h1>

<?php if (!isset($response->body->winstrom->$evidence)): ?>
<p>Na Vaši firmu nebyla vystavena žádná faktura.</p>
<?php else: ?>


<table>
<thead>
<tr>
<th>Číslo faktury</th>
<th>Datum faktury</th>
<th>Částka</th>
<th>Stav</th>
</tr>
</thead>
<tbody>
<?php foreach($response->body->winstrom->$evidence as $faktura): ?>
<tr>
<td><a href="pdf.php?id=<?php echo $faktura->id; ?>"><?php echo $faktura->kod; ?></a></td>
<?php $date = new \DateTime($faktura->datVyst); ?>
<td><?php echo $date->format('d.m.Y'); ?></td>
<td style="text-align:right"><?php echo $faktura->sumCelkem; ?> Kč</td>
<td><?php echo ($faktura->stavUhrK == "") ? "<span style=\"color: red\">Neuhrazeno</span>" : "<span style=\"color: green\">".$faktura->{"stavUhrK@showAs"}." (dne ".$faktura->datUhr.")</span>"; ?> </td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>

To allow the user to view the PDF version of an invoice, we also create a file called pdf.php:

<?php
include('httpful.phar');
include('config.php');


$id = $_GET["id"];

$evidence = 'faktura-vydana';

$suffix = "/".$evidence."/".urlencode($id).".pdf";

$uri = $host.'/c/'.$firma.$suffix;

$response = \Httpful\Request::get($uri)
->authenticateWith($user, $password)
->send();

if($response->hasErrors())
{
echo '<html><body><h1 style="color:red">'.$response->body->winstrom->message.'</h1>';
die;
}
header("Content-Type: application/pdf");
header("Content-Disposition: inline; filename=\"faktura.pdf\" ");
echo $response->body;
?>

Using the Flexi REST API, you can also export invoices as ISDOC, display price lists, orders, and much more.

You can try out the resulting application on our website, or download it.

Did this answer your question?