LimeReport Forum

General Category | Основное => Discussion | Обсуждение => Topic started by: pcuevas on April 24, 2017, 04:08:30 PM

Title: PADDING numbers
Post by: pcuevas on April 24, 2017, 04:08:30 PM
First off, your app is great. You must accept donations for this great job.

Anyway, I would like to know if possible to pad number?
I mean if I have 23, I would like something like 0000023.

Best Regards
Pablo
Title: Re: PADDING numbers
Post by: Arin Alex on April 24, 2017, 05:56:41 PM
Hi! Thank you for your kind words and your suggestion :)
For padding you can use the next trick
Put this code into the TextItem content.
Code: [Select]
$S{
function padLeft(nr, n, str){
    return Array(n-String(nr).length+1).join(str||'0')+nr;
}
padLeft(23,7,"0")
}
Also you can put the padLeft function description on the Script page
Code: [Select]
 
function padLeft(nr, n, str){
    return Array(n-String(nr).length+1).join(str||'0')+nr;
}
and use it in the TextItem like this:
Code: [Select]
$S{ padLeft(23,7,"0") }
Title: Re: PADDING numbers
Post by: pcuevas on April 24, 2017, 08:03:40 PM
Many thanks Amigo!!

I make an alternate solution, as my data was comming from postgresql I create an sql statement into the datasource to get the values:

select LPAD(punto_venta::text,4,'0') AS PtoVta,  LPAD(numeracion::text,8,'0') AS Numeracion,
to_char(to_date(substring(fechaemision from 1 for 8),'YYYYMMDD'),'DD/MM/YYYY') AS fechaemision,
to_char(to_date(substring(fechainiactividades from 1 for 8),'YYYYMMDD'),'DD/MM/YYYY') AS fechainiactividades
from comprobantes_encabezado
where id = $V{IDComprobante}