Integrating accounting with E-conomic

E-conomic is danish accounting system. For us here in Estonia it may seem far and irrelevant, but I'll still try to describe its posiibilities and integration, because it has been expanding for couple of years now and by now it supports 9 countries. Thus this article may be useful for business owners, legal or integration men like me. To contrast it all, this system is often integrated with payment systems, like epay.

economic_data_model.png

Before going to youtube videos to understand how things are done from UI, we, developers tend to ask conceptual or database diagram first. So here it is 

As you can see, central objects here are invoice, debtor, product, order, subscription and main functionality is done around them. Smaller tables only specify parameters like currency, taxes and measurement units.

To integrate our application with their API we'll be using SOAP 1.2, which is very poorly documented and number of objects-methods is hardly understandable without knowing the structure above. Here is my example of adding client

$resClient = new SoapClient('https://www.e-conomic.com/secure/api1/EconomicWebService.asmx?wsdl', array('soap_version' => SOAP_1_2));

$resClient->connect(array( 
'agreementNumber' => your_service_id
'userName' => login
'password' => password ));

$arrExDebtor = $resClient->Debtor_FindByNumber(array('number' => 57945)); //looking up some user by ID

if (!isset($arrExDebtor->Debtor_FindByNumberResult->Number)){
$resClient->Debtor_Create(array(
'number' => 57945,
'debtorGroupHandle' => array('Number' => 3), //add him to group nr 3
'name' => 'Artjom Kurapov',
'vatZone' => 'HomeCountry' //tax zone, if country is not within EU, then = Abroad
));
}

$resClient->Debtor_SetCurrency(array(
'debtorHandle' => array('Number'=> 57945),
'valueHandle' => array('Code'=>978) //yes, its EUR currency code in ISO
));

Note that I've excluded try-catch blocks to make things more compact. Actually you'll need to wrap it around because server may go offline. Also, if you are going to make payments, do take it into account (so that your payment doesnt nesseserily gets affected by this service being down)


So now lets try adding new invoice that will be available as pdf for download

$objInvoice = $resClient->CurrentInvoice_Create(array(
'debtorHandle'=>array('Number'=>57945),
'name'=> 'Artjom Kurapov'
));

$resClient->CurrentInvoice_SetCurrency(array(
'currentInvoiceHandle'=>array('Id'=>$objInvoice->CurrentInvoice_CreateResult->Id),
'valueHandle'=>array('Code'=>$arrUser['currency']
)));


//now lets add invoice line.. you may need cycle here for multiple lines
$objLineHandle = $resClient->CurrentInvoiceLine_Create( array(
'invoiceHandle'=>array('Id'=>$intInvoiceHandle)
));
$intLineID = $objLineHandle->CurrentInvoiceLine_CreateResult->Id;
$intLineNr = $objLineHandle->CurrentInvoiceLine_CreateResult->Number;

$resClient->CurrentInvoiceLine_SetProduct(array(
'currentInvoiceLineHandle'=>array('Id'=>$intLineID,'Number'=>$intLineNr),
'valueHandle'=>array('Number'=> some_product_number_id) //static in this case
));

$resClient->CurrentInvoiceLine_SetDescription(array(
'currentInvoiceLineHandle'=>array('Id'=>$intLineID,'Number'=>$intLineNr),
'value'=> "Product description for pdf"
));

$resClient->CurrentInvoiceLine_SetUnitNetPrice(array(
'currentInvoiceLineHandle'=>array('Id'=>$intLineID,'Number'=>$intLineNr),
'value'=> 50 //price of unit, netto
));
$resClient->CurrentInvoiceLine_SetQuantity(array(
'currentInvoiceLineHandle'=>array('Id'=>$intLineID,'Number'=>$intLineNr),
'value'=>1 //product quantity
));

$resClient->CurrentInvoiceLine_SetUnit(array(
'currentInvoiceLineHandle'=>array('Id'=>$intLineID,'Number'=>$intLineNr),
'valueHandle'=>array('Number' => number_of_unit_for_product) // years,kilograms,meters
));
RSS

Comments

  • Deen
    avatar
    Do you have an example how to update the debtor from mySQL?
  • What do you mean by "from mySQL"? This is a remote service.. And if you want to sync data with your local mysql, then its another story :)
  • Deen
    avatar
    Yes thats what I mean. Data integration between mySQL database and e-conomics database through the API. Like when a new customer register in mySQL it will be updated into e-conomics as well. Do you have the script or can you develop it? or do you know any source for the code
  • Thats exactly the code that is listed above, except that I didn't provide all the mysql connect & select process (that supposed to be easy). Basically you get your data and pass it through wsdl Debtor_Set... methods

    And data/process entirely depends on your application logic. For example E-conomic provides methods to fetch invoices in pdf.. some may find that useful, some not.
  • Deen
    avatar
    How do I pass data through wsdl_set..methods ? Can you give an example here ?
  • Example is above. It uses only Debtor_SetCurrency, but there are all sorts of methods like Debtor_SetName, Debtor_SetAddress, Debtor_SetEmail, Debtor_SetVatZone, Debtor_SetCountry... thats in case you update user.
  • Deen
    avatar
    How do I pass data through wsdl_set..methods ? Can you give an example here ?
  • Deen
    avatar
    Thanks for your help. Really appreciate it.