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 #######################################################################
 
  41 require "bin/mozilla/common.pl";
 
  43 # any custom scripts for this one
 
  44 if (-f "bin/mozilla/custom_io.pl") {
 
  45   eval { require "bin/mozilla/custom_io.pl"; };
 
  47 if (-f "bin/mozilla/$form->{login}_io.pl") {
 
  48   eval { require "bin/mozilla/$form->{login}_io.pl"; };
 
  55 # this is for our long dates
 
  56 # $locale->text('January')
 
  57 # $locale->text('February')
 
  58 # $locale->text('March')
 
  59 # $locale->text('April')
 
  60 # $locale->text('May ')
 
  61 # $locale->text('June')
 
  62 # $locale->text('July')
 
  63 # $locale->text('August')
 
  64 # $locale->text('September')
 
  65 # $locale->text('October')
 
  66 # $locale->text('November')
 
  67 # $locale->text('December')
 
  69 # this is for our short month
 
  70 # $locale->text('Jan')
 
  71 # $locale->text('Feb')
 
  72 # $locale->text('Mar')
 
  73 # $locale->text('Apr')
 
  74 # $locale->text('May')
 
  75 # $locale->text('Jun')
 
  76 # $locale->text('Jul')
 
  77 # $locale->text('Aug')
 
  78 # $locale->text('Sep')
 
  79 # $locale->text('Oct')
 
  80 # $locale->text('Nov')
 
  81 # $locale->text('Dec')
 
  86 ########################################
 
  87 # Eintrag fuer Version 2.2.0 geaendert #
 
  88 # neue Optik im Rechnungsformular      #
 
  89 ########################################
 
  91   $lxdebug->enter_sub();
 
  94   if ($lizenzen && $form->{vc} eq "customer") {
 
  95     if ($form->{type} =~ /sales_order/) {
 
  96       @column_index = (runningnumber, partnumber, description, ship, qty);
 
  97     } elsif ($form->{type} =~ /sales_quotation/) {
 
  98       @column_index = (runningnumber, partnumber, description, qty);
 
 100       @column_index = (runningnumber, partnumber, description, qty);
 
 103     if (   ($form->{type} =~ /purchase_order/)
 
 104         || ($form->{type} =~ /sales_order/)) {
 
 105       @column_index = (runningnumber, partnumber, description, ship, qty);
 
 107       @column_index = (runningnumber, partnumber, description, qty);
 
 110 ############## ENDE Neueintrag ##################
 
 112   my $dimension_units = AM->retrieve_units(\%myconfig, $form, "dimension");
 
 113   my $service_units = AM->retrieve_units(\%myconfig, $form, "service");
 
 114   my $all_units = AM->retrieve_units(\%myconfig, $form);
 
 116   push @column_index, qw(unit);
 
 118   #for pricegroups column
 
 119   if (   $form->{type} =~ (/sales_quotation/)
 
 120       or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/))
 
 121       or (($form->{level} eq undef) and ($form->{type} =~ /invoice/))
 
 122       or ($form->{type} =~ /sales_order/)) {
 
 123     push @column_index, qw(sellprice_pg);
 
 126   push @column_index, qw(sellprice);
 
 128   if ($form->{vc} eq 'customer') {
 
 129     push @column_index, qw(discount);
 
 132   push @column_index, "linetotal";
 
 134   my $colspan = $#column_index + 1;
 
 136   $form->{invsubtotal} = 0;
 
 137   map { $form->{"${_}_base"} = 0 } (split(/ /, $form->{taxaccounts}));
 
 139 ########################################
 
 140   # Eintrag fuer Version 2.2.0 geaendert #
 
 141   # neue Optik im Rechnungsformular      #
 
 142 ########################################
 
 143   $column_data{runningnumber} =
 
 144       qq|<th align="left" nowrap width="5" class="listheading">|
 
 145     . $locale->text('No.')
 
 147   $column_data{partnumber} =
 
 148       qq|<th align="left" nowrap width="12" class="listheading">|
 
 149     . $locale->text('Number')
 
 151   $column_data{description} =
 
 152       qq|<th align="left" nowrap width="30" class="listheading">|
 
 153     . $locale->text('Part Description')
 
 155   if ($form->{"type"} eq "purchase_order") {
 
 157       qq|<th align="left" nowrap width="5" class="listheading">|
 
 158       . $locale->text('Ship rcvd')
 
 162       qq|<th align="left" nowrap width="5" class="listheading">|
 
 163       . $locale->text('Ship')
 
 167       qq|<th align="left" nowrap width="5" class="listheading">|
 
 168     . $locale->text('Qty')
 
 171       qq|<th align="left" nowrap width="5" class="listheading">|
 
 172     . $locale->text('Unit')
 
 174   $column_data{license} =
 
 175       qq|<th align="left" nowrap width="10" class="listheading">|
 
 176     . $locale->text('License')
 
 178   $column_data{serialnr} =
 
 179       qq|<th align="left" nowrap width="10" class="listheading">|
 
 180     . $locale->text('Serial No.')
 
 182   $column_data{projectnr} =
 
 183       qq|<th align="left" nowrap width="10" class="listheading">|
 
 184     . $locale->text('Project')
 
 186   $column_data{sellprice} =
 
 187       qq|<th align="left" nowrap width="15" class="listheading">|
 
 188     . $locale->text('Price')
 
 190   $column_data{sellprice_pg} =
 
 191       qq|<th align="left" nowrap width="15" class="listheading">|
 
 192     . $locale->text('Pricegroup')
 
 194   $column_data{discount} =
 
 195       qq|<th align="left" class="listheading">|
 
 196     . $locale->text('Discount')
 
 198   $column_data{linetotal} =
 
 199       qq|<th align="left" nowrap width="10" class="listheading">|
 
 200     . $locale->text('Extended')
 
 203       qq|<th align="left" nowrap width="10" class="listheading">|
 
 204     . $locale->text('Bin')
 
 206 ############## ENDE Neueintrag ##################
 
 208   $myconfig{"show_form_details"} = 1
 
 209     unless (defined($myconfig{"show_form_details"}));
 
 210   $form->{"show_details"} = $myconfig{"show_form_details"}
 
 211     unless (defined($form->{"show_details"}));
 
 212   $form->{"show_details"} = $form->{"show_details"} ? 1 : 0;
 
 213   my $show_details_new = 1 - $form->{"show_details"};
 
 214   my $show_details_checked = $form->{"show_details"} ? "checked" : "";
 
 218     <td>| . $cgi->hidden("-name" => "show_details", "-value" => $form->{show_details}) . qq|
 
 219       <input type="checkbox" id="cb_show_details" onclick="show_form_details($show_details_new);" $show_details_checked>
 
 220       <label for="cb_show_details">| . $locale->text("Show details") . qq|</label><br>
 
 222         <tr class="listheading">|;
 
 224   map { print "\n$column_data{$_}" } @column_index;
 
 230   $runningnumber = $locale->text('No.');
 
 231   $deliverydate  = $locale->text('Delivery Date');
 
 232   $serialnumber  = $locale->text('Serial No.');
 
 233   $projectnumber = $locale->text('Project');
 
 234   $partsgroup    = $locale->text('Group');
 
 235   $reqdate       = $locale->text('Reqdate');
 
 237   $delvar = 'deliverydate';
 
 239   if ($form->{type} =~ /_order$/ || $form->{type} =~ /_quotation$/) {
 
 240     $deliverydate = $locale->text('Required by');
 
 244   my %projectnumber_labels = ();
 
 245   my @projectnumber_values = ("");
 
 246   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
 247     push(@projectnumber_values, $item->{"id"});
 
 248     $projectnumber_labels{$item->{"id"}} = $item->{"projectnumber"};
 
 251   for $i (1 .. $numrows) {
 
 256         $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
 
 257     } qw(qty ship discount sellprice price_new price_old) unless ($form->{simple_save});
 
 259     if (!$form->{"unit_old_$i"}) {
 
 260       # Neue Ware aus der Datenbank. In diesem Fall ist unit_$i die
 
 261       # Einheit, wie sie in den Stammdaten hinterlegt wurde.
 
 262       # Es sollte also angenommen werden, dass diese ausgewaehlt war.
 
 263       $form->{"unit_old_$i"} = $form->{"unit_$i"};
 
 266     # Die zuletzt ausgewaehlte mit der aktuell ausgewaehlten Einheit
 
 267     # vergleichen und bei Unterschied den Preis entsprechend umrechnen.
 
 268     $form->{"selected_unit_$i"} = $form->{"unit_$i"} unless ($form->{"selected_unit_$i"});
 
 270     my $check_units = $form->{"inventory_accno_$i"} ? $dimension_units : $service_units;
 
 271     if (!$check_units->{$form->{"selected_unit_$i"}} ||
 
 272         ($check_units->{$form->{"selected_unit_$i"}}->{"base_unit"} ne
 
 273          $all_units->{$form->{"unit_old_$i"}}->{"base_unit"})) {
 
 274       # Die ausgewaehlte Einheit ist fuer diesen Artikel nicht gueltig
 
 275       # (z.B. Dimensionseinheit war ausgewaehlt, es handelt sich aber
 
 276       # um eine Dienstleistung). Dann keinerlei Umrechnung vornehmen.
 
 277       $form->{"unit_old_$i"} = $form->{"selected_unit_$i"} = $form->{"unit_$i"};
 
 279     if ((!$form->{"prices_$i"}) || ($form->{"new_pricegroup_$i"} == $form->{"old_pricegroup_$i"})) {
 
 280       if ($form->{"unit_old_$i"} ne $form->{"selected_unit_$i"}) {
 
 282         if (defined($all_units->{$form->{"unit_old_$i"}}->{"factor"}) &&
 
 283             $all_units->{$form->{"unit_old_$i"}}->{"factor"}) {
 
 284           $basefactor = $all_units->{$form->{"selected_unit_$i"}}->{"factor"} /
 
 285             $all_units->{$form->{"unit_old_$i"}}->{"factor"};
 
 287         $form->{"sellprice_$i"} *= $basefactor;
 
 288         $form->{"unit_old_$i"} = $form->{"selected_unit_$i"};
 
 291     ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
 
 293     $decimalplaces = ($dec > 2) ? $dec : 2;
 
 297                         $form->{"sellprice_$i"} * $form->{"discount_$i"} / 100,
 
 301       $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
 
 302     $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
 
 304     # convert " to "
 
 305     map { $form->{"${_}_$i"} =~ s/\"/"/g }
 
 306       qw(partnumber description unit unit_old);
 
 308 ########################################
 
 309     # Eintrag fuer Version 2.2.0 geaendert #
 
 310     # neue Optik im Rechnungsformular      #
 
 311 ########################################
 
 312     $column_data{runningnumber} =
 
 313       qq|<td><input name="runningnumber_$i" size="5" value="$i"></td>|;    # HuT
 
 314 ############## ENDE Neueintrag ##################
 
 316     $column_data{partnumber} =
 
 317       qq|<td><input name="partnumber_$i" size=12 value="$form->{"partnumber_$i"}"></td>|;
 
 319     if (($rows = $form->numtextrows($form->{"description_$i"}, 30, 6)) > 1) {
 
 320       $column_data{description} =
 
 321         qq|<td><textarea name="description_$i" rows="$rows" cols="30" wrap="soft">| . H($form->{"description_$i"}) . qq|</textarea><button type="button" onclick="set_longdescription_window('longdescription_$i')">| . $locale->text('L') . qq|</button></td>|;
 
 323       $column_data{description} =
 
 324         qq|<td><input name="description_$i" size="30" value="| . $form->quote($form->{"description_$i"}) . qq|"><button type="button" onclick="set_longdescription_window('longdescription_$i')">| . $locale->text('L') . qq|</button></td>|;
 
 327     (my $qty_dec) = ($form->{"qty_$i"} =~ /\.(\d+)/);
 
 328     $qty_dec = length $qty_dec;
 
 331         qq|<td align="right"><input name="qty_$i" size="5" value="|
 
 332       . $form->format_amount(\%myconfig, $form->{"qty_$i"}, $qty_dec) .qq|">|;
 
 333     if ($form->{"formel_$i"}) {
 
 334     $column_data{qty} .= qq|<button type="button" onclick="calculate_qty_selection_window('qty_$i','alu_$i', 'formel_$i', $i)">| . $locale->text('*/') . qq|</button>| .
 
 335           $cgi->hidden("-name" => "formel_$i", "-value" => $form->{"formel_$i"}) . $cgi->hidden("-name" => "alu_$i", "-value" => $form->{"alu_$i"}). qq|</td>|;
 
 338         qq|<td align="right"><input name="ship_$i" size=5 value="|
 
 339       . $form->format_amount(\%myconfig, $form->{"ship_$i"})
 
 342     my $is_part     = $form->{"inventory_accno_$i"};
 
 343     my $is_assembly = $form->{"assembly_$i"};
 
 344     my $is_assigned = $form->{"id_$i"};
 
 345     my $this_unit = $form->{"unit_$i"};
 
 346     if ($form->{"selected_unit_$i"} && $this_unit &&
 
 347         $all_units->{$form->{"selected_unit_$i"}} && $all_units->{$this_unit} &&
 
 348         ($all_units->{$form->{"selected_unit_$i"}}->{"base_unit"} eq $all_units->{$this_unit}->{"base_unit"})) {
 
 349       $this_unit = $form->{"selected_unit_$i"};
 
 350     } elsif (!$is_assigned ||
 
 351              ($is_part && !$this_unit && ($all_units->{$this_unit} && ($all_units->{$this_unit}->{"base_unit"} eq $all_units->{"kg"}->{"base_unit"})))) {
 
 355     $column_data{"unit"} = "<td>" .
 
 356        AM->unit_select_html($is_part || $is_assembly ? $dimension_units :
 
 357                             $is_assigned ? $service_units : $all_units,
 
 358                             "unit_$i", $this_unit,
 
 359                             $is_assigned ? $form->{"unit_$i"} : undef)
 
 362     # build in drop down list for pricesgroups
 
 363     if ($form->{"prices_$i"}) {
 
 364       if  ($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"}) {
 
 365         $price_tmp = $form->format_amount(\%myconfig, $form->{"price_new_$i"}, $decimalplaces);
 
 367         $price_tmp = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
 
 370       $column_data{sellprice_pg} =
 
 371       qq|<td align="right"><select name="sellprice_pg_$i">$form->{"prices_$i"}</select></td>|;
 
 372       $column_data{sellprice} =
 
 373       qq|<td><input name="sellprice_$i" size="10" value="$price_tmp" onBlur=\"check_right_number_format(this)\"></td>|;
 
 376       # for last row and report
 
 377       # set pricegroup drop down list from report menu
 
 378       if ($form->{"sellprice_$i"} != 0) {
 
 380           qq|<option value="$form->{"sellprice_$i"}--$form->{"pricegroup_id_$i"}" selected>$form->{"pricegroup_$i"}</option>\n|;
 
 382         $form->{"pricegroup_old_$i"} = $form->{"pricegroup_id_$i"};
 
 384         $column_data{sellprice_pg} =
 
 385           qq|<td align="right"><select name="sellprice_pg_$i">$prices</select></td>|;
 
 390         $column_data{sellprice_pg} = qq|<td align="right"> </td>|;
 
 393       $column_data{sellprice} =
 
 394       qq|<td><input name="sellprice_$i" size="10" onBlur=\"check_right_number_format(this)\" value="|
 
 395         . $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
 
 399     $column_data{discount} =
 
 400         qq|<td align="right"><input name="discount_$i" size=3 value="|
 
 401       . $form->format_amount(\%myconfig, $form->{"discount_$i"})
 
 403     $column_data{linetotal} =
 
 404         qq|<td align="right">|
 
 405       . $form->format_amount(\%myconfig, $linetotal, 2)
 
 407     $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
 
 409 ########################################
 
 410     # Eintrag fuer Version 2.2.0 geaendert #
 
 411     # neue Optik im Rechnungsformular      #
 
 412 ########################################
 
 413     #     if ($lizenzen &&  $form->{type} eq "invoice" &&  $form->{vc} eq "customer") {
 
 414     #     $column_data{license} = qq|<td><select name="licensenumber_$i">$form->{"lizenzen_$i"}></select></td>|;
 
 417     #     if ($form->{type} !~ /_quotation/) {
 
 418     #     $column_data{serialnr} = qq|<td><input name="serialnumber_$i" size=10 value="$form->{"serialnumber_$i"}"></td>|;
 
 421     #     $column_data{projectnr} = qq|<td><input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}"></td>|;
 
 422 ############## ENDE Neueintrag ##################
 
 426         <tr valign="top" class="listrow$j">|;
 
 428     map { print "\n$column_data{$_}" } @column_index;
 
 431           $cgi->hidden("-name" => "unit_old_$i",
 
 432                        "-value" => $form->{"selected_unit_$i"})
 
 434           $cgi->hidden("-name" => "price_new_$i",
 
 435                        "-value" => $form->format_amount(\%myconfig, $form->{"price_new_$i"}))
 
 437     map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_}) . "\n"); }
 
 438         ("orderitems_id_$i", "bo_$i", "pricegroup_old_$i", "price_old_$i",
 
 439          "id_$i", "inventory_accno_$i", "bin_$i", "partsgroup_$i", "partnotes_$i",
 
 440          "income_accno_$i", "expense_accno_$i", "listprice_$i", "assembly_$i",
 
 441          "taxaccounts_$i", "ordnumber_$i", "transdate_$i", "cusordnumber_$i",
 
 442          "longdescription_$i", "basefactor_$i"));
 
 444 ########################################
 
 445     # Eintrag fuer Version 2.2.0 geaendert #
 
 446     # neue Optik im Rechnungsformular      #
 
 447 ########################################
 
 450       'style="display:none;"' if (!$form->{"show_details"});
 
 454         <tr  class="listrow$j" $row_style_attr>
 
 455           <td colspan="$colspan">
 
 457     if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
 
 458       my $selected = $form->{"licensenumber_$i"};
 
 460       $form->{"lizenzen_$i"} =~ s/ selected//g;
 
 461       $form->{"lizenzen_$i"} =~
 
 462         s/value="${selected}"\>/value="${selected}" selected\>/;
 
 463       $lizenzen_quoted = $form->{"lizenzen_$i"};
 
 464       $lizenzen_quoted =~ s/\"/"/g;
 
 466         <b>Lizenz\#</b> <select name="licensenumber_$i" size="1">
 
 467         $form->{"lizenzen_$i"}
 
 469         <input type="hidden" name="lizenzen_$i" value="${lizenzen_quoted}">
 
 472     if ($form->{type} !~ /_quotation/) {
 
 474           <b>$serialnumber</b> <input name="serialnumber_$i" size="15" value="$form->{"serialnumber_$i"}">|;
 
 477     print qq|<b>$projectnumber</b> | .
 
 478       NTI($cgi->popup_menu('-name' => "project_id_$i",
 
 479                            '-values' => \@projectnumber_values,
 
 480                            '-labels' => \%projectnumber_labels,
 
 481                            '-default' => $form->{"project_id_$i"}));
 
 483     if ($form->{type} eq 'invoice' or $form->{type} =~ /order/) {
 
 485         ($form->{type} eq 'invoice')
 
 487         : 'reqdate';    # invoice uses a different term for the same thing.
 
 489         <b>${$reqdate_term}</b> <input name="${reqdate_term}_$i" size="11" onBlur="check_right_date_format(this)" value="$form->{"${reqdate_term}_$i"}">
 
 492     my $subtotalchecked = ($form->{"subtotal_$i"}) ? "checked" : "";
 
 494           <b>|.$locale->text('Subtotal').qq|</b> <input type="checkbox" name="subtotal_$i" value="1" "$subtotalchecked">
 
 500 ############## ENDE Neueintrag ##################
 
 502     map { $form->{"${_}_base"} += $linetotal }
 
 503       (split(/ /, $form->{"taxaccounts_$i"}));
 
 505     $form->{invsubtotal} += $linetotal;
 
 514   $lxdebug->leave_sub();
 
 517 ##################################################
 
 518 # build html-code for pricegroups in variable $form->{prices_$j}
 
 521   $lxdebug->enter_sub();
 
 522   my $rowcount = shift;
 
 523   for $j (1 .. $rowcount) {
 
 524     my $pricegroup_old = $form->{"pricegroup_old_$i"};
 
 525     if ($form->{PRICES}{$j}) {
 
 527       $prices = '<option value="--">' . $locale->text("none (pricegroup)") . '</option>';
 
 529       foreach $item (@{ $form->{PRICES}{$j} }) {
 
 531         #$price = $form->round_amount($myconfig,  $item->{price}, 5);
 
 532         #$price = $form->format_amount($myconfig, $item->{price}, 2);
 
 533         $price         = $item->{price};
 
 534         $pricegroup_id = $item->{pricegroup_id};
 
 535         $pricegroup    = $item->{pricegroup};
 
 537         # build drop down list for pricegroups
 
 539           qq|<option value="$price--$pricegroup_id"$item->{selected}>$pricegroup</option>\n|;
 
 544         #               $form->{"${_}_$j"} =
 
 545         #               $form->format_amount(\%myconfig, $form->{"${_}_$j"})
 
 546         #              } qw(sellprice price_new price_old);
 
 548         # set new selectedpricegroup_id and prices for "Preis"
 
 549         if ($item->{selected} && ($pricegroup_id != 0)) {
 
 550           $form->{"pricegroup_old_$j"} = $pricegroup_id;
 
 551           $form->{"price_new_$j"}      = $price;
 
 552           $form->{"sellprice_$j"}      = $price;
 
 554         if ($pricegroup_id == 0) {
 
 555           $form->{"price_new_$j"} = $form->{"sellprice_$j"};
 
 558       $form->{"prices_$j"} = $prices;
 
 561   $lxdebug->leave_sub();
 
 565   $lxdebug->enter_sub();
 
 566   @column_index = qw(ndx partnumber description onhand unit sellprice);
 
 568   $column_data{ndx}        = qq|<th> </th>|;
 
 569   $column_data{partnumber} =
 
 570     qq|<th class="listheading">| . $locale->text('Number') . qq|</th>|;
 
 571   $column_data{description} =
 
 572     qq|<th class="listheading">| . $locale->text('Part Description') . qq|</th>|;
 
 573   $column_data{sellprice} =
 
 574     qq|<th class="listheading">| . $locale->text('Price') . qq|</th>|;
 
 575   $column_data{onhand} =
 
 576     qq|<th class="listheading">| . $locale->text('Qty') . qq|</th>|;
 
 578     qq|<th class="listheading">| . $locale->text('Unit') . qq|</th>|;
 
 579   # list items with radio button on a form
 
 582   $title   = $locale->text('Select from one of the items below');
 
 583   $colspan = $#column_index + 1;
 
 588 <form method="post" action="$form->{script}">
 
 592     <th class="listtop" colspan="$colspan">$title</th>
 
 595   <tr class="listheading">|;
 
 597   map { print "\n$column_data{$_}" } @column_index;
 
 602   foreach $ref (@{ $form->{item_list} }) {
 
 603     $checked = ($i++) ? "" : "checked";
 
 606       if ($ref->{inventory_accno} > 0) {
 
 607         $ref->{"lizenzen"} = qq|<option></option>|;
 
 608         foreach $item (@{ $form->{LIZENZEN}{ $ref->{"id"} } }) {
 
 609           $ref->{"lizenzen"} .=
 
 610             qq|<option value=\"$item->{"id"}\">$item->{"licensenumber"}</option>|;
 
 612         $ref->{"lizenzen"} .= qq|<option value="-1">Neue Lizenz</option>|;
 
 613         $ref->{"lizenzen"} =~ s/\"/"/g;
 
 617     map { $ref->{$_} =~ s/\"/"/g } qw(partnumber description unit);
 
 621       $form->round_amount($ref->{sellprice} * (1 - $form->{tradediscount}), 2);
 
 623       qq|<td><input name="ndx" class="radio" type="radio" value="$i" $checked></td>|;
 
 624     $column_data{partnumber} =
 
 625       qq|<td><input name="new_partnumber_$i" type="hidden" value="$ref->{partnumber}">$ref->{partnumber}</td>|;
 
 626     $column_data{description} =
 
 627       qq|<td><input name="new_description_$i" type="hidden" value="$ref->{description}">$ref->{description}</td>|;
 
 628     $column_data{sellprice} =
 
 629       qq|<td align="right"><input name="new_sellprice_$i" type="hidden" value="$ref->{sellprice}">|
 
 630       . $form->format_amount(\%myconfig, $ref->{sellprice}, 2, " ")
 
 632     $column_data{onhand} =
 
 633       qq|<td align="right"><input name="new_onhand_$i" type="hidden" value="$ref->{onhand}">|
 
 634       . $form->format_amount(\%myconfig, $ref->{onhand}, '', " ")
 
 637       qq|<td>$ref->{unit}</td>|;
 
 641 <tr class=listrow$j>|;
 
 643     map { print "\n$column_data{$_}" } @column_index;
 
 648       qw(bin listprice inventory_accno income_accno expense_accno unit weight
 
 649          assembly taxaccounts partsgroup formel longdescription not_discountable
 
 650          part_payment_id partnotes id);
 
 651     push(@new_fields, "lizenzen") if ($lizenzen);
 
 653     print join "\n", map { $cgi->hidden("-name" => "new_${_}_$i", "-value" => $ref->{$_}) } @new_fields;
 
 658 <tr><td colspan="8"><hr size="3" noshade></td></tr>
 
 661 <input name="lastndx" type="hidden" value="$i">
 
 665   # delete action variable
 
 666   map { delete $form->{$_} } qw(action item_list header);
 
 668   # save all other form variables
 
 669   foreach $key (keys %${form}) {
 
 670     $form->{$key} =~ s/\"/"/g;
 
 671     print qq|<input name="$key" type="hidden" value="$form->{$key}">\n|;
 
 675 <input type="hidden" name="nextsub" value="item_selected">
 
 678 <input class="submit" type="submit" name="action" value="|
 
 679     . $locale->text('Continue') . qq|">
 
 686   $lxdebug->leave_sub();
 
 690   $lxdebug->enter_sub();
 
 692   # replace the last row with the checked row
 
 693   $i = $form->{rowcount};
 
 694   $i = $form->{assembly_rows} if ($form->{item} eq 'assembly');
 
 700   #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
 
 701   #$form->{"sellprice_$i"} = $form->{"sellprice_$i"};
 
 703   # if there was a price entered, override it
 
 704   $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
 
 706   map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} }
 
 707     qw(id partnumber description sellprice listprice inventory_accno
 
 708        income_accno expense_accno bin unit weight assembly taxaccounts
 
 709        partsgroup formel longdescription not_discountable partnotes lastcost);
 
 710   if ($form->{"part_payment_id_$i"} ne "") {
 
 711     $form->{payment_id} = $form->{"part_payment_id_$i"};
 
 715     map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } qw(lizenzen);
 
 718   ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
 
 720   $decimalplaces = ($dec > 2) ? $dec : 2;
 
 723     $form->{"sellprice_$i"} = $sellprice;
 
 726     # if there is an exchange rate adjust sellprice
 
 727     if (($form->{exchangerate} * 1) != 0) {
 
 728       $form->{"sellprice_$i"} /= $form->{exchangerate};
 
 729       $form->{"sellprice_$i"} =
 
 730         $form->round_amount($form->{"sellprice_$i"}, $decimalplaces);
 
 734   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
 735     qw(sellprice listprice weight);
 
 737   $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
 
 738   $form->{weight}    += ($form->{"weight_$i"} * $form->{"qty_$i"});
 
 740   if ($form->{"not_discountable_$i"}) {
 
 741     $form->{"discount_$i"} = 0;
 
 745     $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) *
 
 747   map { $form->{"${_}_base"} += $amount }
 
 748     (split / /, $form->{"taxaccounts_$i"});
 
 749   map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /,
 
 750     $form->{"taxaccounts_$i"}
 
 751     if !$form->{taxincluded};
 
 753   $form->{creditremaining} -= $amount;
 
 755   $form->{"runningnumber_$i"} = $i;
 
 757   # delete all the new_ variables
 
 758   for $i (1 .. $form->{lastndx}) {
 
 759     map { delete $form->{"new_${_}_$i"} }
 
 760       qw(partnumber description sellprice bin listprice inventory_accno income_accno expense_accno unit assembly taxaccounts id);
 
 763   map { delete $form->{$_} } qw(ndx lastndx nextsub);
 
 768       $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces)
 
 769   } qw(sellprice listprice) if $form->{item} ne 'assembly';
 
 771   # get pricegroups for parts
 
 772   IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
 774   # build up html code for prices_$i
 
 775   set_pricegroup($form->{rowcount});
 
 779   $lxdebug->leave_sub();
 
 783   $lxdebug->enter_sub();
 
 786   $form->{old_callback} = $form->escape($form->{callback}, 1);
 
 787   $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
 
 790   delete $form->{action};
 
 792   # save all other form variables in a previousform variable
 
 793   foreach $key (keys %$form) {
 
 796     $form->{$key} =~ s/&/%26/g;
 
 797     $previousform .= qq|$key=$form->{$key}&|;
 
 800   $previousform = $form->escape($previousform, 1);
 
 802   $i = $form->{rowcount};
 
 803   map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description);
 
 810 <h4 class="error">| . $locale->text('Item not on file!') . qq|
 
 813 | . $locale->text('What type of item is this?') . qq|</h4>
 
 815 <form method="post" action="ic.pl">
 
 819   <input class="radio" type="radio" name="item" value="part" checked> |
 
 820     . $locale->text('Part') . qq|<br>
 
 821   <input class="radio" type="radio" name="item" value="service"> |
 
 822     . $locale->text('Service');
 
 823 print $cgi->hidden("-name" => "previousform", "-value" => $previousform);
 
 824 map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); } 
 
 825      qw(rowcount vc login password));
 
 826      map({ print($cgi->hidden("-name" => $_, "-value" => $form->{"$__$i"})); }
 
 827      ("partnumber", "description"));
 
 828 print $cgi->hidden("-name" => "taxaccount2", "-value" => $form->{taxaccounts});
 
 831 <input type="hidden" name="nextsub" value="add">
 
 834 <input class="submit" type="submit" name="action" value="|
 
 835     . $locale->text('Continue') . qq|">
 
 842   $lxdebug->leave_sub();
 
 846   $lxdebug->enter_sub();
 
 850   my $new_rowcount = $form->{"rowcount"} * 1 + 1;
 
 851   $form->{"project_id_${new_rowcount}"} = $form->{"globalproject_id"};
 
 853   $form->language_payment(\%myconfig);
 
 855   # if we have a display_form
 
 856   if ($form->{display_form}) {
 
 857     call_sub($form->{"display_form"});
 
 861   Common::webdav_folder($form) if ($webdav);
 
 863   #   if (   $form->{print_and_post}
 
 864   #       && $form->{second_run}
 
 865   #       && ($form->{action} eq "display_form")) {
 
 866   #     for (keys %$form) { $old_form->{$_} = $form->{$_} }
 
 867   #     $old_form->{rowcount}++;
 
 869   #     #$form->{rowcount}--;
 
 870   #     #$form->{rowcount}--;
 
 872   #     $form->{print_and_post} = 0;
 
 874   #     &print_form($old_form);
 
 878   #   $form->{action}   = "";
 
 879   #   $form->{resubmit} = 0;
 
 881   #   if ($form->{print_and_post} && !$form->{second_run}) {
 
 882   #     $form->{second_run} = 1;
 
 883   #     $form->{action}     = "display_form";
 
 884   #     $form->{rowcount}--;
 
 885   #     my $rowcount = $form->{rowcount};
 
 887   #     # get pricegroups for parts
 
 888   #     IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
 890   #     # build up html code for prices_$i
 
 891   #     set_pricegroup($rowcount);
 
 893   #     $form->{resubmit} = 1;
 
 898   $numrows    = ++$form->{rowcount};
 
 899   $subroutine = "display_row";
 
 901   if ($form->{item} eq 'part') {
 
 903     #set preisgruppenanzahl
 
 904     $numrows    = $form->{price_rows};
 
 905     $subroutine = "price_row";
 
 907     &{$subroutine}($numrows);
 
 909     $numrows    = ++$form->{makemodel_rows};
 
 910     $subroutine = "makemodel_row";
 
 912   if ($form->{item} eq 'assembly') {
 
 913     $numrows    = $form->{price_rows};
 
 914     $subroutine = "price_row";
 
 916     &{$subroutine}($numrows);
 
 918     $numrows    = ++$form->{makemodel_rows};
 
 919     $subroutine = "makemodel_row";
 
 921     # create makemodel rows
 
 922     &{$subroutine}($numrows);
 
 924     $numrows    = ++$form->{assembly_rows};
 
 925     $subroutine = "assembly_row";
 
 927   if ($form->{item} eq 'service') {
 
 928     $numrows    = $form->{price_rows};
 
 929     $subroutine = "price_row";
 
 931     &{$subroutine}($numrows);
 
 937   &{$subroutine}($numrows) if $numrows;
 
 941   $lxdebug->leave_sub();
 
 945   $lxdebug->enter_sub();
 
 949     qw(id partnumber description qty ship sellprice unit discount inventory_accno income_accno expense_accno listprice taxaccounts bin assembly weight projectnumber project_id oldprojectnumber runningnumber serialnumber partsgroup payment_id not_discountable shop ve gv buchungsgruppen_id language_values sellprice_pg pricegroup_old price_old price_new unit_old ordnumber transdate longdescription basefactor)
 
 953   # remove any makes or model rows
 
 954   if ($form->{item} eq 'part') {
 
 955     map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
 956       qw(listprice sellprice lastcost weight rop);
 
 958     @flds = (make, model);
 
 959     for my $i (1 .. ($form->{makemodel_rows})) {
 
 960       if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
 
 964         map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
 
 969     $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
 
 970     $form->{makemodel_rows} = $count;
 
 972   } elsif ($form->{item} eq 'assembly') {
 
 974     $form->{sellprice} = 0;
 
 976     map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
 977       qw(listprice rop stock);
 
 980       qw(id qty unit bom partnumber description sellprice weight runningnumber partsgroup);
 
 982     for my $i (1 .. ($form->{assembly_rows} - 1)) {
 
 983       if ($form->{"qty_$i"}) {
 
 987         $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
 
 989         map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
 
 991         #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
 
 993         $form->{sellprice} += ($form->{"qty_$i"} * $form->{"sellprice_$i"});
 
 994         $form->{weight}    += ($form->{"qty_$i"} * $form->{"weight_$i"});
 
 999     $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
 
1001     $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
 
1002     $form->{assembly_rows} = $count;
 
1005     @flds  = qw(make model);
 
1008     for my $i (1 .. ($form->{makemodel_rows})) {
 
1009       if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
 
1013         map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
 
1018     $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
 
1019     $form->{makemodel_rows} = $count;
 
1023     # this section applies to invoices and orders
 
1024     # remove any empty numbers
 
1025     if ($form->{rowcount}) {
 
1026       for my $i (1 .. $form->{rowcount} - 1) {
 
1027         if ($form->{"partnumber_$i"}) {
 
1031           map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
 
1034             if ($form->{"licensenumber_$i"} == -1) {
 
1042       $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
 
1043       $form->{rowcount} = $count;
 
1045       $form->{creditremaining} -= &invoicetotal;
 
1052   if (   $form->{type} =~ (/sales_quotation/)
 
1053       or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/))
 
1054       or (($form->{level} eq undef) and ($form->{type} =~ /invoice/))
 
1055       or ($form->{type} =~ /sales_order/)) {
 
1057     # get pricegroups for parts
 
1058     IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
1060     # build up html code for prices_$i
 
1061     set_pricegroup($form->{rowcount});
 
1067   $lxdebug->leave_sub();
 
1071   $lxdebug->enter_sub();
 
1073   $form->{oldinvtotal} = 0;
 
1075   # add all parts and deduct paid
 
1076   map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
 
1078   my ($amount, $sellprice, $discount, $qty);
 
1080   for my $i (1 .. $form->{rowcount}) {
 
1081     $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
 
1082     $discount  = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
 
1083     $qty       = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
 
1085     #($form->{"sellprice_$i"}, $form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
 
1087     $amount = $sellprice * (1 - $discount / 100) * $qty;
 
1088     map { $form->{"${_}_base"} += $amount }
 
1089       (split (/ /, $form->{"taxaccounts_$i"}));
 
1090     $form->{oldinvtotal} += $amount;
 
1093   map { $form->{oldinvtotal} += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
 
1094     split(/ /, $form->{taxaccounts})
 
1095     if !$form->{taxincluded};
 
1097   $form->{oldtotalpaid} = 0;
 
1098   for $i (1 .. $form->{paidaccounts}) {
 
1099     $form->{oldtotalpaid} += $form->{"paid_$i"};
 
1102   $lxdebug->leave_sub();
 
1105   return ($form->{oldinvtotal} - $form->{oldtotalpaid});
 
1108 sub validate_items {
 
1109   $lxdebug->enter_sub();
 
1111   # check if items are valid
 
1112   if ($form->{rowcount} == 1) {
 
1117   for $i (1 .. $form->{rowcount} - 1) {
 
1118     $form->isblank("partnumber_$i",
 
1119                    $locale->text('Number missing in Row') . " $i");
 
1122   $lxdebug->leave_sub();
 
1126   $lxdebug->enter_sub();
 
1127   if ($form->{second_run}) {
 
1128     $form->{print_and_post} = 0;
 
1130   $form->{ordnumber} = $form->{invnumber};
 
1132   $form->{old_employee_id} = $form->{employee_id};
 
1133   $form->{old_salesman_id} = $form->{salesman_id};
 
1135   map { delete $form->{$_} } qw(id printed emailed queued);
 
1136   if ($form->{script} eq 'ir.pl' || $form->{type} eq 'request_quotation') {
 
1137     $form->{title} = $locale->text('Add Purchase Order');
 
1138     $form->{vc}    = 'vendor';
 
1139     $form->{type}  = 'purchase_order';
 
1142   if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_quotation') {
 
1143     $form->{title} = $locale->text('Add Sales Order');
 
1144     $form->{vc}    = 'customer';
 
1145     $form->{type}  = 'sales_order';
 
1148   $form->{script} = 'oe.pl';
 
1150   $form->{shipto} = 1;
 
1152   $form->{rowcount}--;
 
1154   $form->{cp_id} *= 1;
 
1156   require "bin/mozilla/$form->{script}";
 
1157   my $script = $form->{"script"};
 
1159   $script =~ s|.pl$||;
 
1160   $locale = new Locale($language, $script);
 
1162   map { $form->{"select$_"} = "" } ($form->{vc}, currency);
 
1164   $currency = $form->{currency};
 
1168   $form->{currency}     = $currency;
 
1169   $form->{exchangerate} = "";
 
1170   $form->{forex}        = "";
 
1171   $form->{exchangerate} = $exchangerate
 
1175                     $form->check_exchangerate(
 
1176                     \%myconfig, $form->{currency}, $form->{transdate}, $buysell
 
1179   for $i (1 .. $form->{rowcount}) {
 
1180     map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
 
1181                                                      $form->{"${_}_${i}"})
 
1182             if ($form->{"${_}_${i}"}) }
 
1183         qw(ship qty sellprice listprice basefactor));
 
1189   $lxdebug->leave_sub();
 
1193   $lxdebug->enter_sub();
 
1194   if ($form->{second_run}) {
 
1195     $form->{print_and_post} = 0;
 
1197   map { delete $form->{$_} } qw(id printed emailed queued);
 
1199   if ($form->{script} eq 'ir.pl' || $form->{type} eq 'purchase_order') {
 
1200     $form->{title} = $locale->text('Add Request for Quotation');
 
1201     $form->{vc}    = 'vendor';
 
1202     $form->{type}  = 'request_quotation';
 
1205   if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_order') {
 
1206     $form->{title} = $locale->text('Add Quotation');
 
1207     $form->{vc}    = 'customer';
 
1208     $form->{type}  = 'sales_quotation';
 
1212   $form->{cp_id} *= 1;
 
1214   $form->{script} = 'oe.pl';
 
1216   $form->{shipto} = 1;
 
1218   $form->{rowcount}--;
 
1220   require "bin/mozilla/$form->{script}";
 
1222   map { $form->{"select$_"} = "" } ($form->{vc}, currency);
 
1224   $currency = $form->{currency};
 
1228   $form->{currency}     = $currency;
 
1229   $form->{exchangerate} = "";
 
1230   $form->{forex}        = "";
 
1231   $form->{exchangerate} = $exchangerate
 
1235                     $form->check_exchangerate(
 
1236                     \%myconfig, $form->{currency}, $form->{transdate}, $buysell
 
1239   for $i (1 .. $form->{rowcount}) {
 
1240     map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
 
1241                                                      $form->{"${_}_${i}"})
 
1242             if ($form->{"${_}_${i}"}) }
 
1243         qw(ship qty sellprice listprice basefactor));
 
1249   $lxdebug->leave_sub();
 
1252 sub request_for_quotation {
 
1257   $lxdebug->enter_sub();
 
1258   if ($form->{second_run}) {
 
1259     $form->{print_and_post} = 0;
 
1260     $form->{resubmit}       = 0;
 
1263   $form->{email} = $form->{shiptoemail} if $form->{shiptoemail} && $form->{formname} =~ /(pick|packing|bin)_list/;
 
1265   if ($form->{"cp_id"} && !$form->{"email"}) {
 
1266     CT->get_contact(\%myconfig, $form);
 
1267     $form->{"email"} = $form->{"cp_email"};
 
1270   $form->{ $form->{vc} } =~ /--/;
 
1271   $title = $locale->text('E-mail') . " $`";
 
1273   $form->{oldmedia} = $form->{media};
 
1274   $form->{media}    = "email";
 
1276   my $attachment_filename = $form->generate_attachment_filename();
 
1278   $form->{"fokus"} = $form->{"email"} ? "Form.subject" : "Form.email";
 
1281   my (@dont_hide_key_list, %dont_hide_key, @hidden_keys);
 
1282   @dont_hide_key_list = qw(action email cc bcc subject message formname sendmode format header override);
 
1283   @dont_hide_key{@dont_hide_key_list} = (1) x @dont_hide_key_list;
 
1284   @hidden_keys = grep { !$dont_hide_key{$_} } grep { !ref $form->{$_} } keys %$form;
 
1286   print $form->parse_html_template('generic/edit_email', 
 
1288                                     a_filename      => $attachment_filename,
 
1289                                     _print_options_ => print_options({ 'inline' => 1 }),
 
1290                                     HIDDEN          => [ map +{ name => $_, value => $form->{$_} }, @hidden_keys ],
 
1291                                     SHOW_BCC        => $myconfig{role} eq 'admin' });
 
1293   $lxdebug->leave_sub();
 
1297   $lxdebug->enter_sub();
 
1299   my $callback = $form->{script} . "?action=edit";
 
1300   map({ $callback .= "\&${_}=" . E($form->{$_}); }
 
1301       qw(login password type id));
 
1303   print_form("return");
 
1305   $form->{callback} = $callback;
 
1308   $lxdebug->leave_sub();
 
1311 # generate the printing options displayed at the bottom of oe and is forms.
 
1312 # this function will attempt to guess what type of form is displayed, and will generate according options
 
1315 # this version builds the arrays of options pretty directly. if you have trouble understanding how,
 
1316 # the opthash function builds hashrefs which are then pieced together for the template arrays.
 
1317 # unneeded options are "undef"ed out, and then grepped out. 
 
1319 # the inline options is untested, but intended to be used later in metatemplating
 
1321   $lxdebug->enter_sub();
 
1327   # names 3 parameters and returns a hashref, for use in templates
 
1328   sub opthash { +{ value => shift, selected => shift, oname => shift } }
 
1329   (@FORMNAME, @FORMNAME, @LANGUAGE_ID, @FORMAT, @SENDMODE, @MEDIA, @PRINTER_ID, @SELECTS) = ();
 
1331   # note: "||"-selection is only correct for values where "0" is _not_ a correct entry
 
1332   $form->{sendmode}   = "attachment";
 
1333   $form->{format}     = $form->{format} || $myconfig{template_format} || "pdf";
 
1334   $form->{copies}     = $form->{copies} || $myconfig{copies} || 3;
 
1335   $form->{media}      = $form->{media} || $myconfig{default_media} || "screen";
 
1336   $form->{printer_id} = defined $form->{printer_id}           ? $form->{printer_id} :
 
1337                         defined $myconfig{default_printer_id} ? $myconfig{default_printer_id} : "";
 
1339   $form->{PD}{ $form->{formname} } = "selected";
 
1340   $form->{DF}{ $form->{format} }   = "selected";
 
1341   $form->{OP}{ $form->{media} }    = "selected";
 
1342   $form->{SM}{ $form->{formname} } = "selected";
 
1344   push @FORMNAME, grep $_,
 
1345     ($form->{type} eq 'purchase_order') ? (
 
1346       opthash("purchase_order", $form->{PD}{purchase_order}, $locale->text('Purchase Order')),
 
1347       opthash("bin_list", $form->{PD}{bin_list}, $locale->text('Bin List')) 
 
1349     ($form->{type} eq 'credit_note') ?
 
1350       opthash("credit_note", $form->{PD}{credit_note}, $locale->text('Credit Note')) : undef,
 
1351     ($form->{type} eq 'sales_order') ? (
 
1352       opthash("sales_order", $form->{PD}{sales_order}, $locale->text('Confirmation')),
 
1353       opthash("proforma", $form->{PD}{proforma}, $locale->text('Proforma Invoice')),
 
1354       opthash("pick_list", $form->{PD}{pick_list}, $locale->text('Pick List')),
 
1355       opthash("packing_list", $form->{PD}{packing_list}, $locale->text('Packing List')) 
 
1357     ($form->{type} =~ /_quotation$/) ?
 
1358       opthash("$`_quotation", $form->{PD}{"$`_quotation"}, $locale->text('Quotation')) : undef,
 
1359     ($form->{type} eq 'invoice') ? (
 
1360       opthash("invoice", $form->{PD}{invoice}, $locale->text('Invoice')),
 
1361       opthash("proforma", $form->{PD}{proforma}, $locale->text('Proforma Invoice')),
 
1362       opthash("packing_list", $form->{PD}{packing_list}, $locale->text('Packing List'))
 
1364     ($form->{type} eq 'invoice' && $form->{storno}) ? (
 
1365       opthash("storno_invoice", $form->{PD}{storno_invoice}, $locale->text('Storno Invoice')),
 
1366       opthash("storno_packing_list", $form->{PD}{storno_packing_list}, $locale->text('Storno Packing List')) 
 
1368     ($form->{type} eq 'credit_note') ?
 
1369       opthash("credit_note", $form->{PD}{credit_note}, $locale->text('Credit Note')) : undef;
 
1372     opthash("attachment", $form->{SM}{attachment}, $locale->text('Attachment')),
 
1373     opthash("inline", $form->{SM}{inline}, $locale->text('In-line'))
 
1374       if ($form->{media} eq 'email');
 
1376   push @MEDIA, grep $_,
 
1377       opthash("screen", $form->{OP}{screen}, $locale->text('Screen')),
 
1378     (scalar @{ $form->{printers} } && $latex_templates) ?
 
1379       opthash("printer", $form->{OP}{printer}, $locale->text('Printer')) : undef,
 
1380     ($latex_templates && !$options->{no_queue}) ?
 
1381       opthash("queue", $form->{OP}{queue}, $locale->text('Queue')) : undef
 
1382         if ($form->{media} ne 'email');
 
1384   push @FORMAT, grep $_,
 
1385     ($opendocument_templates && $openofficeorg_writer_bin && $xvfb_bin && (-x $openofficeorg_writer_bin) && (-x $xvfb_bin)
 
1386      && !$options->{no_opendocument_pdf}) ?
 
1387       opthash("opendocument_pdf", $form->{DF}{"opendocument_pdf"}, $locale->text("PDF (OpenDocument/OASIS)")) : undef,
 
1388     ($latex_templates) ?
 
1389       opthash("pdf", $form->{DF}{pdf}, $locale->text('PDF')) : undef,
 
1390     ($latex_templates && !$options->{no_postscript}) ?
 
1391       opthash("postscript", $form->{DF}{postscript}, $locale->text('Postscript')) : undef,
 
1392     (!$options->{no_html}) ?
 
1393       opthash("html", $form->{DF}{html}, "HTML") : undef,
 
1394     ($opendocument_templates && !$options->{no_opendocument}) ?
 
1395       opthash("opendocument", $form->{DF}{opendocument}, $locale->text("OpenDocument/OASIS")) : undef;
 
1398     map { opthash($_->{id}, ($_->{id} eq $form->{language} ? 'selected' : ''), $_->{description}) } +{}, @{ $form->{languages} }
 
1399       if (ref $form->{languages} eq 'ARRAY');
 
1402     map { opthash($_->{id}, ($_->{id} eq $form->{printer_id} ? 'selected' : ''), $_->{printer_description}) } +{}, @{ $form->{printers} }
 
1403       if ((ref $form->{printers} eq 'ARRAY') && scalar @{ $form->{printers } });
 
1405   @SELECTS = map { sname => lc $_, DATA => \@$_, show => scalar @$_ }, qw(FORMNAME LANGUAGE_ID FORMAT SENDMODE MEDIA PRINTER_ID);
 
1407   my %dont_display_groupitems = (
 
1412     display_copies       => scalar @{ $form->{printers} } && $latex_templates && $form->{media} ne 'email',
 
1413     display_remove_draft => (!$form->{id} && $form->{draft_id}),
 
1414     display_groupitems   => !$dont_display_groupitems{$form->{type}},
 
1415     groupitems_checked   => $form->{groupitems} ? "checked" : '',
 
1416     remove_draft_checked => $form->{remove_draft} ? "checked" : ''
 
1419   my $print_options = $form->parse_html_template("generic/print_options", { SELECTS  => \@SELECTS, %template_vars } );
 
1421   if ($options->{inline}) {
 
1422     $lxdebug->leave_sub() and return $print_options;
 
1424     print $print_options; $lxdebug->leave_sub();
 
1429   $lxdebug->enter_sub();
 
1431   if ($form->{print_nextsub}) {
 
1432     call_sub($form->{print_nextsub});
 
1433     $lxdebug->leave_sub();
 
1437   # if this goes to the printer pass through
 
1438   if ($form->{media} eq 'printer' || $form->{media} eq 'queue') {
 
1439     $form->error($locale->text('Select postscript or PDF!'))
 
1440       if ($form->{format} !~ /(postscript|pdf)/);
 
1442     $old_form = new Form;
 
1443     map { $old_form->{$_} = $form->{$_} } keys %$form;
 
1446   if (!$form->{id} || (($form->{formname} eq "proforma") && !$form->{proforma} && (($form->{type} =~ /_order$/) || ($form->{type} =~ /_quotation$/)))) {
 
1447     if ($form->{formname} eq "proforma") {
 
1448       $form->{proforma} = 1;
 
1450     $form->{print_and_save} = 1;
 
1451     my $formname = $form->{formname};
 
1453     $form->{formname} = $formname;
 
1458   &print_form($old_form);
 
1460   $lxdebug->leave_sub();
 
1464   $lxdebug->enter_sub();
 
1465   my ($old_form) = @_;
 
1469   $numberfld = "invnumber";
 
1472     ($form->{display_form}) ? $form->{display_form} : "display_form";
 
1474   # $form->{"notes"} will be overridden by the customer's/vendor's "notes" field. So save it here.
 
1475   $form->{ $form->{"formname"} . "notes" } = $form->{"notes"};
 
1477   if ($form->{formname} eq "invoice") {
 
1478     $form->{label} = $locale->text('Invoice');
 
1480   if ($form->{formname} eq "packing_list") {
 
1482     # this is from an invoice
 
1483     $form->{label} = $locale->text('Packing List');
 
1485   if ($form->{formname} eq 'sales_order') {
 
1488     $form->{"${inv}date"} = $form->{transdate};
 
1489     $form->{label}        = $locale->text('Sales Order');
 
1490     $numberfld            = "sonumber";
 
1494   if (($form->{type} eq 'invoice') && ($form->{formname} eq 'proforma') ) {
 
1497     $form->{"${inv}date"} = $form->{invdate};
 
1498     $form->{label}        = $locale->text('Proforma Invoice');
 
1499     $numberfld            = "sonumber";
 
1503   if (($form->{type} eq 'sales_order') && ($form->{formname} eq 'proforma') ) {
 
1506     $form->{"${inv}date"} = $form->{transdate};
 
1507     $form->{"invdate"}    = $form->{transdate};
 
1508     $form->{invnumber}    = $form->{ordnumber};
 
1509     $form->{label}        = $locale->text('Proforma Invoice');
 
1510     $numberfld            = "sonumber";
 
1514   if ($form->{formname} eq 'packing_list' && $form->{type} ne 'invoice') {
 
1516     # we use the same packing list as from an invoice
 
1519     $form->{invdate} = $form->{"${inv}date"} = $form->{transdate};
 
1520     $form->{label} = $locale->text('Packing List');
 
1522     # set invnumber for template packing_list 
 
1523     $form->{invnumber}   = $form->{ordnumber};
 
1525   if ($form->{formname} eq 'pick_list') {
 
1528     $form->{"${inv}date"} =
 
1529       ($form->{transdate}) ? $form->{transdate} : $form->{invdate};
 
1530     $form->{label} = $locale->text('Pick List');
 
1531     $order = 1 unless $form->{type} eq 'invoice';
 
1533   if ($form->{formname} eq 'purchase_order') {
 
1536     $form->{"${inv}date"} = $form->{transdate};
 
1537     $form->{label}        = $locale->text('Purchase Order');
 
1538     $numberfld            = "ponumber";
 
1541   if ($form->{formname} eq 'bin_list') {
 
1544     $form->{"${inv}date"} = $form->{transdate};
 
1545     $form->{label}        = $locale->text('Bin List');
 
1548   if ($form->{formname} eq 'sales_quotation') {
 
1551     $form->{"${inv}date"} = $form->{transdate};
 
1552     $form->{label}        = $locale->text('Quotation');
 
1553     $numberfld            = "sqnumber";
 
1557   if (($form->{type} eq 'sales_quotation') && ($form->{formname} eq 'proforma') ) {
 
1560     $form->{"${inv}date"} = $form->{transdate};
 
1561     $form->{"invdate"}    = $form->{transdate};
 
1562     $form->{label}        = $locale->text('Proforma Invoice');
 
1563     $numberfld            = "sqnumber";
 
1567   if ($form->{formname} eq 'request_quotation') {
 
1570     $form->{"${inv}date"} = $form->{transdate};
 
1571     $form->{label}        = $locale->text('Quotation');
 
1572     $numberfld            = "rfqnumber";
 
1576   $form->isblank("email", $locale->text('E-mail address missing!'))
 
1577     if ($form->{media} eq 'email');
 
1578   $form->isblank("${inv}date",
 
1579            $locale->text($form->{label}) 
 
1581            . $locale->text(' Date missing!'));
 
1583   # $locale->text('Invoice Number missing!')
 
1584   # $locale->text('Invoice Date missing!')
 
1585   # $locale->text('Packing List Number missing!')
 
1586   # $locale->text('Packing List Date missing!')
 
1587   # $locale->text('Order Number missing!')
 
1588   # $locale->text('Order Date missing!')
 
1589   # $locale->text('Quotation Number missing!')
 
1590   # $locale->text('Quotation Date missing!')
 
1593   $form->{what_done} = $form->{formname};
 
1594   if (!$form->{"${inv}number"} && !$form->{preview} && !$form->{id}) {
 
1595     $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
 
1596     if ($form->{media} ne 'email') {
 
1598       # get pricegroups for parts
 
1599       IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
1601       # build up html code for prices_$i
 
1602       set_pricegroup($form->{rowcount});
 
1604       $form->{rowcount}--;
 
1606       call_sub($display_form);
 
1607       # saving the history
 
1608           if(!exists $form->{addition}) {
 
1609         $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber}; 
 
1610             $form->{addition} = "PRINTED";
 
1611             $form->save_history($form->dbconnect(\%myconfig));
 
1613       # /saving the history
 
1620   # Save the email address given in the form because it should override the setting saved for the customer/vendor.
 
1621   my ($saved_email, $saved_cc, $saved_bcc) =
 
1622     ($form->{"email"}, $form->{"cc"}, $form->{"bcc"});
 
1624   $language_saved = $form->{language_id};
 
1625   $payment_id_saved = $form->{payment_id};
 
1626   $salesman_id_saved = $form->{salesman_id};
 
1627   $cp_id_saved = $form->{cp_id};
 
1629   call_sub("$form->{vc}_details");
 
1631   $form->{language_id} = $language_saved;
 
1632   $form->{payment_id} = $payment_id_saved;
 
1634   $form->{"email"} = $saved_email if ($saved_email);
 
1635   $form->{"cc"}    = $saved_cc    if ($saved_cc);
 
1636   $form->{"bcc"}   = $saved_bcc   if ($saved_bcc);
 
1638   if (!$cp_id_saved) {
 
1639     # No contact was selected. Delete all contact variables because
 
1640     # IS->customer_details() and IR->vendor_details() get the default
 
1642     map({ delete($form->{$_}); } grep(/^cp_/, keys(%{ $form })));
 
1645   my ($language_tc, $output_numberformat, $output_dateformat, $output_longdates);
 
1646   if ($form->{"language_id"}) {
 
1647     ($language_tc, $output_numberformat, $output_dateformat, $output_longdates) =
 
1648       AM->get_language_details(\%myconfig, $form, $form->{language_id});
 
1650     $output_dateformat = $myconfig{"dateformat"};
 
1651     $output_numberformat = $myconfig{"numberformat"};
 
1652     $output_longdates = 1;
 
1655   ($form->{employee}) = split /--/, $form->{employee};
 
1657   # create the form variables
 
1659     OE->order_details(\%myconfig, \%$form);
 
1661     IS->invoice_details(\%myconfig, \%$form, $locale);
 
1664   $form->get_salesman(\%myconfig, $salesman_id_saved);
 
1666   if ($form->{shipto_id}) {
 
1667     $form->get_shipto(\%myconfig);
 
1670   @a = qw(name street zipcode city country);
 
1674   # if there is no shipto fill it in from billto
 
1675   foreach $item (@a) {
 
1676     if ($form->{"shipto$item"}) {
 
1683     if (   $form->{formname} eq 'purchase_order'
 
1684         || $form->{formname} eq 'request_quotation') {
 
1685       $form->{shiptoname}   = $myconfig{company};
 
1686       $form->{shiptostreet} = $myconfig{address};
 
1688       map { $form->{"shipto$_"} = $form->{$_} } @a;
 
1692   $form->{notes} =~ s/^\s+//g;
 
1694   $form->{templates} = "$myconfig{templates}";
 
1696   delete $form->{printer_command};
 
1698   $form->{language} = $form->get_template_language(\%myconfig);
 
1701   if ($form->{media} ne 'email') {
 
1702     $printer_code = $form->get_printer_code(\%myconfig);
 
1703     if ($printer_code ne "") {
 
1704       $printer_code = "_" . $printer_code;
 
1708   if ($form->{language} ne "") {
 
1709     map({ $form->{"unit"}->[$_] =
 
1710             AM->translate_units($form, $form->{"language"},
 
1711                                 $form->{"unit"}->[$_], $form->{"qty"}->[$_]); }
 
1712         (0..scalar(@{$form->{"unit"}}) - 1));
 
1713     $form->{language} = "_" . $form->{language};
 
1717   format_dates($output_dateformat, $output_longdates,
 
1718                qw(invdate orddate quodate pldate duedate reqdate transdate
 
1719                   shippingdate deliverydate validitydate paymentdate
 
1720                   datepaid transdate_oe deliverydate_oe
 
1721                   employee_startdate employee_enddate
 
1723                grep({ /^datepaid_\d+$/ ||
 
1724                         /^transdate_oe_\d+$/ ||
 
1725                         /^deliverydate_oe_\d+$/ ||
 
1727                         /^deliverydate_\d+$/ ||
 
1731   reformat_numbers($output_numberformat, 2,
 
1732                    qw(invtotal ordtotal quototal subtotal linetotal
 
1733                       listprice sellprice netprice discount
 
1734                       tax taxbase total paid),
 
1735                    grep({ /^linetotal_\d+$/ ||
 
1736                             /^listprice_\d+$/ ||
 
1737                             /^sellprice_\d+$/ ||
 
1747   reformat_numbers($output_numberformat, undef,
 
1752   $form->{IN} = "$form->{formname}$form->{language}${printer_code}.html";
 
1753   if ($form->{format} eq 'postscript') {
 
1754     $form->{postscript} = 1;
 
1755     $form->{IN} =~ s/html$/tex/;
 
1756   } elsif ($form->{"format"} =~ /pdf/) {
 
1758     if ($form->{"format"} =~ /opendocument/) {
 
1759       $form->{IN} =~ s/html$/odt/;
 
1761       $form->{IN} =~ s/html$/tex/;
 
1763   } elsif ($form->{"format"} =~ /opendocument/) {
 
1764     $form->{"opendocument"} = 1;
 
1765     $form->{"IN"} =~ s/html$/odt/;
 
1768   delete $form->{OUT};
 
1770   if ($form->{media} eq 'printer') {
 
1771     $form->{OUT} = "| $form->{printer_command} &>/dev/null";
 
1772     $form->{printed} .= " $form->{formname}";
 
1773     $form->{printed} =~ s/^ //;
 
1775   $printed = $form->{printed};
 
1777   if ($form->{media} eq 'email') {
 
1778     $form->{subject} = qq|$form->{label} $form->{"${inv}number"}|
 
1779       unless $form->{subject};
 
1781     $form->{emailed} .= " $form->{formname}";
 
1782     $form->{emailed} =~ s/^ //;
 
1784   $emailed = $form->{emailed};
 
1786   if ($form->{media} eq 'queue') {
 
1787     %queued = map { s|.*/|| } split / /, $form->{queued};
 
1789     if ($filename = $queued{ $form->{formname} }) {
 
1790       $form->{queued} =~ s/$form->{formname} $filename//;
 
1791       unlink "$spool/$filename";
 
1792       $filename =~ s/\..*$//g;
 
1798     $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
 
1799     $form->{OUT} = ">$spool/$filename";
 
1802     $form->{queued} .= " $form->{formname} $filename";
 
1804     $form->{queued} =~ s/^ //;
 
1806   $queued = $form->{queued};
 
1808 # saving the history
 
1809   if(!exists $form->{addition}) {
 
1810     $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
 
1811     if($form->{media} =~ /printer/) {
 
1812         $form->{addition} = "PRINTED";
 
1814     elsif($form->{media} =~ /email/) {
 
1815         $form->{addition} = "MAILED";
 
1817     elsif($form->{media} =~ /queue/) {
 
1818         $form->{addition} = "QUEUED";
 
1820     elsif($form->{media} =~ /screen/) {
 
1821         $form->{addition} = "SCREENED";
 
1823     $form->save_history($form->dbconnect(\%myconfig));
 
1825   # /saving the history
 
1827   $form->parse_template(\%myconfig, $userspath);
 
1829   $form->{callback} = "";
 
1831   if ($form->{media} eq 'email') {
 
1832     $form->{message} = $locale->text('sent') unless $form->{message};
 
1834   $message = $form->{message};
 
1836   # if we got back here restore the previous form
 
1837   if ($form->{media} =~ /(printer|email|queue)/) {
 
1839     $form->update_status(\%myconfig)
 
1840       if ($form->{media} eq 'queue' && $form->{id});
 
1842     return $lxdebug->leave_sub() if ($old_form eq "return");
 
1846       $old_form->{"${inv}number"} = $form->{"${inv}number"};
 
1848       # restore and display form
 
1849       map { $form->{$_} = $old_form->{$_} } keys %$old_form;
 
1851       $form->{queued}  = $queued;
 
1852       $form->{printed} = $printed;
 
1853       $form->{emailed} = $emailed;
 
1854       $form->{message} = $message;
 
1856       $form->{rowcount}--;
 
1857       map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
1858         qw(exchangerate creditlimit creditremaining);
 
1860       for $i (1 .. $form->{paidaccounts}) {
 
1862           $form->{"${_}_$i"} =
 
1863             $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
 
1864         } qw(paid exchangerate);
 
1867       call_sub($display_form);
 
1872       ($form->{media} eq 'printer')
 
1873       ? $locale->text('sent to printer')
 
1874       : $locale->text('emailed to') . " $form->{email}";
 
1875     $form->redirect(qq|$form->{label} $form->{"${inv}number"} $msg|);
 
1877   if ($form->{printing}) {
 
1878    call_sub($display_form);
 
1882   $lxdebug->leave_sub();
 
1885 sub customer_details {
 
1886   $lxdebug->enter_sub();
 
1887   IS->customer_details(\%myconfig, \%$form, @_);
 
1888   $lxdebug->leave_sub();
 
1891 sub vendor_details {
 
1892   $lxdebug->enter_sub();
 
1894   IR->vendor_details(\%myconfig, \%$form, @_);
 
1896   $lxdebug->leave_sub();
 
1900   $lxdebug->enter_sub();
 
1902   $form->{postasnew} = 1;
 
1903   map { delete $form->{$_} } qw(printed emailed queued);
 
1907   $lxdebug->leave_sub();
 
1911   $lxdebug->enter_sub();
 
1912   if ($form->{second_run}) {
 
1913     $form->{print_and_post} = 0;
 
1916   $title = $form->{title};
 
1917   $form->{title} = $locale->text('Ship to');
 
1919   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
1920     qw(exchangerate creditlimit creditremaining);
 
1923     qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry
 
1924        shiptocontact shiptophone shiptofax shiptoemail
 
1925        shiptodepartment_1 shiptodepartment_2);
 
1928     (qw(name department_1 department_2 street zipcode city country
 
1929         contact email phone fax));
 
1931   # get details for name
 
1932   call_sub("$form->{vc}_details", @addr_vars);
 
1935     ($form->{vc} eq 'customer')
 
1936     ? $locale->text('Customer Number')
 
1937     : $locale->text('Vendor Number');
 
1939   # get pricegroups for parts
 
1940   IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
1942   # build up html code for prices_$i
 
1943   set_pricegroup($form->{rowcount});
 
1945   $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
 
1947   $form->{rowcount}--;
 
1954 <form method="post" action="$form->{script}">
 
1956 <table width="100%">
 
1960         <tr class="listheading">
 
1961           <th class="listheading" colspan="2" width="50%">|
 
1962     . $locale->text('Billing Address') . qq|</th>
 
1963           <th class="listheading" width="50%">|
 
1964     . $locale->text('Shipping Address') . qq|</th>
 
1966         <tr height="5"></tr>
 
1968           <th align="right" nowrap>$number</th>
 
1969           <td>$form->{"$form->{vc}number"}</td>
 
1972           <th align="right" nowrap>| . $locale->text('Company Name') . qq|</th>
 
1973           <td>$form->{name}</td>
 
1974           <td><input name="shiptoname" size="35" value="$form->{shiptoname}"></td>
 
1977           <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
 
1978           <td>$form->{department_1}</td>
 
1979           <td><input name="shiptodepartment_1" size="35" value="$form->{shiptodepartment_1}"></td>
 
1982           <th align="right" nowrap> </th>
 
1983           <td>$form->{department_2}</td>
 
1984           <td><input name="shiptodepartment_2" size="35" value="$form->{shiptodepartment_2}"></td>
 
1987           <th align="right" nowrap>| . $locale->text('Street') . qq|</th>
 
1988           <td>$form->{street}</td>
 
1989           <td><input name="shiptostreet" size="35" value="$form->{shiptostreet}"></td>
 
1992           <th align="right" nowrap>| . $locale->text('Zipcode') . qq|</th>
 
1993           <td>$form->{zipcode}</td>
 
1994           <td><input name="shiptozipcode" size="35" value="$form->{shiptozipcode}"></td>
 
1997           <th align="right" nowrap>| . $locale->text('City') . qq|</th>
 
1998           <td>$form->{city}</td>
 
1999           <td><input name="shiptocity" size="35" value="$form->{shiptocity}"></td>
 
2002           <th align="right" nowrap>| . $locale->text('Country') . qq|</th>
 
2003           <td>$form->{country}</td>
 
2004           <td><input name="shiptocountry" size="35" value="$form->{shiptocountry}"></td>
 
2007           <th align="right" nowrap>| . $locale->text('Contact') . qq|</th>
 
2008           <td>$form->{contact}</td>
 
2009           <td><input name="shiptocontact" size="35" value="$form->{shiptocontact}"></td>
 
2012           <th align="right" nowrap>| . $locale->text('Phone') . qq|</th>
 
2013           <td>$form->{phone}</td>
 
2014           <td><input name="shiptophone" size="20" value="$form->{shiptophone}"></td>
 
2017           <th align="right" nowrap>| . $locale->text('Fax') . qq|</th>
 
2018           <td>$form->{fax}</td>
 
2019           <td><input name="shiptofax" size="20" value="$form->{shiptofax}"></td>
 
2022           <th align="right" nowrap>| . $locale->text('E-mail') . qq|</th>
 
2023           <td>$form->{email}</td>
 
2024           <td><input name="shiptoemail" size="35" value="$form->{shiptoemail}"></td>
 
2030 | . $cgi->hidden("-name" => "nextsub", "-value" => $nextsub);
 
2036   map({ delete $form->{$_} } (@shipto_vars, qw(header)));
 
2037   $form->{title} = $title;
 
2039   foreach $key (keys %$form) {
 
2040     $form->{$key} =~ s/\"/"/g;
 
2041     print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
 
2046 <hr size="3" noshade>
 
2049 <input class="submit" type="submit" name="action" value="|
 
2050     . $locale->text('Continue') . qq|">
 
2057   $lxdebug->leave_sub();
 
2061   $lxdebug->enter_sub();
 
2066   $form->{old_callback} = $form->escape($form->{callback}, 1);
 
2067   $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
 
2068   $form->{old_callback} = $form->escape($form->{old_callback}, 1);
 
2071   delete $form->{action};
 
2072   $customer = $form->{customer};
 
2073   map { $form->{"old_$_"} = $form->{"${_}_$row"} } qw(partnumber description);
 
2075   # save all other form variables in a previousform variable
 
2076   $form->{row} = $row;
 
2077   foreach $key (keys %$form) {
 
2080     $form->{$key} =~ s/&/%26/g;
 
2081     $previousform .= qq|$key=$form->{$key}&|;
 
2084   $previousform = $form->escape($previousform, 1);
 
2086   $form->{script} = "licenses.pl";
 
2088   map { $form->{$_} = $form->{"old_$_"} } qw(partnumber description);
 
2089   map { $form->{$_} = $form->escape($form->{$_}, 1) }
 
2090     qw(partnumber description);
 
2092     qq|$form->{script}?login=$form->{login}&password=$form->{password}&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|;
 
2095   $lxdebug->leave_sub();
 
2098 sub relink_accounts {
 
2099   $lxdebug->enter_sub();
 
2101   $form->{"taxaccounts"} =~ s/\s*$//;
 
2102   $form->{"taxaccounts"} =~ s/^\s*//;
 
2103   foreach my $accno (split(/\s*/, $form->{"taxaccounts"})) {
 
2104     map({ delete($form->{"${accno}_${_}"}); } qw(rate description taxnumber));
 
2106   $form->{"taxaccounts"} = "";
 
2108   for (my $i = 1; $i <= $form->{"rowcount"}; $i++) {
 
2109     if ($form->{"id_$i"}) {
 
2110       IC->retrieve_accounts(\%myconfig, $form, $form->{"id_$i"}, $i, 1);
 
2114   $lxdebug->leave_sub();
 
2118   $lxdebug->enter_sub();
 
2120   $form->get_duedate(\%myconfig);
 
2123   $result = "$form->{duedate}";
 
2126   $lxdebug->leave_sub();