Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision b6dc5623

Von Sven Schöling vor fast 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/oe.pl
1
# #=====================================================================
1
#=====================================================================
2 2
# LX-Office ERP
3 3
# Copyright (C) 2004
4 4
# Based on SQL-Ledger Version 2.1.9
......
38 38
use SL::IS;
39 39
use SL::PE;
40 40
use SL::ReportGenerator;
41
use List::Util qw(max);
41
use List::Util qw(max reduce);
42 42

  
43 43
require "bin/mozilla/io.pl";
44 44
require "bin/mozilla/arap.pl";
......
162 162
sub order_links {
163 163
  $lxdebug->enter_sub();
164 164
  # get customer/vendor
165
  $form->all_vc(\%myconfig, $form->{vc},
166
                ($form->{vc} eq 'customer') ? "AR" : "AP");
165
  $form->all_vc(\%myconfig, $form->{vc}, ($form->{vc} eq 'customer') ? "AR" : "AP");
167 166

  
168 167
  # retrieve order/quotation
169 168
  $form->{webdav}   = $webdav;
......
245 244
  }
246 245
  $form->{intnotes} = $intnotes if $intnotes;
247 246
  ($form->{ $form->{vc} }) = split /--/, $form->{ $form->{vc} };
248
  $form->{"old$form->{vc}"} =
249
    qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
247
  $form->{"old$form->{vc}"} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
250 248

  
251 249
  # build the popup menus
252 250
  if (@{ $form->{"all_$form->{vc}"} }) {
......
265 263
    $form->{department}       = "$form->{department}--$form->{department_id}";
266 264

  
267 265
    map {
268
      $form->{selectdepartment} .=
269
        "<option>$_->{description}--$_->{id}</option>\n"
270
    } (@{ $form->{all_departments} });
266
      $form->{selectdepartment} .= "<option>$_->{description}--$_->{id}</option>\n"
267
    } @{ $form->{all_departments} };
271 268
  }
272 269

  
273 270
  $form->{employee} = "$form->{employee}--$form->{employee_id}";
......
287 284
  my $i = 0;
288 285
  foreach $ref (@{ $form->{form_details} }) {
289 286
    $form->{rowcount} = ++$i;
290

  
291 287
    map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
292 288
  }
293 289
  for my $i (1 .. $form->{rowcount}) {
294
    if ($form->{id}) {
295
      $form->{"discount_$i"} =
296
        $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
297
    } else {
298
      $form->{"discount_$i"} =
299
        $form->format_amount(\%myconfig, $form->{"discount_$i"});
300
    }
301
    ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
302
    $dec           = length $dec;
303
    $decimalplaces = ($dec > 2) ? $dec : 2;
304

  
305
    # copy reqdate from deliverydate for invoice -> order conversion
306
    $form->{"reqdate_$i"} = $form->{"deliverydate_$i"}
307
      unless $form->{"reqdate_$i"};
308

  
309
    $form->{"sellprice_$i"} =
310
      $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
311
                           $decimalplaces);
