@ -871,19 +871,11 @@ sub invoice_template_aux_embedImage :Chained('list_customer') :PathPart('auxembe
$ c - > log - > debug ( 'invoice_template_aux_handleImageUpload' ) ;
my ( $ validator , $ backend , $ in , $ out ) ;
#$upload->basename;
#$upload->copy_to;
#$upload->fh;
#$upload->filename;
#$upload->headers;
#$upload->link_to;
#$upload->size;
#$upload->slurp;
#$upload->tempname;
#$upload->type;
#todo
#mime-type and type checking in form
$ in = $ c - > request - > parameters ;
$ in - > { svg_file } = $ c - > request - > upload ( 'svg_file' ) ;
#$in->{}
if ( $ in - > { svg_file } ) {
my $ ft = File::Type - > new ( ) ;
$ out - > { image_content } = $ in - > { svg_file } - > slurp ;
@ -891,31 +883,10 @@ sub invoice_template_aux_embedImage :Chained('list_customer') :PathPart('auxembe
$ out - > { image_content_base64 } = encode_base64 ( $ out - > { image_content } , '' ) ;
}
$ c - > log - > debug ( 'mime-type ' . $ out - > { image_content_mimetype } ) ;
#$c->response->body($in->{svg_file}->slurp);
$ c - > stash ( out = > $ out ) ;
$ c - > stash ( in = > $ in ) ;
$ c - > stash ( template = > 'customer/invoice_template_aux_embedimage.tt' ) ;
$ c - > detach ( $ c - > view ( 'SVG' ) ) ;
#$c->log->debug('filename='.);
#$type = $_REQUEST['type'];
#if (!in_array($type, array('load_svg', 'import_svg', 'import_img'))) {
# exit;
#}
#require('allowedMimeTypes.php');
#$file = $_FILES['svg_file']['tmp_name'];
#$output = file_get_contents($file);
#$prefix = '';
#// Make Data URL prefix for import image
#if ($type == 'import_img') {
# $info = getimagesize($file);
# if (!in_array($info['mime'], $allowedMimeTypesBySuffix)) {
# exit;
# }
# $prefix = 'data:' . $info['mime'] . ';base64,';
#}
}
sub invoice_data :Chained('base') :PathPart('invoice') :CaptureArgs(0) {
@ -938,55 +909,15 @@ sub invoice_data :Chained('base') :PathPart('invoice') :CaptureArgs(0) {
$ invoice_details = [ map { [ $ i + + , $ _ ] } ( @$ invoice_details ) x 21 ] ;
$ c - > stash ( invoice_details = > $ invoice_details ) ;
}
#method separated as some day
sub invoice_template_list :Chained('invoice_data') :PathPart('') :CaptureArgs(0) {
my ( $ self , $ c ) = @ _ ;
$ c - > log - > debug ( 'invoice_template_list' ) ;
my ( $ validator , $ backend , $ in , $ out ) ;
#this is just copy-paste from method above
#of course we are chained and we can put in and out to stash
#input
$ in - > { contract_id } = $ c - > stash - > { contract } - > id ;
#output
$ out = { } ;
#storage
#pass scheme here is ugly, and should be moved somehow to DB::Base
$ backend = NGCP::Panel::Model::DB::InvoiceTemplate - > new ( schema = > $ c - > model ( 'DB' ) ) ;
#input checking & simple preprocessing
$ validator = NGCP::Panel::Form::Customer::InvoiceTemplate - > new ( backend = > $ backend ) ;
# $form->schema( $c->model('DB::InvoiceTemplate')->schema );
#to common form package ? removing is necessary due to FormHandler param presence evaluation - it is based on key presence, not on defined/not defined value
#in future this method should be called by ControllerBase
$ validator - > remove_undef_in ( $ in ) ;
#really, we don't need a form here at all
#just use as already implemented fields checking and defaults applying
#$validator->setup_form(
$ validator - > process (
posted = > 1 ,
params = > $ in ,
) ;
#$validator->validate_form();
#multi return...
$ c - > log - > debug ( "validated=" . $ validator - > validated . ";\n" ) ;
if ( ! $ validator - > validated ) {
return ;
}
my $ in_validated = $ validator - > fif ;
#dirty hack 1
#really model logic should recieve validated input, but raw input also should be saved somewhere
$ in = $ in_validated ;
#think about it more
#$out->{invoice_template_list} = $backend->getCustomerInvoiceTemplateList( %$in );
$ c - > stash ( invoice_template_list = > $ backend - > getCustomerInvoiceTemplateList ( %$ in ) - > all ) ;
}
sub invoice :Chained('invoice_template_list') :PathPart('') :Args(0) {
my ( $ self , $ c ) = @ _ ;
$ c - > stash ( template = > 'customer/invoice.tt' ) ;
@ -1013,15 +944,16 @@ sub invoice_template :Chained('invoice_data') :PathPart('template') :Args {
#output
$ out = { } ;
#storage
#pass scheme here is ugly, and should be moved somehow to DB::Base
$ backend = NGCP::Panel::Model::DB::InvoiceTemplate - > new ( schema = > $ c - > model ( 'DB' ) ) ;
#input checking & simple preprocessing
$ validator = NGCP::Panel::Form::Customer::InvoiceTemplate - > new ;
# $form->schema( $c->model('DB::InvoiceTemplate')->schema );
#to common form package ? removing is necessary due to FormHandler param presence evaluation - it is based on key presence, not on defined/not defined value
foreach ( keys %$ in ) { if ( ! ( defined $ in - > { $ _ } ) ) { delete $ in - > { $ _ } ; } } ;
#storage
#pass scheme here is ugly, and should be moved somehow to DB::Base
$ backend = NGCP::Panel::Model::DB::InvoiceTemplate - > new ( schema = > $ c - > model ( 'DB' ) ) ;
#really, we don't need a form here at all
#just use as already implemented fields checking and defaults applying
@ -1140,8 +1072,10 @@ sub invoice_template :Chained('invoice_data') :PathPart('template') :Args {
#preShowCustomTemplate prerpocessing
{
#preShowInvoice
#even better - to template filters
#also to model
$ out - > { tt_string } =~ s/(?:{\s*)?<!--{|}-->(?:\s*})?//gs ;
$ out - > { tt_string } =~ s/(<g .*?(id *=["' ]+(?:title|bg|mid)page["' ]+)?.*?)(?:display="none")(?(2)(?:.*?>)($2.*?>))/$1$3/gs ;
}
if ( ( $ in - > { tt_output_type } eq 'svg' ) || ( $ in - > { tt_output_type } eq 'html' ) ) {
@ -1204,9 +1138,7 @@ sub invoice_template :Chained('invoice_data') :PathPart('template') :Args {
#my $cmd = "/tmp/wkhtmltox/bin/wkhtmltopdf $filename - ";
my $ cmd = "rsvg-convert -f pdf " . join ( " " , @ pagefiles ) ;
$ c - > log - > debug ( $ cmd ) ;
#`chmod ugo+rwx $filename`;
#binmode(STDOUT);
#binmode(STDIN);
#$out->{tt_string} = `$cmd`;
@ -1220,7 +1152,6 @@ sub invoice_template :Chained('invoice_data') :PathPart('template') :Args {
}
$ c - > response - > body ( $ out - > { tt_string } ) ;
return ;
#$out->{tt_string} = `cat $filename `;
}