Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 5d59ad23

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

  • ID 5d59ad2393b60eed6a78d7d82faeb0e4ef9c0357
  • Vorgänger 5486b4a9
  • Nachfolger 56e9d812

oe strict

Unterschiede anzeigen:

bin/mozilla/oe.pl
48 48
require "bin/mozilla/arap.pl";
49 49
require "bin/mozilla/reportgenerator.pl";
50 50

  
51
use strict;
52

  
53
my $print_post;
54
my %TMPL_VAR;
55

  
51 56
1;
52 57

  
53 58
# end of main
......
71 76
};
72 77

  
73 78
sub check_oe_access {
79
  my $form     = $main::form;
80

  
74 81
  my $right   = $oe_access_map->{$form->{type}};
75 82
  $right    ||= 'DOES_NOT_EXIST';
76 83

  
77
  $auth->assert($right);
84
  $main::auth->assert($right);
78 85
}
79 86

  
80 87
sub set_headings {
81
  $lxdebug->enter_sub();
88
  $main::lxdebug->enter_sub();
89

  
90
  my $form     = $main::form;
91
  my $locale   = $main::locale;
82 92

  
83 93
  check_oe_access();
84 94

  
......
113 123
    $form->{vc}      = 'customer';
114 124
  }
115 125

  
116
  $lxdebug->leave_sub();
126
  $main::lxdebug->leave_sub();
117 127
}
118 128

  
119 129
sub add {
120
  $lxdebug->enter_sub();
130
  $main::lxdebug->enter_sub();
131

  
132
  my $form     = $main::form;
121 133

  
122 134
  check_oe_access();
123 135

  
......
131 143
  &prepare_order;
132 144
  &display_form;
133 145

  
134
  $lxdebug->leave_sub();
146
  $main::lxdebug->leave_sub();
135 147
}
136 148

  
137 149
sub edit {
138
  $lxdebug->enter_sub();
150
  $main::lxdebug->enter_sub();
151

  
152
  my $form     = $main::form;
139 153

  
140 154
  check_oe_access();
141 155

  
......
149 163

  
150 164
  # editing without stuff to edit? try adding it first
151 165
  if ($form->{rowcount} && !$form->{print_and_save}) {
166
    my $id;
152 167
    map { $id++ if $form->{"multi_id_$_"} } (1 .. $form->{rowcount});
153 168
    if (!$id) {
154 169

  
155 170
      # reset rowcount
156 171
      undef $form->{rowcount};
157 172
      &add;
158
      $lxdebug->leave_sub();
173
      $main::lxdebug->leave_sub();
159 174
      return;
160 175
    }
161 176
  } elsif (!$form->{id}) {
162 177
    &add;
163
    $lxdebug->leave_sub();
178
    $main::lxdebug->leave_sub();
164 179
    return;
165 180
  }
166 181

  
182
  my ($language_id, $printer_id);
167 183
  if ($form->{print_and_save}) {
168 184
    $form->{action}   = "print";
169 185
    $form->{resubmit} = 1;
......
176 192
  &order_links;
177 193

  
178 194
  $form->{rowcount} = 0;
179
  foreach $ref (@{ $form->{form_details} }) {
195
  foreach my $ref (@{ $form->{form_details} }) {
180 196
    $form->{rowcount}++;
181 197
    map { $form->{"${_}_$form->{rowcount}"} = $ref->{$_} } keys %{$ref};
182 198
  }
......
190 206

  
191 207
  &display_form;
192 208

  
193
  $lxdebug->leave_sub();
209
  $main::lxdebug->leave_sub();
194 210
}
195 211

  
196 212
sub order_links {
197
  $lxdebug->enter_sub();
213
  $main::lxdebug->enter_sub();
214

  
215
  my $form     = $main::form;
216
  my %myconfig = %main::myconfig;
217
  my $locale   = $main::locale;
198 218

  
199 219
  check_oe_access();
200 220

  
......
202 222
  $form->all_vc(\%myconfig, $form->{vc}, ($form->{vc} eq 'customer') ? "AR" : "AP");
203 223

  
204 224
  # retrieve order/quotation
205
  $form->{webdav}   = $webdav;
225
  $form->{webdav}   = $main::webdav;
206 226
  $form->{jsscript} = 1;
207 227

  
208 228
  my $editing = $form->{id};
......
243 263
    $form->{"old$form->{vc}"} .= qq|--$form->{"$form->{vc}_id"}|
244 264
  }
245 265

  
246
  $lxdebug->leave_sub();
266
  $main::lxdebug->leave_sub();
247 267
}
248 268

  
249 269
sub prepare_order {
250
  $lxdebug->enter_sub();
270
  $main::lxdebug->enter_sub();
271

  
272
  my $form     = $main::form;
273
  my %myconfig = %main::myconfig;
251 274

  
252 275
  check_oe_access();
253 276

  
......
263 286
    $form->{"qty_$i"}       = $form->format_amount(\%myconfig, $form->{"qty_$i"});
264 287
  }
265 288

  
266
  $lxdebug->leave_sub();
289
  $main::lxdebug->leave_sub();
267 290
}
268 291

  
269 292
sub form_header {
270
  $lxdebug->enter_sub();
293
  $main::lxdebug->enter_sub();
271 294
  my @custom_hiddens;
272 295

  
296
  my $form     = $main::form;
297
  my %myconfig = %main::myconfig;
298
  my $locale   = $main::locale;
299
  my $cgi      = $main::cgi;
300

  
273 301
  check_oe_access();
274 302

  
275 303
  # Container for template variables. Unfortunately this has to be visible in form_footer too, so not my.
......
325 353
  push @custom_hiddens, "select$form->{vc}";
326 354

  
327 355
  # currencies and exchangerate
328
  @values = map { $_ } @{ $form->{ALL_CURRENCIES} };
329
  %labels = map { $_ => $_ } @{ $form->{ALL_CURRENCIES} };
356
  my @values = map { $_ } @{ $form->{ALL_CURRENCIES} };
357
  my %labels = map { $_ => $_ } @{ $form->{ALL_CURRENCIES} };
330 358
  $form->{currency}            = $form->{defaultcurrency} unless $form->{currency};
331 359
  $TMPL_VAR{show_exchangerate} = $form->{currency} ne $form->{defaultcurrency};
332 360
  $TMPL_VAR{currencies}        = NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
......
335 363
  push @custom_hiddens, "exchangerate" if $form->{forex};
336 364

  
337 365
  # credit remaining
338
  $creditwarning = (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) ? 1 : 0;
366
  my $creditwarning = (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) ? 1 : 0;
339 367
  $TMPL_VAR{is_credit_remaining_negativ} = ($form->{creditremaining} =~ /-/) ? "0" : "1";
340 368

  
341 369
  # business
......
343 371

  
344 372
  push @custom_hiddens, "customer_klass" if $form->{vc} eq 'customer';
345 373

  
346
  $credittext = $locale->text('Credit Limit exceeded!!!');
374
  my $credittext = $locale->text('Credit Limit exceeded!!!');
347 375

  
348 376
  my $follow_up_vc                =  $form->{ $form->{vc} eq 'customer' ? 'customer' : 'vendor' };
349 377
  $follow_up_vc                   =~ s/--\d*\s*$//;
......
358 386
    }
