MT#5879 Mainly template changes to generate multipage document. now is generated, but with errors. Added rows as allowed attribute for <g. Additional changes for fake calls rows = with row numbers/

ipeshinskaya/InvoiceTemplate5
Irina Peshinskaya 11 years ago committed by Victor Seva
parent 44e61d95f6
commit 4fdee6478b

@ -354,17 +354,17 @@ sub base :Chained('list_customer') :PathPart('') :CaptureArgs(1) {
$c->stash(template => 'customer/details.tt');
$c->stash(contract => $contract_first);
$c->stash(contract_rs => $contract_rs);
#$zonecalls_rs = [$zonecalls_rs->all()];
#my @array = @$zonecalls_rs;
#FAKE FAKE FAKE FAKE
$zonecalls_rs = [$zonecalls_rs->all()];
my @array = @$zonecalls_rs;
##@array = (@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array);
#$zonecalls_rs = [@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array];
$zonecalls_rs = [@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array];
##$zonecalls_rs = [ 1..100 ];
my $i = 1;
$zonecalls_rs = [map{[$i++,$_]}@$zonecalls_rs];
#use irka;
#use Data::Dumper;
#irka::loglong(Dumper($zonecalls_rs) );
$c->stash(zonecalls_rs => $zonecalls_rs->all() );
$c->stash(zonecalls_rs => $zonecalls_rs );
$c->stash(billing_mapping => $billing_mapping );
}
@ -837,8 +837,8 @@ sub calls :Chained('base') :PathPart('calls') :Args(0) {
);
#my @array = $zonecalls_rs->all();
#s$zonecalls_rs = [@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array];
$c->stash(zonecalls_rs => $zonecalls_rs);
#$c->stash(zonecalls_rs => [1..100] );
#$c->stash(zonecalls_rs => $zonecalls_rs);
$c->stash(zonecalls_rs => [1..100] );
}
$c->stash(template => 'customer/calls.tt');
}
@ -970,7 +970,8 @@ sub calls_svg :Chained('base') :PathPart('calls/template') :Args {
#prepare response
#mess,mess,mess here
if($in->{tt_output_type} eq 'svg'){
$c->response->content_type('image/svg+xml');
$c->response->content_type('text/html');
# $c->response->content_type('image/svg+xml');
}elsif($in->{tt_output_type} eq 'pdf'){
$c->response->content_type('application/pdf');
}elsif($in->{tt_output_type} eq 'html'){

@ -4764,7 +4764,8 @@ this.setSvgString = function(xmlString) {
svgroot.appendChild(svgcontent);
//var startre=;
//svgroot.outerSvgTag = outerSvgTag;
svgroot.outerSvgTag = xmlString.match(/\<svg[^\>]*\>/);
svgroot.outerSvgTagStart = xmlString.match(/^(?:[\n\r\t\s]|.)*?(?:\<svg)[^\>]*\>/);
svgroot.outerSvgTagEnd = xmlString.match(/<\/svg>(?:[\n\r\t\s]|.)*$/);
//console.log(outerSvgTag[0]);
//alert(outerSvgTag[0]);
//alert('svgroot.innerHTML='+svgroot.outerHTML);

@ -27,6 +27,7 @@
<tbody>
[%# Dumper.dump_html(zonecalls_rs.as_query)%]
[% FOR call IN zonecalls_rs -%]
[%IF call.1; call = call.1; END%]
[% total_number = total_number + call.get_column('number') %]
[% total_duration = total_duration + call.get_column('duration') %]
[% total_free_time = total_free_time + call.get_column('free_time') %]
@ -86,7 +87,7 @@ function init_embed() {
}
function loadSvg(params) {
//alert('[%- c.uri_for_action("/customer/calls_svg", [contract.id]) -%]'+params);
alert('[%- c.uri_for_action("/customer/calls_svg", [contract.id]) -%]'+params);
background( '[%- c.uri_for_action("/customer/calls_svg", [contract.id]) -%]'+params,'',
function(httpResponse){
//alert(httpResponse);
@ -109,14 +110,58 @@ function handleShowSvgParsedData(data, error) {
else
{
//alert('Congratulations. Your SVG string is back in the host page, do with it what you will\n\n' + data);
//alert(encodeURIComponent(data));//works in ie
background('[%- c.uri_for_action("/customer/calls_svg", [contract.id]) -%]'+'/svg/parsed/previewed','template='+encodeURIComponent(data),
//alert(encodeURIComponent(data));
var q = '[%- c.uri_for_action("/customer/calls_svg", [contract.id]) -%]'+'/svg/parsed/previewed';
//alert(q);
//alert(data);
background( q ,'template='+encodeURIComponent(data),
function(httpResponse){
//alert(httpResponse);
var img = document.getElementById('svgpreview'); //new Image();
img.src = "data:image/svg+xml," + encodeURIComponent(httpResponse);
alert(img.outerHTML);
alert(img.html());
var previewIframe = document.getElementById('svgpreview'); //new Image();
var previewDoc = previewIframe.contentWindow.document;
//if(previewIframe.contentDocument) {
// doc = previewIframe.contentDocument;
//} else {
// doc = previewIframe.contentWindow.document;
//}
//previewIframe.contentWindow.document.body.innerHTML='<html></html>';
//alert(doc);
var pages = new Array();
pages = httpResponse.match(/(<svg[\r\n\t\s\S\w\W]*?(?:\/svg>))/gi );
if(!pages){
pages = new Array();
}
alert('images='+previewDoc.images.length+';pages='+pages.length);
if(pages.length > 0 ){
previewIframe.src = '';
previewDoc.body.innerHTML = '<html><body>'+httpResponse+'</body></html>';
alert(previewDoc.body.innerHTML);
/*
var i;
for( i = 0; i < previewDoc.images.length; i++ ){
var img = previewDoc.images[i];
img.parentElement.remove(img);
}
for( i = 0; i < pages.length; i++ ){
img = previewDoc.createElement('img');
//alert(img);
//img.width=215;
//img.heith=297;
img.src = "data:image/svg+xml," + encodeURIComponent(pages[i]);
}
alert('images='+previewDoc.images.length);
alert(previewDoc.body.innerHTML);
*/
}else{
previewIframe.src = "data:image/svg+xml," + encodeURIComponent(httpResponse);
}
//alert(img.outerHTML);
//alert(img.html());
}
);
}

@ -1,5 +1,6 @@
<!--{[%PROCESS 'customer/calls_template.tt' -%]}-->
<!--{[%row_vertical_interval = 10 -%]}-->
<!--{[%MACRO document_header BLOCK-%]}-->
<svg width="215mm" height="297mm" viewBox="0 0 215 297" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" stroke-width="0" stroke="#000000" fill="#000000" font-size="4pt" font-family="HelveticaNeue-Light" xml:space="preserve" text-anchor="start">
<style>
@ -39,11 +40,11 @@ g, text, tspan {
}
]]>
</style>
<!--pageSet>
<page-->
<!--pageSet-->
<!--{[%END-%]}-->
<!--{[%MACRO titlepage(callsdata) BLOCK-%]}-->
<!--page-->
<g y="0" x="0" width="215" height="297" id="titlepage">
<title>TitlePage</title>
@ -92,7 +93,9 @@ g, text, tspan {
<!--{[%END-%]}-->
<!--{[%MACRO datarow(call) BLOCK-%]}-->
<text y="10" text-anchor="end" id="calls[%loop.count-%]" class="datarow">
<tspan x="5" id="calls_zone[%loop.count-%]" text-anchor="start"><!--{[% call.get_column('zone') %]}--><!--{[%#}-->Example zone<!--{%]}--></tspan>
<tspan x="5" id="calls_number[%loop.count-%]" text-anchor="start"><!--{[% call.0 %]}--><!--{[%#}-->1<!--{%]}--></tspan>
<!--{[%IF call.1; call = call.1; END%]}-->
<tspan x="15" id="calls_zone[%loop.count-%]" text-anchor="start"><!--{[% call.get_column('zone') %]}--><!--{[%#}-->Example zone<!--{%]}--></tspan>
<tspan x="95" id="calls_number[%loop.count-%]"><!--{[% call.get_column('number') %]}--><!--{[%#}-->0<!--{%]}--></tspan>
<tspan x="130" id="calls_duration[%loop.count-%]"><!--{[% call.get_column('duration')|format('%.3f') %]}--><!--{[%#}-->0.000<!--{%]}--></tspan>
<tspan x="160" id="calls_freetime[%loop.count-%]"><!--{[% call.get_column('free_time')|format('%d') %]}--><!--{[%#}-->0.0<!--{%]}--></tspan>
@ -108,6 +111,7 @@ g, text, tspan {
<tspan x="190" id="calls_total_cost"><!--{[% ( total_cost / 100 )|format('%.2f') %]}--><!--{[%#}-->0.00<!--{%]}--></tspan>
</text>
<!--{[%END-%]}-->
<!--{[% titlerow -%]}-->
<!--{[% total = {} -%]}-->
<!--{[% list_calls(callsdata, 'datarow', total, 'svg', row_vertical_interval) -%]}-->
@ -116,30 +120,106 @@ g, text, tspan {
</g>
</g>
<!--/page-->
<!--{[%END-%]}-->
<!--/page>
<page-->
<!--{[%MACRO midpage BLOCK-%]}-->
<!--{[%MACRO midpage(callsdata) BLOCK-%]}-->
<!--page-->
<g id="midpage">
<title>MidPage</title>
<g y="15" x="10" width="195" height="150" id="midpage_invoicedetails" transform="translate(10, 15)" rows="15">
<g y="15" x="10" width="195" height="150" id="midpage_invoicedetails" transform="translate(10, 15)" rows="3">
<!--{[%MACRO titlerow BLOCK-%]}-->
<text id="midpage_calls_title" text-anchor="end">
<tspan x="5" id="midpage_calls_number" text-anchor="start">#</tspan>
<tspan x="15" id="midpage_calls_zone" text-anchor="start">Zone</tspan>
<tspan x="95" id="midpage_calls_number">Number</tspan>
<tspan x="130" id="midpage_calls_duration">Duration</tspan>
<tspan x="160" id="midpage_calls_freetime">Free time</tspan>
<tspan x="190" id="midpage_calls_cost">Cost</tspan>
</text>
<!--{[%END-%]}-->
<!--{[%MACRO datarow(call) BLOCK-%]}-->
<text y="10" text-anchor="end" id="midpage_calls[%loop.count-%]" class="datarow">
<tspan x="5" id="midpage_calls_number[%loop.count-%]" text-anchor="start"><!--{[% call.0 %]}--><!--{[%#}-->1<!--{%]}--></tspan>
<!--{[%IF call.1; call = call.1; END%]}-->
<tspan x="15" id="midpage_calls_zone[%loop.count-%]" text-anchor="start"><!--{[% call.get_column('zone') %]}--><!--{[%#}-->Example zone<!--{%]}--></tspan>
<tspan x="95" id="midpage_calls_number[%loop.count-%]"><!--{[% call.get_column('number') %]}--><!--{[%#}-->0<!--{%]}--></tspan>
<tspan x="130" id="midpage_calls_duration[%loop.count-%]"><!--{[% call.get_column('duration')|format('%.3f') %]}--><!--{[%#}-->0.000<!--{%]}--></tspan>
<tspan x="160" id="midpage_calls_freetime[%loop.count-%]"><!--{[% call.get_column('free_time')|format('%d') %]}--><!--{[%#}-->0.0<!--{%]}--></tspan>
<tspan x="190" id="midpage_calls_cost[%loop.count-%]"><!--{[% ( call.get_column('cost') / 100 ) |format('%.2f') %]}--><!--{[%#}-->0.00<!--{%]}--></tspan>
</text>
<!--{[%END-%]}-->
<!--{[%MACRO totalrow BLOCK-%]}-->
<text y="20" text-anchor="end" id="midpage_calls_total" class="datarow">
<tspan x="5" id="midpage_calls_total_title" text-anchor="start">Total:</tspan>
<tspan x="95" id="midpage_calls_total_number"><!--{[% total_number %]}--><!--{[%#}-->0<!--{%]}--></tspan>
<tspan x="130" id="midpage_calls_total_duration"><!--{[% total_duration|format('%.3f') %]}--><!--{[%#}-->0.000<!--{%]}--></tspan>
<tspan x="160" id="midpage_calls_total_freetime"><!--{[% total_free_time|format('%d') %]}--><!--{[%#}-->0.0<!--{%]}--></tspan>
<tspan x="190" id="midpage_calls_total_cost"><!--{[% ( total_cost / 100 )|format('%.2f') %]}--><!--{[%#}-->0.00<!--{%]}--></tspan>
</text>
<!--{[%END-%]}-->
<!--{[% titlerow -%]}-->
<!--{[% list_calls(zonecalls_rs, 'datarow', total, 'svg', row_vertical_interval) -%]}-->
<!--{[% total = {} -%]}-->
<!--{[% list_calls(callsdata, 'datarow', total, 'svg', row_vertical_interval) -%]}-->
<!--{[% adjustrow (total, 'totalrow', 'svg', row_vertical_interval, zonecalls_rs.size) -%]}-->
</g>
</g>
<!--/page-->
<!--{[%END-%]}-->
<!--{[%MACRO lastpage BLOCK-%]}-->
<!--{[%MACRO lastpage(callsdata) BLOCK-%]}-->
<!--page-->
<g id="lastpage">
<title>LastPage</title>
<g y="15" x="10" width="195" height="150" id="lastpage_invoicedetails" transform="translate(10, 15)" rows="10">
<g y="15" x="10" width="195" height="150" id="lastpage_invoicedetails" transform="translate(10, 15)">
<!--{[%MACRO titlerow BLOCK-%]}-->
<text id="lastpage_calls_title" text-anchor="end">
<tspan x="5" id="lastpage_calls_number" text-anchor="start">#</tspan>
<tspan x="15" id="lastpage_calls_zone" text-anchor="start">Zone</tspan>
<tspan x="95" id="lastpage_calls_number">Number</tspan>
<tspan x="130" id="lastpage_calls_duration">Duration</tspan>
<tspan x="160" id="lastpage_calls_freetime">Free time</tspan>
<tspan x="190" id="lastpage_calls_cost">Cost</tspan>
</text>
<!--{[%END-%]}-->
<!--{[%MACRO datarow(call) BLOCK-%]}-->
<text y="10" text-anchor="end" id="lastpage_calls[%loop.count-%]" class="datarow">
<tspan x="5" id="lastpage_calls_number[%loop.count-%]" text-anchor="start"><!--{[% call.0 %]}--><!--{[%#}-->1<!--{%]}--></tspan>
<!--{[%IF call.1; call = call.1; END%]}-->
<tspan x="15" id="lastpage_calls_zone[%loop.count-%]" text-anchor="start"><!--{[% call.get_column('zone') %]}--><!--{[%#}-->Example zone<!--{%]}--></tspan>
<tspan x="95" id="lastpage_calls_number[%loop.count-%]"><!--{[% call.get_column('number') %]}--><!--{[%#}-->0<!--{%]}--></tspan>
<tspan x="130" id="lastpage_calls_duration[%loop.count-%]"><!--{[% call.get_column('duration')|format('%.3f') %]}--><!--{[%#}-->0.000<!--{%]}--></tspan>
<tspan x="160" id="lastpage_calls_freetime[%loop.count-%]"><!--{[% call.get_column('free_time')|format('%d') %]}--><!--{[%#}-->0.0<!--{%]}--></tspan>
<tspan x="190" id="lastpage_calls_cost[%loop.count-%]"><!--{[% ( call.get_column('cost') / 100 ) |format('%.2f') %]}--><!--{[%#}-->0.00<!--{%]}--></tspan>
</text>
<!--{[%END-%]}-->
<!--{[%MACRO totalrow BLOCK-%]}-->
<text y="20" text-anchor="end" id="lastpage_calls_total" class="datarow">
<tspan x="5" id="lastpage_calls_total_title" text-anchor="start">Total:</tspan>
<tspan x="95" id="lastpage_calls_total_number"><!--{[% total_number %]}--><!--{[%#}-->0<!--{%]}--></tspan>
<tspan x="130" id="lastpage_calls_total_duration"><!--{[% total_duration|format('%.3f') %]}--><!--{[%#}-->0.000<!--{%]}--></tspan>
<tspan x="160" id="lastpage_calls_total_freetime"><!--{[% total_free_time|format('%d') %]}--><!--{[%#}-->0.0<!--{%]}--></tspan>
<tspan x="190" id="lastpage_calls_total_cost"><!--{[% ( total_cost / 100 )|format('%.2f') %]}--><!--{[%#}-->0.00<!--{%]}--></tspan>
</text>
<!--{[%END-%]}-->
<!--{[% titlerow -%]}-->
<!--{[% list_calls(zonecalls_rs, 'datarow', total, 'svg', row_vertical_interval) -%]}-->
<!--{[% list_calls(callsdata, 'datarow', total, 'svg', row_vertical_interval) -%]}-->
<!--{[% adjustrow (total, 'totalrow', 'svg', row_vertical_interval, zonecalls_rs.size) -%]}-->
</g>
</g>
<!--/page-->
<!--{[%END-%]}-->
<!--{[%MACRO bgpage BLOCK-%]}-->
<!--page-->
<g id="bgpage">
<title>Background</title>
<g y="270" x="5" width="205" height="18" transform="translate(5, 270)" class="address" font-size="2pt" id="bgpage_companyaddress_sipwise">
@ -151,14 +231,17 @@ g, text, tspan {
<text x="203" y="15" id="bgpage_companyaddress_sipwise__page_num" text-anchor="end" >{<!--{[%}-->page<!--{%]}-->}</text>
</g>
</g>
<!--/page-->
<!--{[%END-%]}-->
<!--{[%MACRO document_footer BLOCK-%]}-->
<!--/page>
</pageSet-->
<!--/pageSet-->
</svg>
<!--{[%END-%]}-->
<!--{[% show_pages(zonecalls_rs,'title')-%]}-->
<!--{[%# show_pages(zonecalls_rs,'title')-%]}-->
<!--{[%# show_pages('mid')-%]}-->
<!--{[%# show_pages('last')-%]}-->
<!--{[%# show_pages('all')-%]}-->
<!--{[% show_pages( zonecalls_rs,'all' )-%]}-->

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 15 KiB

@ -1,5 +1,6 @@
[%USE Dumper%]
[%USE Math%]
[%MACRO row_y_re(tt_type) BLOCK -%]
[% IF tt_type == 'svg' -%]
[% y_re = '(?s)(<text[^>]*\s+y\s?=.*?)(\d+)(.*)' -%]
@ -24,7 +25,6 @@
[%page_rows_re%]
[%END%]
[%MACRO get_row(data, rowtype) BLOCK -%]
[%#use this macro until no symbolic references in tt %]
[%#data can be empty, if we just need y - it doesn't depend on data %]
@ -75,8 +75,8 @@
[%END -%]
[%END -%]
[%MACRO get_page_rows_number(pagetype, tt_type, row_vertical_interval) BLOCK-%]
in before get_page_rows_number
[%#doesn't work %]
[% page_rows_re = page_rows_re(tt_type) %]
@ -88,24 +88,28 @@
[% page = get_page(pagetype) %]
[% matches = page.match( page_rows_re ) -%]
[%#page=Dumper.dump(page)%]
[%#page_rows_re=Dumper.dump(page_rows_re)%]
[%#matches=Dumper.dump(matches)%]
[%#page=Dumper.dump(page)%]===
[%#page_rows_re=Dumper.dump(page_rows_re)%]===
[%#matches=Dumper.dump(matches)%]===
[% rows = matches.0 || matches.1 %]
[%#IF !rows%]
[%# all_g_y_re = page_y_re(tt_type) %]
[%# matches = page.match( page_rows_re ) -%]
[%#END%]
[%IF !rows ; rows = 10; END%]
[%#IF ! rows %][%# rows = 10%][%#END%]
[%rows = Math.int(rows)%]
[%rows%]
[%END -%]
[%MACRO show_pages(zonecalls_rs, pagetype, pagenum_in) BLOCK-%]
[% allrowsnumber = zonecalls_rs.size() %]
[% titlerows = get_page_rows_number('titlepage','svg') || 10 %]
[% midrows = get_page_rows_number('midpage','svg') || 30 %]
[% titlerows = get_page_rows_number('titlepage','svg') %]
titlerows=[%titlerows%]===
[%IF titlerows== 0 ; titlerows = 10; END%]
[% midrows = get_page_rows_number('midpage','svg') %]
[%IF midrows == 0 ; midrows = 30 ; END%]
[% midrows = 2%]
[% allmidpages = ( (allrowsnumber - titlerows) / midrows )|format('%d') %]
[% allmidrows = allmidpages * midrows %]
[% lastrows = allrowsnumber - allmidrows - titlerows %]
@ -117,18 +121,17 @@
[% document_footer()%]
[%END-%]
[%IF ( pagetype == 'mid' || pagetype=='all' ) && allmidrows %]
[% allmidpages = allmidrows / midrows %]
[% pages = pagenum_in ? [ pagenum_in ] : [ 1 .. ${allmidpages} ] %]
[% pages = pagenum_in ? [ pagenum_in ] : [ 1 .. allmidpages ] %]
[%FOREACH pagenum IN pages %]
[% pagerowsstart = titlerows + midrows*(pagenum - 1)%]
[% pagerowsend = titlerows + midrows*pagenum%]
[% pagerowsstart = titlerows + midrows * ( pagenum - 1 )%]
[% pagerowsend = titlerows + midrows * pagenum%]
[% document_header()%]
[% midpage( zonecalls_rs.slice(pagerowsstart, pagerowsend )) -%]
[% midpage( zonecalls_rs.slice( pagerowsstart, pagerowsend )) -%]
[% bgpage() -%]
[% document_footer()%]
[%END-%]
[%END-%]
[%IF ( pagetype == 'last' || pagetype=='all' ) %]
[%IF ( pagetype == 'last' || pagetype=='all' )%]
[% document_header()%]
[% lastpage( zonecalls_rs.slice(lastrows) ) -%]
[% bgpage() -%]

Loading…
Cancel
Save