Member
Posts: 153
Registered: ‎04-11-2017
Kudos: 26
Solutions: 4
Accepted Solution

ARGENTINA | AFIP - INVOICES

In argentina in the invoices the tax entity (afip) forces us to get and print 2 codes that they deliver via webservices (http://www.afip.gob.ar/ws/default.asp?noalert=1) "bardcode + cae" this could be incorporated into ucrm?


Accepted Solutions
Ubiquiti Employee
Posts: 3,913
Registered: ‎12-10-2015
Kudos: 1379
Solutions: 299

Re: ARGENTINA | AFIP - INVOICES

[ Edited ]

The new plugin for Argentinian Invoicing has been released!

Check out the Plugin Section in your UCRM:

 

Selection_999(363).png

 

Or go the plugin repo: https://github.com/Ubiquiti-App/UCRM-plugins/tree/master/plugins/argentina-afip-invoices


Credit to @fgampel

View solution in original post


All Replies
Ubiquiti Employee
Posts: 3,913
Registered: ‎12-10-2015
Kudos: 1379
Solutions: 299

Re: ARGENTINA | AFIP - INVOICES

could you please provide us with some more details?

INPUT
- What data you need to have the codes generated? (clientId or your organizationID,...)

OUTPUT
- How does the output look like? Just a number or image?

USAGE
- how do you need to display it on the invoice? as an image, or number?
Member
Posts: 153
Registered: ‎04-11-2017
Kudos: 26
Solutions: 4

Re: ARGENTINA | AFIP - INVOICES

I really do not know exactly how it works, what it is is that the systems that make invoices in Argentina when making an invoice should send via webservices to the controller (afip) all the data of the invoice and they respond with a bar code and a value date (CAE) to be printed at the bottom of the invoice.

 

https://www.afip.gob.ar/fe/documentos/manual_desarrollador_COMPG_v2_9.pdf

https://wswhomo.afip.gov.ar/wsfex/service.asmx?WSDL

 

but let's hope that some developer from Argentina with experience in this that is from the group can explain it.

It is quite complicated in Argentina billing there is much control, will there be way to export all the data from a separate invoice all fields to a csv excel?

 

 

New Member
Posts: 2
Registered: ‎09-17-2017

Re: ARGENTINA | AFIP - INVOICES

tiene el modulo para facturacion electronica con afip en argentina??

Member
Posts: 153
Registered: ‎04-11-2017
Kudos: 26
Solutions: 4

Re: ARGENTINA | AFIP - INVOICES

no, pero por ahi pueden añadirlo, pero necesitamos algun programador que les pase un php o se los explique.. jeje..

Ubiquiti Employee
Posts: 3,913
Registered: ‎12-10-2015
Kudos: 1379
Solutions: 299

Re: ARGENTINA | AFIP - INVOICES

I think it's feasible. I suggest this way:
1) create a custom invoice template with an image for the bar code. The source of the image will point to your script
2) the script will use UCRM API and the Argentine webservice to generate the image

We can help with the php scripting, especially the UCRM API side. But it would be helpful to get some help from someone who knows some details about the Argentine webservice.

If you need to download all invoices, you can use the export feature at Billing > Invoices - select all rows and click export.
If you need more details about the invoices, again, the solution is API. This is an example script, which when modified, could give you all the details about invoices https://help.ubnt.com/hc/en-us/articles/115003906007-UCRM-API-Usage
Member
Posts: 153
Registered: ‎04-11-2017
Kudos: 26
Solutions: 4

Re: ARGENTINA | AFIP - INVOICES

i attach sample invoice type B for end user (not enterprise)

 

adjunt html code.

 

<!DOCTYPE html>
<html><head><title>Print Invoice</title>

