Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 91ab1ef6

Von Sven Schöling vor etwa 17 Jahren hinzugefügt

  • ID 91ab1ef646193de9359076a876a33a74d7691145
  • Vorgänger d1e4ee79
  • Nachfolger ac7a6ae3

Um die Benutzung des Template Systems mal ein wenig zu foerdern.

Die bin/mozilla/oe.pl noch einmal umgeschrieben, so dass jetzt noch mehr Funktionen ins Frontend ausgelagert sind.

Ein neues Highlight ist die template/generic/multibox.html, die es erlaubt aus wenigen Steuerkommandos ein HTML-Eingabefeld zu erstellen, was bei kleinen Datenmengen als Dropdownbox erscheint, udn bei grossen asl Textfeld, mit dazugehörigem Popup-Button, um eine Auswahlliste aufzumachen. Saemtliche Funktionen lassen sich ueber Perlfunktionsreferenzen wieder zurück ins Backend leiten, und dort wieder mit komplexer Logik füllen. Dokumentation ist im Template direkt enthalten.

Die Customer/Vendor Eingabe macht auch gleich Gebrauch davon und erzeugt bei zu grosser Anzahl ein Textfeld, und daneben einen Suchbutton, der die passenden Kunden in einer Liste anzeigt.

Der "Kundendetails"-Button wurde von "?" umbenannt in "D" (immernoch gruselig)

Auf Wunsch von Moritz habe ich die display_row von bin/mozilla/oe.pl wieder verlagert in die bin/mozilla/io.pl, und dafuer die Version in bin/mozilla/invoice_io.pl deaktiviert.

Unterschiede anzeigen:

SL/Common.pm
154 154
  return $employees;