312

  
313
    (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
314
    $dec_qty = length $dec_qty;
315
    $form->{"qty_$i"} =
316
      $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
317

  
318
    map { $form->{"${_}_$i"} =~ s/\"/&quot;/g }
319
      qw(partnumber description unit);
290
    $form->{"reqdate_$i"}   = $form->{"deliverydate_$i"} unless $form->{"reqdate_$i"};
291
    $form->{"discount_$i"}  = $form->format_amount(\%myconfig, $form->{"discount_$i"} * ($form->{id} ? 100 : 1));
292
    $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"});
293
    $form->{"qty_$i"}       = $form->format_amount(\%myconfig, $form->{"qty_$i"});
294
    map { $form->{"${_}_$i"} =~ s/\"/&quot;/g } qw(partnumber description unit);
320 295
  }
321 296

  
322 297
  $lxdebug->leave_sub();
......
324 299

  
325 300
sub form_header {
326 301
  $lxdebug->enter_sub();
327

  
328
  my $checkedclosed    = $form->{"closed"}    ? "checked" : "";
329
  my $checkeddelivered = $form->{"delivered"} ? "checked" : "";
302
  my @custom_hiddens;
303
  %TMPL_VAR = ();
330 304

  
331 305
  $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
332 306
  $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
......
340 314
    qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname
341 315
       shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact
342 316
       shiptophone shiptofax shiptodepartment_1 shiptodepartment_2);
343

  
317
 
344 318
  # use JavaScript Calendar or not
345 319
  $form->{jsscript} = 1;
346
  $jsscript = "";
347

  
348
  $button1 = qq|
320
  $TMPL_VAR{button1} = qq|
349 321
     <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\">
350
      <input type=button name=transdate id="trigger1" value=|
351
    . $locale->text('button') . qq|></td>
322
      <input type=button name=transdate id="trigger1" value=| . $locale->text('button') . qq|></td>
352 323
    |;
353
  $button2 = qq|
324
  $TMPL_VAR{button2} = qq|
354 325
     <td width="13"><input name=reqdate id=reqdate size=11 title="$myconfig{dateformat}" value="$form->{reqdate}" onBlur=\"check_right_date_format(this)\">
355
      <input type=button name=reqdate name=reqdate id="trigger2" value=|
356
    . $locale->text('button') . qq|></td>
326
      <input type=button name=reqdate name=reqdate id="trigger2" value=| . $locale->text('button') . qq|></td>
357 327
   |;
358

  
359 328
  #write Trigger
360
  $jsscript = Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1", "reqdate", "BL", "trigger2");
329
  $TMPL_VAR{jsscript} = Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1", "reqdate", "BL", "trigger2");
361 330

  
331
  # openclosed checkboxes
362 332
  my @tmp;
363

  
364
  if (($form->{"type"} eq "sales_order") ||
365
      ($form->{"type"} eq "purchase_order")) {
366
    push(@tmp, qq|<input name="delivered" id="delivered" type="checkbox" class="checkbox" value="1" $checkeddelivered>
367
                  <label for="delivered">| . $locale->text('Delivered') . qq|</label>|);
368
  }
369

  
370
  if ($form->{id}) {
371
    push(@tmp, qq|<input name="closed" id="closed" type="checkbox" class="checkbox" value="1" $checkedclosed>
372
                  <label for="closed">| . $locale->text('Closed') . qq|</label>|);
373
  }
374

  
375
  if (@tmp) {
376
    $openclosed .= qq|<tr>
377
                        <td colspan=| . (2 * scalar(@tmp)) . qq| align=center>| . join("\n", @tmp) . qq|
378
                        </td>
379
                      </tr>\n|;
380
  }
333
  push @tmp, sprintf qq|<input name="delivered" id="delivered" type="checkbox" class="checkbox" value="1" %s><label for="delivered">%s</label>|,
334
                        $form->{"delivered"} ? "checked" : "",  $locale->text('Delivered') if $form->{"type"} =~ /_order$/;
335
  push @tmp, sprintf qq|<input name="closed" id="closed" type="checkbox" class="checkbox" value="1" %s><label for="closed">%s</label>|,
336
                        $form->{"closed"}    ? "checked" : "",  $locale->text('Closed')    if $form->{id};
337
  $TMPL_VAR{openclosed} = sprintf qq|<tr><td colspan=%d align=center>%s</td></tr>\n|, 2 * scalar @tmp, join "\n", @tmp if @tmp;
381 338

  
382 339
  # set option selected
383
  foreach $item ($form->{vc}, currency, department, ($form->{vc} eq "customer" ? customer : vendor)) {
340
  foreach $item ($form->{vc}, 'currency', 'department', ($form->{vc} eq "customer" ? 'customer' : 'vendor')) {
384 341
    $form->{"select$item"} =~ s/ selected//;
385 342
    $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
386 343
  }
......
391 348
  #substitute \n and \r to \s (bug 543)
392 349
  $form->{"select$form->{vc}"} =~ s/[\n\r]/&nbsp;/g;
393 350
  
394
  my @old_project_ids = ($form->{"globalproject_id"});
395
  map({ push(@old_project_ids, $form->{"project_id_$_"})
396
          if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
351
  my @old_project_ids = ($form->{"globalproject_id"}, grep { $_ } map { $form->{"project_id_$_"} } 1..$form->{"rowcount"});
397 352

  
398 353
  my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
399
  $form->get_lists("contacts"   => "ALL_CONTACTS",
400
                   "shipto"     => "ALL_SHIPTO",
401
                   "projects"   => {
402
                     "key"      => "ALL_PROJECTS",
403
                     "all"      => 0,
404
                     "old_id"   => \@old_project_ids
405
                   },
354
  $form->get_lists("contacts"      => "ALL_CONTACTS",
355
                   "shipto"        => "ALL_SHIPTO",
356
                   "projects"      => { "key"      => "ALL_PROJECTS",
357
                                        "all"      => 0,
358
                                        "old_id"   => \@old_project_ids },
406 359
                   "employees"     => "ALL_EMPLOYEES",
407 360
                   "salesmen"      => "ALL_SALESMEN",
408 361
                   "taxzones"      => "ALL_TAXZONES",
409 362
                   "payments"      => "ALL_PAYMENTS",
410 363
                   "currencies"    => "ALL_CURRENCIES",
411
                   $vc             => "ALL_" . uc($vc),
364
                   $vc             => { key   => "ALL_" . uc($vc),
365
                                        limit => $myconfig{vclimit} + 1 },
412 366
                   "price_factors" => "ALL_PRICE_FACTORS");
413 367

  
414
  my %labels;
415
  my @values = (undef);
416
  foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
417
    push(@values, $item->{"cp_id"});
418
    $labels{$item->{"cp_id"}} = $item->{"cp_name"} . ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
419
  }
420

  
421
  my $contact;
422
  if (scalar @values > 1) {
423
    $contact = qq|
424
    <tr>
425
      <th align="right">| . $locale->text('Contact Person') . qq|</th>
426
      <td>| .
427
      NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
428
                           '-labels' => \%labels, '-default' => $form->{"cp_id"}))
429
      . qq|
430
      </td>
431
    </tr>|;
432
  }
433

  
434
  %labels = ();
435
  @values = ();
436

  
437
  foreach my $item (@{ $form->{($form->{vc} eq "customer" ? "ALL_CUSTOMERS" : "ALL_VENDORS")}}) {
438
    push(@values, $item->{"name"}.qq|--|.$item->{"id"});
439
    $labels{$item->{"name"}.qq|--|.$item->{"id"}} = $item->{name};
440
  }
441

  
442
  $vc = qq|
443
      <input type="hidden" name="$form->{vc}_id" value="| . H($form->{"$form->{vc}_id"}) . qq|">
444
      <input type="hidden" name="old$form->{vc}" value="| . H($form->{"old$form->{vc}"}) . qq|">
445
      <th align="right">| . $locale->text(ucfirst($form->{vc})) . qq|</th>
446
      <td>| . 
447
        (($myconfig{vclimit} <=  scalar(@values)) 
448
              ? qq|<input type="text" value="| . H(($form->{"old$form->{vc}"} =~ /^(.*)\-\-.*$/)) . qq|" name="$form->{vc}">| 
449
              : (NTI($cgi->popup_menu('-name' => "$form->{vc}", '-default' => $form->{"old$form->{vc}"}, 
450
                             '-onChange' => 'document.getElementById(\'update_button\').click();',
451
                             '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
452
        <input type="button" value="?" onclick="show_vc_details('$form->{vc}')">
453
      </td><input type=hidden name="select$form->{vc}" value="| .
454
    Q($form->{"select$form->{vc}"}) . qq|">|;
455

  
456
  if ($form->{vc} eq 'customer') {
457
    $vc .= qq|<input type="hidden" name="customer_klass" value="$form->{customer_klass}">|;
458
  }
459

  
460
  %labels = ();
461
  @values = ("");
462
  foreach my $item (@{ $form->{"ALL_PAYMENTS"} }) {
463
    push(@values, $item->{"id"});
464
    $labels{$item->{"id"}} = $item->{"description"};
465
  }
466
  
467
  $payments = qq|
468
    <th align="right">| . $locale->text('Payment Terms') . qq|</th>
469
    <td>| .
470
    NTI($cgi->popup_menu('-name' => 'payment_id', '-values' => \@values, '-style' => 'width: 250px',
471
                         '-labels' => \%labels, '-default' => $form->{payment_id}))
472
    . qq|</td>|;
473

  
474
  %labels = ();
475
  @values = ("");
476
  foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
477
    push(@values, $item->{"shipto_id"});
478
    $labels{$item->{"shipto_id"}} = join "; ", grep { $_ } map { $item->{"shipto${_}" } } qw(name department_1 street city);
479
  }
480

  
481
  my $shipto;
482
  if (scalar @values > 1) {
483
    $shipto = qq|
484
    <tr>
485
      <th align="right">| . $locale->text('Shipping Address') . qq|</th>
486
      <td>| .
487
      NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
488
                           '-labels' => \%labels, '-default' => $form->{"shipto_id"}))
489
    . qq|</td>|;
490
  }
491

  
492
  %labels = ();
493
  @values = ("");
494
  foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
495
    push(@values, $item->{"id"});
496
    $labels{$item->{"id"}} = $item->{"projectnumber"};
497
  }
498
  my $globalprojectnumber = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
499
                                                 '-labels' => \%labels,
500
                                                 '-default' => $form->{"globalproject_id"}));
368
  # contacts
369
  @values = ("", map { $_->{cp_id} } @{ $form->{ALL_CONTACTS} });
370
  %labels = map { $_->{cp_id} => $_->{"cp_name"} . ($_->{cp_abteilung} ? " ($_->{cp_abteilung})" : "") } @{ $form->{ALL_CONTACTS} };
371
  $TMPL_VAR{contact} = NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
372
                                            '-labels' => \%labels, '-default' => $form->{"cp_id"})) if scalar @values > 1;
373

  
374
  # vendor/customer
375
  @values = map { "$_->{name}--$_->{id}" } @{ $form->{uc "all_$form->{vc}s" } };
376
  %labels = map { +"$_->{name}--$_->{id}" => $_->{name} } @{ $form->{uc "all_$form->{vc}s" } };
377
  push @custom_hiddens, "$form->{vc}_id";
378
  push @custom_hiddens, "old$form->{vc}";
379
  push @custom_hiddens, "select$form->{vc}";
380
  $TMPL_VAR{vc} = sprintf qq|<th align="right">%s</th><td>%s<input type="button" value="?" onclick="show_vc_details('$form->{vc}')"></td>|,
381
       $locale->text(ucfirst $form->{vc}), 
382
       ($myconfig{vclimit} <=  scalar(@values)) 
383
        ? $cgi->textfield(-value => H($form->{"old$form->{vc}"} =~ /^(.*)\-\-.*$/), -name => $form->{vc}) 
384
        : NTI($cgi->popup_menu('-name' => "$form->{vc}", '-default' => $form->{"old$form->{vc}"}, 
385
                               '-onChange' => 'document.getElementById(\'update_button\').click();',
386
                               '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px'));
387

  
388
  # payments (for footer)
389
  @values = ("", map { $_->{id} } @{ $form->{ALL_PAYMENTS} });
390
  %labels = map { $_->{id} => $_->{description} } @{ $form->{ALL_PAYMENTS} };
391
  $TMPL_VAR{payments} = NTI($cgi->popup_menu('-name' => 'payment_id', '-values' => \@values, '-style' => 'width: 250px',
392
                                             '-labels' => \%labels, '-default' => $form->{payment_id}));
393

  
394
  # shipto
395
  @values = ("", map { $_->{shipto_id} } @{ $form->{ALL_SHIPTO} });
396
  %labels = map { my $item=$_; $_->{shipto_id} => join "; ", grep { $_ } map { $item->{"shipto${_}" } } qw(name department_1 street city) } @{ $form->{ALL_SHIPTO} };
397
  $TMPL_VAR{shipto} = NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
398
                                           '-labels' => \%labels, '-default' => $form->{"shipto_id"})) if scalar @values > 1;
399

  
400
  # projects
401
  @values = ("", map { $_->{id} } @{ $form->{ALL_PROJECTS} });
402
  %labels = map { $_->{id} => $_->{projectnumber} } @{ $form->{ALL_PROJECTS} };
403
  $TMPL_VAR{globalprojectnumber} = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
404
                                                        '-labels' => \%labels, '-default' => $form->{"globalproject_id"}));
501 405
  
502
  my $salesmen = "";
503
  %labels = ();
504
  @values = ();