<meta charset="UTF-8">
<style>
*
{
margin:0;
padding:0;
font-family:Arial;
font-size:10pt;
color:#000;
}
body
{
width:100%;
font-family:Arial;
font-size:10pt;
margin:0;
padding:0;
}
p
{
margin:0;
padding:0;
}
#contentbill{
height:auto;
}
#wrapperbill
{
width:180mm;
margin:0 15mm;
}
.page
{
height:297mm;
width:210mm;
page-break-after:always;
}
table
{
border-left: 1px solid #ccc;
border-top: 1px solid #ccc;
border-spacing:0;
border-collapse: collapse; }
table td {
border-right: 1px solid #ccc;
border-bottom: 1px solid #ccc;
padding: 2mm;
}
table.heading
{
height:50mm;
}
h1.heading
{
font-size:14pt;
color:#000;
font-weight:normal;
}
h2.heading
{
font-size:9pt;
color:#000;
font-weight:normal;
}
hr
{
color:#ccc;
background:#ccc;
}
#footer
{ width:180mm;
margin:0 15mm;
padding-bottom:3mm;
}
#footer table
{
width:100%;
border-left: 1px solid #ccc;
border-top: 1px solid #ccc;
background:#eee;
border-spacing:0;
border-collapse: collapse; }
#footer table td
{
width:25%;
text-align:center;
font-size:9pt;
border-right: 1px solid #ccc;
border-bottom: 1px solid #ccc;
}
.lineSmall{
border: 0;
color: #345092;
background-color: #345092;
height: 2px;
}
.lineLarge{
width: 680px;
border: 0;
color: #345092;
background-color: #345092;
height: 2px;
margin-top: 0px;
margin-bottom: 0px;
}
.lineDotted{
width: 680px;
border: 1px dashed black;
color: #345092;
height: 1px;
margin-top: 0px;
margin-bottom: 0px;
}
</style></head>
<body>
<div id="wrapperbill">
<div id="logofactura" style="text-align: center;"></div>
<div id="tipofactura" style="text-align: center; padding-top: 5mm;"></div>
<hr class="lineLarge"><br>
<table style="width: 681px; height: 127px;" class="heading">
<tbody>
<tr>
<td style="text-align: center; height: 107px; width: 80mm;" width="301">
<h1 class="heading"><img src="%logo%" height="100" width="291"></h1>
</td>
<td style="padding: 3mm; height: 75px;" rowspan="1" colspan="1" align="center" valign="top" width="65">
<p style="border: 1px solid grey; padding-top: 0px; padding-bottom: 0px; background-color: rgb(52, 80, 146); color: white; font-size: 42px;">&nbsp;B&nbsp;
</p>
<br>
<p style="margin-left: 0px; width: 87px;"><small><small>Codigo Nº 06</small></small></p>
</td>
<td colspan="1" rowspan="3" style="padding: 3mm; height: 75px;" align="right" valign="top" width="282">
<div style="text-align: right;"><big><big><span style="font-weight: bold;"><big><big><big><br>
FACTURA<br><br></big></big>
</big></span></big></big></div>
<table>
<tbody>
<tr>
<td>Numero: </td>
<td>%invoiceNum%</td>
</tr>
<tr>
<td>Fecha : </td>
<td>%date%</td>
</tr>
<tr>
<td><b>1er Vencimiento : </b></td>
<td><b>%ddate1%</b></td>
</tr>
<tr>
<td><b>2do Vencimiento : </b></td>
<td><b>%ddate2%</b></td>
</tr>
<tr>
</tr>
<tr>
<td><b>Total : </b></td>
<td><b>$ %billTotal%</b></td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div style="margin-left: 15px; text-align: left; width: 192px;">
<p><b>CUIT:&nbsp;</b>%cuitnumber%</p>
<p><b>Ing. Brutos:&nbsp;</b>%ibnumber%</p>
<p><b>Inicio de Act.:&nbsp;</b>%startactivity%</p>
</div>
</td>
</tr>
<tr>
<td colspan="2" rowspan="1" style="height: 75px;"><small>
</small>
<p style="font-family: Helvetica,Arial,sans-serif;"><span style="font-weight: bold;">%empresa&amp;</span></p>
<p style="font-family: Helvetica,Arial,sans-serif;">%direccion%</p>
<p style="font-family: Helvetica,Arial,sans-serif;"><b>%email$</b></p>
<p style="font-family: Helvetica,Arial,sans-serif;"><b>%telefono%</b></p>
<p style="font-family: Helvetica,Arial,sans-serif;">%situacioniva%</p>
</td>

