From 0aa294a49c13a756e43fddb3ae294666a8d8bfca Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 11 Oct 2012 14:07:29 +0200 Subject: [PATCH] =?utf8?q?Beim=20Anlegen=20von=20Kunden/Lieferanten=20CVar?= =?utf8?q?s=20f=C3=BCr=20Ansprechpersonen=20speichern?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fixt #2016. --- SL/CT.pm | 115 +++++++++++++++---------------------------------------- 1 file changed, 30 insertions(+), 85 deletions(-) diff --git a/SL/CT.pm b/SL/CT.pm index 0019e0601..de10623f2 100644 --- a/SL/CT.pm +++ b/SL/CT.pm @@ -368,21 +368,7 @@ sub save_customer { ); do_query( $form, $dbh, $query, @values ); - $query = undef; - my @columns = qw(cp_title cp_givenname cp_name cp_email cp_phone1 cp_phone2 cp_abteilung cp_fax - cp_mobile1 cp_mobile2 cp_satphone cp_satfax cp_project cp_privatphone cp_privatemail cp_birthday cp_gender - cp_street cp_zipcode cp_city); - @values = map { $_ eq 'cp_gender' ? ($form->{$_} eq 'f' ? 'f' : 'm') : $form->{$_} } @columns; - - if ( $form->{cp_id} ) { - $query = qq|UPDATE contacts SET | . join(', ', map { "${_} = ?" } @columns) . qq| WHERE cp_id = ?|; - push @values, $form->{cp_id}; - - } elsif ( $form->{cp_name} || $form->{cp_givenname} ) { - $query = qq|INSERT INTO contacts (| . join(', ', 'cp_cv_id', @columns) . qq|) VALUES (?, | . join(', ', ('?') x scalar(@columns)) . qq|)|; - unshift @values, $form->{id}; - } - do_query( $form, $dbh, $query, @values ) if ($query); + $form->{cp_id} = $self->_save_contact($form, $dbh); # add shipto $form->add_shipto( $dbh, $form->{id}, "CT" ); @@ -530,76 +516,7 @@ sub save_vendor { ); do_query($form, $dbh, $query, @values); - $query = undef; - if ( $form->{cp_id} ) { - $query = qq|UPDATE contacts SET | . - qq|cp_title = ?, | . - qq|cp_givenname = ?, | . - qq|cp_name = ?, | . - qq|cp_email = ?, | . - qq|cp_phone1 = ?, | . - qq|cp_phone2 = ?, | . - qq|cp_abteilung = ?, | . - qq|cp_fax = ?, | . - qq|cp_mobile1 = ?, | . - qq|cp_mobile2 = ?, | . - qq|cp_satphone = ?, | . - qq|cp_satfax = ?, | . - qq|cp_project = ?, | . - qq|cp_privatphone = ?, | . - qq|cp_privatemail = ?, | . - qq|cp_birthday = ?, | . - qq|cp_gender = ? | . - qq|WHERE cp_id = ?|; - @values = ( - $form->{cp_title}, - $form->{cp_givenname}, - $form->{cp_name}, - $form->{cp_email}, - $form->{cp_phone1}, - $form->{cp_phone2}, - $form->{cp_abteilung}, - $form->{cp_fax}, - $form->{cp_mobile1}, - $form->{cp_mobile2}, - $form->{cp_satphone}, - $form->{cp_satfax}, - $form->{cp_project}, - $form->{cp_privatphone}, - $form->{cp_privatemail}, - $form->{cp_birthday}, - $form->{cp_gender} eq 'f' ? 'f' : 'm', - $form->{cp_id} - ); - } elsif ( $form->{cp_name} || $form->{cp_givenname} ) { - $query = - qq|INSERT INTO contacts ( cp_cv_id, cp_title, cp_givenname, | . - qq| cp_name, cp_email, cp_phone1, cp_phone2, cp_abteilung, cp_fax, cp_mobile1, | . - qq| cp_mobile2, cp_satphone, cp_satfax, cp_project, cp_privatphone, cp_privatemail, | . - qq| cp_birthday, cp_gender) | . - qq|VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|; - @values = ( - $form->{id}, - $form->{cp_title}, - $form->{cp_givenname}, - $form->{cp_name}, - $form->{cp_email}, - $form->{cp_phone1}, - $form->{cp_phone2}, - $form->{cp_abteilung}, - $form->{cp_fax}, - $form->{cp_mobile1}, - $form->{cp_mobile2}, - $form->{cp_satphone}, - $form->{cp_satfax}, - $form->{cp_project}, - $form->{cp_privatphone}, - $form->{cp_privatemail}, - $form->{cp_birthday}, - $form->{cp_gender} - ); - } - do_query($form, $dbh, $query, @values) if ($query); + $form->{cp_id} = $self->_save_contact($form, $dbh); # add shipto $form->add_shipto( $dbh, $form->{id}, "CT" ); @@ -627,6 +544,34 @@ sub save_vendor { return $rc; } +sub _save_contact { + my ($self, $form, $dbh) = @_; + + return undef unless $form->{cp_id} || $form->{cp_name} || $form->{cp_givenname}; + + my @columns = qw(cp_title cp_givenname cp_name cp_email cp_phone1 cp_phone2 cp_abteilung cp_fax + cp_mobile1 cp_mobile2 cp_satphone cp_satfax cp_project cp_privatphone cp_privatemail cp_birthday cp_gender + cp_street cp_zipcode cp_city); + my @values = map { $_ eq 'cp_gender' ? ($form->{$_} eq 'f' ? 'f' : 'm') : $form->{$_} } @columns; + + my ($query, $cp_id); + if ($form->{cp_id}) { + $query = qq|UPDATE contacts SET | . join(', ', map { "${_} = ?" } @columns) . qq| WHERE cp_id = ?|; + push @values, $form->{cp_id}; + $cp_id = $form->{cp_id}; + + } else { + ($cp_id) = selectrow_query($form, $dbh, qq|SELECT nextval('id')|); + + $query = qq|INSERT INTO contacts (| . join(', ', @columns, 'cp_cv_id', 'cp_id') . qq|) VALUES (| . join(', ', ('?') x (2 + scalar @columns)) . qq|)|; + push @values, $form->{id}, $cp_id; + } + + do_query($form, $dbh, $query, @values); + + return $cp_id; +} + sub delete { $main::lxdebug->enter_sub(); -- 2.20.1