1 #=====================================================================
 
   4 # Based on SQL-Ledger Version 2.1.9
 
   5 # Web http://www.lx-office.org
 
   6 #############################################################################
 
   7 # Veraendert 2005-01-05 - Marco Welter <mawe@linux-studio.de> - Neue Optik  #
 
   8 #############################################################################
 
   9 # SQL-Ledger, Accounting
 
  10 # Copyright (c) 1998-2002
 
  12 #  Author: Dieter Simader
 
  13 #   Email: dsimader@sql-ledger.org
 
  14 #     Web: http://www.sql-ledger.org
 
  17 # This program is free software; you can redistribute it and/or modify
 
  18 # it under the terms of the GNU General Public License as published by
 
  19 # the Free Software Foundation; either version 2 of the License, or
 
  20 # (at your option) any later version.
 
  22 # This program is distributed in the hope that it will be useful,
 
  23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  25 # GNU General Public License for more details.
 
  26 # You should have received a copy of the GNU General Public License
 
  27 # along with this program; if not, write to the Free Software
 
  28 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
  30 #######################################################################
 
  32 # common routines used in is, ir, oe
 
  34 #######################################################################
 
  38 use List::Util qw(max);
 
  44 require "bin/mozilla/common.pl";
 
  46 # any custom scripts for this one
 
  47 if (-f "bin/mozilla/custom_io.pl") {
 
  48   eval { require "bin/mozilla/custom_io.pl"; };
 
  50 if (-f "bin/mozilla/$form->{login}_io.pl") {
 
  51   eval { require "bin/mozilla/$form->{login}_io.pl"; };
 
  58 # this is for our long dates
 
  59 # $locale->text('January')
 
  60 # $locale->text('February')
 
  61 # $locale->text('March')
 
  62 # $locale->text('April')
 
  63 # $locale->text('May ')
 
  64 # $locale->text('June')
 
  65 # $locale->text('July')
 
  66 # $locale->text('August')
 
  67 # $locale->text('September')
 
  68 # $locale->text('October')
 
  69 # $locale->text('November')
 
  70 # $locale->text('December')
 
  72 # this is for our short month
 
  73 # $locale->text('Jan')
 
  74 # $locale->text('Feb')
 
  75 # $locale->text('Mar')
 
  76 # $locale->text('Apr')
 
  77 # $locale->text('May')
 
  78 # $locale->text('Jun')
 
  79 # $locale->text('Jul')
 
  80 # $locale->text('Aug')
 
  81 # $locale->text('Sep')
 
  82 # $locale->text('Oct')
 
  83 # $locale->text('Nov')
 
  84 # $locale->text('Dec')
 
  89 ########################################
 
  90 # Eintrag fuer Version 2.2.0 geaendert #
 
  91 # neue Optik im Rechnungsformular      #
 
  92 ########################################
 
  94 ##################################################
 
  95 # build html-code for pricegroups in variable $form->{prices_$j}
 
  98   $lxdebug->enter_sub();
 
 100   for $j (1 .. $rowcount) {
 
 101     next unless $form->{PRICES}{$j};
 
 102     # build drop down list for pricegroups
 
 103     my $option_tmpl = qq|<option value="%s--%s" %s>%s</option>|;
 
 104     $form->{"prices_$j"}  = join '', map { sprintf $option_tmpl, @$_{qw(price pricegroup_id selected pricegroup)} } 
 
 105                                          (+{ pricegroup => $locale->text("none (pricegroup)") }, @{ $form->{PRICES}{$j} });
 
 107     foreach $item (@{ $form->{PRICES}{$j} }) {
 
 108       # set new selectedpricegroup_id and prices for "Preis"
 
 109       $form->{"pricegroup_old_$j"} = $item->{pricegroup_id}   if $item->{selected} &&  $item->{pricegroup_id};
 
 110       $form->{"sellprice_$j"}      = $item->{price}           if $item->{selected} &&  $item->{pricegroup_id};
 
 111       $form->{"price_new_$j"}      = $form->{"sellprice_$j"}  if $item->{selected} || !$item->{pricegroup_id};
 
 114   $lxdebug->leave_sub();
 
 118   $lxdebug->enter_sub();
 
 119   @column_index = qw(ndx partnumber description onhand unit sellprice);
 
 121   $column_data{ndx}        = qq|<th> </th>|;
 
 122   $column_data{partnumber} =
 
 123     qq|<th class="listheading">| . $locale->text('Number') . qq|</th>|;
 
 124   $column_data{description} =
 
 125     qq|<th class="listheading">| . $locale->text('Part Description') . qq|</th>|;
 
 126   $column_data{sellprice} =
 
 127     qq|<th class="listheading">| . $locale->text('Price') . qq|</th>|;
 
 128   $column_data{onhand} =
 
 129     qq|<th class="listheading">| . $locale->text('Qty') . qq|</th>|;
 
 131     qq|<th class="listheading">| . $locale->text('Unit') . qq|</th>|;
 
 132   # list items with radio button on a form
 
 135   $title   = $locale->text('Select from one of the items below');
 
 136   $colspan = $#column_index + 1;
 
 141 <form method="post" action="$form->{script}">
 
 145     <th class="listtop" colspan="$colspan">$title</th>
 
 148   <tr class="listheading">|;
 
 150   map { print "\n$column_data{$_}" } @column_index;
 
 155   foreach $ref (@{ $form->{item_list} }) {
 
 156     $checked = ($i++) ? "" : "checked";
 
 159       if ($ref->{inventory_accno} > 0) {
 
 160         $ref->{"lizenzen"} = qq|<option></option>|;
 
 161         foreach $item (@{ $form->{LIZENZEN}{ $ref->{"id"} } }) {
 
 162           $ref->{"lizenzen"} .=
 
 163             qq|<option value=\"$item->{"id"}\">$item->{"licensenumber"}</option>|;
 
 165         $ref->{"lizenzen"} .= qq|<option value="-1">Neue Lizenz</option>|;
 
 166         $ref->{"lizenzen"} =~ s/\"/"/g;
 
 170     map { $ref->{$_} =~ s/\"/"/g } qw(partnumber description unit);
 
 172     my $display_sellprice  = $ref->{sellprice} * (1 - $form->{tradediscount});
 
 173     $display_sellprice    /= $ref->{price_factor} if ($ref->{price_factor});
 
 174     $display_sellprice     = $form->format_amount(\%myconfig, $display_sellprice, 2);
 
 177       qq|<td><input name="ndx" class="radio" type="radio" value="$i" $checked></td>|;
 
 178     $column_data{partnumber} =
 
 179       qq|<td><input name="new_partnumber_$i" type="hidden" value="$ref->{partnumber}">$ref->{partnumber}</td>|;
 
 180     $column_data{description} =
 
 181       qq|<td><input name="new_description_$i" type="hidden" value="$ref->{description}">$ref->{description}</td>|;
 
 182     $column_data{sellprice} =
 
 183       qq|<td align="right"><input name="new_sellprice_$i" type="hidden" value="$ref->{sellprice}">|
 
 186     $column_data{onhand} =
 
 187       qq|<td align="right"><input name="new_onhand_$i" type="hidden" value="$ref->{onhand}">|
 
 188       . $form->format_amount(\%myconfig, $ref->{onhand}, '', " ")
 
 191       qq|<td>$ref->{unit}</td>|;
 
 195 <tr class=listrow$j>|;
 
 197     map { print "\n$column_data{$_}" } @column_index;
 
 202       qw(bin listprice inventory_accno income_accno expense_accno unit weight
 
 203          assembly taxaccounts partsgroup formel longdescription not_discountable
 
 204          part_payment_id partnotes id lastcost price_factor_id price_factor);
 
 205     push(@new_fields, "lizenzen") if ($lizenzen);
 
 207     print join "\n", map { $cgi->hidden("-name" => "new_${_}_$i", "-value" => $ref->{$_}) } @new_fields;
 
 212 <tr><td colspan="8"><hr size="3" noshade></td></tr>
 
 215 <input name="lastndx" type="hidden" value="$i">
 
 219   # delete action variable
 
 220   map { delete $form->{$_} } qw(action item_list header);
 
 222   # save all other form variables
 
 223   foreach $key (keys %${form}) {
 
 224     $form->{$key} =~ s/\"/"/g;
 
 225     print qq|<input name="$key" type="hidden" value="$form->{$key}">\n|;
 
 229 <input type="hidden" name="nextsub" value="item_selected">
 
 232 <input class="submit" type="submit" name="action" value="|
 
 233     . $locale->text('Continue') . qq|">
 
 240   $lxdebug->leave_sub();
 
 244   $lxdebug->enter_sub();
 
 246   # replace the last row with the checked row
 
 247   $i = $form->{rowcount};
 
 248   $i = $form->{assembly_rows} if ($form->{item} eq 'assembly');
 
 254   #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
 
 255   #$form->{"sellprice_$i"} = $form->{"sellprice_$i"};
 
 257   # if there was a price entered, override it
 
 258   $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
 
 261     qw(id partnumber description sellprice listprice inventory_accno
 
 262        income_accno expense_accno bin unit weight assembly taxaccounts
 
 263        partsgroup formel longdescription not_discountable partnotes lastcost
 
 264        price_factor_id price_factor);
 
 266   map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } @new_fields;
 
 268   $form->{"marge_price_factor_$i"} = $form->{"new_price_factor_$j"};
 
 270   if ($form->{"part_payment_id_$i"} ne "") {
 
 271     $form->{payment_id} = $form->{"part_payment_id_$i"};
 
 275     map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } qw(lizenzen);
 
 278   ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
 
 280   $decimalplaces = ($dec > 2) ? $dec : 2;
 
 283     $form->{"sellprice_$i"} = $sellprice;
 
 286     # if there is an exchange rate adjust sellprice
 
 287     if (($form->{exchangerate} * 1) != 0) {
 
 288       $form->{"sellprice_$i"} /= $form->{exchangerate};
 
 289       $form->{"sellprice_$i"} =
 
 290         $form->round_amount($form->{"sellprice_$i"}, $decimalplaces);
 
 294   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
 295     qw(sellprice listprice weight);
 
 297   $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
 
 298   $form->{weight}    += ($form->{"weight_$i"} * $form->{"qty_$i"});
 
 300   if ($form->{"not_discountable_$i"}) {
 
 301     $form->{"discount_$i"} = 0;
 
 305     $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) *
 
 307   map { $form->{"${_}_base"} += $amount }
 
 308     (split / /, $form->{"taxaccounts_$i"});
 
 309   map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /,
 
 310     $form->{"taxaccounts_$i"}
 
 311     if !$form->{taxincluded};
 
 313   $form->{creditremaining} -= $amount;
 
 315   $form->{"runningnumber_$i"} = $i;
 
 317   # delete all the new_ variables
 
 318   for $i (1 .. $form->{lastndx}) {
 
 319     map { delete $form->{"new_${_}_$i"} } @new_fields;
 
 322   map { delete $form->{$_} } qw(ndx lastndx nextsub);
 
 327       $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces)
 
 328   } qw(sellprice listprice) if $form->{item} ne 'assembly';
 
 330   # get pricegroups for parts
 
 331   IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
 333   # build up html code for prices_$i
 
 334   set_pricegroup($form->{rowcount});
 
 338   $lxdebug->leave_sub();
 
 342   $lxdebug->enter_sub();
 
 345   $form->{old_callback} = $form->escape($form->{callback}, 1);
 
 346   $form->{callback}     = $form->escape("$form->{script}?action=display_form", 1);
 
 348   # save all form variables except action in a previousform variable
 
 349   my $previousform = join '&', map { $form->{$_} =~ s/&/%26/; "$_=$form->{$_}" } grep { !/action/ } keys %$form;
 
 351   push @HIDDENS,      { 'name' => 'previousform', 'value' => $form->escape($previousform, 1) };
 
 352   push @HIDDENS, map +{ 'name' => $_,             'value' => $form->{$_} },                       qw(rowcount vc login password);
 
 353   push @HIDDENS, map +{ 'name' => $_,             'value' => $form->{"${_}_$form->{rowcount}"} }, qw(partnumber description unit sellprice);
 
 354   push @HIDDENS,      { 'name' => 'taxaccount2',  'value' => $form->{taxaccounts} };
 
 357   print $form->parse_html_template2("generic/new_item", { HIDDENS => [ sort { $a->{name} cmp $b->{name} } @HIDDENS ] } );
 
 359   $lxdebug->leave_sub();
 
 363   $lxdebug->enter_sub();
 
 366   my @flds  = (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 marge_total marge_percent marge_price_factor lastcost price_factor_id));
 
 368   # remove any makes or model rows
 
 369   if ($form->{item} eq 'part') {
 
 370     map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
 371       qw(listprice sellprice lastcost weight rop);
 
 373     @flds = (make, model);
 
 374     for my $i (1 .. ($form->{makemodel_rows})) {
 
 375       if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
 
 379         map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
 
 384     $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
 
 385     $form->{makemodel_rows} = $count;
 
 387   } elsif ($form->{item} eq 'assembly') {
 
 389     $form->{sellprice} = 0;
 
 391     map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
 392       qw(listprice rop stock);
 
 395       qw(id qty unit bom partnumber description sellprice weight runningnumber partsgroup);
 
 397     for my $i (1 .. ($form->{assembly_rows} - 1)) {
 
 398       if ($form->{"qty_$i"}) {
 
 402         $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
 
 404         map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
 
 406         #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
 
 408         $form->{sellprice} += ($form->{"qty_$i"} * $form->{"sellprice_$i"});
 
 409         $form->{weight}    += ($form->{"qty_$i"} * $form->{"weight_$i"});
 
 414     $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
 
 416     $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
 
 417     $form->{assembly_rows} = $count;
 
 420     @flds  = qw(make model);
 
 423     for my $i (1 .. ($form->{makemodel_rows})) {
 
 424       if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
 
 428         map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
 
 433     $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
 
 434     $form->{makemodel_rows} = $count;
 
 436   } elsif ($form->{item} eq 'service') {
 
 437     map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(listprice sellprice lastcost);
 
 441     # this section applies to invoices and orders
 
 442     # remove any empty numbers
 
 443     if ($form->{rowcount}) {
 
 444       for my $i (1 .. $form->{rowcount} - 1) {
 
 445         if ($form->{"partnumber_$i"}) {
 
 449           map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
 
 452             if ($form->{"licensenumber_$i"} == -1) {
 
 460       $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
 
 461       $form->{rowcount} = $count;
 
 463       $form->{creditremaining} -= &invoicetotal;
 
 470   if (   $form->{type} =~ (/sales_quotation/)
 
 471       or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/))
 
 472       or (($form->{level} eq undef) and ($form->{type} =~ /invoice/))
 
 473       or ($form->{type} =~ /sales_order/)) {
 
 475     # get pricegroups for parts
 
 476     IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
 478     # build up html code for prices_$i
 
 479     set_pricegroup($form->{rowcount});
 
 485   $lxdebug->leave_sub();
 
 489   $lxdebug->enter_sub();
 
 491   $form->{oldinvtotal} = 0;
 
 493   # add all parts and deduct paid
 
 494   map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
 
 496   my ($amount, $sellprice, $discount, $qty);
 
 498   for my $i (1 .. $form->{rowcount}) {
 
 499     $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
 
 500     $discount  = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
 
 501     $qty       = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
 
 503     #($form->{"sellprice_$i"}, $form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
 
 505     $amount = $sellprice * (1 - $discount / 100) * $qty;
 
 506     map { $form->{"${_}_base"} += $amount }
 
 507       (split (/ /, $form->{"taxaccounts_$i"}));
 
 508     $form->{oldinvtotal} += $amount;
 
 511   map { $form->{oldinvtotal} += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
 
 512     split(/ /, $form->{taxaccounts})
 
 513     if !$form->{taxincluded};
 
 515   $form->{oldtotalpaid} = 0;
 
 516   for $i (1 .. $form->{paidaccounts}) {
 
 517     $form->{oldtotalpaid} += $form->{"paid_$i"};
 
 520   $lxdebug->leave_sub();
 
 523   return ($form->{oldinvtotal} - $form->{oldtotalpaid});
 
 527   $lxdebug->enter_sub();
 
 529   # check if items are valid
 
 530   if ($form->{rowcount} == 1) {
 
 535   for $i (1 .. $form->{rowcount} - 1) {
 
 536     $form->isblank("partnumber_$i",
 
 537                    $locale->text('Number missing in Row') . " $i");
 
 540   $lxdebug->leave_sub();
 
 544   $lxdebug->enter_sub();
 
 545   if ($form->{second_run}) {
 
 546     $form->{print_and_post} = 0;
 
 548   $form->{ordnumber} = $form->{invnumber};
 
 550   $form->{old_employee_id} = $form->{employee_id};
 
 551   $form->{old_salesman_id} = $form->{salesman_id};
 
 553   map { delete $form->{$_} } qw(id printed emailed queued);
 
 554   if ($form->{script} eq 'ir.pl' || $form->{type} eq 'request_quotation') {
 
 555     $form->{title} = $locale->text('Add Purchase Order');
 
 556     $form->{vc}    = 'vendor';
 
 557     $form->{type}  = 'purchase_order';
 
 560   if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_quotation') {
 
 561     $form->{title} = $locale->text('Add Sales Order');
 
 562     $form->{vc}    = 'customer';
 
 563     $form->{type}  = 'sales_order';
 
 566   $form->{script} = 'oe.pl';
 
 574   require "bin/mozilla/$form->{script}";
 
 575   my $script = $form->{"script"};
 
 578   $locale = new Locale($language, $script);
 
 580   map { $form->{"select$_"} = "" } ($form->{vc}, currency);
 
 582   $currency = $form->{currency};
 
 586   $form->{currency}     = $currency;
 
 587   $form->{exchangerate} = "";
 
 589   $form->{exchangerate} = $exchangerate
 
 593                     $form->check_exchangerate(
 
 594                     \%myconfig, $form->{currency}, $form->{transdate}, $buysell
 
 597   for $i (1 .. $form->{rowcount}) {
 
 598     map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
 
 599                                                      $form->{"${_}_${i}"})
 
 600             if ($form->{"${_}_${i}"}) }
 
 601         qw(ship qty sellprice listprice basefactor));
 
 607   $lxdebug->leave_sub();
 
 611   $lxdebug->enter_sub();
 
 612   if ($form->{second_run}) {
 
 613     $form->{print_and_post} = 0;
 
 615   map { delete $form->{$_} } qw(id printed emailed queued);
 
 617   if ($form->{script} eq 'ir.pl' || $form->{type} eq 'purchase_order') {
 
 618     $form->{title} = $locale->text('Add Request for Quotation');
 
 619     $form->{vc}    = 'vendor';
 
 620     $form->{type}  = 'request_quotation';
 
 623   if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_order') {
 
 624     $form->{title} = $locale->text('Add Quotation');
 
 625     $form->{vc}    = 'customer';
 
 626     $form->{type}  = 'sales_quotation';
 
 632   $form->{script} = 'oe.pl';
 
 638   require "bin/mozilla/$form->{script}";
 
 640   map { $form->{"select$_"} = "" } ($form->{vc}, currency);
 
 642   $currency = $form->{currency};
 
 646   $form->{currency}     = $currency;
 
 647   $form->{exchangerate} = "";
 
 649   $form->{exchangerate} = $exchangerate
 
 653                     $form->check_exchangerate(
 
 654                     \%myconfig, $form->{currency}, $form->{transdate}, $buysell
 
 657   for $i (1 .. $form->{rowcount}) {
 
 658     map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
 
 659                                                      $form->{"${_}_${i}"})
 
 660             if ($form->{"${_}_${i}"}) }
 
 661         qw(ship qty sellprice listprice basefactor));
 
 667   $lxdebug->leave_sub();
 
 670 sub request_for_quotation {
 
 675   $lxdebug->enter_sub();
 
 677   if ($form->{second_run}) {
 
 678     $form->{print_and_post} = 0;
 
 679     $form->{resubmit}       = 0;
 
 682   $form->{email} = $form->{shiptoemail} if $form->{shiptoemail} && $form->{formname} =~ /(pick|packing|bin)_list/;
 
 684   if ($form->{"cp_id"} && !$form->{"email"}) {
 
 685     CT->get_contact(\%myconfig, $form);
 
 686     $form->{"email"} = $form->{"cp_email"};
 
 689   $title = $locale->text('E-mail') . " " . $form->get_formname_translation();
 
 691   $form->{oldmedia} = $form->{media};
 
 692   $form->{media}    = "email";
 
 694   my $attachment_filename = $form->generate_attachment_filename();
 
 696   $form->{"fokus"} = $form->{"email"} ? "Form.subject" : "Form.email";
 
 699   my (@dont_hide_key_list, %dont_hide_key, @hidden_keys);
 
 700   @dont_hide_key_list = qw(action email cc bcc subject message sendmode format header override);
 
 701   @dont_hide_key{@dont_hide_key_list} = (1) x @dont_hide_key_list;
 
 702   @hidden_keys = sort grep { !$dont_hide_key{$_} } grep { !ref $form->{$_} } keys %$form;
 
 704   print $form->parse_html_template2('generic/edit_email',
 
 706                                       a_filename      => $attachment_filename,
 
 707                                       _print_options_ => print_options('inline' => 1),
 
 708                                       HIDDEN          => [ map +{ name => $_, value => $form->{$_} }, @hidden_keys ],
 
 709                                       SHOW_BCC        => $myconfig{role} eq 'admin' });
 
 711   $lxdebug->leave_sub();
 
 715   $lxdebug->enter_sub();
 
 717   my $callback = $form->{script} . "?action=edit";
 
 718   map({ $callback .= "\&${_}=" . E($form->{$_}); }
 
 719       qw(login password type id));
 
 721   print_form("return");
 
 723   Common->save_email_status(\%myconfig, $form);
 
 725   $form->{callback} = $callback;
 
 728   $lxdebug->leave_sub();
 
 731 # generate the printing options displayed at the bottom of oe and is forms.
 
 732 # this function will attempt to guess what type of form is displayed, and will generate according options
 
 735 # this version builds the arrays of options pretty directly. if you have trouble understanding how,
 
 736 # the opthash function builds hashrefs which are then pieced together for the template arrays.
 
 737 # unneeded options are "undef"ed out, and then grepped out. 
 
 739 # the inline options is untested, but intended to be used later in metatemplating
 
 741   $lxdebug->enter_sub();
 
 745   # names 3 parameters and returns a hashref, for use in templates
 
 746   sub opthash { +{ value => shift, selected => shift, oname => shift } }
 
 747   (@FORMNAME, @FORMNAME, @LANGUAGE_ID, @FORMAT, @SENDMODE, @MEDIA, @PRINTER_ID, @SELECTS) = ();
 
 749   # note: "||"-selection is only correct for values where "0" is _not_ a correct entry
 
 750   $form->{sendmode}   = "attachment";
 
 751   $form->{format}     = $form->{format} || $myconfig{template_format} || "pdf";
 
 752   $form->{copies}     = $form->{copies} || $myconfig{copies}          || 3;
 
 753   $form->{media}      = $form->{media}  || $myconfig{default_media}   || "screen";
 
 754   $form->{printer_id} = defined $form->{printer_id}           ? $form->{printer_id} :
 
 755                         defined $myconfig{default_printer_id} ? $myconfig{default_printer_id} : "";
 
 757   $form->{PD}{ $form->{formname} } = "selected";
 
 758   $form->{DF}{ $form->{format} }   = "selected";
 
 759   $form->{OP}{ $form->{media} }    = "selected";
 
 760   $form->{SM}{ $form->{formname} } = "selected";
 
 762   push @FORMNAME, grep $_,
 
 763     ($form->{type} eq 'purchase_order') ? (
 
 764       opthash("purchase_order",      $form->{PD}{purchase_order},      $locale->text('Purchase Order')),
 
 765       opthash("bin_list",            $form->{PD}{bin_list},            $locale->text('Bin List')) 
 
 767     ($form->{type} eq 'credit_note') ?
 
 768       opthash("credit_note",         $form->{PD}{credit_note},         $locale->text('Credit Note')) : undef,
 
 769     ($form->{type} eq 'sales_order') ? (
 
 770       opthash("sales_order",         $form->{PD}{sales_order},         $locale->text('Confirmation')),
 
 771       opthash("proforma",            $form->{PD}{proforma},            $locale->text('Proforma Invoice')),
 
 772       opthash("pick_list",           $form->{PD}{pick_list},           $locale->text('Pick List')),
 
 773       opthash("packing_list",        $form->{PD}{packing_list},        $locale->text('Packing List')) 
 
 775     ($form->{type} =~ /_quotation$/) ?
 
 776       opthash("$`_quotation",        $form->{PD}{"$`_quotation"},      $locale->text('Quotation')) : undef,
 
 777     ($form->{type} eq 'invoice') ? (
 
 778       opthash("invoice",             $form->{PD}{invoice},             $locale->text('Invoice')),
 
 779       opthash("proforma",            $form->{PD}{proforma},            $locale->text('Proforma Invoice')),
 
 780       opthash("packing_list",        $form->{PD}{packing_list},        $locale->text('Packing List'))
 
 782     ($form->{type} eq 'invoice' && $form->{storno}) ? (
 
 783       opthash("storno_invoice",      $form->{PD}{storno_invoice},      $locale->text('Storno Invoice')),
 
 784       opthash("storno_packing_list", $form->{PD}{storno_packing_list}, $locale->text('Storno Packing List')) 
 
 786     ($form->{type} eq 'credit_note') ?
 
 787       opthash("credit_note",         $form->{PD}{credit_note},         $locale->text('Credit Note')) : undef;
 
 790     opthash("attachment",            $form->{SM}{attachment},          $locale->text('Attachment')),
 
 791     opthash("inline",                $form->{SM}{inline},              $locale->text('In-line'))
 
 792       if ($form->{media} eq 'email');
 
 794   push @MEDIA, grep $_,
 
 795       opthash("screen",              $form->{OP}{screen},              $locale->text('Screen')),
 
 796     (scalar @{ $form->{printers} } && $latex_templates) ?
 
 797       opthash("printer",             $form->{OP}{printer},             $locale->text('Printer')) : undef,
 
 798     ($latex_templates && !$options->{no_queue}) ?
 
 799       opthash("queue",               $form->{OP}{queue},               $locale->text('Queue')) : undef
 
 800         if ($form->{media} ne 'email');
 
 802   push @FORMAT, grep $_,
 
 803     ($opendocument_templates && $openofficeorg_writer_bin && $xvfb_bin && (-x $openofficeorg_writer_bin) && (-x $xvfb_bin)
 
 804      && !$options->{no_opendocument_pdf}) ?
 
 805       opthash("opendocument_pdf",    $form->{DF}{"opendocument_pdf"},  $locale->text("PDF (OpenDocument/OASIS)")) : undef,
 
 807       opthash("pdf",                 $form->{DF}{pdf},                 $locale->text('PDF')) : undef,
 
 808     ($latex_templates && !$options->{no_postscript}) ?
 
 809       opthash("postscript",          $form->{DF}{postscript},          $locale->text('Postscript')) : undef,
 
 810     (!$options->{no_html}) ?
 
 811       opthash("html", $form->{DF}{html}, "HTML") : undef,
 
 812     ($opendocument_templates && !$options->{no_opendocument}) ?
 
 813       opthash("opendocument",        $form->{DF}{opendocument},        $locale->text("OpenDocument/OASIS")) : undef;
 
 816     map { opthash($_->{id}, ($_->{id} eq $form->{language_id} ? 'selected' : ''), $_->{description}) } +{}, @{ $form->{languages} }
 
 817       if (ref $form->{languages} eq 'ARRAY');
 
 820     map { opthash($_->{id}, ($_->{id} eq $form->{printer_id} ? 'selected' : ''), $_->{printer_description}) } +{}, @{ $form->{printers} }
 
 821       if ((ref $form->{printers} eq 'ARRAY') && scalar @{ $form->{printers } });
 
 823   @SELECTS = map { sname => lc $_, DATA => \@$_, show => !$options{"hide_" . lc($_)} && scalar @$_ }, qw(FORMNAME LANGUAGE_ID FORMAT SENDMODE MEDIA PRINTER_ID);
 
 825   my %dont_display_groupitems = (
 
 830     display_copies       => scalar @{ $form->{printers} } && $latex_templates && $form->{media} ne 'email',
 
 831     display_remove_draft => (!$form->{id} && $form->{draft_id}),
 
 832     display_groupitems   => !$dont_display_groupitems{$form->{type}},
 
 833     groupitems_checked   => $form->{groupitems} ? "checked" : '',
 
 834     remove_draft_checked => $form->{remove_draft} ? "checked" : ''
 
 837   my $print_options = $form->parse_html_template2("generic/print_options", { SELECTS  => \@SELECTS, %template_vars } );
 
 839   if ($options{inline}) {
 
 840     $lxdebug->leave_sub();
 
 841     return $print_options;
 
 844   print $print_options;
 
 846   $lxdebug->leave_sub();
 
 850   $lxdebug->enter_sub();
 
 852   if ($form->{print_nextsub}) {
 
 853     call_sub($form->{print_nextsub});
 
 854     $lxdebug->leave_sub();
 
 858   # if this goes to the printer pass through
 
 859   if ($form->{media} eq 'printer' || $form->{media} eq 'queue') {
 
 860     $form->error($locale->text('Select postscript or PDF!'))
 
 861       if ($form->{format} !~ /(postscript|pdf)/);
 
 863     $old_form = new Form;
 
 864     map { $old_form->{$_} = $form->{$_} } keys %$form;
 
 867   if (!$form->{id} || (($form->{formname} eq "proforma") && !$form->{proforma} && (($form->{type} =~ /_order$/) || ($form->{type} =~ /_quotation$/)))) {
 
 868     if ($form->{formname} eq "proforma") {
 
 869       $form->{proforma} = 1;
 
 871     $form->{print_and_save} = 1;
 
 872     my $formname = $form->{formname};
 
 874     $form->{formname} = $formname;
 
 879   &print_form($old_form);
 
 881   $lxdebug->leave_sub();
 
 885   $lxdebug->enter_sub();
 
 890   $numberfld = "invnumber";
 
 893     ($form->{display_form}) ? $form->{display_form} : "display_form";
 
 895   # $form->{"notes"} will be overridden by the customer's/vendor's "notes" field. So save it here.
 
 896   $form->{ $form->{"formname"} . "notes" } = $form->{"notes"};
 
 898   if ($form->{formname} eq "invoice") {
 
 899     $form->{label} = $locale->text('Invoice');
 
 901   if ($form->{formname} eq "packing_list") {
 
 903     # this is from an invoice
 
 904     $form->{label} = $locale->text('Packing List');
 
 906   if ($form->{formname} eq 'sales_order') {
 
 909     $form->{"${inv}date"} = $form->{transdate};
 
 910     $form->{label}        = $locale->text('Confirmation');
 
 911     $numberfld            = "sonumber";
 
 915   if (($form->{type} eq 'invoice') && ($form->{formname} eq 'proforma') ) {
 
 918     $form->{"${inv}date"} = $form->{invdate};
 
 919     $form->{label}        = $locale->text('Proforma Invoice');
 
 920     $numberfld            = "sonumber";
 
 924   if (($form->{type} eq 'sales_order') && ($form->{formname} eq 'proforma') ) {
 
 927     $form->{"${inv}date"} = $form->{transdate};
 
 928     $form->{"invdate"}    = $form->{transdate};
 
 929     $form->{invnumber}    = $form->{ordnumber};
 
 930     $form->{label}        = $locale->text('Proforma Invoice');
 
 931     $numberfld            = "sonumber";
 
 935   if ($form->{formname} eq 'packing_list' && $form->{type} ne 'invoice') {
 
 937     # we use the same packing list as from an invoice
 
 940     $form->{invdate} = $form->{"${inv}date"} = $form->{transdate};
 
 941     $form->{label} = $locale->text('Packing List');
 
 943     # set invnumber for template packing_list 
 
 944     $form->{invnumber}   = $form->{ordnumber};
 
 946   if ($form->{formname} eq 'pick_list') {
 
 949     $form->{"${inv}date"} =
 
 950       ($form->{transdate}) ? $form->{transdate} : $form->{invdate};
 
 951     $form->{label} = $locale->text('Pick List');
 
 952     $order = 1 unless $form->{type} eq 'invoice';
 
 954   if ($form->{formname} eq 'purchase_order') {
 
 957     $form->{"${inv}date"} = $form->{transdate};
 
 958     $form->{label}        = $locale->text('Purchase Order');
 
 959     $numberfld            = "ponumber";
 
 962   if ($form->{formname} eq 'bin_list') {
 
 965     $form->{"${inv}date"} = $form->{transdate};
 
 966     $form->{label}        = $locale->text('Bin List');
 
 969   if ($form->{formname} eq 'sales_quotation') {
 
 972     $form->{"${inv}date"} = $form->{transdate};
 
 973     $form->{label}        = $locale->text('Quotation');
 
 974     $numberfld            = "sqnumber";
 
 978   if (($form->{type} eq 'sales_quotation') && ($form->{formname} eq 'proforma') ) {
 
 981     $form->{"${inv}date"} = $form->{transdate};
 
 982     $form->{"invdate"}    = $form->{transdate};
 
 983     $form->{label}        = $locale->text('Proforma Invoice');
 
 984     $numberfld            = "sqnumber";
 
 988   if ($form->{formname} eq 'request_quotation') {
 
 991     $form->{"${inv}date"} = $form->{transdate};
 
 992     $form->{label}        = $locale->text('RFQ');
 
 993     $numberfld            = "rfqnumber";
 
 997   $form->isblank("email", $locale->text('E-mail address missing!'))
 
 998     if ($form->{media} eq 'email');
 
 999   $form->isblank("${inv}date",
 
1000            $locale->text($form->{label}) 
 
1002            . $locale->text(' Date missing!'));
 
1004   # $locale->text('Invoice Number missing!')
 
1005   # $locale->text('Invoice Date missing!')
 
1006   # $locale->text('Packing List Number missing!')
 
1007   # $locale->text('Packing List Date missing!')
 
1008   # $locale->text('Order Number missing!')
 
1009   # $locale->text('Order Date missing!')
 
1010   # $locale->text('Quotation Number missing!')
 
1011   # $locale->text('Quotation Date missing!')
 
1014   $form->{what_done} = $form->{formname};
 
1015   if (!$form->{"${inv}number"} && !$form->{preview} && !$form->{id}) {
 
1016     $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
 
1017     if ($form->{media} ne 'email') {
 
1019       # get pricegroups for parts
 
1020       IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
1022       # build up html code for prices_$i
 
1023       set_pricegroup($form->{rowcount});
 
1025       $form->{rowcount}--;
 
1027       call_sub($display_form);
 
1028       # saving the history
 
1029           if(!exists $form->{addition}) {
 
1030         $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber}; 
 
1031             $form->{addition} = "PRINTED";
 
1032             $form->save_history($form->dbconnect(\%myconfig));
 
1034       # /saving the history
 
1041   # Save the email address given in the form because it should override the setting saved for the customer/vendor.
 
1042   my ($saved_email, $saved_cc, $saved_bcc) =
 
1043     ($form->{"email"}, $form->{"cc"}, $form->{"bcc"});
 
1045   $language_saved = $form->{language_id};
 
1046   $payment_id_saved = $form->{payment_id};
 
1047   $salesman_id_saved = $form->{salesman_id};
 
1048   $cp_id_saved = $form->{cp_id};
 
1050   call_sub("$form->{vc}_details");
 
1052   $form->{language_id} = $language_saved;
 
1053   $form->{payment_id} = $payment_id_saved;
 
1055   $form->{"email"} = $saved_email if ($saved_email);
 
1056   $form->{"cc"}    = $saved_cc    if ($saved_cc);
 
1057   $form->{"bcc"}   = $saved_bcc   if ($saved_bcc);
 
1059   if (!$cp_id_saved) {
 
1060     # No contact was selected. Delete all contact variables because
 
1061     # IS->customer_details() and IR->vendor_details() get the default
 
1063     map({ delete($form->{$_}); } grep(/^cp_/, keys(%{ $form })));
 
1066   my ($language_tc, $output_numberformat, $output_dateformat, $output_longdates);
 
1067   if ($form->{"language_id"}) {
 
1068     ($language_tc, $output_numberformat, $output_dateformat, $output_longdates) =
 
1069       AM->get_language_details(\%myconfig, $form, $form->{language_id});
 
1071     $output_dateformat = $myconfig{"dateformat"};
 
1072     $output_numberformat = $myconfig{"numberformat"};
 
1073     $output_longdates = 1;
 
1076   ($form->{employee}) = split /--/, $form->{employee};
 
1078   # create the form variables
 
1080     OE->order_details(\%myconfig, \%$form);
 
1082     IS->invoice_details(\%myconfig, \%$form, $locale);
 
1085   $form->get_salesman(\%myconfig, $salesman_id_saved);
 
1087   if ($form->{shipto_id}) {
 
1088     $form->get_shipto(\%myconfig);
 
1091   @a = qw(name street zipcode city country);
 
1095   # if there is no shipto fill it in from billto
 
1096   foreach $item (@a) {
 
1097     if ($form->{"shipto$item"}) {
 
1104     if (   $form->{formname} eq 'purchase_order'
 
1105         || $form->{formname} eq 'request_quotation') {
 
1106       $form->{shiptoname}   = $myconfig{company};
 
1107       $form->{shiptostreet} = $myconfig{address};
 
1109       map { $form->{"shipto$_"} = $form->{$_} } @a;
 
1113   $form->{notes} =~ s/^\s+//g;
 
1115   $form->{templates} = "$myconfig{templates}";
 
1117   delete $form->{printer_command};
 
1119   $form->{language} = $form->get_template_language(\%myconfig);
 
1122   if ($form->{media} ne 'email') {
 
1123     $printer_code = $form->get_printer_code(\%myconfig);
 
1124     if ($printer_code ne "") {
 
1125       $printer_code = "_" . $printer_code;
 
1129   if ($form->{language} ne "") {
 
1130     map({ $form->{"unit"}->[$_] =
 
1131             AM->translate_units($form, $form->{"language"},
 
1132                                 $form->{"unit"}->[$_], $form->{"qty"}->[$_]); }
 
1133         (0..scalar(@{$form->{"unit"}}) - 1));
 
1134     $form->{language} = "_" . $form->{language};
 
1138   format_dates($output_dateformat, $output_longdates,
 
1139                qw(invdate orddate quodate pldate duedate reqdate transdate
 
1140                   shippingdate deliverydate validitydate paymentdate
 
1141                   datepaid transdate_oe deliverydate_oe
 
1142                   employee_startdate employee_enddate
 
1144                grep({ /^datepaid_\d+$/ ||
 
1145                         /^transdate_oe_\d+$/ ||
 
1146                         /^deliverydate_oe_\d+$/ ||
 
1148                         /^deliverydate_\d+$/ ||
 
1152   reformat_numbers($output_numberformat, 2,
 
1153                    qw(invtotal ordtotal quototal subtotal linetotal
 
1154                       listprice sellprice netprice discount
 
1155                       tax taxbase total paid),
 
1156                    grep({ /^linetotal_\d+$/ ||
 
1157                             /^listprice_\d+$/ ||
 
1158                             /^sellprice_\d+$/ ||
 
1168   reformat_numbers($output_numberformat, undef,
 
1169                    qw(qty price_factor),
 
1173   $form->{IN} = "$form->{formname}$form->{language}${printer_code}.html";
 
1174   if ($form->{format} eq 'postscript') {
 
1175     $form->{postscript} = 1;
 
1176     $form->{IN} =~ s/html$/tex/;
 
1177   } elsif ($form->{"format"} =~ /pdf/) {
 
1179     if ($form->{"format"} =~ /opendocument/) {
 
1180       $form->{IN} =~ s/html$/odt/;
 
1182       $form->{IN} =~ s/html$/tex/;
 
1184   } elsif ($form->{"format"} =~ /opendocument/) {
 
1185     $form->{"opendocument"} = 1;
 
1186     $form->{"IN"} =~ s/html$/odt/;
 
1189   delete $form->{OUT};
 
1191   if ($form->{media} eq 'printer') {
 
1192     $form->{OUT} = "| $form->{printer_command} &>/dev/null";
 
1193     $form->{printed} .= " $form->{formname}";
 
1194     $form->{printed} =~ s/^ //;
 
1196   $printed = $form->{printed};
 
1198   if ($form->{media} eq 'email') {
 
1199     $form->{subject} = qq|$form->{label} $form->{"${inv}number"}|
 
1200       unless $form->{subject};
 
1202     $form->{emailed} .= " $form->{formname}";
 
1203     $form->{emailed} =~ s/^ //;
 
1205   $emailed = $form->{emailed};
 
1207   if ($form->{media} eq 'queue') {
 
1208     %queued = map { s|.*/|| } split / /, $form->{queued};
 
1210     if ($filename = $queued{ $form->{formname} }) {
 
1211       $form->{queued} =~ s/\Q$form->{formname} $filename\E//;
 
1212       unlink "$spool/$filename";
 
1213       $filename =~ s/\..*$//g;
 
1219     $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
 
1220     $form->{OUT} = ">$spool/$filename";
 
1223     $form->{queued} .= " $form->{formname} $filename";
 
1225     $form->{queued} =~ s/^ //;
 
1227   $queued = $form->{queued};
 
1229 # saving the history
 
1230   if(!exists $form->{addition}) {
 
1231     $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
 
1232     if($form->{media} =~ /printer/) {
 
1233         $form->{addition} = "PRINTED";
 
1235     elsif($form->{media} =~ /email/) {
 
1236         $form->{addition} = "MAILED";
 
1238     elsif($form->{media} =~ /queue/) {
 
1239         $form->{addition} = "QUEUED";
 
1241     elsif($form->{media} =~ /screen/) {
 
1242         $form->{addition} = "SCREENED";
 
1244     $form->save_history($form->dbconnect(\%myconfig));
 
1246   # /saving the history
 
1248   $form->parse_template(\%myconfig, $userspath);
 
1250   $form->{callback} = "";
 
1252   if ($form->{media} eq 'email') {
 
1253     $form->{message} = $locale->text('sent') unless $form->{message};
 
1255   $message = $form->{message};
 
1257   # if we got back here restore the previous form
 
1258   if ($form->{media} =~ /(printer|email|queue)/) {
 
1260     $form->update_status(\%myconfig)
 
1261       if ($form->{media} eq 'queue' && $form->{id});
 
1263     return $lxdebug->leave_sub() if ($old_form eq "return");
 
1267       $old_form->{"${inv}number"} = $form->{"${inv}number"};
 
1269       # restore and display form
 
1270       map { $form->{$_} = $old_form->{$_} } keys %$old_form;
 
1272       $form->{queued}  = $queued;
 
1273       $form->{printed} = $printed;
 
1274       $form->{emailed} = $emailed;
 
1275       $form->{message} = $message;
 
1277       $form->{rowcount}--;
 
1278       map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
1279         qw(exchangerate creditlimit creditremaining);
 
1281       for $i (1 .. $form->{paidaccounts}) {
 
1283           $form->{"${_}_$i"} =
 
1284             $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
 
1285         } qw(paid exchangerate);
 
1288       call_sub($display_form);
 
1293       ($form->{media} eq 'printer')
 
1294       ? $locale->text('sent to printer')
 
1295       : $locale->text('emailed to') . " $form->{email}";
 
1296     $form->redirect(qq|$form->{label} $form->{"${inv}number"} $msg|);
 
1298   if ($form->{printing}) {
 
1299    call_sub($display_form);
 
1303   $lxdebug->leave_sub();
 
1306 sub customer_details {
 
1307   $lxdebug->enter_sub();
 
1308   IS->customer_details(\%myconfig, \%$form, @_);
 
1309   $lxdebug->leave_sub();
 
1312 sub vendor_details {
 
1313   $lxdebug->enter_sub();
 
1315   IR->vendor_details(\%myconfig, \%$form, @_);
 
1317   $lxdebug->leave_sub();
 
1321   $lxdebug->enter_sub();
 
1323   $form->{postasnew} = 1;
 
1324   map { delete $form->{$_} } qw(printed emailed queued);
 
1328   $lxdebug->leave_sub();
 
1332   $lxdebug->enter_sub();
 
1333   if ($form->{second_run}) {
 
1334     $form->{print_and_post} = 0;
 
1337   $title = $form->{title};
 
1338   $form->{title} = $locale->text('Ship to');
 
1340   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
1341     qw(exchangerate creditlimit creditremaining);
 
1344     qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry
 
1345        shiptocontact shiptophone shiptofax shiptoemail
 
1346        shiptodepartment_1 shiptodepartment_2);
 
1349     (qw(name department_1 department_2 street zipcode city country
 
1350         contact email phone fax));
 
1352   # get details for name
 
1353   call_sub("$form->{vc}_details", @addr_vars);
 
1356     ($form->{vc} eq 'customer')
 
1357     ? $locale->text('Customer Number')
 
1358     : $locale->text('Vendor Number');
 
1360   # get pricegroups for parts
 
1361   IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
1363   # build up html code for prices_$i
 
1364   set_pricegroup($form->{rowcount});
 
1366   $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
 
1368   $form->{rowcount}--;
 
1375 <form method="post" action="$form->{script}">
 
1377 <table width="100%">
 
1381         <tr class="listheading">
 
1382           <th class="listheading" colspan="2" width="50%">|
 
1383     . $locale->text('Billing Address') . qq|</th>
 
1384           <th class="listheading" width="50%">|
 
1385     . $locale->text('Shipping Address') . qq|</th>
 
1387         <tr height="5"></tr>
 
1389           <th align="right" nowrap>$number</th>
 
1390           <td>$form->{"$form->{vc}number"}</td>
 
1393           <th align="right" nowrap>| . $locale->text('Company Name') . qq|</th>
 
1394           <td>$form->{name}</td>
 
1395           <td><input name="shiptoname" size="35" value="$form->{shiptoname}"></td>
 
1398           <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
 
1399           <td>$form->{department_1}</td>
 
1400           <td><input name="shiptodepartment_1" size="35" value="$form->{shiptodepartment_1}"></td>
 
1403           <th align="right" nowrap> </th>
 
1404           <td>$form->{department_2}</td>
 
1405           <td><input name="shiptodepartment_2" size="35" value="$form->{shiptodepartment_2}"></td>
 
1408           <th align="right" nowrap>| . $locale->text('Street') . qq|</th>
 
1409           <td>$form->{street}</td>
 
1410           <td><input name="shiptostreet" size="35" value="$form->{shiptostreet}"></td>
 
1413           <th align="right" nowrap>| . $locale->text('Zipcode') . qq|</th>
 
1414           <td>$form->{zipcode}</td>
 
1415           <td><input name="shiptozipcode" size="35" value="$form->{shiptozipcode}"></td>
 
1418           <th align="right" nowrap>| . $locale->text('City') . qq|</th>
 
1419           <td>$form->{city}</td>
 
1420           <td><input name="shiptocity" size="35" value="$form->{shiptocity}"></td>
 
1423           <th align="right" nowrap>| . $locale->text('Country') . qq|</th>
 
1424           <td>$form->{country}</td>
 
1425           <td><input name="shiptocountry" size="35" value="$form->{shiptocountry}"></td>
 
1428           <th align="right" nowrap>| . $locale->text('Contact') . qq|</th>
 
1429           <td>$form->{contact}</td>
 
1430           <td><input name="shiptocontact" size="35" value="$form->{shiptocontact}"></td>
 
1433           <th align="right" nowrap>| . $locale->text('Phone') . qq|</th>
 
1434           <td>$form->{phone}</td>
 
1435           <td><input name="shiptophone" size="20" value="$form->{shiptophone}"></td>
 
1438           <th align="right" nowrap>| . $locale->text('Fax') . qq|</th>
 
1439           <td>$form->{fax}</td>
 
1440           <td><input name="shiptofax" size="20" value="$form->{shiptofax}"></td>
 
1443           <th align="right" nowrap>| . $locale->text('E-mail') . qq|</th>
 
1444           <td>$form->{email}</td>
 
1445           <td><input name="shiptoemail" size="35" value="$form->{shiptoemail}"></td>
 
1451 | . $cgi->hidden("-name" => "nextsub", "-value" => $nextsub);
 
1457   map({ delete $form->{$_} } (@shipto_vars, qw(header)));
 
1458   $form->{title} = $title;
 
1460   foreach $key (keys %$form) {
 
1461     $form->{$key} =~ s/\"/"/g;
 
1462     print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
 
1467 <hr size="3" noshade>
 
1470 <input class="submit" type="submit" name="action" value="|
 
1471     . $locale->text('Continue') . qq|">
 
1478   $lxdebug->leave_sub();
 
1482   $lxdebug->enter_sub();
 
1487   $form->{old_callback} = $form->escape($form->{callback}, 1);
 
1488   $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
 
1489   $form->{old_callback} = $form->escape($form->{old_callback}, 1);
 
1492   delete $form->{action};
 
1493   $customer = $form->{customer};
 
1494   map { $form->{"old_$_"} = $form->{"${_}_$row"} } qw(partnumber description);
 
1496   # save all other form variables in a previousform variable
 
1497   $form->{row} = $row;
 
1498   foreach $key (keys %$form) {
 
1501     $form->{$key} =~ s/&/%26/g;
 
1502     $previousform .= qq|$key=$form->{$key}&|;
 
1505   $previousform = $form->escape($previousform, 1);
 
1507   $form->{script} = "licenses.pl";
 
1509   map { $form->{$_} = $form->{"old_$_"} } qw(partnumber description);
 
1510   map { $form->{$_} = $form->escape($form->{$_}, 1) }
 
1511     qw(partnumber description);
 
1513     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|;
 
1516   $lxdebug->leave_sub();
 
1519 sub relink_accounts {
 
1520   $lxdebug->enter_sub();
 
1522   $form->{"taxaccounts"} =~ s/\s*$//;
 
1523   $form->{"taxaccounts"} =~ s/^\s*//;
 
1524   foreach my $accno (split(/\s*/, $form->{"taxaccounts"})) {
 
1525     map({ delete($form->{"${accno}_${_}"}); } qw(rate description taxnumber));
 
1527   $form->{"taxaccounts"} = "";
 
1529   for (my $i = 1; $i <= $form->{"rowcount"}; $i++) {
 
1530     if ($form->{"id_$i"}) {
 
1531       IC->retrieve_accounts(\%myconfig, $form, $form->{"id_$i"}, $i, 1);
 
1535   $lxdebug->leave_sub();
 
1539   $lxdebug->enter_sub();
 
1541   $form->get_duedate(\%myconfig);
 
1544   $result = "$form->{duedate}";
 
1547   $lxdebug->leave_sub();