MT#5879 Save state before start geography implementation

mr3.3.1
Irina Peshinskaya 12 years ago committed by Andreas Granig
parent 044c9ca46b
commit 45b475327b

@ -7,6 +7,7 @@ use warnings;
use Sipwise::Base;
use File::Temp qw/tempfile tempdir/;
use File::Path qw/mkpath/;
use XML::XPath;
sub getDefaultInvoiceTemplate{
my (%in) = @_;
@ -24,7 +25,7 @@ sub convertSvg2Pdf{
my($c,$svg_ref,$in,$out) = @_;
my $svg = $$svg_ref;
my(@pages) = $svg=~/(<svg.*?(?:\/svg>))/sig;
no warnings 'uninitialized';
#$c->log->debug($svg);
my ($tempdirbase,$tempdir );
#my($fh, $tempfilename) = tempfile();
@ -60,8 +61,8 @@ sub convertSvg2Pdf{
close $fh;
$pagenum++;
}
my $cmd = "rsvg-convert -f pdf ".join(" ", @pagefiles);
#no unit specification in documentation. Cool!
my $cmd = "rsvg-convert -h 849 -w 600 -a -f pdf ".join(" ", @pagefiles);
#print $cmd;
#die();
$c and $c->log->debug($cmd);
@ -75,22 +76,47 @@ sub convertSvg2Pdf{
local $/ = undef;
$out->{tt_string_pdf} = <B>;
$c->log->error("Pipe: close: !=$!; ?=$?;");
if($? != 0){
close B or ($? == 0 ) or $c->log->error("Error closing rsvg pipe: close: $!;");
}
close B or ($? == 0 ) or $c->log->error("Error closing rsvg pipe: close: $!;");
}
}
sub preprocessInvoiceTemplateSvg{
my($in,$svg_ref) = @_;
no warnings 'uninitialized';
#print "1.\n\n\n\n\nsvg=".$out->{tt_string_prepared}.";";
$$svg_ref=~s/(?:{\s*)?<!--{|}-->(?:\s*})?//gs;
$$svg_ref=~s/<(g .*?)(?:display\s*=\s*["']*none["'[:blank:]]+)(.*?id *=["' ]+(?:title|bg|mid|zone|call)page["' ]+)([^>]*)>/<$1$2$3>/gs;
$$svg_ref=~s/<(g .*?)(id *=["' ]+(?:title|bg|mid|zone|call)page["' ]+.*?)(?:display\s*=\s*["']*none["'[:blank:]]+)([^>]*)>/<$1$2$3>/gs;
if($in->{no_fake_data}){
$$svg_ref=~s/\[%[^\[\%]+lorem.*?%\]//gs;
my $xp = XML::XPath->new($$svg_ref);
my $g = $xp->find('//g[@id="titlepage" or @id="bgpage" or
@id="midpage" or @id="callpage" or @id="zonepage"]');
foreach my $node($g->get_nodelist) {
if($node->getAttribute('display')) {
$node->removeAttribute('display');
}
}
#print "\n\n2.\n\n\n\nsvg=".$out->{tt_string_prepared}.";";
if($in->{no_fake_data}) {
my $comment = $xp->find('/comment()[contains(.,
"invoice_template_lorem.tt")]');
foreach my $node($comment->get_nodelist) {
$node->getParentNode->removeChild($node);
}
}
my $comment = $xp->find('//comment()[normalize-space(.) = "{}" or
normalize-space(.) = "{ }"]');
foreach my $node($comment->get_nodelist) {
$node->getParentNode->removeChild($node);
}
$$svg_ref = ($xp->findnodes('/'))[0]->toString();
#no warnings 'uninitialized';
##print "1.\n\n\n\n\nsvg=".$out->{tt_string_prepared}.";";
#$$svg_ref=~s/(?:{\s*)?<!--{|}-->(?:\s*})?//gs;
#$$svg_ref=~s/<(g .*?)(?:display\s*=\s*["']*none["'[:blank:]]+)(.*?id *=["' ]+(?:title|bg|mid|zone|call)page["' ]+)([^>]*)>/<$1$2$3>/gs;
#$$svg_ref=~s/<(g .*?)(id *=["' ]+(?:title|bg|mid|zone|call)page["' ]+.*?)(?:display\s*=\s*["']*none["'[:blank:]]+)([^>]*)>/<$1$2$3>/gs;
#if($in->{no_fake_data}){
# $$svg_ref=~s/\[%[^\[\%]+lorem.*?%\]//gs;
#}
##print "\n\n2.\n\n\n\nsvg=".$out->{tt_string_prepared}.";";
}
1;

@ -4,18 +4,28 @@ 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;
datenow.value = date.now();
datenow.month_end = date_format(month_end (datenow.value), noyear = 1 );
datenow.month_start = date_format(month_start(datenow.value), noyear = 1 );
datenow.year=date.format(datenow.value,'%Y');
IF invoice.serial;
invoice.serial=Math.int(ifz(invoice.serial))|format('%06d');
#invoice.date_start = '00:00:00 01-' _ invoice.month _ invoice.year;
invoice.date_start = '00:00:00 01-05-2014';
invoice.date_end = month_end(invoice.date_start);
END;
dateval.value = date.now();
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(ifz(invoice.serial))|format('%06d');
invoice.month=date.format(invoice.start,'%B');
MACRO date_format(dateval,noyear) BLOCK;
date.format(dateval,'%B'); ordinate(date.format(dateval,'%e')); IF !noyear; date.format(dateval,'%Y'); END;
END;
MACRO month_start(dateval) BLOCK;
'00:00:00 01-' _ date.format(dateval,'%m-%Y');
END;
MACRO month_end(dateval) BLOCK;
'00:00:00 00-' _ (Math.int(ifz(date.format(dateval,'%m'))) + 1) _ date.format(dateval,'-%Y');
END;
MACRO ordinate(num) BLOCK;
IF num.search('(?<!1)1$');
@ -140,7 +150,7 @@ MACRO get_page_rows_number(pagetype, tt_type, rows_type) BLOCK;
rows = matches.0 || matches.1 ;
rows = Math.int(ifz(rows));
ifz(rows);
rows;
END ;
@ -163,84 +173,84 @@ MACRO show_pages(invoice_details_zones, invoice_details_calls, pagetype, pagenum
#todo: remove copypast with some macro, later;
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 ;
alltitlepages = ifz(alltitlepages) ? alltitlepages : 1;
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 > 0 ? 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 > 0 ? 1 : 0 ) ;
IF ( pagetype == 'zone' || pagetype=='all' ) && allzonerowsnumber ;
pages = pagenum_in ? [ pagenum_in ] : [ 1 .. allmidzonepages ] ;
pages = pagenum_in ? [ pagenum_in ] : [ 1 .. allmidzonepages ] ;
FOREACH pagenum IN pages ;
pagerowsstart = titlezonerows + midzonerows * ( pagenum - 1 );
pagerowsend = titlezonerows + midzonerows * pagenum - 1 ;
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 ) ;
output = output _ document_header();
output = output _ zonepage( invoice_details_zones.slice( pagerowsstart, pagerowsend ), total, pagenum + alltitlepages, pagenum, allzonepages, midzoneinterval ) ;
#+1 because of 1 for titlepage ;
output = output _ bgpage(pagenum + 1, pagenum, allzonepages) ;
output = output _ document_footer();
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();
#+1 is for last page number, so ( alltitlepages + allmidzonepages ) was previous page
pagenum = 1 + alltitlepages + 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);
total.pagetype.call.global.import(total.global);
total.pagetype.call.global.import(total.global);
# total.pagetype.call.perpage.import(total.perpage);
#Dumper.dump(total);
total.global = {};
total.perpage = [] ;
total.global = {};
total.perpage = [] ;
IF ( pagetype == 'call' || pagetype=='all' );
pages = pagenum_in ? [ pagenum_in ] : [ 1 .. allmidcallpages ] ;
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 ) ;
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();
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();
pagenum = 1 + alltitlepages + 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;

@ -10,17 +10,26 @@ template_variables.description.import({
}
});
%]
invoice serial ======> [% invoice.serial%] <===========================
invoice month ======> [% invoice.month%] <===========================
invoice year ======> [% invoice.year%] <===========================
[%;
IF !invoice.serial;
#info from db
DEFAULT invoice.month=date.format(date.now(),'%m');
DEFAULT invoice.serial=Math.int(Math.rand(999999))|format('%06d');
DEFAULT invoice.year=date.format(date.now(),'%y');
#/info from db
DEFAULT invoice.amount='1200';
DEFAULT invoice.amount_netto='1000';
DEFAULT invoice.amount_payment='650';
DEFAULT invoice.amount_vat='200';
DEFAULT invoice.cloud_pbx_amount='921';
DEFAULT invoice.month=date.format(date.now(),'%B');
DEFAULT invoice.debit='500';
DEFAULT invoice.discount_service='10';
DEFAULT invoice.discount_wire_transfer='40';
DEFAULT invoice.serial=Math.int(Math.rand(999999))|format('%06d');
DEFAULT invoice.serviceallowance='69';
DEFAULT invoice.voice_termination_fees='10';
END;

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Loading…
Cancel
Save