505
  if ($form->{type} =~ /^sales_/) {
506
    foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
507
      push(@values, $item->{"id"});
508
      $labels{$item->{"id"}} = ($item->{"name"} ne "" ? $item->{"name"} : $item->{"login"});
509
    }
510
    $salesmen =
511
      qq|<tr>
512
          <th align="right">| . $locale->text('Salesman') . qq|</th>
513
          <td>| .
514
      NTI($cgi->popup_menu('-name' => 'salesman_id', '-default' => $form->{"salesman_id"} ? $form->{"salesman_id"} : $form->{"employee_id"},
515
                           '-values' => \@values, '-labels' => \%labels))
516
      . qq|</td>
517
         </tr>|;
518
  }
519

  
520
  %labels = ();
521
  @values = ();
522
  foreach my $item (@{ $form->{"ALL_EMPLOYEES"} }) {
523
    push(@values, $item->{"id"});
524
    $labels{$item->{"id"}} = $item->{"name"} ne "" ? $item->{"name"} : $item->{"login"};
525
  }
526

  
527
  my $employee = qq|
528
    <tr>
529
      <th align="right">| . $locale->text('Employee') . qq|</th>
530
      <td>| .
531
        NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
532
                             '-values' => \@values, '-labels' => \%labels)) . qq|
533
      </td>
534
    </tr>|;
535

  
536
  %labels = ();
537
  @values = ();
538
  foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
539
    push(@values, $item->{"id"});
540
    $labels{$item->{"id"}} = $item->{"description"};
541
  }
542

  
543
  $taxzone = qq|
544
    <tr>
545
      <th align="right">| . $locale->text('Steuersatz') . qq|</th>
546
      <td>| .
547
        NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
548
                             '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')) . qq|
549
      </td>
550
    </tr>|;
551

  
552
  %labels = ();
553
  @values = ();
554
  my $i = 0;
555
  foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
556
    push(@values, $item);
557
    $labels{$item} = $item;
558
  }
559

  
560
  $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
561
  my $currencies;
562
  if (scalar @values) {
563
    $currencies = qq|
564
    <tr>
565
      <th align="right">| . $locale->text('Currency') . qq|</th>
566
      <td>| .
567
        NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
568
                             '-values' => \@values, '-labels' => \%labels)) . qq|
569
      </td>
570
    </tr>|;
571
  }
572

  
573
  $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
574
  $form->{exchangerate} = "" unless $form->{exchangerate};
575

  
406
  # salesmen
407
  @values = map { $_->{id} } @{ $form->{ALL_SALESMEN} };
408
  %labels = map { $_->{id} => ($_->{name} || $_->{login}) } @{ $form->{ALL_SALESMEN} };
409
  $TMPL_VAR{salesmen} = NTI($cgi->popup_menu('-name' => 'salesman_id', '-default' => $form->{"salesman_id"} ? $form->{"salesman_id"} : $form->{"employee_id"},
410
                                             '-values' => \@values, '-labels' => \%labels)) if $form->{type} =~ /^sales_/ && scalar @values;
411

  
412
  # employees
413
  @values = map { $_->{id} } @{ $form->{ALL_EMPLOYEES} };
414
  %labels = map { $_->{id} => $_->{name} || $_->{login} } @{ $form->{ALL_EMPLOYEES} };
415
  $TMPL_VAR{employee} = NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
416
                                             '-values' => \@values, '-labels' => \%labels));
417

  
418
  # taxzone
419
  @values = map { $_->{id} } @{ $form->{ALL_TAXZONES} };
420
  %labels = map { $_->{id} => $_->{description} } @{ $form->{ALL_TAXZONES} };
421
  $TMPL_VAR{taxzone} = NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
422
                                            '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px'));
423

  
424
  # currencies and exchangerate
425
  @values = map { $_ } @{ $form->{ALL_CURRENCIES} };
426
  %labels = map { $_ => $_ } @{ $form->{ALL_CURRENCIES} };
427
  $form->{currency}            = $form->{defaultcurrency} unless $form->{currency};
428
  $TMPL_VAR{show_exchangerate} = $form->{currency} ne $form->{defaultcurrency} && $form->{exchangerate};
429
  $TMPL_VAR{currencies}        = NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
430
                                                      '-values' => \@values, '-labels' => \%labels)) if scalar @values;
431
  push @custom_hiddens, "forex";
432
  push @custom_hiddens, "exchangerate" if $form->{forex};
433

  
434
  # credit remaining
576 435
  $creditwarning = (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) ? 1 : 0;
436
  $TMPL_VAR{is_credit_remaining_negativ} = ($form->{creditremaining} =~ /-/) ? "0" : "1";
437
  
438
  # business
439
  $TMPL_VAR{business_label} = ($form->{vc} eq "customer" ? $locale->text('Customer type') : $locale->text('Vendor type'));
577 440

  
578
  $form->{creditlimit}     = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
579
  $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
580

  
581
  $exchangerate = qq|\n<input type=hidden name=forex value=$form->{forex}>\n|;
582

  
583
  if ($form->{currency} ne $form->{defaultcurrency}) {
584
    if ($form->{forex}) {
585
      $exchangerate .=
586
          qq|<th align=right>| . $locale->text('Exchangerate')
587
        . qq|</th><td>$form->{exchangerate}</td>
588
      <input type=hidden name=exchangerate value=$form->{exchangerate}>
589
|;
590
    } else {
591
      $exchangerate .=
592
          qq|<th align=right>| . $locale->text('Exchangerate')
593
        . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
594
    }
595
  }
596

  
597
  if ($form->{business}) {
598
    $business = qq|
599
	      <tr>
600
          <th align="right">| . ($form->{vc} eq "customer" ? $locale->text('Customer type') : $locale->text('Vendor type')) . qq|</th>
601
          <td>$form->{business}; | . $locale->text('Trade Discount') . qq| |
602
      . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
603
      . qq| %</td>
604
        </tr>
605
|;
606
  }
607

  
608
  if ($form->{max_dunning_level}) {
609
    $dunning = qq|
610
      <tr>
611
        <th align="right">| . $locale->text('Max. Dunning Level') . qq|:</th>
612
        <td>
613
          <b>$form->{max_dunning_level}</b>;
614
          | . $locale->text('Dunning Amount') . qq|: <b>|
615
        . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
616
        . qq|</b>
617
        </td>
618
      </tr>
619
|;
620
  }
621

  
622
  if ($form->{type} !~ /_quotation$/) {
623
    $ordnumber = qq|
624
	      <tr>
625
		<th width=70% align=right nowrap>| . $locale->text('Order Number') . qq|</th>
626
                <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
627
	      </tr>
628
	      <tr>
629
		<th width=70% align=right nowrap>|
630
      . $locale->text('Quotation Number') . qq|</th>
631
                <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
632
	      </tr>
633
              <tr>
634
		<th width=70% align=right nowrap>|
635
      . $locale->text('Customer Order Number') . qq|</th>
636
                <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
637
	      </tr>
638
	      <tr>
639
		<th align=right nowrap>| . $locale->text('Order Date') . qq|</th>
640
                $button1
641

  
642
	      </tr>
643
	      <tr>
644
		<th align=right nowrap=true>| . $locale->text('Required by') . qq|</th>
645
                $button2
646
	      </tr>
647
|;
648

  
649
    $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
650

  
651
    $creditremaining = qq|
652
        $shipto
653
        <tr>
654
          <td align="right">| . $locale->text('Credit Limit') . qq|</td>
655
          <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
656
        </tr>
657
	      </tr>
658
|;
659
  } else {
660
    $reqlabel = ($form->{type} eq 'sales_quotation') ? $locale->text('Valid until') : $locale->text('Required by');
661
    if ($form->{type} eq 'sales_quotation') {
662
      $ordnumber = qq|
663
	      <tr>
664
		<th width=70% align=right nowrap>|
665
        . $locale->text('Quotation Number') . qq|</th>
666
		<td><input name=quonumber size=11 value="$form->{quonumber}"></td>
667
		<input type=hidden name=ordnumber value="$form->{ordnumber}">
668
	      </tr>
669
|;
670
    } else {
671
      $ordnumber = qq|
672
	      <tr>
673
		<th width=70% align=right nowrap>| . $locale->text('RFQ Number') . qq|</th>
674
		<td><input name=quonumber size=11 value="$form->{quonumber}"></td>
675
		<input type=hidden name=ordnumber value="$form->{ordnumber}">
676
	      </tr>
677
|;
678

  
679
    }
680

  
681
    $ordnumber      .= qq| <tr> <th align=right nowrap>| . $locale->text('Quotation Date') . qq|</th> $button1 </tr>
682
                           <tr> <th align=right nowrap=true>$reqlabel</th> $button2 </tr>\n|;
683
    $creditremaining = qq| <tr> <td colspan=4></td> $shipto </tr>|;
684
  }