155 155
}
156 156

  
157
sub retrieve_customers_or_vendors {
158
  $main::lxdebug->enter_sub();
159

  
160
  my ($self, $myconfig, $form, $order_by, $order_dir, $is_vendor, $allow_both) = @_;
161

  
162
  my $dbh = $form->dbconnect($myconfig);
163

  
164
  my (@filter_values, $filter);
165
  if ($form->{"name"}) {
166
    $filter .= " AND (TABLE.name ILIKE ?)";
167
    push(@filter_values, '%' . $form->{"name"} . '%');
168
  }
169
  if (!$form->{"obsolete"}) {
170
    $filter .= " AND NOT TABLE.obsolete";
171
  }
172
  substr($filter, 1, 3) = "WHERE" if ($filter);
173

  
174
  $order_by =~ s/[^a-zA-Z_]//g;
175
  $order_dir = $order_dir ? "ASC" : "DESC";
176

  
177
  my (@queries, @query_parameters);
178

  
179
  if ($allow_both || !$is_vendor) {
180
    my $c_filter = $filter;
181
    $c_filter =~ s/TABLE/c/g;
182
    push(@queries, qq|SELECT
183
                        c.id, c.name, 0 AS customer_is_vendor,
184
                        c.street, c.zipcode, c.city,
185
                        ct.cp_greeting, ct.cp_title, ct.cp_givenname, ct.cp_name
186
                      FROM customer c
187
                      LEFT JOIN contacts ct ON (c.id = ct.cp_cv_id)
188
                      $c_filter|);
189
    push(@query_parameters, @filter_values);
190
  }
191

  
192
  if ($allow_both || $is_vendor) {
193
    my $v_filter = $filter;
194
    $v_filter =~ s/TABLE/v/g;
195
    push(@queries, qq|SELECT
196
                        v.id, v.name, 1 AS customer_is_vendor,
197
                        v.street, v.zipcode, v.city,
198
                        ct.cp_greeting, ct.cp_title, ct.cp_givenname, ct.cp_name
199
                      FROM vendor v
200
                      LEFT JOIN contacts ct ON (v.id = ct.cp_cv_id)
201
                      $v_filter|);
202
    push(@query_parameters, @filter_values);
203
  }
204

  
205
  my $query = join(" UNION ", @queries) . " ORDER BY $order_by $order_dir";
206
  my $sth = $dbh->prepare($query);
207
  $sth->execute(@query_parameters) || $form->dberror($query . " (" . join(", ", @query_parameters) . ")");
208
  my $customers = [];
209
  while (my $ref = $sth->fetchrow_hashref()) {
210
    push(@{$customers}, $ref);
211
  }
212
  $sth->finish();
213
  $dbh->disconnect();
214

  
215
  $main::lxdebug->leave_sub();
216

  
217
  return $customers;
218
}
219

  
157 220
sub retrieve_delivery_customer {
158 221
  $main::lxdebug->enter_sub();
159 222

  
SL/Form.pm
555 555

  
556 556
  $file = $self->_prepare_html_template($file, $additional_params);
557 557

  
558
  my $template = Template->new({ 'INTERPOLATE' => 0,
559
                                 'EVAL_PERL'   => 0,
560
                                 'ABSOLUTE'    => 1,
561
                                 'CACHE_SIZE'  => 0,
562
                                 'PLUGIN_BASE' => 'SL::Template::Plugin',
558
  my $template = Template->new({ 'INTERPOLATE'  => 0,
559
                                 'EVAL_PERL'    => 0,
560
                                 'ABSOLUTE'     => 1,
561
                                 'CACHE_SIZE'   => 0,
562
                                 'PLUGIN_BASE'  => 'SL::Template::Plugin',
563
                                 'INCLUDE_PATH' => '.:templates/webpages',
563 564
                               }) || die;
564 565

  
565 566
  map { $additional_params->{$_} ||= $self->{$_} } keys %{ $self };
SL/Template/Plugin/LxERP.pm
2 2

  
3 3
use base qw( Template::Plugin );
4 4
use Template::Plugin;
5
use List::Util qw(first);
5 6

  
6 7
sub new {
7 8
  my $class   = shift;
bin/mozilla/common.pl
80 80
  $lxdebug->leave_sub();
81 81
}
82 82

  
83
## Customers/Vendors
84

  
85
sub check_customer_or_vendor {
86
  $lxdebug->enter_sub();
87

  
88
  my ($field, $cov_selected_nextsub, $is_vendor) = @_;
89

  
90
  if ($form->{"f_${field}"} eq $form->{"f_old_${field}"}) {
91
    $lxdebug->leave_sub();
92
    return 1;
93
  }
94

  
95
  my $type = $is_vendor ? $locale->text("vendor") : $locale->text("customer");
96

  
97
  my $old_form = save_form();
98
  $form->{"name"} = $form->{"f_${field}"};
99
  $form->{"obsolete"} = 1;
100
  my $covs;
101
  $covs = Common->retrieve_customers_or_vendors(\%myconfig, $form, "name", 1, $is_vendor);
102
  restore_form($old_form);
103

  
104
  if (0 == scalar(@{$covs})) {
105
    $form->header();
106
    $form->show_generic_error(sprintf($locale->text("There is no %s whose name matches '%s'."), $type, $form->{"f_${field}"}));
107

  
108
    $lxdebug->leave_sub();
109
    return 0;
110

  
111
  }
112

  
113
  if (1 != scalar(@{$covs})) {
114
    # If there is more than one CoV with the same name
115
    # then we have to check if the ID is set, too. Otherwise
116
    # we'd be stuck in an endless loop.
117
    if ($form->{"f_${field}_id"}) {
118
      foreach my $cov (@{$covs}) {
119
        if (($form->{"f_${field}_id"} == $cov->{"id"}) &&
120
            ($form->{"f_${field}"} eq $cov->{"name"})) {
121
          $lxdebug->leave_sub();
122
          return 1;
123
        }
124
      }
125
    }
126

  
127
    $form->{"cov_selected_nextsub"} = $cov_selected_nextsub;
128
    $form->{"check_cov_field"} = $field;
129
    select_customer_or_vendor("cov_selected", $is_vendor, @{$covs});
130
    $lxdebug->leave_sub();
131
    return 0;
132
  }
133

  
134
  $form->{"f_${field}_id"} = $covs->[0]->{"id"};
135
  $form->{"f_${field}"} = $covs->[0]->{"name"};
136

  
137
  $lxdebug->leave_sub();
138

  
139
  return 1;
140
}
141

  
142
sub select_customer_or_vendor {
143
  $lxdebug->enter_sub();
144

  
145
  my ($callback_sub, $is_vendor, @covs) = @_;
146

  
147
  my $old_form = save_form();
148

  
149
  if (0 == scalar(@covs)) {
150
    delete($form->{"name"});
151
    $form->{"obsolete"} = 1;
152
    my $c = Common->retrieve_customers_or_vendors(\%myconfig, $form, "name", 1, $is_vendor);
153
    restore_form($old_form);
154
    @covs = @{$c};
155
  }
156

  
157
  $form->header();
158
  print($form->parse_html_template("generic/select_customer_or_vendor",
159
                                   { "COVS" => \@covs,
160
                                     "old_form" => $old_form,
161
                                     "title" => $is_vendor ? $locale->text("Select a vendor") : $locale->text("Select a customer"),
162
                                     "nextsub" => "select_cov_internal",
163
                                     "callback_sub" => $callback_sub }));
164

  
165
  $lxdebug->leave_sub();
166
}
167

  
168
sub cov_selected {
169
  $lxdebug->enter_sub();
170
  my ($new_id, $new_name) = @_;
171

  
172
  my $field = $form->{"check_cov_field"};
173
  delete($form->{"check_cov_field"});
174

  
175
  $form->{"f_${field}_id"} = $new_id;
176
  $form->{"f_${field}"} = $new_name;
177
  $form->{"f_old_${field}"} = $new_name;
178

  
179
  &{ $form->{"cov_selected_nextsub"} }();
180

  
181
  $lxdebug->leave_sub();
182
}
183

  
184
sub select_cov_internal {
185
  $lxdebug->enter_sub();
186

  
187
  my ($new_id, $new_name, $callback_sub);
188

  
189
  my $new_id = $form->{"new_id_" . $form->{"selection"}};
190
  my $new_name = $form->{"new_name_" . $form->{"selection"}};
191
  my $callback_sub = $form->{"callback_sub"};
192

  
193
  restore_form($form->{"old_form"});
194

  
195
  &{ $callback_sub }($new_id, $new_name);
196

  
197
  $lxdebug->leave_sub();
198
}
199

  
83 200
sub select_part {
84 201
  $lxdebug->enter_sub();
85 202

  
......
588 705
  $lxdebug->leave_sub();
589 706
}
590 707

  
708
sub cov_selection_internal {
709
  $lxdebug->enter_sub();
710

  
711
  $order_by = "name";
712
  $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
713
  $order_dir = 1;
714
  $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
715

  
716
  my $type = $form->{"is_vendor"} ? $locale->text("vendor") : $locale->text("customer");
717

  
718
  $covs = Common->retrieve_customers_or_vendors(\%myconfig, $form, $order_by, $order_dir, $form->{"is_vendor"}, $form->{"allow_both"});
719
  map({ $covs->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$covs}));
720
  if (0 == scalar(@{$covs})) {
721
    $form->show_generic_information(sprintf($locale->text("No %s was found matching the search parameters."), $type));
722
  } elsif (1 == scalar(@{$covs})) {
723
    $onload = "cov_selected('1')";
724
  }
725

  
726
  my $callback = "$form->{script}?action=cov_selection_internal&";
727
  map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
728
      (qw(login path password name input_name input_id is_vendor allow_both), grep({ /^[fl]_/ } keys %$form)));
729

  
730
  my @header_sort = qw(name address contact);
731
  my %header_title = ( "name" => $locale->text("Name"),
732
                       "address" => $locale->text("Address"),
733
                       "contact" => $locale->text("Contact"),
734
                       );
735

  
736
  my @header =
737
    map(+{ "column_title" => $header_title{$_},
738
           "column" => $_,
739
           "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
740
         },
741
        @header_sort);
742

  
743
  foreach my $cov (@{ $covs }) {
744
    $cov->{address} = "$cov->{street}, $cov->{zipcode} $cov->{city}";
745
    $cov->{address} =~ s{^,}{}x;
746
    $cov->{address} =~ s{\ +}{\ }gx;
747

  
748
    $cov->{contact} = join " ", map { $cov->{$_} } qw(cp_greeting cp_title cp_givenname cp_name);
749
    $cov->{contact} =~ s{\ +}{\ }gx;
750
  }
751

  
752
  $form->{"title"} = $form->{is_vendor} ? $locale->text("Select a vendor") : $locale->text("Select a customer");
753
  $form->header();
754
  print($form->parse_html_template("generic/cov_selection", { "HEADER" => \@header,
755
                                                              "COVS" => $covs,
756
                                                              "onload" => $onload }));
757

  
758
  $lxdebug->leave_sub();
759
}
760

  
761
sub check_cov2 {
762
  $lxdebug->enter_sub();
763

  
764
  my $callback_sub = shift;
765

  
766
  if (!$form->{customer}
767
      || ($form->{customer} eq $form->{old_customer})
768
      || ("$form->{customer}--$form->{customer_id}" eq $form->{old_customer})) {
769
    $lxdebug->leave_sub();
770
    return;
771
  }
772

  
773
  $old_name     = $form->{name};
774
  $form->{name} = $form->{customer};
775

  
776
  my $covs = Common->retrieve_customers_or_vendors(\%myconfig, $form, "name", "ASC", 0, 1);
777

  
778
  $form->{name} = $old_name;
779

  
780
  if (0 == scalar @{$covs}) {
781
    $form->show_generic_information(sprintf($locale->text("No %s was found matching the search parameters."), $type));
782

  
783
  } elsif (1 == scalar @{ $covs }) {
784
    $form->{customer}           = $covs->[0]->{name};
785
    $form->{old_customer}       = $covs->[0]->{name};
786
    $form->{customer_id}        = $covs->[0]->{id};
787
    $form->{customer_is_vendor} = $covs->[0]->{customer_is_vendor};
788

  
789
  } else {
790
    $form->{new_cov_nextsub} = $callback_sub;
791

  
792
    delete @{$form}{qw(customer customer_is_vendor customer_id old_customer action)};
793
    my @hidden = map { { 'key' => $_, 'value' => $form->{$_} } } grep { '' eq ref $form->{$_} } keys %{ $form };
794

  
795
    foreach my $cov (@{ $covs }) {
796
      $cov->{address} = "$cov->{street}, $cov->{zipcode} $cov->{city}";
797
      $cov->{address} =~ s{^,}{}x;
798
      $cov->{address} =~ s{\ +}{\ }gx;
799

  
800
      $cov->{contact} = join " ", map { $cov->{$_} } qw(cp_greeting cp_title cp_givenname cp_name);
801
      $cov->{contact} =~ s{\ +}{\ }gx;
802
    }
803

  
804
    $form->{title} = $locale->text("Select a vendor or customer");
805
    $form->header();
806

  
807
    print $form->parse_html_template("generic/cov_selection2", { "COVS" => $covs, "HIDDEN" => \@hidden });
808

  
809
    exit 0;
810
  }
811

  
812
  $lxdebug->leave_sub();
813
}
814

  
815
sub cov_selected2 {
816
  $lxdebug->enter_sub();
817

  
818
  if (!$form->{new_cov} || !$form->{new_cov_nextsub}) {
819
    $form->error($locale->text('No customer has been selected.'));
820
  }
821

  
822
  map { $form->{$_} = $form->{"new_cov_${_}_$form->{new_cov}"} } qw(customer customer_id customer_is_vendor);
823
  $form->{old_customer} = $form->{customer};
824

  
825
  &{ $form->{new_cov_nextsub} }();
826

  
827
  $lxdebug->leave_sub();
828
}
829

  
830
sub select_item_selection_internal {
831
  $lxdebug->enter_sub();
832

  
833
  @items = SystemBrace->retrieve_select_items(\%myconfig, $form, $form->{"select_item_type"});
834
  if (0 == scalar(@items)) {
835
    $form->show_generic_information($locale->text("No item was found."));
836
  } elsif (1 == scalar(@items)) {
837
    $onload = "select_item_selected('1')";
838
  }
839

  
840
  $form->{"title"} = $locale->text("Select an entry");
841
  $form->header();
842
  print($form->parse_html_template("generic/select_item_selection", { "SELECT_ITEMS" => \@items,
843
                                                                      "onload" => $onload }));
844

  
845
  $lxdebug->leave_sub();
846
}
591 847
1;
bin/mozilla/invoice_io.pl
90 90
# Eintrag fuer Version 2.2.0 geaendert #
91 91
# neue Optik im Rechnungsformular      #
92 92
########################################
93
sub display_row {
94
  $lxdebug->enter_sub();
95
  my $numrows = shift;
96

  
97
  my $is_sales =
98
    (substr($form->{type}, 0, 6) eq "sales_")
99
    || (($form->{type} eq "invoice") && ($form->{script} eq "is.pl"))
100
    || ($form->{type} eq 'credit_note');
101

  
102
  if ($lizenzen && $form->{vc} eq "customer") {
103
    if ($form->{type} =~ /sales_order/) {
104
      @column_index = (runningnumber, partnumber, description, ship, qty);
105
    } elsif ($form->{type} =~ /sales_quotation/) {
106
      @column_index = (runningnumber, partnumber, description, qty);
107
    } else {
108
      @column_index = (runningnumber, partnumber, description, qty);
109
    }
110
  } else {
111
    if (   ($form->{type} =~ /purchase_order/)
112
        || ($form->{type} =~ /sales_order/)) {
113
      @column_index = (runningnumber, partnumber, description, ship, qty);
114
        } else {
115
      @column_index = (runningnumber, partnumber, description, qty);
116
    }
117
  }
118
############## ENDE Neueintrag ##################
119

  
120
  my $dimension_units = AM->retrieve_units(\%myconfig, $form, "dimension");
121
  my $service_units = AM->retrieve_units(\%myconfig, $form, "service");
122
  my $all_units = AM->retrieve_units(\%myconfig, $form);
123

  
124
  my %price_factors = map { $_->{id} => $_->{factor} } @{ $form->{ALL_PRICE_FACTORS} };
125

  
126
  push @column_index, qw(unit);
127

  
128
  #for pricegroups column
129
  if (   $form->{type} =~ (/sales_quotation/)
130
      or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/))
131
      or (($form->{level} eq undef) and ($form->{type} =~ /invoice/))
132
      or ($form->{type} =~ /sales_order/)) {
133
    push @column_index, qw(sellprice_pg);
134
  }
135

  
136
  push @column_index, qw(sellprice);
137

  
138
  if ($form->{vc} eq 'customer') {
139
    push @column_index, qw(discount);
140
  }
141

  
142
  push @column_index, "linetotal";
143

  
144
  my $colspan = $#column_index + 1;
145

  
146
  $form->{invsubtotal} = 0;
147
  map { $form->{"${_}_base"} = 0 } (split(/ /, $form->{taxaccounts}));
148

  
149
########################################
150
  # Eintrag fuer Version 2.2.0 geaendert #
151
  # neue Optik im Rechnungsformular      #
152
########################################
153
  $column_data{runningnumber} = qq|<th align="left" nowrap width="5%"  class="listheading">| . $locale->text('No.') .         qq|</th>|;
154
  $column_data{partnumber}    = qq|<th align="left" nowrap width="12%" class="listheading">| . $locale->text('Number') .      qq|</th>|;
155
  $column_data{description}   = qq|<th align="left" nowrap width="30%" class="listheading">| . $locale->text('Part Description') . qq|</th>|;
156
  if ($form->{"type"} eq "purchase_order") {
157
    $column_data{ship}        = qq|<th align="left" nowrap width="5%"  class="listheading">| . $locale->text('Ship rcvd') .   qq|</th>|;
158
  } else {
159
    $column_data{ship}        = qq|<th align="left" nowrap width="5%"  class="listheading">| . $locale->text('Ship') .        qq|</th>|;
160
  }
