1 #=====================================================================
 
   4 # Based on SQL-Ledger Version 2.1.9
 
   5 # Web http://www.lx-office.org
 
   6 #############################################################################
 
   7 # Veraendert 2005-01-05 - Marco Welter <mawe@linux-studio.de> - Neue Optik  #
 
   8 #############################################################################
 
   9 # SQL-Ledger, Accounting
 
  10 # Copyright (c) 1998-2002
 
  12 #  Author: Dieter Simader
 
  13 #   Email: dsimader@sql-ledger.org
 
  14 #     Web: http://www.sql-ledger.org
 
  17 # This program is free software; you can redistribute it and/or modify
 
  18 # it under the terms of the GNU General Public License as published by
 
  19 # the Free Software Foundation; either version 2 of the License, or
 
  20 # (at your option) any later version.
 
  22 # This program is distributed in the hope that it will be useful,
 
  23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  25 # GNU General Public License for more details.
 
  26 # You should have received a copy of the GNU General Public License
 
  27 # along with this program; if not, write to the Free Software
 
  28 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
  30 #######################################################################
 
  32 # common routines used in is, ir, oe
 
  34 #######################################################################
 
  38 use List::Util qw(max first);
 
  46 require "bin/mozilla/common.pl";
 
  48 # any custom scripts for this one
 
  49 if (-f "bin/mozilla/custom_io.pl") {
 
  50   eval { require "bin/mozilla/custom_io.pl"; };
 
  52 if (-f "bin/mozilla/$form->{login}_io.pl") {
 
  53   eval { require "bin/mozilla/$form->{login}_io.pl"; };
 
  60 # this is for our long dates
 
  61 # $locale->text('January')
 
  62 # $locale->text('February')
 
  63 # $locale->text('March')
 
  64 # $locale->text('April')
 
  65 # $locale->text('May ')
 
  66 # $locale->text('June')
 
  67 # $locale->text('July')
 
  68 # $locale->text('August')
 
  69 # $locale->text('September')
 
  70 # $locale->text('October')
 
  71 # $locale->text('November')
 
  72 # $locale->text('December')
 
  74 # this is for our short month
 
  75 # $locale->text('Jan')
 
  76 # $locale->text('Feb')
 
  77 # $locale->text('Mar')
 
  78 # $locale->text('Apr')
 
  79 # $locale->text('May')
 
  80 # $locale->text('Jun')
 
  81 # $locale->text('Jul')
 
  82 # $locale->text('Aug')
 
  83 # $locale->text('Sep')
 
  84 # $locale->text('Oct')
 
  85 # $locale->text('Nov')
 
  86 # $locale->text('Dec')
 
  91 ########################################
 
  92 # Eintrag fuer Version 2.2.0 geaendert #
 
  93 # neue Optik im Rechnungsformular      #
 
  94 ########################################
 
  96   $lxdebug->enter_sub();
 
  98   $auth->assert('part_service_assembly_edit | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
 
  99                 'request_quotation_edit     | sales_quotation_edit | purchase_order_edit');
 
 103   my ($readonly, $stock_in_out, $stock_in_out_title);
 
 105   my $is_purchase = (first { $_ eq $form->{type} } qw(request_quotation purchase_order)) || ($form->{script} eq 'ir.pl');
 
 108   my @header_sort = qw(runningnumber partnumber description ship qty unit sellprice_pg sellprice discount linetotal);
 
 110     {  id => 'runningnumber', width => 5,     value => $locale->text('No.'),                  display => 1, },
 
 111     {  id => 'partnumber',    width => 12,    value => $locale->text('Number'),               display => 1, },
 
 112     {  id => 'description',   width => 30,    value => $locale->text('Part Description'),     display => 1, },
 
 113     {  id => 'ship',          width => 5,     value => ($form->{type} eq 'purchase_order' ? $locale->text('Ship rcvd') : $locale->text('Ship')),                 
 
 114        display => $form->{type} =~ /sales_order/ || ($form->{type} =~ /purchase_order/ && !($lizenzen && $form->{vc} eq "customer")) , },
 
 115     {  id => 'qty',           width => 5,     value => $locale->text('Qty'),                  display => 1, },
 
 116     {  id => 'price_factor',  width => 5,     value => $locale->text('Price Factor'),         display => 1, },
 
 117     {  id => 'unit',          width => 5,     value => $locale->text('Unit'),                 display => 1, },
 
 118     {  id => 'license',       width => 10,    value => $locale->text('License'),              display => 0, },
 
 119     {  id => 'serialnr',      width => 10,    value => $locale->text('Serial No.'),           display => 0, },
 
 120     {  id => 'projectnr',     width => 10,    value => $locale->text('Project'),              display => 0, },
 
 121     {  id => 'sellprice',     width => 15,    value => $locale->text('Price'),                display => 1, },
 
 122     {  id => 'sellprice_pg',  width => 15,    value => $locale->text('Pricegroup'),           display => ($form->{type} =~ /^sales_/),  },
 
 123     {  id => 'discount',      width => 5,     value => $locale->text('Discount'),             display => ($form->{vc} eq 'customer'), },
 
 124     {  id => 'linetotal',     width => 10,    value => $locale->text('Extended'),             display => 1, },
 
 125     {  id => 'bin',           width => 10,    value => $locale->text('Bin'),                  display => 0, },
 
 127   my @column_index = map { $_->{id} } grep { $_->{display} } @HEADER;
 
 130   my $dimension_units = AM->retrieve_units(\%myconfig, $form, "dimension");
 
 131   my $service_units   = AM->retrieve_units(\%myconfig, $form, "service");
 
 132   my $all_units       = AM->retrieve_units(\%myconfig, $form);
 
 134   my %price_factors   = map { $_->{id} => $_->{factor} } @{ $form->{ALL_PRICE_FACTORS} };
 
 136   my $colspan = scalar @column_index;
 
 138   $form->{invsubtotal} = 0;
 
 139   map { $form->{"${_}_base"} = 0 } (split(/ /, $form->{taxaccounts}));
 
 142   $myconfig{show_form_details} = 1                            unless (defined($myconfig{show_form_details}));
 
 143   $form->{show_details}        = $myconfig{show_form_details} unless (defined($form->{show_details}));
 
 146   # translations, unused commented out
 
 147 #  $runningnumber = $locale->text('No.');
 
 148   $deliverydate  = $locale->text('Delivery Date');
 
 149   $serialnumber  = $locale->text('Serial No.');
 
 150   $projectnumber = $locale->text('Project');
 
 151 #  $partsgroup    = $locale->text('Group');
 
 152   $reqdate       = $locale->text('Reqdate');
 
 153   $deliverydate  = $locale->text('Required by');
 
 156   my %align  = map { $_ => 'right' } qw(qty ship right sellprice_pg discount linetotal);
 
 157   my %nowrap = map { $_ => 1 }       qw(description unit);
 
 159   $form->{marge_total}           = 0;
 
 160   $form->{sellprice_total}       = 0;
 
 161   $form->{lastcost_total}        = 0;
 
 162   my %projectnumber_labels = ();
 
 163   my @projectnumber_values = ("");
 
 165   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
 166     push(@projectnumber_values, $item->{"id"});
 
 167     $projectnumber_labels{$item->{"id"}} = $item->{"projectnumber"};
 
 171   for $i (1 .. $numrows) {
 
 174     map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(qty ship discount sellprice price_new price_old) unless ($form->{simple_save});
 
 177     $form->{"unit_old_$i"}      ||= $form->{"unit_$i"};
 
 178     $form->{"selected_unit_$i"} ||= $form->{"unit_$i"};
 
 180     my $local_units = $form->{"inventory_accno_$i"} || $form->{"assembly_$i"} ? $dimension_units 
 
 181                     : $form->{"id_$i"}                                        ? $service_units 
 
 183     if (   !$local_units->{$form->{"selected_unit_$i"}}                                          # Die ausgewaehlte Einheit ist fuer diesen Artikel nicht gueltig
 
 184         || !AM->convert_unit($form->{"selected_unit_$i"}, $form->{"unit_old_$i"}, $all_units)) { # (z.B. Dimensionseinheit war ausgewaehlt, es handelt sich aber
 
 185       $form->{"unit_old_$i"} = $form->{"selected_unit_$i"} = $form->{"unit_$i"};                 # um eine Dienstleistung). Dann keinerlei Umrechnung vornehmen.
 
 187     # adjust prices by unit, ignore if pricegroup changed
 
 188     if ((!$form->{"prices_$i"}) || ($form->{"new_pricegroup_$i"} == $form->{"old_pricegroup_$i"})) {
 
 189         $form->{"sellprice_$i"} *= AM->convert_unit($form->{"selected_unit_$i"}, $form->{"unit_old_$i"}, $all_units) || 1;
 
 190         $form->{"unit_old_$i"}   = $form->{"selected_unit_$i"};
 
 192     my $this_unit = $form->{"unit_$i"};
 
 193     $this_unit    = $form->{"selected_unit_$i"} if AM->convert_unit($this_unit, $form->{"selected_unit_$i"}, $all_units);
 
 196     if (0 < scalar @{ $form->{ALL_PRICE_FACTORS} }) {
 
 197       my @values = ('', map { $_->{id}                      } @{ $form->{ALL_PRICE_FACTORS} });
 
 198       my %labels =      map { $_->{id} => $_->{description} } @{ $form->{ALL_PRICE_FACTORS} };
 
 200       $column_data{price_factor} =
 
 201         NTI($cgi->popup_menu('-name'    => "price_factor_id_$i",
 
 202                              '-default' => $form->{"price_factor_id_$i"},
 
 203                              '-values'  => \@values,
 
 204                              '-labels'  => \%labels,
 
 205                              '-style'   => 'width:90px'));
 
 207       $column_data{price_factor} = ' ';
 
 210     $column_data{"unit"} = AM->unit_select_html($local_units, "unit_$i", $this_unit, $form->{"id_$i"} ? $form->{"unit_$i"} : undef);
 
 213     $form->{"sellprice_$i"} =~ /\.(\d+)/;
 
 214     $decimalplaces = max 2, length $1;
 
 216     $price_factor   = $price_factors{$form->{"price_factor_id_$i"}} || 1;
 
 217     $discount       = $form->round_amount($form->{"sellprice_$i"} * $form->{"discount_$i"} / 100, $decimalplaces);
 
 218     $linetotal      = $form->round_amount(($form->{"sellprice_$i"} - $discount) / $price_factor, $decimalplaces);
 
 219     $linetotal      = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
 
 221     # convert " to "
 
 222     map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description unit unit_old);
 
 224     $column_data{runningnumber} = $cgi->textfield(-name => "runningnumber_$i", -size => 5,  -value => $i);    # HuT
 
 225     $column_data{partnumber}    = $cgi->textfield(-name => "partnumber_$i",    -size => 12, -value => $form->{"partnumber_$i"});
 
 226     $column_data{description} = ((($rows = $form->numtextrows($form->{"description_$i"}, 30, 6)) > 1) # if description is too large, use a textbox instead
 
 227                                 ? $cgi->textarea( -name => "description_$i", -default => H($form->{"description_$i"}), -rows => $rows, -columns => 30)
 
 228                                 : $cgi->textfield(-name => "description_$i",   -size => 30, -value => $form->quote($form->{"description_$i"})))
 
 229                                 . $cgi->button(-value => $locale->text('L'), -onClick => "set_longdescription_window('longdescription_$i')");
 
 231     $form->{"qty_$i"} =~ /\.(\d+)/;
 
 232     my $qty_dec = length $1;
 
 234     $column_data{qty}  = $cgi->textfield(-name => "qty_$i", -size => 5, -value => $form->format_amount(\%myconfig, $form->{"qty_$i"}, $qty_dec));
 
 235     $column_data{qty} .= $cgi->button(-onclick => "calculate_qty_selection_window('qty_$i','alu_$i', 'formel_$i', $i)", -value => $locale->text('*/'))
 
 236                        . $cgi->hidden(-name => "formel_$i", -value => $form->{"formel_$i"}) . $cgi->hidden("-name" => "alu_$i", "-value" => $form->{"alu_$i"})
 
 237       if $form->{"formel_$i"};
 
 238     $column_data{ship} = $cgi->textfield(-name => "ship_$i", -size => 5, -value => $form->format_amount(\%myconfig, $form->{"ship_$i"}));
 
 240     # build in drop down list for pricesgroups
 
 241     if ($form->{"prices_$i"}) {
 
 242       $column_data{sellprice_pg} = qq|<select name="sellprice_pg_$i">$form->{"prices_$i"}</select>|;
 
 243       $column_data{sellprice}    = $cgi->textfield(-name => "sellprice_$i", -size => 10, -onBlur => 'check_right_number_format(this)', -value =>
 
 244                                    (($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"})
 
 245                                       ? $form->format_amount(\%myconfig, $form->{"price_new_$i"}, $decimalplaces)
 
 246                                       : $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces)));
 
 248       # for last row and report
 
 249       # set pricegroup drop down list from report menu
 
 250       if ($form->{"sellprice_$i"} != 0) {
 
 251         $form->{"pricegroup_old_$i"} = $form->{"pricegroup_id_$i"};
 
 252         my $default_option           = $form->{"sellprice_$i"}.'--'.$form->{"pricegroup_id_$i"};
 
 253         $column_data{sellprice_pg}   = NTI($cgi->popup_menu("sellpricepg_$i", [ $default_option ], $default_option, { $default_option => $form->{"pricegroup_$i"} || '' }));
 
 255         $column_data{sellprice_pg} = qq| |;
 
 257       $column_data{sellprice} = $cgi->textfield(-name => "sellprice_$i", -size => 10, -onBlur => "check_right_number_format(this)", -value =>
 
 258                                                 $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces));
 
 260     $column_data{discount}    = $cgi->textfield(-name => "discount_$i", -size => 3, -value => $form->format_amount(\%myconfig, $form->{"discount_$i"}));
 
 261     $column_data{linetotal}   = $form->format_amount(\%myconfig, $linetotal, 2);
 
 262     $column_data{bin}         = $form->{"bin_$i"};
 
 264     my @ROW1 = map { value => $column_data{$_}, align => $align{$_}, nowrap => $nowrap{$_} }, @column_index;
 
 268     push @ROW2, { value => qq|<b>$serialnumber</b> <input name="serialnumber_$i" size="15" value="$form->{"serialnumber_$i"}">| } 
 
 269       if $form->{type} !~ /_quotation/;
 
 270     push @ROW2, { value => qq|<b>$projectnumber</b> | . NTI($cgi->popup_menu('-name'  => "project_id_$i",        '-values'  => \@projectnumber_values,
 
 271                                                                              '-labels' => \%projectnumber_labels, '-default' => $form->{"project_id_$i"})) };
 
 272     push @ROW2, { value => qq|<b>$reqdate</b> <input name="reqdate_$i" size="11" onBlur="check_right_date_format(this)" value="$form->{"reqdate_$i"}">| }
 
 273       if $form->{type} =~ /order/;
 
 274     push @ROW2, { value => sprintf qq|<b>%s</b> <input type="checkbox" name="subtotal_$i" value="1" %s>|, 
 
 275                    $locale->text('Subtotal'), $form->{"subtotal_$i"} ? 'checked' : '' };
 
 277 # begin marge calculations
 
 279     my $real_sellprice     = ($form->{"sellprice_$i"} - $discount) / $price_factor;
 
 280     my $marge_price_factor = $form->{"marge_price_factor_$i"} * 1 || 1;
 
 282     $form->{"lastcost_$i"} *= 1;
 
 283     $form->{"marge_percent_$i"} = 0;
 
 285     if ($real_sellprice && ($form->{"qty_$i"} * 1)) {
 
 286       $form->{"marge_percent_$i"}     = ($real_sellprice - $form->{"lastcost_$i"} / $marge_price_factor) * 100 / $real_sellprice;
 
 287       $myconfig{marge_percent_warn} ||= 15;
 
 288       $marge_color                    = 'color="#ff0000"' if $form->{"id_$i"} && ($form->{"marge_percent_$i"} < (1 * $myconfig{marge_percent_warn}));
 
 291     my $marge_adjust_credit_note = $form->{type} eq 'credit_note' ? -1 : 1;
 
 292     $form->{"marge_absolut_$i"}  = ($real_sellprice - $form->{"lastcost_$i"} / $marge_price_factor) * $form->{"qty_$i"} * $marge_adjust_credit_note;
 
 293     $form->{"marge_total"}      += $form->{"marge_absolut_$i"};
 
 294     $form->{"lastcost_total"}   += $form->{"lastcost_$i"} * $form->{"qty_$i"} / $marge_price_factor;
 
 295     $form->{"sellprice_total"}  += $real_sellprice * $form->{"qty_$i"};
 
 297     map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) } qw(marge_absolut marge_percent);
 
 299     push @ROW2, { value => sprintf qq|<font %s><b>%s</b> %s  %s%% </font>  <b>%s</b> %s  <b>%s</b> %s|,
 
 300                    $marge_color, $locale->text('Ertrag'),$form->{"marge_absolut_$i"}, $form->{"marge_percent_$i"},
 
 301                    $locale->text('LP'), $form->format_amount(\%myconfig, $form->{"listprice_$i"}, 2),
 
 302                    $locale->text('EK'), $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, 2) }
 
 303       if $form->{"id_$i"} && $form->{type} =~ /^sales_/ && !$is_delivery_order;
 
 304 # / marge calculations ending
 
 308     push @hidden_vars, qw(partunit) if ($is_purchase);
 
 310     my @HIDDENS = map { value => $_}, (
 
 311           $cgi->hidden("-name" => "unit_old_$i", "-value" => $form->{"selected_unit_$i"}),
 
 312           $cgi->hidden("-name" => "price_new_$i", "-value" => $form->format_amount(\%myconfig, $form->{"price_new_$i"})),
 
 313           map { ($cgi->hidden("-name" => $_, "-value" => $form->{$_})); } map { $_."_$i" } 
 
 314             (qw(orderitems_id bo pricegroup_old price_old id inventory_accno bin partsgroup partnotes
 
 315                 income_accno expense_accno listprice assembly taxaccounts ordnumber transdate cusordnumber
 
 316                 longdescription basefactor marge_absolut marge_percent marge_price_factor lastcost), @hidden_vars)
 
 319     map { $form->{"${_}_base"} += $linetotal } (split(/ /, $form->{"taxaccounts_$i"}));
 
 321     $form->{invsubtotal} += $linetotal;
 
 323     push @ROWS, { ROW1 => \@ROW1, ROW2 => \@ROW2, HIDDENS => \@HIDDENS, colspan => $colspan, error => $form->{"row_error_$i"}, };
 
 326   print $form->parse_html_template('oe/sales_order', { ROWS   => \@ROWS,
 
 330   if (0 != ($form->{sellprice_total} * 1)) {
 
 331     $form->{marge_percent} = ($form->{sellprice_total} - $form->{lastcost_total}) / $form->{sellprice_total} * 100;
 
 334   $lxdebug->leave_sub();
 
 337 ##################################################
 
 338 # build html-code for pricegroups in variable $form->{prices_$j}
 
 341   $lxdebug->enter_sub();
 
 343   $auth->assert('part_service_assembly_edit | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
 
 344                 'request_quotation_edit     | sales_quotation_edit | purchase_order_edit');
 
 346   my $rowcount = shift;
 
 347   for $j (1 .. $rowcount) {
 
 348     next unless $form->{PRICES}{$j};
 
 349     # build drop down list for pricegroups
 
 350     my $option_tmpl = qq|<option value="%s--%s" %s>%s</option>|;
 
 351     $form->{"prices_$j"}  = join '', map { sprintf $option_tmpl, @$_{qw(price pricegroup_id selected pricegroup)} } 
 
 352                                          (+{ pricegroup => $locale->text("none (pricegroup)") }, @{ $form->{PRICES}{$j} });
 
 354     foreach $item (@{ $form->{PRICES}{$j} }) {
 
 355       # set new selectedpricegroup_id and prices for "Preis"
 
 356       $form->{"pricegroup_old_$j"} = $item->{pricegroup_id}   if $item->{selected} &&  $item->{pricegroup_id};
 
 357       $form->{"sellprice_$j"}      = $item->{price}           if $item->{selected} &&  $item->{pricegroup_id};
 
 358       $form->{"price_new_$j"}      = $form->{"sellprice_$j"}  if $item->{selected} || !$item->{pricegroup_id};
 
 361   $lxdebug->leave_sub();
 
 365   $lxdebug->enter_sub();
 
 367   $auth->assert('part_service_assembly_edit | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
 
 368                 'request_quotation_edit     | sales_quotation_edit | purchase_order_edit');
 
 370   @column_index = qw(ndx partnumber description onhand unit sellprice);
 
 372   $column_data{ndx}        = qq|<th> </th>|;
 
 373   $column_data{partnumber} =
 
 374     qq|<th class="listheading">| . $locale->text('Number') . qq|</th>|;
 
 375   $column_data{description} =
 
 376     qq|<th class="listheading">| . $locale->text('Part Description') . qq|</th>|;
 
 377   $column_data{sellprice} =
 
 378     qq|<th class="listheading">| . $locale->text('Price') . qq|</th>|;
 
 379   $column_data{onhand} =
 
 380     qq|<th class="listheading">| . $locale->text('Qty') . qq|</th>|;
 
 382     qq|<th class="listheading">| . $locale->text('Unit') . qq|</th>|;
 
 383   # list items with radio button on a form
 
 386   $title   = $locale->text('Select from one of the items below');
 
 387   $colspan = $#column_index + 1;
 
 392 <form method="post" action="$form->{script}">
 
 396     <th class="listtop" colspan="$colspan">$title</th>
 
 399   <tr class="listheading">|;
 
 401   map { print "\n$column_data{$_}" } @column_index;
 
 406   foreach $ref (@{ $form->{item_list} }) {
 
 407     $checked = ($i++) ? "" : "checked";
 
 410       if ($ref->{inventory_accno} > 0) {
 
 411         $ref->{"lizenzen"} = qq|<option></option>|;
 
 412         foreach $item (@{ $form->{LIZENZEN}{ $ref->{"id"} } }) {
 
 413           $ref->{"lizenzen"} .=
 
 414             qq|<option value=\"$item->{"id"}\">$item->{"licensenumber"}</option>|;
 
 416         $ref->{"lizenzen"} .= qq|<option value="-1">Neue Lizenz</option>|;
 
 417         $ref->{"lizenzen"} =~ s/\"/"/g;
 
 421     map { $ref->{$_} =~ s/\"/"/g } qw(partnumber description unit);
 
 423     my $display_sellprice  = $ref->{sellprice} * (1 - $form->{tradediscount});
 
 424     $display_sellprice    /= $ref->{price_factor} if ($ref->{price_factor});
 
 425     $display_sellprice     = $form->format_amount(\%myconfig, $display_sellprice, 2);
 
 428       qq|<td><input name="ndx" class="radio" type="radio" value="$i" $checked></td>|;
 
 429     $column_data{partnumber} =
 
 430       qq|<td><input name="new_partnumber_$i" type="hidden" value="$ref->{partnumber}">$ref->{partnumber}</td>|;
 
 431     $column_data{description} =
 
 432       qq|<td><input name="new_description_$i" type="hidden" value="$ref->{description}">$ref->{description}</td>|;
 
 433     $column_data{sellprice} =
 
 434       qq|<td align="right"><input name="new_sellprice_$i" type="hidden" value="$ref->{sellprice}">|
 
 437     $column_data{onhand} =
 
 438       qq|<td align="right"><input name="new_onhand_$i" type="hidden" value="$ref->{onhand}">|
 
 439       . $form->format_amount(\%myconfig, $ref->{onhand}, '', " ")
 
 442       qq|<td>$ref->{unit}</td>|;
 
 446 <tr class=listrow$j>|;
 
 448     map { print "\n$column_data{$_}" } @column_index;
 
 453       qw(bin listprice inventory_accno income_accno expense_accno unit weight
 
 454          assembly taxaccounts partsgroup formel longdescription not_discountable
 
 455          part_payment_id partnotes id lastcost price_factor_id price_factor);
 
 456     push(@new_fields, "lizenzen") if ($lizenzen);
 
 458     print join "\n", map { $cgi->hidden("-name" => "new_${_}_$i", "-value" => $ref->{$_}) } @new_fields;
 
 463 <tr><td colspan="8"><hr size="3" noshade></td></tr>
 
 466 <input name="lastndx" type="hidden" value="$i">
 
 470   # delete action variable
 
 471   map { delete $form->{$_} } qw(action item_list header);
 
 473   # save all other form variables
 
 474   foreach $key (keys %${form}) {
 
 475     next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
 
 476     $form->{$key} =~ s/\"/"/g;
 
 477     print qq|<input name="$key" type="hidden" value="$form->{$key}">\n|;
 
 481 <input type="hidden" name="nextsub" value="item_selected">
 
 484 <input class="submit" type="submit" name="action" value="|
 
 485     . $locale->text('Continue') . qq|">
 
 492   $lxdebug->leave_sub();
 
 496   $lxdebug->enter_sub();
 
 498   $auth->assert('part_service_assembly_edit | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
 
 499                 'request_quotation_edit     | sales_quotation_edit | purchase_order_edit');
 
 501   # replace the last row with the checked row
 
 502   $i = $form->{rowcount};
 
 503   $i = $form->{assembly_rows} if ($form->{item} eq 'assembly');
 
 509   #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
 
 510   #$form->{"sellprice_$i"} = $form->{"sellprice_$i"};
 
 512   # if there was a price entered, override it
 
 513   $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
 
 516     qw(id partnumber description sellprice listprice inventory_accno
 
 517        income_accno expense_accno bin unit weight assembly taxaccounts
 
 518        partsgroup formel longdescription not_discountable partnotes lastcost
 
 519        price_factor_id price_factor);
 
 521   map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } @new_fields;
 
 523   $form->{"marge_price_factor_$i"} = $form->{"new_price_factor_$j"};
 
 525   if ($form->{"part_payment_id_$i"} ne "") {
 
 526     $form->{payment_id} = $form->{"part_payment_id_$i"};
 
 530     map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } qw(lizenzen);
 
 533   ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
 
 535   $decimalplaces = ($dec > 2) ? $dec : 2;
 
 538     $form->{"sellprice_$i"} = $sellprice;
 
 541     # if there is an exchange rate adjust sellprice
 
 542     if (($form->{exchangerate} * 1) != 0) {
 
 543       $form->{"sellprice_$i"} /= $form->{exchangerate};
 
 544       $form->{"sellprice_$i"} =
 
 545         $form->round_amount($form->{"sellprice_$i"}, $decimalplaces);
 
 549   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
 550     qw(sellprice listprice weight);
 
 552   $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
 
 553   $form->{weight}    += ($form->{"weight_$i"} * $form->{"qty_$i"});
 
 555   if ($form->{"not_discountable_$i"}) {
 
 556     $form->{"discount_$i"} = 0;
 
 560     $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) *
 
 562   map { $form->{"${_}_base"} += $amount }
 
 563     (split / /, $form->{"taxaccounts_$i"});
 
 564   map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /,
 
 565     $form->{"taxaccounts_$i"}
 
 566     if !$form->{taxincluded};
 
 568   $form->{creditremaining} -= $amount;
 
 570   $form->{"runningnumber_$i"} = $i;
 
 572   # delete all the new_ variables
 
 573   for $i (1 .. $form->{lastndx}) {
 
 574     map { delete $form->{"new_${_}_$i"} } @new_fields;
 
 577   map { delete $form->{$_} } qw(ndx lastndx nextsub);
 
 582       $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces)
 
 583   } qw(sellprice listprice) if $form->{item} ne 'assembly';
 
 585   # get pricegroups for parts
 
 586   IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
 588   # build up html code for prices_$i
 
 589   set_pricegroup($form->{rowcount});
 
 593   $lxdebug->leave_sub();
 
 597   $lxdebug->enter_sub();
 
 599   $auth->assert('part_service_assembly_edit | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
 
 600                 'request_quotation_edit     | sales_quotation_edit | purchase_order_edit');
 
 603   $form->{old_callback} = $form->escape($form->{callback}, 1);
 
 604   $form->{callback}     = $form->escape("$form->{script}?action=display_form", 1);
 
 606   # save all form variables except action in a previousform variable
 
 607   my $previousform = join '&', map { $form->{$_} =~ s/&/%26/; "$_=$form->{$_}" } grep { !/action/ } keys %$form;
 
 609   push @HIDDENS,      { 'name' => 'previousform', 'value' => $form->escape($previousform, 1) };
 
 610   push @HIDDENS, map +{ 'name' => $_,             'value' => $form->{$_} },                       qw(rowcount vc);
 
 611   push @HIDDENS, map +{ 'name' => $_,             'value' => $form->{"${_}_$form->{rowcount}"} }, qw(partnumber description unit sellprice);
 
 612   push @HIDDENS,      { 'name' => 'taxaccount2',  'value' => $form->{taxaccounts} };
 
 615   print $form->parse_html_template("generic/new_item", { HIDDENS => [ sort { $a->{name} cmp $b->{name} } @HIDDENS ] } );
 
 617   $lxdebug->leave_sub();
 
 621   $lxdebug->enter_sub();
 
 623   $auth->assert('part_service_assembly_edit | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
 
 624                 'request_quotation_edit     | sales_quotation_edit | purchase_order_edit');
 
 629   my @flds = qw(id partnumber description qty ship sellprice unit
 
 630                 discount inventory_accno income_accno expense_accno listprice
 
 631                 taxaccounts bin assembly weight projectnumber project_id
 
 632                 oldprojectnumber runningnumber serialnumber partsgroup payment_id
 
 633                 not_discountable shop ve gv buchungsgruppen_id language_values
 
 634                 sellprice_pg pricegroup_old price_old price_new unit_old ordnumber
 
 635                 transdate longdescription basefactor marge_total marge_percent
 
 636                 marge_price_factor lastcost price_factor_id);
 
 638   # remove any makes or model rows
 
 639   if ($form->{item} eq 'part') {
 
 640     map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
 641       qw(listprice sellprice lastcost weight rop);
 
 643   } elsif ($form->{item} eq 'assembly') {
 
 645     $form->{sellprice} = 0;
 
 647     map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
 648       qw(listprice rop stock);
 
 651       qw(id qty unit bom partnumber description sellprice weight runningnumber partsgroup);
 
 653     for my $i (1 .. ($form->{assembly_rows} - 1)) {
 
 654       if ($form->{"qty_$i"}) {
 
 658         $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
 
 660         map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
 
 662         #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
 
 664         $form->{sellprice} += ($form->{"qty_$i"} * $form->{"sellprice_$i"});
 
 665         $form->{weight}    += ($form->{"qty_$i"} * $form->{"weight_$i"});
 
 670     $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
 
 672     $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
 
 673     $form->{assembly_rows} = $count;
 
 675   } elsif ($form->{item} eq 'service') {
 
 676     map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(listprice sellprice lastcost);
 
 680     # this section applies to invoices and orders
 
 681     # remove any empty numbers
 
 682     if ($form->{rowcount}) {
 
 683       for my $i (1 .. $form->{rowcount} - 1) {
 
 684         if ($form->{"partnumber_$i"}) {
 
 688           map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
 
 691             if ($form->{"licensenumber_$i"} == -1) {
 
 699       $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
 
 700       $form->{rowcount} = $count;
 
 702       $form->{creditremaining} -= &invoicetotal;
 
 709   if (   $form->{type} =~ (/sales_quotation/)
 
 710       or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/))
 
 711       or (($form->{level} eq undef) and ($form->{type} =~ /invoice/))
 
 712       or ($form->{type} =~ /sales_order/)) {
 
 714     # get pricegroups for parts
 
 715     IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
 717     # build up html code for prices_$i
 
 718     set_pricegroup($form->{rowcount});
 
 724   $lxdebug->leave_sub();
 
 728   $lxdebug->enter_sub();
 
 730   $auth->assert('part_service_assembly_edit | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
 
 731                 'request_quotation_edit     | sales_quotation_edit | purchase_order_edit');
 
 733   $form->{oldinvtotal} = 0;
 
 735   # add all parts and deduct paid
 
 736   map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
 
 738   my ($amount, $sellprice, $discount, $qty);
 
 740   for my $i (1 .. $form->{rowcount}) {
 
 741     $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
 
 742     $discount  = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
 
 743     $qty       = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
 
 745     #($form->{"sellprice_$i"}, $form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
 
 747     $amount = $sellprice * (1 - $discount / 100) * $qty;
 
 748     map { $form->{"${_}_base"} += $amount }
 
 749       (split (/ /, $form->{"taxaccounts_$i"}));
 
 750     $form->{oldinvtotal} += $amount;
 
 753   map { $form->{oldinvtotal} += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
 
 754     split(/ /, $form->{taxaccounts})
 
 755     if !$form->{taxincluded};
 
 757   $form->{oldtotalpaid} = 0;
 
 758   for $i (1 .. $form->{paidaccounts}) {
 
 759     $form->{oldtotalpaid} += $form->{"paid_$i"};
 
 762   $lxdebug->leave_sub();
 
 765   return ($form->{oldinvtotal} - $form->{oldtotalpaid});
 
 769   $lxdebug->enter_sub();
 
 771   $auth->assert('part_service_assembly_edit | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
 
 772                 'request_quotation_edit     | sales_quotation_edit | purchase_order_edit');
 
 774   # check if items are valid
 
 775   if ($form->{rowcount} == 1) {
 
 780   for $i (1 .. $form->{rowcount} - 1) {
 
 781     $form->isblank("partnumber_$i",
 
 782                    $locale->text('Number missing in Row') . " $i");
 
 785   $lxdebug->leave_sub();
 
 789   $lxdebug->enter_sub();
 
 791   $auth->assert('part_service_assembly_edit | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
 
 792                 'request_quotation_edit     | sales_quotation_edit | purchase_order_edit');
 
 794   if ($form->{second_run}) {
 
 795     $form->{print_and_post} = 0;
 
 797   $form->{ordnumber} = $form->{invnumber};
 
 799   $form->{old_employee_id} = $form->{employee_id};
 
 800   $form->{old_salesman_id} = $form->{salesman_id};
 
 802   map { delete $form->{$_} } qw(id printed emailed queued);
 
 803   if ($form->{script} eq 'ir.pl' || $form->{type} eq 'request_quotation') {
 
 804     $form->{title} = $locale->text('Add Purchase Order');
 
 805     $form->{vc}    = 'vendor';
 
 806     $form->{type}  = 'purchase_order';
 
 809   if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_quotation') {
 
 810     $form->{title} = $locale->text('Add Sales Order');
 
 811     $form->{vc}    = 'customer';
 
 812     $form->{type}  = 'sales_order';
 
 815   $form->{script} = 'oe.pl';
 
 823   require "bin/mozilla/$form->{script}";
 
 824   my $script = $form->{"script"};
 
 827   $locale = new Locale($language, $script);
 
 829   map { $form->{"select$_"} = "" } ($form->{vc}, currency);
 
 831   $currency = $form->{currency};
 
 835   $form->{currency}     = $currency;
 
 836   $form->{exchangerate} = "";
 
 838   $form->{exchangerate} = $exchangerate
 
 842                     $form->check_exchangerate(
 
 843                     \%myconfig, $form->{currency}, $form->{transdate}, $buysell
 
 846   for $i (1 .. $form->{rowcount}) {
 
 847     map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
 
 848                                                      $form->{"${_}_${i}"})
 
 849             if ($form->{"${_}_${i}"}) }
 
 850         qw(ship qty sellprice listprice basefactor));
 
 856   $lxdebug->leave_sub();
 
 860   $lxdebug->enter_sub();
 
 862   $auth->assert('part_service_assembly_edit | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
 
 863                 'request_quotation_edit     | sales_quotation_edit | purchase_order_edit');
 
 865   if ($form->{second_run}) {
 
 866     $form->{print_and_post} = 0;
 
 868   map { delete $form->{$_} } qw(id printed emailed queued);
 
 870   if ($form->{script} eq 'ir.pl' || $form->{type} eq 'purchase_order') {
 
 871     $form->{title} = $locale->text('Add Request for Quotation');
 
 872     $form->{vc}    = 'vendor';
 
 873     $form->{type}  = 'request_quotation';
 
 876   if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_order') {
 
 877     $form->{title} = $locale->text('Add Quotation');
 
 878     $form->{vc}    = 'customer';
 
 879     $form->{type}  = 'sales_quotation';
 
 885   $form->{script} = 'oe.pl';
 
 891   require "bin/mozilla/$form->{script}";
 
 893   map { $form->{"select$_"} = "" } ($form->{vc}, currency);
 
 895   $currency = $form->{currency};
 
 899   $form->{currency}     = $currency;
 
 900   $form->{exchangerate} = "";
 
 902   $form->{exchangerate} = $exchangerate
 
 906                     $form->check_exchangerate(
 
 907                     \%myconfig, $form->{currency}, $form->{transdate}, $buysell
 
 910   for $i (1 .. $form->{rowcount}) {
 
 911     map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
 
 912                                                      $form->{"${_}_${i}"})
 
 913             if ($form->{"${_}_${i}"}) }
 
 914         qw(ship qty sellprice listprice basefactor));
 
 920   $lxdebug->leave_sub();
 
 923 sub request_for_quotation {
 
 928   $lxdebug->enter_sub();
 
 930   $auth->assert('part_service_assembly_edit | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
 
 931                 'request_quotation_edit     | sales_quotation_edit | purchase_order_edit');
 
 933   if ($form->{second_run}) {
 
 934     $form->{print_and_post} = 0;
 
 935     $form->{resubmit}       = 0;
 
 938   $form->{email} = $form->{shiptoemail} if $form->{shiptoemail} && $form->{formname} =~ /(pick|packing|bin)_list/;
 
 940   if ($form->{"cp_id"} && !$form->{"email"}) {
 
 941     CT->get_contact(\%myconfig, $form);
 
 942     $form->{"email"} = $form->{"cp_email"};
 
 945   $title = $locale->text('E-mail') . " " . $form->get_formname_translation();
 
 947   $form->{oldmedia} = $form->{media};
 
 948   $form->{media}    = "email";
 
 950   my $attachment_filename = $form->generate_attachment_filename();
 
 952   $form->{"fokus"} = $form->{"email"} ? "Form.subject" : "Form.email";
 
 955   my (@dont_hide_key_list, %dont_hide_key, @hidden_keys);
 
 956   @dont_hide_key_list = qw(action email cc bcc subject message sendmode format header override login password);
 
 957   @dont_hide_key{@dont_hide_key_list} = (1) x @dont_hide_key_list;
 
 958   @hidden_keys = sort grep { !$dont_hide_key{$_} } grep { !ref $form->{$_} } keys %$form;
 
 960   print $form->parse_html_template('generic/edit_email',
 
 962                                      a_filename      => $attachment_filename,
 
 963                                      _print_options_ => print_options('inline' => 1),
 
 964                                      HIDDEN          => [ map +{ name => $_, value => $form->{$_} }, @hidden_keys ],
 
 965                                      SHOW_BCC        => $myconfig{role} eq 'admin' });
 
 967   $lxdebug->leave_sub();
 
 971   $lxdebug->enter_sub();
 
 973   $auth->assert('part_service_assembly_edit | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
 
 974                 'request_quotation_edit     | sales_quotation_edit | purchase_order_edit');
 
 976   my $callback = $form->{script} . "?action=edit";
 
 977   map({ $callback .= "\&${_}=" . E($form->{$_}); } qw(type id));
 
 979   print_form("return");
 
 981   Common->save_email_status(\%myconfig, $form);
 
 983   $form->{callback} = $callback;
 
 986   $lxdebug->leave_sub();
 
 989 # generate the printing options displayed at the bottom of oe and is forms.
 
 990 # this function will attempt to guess what type of form is displayed, and will generate according options
 
 993 # this version builds the arrays of options pretty directly. if you have trouble understanding how,
 
 994 # the opthash function builds hashrefs which are then pieced together for the template arrays.
 
 995 # unneeded options are "undef"ed out, and then grepped out. 
 
 997 # the inline options is untested, but intended to be used later in metatemplating
 
 999   $lxdebug->enter_sub();
 
1001   $auth->assert('part_service_assembly_edit     | vendor_invoice_edit        | sales_order_edit    | invoice_edit |' .
 
1002                 'request_quotation_edit         | sales_quotation_edit       | purchase_order_edit | dunning_edit');
 
1006   # names 3 parameters and returns a hashref, for use in templates
 
1007   sub opthash { +{ value => shift, selected => shift, oname => shift } }
 
1008   (@FORMNAME, @FORMNAME, @LANGUAGE_ID, @FORMAT, @SENDMODE, @MEDIA, @PRINTER_ID, @SELECTS) = ();
 
1010   # note: "||"-selection is only correct for values where "0" is _not_ a correct entry
 
1011   $form->{sendmode}   = "attachment";
 
1012   $form->{format}     = $form->{format} || $myconfig{template_format} || "pdf";
 
1013   $form->{copies}     = $form->{copies} || $myconfig{copies}          || 3;
 
1014   $form->{media}      = $form->{media}  || $myconfig{default_media}   || "screen";
 
1015   $form->{printer_id} = defined $form->{printer_id}           ? $form->{printer_id} :
 
1016                         defined $myconfig{default_printer_id} ? $myconfig{default_printer_id} : "";
 
1018   $form->{PD}{ $form->{formname} } = "selected";
 
1019   $form->{DF}{ $form->{format} }   = "selected";
 
1020   $form->{OP}{ $form->{media} }    = "selected";
 
1021   $form->{SM}{ $form->{formname} } = "selected";
 
1023   push @FORMNAME, grep $_,
 
1024     ($form->{type} eq 'purchase_order') ? (
 
1025       opthash("purchase_order",      $form->{PD}{purchase_order},      $locale->text('Purchase Order')),
 
1026       opthash("bin_list",            $form->{PD}{bin_list},            $locale->text('Bin List')) 
 
1028     ($form->{type} eq 'credit_note') ?
 
1029       opthash("credit_note",         $form->{PD}{credit_note},         $locale->text('Credit Note')) : undef,
 
1030     ($form->{type} eq 'sales_order') ? (
 
1031       opthash("sales_order",         $form->{PD}{sales_order},         $locale->text('Confirmation')),
 
1032       opthash("proforma",            $form->{PD}{proforma},            $locale->text('Proforma Invoice')),
 
1033       opthash("pick_list",           $form->{PD}{pick_list},           $locale->text('Pick List')),
 
1034       opthash("packing_list",        $form->{PD}{packing_list},        $locale->text('Packing List')) 
 
1036     ($form->{type} =~ /sales_quotation$/) ?
 
1037       opthash('sales_quotation',     $form->{PD}{sales_quotation},     $locale->text('Quotation')) : undef,
 
1038     ($form->{type} =~ /request_quotation$/) ?
 
1039       opthash('request_quotation',   $form->{PD}{request_quotation},   $locale->text('Request for Quotation')) : undef,
 
1040     ($form->{type} eq 'invoice') ? (
 
1041       opthash("invoice",             $form->{PD}{invoice},             $locale->text('Invoice')),
 
1042       opthash("proforma",            $form->{PD}{proforma},            $locale->text('Proforma Invoice')),
 
1043       opthash("packing_list",        $form->{PD}{packing_list},        $locale->text('Packing List'))
 
1045     ($form->{type} eq 'invoice' && $form->{storno}) ? (
 
1046       opthash("storno_invoice",      $form->{PD}{storno_invoice},      $locale->text('Storno Invoice')),
 
1047       opthash("storno_packing_list", $form->{PD}{storno_packing_list}, $locale->text('Storno Packing List')) 
 
1049     ($form->{type} eq 'credit_note') ?
 
1050       opthash("credit_note",         $form->{PD}{credit_note},         $locale->text('Credit Note')) : undef;
 
1053     opthash("attachment",            $form->{SM}{attachment},          $locale->text('Attachment')),
 
1054     opthash("inline",                $form->{SM}{inline},              $locale->text('In-line'))
 
1055       if ($form->{media} eq 'email');
 
1057   push @MEDIA, grep $_,
 
1058       opthash("screen",              $form->{OP}{screen},              $locale->text('Screen')),
 
1059     (scalar @{ $form->{printers} } && $latex_templates) ?
 
1060       opthash("printer",             $form->{OP}{printer},             $locale->text('Printer')) : undef,
 
1061     ($latex_templates && !$options{no_queue}) ?
 
1062       opthash("queue",               $form->{OP}{queue},               $locale->text('Queue')) : undef
 
1063         if ($form->{media} ne 'email');
 
1065   push @FORMAT, grep $_,
 
1066     ($opendocument_templates && $openofficeorg_writer_bin && $xvfb_bin && (-x $openofficeorg_writer_bin) && (-x $xvfb_bin)
 
1067      && !$options{no_opendocument_pdf}) ?
 
1068       opthash("opendocument_pdf",    $form->{DF}{"opendocument_pdf"},  $locale->text("PDF (OpenDocument/OASIS)")) : undef,
 
1069     ($latex_templates) ?
 
1070       opthash("pdf",                 $form->{DF}{pdf},                 $locale->text('PDF')) : undef,
 
1071     ($latex_templates && !$options{no_postscript}) ?
 
1072       opthash("postscript",          $form->{DF}{postscript},          $locale->text('Postscript')) : undef,
 
1073     (!$options{no_html}) ?
 
1074       opthash("html", $form->{DF}{html}, "HTML") : undef,
 
1075     ($opendocument_templates && !$options{no_opendocument}) ?
 
1076       opthash("opendocument",        $form->{DF}{opendocument},        $locale->text("OpenDocument/OASIS")) : undef;
 
1079     map { opthash($_->{id}, ($_->{id} eq $form->{language_id} ? 'selected' : ''), $_->{description}) } +{}, @{ $form->{languages} }
 
1080       if (ref $form->{languages} eq 'ARRAY');
 
1083     map { opthash($_->{id}, ($_->{id} eq $form->{printer_id} ? 'selected' : ''), $_->{printer_description}) } +{}, @{ $form->{printers} }
 
1084       if ((ref $form->{printers} eq 'ARRAY') && scalar @{ $form->{printers } });
 
1086   @SELECTS = map { sname => lc $_, DATA => \@$_, show => !$options{"hide_" . lc($_)} && scalar @$_ }, qw(FORMNAME LANGUAGE_ID FORMAT SENDMODE MEDIA PRINTER_ID);
 
1088   my %dont_display_groupitems = (
 
1093     display_copies       => scalar @{ $form->{printers} } && $latex_templates && $form->{media} ne 'email',
 
1094     display_remove_draft => (!$form->{id} && $form->{draft_id}),
 
1095     display_groupitems   => !$dont_display_groupitems{$form->{type}},
 
1096     groupitems_checked   => $form->{groupitems} ? "checked" : '',
 
1097     remove_draft_checked => $form->{remove_draft} ? "checked" : ''
 
1100   my $print_options = $form->parse_html_template("generic/print_options", { SELECTS  => \@SELECTS, %template_vars } );
 
1102   if ($options{inline}) {
 
1103     $lxdebug->leave_sub();
 
1104     return $print_options;
 
1107   print $print_options;
 
1109   $lxdebug->leave_sub();
 
1113   $lxdebug->enter_sub();
 
1115   $auth->assert('part_service_assembly_edit | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
 
1116                 'request_quotation_edit     | sales_quotation_edit | purchase_order_edit | ' .
 
1117                 'order_request_edit_all     | order_request_edit');
 
1119   if ($form->{print_nextsub}) {
 
1120     call_sub($form->{print_nextsub});
 
1121     $lxdebug->leave_sub();
 
1125   # if this goes to the printer pass through
 
1126   if ($form->{media} eq 'printer' || $form->{media} eq 'queue') {
 
1127     $form->error($locale->text('Select postscript or PDF!'))
 
1128       if ($form->{format} !~ /(postscript|pdf)/);
 
1130     $old_form = new Form;
 
1131     map { $old_form->{$_} = $form->{$_} } keys %$form;
 
1134   if (!$form->{id} || (($form->{formname} eq "proforma") && !$form->{proforma} && (($form->{type} =~ /_order$/) || ($form->{type} =~ /_quotation$/)))) {
 
1135     if ($form->{formname} eq "proforma") {
 
1136       $form->{proforma} = 1;
 
1138     $form->{print_and_save} = 1;
 
1139     my $formname = $form->{formname};
 
1141     $form->{formname} = $formname;
 
1146   &print_form($old_form);
 
1148   $lxdebug->leave_sub();
 
1152   $lxdebug->enter_sub();
 
1154   $auth->assert('part_service_assembly_edit     | vendor_invoice_edit        | sales_order_edit    | invoice_edit |' .
 
1155                 'request_quotation_edit         | sales_quotation_edit       | purchase_order_edit');
 
1157   my ($old_form) = @_;
 
1161   $numberfld = "invnumber";
 
1164     ($form->{display_form}) ? $form->{display_form} : "display_form";
 
1166   # $form->{"notes"} will be overridden by the customer's/vendor's "notes" field. So save it here.
 
1167   $form->{ $form->{"formname"} . "notes" } = $form->{"notes"};
 
1169   if ($form->{formname} eq "invoice") {
 
1170     $form->{label} = $locale->text('Invoice');
 
1172   if ($form->{formname} eq "packing_list") {
 
1174     # this is from an invoice
 
1175     $form->{label} = $locale->text('Packing List');
 
1177   if ($form->{formname} eq 'sales_order') {
 
1180     $form->{"${inv}date"} = $form->{transdate};
 
1181     $form->{label}        = $locale->text('Confirmation');
 
1182     $numberfld            = "sonumber";
 
1186   if (($form->{type} eq 'invoice') && ($form->{formname} eq 'proforma') ) {
 
1189     $form->{"${inv}date"} = $form->{invdate};
 
1190     $form->{label}        = $locale->text('Proforma Invoice');
 
1191     $numberfld            = "sonumber";
 
1195   if (($form->{type} eq 'sales_order') && ($form->{formname} eq 'proforma') ) {
 
1198     $form->{"${inv}date"} = $form->{transdate};
 
1199     $form->{"invdate"}    = $form->{transdate};
 
1200     $form->{invnumber}    = $form->{ordnumber};
 
1201     $form->{label}        = $locale->text('Proforma Invoice');
 
1202     $numberfld            = "sonumber";
 
1206   if ($form->{formname} eq 'packing_list' && $form->{type} ne 'invoice') {
 
1208     # we use the same packing list as from an invoice
 
1211     $form->{invdate} = $form->{"${inv}date"} = $form->{transdate};
 
1212     $form->{label} = $locale->text('Packing List');
 
1214     # set invnumber for template packing_list 
 
1215     $form->{invnumber}   = $form->{ordnumber};
 
1217   if ($form->{formname} eq 'pick_list') {
 
1220     $form->{"${inv}date"} = ($form->{transdate}) ? $form->{transdate} : $form->{invdate};
 
1221     $form->{label}        = $locale->text('Pick List');
 
1222     $order                = 1 unless $form->{type} eq 'invoice';
 
1224   if ($form->{formname} eq 'purchase_order') {
 
1227     $form->{"${inv}date"} = $form->{transdate};
 
1228     $form->{label}        = $locale->text('Purchase Order');
 
1229     $numberfld            = "ponumber";
 
1232   if ($form->{formname} eq 'bin_list') {
 
1235     $form->{"${inv}date"} = $form->{transdate};
 
1236     $form->{label}        = $locale->text('Bin List');
 
1239   if ($form->{formname} eq 'sales_quotation') {
 
1242     $form->{"${inv}date"} = $form->{transdate};
 
1243     $form->{label}        = $locale->text('Quotation');
 
1244     $numberfld            = "sqnumber";
 
1248   if (($form->{type} eq 'sales_quotation') && ($form->{formname} eq 'proforma') ) {
 
1251     $form->{"${inv}date"} = $form->{transdate};
 
1252     $form->{"invdate"}    = $form->{transdate};
 
1253     $form->{label}        = $locale->text('Proforma Invoice');
 
1254     $numberfld            = "sqnumber";
 
1258   if ($form->{formname} eq 'request_quotation') {
 
1261     $form->{"${inv}date"} = $form->{transdate};
 
1262     $form->{label}        = $locale->text('RFQ');
 
1263     $numberfld            = "rfqnumber";
 
1267   $form->isblank("email", $locale->text('E-mail address missing!'))
 
1268     if ($form->{media} eq 'email');
 
1269   $form->isblank("${inv}date",
 
1270            $locale->text($form->{label}) 
 
1272            . $locale->text(' Date missing!'));
 
1274   # $locale->text('Invoice Number missing!')
 
1275   # $locale->text('Invoice Date missing!')
 
1276   # $locale->text('Packing List Number missing!')
 
1277   # $locale->text('Packing List Date missing!')
 
1278   # $locale->text('Order Number missing!')
 
1279   # $locale->text('Order Date missing!')
 
1280   # $locale->text('Quotation Number missing!')
 
1281   # $locale->text('Quotation Date missing!')
 
1284   $form->{what_done} = $form->{formname};
 
1285   if (!$form->{"${inv}number"} && !$form->{preview} && !$form->{id}) {
 
1286     $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
 
1287     if ($form->{media} ne 'email') {
 
1289       # get pricegroups for parts
 
1290       IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
1292       # build up html code for prices_$i
 
1293       set_pricegroup($form->{rowcount});
 
1295       $form->{rowcount}--;
 
1297       call_sub($display_form);
 
1298       # saving the history
 
1299           if(!exists $form->{addition}) {
 
1300         $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber}; 
 
1301             $form->{addition} = "PRINTED";
 
1302             $form->save_history($form->dbconnect(\%myconfig));
 
1304       # /saving the history
 
1311   # Save the email address given in the form because it should override the setting saved for the customer/vendor.
 
1312   my ($saved_email, $saved_cc, $saved_bcc) =
 
1313     ($form->{"email"}, $form->{"cc"}, $form->{"bcc"});
 
1315   $language_saved = $form->{language_id};
 
1316   $payment_id_saved = $form->{payment_id};
 
1317   $salesman_id_saved = $form->{salesman_id};
 
1318   $cp_id_saved = $form->{cp_id};
 
1320   call_sub("$form->{vc}_details") if ($form->{vc});
 
1322   $form->{language_id} = $language_saved;
 
1323   $form->{payment_id} = $payment_id_saved;
 
1325   $form->{"email"} = $saved_email if ($saved_email);
 
1326   $form->{"cc"}    = $saved_cc    if ($saved_cc);
 
1327   $form->{"bcc"}   = $saved_bcc   if ($saved_bcc);
 
1329   if (!$cp_id_saved) {
 
1330     # No contact was selected. Delete all contact variables because
 
1331     # IS->customer_details() and IR->vendor_details() get the default
 
1333     map({ delete($form->{$_}); } grep(/^cp_/, keys(%{ $form })));
 
1336   my ($language_tc, $output_numberformat, $output_dateformat, $output_longdates);
 
1337   if ($form->{"language_id"}) {
 
1338     ($language_tc, $output_numberformat, $output_dateformat, $output_longdates) =
 
1339       AM->get_language_details(\%myconfig, $form, $form->{language_id});
 
1341     $output_dateformat = $myconfig{"dateformat"};
 
1342     $output_numberformat = $myconfig{"numberformat"};
 
1343     $output_longdates = 1;
 
1346   ($form->{employee}) = split /--/, $form->{employee};
 
1348   # create the form variables
 
1349   if ($form->{formname} eq 'order_request') {
 
1350     order_request_details();
 
1351   } elsif ($form->{formname} eq 'return_material_slip') {
 
1353   } elsif ($form->{formname} eq 'release_material_slip') {
 
1355   } elsif ($form->{type} =~ /_delivery_order$/) {
 
1356     DO->order_details();
 
1358     OE->order_details(\%myconfig, \%$form);
 
1360     IS->invoice_details(\%myconfig, \%$form, $locale);
 
1363   $form->get_salesman(\%myconfig, $salesman_id_saved);
 
1365   if ($form->{shipto_id}) {
 
1366     $form->get_shipto(\%myconfig);
 
1369   @a = qw(name street zipcode city country);
 
1373   # if there is no shipto fill it in from billto
 
1374   foreach $item (@a) {
 
1375     if ($form->{"shipto$item"}) {
 
1382     if (   $form->{formname} eq 'purchase_order'
 
1383         || $form->{formname} eq 'request_quotation') {
 
1384       $form->{shiptoname}   = $myconfig{company};
 
1385       $form->{shiptostreet} = $myconfig{address};
 
1387       map { $form->{"shipto$_"} = $form->{$_} } @a;
 
1391   $form->{notes} =~ s/^\s+//g;
 
1393   $form->{templates} = "$myconfig{templates}";
 
1395   delete $form->{printer_command};
 
1397   $form->{language} = $form->get_template_language(\%myconfig);
 
1400   if ($form->{media} ne 'email') {
 
1401     $printer_code = $form->get_printer_code(\%myconfig);
 
1402     if ($printer_code ne "") {
 
1403       $printer_code = "_" . $printer_code;
 
1407   if ($form->{language} ne "") {
 
1408     map({ $form->{"unit"}->[$_] =
 
1409             AM->translate_units($form, $form->{"language"},
 
1410                                 $form->{"unit"}->[$_], $form->{"qty"}->[$_]); }
 
1411         (0..scalar(@{$form->{"unit"}}) - 1));
 
1412     $form->{language} = "_" . $form->{language};
 
1415   # Format dates and numbers.
 
1416   format_dates($output_dateformat, $output_longdates,
 
1417                qw(invdate orddate quodate pldate duedate reqdate transdate
 
1418                   shippingdate deliverydate validitydate paymentdate
 
1419                   datepaid transdate_oe deliverydate_oe
 
1420                   employee_startdate employee_enddate
 
1422                grep({ /^datepaid_\d+$/ ||
 
1423                         /^transdate_oe_\d+$/ ||
 
1424                         /^deliverydate_oe_\d+$/ ||
 
1426                         /^deliverydate_\d+$/ ||
 
1430   reformat_numbers($output_numberformat, 2,
 
1431                    qw(invtotal ordtotal quototal subtotal linetotal
 
1432                       listprice sellprice netprice discount
 
1433                       tax taxbase total paid),
 
1434                    grep({ /^linetotal_\d+$/ ||
 
1435                             /^listprice_\d+$/ ||
 
1436                             /^sellprice_\d+$/ ||
 
1446   reformat_numbers($output_numberformat, undef,
 
1447                    qw(qty price_factor),
 
1451   my ($cvar_date_fields, $cvar_number_fields) = CVar->get_field_format_list('module' => 'CT', 'prefix' => 'vc_');
 
1453   if (scalar @{ $cvar_date_fields }) {
 
1454     format_dates($output_dateformat, $output_longdates, @{ $cvar_date_fields });
 
1457   while (my ($precision, $field_list) = each %{ $cvar_number_fields }) {
 
1458     reformat_numbers($output_numberformat, $precision, @{ $field_list });
 
1461   $form->{IN} = "$form->{formname}$form->{language}${printer_code}.html";
 
1462   if ($form->{format} eq 'postscript') {
 
1463     $form->{postscript} = 1;
 
1464     $form->{IN} =~ s/html$/tex/;
 
1465   } elsif ($form->{"format"} =~ /pdf/) {
 
1467     if ($form->{"format"} =~ /opendocument/) {
 
1468       $form->{IN} =~ s/html$/odt/;
 
1470       $form->{IN} =~ s/html$/tex/;
 
1472   } elsif ($form->{"format"} =~ /opendocument/) {
 
1473     $form->{"opendocument"} = 1;
 
1474     $form->{"IN"} =~ s/html$/odt/;
 
1477   delete $form->{OUT};
 
1479   if ($form->{media} eq 'printer') {
 
1480     $form->{OUT} = "| $form->{printer_command} &>/dev/null";
 
1481     $form->{printed} .= " $form->{formname}";
 
1482     $form->{printed} =~ s/^ //;
 
1484   $printed = $form->{printed};
 
1486   if ($form->{media} eq 'email') {
 
1487     $form->{subject} = qq|$form->{label} $form->{"${inv}number"}|
 
1488       unless $form->{subject};
 
1490     $form->{emailed} .= " $form->{formname}";
 
1491     $form->{emailed} =~ s/^ //;
 
1493   $emailed = $form->{emailed};
 
1495   if ($form->{media} eq 'queue') {
 
1496     %queued = map { s|.*/|| } split / /, $form->{queued};
 
1498     if ($filename = $queued{ $form->{formname} }) {
 
1499       $form->{queued} =~ s/\Q$form->{formname} $filename\E//;
 
1500       unlink "$spool/$filename";
 
1501       $filename =~ s/\..*$//g;
 
1507     $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
 
1508     $form->{OUT} = ">$spool/$filename";
 
1511     $form->{queued} .= " $form->{formname} $filename";
 
1513     $form->{queued} =~ s/^ //;
 
1515   $queued = $form->{queued};
 
1517 # saving the history
 
1518   if(!exists $form->{addition}) {
 
1519     $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
 
1520     if($form->{media} =~ /printer/) {
 
1521         $form->{addition} = "PRINTED";
 
1523     elsif($form->{media} =~ /email/) {
 
1524         $form->{addition} = "MAILED";
 
1526     elsif($form->{media} =~ /queue/) {
 
1527         $form->{addition} = "QUEUED";
 
1529     elsif($form->{media} =~ /screen/) {
 
1530         $form->{addition} = "SCREENED";
 
1532     $form->save_history($form->dbconnect(\%myconfig));
 
1534   # /saving the history
 
1536   $form->parse_template(\%myconfig, $userspath);
 
1538   $form->{callback} = "";
 
1540   if ($form->{media} eq 'email') {
 
1541     $form->{message} = $locale->text('sent') unless $form->{message};
 
1543   $message = $form->{message};
 
1545   # if we got back here restore the previous form
 
1546   if ($form->{media} =~ /(printer|email|queue)/) {
 
1548     $form->update_status(\%myconfig)
 
1549       if ($form->{media} eq 'queue' && $form->{id});
 
1551     return $lxdebug->leave_sub() if ($old_form eq "return");
 
1555       $old_form->{"${inv}number"} = $form->{"${inv}number"};
 
1557       # restore and display form
 
1558       map { $form->{$_} = $old_form->{$_} } keys %$old_form;
 
1560       $form->{queued}  = $queued;
 
1561       $form->{printed} = $printed;
 
1562       $form->{emailed} = $emailed;
 
1563       $form->{message} = $message;
 
1565       $form->{rowcount}--;
 
1566       map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
1567         qw(exchangerate creditlimit creditremaining);
 
1569       for $i (1 .. $form->{paidaccounts}) {
 
1571           $form->{"${_}_$i"} =
 
1572             $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
 
1573         } qw(paid exchangerate);
 
1576       call_sub($display_form);
 
1581       ($form->{media} eq 'printer')
 
1582       ? $locale->text('sent to printer')
 
1583       : $locale->text('emailed to') . " $form->{email}";
 
1584     $form->redirect(qq|$form->{label} $form->{"${inv}number"} $msg|);
 
1586   if ($form->{printing}) {
 
1587    call_sub($display_form);
 
1591   $lxdebug->leave_sub();
 
1594 sub customer_details {
 
1595   $lxdebug->enter_sub();
 
1596   IS->customer_details(\%myconfig, \%$form, @_);
 
1597   $lxdebug->leave_sub();
 
1600 sub vendor_details {
 
1601   $lxdebug->enter_sub();
 
1603   IR->vendor_details(\%myconfig, \%$form, @_);
 
1605   $lxdebug->leave_sub();
 
1609   $lxdebug->enter_sub();
 
1611   $auth->assert('part_service_assembly_edit | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
 
1612                 'request_quotation_edit     | sales_quotation_edit | purchase_order_edit');
 
1614   $form->{postasnew} = 1;
 
1615   map { delete $form->{$_} } qw(printed emailed queued);
 
1619   $lxdebug->leave_sub();
 
1623   $lxdebug->enter_sub();
 
1625   $auth->assert('part_service_assembly_edit | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
 
1626                 'request_quotation_edit     | sales_quotation_edit | purchase_order_edit');
 
1628   if ($form->{second_run}) {
 
1629     $form->{print_and_post} = 0;
 
1632   $title = $form->{title};
 
1633   $form->{title} = $locale->text('Ship to');
 
1635   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
1636     qw(exchangerate creditlimit creditremaining);
 
1639     qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry
 
1640        shiptocontact shiptophone shiptofax shiptoemail
 
1641        shiptodepartment_1 shiptodepartment_2);
 
1644     (qw(name department_1 department_2 street zipcode city country
 
1645         contact email phone fax));
 
1647   # get details for name
 
1648   call_sub("$form->{vc}_details", @addr_vars);
 
1651     ($form->{vc} eq 'customer')
 
1652     ? $locale->text('Customer Number')
 
1653     : $locale->text('Vendor Number');
 
1655   # get pricegroups for parts
 
1656   IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
1658   # build up html code for prices_$i
 
1659   set_pricegroup($form->{rowcount});
 
1661   $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
 
1663   $form->{rowcount}--;
 
1670 <form method="post" action="$form->{script}">
 
1672 <table width="100%">
 
1676         <tr class="listheading">
 
1677           <th class="listheading" colspan="2" width="50%">|
 
1678     . $locale->text('Billing Address') . qq|</th>
 
1679           <th class="listheading" width="50%">|
 
1680     . $locale->text('Shipping Address') . qq|</th>
 
1682         <tr height="5"></tr>
 
1684           <th align="right" nowrap>$number</th>
 
1685           <td>$form->{"$form->{vc}number"}</td>
 
1688           <th align="right" nowrap>| . $locale->text('Company Name') . qq|</th>
 
1689           <td>$form->{name}</td>
 
1690           <td><input name="shiptoname" size="35" value="$form->{shiptoname}"></td>
 
1693           <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
 
1694           <td>$form->{department_1}</td>
 
1695           <td><input name="shiptodepartment_1" size="35" value="$form->{shiptodepartment_1}"></td>
 
1698           <th align="right" nowrap> </th>
 
1699           <td>$form->{department_2}</td>
 
1700           <td><input name="shiptodepartment_2" size="35" value="$form->{shiptodepartment_2}"></td>
 
1703           <th align="right" nowrap>| . $locale->text('Street') . qq|</th>
 
1704           <td>$form->{street}</td>
 
1705           <td><input name="shiptostreet" size="35" value="$form->{shiptostreet}"></td>
 
1708           <th align="right" nowrap>| . $locale->text('Zipcode') . qq|</th>
 
1709           <td>$form->{zipcode}</td>
 
1710           <td><input name="shiptozipcode" size="35" value="$form->{shiptozipcode}"></td>
 
1713           <th align="right" nowrap>| . $locale->text('City') . qq|</th>
 
1714           <td>$form->{city}</td>
 
1715           <td><input name="shiptocity" size="35" value="$form->{shiptocity}"></td>
 
1718           <th align="right" nowrap>| . $locale->text('Country') . qq|</th>
 
1719           <td>$form->{country}</td>
 
1720           <td><input name="shiptocountry" size="35" value="$form->{shiptocountry}"></td>
 
1723           <th align="right" nowrap>| . $locale->text('Contact') . qq|</th>
 
1724           <td>$form->{contact}</td>
 
1725           <td><input name="shiptocontact" size="35" value="$form->{shiptocontact}"></td>
 
1728           <th align="right" nowrap>| . $locale->text('Phone') . qq|</th>
 
1729           <td>$form->{phone}</td>
 
1730           <td><input name="shiptophone" size="20" value="$form->{shiptophone}"></td>
 
1733           <th align="right" nowrap>| . $locale->text('Fax') . qq|</th>
 
1734           <td>$form->{fax}</td>
 
1735           <td><input name="shiptofax" size="20" value="$form->{shiptofax}"></td>
 
1738           <th align="right" nowrap>| . $locale->text('E-mail') . qq|</th>
 
1739           <td>$form->{email}</td>
 
1740           <td><input name="shiptoemail" size="35" value="$form->{shiptoemail}"></td>
 
1746 | . $cgi->hidden("-name" => "nextsub", "-value" => $nextsub);
 
1752   map({ delete $form->{$_} } (@shipto_vars, qw(header)));
 
1753   $form->{title} = $title;
 
1755   foreach $key (keys %$form) {
 
1756     next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
 
1757     $form->{$key} =~ s/\"/"/g;
 
1758     print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
 
1763 <hr size="3" noshade>
 
1766 <input class="submit" type="submit" name="action" value="|
 
1767     . $locale->text('Continue') . qq|">
 
1774   $lxdebug->leave_sub();
 
1778   $lxdebug->enter_sub();
 
1780   $auth->assert('part_service_assembly_edit | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
 
1781                 'request_quotation_edit     | sales_quotation_edit | purchase_order_edit');
 
1786   $form->{old_callback} = $form->escape($form->{callback}, 1);
 
1787   $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
 
1788   $form->{old_callback} = $form->escape($form->{old_callback}, 1);
 
1791   delete $form->{action};
 
1792   $customer = $form->{customer};
 
1793   map { $form->{"old_$_"} = $form->{"${_}_$row"} } qw(partnumber description);
 
1795   # save all other form variables in a previousform variable
 
1796   $form->{row} = $row;
 
1797   foreach $key (keys %$form) {
 
1798     next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
 
1801     $form->{$key} =~ s/&/%26/g;
 
1802     $previousform .= qq|$key=$form->{$key}&|;
 
1805   $previousform = $form->escape($previousform, 1);
 
1807   $form->{script} = "licenses.pl";
 
1809   map { $form->{$_} = $form->{"old_$_"} } qw(partnumber description);
 
1810   map { $form->{$_} = $form->escape($form->{$_}, 1) }
 
1811     qw(partnumber description);
 
1813     qq|$form->{script}?action=add&vc=$form->{db}&$form->{db}_id=$form->{id}&$form->{db}=$name&type=$form->{type}&customer=$customer&partnumber=$form->{partnumber}&description=$form->{description}&previousform="$previousform"&initial=1|;
 
1816   $lxdebug->leave_sub();
 
1819 sub relink_accounts {
 
1820   $lxdebug->enter_sub();
 
1822   $auth->assert('part_service_assembly_edit | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
 
1823                 'request_quotation_edit     | sales_quotation_edit | purchase_order_edit');
 
1825   $form->{"taxaccounts"} =~ s/\s*$//;
 
1826   $form->{"taxaccounts"} =~ s/^\s*//;
 
1827   foreach my $accno (split(/\s*/, $form->{"taxaccounts"})) {
 
1828     map({ delete($form->{"${accno}_${_}"}); } qw(rate description taxnumber));
 
1830   $form->{"taxaccounts"} = "";
 
1832   for (my $i = 1; $i <= $form->{"rowcount"}; $i++) {
 
1833     if ($form->{"id_$i"}) {
 
1834       IC->retrieve_accounts(\%myconfig, $form, $form->{"id_$i"}, $i, 1);
 
1838   $lxdebug->leave_sub();
 
1842   $lxdebug->enter_sub();
 
1844   $auth->assert('part_service_assembly_edit | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
 
1845                 'request_quotation_edit     | sales_quotation_edit | purchase_order_edit');
 
1847   $form->get_duedate(\%myconfig);
 
1850   $result = "$form->{duedate}";
 
1853   $lxdebug->leave_sub();