685

  
686
  $department = qq|
687
              <tr>
688
	        <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
689
		<td colspan=3><select name=department style="width: 250px">$form->{selectdepartment}</select>
690
		<input type=hidden name=selectdepartment value="$form->{selectdepartment}">
691
		</td>
692
	      </tr> | if $form->{selectdepartment};
441
  push @custom_hiddens, "ordnumber"      if $form->{type} =~ /_quotation$/;
442
  push @custom_hiddens, "customer_klass" if $form->{vc} eq 'customer';
693 443

  
694 444
  $credittext = $locale->text('Credit Limit exceeded!!!');
695 445

  
......
700 450

  
701 451
  $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
702 452
  $onload .= qq|;setupPoints('|.   $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
453
  $TMPL_VAR{onload} = $onload;
703 454
  
704 455
  $form->{javascript} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
705 456
  $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
......
707 458

  
708 459
  $form->header;
709 460

  
710
  print qq|
711
<body onLoad="$onload">
712

  
713
<form method=post name=oe action=$form->{script}>
714

  
715
 <script type="text/javascript" src="js/common.js"></script>
716
 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
717
 <script type="text/javascript" src="js/vendor_selection.js"></script>
718
 <script type="text/javascript" src="js/calculate_qty.js"></script>
719
|;
720

  
721
  $form->hide_form(qw(id action type vc formname media format proforma queued printed emailed
722
                      title discount creditlimit creditremaining tradediscount business
723
                      max_dunning_level dunning_amount shiptoname shiptostreet shiptozipcode
724
                      shiptocity shiptocountry shiptocontact shiptophone shiptofax 
725
                      shiptodepartment_1 shiptodepartment_2 shiptoemail 
726
                      message email subject cc bcc taxpart taxservice taxaccounts), 
727
                      map { $_.'_rate', $_.'_description' } split / /, $form->{taxaccounts} );
728
  print qq|
729

  
730
<table width=100%>
731
  <tr class=listtop>
732
    <th class=listtop>$form->{title}</th>
733
  </tr>
734
  <tr height="5"></tr>
735
  <tr>
736
    <td>
737
      <table width="100%">
738
        <tr valign=top>
739
	  <td>
740
	    <table width=100%>
741
	      <tr>
742
        $vc
743
        $contact
744
	      $creditremaining
745
	      $business
746
              $dunning
747
              $taxzone
748
	      $department
749
	      <tr>
750
		$currencies
751
		$exchangerate
752
	      </tr>
753
	      <tr>
754
		<th align=right>| . $locale->text('Shipping Point') . qq|</th>
755
		<td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
756
	      </tr>
757
	      <tr>
758
		<th align=right>| . $locale->text('Ship via') . qq|</th>
759
		<td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
760
	      </tr>
761
              <tr>
762
                <th align="right">| . $locale->text('Transaction description') . qq|</th>
763
                <td colspan="3"><input name="transaction_description" size="35" value="| . H($form->{transaction_description}) . qq|"></td>
764
              </tr>|;
765
#              <tr>
766
#                 <td colspan=4>
767
#                   <table>
768
#                     <tr>
769
#                       <td colspan=2>
770
#                         <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
771
#                       </td>
772
#                       <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
773
#                       <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
774
#                     </tr>
775
#                     <tr>
776
#                       <td colspan=2>
777
#                         <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
778
#                       </td>
779
#                       <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
780
#                       <input size=45 id=vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
781
#                     </tr>
782
#                   </table>
783
#                 </td>
784
#               </tr>
785
print qq|	    </table>
786
	  </td>
787
	  <td align=right>
788
	    <table>
789
	      $openclosed
790
	      $employee
791
        $salesmen
792
	      $ordnumber
793
	      <tr>
794
          <th width="70%" align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
795
          <td>$globalprojectnumber</td>
796
	      </tr>
797
	    </table>
798
	  </td>
799
	</tr>
800
      </table>
801
    </td>
802
  </tr>
803

  
804
$jsscript
461
  $TMPL_VAR{HIDDENS} = [ map { name => $_, value => $form->{$_} },
462
     qw(id action type vc formname media format proforma queued printed emailed
463
        title creditlimit creditremaining tradediscount business
464
        max_dunning_level dunning_amount shiptoname shiptostreet shiptozipcode
465
        shiptocity shiptocountry shiptocontact shiptophone shiptofax
466
        shiptodepartment_1 shiptodepartment_2 shiptoemail
467
        message email subject cc bcc taxpart taxservice taxaccounts),
468
        @custom_hiddens,
469
        map { $_.'_rate', $_.'_description' } split / /, $form->{taxaccounts} ];  # deleted: discount
470

  
471
  %TMPL_VAR = (
472
     %TMPL_VAR,
473
     is_sales        => scalar ($form->{type} =~ /^sales_/),              # these vars are exported, so that the template
474
     is_order        => scalar ($form->{type} =~ /_order$/),              # may determine what to show
475
     is_sales_quo    => scalar ($form->{type} =~ /sales_quotation$/),
476
     is_req_quo      => scalar ($form->{type} =~ /request_quotation$/),
477
     is_sales_ord    => scalar ($form->{type} =~ /sales_order$/),
478
     is_pur_ord      => scalar ($form->{type} =~ /purchase_order$/),
479
  );
805 480

  
806
|;
481
  print $form->parse_html_template2("oe/orders_header", { %TMPL_VAR });
807 482

  
808 483
  $lxdebug->leave_sub();
809 484
}
......
813 488

  
814 489
  $form->{invtotal} = $form->{invsubtotal};
815 490

  
816
  if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
817
    $rows = 2;
818
  }
819
  if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
820
    $introws = 2;
821
  }
822
  $rows = ($rows > $introws) ? $rows : $introws;
823
  $notes =
824
    qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
825
  $intnotes =
826
    qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
827

  
828
  $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
491
  $rows    = max 2, $form->numtextrows($form->{notes}, 25, 8);
492
  $introws = max 2, $form->numtextrows($form->{intnotes}, 35, 8);
493
  $rows    = max $rows, $introws;
829 494

  
830
  $taxincluded = "";
831
  if ($form->{taxaccounts}) {
832
    $taxincluded = qq|
833
	      <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
834
      . $locale->text('Tax Included') . qq|</b><br><br>
835
|;
836
  }
495
  $TMPL_VAR{notes} = qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
496
  $TMPL_VAR{intnotes} = qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
837 497

  
838 498
  if (!$form->{taxincluded}) {
839 499

  
840 500
    foreach $item (split / /, $form->{taxaccounts}) {
841 501
      if ($form->{"${item}_base"}) {
842
        $form->{invtotal} += $form->{"${item}_total"} =
843
          $form->round_amount(
844
                             $form->{"${item}_base"} * $form->{"${item}_rate"},
845
                             2);
846
        $form->{"${item}_total"} =
847
          $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
848

  
849
        $tax .= qq|
502
        $form->{invtotal} += $form->{"${item}_total"} = $form->round_amount( $form->{"${item}_base"} * $form->{"${item}_rate"}, 2);
503
        $form->{"${item}_total"} = $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
504

  
505
        $TMPL_VAR{tax} .= qq|
850 506
	      <tr>
851
		<th align=right>$form->{"${item}_description"}&nbsp;|
852
		                    . $form->{"${item}_rate"} * 100 .qq|%</th>
507
		<th align=right>$form->{"${item}_description"}&nbsp;| . $form->{"${item}_rate"} * 100 .qq|%</th>
853 508
		<td align=right>$form->{"${item}_total"}</td>
854
	      </tr>
855
|;
509
	      </tr> |;
856 510
      }
857 511
    }
858 512

  
859
    $form->{invsubtotal} =
860
      $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
861

  
862
    $subtotal = qq|
863
	      <tr>
864
		<th align=right>| . $locale->text('Subtotal') . qq|</th>
865
		<td align=right>$form->{invsubtotal}</td>
866
	      </tr>
867
|;
868

  
869
  }