161
  $column_data{qty}           = qq|<th align="left" nowrap width="5%"  class="listheading">| . $locale->text('Qty') .         qq|</th>|;
162
  $column_data{unit}          = qq|<th align="left" nowrap width="20%" class="listheading">| . $locale->text('Unit') .        qq|</th>|;
163
  $column_data{license}       = qq|<th align="left" nowrap width="10%" class="listheading">| . $locale->text('License') .     qq|</th>|;
164
  $column_data{serialnr}      = qq|<th align="left" nowrap width="10%" class="listheading">| . $locale->text('Serial No.') .  qq|</th>|;
165
  $column_data{projectnr}     = qq|<th align="left" nowrap width="10%" class="listheading">| . $locale->text('Project') .     qq|</th>|;
166
  $column_data{sellprice}     = qq|<th align="left" nowrap width="15%" class="listheading">| . $locale->text('Price') .       qq|</th>|;
167
  $column_data{sellprice_pg}  = qq|<th align="left" nowrap width="15%" class="listheading">| . $locale->text('Pricegroup') .  qq|</th>|;
168
  $column_data{discount}      = qq|<th align="left" nowrap width="5%"  class="listheading">| . $locale->text('Discount') .    qq|</th>|;
169
  $column_data{linetotal}     = qq|<th align="left" nowrap width="10%" class="listheading">| . $locale->text('Extended') .    qq|</th>|;
170
  $column_data{bin}           = qq|<th align="left" nowrap width="10%" class="listheading">| . $locale->text('Bin') .         qq|</th>|;
171
############## ENDE Neueintrag ##################
172

  
173
  $myconfig{"show_form_details"} = 1
174
    unless (defined($myconfig{"show_form_details"}));
175
  $form->{"show_details"} = $myconfig{"show_form_details"}
176
    unless (defined($form->{"show_details"}));
177
  $form->{"show_details"} = $form->{"show_details"} ? 1 : 0;
178
  my $show_details_new = 1 - $form->{"show_details"};
179
  my $show_details_checked = $form->{"show_details"} ? "checked" : "";
180

  
181
  print qq|
182
  <tr>
183
    <td>| . $cgi->hidden("-name" => "show_details", "-value" => $form->{show_details}) . qq|
184
      <input type="checkbox" id="cb_show_details" onclick="show_form_details($show_details_new);" $show_details_checked>
185
      <label for="cb_show_details">| . $locale->text("Show details") . qq|</label><br>
186
      <table width="100%">
187
	<tr class="listheading">|;
188

  
189
  map { print "\n$column_data{$_}" } @column_index;
190

  
191
  print qq|
192
        </tr>
193
|;
194

  
195
  $runningnumber = $locale->text('No.');
196
  $deliverydate  = $locale->text('Delivery Date');
197
  $serialnumber  = $locale->text('Serial No.');
198
  $projectnumber = $locale->text('Project');
199
  $partsgroup    = $locale->text('Group');
200
  $reqdate       = $locale->text('Reqdate');
201

  
202
  $delvar = 'deliverydate';
203

  
204
  if ($form->{type} =~ /_order$/ || $form->{type} =~ /_quotation$/) {
205
    $deliverydate = $locale->text('Required by');
206
    $delvar       = 'reqdate';
207
  }
208

  
209
  $form->{marge_total} = 0;
210
  $form->{sellprice_total} = 0;
211
  $form->{lastcost_total} = 0;
212
  my %projectnumber_labels = ();
213
  my @projectnumber_values = ("");
214
  foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
215
    push(@projectnumber_values, $item->{"id"});
216
    $projectnumber_labels{$item->{"id"}} = $item->{"projectnumber"};
217
  }
218

  
219
  for $i (1 .. $numrows) {
220

  
221
    # undo formatting
222
    map {
223
      $form->{"${_}_$i"} =
224
        $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
225
    } qw(qty ship discount sellprice price_new price_old) unless ($form->{simple_save});
226

  
227
    if (!$form->{"unit_old_$i"}) {
228
      # Neue Ware aus der Datenbank. In diesem Fall ist unit_$i die
229
      # Einheit, wie sie in den Stammdaten hinterlegt wurde.
230
      # Es sollte also angenommen werden, dass diese ausgewaehlt war.
231
      $form->{"unit_old_$i"} = $form->{"unit_$i"};
232
    }
233

  
234
    # Die zuletzt ausgewaehlte mit der aktuell ausgewaehlten Einheit
235
    # vergleichen und bei Unterschied den Preis entsprechend umrechnen.
236
    $form->{"selected_unit_$i"} = $form->{"unit_$i"} unless ($form->{"selected_unit_$i"});
237

  
238
    my $check_units = $form->{"inventory_accno_$i"} ? $dimension_units : $service_units;
239
    if (!$check_units->{$form->{"selected_unit_$i"}} ||
240
        ($check_units->{$form->{"selected_unit_$i"}}->{"base_unit"} ne
241
         $all_units->{$form->{"unit_old_$i"}}->{"base_unit"})) {
242
      # Die ausgewaehlte Einheit ist fuer diesen Artikel nicht gueltig
243
      # (z.B. Dimensionseinheit war ausgewaehlt, es handelt sich aber
244
      # um eine Dienstleistung). Dann keinerlei Umrechnung vornehmen.
245
      $form->{"unit_old_$i"} = $form->{"selected_unit_$i"} = $form->{"unit_$i"};
246
    }
247
    if ((!$form->{"prices_$i"}) || ($form->{"new_pricegroup_$i"} == $form->{"old_pricegroup_$i"})) {
248
      if ($form->{"unit_old_$i"} ne $form->{"selected_unit_$i"}) {
249
        my $basefactor = 1;
250
        if (defined($all_units->{$form->{"unit_old_$i"}}->{"factor"}) &&
251
            $all_units->{$form->{"unit_old_$i"}}->{"factor"}) {
252
          $basefactor = $all_units->{$form->{"selected_unit_$i"}}->{"factor"} /
253
            $all_units->{$form->{"unit_old_$i"}}->{"factor"};
254
        }
255
        $form->{"sellprice_$i"} *= $basefactor;
256
        $form->{"unit_old_$i"} = $form->{"selected_unit_$i"};
257
      }
258
    }
259

  
260
    ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
261
    $decimalplaces = max length($dec), 2;
262

  
263
    $price_factor = $price_factors{$form->{"price_factor_id_$i"}} || 1;
264
    $discount     = (100 - $form->{"discount_$i"} * 1) / 100;
265

  
266
    $linetotal    = $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"} * $discount / $price_factor, $decimalplaces);
267

  
268
    my $real_sellprice = $form->{"sellprice_$i"} * $discount / $price_factor;
269

  
270
    # marge calculations
271
    my ($marge_font_start, $marge_font_end);
272

  
273
    $form->{"lastcost_$i"} *= 1;
274

  
275
    $marge_price_factor = $form->{"marge_price_factor_$i"} * 1 || 1;
276

  
277
    if ($real_sellprice && ($form->{"qty_$i"} * 1)) {
278
      $form->{"marge_percent_$i"}     = ($real_sellprice - $form->{"lastcost_$i"} / $marge_price_factor) * 100 / $real_sellprice;
279
      $myconfig{"marge_percent_warn"} = 15 unless (defined($myconfig{"marge_percent_warn"}));
280

  
281
      if ($form->{"id_$i"} &&
282
          ($form->{"marge_percent_$i"} < (1 * $myconfig{"marge_percent_warn"}))) {
283
        $marge_font_start = "<font color=\"#ff0000\">";
284
        $marge_font_end   = "</font>";
285
      }
286

  
287
    } else {
288
      $form->{"marge_percent_$i"} = 0;
289
    }
290

  
291
    my $marge_adjust_credit_note = $form->{type} eq 'credit_note' ? -1 : 1;
292
    $form->{"marge_total_$i"}  = ($real_sellprice - $form->{"lastcost_$i"} / $marge_price_factor) * $form->{"qty_$i"} * $marge_adjust_credit_note;
293
    $form->{"marge_total"}      += $form->{"marge_total_$i"};
294
    $form->{"lastcost_total"}   += $form->{"lastcost_$i"} * $form->{"qty_$i"} / $marge_price_factor;
295
    $form->{"sellprice_total"}  += $real_sellprice * $form->{"qty_$i"};
296

  
297
    map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) } qw(marge_total marge_percent);
298

  
299
    # convert " to &quot;
