Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 91ab1ef6

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

  • ID 91ab1ef646193de9359076a876a33a74d7691145
  • Vorgänger d1e4ee79
  • Nachfolger ac7a6ae3

Um die Benutzung des Template Systems mal ein wenig zu foerdern.

Die bin/mozilla/oe.pl noch einmal umgeschrieben, so dass jetzt noch mehr Funktionen ins Frontend ausgelagert sind.

Ein neues Highlight ist die template/generic/multibox.html, die es erlaubt aus wenigen Steuerkommandos ein HTML-Eingabefeld zu erstellen, was bei kleinen Datenmengen als Dropdownbox erscheint, udn bei grossen asl Textfeld, mit dazugehörigem Popup-Button, um eine Auswahlliste aufzumachen. Saemtliche Funktionen lassen sich ueber Perlfunktionsreferenzen wieder zurück ins Backend leiten, und dort wieder mit komplexer Logik füllen. Dokumentation ist im Template direkt enthalten.

Die Customer/Vendor Eingabe macht auch gleich Gebrauch davon und erzeugt bei zu grosser Anzahl ein Textfeld, und daneben einen Suchbutton, der die passenden Kunden in einer Liste anzeigt.

Der "Kundendetails"-Button wurde von "?" umbenannt in "D" (immernoch gruselig)

Auf Wunsch von Moritz habe ich die display_row von bin/mozilla/oe.pl wieder verlagert in die bin/mozilla/io.pl, und dafuer die Version in bin/mozilla/invoice_io.pl deaktiviert.

Unterschiede anzeigen:

bin/mozilla/oe.pl
367 367
                                        limit => $myconfig{vclimit} + 1 },
368 368
                   "price_factors" => "ALL_PRICE_FACTORS");
369 369

  
370
  # contacts
371
  @values = ("", map { $_->{cp_id} } @{ $form->{ALL_CONTACTS} });
372
  %labels = map { $_->{cp_id} => $_->{"cp_name"} . ($_->{cp_abteilung} ? " ($_->{cp_abteilung})" : "") } @{ $form->{ALL_CONTACTS} };
373
  $TMPL_VAR{contact} = NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
374
                                            '-labels' => \%labels, '-default' => $form->{"cp_id"})) if scalar @values > 1;
370
  # label subs
371
  $TMPL_VAR{sales_employee_labels} = sub { $_[0]->{name} || $_[0]->{login} };
372
  $TMPL_VAR{shipto_labels} = sub { join "; ", grep { $_ } map { $_[0]->{"shipto${_}" } } qw(name department_1 street city) };
373
  $TMPL_VAR{contact_labels} = sub { $_[0]->{"cp_name"} . ($_[0]->{cp_abteilung} ? " ($_[0]->{cp_abteilung})" : "") };
375 374

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

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

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

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

  
418
  # employees
419
  @values = map { $_->{id} } @{ $form->{ALL_EMPLOYEES} };
420
  %labels = map { $_->{id} => $_->{name} || $_->{login} } @{ $form->{ALL_EMPLOYEES} };
421
  $TMPL_VAR{employee} = NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
422
                                             '-values' => \@values, '-labels' => \%labels));
423

  
424
  # taxzone
425
  @values = map { $_->{id} } @{ $form->{ALL_TAXZONES} };
426
  %labels = map { $_->{id} => $_->{description} } @{ $form->{ALL_TAXZONES} };
427
  $TMPL_VAR{taxzone} = NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
428
                                            '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px'));
429 382

  
430 383
  # currencies and exchangerate
431 384
  @values = map { $_ } @{ $form->{ALL_CURRENCIES} };
......
2000 1953
  $lxdebug->leave_sub();
2001 1954
}
2002 1955

  
2003
sub display_row {
2004
  $lxdebug->enter_sub();
2005
  my $numrows = shift;
2006

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

  
2028
  # cache units
2029
  my $dimension_units = AM->retrieve_units(\%myconfig, $form, "dimension");
2030
  my $service_units   = AM->retrieve_units(\%myconfig, $form, "service");
2031
  my $all_units       = AM->retrieve_units(\%myconfig, $form);
2032

  
2033
  my $colspan = scalar @column_index;
2034

  
2035
  $form->{invsubtotal} = 0;
2036
  map { $form->{"${_}_base"} = 0 } (split(/ /, $form->{taxaccounts}));
2037

  
2038
  # about details 
2039
  $myconfig{show_form_details} = 1                            unless (defined($myconfig{show_form_details}));
2040
  $form->{show_details}        = $myconfig{show_form_details} unless (defined($form->{show_details}));
2041
  # /about details
2042

  
2043
  # translations, unused commented out
2044
#  $runningnumber = $locale->text('No.');
2045
  $deliverydate  = $locale->text('Delivery Date');
2046
  $serialnumber  = $locale->text('Serial No.');
2047
  $projectnumber = $locale->text('Project');
2048
#  $partsgroup    = $locale->text('Group');
2049
  $reqdate       = $locale->text('Reqdate');
2050
  $deliverydate  = $locale->text('Required by');
2051

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

  
2055
  $form->{marge_total}           = 0;
2056
  $form->{sellprice_total}       = 0;
2057
  $form->{lastcost_total}        = 0;
2058
  my %projectnumber_labels = ();
2059
  my @projectnumber_values = ("");
2060

  
2061
  foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
2062
    push(@projectnumber_values, $item->{"id"});
2063
    $projectnumber_labels{$item->{"id"}} = $item->{"projectnumber"};
2064
  }