</tr>
<tr>
<td colspan="2" rowspan="1" style="height: 57px;"><big><b><small>Cliente Numero:</small>
<big>%user%</big></b></big><br><b>Titular:
%custName%</b> <br>
Domicilio: %custAddress% <br>
Ciudad: %custCity% - %custState%<br>
Tipo: %customertype%<br></td>
</tr>
</tbody>
</table>
<div id="contentbill">
<div id="periodo" style="text-align: center;">
<hr class="lineLarge"><br>
<b>%month%</b> </div>
<div id="invoice_body">
%items%
<table>
<tbody>
<tr style="background: rgb(238, 238, 238) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;">
<td style="width: 8%;"><b>N</b></td>
<td style="width: 8%;"><b>Codigo</b></td>
<td><b>Detalle</b></td>
<td style="width: 15%;"><b>Cantidad</b></td>
<td style="width: 15%;"><b>Precio Unitario</b></td>
<td style="width: 15%;"><b>Total</b></td>
</tr>
%items
</tbody>
</table>
<br>
<!-- <p><strong>TOTAL FACTURADO: $ %billTotal%</strong></p>-->
<table style="border-top: 1px double rgb(0, 0, 0); text-align: left; width: 680px; height: 66px;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; text-align: right;"><span style="font-weight: bold;">Total:</span><br>
</td>
</tr>
<tr>
<td style="vertical-align: top; text-align: right;"><span style="font-weight: bold;">$ %billTotal%</span></td>
</tr>
</tbody>
</table>
<br>
<p><strong>Monto adeudado meses vencidos: $ %comment%</strong></p>
<!-- <p>Si tiene dudas sobre el monto que usted debe abonar consultelas via email a facturacion@wninternet.com</p> -->
<p><br>
</p>
</div>
<hr class="lineLarge"><br>
<br>
<div id="codigoafip" style="text-align: center;"> <barcode code="%codebar%" type="I25" size="1.0" height="1.0"><br>
</barcode>
<div style="text-align: right;"><barcode code="%codebar%" type="I25" size="1.0" height="1.0"><b>CAE:</b> %cae% </barcode><br>
<barcode code="%codebar%" type="I25" size="1.0" height="1.0"><b>Vto. CAE:</b> %vtoCae%</barcode><br>
<barcode code="%codebar%" type="I25" size="1.0" height="1.0"></barcode></div>
<div style="text-align: left;">%codebar2%
</div>
</div>
<br>
<hr class="lineDotted"><br>
<br>
	<table style="width: 681px; height: 71px; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="text-align: justify; width: 401px;"><span style="font-weight: bold;">Recuerde que con este codigo podra realizar el pago en:</span><br style="font-weight: bold;">PagoFacil, RapiPago, Bapro, Visa, Mastercard, AmericanExpress, Tarjeta Naranja, Tarjeta Cencosud, Tarjeta Mas, Tarjeta Shopping.</td><td colspan="1" rowspan="1" style="text-align: center; vertical-align: middle; white-space: nowrap; width: 246px;"><strong>Codigo Pago Electronico: </strong>
			<br>
			<img src="%ctadigital%">			
		</td>
		
</tr></tbody></table><br><br>
<hr class="lineDotted"><br>
<div id="textoabajofactura" style="text-align: justify;">
<p>&nbsp;</p>
<p><strong>¿COMO PUEDO VER ESTA FACTURA?</strong></p>
<p><br>
Recuerde que puede ver sus facturas en
http://%clientportal%<br>
Usuario: %user% y Clave: %password%<br>
<br>
</p>
<hr class="lineLarge"></div>
</div>
<p>&nbsp;</p>
</div>
</body></html>

 

Capture.PNG
New Member
Posts: 38
Registered: ‎05-16-2016
Kudos: 17

Re: ARGENTINA | AFIP - INVOICES

Hello there, argentinian dev here with experience implementing AFIP webservices.

 

@UBNT-Petr the only feasible way to implement this is if we get API callbacks from UCRM.

 

The AFIP web service is the one in charge of prividing you the invoice UUID, which is unique.

Argentinian electronic bills have a unique number with the format XXXXX-XXXXXXXXXXX.

First 5 digits are the point of sale, remaining digits are the invoice number.

Numbers are unique and correlative and you can not generate an invoice with other number than the one provided by the web service.

Also, there is the "CAE" code, which is a validation code provided by AFIP to the user so that he can validate the invoice online at AFIP's website.