300
    map { $form->{"${_}_$i"} =~ s/\"/&quot;/g }
301
      qw(partnumber description unit unit_old);
302

  
303
########################################
304
    # Eintrag fuer Version 2.2.0 geaendert #
305
    # neue Optik im Rechnungsformular      #
306
########################################
307
    $column_data{runningnumber} =
308
      qq|<td><input name="runningnumber_$i" size="5" value="$i"></td>|;    # HuT
309
############## ENDE Neueintrag ##################
310

  
311
    $column_data{partnumber} =
312
      qq|<td><input name="partnumber_$i" size=12 value="$form->{"partnumber_$i"}"></td>|;
313

  
314
    if (($rows = $form->numtextrows($form->{"description_$i"}, 30, 6)) > 1) {
315
      $column_data{description} =
316
        qq|<td><textarea name="description_$i" rows="$rows" cols="30" wrap="soft">| . H($form->{"description_$i"}) . qq|</textarea><button type="button" onclick="set_longdescription_window('longdescription_$i')">| . $locale->text('L') . qq|</button></td>|;
317
    } else {
318
      $column_data{description} =
319
        qq|<td><input name="description_$i" size="30" value="| . $form->quote($form->{"description_$i"}) . qq|"><button type="button" onclick="set_longdescription_window('longdescription_$i')">| . $locale->text('L') . qq|</button></td>|;
320
    }
321

  
322
    (my $qty_dec) = ($form->{"qty_$i"} =~ /\.(\d+)/);
323
    $qty_dec = length $qty_dec;
324

  
325
    $column_data{qty} =
326
        qq|<td align="right"><input name="qty_$i" size="5" value="|
327
      . $form->format_amount(\%myconfig, $form->{"qty_$i"}, $qty_dec) .qq|">|;
328
    if ($form->{"formel_$i"}) {
329
      $column_data{qty} .= qq|<button type="button" onclick="calculate_qty_selection_window('qty_$i','alu_$i', 'formel_$i', $i)">| . $locale->text('*/') . qq|</button>|
330
        . $cgi->hidden("-name" => "formel_$i", "-value" => $form->{"formel_$i"}) . $cgi->hidden("-name" => "alu_$i", "-value" => $form->{"alu_$i"});
331
    }
332
    $column_data{qty} .= qq|</td>|;
333
    $column_data{ship} =
334
        qq|<td align="right"><input name="ship_$i" size=5 value="|
335
      . $form->format_amount(\%myconfig, $form->{"ship_$i"})
336
      . qq|"></td>|;
337

  
338
    my $is_part     = $form->{"inventory_accno_$i"};
339
    my $is_assembly = $form->{"assembly_$i"};
340
    my $is_assigned = $form->{"id_$i"};
341
    my $this_unit = $form->{"unit_$i"};
342
    if ($form->{"selected_unit_$i"} && $this_unit &&
343
        $all_units->{$form->{"selected_unit_$i"}} && $all_units->{$this_unit} &&
344
        ($all_units->{$form->{"selected_unit_$i"}}->{"base_unit"} eq $all_units->{$this_unit}->{"base_unit"})) {
345
      $this_unit = $form->{"selected_unit_$i"};
346
    } elsif (!$is_assigned ||
347
             ($is_part && !$this_unit && ($all_units->{$this_unit} && ($all_units->{$this_unit}->{"base_unit"} eq $all_units->{"kg"}->{"base_unit"})))) {
348
      $this_unit = "kg";
349
    }
350

  
351
    my $price_factor_select;
352
    if (0 < scalar @{ $form->{ALL_PRICE_FACTORS} }) {
353
      my @values = ('', map { $_->{id}                      } @{ $form->{ALL_PRICE_FACTORS} });
354
      my %labels =      map { $_->{id} => $_->{description} } @{ $form->{ALL_PRICE_FACTORS} };
355

  
356
      $price_factor_select =
357
        NTI($cgi->popup_menu('-name'    => "price_factor_id_$i",
358
                             '-default' => $form->{"price_factor_id_$i"},
359
                             '-values'  => \@values,
360
                             '-labels'  => \%labels,
361
                             '-style'   => 'width:90px'))
362
        . ' ';
363
    }
364

  
365
    $column_data{"unit"} = "<td>" .
366
      $price_factor_select .
367
       AM->unit_select_html($is_part || $is_assembly ? $dimension_units :
368
                            $is_assigned ? $service_units : $all_units,
369
                            "unit_$i", $this_unit,
370
                            $is_assigned ? $form->{"unit_$i"} : undef)
371
      . "</td>";
372

  
373
    # build in drop down list for pricesgroups
374
    if ($form->{"prices_$i"}) {
375
      if  ($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"}) {
376
        $price_tmp = $form->format_amount(\%myconfig, $form->{"price_new_$i"}, $decimalplaces);
377
      } else {
378
        $price_tmp = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
379
      }
380

  
381
      $column_data{sellprice_pg} =
382
      qq|<td align="right"><select name="sellprice_pg_$i">$form->{"prices_$i"}</select></td>|;
383
      $column_data{sellprice} =
384
      qq|<td><input name="sellprice_$i" size="10" value="$price_tmp" onBlur=\"check_right_number_format(this)\"></td>|;
385
    } else {
386

  
387
      # for last row and report
388
      # set pricegroup drop down list from report menu
389
      if ($form->{"sellprice_$i"} != 0) {
390
        $prices =
391
          qq|<option value="$form->{"sellprice_$i"}--$form->{"pricegroup_id_$i"}" selected>$form->{"pricegroup_$i"}</option>\n|;
392

  
393
        $form->{"pricegroup_old_$i"} = $form->{"pricegroup_id_$i"};
394

  
395
        $column_data{sellprice_pg} =
396
          qq|<td align="right"><select name="sellprice_pg_$i">$prices</select></td>|;
397

  
398
      } else {
399

  
400
        # for last row
401
        $column_data{sellprice_pg} = qq|<td align="right">&nbsp;</td>|;
402
        }
403
        
404
      $column_data{sellprice} =
405
      qq|<td><input name="sellprice_$i" size="10" onBlur=\"check_right_number_format(this)\" value="|
406
        . $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
407
                               $decimalplaces)
408
        . qq|"></td>|;
409
    }
410
    $column_data{discount} =
411
        qq|<td align="right"><input name="discount_$i" size=3 value="|
412
      . $form->format_amount(\%myconfig, $form->{"discount_$i"})
413
      . qq|"></td>|;
414
    $column_data{linetotal} =
415
        qq|<td align="right">|
416
      . $form->format_amount(\%myconfig, $linetotal, 2)
417
      . qq|</td>|;
418
    $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
419

  
420
########################################
421
    # Eintrag fuer Version 2.2.0 geaendert #
422
    # neue Optik im Rechnungsformular      #
423
########################################
424
    #     if ($lizenzen &&  $form->{type} eq "invoice" &&  $form->{vc} eq "customer") {
425
    #     $column_data{license} = qq|<td><select name="licensenumber_$i">$form->{"lizenzen_$i"}></select></td>|;
426
    #     }
427
    #
428
    #     if ($form->{type} !~ /_quotation/) {
429
    #     $column_data{serialnr} = qq|<td><input name="serialnumber_$i" size=10 value="$form->{"serialnumber_$i"}"></td>|;
430
    #     }
431
    #
432
    #     $column_data{projectnr} = qq|<td><input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}"></td>|;
433
############## ENDE Neueintrag ##################
434
    my $j = $i % 2;
435
    print qq|
436

  
437
        <tr valign="top" class="listrow$j">|;
438

  
439
    map { print "\n$column_data{$_}" } @column_index;
440

  
441
    print("</tr>\n" .
442
          $cgi->hidden("-name" => "unit_old_$i",
443
                       "-value" => $form->{"selected_unit_$i"})
444
          . "\n" .
445
          $cgi->hidden("-name" => "price_new_$i",
446
                       "-value" => $form->format_amount(\%myconfig, $form->{"price_new_$i"}))
447
          . "\n");
448
    map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_}) . "\n"); }
449
        ("orderitems_id_$i", "bo_$i", "pricegroup_old_$i", "price_old_$i",
450
         "id_$i", "inventory_accno_$i", "bin_$i", "partsgroup_$i", "partnotes_$i",
451
         "income_accno_$i", "expense_accno_$i", "listprice_$i", "assembly_$i",
452
         "taxaccounts_$i", "ordnumber_$i", "transdate_$i", "cusordnumber_$i",
453
         "longdescription_$i", "basefactor_$i", "marge_total_$i", "marge_percent_$i", "lastcost_$i",
454
         "marge_price_factor_$i"));
455

  
456
########################################
457
    # Eintrag fuer Version 2.2.0 geaendert #
458
    # neue Optik im Rechnungsformular      #
459
########################################
460

  
461
    my $row_style_attr =
462
      'style="display:none;"' if (!$form->{"show_details"});
463

  
464
    # print second row
465
    print qq|
466
        <tr  class="listrow$j" $row_style_attr>
467
	  <td colspan="$colspan">
468
|;
469
    if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
470
      my $selected = $form->{"licensenumber_$i"};
471
      my $lizenzen_quoted;
472
      $form->{"lizenzen_$i"} =~ s/ selected//g;
473
      $form->{"lizenzen_$i"} =~
474
        s/value="${selected}"\>/value="${selected}" selected\>/;
475
      $lizenzen_quoted = $form->{"lizenzen_$i"};
476
      $lizenzen_quoted =~ s/\"/&quot;/g;
477
      print qq|
478
	<b>Lizenz\#</b>&nbsp;<select name="licensenumber_$i" size="1">
479
	$form->{"lizenzen_$i"}
480
        </select>
481
	<input type="hidden" name="lizenzen_$i" value="${lizenzen_quoted}">
482
|;
483
    }
484
    if ($form->{type} !~ /_quotation/) {
485
      print qq|
486
          <b>$serialnumber</b>&nbsp;<input name="serialnumber_$i" size="15" value="$form->{"serialnumber_$i"}">|;
487
    }
488

  
489
    print qq|<b>$projectnumber</b>&nbsp;| .
490
      NTI($cgi->popup_menu('-name' => "project_id_$i",
491
                           '-values' => \@projectnumber_values,
492
                           '-labels' => \%projectnumber_labels,
493
                           '-default' => $form->{"project_id_$i"}));
494

  
495
    if ($form->{type} eq 'invoice' or $form->{type} =~ /order/) {
496
      my $reqdate_term =
497
        ($form->{type} eq 'invoice')
498
        ? 'deliverydate'
499
        : 'reqdate';    # invoice uses a different term for the same thing.
500
      print qq|
501
        <b>${$reqdate_term}</b>&nbsp;<input name="${reqdate_term}_$i" size="11" onBlur="check_right_date_format(this)" value="$form->{"${reqdate_term}_$i"}">
502
|;
503
    }
504
    my $subtotalchecked = ($form->{"subtotal_$i"}) ? "checked" : "";
505
    print qq|
506
          <b>|.$locale->text('Subtotal').qq|</b>&nbsp;<input type="checkbox" name="subtotal_$i" value="1" $subtotalchecked>
