LimeReport Forum
General Category | Основное => Discussion | Обсуждение => Topic started 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
-
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.
$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
function padLeft(nr, n, str){
return Array(n-String(nr).length+1).join(str||'0')+nr;
}
and use it in the TextItem like this:
$S{ padLeft(23,7,"0") }
-
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}