Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision b6dc5623

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

  • ID b6dc5623d93c1be1c54248d4512e80f495af2899
  • Vorgänger ac517355
  • Nachfolger 270df900
  • Auslagerung der OE-Masken in Templates *

Diese Patch ist ein Merge der Revisionen
2866, 5349, 5365, 5370, 5408, 5413, 5470, 5473, 5475, 5519, 5520, 5521, 5524, 5526, 5591, 5618, 5622, 5814, 5881, 5882 und 5961
in das Unstable.

Hintergrund ist die Auslagerung der OE-Masken, das heisst aller Masken, die fuer Auftraege, Angebote und teilweise Rechnungen zustaendig sind.
Dadurch vereinfacht sich der Code an vielen Stellen deutlich, ausserdem konnten viele Berechnungen verkleinert werden, weil der Code fuer Angebote/Auftraege jetzt getrennt von Rechnungen liegt.

Ein Grossteil der bin/mozilla/io.pl wurde dafuer dubliziert, die Methoden die fuer Auftraege noetig sind liegen jetzt in der bin/mozilla/oe.pl (vor allem display_form und display_row, aber auch ein paar andere), ihr jeweiliges Pendant fuer Rechnungen wurde unveraendert in eine Datei invoice_io.pl ausgelagert die von den Skripten die sie benoetigen zusaetzlich zur io.pl eingelesen wird.

Wie der Name der Templates andeutet ist der Patch im Verkaufsbaum entstanden, im Verlauf der Programmierung habe cih aber nicht genug Unterschiede gefunden um separate Templates fuer Verkauf und Einkauf zu rechtfertigen. Eventuell werden die Templates noch umbenannt.

Komplexe Maskenaenderungen wie der Austausch von Drop-Down Menues bei zu grosser Anzahl durch Eingabefelder werden ebenfalls noch manuell gemacht.
Auch das wird in der naechsten Version ausgelagert um den Backend Code schlanker zu machen.

Die Berechnung fuer Units und Steuern wurde vereinfacht, und dabei einige unschoene Bugs gefixt, die aus der unvollstaendigen Abdeckung von Verzweigungen resultierten.

Zuletzt wurden noch fast alle serverseitigen Datenformatierungen ausgelagert in ein Templateplugin, welches Zahlen waehrend des Templatings formatiert (mehr dazu in der Dakumentation zu Template.pm).

Der Patch beinhaltet ausserdem die ueblichen Codekosmetika.

Unterschiede anzeigen:

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
  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} =
154
      qq|<th align="left" nowrap width="5" class="listheading">|
155
    . $locale->text('No.')
156
    . qq|</th>|;
157
  $column_data{partnumber} =
158
      qq|<th align="left" nowrap width="12" class="listheading">|
159
    . $locale->text('Number')
160
    . qq|</th>|;
161
  $column_data{description} =
162
      qq|<th align="left" nowrap width="30" class="listheading">|
163
    . $locale->text('Part Description')
164
    . qq|</th>|;
165
  if ($form->{"type"} eq "purchase_order") {
166
    $column_data{ship} =
167
      qq|<th align="left" nowrap width="5" class="listheading">|
168
      . $locale->text('Ship rcvd')
169
      . qq|</th>|;
170
  } else {
171
    $column_data{ship} =
172
      qq|<th align="left" nowrap width="5" class="listheading">|
173
      . $locale->text('Ship')
174
      . qq|</th>|;
175
  }
176
  $column_data{qty} =
177
      qq|<th align="left" nowrap width="5" class="listheading">|
178
    . $locale->text('Qty')
179
    . qq|</th>|;
180
  $column_data{unit} =
181
      qq|<th align="left" nowrap width="5" class="listheading">|
182
    . $locale->text('Unit')
183
    . qq|</th>|;
184
  $column_data{license} =
185
      qq|<th align="left" nowrap width="10" class="listheading">|
186
    . $locale->text('License')
187
    . qq|</th>|;
188
  $column_data{serialnr} =
189
      qq|<th align="left" nowrap width="10" class="listheading">|
190
    . $locale->text('Serial No.')
191
    . qq|</th>|;
192
  $column_data{projectnr} =
193
      qq|<th align="left" nowrap width="10" class="listheading">|
194
    . $locale->text('Project')
195
    . qq|</th>|;
196
  $column_data{sellprice} =
197
      qq|<th align="left" nowrap width="15" class="listheading">|
198
    . $locale->text('Price')
199
    . qq|</th>|;
200
  $column_data{sellprice_pg} =
201
      qq|<th align="left" nowrap width="15" class="listheading">|
202
    . $locale->text('Pricegroup')
203
    . qq|</th>|;
204
  $column_data{discount} =
205
      qq|<th align="left" class="listheading">|
206
    . $locale->text('Discount')
207
    . qq|</th>|;
208
  $column_data{linetotal} =
209
      qq|<th align="left" nowrap width="10" class="listheading">|
210
    . $locale->text('Extended')
211
    . qq|</th>|;
212
  $column_data{bin} =
213
      qq|<th align="left" nowrap width="10" class="listheading">|
214
    . $locale->text('Bin')
215
    . qq|</th>|;