507
|;
508

  
509
    if ($form->{"id_$i"} && $is_sales) {
510
      my $marge_price_factor;
511

  
512
      $form->{"marge_price_factor_$i"} *= 1;
513

  
514
      if ($form->{"marge_price_factor_$i"} && (1 != $form->{"marge_price_factor_$i"})) {
515
        $marge_price_factor = '/' . $form->format_amount(\%myconfig, $form->{"marge_price_factor_$i"});
516
      }
517

  
518
      print qq|
519
          ${marge_font_start}<b>| . $locale->text('Ertrag') . qq|</b>&nbsp;$form->{"marge_total_$i"}&nbsp;$form->{"marge_percent_$i"} % ${marge_font_end}|;
520
   }
521
   print qq|
522
          &nbsp;<b>| . $locale->text('LP') . qq|</b>&nbsp;| . $form->format_amount(\%myconfig, $form->{"listprice_$i"}, 2) . qq|
523
          &nbsp;<b>| . $locale->text('EK') . qq|</b>&nbsp;| . $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, 2) . $marge_price_factor;
524

  
525

  
526
    print qq|
527
	  </td>
528
	</tr>
529
|;
530

  
531
############## ENDE Neueintrag ##################
532

  
533
    map { $form->{"${_}_base"} += $linetotal }
534
      (split(/ /, $form->{"taxaccounts_$i"}));
535

  
536
    $form->{invsubtotal} += $linetotal;
537
  }
538

  
539
  print qq|
540
      </table>
541
    </td>
542
  </tr>
543
|;
544

  
545
  if (0 != ($form->{sellprice_total} * 1)) {
546
    $form->{marge_percent} = ($form->{sellprice_total} - $form->{lastcost_total}) / $form->{sellprice_total} * 100;
547
  }
548

  
549
  $lxdebug->leave_sub();