The barcode is just the CAE code rendered in EAN19 formar and that should not be UCRM's duty IMHO.

 

Ideally, if we could get a callback that runs BEFORE the invoice data is actually generated, that would be in my opinion the perfect way.

 

The callback would call a custom script with the invoice data (products, amounts, customer data, etc), the script would call AFIP WS and get the CAE and invoice number and return the data in whatever format you guys define.

But keep in mind that it is mandatory that the invoice number can be set as the one returned by AFIP web services, so, ideally, the script would return:

  1. POS number
  2. Invoice number
  3. CAE code

and then we should be able to read that from an invoice template.

 

I have all this working already on a custom CRM im using for my ISP and i would be willing to contribute the integration if the API callback is there one day (or maybe you have a better idea?).

 

Cheers!

// Diego

 

 

 

 

Ubiquiti Employee
Posts: 3,913
Registered: ‎12-10-2015
Kudos: 1379
Solutions: 299

Re: ARGENTINA | AFIP - INVOICES

@DiegoMax
I think it is feasible, we will make more investigation in this.
Can you please send me some details about the AFIP usage - What you need to configure in your current custom CRM? It will help us to make the interface most convenient for you.

Meanwhile, the only workaround is as described above - through the images placed into the invoice template, which source would point to your custom script.
New Member
Posts: 38
Registered: ‎05-16-2016
Kudos: 17

Re: ARGENTINA | AFIP - INVOICES

@UBNT-Petr, thanks for replying!

 

This is the an excerpt from my custom CRM config file (i have replaced sensitive details with XXXXXX):

 

 

    [
      'cuit' => '20XXXXXXXX4',
      'uuid' => 'dffsdlfdsflkdfs',
      'description' => '20-XXXXXXXX-4 / HOMOLOG',
      'address1' => 'Address line 1 displayed on invoice',
      'address2' => 'Address line 2 displayed on invoice',
      'production' => false,
      'wsaa' => array(
        'passprhase' => 'foobar',
        'wsdl' => 'https://wsaahomo.afip.gov.ar/ws/services/LoginCms?wsdl',
        'end_point' => 'https://wsaahomo.afip.gov.ar/ws/services/LoginCms',
        'cert_file_name' => CONFIG . 'AFIP' . DS . 'XXXXXXXXXXX/afip.pem',
        'key_file_name' => CONFIG . 'AFIP' . DS . 'XXXXXXXXXXX/afip.key',
      ),
      'wsfev1' => array(
        'wsdl' => 'https://wswhomo.afip.gov.ar/wsfev1/service.asmx?wsdl',
        'end_point' => 'https://wswhomo.afip.gov.ar/wsfev1/service.asmx',
        'sale_point' => 4
      )
    ]

 

Basically there are 2 different web services that AFIP provides.

  • wsaa is for authentication and authorization (gives you back a token)
  • wsfev1 is for getting and authorizing invoices (gives you back the CAE code and authorized invoice number)

When you sign up for electronic invoicing with AFIP, at the end of the process they will give you the .pem certificate that (together with the key) you use to authenticate with wsaa.

 

This is the code im currently using on my CRM (and the one that i was thinking of implementing with UCRM if we ever get the callbacks i was mentioning before): https://github.com/DiegoMax/AfipServices

 

But like i said before @UBNT-Petr, we NEED a way to override the invoice number in UCRM BEFORE the invoice is actually generated/saved, because in argentina it is the AFIP the one authorizing the invoice number.

So even if your idea of calling an image script above could work, its useless if we can not override the invoice number in UCRM. 

 