216
############## ENDE Neueintrag ##################
217

  
218
  $myconfig{"show_form_details"} = 1
219
    unless (defined($myconfig{"show_form_details"}));
220
  $form->{"show_details"} = $myconfig{"show_form_details"}
221
    unless (defined($form->{"show_details"}));
222
  $form->{"show_details"} = $form->{"show_details"} ? 1 : 0;
223
  my $show_details_new = 1 - $form->{"show_details"};
224
  my $show_details_checked = $form->{"show_details"} ? "checked" : "";
225

  
226
  print qq|
227
  <tr>
228
    <td>| . $cgi->hidden("-name" => "show_details", "-value" => $form->{show_details}) . qq|
229
      <input type="checkbox" id="cb_show_details" onclick="show_form_details($show_details_new);" $show_details_checked>
230
      <label for="cb_show_details">| . $locale->text("Show details") . qq|</label><br>
231
      <table width="100%">
232
	<tr class="listheading">|;
233

  
234
  map { print "\n$column_data{$_}" } @column_index;
235

  
236
  print qq|
237
        </tr>
238
|;
239

  
240
  $runningnumber = $locale->text('No.');
241
  $deliverydate  = $locale->text('Delivery Date');
242
  $serialnumber  = $locale->text('Serial No.');
243
  $projectnumber = $locale->text('Project');
244
  $partsgroup    = $locale->text('Group');
245
  $reqdate       = $locale->text('Reqdate');
246

  
247
  $delvar = 'deliverydate';
248

  
249
  if ($form->{type} =~ /_order$/ || $form->{type} =~ /_quotation$/) {
250
    $deliverydate = $locale->text('Required by');
251
    $delvar       = 'reqdate';
252
  }
253

  
254
  $form->{marge_total} = 0;
255
  $form->{sellprice_total} = 0;
256
  $form->{lastcost_total} = 0;
257
  my %projectnumber_labels = ();
258
  my @projectnumber_values = ("");
259
  foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
260
    push(@projectnumber_values, $item->{"id"});
261
    $projectnumber_labels{$item->{"id"}} = $item->{"projectnumber"};
262
  }
