Ansprechpartner löschbar machen.
authorSven Schöling <s.schoeling@linet-services.de>
Tue, 17 Jan 2012 10:35:08 +0000 (11:35 +0100)
committerSven Schöling <s.schoeling@linet-services.de>
Tue, 17 Jan 2012 10:35:08 +0000 (11:35 +0100)
Ansprechpartner können jetzt gelöscht werden. Ist der Ansprechpartner noch in
verwendung wird eine Nachricht an den User gegeben und der Ansprechpartner nur
auf ungültig gesetzt. Ungültige Ansprechpartner werden in den Belegmasken nicht
angezeigt, es sei denn der Beleg wird aus der Datenbank geholt und der
ungültige Ansprechpartner ist vorausgewählt. Beim ersten Erneuern bei dem ein
anderer Ansprechpartner ausgewählt ist, der ungültige nicht mehr zur Auswahl
gestellt.

Es gibt noch keinen Aufräummechanismus für unbenutzte Zombieansprechpartner in
der Datenbank.

Beim Testen in Bonn hatte ich massive Probleme mit einem Setup unter Ubuntu
10.04 mit Postgres 8.4.10, Perl 5.10.1, DBI 1.609, RDBO 0.785, RDB 0.758, RO
0.856. Kompilierung ist scheinbar ohne erkennbare Zusammenhänge unter CGI und
FCGI schon zur compile time abgestürzt.

Sollten diese Probleme nochmal auftauchen, bitte melden.

13 files changed:
SL/DB/Contact.pm
bin/mozilla/ct.pl
bin/mozilla/do.pl
bin/mozilla/ir.pl
bin/mozilla/is.pl
bin/mozilla/oe.pl
locale/de/all
templates/webpages/ct/_contact.html
templates/webpages/ct/form_header.html
templates/webpages/do/form_header.html
templates/webpages/ir/form_header.html
templates/webpages/is/form_header.html
templates/webpages/oe/form_header.html