513
    $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
870 514

  
871
  if ($form->{taxincluded}) {
515
  } else {
872 516
    foreach $item (split / /, $form->{taxaccounts}) {
873 517
      if ($form->{"${item}_base"}) {
874
        $form->{"${item}_total"} =
875
          $form->round_amount(
876
                           ($form->{"${item}_base"} * $form->{"${item}_rate"} /
877
                              (1 + $form->{"${item}_rate"})
878
                           ),
879
                           2);
880
        $form->{"${item}_netto"} =
881
          $form->round_amount(
882
                          ($form->{"${item}_base"} - $form->{"${item}_total"}),
883
                          2);
884
        $form->{"${item}_total"} =
885
          $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
886
        $form->{"${item}_netto"} =
887
          $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
888

  
889
        $tax .= qq|
518
        $form->{"${item}_total"} = $form->round_amount( ($form->{"${item}_base"} * $form->{"${item}_rate"} / (1 + $form->{"${item}_rate"})), 2);
519
        $form->{"${item}_netto"} = $form->round_amount( ($form->{"${item}_base"} - $form->{"${item}_total"}), 2);
520
        $form->{"${item}_total"} = $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
521
        $form->{"${item}_netto"} = $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
522

  
523
        $TMPL_VAR{tax} .= qq|
890 524
	      <tr>
891
		<th align=right>Enthaltene $form->{"${item}_description"}&nbsp;|
892
		                    . $form->{"${item}_rate"} * 100 .qq|%</th>
525
		<th align=right>Enthaltene $form->{"${item}_description"}&nbsp;| . $form->{"${item}_rate"} * 100 .qq|%</th>
893 526
		<td align=right>$form->{"${item}_total"}</td>
894 527
	      </tr>
895 528
	      <tr>
896 529
	        <th align=right>Nettobetrag</th>
897 530
		<td align=right>$form->{"${item}_netto"}</td>
898
	      </tr>
899
|;
531
	      </tr> |;
900 532
      }
901 533
    }
902

  
903 534
  }
904 535

  
905 536
  $form->{oldinvtotal} = $form->{invtotal};
906
  $form->{invtotal}    =
907
    $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
908

  
909
  print qq|
910
  <tr>
911
    <td>
912
      <table width=100%>
913
	<tr valign=bottom>
914
	  <td>
915
	    <table>
916
	      <tr>
917
		<th align=left>| . $locale->text('Notes') . qq|</th>
918
		<th align=left>| . $locale->text('Internal Notes') . qq|</th>
919
	      </tr>
920
	      <tr valign=top>
921
		<td>$notes</td>
922
		<td>$intnotes</td>
923
	      </tr>
924
	  <tr>
925
    $payments
926
	    </tr>
927
      </table>
928
	  </td>
929
          <td>
930
            <table>
931
|;
932

  
933
  if ($form->{type} =~ /^sales_/) {
934
    print qq|
935
            <tr>
936
              <th  align=left>| . $locale->text('Ertrag') . qq|</th>
937
              <td>| .  $form->format_amount(\%myconfig, $form->{marge_total}, 2, 0) . qq|</td>
938
            </tr>
939
            <tr>
940
              <th  align=left>| . $locale->text('Ertrag prozentual') . qq|</th>
941
              <td>| .  $form->format_amount(\%myconfig, $form->{marge_percent}, 2, 0) . qq| %</td>
942
            </tr>
943
|;
944
  }
945

  
946
  print qq|
947
            <input type=hidden name="marge_total" value="$form->{"marge_total"}">
948
            <input type=hidden name="marge_percent" value="$form->{"marge_percent"}">
949
            </table>
950
          </td>
951
	  <td align=right>
952
	    $taxincluded
953
	    <table>
954
	      $subtotal
955
	      $tax
956
	      <tr>
957
		<th align=right>| . $locale->text('Total') . qq|</th>
958
		<td align=right>$form->{invtotal}</td>
959
	      </tr>
960
	    </table>
961
	  </td>
962
	</tr>
963
      </table>
964
    </td>
965
  </tr>
966
<input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
967
<input type=hidden name=oldtotalpaid value=$totalpaid>
968
  <tr>
969
    <td><hr size=3 noshade></td>
970
  </tr>
971
|;
972

  
973
  if ($webdav) {
974
    $webdav_list = qq|
975

  
976
  <tr>
977
    <th class=listtop align=left>Dokumente im Webdav-Repository</th>
978
  </tr>
979
    <table width=100%>
980
      <td align=left width=30%><b>Dateiname</b></td>
981
      <td align=left width=70%><b>Webdavlink</b></td>
982
|;
983
    foreach $file (@{ $form->{WEBDAV} }) {
984
      $webdav_list .= qq|
985
      <tr>
986
        <td align="left">$file->{name}</td>
987
        <td align="left"><a href="$file->{link}">$file->{type}</a></td>
988
      </tr>
989
|;
990
    }
991
    $webdav_list .= qq|
992
    </table>
993
  </tr>
994
  <tr>
995
    <td><hr size=3 noshade></td>
996
  </tr>
997
|;
998

  
999
    print $webdav_list;
1000
  }
1001

  
1002
  print qq|
1003
  <tr>
1004
    <td>
1005
|;
1006
  print_options();
1007 537

  
1008
  print qq|
1009
    </td>
1010
  </tr>
1011
</table>
538
  print $form->parse_html_template2("oe/orders_footer", {
539
     %TMPL_VAR,
540
     webdav          => $webdav,
541
     print_options   => print_options(inline => 1),
542
     label_edit      => $locale->text("Edit the $form->{type}"),
543
     label_workflow  => $locale->text("Workflow $form->{type}"),
544
  });
1012 545

  
1013
| . $locale->text("Edit the $form->{type}") . qq|<br>
1014
<input class=submit type=submit name=action id=update_button value="|
1015
    . $locale->text('Update') . qq|">
1016
<input class=submit type=submit name=action value="|
1017
    . $locale->text('Ship to') . qq|">
1018
<input class=submit type=submit name=action value="|
1019
    . $locale->text('Print') . qq|">
1020
<input class=submit type=submit name=action value="|
1021
    . $locale->text('E-mail') . qq|">
1022
<input class=submit type=submit name=action value="|
1023
    . $locale->text('Save') . qq|">
1024
<input class=submit type=submit name=action value="|
1025
    . $locale->text('Save and Close') . qq|">
1026
|;
1027

  
1028
  if (($form->{id})) {
1029
    print qq|
1030
  	<input type="button" class="submit" onclick="set_history_window(|
1031
  	. Q($form->{id})
1032
  	. qq|);" name="history" id="history" value="|
1033
  	. $locale->text('history')
1034
  	. qq|">
1035

  
1036
<br>| . $locale->text("Workflow $form->{type}") . qq|<br>
1037
<input class=submit type=submit name=action value="|
1038
      . $locale->text('Save as new') . qq|">
1039
<input class=submit type=submit name=action value="|
1040
      . $locale->text('Delete') . qq|">|;
1041
    if (($form->{type} =~ /sales_quotation$/)) {
1042
      print qq|
1043
<input class=submit type=submit name=action value="|
1044
        . $locale->text('Sales Order') . qq|">|;
1045
    }
1046
    if ($form->{type} =~ /request_quotation$/) {
1047
      print qq|
1048
<input class=submit type=submit name=action value="|
1049
        . $locale->text('Purchase Order') . qq|">|;
1050
    }
1051
    print qq|
1052
<input class=submit type=submit name=action value="|
1053
      . $locale->text('Invoice') . qq|">
1054
|;
1055

  
1056
    if ($form->{type} =~ /sales_order$/) {
1057
      print qq|
1058
<br>$form->{heading} als neue Vorlage verwenden f&uuml;r<br>
1059
<input class=submit type=submit name=action value="|
1060
        . $locale->text('Purchase Order') . qq|">
1061
<input class=submit type=submit name=action value="|
1062
        . $locale->text('Quotation') . qq|">
1063
|;
1064

  
1065
    } elsif ($form->{type} =~ /purchase_order$/) {
1066
      print qq|
1067
<br>$form->{heading} als neue Vorlage verwenden f&uuml;r<br>
1068
<input class=submit type=submit name=action value="|
1069
        . $locale->text('Sales Order') . qq|">
1070
<input class=submit type=submit name=action value="|
1071
        . $locale->text('Request for Quotation') . qq|">
1072
|;
1073

  
1074
    } else {
1075
      print qq|
1076
<br>$form->{heading} als neue Vorlage verwenden f&uuml;r<br>
1077
<input class=submit type=submit name=action value="|
1078
        . $locale->text('Order') . qq|">
1079
|;
1080
    }
