+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 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 = join ", ", ('?') 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;
+}
+
+sub parse_excel_file {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+ my $locale = $main::locale;
+
+ $form->{formname} = 'sales_quotation';
+ $form->{type} = 'sales_quotation';
+ $form->{format} = 'excel';
+ $form->{media} = 'screen';
+ $form->{quonumber} = 1;
+
+
+ # $form->{"notes"} will be overridden by the customer's/vendor's "notes" field. So save it here.
+ $form->{ $form->{"formname"} . "notes" } = $form->{"notes"};
+
+ my $inv = "quo";
+ my $due = "req";
+ $form->{"${inv}date"} = $form->{transdate};
+ $form->{label} = $locale->text('Quotation');
+ my $numberfld = "sqnumber";
+ my $order = 1;
+
+ # assign number
+ $form->{what_done} = $form->{formname};
+
+ map({ delete($form->{$_}); } grep(/^cp_/, keys(%{ $form })));
+
+ my $output_dateformat = $myconfig->{"dateformat"};
+ my $output_numberformat = $myconfig->{"numberformat"};
+ my $output_longdates = 1;
+
+ # map login user variables
+ map { $form->{"login_$_"} = $myconfig->{$_} } ("name", "email", "fax", "tel", "company");
+
+ # format item dates
+ for my $field (qw(transdate_oe deliverydate_oe)) {
+ map {
+ $form->{$field}[$_] = $locale->date($myconfig, $form->{$field}[$_], 1);
+ } 0 .. $#{ $form->{$field} };
+ }
+
+ if ($form->{shipto_id}) {
+ $form->get_shipto($myconfig);
+ }
+
+ $form->{notes} =~ s/^\s+//g;
+
+ $form->{templates} = $myconfig->{templates};
+
+ delete $form->{printer_command};
+
+ $form->get_employee_info($myconfig);
+
+ my ($cvar_date_fields, $cvar_number_fields) = CVar->get_field_format_list('module' => 'CT', 'prefix' => 'vc_');
+
+ if (scalar @{ $cvar_date_fields }) {
+ format_dates($output_dateformat, $output_longdates, @{ $cvar_date_fields });
+ }
+
+ while (my ($precision, $field_list) = each %{ $cvar_number_fields }) {
+ reformat_numbers($output_numberformat, $precision, @{ $field_list });
+ }
+
+ $form->{excel} = 1;
+ my $extension = 'xls';
+
+ $form->{IN} = "$form->{formname}.${extension}";
+
+ delete $form->{OUT};
+
+ $form->parse_template($myconfig, $main::userspath);
+
+ $main::lxdebug->leave_sub();
+}
+