From 3e557152bcb4d82cded8a40c40508d557d689648 Mon Sep 17 00:00:00 2001 From: Irina Peshinskaya Date: Mon, 17 Mar 2014 11:28:35 +0100 Subject: [PATCH] MT#5879 Separate actions for invoice templates. Saving and view should be separated too. Rename ttemplates: calls to invoice and "template" according to content. --- lib/NGCP/Panel/Controller/Customer.pm | 55 +-- .../Panel/Form/Customer/InvoiceTemplate.pm | 4 +- lib/NGCP/Panel/Model/DB/InvoiceTemplate.pm | 9 +- lib/NGCP/Panel/Utils/InvoiceTemplate.pm | 4 +- lib/NGCP/Panel/View/SVG.pm | 4 + share/templates/customer/details.tt | 56 +-- share/templates/customer/invoice.tt | 322 +++++++++++------- share/templates/customer/invoice_template.tt | 2 +- .../customer/invoice_template_svg.tt | 14 +- 9 files changed, 270 insertions(+), 200 deletions(-) diff --git a/lib/NGCP/Panel/Controller/Customer.pm b/lib/NGCP/Panel/Controller/Customer.pm index a756f59359..756dbf863a 100644 --- a/lib/NGCP/Panel/Controller/Customer.pm +++ b/lib/NGCP/Panel/Controller/Customer.pm @@ -812,13 +812,30 @@ sub edit_balance :Chained('base') :PathPart('balance/edit') :Args(0) { $c->stash(edit_flag => 1); } -sub invoice :Chained('base') :PathPart('invoice') :CaptureArgs(0) { +sub invoice_data :Chained('base') :PathPart('invoice') :CaptureArgs(0) { my ($self, $c) = @_; - $c->stash(template => 'customer/invoice.tt'); -} + $c->log->debug('invoice_data'); + my $contract_id = $c->stash->{contract}->id; + my $stime = NGCP::Panel::Utils::DateTime::current_local()->truncate(to => 'month'); + my $etime = $stime->clone->add(months => 1); -sub invoice_template_list :Chained('invoice') :PathPart('') :CaptureArgs(0) { + #look, NGCP::Panel::Utils::Contract - it is kind of backend separation here + my $zonecalls_rs = NGCP::Panel::Utils::Contract::get_contract_calls_rs( + c => $c, + contract_id => $contract_id, + stime => $stime, + etime => $etime, + ); + #FAKE FAKE FAKE FAKE + $zonecalls_rs = [$zonecalls_rs->all()]; + my $i = 1; + $zonecalls_rs = [map{[$i++,$_]} (@$zonecalls_rs) x 21]; + $c->stash(zonecalls_rs => $zonecalls_rs ); +} +#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 @@ -861,31 +878,14 @@ sub invoice_template_list :Chained('invoice') :PathPart('') :CaptureArgs(0) { #think about it more #$out->{invoice_template_list} = $backend->getCustomerInvoiceTemplateList( %$in ); - $c->stash(invoice_template_list => $backend->getCustomerInvoiceTemplateList( %$in ) ); + $c->stash( invoice_template_list => $backend->getCustomerInvoiceTemplateList( %$in )->all ); } - -sub invoice_data :Chained('invoice_template_list') :PathPart('') :CaptureArgs(0) { +sub invoice :Chained('invoice_template_list') :PathPart('') :Args(0) { my ($self, $c) = @_; - $c->log->debug('calls_list'); - my $contract_id = $c->stash->{contract}->id; - my $stime = NGCP::Panel::Utils::DateTime::current_local()->truncate(to => 'month'); - my $etime = $stime->clone->add(months => 1); - - #look, NGCP::Panel::Utils::Contract - it is kind of backend separation here - my $zonecalls_rs = NGCP::Panel::Utils::Contract::get_contract_calls_rs( - c => $c, - contract_id => $contract_id, - stime => $stime, - etime => $etime, - ); - #FAKE FAKE FAKE FAKE - $zonecalls_rs = [$zonecalls_rs->all()]; - my $i = 1; - $zonecalls_rs = [map{[$i++,$_]} (@$zonecalls_rs) x 21]; - $c->stash(zonecalls_rs => $zonecalls_rs ); + $c->stash(template => 'customer/invoice.tt'); } -sub invoice_template :Chained('invoice_data') :PathPart('') :CaptureArgs(5) { +sub invoice_template :Chained('invoice_data') :PathPart('template') :Args { my ($self, $c) = @_; #$c->log->debug($c->model('DB')); #return; @@ -894,7 +894,7 @@ sub invoice_template :Chained('invoice_data') :PathPart('') :CaptureArgs(5) { #my $contract_id = $in->{contract_id} = ; - #no warnings 'uninitialized'; + no warnings 'uninitialized'; my($validator,$backend,$in,$out); @@ -949,7 +949,8 @@ sub invoice_template :Chained('invoice_data') :PathPart('') :CaptureArgs(5) { }elsif($in->{tt_type} eq 'html'){ $in->{tt_output_type} = 'html'; } - + #use irka; + #use Data::Dumper; #irka::loglong(Dumper($in)); #model logic diff --git a/lib/NGCP/Panel/Form/Customer/InvoiceTemplate.pm b/lib/NGCP/Panel/Form/Customer/InvoiceTemplate.pm index 1cb409bd1a..e3db1948c4 100644 --- a/lib/NGCP/Panel/Form/Customer/InvoiceTemplate.pm +++ b/lib/NGCP/Panel/Form/Customer/InvoiceTemplate.pm @@ -56,14 +56,14 @@ has_field 'tt_string' => ( ); has_field 'contract_id' => ( - type => 'Number', + type => 'Text', #default => \& #apply => [ { check => \&validate_tt_string } ], required => 1, ); has_field 'tt_id' => ( - type => 'Number', + type => 'Text', #default => \& #apply => [ { check => \&validate_tt_string } ], required => 0, diff --git a/lib/NGCP/Panel/Model/DB/InvoiceTemplate.pm b/lib/NGCP/Panel/Model/DB/InvoiceTemplate.pm index c304ed0a79..07215f394f 100644 --- a/lib/NGCP/Panel/Model/DB/InvoiceTemplate.pm +++ b/lib/NGCP/Panel/Model/DB/InvoiceTemplate.pm @@ -77,5 +77,12 @@ sub storeCustomerInvoiceTemplate{ } }); } - +sub getCustomerInvoiceTemplateList{ + my $self = shift; + my (%params) = @_; + my ($contract_id,$tt_sourcestate,$tt_type, $tt_string, $tt_id) = @params{qw/contract_id tt_sourcestate tt_type tt_string_sanitized tt_id/}; + return $self->schema->resultset('invoice_template')->search({ + reseller_id => $contract_id, + }); +} 1; \ No newline at end of file diff --git a/lib/NGCP/Panel/Utils/InvoiceTemplate.pm b/lib/NGCP/Panel/Utils/InvoiceTemplate.pm index 8e2e1d1e44..116e27b034 100644 --- a/lib/NGCP/Panel/Utils/InvoiceTemplate.pm +++ b/lib/NGCP/Panel/Utils/InvoiceTemplate.pm @@ -1,4 +1,6 @@ package NGCP::Panel::Utils::InvoiceTemplate; +#it should be part of real model, or subcontroller + use strict; use warnings; use Moose; @@ -7,7 +9,7 @@ use Sipwise::Base; sub getDefaultInvoiceTemplate{ my (%in) = @_; #in future may be we will store root default in Db too, but now it is convenient to edit template as file - my $result = $in{c}->view('SVG')->getTemplateContent($in{c}, 'customer/calls_'.$in{type}.'.tt'); + my $result = $in{c}->view('SVG')->getTemplateContent($in{c}, 'customer/invoice_template_'.$in{type}.'.tt'); #$in{c}->log->debug("result=$result;"); diff --git a/lib/NGCP/Panel/View/SVG.pm b/lib/NGCP/Panel/View/SVG.pm index 5ee61f801e..c269d393e8 100644 --- a/lib/NGCP/Panel/View/SVG.pm +++ b/lib/NGCP/Panel/View/SVG.pm @@ -56,7 +56,11 @@ sub getTemplateContent{ } sub getTemplateProcessed{ my ( $self, $c, $template, $stash ) = @_; + #$c->log->debug("getTemplateProcessed: template=$template;"); + #my $result = $self->{template}->context->process($template, $stash); + #$c->log->debug("getTemplateProcessed: result=$result;"); + #return $result return $self->{template}->context->process($template, $stash); } diff --git a/share/templates/customer/details.tt b/share/templates/customer/details.tt index d71cb86101..c816044130 100644 --- a/share/templates/customer/details.tt +++ b/share/templates/customer/details.tt @@ -399,30 +399,20 @@ -[%BLOCK accordion_group_internal %] -
-
- -[% content %] -
-
-
-[%END%] - -[%BLOCK accordion_group %] +[%# USE Dumper %] +[%# Dumper.dump(zonecalls_rs)%] +[%# zonecalls_rs.size%]
-[%content%] -
-[%END%] - -[% USE Dumper %] -[%# Dumper.dump(zonecalls_rs)%] -[%# zonecalls_rs.size%] -[% WRAPPER accordion_group id="collapse_calls" title=c.loc('Balance details') %] -[% WRAPPER accordion_group_internal id="collapse_calls" title='Balance details' %] +
+
+ + [% c.loc('Invoice Template')%] + +
+ @@ -430,12 +420,12 @@ - [%# Dumper.dump_html(zonecalls_rs.as_query)%] [% FOR call IN zonecalls_rs -%] + [%IF call.1; call = call.1; END%] [% total_number = total_number + call.get_column('number') %] [% total_duration = total_duration + call.get_column('duration') %] [% total_free_time = total_free_time + call.get_column('free_time') %] @@ -446,14 +436,6 @@ - [%END%] @@ -462,18 +444,12 @@ - -[%END%] -[%END%] +
[% c.loc('Zone') %][% c.loc('Duration') %] [% c.loc('Free time') %] [% c.loc('Cash') %]
[% call.get_column('duration')|format('%.3f') %]
[% call.get_column('free_time')|format('%d') %]
[% money_format( call.get_column('cost') / 100 ) %]
- -
[% total_duration | format('%.3f') %]
[% total_free_time | format('%d')%]
[% money_format( total_cost / 100 ) %]
- -
+
+
+ [% IF c.user.roles == 'admin' || c.user.roles == 'reseller' %]
diff --git a/share/templates/customer/invoice.tt b/share/templates/customer/invoice.tt index 58700eda5d..4320726e0c 100644 --- a/share/templates/customer/invoice.tt +++ b/share/templates/customer/invoice.tt @@ -1,73 +1,26 @@ [% IF c.user.roles == "subscriber" || c.user.roles == "subscriberadmin" -%] - [% site_config.title = c.loc('Customer Calls') -%] + [% site_config.title = c.loc('Invoice template manager') -%] [% ELSE -%] - [% site_config.title = c.loc('Customer Calls for #[_1] ([_2])',contract.id, product.name) -%] + [% site_config.title = c.loc('Customer Invoice template for #[_1] ([_2])',contract.id, product.name) -%] [% END -%] -[% BLOCK accordion_group_internal %] -
- -[% content %] -
-
+[% IF !c.user.read_only && (c.user.roles == 'admin' || c.user.roles == 'reseller') -%] +[% write_access = 1 %] [%END%] + + +
+[% back_created = 1 -%] + + [% USE Dumper %] -[% WRAPPER accordion_group_internal id="collapse_calls" title='Balance details' %] - - - [% c.loc('Zone') %] - [% c.loc('Calls amount') %] - [% c.loc('Duration') %] - [% c.loc('Free time') %] - [% c.loc('Cash') %] - - - - - [%# Dumper.dump_html(zonecalls_rs.as_query)%] - [% FOR call IN zonecalls_rs -%] - [%IF call.1; call = call.1; END%] - [% total_number = total_number + call.get_column('number') %] - [% total_duration = total_duration + call.get_column('duration') %] - [% total_free_time = total_free_time + call.get_column('free_time') %] - [% total_cost = total_cost + call.get_column('cost') %] - - [% call.get_column('zone') %] -
[% call.get_column('number') %]
-
[% call.get_column('duration')|format('%.3f') %]
-
[% call.get_column('free_time')|format('%d') %]
-
[% money_format( call.get_column('cost') / 100 ) %]
- - - - - [%END%] - - [% c.loc('Total') %] -
[% total_number %] -
[% total_duration | format('%.3f') %] -
[% total_free_time | format('%d')%] -
[% money_format( total_cost / 100 ) %]
- - - - - -[%END%] - - - - + +
+ +
+ + +
+
+ + + + + + + + + + + + + [%# Dumper.dump_html(zonecalls_rs.as_query)%] + [% FOR call IN zonecalls_rs -%] + [%IF call.1; call = call.1; END%] + [% total_number = total_number + call.get_column('number') %] + [% total_duration = total_duration + call.get_column('duration') %] + [% total_free_time = total_free_time + call.get_column('free_time') %] + [% total_cost = total_cost + call.get_column('cost') %] + + + + + + + + [%END%] + + + + + + + + +
[% c.loc('Zone') %][% c.loc('Calls amount') %][% c.loc('Duration') %][% c.loc('Free time') %][% c.loc('Cash') %]
[% call.get_column('zone') %]
[% call.get_column('number') %]
[% call.get_column('duration')|format('%.3f') %]
[% call.get_column('free_time')|format('%d') %]
[% money_format( call.get_column('cost') / 100 ) %]
[% c.loc('Total') %]
[% total_number %]
[% total_duration | format('%.3f') %]
[% total_free_time | format('%d')%]
[% money_format( total_cost / 100 ) %]
+
+
+
+ + + +
+ +
+
+ [% IF write_access -%] + + [% c.loc('Create invoice template')%] + +
+ [% END -%] + + + + + + + + + + + [%# Dumper.dump_html(invoice_template_list.as_query)%] + [% FOR template IN invoice_template_list -%] + + + + + + + [%END%] + +
[% c.loc('Active') %][% c.loc('Type') %][%# c.loc('Name') %]
[% template.get_column('is_active') %][% template.get_column('type') %][%# template.get_column('name') %] + +
+ + +
[%initial = 'saved'%] -