MT#5879 Save templates state. Total isn't shown.

Added bars after records titles and before total.
Implemented other row components position ajustment.

@. Total only on last page.
ipeshinskaya/InvoiceTemplate5
Irina Peshinskaya 11 years ago committed by Victor Seva
parent dbf2b5414a
commit e9a88a5ef2

@ -3,6 +3,23 @@
[%USE date%]
[% total = {perpage => [], global => {} } -%]
[%MACRO date_format(dateval) BLOCK%]
[%date.format(dateval,'%B')%] [%ordinate(date.format(dateval,'%e'))%] [%date.format(dateval,'%Y')%]
[%END%]
[%MACRO ordinate(num) BLOCK -%]
[% IF num.search('(?<!1)1$') -%]
[% sfx = 'st' -%]
[% ELSIF num.search('(?<!1)2$') -%]
[% sfx = 'nd' -%]
[% ELSIF num.search('(?<!1)3$') -%]
[% sfx = 'rd' -%]
[% ELSE -%]
[% sfx = 'th' -%]
[%END%]
[% num _ sfx %]
[%END%]
[%MACRO if(prefix, value) BLOCK -%]
[%value_clear = value.replace('[ ,]','')%]
[% IF value_clear -%]
@ -10,18 +27,6 @@
[%END%]
[%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 %]
[%IF rowtype == 'datarow' %]
[%row = datarow(data)%]
[%ELSIF rowtype == 'totalrow' %]
[%row = totalrow(data)%]
[%END%]
[%# row = $rowtype(data) %]
[%row%]
[%END%]
[%MACRO get_page(pagetype) 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 %]
@ -35,41 +40,61 @@
[%page%]
[%END%]
[%MACRO adjustrow(data, page, rowtype, tt_type, rows_interval_in, rownumber) BLOCK -%]
[%# y_re = row_y_re(tt_type) %]
[%MACRO adjustrow(data, page, pagelocal, pageslocalnum, rowtype, tt_type, rows_interval_in, rownumber) BLOCK -%]
[% rows_interval = ( rows_interval_in > 0 ) ? rows_interval_in : row_vertical_interval%]
[% row = get_row(data, rowtype) %]
[%IF rowtype == 'datarow' %]
[%row = datarow(data)%]
[%ELSIF rowtype == 'totalrow' %]
===[%Dumper.dump(data)%]
[%row = totalrow( (pagelocal == pageslocalnum) ? data.global : data.perpage.${pagelocal} )%]
[%END%]
[% IF tt_type == 'svg' -%]
[% y_re = '(?s)(<(?:text)[^>]*\s+y\s?=.*?)(\d+)(.*)' -%]
[% y_re = '(?s)(<(?:text)[^>]*\s+y\s*=.*?)([-\d\.,]+)(.*)' -%]
[%END%]
[% matches = row.match( y_re ) -%]
[% IF matches.size > 0 -%]
[% y = matches.1 + ( rows_interval * ( rownumber - 1 ) ) %]
[% y_old = Math.int(matches.1) %]
[% y = y_old + ( rows_interval * ( rownumber - 1 ) ) %]
[% row = matches.0 _ y _ matches.2 %]
[% matches_other = row.match('(<.*?\s+y\s*=.*?)([-\d\.,]+)', 1) %]
[% i = 0 %]
[%#matches_other[%Dumper.dump_html(matches_other)%]
[% WHILE i*2 < matches_other.size() %]
[%IF !matches_other.item(i*2).search('<text')%]
[% search = matches_other.item(i*2) _ matches_other.item(i*2 + 1)%]
[% replace = matches_other.item(i*2) _ ( Math.int( matches_other.item(i*2 + 1)) - y_old + y ) %][%#+ rows_interval%][%# + ( rowtype == 'totalrow' ? rows_interval : 0)%]
[%#search1=[% search%]
[%#search=[% row.search(search)%]
[%#replace=[% replace%]
[% row = row.replace(search, replace ) %]
[%END -%]
[% i = i + 1 %]
[%END -%]
[%END -%]
[%row%]
[%END -%]
[%MACRO list_zones(callsdata, page, rowtype, total, tt_type, rows_interval) BLOCK-%]
[%MACRO list_zones(callsdata, page, pagelocal, pageslocalnum, rowtype, total, tt_type, rows_interval) BLOCK-%]
[% FOR call IN callsdata -%][%#invoice_details%]
[% total.global.number = total.number + call.get_column('number') -%]
[% total.global.duration = total.duration + call.get_column('duration') -%]
[% total.global.free_time = total.free_time + call.get_column('free_time') -%]
[% total.global.cost = total.cost + call.get_column('cost') -%]
[% total.perpage.${page}.number = total.number + call.get_column('number') -%]
[% total.perpage.${page}.duration = total.duration + call.get_column('duration') -%]
[% total.perpage.${page}.free_time = total.free_time + call.get_column('free_time') -%]
[% total.perpage.${page}.cost = total.cost + call.get_column('cost') -%]
[% adjustrow(call, page, rowtype, tt_type, rows_interval, loop.count) -%]
[% total.global.number = total.global.number + call.get_column('number') -%]
[% total.global.duration = total.global.duration + call.get_column('duration') -%]
[% total.global.free_time = total.global.free_time + call.get_column('free_time') -%]
[% total.global.cost = total.global.cost + call.get_column('cost') -%]
[% total.perpage.${pagelocal}.number = total.perpage.${pagelocal}.number + call.get_column('number') -%]
[% total.perpage.${pagelocal}.duration = total.perpage.${pagelocal}.duration + call.get_column('duration') -%]
[% total.perpage.${pagelocal}.free_time = total.perpage.${pagelocal}.free_time + call.get_column('free_time') -%]
[% total.perpage.${pagelocal}.cost = total.perpage.${pagelocal}.cost + call.get_column('cost') -%]
[% adjustrow(call, page, pagelocal, pageslocalnum, rowtype, tt_type, rows_interval, loop.count) -%]
[%END -%]
[%END -%]
[%MACRO list_calls(callsdata, page, rowtype, total, tt_type, rows_interval) BLOCK-%]
[%MACRO list_calls(callsdata, page, pagelocal, pageslocalnum, rowtype, total, tt_type, rows_interval) BLOCK-%]
[% FOR call IN callsdata -%][%#invoice_details%]
[% total.global.duration = total.duration + call.get_column('duration') -%]
[% total.global.cost = total.cost + call.get_column('source_customer_cost') -%]
[% total.perpage.${page}.duration = total.duration + call.get_column('duration') -%]
[% total.perpage.${page}.cost = total.cost + call.get_column('source_customer_cost') -%]
[% adjustrow(call, page, rowtype, tt_type, rows_interval, loop.count) -%]
[% total.global.duration = total.global.duration + call.get_column('duration') -%]
[% total.global.cost = total.global.cost + call.get_column('source_customer_cost') -%]
[% total.perpage.${pagelocal}.duration = total.perpage.${pagelocal}.duration + call.get_column('duration') -%]
[% total.perpage.${pagelocal}.cost = total.perpage.${pagelocal}.cost + call.get_column('source_customer_cost') -%]
[% adjustrow(call, page, pagelocal, pageslocalnum, rowtype, tt_type, rows_interval, loop.count) -%]
[%END -%]
[%END -%]
@ -91,7 +116,6 @@
[% IF tt_type == 'svg' -%]
[% interval_type = interval_type ? interval_type _ '-' : '' %]
[% page_interval_re = interval_type _ 'rows-interval="([0-9]+)"' -%]
==[%page_interval_re%]==
[%END%]
[% page = get_page(pagetype) %]
@ -112,9 +136,10 @@
[% midzonerows = get_page_rows_number('zonepage','svg') %]
[% midzonerows = ( midzonerows < 1 ) ? 30 : midzonerows %]
[% allzonepages = ( (allzonerowsnumber - titlezonerows) / midzonerows )|format('%d') %]
[% allmidzonerows = allzonepages * midzonerows %]
[% allmidzonepages = ( (allzonerowsnumber - titlezonerows) / midzonerows )|format('%d') %]
[% allmidzonerows = allmidzonepages * midzonerows %]
[% lastzonerows = allzonerowsnumber - allmidzonerows - titlezonerows %]
[% allzonepages = allmidzonepages + ( lastzonerows ? 1 : 0 ) %]
[% allcallrowsnumber = invoice_details_calls.size() %]
@ -123,9 +148,11 @@
[% midcallrows = ( midcallrows < 1 ) ? 30 : midcallrows %]
[% titlecallinterval = get_page_interval('titlepage','svg', 'call') %]
[% midcallinterval = get_page_interval('callpage','svg') %]
[% allcallpages = ( (allcallrowsnumber - titlecallrows) / midcallrows )|format('%d') %]
[% allmidcallrows = allcallpages * midcallrows %]
[% allmidcallpages = ( (allcallrowsnumber - titlecallrows) / midcallrows )|format('%d') %]
[% allmidcallrows = allmidcallpages * midcallrows %]
[% lastcallrows = allcallrowsnumber - allmidcallrows - titlecallrows %]
[% allcallpages = allmidcallpages + ( lastcallrows ? 1 : 0 ) %]
[%IF ( pagetype == 'title' || pagetype=='all') %]
@ -144,42 +171,43 @@
[% document_footer()%]
[%END-%]
[%IF ( pagetype == 'zone' || pagetype=='all' ) && allmidzonerows %]
[% pages = pagenum_in ? [ pagenum_in ] : [ 1 .. allzonepages ] %]
[% pages = pagenum_in ? [ pagenum_in ] : [ 1 .. allmidzonepages ] %]
[%FOREACH pagenum IN pages %]
[% pagerowsstart = titlezonerows + midzonerows * ( pagenum - 1 )%]
[% pagerowsend = titlezonerows + midzonerows * pagenum - 1 %]
[%# pagerowsend = pagerowsend > invoice_details_zones.size() - 1 ? invoice_details_zones.size() - 1 : pagerowsend %]
[% document_header()%]
[% zonepage( invoice_details_zones.slice( pagerowsstart, pagerowsend ), pagenum + 1, midzoneinterval ) -%]
[% zonepage( invoice_details_zones.slice( pagerowsstart, pagerowsend ), total, pagenum + 1, pagenum, allzonepages, midzoneinterval ) -%]
[%#+1 because of 1 for titlepage %]
[% bgpage(pagenum + 1) -%]
[% bgpage(pagenum + 1, pagenum, allzonepages) -%]
[% document_footer()%]
[%END-%]
[%IF lastzonerows > 0 %]
[%#2 because zonepages started from 1, not from 0, and we need add 1 for titlepage %]
[% pagenum = 2 + allzonepages %]
[% pagenum = 2 + allmidzonepages %]
[% document_header()%]
[% zonepage( invoice_details_zones.slice( allzonerowsnumber - lastzonerows, allzonerowsnumber ), pagenum, midzoneinterval ) -%]
[% bgpage(pagenum) -%]
[% zonepage( invoice_details_zones.slice( allzonerowsnumber - lastzonerows ), total, pagenum, allzonepages, allzonepages, midzoneinterval ) -%]
[% bgpage(pagenum, allzonepages, allzonepages) -%]
[% document_footer()%]
[%END-%]
[%END-%]
[%IF ( pagetype == 'call' || pagetype=='all' )%]
[% pages = pagenum_in ? [ pagenum_in ] : [ 1 .. allcallpages ] %]
[% pages = pagenum_in ? [ pagenum_in ] : [ 1 .. allmidcallpages ] %]
[%FOREACH pagenum IN pages %]
[% pagerowsstart = titlecallrows + midcallrows * ( pagenum - 1 )%]
[% pagerowsend = titlecallrows + midcallrows * pagenum - 1 %]
[% document_header()%]
[% callpage( invoice_details_calls.slice( pagerowsstart, pagerowsend ), pagenum + 1, midcallinterval ) -%]
[% callpage( invoice_details_calls.slice( pagerowsstart, pagerowsend ), total, pagenum + 1 + allzonepages, pagenum, allcallpages, midcallinterval ) -%]
[%#+1 because of 1 for titlepage %]
[% bgpage(pagenum + allzonepages + 1) -%]
[% bgpage(pagenum + 1 + allzonepages, pagenum, allcallpages ) -%]
[% document_footer()%]
[%END-%]
[%IF lastcallrows > 0 %]
[%#2 because callpages started from 1, not from 0, and we need add 1 for titlepage %]
[% pagenum = 2 + allcallpages %]
[% pagenum = 2 + allmidcallpages + ( allzonepages ? 1 : 0 ) %]
[% document_header()%]
[% callpage( invoice_details_calls.slice( allcallrowsnumber - lastcallrows, allcallrowsnumber ), pagenum, midcallinterval ) -%]
[% bgpage(pagenum) -%]
[% callpage( invoice_details_calls.slice( allcallrowsnumber - lastcallrows ), total, pagenum, allcallpages, allcallpages, midcallinterval ) -%]
[% bgpage(pagenum, allcallpages, allcallpages) -%]
[% document_footer()%]
[%END-%]
[%END-%]

@ -36,6 +36,13 @@ function formSerialize(){
contract_id: '[%contract.id%]',
});void(0);">[% c.loc('Load default')%] <i class="icon-edit"></i></a>
</span>
<span>
<a class="btn btn-secondary btn-small" data-confirm="[%c.loc('Overwrite changes');%]" href="javascript:fetchInvoiceTemplateData({
tt_sourcestate: 'saved',
tt_id: getTtIdVal(),
contract_id: '[%contract.id%]',
});void(0);">[% c.loc('Load saved')%] <i class="icon-edit"></i></a>
</span>
<span id="load_previewed_control" style="display:none;">
<a class="btn btn-secondary btn-small" data-confirm="[%c.loc('Overwrite changes');%]" href="javascript:fetchInvoiceTemplateData({
tt_sourcestate: 'previewed',
@ -43,6 +50,39 @@ function formSerialize(){
contract_id: '[%contract.id%]',
});void(0);">[% c.loc('Load previewed')%] <i class="icon-edit"></i></a>
</span>
<div class="ngcp-separator"></div>
<span>
<a class="btn btn-primary btn-small" href="javascript:window.open(uriForAction({
tt_sourcestate: 'previewed',
tt_output_type : 'svg',
tt_id: getTtIdVal(),
contract_id: '[%contract.id%]',
}),'_blank');void(0);">[% c.loc('Previewed SVG')%] <i class="icon-edit"></i></a>
</span>
<span>
<a class="btn btn-primary btn-small" href="javascript:window.open(uriForAction({
tt_sourcestate: 'previewed',
tt_output_type : 'pdf',
tt_id: getTtIdVal(),
contract_id: '[%contract.id%]',
}),'_blank');void(0);">[% c.loc('Previewed PDF')%] <i class="icon-edit"></i></a>
</span>
<span>
<a class="btn btn-primary btn-small" href="javascript:window.open(uriForAction({
tt_sourcestate: 'saved',
tt_output_type : 'svg',
tt_id: getTtIdVal(),
contract_id: '[%contract.id%]',
}),'_blank');void(0);">[% c.loc('Saved SVG')%] <i class="icon-edit"></i></a>
</span>
<span>
<a class="btn btn-primary btn-small" href="javascript:window.open(uriForAction({
tt_sourcestate: 'saved',
tt_output_type : 'pdf',
tt_id: getTtIdVal(),
contract_id: '[%contract.id%]',
}),'_blank');void(0);">[% c.loc('Saved PDF')%] <i class="icon-edit"></i></a>
</span>
[%initial = 'default'%]
<div class="ngcp-separator"></div>
<iframe

@ -12,6 +12,7 @@ var staticContainerId='invoice_template_list';
<thead>
<tr>
<th>[% c.loc('Active') %]</th>
<th>[% c.loc('Id') %]</th>
<th>[% c.loc('Name') %]</th>
<th>[% c.loc('Type') %]</th>
<th class="ngcp-actions-column"></th>
@ -23,6 +24,7 @@ var staticContainerId='invoice_template_list';
[%# Dumper.dump_html(template)%]
<tr class="sw_action_row" data-id="[%template.get_column('id')%]">
<td style="font-size: 20px;">[%IF template.get_column('is_active') > 0; '✓'; END%]</td><!--✓-->
<td>[% template.get_column('id') %]</td>
<td>[% template.get_column('name') %]</td>
<td>[% template.get_column('type') %]</td>
<td class="ngcp-actions-column">

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Loading…
Cancel
Save