2065

  
2066
  # rows
2067
  for $i (1 .. $numrows) {
2068

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

  
2072
# unit begin
2073
    $form->{"unit_old_$i"}      ||= $form->{"unit_$i"};
2074
    $form->{"selected_unit_$i"} ||= $form->{"unit_$i"};
2075

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

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

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

  
2098
    $discount  = $form->round_amount($form->{"sellprice_$i"} * $form->{"discount_$i"} / 100, $decimalplaces);
2099
    $linetotal = $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
2100
    $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
2101

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

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

  
2112
    $form->{"qty_$i"} =~ /\.(\d+)/;
2113
    my $qty_dec = length $1;
2114

  
2115
    $column_data{qty}  = $cgi->textfield(-name => "qty_$i", -size => 5, -value => $form->format_amount(\%myconfig, $form->{"qty_$i"}, $qty_dec));
2116
    $column_data{qty} .= $cgi->button(-onclick => "calculate_qty_selection_window('qty_$i','alu_$i', 'formel_$i', $i)", -value => $locale->text('*/'))
2117
                       . $cgi->hidden(-name => "formel_$i", -value => $form->{"formel_$i"}) . $cgi->hidden("-name" => "alu_$i", "-value" => $form->{"alu_$i"})
2118
      if $form->{"formel_$i"};
2119
    $column_data{ship} = $cgi->textfield(-name => "ship_$i", -size => 5, -value => $form->format_amount(\%myconfig, $form->{"ship_$i"}));
2120

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

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

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

  
2158
# begin marge calculations
2159
    my $marge_color;
2160
    my $real_sellprice = $form->{"sellprice_$i"} - $discount;
2161

  
2162
    $form->{"lastcost_$i"} *= 1;
2163
    $form->{"marge_percent_$i"} = 0;
2164

  
2165
    if ($real_sellprice && ($form->{"qty_$i"} * 1)) {
2166
      $form->{"marge_percent_$i"}     = ($real_sellprice - $form->{"lastcost_$i"}) * 100 / $real_sellprice;
2167
      $myconfig{marge_percent_warn} ||= 15;
2168
      $marge_color                    = 'color="#ff0000"' if $form->{"id_$i"} && ($form->{"marge_percent_$i"} < (1 * $myconfig{marge_percent_warn}));
2169
    }
2170

  
2171
    my $marge_adjust_credit_note = $form->{type} eq 'credit_note' ? -1 : 1;
2172
    $form->{"marge_absolut_$i"}  = ($real_sellprice - $form->{"lastcost_$i"}) * $form->{"qty_$i"} * $marge_adjust_credit_note;
2173
    $form->{"marge_total"}      += $form->{"marge_absolut_$i"};
2174
    $form->{"lastcost_total"}   += $form->{"lastcost_$i"} * $form->{"qty_$i"};
2175
    $form->{"sellprice_total"}  += $real_sellprice * $form->{"qty_$i"};
2176

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

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

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

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

  
2197
    $form->{invsubtotal} += $linetotal;
2198

  
2199
    push @ROWS, { ROW1 => \@ROW1, ROW2 => \@ROW2, HIDDENS => \@HIDDENS, colspan => $colspan, };
2200
  }
2201

  
2202
  print $form->parse_html_template('oe/sales_order', { ROWS   => \@ROWS,
2203
                                                       HEADER => \@HEADER,
2204
                                                     });
2205

  
2206
  if (0 != ($form->{sellprice_total} * 1)) {
2207
    $form->{marge_percent} = ($form->{sellprice_total} - $form->{lastcost_total}) / $form->{sellprice_total} * 100;
2208
  }
2209

  
2210
  $lxdebug->leave_sub();
2211
}

Auch abrufbar als: Unified diff