invoice_io strict
[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 use strict;
47
48 # any custom scripts for this one
49 if (-f "bin/mozilla/custom_invoice_io.pl") {
50   eval { require "bin/mozilla/custom_ivvoice_io.pl"; };
51 }
52 if (-f "bin/mozilla/$main::form->{login}_invoice_io.pl") {
53   eval { require "bin/mozilla/$main::form->{login}_invoice_io.pl"; };
54 }
55
56 1;
57
58 # end of main
59
60 # this is for our long dates
61 # $locale->text('January')
62 # $locale->text('February')
63 # $locale->text('March')
64 # $locale->text('April')
65 # $locale->text('May ')
66 # $locale->text('June')
67 # $locale->text('July')
68 # $locale->text('August')
69 # $locale->text('September')
70 # $locale->text('October')
71 # $locale->text('November')
72 # $locale->text('December')
73
74 # this is for our short month
75 # $locale->text('Jan')
76 # $locale->text('Feb')
77 # $locale->text('Mar')
78 # $locale->text('Apr')
79 # $locale->text('May')
80 # $locale->text('Jun')
81 # $locale->text('Jul')
82 # $locale->text('Aug')
83 # $locale->text('Sep')
84 # $locale->text('Oct')
85 # $locale->text('Nov')
86 # $locale->text('Dec')
87 use SL::IS;
88 use SL::PE;
89 use SL::AM;
90 use Data::Dumper;
91 ########################################
92 # Eintrag fuer Version 2.2.0 geaendert #
93 # neue Optik im Rechnungsformular      #
94 ########################################
95 #sub display_row {
96 #  $main::lxdebug->enter_sub();
97 #  my $numrows = shift;
98 #
99 #  my $is_sales =
100 #    (substr($form->{type}, 0, 6) eq "sales_")
101 #    || (($form->{type} eq "invoice") && ($form->{script} eq "is.pl"))
102 #    || ($form->{type} eq 'credit_note');
103 #
104 #  if ($lizenzen && $form->{vc} eq "customer") {
105 #    if ($form->{type} =~ /sales_order/) {
106 #      @column_index = (runningnumber, partnumber, description, ship, qty);
107 #    } elsif ($form->{type} =~ /sales_quotation/) {
108 #      @column_index = (runningnumber, partnumber, description, qty);
109 #    } else {
110 #      @column_index = (runningnumber, partnumber, description, qty);
111 #    }
112 #  } else {
113 #    if (   ($form->{type} =~ /purchase_order/)
114 #        || ($form->{type} =~ /sales_order/)) {
115 #      @column_index = (runningnumber, partnumber, description, ship, qty);
116 #        } else {
117 #      @column_index = (runningnumber, partnumber, description, qty);
118 #    }
119 #  }
120 ############### ENDE Neueintrag ##################
121 #
122 #  my $all_units = AM->retrieve_units(\%myconfig, $form);
123 #  my $dimension_units = $all_units;
124 #  my $service_units = $all_units;
125 #
126 #  my %price_factors = map { $_->{id} => $_->{factor} } @{ $form->{ALL_PRICE_FACTORS} };
127 #
128 #  push @column_index, qw(unit);
129 #
130 #  #for pricegroups column
131 #  if (   $form->{type} =~ (/sales_quotation/)
132 #      or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/))
133 #      or (($form->{level} eq undef) and ($form->{type} =~ /invoice/))
134 #      or ($form->{type} =~ /sales_order/)) {
135 #    push @column_index, qw(sellprice_pg);
136 #  }
137 #
138 #  push @column_index, qw(sellprice);
139 #
140 #  if ($form->{vc} eq 'customer') {
141 #    push @column_index, qw(discount);
142 #  }
143 #
144 #  push @column_index, "linetotal";
145 #
146 #  my $colspan = $#column_index + 1;
147 #
148 #  $form->{invsubtotal} = 0;
149 #  map { $form->{"${_}_base"} = 0 } (split(/ /, $form->{taxaccounts}));
150 #
151 #########################################
152 #  # Eintrag fuer Version 2.2.0 geaendert #
153 #  # neue Optik im Rechnungsformular      #
154 #########################################
155 #  $column_data{runningnumber} = qq|<th align="left" nowrap width="5%"  class="listheading">| . $locale->text('No.') .         qq|</th>|;
156 #  $column_data{partnumber}    = qq|<th align="left" nowrap width="12%" class="listheading">| . $locale->text('Number') .      qq|</th>|;
157 #  $column_data{description}   = qq|<th align="left" nowrap width="30%" class="listheading">| . $locale->text('Part Description') . qq|</th>|;
158 #  if ($form->{"type"} eq "purchase_order") {
159 #    $column_data{ship}        = qq|<th align="left" nowrap width="5%"  class="listheading">| . $locale->text('Ship rcvd') .   qq|</th>|;
160 #  } else {
161 #    $column_data{ship}        = qq|<th align="left" nowrap width="5%"  class="listheading">| . $locale->text('Ship') .        qq|</th>|;
162 #  }
163 #  $column_data{qty}           = qq|<th align="left" nowrap width="5%"  class="listheading">| . $locale->text('Qty') .         qq|</th>|;
164 #  $column_data{unit}          = qq|<th align="left" nowrap width="20%" class="listheading">| . $locale->text('Unit') .        qq|</th>|;
165 #  $column_data{license}       = qq|<th align="left" nowrap width="10%" class="listheading">| . $locale->text('License') .     qq|</th>|;
166 #  $column_data{serialnr}      = qq|<th align="left" nowrap width="10%" class="listheading">| . $locale->text('Serial No.') .  qq|</th>|;
167 #  $column_data{projectnr}     = qq|<th align="left" nowrap width="10%" class="listheading">| . $locale->text('Project') .     qq|</th>|;
168 #  $column_data{sellprice}     = qq|<th align="left" nowrap width="15%" class="listheading">| . $locale->text('Price') .       qq|</th>|;
169 #  $column_data{sellprice_pg}  = qq|<th align="left" nowrap width="15%" class="listheading">| . $locale->text('Pricegroup') .  qq|</th>|;
170 #  $column_data{discount}      = qq|<th align="left" nowrap width="5%"  class="listheading">| . $locale->text('Discount') .    qq|</th>|;
171 #  $column_data{linetotal}     = qq|<th align="left" nowrap width="10%" class="listheading">| . $locale->text('Extended') .    qq|</th>|;
172 #  $column_data{bin}           = qq|<th align="left" nowrap width="10%" class="listheading">| . $locale->text('Bin') .         qq|</th>|;
173 ############### ENDE Neueintrag ##################
174 #
175 #  $myconfig{"show_form_details"} = 1
176 #    unless (defined($myconfig{"show_form_details"}));
177 #  $form->{"show_details"} = $myconfig{"show_form_details"}
178 #    unless (defined($form->{"show_details"}));
179 #  $form->{"show_details"} = $form->{"show_details"} ? 1 : 0;
180 #  my $show_details_new = 1 - $form->{"show_details"};
181 #  my $show_details_checked = $form->{"show_details"} ? "checked" : "";
182 #
183 #  print qq|
184 #  <tr>
185 #    <td>| . $cgi->hidden("-name" => "show_details", "-value" => $form->{show_details}) . qq|
186 #      <input type="checkbox" id="cb_show_details" onclick="show_form_details($show_details_new);" $show_details_checked>
187 #      <label for="cb_show_details">| . $locale->text("Show details") . qq|</label><br>
188 #      <table width="100%">
189 #       <tr class="listheading">|;
190 #
191 #  map { print "\n$column_data{$_}" } @column_index;
192 #
193 #  print qq|
194 #        </tr>
195 #|;
196 #
197 #  $runningnumber = $locale->text('No.');
198 #  $deliverydate  = $locale->text('Delivery Date');
199 #  $serialnumber  = $locale->text('Serial No.');
200 #  $projectnumber = $locale->text('Project');
201 #  $partsgroup    = $locale->text('Group');
202 #  $reqdate       = $locale->text('Reqdate');
203 #
204 #  $delvar = 'deliverydate';
205 #
206 #  if ($form->{type} =~ /_order$/ || $form->{type} =~ /_quotation$/) {
207 #    $deliverydate = $locale->text('Required by');
208 #    $delvar       = 'reqdate';
209 #  }
210 #
211 #  $form->{marge_total} = 0;
212 #  $form->{sellprice_total} = 0;
213 #  $form->{lastcost_total} = 0;
214 #  my %projectnumber_labels = ();
215 #  my @projectnumber_values = ("");
216 #  foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
217 #    push(@projectnumber_values, $item->{"id"});
218 #    $projectnumber_labels{$item->{"id"}} = $item->{"projectnumber"};
219 #  }
220 #
221 #  for $i (1 .. $numrows) {
222 #
223 #    # undo formatting
224 #    map {
225 #      $form->{"${_}_$i"} =
226 #        $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
227 #    } qw(qty ship discount sellprice price_new price_old) unless ($form->{simple_save});
228 #
229 #    if (!$form->{"unit_old_$i"}) {
230 #      # Neue Ware aus der Datenbank. In diesem Fall ist unit_$i die
231 #      # Einheit, wie sie in den Stammdaten hinterlegt wurde.
232 #      # Es sollte also angenommen werden, dass diese ausgewaehlt war.
233 #      $form->{"unit_old_$i"} = $form->{"unit_$i"};
234 #    }
235 #
236 #    # Die zuletzt ausgewaehlte mit der aktuell ausgewaehlten Einheit
237 #    # vergleichen und bei Unterschied den Preis entsprechend umrechnen.
238 #    $form->{"selected_unit_$i"} = $form->{"unit_$i"} unless ($form->{"selected_unit_$i"});
239 #
240 #    my $check_units = $form->{"inventory_accno_$i"} ? $dimension_units : $service_units;
241 #    if (!$check_units->{$form->{"selected_unit_$i"}} ||
242 #        ($check_units->{$form->{"selected_unit_$i"}}->{"base_unit"} ne
243 #         $all_units->{$form->{"unit_old_$i"}}->{"base_unit"})) {
244 #      # Die ausgewaehlte Einheit ist fuer diesen Artikel nicht gueltig
245 #      # (z.B. Dimensionseinheit war ausgewaehlt, es handelt sich aber
246 #      # um eine Dienstleistung). Dann keinerlei Umrechnung vornehmen.
247 #      $form->{"unit_old_$i"} = $form->{"selected_unit_$i"} = $form->{"unit_$i"};
248 #    }
249 #    if ((!$form->{"prices_$i"}) || ($form->{"new_pricegroup_$i"} == $form->{"old_pricegroup_$i"})) {
250 #      if ($form->{"unit_old_$i"} ne $form->{"selected_unit_$i"}) {
251 #        my $basefactor = 1;
252 #        if (defined($all_units->{$form->{"unit_old_$i"}}->{"factor"}) &&
253 #            $all_units->{$form->{"unit_old_$i"}}->{"factor"}) {
254 #          $basefactor = $all_units->{$form->{"selected_unit_$i"}}->{"factor"} /
255 #            $all_units->{$form->{"unit_old_$i"}}->{"factor"};
256 #        }
257 #        $form->{"sellprice_$i"} *= $basefactor;
258 #        $form->{"unit_old_$i"} = $form->{"selected_unit_$i"};
259 #      }
260 #    }
261 #
262 #    ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
263 #    $decimalplaces = max length($dec), 2;
264 #
265 #    $price_factor = $price_factors{$form->{"price_factor_id_$i"}} || 1;
266 #    $discount     = (100 - $form->{"discount_$i"} * 1) / 100;
267 #
268 #    $linetotal    = $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"} * $discount / $price_factor, $decimalplaces);
269 #
270 #    my $real_sellprice = $form->{"sellprice_$i"} * $discount / $price_factor;
271 #
272 #    # marge calculations
273 #    my ($marge_font_start, $marge_font_end);
274 #
275 #    $form->{"lastcost_$i"} *= 1;
276 #
277 #    $marge_price_factor = $form->{"marge_price_factor_$i"} * 1 || 1;
278 #
279 #    if ($real_sellprice && ($form->{"qty_$i"} * 1)) {
280 #      $form->{"marge_percent_$i"}     = ($real_sellprice - $form->{"lastcost_$i"} / $marge_price_factor) * 100 / $real_sellprice;
281 #      $myconfig{"marge_percent_warn"} = 15 unless (defined($myconfig{"marge_percent_warn"}));
282 #
283 #      if ($form->{"id_$i"} &&
284 #          ($form->{"marge_percent_$i"} < (1 * $myconfig{"marge_percent_warn"}))) {
285 #        $marge_font_start = "<font color=\"#ff0000\">";
286 #        $marge_font_end   = "</font>";
287 #      }
288 #
289 #    } else {
290 #      $form->{"marge_percent_$i"} = 0;
291 #    }
292 #
293 #    my $marge_adjust_credit_note = $form->{type} eq 'credit_note' ? -1 : 1;
294 #    $form->{"marge_total_$i"}  = ($real_sellprice - $form->{"lastcost_$i"} / $marge_price_factor) * $form->{"qty_$i"} * $marge_adjust_credit_note;
295 #    $form->{"marge_total"}      += $form->{"marge_total_$i"};
296 #    $form->{"lastcost_total"}   += $form->{"lastcost_$i"} * $form->{"qty_$i"} / $marge_price_factor;
297 #    $form->{"sellprice_total"}  += $real_sellprice * $form->{"qty_$i"};
298 #
299 #    map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) } qw(marge_total marge_percent);
300 #
301 #    # convert " to &quot;
302 #    map { $form->{"${_}_$i"} =~ s/\"/&quot;/g }
303 #      qw(partnumber description unit unit_old);
304 #
305 #########################################
306 #    # Eintrag fuer Version 2.2.0 geaendert #
307 #    # neue Optik im Rechnungsformular      #
308 #########################################
309 #    $column_data{runningnumber} =
310 #      qq|<td><input name="runningnumber_$i" size="5" value="$i"></td>|;    # HuT
311 ############### ENDE Neueintrag ##################
312 #
313 #    $column_data{partnumber} =
314 #      qq|<td><input name="partnumber_$i" size=12 value="$form->{"partnumber_$i"}"></td>|;
315 #
316 #    if (($rows = $form->numtextrows($form->{"description_$i"}, 30, 6)) > 1) {
317 #      $column_data{description} =
318 #        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>|;
319 #    } else {
320 #      $column_data{description} =
321 #        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>|;
322 #    }
323 #
324 #    (my $qty_dec) = ($form->{"qty_$i"} =~ /\.(\d+)/);
325 #    $qty_dec = length $qty_dec;
326 #
327 #    $column_data{qty} =
328 #        qq|<td align="right" nowrap><input name="qty_$i" size="5" value="|
329 #      . $form->format_amount(\%myconfig, $form->{"qty_$i"}, $qty_dec) .qq|">|;
330 #    if ($form->{"formel_$i"}) {
331 #      $column_data{qty} .= qq|<button type="button" onclick="calculate_qty_selection_window('qty_$i','alu_$i', 'formel_$i', $i)">| . $locale->text('*/') . qq|</button>|
332 #        . $cgi->hidden("-name" => "formel_$i", "-value" => $form->{"formel_$i"}) . $cgi->hidden("-name" => "alu_$i", "-value" => $form->{"alu_$i"});
333 #    }
334 #    $column_data{qty} .= qq|</td>|;
335 #    $column_data{ship} =
336 #        qq|<td align="right"><input name="ship_$i" size=5 value="|
337 #      . $form->format_amount(\%myconfig, $form->{"ship_$i"})
338 #      . qq|"></td>|;
339 #
340 #    my $is_part     = $form->{"inventory_accno_$i"};
341 #    my $is_assembly = $form->{"assembly_$i"};
342 #    my $is_assigned = $form->{"id_$i"};
343 #    my $this_unit = $form->{"unit_$i"};
344 #    if ($form->{"selected_unit_$i"} && $this_unit &&
345 #        $all_units->{$form->{"selected_unit_$i"}} && $all_units->{$this_unit} &&
346 #        ($all_units->{$form->{"selected_unit_$i"}}->{"base_unit"} eq $all_units->{$this_unit}->{"base_unit"})) {
347 #      $this_unit = $form->{"selected_unit_$i"};
348 #    } elsif (!$is_assigned ||
349 #             ($is_part && !$this_unit && ($all_units->{$this_unit} && ($all_units->{$this_unit}->{"base_unit"} eq $all_units->{"kg"}->{"base_unit"})))) {
350 #      $this_unit = "kg";
351 #    }
352 #
353 #    my $price_factor_select;
354 #    if (0 < scalar @{ $form->{ALL_PRICE_FACTORS} }) {
355 #      my @values = ('', map { $_->{id}                      } @{ $form->{ALL_PRICE_FACTORS} });
356 #      my %labels =      map { $_->{id} => $_->{description} } @{ $form->{ALL_PRICE_FACTORS} };
357 #
358 #      $price_factor_select =
359 #        NTI($cgi->popup_menu('-name'    => "price_factor_id_$i",
360 #                             '-default' => $form->{"price_factor_id_$i"},
361 #                             '-values'  => \@values,
362 #                             '-labels'  => \%labels,
363 #                             '-style'   => 'width:90px'))
364 #        . ' ';
365 #    }
366 #
367 #    $column_data{"unit"} = "<td>" .
368 #      $price_factor_select .
369 #       AM->unit_select_html($is_part || $is_assembly ? $dimension_units :
370 #                            $is_assigned ? $service_units : $all_units,
371 #                            "unit_$i", $this_unit,
372 #                            $is_assigned ? $form->{"unit_$i"} : undef)
373 #      . "</td>";
374 #
375 #    # build in drop down list for pricesgroups
376 #    if ($form->{"prices_$i"}) {
377 #      if  ($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"}) {
378 #        $price_tmp = $form->format_amount(\%myconfig, $form->{"price_new_$i"}, $decimalplaces);
379 #      } else {
380 #        $price_tmp = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
381 #      }
382 #
383 #      $column_data{sellprice_pg} =
384 #      qq|<td align="right"><select name="sellprice_pg_$i">$form->{"prices_$i"}</select></td>|;
385 #      $column_data{sellprice} =
386 #      qq|<td><input name="sellprice_$i" size="10" value="$price_tmp" onBlur=\"check_right_number_format(this)\"></td>|;
387 #    } else {
388 #
389 #      # for last row and report
390 #      # set pricegroup drop down list from report menu
391 #      if ($form->{"sellprice_$i"} != 0) {
392 #        $prices =
393 #          qq|<option value="$form->{"sellprice_$i"}--$form->{"pricegroup_id_$i"}" selected>$form->{"pricegroup_$i"}</option>\n|;
394 #
395 #        $form->{"pricegroup_old_$i"} = $form->{"pricegroup_id_$i"};
396 #
397 #        $column_data{sellprice_pg} =
398 #          qq|<td align="right"><select name="sellprice_pg_$i">$prices</select></td>|;
399 #
400 #      } else {
401 #
402 #        # for last row
403 #        $column_data{sellprice_pg} = qq|<td align="right">&nbsp;</td>|;
404 #        }
405 #
406 #      $column_data{sellprice} =
407 #      qq|<td><input name="sellprice_$i" size="10" onBlur=\"check_right_number_format(this)\" value="|
408 #        . $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
409 #                               $decimalplaces)
410 #        . qq|"></td>|;
411 #    }
412 #    $column_data{discount} =
413 #        qq|<td align="right"><input name="discount_$i" size=3 value="|
414 #      . $form->format_amount(\%myconfig, $form->{"discount_$i"})
415 #      . qq|"></td>|;
416 #    $column_data{linetotal} =
417 #        qq|<td align="right">|
418 #      . $form->format_amount(\%myconfig, $linetotal, 2)
419 #      . qq|</td>|;
420 #    $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
421 #
422 #########################################
423 #    # Eintrag fuer Version 2.2.0 geaendert #
424 #    # neue Optik im Rechnungsformular      #
425 #########################################
426 #    #     if ($lizenzen &&  $form->{type} eq "invoice" &&  $form->{vc} eq "customer") {
427 #    #     $column_data{license} = qq|<td><select name="licensenumber_$i">$form->{"lizenzen_$i"}></select></td>|;
428 #    #     }
429 #    #
430 #    #     if ($form->{type} !~ /_quotation/) {
431 #    #     $column_data{serialnr} = qq|<td><input name="serialnumber_$i" size=10 value="$form->{"serialnumber_$i"}"></td>|;
432 #    #     }
433 #    #
434 #    #     $column_data{projectnr} = qq|<td><input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}"></td>|;
435 ############### ENDE Neueintrag ##################
436 #    my $j = $i % 2;
437 #    print qq|
438 #
439 #        <tr valign="top" class="listrow$j">|;
440 #
441 #    map { print "\n$column_data{$_}" } @column_index;
442 #
443 #    print("</tr>\n" .
444 #          $cgi->hidden("-name" => "unit_old_$i",
445 #                       "-value" => $form->{"selected_unit_$i"})
446 #          . "\n" .
447 #          $cgi->hidden("-name" => "price_new_$i",
448 #                       "-value" => $form->format_amount(\%myconfig, $form->{"price_new_$i"}))
449 #          . "\n");
450 #    map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_}) . "\n"); }
451 #        ("orderitems_id_$i", "bo_$i", "pricegroup_old_$i", "price_old_$i",
452 #         "id_$i", "inventory_accno_$i", "bin_$i", "partsgroup_$i", "partnotes_$i",
453 #         "income_accno_$i", "expense_accno_$i", "listprice_$i", "assembly_$i",
454 #         "taxaccounts_$i", "ordnumber_$i", "transdate_$i", "cusordnumber_$i",
455 #         "longdescription_$i", "basefactor_$i", "marge_total_$i", "marge_percent_$i", "lastcost_$i",
456 #         "marge_price_factor_$i"));
457 #
458 #########################################
459 #    # Eintrag fuer Version 2.2.0 geaendert #
460 #    # neue Optik im Rechnungsformular      #
461 #########################################
462 #
463 #    my $row_style_attr =
464 #      'style="display:none;"' if (!$form->{"show_details"});
465 #
466 #    # print second row
467 #    print qq|
468 #        <tr  class="listrow$j" $row_style_attr>
469 #         <td colspan="$colspan">
470 #|;
471 #    if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
472 #      my $selected = $form->{"licensenumber_$i"};
473 #      my $lizenzen_quoted;
474 #      $form->{"lizenzen_$i"} =~ s/ selected//g;
475 #      $form->{"lizenzen_$i"} =~
476 #        s/value="${selected}"\>/value="${selected}" selected\>/;
477 #      $lizenzen_quoted = $form->{"lizenzen_$i"};
478 #      $lizenzen_quoted =~ s/\"/&quot;/g;
479 #      print qq|
480 #       <b>Lizenz\#</b>&nbsp;<select name="licensenumber_$i" size="1">
481 #       $form->{"lizenzen_$i"}
482 #        </select>
483 #       <input type="hidden" name="lizenzen_$i" value="${lizenzen_quoted}">
484 #|;
485 #    }
486 #    if ($form->{type} !~ /_quotation/) {
487 #      print qq|
488 #          <b>$serialnumber</b>&nbsp;<input name="serialnumber_$i" size="15" value="$form->{"serialnumber_$i"}">|;
489 #    }
490 #
491 #    print qq|<b>$projectnumber</b>&nbsp;| .
492 #      NTI($cgi->popup_menu('-name' => "project_id_$i",
493 #                           '-values' => \@projectnumber_values,
494 #                           '-labels' => \%projectnumber_labels,
495 #                           '-default' => $form->{"project_id_$i"}));
496 #
497 #    if ($form->{type} eq 'invoice' or $form->{type} =~ /order/) {
498 #      my $reqdate_term =
499 #        ($form->{type} eq 'invoice')
500 #        ? 'deliverydate'
501 #        : 'reqdate';    # invoice uses a different term for the same thing.
502 #      print qq|
503 #        <b>${$reqdate_term}</b>&nbsp;<input name="${reqdate_term}_$i" size="11" onBlur="check_right_date_format(this)" value="$form->{"${reqdate_term}_$i"}">
504 #|;
505 #    }
506 #    my $subtotalchecked = ($form->{"subtotal_$i"}) ? "checked" : "";
507 #    print qq|
508 #          <b>|.$locale->text('Subtotal').qq|</b>&nbsp;<input type="checkbox" name="subtotal_$i" value="1" $subtotalchecked>
509 #|;
510 #
511 #    if ($form->{"id_$i"} && $is_sales) {
512 #      my $marge_price_factor;
513 #
514 #      $form->{"marge_price_factor_$i"} *= 1;
515 #
516 #      if ($form->{"marge_price_factor_$i"} && (1 != $form->{"marge_price_factor_$i"})) {
517 #        $marge_price_factor = '/' . $form->format_amount(\%myconfig, $form->{"marge_price_factor_$i"});
518 #      }
519 #
520 #      print qq|
521 #          ${marge_font_start}<b>| . $locale->text('Ertrag') . qq|</b>&nbsp;$form->{"marge_total_$i"}&nbsp;$form->{"marge_percent_$i"} % ${marge_font_end}|;
522 #   }
523 #   print qq|
524 #          &nbsp;<b>| . $locale->text('LP') . qq|</b>&nbsp;| . $form->format_amount(\%myconfig, $form->{"listprice_$i"}, 2) . qq|
525 #          &nbsp;<b>| . $locale->text('EK') . qq|</b>&nbsp;| . $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, 2) . $marge_price_factor;
526 #
527 #
528 #    print qq|
529 #         </td>
530 #       </tr>
531 #|;
532 #
533 ############### ENDE Neueintrag ##################
534 #
535 #    map { $form->{"${_}_base"} += $linetotal }
536 #      (split(/ /, $form->{"taxaccounts_$i"}));
537 #
538 #    $form->{invsubtotal} += $linetotal;
539 #  }
540 #
541 #  print qq|
542 #      </table>
543 #    </td>
544 #  </tr>
545 #|;
546 #
547 #  if (0 != ($form->{sellprice_total} * 1)) {
548 #    $form->{marge_percent} = ($form->{sellprice_total} - $form->{lastcost_total}) / $form->{sellprice_total} * 100;
549 #  }
550 #
551 #  $main::lxdebug->leave_sub();
552 #}
553
554 sub set_pricegroup {
555   $main::lxdebug->enter_sub();
556
557   my $form     = $main::form;
558   my %myconfig = %main::myconfig;
559   my $locale   = $main::locale;
560
561   my $rowcount = shift;
562   for my $j (1 .. $rowcount) {
563     my $pricegroup_old = $form->{"pricegroup_old_$j"};
564     if ($form->{PRICES}{$j}) {
565       my $len    = 0;
566       my $prices = '<option value="--">' . $locale->text("none (pricegroup)") . '</option>';
567       my $price  = 0;
568       foreach my $item (@{ $form->{PRICES}{$j} }) {
569
570         #$price = $form->round_amount($myconfig,  $item->{price}, 5);
571         #$price = $form->format_amount($myconfig, $item->{price}, 2);
572         my $price         = $item->{price};
573         my $pricegroup_id = $item->{pricegroup_id};
574         my $pricegroup    = $item->{pricegroup};
575
576         # build drop down list for pricegroups
577         $prices .=
578           qq|<option value="$price--$pricegroup_id"$item->{selected}>$pricegroup</option>\n|;
579
580         $len += 1;
581
582         #        map {
583         #               $form->{"${_}_$j"} =
584         #               $form->format_amount(\%myconfig, $form->{"${_}_$j"})
585         #              } qw(sellprice price_new price_old);
586
587         # set new selectedpricegroup_id and prices for "Preis"
588         if ($item->{selected} && ($pricegroup_id != 0)) {
589           $form->{"pricegroup_old_$j"} = $pricegroup_id;
590           $form->{"price_new_$j"}      = $price;
591           $form->{"sellprice_$j"}      = $price;
592         }
593         if ($pricegroup_id == 0) {
594           $form->{"price_new_$j"} = $form->{"sellprice_$j"};
595         }
596       }
597       $form->{"prices_$j"} = $prices;
598     }
599   }
600   $main::lxdebug->leave_sub();
601 }
602
603 sub display_form {
604   $main::lxdebug->enter_sub();
605
606   my $form     = $main::form;
607   my %myconfig = %main::myconfig;
608
609   $main::auth->assert('part_service_assembly_edit   | vendor_invoice_edit       | sales_order_edit    | invoice_edit |' .
610                 'request_quotation_edit       | sales_quotation_edit      | purchase_order_edit | '.
611                 'purchase_delivery_order_edit | sales_delivery_order_edit');
612
613   relink_accounts();
614   retrieve_partunits() if ($form->{type} =~ /_delivery_order$/);
615
616   my $new_rowcount = $form->{"rowcount"} * 1 + 1;
617   $form->{"project_id_${new_rowcount}"} = $form->{"globalproject_id"};
618
619   $form->language_payment(\%myconfig);
620
621   # if we have a display_form
622   if ($form->{display_form}) {
623     call_sub($form->{"display_form"});
624     exit;
625   }
626
627   Common::webdav_folder($form) if ($main::webdav);
628
629   #   if (   $form->{print_and_post}
630   #       && $form->{second_run}
631   #       && ($form->{action} eq "display_form")) {
632   #     for (keys %$form) { $old_form->{$_} = $form->{$_} }
633   #     $old_form->{rowcount}++;
634   #
635   #     #$form->{rowcount}--;
636   #     #$form->{rowcount}--;
637   #
638   #     $form->{print_and_post} = 0;
639   #
640   #     &print_form($old_form);
641   #     exit;
642   #   }
643   #
644   #   $form->{action}   = "";
645   #   $form->{resubmit} = 0;
646   #
647   #   if ($form->{print_and_post} && !$form->{second_run}) {
648   #     $form->{second_run} = 1;
649   #     $form->{action}     = "display_form";
650   #     $form->{rowcount}--;
651   #     my $rowcount = $form->{rowcount};
652   #
653   #     # get pricegroups for parts
654   #     IS->get_pricegroups_for_parts(\%myconfig, \%$form);
655   #
656   #     # build up html code for prices_$i
657   #     set_pricegroup($rowcount);
658   #
659   #     $form->{resubmit} = 1;
660   #
661   #   }
662   &form_header;
663
664   my $numrows    = ++$form->{rowcount};
665   my $subroutine = "display_row";
666
667   if ($form->{item} eq 'part') {
668
669     #set preisgruppenanzahl
670     $numrows    = $form->{price_rows};
671     $subroutine = "price_row";
672
673     &{$subroutine}($numrows);
674
675     $numrows    = ++$form->{makemodel_rows};
676     $subroutine = "makemodel_row";
677   }
678   if ($form->{item} eq 'assembly') {
679     $numrows    = $form->{price_rows};
680     $subroutine = "price_row";
681
682     &{$subroutine}($numrows);
683
684     $numrows    = ++$form->{makemodel_rows};
685     $subroutine = "makemodel_row";
686
687     # create makemodel rows
688     &{$subroutine}($numrows);
689
690     $numrows    = ++$form->{assembly_rows};
691     $subroutine = "assembly_row";
692   }
693   if ($form->{item} eq 'service') {
694     $numrows    = $form->{price_rows};
695     $subroutine = "price_row";
696
697     &{$subroutine}($numrows);
698
699     $numrows = 0;
700   }
701
702   # create rows
703   &{$subroutine}($numrows) if $numrows;
704
705   &form_footer;
706
707   $main::lxdebug->leave_sub();
708 }