- $form->get_lists("contacts" => "ALL_CONTACTS",
- "shipto" => "ALL_SHIPTO",
- "projects" => { "key" => "ALL_PROJECTS",
- "all" => 0,
- "old_id" => \@old_project_ids },
- "employees" => "ALL_SALESMEN",
- "taxzones" => "ALL_TAXZONES",
- "payments" => "ALL_PAYMENTS",
- "currencies" => "ALL_CURRENCIES",
- $vc => "ALL_" . uc($vc));
-
- my %labels;
- my @values = (undef);
- foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
- push(@values, $item->{"cp_id"});
- $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
- ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
- }
- my $contact =
- NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
- '-labels' => \%labels, '-default' => $form->{"cp_id"}));
-
- %labels = ();
- @values = ();
-
- foreach my $item (@{ $form->{($form->{vc} eq "customer" ? "ALL_CUSTOMERS" : "ALL_VENDORS")}}) {
- push(@values, $item->{name}.qq|--|.$item->{"id"});
- $labels{$item->{"id"}} = $item->{name}.qq|--|.$item->{"id"};
- }
-
- $vc = qq|
- <input type="hidden" name="$form->{vc}_id" value="| . H($form->{"$form->{vc}_id"}) . qq|">
- <input type="hidden" name="old$form->{vc}" value="| . H($form->{"old$form->{vc}"}) . qq|">
- <th align="right">| . $locale->text(ucfirst($form->{vc})) . qq|</th>
- <td>| .
- (($myconfig{vclimit} <= scalar(@values))
- ? qq|<input type="text" value="| . H($form->{"old$form->{vc}"}) . qq|" name="$form->{vc}">|
- : (NTI($cgi->popup_menu('-name' => "$form->{vc}", '-default' => $form->{"old$form->{vc}"},
- '-onChange' => 'document.getElementById(\'update_button\').click();',
- '-values' => \@values, '-labels' => \%labels)))) . qq|
- </td><input type=hidden name="select$form->{vc}" value="| .
- Q($form->{"select$form->{vc}"}) . qq|">|;
-
- %labels = ();
- @values = ("");
- foreach my $item (@{ $form->{"ALL_PAYMENTS"} }) {
- push(@values, $item->{"id"});
- $labels{$item->{"id"}} = $item->{"description"};
- }
-
- $payments = qq|
- <th align="right">| . $locale->text('Payment Terms') . qq|</th>
- <td>| .
- NTI($cgi->popup_menu('-name' => 'payment_id', '-values' => \@values,
- '-labels' => \%labels, '-default' => $form->{payment_id}))
- . qq|</td>|;
-
- %labels = ();
- @values = ("");
- foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
- push(@values, $item->{"shipto_id"});
- $labels{$item->{"shipto_id"}} =
- $item->{"shiptoname"} . " " . $item->{"shiptodepartment_1"};
- }
-
- my $shipto = qq|
- <th align=right>| . $locale->text('Shipping Address') . qq|</th>
- <td>| .
- NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values,
- '-labels' => \%labels, '-default' => $form->{"shipto_id"}))
- . qq|</td>|;
-
- %labels = ();
- @values = ("");
- foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
- push(@values, $item->{"id"});
- $labels{$item->{"id"}} = $item->{"projectnumber"};
- }
- my $globalprojectnumber =
- NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
- '-labels' => \%labels,
- '-default' => $form->{"globalproject_id"}));
-
- $salesman = "";
- if ($form->{type} =~ /^sales_/) {
- %labels = ();
- @values = ("");
- foreach my $item (@{ $form->{ALL_SALESMEN} }) {
- push(@values, $item->{id});
- $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
- }
-
- $salesman =
- qq|<tr>
- <th align="right">| . $locale->text('Salesman') . qq|</th>
- <td>| .
- NTI($cgi->popup_menu('-name' => 'salesman_id', '-default' => $form->{salesman_id},
- '-values' => \@values, '-labels' => \%labels))
- . qq|</td>
- </tr>|;
- }
-
- %labels = ();
- @values = ();
- foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
- push(@values, $item->{"id"});
- $labels{$item->{"id"}} = $item->{"name"};
- }
-
- my $employees = qq|
- <tr>
- <th align="right">| . $locale->text('Employee') . qq|</th>
- <td>| .
- NTI($cgi->popup_menu('-name' => 'employee', '-default' => $form->{"employee"},
- '-values' => \@values, '-labels' => \%labels)) . qq|
- </td>
- </tr>|;
-
- %labels = ();
- @values = ();
- foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
- push(@values, $item->{"id"});
- $labels{$item->{"id"}} = $item->{"description"};
- }
-
- $taxzone = qq|
- <tr>
- <th align="right">| . $locale->text('Steuersatz') . qq|</th>
- <td>| .
- NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
- '-values' => \@values, '-labels' => \%labels)) . qq|
- </td>
- </tr>|;
-
- %labels = ();
- @values = ();
- my $i = 0;
- foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
- push(@values, $item);
- $labels{$item} = $item;
- }
-
- $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
- my $currencies = qq|
- <tr>
- <th align="right">| . $locale->text('Currency') . qq|</th>
- <td>| .
- NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
- '-values' => \@values, '-labels' => \%labels)) . qq|
- </td>
- </tr>|;
-
-
- $form->{exchangerate} =
- $form->format_amount(\%myconfig, $form->{exchangerate});
-
- if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
- $creditwarning = 1;
- } else {
- $creditwarning = 0;
- }
-
- $form->{creditlimit} =
- $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
- $form->{creditremaining} =
- $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
+ $form->get_lists("contacts" => "ALL_CONTACTS",
+ "shipto" => "ALL_SHIPTO",
+ "projects" => { "key" => "ALL_PROJECTS",
+ "all" => 0,
+ "old_id" => \@old_project_ids },
+ "employees" => "ALL_EMPLOYEES",
+ "salesmen" => "ALL_SALESMEN",
+ "taxzones" => "ALL_TAXZONES",
+ "payments" => "ALL_PAYMENTS",
+ "currencies" => "ALL_CURRENCIES",
+ "departments" => "ALL_DEPARTMENTS",
+ $vc => { key => "ALL_" . uc($vc),
+ limit => $myconfig{vclimit} + 1 },
+ "price_factors" => "ALL_PRICE_FACTORS");
+
+ # label subs
+ $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{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" };
+ $TMPL_VAR{vclimit} = $myconfig{vclimit};
+ $TMPL_VAR{vc_select} = "customer_or_vendor_selection_window('$form->{vc}', '', @{[ $form->{vc} eq 'vendor' ? 1 : 0 ]}, 0)";
+ push @custom_hiddens, "$form->{vc}_id";
+ push @custom_hiddens, "old$form->{vc}";
+ push @custom_hiddens, "select$form->{vc}";
+
+ # currencies and exchangerate
+ my @values = map { $_ } @{ $form->{ALL_CURRENCIES} };
+ my %labels = map { $_ => $_ } @{ $form->{ALL_CURRENCIES} };
+ $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
+ $TMPL_VAR{show_exchangerate} = $form->{currency} ne $form->{defaultcurrency};
+ $TMPL_VAR{currencies} = NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
+ '-values' => \@values, '-labels' => \%labels,
+ '-onchange' => "document.getElementById('update_button').click();"
+ )) if scalar @values;
+ push @custom_hiddens, "forex";
+ push @custom_hiddens, "exchangerate" if $form->{forex};
+
+ # credit remaining
+ my $creditwarning = (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) ? 1 : 0;
+ $TMPL_VAR{is_credit_remaining_negativ} = ($form->{creditremaining} =~ /-/) ? "0" : "1";
+
+ # business
+ $TMPL_VAR{business_label} = ($form->{vc} eq "customer" ? $locale->text('Customer type') : $locale->text('Vendor type'));
+
+ push @custom_hiddens, "customer_klass" if $form->{vc} eq 'customer';
+
+ my $credittext = $locale->text('Credit Limit exceeded!!!');
+
+ my $follow_up_vc = $form->{ $form->{vc} eq 'customer' ? 'customer' : 'vendor' };
+ $follow_up_vc =~ s/--\d*\s*$//;
+ $TMPL_VAR{follow_up_trans_info} = ($form->{type} =~ /_quotation$/ ? $form->{quonumber} : $form->{ordnumber}) . " ($follow_up_vc)";