diff --git a/lib/NGCP/Panel/Controller/Customer.pm b/lib/NGCP/Panel/Controller/Customer.pm index b7e95f5a08..ab8a56d353 100644 --- a/lib/NGCP/Panel/Controller/Customer.pm +++ b/lib/NGCP/Panel/Controller/Customer.pm @@ -354,16 +354,16 @@ 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); - - #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); + #@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 = [ 1..100 ]; - my $i = 1; - $zonecalls_rs = [map{[$i++,$_]}@$zonecalls_rs]; + #$zonecalls_rs = [ 1..100 ]; + use irka; + use Data::Dumper; + irka::loglong(Dumper($zonecalls_rs) ); + $c->stash(zonecalls_rs => $zonecalls_rs ); $c->stash(billing_mapping => $billing_mapping ); @@ -835,7 +835,10 @@ sub calls :Chained('base') :PathPart('calls') :Args(0) { stime => $stime, etime => $etime, ); - $c->stash(zonecalls_rs => $zonecalls_rs); + #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(template => 'customer/calls.tt'); } @@ -854,7 +857,7 @@ sub calls_svg :Chained('base') :PathPart('calls/template') :Args { my($validator,$backend,$in); #input - (undef,undef,@$in{qw/tt_type tt_viewmode tt_sourcestate tt_id/}) = @_ ; + (undef,undef,@$in{qw/tt_type tt_viewmode tt_sourcestate tt_output_type tt_id/}) = @_ ; $in->{contract_id} = $c->stash->{contract}->id; $in->{tt_string} = $c->request->body_parameters->{template} || ''; @@ -874,10 +877,12 @@ sub calls_svg :Chained('base') :PathPart('calls/template') :Args { #really, we don't need a form here at all #just use as already implemented fields checking and defaults applying - $validator->setup_form( + #$validator->setup_form( + $validator->process( posted => 1, params => $in, ); + #$validator->validate_form(); #multi return... $c->log->debug("validated=".$validator->validated.";\n"); @@ -894,18 +899,21 @@ sub calls_svg :Chained('base') :PathPart('calls/template') :Args { $in = $in_validated; #dirty hack 2 - #validate methods don't work in form configuration, will find why later + #validate methods in form configuration don't change fields values, will find why later if($in->{tt_type} eq 'svgpdf'){ $in->{tt_type} = 'svg'; $in->{tt_output_type} = 'pdf'; + }elsif($in->{tt_type} eq 'html'){ + $in->{tt_output_type} = 'html'; } + irka::loglong(Dumper($in)); - #model logic my $tt_string_default = ''; my $tt_string_customer = ''; - my $tt_string_force_default = $in->{tt_sourcestate} eq 'default'; + my $tt_string_force_default = ( $in->{tt_sourcestate} eq 'default' ); + $c->log->debug("force_default=$tt_string_force_default;"); if(!$in->{tt_string} && !$tt_string_force_default){ #here we also may be better should contact model, not DB directly. Will return to this separation later #at the end - we can figure out rather basic controller behaviour @@ -916,7 +924,7 @@ sub calls_svg :Chained('base') :PathPart('calls/template') :Args { if($in->{tt_string} || !$tt_string_customer || $tt_string_force_default ){ try{ #Utils... mmm - if it were model - there would be no necessity in utils using - NGCP::Panel::Utils::InvoiceTemplate::getDefaultInvoiceTemplate( c => $c, result => \$tt_string_default ); + NGCP::Panel::Utils::InvoiceTemplate::getDefaultInvoiceTemplate( c => $c, type => $in->{tt_type}, result => \$tt_string_default ); } catch($e) { NGCP::Panel::Utils::Message->error( c => $c, @@ -952,6 +960,7 @@ sub calls_svg :Chained('base') :PathPart('calls/template') :Args { $output_string = $tt_string_sanitized; }elsif(!$tt_string_customer || $tt_string_force_default){ $output_string = $tt_string_default; + $c->log->debug("apply default;"); } }else{#we have customer template, we don't have dynamic template string, we weren't requested to show default $output_string = $tt_string_customer; @@ -964,6 +973,8 @@ sub calls_svg :Chained('base') :PathPart('calls/template') :Args { $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'){ + $c->response->content_type('text/html'); } if($in->{tt_viewmode} eq 'raw'){ #$c->stash->{VIEW_NO_TT_PROCESS} = 1; @@ -983,19 +994,47 @@ sub calls_svg :Chained('base') :PathPart('calls/template') :Args { $c->stash( provider => $contacts->first ); - if($in->{tt_output_type} eq 'svg'){ + if($in->{tt_output_type} eq 'svg' || $in->{tt_output_type} eq 'html'){ #$c->response->content_type('image/svg+xml'); + $c->stash( template => \$output_string ); + $c->detach($c->view('SVG')); }elsif($in->{tt_output_type} eq 'pdf'){ $c->response->content_type('application/pdf'); my $svg = $c->view('SVG')->getTemplateProcessed($c,\$output_string, $c->stash ); - $c->log->debug($svg); - my $kit = PDF::WebKit->new(\$svg, page_size => 'Letter'); + #$c->log->debug($svg); + my $kit = PDF::WebKit->new(\$svg, page_size => 'A4'); #push @{ $kit->stylesheets }, "/path/to/css/file"; # Get an inline PDF $output_string = $kit->to_pdf; + $c->response->body($output_string); + + use File::Temp qw/tempfile/; + my($fh, $filename) = tempfile(); + + #$fh->unlink_on_destroy( 0 ); + #my $filename = "/tmp/bbb.svg"; + #open my $fh, ">$filename"; + #binmode $fh; + #print $fh $svg; + #close $fh; + #my $cmd = "/tmp/wkhtmltox/bin/wkhtmltopdf $filename - "; + #$c->log->debug($cmd); + + #`chmod ugo+rwx $filename`; + + #binmode(STDOUT); + #binmode(STDIN); + #$output_string = `$cmd`; + + #open B, "$cmd |"; + #binmode B; + #$/ = undef; + #$output_string = ; + #close B; + + #$output_string = `cat $filename `; } - $c->stash( template => \$output_string ); - $c->detach($c->view('SVG')); + } } diff --git a/lib/NGCP/Panel/Form/Customer/InvoiceTemplate.pm b/lib/NGCP/Panel/Form/Customer/InvoiceTemplate.pm index 4b6de5ba95..e3db1948c4 100644 --- a/lib/NGCP/Panel/Form/Customer/InvoiceTemplate.pm +++ b/lib/NGCP/Panel/Form/Customer/InvoiceTemplate.pm @@ -72,30 +72,18 @@ has_field 'tt_id' => ( #sub validate_tt_string{ #here could be following: take default from file and get all variables and validate variables from customer string #}; -sub validate_tt_type { - my ( $self, $field ) = @_; # self is the form - use irka; - use Data::Dumper; - irka::loglong("\n\n\nin validate\naaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaa\n"); - die(); - if( $self->field('tt_type')->value eq 'svgpdf'){ - $self->field('tt_output_type')->value('pdf'); - $self->field('tt_type')->value('svg'); - } - return 1; -}; -sub validate { - my $self = shift; - use irka; - use Data::Dumper; - irka::loglong("\n\n\nin validate\naaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaa\n"); - die(); - if( $self->field('tt_type')->value eq 'svgpdf'){ - $self->field('tt_output_type')->value('pdf'); - $self->field('tt_type')->value('svg'); - } - return 1; -} +#sub validate { +# my ( $self ) = @_; # self is the form +# if( $self->field('tt_type')->value eq 'svgpdf'){ +# use irka; +# use Data::Dumper; +# irka::loglong("\n\n\nin validate\nBBBBBBBBBBBBBBBBBBBBB\naaaaaaaaaaaaaaa\n"); +# #die(); +# $self->field('tt_output_type')->value('pdf'); +# $self->field('tt_type')->value('svg'); +# } +# return 1; +#}; 1; diff --git a/share/static/js/libs/svg-edit/svgcanvas.js b/share/static/js/libs/svg-edit/svgcanvas.js index cc58ad57e7..20c7177df1 100644 --- a/share/static/js/libs/svg-edit/svgcanvas.js +++ b/share/static/js/libs/svg-edit/svgcanvas.js @@ -4764,8 +4764,7 @@ this.setSvgString = function(xmlString) { svgroot.appendChild(svgcontent); //var startre=; //svgroot.outerSvgTag = outerSvgTag; - svgroot.outerSvgTagStart = xmlString.match(/^(?:[\n\r\t\s]|.)*?(?:\]*\>/); - svgroot.outerSvgTagEnd = xmlString.match(/<\/svg>(?:[\n\r\t\s]|.)*$/); + svgroot.outerSvgTag = xmlString.match(/\]*\>/); //console.log(outerSvgTag[0]); //alert(outerSvgTag[0]); //alert('svgroot.innerHTML='+svgroot.outerHTML); diff --git a/share/templates/customer/calls_svg.tt b/share/templates/customer/calls_svg.tt index f4c25c76db..ea83ccffaf 100644 --- a/share/templates/customer/calls_svg.tt +++ b/share/templates/customer/calls_svg.tt @@ -1,7 +1,6 @@ - - +