diff --git a/lib/NGCP/Panel/Form/InvoiceTemplate/Basic.pm b/lib/NGCP/Panel/Form/InvoiceTemplate/Basic.pm index cd350a1c26..3b21b610c2 100644 --- a/lib/NGCP/Panel/Form/InvoiceTemplate/Basic.pm +++ b/lib/NGCP/Panel/Form/InvoiceTemplate/Basic.pm @@ -4,14 +4,19 @@ use HTML::FormHandler::Moose; extends 'NGCP::Panel::Form::ValidatorBase'; use Moose::Util::TypeConstraints; +use HTML::FormHandler::Widget::Block::Bootstrap; enum 'TemplateType' => [ qw/svg html/ ];#html enum 'TemplateTypeOutput' => [ qw/svg html pdf json svgzip htmlzip pdfzip/ ];#html enum 'TemplateViewMode' => [ qw/raw parsed both/ ]; enum 'TemplateSourceState' => [ qw/saved previewed default/ ]; #no Moose::Util::TypeConstraints; +has '+widget_wrapper' => ( default => 'Bootstrap' ); has '+use_fields_for_input_without_param' => ( default => 1 ); +sub build_render_list {[qw/fields actions/]} +sub build_form_element_class { [qw/form-horizontal/] } +has_field 'submitid' => ( type => 'Hidden' ); has_field 'tt_type' => ( type => 'Text', required => 1, @@ -54,7 +59,7 @@ has_field 'tt_string' => ( ); has_field 'contract_id' => ( - type => 'Text', + type => 'Hidden', #default => \& #apply => [ { check => \&validate_tt_string } ], required => 1, @@ -68,9 +73,9 @@ has_field 'tt_id' => ( ); has_field 'name' => ( type => 'Text', - default => '', + #default => '', #apply => [ { check => \&validate_tt_string } ], - required => 0, + required => 1, ); has_field 'is_active' => ( type => 'Checkbox', @@ -79,6 +84,25 @@ has_field 'is_active' => ( required => 0, ); +has_field 'save' => ( + type => 'Button', + value => 'Save', + element_class => [qw/btn btn-primary/], + label => '', +); + +has_block 'fields' => ( + tag => 'div', + class => [qw/modal-body/], + render_list => [qw/name tt_id is_active submitid contract_id/], +); + +has_block 'actions' => ( + tag => 'div', + class => [qw/modal-footer/], + render_list => [qw/save/], +); + 1; =head1 NAME diff --git a/lib/NGCP/Panel/Model/DB/InvoiceTemplate.pm b/lib/NGCP/Panel/Model/DB/InvoiceTemplate.pm index 2fbbdd520e..9ee40856b3 100644 --- a/lib/NGCP/Panel/Model/DB/InvoiceTemplate.pm +++ b/lib/NGCP/Panel/Model/DB/InvoiceTemplate.pm @@ -27,19 +27,28 @@ sub getCustomerInvoiceTemplate{ my (%params) = @_; my ($contract_id,$tt_sourcestate,$tt_type,$tt_id) = @params{qw/contract_id tt_sourcestate tt_type tt_id/}; - irka::loglong("getCustomerInvoiceTemplate: tt_id=$tt_id;\n"); + #irka::loglong("getCustomerInvoiceTemplate: tt_id=$tt_id;\n"); #irka::loglong(Dumper(\%params)); my $result = ''; my $conditions = $self->getDefaultConditions(\%params); #my $tt_record = $self->resultset('invoice_templates')->search({ - my $tt_record = $self->schema->resultset('invoice_templates')->search($conditions)->first; + my $tt_record = $self->schema->resultset('invoice_templates')->search( + { id => $tt_id }, { + #'+select' => [{'reseller_id' =>'contract_id','-as'=>'contract_id'},{'id' => 'tt_id','-as'=>'tt_id'}] + '+select' => [ + [ 'reseller_id', {'-as'=>'contract_id'}], + [ 'id', {'-as'=>'tt_id'}], + ], + #'+select' => [qw/reseller_id id/], + #'+as' => [qw/contract_id tt_id/] + })->first; #here may be base64 decoding #here we will rely on form checking and defaults #if('saved' eq $tt_sourcestate){ if( $tt_record ){ - $result = $tt_record->get_column( 'base64_'.$tt_sourcestate ); + $tt_sourcestate and $result = $tt_record->get_column( 'base64_'.$tt_sourcestate ); $tt_id = $tt_record->get_column( 'id' ); } if( $result && exists $params{result} ){ @@ -101,6 +110,37 @@ sub storeCustomerInvoiceTemplate{ }); return { tt_id => $tt_id }; } +sub storeInvoiceTemplateInfo{ + my $self = shift; + my (%params) = @_; + my ($contract_id,$tt_id,$is_active,$name) = @params{qw/contract_id tt_id is_active name/}; + + #my $tt_record = $self->resultset('invoice_templates')->search({ + $self->schema->txn_do(sub { + my $tt_record_created; + my $tt_record_updated; + if( !$tt_id ){ + $tt_record_created = $self->schema->resultset('invoice_templates')->create({ + reseller_id => $contract_id, + is_active => $is_active, + name => $name, + }); + if($tt_record_created){ + $tt_id = $tt_record_created->id(); + } + }else{ + $tt_record_updated = $self->schema->resultset('invoice_templates')->search({ id => $tt_id }); + $tt_record_updated->update({ + is_active => $is_active, + name => $name, + }); + } + if($is_active && $tt_id){ + $self->deactivateOtherTemplates($contract_id,$tt_id); + } + }); + return { tt_id => $tt_id }; +} sub getCustomerInvoiceTemplateList{ my $self = shift; my (%params) = @_; @@ -110,9 +150,6 @@ sub getCustomerInvoiceTemplateList{ #$self->schema->resultset('invoice_template_fake')->find(\'select * from invoice_templates')->all #$self->schema->resultset('invoice_templates')->name(\'(select * from invoice_templates)')->all #]; - use irka; - use Data::Dumper; - irka::loglong(Dumper(\%INC)); return [ $self->schema->resultset('invoice_templates')->search({ reseller_id => $contract_id, })->all ]; diff --git a/lib/NGCP/Panel/View/SVG.pm b/lib/NGCP/Panel/View/SVG.pm index c269d393e8..8392b20ae9 100644 --- a/lib/NGCP/Panel/View/SVG.pm +++ b/lib/NGCP/Panel/View/SVG.pm @@ -14,8 +14,13 @@ __PACKAGE__->config( WRAPPER => '', FILTERS => {}, ABSOLUTE => 0, - expose_methods => [], + expose_methods => [qw/translate_form/], ); +#copy-paste from html, method is too small to move it to separate class +sub translate_form { + my $self = shift; + NGCP::Panel::Utils::I18N->translate_form(@_); +} sub process { diff --git a/share/static/js/invoice_template.js b/share/static/js/invoice_template.js index 0a5f1ecd49..711be72a2b 100644 --- a/share/static/js/invoice_template.js +++ b/share/static/js/invoice_template.js @@ -10,8 +10,8 @@ function init_embed() { { doc = frame.contentWindow.document; } - //var mainButton = doc.getElementById('main_button'); - //mainButton.style.display = 'none'; + var mainButton = doc.getElementById('main_button'); + mainButton.style.display = 'none'; } //private function getSvgString(){ @@ -54,10 +54,11 @@ function fetchSvgToEditor( data ) { setSvgStringToEditor( httpResponse ); }); } -function refreshTemplateList ( contract_id ){ +function refreshAccordionAjaxList ( item, data ){ + alert('refreshAccordionAjaxList: q='+uriForAction( data, item + '_list' )+';item='+item); fetch_into( - 'collapse_invoice_template_list', - uriForAction( {'contract_id': contract_id}, 'invoice_template_list' ), + 'collapse_' +item + '_list', + uriForAction( data, item + '_list' ), '', function(){ mainWrapperInit(); } ); @@ -100,7 +101,7 @@ function savePreviewedAndShowParsed( data ){ //alert('savePreviewedAndShowParsed: httpResponse='+httpResponse+';'); setSvgStringToPreview( httpResponse, q ) //refresh list after saving - refreshTemplateList( data.contract_id ); + refreshAccordionAjaxList( 'invoice_template', data ); } ); } function saveTemplate( data ) { @@ -119,6 +120,56 @@ function saveTemplate( data ) { if(jsonResponse.aaData && jsonResponse.aaData.form){ $('form[name=invoice_template]').loadJSON(jsonResponse.aaData.form); } - refreshTemplateList( data.contract_id ); + refreshAccordionAjaxList( 'invoice_template', data ); }); } +function processModalFormAjax( form, callback ) { + //preventDefault(); + alert(form.attr('action')+'?'+form.serialize()); + var item = form.attr('id'); + $.ajax( { + url: form.attr('action'), + type: "POST", + data: form.serialize(), + } ).done( function( responseText, textStatus, request ) { + /* + var headers = request.getAllResponseHeaders(); + var i =0; + alert('headers='+headers); + for(i=0; i[% m.text %] +[% END -%] +[% messages = [] -%] diff --git a/share/templates/helpers/modal.tt b/share/templates/helpers/modal.tt index 8731221c96..c40a6291f1 100644 --- a/share/templates/helpers/modal.tt +++ b/share/templates/helpers/modal.tt @@ -28,20 +28,40 @@ [% MACRO modal_script BLOCK %] [% END -%] diff --git a/share/templates/invoice/invoice.tt b/share/templates/invoice/invoice.tt index b3e298870c..681a2a73f3 100644 --- a/share/templates/invoice/invoice.tt +++ b/share/templates/invoice/invoice.tt @@ -1,24 +1,24 @@ [% USE Dumper %] [% USE format %] [% money_format = format('%.2f') %] -[% IF !c.user.read_only && (c.user.roles == 'admin' || c.user.roles == 'reseller') -%] [% write_access = 1 %] -[%END%] [%PROCESS 'helpers/datatables_vars.tt' no_auto_helper = 1 -%] +[%PROCESS 'helpers/modal.tt' -%] +[%mf_helper = { + ajax_load => 1, +}%] +[%modal_script( m = mf_helper )%] -[% IF c.user.roles == "subscriber" || c.user.roles == "subscriberadmin" -%] - [% site_config.title = c.loc('Invoice template manager') -%] -[% ELSE -%] - [% site_config.title = c.loc('Customer Invoice template for #[_1] ([_2])',contract.id, product.name) -%] -[% END -%] +[% site_config.title = c.loc('Invoice template for [_1]', reseller.first.name) -%] + @@ -62,7 +61,20 @@ var uriForAction = function( data, type ){ [% c.loc('Back') %] + + + [% c.loc('Create invoices template')%] + + + +[% IF reseller.first.status != "active" -%] + [%messages.unshift( c.loc('Reseller is [_1]', reseller.first.status) ); %] +[% END -%] +
+[%PROCESS 'helpers/ajax_messages.tt' -%]
+ +
[% back_created = 1 -%] @@ -111,8 +123,13 @@ var uriForAction = function( data, type ){ +
[%PROCESS 'invoice/invoice_template_form.tt' %]
- \ No newline at end of file + + +
+
+ diff --git a/share/templates/invoice/invoice_template_form.tt b/share/templates/invoice/invoice_template_form.tt index 7d9da0f35a..9833e5dc34 100644 --- a/share/templates/invoice/invoice_template_form.tt +++ b/share/templates/invoice/invoice_template_form.tt @@ -3,23 +3,28 @@ [%# USE FillInForm %] -
+
[% IF write_access -%] - +
[% END -%]
diff --git a/share/templates/invoice/invoice_template_form_modal.tt b/share/templates/invoice/invoice_template_form_modal.tt new file mode 100644 index 0000000000..37fcd66ed5 --- /dev/null +++ b/share/templates/invoice/invoice_template_form_modal.tt @@ -0,0 +1,2 @@ +[%m.name = "Invoice Template"%] +[%PROCESS 'helpers/ajax_form_modal.tt'-%] diff --git a/share/templates/invoice/invoice_template_list.tt b/share/templates/invoice/invoice_template_list.tt index 5c95e8b21b..660a4cf062 100644 --- a/share/templates/invoice/invoice_template_list.tt +++ b/share/templates/invoice/invoice_template_list.tt @@ -11,8 +11,8 @@ [% c.loc('Active') %] - [% c.loc('Type') %] [% c.loc('Name') %] + [% c.loc('Type') %] @@ -21,53 +21,34 @@ [%# Dumper.dump_html(invoice_template_list.as_query)%] [%# Dumper.dump_html(template)%] - - [% template.get_column('type') %] + [%IF template.get_column('is_active') > 0; '✓'; END%] [% template.get_column('name') %] - + [% template.get_column('type') %]
- [% IF write_access -%] - [%IF template.get_column('base64_previewed')%] - - [% c.loc('Edit previewed') %] + + [% c.loc('Edit template info') %] - [%END%] - [%IF template.get_column('base64_saved')%] - [% c.loc('Edit saved') %] + [% c.loc('Edit template') %] + + + [%IF template.get_column('is_active'); c.loc('Deactivate'); ELSE; c.loc('Activate'); END%] - [%END%] - [%IF !template.is_active%] - - [%END%] [% c.loc('Delete') %] [%END%] -
diff --git a/share/templates/reseller/details.tt b/share/templates/reseller/details.tt index 5a668ed934..9284d4d5c2 100644 --- a/share/templates/reseller/details.tt +++ b/share/templates/reseller/details.tt @@ -230,7 +230,7 @@
-[%PROCESS 'invoice/invoice_template_list.tt' %] +[%PROCESS 'invoice/invoice_details_list.tt' %]