From a0773b259113025c86d6b8eb20b59137abc6c71a Mon Sep 17 00:00:00 2001 From: Gerhard Jungwirth Date: Mon, 29 Apr 2013 18:24:52 +0200 Subject: [PATCH] billing: fix links, create forms (billing_fees, billing_profiles) - another datatables structure is there for billing_fees - forms are now performing the desired actions (in ngcp-schema) --- lib/NGCP/Panel/Controller/Billing.pm | 148 +++++++++++++++++++++++++- lib/NGCP/Panel/Form/BillingFee.pm | 95 +++++++++++++++++ lib/NGCP/Panel/Form/BillingProfile.pm | 8 +- share/templates/billing/fees.tt | 18 ++++ share/templates/billing/list.tt | 2 + share/templates/contact/list.tt | 2 + share/templates/contract/list.tt | 2 + share/templates/domain/list.tt | 2 + share/templates/helpers/datatables.tt | 10 +- share/templates/reseller/list.tt | 2 + 10 files changed, 278 insertions(+), 11 deletions(-) create mode 100644 lib/NGCP/Panel/Form/BillingFee.pm create mode 100644 share/templates/billing/fees.tt diff --git a/lib/NGCP/Panel/Controller/Billing.pm b/lib/NGCP/Panel/Controller/Billing.pm index f5b4a257d1..c5c8e0c328 100644 --- a/lib/NGCP/Panel/Controller/Billing.pm +++ b/lib/NGCP/Panel/Controller/Billing.pm @@ -5,6 +5,7 @@ use namespace::autoclean; BEGIN { extends 'Catalyst::Controller'; } use NGCP::Panel::Form::BillingProfile; +use NGCP::Panel::Form::BillingFee; sub list :Chained('/') :PathPart('billing') :CaptureArgs(0) :Args(0) { my ( $self, $c ) = @_; @@ -60,7 +61,9 @@ sub edit :Chained('base') :PathPart('edit') { action => $c->uri_for($c->stash->{profile}->{id}, 'edit'), ); if($posted && $form->validated) { - #do the database update here + $c->model('billing')->resultset('billing_profiles') + ->find($form->field('id')->value) + ->update($form->fif() ); $c->flash(messages => [{type => 'success', text => 'Billing Profile successfully changed!'}]); $c->response->redirect($c->uri_for()); return; @@ -69,6 +72,114 @@ sub edit :Chained('base') :PathPart('edit') { $c->stash(form => $form); } +sub create :Chained('list') :PathPart('create') :Args(0) { + my ($self, $c) = @_; + + my $form = NGCP::Panel::Form::BillingProfile->new; + $form->process( + posted => ($c->request->method eq 'POST'), + params => $c->request->params, + action => $c->uri_for('create'), + ); + if($form->validated) { + $c->model('billing')->resultset('billing_profiles')->create( + $form->fif() ); + $c->flash(messages => [{type => 'success', text => 'Billing profile successfully created!'}]); + $c->response->redirect($c->uri_for()); + return; + } + + $c->stash(close_target => $c->uri_for()); + $c->stash(create_flag => 1); + $c->stash(form => $form); +} + +sub delete :Chained('base') :PathPart('delete') :Args(0) { + my ($self, $c) = @_; + + unless ( defined($c->stash->{'profile_result'}) ) { + $c->flash(messages => [{type => 'error', text => 'Billing profile not found!'}]); + return; + } + $c->stash->{'profile_result'}->delete; + + $c->flash(messages => [{type => 'success', text => 'Billing profile successfully deleted!'}]); + $c->response->redirect($c->uri_for); +} + +sub fees_list :Chained('base') :PathPart('fees') :CaptureArgs(0) { + my ($self, $c) = @_; + + $c->stash(has_edit => 1); + $c->stash(has_preferences => 0); + $c->stash(template => 'billing/fees.tt'); + + +} + +sub fees :Chained('fees_list') :PathPart('') :Args(0) { + my ($self, $c) = @_; + +} + +sub fees_base :Chained('fees_list') :PathPart('') :CaptureArgs(1) { + my ($self, $c) = @_; + +} + +sub fees_ajax :Chained('fees_list') :PathPart('ajax') :Args(0) { + my ($self, $c) = @_; + + my $resultset = $c->stash->{'profile_result'}->billing_fees + ->search(undef, { + join => 'billing_zone', + columns => [ + {'zone' => 'billing_zone.zone'}, + 'id','source','destination','direction' + ] + }); + + $c->forward( "/ajax_process_resultset", [$resultset, + ["id", "source", "destination", "direction", 'zone'], + [1,2,3]]); + + $c->detach( $c->view("JSON") ); +} + +sub fees_create :Chained('fees_list') :PathPart('create') :Args(0) { + my ($self, $c) = @_; + + my $form = NGCP::Panel::Form::BillingFee->new; + $form->process( + posted => ($c->request->method eq 'POST'), + params => $c->request->params, + action => $c->uri_for($c->stash->{profile}->{id}, 'fees', 'create'), + ); + if($form->validated) { + $c->stash->{'profile_result'}->billing_fees + ->create( + $form->fif() + ); + $c->flash(messages => [{type => 'success', text => 'Billing Fee successfully created!'}]); + $c->response->redirect($c->uri_for($c->stash->{profile}->{id}, 'fees')); + return; + } + + $c->stash(close_target => $c->uri_for($c->stash->{profile}->{id}, 'fees')); + $c->stash(create_flag => 1); + $c->stash(form => $form); +} + +sub fees_edit :Chained('fees_base') :PathPart('edit') :Args(0) { + + +} + +sub fees_delete :Chained('fees_base') :PathPart('delete') :Args(0) { + + +} + __PACKAGE__->meta->make_immutable; 1; @@ -91,7 +202,7 @@ basis for the billing controller =head2 root -just shows a list of billing profiles +just shows a list of billing profiles using datatables =head2 ajax @@ -105,6 +216,39 @@ Fetch a billing_profile by its id. Show a modal to edit one billing_profile. +=head2 create + +Show a modal to add a new billing_profile. + +=head2 delete + +Delete a billing_profile identified by base. + +=head2 fees_list + +basis for the billing_fees logic. for a certain billing_profile identified +by base. + +=head2 fees + +Shows a list of billing_fees for one billing_profile using datatables. + +=head2 fees_base + +Fetch a billing_fee (identified by id). + +=head2 fees_ajax + +Get billing_fees and output them as JSON. + +=head2 fees_create + +Show a modal to add a new billing_fee. + +=head2 fees_edit + +=head2 fees_delete + =head1 AUTHOR Gerhard Jungwirth C<< >> diff --git a/lib/NGCP/Panel/Form/BillingFee.pm b/lib/NGCP/Panel/Form/BillingFee.pm new file mode 100644 index 0000000000..4bbee6379b --- /dev/null +++ b/lib/NGCP/Panel/Form/BillingFee.pm @@ -0,0 +1,95 @@ +package NGCP::Panel::Form::BillingFee; + +use HTML::FormHandler::Moose; +extends 'HTML::FormHandler'; +use Moose::Util::TypeConstraints; + +use HTML::FormHandler::Widget::Block::Bootstrap; + +has '+widget_wrapper' => ( default => 'Bootstrap' ); +sub build_render_list {[qw/fields actions/]} +sub build_form_element_class { [qw/form-horizontal/] } + +has_field 'id' => ( + type => 'Hidden' +); + +has_field 'source' => ( + type => 'Text', #Regexp + maxlength => 255, +); + +has_field 'destination' => ( + type => 'Text', #Regexp nonepty + maxlength => 255, + required => 1, +); + +has_field 'direction' => ( + type => 'Select', + options => [ + { value => 'in', label => 'inbound' }, + { value => 'out', label => 'outbound' }, + ], +); + +has_field 'onpeak_init_rate' => ( + type => 'Float', +); + +has_field 'onpeak_init_interval' => ( + type => 'Integer', +); + +has_field 'onpeak_follow_rate' => ( + type => 'Float', +); + +has_field 'onpeak_follow_interval' => ( + type => 'Integer', +); + +has_field 'offpeak_init_rate' => ( + type => 'Float', +); + +has_field 'offpeak_init_interval' => ( + type => 'Integer', +); + +has_field 'offpeak_follow_rate' => ( + type => 'Float', +); + +has_field 'offpeak_follow_interval' => ( + type => 'Integer', +); + +has_field 'use_free_time' => ( + type => 'Boolean', +); + +has_field 'save' => ( + type => 'Submit', + value => 'Save', + element_class => [qw/btn btn-primary/], + label => '', +); + +has_block 'fields' => ( + tag => 'div', + class => [qw/modal-body/], + render_list => [qw/id source destination direction + onpeak_init_rate onpeak_init_interval onpeak_follow_rate + onpeak_follow_interval offpeak_init_rate offpeak_init_interval + offpeak_follow_rate offpeak_follow_interval use_free_time/], +); + +has_block 'actions' => ( + tag => 'div', + class => [qw/modal-footer/], + render_list => [qw/save/], +); + +1; +# vim: set tabstop=4 expandtab: diff --git a/lib/NGCP/Panel/Form/BillingProfile.pm b/lib/NGCP/Panel/Form/BillingProfile.pm index 121c84a6f2..3842106985 100644 --- a/lib/NGCP/Panel/Form/BillingProfile.pm +++ b/lib/NGCP/Panel/Form/BillingProfile.pm @@ -10,9 +10,9 @@ has '+widget_wrapper' => ( default => 'Bootstrap' ); sub build_render_list {[qw/fields actions/]} sub build_form_element_class { [qw/form-horizontal/] } -#has_field 'submitid' => ( -# type => 'Hidden' -#); +has_field 'id' => ( + type => 'Hidden' +); has_field 'name' => ( type => 'Text', @@ -105,7 +105,7 @@ has_block 'fields' => ( render_list => [qw/name interval_charge interval_free_time interval_free_cash fraud_interval_limit fraud_interval_lock fraud_interval_notify fraud_daily_limit fraud_daily_lock fraud_daily_notify - currency vat_rate vat_included/], + currency vat_rate vat_included id/], ); has_block 'actions' => ( diff --git a/share/templates/billing/fees.tt b/share/templates/billing/fees.tt new file mode 100644 index 0000000000..4bd13bb8d7 --- /dev/null +++ b/share/templates/billing/fees.tt @@ -0,0 +1,18 @@ +[% META title = 'Billing Fees' -%] +[% + helper.name = 'Billing Fees'; + helper.messages = messages; + helper.column_titles = [ '#', 'Source', 'Destination', 'Direction', 'Zone' ]; + helper.column_fields = [ 'id', 'source', 'destination', 'direction', 'zone' ]; + + helper.close_target = close_target; + helper.create_flag = create_flag; + helper.form_object = form; + helper.has_edit = has_edit; + helper.has_preferences = has_preferences; + helper.ajax_uri = c.uri_for( c.action, c.req.captures, 'ajax' ); + helper.base_uri = c.uri_for( profile.id, 'fees'); + + PROCESS 'helpers/datatables.tt'; +-%] +[% # vim: set tabstop=4 syntax=html expandtab: -%] diff --git a/share/templates/billing/list.tt b/share/templates/billing/list.tt index 63b00a0437..d87304d96a 100644 --- a/share/templates/billing/list.tt +++ b/share/templates/billing/list.tt @@ -11,6 +11,8 @@ helper.form_object = form; helper.has_edit = has_edit; helper.has_preferences = has_preferences; + helper.ajax_uri = c.uri_for( c.controller.action_for('ajax') ); + helper.base_uri = c.uri_for( c.controller.action_for("") ); helper.extra_buttons = [ [ 'Edit Fees', 'fees'], diff --git a/share/templates/contact/list.tt b/share/templates/contact/list.tt index 7e337c5a1b..94ec2f0dc0 100644 --- a/share/templates/contact/list.tt +++ b/share/templates/contact/list.tt @@ -10,6 +10,8 @@ helper.create_flag = create_flag; helper.edit_object = contact; helper.form_object = form; + helper.ajax_uri = c.uri_for( c.controller.action_for('ajax') ); + helper.base_uri = c.uri_for( c.controller.action_for("") ); PROCESS 'helpers/datatables.tt'; -%] diff --git a/share/templates/contract/list.tt b/share/templates/contract/list.tt index fbeb646749..48f3ee5e8d 100644 --- a/share/templates/contract/list.tt +++ b/share/templates/contract/list.tt @@ -10,6 +10,8 @@ helper.create_flag = create_flag; helper.edit_object = contract; helper.form_object = form; + helper.ajax_uri = c.uri_for( c.controller.action_for('ajax') ); + helper.base_uri = c.uri_for( c.controller.action_for("") ); PROCESS 'helpers/datatables.tt'; -%] diff --git a/share/templates/domain/list.tt b/share/templates/domain/list.tt index 7f4e4b4243..17a99fea11 100644 --- a/share/templates/domain/list.tt +++ b/share/templates/domain/list.tt @@ -12,6 +12,8 @@ helper.form_object = form; helper.has_edit = has_edit; helper.has_preferences = has_preferences; + helper.ajax_uri = c.uri_for( c.controller.action_for('ajax') ); + helper.base_uri = c.uri_for( c.controller.action_for("") ); PROCESS 'helpers/datatables.tt'; -%] diff --git a/share/templates/helpers/datatables.tt b/share/templates/helpers/datatables.tt index 928b012dc1..52502fb8cc 100644 --- a/share/templates/helpers/datatables.tt +++ b/share/templates/helpers/datatables.tt @@ -139,7 +139,7 @@ $(document).ready(function() { "bSort": true, "bInfo": true, "iDisplayLength": 5, - "sAjaxSource": "[% c.uri_for( c.controller.action_for('ajax') ) %]", + "sAjaxSource": "[% helper.ajax_uri %]", "aoColumns": [ [% FOREACH f IN helper.column_fields -%] { "sName": "[% f %]" }, @@ -148,16 +148,16 @@ $(document).ready(function() { return '' + '
' + [%- IF helper.has_edit != 0 %] - '' + + '' + ' Edit' + '' + [%- END %] - '' + + '' + ' Delete' + '' + [%- IF helper.extra_buttons.size > 0 %] [% FOR b IN helper.extra_buttons %] - '' + '[% b.0 %]' + '' + @@ -175,7 +175,7 @@ $(document).ready(function() { { "aTargets": [ 0 ], "mRender": function ( data, type, full ) { - return ''+data+''; } diff --git a/share/templates/reseller/list.tt b/share/templates/reseller/list.tt index e9a11838d4..7b2e3c8a4e 100644 --- a/share/templates/reseller/list.tt +++ b/share/templates/reseller/list.tt @@ -10,6 +10,8 @@ helper.create_flag = create_flag; helper.edit_object = reseller; helper.form_object = form; + helper.ajax_uri = c.uri_for( c.controller.action_for('ajax') ); + helper.base_uri = c.uri_for( c.controller.action_for("") ); PROCESS 'helpers/datatables.tt'; -%]