In Argentina, bills can be generated for a customer with either his DNI (argentina's national id number) or by the customer's CUIT (like US' SSN), so when  you call the AFIP WS, at the bare minimum you will need:

 

  • Customer's DNI or CUIT
  • Customer's ID type (80 for CUIT, 22 for DNI) 
  • Invoice amount
  • Invoice type (A, B or C)
  • Organization's Point of Sale #
  • Organization's CUIT

However, (and ideally) nothing of this code should be inside UCRM in my opinion.

 

Regarding specific fields to deal with AFIP, we might need

  • For Organizations:
    • CUIT (format is: XX-XXXXXXXX-X, last digit is a validator, and i can link you up to validation code)
    • Fiscal Condition (it can be either "IVA Responsable Inscripto" or "IVA Responsable Monotributo")
  • For Customers:
    • CUIT
    • DNI (format is XXXXXXXX, just an int, no validation)

There is of course a lot more to AFIP web services, but with this bare minimum implementation it could be usable.

 

Im willing to help you test this (and i can provide you with access to their testing web services via private communication).

 

Thanks!

 

 

 

 

 

 

New Member
Posts: 16
Registered: ‎05-01-2016
Kudos: 9

Re: ARGENTINA | AFIP - INVOICES

Hello @UBNT-Petr !!!

 

Do you have an estimate when this solution will be available?

 

Best regards,

Martin.-

 

Ubiquiti Employee
Posts: 3,913
Registered: ‎12-10-2015
Kudos: 1379
Solutions: 299

Re: ARGENTINA | AFIP - INVOICES

It's on our list, but it hasn't been scheduled yet. Hopefully, the development will start early next year.
New Member
Posts: 1
Registered: ‎02-05-2018

Re: ARGENTINA | AFIP - INVOICES

Hi @UBNT-Petr, I'm trying to add the link of my script.php in the img source to then make the calls to afip but TWIG TEMPLATE ENGINE does not let me add php in the template of the invoice, how should I add it? thank you, i am from Argentinan and I need you generate invoices with AFIP.

sorry for my english.

Ubiquiti Employee
Posts: 3,913
Registered: ‎12-10-2015
Kudos: 1379
Solutions: 299

Re: ARGENTINA | AFIP - INVOICES

@antolinij Hi, you can't add a script into a template directly, that would be a security risk. What you can do is to use the script URL in the template, something like src="http://10.11.12.13/myscript.php"

Currently, you need to manage the script outside UCRM, on your own web server.

However, in the next release, you will be able to create and upload any php script as a plugin directly into UCRM. Please follow the forum for more details. We would be happy to help you with creating a new plugin.
Member
Posts: 153
Registered: ‎04-11-2017
Kudos: 26
Solutions: 4

Re: ARGENTINA | AFIP - INVOICES

"However, in the next release, you will be able to create and upload any php script as a plugin directly into UCRM. Please follow the forum for more details. We would be happy to help you with creating a new plugin."

 

in which version of relase?

Ubiquiti Employee
Posts: 1,385
Registered: ‎03-21-2016
Kudos: 226
Solutions: 155

Re: ARGENTINA | AFIP - INVOICES

@PabloE Plugin support is planned for 2.10.0-beta1.

Ubiquiti Employee
Posts: 3,913
Registered: ‎12-10-2015
Kudos: 1379
Solutions: 299

Re: ARGENTINA | AFIP - INVOICES

Hi @DiegoMax please take a look at the UCRM Plugins introduced in 2.10.0-beta1 (https://community.ubnt.com/t5/UCRM/UCRM-Plugins-are-here/m-p/2245582#M7253) Do you think you could reuse your script and create a plugin from that? Then, we will be able to get a better insight and probably come up with seamless integration of the plugin output into the invoice template.
New Member
Posts: 38
Registered: ‎05-16-2016
Kudos: 17

Re: ARGENTINA | AFIP - INVOICES


@UBNT-Petrwrote:
Hi @DiegoMax please take a look at the UCRM Plugins introduced in 2.10.0-beta1 (https://community.ubnt.com/t5/UCRM/UCRM-Plugins-are-here/m-p/2245582#M7253) Do you think you could reuse your script and create a plugin from that? Then, we will be able to get a better insight and probably come up with seamless integration of the plugin output into the invoice template.

Hello, i have uninstalled UCRM some weeks ago (i never had it in a production env), because it had a lot of missing features that i really needed (mainly this one), i will reinstall it ASAP and see what i can do.

Thanks a lot!

 

// Diego

Ubiquiti Employee
Posts: 3,913
Registered: ‎12-10-2015
Kudos: 1379
Solutions: 299

Re: ARGENTINA | AFIP - INVOICES

Thanks @DiegoMax

Could you possibly write down a brief list of the topmost missing features related to Argentina (besides the AFIP)?
New Member
Posts: 1
Registered: ‎02-05-2015

Re: ARGENTINA | AFIP - INVOICES

someone has been able to generate afip invoice ?