MT#5879 separate row listing subs in template toolkit to have possibility generate multi-parted document

ipeshinskaya/InvoiceTemplate5
Irina Peshinskaya 12 years ago committed by Victor Seva
parent 21e2f2b38f
commit ae5360882a

@ -7,7 +7,7 @@ use Sipwise::Base;
sub getDefaultInvoiceTemplate{
my (%in) = @_;
#in future may be we will store root default in Db too, but now it is convenient to edit template as file
my $result = $in{c}->view('SVG')->getTemplateContent($in{c}, 'customer/calls_svg.tt');
my $result = $in{c}->view('SVG')->getTemplateContent($in{c}, 'customer/calls_'.$in{type}.'.tt');
#$in{c}->log->debug("result=$result;");

@ -20,7 +20,7 @@ __PACKAGE__->config(
sub process
{
my ( $self, $c ) = @_;
$c->res->content_type("image/svg+xml");
#$c->res->content_type("image/svg+xml");
if($c->stash->{VIEW_NO_TT_PROCESS}) {

@ -26,7 +26,7 @@
</thead>
<tbody>
[%# Dumper.dump_html(zonecalls_rs.as_query)%]
[% FOR call IN zonecalls_rs.all -%]
[% FOR call IN zonecalls_rs -%]
[% 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') %]
@ -115,6 +115,8 @@ function handleShowSvgParsedData(data, error) {
//alert(httpResponse);
var img = document.getElementById('svgpreview'); //new Image();
img.src = "data:image/svg+xml," + encodeURIComponent(httpResponse);
alert(img.outerHTML);
alert(img.html());
}
);
}

@ -0,0 +1,95 @@
<html>
<body width="215mm" height="297mm">
<style>
<![CDATA[
.address .company{
font-weight: bold
}
g {
/*
fill:#000000;fill-opacity:1;fill-rule:nonzero;
stroke:none;
*/
//font-family:HelveticaNeue;
//font-family:Arial;
font-family:HelveticaNeue-Light;
font-variant:normal;
//font-weight:300;
font-size:2.6pt;
writing-mode:lr;
-inkscape-font-specification:HelveticaNeue-Light;
}
#titlepage{
border: 1px solid black;
}
]]>
</style>
<div>
<title>MidPage</title>
</div>
<div>
<title>LastPage</title>
</div>
<div y="0" x="0" width="215" height="297" id="titlepage">
<title>TitlePage</title>
<rect x="0" y="0" width="214.6" height="296.6" stroke-width="0.1" stroke="#FF0000" fill="#FFFFFF" id="totalborder"/>
<div y="40" x="10" width="50" height="30" id="titlepage_companyaddress_custom" transform="translate(10, 40)">
<rect x="0" y="0" width="50" height="30" stroke-width="0.25" fill="#FFFFFF" id="titlepage_companyaddress_custom_border"/>
<div x="5" y="7" id="titlepage_companyaddress_custom_1">address line 1</div>
<div x="5" y="17" id="titlepage_companyaddress_custom_2">address line 2</div>
<div x="5" y="27" id="titlepage_companyaddress_custom_3">address line 3</div>
</div>
<div y="135" x="10" width="195" height="150" id="titlepage_invoicedetails_head" transform="translate(10, 135)">
<div id="calls_title" text-anchor="end">
<span x="5" id="calls_zone" text-anchor="start">Zone</span>
<span x="95" id="calls_number">Number</span>
<span x="130" id="calls_duration">Duration</span>
<span x="160" id="calls_freetime">Free time</span>
<span x="190" id="calls_cost">Cost</span>
</div>
<!--{[% row_vertical_interval = 10 -%]}-->
<!--{[%MACRO datarow BLOCK -%]}-->
<div y="10" text-anchor="end" id="calls[%loop.count-%]" class="datarow">
<span x="5" id="calls_zone[%loop.count-%]" text-anchor="start"><!--{[% call.get_column('zone') %]}--><!--{[%#}-->Example zone<!--{%]}--></span>
<span x="95" id="calls_number[%loop.count-%]"><!--{[% call.get_column('number') %]}--><!--{[%#}-->0<!--{%]}--></span>
<span x="130" id="calls_duration[%loop.count-%]"><!--{[% call.get_column('duration')|format('%.3f') %]}--><!--{[%#}-->0.000<!--{%]}--></span>
<span x="160" id="calls_freetime[%loop.count-%]"><!--{[% call.get_column('free_time')|format('%d') %]}--><!--{[%#}-->0.0<!--{%]}--></span>
<span x="190" id="calls_cost[%loop.count-%]"><!--{[% ( call.get_column('cost') / 100 ) |format('%.2f') %]}--><!--{[%#}-->0.00<!--{%]}--></span>
</div>
<!--{[%END-%]}-->
<!--{[%MACRO totalrow BLOCK -%]}-->
<div y="20" text-anchor="end" id="calls_total" class="datarow">
<span x="5" id="calls_total_title" text-anchor="start">Total:</span>
<span x="95" id="calls_total_number"><!--{[% total_number %]}--><!--{[%#}-->0<!--{%]}--></span>
<span x="130" id="calls_total_duration"><!--{[% total_duration|format('%.3f') %]}--><!--{[%#}-->0.000<!--{%]}--></span>
<span x="160" id="calls_total_freetime"><!--{[% total_free_time|format('%d') %]}--><!--{[%#}-->0.0<!--{%]}--></span>
<span x="190" id="calls_total_cost"><!--{[% ( total_cost / 100 )|format('%.2f') %]}--><!--{[%#}-->0.00<!--{%]}--></span>
</div>
<!--{[%END-%]}-->
</div>
</div>
<div id="bgpage">
<title>Background</title>
<div y="270" x="5" width="205" height="18" transform="translate(5, 270)" class="address" font-size="2pt" id="bgpage_companyaddress_sipwise">
<rect x="0" y="0" width="205" height="18" stroke-width="0.25" fill="#FFFFFF" id="titlepage_companyaddress_sipwise__border"/>
<div x="2" y="5" id="bgpage_companyaddress_sipwise__company" class="company">{<!--{[%}-->provider.company<!--{%]}-->}</div>
<div x="2" y="10" id="bgpage_companyaddress_sipwise__address">{<!--{[%}-->provider.street<!--{%]}-->}, Postcode {<!--{[%}-->provider.postcode<!--{%]}-->} {<!--{[%}-->provider.city<!--{%]}-->} {<!--{[%}-->provider.country<!--{%]}-->}</div>
<div x="2" y="15" id="bgpage_companyaddress_sipwise__contact">{<!--{[%}-->provider.firstname<!--{%]}-->} {<!--{[%}-->provider.lastname<!--{%]}-->}. Phone: {<!--{[%}-->provider.phone<!--{%]}-->}. Mobile: {<!--{[%}-->provider.mobile<!--{%]}-->}. Fax: {<!--{[%}-->provider.fax<!--{%]}-->}</div>
<div x="203" y="15" id="bgpage_companyaddress_sipwise__contact" text-anchor="end" >Page {<!--{[%}-->page<!--{%]}-->}</div>
</div>
</div>
</body>
</html>

@ -1,5 +1,8 @@
<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">
<!--{[%PROCESS 'customer/calls_template.tt' -%]}-->
<!--{[%row_vertical_interval = 10 -%]}-->
<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>
<![CDATA[
.address .company{
@ -21,14 +24,8 @@ g {
}
]]>
</style>
<g>
<title>MidPage</title>
</g>
<g>
<title>LastPage</title>
</g>
<!--pageSet>
<page-->
<g y="0" x="0" width="215" height="297" id="titlepage">
<title>TitlePage</title>
@ -42,6 +39,8 @@ g {
<text x="5" y="27" id="titlepage_companyaddress_custom_3">address line 3</text>
</g>
<g y="135" x="10" width="195" height="150" id="titlepage_invoicedetails_head" transform="translate(10, 135)">
<!--{[%MACRO titlerow BLOCK-%]}-->
<text id="calls_title" text-anchor="end">
<tspan x="5" id="calls_zone" text-anchor="start">Zone</tspan>
<tspan x="95" id="calls_number">Number</tspan>
@ -49,8 +48,8 @@ g {
<tspan x="160" id="calls_freetime">Free time</tspan>
<tspan x="190" id="calls_cost">Cost</tspan>
</text>
<!--{[% row_vertical_interval = 10 -%]}-->
<!--{[%MACRO datarow BLOCK -%]}-->
<!--{[%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="95" id="calls_number[%loop.count-%]"><!--{[% call.get_column('number') %]}--><!--{[%#}-->0<!--{%]}--></tspan>
@ -59,20 +58,7 @@ g {
<tspan x="190" id="calls_cost[%loop.count-%]"><!--{[% ( call.get_column('cost') / 100 ) |format('%.2f') %]}--><!--{[%#}-->0.00<!--{%]}--></tspan>
</text>
<!--{[%END-%]}-->
<!--{[% BLOCK adjustrow -%]}-->
<!--{[% heights = datarow.match('(?s)(<text[^>]*\s+y\s?=.*?)(\d+)(.*)' ) -%]}-->
<!--{[% y = heights.1 + ( row_vertical_interval * ( rownumber - 1 ) ) %]}-->
<!--{[% heights.0 _ y _ heights.2 %]}-->
<!--{[%END -%]}-->
<!--{[% FOR call IN zonecalls_rs.all -%]}-->
<!--{[% 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') -%]}-->
<!--{[% total_cost = total_cost + call.get_column('cost') -%]}-->
<!--{[%PROCESS adjustrow rownumber = loop.count -%]}-->
<!--{[%END -%]}-->
<!--{[%MACRO totalrow BLOCK -%]}-->
<!--{[%MACRO totalrow BLOCK-%]}-->
<text y="20" text-anchor="end" id="calls_total" class="datarow">
<tspan x="5" id="calls_total_title" text-anchor="start">Total:</tspan>
<tspan x="95" id="calls_total_number"><!--{[% total_number %]}--><!--{[%#}-->0<!--{%]}--></tspan>
@ -82,10 +68,23 @@ g {
</text>
<!--{[%END-%]}-->
<!--{[%PROCESS adjustrow datarow=totalrow, rownumber = zonecalls_rs.all.size -%]}-->
<!--{[% titlerow -%]}-->
<!--{[% total = {} -%]}-->
<!--{[% list_calls(zonecalls_rs, 'datarow', total, 'svg', row_vertical_interval) -%]}-->
<!--{[% adjustrow (total, 'totalrow', 'svg', row_vertical_interval, zonecalls_rs.size) -%]}-->
</g>
</g>
<!--/page>
<page-->
<g id="midpage">
<title>MidPage</title>
</g>
<g id="lastpage">
<title>LastPage</title>
</g>
<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">
@ -96,4 +95,6 @@ g {
<text x="203" y="15" id="bgpage_companyaddress_sipwise__contact" text-anchor="end" >Page {<!--{[%}-->page<!--{%]}-->}</text>
</g>
</g>
<!--/page>
</pageSet-->
</svg>

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

@ -0,0 +1,30 @@
[%MACRO adjustrow(data, rowtype, tt_type, row_vertical_interval, rownumber) BLOCK -%]
[%# USE Dumper%]
[%# Dumper.dump_html(data)%]
[%IF rowtype == 'datarow' %]
[%row = datarow(data)%]
[%ELSIF rowtype == 'totalrow' %]
[%row = totalrow(data)%]
[%END%]
[%# row = $rowtype(data) %]
[%tt_type%]
[% IF tt_type == 'svg' -%]
[% heights = row.match('(?s)(<text[^>]*\s+y\s?=.*?)(\d+)(.*)' ) -%]
[%END -%]
[%row_vertical_interval%]
[% IF heights.size > 0 -%]
[% y = heights.1 + ( row_vertical_interval * ( rownumber - 1 ) ) %]
[% row = heights.0 _ y _ heights.2 %]
[%END -%]
[%row%]
[%END -%]
[%MACRO list_calls(zonecalls_rs, rowtype, total, tt_type, row_vertical_interval) BLOCK-%]
[% FOR call IN zonecalls_rs -%]
[% 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') -%]
[% total.cost = total.cost + call.get_column('cost') -%]
[% adjustrow(call, rowtype, tt_type, row_vertical_interval, loop.count) -%]
[%END -%]
[%END -%]

@ -419,7 +419,6 @@
[%END%]
[% USE Dumper %]
[%# Dumper.dump(zonecalls_rs)%]
[%# zonecalls_rs.size%]
[% WRAPPER accordion_group id="collapse_calls" title=c.loc('Balance details') %]
@ -436,7 +435,7 @@
</thead>
<tbody>
[%# Dumper.dump_html(zonecalls_rs.as_query)%]
[% FOR call IN zonecalls_rs.all -%]
[% FOR call IN zonecalls_rs -%]
[% 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') %]

Loading…
Cancel
Save