263

  
264
  for $i (1 .. $numrows) {
265

  
266
    # undo formatting
267
    map {
268
      $form->{"${_}_$i"} =
269
        $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
270
    } qw(qty ship discount sellprice price_new price_old) unless ($form->{simple_save});
271

  
272
    if (!$form->{"unit_old_$i"}) {
273
      # Neue Ware aus der Datenbank. In diesem Fall ist unit_$i die
274
      # Einheit, wie sie in den Stammdaten hinterlegt wurde.
275
      # Es sollte also angenommen werden, dass diese ausgewaehlt war.
276
      $form->{"unit_old_$i"} = $form->{"unit_$i"};
277
    }
278

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

  
283
    my $check_units = $form->{"inventory_accno_$i"} ? $dimension_units : $service_units;
284
    if (!$check_units->{$form->{"selected_unit_$i"}} ||
285
        ($check_units->{$form->{"selected_unit_$i"}}->{"base_unit"} ne
286
         $all_units->{$form->{"unit_old_$i"}}->{"base_unit"})) {
287
      # Die ausgewaehlte Einheit ist fuer diesen Artikel nicht gueltig
288
      # (z.B. Dimensionseinheit war ausgewaehlt, es handelt sich aber
289
      # um eine Dienstleistung). Dann keinerlei Umrechnung vornehmen.
290
      $form->{"unit_old_$i"} = $form->{"selected_unit_$i"} = $form->{"unit_$i"};
291
    }
292
    if ((!$form->{"prices_$i"}) || ($form->{"new_pricegroup_$i"} == $form->{"old_pricegroup_$i"})) {
293
      if ($form->{"unit_old_$i"} ne $form->{"selected_unit_$i"}) {
294
        my $basefactor = 1;
295
        if (defined($all_units->{$form->{"unit_old_$i"}}->{"factor"}) &&
296
            $all_units->{$form->{"unit_old_$i"}}->{"factor"}) {
297
          $basefactor = $all_units->{$form->{"selected_unit_$i"}}->{"factor"} /
298
            $all_units->{$form->{"unit_old_$i"}}->{"factor"};
299
        }
300
        $form->{"sellprice_$i"} *= $basefactor;
301
        $form->{"unit_old_$i"} = $form->{"selected_unit_$i"};
302
      }
303
    }
304

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

  
308
    $price_factor = $price_factors{$form->{"price_factor_id_$i"}} || 1;
309
    $discount     = (100 - $form->{"discount_$i"} * 1) / 100;
310

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

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

  
315
    # marge calculations
316
    my ($marge_font_start, $marge_font_end);
317

  
318
    $form->{"lastcost_$i"} *= 1;
319

  
320
    $marge_price_factor = $form->{"marge_price_factor_$i"} * 1 || 1;
321

  
322
    if ($real_sellprice && ($form->{"qty_$i"} * 1)) {
323
      $form->{"marge_percent_$i"}     = ($real_sellprice - $form->{"lastcost_$i"} / $marge_price_factor) * 100 / $real_sellprice;
324
      $myconfig{"marge_percent_warn"} = 15 unless (defined($myconfig{"marge_percent_warn"}));
325

  
326
      if ($form->{"id_$i"} &&
327
          ($form->{"marge_percent_$i"} < (1 * $myconfig{"marge_percent_warn"}))) {
328
        $marge_font_start = "<font color=\"#ff0000\">";
329
        $marge_font_end   = "</font>";
330
      }
331

  
332
    } else {
333
      $form->{"marge_percent_$i"} = 0;
334
    }
335

  
336
    my $marge_adjust_credit_note = $form->{type} eq 'credit_note' ? -1 : 1;
337
    $form->{"marge_total_$i"}  = ($real_sellprice - $form->{"lastcost_$i"} / $marge_price_factor) * $form->{"qty_$i"} * $marge_adjust_credit_note;
338
    $form->{"marge_total"}      += $form->{"marge_total_$i"};
339
    $form->{"lastcost_total"}   += $form->{"lastcost_$i"} * $form->{"qty_$i"} / $marge_price_factor;
340
    $form->{"sellprice_total"}  += $real_sellprice * $form->{"qty_$i"};
341

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

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

  
348
########################################
349
    # Eintrag fuer Version 2.2.0 geaendert #
350
    # neue Optik im Rechnungsformular      #
351
########################################
352
    $column_data{runningnumber} =
353
      qq|<td><input name="runningnumber_$i" size="5" value="$i"></td>|;    # HuT
354
############## ENDE Neueintrag ##################
355

  
356
    $column_data{partnumber} =
357
      qq|<td><input name="partnumber_$i" size=12 value="$form->{"partnumber_$i"}"></td>|;
358

  
359
    if (($rows = $form->numtextrows($form->{"description_$i"}, 30, 6)) > 1) {
360
      $column_data{description} =
361
        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>|;
362
    } else {
363
      $column_data{description} =
364
        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>|;
365
    }
366

  
367
    (my $qty_dec) = ($form->{"qty_$i"} =~ /\.(\d+)/);
368
    $qty_dec = length $qty_dec;
369

  
370
    $column_data{qty} =
371
        qq|<td align="right"><input name="qty_$i" size="5" value="|
372
      . $form->format_amount(\%myconfig, $form->{"qty_$i"}, $qty_dec) .qq|">|;
373
    if ($form->{"formel_$i"}) {
374
      $column_data{qty} .= qq|<button type="button" onclick="calculate_qty_selection_window('qty_$i','alu_$i', 'formel_$i', $i)">| . $locale->text('*/') . qq|</button>|
375
        . $cgi->hidden("-name" => "formel_$i", "-value" => $form->{"formel_$i"}) . $cgi->hidden("-name" => "alu_$i", "-value" => $form->{"alu_$i"});
376
    }
377
    $column_data{qty} .= qq|</td>|;
378
    $column_data{ship} =
379
        qq|<td align="right"><input name="ship_$i" size=5 value="|
380
      . $form->format_amount(\%myconfig, $form->{"ship_$i"})
381
      . qq|"></td>|;
382

  
383
    my $is_part     = $form->{"inventory_accno_$i"};
384
    my $is_assembly = $form->{"assembly_$i"};
385
    my $is_assigned = $form->{"id_$i"};
386
    my $this_unit = $form->{"unit_$i"};
387
    if ($form->{"selected_unit_$i"} && $this_unit &&
388
        $all_units->{$form->{"selected_unit_$i"}} && $all_units->{$this_unit} &&
389
        ($all_units->{$form->{"selected_unit_$i"}}->{"base_unit"} eq $all_units->{$this_unit}->{"base_unit"})) {
390
      $this_unit = $form->{"selected_unit_$i"};
391
    } elsif (!$is_assigned ||
392
             ($is_part && !$this_unit && ($all_units->{$this_unit} && ($all_units->{$this_unit}->{"base_unit"} eq $all_units->{"kg"}->{"base_unit"})))) {
393
      $this_unit = "kg";
394
    }
395

  
396
    my $price_factor_select;
397
    if (0 < scalar @{ $form->{ALL_PRICE_FACTORS} }) {
398
      my @values = ('', map { $_->{id}                      } @{ $form->{ALL_PRICE_FACTORS} });
399
      my %labels =      map { $_->{id} => $_->{description} } @{ $form->{ALL_PRICE_FACTORS} };
400

  
401
      $price_factor_select =
402
        NTI($cgi->popup_menu('-name'    => "price_factor_id_$i",
403
                             '-default' => $form->{"price_factor_id_$i"},
404
                             '-values'  => \@values,
405
                             '-labels'  => \%labels,
406
                             '-style'   => 'width:90px'))
407
        . ' ';
408
    }
409

  
410
    $column_data{"unit"} = "<td>" .
411
      $price_factor_select .
412
       AM->unit_select_html($is_part || $is_assembly ? $dimension_units :
413
                            $is_assigned ? $service_units : $all_units,
414
                            "unit_$i", $this_unit,
415
                            $is_assigned ? $form->{"unit_$i"} : undef)
416
      . "</td>";
417

  
418
    # build in drop down list for pricesgroups
419
    if ($form->{"prices_$i"}) {
420
      if  ($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"}) {
421
        $price_tmp = $form->format_amount(\%myconfig, $form->{"price_new_$i"}, $decimalplaces);
422
      } else {
423
        $price_tmp = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
424
      }
425

  
426
      $column_data{sellprice_pg} =
427
      qq|<td align="right"><select name="sellprice_pg_$i">$form->{"prices_$i"}</select></td>|;
428
      $column_data{sellprice} =
429
      qq|<td><input name="sellprice_$i" size="10" value="$price_tmp" onBlur=\"check_right_number_format(this)\"></td>|;
430
    } else {
431

  
432
      # for last row and report
433
      # set pricegroup drop down list from report menu
434
      if ($form->{"sellprice_$i"} != 0) {
435
        $prices =
436
          qq|<option value="$form->{"sellprice_$i"}--$form->{"pricegroup_id_$i"}" selected>$form->{"pricegroup_$i"}</option>\n|;
437

  
438
        $form->{"pricegroup_old_$i"} = $form->{"pricegroup_id_$i"};
439

  
440
        $column_data{sellprice_pg} =
441
          qq|<td align="right"><select name="sellprice_pg_$i">$prices</select></td>|;
442

  
443
      } else {
444

  
445
        # for last row
446
        $column_data{sellprice_pg} = qq|<td align="right">&nbsp;</td>|;
447
        }
448
        
449
      $column_data{sellprice} =
450
      qq|<td><input name="sellprice_$i" size="10" onBlur=\"check_right_number_format(this)\" value="|
451
        . $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
452
                               $decimalplaces)
453
        . qq|"></td>|;
454
    }
