diff --git a/lib/admin/Controller/customer.pm b/lib/admin/Controller/customer.pm index 4104ea7..bf67dbd 100644 --- a/lib/admin/Controller/customer.pm +++ b/lib/admin/Controller/customer.pm @@ -93,28 +93,34 @@ sub detail : Local { my ( $self, $c ) = @_; $c->stash->{template} = 'tt/customer_detail.tt'; - my $customer_id = $c->request->params->{customer_id}; - return unless $c->model('Provisioning')->call_prov( $c, 'billing', 'get_customer', - { id => $customer_id }, - \$c->session->{customer} - ); - my $contracts; - return unless $c->model('Provisioning')->call_prov( $c, 'billing', 'get_customer_contracts', - { id => $customer_id }, - \$contracts - ); - $c->session->{customer}{contracts} = $$contracts{result}; - my $orders; - return unless $c->model('Provisioning')->call_prov( $c, 'billing', 'get_customer_orders', - { id => $customer_id }, - \$orders - ); - $c->session->{customer}{orders} = $$orders{result}; + unless($c->request->params->{new_customer}) { + my $customer_id = $c->request->params->{customer_id}; + return unless $c->model('Provisioning')->call_prov( $c, 'billing', 'get_customer', + { id => $customer_id }, + \$c->session->{customer} + ); + my $contracts; + return unless $c->model('Provisioning')->call_prov( $c, 'billing', 'get_customer_contracts', + { id => $customer_id }, + \$contracts + ); + $c->session->{customer}{contracts} = $$contracts{result}; + my $orders; + return unless $c->model('Provisioning')->call_prov( $c, 'billing', 'get_customer_orders', + { id => $customer_id }, + \$orders + ); + $c->session->{customer}{orders} = $$orders{result}; - $c->stash->{customer} = $c->session->{customer}; + $c->stash->{customer} = $c->session->{customer}; + } if(ref $c->session->{restore_customer_input} eq 'HASH') { - $c->stash->{customer} = $c->session->{restore_customer_input}; + if(ref $c->stash->{customer} eq 'HASH') { + $c->stash->{customer} = { %{$c->stash->{customer}}, %{$c->session->{restore_customer_input}} }; + } else { + $c->stash->{customer} = $c->session->{restore_customer_input}; + } delete $c->session->{restore_customer_input}; } if(ref $c->session->{restore_contact_input} eq 'HASH') { @@ -131,35 +137,76 @@ sub detail : Local { } $c->stash->{show_pass} = $c->request->params->{show_pass}; -# there's currently nothing to edit -# $c->stash->{edit_customer} = $c->request->params->{edit_customer}; - $c->stash->{edit_contact} = $c->request->params->{edit_contact}; + $c->stash->{edit_customer} = $c->request->params->{new_customer} || $c->request->params->{edit_customer}; + $c->stash->{edit_contact} = $c->request->params->{new_customer} || $c->request->params->{edit_contact}; $c->stash->{edit_commercial} = $c->request->params->{edit_commercial}; $c->stash->{edit_technical} = $c->request->params->{edit_technical}; + $c->stash->{new_customer} = $c->request->params->{new_customer}; + return 1; } =head2 create_customer -Creates a new customer. Not yet implemented. +Creates a new customer. =cut sub create_customer : Local { my ( $self, $c ) = @_; - my $customer_id; - if($c->model('Provisioning')->call_prov( $c, 'billing', 'create_customer', - { - }, - \$customer_id)) + my (%settings, %messages); + + if(length $c->request->params->{shopuser}) { + $settings{shopuser} = $c->request->params->{shopuser}; + my $checkresult; + return unless $c->model('Provisioning')->call_prov( $c, 'voip', 'check_username', + $settings{shopuser}, \$checkresult + ); + $messages{username} = 'Client.Syntax.MalformedUsername' unless $checkresult; + } elsif(length $c->request->params->{shoppass}) { + $messages{username} = 'Client.Syntax.MissingUsername'; + } + if(length $c->request->params->{shoppass}) { + $settings{shoppass} = $c->request->params->{shoppass}; + $messages{password} = 'Client.Voip.PassLength' unless length $settings{shoppass} >= 6; + } elsif($settings{shopuser}) { + $messages{password} = 'Client.Voip.PassLength'; + } + + for(qw(gender firstname lastname comregnum company street + postcode city phonenumber mobilenumber email newsletter)) { - $c->response->redirect("/customer/detail?customer_id=$customer_id"); - return; + if(defined $c->request->params->{$_} and length $c->request->params->{$_}) { + $settings{contact}{$_} = $c->request->params->{$_}; + } } - $c->response->redirect("/customer"); + $messages{conterr} = 'Client.Billing.ContactIncomplete' + unless exists $settings{contact} + and ( exists $settings{contact}{firstname} + or exists $settings{contact}{lastname} + or exists $settings{contact}{company}); + + unless(keys %messages) { + my $customer_id; + if($c->model('Provisioning')->call_prov( $c, 'billing', 'create_customer', + { data => \%settings }, + \$customer_id)) + { + $c->session->{messages}{newmsg} = 'Server.Voip.SavedSettings'; + $c->response->redirect("/customer/detail?customer_id=$customer_id"); + return; + } + } + + $c->session->{messages} = \%messages; + $c->session->{restore_customer_input} = \%settings; + $c->session->{restore_customer_input}{edit_shoppass} = $settings{shoppass}; + $c->session->{restore_contact_input} = $settings{contact}; + + $c->response->redirect("/customer/detail?new_customer=1"); return; } @@ -177,15 +224,20 @@ sub update_customer : Local { my $customer_id = $c->request->params->{customer_id}; - if(defined $c->request->params->{shopuser} and length $c->request->params->{shopuser}) { + if(length $c->request->params->{shopuser}) { $settings{shopuser} = $c->request->params->{shopuser}; my $checkresult; return unless $c->model('Provisioning')->call_prov( $c, 'voip', 'check_username', $settings{shopuser}, \$checkresult ); $messages{username} = 'Client.Syntax.MalformedUsername' unless $checkresult; + } elsif(length $c->request->params->{shoppass}) { + $messages{username} = 'Client.Syntax.MissingUsername'; + } else { + $settings{shopuser} = undef; + $settings{shoppass} = undef; } - if(defined $c->request->params->{shoppass} and length $c->request->params->{shoppass}) { + if(length $c->request->params->{shoppass}) { $settings{shoppass} = $c->request->params->{shoppass}; $messages{password} = 'Client.Voip.PassLength' unless length $settings{shoppass} >= 6; } @@ -206,6 +258,7 @@ sub update_customer : Local { $c->session->{messages} = \%messages; $c->session->{restore_customer_input} = \%settings; + $c->session->{restore_customer_input}{edit_shoppass} = $settings{shoppass}; $c->response->redirect("/customer/detail?customer_id=$customer_id&edit_customer=1"); return; } @@ -278,60 +331,14 @@ sub update_contact : Local { my $ctype = $c->request->params->{ctype}; - if(defined $c->request->params->{gender} and length $c->request->params->{gender}) { - $settings{gender} = $c->request->params->{gender}; - } else { - $settings{gender} = undef; - } - if(defined $c->request->params->{firstname} and length $c->request->params->{firstname}) { - $settings{firstname} = $c->request->params->{firstname}; - } else { - $settings{firstname} = undef; - } - if(defined $c->request->params->{lastname} and length $c->request->params->{lastname}) { - $settings{lastname} = $c->request->params->{lastname}; - } else { - $settings{lastname} = undef; - } - if(defined $c->request->params->{comregnum} and length $c->request->params->{comregnum}) { - $settings{comregnum} = $c->request->params->{comregnum}; - } else { - $settings{comregnum} = undef; - } - if(defined $c->request->params->{company} and length $c->request->params->{company}) { - $settings{company} = $c->request->params->{company}; - } else { - $settings{company} = undef; - } - if(defined $c->request->params->{street} and length $c->request->params->{street}) { - $settings{street} = $c->request->params->{street}; - } else { - $settings{street} = undef; - } - if(defined $c->request->params->{postcode} and length $c->request->params->{postcode}) { - $settings{postcode} = $c->request->params->{postcode}; - } else { - $settings{postcode} = undef; - } - if(defined $c->request->params->{phonenumber} and length $c->request->params->{phonenumber}) { - $settings{phonenumber} = $c->request->params->{phonenumber}; - } else { - $settings{phonenumber} = undef; - } - if(defined $c->request->params->{mobilenumber} and length $c->request->params->{mobilenumber}) { - $settings{mobilenumber} = $c->request->params->{mobilenumber}; - } else { - $settings{mobilenumber} = undef; - } - if(defined $c->request->params->{email} and length $c->request->params->{email}) { - $settings{email} = $c->request->params->{email}; - } else { - $settings{email} = undef; - } - if(defined $c->request->params->{newsletter} and $c->request->params->{newsletter}) { - $settings{newsletter} = 1; - } else { - $settings{newsletter} = 0; + for(qw(gender firstname lastname comregnum company street + postcode city phonenumber mobilenumber email newsletter)) + { + if(defined $c->request->params->{$_} and length $c->request->params->{$_}) { + $settings{$_} = $c->request->params->{$_}; + } else { + $settings{$_} = undef; + } } unless(keys %messages) { diff --git a/root/css/admin.css b/root/css/admin.css index 6775d8c..315c8cd 100644 --- a/root/css/admin.css +++ b/root/css/admin.css @@ -93,6 +93,7 @@ h3 { #contentplace .tdkey { font-weight: bold; white-space: nowrap; + vertical-align: top; } #contentplace .table_header { @@ -211,7 +212,7 @@ h3 { /* decrease input text fields for cc/ac */ .ishort { - width: 40px; + width: 50px; } /* increase spacing between password and show/hide href */ diff --git a/root/tt/customer.tt b/root/tt/customer.tt index 0be93c0..a99d314 100644 --- a/root/tt/customer.tt +++ b/root/tt/customer.tt @@ -15,14 +15,16 @@ [% IF messages.accsearcherr %]
[% messages.accsearcherr %]
[% END %] - + + [% UNLESS Catalyst.session.admin.read_only %] +

Create new customer

+
+
+ +
+
+ [% END %] + [% IF customer_list %]

Customers

diff --git a/root/tt/customer_detail.tt b/root/tt/customer_detail.tt index 1105fcc..bfaf0d6 100644 --- a/root/tt/customer_detail.tt +++ b/root/tt/customer_detail.tt @@ -1,68 +1,83 @@ -

Customer - - #[% customer.id %] -

+ [% IF new_customer %] +

New Customer

+ [% ELSE %] +

Customer + + #[% customer.id %] +

+ [% END %] - [% UNLESS Catalyst.session.admin.read_only %] + [% IF messages.newmsg %]
[% messages.newmsg %]
[% END %] + [% IF messages.newerr %]
[% messages.newerr %]
[% END %] + + [% UNLESS Catalyst.session.admin.read_only || new_customer %]
- + [% ELSE %] delete + [% END %]
[% END %] -
- [% IF messages.custmsg %]
[% messages.custmsg %]
[% END %] - [% IF messages.custerr %]
[% messages.custerr %]
[% END %] -
- - - - - - - - - - + + + +
CustomerID:[% customer.id %]
shop user: - -
shop password: - [% IF edit_customer %] - - [% ELSE %] - Hide + [% IF new_customer %] + + [% ELSE %] + + [% END %] + +
+ [% IF messages.custmsg %]
[% messages.custmsg %]
[% END %] + [% IF messages.custerr %]
[% messages.custerr %]
[% END %] + + + + + + + + + + - - - -
CustomerID:[% customer.id %]
shop username: + + [% IF messages.username %]
[% messages.username %]
[% END %] +
shop password: + [% IF edit_customer %] + [% ELSE %] - [% IF customer.shoppass %] - value="********" /> - [% IF Catalyst.session.admin.show_passwords %] - Show - [% END %] + Hide [% ELSE %] - value="" /> + [% IF customer.shoppass %] + value="********" /> + [% IF Catalyst.session.admin.show_passwords %] + Show + [% END %] + [% ELSE %] + value="" /> + [% END %] [% END %] [% END %] - [% END %] -
created:[% customer.create_timestamp %]
modified:[% customer.modify_timestamp %]
- [% IF edit_customer %] - - [% END %] - -
+ [% IF messages.password %]
[% messages.password %]
[% END %] +
created:[% customer.create_timestamp %]
modified:[% customer.modify_timestamp %]
+ [% IF edit_customer && ! new_customer %] + + [% END %] +
+ [% UNLESS new_customer %] + + [% END %]

Contact

- [% UNLESS Catalyst.session.admin.read_only %] + [% UNLESS Catalyst.session.admin.read_only || new_customer %]
edit [% IF edit_contact %] @@ -71,98 +86,119 @@
[% END %] -
- [% IF messages.contmsg %]
[% messages.contmsg %]
[% END %] - [% IF messages.conterr %]
[% messages.conterr %]
[% END %] -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
name: - - - -
comm. register num.: - -
company: - -
street: - -
postcode / city: - - -
phonenumber: - -
mobilenumber: - -
email: - -
newsletter: - -
created: [% customer.contact.create_timestamp %]
modified: [% customer.contact.modify_timestamp %]
- [% IF edit_contact %] - - [% END %] -
-
+ [% UNLESS new_customer %] +
+ [% END %] + +
+ [% IF messages.contmsg %]
[% messages.contmsg %]
[% END %] + [% IF messages.conterr %]
[% messages.conterr %]
[% END %] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
gender: + +
firstname: + +
lastname: + +
comm. register num.: + +
company: + +
street: + +
postcode / city: + + +
phonenumber: + +
mobilenumber: + +
email: + +
newsletter: + +
created: [% customer.contact.create_timestamp %]
modified: [% customer.contact.modify_timestamp %]
+ [% IF edit_contact && ! new_customer %] + + [% END %] +
+ + [% IF new_customer %] + + [% END %] + +
+ + [% UNLESS new_customer %]

Commercial Contact

@@ -183,14 +219,24 @@ - + + + + + + + + + @@ -257,14 +303,24 @@
name:gender: +
firstname: +
lastname:
- + + + + + + + + + @@ -435,3 +491,5 @@ [% END %] + [% END %] +
name:gender: +
firstname: +
lastname: