FlexiPeeHP Logo" title="Project Logo" style="max-width: 100%;">
PHP Based Library for easy interaction with Czech accounting system FlexiBee.
CZ: PHP Library for easy work with the Czech economic system FlexiBee
❗ This library will be marked as deprecated. Please pay attention to its lightweight successor https://github.com/Spoje-NET/php-flexibee ❗
The creation of this library would not have been possible without the kind support of Spoje.Net, which paid for the development of the solution for connecting LMS / FlexiBee and importing the warehouse. ?
I would also like to thank the technical support of ABRA Flexi s.r.o. for their holy patience in responding to my not always smart questions and bug reports.
The parsing of results for GDPR logging purposes has been refined with the kind support of <PureHTML>
composer require spoje.net/ FlexiPeeHP
if your resulting composer.json will look something like this:
{
"name" : " vendor/projectname " ,
"description" : " Test " ,
"type" : " project " ,
"require" : {
"spoje.net/ FlexiPeeHP " : " * "
},
"license" : " MIT " ,
"authors" : [
{
"name" : " Vítězslav Dvořák " ,
"email" : " [email protected] "
}
],
"minimum-stability" : " stable "
}
the composer install command starts the installation:
Configuration is done by setting the following constants:
/*
* URL Flexibee API
*/
define ( ' FLEXIBEE_URL ' , ' https://flexibee-dev.spoje.net:5434 ' );
/*
* Uživatel FlexiBee API
*/
define ( ' FLEXIBEE_LOGIN ' , ' apiuser ' );
/*
* Heslo FlexiBee API
*/
define ( ' FLEXIBEE_PASSWORD ' , ' apipass ' );
/*
* Společnost v FlexiBee
*/
define ( ' FLEXIBEE_COMPANY ' , ' test_s_r_o_ ' );
/*
* Nebo pokud nechceme používat jméno a heslo
*/
define ( ' FLEXIBEE_AUTHSESSID ' , ' 6QuifebMits ' ); //Volitelné
/*
* Pomalý server, velká databáze a přes modem k tomu
*/
define ( ' FLEXIBEE_TIMEOUT ' , 60 ); //Volitelné
or credentials can be provided when instantiating the class.
$ invoicer = new FlexiPeeHP FakturaVydana ( null ,[
' company ' => ' Firma_s_r_o_ ' ,
' url ' => ' https://flexibee.firma.cz/ ' ,
' user ' => ' rest ' ,
' password ' => ' -dj3x21xaA_ '
]);
This method of setting has a higher priority than the above defined constants.
$ order = new FlexiPeeHP ObjednavkaPrijata( ' code:OBP0034/2019 ' ,[ ' companyUrl ' => $ _GET [ ' companyUrl ' ], ' authSessionId ' => $ _GET [ ' authSessionId ' ] ])
In this way, an application called by a user button passing the companyUrl and authSessionId values can connect to the flexibee and the concrete order
The central component of the entire library is the FlexiBeeRO Class, which is able to communicate with the FlexiBee REST API using the curl PHP extension.
Classes for individual records are then derived from it, containing methods for frequently used operations, for example "Pay" in the case of received invoices.
A new derived class is created in such a way that the name of the class is the name of the record, but without hyphens. These are replaced by a capital letter in the name.
function evidenceToClass ( $ evidence )
{
return str_replace ( ' ' , '' , ucwords ( str_replace ( ' - ' , ' ' , $ evidence )));
}
That is If we want to derive a new class for the "Measurement units" record, it will look like this:
<?php
/**
* @link https://demo.flexibee.eu/c/demo/merna-jednotka/properties Vlastnosti evidence
*/
class MernaJednotka extends / FlexiPeeHP /FlexiBee
{
/**
* Evidence užitá objektem.
*
* @var string
*/
public $ evidence = ' merna-jednotka ' ;
}
And then it's easy to write the measurement units on 2 lines:
$ jednotky = new MernaJednotka ();
print_r ( $ jednotky -> getAllFromFlexiBee () );
If we want the newly created class to be able to write to the flexibee, it must be derived from the ancestor FlexiBeeRW.
More usage examples can be found in a separate project
In some cases, it is good to know what actions we can take, or what the structure of the records is. This information can be obtained by calling https://demo.flexibee.eu/c/demo/*/properties.json or https://demo.flexibee.eu/c/demo/*/actions.json, but this is relatively time-consuming operation. Since the structure of records and Actions or relationships between FlexiBee records do not change often, FlexiPeeHP has a mechanism that allows working with this data without the need to query the server.
The structure is stored in the Structure class (Actions,Relations) which contains a statically defined field containing information that would otherwise have to be obtained from FlexiBee.
The item in the evidence list https://demo.flexibee.eu/c/demo/evidence-list can then be easily shown at any time:
echo FlexiPeeHP Structure:: $ evidence [ ' faktura-vydana ' ];
The structures of individual records are then stored in static variables. Their name follows the same rules as for creating a new class name, except that the first letter is lowercase. That is:
lcfirst ( FlexiPeeHP FlexiBeeRO:: evidenceToClassName ( $ evidence ))
If necessary, these classes can then be generated with the current content with the following command:
cd tools/
./update_all.sh
The operation takes a few minutes. We can display the progress as follows:
tail -f /var/log/syslog | grep FlexiPeeHP test
If you set $this->debug to true in FlexiPeeHP objects, additional tests will be performed before sending data to FlexiBee. The following possible errors are checked:
In debug mode, all flexibee requests and their responses are also saved to the /tmp folder
The library includes a mechanism for sending FlexiBee runtime errors to developers:
If FlexiBee returns an Internal Server Error 500, an email containing the error message is sent to the developers.
If FlexiBee running on the same server is used and it is possible to read the error logs, an appropriate fragment is extracted from them and added to the body of the mail.
The email also contains additional information about the license and enabled modules.
Also attached as attachments are files containing the body of the request to the server, the body of its response, and a file containing information about curl.
During the lifetime of the object, errors are logged and only the first of each type is sent.
PHPUnit tests are located in the testing folder. If you want to test against a server other than the official http://demo.flexibee.eu/ , you need to change the settings in the bootstrap.php file.
The contents of the $testServer variable determine which of the default settings will be used. And of course you can define your own. As an example, the spoje.net test server is shown here.
For testing, please first create a testing company TESTING s.r.o. and set the access data of a user authorized to use the REST API. (Which is the administrator user entered when installing FlexiBee.)
Warning: testing against a company with a lot of invoices and a connected bank may take some time, as the automatic document matching call is also tested.
If you decide to inherit FlexiPeeHP in your project and write tests for these classes also inherited from FlexiPeeHP , e.g.:
class HookRecieverTest extends Test FlexiPeeHP ChangesTest
Also add the paths to the original tests to your composer.json:
"autoload-dev": {
"psr-4": {
"Test\": "vendor/spoje.net/ FlexiPeeHP /testing/src/ FlexiPeeHP /testing/",
"Test\Ease\": "vendor/vitexsoftware/ease-framework/tests/src/Ease",
"Test\ FlexiPeeHP \": "vendor/spoje.net/ FlexiPeeHP /testing/src/ FlexiPeeHP /",
}
}
In the Examples folder are the following usage examples:
File | Description |
---|---|
AttachmentSaveToFile.php | save the attachment to a file |
AttachmentUpload.php | upload attachment |
AuthSessionIdUsage.php | AuthSessionId authentication sample |
AuthenticateContact.php | contact authentication |
BatchOperation.php | Using a filter in batch operations |
CreateLabel.php | work with labels |
DryRun.php | Test storage (dry-run) |
DownloadInvoicePDF.php | PDF invoice download |
Error404.php | work with non-existent records |
FindOverdueInvoices.php | find overdue invoices |
GetRecordWithRelation.php | Obtaining a record including data from sub-debit |
GetBankAccountForCompany.php | Obtaining a bank account for a company from the directory |
InvoiceLockUnlock.php | Locking and unlocking the record |
InvoiceCopy.php | creation of a tax document from the advance payment |
LoginLogout | user login and logout |
NajdiDanovyDokladKzalohovemu.php | document tracing |
Storage.php | Stock product with serial numbers |
NewInvoice.php | New invoice with due date written as json |
ObjectChaining.php | Chaining of objects for multiple operations in a queue only |
ObjectCooperation.php | Sharing data and connection parameters between objects |
PerformingActions.php | How to perform actions on an action document. e.g. cancellation |
ReadAddressColumns.php | return specific columns |
sendInvoiceByMail.php | sending the invoice by email |
SendReminders.php | sending reminders |
SetContactAuth.php | authentication settings |
TestConnection.php | connection check |
docker pull vitexsoftware/ FlexiPeeHP
There are .deb packages available for Linux. Please use the repo:
wget -O - http://v.s.cz/[email protected]|sudo apt-key add -
echo deb http://v.s.cz/ stable main > /etc/apt/sources.list.d/ease.list
aptitude update
aptitude install FlexiPeeHP
In this case, you need to add the following to your application's composer.json file:
"require" : {
"spojenet_ FlexiPeeHP " : " * " ,
"vitexsoftware_ease-framework" : " * "
},
"repositories" : [
{
"type" : " path " ,
"url" : " /usr/share/php/ FlexiPeeHP " ,
"options" : {
"symlink" : true
}
},
{
"type" : " path " ,
"url" : " /usr/share/php/Ease " ,
"options" : {
"symlink" : true
}
}
]
So when you install the dependencies it will look something like this:
Loading composer repositories with package information
Installing dependencies from lock file
- Installing vitexsoftware_ease-framework (1.1.3.3)
Symlinked from /usr/share/php/Ease
- Installing spojenet_ FlexiPeeHP (0.2.1)
Symlinked from /usr/share/php/ FlexiPeeHP
And it will be possible to update globally for the entire system via apt-get.
We also generate the FlexiPeeHP -doc package, containing developer documentation generated using the ApiGen program. The documentation can be viewed online at http://flexibee-dev.spoje.net/FlexiPeeHP/
Testing:
cd /usr/share/doc/ FlexiPeeHP /
composer install
php -f flexibeeping.php
We create the Debian package by running make deb
Image for Docker:
docker build -t vitexsoftware/ FlexiPeeHP
Work statistics on the WakaTime project