1081
  }
1082

  
1083
  $form->hide_form("saved_xyznumber");
1084

  
1085
  print qq|
1086

  
1087
<input type=hidden name=rowcount value=$form->{rowcount}>
1088

  
1089
<input name=callback type=hidden value="$form->{callback}">
1090

  
1091
<input type=hidden name=login value=$form->{login}>
1092
<input type=hidden name=password value=$form->{password}>
1093

  
1094
</form>
1095

  
1096
</body>
1097
</html>
1098
|;
1099 546
  $lxdebug->leave_sub();
1100 547
}
1101 548

  
......
1120 567
  $form->{exchangerate} = $exchangerate if 
1121 568
    $form->{forex} = $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell);
1122 569

  
1123
  # for pricegroups
1124
  $i = $form->{rowcount};
1125

  
1126 570
  $exchangerate = $form->{exchangerate} || 1;
1127 571

  
572
##################### process items ######################################
573
  # for pricegroups
574
  $i = $form->{rowcount};
1128 575
  if (   ($form->{"partnumber_$i"} eq "")
1129 576
      && ($form->{"description_$i"} eq "")
1130 577
      && ($form->{"partsgroup_$i"}  eq "")) {
......
1134 581

  
1135 582
  } else {
1136 583

  
1137
    if (   $form->{type} eq 'purchase_order'
1138
        || $form->{type} eq 'request_quotation') {
1139
      IR->retrieve_item(\%myconfig, \%$form);
1140
    }
1141
    if (   $form->{type} eq 'sales_order' 
1142
        || $form->{type} eq 'sales_quotation') {
584
    if ($form->{type} =~ /^sales/) {
1143 585
      IS->retrieve_item(\%myconfig, \%$form);
586
    } else {
587
      IR->retrieve_item(\%myconfig, \%$form);
1144 588
    }
1145 589

  
1146 590
    my $rows = scalar @{ $form->{item_list} };
......
1192 636
        &set_pricegroup($i);
1193 637
      }
1194 638

  
1195
      &display_form;
1196

  
639
      display_form();
1197 640
    } else {
1198 641

  
1199 642
      # ok, so this is a new part
......
1204 647
          && ($form->{"description_$i"} eq "")) {
1205 648
        $form->{rowcount}--;
1206 649
        $form->{"discount_$i"} = "";
1207
        display_form();
1208 650

  
651
        display_form();
1209 652
      } else {
1210 653
        $form->{"id_$i"}   = 0;
1211 654
        new_item();
1212 655
      }
1213 656
    }
1214 657
  }
658
##################### process items ######################################
659

  
1215 660

  
1216 661
  $lxdebug->leave_sub();
1217 662
}
......
1343 788
  my $employee_block = qq|
1344 789
    <tr>
1345 790
      <th align="right">| . $locale->text('Employee') . qq|</th>
1346
      <td>| .
1347
        NTI($cgi->popup_menu('-name'   => 'employee_id',
1348
                             '-values' => \@values,
1349
                             '-labels' => \%labels)) . qq|
1350
      </td>
791
      <td>| .  NTI($cgi->popup_menu('-name'   => 'employee_id', '-values' => \@values, '-labels' => \%labels)) . qq|</td>
1351 792
    </tr>
1352 793
    <tr>
1353 794
      <th align="right">| . $locale->text('Salesman') . qq|</th>
......
1394 835
          <th align=right>$vc_label</th>
1395 836
          <td colspan=3>$vc</td>
1396 837
        </tr>
1397
	$department
838
$department
1398 839
        <tr>
1399 840
          <th align=right>$ordlabel</th>
1400 841
          <td colspan=3><input name="$ordnumber" size=20></td>
1401 842
        </tr>
1402
  $employee_block
843
$employee_block
1403 844
        <tr>
1404 845
          <th align="right">| . $locale->text('Transaction description') . qq|</th>
1405 846
          <td colspan="3"><input name="transaction_description" size=20></td>
......
1409 850
          <td colspan="3">$projectnumber</td>
1410 851
        </tr>
1411 852
        <tr>
1412
          <th align=right>| . $locale->text('From') . qq|</th>
1413
          $button1
1414
          <th align=right>| . $locale->text('Bis') . qq|</th>
1415
          $button2
853
          <th align=right>| . $locale->text('From') . qq|</th> $button1
854
          <th align=right>| . $locale->text('Bis') . qq|</th> $button2
1416 855
        </tr>
1417 856
        <input type=hidden name=sort value=transdate>
1418 857
        <tr>
......
1420 859
          <td colspan=5>
1421 860
	    <table>
1422 861
        <tr>
1423
          <td><input type="checkbox" name="open" value="1" id="open" checked>
1424
            <label for="open">| . $locale->text("Open") . qq|</td>
1425
          <td><input type="checkbox" name="closed" value="1" id="closed">
1426
            <label for="closed">| . $locale->text("Closed") . qq|</td>
862
          <td><input type="checkbox" name="open" value="1" id="open" checked> <label for="open">| . $locale->text("Open") . qq|</td>
863
          <td><input type="checkbox" name="closed" value="1" id="closed"> <label for="closed">| . $locale->text("Closed") . qq|</td>
1427 864
        </tr>
1428 865
        $delivered
1429 866
	      <tr>
1430
		<td><input name="l_id" class=checkbox type=checkbox value=Y>
1431
		| . $locale->text('ID') . qq|</td>
867
		<td><input name="l_id" class=checkbox type=checkbox value=Y> | . $locale->text('ID') . qq|</td>
1432 868
		<td><input name="l_$ordnumber" class=checkbox type=checkbox value=Y checked> $ordlabel</td>
1433
		<td><input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
1434
    . $locale->text('Date') . qq|</td>
1435
		<td><input name="l_reqdate" class=checkbox type=checkbox value=Y checked> |
1436
    . $locale->text('Required by') . qq|</td>
869
		<td><input name="l_transdate" class=checkbox type=checkbox value=Y checked> | . $locale->text('Date') . qq|</td>
870
		<td><input name="l_reqdate" class=checkbox type=checkbox value=Y checked> | . $locale->text('Required by') . qq|</td>
1437 871
	      </tr>
1438 872
	      <tr>
1439 873
	        <td><input name="l_name" class=checkbox type=checkbox value=Y checked> $vc_label</td>
1440 874
	        <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1441 875
	        
1442
		<td><input name="l_shipvia" class=checkbox type=checkbox value=Y> |
1443
    . $locale->text('Ship via') . qq|</td>
876
		<td><input name="l_shipvia" class=checkbox type=checkbox value=Y> | . $locale->text('Ship via') . qq|</td>
1444 877
	      </tr>
1445 878
	      <tr>
1446
		<td><input name="l_netamount" class=checkbox type=checkbox value=Y> |
1447
    . $locale->text('Amount') . qq|</td>
1448
		<td><input name="l_tax" class=checkbox type=checkbox value=Y> |
1449
    . $locale->text('Tax') . qq|</td>
1450
		<td><input name="l_amount" class=checkbox type=checkbox value=Y checked> |
1451
    . $locale->text('Total') . qq|</td>
879
		<td><input name="l_netamount" class=checkbox type=checkbox value=Y> | . $locale->text('Amount') . qq|</td>
880
		<td><input name="l_tax" class=checkbox type=checkbox value=Y> | . $locale->text('Tax') . qq|</td>
881
		<td><input name="l_amount" class=checkbox type=checkbox value=Y checked> | . $locale->text('Total') . qq|</td>
1452 882
	      </tr>
1453 883
	      <tr>
1454
		<td><input name="l_marge_total" class=checkbox type=checkbox value=Y> |
1455
    .             $locale->text('Ertrag') . qq|</td>
1456
		<td><input name="l_marge_percent" class=checkbox type=checkbox value=Y> |
