Trennung zwischen Dienstleistungs- und Wareneinheiten aufgehoben.
[kivitendo-erp.git] / bin / mozilla / invoice_io.pl
1 #=====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2004
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #############################################################################
7 # Veraendert 2005-01-05 - Marco Welter <mawe@linux-studio.de> - Neue Optik  #
8 #############################################################################
9 # SQL-Ledger, Accounting
10 # Copyright (c) 1998-2002
11 #
12 #  Author: Dieter Simader
13 #   Email: dsimader@sql-ledger.org
14 #     Web: http://www.sql-ledger.org
15 #
16 #
17 # This program is free software; you can redistribute it and/or modify
18 # it under the terms of the GNU General Public License as published by
19 # the Free Software Foundation; either version 2 of the License, or
20 # (at your option) any later version.
21 #
22 # This program is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25 # GNU General Public License for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the Free Software
28 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #
30 #######################################################################
31 #
32 # common routines used in is, ir but not in oe
33 #
34 #######################################################################
35
36 use CGI;
37 use CGI::Ajax;
38 use List::Util qw(max);
39
40 use SL::Common;
41 use SL::CT;
42 use SL::IC;
43
44 require "bin/mozilla/common.pl";
45
46 # any custom scripts for this one
47 if (-f "bin/mozilla/custom_invoice_io.pl") {
48   eval { require "bin/mozilla/custom_ivvoice_io.pl"; };
49 }
50 if (-f "bin/mozilla/$form->{login}_invoice_io.pl") {
51   eval { require "bin/mozilla/$form->{login}_invoice_io.pl"; };
52 }
53
54 1;
55
56 # end of main
57
58 # this is for our long dates
59 # $locale->text('January')
60 # $locale->text('February')
61 # $locale->text('March')
62 # $locale->text('April')
63 # $locale->text('May ')
64 # $locale->text('June')
65 # $locale->text('July')
66 # $locale->text('August')
67 # $locale->text('September')
68 # $locale->text('October')
69 # $locale->text('November')
70 # $locale->text('December')
71
72 # this is for our short month
73 # $locale->text('Jan')
74 # $locale->text('Feb')
75 # $locale->text('Mar')
76 # $locale->text('Apr')
77 # $locale->text('May')
78 # $locale->text('Jun')
79 # $locale->text('Jul')
80 # $locale->text('Aug')
81 # $locale->text('Sep')
82 # $locale->text('Oct')
83 # $locale->text('Nov')
84 # $locale->text('Dec')
85 use SL::IS;
86 use SL::PE;
87 use SL::AM;
88 use Data::Dumper;
89 ########################################
90 # Eintrag fuer Version 2.2.0 geaendert #
91 # neue Optik im Rechnungsformular      #
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 $all_units = AM->retrieve_units(\%myconfig, $form);
121 #  my $dimension_units = $all_units;
122 #  my $service_units = $all_units;
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
552 sub set_pricegroup {
553   $lxdebug->enter_sub();
554   my $rowcount = shift;
555   for $j (1 .. $rowcount) {
556     my $pricegroup_old = $form->{"pricegroup_old_$i"};
557     if ($form->{PRICES}{$j}) {
558       $len    = 0;
559       $prices = '<option value="--">' . $locale->text("none (pricegroup)") . '</option>';
560       $price  = 0;
561       foreach $item (@{ $form->{PRICES}{$j} }) {
562
563         #$price = $form->round_amount($myconfig,  $item->{price}, 5);
564         #$price = $form->format_amount($myconfig, $item->{price}, 2);
565         $price         = $item->{price};
566         $pricegroup_id = $item->{pricegroup_id};
567         $pricegroup    = $item->{pricegroup};
568
569         # build drop down list for pricegroups
570         $prices .=
571           qq|<option value="$price--$pricegroup_id"$item->{selected}>$pricegroup</option>\n|;
572
573         $len += 1;
574
575         #        map {
576         #               $form->{"${_}_$j"} =
577         #               $form->format_amount(\%myconfig, $form->{"${_}_$j"})
578         #              } qw(sellprice price_new price_old);
579
580         # set new selectedpricegroup_id and prices for "Preis"
581         if ($item->{selected} && ($pricegroup_id != 0)) {
582           $form->{"pricegroup_old_$j"} = $pricegroup_id;
583           $form->{"price_new_$j"}      = $price;
584           $form->{"sellprice_$j"}      = $price;
585         }
586         if ($pricegroup_id == 0) {
587           $form->{"price_new_$j"} = $form->{"sellprice_$j"};
588         }
589       }
590       $form->{"prices_$j"} = $prices;
591     }
592   }
593   $lxdebug->leave_sub();
594 }
595
596 sub display_form {
597   $lxdebug->enter_sub();
598
599   $auth->assert('part_service_assembly_edit | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
600                 'request_quotation_edit     | sales_quotation_edit | purchase_order_edit');
601
602   relink_accounts();
603   retrieve_partunits() if ($form->{type} =~ /_delivery_order$/);
604
605   my $new_rowcount = $form->{"rowcount"} * 1 + 1;
606   $form->{"project_id_${new_rowcount}"} = $form->{"globalproject_id"};
607
608   $form->language_payment(\%myconfig);
609
610   # if we have a display_form
611   if ($form->{display_form}) {
612     call_sub($form->{"display_form"});
613     exit;
614   }
615
616   Common::webdav_folder($form) if ($webdav);
617
618   #   if (   $form->{print_and_post}
619   #       && $form->{second_run}
620   #       && ($form->{action} eq "display_form")) {
621   #     for (keys %$form) { $old_form->{$_} = $form->{$_} }
622   #     $old_form->{rowcount}++;
623   #
624   #     #$form->{rowcount}--;
625   #     #$form->{rowcount}--;
626   #
627   #     $form->{print_and_post} = 0;
628   #
629   #     &print_form($old_form);
630   #     exit;
631   #   }
632   #
633   #   $form->{action}   = "";
634   #   $form->{resubmit} = 0;
635   #
636   #   if ($form->{print_and_post} && !$form->{second_run}) {
637   #     $form->{second_run} = 1;
638   #     $form->{action}     = "display_form";
639   #     $form->{rowcount}--;
640   #     my $rowcount = $form->{rowcount};
641   #
642   #     # get pricegroups for parts
643   #     IS->get_pricegroups_for_parts(\%myconfig, \%$form);
644   #
645   #     # build up html code for prices_$i
646   #     set_pricegroup($rowcount);
647   #
648   #     $form->{resubmit} = 1;
649   #
650   #   }
651   &form_header;
652
653   $numrows    = ++$form->{rowcount};
654   $subroutine = "display_row";
655
656   if ($form->{item} eq 'part') {
657
658     #set preisgruppenanzahl
659     $numrows    = $form->{price_rows};
660     $subroutine = "price_row";
661
662     &{$subroutine}($numrows);
663
664     $numrows    = 0;
665   }
666   if ($form->{item} eq 'assembly') {
667     $numrows    = $form->{price_rows};
668     $subroutine = "price_row";
669
670     &{$subroutine}($numrows);
671
672     $numrows    = ++$form->{makemodel_rows};
673     $subroutine = "makemodel_row";
674
675     # create makemodel rows
676     &{$subroutine}($numrows);
677
678     $numrows    = ++$form->{assembly_rows};
679     $subroutine = "assembly_row";
680   }
681   if ($form->{item} eq 'service') {
682     $numrows    = $form->{price_rows};
683     $subroutine = "price_row";
684
685     &{$subroutine}($numrows);
686
687     $numrows = 0;
688   }
689
690   # create rows
691   &{$subroutine}($numrows) if $numrows;
692
693   &form_footer;
694
695   $lxdebug->leave_sub();
696 }