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 "$form->{path}/common.pl";
 
  43 # any custom scripts for this one
 
  44 if (-f "$form->{path}/custom_io.pl") {
 
  45   eval { require "$form->{path}/custom_io.pl"; };
 
  47 if (-f "$form->{path}/$form->{login}_io.pl") {
 
  48   eval { require "$form->{path}/$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" : "";
 
 219       <input type="hidden" name="show_details" value="$form->{show_details}">
 
 220       <input type="checkbox" id="cb_show_details" onclick="show_form_details($show_details_new);" $show_details_checked>
 
 221       <label for="cb_show_details">| . $locale->text("Show details") . qq|</label><br>
 
 223         <tr class=listheading>|;
 
 225   map { print "\n$column_data{$_}" } @column_index;
 
 231   $runningnumber = $locale->text('No.');
 
 232   $deliverydate  = $locale->text('Delivery Date');
 
 233   $serialnumber  = $locale->text('Serial No.');
 
 234   $projectnumber = $locale->text('Project');
 
 235   $partsgroup    = $locale->text('Group');
 
 236   $reqdate       = $locale->text('Reqdate');
 
 238   $delvar = 'deliverydate';
 
 240   if ($form->{type} =~ /_order$/ || $form->{type} =~ /_quotation$/) {
 
 241     $deliverydate = $locale->text('Required by');
 
 245   for $i (1 .. $numrows) {
 
 250         $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
 
 251     } qw(qty ship discount sellprice price_new price_old) unless ($form->{simple_save});
 
 253     if (!$form->{"unit_old_$i"}) {
 
 254       # Neue Ware aus der Datenbank. In diesem Fall ist unit_$i die
 
 255       # Einheit, wie sie in den Stammdaten hinterlegt wurde.
 
 256       # Es sollte also angenommen werden, dass diese ausgewaehlt war.
 
 257       $form->{"unit_old_$i"} = $form->{"unit_$i"};
 
 262     # Die zuletzt ausgewaehlte mit der aktuell ausgewaehlten Einheit
 
 263     # vergleichen und bei Unterschied den Preis entsprechend umrechnen.
 
 264     $form->{"selected_unit_$i"} = $form->{"unit_$i"} unless ($form->{"selected_unit_$i"});
 
 266     my $check_units = $form->{"inventory_accno_$i"} ? $dimension_units : $service_units;
 
 267     if (!$check_units->{$form->{"selected_unit_$i"}} ||
 
 268         ($check_units->{$form->{"selected_unit_$i"}}->{"base_unit"} ne
 
 269          $all_units->{$form->{"unit_old_$i"}}->{"base_unit"})) {
 
 270       # Die ausgewaehlte Einheit ist fuer diesen Artikel nicht gueltig
 
 271       # (z.B. Dimensionseinheit war ausgewaehlt, es handelt sich aber
 
 272       # um eine Dienstleistung). Dann keinerlei Umrechnung vornehmen.
 
 273       $form->{"unit_old_$i"} = $form->{"selected_unit_$i"} = $form->{"unit_$i"};
 
 275     if ((!$form->{"prices_$i"}) || ($form->{"new_pricegroup_$i"} == $form->{"old_pricegroup_$i"})) {
 
 276       if ($form->{"unit_old_$i"} ne $form->{"selected_unit_$i"}) {
 
 278         if (defined($all_units->{$form->{"unit_old_$i"}}->{"factor"}) &&
 
 279             $all_units->{$form->{"unit_old_$i"}}->{"factor"}) {
 
 280           $basefactor = $all_units->{$form->{"selected_unit_$i"}}->{"factor"} /
 
 281             $all_units->{$form->{"unit_old_$i"}}->{"factor"};
 
 283         $form->{"sellprice_$i"} *= $basefactor;
 
 284         $form->{"unit_old_$i"} = $form->{"selected_unit_$i"};
 
 287     ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
 
 289     $decimalplaces = ($dec > 2) ? $dec : 2;
 
 293                         $form->{"sellprice_$i"} * $form->{"discount_$i"} / 100,
 
 297       $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
 
 298     $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
 
 300     # convert " to "
 
 301     map { $form->{"${_}_$i"} =~ s/\"/"/g }
 
 302       qw(partnumber description unit unit_old);
 
 304 ########################################
 
 305     # Eintrag fuer Version 2.2.0 geaendert #
 
 306     # neue Optik im Rechnungsformular      #
 
 307 ########################################
 
 308     $column_data{runningnumber} =
 
 309       qq|<td><input name="runningnumber_$i" size=5 value=$i></td>|;    # HuT
 
 310 ############## ENDE Neueintrag ##################
 
 312     $column_data{partnumber} =
 
 313       qq|<td><input name="partnumber_$i" size=12 value="$form->{"partnumber_$i"}"></td>|;
 
 315     if (($rows = $form->numtextrows($form->{"description_$i"}, 30, 6)) > 1) {
 
 316       $column_data{description} =
 
 317         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>|;
 
 319       $column_data{description} =
 
 320         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>|;
 
 323     (my $qty_dec) = ($form->{"qty_$i"} =~ /\.(\d+)/);
 
 324     $qty_dec = length $qty_dec;
 
 327         qq|<td align=right><input name="qty_$i" size=5 value=|
 
 328       . $form->format_amount(\%myconfig, $form->{"qty_$i"}, $qty_dec) .qq|>|;
 
 329     if ($form->{"formel_$i"}) {
 
 330     $column_data{qty} .= qq|<button type="button" onclick="calculate_qty_selection_window('qty_$i','alu_$i', 'formel_$i', $i)">| . $locale->text('*/') . qq|</button>
 
 331           <input type=hidden name="formel_$i" value="$form->{"formel_$i"}"><input type=hidden name="alu_$i" value="$form->{"alu_$i"}"></td>|;
 
 334         qq|<td align=right><input name="ship_$i" size=5 value=|
 
 335       . $form->format_amount(\%myconfig, $form->{"ship_$i"})
 
 338     my $is_part = $form->{"inventory_accno_$i"};
 
 339     my $is_assigned = $form->{"id_$i"};
 
 340     my $this_unit = $form->{"unit_$i"};
 
 341     if ($form->{"selected_unit_$i"} && $this_unit &&
 
 342         $all_units->{$form->{"selected_unit_$i"}} && $all_units->{$this_unit} &&
 
 343         ($all_units->{$form->{"selected_unit_$i"}}->{"base_unit"} eq $all_units->{$this_unit}->{"base_unit"})) {
 
 344       $this_unit = $form->{"selected_unit_$i"};
 
 345     } elsif (!$is_assigned ||
 
 346              ($is_part && !$this_unit && ($all_units->{$this_unit} && ($all_units->{$this_unit}->{"base_unit"} eq $all_units->{"kg"}->{"base_unit"})))) {
 
 350     $column_data{"unit"} = "<td>" .
 
 351       ($qty_readonly ? " " :
 
 352        AM->unit_select_html($is_part ? $dimension_units :
 
 353                             $is_assigned ? $service_units : $all_units,
 
 354                             "unit_$i", $this_unit,
 
 355                             $is_assigned ? $form->{"unit_$i"} : undef))
 
 358     # build in drop down list for pricesgroups
 
 359     if ($form->{"prices_$i"}) {
 
 360       if  ($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"}) {
 
 361         $price_tmp = $form->format_amount(\%myconfig, $form->{"price_new_$i"}, $decimalplaces);
 
 363         $price_tmp = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
 
 366       $column_data{sellprice_pg} =
 
 367         qq|<td align=right><select name="sellprice_pg_$i">$form->{"prices_$i"}</select></td>|;
 
 368       $column_data{sellprice} =
 
 369         qq|<td><input name="sellprice_$i" size=10 value=$price_tmp></td>|;
 
 372       # for last row and report
 
 373       # set pricegroup drop down list from report menu
 
 374       if ($form->{"sellprice_$i"} != 0) {
 
 376           qq|<option value="$form->{"sellprice_$i"}--$form->{"pricegroup_id_$i"}" selected>$form->{"pricegroup_$i"}</option>\n|;
 
 378         $form->{"pricegroup_old_$i"} = $form->{"pricegroup_id_$i"};
 
 380         $column_data{sellprice_pg} =
 
 381           qq|<td align=right><select name="sellprice_pg_$i">$prices</select></td>|;
 
 386         $column_data{sellprice_pg} = qq|<td align=right> </td>|;
 
 389       $column_data{sellprice} =
 
 390         qq|<td><input name="sellprice_$i" size=10 value=|
 
 391         . $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
 
 395     $column_data{discount} =
 
 396         qq|<td align=right><input name="discount_$i" size=3 value=|
 
 397       . $form->format_amount(\%myconfig, $form->{"discount_$i"})
 
 399     $column_data{linetotal} =
 
 401       . $form->format_amount(\%myconfig, $linetotal, 2)
 
 403     $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
 
 405 ########################################
 
 406     # Eintrag fuer Version 2.2.0 geaendert #
 
 407     # neue Optik im Rechnungsformular      #
 
 408 ########################################
 
 409     #     if ($lizenzen &&  $form->{type} eq "invoice" &&  $form->{vc} eq "customer") {
 
 410     #     $column_data{license} = qq|<td><select name="licensenumber_$i">$form->{"lizenzen_$i"}></select></td>|;
 
 413     #     if ($form->{type} !~ /_quotation/) {
 
 414     #     $column_data{serialnr} = qq|<td><input name="serialnumber_$i" size=10 value="$form->{"serialnumber_$i"}"></td>|;
 
 417     #     $column_data{projectnr} = qq|<td><input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}"></td>|;
 
 418 ############## ENDE Neueintrag ##################
 
 422         <tr valign=top class=listrow$j>|;
 
 424     map { print "\n$column_data{$_}" } @column_index;
 
 429 <input type=hidden name="orderitems_id_$i" value=$form->{"orderitems_id_$i"}>
 
 430 <input type=hidden name="bo_$i" value=$form->{"bo_$i"}>
 
 432 <input type=hidden name="pricegroup_old_$i" value=$form->{"pricegroup_old_$i"}>
 
 433 <input type=hidden name="price_old_$i" value=$form->{"price_old_$i"}>
 
 434 <input type=hidden name="unit_old_$i" value="| . $form->quote($form->{"selected_unit_$i"}) . qq|">
 
 435 <input type=hidden name="price_new_$i" value=|
 
 436       . $form->format_amount(\%myconfig, $form->{"price_new_$i"}) . qq|>
 
 438 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
 
 439 <input type=hidden name="inventory_accno_$i" value=$form->{"inventory_accno_$i"}>
 
 440 <input type=hidden name="bin_$i" value="$form->{"bin_$i"}">
 
 441 <input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">
 
 442 <input type=hidden name="partnotes_$i" value="| . $form->quote($form->{"partnotes_$i"}) . qq|">
 
 443 <input type=hidden name="income_accno_$i" value=$form->{"income_accno_$i"}>
 
 444 <input type=hidden name="expense_accno_$i" value=$form->{"expense_accno_$i"}>
 
 445 <input type=hidden name="listprice_$i" value="$form->{"listprice_$i"}">
 
 446 <input type=hidden name="assembly_$i" value="$form->{"assembly_$i"}">
 
 447 <input type=hidden name="taxaccounts_$i" value="$form->{"taxaccounts_$i"}">
 
 448 <input type=hidden name="ordnumber_$i" value="$form->{"ordnumber_$i"}">
 
 449 <input type=hidden name="transdate_$i" value="$form->{"transdate_$i"}">
 
 450 <input type=hidden name="cusordnumber_$i" value="$form->{"cusordnumber_$i"}">
 
 451 <input type=hidden name="longdescription_$i" value="| . $form->quote($form->{"longdescription_$i"}) . qq|">
 
 452 <input type=hidden name="basefactor_$i" value="$form->{"basefactor_$i"}">
 
 456 ########################################
 
 457     # Eintrag fuer Version 2.2.0 geaendert #
 
 458     # neue Optik im Rechnungsformular      #
 
 459 ########################################
 
 462       'style="display:none;"' if (!$form->{"show_details"});
 
 466         <tr  class=listrow$j $row_style_attr>
 
 467           <td colspan=$colspan>
 
 469     if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
 
 470       my $selected = $form->{"licensenumber_$i"};
 
 472       $form->{"lizenzen_$i"} =~ s/ selected//g;
 
 473       $form->{"lizenzen_$i"} =~
 
 474         s/value="${selected}"\>/value="${selected}" selected\>/;
 
 475       $lizenzen_quoted = $form->{"lizenzen_$i"};
 
 476       $lizenzen_quoted =~ s/\"/"/g;
 
 478         <b>Lizenz\#</b> <select name="licensenumber_$i" size=1>
 
 479         $form->{"lizenzen_$i"}
 
 481         <input type=hidden name="lizenzen_$i" value="${lizenzen_quoted}">
 
 484     if ($form->{type} !~ /_quotation/) {
 
 486           <b>$serialnumber</b> <input name="serialnumber_$i" size=15 value="$form->{"serialnumber_$i"}">|;
 
 490           <b>$projectnumber</b> <input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}">
 
 491                   <input type=hidden name="oldprojectnumber_$i" value="$form->{"projectnumber_$i"}">
 
 492                   <input type=hidden name="project_id_$i" value="$form->{"project_id_$i"}">
 
 494     if ($form->{type} eq 'invoice' or $form->{type} =~ /order/) {
 
 496         ($form->{type} eq 'invoice')
 
 498         : 'reqdate';    # invoice uses a different term for the same thing.
 
 500         <b>${$reqdate_term}</b> <input name="${reqdate_term}_$i" size=11 value="$form->{"${reqdate_term}_$i"}">
 
 503     my $subtotalchecked = ($form->{"subtotal_$i"}) ? "checked" : "";
 
 505           <b>|.$locale->text('Subtotal').qq|</b> <input type="checkbox" name="subtotal_$i" value="1" "$subtotalchecked">
 
 511 ############## ENDE Neueintrag ##################
 
 513     map { $form->{"${_}_base"} += $linetotal }
 
 514       (split / /, $form->{"taxaccounts_$i"});
 
 516     $form->{invsubtotal} += $linetotal;
 
 525   $lxdebug->leave_sub();
 
 528 ##################################################
 
 529 # build html-code for pricegroups in variable $form->{prices_$j}
 
 532   $lxdebug->enter_sub();
 
 533   my $rowcount = shift;
 
 534   for $j (1 .. $rowcount) {
 
 535     my $pricegroup_old = $form->{"pricegroup_old_$i"};
 
 536     if ($form->{PRICES}{$j}) {
 
 538       $prices = '<option value="--">' . $locale->text("none (pricegroup)") . '</option>';
 
 540       foreach $item (@{ $form->{PRICES}{$j} }) {
 
 542         #$price = $form->round_amount($myconfig,  $item->{price}, 5);
 
 543         #$price = $form->format_amount($myconfig, $item->{price}, 2);
 
 544         $price         = $item->{price};
 
 545         $pricegroup_id = $item->{pricegroup_id};
 
 546         $pricegroup    = $item->{pricegroup};
 
 548         # build drop down list for pricegroups
 
 550           qq|<option value="$price--$pricegroup_id"$item->{selected}>$pricegroup</option>\n|;
 
 555         #               $form->{"${_}_$j"} =
 
 556         #               $form->format_amount(\%myconfig, $form->{"${_}_$j"})
 
 557         #              } qw(sellprice price_new price_old);
 
 559         # set new selectedpricegroup_id and prices for "Preis"
 
 560         if ($item->{selected} && ($pricegroup_id != 0)) {
 
 561           $form->{"pricegroup_old_$j"} = $pricegroup_id;
 
 562           $form->{"price_new_$j"}      = $price;
 
 563           $form->{"sellprice_$j"}      = $price;
 
 565         if ($pricegroup_id == 0) {
 
 566           $form->{"price_new_$j"} = $form->{"sellprice_$j"};
 
 569       $form->{"prices_$j"} = $prices;
 
 572   $lxdebug->leave_sub();
 
 576   $lxdebug->enter_sub();
 
 577   @column_index = qw(ndx partnumber description onhand unit sellprice);
 
 579   $column_data{ndx}        = qq|<th> </th>|;
 
 580   $column_data{partnumber} =
 
 581     qq|<th class=listheading>| . $locale->text('Number') . qq|</th>|;
 
 582   $column_data{description} =
 
 583     qq|<th class=listheading>| . $locale->text('Part Description') . qq|</th>|;
 
 584   $column_data{sellprice} =
 
 585     qq|<th class=listheading>| . $locale->text('Price') . qq|</th>|;
 
 586   $column_data{onhand} =
 
 587     qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
 
 589     qq|<th class=listheading>| . $locale->text('Unit') . qq|</th>|;
 
 590   # list items with radio button on a form
 
 593   $title   = $locale->text('Select from one of the items below');
 
 594   $colspan = $#column_index + 1;
 
 599 <form method=post action=$form->{script}>
 
 603     <th class=listtop colspan=$colspan>$title</th>
 
 606   <tr class=listheading>|;
 
 608   map { print "\n$column_data{$_}" } @column_index;
 
 613   foreach $ref (@{ $form->{item_list} }) {
 
 614     $checked = ($i++) ? "" : "checked";
 
 617       if ($ref->{inventory_accno} > 0) {
 
 618         $ref->{"lizenzen"} = qq|<option></option>|;
 
 619         foreach $item (@{ $form->{LIZENZEN}{ $ref->{"id"} } }) {
 
 620           $ref->{"lizenzen"} .=
 
 621             qq|<option value=\"$item->{"id"}\">$item->{"licensenumber"}</option>|;
 
 623         $ref->{"lizenzen"} .= qq|<option value=-1>Neue Lizenz</option>|;
 
 624         $ref->{"lizenzen"} =~ s/\"/"/g;
 
 628     map { $ref->{$_} =~ s/\"/"/g } qw(partnumber description unit);
 
 632       $form->round_amount($ref->{sellprice} * (1 - $form->{tradediscount}), 2);
 
 634       qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
 
 635     $column_data{partnumber} =
 
 636       qq|<td><input name="new_partnumber_$i" type=hidden value="$ref->{partnumber}">$ref->{partnumber}</td>|;
 
 637     $column_data{description} =
 
 638       qq|<td><input name="new_description_$i" type=hidden value="$ref->{description}">$ref->{description}</td>|;
 
 639     $column_data{sellprice} =
 
 640       qq|<td align=right><input name="new_sellprice_$i" type=hidden value=$ref->{sellprice}>|
 
 641       . $form->format_amount(\%myconfig, $ref->{sellprice}, 2, " ")
 
 643     $column_data{onhand} =
 
 644       qq|<td align=right><input name="new_onhand_$i" type=hidden value=$ref->{onhand}>|
 
 645       . $form->format_amount(\%myconfig, $ref->{onhand}, '', " ")
 
 648       qq|<td>$ref->{unit}</td>|;
 
 652 <tr class=listrow$j>|;
 
 654     map { print "\n$column_data{$_}" } @column_index;
 
 659 <input name="new_bin_$i" type=hidden value="$ref->{bin}">
 
 660 <input name="new_listprice_$i" type=hidden value=$ref->{listprice}>
 
 661 <input name="new_inventory_accno_$i" type=hidden value=$ref->{inventory_accno}>
 
 662 <input name="new_income_accno_$i" type=hidden value=$ref->{income_accno}>
 
 663 <input name="new_expense_accno_$i" type=hidden value=$ref->{expense_accno}>
 
 664 <input name="new_unit_$i" type=hidden value="$ref->{unit}">
 
 665 <input name="new_weight_$i" type=hidden value="$ref->{weight}">
 
 666 <input name="new_assembly_$i" type=hidden value="$ref->{assembly}">
 
 667 <input name="new_taxaccounts_$i" type=hidden value="$ref->{taxaccounts}">
 
 668 <input name="new_partsgroup_$i" type=hidden value="$ref->{partsgroup}">
 
 669 <input name="new_formel_$i" type=hidden value="$ref->{formel}">
 
 670 <input name="new_longdescription_$i" type=hidden value="| . Q($ref->{longdescription}) . qq|">
 
 671 <input name="new_not_discountable_$i" type=hidden value="$ref->{not_discountable}">
 
 672 <input name="new_part_payment_id_$i" type=hidden value="$ref->{part_payment_id}">
 
 673 <input name="new_partnotes_$i" type="hidden" value="| . Q($ref->{"partnotes"}) . qq|">
 
 675 <input name="new_id_$i" type=hidden value=$ref->{id}>
 
 680 <input name="new_lizenzen_$i" type=hidden value="$ref->{lizenzen}">
 
 687 <tr><td colspan=8><hr size=3 noshade></td></tr>
 
 690 <input name=lastndx type=hidden value=$i>
 
 694   # delete action variable
 
 695   map { delete $form->{$_} } qw(action item_list header);
 
 697   # save all other form variables
 
 698   foreach $key (keys %${form}) {
 
 699     $form->{$key} =~ s/\"/"/g;
 
 700     print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
 
 704 <input type=hidden name=nextsub value=item_selected>
 
 707 <input class=submit type=submit name=action value="|
 
 708     . $locale->text('Continue') . qq|">
 
 715   $lxdebug->leave_sub();
 
 719   $lxdebug->enter_sub();
 
 721   # replace the last row with the checked row
 
 722   $i = $form->{rowcount};
 
 723   $i = $form->{assembly_rows} if ($form->{item} eq 'assembly');
 
 729   #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
 
 730   #$form->{"sellprice_$i"} = $form->{"sellprice_$i"};
 
 732   # if there was a price entered, override it
 
 733   $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
 
 735   map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} }
 
 736     qw(id partnumber description sellprice listprice inventory_accno
 
 737        income_accno expense_accno bin unit weight assembly taxaccounts
 
 738        partsgroup formel longdescription not_discountable partnotes);
 
 739   if ($form->{"part_payment_id_$i"} ne "") {
 
 740     $form->{payment_id} = $form->{"part_payment_id_$i"};
 
 744     map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } qw(lizenzen);
 
 747   ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
 
 749   $decimalplaces = ($dec > 2) ? $dec : 2;
 
 752     $form->{"sellprice_$i"} = $sellprice;
 
 755     # if there is an exchange rate adjust sellprice
 
 756     if (($form->{exchangerate} * 1) != 0) {
 
 757       $form->{"sellprice_$i"} /= $form->{exchangerate};
 
 758       $form->{"sellprice_$i"} =
 
 759         $form->round_amount($form->{"sellprice_$i"}, $decimalplaces);
 
 763   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
 764     qw(sellprice listprice weight);
 
 766   $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
 
 767   $form->{weight}    += ($form->{"weight_$i"} * $form->{"qty_$i"});
 
 769   if ($form->{"not_discountable_$i"}) {
 
 770     $form->{"discount_$i"} = 0;
 
 774     $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) *
 
 776   map { $form->{"${_}_base"} += $amount }
 
 777     (split / /, $form->{"taxaccounts_$i"});
 
 778   map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /,
 
 779     $form->{"taxaccounts_$i"}
 
 780     if !$form->{taxincluded};
 
 782   $form->{creditremaining} -= $amount;
 
 784   $form->{"runningnumber_$i"} = $i;
 
 786   # delete all the new_ variables
 
 787   for $i (1 .. $form->{lastndx}) {
 
 788     map { delete $form->{"new_${_}_$i"} }
 
 789       qw(partnumber description sellprice bin listprice inventory_accno income_accno expense_accno unit assembly taxaccounts id);
 
 792   map { delete $form->{$_} } qw(ndx lastndx nextsub);
 
 797       $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces)
 
 798   } qw(sellprice listprice) if $form->{item} ne 'assembly';
 
 800   # get pricegroups for parts
 
 801   IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
 803   # build up html code for prices_$i
 
 804   set_pricegroup($form->{rowcount});
 
 808   $lxdebug->leave_sub();
 
 812   $lxdebug->enter_sub();
 
 815   $form->{old_callback} = $form->escape($form->{callback}, 1);
 
 816   $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
 
 819   delete $form->{action};
 
 821   # save all other form variables in a previousform variable
 
 822   foreach $key (keys %$form) {
 
 825     $form->{$key} =~ s/&/%26/g;
 
 826     $previousform .= qq|$key=$form->{$key}&|;
 
 829   $previousform = $form->escape($previousform, 1);
 
 831   $i = $form->{rowcount};
 
 832   map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description);
 
 839 <h4 class=error>| . $locale->text('Item not on file!') . qq|
 
 842 | . $locale->text('What type of item is this?') . qq|</h4>
 
 844 <form method=post action=ic.pl>
 
 848   <input class=radio type=radio name=item value=part checked> |
 
 849     . $locale->text('Part') . qq|<br>
 
 850   <input class=radio type=radio name=item value=service> |
 
 851     . $locale->text('Service')
 
 854 <input type=hidden name=previousform value="$previousform">
 
 855 <input type=hidden name=partnumber value="$form->{"partnumber_$i"}">
 
 856 <input type=hidden name=description value="$form->{"description_$i"}">
 
 857 <input type=hidden name=rowcount value=$form->{rowcount}>
 
 858 <input type=hidden name=taxaccount2 value=$form->{taxaccounts}>
 
 859 <input type=hidden name=vc value=$form->{vc}>
 
 861 <input type=hidden name=path value=$form->{path}>
 
 862 <input type=hidden name=login value=$form->{login}>
 
 863 <input type=hidden name=password value=$form->{password}>
 
 865 <input type=hidden name=nextsub value=add>
 
 868 <input class=submit type=submit name=action value="|
 
 869     . $locale->text('Continue') . qq|">
 
 876   $lxdebug->leave_sub();
 
 880   $lxdebug->enter_sub();
 
 884   $form->language_payment(\%myconfig);
 
 886   # if we have a display_form
 
 887   if ($form->{display_form}) {
 
 888     &{"$form->{display_form}"};
 
 892   Common::webdav_folder($form) if ($webdav);
 
 894   #   if (   $form->{print_and_post}
 
 895   #       && $form->{second_run}
 
 896   #       && ($form->{action} eq "display_form")) {
 
 897   #     for (keys %$form) { $old_form->{$_} = $form->{$_} }
 
 898   #     $old_form->{rowcount}++;
 
 900   #     #$form->{rowcount}--;
 
 901   #     #$form->{rowcount}--;
 
 903   #     $form->{print_and_post} = 0;
 
 905   #     &print_form($old_form);
 
 909   #   $form->{action}   = "";
 
 910   #   $form->{resubmit} = 0;
 
 912   #   if ($form->{print_and_post} && !$form->{second_run}) {
 
 913   #     $form->{second_run} = 1;
 
 914   #     $form->{action}     = "display_form";
 
 915   #     $form->{rowcount}--;
 
 916   #     my $rowcount = $form->{rowcount};
 
 918   #     # get pricegroups for parts
 
 919   #     IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
 921   #     # build up html code for prices_$i
 
 922   #     set_pricegroup($rowcount);
 
 924   #     $form->{resubmit} = 1;
 
 929   $numrows    = ++$form->{rowcount};
 
 930   $subroutine = "display_row";
 
 932   if ($form->{item} eq 'part') {
 
 934     #set preisgruppenanzahl
 
 935     $numrows    = $form->{price_rows};
 
 936     $subroutine = "price_row";
 
 938     &{$subroutine}($numrows);
 
 940     $numrows    = ++$form->{makemodel_rows};
 
 941     $subroutine = "makemodel_row";
 
 943   if ($form->{item} eq 'assembly') {
 
 944     $numrows    = $form->{price_rows};
 
 945     $subroutine = "price_row";
 
 947     &{$subroutine}($numrows);
 
 949     $numrows    = ++$form->{makemodel_rows};
 
 950     $subroutine = "makemodel_row";
 
 952     # create makemodel rows
 
 953     &{$subroutine}($numrows);
 
 955     $numrows    = ++$form->{assembly_rows};
 
 956     $subroutine = "assembly_row";
 
 958   if ($form->{item} eq 'service') {
 
 959     $numrows    = $form->{price_rows};
 
 960     $subroutine = "price_row";
 
 962     &{$subroutine}($numrows);
 
 968   &{$subroutine}($numrows) if $numrows;
 
 972   $lxdebug->leave_sub();
 
 976   $lxdebug->enter_sub();
 
 980     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)
 
 984   # remove any makes or model rows
 
 985   if ($form->{item} eq 'part') {
 
 986     map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
 987       qw(listprice sellprice lastcost weight rop);
 
 989     @flds = (make, model);
 
 990     for my $i (1 .. ($form->{makemodel_rows})) {
 
 991       if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
 
 995         map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
 
1000     $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
 
1001     $form->{makemodel_rows} = $count;
 
1003   } elsif ($form->{item} eq 'assembly') {
 
1005     $form->{sellprice} = 0;
 
1006     $form->{weight}    = 0;
 
1007     map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
1008       qw(listprice rop stock);
 
1011       qw(id qty unit bom partnumber description sellprice weight runningnumber partsgroup);
 
1013     for my $i (1 .. ($form->{assembly_rows} - 1)) {
 
1014       if ($form->{"qty_$i"}) {
 
1018         $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
 
1020         map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
 
1022         #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
 
1024         $form->{sellprice} += ($form->{"qty_$i"} * $form->{"sellprice_$i"});
 
1025         $form->{weight}    += ($form->{"qty_$i"} * $form->{"weight_$i"});
 
1030     $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
 
1032     $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
 
1033     $form->{assembly_rows} = $count;
 
1036     @flds  = qw(make model);
 
1039     for my $i (1 .. ($form->{makemodel_rows})) {
 
1040       if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
 
1044         map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
 
1049     $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
 
1050     $form->{makemodel_rows} = $count;
 
1054     # this section applies to invoices and orders
 
1055     # remove any empty numbers
 
1056     if ($form->{rowcount}) {
 
1057       for my $i (1 .. $form->{rowcount} - 1) {
 
1058         if ($form->{"partnumber_$i"}) {
 
1062           map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
 
1065             if ($form->{"licensenumber_$i"} == -1) {
 
1073       $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
 
1074       $form->{rowcount} = $count;
 
1076       $form->{creditremaining} -= &invoicetotal;
 
1083   if (   $form->{type} =~ (/sales_quotation/)
 
1084       or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/))
 
1085       or (($form->{level} eq undef) and ($form->{type} =~ /invoice/))
 
1086       or ($form->{type} =~ /sales_order/)) {
 
1088     # get pricegroups for parts
 
1089     IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
1091     # build up html code for prices_$i
 
1092     set_pricegroup($form->{rowcount});
 
1098   $lxdebug->leave_sub();
 
1102   $lxdebug->enter_sub();
 
1104   $form->{oldinvtotal} = 0;
 
1106   # add all parts and deduct paid
 
1107   map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
 
1109   my ($amount, $sellprice, $discount, $qty);
 
1111   for my $i (1 .. $form->{rowcount}) {
 
1112     $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
 
1113     $discount  = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
 
1114     $qty       = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
 
1116     #($form->{"sellprice_$i"}, $form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
 
1118     $amount = $sellprice * (1 - $discount / 100) * $qty;
 
1119     map { $form->{"${_}_base"} += $amount }
 
1120       (split / /, $form->{"taxaccounts_$i"});
 
1121     $form->{oldinvtotal} += $amount;
 
1124   map { $form->{oldinvtotal} += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
 
1125     split / /, $form->{taxaccounts}
 
1126     if !$form->{taxincluded};
 
1128   $form->{oldtotalpaid} = 0;
 
1129   for $i (1 .. $form->{paidaccounts}) {
 
1130     $form->{oldtotalpaid} += $form->{"paid_$i"};
 
1133   $lxdebug->leave_sub();
 
1136   return ($form->{oldinvtotal} - $form->{oldtotalpaid});
 
1139 sub validate_items {
 
1140   $lxdebug->enter_sub();
 
1142   # check if items are valid
 
1143   if ($form->{rowcount} == 1) {
 
1148   for $i (1 .. $form->{rowcount} - 1) {
 
1149     $form->isblank("partnumber_$i",
 
1150                    $locale->text('Number missing in Row') . " $i");
 
1153   $lxdebug->leave_sub();
 
1157   $lxdebug->enter_sub();
 
1158   if ($form->{second_run}) {
 
1159     $form->{print_and_post} = 0;
 
1161   $form->{ordnumber} = $form->{invnumber};
 
1163   map { delete $form->{$_} } qw(id printed emailed queued);
 
1164   if ($form->{script} eq 'ir.pl' || $form->{type} eq 'request_quotation') {
 
1165     $form->{title} = $locale->text('Add Purchase Order');
 
1166     $form->{vc}    = 'vendor';
 
1167     $form->{type}  = 'purchase_order';
 
1170   if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_quotation') {
 
1171     $form->{title} = $locale->text('Add Sales Order');
 
1172     $form->{vc}    = 'customer';
 
1173     $form->{type}  = 'sales_order';
 
1176   $form->{script} = 'oe.pl';
 
1178   $form->{shipto} = 1;
 
1180   $form->{rowcount}--;
 
1182   $form->{cp_id} *= 1;
 
1184   require "$form->{path}/$form->{script}";
 
1185   my $script = $form->{"script"};
 
1187   $script =~ s|.pl$||;
 
1188   $locale = new Locale($language, $script);
 
1190   map { $form->{"select$_"} = "" } ($form->{vc}, currency);
 
1192   $currency = $form->{currency};
 
1196   $form->{currency}     = $currency;
 
1197   $form->{exchangerate} = "";
 
1198   $form->{forex}        = "";
 
1199   $form->{exchangerate} = $exchangerate
 
1203                     $form->check_exchangerate(
 
1204                     \%myconfig, $form->{currency}, $form->{transdate}, $buysell
 
1207   for $i (1 .. $form->{rowcount}) {
 
1208     map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
 
1209                                                      $form->{"${_}_${i}"})
 
1210             if ($form->{"${_}_${i}"}) }
 
1211         qw(ship qty sellprice listprice basefactor));
 
1217   $lxdebug->leave_sub();
 
1221   $lxdebug->enter_sub();
 
1222   if ($form->{second_run}) {
 
1223     $form->{print_and_post} = 0;
 
1225   map { delete $form->{$_} } qw(id printed emailed queued);
 
1227   if ($form->{script} eq 'ir.pl' || $form->{type} eq 'purchase_order') {
 
1228     $form->{title} = $locale->text('Add Request for Quotation');
 
1229     $form->{vc}    = 'vendor';
 
1230     $form->{type}  = 'request_quotation';
 
1233   if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_order') {
 
1234     $form->{title} = $locale->text('Add Quotation');
 
1235     $form->{vc}    = 'customer';
 
1236     $form->{type}  = 'sales_quotation';
 
1240   $form->{cp_id} *= 1;
 
1242   $form->{script} = 'oe.pl';
 
1244   $form->{shipto} = 1;
 
1246   $form->{rowcount}--;
 
1248   require "$form->{path}/$form->{script}";
 
1250   map { $form->{"select$_"} = "" } ($form->{vc}, currency);
 
1252   $currency = $form->{currency};
 
1256   $form->{currency}     = $currency;
 
1257   $form->{exchangerate} = "";
 
1258   $form->{forex}        = "";
 
1259   $form->{exchangerate} = $exchangerate
 
1263                     $form->check_exchangerate(
 
1264                     \%myconfig, $form->{currency}, $form->{transdate}, $buysell
 
1267   for $i (1 .. $form->{rowcount}) {
 
1268     map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
 
1269                                                      $form->{"${_}_${i}"})
 
1270             if ($form->{"${_}_${i}"}) }
 
1271         qw(ship qty sellprice listprice basefactor));
 
1277   $lxdebug->leave_sub();
 
1280 sub request_for_quotation {
 
1285   $lxdebug->enter_sub();
 
1286   if ($form->{second_run}) {
 
1287     $form->{print_and_post} = 0;
 
1288     $form->{resubmit}       = 0;
 
1290   if ($myconfig{role} eq 'admin') {
 
1293       <th align="right" nowrap="true">| . $locale->text('Bcc') . qq|</th>
 
1294       <td><input name="bcc" size="30" value="| . Q($form->{bcc}) . qq|"></td>
 
1299   if ($form->{formname} =~ /(pick|packing|bin)_list/) {
 
1300     $form->{email} = $form->{shiptoemail} if $form->{shiptoemail};
 
1303   if ($form->{"cp_id"} && !$form->{"email"}) {
 
1304     CT->get_contact(\%myconfig, $form);
 
1305     $form->{"email"} = $form->{"cp_email"};
 
1308   $name = $form->{ $form->{vc} };
 
1310   $title = $locale->text('E-mail') . " $name";
 
1312   $form->{oldmedia} = $form->{media};
 
1313   $form->{media}    = "email";
 
1315   my %formname_translations =
 
1317      "bin_list" => $locale->text('Bin List'),
 
1318      "credit_note" => $locale->text('Credit Note'),
 
1319      "invoice" => $locale->text('Invoice'),
 
1320      "packing_list" => $locale->text('Packing List'),
 
1321      "pick_list" => $locale->text('Pick List'),
 
1322      "proforma" => $locale->text('Proforma Invoice'),
 
1323      "purchase_order" => $locale->text('Purchase Order'),
 
1324      "request_quotation" => $locale->text('RFQ'),
 
1325      "sales_order" => $locale->text('Confirmation'),
 
1326      "sales_quotation" => $locale->text('Quotation'),
 
1327      "storno_invoice" => $locale->text('Storno Invoice'),
 
1328      "storno_packing_list" => $locale->text('Storno Packing List'),
 
1331   my $attachment_filename = $formname_translations{$form->{"formname"}};
 
1334   if (grep({ $form->{"type"} eq $_ } qw(invoice credit_note))) {
 
1336   } elsif ($form->{"type"} =~ /_quotation$/) {
 
1342   if ($attachment_filename && $form->{"${prefix}number"}) {
 
1343     $attachment_filename .= "_" . $form->{"${prefix}number"} .
 
1344       ($form->{"format"} =~ /pdf/i ? ".pdf" :
 
1345        $form->{"format"} =~ /postscript/i ? ".ps" :
 
1346        $form->{"format"} =~ /opendocument/i ? ".odt" :
 
1347        $form->{"format"} =~ /html/i ? ".html" : "");
 
1348     $attachment_filename =~ s/ /_/g;
 
1351        "ä" => "ae", "ö" => "oe", "ü" => "ue",
 
1352        "Ä" => "Ae", "Ö" => "Oe", "Ü" => "Ue",
 
1355     map({ $attachment_filename =~ s/$_/$umlaute{$_}/g; } keys(%umlaute));
 
1357     $attachment_filename = "";
 
1360   if ($form->{"email"}) {
 
1361     $form->{"fokus"} = "Form.subject";
 
1363     $form->{"fokus"} = "Form.email";
 
1368 <body onload="fokus()">
 
1370 <form name="Form" method="post" action="$form->{script}">
 
1372 <table width="100%">
 
1373   <tr class="listtop">
 
1374     <th class="listtop">$title</th>
 
1376   <tr height="5"></tr>
 
1381           <th align="right" nowrap>| . $locale->text('To') . qq|</th>
 
1382           <td><input name="email" size="30" value="| .
 
1383           Q($form->{"email"}) . qq|"></td>
 
1386           <th align="right" nowrap>| . $locale->text('Cc') . qq|</th>
 
1387           <td><input name="cc" size="30" value="| .
 
1388           Q($form->{"cc"}) . qq|"></td>
 
1392           <th align="right" nowrap>| . $locale->text('Subject') . qq|</th>
 
1393           <td><input name="subject" size="30" value="| .
 
1394           Q($form->{"subject"}) . qq|"></td>
 
1397           <th align="right" nowrap>| . $locale->text('Attachment name') .
 
1399           <td><input name="attachment_filename" size="30" value="| .
 
1400           Q($attachment_filename) . qq|"></td>
 
1408           <th align="left" nowrap>| . $locale->text('Message') . qq|</th>
 
1411           <td><textarea name="message" rows="15" cols="60" wrap="soft">| .
 
1412           H($form->{"message"}) . qq|</textarea></td>
 
1423   map { delete $form->{$_} }
 
1424     qw(action email cc bcc subject message formname sendmode format header override);
 
1426   # save all other variables
 
1427   foreach $key (keys %$form) {
 
1428     $form->{$key} =~ s/\"/"/g;
 
1429     print qq|<input type="hidden" name="$key" value="| . Q($form->{$key}) . qq|">\n|;
 
1436     <td><hr size="3" noshade></td>
 
1440 <input type="hidden" name="nextsub" value="send_email">
 
1443 <input name="action" class="submit" type="submit" value="|
 
1444     . $locale->text('Continue') . qq|">
 
1451   $lxdebug->leave_sub();
 
1455   $lxdebug->enter_sub();
 
1457   $old_form = new Form;
 
1459   map { $old_form->{$_} = $form->{$_} } keys %$form;
 
1460   $old_form->{media} = $form->{oldmedia};
 
1462   &print_form($old_form);
 
1464   $lxdebug->leave_sub();
 
1468   $lxdebug->enter_sub();
 
1469   $form->{sendmode} = "attachment";
 
1472     $form->{"format"} ? $form->{"format"} :
 
1473     $myconfig{"template_format"} ? $myconfig{"template_format"} :
 
1477     $form->{"copies"} ? $form->{"copies"} :
 
1478     $myconfig{"copies"} ? $myconfig{"copies"} :
 
1482     $form->{"media"} ? $form->{"media"} :
 
1483     $myconfig{"default_media"} ? $myconfig{"default_media"} :
 
1486   $form->{"printer_id"} =
 
1487     defined($form->{"printer_id"}) ? $form->{"printer_id"} :
 
1488     $myconfig{"default_printer_id"} ? $myconfig{"default_printer_id"} :
 
1491   $form->{PD}{ $form->{formname} } = "selected";
 
1492   $form->{DF}{ $form->{format} }   = "selected";
 
1493   $form->{OP}{ $form->{media} }    = "selected";
 
1494   $form->{SM}{ $form->{sendmode} } = "selected";
 
1496   if ($form->{type} eq 'purchase_order') {
 
1497     $type = qq|<select name=formname>
 
1498             <option value=purchase_order $form->{PD}{purchase_order}>|
 
1499       . $locale->text('Purchase Order') . qq|
 
1500             <option value=bin_list $form->{PD}{bin_list}>|
 
1501       . $locale->text('Bin List');
 
1504   if ($form->{type} eq 'credit_note') {
 
1505     $type = qq|<select name=formname>
 
1506             <option value=credit_note $form->{PD}{credit_note}>|
 
1507       . $locale->text('Credit Note');
 
1510   if ($form->{type} eq 'sales_order') {
 
1511     $type = qq|<select name=formname>
 
1512             <option value=sales_order $form->{PD}{sales_order}>|
 
1513       . $locale->text('Confirmation') . qq|
 
1514       <option value=proforma $form->{PD}{proforma}>|
 
1515       . $locale->text('Proforma Invoice') . qq|
 
1516             <option value=pick_list $form->{PD}{pick_list}>|
 
1517       . $locale->text('Pick List') . qq|
 
1518             <option value=packing_list $form->{PD}{packing_list}>|
 
1519       . $locale->text('Packing List');
 
1522   if ($form->{type} =~ /_quotation$/) {
 
1523     $type = qq|<select name=formname>
 
1524             <option value="$`_quotation" $form->{PD}{"$`_quotation"}>|
 
1525       . $locale->text('Quotation');
 
1528   if ($form->{type} eq 'invoice') {
 
1529     $type = qq|<select name=formname>
 
1530             <option value=invoice $form->{PD}{invoice}>|
 
1531       . $locale->text('Invoice') . qq|
 
1532       <option value=proforma $form->{PD}{proforma}>|
 
1533       . $locale->text('Proforma Invoice') . qq|
 
1534       <option value=packing_list $form->{PD}{packing_list}>|
 
1535       . $locale->text('Packing List');
 
1538   if ($form->{type} eq 'invoice' && $form->{storno}) {
 
1539     $type = qq|<select name=formname>
 
1540             <option value=storno_invoice $form->{PD}{storno_invoice}>|
 
1541       . $locale->text('Storno Invoice') . qq|
 
1542       <option value=storno_packing_list $form->{PD}{storno_packing_list}>|
 
1543       . $locale->text('Storno Packing List');
 
1546   if ($form->{type} eq 'credit_note') {
 
1547     $type = qq|<select name=formname>
 
1548             <option value=credit_note $form->{PD}{credit_note}>|
 
1549       . $locale->text('Credit Note');
 
1552   if ($form->{media} eq 'email') {
 
1553     $media = qq|<select name=sendmode>
 
1554             <option value=attachment $form->{SM}{attachment}>|
 
1555       . $locale->text('Attachment') . qq|
 
1556             <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
 
1558     $media = qq|<select name=media>
 
1559             <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
 
1560     if (scalar(keys (%{ $form->{printers} })) !=0 && $latex_templates) {
 
1562             <option value=printer $form->{OP}{printer}>|
 
1563         . $locale->text('Printer');
 
1565     if ($latex_templates) {
 
1567             <option value=queue $form->{OP}{queue}>| . $locale->text('Queue');
 
1571   $format = qq|<select name=format>|;
 
1572   if ($opendocument_templates && $openofficeorg_writer_bin &&
 
1573       $xvfb_bin && (-x $openofficeorg_writer_bin) && (-x $xvfb_bin)) {
 
1574     $format .= qq|<option value=opendocument_pdf | .
 
1575       $form->{DF}{"opendocument_pdf"} . qq|>| .
 
1576       $locale->text("PDF (OpenDocument/OASIS)") . qq|</option>|;
 
1579   if ($latex_templates) {
 
1580     $format .= qq|<option value=pdf $form->{DF}{pdf}>| .
 
1581       $locale->text('PDF') . qq|</option>|;
 
1584   $format .= qq|<option value=html $form->{DF}{html}>HTML</option>|;
 
1586   if ($latex_templates) {
 
1587     $format .= qq|<option value=postscript $form->{DF}{postscript}>| .
 
1588       $locale->text('Postscript') . qq|</option>|;
 
1591   if ($opendocument_templates) {
 
1592     $format .= qq|<option value=opendocument $form->{DF}{opendocument}>| .
 
1593       $locale->text("OpenDocument/OASIS") . qq|</option>|;
 
1595   $format .= qq|</select>|;
 
1597   if (scalar(keys (%{ $form->{languages} })) !=0) {
 
1598     $language_select = qq|<select name=language_id>
 
1599                 <option value=""></option>}|;
 
1600     foreach $item (@{ $form->{languages} }) {
 
1601       if ($form->{language_id} eq $item->{id}) {
 
1602         $language_select .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
 
1604         $language_select .= qq|<option value="$item->{id}">$item->{description}</option>|;
 
1609   if (scalar(keys (%{ $form->{printers} })) !=0) {
 
1610     my $selected = !$form->{"printer_id"} ? "selected" : "";
 
1611     $printer_select = qq|<select name=printer_id $selected>
 
1612                   <option value=""></option>|;
 
1613     foreach $item (@{ $form->{printers} }) {
 
1614       $selected = $item->{"id"} == $form->{"printer_id"} ? "selected" : "";
 
1615       $printer_select .= qq|<option value="$item->{id}" $selected>$item->{printer_description}</option>|;
 
1622 <table width=100% cellspacing=0 cellpadding=0>
 
1627           <td>$type</select></td>|;
 
1628   if (scalar(keys (%{ $form->{languages} })) !=0) {
 
1630           <td>${language_select}</select></td>|;
 
1633           <td>$format</select></td>
 
1634           <td>$media</select></td>|;
 
1635   if (scalar(keys (%{ $form->{printers} })) !=0) {
 
1637           <td>$printer_select</select></td>
 
1641   if (scalar(keys (%{ $form->{printers} })) !=0 && $latex_templates && $form->{media} ne 'email') {
 
1643           <td>| . $locale->text('Copies') . qq|
 
1644           <input name=copies size=2 value=$form->{copies}></td>
 
1648   $form->{groupitems} = "checked" if $form->{groupitems};
 
1651           <td>| . $locale->text('Group Items') . qq|</td>
 
1652           <td><input name=groupitems type=checkbox class=checkbox $form->{groupitems}></td>
 
1661   if ($form->{printed} =~ /$form->{formname}/) {
 
1663           <th>\|| . $locale->text('Printed') . qq|\|</th>
 
1667   if ($form->{emailed} =~ /$form->{formname}/) {
 
1669           <th>\|| . $locale->text('E-mailed') . qq|\|</th>
 
1673   if ($form->{queued} =~ /$form->{formname}/) {
 
1675           <th>\|| . $locale->text('Queued') . qq|\|</th>
 
1687   $lxdebug->leave_sub();
 
1691   $lxdebug->enter_sub();
 
1693   # if this goes to the printer pass through
 
1694   if ($form->{media} eq 'printer' || $form->{media} eq 'queue') {
 
1695     $form->error($locale->text('Select postscript or PDF!'))
 
1696       if ($form->{format} !~ /(postscript|pdf)/);
 
1698     $old_form = new Form;
 
1699     map { $old_form->{$_} = $form->{$_} } keys %$form;
 
1702   if (!$form->{id} || (($form->{formname} eq "proforma") && !$form->{proforma} && (($form->{type} =~ /_order$/) || ($form->{type} =~ /_quotation$/)))) {
 
1703     if ($form->{formname} eq "proforma") {
 
1704       $form->{proforma} = 1;
 
1706     $form->{print_and_save} = 1;
 
1707     my $formname = $form->{formname};
 
1709     $form->{formname} = $formname;
 
1714   &print_form($old_form);
 
1716   $lxdebug->leave_sub();
 
1720   $lxdebug->enter_sub();
 
1721   my ($old_form) = @_;
 
1725   $numberfld = "invnumber";
 
1728     ($form->{display_form}) ? $form->{display_form} : "display_form";
 
1730   # $form->{"notes"} will be overridden by the customer's/vendor's "notes" field. So save it here.
 
1731   $form->{ $form->{"formname"} . "notes" } = $form->{"notes"};
 
1733   if ($form->{formname} eq "invoice") {
 
1734     $form->{label} = $locale->text('Invoice');
 
1736   if ($form->{formname} eq "packing_list") {
 
1738     # this is from an invoice
 
1739     $form->{label} = $locale->text('Packing List');
 
1741   if ($form->{formname} eq 'sales_order') {
 
1744     $form->{"${inv}date"} = $form->{transdate};
 
1745     $form->{label}        = $locale->text('Sales Order');
 
1746     $numberfld            = "sonumber";
 
1750   if (($form->{type} eq 'invoice') && ($form->{formname} eq 'proforma') ) {
 
1753     $form->{"${inv}date"} = $form->{invdate};
 
1754     $form->{label}        = $locale->text('Proforma Invoice');
 
1755     $numberfld            = "sonumber";
 
1759   if (($form->{type} eq 'sales_order') && ($form->{formname} eq 'proforma') ) {
 
1762     $form->{"${inv}date"} = $form->{transdate};
 
1763     $form->{"invdate"}    = $form->{transdate};
 
1764     $form->{invnumber}    = $form->{ordnumber};
 
1765     $form->{label}        = $locale->text('Proforma Invoice');
 
1766     $numberfld            = "sonumber";
 
1770   if ($form->{formname} eq 'packing_list' && $form->{type} ne 'invoice') {
 
1772     # we use the same packing list as from an invoice
 
1775     $form->{invdate} = $form->{"${inv}date"} = $form->{transdate};
 
1776     $form->{label} = $locale->text('Packing List');
 
1778     # set invnumber for template packing_list 
 
1779     $form->{invnumber}   = $form->{ordnumber};
 
1781   if ($form->{formname} eq 'pick_list') {
 
1784     $form->{"${inv}date"} =
 
1785       ($form->{transdate}) ? $form->{transdate} : $form->{invdate};
 
1786     $form->{label} = $locale->text('Pick List');
 
1787     $order = 1 unless $form->{type} eq 'invoice';
 
1789   if ($form->{formname} eq 'purchase_order') {
 
1792     $form->{"${inv}date"} = $form->{transdate};
 
1793     $form->{label}        = $locale->text('Purchase Order');
 
1794     $numberfld            = "ponumber";
 
1797   if ($form->{formname} eq 'bin_list') {
 
1800     $form->{"${inv}date"} = $form->{transdate};
 
1801     $form->{label}        = $locale->text('Bin List');
 
1804   if ($form->{formname} eq 'sales_quotation') {
 
1807     $form->{"${inv}date"} = $form->{transdate};
 
1808     $form->{label}        = $locale->text('Quotation');
 
1809     $numberfld            = "sqnumber";
 
1813   if (($form->{type} eq 'sales_quotation') && ($form->{formname} eq 'proforma') ) {
 
1816     $form->{"${inv}date"} = $form->{transdate};
 
1817     $form->{"invdate"}    = $form->{transdate};
 
1818     $form->{label}        = $locale->text('Proforma Invoice');
 
1819     $numberfld            = "sqnumber";
 
1823   if ($form->{formname} eq 'request_quotation') {
 
1826     $form->{"${inv}date"} = $form->{transdate};
 
1827     $form->{label}        = $locale->text('Quotation');
 
1828     $numberfld            = "rfqnumber";
 
1832   $form->isblank("email", $locale->text('E-mail address missing!'))
 
1833     if ($form->{media} eq 'email');
 
1834   $form->isblank("${inv}date",
 
1835            $locale->text($form->{label}) 
 
1837            . $locale->text(' Date missing!'));
 
1839   # $locale->text('Invoice Number missing!')
 
1840   # $locale->text('Invoice Date missing!')
 
1841   # $locale->text('Packing List Number missing!')
 
1842   # $locale->text('Packing List Date missing!')
 
1843   # $locale->text('Order Number missing!')
 
1844   # $locale->text('Order Date missing!')
 
1845   # $locale->text('Quotation Number missing!')
 
1846   # $locale->text('Quotation Date missing!')
 
1849   if (!$form->{"${inv}number"} && !$form->{preview}) {
 
1850     $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
 
1851     if ($form->{media} ne 'email') {
 
1853       # get pricegroups for parts
 
1854       IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
1856       # build up html code for prices_$i
 
1857       set_pricegroup($form->{rowcount});
 
1859       $form->{rowcount}--;
 
1868   # Save the email address given in the form because it should override the setting saved for the customer/vendor.
 
1869   my ($saved_email, $saved_cc, $saved_bcc) =
 
1870     ($form->{"email"}, $form->{"cc"}, $form->{"bcc"});
 
1872   $language_saved = $form->{language_id};
 
1873   $payment_id_saved = $form->{payment_id};
 
1875   &{"$form->{vc}_details"}();
 
1877   $form->{language_id} = $language_saved;
 
1878   $form->{payment_id} = $payment_id_saved;
 
1880   $form->{"email"} = $saved_email if ($saved_email);
 
1881   $form->{"cc"}    = $saved_cc    if ($saved_cc);
 
1882   $form->{"bcc"}   = $saved_bcc   if ($saved_bcc);
 
1884   my ($language_tc, $output_numberformat, $output_dateformat, $output_longdates);
 
1885   if ($form->{"language_id"}) {
 
1886     ($language_tc, $output_numberformat, $output_dateformat, $output_longdates) =
 
1887       AM->get_language_details(\%myconfig, $form, $form->{language_id});
 
1889     $output_dateformat = $myconfig{"dateformat"};
 
1890     $output_numberformat = $myconfig{"numberformat"};
 
1891     $output_longdates = 1;
 
1894   ($form->{employee}) = split /--/, $form->{employee};
 
1896   # create the form variables
 
1898     OE->order_details(\%myconfig, \%$form);
 
1900     IS->invoice_details(\%myconfig, \%$form, $locale);
 
1903   if ($form->{shipto_id}) {
 
1904     $form->get_shipto(\%myconfig);
 
1907   @a = qw(name street zipcode city country);
 
1911   # if there is no shipto fill it in from billto
 
1912   foreach $item (@a) {
 
1913     if ($form->{"shipto$item"}) {
 
1920     if (   $form->{formname} eq 'purchase_order'
 
1921         || $form->{formname} eq 'request_quotation') {
 
1922       $form->{shiptoname}   = $myconfig{company};
 
1923       $form->{shiptostreet} = $myconfig{address};
 
1925       map { $form->{"shipto$_"} = $form->{$_} } @a;
 
1929   $form->{notes} =~ s/^\s+//g;
 
1931   $form->{templates} = "$myconfig{templates}";
 
1933   $form->{language} = $form->get_template_language(\%myconfig);
 
1934   $form->{printer_code} = $form->get_printer_code(\%myconfig);
 
1936   if ($form->{language} ne "") {
 
1937     map({ $form->{"unit"}->[$_] =
 
1938             AM->translate_units($form, $form->{"language"},
 
1939                                 $form->{"unit"}->[$_], $form->{"qty"}->[$_]); }
 
1940         (0..scalar(@{$form->{"unit"}}) - 1));
 
1941     $form->{language} = "_" . $form->{language};
 
1945   format_dates($output_dateformat, $output_longdates,
 
1946                qw(invdate orddate quodate pldate duedate reqdate transdate
 
1947                   shippingdate deliverydate validitydate paymentdate
 
1948                   datepaid transdate_oe deliverydate_oe
 
1949                   employee_startdate employee_enddate
 
1951                grep({ /^datepaid_\d+$/ ||
 
1952                         /^transdate_oe_\d+$/ ||
 
1953                         /^deliverydate_oe_\d+$/ ||
 
1955                         /^deliverydate_\d+$/ ||
 
1959   reformat_numbers($output_numberformat, 2,
 
1960                    qw(invtotal ordtotal quototal subtotal linetotal
 
1961                       listprice sellprice netprice discount
 
1963                    grep({ /^linetotal_\d+$/ ||
 
1964                             /^listprice_\d+$/ ||
 
1965                             /^sellprice_\d+$/ ||
 
1972   reformat_numbers($output_numberformat, undef,
 
1977   if ($form->{printer_code} ne "") {
 
1978     $form->{printer_code} = "_" . $form->{printer_code};
 
1981   $form->{IN} = "$form->{formname}$form->{language}$form->{printer_code}.html";
 
1982   if ($form->{format} eq 'postscript') {
 
1983     $form->{postscript} = 1;
 
1984     $form->{IN} =~ s/html$/tex/;
 
1985   } elsif ($form->{"format"} =~ /pdf/) {
 
1987     if ($form->{"format"} =~ /opendocument/) {
 
1988       $form->{IN} =~ s/html$/odt/;
 
1990       $form->{IN} =~ s/html$/tex/;
 
1992   } elsif ($form->{"format"} =~ /opendocument/) {
 
1993     $form->{"opendocument"} = 1;
 
1994     $form->{"IN"} =~ s/html$/odt/;
 
1997   if ($form->{media} eq 'printer') {
 
1998     $form->{OUT} = "| $form->{printer_command} &>/dev/null";
 
1999     $form->{printed} .= " $form->{formname}";
 
2000     $form->{printed} =~ s/^ //;
 
2002   $printed = $form->{printed};
 
2004   if ($form->{media} eq 'email') {
 
2005     $form->{subject} = qq|$form->{label} $form->{"${inv}number"}|
 
2006       unless $form->{subject};
 
2008     $form->{OUT} = "$sendmail";
 
2010     $form->{emailed} .= " $form->{formname}";
 
2011     $form->{emailed} =~ s/^ //;
 
2013   $emailed = $form->{emailed};
 
2015   if ($form->{media} eq 'queue') {
 
2016     %queued = split / /, $form->{queued};
 
2018     if ($filename = $queued{ $form->{formname} }) {
 
2019       $form->{queued} =~ s/$form->{formname} $filename//;
 
2020       unlink "$spool/$filename";
 
2021       $filename =~ s/\..*$//g;
 
2027     $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
 
2028     $form->{OUT} = ">$spool/$filename";
 
2031     $form->{queued} .= " $form->{formname} $filename";
 
2033     $form->{queued} =~ s/^ //;
 
2035   $queued = $form->{queued};
 
2037   $form->parse_template(\%myconfig, $userspath);
 
2039   $form->{callback} = "";
 
2041   if ($form->{media} eq 'email') {
 
2042     $form->{message} = $locale->text('sent') unless $form->{message};
 
2044   $message = $form->{message};
 
2046   # if we got back here restore the previous form
 
2047   if ($form->{media} =~ /(printer|email|queue)/) {
 
2049     $form->update_status(\%myconfig)
 
2050       if ($form->{media} eq 'queue' && $form->{id});
 
2054       $old_form->{"${inv}number"} = $form->{"${inv}number"};
 
2056       # restore and display form
 
2057       map { $form->{$_} = $old_form->{$_} } keys %$old_form;
 
2059       $form->{queued}  = $queued;
 
2060       $form->{printed} = $printed;
 
2061       $form->{emailed} = $emailed;
 
2062       $form->{message} = $message;
 
2064       $form->{rowcount}--;
 
2065       map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
2066         qw(exchangerate creditlimit creditremaining);
 
2068       for $i (1 .. $form->{paidaccounts}) {
 
2070           $form->{"${_}_$i"} =
 
2071             $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
 
2072         } qw(paid exchangerate);
 
2080       ($form->{media} eq 'printer')
 
2081       ? $locale->text('sent to printer')
 
2082       : $locale->text('emailed to') . " $form->{email}";
 
2083     $form->redirect(qq|$form->{label} $form->{"${inv}number"} $msg|);
 
2085   if ($form->{printing}) {
 
2090   $lxdebug->leave_sub();
 
2093 sub customer_details {
 
2094   $lxdebug->enter_sub();
 
2095   IS->customer_details(\%myconfig, \%$form, @_);
 
2096   $lxdebug->leave_sub();
 
2099 sub vendor_details {
 
2100   $lxdebug->enter_sub();
 
2102   IR->vendor_details(\%myconfig, \%$form, @_);
 
2104   $lxdebug->leave_sub();
 
2108   $lxdebug->enter_sub();
 
2110   $form->{postasnew} = 1;
 
2111   map { delete $form->{$_} } qw(printed emailed queued);
 
2115   $lxdebug->leave_sub();
 
2119   $lxdebug->enter_sub();
 
2120   if ($form->{second_run}) {
 
2121     $form->{print_and_post} = 0;
 
2124   $title = $form->{title};
 
2125   $form->{title} = $locale->text('Ship to');
 
2127   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
2128     qw(exchangerate creditlimit creditremaining);
 
2131     qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry
 
2132        shiptocontact shiptophone shiptofax shiptoemail
 
2133        shiptodepartment_1 shiptodepartment_2);
 
2136     (qw(name department_1 department_2 street zipcode city country
 
2137         contact email phone fax));
 
2139   # get details for name
 
2140   &{"$form->{vc}_details"}(@addr_vars);
 
2143     ($form->{vc} eq 'customer')
 
2144     ? $locale->text('Customer Number')
 
2145     : $locale->text('Vendor Number');
 
2147   # get pricegroups for parts
 
2148   IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
2150   # build up html code for prices_$i
 
2151   set_pricegroup($form->{rowcount});
 
2153   $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
 
2155   $form->{rowcount}--;
 
2162 <form method=post action=$form->{script}>
 
2168         <tr class=listheading>
 
2169           <th class=listheading colspan=2 width=50%>|
 
2170     . $locale->text('Billing Address') . qq|</th>
 
2171           <th class=listheading width=50%>|
 
2172     . $locale->text('Shipping Address') . qq|</th>
 
2174         <tr height="5"></tr>
 
2176           <th align=right nowrap>$number</th>
 
2177           <td>$form->{"$form->{vc}number"}</td>
 
2180           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
 
2181           <td>$form->{name}</td>
 
2182           <td><input name=shiptoname size=35 value="$form->{shiptoname}"></td>
 
2185           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
 
2186           <td>$form->{department_1}</td>
 
2187           <td><input name=shiptodepartment_1 size=35 value="$form->{shiptodepartment_1}"></td>
 
2190           <th align=right nowrap> </th>
 
2191           <td>$form->{department_2}</td>
 
2192           <td><input name=shiptodepartment_2 size=35 value="$form->{shiptodepartment_2}"></td>
 
2195           <th align=right nowrap>| . $locale->text('Street') . qq|</th>
 
2196           <td>$form->{street}</td>
 
2197           <td><input name=shiptostreet size=35 value="$form->{shiptostreet}"></td>
 
2200           <th align=right nowrap>| . $locale->text('Zipcode') . qq|</th>
 
2201           <td>$form->{zipcode}</td>
 
2202           <td><input name=shiptozipcode size=35 value="$form->{shiptozipcode}"></td>
 
2205           <th align=right nowrap>| . $locale->text('City') . qq|</th>
 
2206           <td>$form->{city}</td>
 
2207           <td><input name=shiptocity size=35 value="$form->{shiptocity}"></td>
 
2210           <th align=right nowrap>| . $locale->text('Country') . qq|</th>
 
2211           <td>$form->{country}</td>
 
2212           <td><input name=shiptocountry size=35 value="$form->{shiptocountry}"></td>
 
2215           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
 
2216           <td>$form->{contact}</td>
 
2217           <td><input name=shiptocontact size=35 value="$form->{shiptocontact}"></td>
 
2220           <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
 
2221           <td>$form->{phone}</td>
 
2222           <td><input name=shiptophone size=20 value="$form->{shiptophone}"></td>
 
2225           <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
 
2226           <td>$form->{fax}</td>
 
2227           <td><input name=shiptofax size=20 value="$form->{shiptofax}"></td>
 
2230           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
 
2231           <td>$form->{email}</td>
 
2232           <td><input name=shiptoemail size=35 value="$form->{shiptoemail}"></td>
 
2239 <input type=hidden name=nextsub value=$nextsub>
 
2243   map({ delete $form->{$_} } (@shipto_vars, qw(header)));
 
2244   $form->{title} = $title;
 
2246   foreach $key (keys %$form) {
 
2247     $form->{$key} =~ s/\"/"/g;
 
2248     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
 
2256 <input class=submit type=submit name=action value="|
 
2257     . $locale->text('Continue') . qq|">
 
2264   $lxdebug->leave_sub();
 
2268   $lxdebug->enter_sub();
 
2273   $form->{old_callback} = $form->escape($form->{callback}, 1);
 
2274   $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
 
2275   $form->{old_callback} = $form->escape($form->{old_callback}, 1);
 
2278   delete $form->{action};
 
2279   $customer = $form->{customer};
 
2280   map { $form->{"old_$_"} = $form->{"${_}_$row"} } qw(partnumber description);
 
2282   # save all other form variables in a previousform variable
 
2283   $form->{row} = $row;
 
2284   foreach $key (keys %$form) {
 
2287     $form->{$key} =~ s/&/%26/g;
 
2288     $previousform .= qq|$key=$form->{$key}&|;
 
2291   $previousform = $form->escape($previousform, 1);
 
2293   $form->{script} = "licenses.pl";
 
2295   map { $form->{$_} = $form->{"old_$_"} } qw(partnumber description);
 
2296   map { $form->{$_} = $form->escape($form->{$_}, 1) }
 
2297     qw(partnumber description);
 
2299     qq|$form->{script}?login=$form->{login}&path=$form->{path}&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|;
 
2302   $lxdebug->leave_sub();
 
2305 sub relink_accounts {
 
2306   $lxdebug->enter_sub();
 
2308   $form->{"taxaccounts"} =~ s/\s*$//;
 
2309   $form->{"taxaccounts"} =~ s/^\s*//;
 
2310   foreach my $accno (split(/\s*/, $form->{"taxaccounts"})) {
 
2311     map({ delete($form->{"${accno}_${_}"}); } qw(rate description taxnumber));
 
2313   $form->{"taxaccounts"} = "";
 
2315   for (my $i = 1; $i <= $form->{"rowcount"}; $i++) {
 
2316     if ($form->{"id_$i"}) {
 
2317       IC->retrieve_accounts(\%myconfig, $form, $form->{"id_$i"}, $i, 1);
 
2321   $lxdebug->leave_sub();
 
2326   $lxdebug->enter_sub();
 
2328   $form->get_duedate(\%myconfig);
 
2331   $result = "$form->{duedate}";
 
2334   $lxdebug->leave_sub();