1457
    .             $locale->text('Ertrag prozentual') . qq|</td>
884
		<td><input name="l_marge_total" class=checkbox type=checkbox value=Y> | .             $locale->text('Ertrag') . qq|</td>
885
		<td><input name="l_marge_percent" class=checkbox type=checkbox value=Y> | .             $locale->text('Ertrag prozentual') . qq|</td>
1458 886
	      </tr>
1459 887
	      <tr>
1460
          <td><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y> |
1461
          . $locale->text('Project Number') . qq|</td>
1462
          <td><input name="l_transaction_description" class=checkbox type=checkbox value=Y> |
1463
          . $locale->text('Transaction description') . qq|</td>
888
          <td><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y> | . $locale->text('Project Number') . qq|</td>
889
          <td><input name="l_transaction_description" class=checkbox type=checkbox value=Y> | . $locale->text('Transaction description') . qq|</td>
1464 890
	      </tr>
1465 891
	      <tr>
1466
	        <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
1467
    . $locale->text('Subtotal') . qq|</td>
1468
                <td><input name="l_salesman" class="checkbox" type="checkbox" value="Y"> |
1469
    . $locale->text('Salesman') . qq|</td>
892
	        <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> | . $locale->text('Subtotal') . qq|</td>
893
                <td><input name="l_salesman" class="checkbox" type="checkbox" value="Y"> | . $locale->text('Salesman') . qq|</td>
1470 894
	      </tr>
1471 895
	    </table>
1472 896
          </td>
......
2535 1959
sub no {
2536 1960
  call_sub($form->{no_nextsub});
2537 1961
}
1962

  
1963
######################################################################################################
1964
# IO ENTKOPPLUNG
1965
# ###############################################################################################
1966
sub display_form {
1967
  $lxdebug->enter_sub();
1968

  
1969
  $form->{"taxaccounts"} =~ s/\s*$//;
1970
  $form->{"taxaccounts"} =~ s/^\s*//;
1971
  foreach my $accno (split(/\s*/, $form->{"taxaccounts"})) {
1972
    map({ delete($form->{"${accno}_${_}"}); } qw(rate description taxnumber));
1973
  }
1974
  $form->{"taxaccounts"} = "";
1975

  
1976
  for my $i (1 .. $form->{"rowcount"}) {
1977
    IC->retrieve_accounts(\%myconfig, $form, $form->{"id_$i"}, $i, 1) if $form->{"id_$i"};
1978
  }
1979

  
1980
  $form->{rowcount}++;
1981
  $form->{"project_id_$form->{rowcount}"} = $form->{globalproject_id};
1982

  
1983
  $form->language_payment(\%myconfig);
1984

  
1985
  Common::webdav_folder($form) if ($webdav);
1986

  
1987
  &form_header;
1988

  
1989
  # create rows
1990
  display_row($form->{rowcount}) if $form->{rowcount};
1991

  
1992
  &form_footer;
1993

  
1994
  $lxdebug->leave_sub();
1995
}
1996

  
1997
sub display_row {
1998
  $lxdebug->enter_sub();
1999
  my $numrows = shift;
2000

  
2001
  # column_index
2002
  my @header_sort = qw(runningnumber partnumber description ship qty unit sellprice_pg sellprice discount linetotal);
2003
  my @HEADER = (
2004
    {  id => 'runningnumber', width => 5,     value => $locale->text('No.'),                  display => 1, },
2005
    {  id => 'partnumber',    width => 12,    value => $locale->text('Number'),               display => 1, },
2006
    {  id => 'description',   width => 30,    value => $locale->text('Part Description'),     display => 1, },
2007
    {  id => 'ship',          width => 5,     value => ($form->{type} eq 'purchase_order' ? $locale->text('Ship rcvd') : $locale->text('Ship')),                 
2008
       display => $form->{type} =~ /sales_order/ || ($form->{type} =~ /purchase_order/ && !($lizenzen && $form->{vc} eq "customer")) , },
2009
    {  id => 'qty',           width => 5,     value => $locale->text('Qty'),                  display => 1, },
2010
    {  id => 'unit',          width => 5,     value => $locale->text('Unit'),                 display => 1, },
2011
    {  id => 'license',       width => 10,    value => $locale->text('License'),              display => 0, },
2012
    {  id => 'serialnr',      width => 10,    value => $locale->text('Serial No.'),           display => 0, },
2013
    {  id => 'projectnr',     width => 10,    value => $locale->text('Project'),              display => 0, },
2014
    {  id => 'sellprice',     width => 15,    value => $locale->text('Price'),                display => 1, },
2015
    {  id => 'sellprice_pg',  width => 15,    value => $locale->text('Pricegroup'),           display => $form->{type} =~ /^sales_/,  },
2016
    {  id => 'discount',      width => undef, value => $locale->text('Discount'),             display => $form->{vc} eq 'customer', },
2017
    {  id => 'linetotal',     width => 10,    value => $locale->text('Extended'),             display => 1, },
2018
    {  id => 'bin',           width => 10,    value => $locale->text('Bin'),                  display => 0, },
2019
  ); 
2020
  my @column_index = map { $_->{id} } grep { $_->{display} } @HEADER;
2021

  
2022
  # cache units
2023
  my $dimension_units = AM->retrieve_units(\%myconfig, $form, "dimension");
2024
  my $service_units   = AM->retrieve_units(\%myconfig, $form, "service");
2025
  my $all_units       = AM->retrieve_units(\%myconfig, $form);
2026

  
2027
  my $colspan = scalar @column_index;
2028

  
2029
  $form->{invsubtotal} = 0;
2030
  map { $form->{"${_}_base"} = 0 } (split(/ /, $form->{taxaccounts}));
2031

  
2032
  # about details 
2033
  $myconfig{show_form_details} = 1                            unless (defined($myconfig{show_form_details}));
2034
  $form->{show_details}        = $myconfig{show_form_details} unless (defined($form->{show_details}));
2035
  # /about details
2036

  
2037
  # translations, unused commented out
2038
#  $runningnumber = $locale->text('No.');
2039
  $deliverydate  = $locale->text('Delivery Date');
2040
  $serialnumber  = $locale->text('Serial No.');
2041
  $projectnumber = $locale->text('Project');
2042
#  $partsgroup    = $locale->text('Group');
2043
  $reqdate       = $locale->text('Reqdate');
2044
  $deliverydate  = $locale->text('Required by');
2045

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

  
2049
  $form->{marge_total}           = 0;
2050
  $form->{sellprice_total}       = 0;
2051
  $form->{lastcost_total}        = 0;
2052
  my %projectnumber_labels = ();
2053
  my @projectnumber_values = ("");
2054

  
2055
  foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
2056
    push(@projectnumber_values, $item->{"id"});
2057
    $projectnumber_labels{$item->{"id"}} = $item->{"projectnumber"};
2058
  }
2059

  
2060
  # rows
