From 603a25830d082008ab47985e692964d41ae7eee8 Mon Sep 17 00:00:00 2001 From: Irina Peshinskaya Date: Tue, 27 May 2014 14:43:50 +0200 Subject: [PATCH] MT#5879 Reformat code and init math values to zero. --- .../templates/invoice/invoice_template_aux.tt | 441 +++++++++--------- 1 file changed, 228 insertions(+), 213 deletions(-) diff --git a/share/templates/invoice/invoice_template_aux.tt b/share/templates/invoice/invoice_template_aux.tt index 35d33ce6a2..82e78c4d70 100644 --- a/share/templates/invoice/invoice_template_aux.tt +++ b/share/templates/invoice/invoice_template_aux.tt @@ -1,259 +1,274 @@ -[%USE Dumper%] -[%USE Math%] -[%USE date%] -[%USE format %] +[% +USE Dumper; +USE Math; +USE date; +USE format ; + +MACRO date_format(dateval,noyear) BLOCK; +date.format(dateval,'%B'); ordinate(date.format(dateval,'%e')); IF !noyear; date.format(dateval,'%Y'); END; +END; -[%MACRO date_format(dateval,noyear) BLOCK%] -[%date.format(dateval,'%B')%] [%ordinate(date.format(dateval,'%e'))%] [%IF !noyear; date.format(dateval,'%Y'); END%] -[%END%] -[% dateval.value = date.now(); -dateval.month_end = date_format('00:00:00 00-' _ (Math.int(date.format(dateval.value,'%m')) + 1) _ date.format(dateval.value,'-%Y'), noyear = 1 ); +dateval.month_end = date_format('00:00:00 00-' _ (Math.int(ifz(date.format(dateval.value,'%m'))) + 1) _ date.format(dateval.value,'-%Y'), noyear = 1 ); dateval.month_start = date_format('00:00:00 01-' _ date.format(dateval.value,'%m-%Y'), noyear = 1 ); dateval.year=date.format(dateval.value,'%Y'); -invoice.serial=Math.int(invoice.serial)|format('%06d'); +invoice.serial=Math.int(ifz(invoice.serial))|format('%06d'); invoice.month=date.format(invoice.start,'%B'); -%] +MACRO ordinate(num) BLOCK; + IF num.search('(? 0 ) ? rows_interval_in : row_vertical_interval; + IF rowtype == 'datarow' ; + row = datarow(data); + ELSIF rowtype == 'totalrow' ; + row = totalrow( (pagelocal == pageslocalnum) ? data.global : data.perpage.${pagelocal} ); + END; + IF tt_type == 'svg' ; + y_re = '(?s)(<(?:text)[^>]*\s+y\s*=.*?)([-\d\.,]+)(.*)' ; + END; + matches = row.match( y_re ) ; + IF matches.size > 0 ; + y_old = Math.int(ifz(matches.1)) ; + y = ifz(y_old) + ( ifz(rows_interval) * ( ifz(rownumber) - 1 ) ) ; + row = matches.0 _ y _ matches.2 ; + matches_other = row.match('(<.*?\s+y\s*=.*?)([-\d\.,]+)', 1) ; + i = 0 ; + #matches_otherDumper.dump_html(matches_other); + WHILE i*2 < matches_other.size() ; + IF !matches_other.item(i*2).search(' 0 ) ? rows_interval_in : row_vertical_interval%] - [%IF rowtype == 'datarow' %] - [%row = datarow(data)%] - [%ELSIF rowtype == 'totalrow' %] - [%row = totalrow( (pagelocal == pageslocalnum) ? data.global : data.perpage.${pagelocal} )%] - [%END%] - [% IF tt_type == 'svg' -%] - [% y_re = '(?s)(<(?:text)[^>]*\s+y\s*=.*?)([-\d\.,]+)(.*)' -%] - [%END%] - [% matches = row.match( y_re ) -%] - [% IF matches.size > 0 -%] - [% 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(' [], global => {}, pagetype => { call=> {perpage => [], global => {}}, zone => {perpage => [], global => {}} } } -%] + total = {perpage => [], global => {}, pagetype => { call=> {perpage => [], global => {}}, zone => {perpage => [], global => {}} } } ; - [% allzonerowsnumber = invoice_details_zones.size() %] - [% titlezonerows = get_page_rows_number('titlepage','svg','zone') %] - [% midzonerows = get_page_rows_number('zonepage','svg') %] - [% titlezoneinterval = get_page_interval('titlepage','svg','zone') %] - [% midzoneinterval = get_page_interval('zonepage','svg') %] - [% midzonerows = Math.int(get_page_rows_number('zonepage','svg')) %] - [% midzonerows = ( midzonerows < 1 ) ? 30 : midzonerows %] + allzonerowsnumber = invoice_details_zones.size() ; + titlezonerows = get_page_rows_number('titlepage','svg','zone') ; + midzonerows = get_page_rows_number('zonepage','svg') ; + titlezoneinterval = get_page_interval('titlepage','svg','zone') ; + midzoneinterval = get_page_interval('zonepage','svg') ; + midzonerows = Math.int(get_page_rows_number('zonepage','svg')) ; + midzonerows = ( midzonerows < 1 ) ? 30 : midzonerows ; - [% allmidzonepages = ( (allzonerowsnumber - titlezonerows) / midzonerows )|format('%d') %] - [% allmidzonerows = allmidzonepages * midzonerows %] - [% lastzonerows = allzonerowsnumber - allmidzonerows - titlezonerows %] - [% allzonepages = allmidzonepages + ( lastzonerows ? 1 : 0 ) %] + allmidzonepages = ( (allzonerowsnumber - titlezonerows) / midzonerows )|format('%d') ; + allmidzonerows = allmidzonepages * midzonerows ; + lastzonerows = allzonerowsnumber - allmidzonerows - titlezonerows ; + allzonepages = allmidzonepages + ( lastzonerows ? 1 : 0 ) ; - [% allcallrowsnumber = invoice_details_calls.size() %] - [% titlecallrows = get_page_rows_number('titlepage','svg','call') %] - [% midcallrows = Math.int(get_page_rows_number('callpage','svg')) %] - [% midcallrows = ( midcallrows < 1 ) ? 30 : midcallrows %] - [% titlecallinterval = get_page_interval('titlepage','svg', 'call') %] - [% midcallinterval = get_page_interval('callpage','svg') %] + allcallrowsnumber = invoice_details_calls.size() ; + titlecallrows = get_page_rows_number('titlepage','svg','call') ; + midcallrows = Math.int(get_page_rows_number('callpage','svg')) ; + midcallrows = ( midcallrows < 1 ) ? 30 : midcallrows ; + titlecallinterval = get_page_interval('titlepage','svg', 'call') ; + midcallinterval = get_page_interval('callpage','svg') ; - [% allmidcallpages = ( (allcallrowsnumber - titlecallrows) / midcallrows )|format('%d') %] - [% allmidcallrows = allmidcallpages * midcallrows %] - [% lastcallrows = allcallrowsnumber - allmidcallrows - titlecallrows %] - [% allcallpages = allmidcallpages + ( lastcallrows ? 1 : 0 ) %] + allmidcallpages = ( (allcallrowsnumber - titlecallrows) / midcallrows )|format('%d') ; + allmidcallrows = allmidcallpages * midcallrows ; + lastcallrows = allcallrowsnumber - allmidcallrows - titlecallrows ; + allcallpages = allmidcallpages + ( lastcallrows ? 1 : 0 ) ; - [%IF ( pagetype == 'zone' || pagetype=='all' ) && allzonerowsnumber %] - [% 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 %] - [% output = output _ document_header()%] - [% output = output _ zonepage( invoice_details_zones.slice( pagerowsstart, pagerowsend ), total, pagenum + 1, pagenum, allzonepages, midzoneinterval ) -%] - [%#+1 because of 1 for titlepage %] - [% output = output _ bgpage(pagenum + 1, pagenum, allzonepages) -%] - [% output = output _ document_footer()%] - [%END-%] - [%IF lastzonerows > 0 %] - [%#2 because zonepages started from 1, not from 0, and we need add 1 for titlepage %] - [% pagenum = 2 + allmidzonepages %] - [% output = output _ document_header()%] - [% output = output _ zonepage( invoice_details_zones.slice( allzonerowsnumber - lastzonerows ), total, pagenum, allzonepages, allzonepages, midzoneinterval ) -%] - [% output = output _ bgpage(pagenum, allzonepages, allzonepages) -%] - [% output = output _ document_footer()%] - [%END-%] - [%END-%] + IF ( pagetype == 'zone' || pagetype=='all' ) && allzonerowsnumber ; + 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 ; + output = output _ document_header(); + output = output _ zonepage( invoice_details_zones.slice( pagerowsstart, pagerowsend ), total, pagenum + 1, pagenum, allzonepages, midzoneinterval ) ; + #+1 because of 1 for titlepage ; + output = output _ bgpage(pagenum + 1, pagenum, allzonepages) ; + output = output _ document_footer(); + END; + IF lastzonerows > 0 ; + #2 because zonepages started from 1, not from 0, and we need add 1 for titlepage ; + pagenum = 2 + allmidzonepages ; + output = output _ document_header(); + output = output _ zonepage( invoice_details_zones.slice( allzonerowsnumber - lastzonerows ), total, pagenum, allzonepages, allzonepages, midzoneinterval ) ; + output = output _ bgpage(pagenum, allzonepages, allzonepages) ; + output = output _ document_footer(); + END; + END; - [%#Dumper.dump(total)%] + #Dumper.dump(total); - [% total.pagetype.call.global.import(total.global)%] - [%# total.pagetype.call.perpage.import(total.perpage)%] + total.pagetype.call.global.import(total.global); + # total.pagetype.call.perpage.import(total.perpage); - [%#Dumper.dump(total)%] + #Dumper.dump(total); - [% total.global = {}%] - [% total.perpage = [] %] + total.global = {}; + total.perpage = [] ; - [%IF ( pagetype == 'call' || pagetype=='all' )%] - [% pages = pagenum_in ? [ pagenum_in ] : [ 1 .. allmidcallpages ] %] - [%FOREACH pagenum IN pages %] - [% pagerowsstart = titlecallrows + midcallrows * ( pagenum - 1 )%] - [% pagerowsend = titlecallrows + midcallrows * pagenum - 1 %] - [% output = output _ document_header()%] - [% output = output _ callpage( invoice_details_calls.slice( pagerowsstart, pagerowsend ), total, pagenum + 1 + allzonepages, pagenum, allcallpages, midcallinterval ) -%] - [%#+1 because of 1 for titlepage %] - [% output = output _ bgpage(pagenum + 1 + allzonepages, pagenum, allcallpages ) -%] - [% output = output _ document_footer()%] - [%END-%] - [%IF lastcallrows > 0 %] - [%#2 because callpages started from 1, not from 0, and we need add 1 for titlepage %] - [% pagenum = 1 + 1 + allmidcallpages + allzonepages %] - [% output = output _ document_header()%] - [% output = output _ callpage( invoice_details_calls.slice( allcallrowsnumber - lastcallrows ), total, pagenum, allcallpages, allcallpages, midcallinterval ) -%] - [% output = output _ bgpage(pagenum, allcallpages, allcallpages) -%] - [% output = output _ document_footer()%] - [%END-%] - [%END-%] + IF ( pagetype == 'call' || pagetype=='all' ); + pages = pagenum_in ? [ pagenum_in ] : [ 1 .. allmidcallpages ] ; + FOREACH pagenum IN pages ; + pagerowsstart = titlecallrows + midcallrows * ( pagenum - 1 ); + pagerowsend = titlecallrows + midcallrows * pagenum - 1 ; + output = output _ document_header(); + output = output _ callpage( invoice_details_calls.slice( pagerowsstart, pagerowsend ), total, pagenum + 1 + allzonepages, pagenum, allcallpages, midcallinterval ) ; + #+1 because of 1 for titlepage ; + output = output _ bgpage(pagenum + 1 + allzonepages, pagenum, allcallpages ) ; + output = output _ document_footer(); + END; + IF lastcallrows > 0 ; + #2 because callpages started from 1, not from 0, and we need add 1 for titlepage ; + pagenum = 1 + 1 + allmidcallpages + allzonepages ; + output = output _ document_header(); + output = output _ callpage( invoice_details_calls.slice( allcallrowsnumber - lastcallrows ), total, pagenum, allcallpages, allcallpages, midcallinterval ) ; + output = output _ bgpage(pagenum, allcallpages, allcallpages) ; + output = output _ document_footer(); + END; + END; - [%# Dumper.dump(total)%] + # Dumper.dump(total); - [% total.pagetype.zone.global.import(total.global)%] - [%# total.pagetype.zone.perpage = total.pagetype.zone.perpage.import(total.perpage)%] + total.pagetype.zone.global.import(total.global); + # total.pagetype.zone.perpage = total.pagetype.zone.perpage.import(total.perpage); - [%DEFAULT invoice.amount_netto = total.pagetype.call.global.cost + total.pagetype.zone.global.cost %] - [%DEFAULT invoice.amount_vat = invoice.amount_netto * 0.2 %] - [%DEFAULT invoice.amount = invoice.amount_netto + invoice.amount_vat %] - [%DEFAULT invoice.amount_payment = invoice.amount - invoice.debit %] + DEFAULT invoice.amount_netto = ifz(total.pagetype.call.global.cost) + ifz(total.pagetype.zone.global.cost) ; + DEFAULT invoice.amount_vat = ifz(invoice.amount_netto) * 0.2 ; + DEFAULT invoice.amount = ifz(invoice.amount_netto) + ifz(invoice.amount_vat) ; + DEFAULT invoice.amount_payment = invoice.amount - ifz(invoice.debit) ; - [%IF ( pagetype == 'title' || pagetype=='all') %] - [% pagenum = 1%] - [% output_title = output_title _ document_header()%] + IF ( pagetype == 'title' || pagetype=='all') ; + pagenum = 1; + output_title = output_title _ document_header(); - [% output_title = output_title _ titlepage( + output_title = output_title _ titlepage( ( titlezonerows > 0 && invoice_details_zones.size > 0 ) ? invoice_details_zones.slice(0, titlezonerows - 1 ) : [], ( titlecallrows > 0 && invoice_details_calls.size > 0 ) ? invoice_details_calls.slice(0, titlecallrows - 1 ) : [], pagenum, titlezoneinterval titlecallinterval - ) -%] - [% output_title = output_title _ bgpage(pagenum) -%] - [% output_title = output_title _ document_footer()-%] - [%END-%] - [% output_title _ output-%] -[%END-%] + ) ; + output_title = output_title _ bgpage(pagenum) ; + output_title = output_title _ document_footer(); + END; + output_title _ output; +END; +%] \ No newline at end of file