]> wagnertech.de Git - mfinanz.git/commitdiff
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 aa74bea3dddcee3d50adceee8806802652dfe4cf..4b6c35e42e3c160b47790aed7cda9b36db491482 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;
 
 # 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;
 sub full_name {
   my ($self) = @_;
   die 'not an accessor' if @_ > 1;
index de0a436596f99bb3a4dda02adf73a3b4d49905ff..b47d8e2624ad26263daa3394100f0aabc5b12428 100644 (file)
@@ -51,6 +51,7 @@ use SL::CT;
 use SL::CVar;
 use SL::DB::Business;
 use SL::DB::Default;
 use SL::CVar;
 use SL::DB::Business;
 use SL::DB::Default;
+use SL::Helper::Flash;
 use SL::ReportGenerator;
 
 require "bin/mozilla/common.pl";
 use SL::ReportGenerator;
 
 require "bin/mozilla/common.pl";
@@ -730,23 +731,25 @@ sub delete_shipto {
 }
 
 sub delete_contact {
 }
 
 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();
 
 
   edit();
 
-  $main::lxdebug->leave_sub();
+  $::lxdebug->leave_sub;
 }
 
 sub ajax_autocomplete {
 }
 
 sub ajax_autocomplete {
index 9d28bbb0d8c4a6602b578ad5f4cca7811c2dac49..39cba4a2b5ef87e7d1f5f7c4e0421341472628c9 100644 (file)
@@ -266,8 +266,7 @@ sub form_header {
           if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
 
   my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
           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,
                    "projects"       => {
                      "key"          => "ALL_PROJECTS",
                      "all"          => 0,
@@ -280,6 +279,15 @@ sub form_header {
                    "departments"    => "ALL_DEPARTMENTS",
                    "business_types" => "ALL_BUSINESS_TYPES",
     );
                    "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} };
 
   map { $_->{value} = "$_->{description}--$_->{id}" } @{ $form->{ALL_DEPARTMENTS} };
   map { $_->{value} = "$_->{name}--$_->{id}"        } @{ $form->{ALL_VC} };
index 25831b2eafd03097f6b8bea670ff9f32b81515c1..810e06a4783a0b1943df243a51b1df26f3ecf3cb 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"};
 
   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 },
                    "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");
 
                    "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{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
   $TMPL_VAR{department_labels}     = sub { "$_[0]->{description}--$_[0]->{id}" };
 
   # customer
index f438f1c9bdbaf5ca593bd4da814526351d525eb5..685e7b1828e374fcb444fab8176bea290b73c156 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"};
 
   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 },
                    "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");
 
                    "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{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
   $TMPL_VAR{department_labels}     = sub { "$_[0]->{description}--$_[0]->{id}" };
 
   # customer
index aa6df6d615f3a909f62a764e982ed4969463ddac..11231515d992e7581fe8699988f082e47232fa34 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";
   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 },
                    "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
                    "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{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
   $TMPL_VAR{department_labels}     = sub { "$_[0]->{description}--$_[0]->{id}" };
 
   # vendor/customer
index 66b9e8f6dcdc7d5d02ceb4ac952719c0c021b5c1..2b737d41d291becb87a951a8ea09b436c8a3039b 100644 (file)
@@ -417,6 +417,8 @@ $self->{texts} = {
   'Confirmation'                => 'Auftragsbestätigung',
   'Contact'                     => 'Kontakt',
   'Contact Person'              => 'Ansprechpartner',
   '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',
   'Contact person (surname)'    => 'Ansprechpartner (Nachname)',
   'Contacts'                    => 'Ansprechpartner',
   'Continue'                    => 'Weiter',
index 8da17e9cbdd550231695fcefd0ae3fb88de1953b..995c260e962bb3ff03e271d14b75918cda28e69a 100644 (file)
@@ -1,11 +1,11 @@
 [% USE L %][% USE HTML %][% USE T8 %][% USE LxERP %]
 [% 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),
      <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>
      </tr>
 
       <td><input name="bcc" size="40" value="[% HTML.escape(bcc) %]"></td>
      </tr>
     </table>
       <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 9671cab24ba6708d351bf4f85a5bcebb9e0205b7..4d6ee5a29875a3dd53ac01af8b65bed0d6323bd5 100644 (file)
 
    <div id="contacts" class="tabcontent">
     [% INCLUDE 'ct/_contact.html' %]
 
    <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">
    </div>
 
    <div id="deliveries" class="tabcontent">
index b41ea72d452b21eb08d8309546ede410e815f7fd..3ed1be2304de6c271406e9192ec27630cd941be7 100644 (file)
           [%- HTML.escape(row.cp_name) %][%- IF row.cp_abteilung %] ([% HTML.escape(row.cp_abteilung) %])[% END -%]
           [%- END %]
           [%- ELSE %]
           [%- 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>
           [%- END %]
          </td>
         </tr>
index d070b4d7411190adc1f2f8daa6b9c76365464472..697e3e54f0705d6b11ce1bb7442c402899d47a7e 100644 (file)
         <tr>
           <th align="right">[% 'Contact Person' | $T8 %]</th>
           <td>
         <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 %]
           </td>
         </tr>
 [%- END %]
index 34b340cc279230aac8b4895ba5b44bf9f31c747d..ca2b5364d2df21f3dbd789f40c558530cb4f2f16 100644 (file)
@@ -55,7 +55,7 @@
         <tr>
           <th align="right">[% 'Contact Person' | $T8 %]</th>
           <td>
         <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 %]
           </td>
         </tr>
 [%- END %]
index 5ec0db5ca8990c5011f8c6a33d06a0f28c613d2e..3c1703380f328c014cac6b3080aa0744201d18f6 100644 (file)
@@ -58,7 +58,7 @@
                   <tr>
                     <th align="right">[% 'Contact Person' | $T8 %]</th>
                     <td>
                   <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 %]
                     </td>
                   </tr>
 [%- END %]