index aa74bea..4b6c35e 100644 (file)
@@ -14,6 +14,27 @@ use SL::DB::Helper::CustomVariables (
 # Creates get_all, get_all_count, get_all_iterator, delete_all and update_all.
 __PACKAGE__->meta->make_manager_class;
 
+sub used {
+  my ($self) = @_;
+
+  return unless $self->cp_id;
+
+  require SL::DB::Order;
+  require SL::DB::Invoice;
+  require SL::DB::PurchaseInvoice;
+  require SL::DB::DeliveryOrder;
+
+  return SL::DB::Manager::Order->get_all_count(query => [ cp_id => $self->cp_id ])
+       + SL::DB::Manager::Invoice->get_all_count(query => [ cp_id => $self->cp_id ])
+       + SL::DB::Manager::PurchaseInvoice->get_all_count(query => [ cp_id => $self->cp_id ])
+       + SL::DB::Manager::DeliveryOrder->get_all_count(query => [ cp_id => $self->cp_id ]);
+}
+
+sub detach {
+  $_[0]->cp_cv_id(undef);
+  $_[0]->save;
+}
+
 sub full_name {
   my ($self) = @_;
   die 'not an accessor' if @_ > 1;
index de0a436..b47d8e2 100644 (file)
@@ -51,6 +51,7 @@ use SL::CT;
 use SL::CVar;
 use SL::DB::Business;
 use SL::DB::Default;
+use SL::Helper::Flash;
 use SL::ReportGenerator;
 
 require "bin/mozilla/common.pl";
@@ -730,23 +731,25 @@ sub delete_shipto {
 }
 
 sub delete_contact {
-  $main::lxdebug->enter_sub();
-
-  $main::auth->assert('customer_vendor_edit');
+  $::lxdebug->enter_sub;
+  $::auth->assert('customer_vendor_edit');
 
-  my $form     = $main::form;
-  my %myconfig = %main::myconfig;
+  CT->get_contact(\%::myconfig, $::form);
 
-  CT->get_contact(\%myconfig, \%$form);
+  my $contact = SL::DB::Manager::Contact->find_by(cp_id => $::form->{cp_id});
 
-  unless ($form->{cp_used}) {
-    CT->delete_contact($form->{cp_id});
-    @$form{ grep /^cp_/, keys %$form } = undef;
+  if ($contact->used) {
+    $contact->detach;
+    flash('info', $::locale->text('Contact is in use and was flagged invalid.'));
+  } else {
+    $contact->delete;
+    flash('info', $::locale->text('Contact deleted.'));
   }
+  delete $::form->{$_} for grep /^cp_/, keys %$::form;
 
   edit();
 
-  $main::lxdebug->leave_sub();
+  $::lxdebug->leave_sub;
 }
 
 sub ajax_autocomplete {
index 9d28bbb..39cba4a 100644 (file)
@@ -266,8 +266,7 @@ sub form_header {
           if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
 
   my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
-  $form->get_lists("contacts"       => "ALL_CONTACTS",
-                   "shipto"         => "ALL_SHIPTO",
+  $form->get_lists("shipto"         => "ALL_SHIPTO",
                    "projects"       => {
                      "key"          => "ALL_PROJECTS",
                      "all"          => 0,
@@ -280,6 +279,15 @@ sub form_header {
                    "departments"    => "ALL_DEPARTMENTS",
                    "business_types" => "ALL_BUSINESS_TYPES",
     );
+  $::form->{ALL_CONTACTS}          = SL::DB::Manager::Contact->get_all(query => [
+    or => [
+      cp_cv_id => $::form->{"$::form->{vc}_id"} * 1,
+      and      => [
+        cp_cv_id => undef,
+        cp_id    => $::form->{cp_id} * 1
+      ]
+    ]
+  ]);
 
   map { $_->{value} = "$_->{description}--$_->{id}" } @{ $form->{ALL_DEPARTMENTS} };
   map { $_->{value} = "$_->{name}--$_->{id}"        } @{ $form->{ALL_VC} };
index 25831b2..810e06a 100644 (file)
@@ -283,8 +283,7 @@ sub form_header {
   my @old_project_ids = ($form->{"globalproject_id"});
   map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
 
-  $form->get_lists("contacts"      => "ALL_CONTACTS",
-                   "shipto"        => "ALL_SHIPTO",
+  $form->get_lists("shipto"        => "ALL_SHIPTO",
                    "projects"      => { "key"    => "ALL_PROJECTS",
                                         "all"    => 0,
                                         "old_id" => \@old_project_ids },
@@ -295,9 +294,17 @@ sub form_header {
                    "departments"   => "all_departments",
                    "price_factors" => "ALL_PRICE_FACTORS");
 
+  $TMPL_VAR{ALL_CONTACTS}          = SL::DB::Manager::Contact->get_all(query => [
+    or => [
+      cp_cv_id => $::form->{"$::form->{vc}_id"} * 1,
+      and      => [
+        cp_cv_id => undef,
+        cp_id    => $::form->{cp_id} * 1
+      ]
+    ]
+  ]);
   $TMPL_VAR{sales_employee_labels} = sub { $_[0]->{name} || $_[0]->{login} };
 #  $TMPL_VAR{shipto_labels}         = sub { join "; ", grep { $_ } map { $_[0]->{"shipto${_}" } } qw(name department_1 street city) };
-  $TMPL_VAR{contact_labels}        = sub { join(', ', $_[0]->{"cp_name"}, $_[0]->{"cp_givenname"}) . ($_[0]->{cp_abteilung} ? " ($_[0]->{cp_abteilung})" : "") };
   $TMPL_VAR{department_labels}     = sub { "$_[0]->{description}--$_[0]->{id}" };
 
   # customer
index f438f1c..685e7b1 100644 (file)
@@ -300,8 +300,7 @@ sub form_header {
   my @old_project_ids = ($form->{"globalproject_id"});
   map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
 
-  $form->get_lists("contacts"      => "ALL_CONTACTS",
-                   "shipto"        => "ALL_SHIPTO",
+  $form->get_lists("shipto"        => "ALL_SHIPTO",
                    "projects"      => { "key"    => "ALL_PROJECTS",
                                         "all"    => 0,
                                         "old_id" => \@old_project_ids },
@@ -313,9 +312,17 @@ sub form_header {
                    "departments"   => "all_departments",
                    "price_factors" => "ALL_PRICE_FACTORS");
 
+  $TMPL_VAR{ALL_CONTACTS}          = SL::DB::Manager::Contact->get_all(query => [
+    or => [
+      cp_cv_id => $::form->{"$::form->{vc}_id"} * 1,
+      and      => [
+        cp_cv_id => undef,
+        cp_id    => $::form->{cp_id} * 1
+      ]
+    ]
+  ]);
   $TMPL_VAR{sales_employee_labels} = sub { $_[0]->{name} || $_[0]->{login} };
   $TMPL_VAR{shipto_labels}         = sub { join "; ", grep { $_ } map { $_[0]->{"shipto${_}" } } qw(name department_1 street city) };
-  $TMPL_VAR{contact_labels}        = sub { join(', ', $_[0]->{"cp_name"}, $_[0]->{"cp_givenname"}) . ($_[0]->{cp_abteilung} ? " ($_[0]->{cp_abteilung})" : "") };
   $TMPL_VAR{department_labels}     = sub { "$_[0]->{description}--$_[0]->{id}" };
 
   # customer
index aa6df6d..1123151 100644 (file)
@@ -327,8 +327,7 @@ sub form_header {
   my @old_project_ids = ($form->{"globalproject_id"}, grep { $_ } map { $form->{"project_id_$_"} } 1..$form->{"rowcount"});
 
   my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
-  $form->get_lists("contacts"      => "ALL_CONTACTS",
-                   "shipto"        => "ALL_SHIPTO",
+  $form->get_lists("shipto"        => "ALL_SHIPTO",
                    "projects"      => { "key"      => "ALL_PROJECTS",
                                         "all"      => 0,
                                         "old_id"   => \@old_project_ids },
@@ -343,9 +342,17 @@ sub form_header {
                    "price_factors" => "ALL_PRICE_FACTORS");
 
   # label subs
+  $TMPL_VAR{ALL_CONTACTS}          = SL::DB::Manager::Contact->get_all(query => [
+    or => [
+      cp_cv_id => $::form->{"$::form->{vc}_id"} * 1,
+      and      => [
+        cp_cv_id => undef,
+        cp_id    => $::form->{cp_id} * 1
+      ]
+    ]
+  ]);
   $TMPL_VAR{sales_employee_labels} = sub { $_[0]->{name} || $_[0]->{login} };
   $TMPL_VAR{shipto_labels}         = sub { join "; ", grep { $_ } map { $_[0]->{"shipto${_}" } } qw(name department_1 street city) };
-  $TMPL_VAR{contact_labels}        = sub { join(', ', $_[0]->{"cp_name"}, $_[0]->{"cp_givenname"}) . ($_[0]->{cp_abteilung} ? " ($_[0]->{cp_abteilung})" : "") };
   $TMPL_VAR{department_labels}     = sub { "$_[0]->{description}--$_[0]->{id}" };
 
   # vendor/customer
index 66b9e8f..2b737d4 100644 (file)
@@ -417,6 +417,8 @@ $self->{texts} = {
   'Confirmation'                => 'Auftragsbestätigung',
   'Contact'                     => 'Kontakt',
   'Contact Person'              => 'Ansprechpartner',
+  'Contact deleted.'            => 'Ansprechpartner gelöscht.',
+  'Contact is in use and was flagged invalid.' => 'Ansprechpartner ist noch in Verwendung, und wurde als ungültig markiert.',
   'Contact person (surname)'    => 'Ansprechpartner (Nachname)',
   'Contacts'                    => 'Ansprechpartner',
   'Continue'                    => 'Weiter',
index 8da17e9..995c260 100644 (file)
@@ -1,11 +1,11 @@
 [% USE L %][% USE HTML %][% USE T8 %][% USE LxERP %]
-    <table id="contact_table">
+    <table>
      <input type="hidden" name="cp_id" value="[% HTML.escape(cp_id) %]">
      <tr>
       <th align="left">[% 'Contacts' | $T8 %]</th>
       <td>
        [%- L.select_tag('cp_id', L.options_for_select(CONTACTS, default => cp_id, with_empty => 1, empty_title => LxERP.t8('New contact'), value => 'cp_id', title_sub => \contacts_label),
-                        onchange => "\$('#contact_table').load('ct.pl?action=get_contact&id=' + \$('#cvid').attr('value') + '&db=' + \$('#db').attr('value') + '&cp_id=' + \$('#cp_id').attr('value'))") %]
+                        onchange => "\$('#contacts').load('ct.pl?action=get_contact&id=' + \$('#cvid').attr('value') + '&db=' + \$('#db').attr('value') + '&cp_id=' + \$('#cp_id').attr('value'))") %]
       </td>
      </tr>
 
       <td><input name="bcc" size="40" value="[% HTML.escape(bcc) %]"></td>
      </tr>
     </table>
+
+    <input type="submit" id="delete_contact" name="action" value="[% 'Delete Contact' | $T8 %]" [% IF cp_used %]'disabled'[% END %]>
+
+    <br style="clear: left" />
index 9671cab..4d6ee5a 100644 (file)
 
    <div id="contacts" class="tabcontent">
     [% INCLUDE 'ct/_contact.html' %]
-
-    <input type="submit" id="delete_contact" name="action" value="[% 'Delete Contact' | $T8 %]" disabled>
-    <br style="clear: left" />
    </div>
 
    <div id="deliveries" class="tabcontent">
index b41ea72..3ed1be2 100644 (file)
           [%- HTML.escape(row.cp_name) %][%- IF row.cp_abteilung %] ([% HTML.escape(row.cp_abteilung) %])[% END -%]
           [%- END %]
           [%- ELSE %]
-          <select name="cp_id" class="fixed_width" >
-           <option></option>
-           [%- FOREACH row = ALL_CONTACTS %]
-           <option value="[% HTML.escape(row.cp_id) %]"[% IF cp_id == row.cp_id %] selected[% END %]>
-            [%- HTML.escape(row.cp_name) %][%- IF row.cp_abteilung %] ([% HTML.escape(row.cp_abteilung) %])[% END -%]
-           </option>
-           [%- END %]
-          </select>
+            [% L.select_tag('cp_id', L.options_for_select(ALL_CONTACTS, default=cp_id, value='cp_id', title='full_name_dep', with_empty=1), style='width: 250px') %]
           [%- END %]
          </td>
         </tr>
index d070b4d..697e3e5 100644 (file)
         <tr>
           <th align="right">[% 'Contact Person' | $T8 %]</th>
           <td>
-            [%- INCLUDE 'generic/multibox.html'
-                 name       = 'cp_id',
-                 style      = 'width: 250px',
-                 DATA       = ALL_CONTACTS,
-                 id_key     = 'cp_id',
-                 label_sub  = 'contact_labels',
-                 show_empty = 1 -%]
+            [% L.select_tag('cp_id', L.options_for_select(ALL_CONTACTS, default=cp_id, value='cp_id', title='full_name_dep', with_empty=1), style='width: 250px') %]
           </td>
         </tr>
 [%- END %]
index 34b340c..ca2b536 100644 (file)
@@ -55,7 +55,7 @@
         <tr>
           <th align="right">[% 'Contact Person' | $T8 %]</th>
           <td>
-            [% L.select_tag('cp_id', L.options_for_select(ALL_CONTACTS, default=cp_id, value='cp_id', title_sub=\contact_labels, with_empty=1), style='width: 250px') %]
+            [% L.select_tag('cp_id', L.options_for_select(ALL_CONTACTS, default=cp_id, value='cp_id', title='full_name_dep', with_empty=1), style='width: 250px') %]
           </td>
         </tr>
 [%- END %]
index 5ec0db5..3c17033 100644 (file)
@@ -58,7 +58,7 @@
                   <tr>
                     <th align="right">[% 'Contact Person' | $T8 %]</th>
                     <td>
-                      [% L.select_tag('cp_id', L.options_for_select(ALL_CONTACTS, default=cp_id, value='cp_id', title_sub=\contact_labels, with_empty=1), style='width: 250px') %]
+                      [% L.select_tag('cp_id', L.options_for_select(ALL_CONTACTS, default=cp_id, value='cp_id', title='full_name_dep', with_empty=1), style='width: 250px') %]
                     </td>
                   </tr>
 [%- END %]