455
    $column_data{discount} =
456
        qq|<td align="right"><input name="discount_$i" size=3 value="|
457
      . $form->format_amount(\%myconfig, $form->{"discount_$i"})
458
      . qq|"></td>|;
459
    $column_data{linetotal} =
460
        qq|<td align="right">|
461
      . $form->format_amount(\%myconfig, $linetotal, 2)
462
      . qq|</td>|;
463
    $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
464

  
465
########################################
466
    # Eintrag fuer Version 2.2.0 geaendert #
467
    # neue Optik im Rechnungsformular      #
468
########################################
469
    #     if ($lizenzen &&  $form->{type} eq "invoice" &&  $form->{vc} eq "customer") {
470
    #     $column_data{license} = qq|<td><select name="licensenumber_$i">$form->{"lizenzen_$i"}></select></td>|;
471
    #     }
472
    #
473
    #     if ($form->{type} !~ /_quotation/) {
474
    #     $column_data{serialnr} = qq|<td><input name="serialnumber_$i" size=10 value="$form->{"serialnumber_$i"}"></td>|;
475
    #     }
476
    #
477
    #     $column_data{projectnr} = qq|<td><input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}"></td>|;
478
############## ENDE Neueintrag ##################
479
    my $j = $i % 2;
480
    print qq|
481

  
482
        <tr valign="top" class="listrow$j">|;
483

  
484
    map { print "\n$column_data{$_}" } @column_index;
485

  
486
    print("</tr>\n" .
487
          $cgi->hidden("-name" => "unit_old_$i",
488
                       "-value" => $form->{"selected_unit_$i"})
489
          . "\n" .
490
          $cgi->hidden("-name" => "price_new_$i",
491
                       "-value" => $form->format_amount(\%myconfig, $form->{"price_new_$i"}))
492
          . "\n");
493
    map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_}) . "\n"); }
494
        ("orderitems_id_$i", "bo_$i", "pricegroup_old_$i", "price_old_$i",
495
         "id_$i", "inventory_accno_$i", "bin_$i", "partsgroup_$i", "partnotes_$i",
496
         "income_accno_$i", "expense_accno_$i", "listprice_$i", "assembly_$i",
497
         "taxaccounts_$i", "ordnumber_$i", "transdate_$i", "cusordnumber_$i",
498
         "longdescription_$i", "basefactor_$i", "marge_total_$i", "marge_percent_$i", "lastcost_$i",
499
         "marge_price_factor_$i"));
500

  
501
########################################
502
    # Eintrag fuer Version 2.2.0 geaendert #
503
    # neue Optik im Rechnungsformular      #
504
########################################
505

  
506
    my $row_style_attr =
507
      'style="display:none;"' if (!$form->{"show_details"});
508

  
509
    # print second row
510
    print qq|
511
        <tr  class="listrow$j" $row_style_attr>
512
	  <td colspan="$colspan">
513
|;
514
    if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
515
      my $selected = $form->{"licensenumber_$i"};
516
      my $lizenzen_quoted;
517
      $form->{"lizenzen_$i"} =~ s/ selected//g;
518
      $form->{"lizenzen_$i"} =~
519
        s/value="${selected}"\>/value="${selected}" selected\>/;
520
      $lizenzen_quoted = $form->{"lizenzen_$i"};
521
      $lizenzen_quoted =~ s/\"/&quot;/g;
522
      print qq|
523
	<b>Lizenz\#</b>&nbsp;<select name="licensenumber_$i" size="1">
524
	$form->{"lizenzen_$i"}
525
        </select>
526
	<input type="hidden" name="lizenzen_$i" value="${lizenzen_quoted}">
527
|;
528
    }
