+sub _save_note {
+ $main::lxdebug->enter_sub();
+
+ my $self = shift;
+ my %params = @_;
+
+ my $form = $main::form;
+
+ Common::check_params(\%params, 'dbh');
+
+ if (!$form->{NOTE_subject}) {
+ $main::lxdebug->leave_sub();
+ return;
+ }
+
+ my $dbh = $params{dbh};
+
+ my %follow_up;
+ my %note = (
+ 'id' => $form->{NOTE_id},
+ 'subject' => $form->{NOTE_subject},
+ 'body' => $form->{NOTE_body},
+ 'trans_id' => $form->{id},
+ 'trans_module' => 'ct',
+ );
+
+ $note{id} = Notes->save(%note);
+
+ if ($form->{FU_date}) {
+ %follow_up = (
+ 'id' => $form->{FU_id},
+ 'note_id' => $note{id},
+ 'follow_up_date' => $form->{FU_date},
+ 'created_for_user' => $form->{FU_created_for_user},
+ 'done' => $form->{FU_done} ? 1 : 0,
+ 'subject' => $form->{NOTE_subject},
+ 'body' => $form->{NOTE_body},
+ 'LINKS' => [
+ {
+ 'trans_id' => $form->{id},
+ 'trans_type' => $form->{db} eq 'customer' ? 'customer' : 'vendor',
+ 'trans_info' => $form->{name},
+ },
+ ],
+ );
+
+ $follow_up{id} = FU->save(%follow_up);
+
+ } elsif ($form->{FU_id}) {
+ do_query($form, $dbh, qq|DELETE FROM follow_up_links WHERE follow_up_id = ?|, conv_i($form->{FU_id}));
+ do_query($form, $dbh, qq|DELETE FROM follow_ups WHERE id = ?|, conv_i($form->{FU_id}));
+ }
+
+ delete @{$form}{grep { /^NOTE_|^FU_/ } keys %{ $form }};
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _delete_selected_notes {
+ $main::lxdebug->enter_sub();
+
+ my $self = shift;
+ my %params = @_;
+
+ Common::check_params(\%params, 'dbh');
+
+ my $form = $main::form;
+ my $dbh = $params{dbh};
+
+ foreach my $i (1 .. $form->{NOTES_rowcount}) {
+ next unless ($form->{"NOTE_delete_$i"} && $form->{"NOTE_id_$i"});
+
+ Notes->delete('dbh' => $params{dbh},
+ 'id' => $form->{"NOTE_id_$i"});
+ }
+
+ $main::lxdebug->leave_sub();
+}
+
+sub delete_shipto {
+ $main::lxdebug->enter_sub();
+
+ my $self = shift;
+ my $shipto_id = shift;
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $dbh = $form->get_standard_dbh(\%myconfig);
+
+ do_query($form, $dbh, qq|UPDATE shipto SET trans_id = NULL WHERE shipto_id = ?|, $shipto_id);
+
+ $dbh->commit();
+
+ $main::lxdebug->leave_sub();
+}
+
+sub delete_shipto {
+ $main::lxdebug->enter_sub();
+
+ my $self = shift;
+ my $shipto_id = shift;
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $dbh = $form->get_standard_dbh(\%myconfig);
+
+ do_query($form, $dbh, qq|UPDATE contacts SET cp_cv_id = NULL WHERE cp_id = ?|, $shipto_id);
+
+ $dbh->commit();
+
+ $main::lxdebug->leave_sub();
+}
+
+sub get_bank_info {
+ $main::lxdebug->enter_sub();
+
+ my $self = shift;
+ my %params = @_;
+
+ Common::check_params(\%params, qw(vc id));
+
+ my $myconfig = \%main::myconfig;
+ my $form = $main::form;
+
+ my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig);
+
+ my $table = $params{vc} eq 'customer' ? 'customer' : 'vendor';
+ my @ids = ref $params{id} eq 'ARRAY' ? @{ $params{id} } : ($params{id});
+ my $placeholders = ('?') x scalar @ids;
+ my $query = qq|SELECT id, name, account_number, bank, bank_code, iban, bic
+ FROM ${table}
+ WHERE id IN (${placeholders})|;
+
+ my $result = selectall_hashref_query($form, $dbh, $query, map { conv_i($_) } @ids);
+
+ if (ref $params{id} eq 'ARRAY') {
+ $result = { map { $_->{id} => $_ } @{ $result } };
+ } else {
+ $result = $result->[0] || { 'id' => $params{id} };
+ }
+
+ $main::lxdebug->leave_sub();
+
+ return $result;
+}
+