359 387
  }
360 388

  
361
  $onload = ($form->{resubmit} && ($form->{format} eq "html")) ? "window.open('about:blank','Beleg'); document.oe.target = 'Beleg';document.oe.submit()"
389
  my $onload = ($form->{resubmit} && ($form->{format} eq "html")) ? "window.open('about:blank','Beleg'); document.oe.target = 'Beleg';document.oe.submit()"
362 390
          : ($form->{resubmit})                                ? "document.oe.submit()"
363 391
          : ($creditwarning)                                   ? "alert('$credittext')"
364 392
          :                                                      "";
......
395 423

  
396 424
  print $form->parse_html_template("oe/form_header", { %TMPL_VAR });
397 425

  
398
  $lxdebug->leave_sub();
426
  $main::lxdebug->leave_sub();
399 427
}
400 428

  
401 429
sub form_footer {
402
  $lxdebug->enter_sub();
430
  $main::lxdebug->enter_sub();
431

  
432
  my $form     = $main::form;
433
  my %myconfig = %main::myconfig;
434
  my $locale   = $main::locale;
403 435

  
404 436
  check_oe_access();
405 437

  
406 438
  $form->{invtotal} = $form->{invsubtotal};
407 439

  
408
  $rows    = max 2, $form->numtextrows($form->{notes}, 25, 8);
409
  $introws = max 2, $form->numtextrows($form->{intnotes}, 35, 8);
440
  my $rows    = max 2, $form->numtextrows($form->{notes}, 25, 8);
441
  my $introws = max 2, $form->numtextrows($form->{intnotes}, 35, 8);
410 442
  $rows    = max $rows, $introws;
411 443

  
412 444
  $TMPL_VAR{notes}    = qq|<textarea name=notes rows=$rows cols=25 wrap=soft>| . H($form->{notes}) . qq|</textarea>|;
......
414 446

  
415 447
  if (!$form->{taxincluded}) {
416 448

  
417
    foreach $item (split / /, $form->{taxaccounts}) {
449
    foreach my $item (split / /, $form->{taxaccounts}) {
418 450
      if ($form->{"${item}_base"}) {
419 451
        $form->{invtotal} += $form->{"${item}_total"} = $form->round_amount( $form->{"${item}_base"} * $form->{"${item}_rate"}, 2);
420 452
        $form->{"${item}_total"} = $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
......
430 462
#    $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0); # template does this
431 463

  
432 464
  } else {
433
    foreach $item (split / /, $form->{taxaccounts}) {
465
    foreach my $item (split / /, $form->{taxaccounts}) {
434 466
      if ($form->{"${item}_base"}) {
435 467
        $form->{"${item}_total"} = $form->round_amount( ($form->{"${item}_base"} * $form->{"${item}_rate"} / (1 + $form->{"${item}_rate"})), 2);
436 468
        $form->{"${item}_netto"} = $form->round_amount( ($form->{"${item}_base"} - $form->{"${item}_total"}), 2);
......
454 486

  
455 487
  print $form->parse_html_template("oe/form_footer", {
456 488
     %TMPL_VAR,
457
     webdav          => $webdav,
489
     webdav          => $main::webdav,
458 490
     print_options   => print_options(inline => 1),
459 491
     label_edit      => $locale->text("Edit the $form->{type}"),
460 492
     label_workflow  => $locale->text("Workflow $form->{type}"),
461 493
  });
462 494

  
463
  $lxdebug->leave_sub();
495
  $main::lxdebug->leave_sub();
464 496
}
465 497

  
466 498
sub update {
467
  $lxdebug->enter_sub();
499
  $main::lxdebug->enter_sub();
468 500

  
469 501
  my ($recursive_call) = shift;
470 502

  
503
  my $form     = $main::form;
504
  my %myconfig = %main::myconfig;
505

  
471 506
  check_oe_access();
472 507

  
473 508
#  $main::lxdebug->message(0, Dumper($form));
......
477 512
  map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate) unless $recursive_call;
478 513
  $form->{update} = 1;
479 514

  
480
  $payment_id = $form->{payment_id} if $form->{payment_id};
515
  my $payment_id = $form->{payment_id} if $form->{payment_id};
481 516

  
482 517
  &check_name($form->{vc});
483 518

  
484 519
  $form->{payment_id} = $payment_id if $form->{payment_id} eq "";
485 520

  
486
  $buysell              = 'buy';
521
  my $buysell           = 'buy';
487 522
  $buysell              = 'sell' if ($form->{vc} eq 'vendor');
488 523
  $form->{forex}        = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell);
489 524
  $form->{exchangerate} = $form->{forex} if $form->{forex};
490 525

  
491
  $exchangerate = $form->{exchangerate} || 1;
526
  my $exchangerate = $form->{exchangerate} || 1;
492 527

  
493 528
##################### process items ######################################
494 529
  # for pricegroups
495
  $i = $form->{rowcount};
530
  my $i = $form->{rowcount};
496 531
  if (   ($form->{"partnumber_$i"} eq "")
497 532
      && ($form->{"description_$i"} eq "")
498 533
      && ($form->{"partsgroup_$i"}  eq "")) {
......
526 561

  
527 562
      } else {
528 563

  
529
        $sellprice             = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
564
        my $sellprice             = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
530 565
        # hier werden parts (Artikeleigenschaften) aus item_list (retrieve_item aus IS.pm)
531 566
        # (item wahrscheinlich synonym für parts) entsprechend in die form geschrieben ...
532 567

  
......
543 578
        $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
544 579

  
545 580
        ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
546
        $decimalplaces = max 2, length $1;
581
        my $dec_qty       = length $1;
582
        my $decimalplaces = max 2, $dec_qty;
547 583

  
548 584
        if ($sellprice) {
549 585
          $form->{"sellprice_$i"} = $sellprice;
......
552 588
          $form->{"sellprice_$i"} /= $exchangerate;   # if there is an exchange rate adjust sellprice
553 589
        }
554 590

  
555
        $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
591
        my $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
556 592
        map { $form->{"${_}_base"} = 0 }                                 split / /, $form->{taxaccounts};
557 593
        map { $form->{"${_}_base"} += $amount }                          split / /, $form->{"taxaccounts_$i"};
558 594
        map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{taxaccounts} if !$form->{taxincluded};
......
591 627
##################### process items ######################################
592 628

  
593 629

  
594
  $lxdebug->leave_sub();
630
  $main::lxdebug->leave_sub();
595 631
}
596 632

  
597 633
sub search {
598
  $lxdebug->enter_sub();
634
  $main::lxdebug->enter_sub();
635

  
636
  my $form     = $main::form;
637
  my %myconfig = %main::myconfig;
638
  my $locale   = $main::locale;
599 639

  
600 640
  check_oe_access();
601 641

  
......
645 685

  
646 686
  print $form->parse_html_template('oe/search', { %myconfig });
647 687

  
648
  $lxdebug->leave_sub();
688
  $main::lxdebug->leave_sub();
649 689
}
650 690

  
651 691
sub create_subtotal_row {
652
  $lxdebug->enter_sub();
692
  $main::lxdebug->enter_sub();
653 693

  
654 694
  my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
655 695

  
696
  my $form     = $main::form;
697
  my %myconfig = %main::myconfig;
698

  
656 699
  my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
657 700

  
658 701
  map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
......
661 704

  
662 705
  map { $totals->{$_} = 0 } @{ $subtotal_columns };
663 706

  
664
  $lxdebug->leave_sub();
707
  $main::lxdebug->leave_sub();
665 708

  
666 709
  return $row;
667 710
}
668 711

  
669 712
sub orders {
670
  $lxdebug->enter_sub();
713
  $main::lxdebug->enter_sub();
714

  
715
  my $form     = $main::form;
716
  my %myconfig = %main::myconfig;
717
  my $locale   = $main::locale;
718
  my $cgi      = $main::cgi;
671 719

  
672 720
  check_oe_access();
673 721

  
674
  $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
722
  my $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
675 723

  
676 724
  ($form->{ $form->{vc} }, $form->{"$form->{vc}_id"}) = split(/--/, $form->{ $form->{vc} });
677 725

  
......
810 858
  $form->{callback} = $href .= "&sort=$form->{sort}";
811 859

  
812 860
  # escape callback for href
813
  $callback = $form->escape($href);
861
  my $callback = $form->escape($href);
814 862

  
815 863
  my @subtotal_columns = qw(netamount amount marge_total marge_percent);
816 864

  
......
821 869

  
822 870
  my $edit_url = build_std_url('action=edit', 'type', 'vc');
823 871

  
824
  foreach $oe (@{ $form->{OE} }) {
872
  foreach my $oe (@{ $form->{OE} }) {
825 873
    map { $oe->{$_} *= $oe->{exchangerate} } @subtotal_columns;
826 874

  
827 875
    $oe->{tax}       = $oe->{amount} - $oe->{netamount};
......
873 921

  
874 922
  $report->generate_with_headers();
875 923

  
876
  $lxdebug->leave_sub();
924
  $main::lxdebug->leave_sub();
877 925
}
878 926

  
879 927
sub check_delivered_flag {
880
  $lxdebug->enter_sub();
928
  $main::lxdebug->enter_sub();
929

  
930
  my $form     = $main::form;
931
  my %myconfig = %main::myconfig;
881 932

  
882 933
  check_oe_access();
883 934

  
884 935
  if (($form->{type} ne 'sales_order') && ($form->{type} ne 'purchase_order')) {
885
    return $lxdebug->leave_sub();
936
    return $main::lxdebug->leave_sub();
886 937
  }
887 938

  
888 939
  my $all_delivered = 0;
......
901 952

  
902 953
  $form->{delivered} = 1 if $all_delivered;
903 954

  
904
  $lxdebug->leave_sub();
955
  $main::lxdebug->leave_sub();
905 956
}
906 957

  
907 958
sub save_and_close {
908
  $lxdebug->enter_sub();
959
  $main::lxdebug->enter_sub();
960

  
961
  my $form     = $main::form;
962
  my %myconfig = %main::myconfig;
963
  my $locale   = $main::locale;
909 964

  
910 965
  check_oe_access();
911 966

  
......
921 976
  $form->{$idx} =~ s/^\s*//g;
922 977
  $form->{$idx} =~ s/\s*$//g;
923 978

  
924
  $msg = ucfirst $form->{vc};
979
  my $msg = ucfirst $form->{vc};
925 980
  $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
926 981

  
927 982
  # $locale->text('Customer missing!');
......
932 987

  
933 988
  &validate_items;
934 989

  
990
  my $payment_id;
935 991
  if($form->{payment_id}) {
936 992
    $payment_id = $form->{payment_id};
937 993
  }
......
947 1003

  
948 1004
  $form->{id} = 0 if $form->{saveasnew};
949 1005

  
1006
  my ($numberfld, $ordnumber, $err);
950 1007
  # this is for the internal notes section for the [email] Subject
951 1008
  if ($form->{type} =~ /_order$/) {
952 1009
    if ($form->{type} eq 'sales_order') {
......
1002 1059
  $form->redirect($form->{label} . " $form->{$ordnumber} " .
1003 1060
                  $locale->text('saved!'));
1004 1061

  
1005
  $lxdebug->leave_sub();
1062
  $main::lxdebug->leave_sub();
1006 1063
}
1007 1064

  
1008 1065
sub save {
1009
  $lxdebug->enter_sub();
1066
  $main::lxdebug->enter_sub();
1067

  
1068
  my $form     = $main::form;
1069
  my %myconfig = %main::myconfig;
1070
  my $locale   = $main::locale;
1010 1071

  
1011 1072
  check_oe_access();
1012 1073

  
......
1023 1084
  $form->{$idx} =~ s/^\s*//g;
1024 1085
  $form->{$idx} =~ s/\s*$//g;
1025 1086

  
1026
  $msg = ucfirst $form->{vc};
1087
  my $msg = ucfirst $form->{vc};
1027 1088
  $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1028 1089

  
1029 1090
  # $locale->text('Customer missing!');
......
1034 1095

  
1035 1096
  &validate_items;
1036 1097

  
1098
  my $payment_id;
1037 1099
  if($form->{payment_id}) {
1038 1100
    $payment_id = $form->{payment_id};
1039 1101
  }
......
1049 1111

  
1050 1112
  $form->{id} = 0 if $form->{saveasnew};
1051 1113

  
1114
  my ($numberfld, $ordnumber, $err);
1115

  
1052 1116
  # this is for the internal notes section for the [email] Subject
1053 1117
  if ($form->{type} =~ /_order$/) {
1054 1118
    if ($form->{type} eq 'sales_order') {
......
1105 1169
    edit();
1106 1170
    exit;
1107 1171
  }
1108
  $lxdebug->leave_sub();
1172
  $main::lxdebug->leave_sub();
1109 1173
}
1110 1174

  
1111 1175
sub delete {
1112
  $lxdebug->enter_sub();
1176
  $main::lxdebug->enter_sub();
1177

  
1178
  my $form     = $main::form;
1179
  my $locale   = $main::locale;
1113 1180

  
1114 1181
  check_oe_access();
1115 1182

  
1116 1183
  $form->header;
1117 1184

  
1185
  my ($msg, $ordnumber);
1118 1186
  if ($form->{type} =~ /_order$/) {
1119 1187
    $msg       = $locale->text('Are you sure you want to delete Order Number');
1120 1188
    $ordnumber = 'ordnumber';
......
1132 1200
  # delete action variable
1133 1201
  map { delete $form->{$_} } qw(action header);
1134 1202

  
1135
  foreach $key (keys %$form) {
1203
  foreach my $key (keys %$form) {
1136 1204
    next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1137 1205
    $form->{$key} =~ s/\"/&quot;/g;
1138 1206
    print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
......
1154 1222
</html>
1155 1223
|;
1156 1224

  
1157
  $lxdebug->leave_sub();
1225
  $main::lxdebug->leave_sub();
1158 1226
}
1159 1227

  
1160 1228
sub delete_order_quotation {
1161
  $lxdebug->enter_sub();
1229
  $main::lxdebug->enter_sub();
1230

  
1231
  my $form     = $main::form;
1232
  my %myconfig = %main::myconfig;
1233
  my $locale   = $main::locale;
1162 1234

  
1163 1235
  check_oe_access();
1164 1236

  
1237
  my ($msg, $err);
1165 1238
  if ($form->{type} =~ /_order$/) {
1166 1239
    $msg = $locale->text('Order deleted!');
1167 1240
    $err = $locale->text('Cannot delete order!');
......
1169 1242
    $msg = $locale->text('Quotation deleted!');
1170 1243
    $err = $locale->text('Cannot delete quotation!');
1171 1244
  }
1172
  if (OE->delete(\%myconfig, \%$form, $spool)){
1245
  if (OE->delete(\%myconfig, \%$form, $main::spool)){
1173 1246
    # saving the history
1174 1247
    if(!exists $form->{addition}) {
1175 1248
      $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
......
1182 1255
  }
1183 1256
  $form->error($err);
1184 1257

  
1185
  $lxdebug->leave_sub();
1258
  $main::lxdebug->leave_sub();
1186 1259
}
1187 1260

  
1188 1261
sub invoice {
1189
  $lxdebug->enter_sub();
1262
  $main::lxdebug->enter_sub();
1263

  
1264
  my $form     = $main::form;
1265
  my %myconfig = %main::myconfig;
1266
  my $locale   = $main::locale;
1190 1267

  
1191 1268
  check_oe_access();
1192
  $auth->assert($form->{type} eq 'purchase_order' || $form->{type} eq 'request_quotation' ? 'vendor_invoice_edit' : 'invoice_edit');
1269
  $main::auth->assert($form->{type} eq 'purchase_order' || $form->{type} eq 'request_quotation' ? 'vendor_invoice_edit' : 'invoice_edit');
1193 1270

  
1194 1271
  $form->{old_salesman_id} = $form->{salesman_id};
1195 1272
  $form->get_employee();
......
1214 1291
    $form->{quodate}      = $form->{transdate};
1215 1292
  }
1216 1293

  
1217
  $payment_id = $form->{payment_id} if $form->{payment_id};
1294
  my $payment_id = $form->{payment_id} if $form->{payment_id};
1218 1295

  
1219 1296
  # if the name changed get new values
1220 1297
  if (&check_name($form->{vc})) {
......
1225 1302

  
1226 1303
  $form->{cp_id} *= 1;
1227 1304

  
1228
  for $i (1 .. $form->{rowcount}) {
1305
  for my $i (1 .. $form->{rowcount}) {
1229 1306
    for (qw(ship qty sellprice listprice basefactor)) {
1230 1307
      $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if $form->{"${_}_${i}"};
1231 1308
    }
1232 1309
  }
1233 1310

  
1311
  my ($buysell, $orddate, $exchangerate);
1234 1312
  if (   $form->{type} =~ /_order/
1235 1313
      && $form->{currency} ne $form->{defaultcurrency}) {
1236 1314

  
......
1260 1338
    &create_backorder;
1261 1339
  }
1262 1340

  
1341
  my ($script);
1263 1342
  if (   $form->{type} eq 'purchase_order'
1264 1343
      || $form->{type} eq 'request_quotation') {
1265 1344
    $form->{title}  = $locale->text('Add Vendor Invoice');
......
1288 1367

  
1289 1368
  map { $form->{"select$_"} = "" } ($form->{vc}, "currency");
1290 1369

  
1291
  $currency = $form->{currency};
1370
  my $currency = $form->{currency};
1292 1371
  &invoice_links;
1293 1372

  
1294 1373
  $form->{currency}     = $currency;
......
1300 1379
  &prepare_invoice;
1301 1380

  
1302 1381
  # format amounts
1303
  for $i (1 .. $form->{rowcount}) {
1382
  for my $i (1 .. $form->{rowcount}) {
1304 1383
    $form->{"discount_$i"} =
1305 1384
      $form->format_amount(\%myconfig, $form->{"discount_$i"});
1306 1385

  
1307
    ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
1386
    my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
1308 1387
    $dec           = length $dec;
1309
    $decimalplaces = ($dec > 2) ? $dec : 2;
1388
    my $decimalplaces = ($dec > 2) ? $dec : 2;
1310 1389

  
1311 1390
    # copy delivery date from reqdate for order -> invoice conversion
1312 1391
    $form->{"deliverydate_$i"} = $form->{"reqdate_$i"}
......
1328 1407

  
1329 1408
  &display_form;
1330 1409

  
1331
  $lxdebug->leave_sub();
1410
  $main::lxdebug->leave_sub();
1332 1411
}
1333 1412

  
1334 1413
sub backorder_exchangerate {
1335
  $lxdebug->enter_sub();
1414
  $main::lxdebug->enter_sub();
1415

  
1416
  my $form     = $main::form;
1417
  my $locale   = $main::locale;
1336 1418

  
1337 1419
  check_oe_access();
1338 1420

  
......
1349 1431
  # delete action variable
1350 1432
  map { delete $form->{$_} } qw(action header exchangerate);
1351 1433

  
1352
  foreach $key (keys %$form) {
1434
  foreach my $key (keys %$form) {
1353 1435
    next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1354 1436
    $form->{$key} =~ s/\"/&quot;/g;
1355 1437
    print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
......
1399 1481
</html>
1400 1482
|;
1401 1483

  
1402
  $lxdebug->leave_sub();
1484
  $main::lxdebug->leave_sub();
1403 1485
}
1404 1486

  
1405 1487
sub save_exchangerate {
1406
  $lxdebug->enter_sub();
1488
  $main::lxdebug->enter_sub();
1489

  
1490
  my $form     = $main::form;
1491
  my %myconfig = %main::myconfig;
1492
  my $locale   = $main::locale;
1407 1493

  
1408 1494
  $form->isblank("exchangerate", $locale->text('Exchangerate missing!'));
1409 1495
  $form->{exchangerate} =
......
1414 1500

  
1415 1501
  &invoice;
1416 1502

  
1417
  $lxdebug->leave_sub();
1503
  $main::lxdebug->leave_sub();
1418 1504
}
1419 1505

  
1420 1506
sub create_backorder {
1421
  $lxdebug->enter_sub();
1507
  $main::lxdebug->enter_sub();
1508

  
1509
  my $form     = $main::form;
1510
  my %myconfig = %main::myconfig;
1422 1511

  
1423 1512
  $form->{shipped} = 1;
1424 1513

  
1425 1514
  # figure out if we need to create a backorder
1426 1515
  # items aren't saved if qty != 0
1427 1516

  
1428
  for $i (1 .. $form->{rowcount}) {
1429
    $totalqty  += $qty  = $form->{"qty_$i"};
1430
    $totalship += $ship = $form->{"ship_$i"};
1517
  my ($totalqty, $totalship);
1518
  for my $i (1 .. $form->{rowcount}) {
1519
    my $qty  = $form->{"qty_$i"};
1520
    my $ship = $form->{"ship_$i"};
1521
    $totalqty  += $qty;
1522
    $totalship += $ship;
1431 1523

  
1432 1524
    $form->{"qty_$i"} = $qty - $ship;
1433 1525
  }
......
1445 1537
    return;
1446 1538
  }
1447 1539

  
1448
  @flds = (
1540
  my @flds = (
1449 1541
    qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts partsgroup)
1450 1542
  );
1451 1543

  
1452
  for $i (1 .. $form->{rowcount}) {
1544
  for my $i (1 .. $form->{rowcount}) {
1453 1545
    map {
1454 1546
      $form->{"${_}_$i"} =
1455 1547
        $form->format_amount(\%myconfig, $form->{"${_}_$i"})
......
1461 1553
  OE->save(\%myconfig, \%$form);
1462 1554

  
1463 1555
  # rebuild rows for invoice
1464
  @a     = ();
1465
  $count = 0;
1556
  my @a     = ();
1557
  my $count = 0;
1466 1558

  
1467
  for $i (1 .. $form->{rowcount}) {
1559
  for my $i (1 .. $form->{rowcount}) {
1468 1560
    $form->{"qty_$i"} = $form->{"ship_$i"};
1469 1561

  
1470 1562
    if ($form->{"qty_$i"}) {
1471 1563
      push @a, {};
1472
      $j = $#a;
1564
      my $j = $#a;
1473 1565
      map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1474 1566
      $count++;
1475 1567
    }
......
1478 1570
  $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
1479 1571
  $form->{rowcount} = $count;
1480 1572

  
1481
  $lxdebug->leave_sub();
1573
  $main::lxdebug->leave_sub();
1482 1574
}
1483 1575

  
1484 1576
sub save_as_new {
1485
  $lxdebug->enter_sub();
1577
  $main::lxdebug->enter_sub();
1578

  
1579
  my $form     = $main::form;
1486 1580

  
1487 1581
  check_oe_access();
1488 1582

  
......
1512 1606

  
1513 1607
  &save;
1514 1608

  
1515
  $lxdebug->leave_sub();
1609
  $main::lxdebug->leave_sub();
1516 1610
}
1517 1611

  
1518 1612
sub check_for_direct_delivery_yes {
1519
  $lxdebug->enter_sub();
1613
  $main::lxdebug->enter_sub();
1614

  
1615
  my $form     = $main::form;
1520 1616

  
1521 1617
  check_oe_access();
1522 1618

  
......
1525 1621
  map { s/^CFDD_//; $form->{$_} = $form->{"CFDD_${_}"} } grep /^CFDD_/, keys %{ $form };
1526 1622
  $form->{shipto} = 1;
1527 1623
  purchase_order();
1528
  $lxdebug->leave_sub();
1624
  $main::lxdebug->leave_sub();
1529 1625
}
1530 1626

  
1531 1627
sub check_for_direct_delivery_no {
1532
  $lxdebug->enter_sub();
1628
  $main::lxdebug->enter_sub();
1629

  
1630
  my $form     = $main::form;
1533 1631

  
1534 1632
  check_oe_access();
1535 1633

  
......
1537 1635
  delete @{$form}{grep /^shipto/, keys %{ $form }};
1538 1636
  purchase_order();
1539 1637

  
1540
  $lxdebug->leave_sub();
1638
  $main::lxdebug->leave_sub();
1541 1639
}
1542 1640

  
1543 1641
sub check_for_direct_delivery {
1544
  $lxdebug->enter_sub();
1642
  $main::lxdebug->enter_sub();
1643

  
1644
  my $form     = $main::form;
1645
  my %myconfig = %main::myconfig;
1545 1646

  
1546 1647
  check_oe_access();
1547 1648

  
1548 1649
  if ($form->{direct_delivery_checked}
1549 1650
      || (!$form->{shiptoname} && !$form->{shiptostreet} && !$form->{shipto_id})) {
1550
    $lxdebug->leave_sub();
1651
    $main::lxdebug->leave_sub();
1551 1652
    return;
1552 1653
  }
1553 1654

  
......
1564 1665
  $form->header();
1565 1666
  print $form->parse_html_template("oe/check_for_direct_delivery");
1566 1667

  
1567
  $lxdebug->leave_sub();
1668
  $main::lxdebug->leave_sub();
1568 1669

  
1569 1670
  exit 0;
1570 1671
}
1571 1672

  
1572 1673
sub purchase_order {
1573
  $lxdebug->enter_sub();
1674
  $main::lxdebug->enter_sub();
1675

  
1676
  my $form     = $main::form;
1677
  my $locale   = $main::locale;
1574 1678

  
1575 1679
  check_oe_access();
1576
  $auth->assert('purchase_order_edit');
1680
  $main::auth->assert('purchase_order_edit');
1577 1681

  
1578 1682
  if ($form->{type} eq 'sales_order') {
1579 1683
    check_for_direct_delivery();
......
1593 1697

  
1594 1698
  &poso;
1595 1699

  
1596
  $lxdebug->leave_sub();
1700
  $main::lxdebug->leave_sub();
1597 1701
}
1598 1702

  
1599 1703
sub sales_order {
1600
  $lxdebug->enter_sub();
1704
  $main::lxdebug->enter_sub();
1705

  
1706
  my $form     = $main::form;
1707
  my $locale   = $main::locale;
1601 1708

  
1602 1709
  check_oe_access();
1603
  $auth->assert('sales_order_edit');
1710
  $main::auth->assert('sales_order_edit');
1604 1711

  
1605 1712
  if ($form->{type} eq "purchase_order") {
1606 1713
    delete($form->{ordnumber});
......
1616 1723

  
1617 1724
  &poso;
1618 1725

  
1619
  $lxdebug->leave_sub();
1726
  $main::lxdebug->leave_sub();
1620 1727
}
1621 1728

  
1622 1729
sub poso {
1623
  $lxdebug->enter_sub();
1730
  $main::lxdebug->enter_sub();
1731

  
1732
  my $form     = $main::form;
1733
  my %myconfig = %main::myconfig;
1624 1734

  
1625 1735
  check_oe_access();
1626
  $auth->assert('purchase_order_edit | sales_order_edit');
1736
  $main::auth->assert('purchase_order_edit | sales_order_edit');
1627 1737

  
1628 1738
  $form->{transdate} = $form->current_date(\%myconfig);
1629 1739
  delete $form->{duedate};
......
1638 1748
  map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal delivered
1639 1749
                                ordnumber);
1640 1750

  
1641
  for $i (1 .. $form->{rowcount}) {
1751
  for my $i (1 .. $form->{rowcount}) {
1642 1752
    map { $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if ($form->{"${_}_${i}"}) } qw(ship qty sellprice listprice basefactor discount);
1643 1753
  }
1644 1754

  
......
1652 1762

  
1653 1763
  # prepare_order assumes that the discount is in db-notation (0.05) and not user-notation (5)
1654 1764
  # and therefore multiplies the values by 100 in the case of reading from db or making an order from several quotation, so we convert this back into percent-notation for the user interface by multiplying with 0.01
1655
  for $i (1 .. $form->{rowcount}) {
1765
  for my $i (1 .. $form->{rowcount}) {
1656 1766
    $form->{"discount_$i"}  = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 0.01);
1657 1767
  };
1658 1768

  
1659 1769
  # format amounts
1660
  for $i (1 .. $form->{rowcount} - 1) {
1770
  for my $i (1 .. $form->{rowcount} - 1) {
1661 1771
    map { $form->{"${_}_$i"} =~ s/\"/&quot;/g } qw(partnumber description unit);
1662 1772
  }
1663 1773

  
1664 1774
  &update;
1665 1775

  
1666
  $lxdebug->leave_sub();
1776
  $main::lxdebug->leave_sub();
1667 1777
}
1668 1778

  
1669 1779
sub delivery_order {
1670
  $lxdebug->enter_sub();
1780
  $main::lxdebug->enter_sub();
1781

  
1782
  my $form     = $main::form;
1783
  my %myconfig = %main::myconfig;
1671 1784

  
1672 1785
  if ($form->{type} =~ /^sales/) {
1673
    $auth->assert('sales_delivery_order_edit');
1786
    $main::auth->assert('sales_delivery_order_edit');
1674 1787

  
1675 1788
    $form->{vc}    = 'customer';
1676 1789
    $form->{type}  = 'sales_delivery_order';
1677 1790

  
1678 1791
  } else {
1679
    $auth->assert('purchase_delivery_order_edit');
1792
    $main::auth->assert('purchase_delivery_order_edit');
1680 1793

  
1681 1794
    $form->{vc}    = 'vendor';
1682 1795
    $form->{type}  = 'purchase_delivery_order';
......
1698 1811
  # reset
1699 1812
  delete @{$form}{qw(id subject message cc bcc printed emailed queued creditlimit creditremaining discount tradediscount oldinvtotal closed delivered)};
1700 1813

  
1701
  for $i (1 .. $form->{rowcount}) {
1814
  for my $i (1 .. $form->{rowcount}) {
1702 1815
    map { $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if ($form->{"${_}_${i}"}) } qw(ship qty sellprice listprice basefactor discount);
1703 1816
  }
1704 1817

  
......
1712 1825

  
1713 1826
  update();
1714 1827

  
1715
  $lxdebug->leave_sub();
1828
  $main::lxdebug->leave_sub();
1716 1829
}
1717 1830

  
1718 1831
sub e_mail {
1719
  $lxdebug->enter_sub();
1832
  $main::lxdebug->enter_sub();
1833

  
1834
  my $form     = $main::form;
1720 1835

  
1721 1836
  check_oe_access();
1722 1837

  
......
1732 1847

  
1733 1848
  edit_e_mail();
1734 1849

  
1735
  $lxdebug->leave_sub();
1850
  $main::lxdebug->leave_sub();
1736 1851
}
1737 1852

  
1738 1853
sub yes {
1739
  call_sub($form->{yes_nextsub});
1854
  call_sub($main::form->{yes_nextsub});
1740 1855
}
1741 1856

  
1742 1857
sub no {
1743
  call_sub($form->{no_nextsub});
1858
  call_sub($main::form->{no_nextsub});
1744 1859
}
1745 1860

  
1746 1861
######################################################################################################
1747 1862
# IO ENTKOPPLUNG
1748 1863
# ###############################################################################################
1749 1864
sub display_form {
1750
  $lxdebug->enter_sub();
1865
  $main::lxdebug->enter_sub();
1866

  
1867
  my $form     = $main::form;
1868
  my %myconfig = %main::myconfig;
1751 1869

  
1752 1870
  check_oe_access();
1753 1871

  
......
1769 1887

  
1770 1888
  $form->language_payment(\%myconfig);
1771 1889

  
1772
  Common::webdav_folder($form) if ($webdav);
1890
  Common::webdav_folder($form) if ($main::webdav);
1773 1891

  
1774 1892
  &form_header;
1775 1893

  
......
1778 1896

  
1779 1897
  &form_footer;
1780 1898

  
1781
  $lxdebug->leave_sub();
1899
  $main::lxdebug->leave_sub();
1782 1900
}
1783 1901

  
1784 1902
sub report_for_todo_list {
1785
  $lxdebug->enter_sub();
1903
  $main::lxdebug->enter_sub();
1904

  
1905
  my $form     = $main::form;
1786 1906

  
1787 1907
  my $quotations = OE->transactions_for_todo_list();
1788 1908
  my $content;
......
1794 1914
                                                                           'edit_url'   => $edit_url });
1795 1915
  }
1796 1916

  
1797
  $lxdebug->leave_sub();
1917
  $main::lxdebug->leave_sub();
1798 1918

  
1799 1919
  return $content;
1800 1920
}

Auch abrufbar als: Unified diff