529
    if ($form->{type} !~ /_quotation/) {
530
      print qq|
531
          <b>$serialnumber</b>&nbsp;<input name="serialnumber_$i" size="15" value="$form->{"serialnumber_$i"}">|;
532
    }
533

  
534
    print qq|<b>$projectnumber</b>&nbsp;| .
535
      NTI($cgi->popup_menu('-name' => "project_id_$i",
536
                           '-values' => \@projectnumber_values,
537
                           '-labels' => \%projectnumber_labels,
538
                           '-default' => $form->{"project_id_$i"}));
539

  
540
    if ($form->{type} eq 'invoice' or $form->{type} =~ /order/) {
541
      my $reqdate_term =
542
        ($form->{type} eq 'invoice')
543
        ? 'deliverydate'
544
        : 'reqdate';    # invoice uses a different term for the same thing.
545
      print qq|
546
        <b>${$reqdate_term}</b>&nbsp;<input name="${reqdate_term}_$i" size="11" onBlur="check_right_date_format(this)" value="$form->{"${reqdate_term}_$i"}">
547
|;
548
    }
549
    my $subtotalchecked = ($form->{"subtotal_$i"}) ? "checked" : "";
550
    print qq|
551
          <b>|.$locale->text('Subtotal').qq|</b>&nbsp;<input type="checkbox" name="subtotal_$i" value="1" $subtotalchecked>
552
|;
553

  
554
    if ($form->{"id_$i"} && $is_sales) {
555
      my $marge_price_factor;
556

  
557
      $form->{"marge_price_factor_$i"} *= 1;
558

  
559
      if ($form->{"marge_price_factor_$i"} && (1 != $form->{"marge_price_factor_$i"})) {
560
        $marge_price_factor = '/' . $form->format_amount(\%myconfig, $form->{"marge_price_factor_$i"});
561
      }
562

  
563
      print qq|
564
          ${marge_font_start}<b>| . $locale->text('Ertrag') . qq|</b>&nbsp;$form->{"marge_total_$i"}&nbsp;$form->{"marge_percent_$i"} % ${marge_font_end}|;
565
   }
566
   print qq|
567
          &nbsp;<b>| . $locale->text('LP') . qq|</b>&nbsp;| . $form->format_amount(\%myconfig, $form->{"listprice_$i"}, 2) . qq|
568
          &nbsp;<b>| . $locale->text('EK') . qq|</b>&nbsp;| . $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, 2) . $marge_price_factor;
569

  
570

  
571
    print qq|
572
	  </td>
573
	</tr>
574
|;
575

  
576
############## ENDE Neueintrag ##################
577

  
578
    map { $form->{"${_}_base"} += $linetotal }
579
      (split(/ /, $form->{"taxaccounts_$i"}));
580

  
581
    $form->{invsubtotal} += $linetotal;
582
  }
583

  
584
  print qq|
585
      </table>
586
    </td>
587
  </tr>
588
|;
589

  
590
  if (0 != ($form->{sellprice_total} * 1)) {
591
    $form->{marge_percent} = ($form->{sellprice_total} - $form->{lastcost_total}) / $form->{sellprice_total} * 100;
592
  }
593

  
594
  $lxdebug->leave_sub();
595
}
596 93

  
597 94
##################################################
598 95
# build html-code for pricegroups in variable $form->{prices_$j}
......
601 98
  $lxdebug->enter_sub();
602 99
  my $rowcount = shift;