550
}
93
#sub display_row {
94
#  $lxdebug->enter_sub();
95
#  my $numrows = shift;
96
#
97
#  my $is_sales =
98
#    (substr($form->{type}, 0, 6) eq "sales_")
99
#    || (($form->{type} eq "invoice") && ($form->{script} eq "is.pl"))
100
#    || ($form->{type} eq 'credit_note');
101
#
102
#  if ($lizenzen && $form->{vc} eq "customer") {
103
#    if ($form->{type} =~ /sales_order/) {
104
#      @column_index = (runningnumber, partnumber, description, ship, qty);
105
#    } elsif ($form->{type} =~ /sales_quotation/) {
106
#      @column_index = (runningnumber, partnumber, description, qty);
107
#    } else {
108
#      @column_index = (runningnumber, partnumber, description, qty);
109
#    }
110
#  } else {
111
#    if (   ($form->{type} =~ /purchase_order/)
112
#        || ($form->{type} =~ /sales_order/)) {
113
#      @column_index = (runningnumber, partnumber, description, ship, qty);
114
#        } else {
115
#      @column_index = (runningnumber, partnumber, description, qty);
116
#    }
117
#  }
118
############### ENDE Neueintrag ##################
119
#
120
#  my $dimension_units = AM->retrieve_units(\%myconfig, $form, "dimension");
121
#  my $service_units = AM->retrieve_units(\%myconfig, $form, "service");
122
#  my $all_units = AM->retrieve_units(\%myconfig, $form);
123
#
124
#  my %price_factors = map { $_->{id} => $_->{factor} } @{ $form->{ALL_PRICE_FACTORS} };
125
#
126
#  push @column_index, qw(unit);
127
#
128
#  #for pricegroups column
129
#  if (   $form->{type} =~ (/sales_quotation/)
130
#      or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/))
131
#      or (($form->{level} eq undef) and ($form->{type} =~ /invoice/))
132
#      or ($form->{type} =~ /sales_order/)) {
133
#    push @column_index, qw(sellprice_pg);
134
#  }
135
#
136
#  push @column_index, qw(sellprice);
137
#
138
#  if ($form->{vc} eq 'customer') {
139
#    push @column_index, qw(discount);
140
#  }
141
#
142
#  push @column_index, "linetotal";
143
#
144
#  my $colspan = $#column_index + 1;
145
#
146
#  $form->{invsubtotal} = 0;
147
#  map { $form->{"${_}_base"} = 0 } (split(/ /, $form->{taxaccounts}));
148
#
149
#########################################
150
#  # Eintrag fuer Version 2.2.0 geaendert #
151
#  # neue Optik im Rechnungsformular      #
152
#########################################
153
#  $column_data{runningnumber} = qq|<th align="left" nowrap width="5%"  class="listheading">| . $locale->text('No.') .         qq|</th>|;
154
#  $column_data{partnumber}    = qq|<th align="left" nowrap width="12%" class="listheading">| . $locale->text('Number') .      qq|</th>|;
155
#  $column_data{description}   = qq|<th align="left" nowrap width="30%" class="listheading">| . $locale->text('Part Description') . qq|</th>|;
156
#  if ($form->{"type"} eq "purchase_order") {
157
#    $column_data{ship}        = qq|<th align="left" nowrap width="5%"  class="listheading">| . $locale->text('Ship rcvd') .   qq|</th>|;
158
#  } else {
159
#    $column_data{ship}        = qq|<th align="left" nowrap width="5%"  class="listheading">| . $locale->text('Ship') .        qq|</th>|;
160
#  }
161
#  $column_data{qty}           = qq|<th align="left" nowrap width="5%"  class="listheading">| . $locale->text('Qty') .         qq|</th>|;
162
#  $column_data{unit}          = qq|<th align="left" nowrap width="20%" class="listheading">| . $locale->text('Unit') .        qq|</th>|;
163
#  $column_data{license}       = qq|<th align="left" nowrap width="10%" class="listheading">| . $locale->text('License') .     qq|</th>|;
164
#  $column_data{serialnr}      = qq|<th align="left" nowrap width="10%" class="listheading">| . $locale->text('Serial No.') .  qq|</th>|;
165
#  $column_data{projectnr}     = qq|<th align="left" nowrap width="10%" class="listheading">| . $locale->text('Project') .     qq|</th>|;
166
#  $column_data{sellprice}     = qq|<th align="left" nowrap width="15%" class="listheading">| . $locale->text('Price') .       qq|</th>|;
167
#  $column_data{sellprice_pg}  = qq|<th align="left" nowrap width="15%" class="listheading">| . $locale->text('Pricegroup') .  qq|</th>|;
168
#  $column_data{discount}      = qq|<th align="left" nowrap width="5%"  class="listheading">| . $locale->text('Discount') .    qq|</th>|;
169
#  $column_data{linetotal}     = qq|<th align="left" nowrap width="10%" class="listheading">| . $locale->text('Extended') .    qq|</th>|;
170
#  $column_data{bin}           = qq|<th align="left" nowrap width="10%" class="listheading">| . $locale->text('Bin') .         qq|</th>|;
171
############### ENDE Neueintrag ##################
172
#
173
#  $myconfig{"show_form_details"} = 1
174
#    unless (defined($myconfig{"show_form_details"}));
175
#  $form->{"show_details"} = $myconfig{"show_form_details"}
176
#    unless (defined($form->{"show_details"}));
177
#  $form->{"show_details"} = $form->{"show_details"} ? 1 : 0;
178
#  my $show_details_new = 1 - $form->{"show_details"};
179
#  my $show_details_checked = $form->{"show_details"} ? "checked" : "";
180
#
181
#  print qq|
182
#  <tr>
183
#    <td>| . $cgi->hidden("-name" => "show_details", "-value" => $form->{show_details}) . qq|
184
#      <input type="checkbox" id="cb_show_details" onclick="show_form_details($show_details_new);" $show_details_checked>
185
#      <label for="cb_show_details">| . $locale->text("Show details") . qq|</label><br>
186
#      <table width="100%">
187
#	<tr class="listheading">|;
188
#
189
#  map { print "\n$column_data{$_}" } @column_index;
190
#
191
#  print qq|
192
#        </tr>
193
#|;
194
#
195
#  $runningnumber = $locale->text('No.');
196
#  $deliverydate  = $locale->text('Delivery Date');
197
#  $serialnumber  = $locale->text('Serial No.');
198
#  $projectnumber = $locale->text('Project');
199
#  $partsgroup    = $locale->text('Group');
200
#  $reqdate       = $locale->text('Reqdate');
201
#
202
#  $delvar = 'deliverydate';
203
#
204
#  if ($form->{type} =~ /_order$/ || $form->{type} =~ /_quotation$/) {
205
#    $deliverydate = $locale->text('Required by');
206
#    $delvar       = 'reqdate';
207
#  }
208
#
209
#  $form->{marge_total} = 0;
210
#  $form->{sellprice_total} = 0;
211
#  $form->{lastcost_total} = 0;
212
#  my %projectnumber_labels = ();
213
#  my @projectnumber_values = ("");
214
#  foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
215
#    push(@projectnumber_values, $item->{"id"});
216
#    $projectnumber_labels{$item->{"id"}} = $item->{"projectnumber"};
217
#  }
218
#
219
#  for $i (1 .. $numrows) {
220
#
221
#    # undo formatting
222
#    map {
223
#      $form->{"${_}_$i"} =
224
#        $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
225
#    } qw(qty ship discount sellprice price_new price_old) unless ($form->{simple_save});
226
#
227
#    if (!$form->{"unit_old_$i"}) {
228
#      # Neue Ware aus der Datenbank. In diesem Fall ist unit_$i die
229
#      # Einheit, wie sie in den Stammdaten hinterlegt wurde.
230
#      # Es sollte also angenommen werden, dass diese ausgewaehlt war.
231
#      $form->{"unit_old_$i"} = $form->{"unit_$i"};
232
#    }
233
#
234
#    # Die zuletzt ausgewaehlte mit der aktuell ausgewaehlten Einheit
235
#    # vergleichen und bei Unterschied den Preis entsprechend umrechnen.
236
#    $form->{"selected_unit_$i"} = $form->{"unit_$i"} unless ($form->{"selected_unit_$i"});
237
#
238
#    my $check_units = $form->{"inventory_accno_$i"} ? $dimension_units : $service_units;
239
#    if (!$check_units->{$form->{"selected_unit_$i"}} ||
240
#        ($check_units->{$form->{"selected_unit_$i"}}->{"base_unit"} ne
241
#         $all_units->{$form->{"unit_old_$i"}}->{"base_unit"})) {
242
#      # Die ausgewaehlte Einheit ist fuer diesen Artikel nicht gueltig
243
#      # (z.B. Dimensionseinheit war ausgewaehlt, es handelt sich aber
244
#      # um eine Dienstleistung). Dann keinerlei Umrechnung vornehmen.
245
#      $form->{"unit_old_$i"} = $form->{"selected_unit_$i"} = $form->{"unit_$i"};
246
#    }
247
#    if ((!$form->{"prices_$i"}) || ($form->{"new_pricegroup_$i"} == $form->{"old_pricegroup_$i"})) {
248
#      if ($form->{"unit_old_$i"} ne $form->{"selected_unit_$i"}) {
249
#        my $basefactor = 1;
250
#        if (defined($all_units->{$form->{"unit_old_$i"}}->{"factor"}) &&
251
#            $all_units->{$form->{"unit_old_$i"}}->{"factor"}) {
252
#          $basefactor = $all_units->{$form->{"selected_unit_$i"}}->{"factor"} /
253
#            $all_units->{$form->{"unit_old_$i"}}->{"factor"};
254
#        }
255
#        $form->{"sellprice_$i"} *= $basefactor;
256
#        $form->{"unit_old_$i"} = $form->{"selected_unit_$i"};
257
#      }
258
#    }
259
#
260
#    ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
261
#    $decimalplaces = max length($dec), 2;
262
#
263
#    $price_factor = $price_factors{$form->{"price_factor_id_$i"}} || 1;
264
#    $discount     = (100 - $form->{"discount_$i"} * 1) / 100;
265
#
266
#    $linetotal    = $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"} * $discount / $price_factor, $decimalplaces);
267
#
268
#    my $real_sellprice = $form->{"sellprice_$i"} * $discount / $price_factor;
269
#
270
#    # marge calculations
271
#    my ($marge_font_start, $marge_font_end);
272
#
273
#    $form->{"lastcost_$i"} *= 1;
274
#
275
#    $marge_price_factor = $form->{"marge_price_factor_$i"} * 1 || 1;
276
#
277
#    if ($real_sellprice && ($form->{"qty_$i"} * 1)) {
278
#      $form->{"marge_percent_$i"}     = ($real_sellprice - $form->{"lastcost_$i"} / $marge_price_factor) * 100 / $real_sellprice;
279
#      $myconfig{"marge_percent_warn"} = 15 unless (defined($myconfig{"marge_percent_warn"}));
280
#
281
#      if ($form->{"id_$i"} &&
282
#          ($form->{"marge_percent_$i"} < (1 * $myconfig{"marge_percent_warn"}))) {
283
#        $marge_font_start = "<font color=\"#ff0000\">";
284
#        $marge_font_end   = "</font>";
285
#      }
286
#
287
#    } else {
288
#      $form->{"marge_percent_$i"} = 0;
289
#    }
290
#
291
#    my $marge_adjust_credit_note = $form->{type} eq 'credit_note' ? -1 : 1;
292
#    $form->{"marge_total_$i"}  = ($real_sellprice - $form->{"lastcost_$i"} / $marge_price_factor) * $form->{"qty_$i"} * $marge_adjust_credit_note;
293
#    $form->{"marge_total"}      += $form->{"marge_total_$i"};
294
#    $form->{"lastcost_total"}   += $form->{"lastcost_$i"} * $form->{"qty_$i"} / $marge_price_factor;
295
#    $form->{"sellprice_total"}  += $real_sellprice * $form->{"qty_$i"};
296
#
297
#    map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) } qw(marge_total marge_percent);
298
#
299
#    # convert " to &quot;
300
#    map { $form->{"${_}_$i"} =~ s/\"/&quot;/g }
301
#      qw(partnumber description unit unit_old);
302
#
303
#########################################
304
#    # Eintrag fuer Version 2.2.0 geaendert #
305
#    # neue Optik im Rechnungsformular      #
306
#########################################
307
#    $column_data{runningnumber} =
308
#      qq|<td><input name="runningnumber_$i" size="5" value="$i"></td>|;    # HuT
309
############### ENDE Neueintrag ##################
310
#
311
#    $column_data{partnumber} =
312
#      qq|<td><input name="partnumber_$i" size=12 value="$form->{"partnumber_$i"}"></td>|;
313
#
314
#    if (($rows = $form->numtextrows($form->{"description_$i"}, 30, 6)) > 1) {
315
#      $column_data{description} =
316
#        qq|<td><textarea name="description_$i" rows="$rows" cols="30" wrap="soft">| . H($form->{"description_$i"}) . qq|</textarea><button type="button" onclick="set_longdescription_window('longdescription_$i')">| . $locale->text('L') . qq|</button></td>|;
317
#    } else {
318
#      $column_data{description} =
319
#        qq|<td><input name="description_$i" size="30" value="| . $form->quote($form->{"description_$i"}) . qq|"><button type="button" onclick="set_longdescription_window('longdescription_$i')">| . $locale->text('L') . qq|</button></td>|;
320
#    }
321
#
322
#    (my $qty_dec) = ($form->{"qty_$i"} =~ /\.(\d+)/);
323
#    $qty_dec = length $qty_dec;
324
#
325
#    $column_data{qty} =
326
#        qq|<td align="right"><input name="qty_$i" size="5" value="|
327
#      . $form->format_amount(\%myconfig, $form->{"qty_$i"}, $qty_dec) .qq|">|;
328
#    if ($form->{"formel_$i"}) {
329
#      $column_data{qty} .= qq|<button type="button" onclick="calculate_qty_selection_window('qty_$i','alu_$i', 'formel_$i', $i)">| . $locale->text('*/') . qq|</button>|
330
#        . $cgi->hidden("-name" => "formel_$i", "-value" => $form->{"formel_$i"}) . $cgi->hidden("-name" => "alu_$i", "-value" => $form->{"alu_$i"});
331
#    }
332
#    $column_data{qty} .= qq|</td>|;
333
#    $column_data{ship} =
334
#        qq|<td align="right"><input name="ship_$i" size=5 value="|
335
#      . $form->format_amount(\%myconfig, $form->{"ship_$i"})
336
#      . qq|"></td>|;
337
#
338
#    my $is_part     = $form->{"inventory_accno_$i"};
339
#    my $is_assembly = $form->{"assembly_$i"};
340
#    my $is_assigned = $form->{"id_$i"};
341
#    my $this_unit = $form->{"unit_$i"};
342
#    if ($form->{"selected_unit_$i"} && $this_unit &&
343
#        $all_units->{$form->{"selected_unit_$i"}} && $all_units->{$this_unit} &&
344
#        ($all_units->{$form->{"selected_unit_$i"}}->{"base_unit"} eq $all_units->{$this_unit}->{"base_unit"})) {
345
#      $this_unit = $form->{"selected_unit_$i"};
346
#    } elsif (!$is_assigned ||
347
#             ($is_part && !$this_unit && ($all_units->{$this_unit} && ($all_units->{$this_unit}->{"base_unit"} eq $all_units->{"kg"}->{"base_unit"})))) {
348
#      $this_unit = "kg";
349
#    }
350
#
351
#    my $price_factor_select;
352
#    if (0 < scalar @{ $form->{ALL_PRICE_FACTORS} }) {
353
#      my @values = ('', map { $_->{id}                      } @{ $form->{ALL_PRICE_FACTORS} });
354
#      my %labels =      map { $_->{id} => $_->{description} } @{ $form->{ALL_PRICE_FACTORS} };
355
#
356
#      $price_factor_select =
357
#        NTI($cgi->popup_menu('-name'    => "price_factor_id_$i",
358
#                             '-default' => $form->{"price_factor_id_$i"},
359
#                             '-values'  => \@values,
360
#                             '-labels'  => \%labels,
361
#                             '-style'   => 'width:90px'))
362
#        . ' ';
363
#    }
364
#
365
#    $column_data{"unit"} = "<td>" .
366
#      $price_factor_select .
367
#       AM->unit_select_html($is_part || $is_assembly ? $dimension_units :
368
#                            $is_assigned ? $service_units : $all_units,
369
#                            "unit_$i", $this_unit,
370
#                            $is_assigned ? $form->{"unit_$i"} : undef)
371
#      . "</td>";
372
#
373
#    # build in drop down list for pricesgroups
374
#    if ($form->{"prices_$i"}) {
375
#      if  ($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"}) {
376
#        $price_tmp = $form->format_amount(\%myconfig, $form->{"price_new_$i"}, $decimalplaces);
377
#      } else {
378
#        $price_tmp = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
379
#      }
380
#
381
#      $column_data{sellprice_pg} =
382
#      qq|<td align="right"><select name="sellprice_pg_$i">$form->{"prices_$i"}</select></td>|;
383
#      $column_data{sellprice} =
384
#      qq|<td><input name="sellprice_$i" size="10" value="$price_tmp" onBlur=\"check_right_number_format(this)\"></td>|;
385
#    } else {
386
#
387
#      # for last row and report
388
#      # set pricegroup drop down list from report menu
389
#      if ($form->{"sellprice_$i"} != 0) {
390
#        $prices =
391
#          qq|<option value="$form->{"sellprice_$i"}--$form->{"pricegroup_id_$i"}" selected>$form->{"pricegroup_$i"}</option>\n|;
392
#
393
#        $form->{"pricegroup_old_$i"} = $form->{"pricegroup_id_$i"};
394
#
395
#        $column_data{sellprice_pg} =
396
#          qq|<td align="right"><select name="sellprice_pg_$i">$prices</select></td>|;
397
#
398
#      } else {
399
#
400
#        # for last row
401
#        $column_data{sellprice_pg} = qq|<td align="right">&nbsp;</td>|;
402
#        }
403
#        
404
#      $column_data{sellprice} =
405
#      qq|<td><input name="sellprice_$i" size="10" onBlur=\"check_right_number_format(this)\" value="|
406
#        . $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
407
#                               $decimalplaces)
408
#        . qq|"></td>|;
409
#    }
410
#    $column_data{discount} =
411
#        qq|<td align="right"><input name="discount_$i" size=3 value="|
412
#      . $form->format_amount(\%myconfig, $form->{"discount_$i"})
413
#      . qq|"></td>|;
414
#    $column_data{linetotal} =
415
#        qq|<td align="right">|
416
#      . $form->format_amount(\%myconfig, $linetotal, 2)
417
#      . qq|</td>|;
418
#    $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
419
#
420
#########################################
421
#    # Eintrag fuer Version 2.2.0 geaendert #
422
#    # neue Optik im Rechnungsformular      #
423
#########################################
424
#    #     if ($lizenzen &&  $form->{type} eq "invoice" &&  $form->{vc} eq "customer") {
425
#    #     $column_data{license} = qq|<td><select name="licensenumber_$i">$form->{"lizenzen_$i"}></select></td>|;
426
#    #     }
427
#    #
428
#    #     if ($form->{type} !~ /_quotation/) {
429
#    #     $column_data{serialnr} = qq|<td><input name="serialnumber_$i" size=10 value="$form->{"serialnumber_$i"}"></td>|;
430
#    #     }
431
#    #
432
#    #     $column_data{projectnr} = qq|<td><input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}"></td>|;
433
############### ENDE Neueintrag ##################
434
#    my $j = $i % 2;
435
#    print qq|
436
#
437
#        <tr valign="top" class="listrow$j">|;
438
#
439
#    map { print "\n$column_data{$_}" } @column_index;
440
#
441
#    print("</tr>\n" .
442
#          $cgi->hidden("-name" => "unit_old_$i",
443
#                       "-value" => $form->{"selected_unit_$i"})
444
#          . "\n" .
445
#          $cgi->hidden("-name" => "price_new_$i",
446
#                       "-value" => $form->format_amount(\%myconfig, $form->{"price_new_$i"}))
447
#          . "\n");
448
#    map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_}) . "\n"); }
449
#        ("orderitems_id_$i", "bo_$i", "pricegroup_old_$i", "price_old_$i",
450
#         "id_$i", "inventory_accno_$i", "bin_$i", "partsgroup_$i", "partnotes_$i",
451
#         "income_accno_$i", "expense_accno_$i", "listprice_$i", "assembly_$i",
452
#         "taxaccounts_$i", "ordnumber_$i", "transdate_$i", "cusordnumber_$i",
453
#         "longdescription_$i", "basefactor_$i", "marge_total_$i", "marge_percent_$i", "lastcost_$i",
454
#         "marge_price_factor_$i"));
455
#
456
#########################################
457
#    # Eintrag fuer Version 2.2.0 geaendert #
458
#    # neue Optik im Rechnungsformular      #
459
#########################################
460
#
461
#    my $row_style_attr =
462
#      'style="display:none;"' if (!$form->{"show_details"});
463
#
464
#    # print second row
465
#    print qq|
466
#        <tr  class="listrow$j" $row_style_attr>
467
#	  <td colspan="$colspan">
468
#|;
469
#    if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
470
#      my $selected = $form->{"licensenumber_$i"};
471
#      my $lizenzen_quoted;
472
#      $form->{"lizenzen_$i"} =~ s/ selected//g;
473
#      $form->{"lizenzen_$i"} =~
474
#        s/value="${selected}"\>/value="${selected}" selected\>/;
475
#      $lizenzen_quoted = $form->{"lizenzen_$i"};
476
#      $lizenzen_quoted =~ s/\"/&quot;/g;
477
#      print qq|
478
#	<b>Lizenz\#</b>&nbsp;<select name="licensenumber_$i" size="1">
479
#	$form->{"lizenzen_$i"}
480
#        </select>
481
#	<input type="hidden" name="lizenzen_$i" value="${lizenzen_quoted}">
482
#|;
483
#    }
484
#    if ($form->{type} !~ /_quotation/) {
485
#      print qq|
486
#          <b>$serialnumber</b>&nbsp;<input name="serialnumber_$i" size="15" value="$form->{"serialnumber_$i"}">|;
487
#    }
488
#
489
#    print qq|<b>$projectnumber</b>&nbsp;| .
490
#      NTI($cgi->popup_menu('-name' => "project_id_$i",
491
#                           '-values' => \@projectnumber_values,
492
#                           '-labels' => \%projectnumber_labels,
493
#                           '-default' => $form->{"project_id_$i"}));
494
#
495
#    if ($form->{type} eq 'invoice' or $form->{type} =~ /order/) {
496
#      my $reqdate_term =
497
#        ($form->{type} eq 'invoice')
498
#        ? 'deliverydate'
499
#        : 'reqdate';    # invoice uses a different term for the same thing.
500
#      print qq|
501
#        <b>${$reqdate_term}</b>&nbsp;<input name="${reqdate_term}_$i" size="11" onBlur="check_right_date_format(this)" value="$form->{"${reqdate_term}_$i"}">
502
#|;
503
#    }
504
#    my $subtotalchecked = ($form->{"subtotal_$i"}) ? "checked" : "";
505
#    print qq|
506
#          <b>|.$locale->text('Subtotal').qq|</b>&nbsp;<input type="checkbox" name="subtotal_$i" value="1" $subtotalchecked>
507
#|;
508
#
509
#    if ($form->{"id_$i"} && $is_sales) {
510
#      my $marge_price_factor;
511
#
512
#      $form->{"marge_price_factor_$i"} *= 1;
513
#
514
#      if ($form->{"marge_price_factor_$i"} && (1 != $form->{"marge_price_factor_$i"})) {
515
#        $marge_price_factor = '/' . $form->format_amount(\%myconfig, $form->{"marge_price_factor_$i"});
516
#      }
517
#
518
#      print qq|
519
#          ${marge_font_start}<b>| . $locale->text('Ertrag') . qq|</b>&nbsp;$form->{"marge_total_$i"}&nbsp;$form->{"marge_percent_$i"} % ${marge_font_end}|;
520
#   }
521
#   print qq|
522
#          &nbsp;<b>| . $locale->text('LP') . qq|</b>&nbsp;| . $form->format_amount(\%myconfig, $form->{"listprice_$i"}, 2) . qq|
523
#          &nbsp;<b>| . $locale->text('EK') . qq|</b>&nbsp;| . $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, 2) . $marge_price_factor;
524
#
525
#
526
#    print qq|
527
#	  </td>
528
#	</tr>
529
#|;
530
#
531
############### ENDE Neueintrag ##################
532
#
533
#    map { $form->{"${_}_base"} += $linetotal }
534
#      (split(/ /, $form->{"taxaccounts_$i"}));
535
#
536
#    $form->{invsubtotal} += $linetotal;
537
#  }
538
#
539
#  print qq|
540
#      </table>
541
#    </td>
542
#  </tr>
543
#|;
544
#
545
#  if (0 != ($form->{sellprice_total} * 1)) {
546
#    $form->{marge_percent} = ($form->{sellprice_total} - $form->{lastcost_total}) / $form->{sellprice_total} * 100;
547
#  }
548
#
549
#  $lxdebug->leave_sub();
550
#}
551 551

  
552 552
sub set_pricegroup {
553 553
  $lxdebug->enter_sub();
bin/mozilla/io.pl
90 90
# Eintrag fuer Version 2.2.0 geaendert #
91 91
# neue Optik im Rechnungsformular      #
92 92
########################################
93
sub display_row {
94
  $lxdebug->enter_sub();
95
  my $numrows = shift;
96

  
97
  # column_index
98
  my @header_sort = qw(runningnumber partnumber description ship qty unit sellprice_pg sellprice discount linetotal);
99
  my @HEADER = (
100
    {  id => 'runningnumber', width => 5,     value => $locale->text('No.'),                  display => 1, },
101
    {  id => 'partnumber',    width => 12,    value => $locale->text('Number'),               display => 1, },
102
    {  id => 'description',   width => 30,    value => $locale->text('Part Description'),     display => 1, },
103
    {  id => 'ship',          width => 5,     value => ($form->{type} eq 'purchase_order' ? $locale->text('Ship rcvd') : $locale->text('Ship')),                 
104
       display => $form->{type} =~ /sales_order/ || ($form->{type} =~ /purchase_order/ && !($lizenzen && $form->{vc} eq "customer")) , },
105
    {  id => 'qty',           width => 5,     value => $locale->text('Qty'),                  display => 1, },
106
    {  id => 'unit',          width => 5,     value => $locale->text('Unit'),                 display => 1, },
107
    {  id => 'license',       width => 10,    value => $locale->text('License'),              display => 0, },
108
    {  id => 'serialnr',      width => 10,    value => $locale->text('Serial No.'),           display => 0, },
109
    {  id => 'projectnr',     width => 10,    value => $locale->text('Project'),              display => 0, },
110
    {  id => 'sellprice',     width => 15,    value => $locale->text('Price'),                display => 1, },
111
    {  id => 'sellprice_pg',  width => 15,    value => $locale->text('Pricegroup'),           display => $form->{type} =~ /^sales_/,  },
112
    {  id => 'discount',      width => 5,     value => $locale->text('Discount'),             display => $form->{vc} eq 'customer', },
113
    {  id => 'linetotal',     width => 10,    value => $locale->text('Extended'),             display => 1, },
114
    {  id => 'bin',           width => 10,    value => $locale->text('Bin'),                  display => 0, },
115
  ); 
116
  my @column_index = map { $_->{id} } grep { $_->{display} } @HEADER;
117

  
118
  # cache units
119
  my $dimension_units = AM->retrieve_units(\%myconfig, $form, "dimension");
120
  my $service_units   = AM->retrieve_units(\%myconfig, $form, "service");
121
  my $all_units       = AM->retrieve_units(\%myconfig, $form);
122

  
123
  my $colspan = scalar @column_index;
124

  
125
  $form->{invsubtotal} = 0;
126
  map { $form->{"${_}_base"} = 0 } (split(/ /, $form->{taxaccounts}));
127

  
128
  # about details 
129
  $myconfig{show_form_details} = 1                            unless (defined($myconfig{show_form_details}));
130
  $form->{show_details}        = $myconfig{show_form_details} unless (defined($form->{show_details}));
131
  # /about details
132

  
133
  # translations, unused commented out
134
#  $runningnumber = $locale->text('No.');
135
  $deliverydate  = $locale->text('Delivery Date');
136
  $serialnumber  = $locale->text('Serial No.');
137
  $projectnumber = $locale->text('Project');
138
#  $partsgroup    = $locale->text('Group');
139
  $reqdate       = $locale->text('Reqdate');
140
  $deliverydate  = $locale->text('Required by');
141

  
142
  # special alignings
143
  my %align = map { $_ => 'right' } qw(qty ship right sellprice_pg discount linetotal);
144

  
145
  $form->{marge_total}           = 0;
146
  $form->{sellprice_total}       = 0;
147
  $form->{lastcost_total}        = 0;
148
  my %projectnumber_labels = ();
149
  my @projectnumber_values = ("");
150

  
151
  foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
152
    push(@projectnumber_values, $item->{"id"});
153
    $projectnumber_labels{$item->{"id"}} = $item->{"projectnumber"};
154
  }
155

  
156
  # rows
157
  for $i (1 .. $numrows) {
158

  
159
    # undo formatting
160
    map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(qty ship discount sellprice price_new price_old) unless ($form->{simple_save});
161

  
162
# unit begin
163
    $form->{"unit_old_$i"}      ||= $form->{"unit_$i"};
164
    $form->{"selected_unit_$i"} ||= $form->{"unit_$i"};
165

  
166
    my $local_units = $form->{"inventory_accno_$i"} || $form->{"assembly_$i"} ? $dimension_units 
167
                    : $form->{"id_$i"}                                        ? $service_units 
168
                    :                                                           $all_units;
169
    if (   !$local_units->{$form->{"selected_unit_$i"}}                                          # Die ausgewaehlte Einheit ist fuer diesen Artikel nicht gueltig
170
        || !AM->convert_unit($form->{"selected_unit_$i"}, $form->{"unit_old_$i"}, $all_units)) { # (z.B. Dimensionseinheit war ausgewaehlt, es handelt sich aber
171
      $form->{"unit_old_$i"} = $form->{"selected_unit_$i"} = $form->{"unit_$i"};                 # um eine Dienstleistung). Dann keinerlei Umrechnung vornehmen.
172
    }
173
    # adjust prices by unit, ignore if pricegroup changed
174
    if ((!$form->{"prices_$i"}) || ($form->{"new_pricegroup_$i"} == $form->{"old_pricegroup_$i"})) {
175
        $form->{"sellprice_$i"} *= AM->convert_unit($form->{"selected_unit_$i"}, $form->{"unit_old_$i"}, $all_units) || 1;
176
        $form->{"unit_old_$i"}   = $form->{"selected_unit_$i"};
177
    }
178
    my $this_unit = $form->{"unit_$i"};
179
    $this_unit    = $form->{"selected_unit_$i"} if AM->convert_unit($this_unit, $form->{"selected_unit_$i"}, $all_units);
180
    $this_unit  ||= "kg";
181

  
182
    $column_data{"unit"} = AM->unit_select_html($local_units, "unit_$i", $this_unit, $form->{"id_$i"} ? $form->{"unit_$i"} : undef);
183
# / unit ending
184

  
185
    $form->{"sellprice_$i"} =~ /\.(\d+)/;
186
    $decimalplaces = max 2, length $1;
187

  
188
    $discount  = $form->round_amount($form->{"sellprice_$i"} * $form->{"discount_$i"} / 100, $decimalplaces);
189
    $linetotal = $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
190
    $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
191

  
192
    # convert " to &quot;
193
    map { $form->{"${_}_$i"} =~ s/\"/&quot;/g } qw(partnumber description unit unit_old);
194

  
195
    $column_data{runningnumber} = $cgi->textfield(-name => "runningnumber_$i", -size => 5,  -value => $i);    # HuT
196
    $column_data{partnumber}    = $cgi->textfield(-name => "partnumber_$i",    -size => 12, -value => $form->{"partnumber_$i"});
197
    $column_data{description} = ((($rows = $form->numtextrows($form->{"description_$i"}, 30, 6)) > 1) # if description is too large, use a textbox instead
198
                                ? $cgi->textarea( -name => "description_$i", -default => H($form->{"description_$i"}), -rows => $rows, -columns => 30)
199
                                : $cgi->textfield(-name => "description_$i",   -size => 30, -value => $form->quote($form->{"description_$i"})))
200
                                . $cgi->button(-value => $locale->text('L'), -onClick => "set_longdescription_window('longdescription_$i')");
201

  
202
    $form->{"qty_$i"} =~ /\.(\d+)/;
203
    my $qty_dec = length $1;
204

  
205
    $column_data{qty}  = $cgi->textfield(-name => "qty_$i", -size => 5, -value => $form->format_amount(\%myconfig, $form->{"qty_$i"}, $qty_dec));
206
    $column_data{qty} .= $cgi->button(-onclick => "calculate_qty_selection_window('qty_$i','alu_$i', 'formel_$i', $i)", -value => $locale->text('*/'))
207
                       . $cgi->hidden(-name => "formel_$i", -value => $form->{"formel_$i"}) . $cgi->hidden("-name" => "alu_$i", "-value" => $form->{"alu_$i"})
208
      if $form->{"formel_$i"};
209
    $column_data{ship} = $cgi->textfield(-name => "ship_$i", -size => 5, -value => $form->format_amount(\%myconfig, $form->{"ship_$i"}));
210

  
211
    # build in drop down list for pricesgroups
212
    if ($form->{"prices_$i"}) {
213
      $column_data{sellprice_pg} = qq|<select name="sellprice_pg_$i">$form->{"prices_$i"}</select>|;
214
      $column_data{sellprice}    = $cgi->textfield(-name => "sellprice_$i", -size => 10, -onBlur => 'check_right_number_format(this)', -value =>
215
                                   (($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"})
216
                                      ? $form->format_amount(\%myconfig, $form->{"price_new_$i"}, $decimalplaces)
217
                                      : $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces)));
218
    } else {
219
      # for last row and report
220
      # set pricegroup drop down list from report menu
221
      if ($form->{"sellprice_$i"} != 0) {
222
        $form->{"pricegroup_old_$i"} = $form->{"pricegroup_id_$i"};
223
        my $default_option           = $form->{"sellprice_$i"}.'--'.$form->{"pricegroup_id_$i"};
224
        $column_data{sellprice_pg}   = NTI($cgi->popup_menu("sellpricepg_$i", [ $default_option ], $default_option, { $default_option => $form->{"pricegroup_$i"} || '' }));
225
      } else {
226
        $column_data{sellprice_pg} = qq|&nbsp;|;
227
      }
228
      $column_data{sellprice} = $cgi->textfield(-name => "sellprice_$i", -size => 10, -onBlur => "check_right_number_format(this)", -value =>
229
                                                $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces));
230
    }
231
    $column_data{discount}    = $cgi->textfield(-name => "discount_$i", -size => 3, -value => $form->format_amount(\%myconfig, $form->{"discount_$i"}));
232
    $column_data{linetotal}   = $form->format_amount(\%myconfig, $linetotal, 2);
233
    $column_data{bin}         = $form->{"bin_$i"};
234

  
235
    my @ROW1 = map { value => $column_data{$_}, align => $align{$_} }, @column_index;
236

  
237
    # second row
238
    my @ROW2 = ();
239
    push @ROW2, { value => qq|<b>$serialnumber</b> <input name="serialnumber_$i" size="15" value="$form->{"serialnumber_$i"}">| } 
240
      if $form->{type} !~ /_quotation/;
241
    push @ROW2, { value => qq|<b>$projectnumber</b> | . NTI($cgi->popup_menu('-name'  => "project_id_$i",        '-values'  => \@projectnumber_values,
242
                                                                             '-labels' => \%projectnumber_labels, '-default' => $form->{"project_id_$i"})) };
243
    push @ROW2, { value => qq|<b>$reqdate</b> <input name="reqdate_$i" size="11" onBlur="check_right_date_format(this)" value="$form->{"reqdate_$i"}">| }
244
      if $form->{type} =~ /order/;
245
    push @ROW2, { value => sprintf qq|<b>%s</b>&nbsp;<input type="checkbox" name="subtotal_$i" value="1" %s>|, 
246
                   $locale->text('Subtotal'), $form->{"subtotal_$i"} ? 'checked' : '' };
247

  
248
# begin marge calculations
249
    my $marge_color;
250
    my $real_sellprice = $form->{"sellprice_$i"} - $discount;
251

  
252
    $form->{"lastcost_$i"} *= 1;
253
    $form->{"marge_percent_$i"} = 0;
254

  
255
    if ($real_sellprice && ($form->{"qty_$i"} * 1)) {
256
      $form->{"marge_percent_$i"}     = ($real_sellprice - $form->{"lastcost_$i"}) * 100 / $real_sellprice;
257
      $myconfig{marge_percent_warn} ||= 15;
258
      $marge_color                    = 'color="#ff0000"' if $form->{"id_$i"} && ($form->{"marge_percent_$i"} < (1 * $myconfig{marge_percent_warn}));
259
    }
260

  
261
    my $marge_adjust_credit_note = $form->{type} eq 'credit_note' ? -1 : 1;
262
    $form->{"marge_absolut_$i"}  = ($real_sellprice - $form->{"lastcost_$i"}) * $form->{"qty_$i"} * $marge_adjust_credit_note;
... Dieser Diff wurde abgeschnitten, weil er die maximale Anzahl anzuzeigender Zeilen überschreitet.

Auch abrufbar als: Unified diff