2061
  for $i (1 .. $numrows) {
2062

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

  
2066
# unit begin
2067
    $form->{"unit_old_$i"}      ||= $form->{"unit_$i"};
2068
    $form->{"selected_unit_$i"} ||= $form->{"unit_$i"};
2069

  
2070
    my $local_units = $form->{"inventory_accno_$i"} || $form->{"assembly_$i"} ? $dimension_units 
2071
                    : $form->{"id_$i"}                                        ? $service_units 
2072
                    :                                                           $all_units;
2073
    if (   !$local_units->{$form->{"selected_unit_$i"}}                                          # Die ausgewaehlte Einheit ist fuer diesen Artikel nicht gueltig
2074
        || !AM->convert_unit($form->{"selected_unit_$i"}, $form->{"unit_old_$i"}, $all_units)) { # (z.B. Dimensionseinheit war ausgewaehlt, es handelt sich aber
2075
      $form->{"unit_old_$i"} = $form->{"selected_unit_$i"} = $form->{"unit_$i"};                 # um eine Dienstleistung). Dann keinerlei Umrechnung vornehmen.
2076
    }
2077
    # adjust prices by unit, ignore if pricegroup changed
2078
    if ((!$form->{"prices_$i"}) || ($form->{"new_pricegroup_$i"} == $form->{"old_pricegroup_$i"})) {
2079
        $form->{"sellprice_$i"} *= AM->convert_unit($form->{"selected_unit_$i"}, $form->{"unit_old_$i"}, $all_units) || 1;
2080
        $form->{"unit_old_$i"}   = $form->{"selected_unit_$i"};
2081
    }
2082
    my $this_unit = $form->{"unit_$i"};
2083
    $this_unit    = $form->{"selected_unit_$i"} if AM->convert_unit($this_unit, $form->{"selected_unit_$i"}, $all_units);
2084
    $this_unit  ||= "kg";
2085

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

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

  
2092
    $discount  = $form->round_amount($form->{"sellprice_$i"} * $form->{"discount_$i"} / 100, $decimalplaces);
2093
    $linetotal = $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
2094
    $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
2095

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

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

  
2106
    $form->{"qty_$i"} =~ /\.(\d+)/;
2107
    my $qty_dec = length $1;
2108

  
2109
    $column_data{qty}  = $cgi->textfield(-name => "qty_$i", -size => 5, -value => $form->format_amount(\%myconfig, $form->{"qty_$i"}, $qty_dec));
2110
    $column_data{qty} .= $cgi->button(-onclick => "calculate_qty_selection_window('qty_$i','alu_$i', 'formel_$i', $i)", -value => $locale->text('*/'))
2111
                       . $cgi->hidden(-name => "formel_$i", -value => $form->{"formel_$i"}) . $cgi->hidden("-name" => "alu_$i", "-value" => $form->{"alu_$i"})
2112
      if $form->{"formel_$i"};
2113
    $column_data{ship} = $cgi->textfield(-name => "ship_$i", -size => 5, -value => $form->format_amount(\%myconfig, $form->{"ship_$i"}));
2114

  
2115
    # build in drop down list for pricesgroups
2116
    if ($form->{"prices_$i"}) {
2117
      $column_data{sellprice_pg} = qq|<select name="sellprice_pg_$i">$form->{"prices_$i"}</select>|;
2118
      $column_data{sellprice}    = $cgi->textfield(-name => "sellprice_$i", -size => 10, -onBlur => 'check_right_number_format(this)', -value =>
2119
                                   (($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"})
2120
                                      ? $form->format_amount(\%myconfig, $form->{"price_new_$i"}, $decimalplaces)
2121
                                      : $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces)));
2122
    } else {
2123
      # for last row and report
2124
      # set pricegroup drop down list from report menu
2125
      if ($form->{"sellprice_$i"} != 0) {
2126
        $form->{"pricegroup_old_$i"} = $form->{"pricegroup_id_$i"};
2127
        my $default_option           = $form->{"sellprice_$i"}.'--'.$form->{"pricegroup_id_$i"};
2128
        $column_data{sellprice_pg}   = NTI($cgi->popup_menu("sellpricepg_$i", [ $default_option ], $default_option, { $default_option => $form->{"pricegroup_$i"} || '' }));
2129
      } else {
2130
        $column_data{sellprice_pg} = qq|&nbsp;|;
2131
      }
2132
      $column_data{sellprice} = $cgi->textfield(-name => "sellprice_$i", -size => 10, -onBlur => "check_right_number_format(this)", -value =>
2133
                                                $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces));
2134
    }
2135
    $column_data{discount}    = $cgi->textfield(-name => "discount_$i", -size => 3, -value => $form->format_amount(\%myconfig, $form->{"discount_$i"}));
2136
    $column_data{linetotal}   = $form->format_amount(\%myconfig, $linetotal, 2);
2137
    $column_data{bin}         = $form->{"bin_$i"};
2138

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

  
2141
    # second row
2142
    my @ROW2 = ();
2143
    push @ROW2, { value => qq|<b>$serialnumber</b> <input name="serialnumber_$i" size="15" value="$form->{"serialnumber_$i"}">| } 
2144
      if $form->{type} !~ /_quotation/;
2145
    push @ROW2, { value => qq|<b>$projectnumber</b> | . NTI($cgi->popup_menu('-name'  => "project_id_$i",        '-values'  => \@projectnumber_values,
2146
                                                                             '-labels' => \%projectnumber_labels, '-default' => $form->{"project_id_$i"})) };
2147
    push @ROW2, { value => qq|<b>$reqdate</b> <input name="reqdate_$i" size="11" onBlur="check_right_date_format(this)" value="$form->{"reqdate_$i"}">| }
2148
      if $form->{type} =~ /order/;
2149
    push @ROW2, { value => sprintf qq|<b>%s</b>&nbsp;<input type="checkbox" name="subtotal_$i" value="1" %s>|, 
2150
                   $locale->text('Subtotal'), $form->{"subtotal_$i"} ? 'checked' : '' };
2151

  
2152
# begin marge calculations
2153
    my $marge_color;
2154
    my $real_sellprice = $form->{"sellprice_$i"} - $discount;
2155

  
2156
    $form->{"lastcost_$i"} *= 1;
2157
    $form->{"marge_percent_$i"} = 0;
2158

  
2159
    if ($real_sellprice && ($form->{"qty_$i"} * 1)) {
2160
      $form->{"marge_percent_$i"}     = ($real_sellprice - $form->{"lastcost_$i"}) * 100 / $real_sellprice;
2161
      $myconfig{marge_percent_warn} ||= 15;
2162
      $marge_color                    = 'color="#ff0000"' if $form->{"id_$i"} && ($form->{"marge_percent_$i"} < (1 * $myconfig{marge_percent_warn}));
2163
    }
2164

  
2165
    my $marge_adjust_credit_note = $form->{type} eq 'credit_note' ? -1 : 1;
2166
    $form->{"marge_absolut_$i"}  = ($real_sellprice - $form->{"lastcost_$i"}) * $form->{"qty_$i"} * $marge_adjust_credit_note;
2167
    $form->{"marge_total"}      += $form->{"marge_absolut_$i"};
2168
    $form->{"lastcost_total"}   += $form->{"lastcost_$i"} * $form->{"qty_$i"};
2169
    $form->{"sellprice_total"}  += $real_sellprice * $form->{"qty_$i"};
2170

  
2171
    map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) } qw(marge_absolut marge_percent);
2172

  
2173
    push @ROW2, { value => sprintf qq|<font %s><b>%s</b> %s &nbsp;%s%% </font> &nbsp;<b>%s</b> %s &nbsp;<b>%s</b> %s|,
2174
                   $marge_color, $locale->text('Ertrag'),$form->{"marge_absolut_$i"}, $form->{"marge_percent_$i"},
2175
                   $locale->text('LP'), $form->format_amount(\%myconfig, $form->{"listprice_$i"}, 2),
2176
                   $locale->text('EK'), $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, 2) }
2177
      if $form->{"id_$i"} && $form->{type} =~ /^sales_/;
2178
# / marge calculations ending
2179

  
2180
    my @HIDDENS = map { value => $_}, (
2181
          $cgi->hidden("-name" => "unit_old_$i", "-value" => $form->{"selected_unit_$i"}),
2182
          $cgi->hidden("-name" => "price_new_$i", "-value" => $form->format_amount(\%myconfig, $form->{"price_new_$i"})),
2183
          map { ($cgi->hidden("-name" => $_, "-value" => $form->{$_})); } map { $_."_$i" } 
2184
            qw(orderitems_id bo pricegroup_old price_old id inventory_accno bin partsgroup partnotes
2185
               income_accno expense_accno listprice assembly taxaccounts ordnumber transdate cusordnumber
2186
               longdescription basefactor marge_absolut marge_percent lastcost)
2187
    );
2188

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

  
2191
    $form->{invsubtotal} += $linetotal;
2192

  
2193
    push @ROWS, { ROW1 => \@ROW1, ROW2 => \@ROW2, HIDDENS => \@HIDDENS, colspan => $colspan, };
2194
  }
2195

  
2196
  print $form->parse_html_template('oe/sales_order', { ROWS   => \@ROWS, 
2197
                                                       HEADER => \@HEADER,
2198
                                                       show_details_checked => ($form->{show_details} ? "checked" : ""),
2199
                                                       show_details_new     => !$form->{show_details},
2200
                                                     });
2201

  
2202
  if (0 != ($form->{sellprice_total} * 1)) {
2203
    $form->{marge_percent} = ($form->{sellprice_total} - $form->{lastcost_total}) / $form->{sellprice_total} * 100;
2204
  }
2205

  
2206
  $lxdebug->leave_sub();
2207
}

Auch abrufbar als: Unified diff