603 100
  for $j (1 .. $rowcount) {
604
    my $pricegroup_old = $form->{"pricegroup_old_$i"};
605
    if ($form->{PRICES}{$j}) {
606
      $len    = 0;
607
      $prices = '<option value="--">' . $locale->text("none (pricegroup)") . '</option>';
608
      $price  = 0;
609
      foreach $item (@{ $form->{PRICES}{$j} }) {
610

  
611
        #$price = $form->round_amount($myconfig,  $item->{price}, 5);
612
        #$price = $form->format_amount($myconfig, $item->{price}, 2);
613
        $price         = $item->{price};
614
        $pricegroup_id = $item->{pricegroup_id};
615
        $pricegroup    = $item->{pricegroup};
616

  
617
        # build drop down list for pricegroups
618
        $prices .=
619
          qq|<option value="$price--$pricegroup_id"$item->{selected}>$pricegroup</option>\n|;
620

  
621
        $len += 1;
622

  
623
        #        map {
624
        #               $form->{"${_}_$j"} =
625
        #               $form->format_amount(\%myconfig, $form->{"${_}_$j"})
626
        #              } qw(sellprice price_new price_old);
627

  
628
        # set new selectedpricegroup_id and prices for "Preis"
629
        if ($item->{selected} && ($pricegroup_id != 0)) {
630
          $form->{"pricegroup_old_$j"} = $pricegroup_id;
631
          $form->{"price_new_$j"}      = $price;
632
          $form->{"sellprice_$j"}      = $price;
633
        }
634
        if ($pricegroup_id == 0) {
635
          $form->{"price_new_$j"} = $form->{"sellprice_$j"};
636
        }
637
      }
638
      $form->{"prices_$j"} = $prices;
101
    next unless $form->{PRICES}{$j};
102
    # build drop down list for pricegroups
103
    my $option_tmpl = qq|<option value="%s--%s" %s>%s</option>|;
104
    $form->{"prices_$j"}  = join '', map { sprintf $option_tmpl, @$_{qw(price pricegroup_id selected pricegroup)} } 
105
                                         (+{ pricegroup => $locale->text("none (pricegroup)") }, @{ $form->{PRICES}{$j} });
106

  
107
    foreach $item (@{ $form->{PRICES}{$j} }) {
108
      # set new selectedpricegroup_id and prices for "Preis"
109
      $form->{"pricegroup_old_$j"} = $item->{pricegroup_id}   if $item->{selected} &&  $item->{pricegroup_id};
110
      $form->{"sellprice_$j"}      = $item->{price}           if $item->{selected} &&  $item->{pricegroup_id};
111
      $form->{"price_new_$j"}      = $form->{"sellprice_$j"}  if $item->{selected} || !$item->{pricegroup_id};
639 112
    }
640 113
  }
641 114
  $lxdebug->leave_sub();
......
870 343

  
871 344
  # change callback
872 345
  $form->{old_callback} = $form->escape($form->{callback}, 1);
873
  $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
874

  
875
  # delete action
876
  delete $form->{action};
877

  
878
  # save all other form variables in a previousform variable
879
  foreach $key (keys %$form) {
346
  $form->{callback}     = $form->escape("$form->{script}?action=display_form", 1);
880 347

  
881
    # escape ampersands
882
    $form->{$key} =~ s/&/%26/g;
883
    $previousform .= qq|$key=$form->{$key}&|;
884
  }
885
  chop $previousform;
886
  $previousform = $form->escape($previousform, 1);
348
  # save all form variables except action in a previousform variable
349
  my $previousform = join '&', map { $form->{$_} =~ s/&/%26/; "$_=$form->{$_}" } grep { !/action/ } keys %$form;
887 350

  
888
  $i = $form->{rowcount};
889
  map { $form->{"${_}_$i"} =~ s/\"/&quot;/g } qw(partnumber description);
351
  map { $form->{"${_}_$form->{rowcount}"} =~ s/\"/&quot;/g } qw(partnumber description);
890 352

  
891 353
  $form->header;
892 354

  
893
  print qq|
894
<body>
895

  
896
<h4 class="error">| . $locale->text('Item not on file!') . qq|
897

  
898
<p>
899
| . $locale->text('What type of item is this?') . qq|</h4>
900

  
901
<form method="post" action="ic.pl">
902

  
903
<p>
904

  
905
  <input class="radio" type="radio" name="item" value="part" checked>&nbsp;|
906
    . $locale->text('Part') . qq|<br>
907
  <input class="radio" type="radio" name="item" value="service">&nbsp;|
908
    . $locale->text('Service');
909

  
910
  print $cgi->hidden("-name" => "previousform", "-value" => $previousform);
911
  map { print $cgi->hidden("-name" => $_, "-value" => $form->{$_}); }        qw(rowcount vc login password);
912
  map { print $cgi->hidden("-name" => $_, "-value" => $form->{"${_}_$i"}); } qw(partnumber description unit sellprice price_factor_id);
913
  print $cgi->hidden("-name" => "taxaccount2", "-value" => $form->{taxaccounts});
914

  
915
print qq|
916
<input type="hidden" name="nextsub" value="add">
917

  
918
<p>
919
<input class="submit" type="submit" name="action" value="|
920
    . $locale->text('Continue') . qq|">
921
</form>
922

  
923
</body>
924
</html>
925
|;
926

  
927
  $lxdebug->leave_sub();
928
}
929

  
930
sub display_form {
931
  $lxdebug->enter_sub();
932

  
933
  relink_accounts();
934

  
935
  my $new_rowcount = $form->{"rowcount"} * 1 + 1;
936
  $form->{"project_id_${new_rowcount}"} = $form->{"globalproject_id"};
937

  
938
  $form->language_payment(\%myconfig);
939

  
940
  # if we have a display_form
941
  if ($form->{display_form}) {
942
    call_sub($form->{"display_form"});
943
    exit;
944
  }
945

  
946
  Common::webdav_folder($form) if ($webdav);
947

  
948
  #   if (   $form->{print_and_post}
949
  #       && $form->{second_run}
950
  #       && ($form->{action} eq "display_form")) {
951
  #     for (keys %$form) { $old_form->{$_} = $form->{$_} }
952
  #     $old_form->{rowcount}++;
953
  #
954
  #     #$form->{rowcount}--;
955
  #     #$form->{rowcount}--;
956
  #
957
  #     $form->{print_and_post} = 0;
958
  #
959
  #     &print_form($old_form);
960
  #     exit;
961
  #   }
962
  #
963
  #   $form->{action}   = "";
964
  #   $form->{resubmit} = 0;
965
  #
966
  #   if ($form->{print_and_post} && !$form->{second_run}) {
967
  #     $form->{second_run} = 1;
968
  #     $form->{action}     = "display_form";
969
  #     $form->{rowcount}--;
970
  #     my $rowcount = $form->{rowcount};
971
  #
972
  #     # get pricegroups for parts
973
  #     IS->get_pricegroups_for_parts(\%myconfig, \%$form);
974
  #
975
  #     # build up html code for prices_$i
976
  #     set_pricegroup($rowcount);
977
  #
978
  #     $form->{resubmit} = 1;
979
  #
980
  #   }
981
  &form_header;
982

  
983
  $numrows    = ++$form->{rowcount};
984
  $subroutine = "display_row";
985

  
986
  if ($form->{item} eq 'part') {
987

  
988
    #set preisgruppenanzahl
989
    $numrows    = $form->{price_rows};
990
    $subroutine = "price_row";
991

  
992
    &{$subroutine}($numrows);
993

  
994
    $numrows    = ++$form->{makemodel_rows};
995
    $subroutine = "makemodel_row";
996
  }
997
  if ($form->{item} eq 'assembly') {
998
    $numrows    = $form->{price_rows};
999
    $subroutine = "price_row";
1000

  
1001
    &{$subroutine}($numrows);
1002

  
1003
    $numrows    = ++$form->{makemodel_rows};
1004
    $subroutine = "makemodel_row";
1005

  
1006
    # create makemodel rows
1007
    &{$subroutine}($numrows);
1008

  
1009
    $numrows    = ++$form->{assembly_rows};
1010
    $subroutine = "assembly_row";
1011
  }
1012
  if ($form->{item} eq 'service') {
1013
    $numrows    = $form->{price_rows};
1014
    $subroutine = "price_row";
1015

  
1016
    &{$subroutine}($numrows);
1017

  
1018
    $numrows = 0;
1019
  }
1020

  
1021
  # create rows
1022
  &{$subroutine}($numrows) if $numrows;
355
  push @HIDDENS, { value => $cgi->hidden("-name" => "previousform", "-value" => $form->escape($previousform, 1)) };
356
  push @HIDDENS, map +{ value => $cgi->hidden("-name" => $_, "-value" => $form->{$_}) },                       qw(rowcount vc login password);
357
  push @HIDDENS, map +{ value => $cgi->hidden("-name" => $_, "-value" => $form->{"${_}_$form->{rowcount}"}) }, qw(partnumber description unit sellprice);
358
  push @HIDDENS, { value => $cgi->hidden("-name" => "taxaccount2", "-value" => $form->{taxaccounts}) };
1023 359

  
1024
  &form_footer;
360
  print $form->parse_html_template("generic/new_item", { HIDDENS => \@HIDDENS} );
1025 361

  
1026 362
  $lxdebug->leave_sub();
1027 363
}
......
1415 751
  # note: "||"-selection is only correct for values where "0" is _not_ a correct entry
1416 752
  $form->{sendmode}   = "attachment";
1417 753
  $form->{format}     = $form->{format} || $myconfig{template_format} || "pdf";
1418
  $form->{copies}     = $form->{copies} || $myconfig{copies} || 3;
1419
  $form->{media}      = $form->{media} || $myconfig{default_media} || "screen";
754
  $form->{copies}     = $form->{copies} || $myconfig{copies}          || 3;
755
  $form->{media}      = $form->{media}  || $myconfig{default_media}   || "screen";
1420 756
  $form->{printer_id} = defined $form->{printer_id}           ? $form->{printer_id} :
1421 757
                        defined $myconfig{default_printer_id} ? $myconfig{default_printer_id} : "";
1422 758

  
......
1427 763

  
1428 764
  push @FORMNAME, grep $_,
1429 765
    ($form->{type} eq 'purchase_order') ? (
1430
      opthash("purchase_order", $form->{PD}{purchase_order}, $locale->text('Purchase Order')),
1431
      opthash("bin_list", $form->{PD}{bin_list}, $locale->text('Bin List')) 
766
      opthash("purchase_order",      $form->{PD}{purchase_order},      $locale->text('Purchase Order')),
767
      opthash("bin_list",            $form->{PD}{bin_list},            $locale->text('Bin List')) 
1432 768
    ) : undef,
1433 769
    ($form->{type} eq 'credit_note') ?
1434
      opthash("credit_note", $form->{PD}{credit_note}, $locale->text('Credit Note')) : undef,
770
      opthash("credit_note",         $form->{PD}{credit_note},         $locale->text('Credit Note')) : undef,
1435 771
    ($form->{type} eq 'sales_order') ? (
1436
      opthash("sales_order", $form->{PD}{sales_order}, $locale->text('Confirmation')),
1437
      opthash("proforma", $form->{PD}{proforma}, $locale->text('Proforma Invoice')),
1438
      opthash("pick_list", $form->{PD}{pick_list}, $locale->text('Pick List')),
1439
      opthash("packing_list", $form->{PD}{packing_list}, $locale->text('Packing List')) 
772
      opthash("sales_order",         $form->{PD}{sales_order},         $locale->text('Confirmation')),
773
      opthash("proforma",            $form->{PD}{proforma},            $locale->text('Proforma Invoice')),
774
      opthash("pick_list",           $form->{PD}{pick_list},           $locale->text('Pick List')),
775
      opthash("packing_list",        $form->{PD}{packing_list},        $locale->text('Packing List')) 
1440 776
    ) : undef,
1441 777
    ($form->{type} =~ /_quotation$/) ?
1442
      opthash("$`_quotation", $form->{PD}{"$`_quotation"}, $locale->text('Quotation')) : undef,
778
      opthash("$`_quotation",        $form->{PD}{"$`_quotation"},      $locale->text('Quotation')) : undef,
1443 779
    ($form->{type} eq 'invoice') ? (
1444
      opthash("invoice", $form->{PD}{invoice}, $locale->text('Invoice')),
1445
      opthash("proforma", $form->{PD}{proforma}, $locale->text('Proforma Invoice')),
1446
      opthash("packing_list", $form->{PD}{packing_list}, $locale->text('Packing List'))
780
      opthash("invoice",             $form->{PD}{invoice},             $locale->text('Invoice')),
781
      opthash("proforma",            $form->{PD}{proforma},            $locale->text('Proforma Invoice')),
782
      opthash("packing_list",        $form->{PD}{packing_list},        $locale->text('Packing List'))
1447 783
    ) : undef,
1448 784
    ($form->{type} eq 'invoice' && $form->{storno}) ? (
1449
      opthash("storno_invoice", $form->{PD}{storno_invoice}, $locale->text('Storno Invoice')),
785
      opthash("storno_invoice",      $form->{PD}{storno_invoice},      $locale->text('Storno Invoice')),
1450 786
      opthash("storno_packing_list", $form->{PD}{storno_packing_list}, $locale->text('Storno Packing List')) 
1451 787
    ) : undef,
1452 788
    ($form->{type} eq 'credit_note') ?
1453
      opthash("credit_note", $form->{PD}{credit_note}, $locale->text('Credit Note')) : undef;
789
      opthash("credit_note",         $form->{PD}{credit_note},         $locale->text('Credit Note')) : undef;
1454 790

  
1455 791
  push @SENDMODE, 
1456
    opthash("attachment", $form->{SM}{attachment}, $locale->text('Attachment')),
1457
    opthash("inline", $form->{SM}{inline}, $locale->text('In-line'))
792
    opthash("attachment",            $form->{SM}{attachment},          $locale->text('Attachment')),
793
    opthash("inline",                $form->{SM}{inline},              $locale->text('In-line'))
1458 794
      if ($form->{media} eq 'email');
1459 795

  
1460 796
  push @MEDIA, grep $_,
1461
      opthash("screen", $form->{OP}{screen}, $locale->text('Screen')),
797
      opthash("screen",              $form->{OP}{screen},              $locale->text('Screen')),
1462 798
    (scalar @{ $form->{printers} } && $latex_templates) ?
1463
      opthash("printer", $form->{OP}{printer}, $locale->text('Printer')) : undef,
1464
    ($latex_templates && !$options{no_queue}) ?
1465
      opthash("queue", $form->{OP}{queue}, $locale->text('Queue')) : undef
799
      opthash("printer",             $form->{OP}{printer},             $locale->text('Printer')) : undef,
800
    ($latex_templates && !$options->{no_queue}) ?
801
      opthash("queue",               $form->{OP}{queue},               $locale->text('Queue')) : undef
1466 802
        if ($form->{media} ne 'email');
1467 803

  
1468 804
  push @FORMAT, grep $_,
1469 805
    ($opendocument_templates && $openofficeorg_writer_bin && $xvfb_bin && (-x $openofficeorg_writer_bin) && (-x $xvfb_bin)
1470
     && !$options{no_opendocument_pdf}) ?
1471
      opthash("opendocument_pdf", $form->{DF}{"opendocument_pdf"}, $locale->text("PDF (OpenDocument/OASIS)")) : undef,
806
     && !$options->{no_opendocument_pdf}) ?
807
      opthash("opendocument_pdf",    $form->{DF}{"opendocument_pdf"},  $locale->text("PDF (OpenDocument/OASIS)")) : undef,
1472 808
    ($latex_templates) ?
1473
      opthash("pdf", $form->{DF}{pdf}, $locale->text('PDF')) : undef,
1474
    ($latex_templates && !$options{no_postscript}) ?
1475
      opthash("postscript", $form->{DF}{postscript}, $locale->text('Postscript')) : undef,
1476
    (!$options{no_html}) ?
809
      opthash("pdf",                 $form->{DF}{pdf},                 $locale->text('PDF')) : undef,
810
    ($latex_templates && !$options->{no_postscript}) ?
811
      opthash("postscript",          $form->{DF}{postscript},          $locale->text('Postscript')) : undef,
812
    (!$options->{no_html}) ?
1477 813
      opthash("html", $form->{DF}{html}, "HTML") : undef,
1478
    ($opendocument_templates && !$options{no_opendocument}) ?
1479
      opthash("opendocument", $form->{DF}{opendocument}, $locale->text("OpenDocument/OASIS")) : undef;
814
    ($opendocument_templates && !$options->{no_opendocument}) ?
815
      opthash("opendocument",        $form->{DF}{opendocument},        $locale->text("OpenDocument/OASIS")) : undef;
1480 816

  
1481 817
  push @LANGUAGE_ID, 
1482 818
    map { opthash($_->{id}, ($_->{id} eq $form->{language_id} ? 'selected' : ''), $_->{description}) } +{}, @{ $form->{languages} }

Auch abrufbar als: Unified diff