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)
agranig/1_0_subfix
Gerhard Jungwirth 12 years ago
parent 3df437082c
commit a0773b2591

@ -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<< <gjungwirth@sipwise.com> >>

@ -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:

@ -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' => (

@ -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: -%]

@ -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'],

@ -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';
-%]

@ -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';
-%]

@ -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';
-%]

@ -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 '' +
'<div class="sw_actions pull-right">' +
[%- IF helper.has_edit != 0 %]
'<a style="display:inline;line-height:16px;" class="btn btn-small btn-primary" href="[% c.uri_for( c.controller.action_for("") ) %]/' + full[0] + '/edit">' +
'<a style="display:inline;line-height:16px;" class="btn btn-small btn-primary" href="[% helper.base_uri %]/' + full[0] + '/edit">' +
'<i class="icon-edit" style="line-height:1em;margin-top:2px"></i> Edit' +
'</a>' +
[%- END %]
'<a style="display:inline;line-height:16px;margin-left:5px;" class="btn btn-small btn-secondary" href="[% c.uri_for( c.controller.action_for("") ) %]/' + full[0] + '/delete" data-confirm="Delete">' +
'<a style="display:inline;line-height:16px;margin-left:5px;" class="btn btn-small btn-secondary" href="[% helper.base_uri %]/' + full[0] + '/delete" data-confirm="Delete">' +
'<i class="icon-trash" style="line-height:1em;margin-top:2px"></i> Delete' +
'</a>' +
[%- IF helper.extra_buttons.size > 0 %]
[% FOR b IN helper.extra_buttons %]
'<a style="display:inline;line-height:16px;margin-left:5px;" class="btn btn-small btn-tertiary" href="[% c.uri_for( c.controller.action_for("") ) %]/' + full[0] + '/' +
'<a style="display:inline;line-height:16px;margin-left:5px;" class="btn btn-small btn-tertiary" href="[% helper.base_uri %]/' + full[0] + '/' +
'[% b.1 %]' + '">' +
'[% b.0 %]' +
'</a>' +
@ -175,7 +175,7 @@ $(document).ready(function() {
{
"aTargets": [ 0 ],
"mRender": function ( data, type, full ) {
return '<a href="[% c.uri_for( c.controller.action_for("") ) %]/'+
return '<a href="[% helper.base_uri %]/'+
full[0]+
'/preferences">'+data+'</a>';
}

@ -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';
-%]

Loading…
Cancel
Save