Uebernahme der kompletten Version, so wie sie Philip als "Demo-Version" gezeigt hat...
[kivitendo-erp.git] / bin / mozilla / io.pl
1 #=====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2004
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
11 #
12 #  Author: Dieter Simader
13 #   Email: dsimader@sql-ledger.org
14 #     Web: http://www.sql-ledger.org
15 #
16 #
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.
21 #
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.
29 #
30 #######################################################################
31 #
32 # common routines used in is, ir, oe
33 #
34 #######################################################################
35
36 # any custom scripts for this one
37 if (-f "$form->{path}/custom_io.pl") {
38   eval { require "$form->{path}/custom_io.pl"; };
39 }
40 if (-f "$form->{path}/$form->{login}_io.pl") {
41   eval { require "$form->{path}/$form->{login}_io.pl"; };
42 }
43
44 1;
45
46 # end of main
47
48 # this is for our long dates
49 # $locale->text('January')
50 # $locale->text('February')
51 # $locale->text('March')
52 # $locale->text('April')
53 # $locale->text('May ')
54 # $locale->text('June')
55 # $locale->text('July')
56 # $locale->text('August')
57 # $locale->text('September')
58 # $locale->text('October')
59 # $locale->text('November')
60 # $locale->text('December')
61
62 # this is for our short month
63 # $locale->text('Jan')
64 # $locale->text('Feb')
65 # $locale->text('Mar')
66 # $locale->text('Apr')
67 # $locale->text('May')
68 # $locale->text('Jun')
69 # $locale->text('Jul')
70 # $locale->text('Aug')
71 # $locale->text('Sep')
72 # $locale->text('Oct')
73 # $locale->text('Nov')
74 # $locale->text('Dec')
75 use SL::IS;
76 use SL::PE;
77 use SL::AM;
78 use Data::Dumper;
79 ########################################
80 # Eintrag fuer Version 2.2.0 geaendert #
81 # neue Optik im Rechnungsformular      #
82 ########################################
83 sub display_row {
84   $lxdebug->enter_sub();
85   my $numrows = shift;
86   if ($lizenzen && $form->{vc} eq "customer") {
87     if ($form->{type} =~ /sales_order/) {
88       @column_index = (runningnumber, partnumber, description, ship, qty);
89     } elsif ($form->{type} =~ /sales_quotation/) {
90       @column_index = (runningnumber, partnumber, description, qty);
91     } else {
92       @column_index = (runningnumber, partnumber, description, qty);
93     }
94   } else {
95     if (   ($form->{type} =~ /purchase_order/)
96         || ($form->{type} =~ /sales_order/)) {
97       @column_index = (runningnumber, partnumber, description, ship, qty);
98         } else {
99       @column_index = (runningnumber, partnumber, description, qty);
100     }
101   }
102 ############## ENDE Neueintrag ##################
103
104   my $dimension_units = AM->retrieve_units(\%myconfig, $form, "dimension");
105   my $service_units = AM->retrieve_units(\%myconfig, $form, "service");
106   my $all_units = AM->retrieve_units(\%myconfig, $form);
107
108   push @column_index, qw(unit);
109
110   #for pricegroups column
111   if (   $form->{type} =~ (/sales_quotation/)
112       or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/))
113       or (($form->{level} eq undef) and ($form->{type} =~ /invoice/))
114       or ($form->{type} =~ /sales_order/)) {
115     push @column_index, qw(sellprice_drag);
116   }
117
118   push @column_index, qw(sellprice);
119
120   if ($form->{vc} eq 'customer') {
121     push @column_index, qw(discount);
122   }
123
124   push @column_index, "linetotal";
125
126   my $colspan = $#column_index + 1;
127
128   $form->{invsubtotal} = 0;
129   map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
130
131 ########################################
132   # Eintrag fuer Version 2.2.0 geaendert #
133   # neue Optik im Rechnungsformular      #
134 ########################################
135   $column_data{runningnumber} =
136       qq|<th align=left nowrap width=5 class=listheading>|
137     . $locale->text('No.')
138     . qq|</th>|;
139   $column_data{partnumber} =
140       qq|<th align=left nowrap width=12 class=listheading>|
141     . $locale->text('Number')
142     . qq|</th>|;
143   $column_data{description} =
144       qq|<th align=left nowrap width=30 class=listheading>|
145     . $locale->text('Part Description')
146     . qq|</th>|;
147   $column_data{ship} =
148       qq|<th align=left nowrap width=5 class=listheading>|
149     . $locale->text('Ship')
150     . qq|</th>|;
151   $column_data{qty} =
152       qq|<th align=left nowrap width=5 class=listheading>|
153     . $locale->text('Qty')
154     . qq|</th>|;
155   $column_data{unit} =
156       qq|<th align=left nowrap width=5 class=listheading>|
157     . $locale->text('Unit')
158     . qq|</th>|;
159   $column_data{license} =
160       qq|<th align=left nowrap width=10 class=listheading>|
161     . $locale->text('License')
162     . qq|</th>|;
163   $column_data{serialnr} =
164       qq|<th align=left nowrap width=10 class=listheading>|
165     . $locale->text('Serial No.')
166     . qq|</th>|;
167   $column_data{projectnr} =
168       qq|<th align=left nowrap width=10 class=listheading>|
169     . $locale->text('Project')
170     . qq|</th>|;
171   $column_data{sellprice} =
172       qq|<th align=left nowrap width=15 class=listheading>|
173     . $locale->text('Price')
174     . qq|</th>|;
175   $column_data{sellprice_drag} =
176       qq|<th align=left nowrap width=15 class=listheading>|
177     . $locale->text('Pricegroup')
178     . qq|</th>|;
179   $column_data{discount} =
180       qq|<th align=left class=listheading>|
181     . $locale->text('Discount')
182     . qq|</th>|;
183   $column_data{linetotal} =
184       qq|<th align=left nowrap width=10 class=listheading>|
185     . $locale->text('Extended')
186     . qq|</th>|;
187   $column_data{bin} =
188       qq|<th align=left nowrap width=10 class=listheading>|
189     . $locale->text('Bin')
190     . qq|</th>|;
191 ############## ENDE Neueintrag ##################
192
193   print qq|
194   <tr>
195     <td>
196       <table width=100%>
197         <tr class=listheading>|;
198
199   map { print "\n$column_data{$_}" } @column_index;
200
201   print qq|
202         </tr>
203 |;
204
205   $runningnumber = $locale->text('No.');
206   $deliverydate  = $locale->text('Delivery Date');
207   $serialnumber  = $locale->text('Serial No.');
208   $projectnumber = $locale->text('Project');
209   $partsgroup    = $locale->text('Group');
210   $reqdate       = $locale->text('Reqdate');
211
212   $delvar = 'deliverydate';
213
214   if ($form->{type} =~ /_order$/ || $form->{type} =~ /_quotation$/) {
215     $deliverydate = $locale->text('Required by');
216     $delvar       = 'reqdate';
217   }
218
219   for $i (1 .. $numrows) {
220
221     # undo formatting
222     map {
223       $form->{"${_}_$i"} =
224         $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
225     } qw(qty ship discount sellprice price_new price_old) unless ($form->{simple_save});
226
227     if (!$form->{"unit_old_$i"}) {
228       # Neue Ware aus der Datenbank. In diesem Fall ist unit_$i die
229       # Einheit, wie sie in den Stammdaten hinterlegt wurde.
230       # Es sollte also angenommen werden, dass diese ausgewaehlt war.
231       $form->{"unit_old_$i"} = $form->{"unit_$i"};
232     }
233
234
235
236     # Die zuletzt ausgewaehlte mit der aktuell ausgewaehlten Einheit
237     # vergleichen und bei Unterschied den Preis entsprechend umrechnen.
238     $form->{"selected_unit_$i"} = $form->{"unit_$i"} unless ($form->{"selected_unit_$i"});
239
240     my $check_units = $form->{"inventory_accno_$i"} ? $dimension_units : $service_units;
241     if (!$check_units->{$form->{"selected_unit_$i"}} ||
242         ($check_units->{$form->{"selected_unit_$i"}}->{"base_unit"} ne
243          $all_units->{$form->{"unit_old_$i"}}->{"base_unit"})) {
244       # Die ausgewaehlte Einheit ist fuer diesen Artikel nicht gueltig
245       # (z.B. Dimensionseinheit war ausgewaehlt, es handelt sich aber
246       # um eine Dienstleistung). Dann keinerlei Umrechnung vornehmen.
247       $form->{"unit_old_$i"} = $form->{"selected_unit_$i"} = $form->{"unit_$i"};
248     }
249     if ((!$form->{"prices_$i"}) || ($form->{"new_pricegroup_$i"} == $form->{"old_pricegroup_$i"})) {
250       if ($form->{"unit_old_$i"} ne $form->{"selected_unit_$i"}) {
251         my $basefactor = 1;
252         if (defined($all_units->{$form->{"unit_old_$i"}}->{"factor"}) &&
253             $all_units->{$form->{"unit_old_$i"}}->{"factor"}) {
254           $basefactor = $all_units->{$form->{"selected_unit_$i"}}->{"factor"} /
255             $all_units->{$form->{"unit_old_$i"}}->{"factor"};
256         }
257         $form->{"sellprice_$i"} *= $basefactor;
258         $form->{"unit_old_$i"} = $form->{"selected_unit_$i"};
259       }
260     }
261     ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
262     $dec           = length $dec;
263     $decimalplaces = ($dec > 2) ? $dec : 2;
264
265     $discount =
266       $form->round_amount(
267                         $form->{"sellprice_$i"} * $form->{"discount_$i"} / 100,
268                         $decimalplaces);
269
270     $linetotal =
271       $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
272     $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
273
274     # convert " to &quot;
275     map { $form->{"${_}_$i"} =~ s/\"/&quot;/g }
276       qw(partnumber description unit unit_old);
277
278 ########################################
279     # Eintrag fuer Version 2.2.0 geaendert #
280     # neue Optik im Rechnungsformular      #
281 ########################################
282     $column_data{runningnumber} =
283       qq|<td><input name="runningnumber_$i" size=5 value=$i></td>|;    # HuT
284 ############## ENDE Neueintrag ##################
285
286     $column_data{partnumber} =
287       qq|<td><input name="partnumber_$i" size=12 value="$form->{"partnumber_$i"}"></td>|;
288
289     if (($rows = $form->numtextrows($form->{"description_$i"}, 30, 6)) > 1) {
290       $column_data{description} =
291         qq|<td><textarea name="description_$i" rows=$rows cols=30 wrap=soft>$form->{"description_$i"}</textarea><button type="button" onclick="set_longdescription_window('longdescription_$i')">| . $locale->text('L') . qq|</button></td>|;
292     } else {
293       $column_data{description} =
294         qq|<td><input name="description_$i" size=30 value="$form->{"description_$i"}"><button type="button" onclick="set_longdescription_window('longdescription_$i')">| . $locale->text('L') . qq|</button></td>|;
295     }
296
297     (my $qty_dec) = ($form->{"qty_$i"} =~ /\.(\d+)/);
298     $qty_dec = length $qty_dec;
299
300     $column_data{qty} =
301         qq|<td align=right><input name="qty_$i" size=5 value=|
302       . $form->format_amount(\%myconfig, $form->{"qty_$i"}, $qty_dec) .qq|>|;
303     if ($form->{formel}) {
304     $column_data{qty} .= qq|<button type="button" onclick="calculate_qty_selection_window('qty_$i','alu_$i', 'formel_$i', $i)">| . $locale->text('*/') . qq|</button>
305           <input type=hidden name="formel_$i" value="$form->{"formel_$i"}"><input type=hidden name="alu_$i" value="$form->{"alu_$i"}"></td>|;
306     }
307     $column_data{ship} =
308         qq|<td align=right><input name="ship_$i" size=5 value=|
309       . $form->format_amount(\%myconfig, $form->{"ship_$i"})
310       . qq|></td>|;
311
312     my $is_part = $form->{"inventory_accno_$i"};
313     my $is_assigned = $form->{"id_$i"};
314     my $this_unit = $form->{"unit_$i"};
315     if ($form->{"selected_unit_$i"} && $this_unit &&
316         $all_units->{$form->{"selected_unit_$i"}} && $all_units->{$this_unit} &&
317         ($all_units->{$form->{"selected_unit_$i"}}->{"base_unit"} eq $all_units->{$this_unit}->{"base_unit"})) {
318       $this_unit = $form->{"selected_unit_$i"};
319     } elsif (!$is_assigned ||
320              ($is_part && !$this_unit && ($all_units->{$this_unit} && ($all_units->{$this_unit}->{"base_unit"} eq $all_units->{"kg"}->{"base_unit"})))) {
321       $this_unit = "kg";
322     }
323
324     $column_data{"unit"} = "<td>" .
325       ($qty_readonly ? "&nbsp;" :
326        AM->unit_select_html($is_part ? $dimension_units :
327                             $is_assigned ? $service_units : $all_units,
328                             "unit_$i", $this_unit,
329                             $is_assigned ? $form->{"unit_$i"} : undef))
330       . "</td>";
331
332     # build in dragdrop for pricesgroups
333     if ($form->{"prices_$i"}) {
334       if  ($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"}) {
335         $price_tmp = $form->format_amount(\%myconfig, $form->{"price_new_$i"}, $decimalplaces);
336       } else {
337         $price_tmp = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
338       }
339
340       $column_data{sellprice_drag} =
341         qq|<td align=right><select name="sellprice_drag_$i">$form->{"prices_$i"}</select></td>|;
342       $column_data{sellprice} =
343         qq|<td><input name="sellprice_$i" size=10 value=$price_tmp></td>|;
344     } else {
345
346       # for last row and report
347       # set pricegroup dragdrop from report menu
348       if ($form->{"sellprice_$i"} != 0) {
349         $prices =
350           qq|<option value="$form->{"sellprice_$i"}--$form->{"pricegroup_id_$i"}" selected>$form->{"pricegroup_$i"}</option>\n|;
351
352         $form->{"pricegroup_old_$i"} = $form->{"pricegroup_id_$i"};
353
354         $column_data{sellprice_drag} =
355           qq|<td align=right><select name="sellprice_drag_$i">$prices</select></td>|;
356
357       } else {
358
359         # for last row
360         $column_data{sellprice_drag} =
361           qq|<td align=right><input name="sellprice_$i" size=9 value=|
362           . $form->format_amount(\%myconfig, $form->{"prices_$i"},
363                                  $decimalplaces)
364           . qq|></td>|;
365       }
366     print(STDERR "Sellprice vor Ausgabe: ",$form->{"sellprice_$i"},"\n"); 
367
368       $column_data{sellprice} =
369         qq|<td><input name="sellprice_$i" size=10 value=|
370         . $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
371                                $decimalplaces)
372         . qq|></td>|;
373     }
374     $column_data{discount} =
375         qq|<td align=right><input name="discount_$i" size=3 value=|
376       . $form->format_amount(\%myconfig, $form->{"discount_$i"})
377       . qq|></td>|;
378     $column_data{linetotal} =
379         qq|<td align=right>|
380       . $form->format_amount(\%myconfig, $linetotal, 2)
381       . qq|</td>|;
382     $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
383
384 ########################################
385     # Eintrag fuer Version 2.2.0 geaendert #
386     # neue Optik im Rechnungsformular      #
387 ########################################
388     #     if ($lizenzen &&  $form->{type} eq "invoice" &&  $form->{vc} eq "customer") {
389     #     $column_data{license} = qq|<td><select name="licensenumber_$i">$form->{"lizenzen_$i"}></select></td>|;
390     #     }
391     #
392     #     if ($form->{type} !~ /_quotation/) {
393     #     $column_data{serialnr} = qq|<td><input name="serialnumber_$i" size=10 value="$form->{"serialnumber_$i"}"></td>|;
394     #     }
395     #
396     #     $column_data{projectnr} = qq|<td><input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}"></td>|;
397 ############## ENDE Neueintrag ##################
398     my $j = $i % 2;
399     print qq|
400
401         <tr valign=top class=listrow$j>|;
402
403     map { print "\n$column_data{$_}" } @column_index;
404
405     print qq|
406         </tr>
407
408 <input type=hidden name="orderitems_id_$i" value=$form->{"orderitems_id_$i"}>
409 <input type=hidden name="bo_$i" value=$form->{"bo_$i"}>
410
411 <input type=hidden name="pricegroup_old_$i" value=$form->{"pricegroup_old_$i"}>
412 <input type=hidden name="price_old_$i" value=$form->{"price_old_$i"}>
413 <input type=hidden name="unit_old_$i" value="$form->{"selected_unit_$i"}">
414 <input type=hidden name="price_new_$i" value=|
415       . $form->format_amount(\%myconfig, $form->{"price_new_$i"}) . qq|>
416
417 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
418 <input type=hidden name="inventory_accno_$i" value=$form->{"inventory_accno_$i"}>
419 <input type=hidden name="bin_$i" value="$form->{"bin_$i"}">
420 <input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">
421 <input type=hidden name="partnotes_$i" value="$form->{"partnotes_$i"}">
422 <input type=hidden name="income_accno_$i" value=$form->{"income_accno_$i"}>
423 <input type=hidden name="expense_accno_$i" value=$form->{"expense_accno_$i"}>
424 <input type=hidden name="listprice_$i" value="$form->{"listprice_$i"}">
425 <input type=hidden name="assembly_$i" value="$form->{"assembly_$i"}">
426 <input type=hidden name="taxaccounts_$i" value="$form->{"taxaccounts_$i"}">
427 <input type=hidden name="ordnumber_$i" value="$form->{"ordnumber_$i"}">
428 <input type=hidden name="transdate_$i" value="$form->{"transdate_$i"}">
429 <input type=hidden name="cusordnumber_$i" value="$form->{"cusordnumber_$i"}">
430 <input type=hidden name="longdescription_$i" value="$form->{"longdescription_$i"}">
431 <input type=hidden name="basefactor_$i" value="$form->{"basefactor_$i"}">
432 <input type=hidden name="adr_description_$i" value="$form->{"adr_description_$i"}">
433
434 |;
435
436 ########################################
437     # Eintrag fuer Version 2.2.0 geaendert #
438     # neue Optik im Rechnungsformular      #
439 ########################################
440     # print second row
441     print qq|
442         <tr  class=listrow$j>
443           <td colspan=$colspan>
444 |;
445     if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
446       my $selected = $form->{"licensenumber_$i"};
447       my $lizenzen_quoted;
448       $form->{"lizenzen_$i"} =~ s/ selected//g;
449       $form->{"lizenzen_$i"} =~
450         s/value="${selected}"\>/value="${selected}" selected\>/;
451       $lizenzen_quoted = $form->{"lizenzen_$i"};
452       $lizenzen_quoted =~ s/\"/&quot;/g;
453       print qq|
454         <b>Lizenz\#</b>&nbsp;<select name="licensenumber_$i" size=1>
455         $form->{"lizenzen_$i"}
456         </select>
457         <input type=hidden name="lizenzen_$i" value="${lizenzen_quoted}">
458 |;
459     }
460     if ($form->{type} !~ /_quotation/) {
461       print qq|
462           <b>$serialnumber</b>&nbsp;<input name="serialnumber_$i" size=15 value="$form->{"serialnumber_$i"}">|;
463     }
464
465     print qq|
466           <b>$projectnumber</b>&nbsp;<input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}">
467                   <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}">
468                   <input type=hidden name="project_id_$i" value="$form->{"project_id_$i"}">
469 |;
470     if ($form->{type} eq 'invoice' or $form->{type} =~ /order/) {
471       my $reqdate_term =
472         ($form->{type} eq 'invoice')
473         ? 'deliverydate'
474         : 'reqdate';    # invoice uses a different term for the same thing.
475       print qq|
476         <b>${$reqdate_term}</b>&nbsp;<input name="${reqdate_term}_$i" size=11 value="$form->{"${reqdate_term}_$i"}">
477 |;
478     }
479     my $subtotalchecked = ($form->{"subtotal_$i"}) ? "checked" : "";
480     print qq|
481           <b>|.$locale->text('Subtotal').qq|</b>&nbsp;<input type="checkbox" name="subtotal_$i" value="1" "$subtotalchecked">
482           </td>
483         </tr>
484
485 |;
486
487 ############## ENDE Neueintrag ##################
488
489     map { $form->{"${_}_base"} += $linetotal }
490       (split / /, $form->{"taxaccounts_$i"});
491
492     $form->{invsubtotal} += $linetotal;
493   }
494
495   print qq|
496       </table>
497     </td>
498   </tr>
499 |;
500
501   $lxdebug->leave_sub();
502 }
503
504 ##################################################
505 # build html-code for pricegroups in variable $form->{prices_$j}
506
507 sub set_pricegroup {
508   my $rowcount = shift;
509   $lxdebug->enter_sub();
510   for $j (1 .. $rowcount) {
511     my $pricegroup_old = $form->{"pricegroup_old_$i"};
512     if ($form->{PRICES}{$j}) {
513       $len    = 0;
514       $prices = '';
515       $price  = 0;
516       foreach $item (@{ $form->{PRICES}{$j} }) {
517
518         #$price = $form->round_amount($myconfig,  $item->{price}, 5);
519         #$price = $form->format_amount($myconfig, $item->{price}, 2);
520         $price         = $item->{price};
521         $pricegroup_id = $item->{pricegroup_id};
522         $pricegroup    = $item->{pricegroup};
523
524         # build dragdrop for pricegroups
525         $prices .=
526           qq|<option value="$price--$pricegroup_id"$item->{selected}>$pricegroup</option>\n|;
527
528         $len += 1;
529
530         #        map {
531         #               $form->{"${_}_$j"} =
532         #               $form->format_amount(\%myconfig, $form->{"${_}_$j"})
533         #              } qw(sellprice price_new price_old);
534
535         # set new selectedpricegroup_id and prices for "Preis"
536         if ($item->{selected} && ($pricegroup_id != 0)) {
537           $form->{"pricegroup_old_$j"} = $pricegroup_id;
538           $form->{"price_new_$j"}      = $price;
539           $form->{"sellprice_$j"}      = $price;
540         }
541         if ($pricegroup_id == 0) {
542           $form->{"price_new_$j"} = $form->{"sellprice_$j"};
543         }
544         if ($len > 1) {
545           $form->{"prices_$j"} = $prices;
546         }
547       }
548     }
549   }
550   $lxdebug->leave_sub();
551 }
552
553 sub select_item {
554   $lxdebug->enter_sub();
555   @column_index = qw(ndx partnumber description onhand sellprice);
556
557   $column_data{ndx}        = qq|<th>&nbsp;</th>|;
558   $column_data{partnumber} =
559     qq|<th class=listheading>| . $locale->text('Number') . qq|</th>|;
560   $column_data{description} =
561     qq|<th class=listheading>| . $locale->text('Part Description') . qq|</th>|;
562   $column_data{sellprice} =
563     qq|<th class=listheading>| . $locale->text('Price') . qq|</th>|;
564   $column_data{onhand} =
565     qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
566
567   # list items with radio button on a form
568   $form->header;
569
570   $title   = $locale->text('Select from one of the items below');
571   $colspan = $#column_index + 1;
572
573   print qq|
574 <body>
575
576 <form method=post action=$form->{script}>
577
578 <table width=100%>
579   <tr>
580     <th class=listtop colspan=$colspan>$title</th>
581   </tr>
582   <tr height="5"></tr>
583   <tr class=listheading>|;
584
585   map { print "\n$column_data{$_}" } @column_index;
586
587   print qq|</tr>|;
588
589   my $i = 0;
590   foreach $ref (@{ $form->{item_list} }) {
591     $checked = ($i++) ? "" : "checked";
592
593     if ($lizenzen) {
594       if ($ref->{inventory_accno} > 0) {
595         $ref->{"lizenzen"} = qq|<option></option>|;
596         foreach $item (@{ $form->{LIZENZEN}{ $ref->{"id"} } }) {
597           $ref->{"lizenzen"} .=
598             qq|<option value=\"$item->{"id"}\">$item->{"licensenumber"}</option>|;
599         }
600         $ref->{"lizenzen"} .= qq|<option value=-1>Neue Lizenz</option>|;
601         $ref->{"lizenzen"} =~ s/\"/&quot;/g;
602       }
603     }
604
605     map { $ref->{$_} =~ s/\"/&quot;/g } qw(partnumber description unit);
606
607     #sk tradediscount
608     $ref->{sellprice} =
609       $form->round_amount($ref->{sellprice} * (1 - $form->{tradediscount}), 2);
610     $column_data{ndx} =
611       qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
612     $column_data{partnumber} =
613       qq|<td><input name="new_partnumber_$i" type=hidden value="$ref->{partnumber}">$ref->{partnumber}</td>|;
614     $column_data{description} =
615       qq|<td><input name="new_description_$i" type=hidden value="$ref->{description}">$ref->{description}</td>|;
616     $column_data{sellprice} =
617       qq|<td align=right><input name="new_sellprice_$i" type=hidden value=$ref->{sellprice}>|
618       . $form->format_amount(\%myconfig, $ref->{sellprice}, 2, "&nbsp;")
619       . qq|</td>|;
620     $column_data{onhand} =
621       qq|<td align=right><input name="new_onhand_$i" type=hidden value=$ref->{onhand}>|
622       . $form->format_amount(\%myconfig, $ref->{onhand}, '', "&nbsp;")
623       . qq|</td>|;
624
625     $j++;
626     $j %= 2;
627     print qq|
628 <tr class=listrow$j>|;
629
630     map { print "\n$column_data{$_}" } @column_index;
631
632     print qq|
633 </tr>
634
635 <input name="new_bin_$i" type=hidden value="$ref->{bin}">
636 <input name="new_listprice_$i" type=hidden value=$ref->{listprice}>
637 <input name="new_inventory_accno_$i" type=hidden value=$ref->{inventory_accno}>
638 <input name="new_income_accno_$i" type=hidden value=$ref->{income_accno}>
639 <input name="new_expense_accno_$i" type=hidden value=$ref->{expense_accno}>
640 <input name="new_unit_$i" type=hidden value="$ref->{unit}">
641 <input name="new_weight_$i" type=hidden value="$ref->{weight}">
642 <input name="new_assembly_$i" type=hidden value="$ref->{assembly}">
643 <input name="new_taxaccounts_$i" type=hidden value="$ref->{taxaccounts}">
644 <input name="new_partsgroup_$i" type=hidden value="$ref->{partsgroup}">
645 <input name="new_formel_$i" type=hidden value="$ref->{formel}">
646 <input name="new_alu_$i" type=hidden value="$ref->{alu}">
647 <input name="new_longdescription_$i" type=hidden value="$ref->{longdescription}">
648 <input name="new_not_discountable_$i" type=hidden value="$ref->{not_discountable}">
649 <input name="new_part_payment_id_$i" type=hidden value="$ref->{part_payment_id}">
650 <input name="new_adr_description_$i" type=hidden value="$ref->{adr_description}">
651
652 <input name="new_id_$i" type=hidden value=$ref->{id}>
653
654 |;
655     if ($lizenzen) {
656       print qq|
657 <input name="new_lizenzen_$i" type=hidden value="$ref->{lizenzen}">
658 |;
659     }
660
661   }
662
663   print qq|
664 <tr><td colspan=8><hr size=3 noshade></td></tr>
665 </table>
666
667 <input name=lastndx type=hidden value=$i>
668
669 |;
670
671   # delete action variable
672   map { delete $form->{$_} } qw(action item_list header);
673
674   # save all other form variables
675   foreach $key (keys %${form}) {
676     $form->{$key} =~ s/\"/&quot;/g;
677     print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
678   }
679
680   print qq|
681 <input type=hidden name=nextsub value=item_selected>
682
683 <br>
684 <input class=submit type=submit name=action value="|
685     . $locale->text('Continue') . qq|">
686 </form>
687
688 </body>
689 </html>
690 |;
691
692   $lxdebug->leave_sub();
693 }
694
695 sub item_selected {
696   $lxdebug->enter_sub();
697
698   # replace the last row with the checked row
699   $i = $form->{rowcount};
700   $i = $form->{assembly_rows} if ($form->{item} eq 'assembly');
701
702   # index for new item
703   $j = $form->{ndx};
704
705   #sk
706   #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
707   #$form->{"sellprice_$i"} = $form->{"sellprice_$i"};
708
709   # if there was a price entered, override it
710   $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
711
712   map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} }
713     qw(id partnumber description sellprice listprice inventory_accno income_accno expense_accno bin unit weight assembly taxaccounts partsgroup formel alu longdescription not_discountable adr_description);
714   if ($form->{"part_payment_id_$i"} ne "") {
715     $form->{payment_id} = $form->{"part_payment_id_$i"};
716   }
717
718   if ($lizenzen) {
719     map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } qw(lizenzen);
720   }
721
722   ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
723   $dec           = length $dec;
724   $decimalplaces = ($dec > 2) ? $dec : 2;
725
726   if ($sellprice) {
727     $form->{"sellprice_$i"} = $sellprice;
728   } else {
729
730     # if there is an exchange rate adjust sellprice
731     if (($form->{exchangerate} * 1) != 0) {
732       $form->{"sellprice_$i"} /= $form->{exchangerate};
733       $form->{"sellprice_$i"} =
734         $form->round_amount($form->{"sellprice_$i"}, $decimalplaces);
735     }
736   }
737
738   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
739     qw(sellprice listprice weight);
740
741   $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
742   $form->{weight}    += ($form->{"weight_$i"} * $form->{"qty_$i"});
743   
744   if ($form->{"not_discountable_$i"}) {
745     $form->{"discount_$i"} = 0;
746   }
747
748   $amount =
749     $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) *
750     $form->{"qty_$i"};
751   map { $form->{"${_}_base"} += $amount }
752     (split / /, $form->{"taxaccounts_$i"});
753   map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /,
754     $form->{"taxaccounts_$i"}
755     if !$form->{taxincluded};
756
757   $form->{creditremaining} -= $amount;
758
759   $form->{"runningnumber_$i"} = $i;
760
761   # delete all the new_ variables
762   for $i (1 .. $form->{lastndx}) {
763     map { delete $form->{"new_${_}_$i"} }
764       qw(partnumber description sellprice bin listprice inventory_accno income_accno expense_accno unit assembly taxaccounts id);
765   }
766
767   map { delete $form->{$_} } qw(ndx lastndx nextsub);
768
769   # format amounts
770   map {
771     $form->{"${_}_$i"} =
772       $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces)
773   } qw(sellprice listprice) if $form->{item} ne 'assembly';
774
775   # get pricegroups for parts
776   IS->get_pricegroups_for_parts(\%myconfig, \%$form);
777
778   # build up html code for prices_$i
779   set_pricegroup($form->{rowcount});
780
781   &display_form;
782
783   $lxdebug->leave_sub();
784 }
785
786 sub new_item {
787   $lxdebug->enter_sub();
788
789   # change callback
790   $form->{old_callback} = $form->escape($form->{callback}, 1);
791   $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
792
793   # delete action
794   delete $form->{action};
795
796   # save all other form variables in a previousform variable
797   foreach $key (keys %$form) {
798
799     # escape ampersands
800     $form->{$key} =~ s/&/%26/g;
801     $previousform .= qq|$key=$form->{$key}&|;
802   }
803   chop $previousform;
804   $previousform = $form->escape($previousform, 1);
805
806   $i = $form->{rowcount};
807   map { $form->{"${_}_$i"} =~ s/\"/&quot;/g } qw(partnumber description);
808
809   $form->header;
810
811   print qq|
812 <body>
813
814 <h4 class=error>| . $locale->text('Item not on file!') . qq|
815
816 <p>
817 | . $locale->text('What type of item is this?') . qq|</h4>
818
819 <form method=post action=ic.pl>
820
821 <p>
822
823   <input class=radio type=radio name=item value=part checked>&nbsp;|
824     . $locale->text('Part') . qq|<br>
825   <input class=radio type=radio name=item value=service>&nbsp;|
826     . $locale->text('Service')
827
828     . qq|
829 <input type=hidden name=previousform value="$previousform">
830 <input type=hidden name=partnumber value="$form->{"partnumber_$i"}">
831 <input type=hidden name=description value="$form->{"description_$i"}">
832 <input type=hidden name=rowcount value=$form->{rowcount}>
833 <input type=hidden name=taxaccount2 value=$form->{taxaccounts}>
834 <input type=hidden name=vc value=$form->{vc}>
835
836 <input type=hidden name=path value=$form->{path}>
837 <input type=hidden name=login value=$form->{login}>
838 <input type=hidden name=password value=$form->{password}>
839
840 <input type=hidden name=nextsub value=add>
841
842 <p>
843 <input class=submit type=submit name=action value="|
844     . $locale->text('Continue') . qq|">
845 </form>
846
847 </body>
848 </html>
849 |;
850
851   $lxdebug->leave_sub();
852 }
853
854 sub display_form {
855   $lxdebug->enter_sub();
856   $form->language_payment(\%myconfig);
857
858   # if we have a display_form
859   if ($form->{display_form}) {
860     &{"$form->{display_form}"};
861     exit;
862   }
863
864   #   if (   $form->{print_and_post}
865   #       && $form->{second_run}
866   #       && ($form->{action} eq "display_form")) {
867   #     for (keys %$form) { $old_form->{$_} = $form->{$_} }
868   #     $old_form->{rowcount}++;
869   #
870   #     #$form->{rowcount}--;
871   #     #$form->{rowcount}--;
872   #
873   #     $form->{print_and_post} = 0;
874   #
875   #     &print_form($old_form);
876   #     exit;
877   #   }
878   #
879   #   $form->{action}   = "";
880   #   $form->{resubmit} = 0;
881   #
882   #   if ($form->{print_and_post} && !$form->{second_run}) {
883   #     $form->{second_run} = 1;
884   #     $form->{action}     = "display_form";
885   #     $form->{rowcount}--;
886   #     my $rowcount = $form->{rowcount};
887   #
888   #     # get pricegroups for parts
889   #     IS->get_pricegroups_for_parts(\%myconfig, \%$form);
890   #
891   #     # build up html code for prices_$i
892   #     set_pricegroup($rowcount);
893   #
894   #     $form->{resubmit} = 1;
895   #
896   #   }
897   &form_header;
898
899   $numrows    = ++$form->{rowcount};
900   $subroutine = "display_row";
901
902   if ($form->{item} eq 'part') {
903
904     #set preisgruppenanzahl
905     $numrows    = $form->{price_rows};
906     $subroutine = "price_row";
907
908     &{$subroutine}($numrows);
909
910     $numrows    = ++$form->{makemodel_rows};
911     $subroutine = "makemodel_row";
912   }
913   if ($form->{item} eq 'assembly') {
914     $numrows    = $form->{price_rows};
915     $subroutine = "price_row";
916
917     &{$subroutine}($numrows);
918
919     $numrows    = ++$form->{makemodel_rows};
920     $subroutine = "makemodel_row";
921
922     # create makemodel rows
923     &{$subroutine}($numrows);
924
925     $numrows    = ++$form->{assembly_rows};
926     $subroutine = "assembly_row";
927   }
928   if ($form->{item} eq 'service') {
929     $numrows    = $form->{price_rows};
930     $subroutine = "price_row";
931
932     &{$subroutine}($numrows);
933
934     $numrows = 0;
935   }
936
937   # create rows
938   &{$subroutine}($numrows) if $numrows;
939
940   &form_footer;
941
942   $lxdebug->leave_sub();
943 }
944
945 sub check_form {
946   $lxdebug->enter_sub();
947   my @a     = ();
948   my $count = 0;
949   my @flds  = (
950     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 adr_id language_values)
951   );
952
953
954   # remove any makes or model rows
955   if ($form->{item} eq 'part') {
956     map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
957       qw(listprice sellprice lastcost weight rop);
958
959     @flds = (make, model);
960     for my $i (1 .. ($form->{makemodel_rows})) {
961       if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
962         push @a, {};
963         my $j = $#a;
964
965         map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
966         $count++;
967       }
968     }
969
970     $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
971     $form->{makemodel_rows} = $count;
972
973   } elsif ($form->{item} eq 'assembly') {
974
975     $form->{sellprice} = 0;
976     $form->{weight}    = 0;
977     map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
978       qw(listprice rop stock);
979
980     @flds =
981       qw(id qty unit bom partnumber description sellprice weight runningnumber partsgroup);
982
983     for my $i (1 .. ($form->{assembly_rows} - 1)) {
984       if ($form->{"qty_$i"}) {
985         push @a, {};
986         my $j = $#a;
987
988         $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
989
990         map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
991
992         #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
993
994         $form->{sellprice} += ($form->{"qty_$i"} * $form->{"sellprice_$i"});
995         $form->{weight}    += ($form->{"qty_$i"} * $form->{"weight_$i"});
996         $count++;
997       }
998     }
999
1000     $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
1001
1002     $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
1003     $form->{assembly_rows} = $count;
1004
1005     $count = 0;
1006     @flds  = qw(make model);
1007     @a     = ();
1008
1009     for my $i (1 .. ($form->{makemodel_rows})) {
1010       if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
1011         push @a, {};
1012         my $j = $#a;
1013
1014         map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1015         $count++;
1016       }
1017     }
1018
1019     $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
1020     $form->{makemodel_rows} = $count;
1021
1022   } else {
1023
1024     # this section applies to invoices and orders
1025     # remove any empty numbers
1026     if ($form->{rowcount}) {
1027       for my $i (1 .. $form->{rowcount} - 1) {
1028         if ($form->{"partnumber_$i"}) {
1029           push @a, {};
1030           my $j = $#a;
1031
1032           map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1033           $count++;
1034           if ($lizenzen) {
1035             if ($form->{"licensenumber_$i"} == -1) {
1036               &new_license($i);
1037               exit;
1038             }
1039           }
1040         }
1041       }
1042
1043       $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
1044       $form->{rowcount} = $count;
1045
1046       $form->{creditremaining} -= &invoicetotal;
1047
1048     }
1049   }
1050
1051   #sk
1052   # if pricegroups
1053   if (   $form->{type} =~ (/sales_quotation/)
1054       or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/))
1055       or (($form->{level} eq undef) and ($form->{type} =~ /invoice/))
1056       or ($form->{type} =~ /sales_order/)) {
1057
1058     # get pricegroups for parts
1059     IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1060
1061     # build up html code for prices_$i
1062     set_pricegroup($form->{rowcount});
1063
1064   }
1065
1066   &display_form;
1067
1068   $lxdebug->leave_sub();
1069 }
1070
1071 sub invoicetotal {
1072   $lxdebug->enter_sub();
1073
1074   $form->{oldinvtotal} = 0;
1075
1076   # add all parts and deduct paid
1077   map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
1078
1079   my ($amount, $sellprice, $discount, $qty);
1080
1081   for my $i (1 .. $form->{rowcount}) {
1082     $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1083     $discount  = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
1084     $qty       = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
1085
1086     #($form->{"sellprice_$i"}, $form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
1087
1088     $amount = $sellprice * (1 - $discount / 100) * $qty;
1089     map { $form->{"${_}_base"} += $amount }
1090       (split / /, $form->{"taxaccounts_$i"});
1091     $form->{oldinvtotal} += $amount;
1092   }
1093
1094   map { $form->{oldinvtotal} += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1095     split / /, $form->{taxaccounts}
1096     if !$form->{taxincluded};
1097
1098   $form->{oldtotalpaid} = 0;
1099   for $i (1 .. $form->{paidaccounts}) {
1100     $form->{oldtotalpaid} += $form->{"paid_$i"};
1101   }
1102
1103   $lxdebug->leave_sub();
1104
1105   # return total
1106   return ($form->{oldinvtotal} - $form->{oldtotalpaid});
1107 }
1108
1109 sub validate_items {
1110   $lxdebug->enter_sub();
1111
1112   # check if items are valid
1113   if ($form->{rowcount} == 1) {
1114     &update;
1115     exit;
1116   }
1117
1118   for $i (1 .. $form->{rowcount} - 1) {
1119     $form->isblank("partnumber_$i",
1120                    $locale->text('Number missing in Row') . " $i");
1121   }
1122
1123   $lxdebug->leave_sub();
1124 }
1125
1126 sub order {
1127   $lxdebug->enter_sub();
1128   if ($form->{second_run}) {
1129     $form->{print_and_post} = 0;
1130   }
1131   $form->{ordnumber} = $form->{invnumber};
1132
1133   map { delete $form->{$_} } qw(id printed emailed queued);
1134   if ($form->{script} eq 'ir.pl' || $form->{type} eq 'request_quotation') {
1135     $form->{title} = $locale->text('Add Purchase Order');
1136     $form->{vc}    = 'vendor';
1137     $form->{type}  = 'purchase_order';
1138     $buysell       = 'sell';
1139   }
1140   if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_quotation') {
1141     $form->{title} = $locale->text('Add Sales Order');
1142     $form->{vc}    = 'customer';
1143     $form->{type}  = 'sales_order';
1144     $buysell       = 'buy';
1145   }
1146   $form->{script} = 'oe.pl';
1147
1148   $form->{shipto} = 1;
1149
1150   $form->{rowcount}--;
1151
1152   $form->{cp_id} *= 1;
1153
1154   require "$form->{path}/$form->{script}";
1155
1156   map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1157
1158   $currency = $form->{currency};
1159
1160   &order_links;
1161
1162   $form->{currency}     = $currency;
1163   $form->{exchangerate} = "";
1164   $form->{forex}        = "";
1165   $form->{exchangerate} = $exchangerate
1166     if (
1167         $form->{forex} = (
1168                   $exchangerate =
1169                     $form->check_exchangerate(
1170                     \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1171                     )));
1172
1173   &prepare_order;
1174   &display_form;
1175
1176   $lxdebug->leave_sub();
1177 }
1178
1179 sub quotation {
1180   $lxdebug->enter_sub();
1181   if ($form->{second_run}) {
1182     $form->{print_and_post} = 0;
1183   }
1184   map { delete $form->{$_} } qw(id printed emailed queued);
1185
1186   if ($form->{script} eq 'ir.pl' || $form->{type} eq 'purchase_order') {
1187     $form->{title} = $locale->text('Add Request for Quotation');
1188     $form->{vc}    = 'vendor';
1189     $form->{type}  = 'request_quotation';
1190     $buysell       = 'sell';
1191   }
1192   if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_order') {
1193     $form->{title} = $locale->text('Add Quotation');
1194     $form->{vc}    = 'customer';
1195     $form->{type}  = 'sales_quotation';
1196     $buysell       = 'buy';
1197   }
1198
1199   $form->{cp_id} *= 1;
1200
1201   $form->{script} = 'oe.pl';
1202
1203   $form->{shipto} = 1;
1204
1205   $form->{rowcount}--;
1206
1207   require "$form->{path}/$form->{script}";
1208
1209   map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1210
1211   $currency = $form->{currency};
1212
1213   &order_links;
1214
1215   $form->{currency}     = $currency;
1216   $form->{exchangerate} = "";
1217   $form->{forex}        = "";
1218   $form->{exchangerate} = $exchangerate
1219     if (
1220         $form->{forex} = (
1221                   $exchangerate =
1222                     $form->check_exchangerate(
1223                     \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1224                     )));
1225
1226   &prepare_order;
1227   &display_form;
1228
1229   $lxdebug->leave_sub();
1230 }
1231
1232 sub e_mail {
1233   $lxdebug->enter_sub();
1234   if ($form->{second_run}) {
1235     $form->{print_and_post} = 0;
1236     $form->{resubmit}       = 0;
1237   }
1238   if ($myconfig{role} eq 'admin') {
1239     $bcc = qq|
1240           <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
1241           <td><input name=bcc size=30 value="$form->{bcc}"></td>
1242 |;
1243   }
1244
1245   if ($form->{formname} =~ /(pick|packing|bin)_list/) {
1246     $form->{email} = $form->{shiptoemail} if $form->{shiptoemail};
1247   }
1248
1249   $name = $form->{ $form->{vc} };
1250   $name =~ s/--.*//g;
1251   $title = $locale->text('E-mail') . " $name";
1252
1253   $form->{oldmedia} = $form->{media};
1254   $form->{media}    = "email";
1255
1256   $form->header;
1257
1258   print qq|
1259 <body>
1260
1261 <form method=post action=$form->{script}>
1262
1263 <table width=100%>
1264   <tr class=listtop>
1265     <th class=listtop>$title</th>
1266   </tr>
1267   <tr height="5"></tr>
1268   <tr>
1269     <td>
1270       <table width=100%>
1271         <tr>
1272           <th align=right nowrap>| . $locale->text('To') . qq|</th>
1273           <td><input name=email size=30 value="$form->{email}"></td>
1274           <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
1275           <td><input name=cc size=30 value="$form->{cc}"></td>
1276         </tr>
1277         <tr>
1278           <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
1279           <td><input name=subject size=30 value="$form->{subject}"></td>
1280           $bcc
1281         </tr>
1282       </table>
1283     </td>
1284   </tr>
1285   <tr>
1286     <td>
1287       <table width=100%>
1288         <tr>
1289           <th align=left nowrap>| . $locale->text('Message') . qq|</th>
1290         </tr>
1291         <tr>
1292           <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
1293         </tr>
1294       </table>
1295     </td>
1296   </tr>
1297   <tr>
1298     <td>
1299 |;
1300
1301   &print_options;
1302
1303   map { delete $form->{$_} }
1304     qw(action email cc bcc subject message formname sendmode format header override);
1305
1306   # save all other variables
1307   foreach $key (keys %$form) {
1308     $form->{$key} =~ s/\"/&quot;/g;
1309     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1310   }
1311
1312   print qq|
1313     </td>
1314   </tr>
1315   <tr>
1316     <td><hr size=3 noshade></td>
1317   </tr>
1318 </table>
1319
1320 <input type=hidden name=nextsub value=send_email>
1321
1322 <br>
1323 <input name=action class=submit type=submit value="|
1324     . $locale->text('Continue') . qq|">
1325 </form>
1326
1327 </body>
1328 </html>
1329 |;
1330
1331   $lxdebug->leave_sub();
1332 }
1333
1334 sub send_email {
1335   $lxdebug->enter_sub();
1336
1337   $old_form = new Form;
1338
1339   map { $old_form->{$_} = $form->{$_} } keys %$form;
1340   $old_form->{media} = $form->{oldmedia};
1341
1342   &print_form($old_form);
1343
1344   $lxdebug->leave_sub();
1345 }
1346
1347 sub print_options {
1348   $lxdebug->enter_sub();
1349   $form->{sendmode} = "attachment";
1350   $form->{copies}   = 3 unless $form->{copies};
1351
1352   $form->{PD}{ $form->{formname} } = "selected";
1353   $form->{DF}{ $form->{format} }   = "selected";
1354   $form->{OP}{ $form->{media} }    = "selected";
1355   $form->{SM}{ $form->{sendmode} } = "selected";
1356
1357   if ($form->{type} eq 'purchase_order') {
1358     $type = qq|<select name=formname>
1359             <option value=purchase_order $form->{PD}{purchase_order}>|
1360       . $locale->text('Purchase Order') . qq|
1361             <option value=bin_list $form->{PD}{bin_list}>|
1362       . $locale->text('Bin List');
1363   }
1364
1365   if ($form->{type} eq 'credit_note') {
1366     $type = qq|<select name=formname>
1367             <option value=credit_note $form->{PD}{credit_note}>|
1368       . $locale->text('Credit Note');
1369   }
1370
1371   if ($form->{type} eq 'sales_order') {
1372     $type = qq|<select name=formname>
1373             <option value=sales_order $form->{PD}{sales_order}>|
1374       . $locale->text('Confirmation') . qq|
1375       <option value=proforma $form->{PD}{proforma}>|
1376       . $locale->text('Proforma Invoice') . qq|
1377             <option value=pick_list $form->{PD}{pick_list}>|
1378       . $locale->text('Pick List') . qq|
1379             <option value=packing_list $form->{PD}{packing_list}>|
1380       . $locale->text('Packing List') . qq|
1381             <option value=agb $form->{PD}{agb}>|
1382       . $locale->text('AGB') . qq|
1383             <option value=bunker_receipt $form->{PD}{bunker_receipt}>|
1384       . $locale->text('Bunker Receipt');
1385   }
1386
1387   if ($form->{type} =~ /_quotation$/) {
1388     $type = qq|<select name=formname>
1389             <option value="$`_quotation" $form->{PD}{"$`_quotation"}>|
1390       . $locale->text('Quotation')
1391 ;
1392   }
1393
1394   if ($form->{type} eq 'invoice') {
1395     $type = qq|<select name=formname>
1396             <option value=invoice $form->{PD}{invoice}>|
1397       . $locale->text('Invoice') . qq|
1398       <option value=proforma $form->{PD}{proforma}>|
1399       . $locale->text('Proforma Invoice') . qq|
1400       <option value=packing_list $form->{PD}{packing_list}>|
1401       . $locale->text('Packing List');
1402   }
1403
1404   if ($form->{type} eq 'invoice' && $form->{storno}) {
1405     $type = qq|<select name=formname>
1406             <option value=storno_invoice $form->{PD}{storno_invoice}>|
1407       . $locale->text('Storno Invoice') . qq|
1408       <option value=storno_packing_list $form->{PD}{storno_packing_list}>|
1409       . $locale->text('Storno Packing List');
1410   }
1411
1412   if ($form->{type} eq 'credit_note') {
1413     $type = qq|<select name=formname>
1414             <option value=credit_note $form->{PD}{credit_note}>|
1415       . $locale->text('Credit Note');
1416   }
1417
1418   if ($form->{type} eq 'ship_order') {
1419     $type = qq|<select name=formname>
1420             <option value=pick_list $form->{PD}{pick_list}>|
1421       . $locale->text('Pick List') . qq|
1422             <option value=packing_list $form->{PD}{packing_list}>|
1423       . $locale->text('Packing List');
1424   }
1425
1426   if ($form->{type} eq 'receive_order') {
1427     $type = qq|<select name=formname>
1428             <option value=bin_list $form->{PD}{bin_list}>|
1429       . $locale->text('Bin List');
1430   }
1431
1432   if ($form->{media} eq 'email') {
1433     $media = qq|<select name=sendmode>
1434             <option value=attachment $form->{SM}{attachment}>|
1435       . $locale->text('Attachment') . qq|
1436             <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
1437   } else {
1438     $media = qq|<select name=media>
1439             <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
1440     if (scalar(keys (%{ $form->{printers} })) !=0 && $latex_templates) {
1441       $media .= qq|
1442             <option value=printer $form->{OP}{printer}>|
1443         . $locale->text('Printer');
1444     }
1445     if ($latex_templates) {
1446       $media .= qq|
1447             <option value=queue $form->{OP}{queue}>| . $locale->text('Queue');
1448     }
1449   }
1450
1451   $format = qq|<select name=format>|;
1452   if ($opendocument_templates && $openofficeorg_writer_bin &&
1453       $xvfb_bin && (-x $openofficeorg_writer_bin) && (-x $xvfb_bin)) {
1454     $format .= qq|<option value=opendocument_pdf | .
1455       $form->{DF}{"opendocument_pdf"} . qq|>| .
1456       $locale->text("PDF (OpenDocument/OASIS)") . qq|</option>|;
1457   }
1458
1459   if ($latex_templates) {
1460     $format .= qq|<option value=pdf $form->{DF}{pdf}>| .
1461       $locale->text('PDF') . qq|</option>|;
1462   }
1463
1464   $format .= qq|<option value=html $form->{DF}{html}>HTML</option>|;
1465
1466   if ($latex) {
1467     $format .= qq|<option value=postscript $form->{DF}{postscript}>| .
1468       $locale->text('Postscript') . qq|</option>|;
1469   }
1470
1471   if ($opendocument_templates) {
1472     $format .= qq|<option value=opendocument $form->{DF}{opendocument}>| .
1473       $locale->text("OpenDocument/OASIS") . qq|</option>|;
1474   }
1475   $format .= qq|</select>|;
1476
1477   if (scalar(keys (%{ $form->{languages} })) !=0) {
1478
1479     $language_select = qq|<select name=language_id>|;
1480     foreach $item (@{ $form->{languages} }) {
1481       if ($form->{language_id} eq $item->{id}) {
1482         $language_select .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
1483       } else {
1484         $language_select .= qq|<option value="$item->{id}">$item->{description}</option>|;
1485       }
1486     }
1487   }
1488
1489   if (scalar(keys (%{ $form->{printers} })) !=0) {
1490
1491     $printer_select = qq|<select name=printer_id>
1492                   <option value=""></option>|;
1493     foreach $item (@{ $form->{printers} }) {
1494       $printer_select .= qq|<option value="$item->{id}">$item->{printer_description}</option>|;
1495     }
1496   }
1497
1498
1499
1500   print qq|
1501 <table width=100% cellspacing=0 cellpadding=0>
1502   <tr>
1503     <td>
1504       <table>
1505         <tr>
1506           <td>$type</select></td>|;
1507   if (scalar(keys (%{ $form->{languages} })) !=0) {
1508   print qq|
1509           <td>${language_select}</select></td>|;
1510   }
1511   print qq|
1512           <td>$format</select></td>
1513           <td>$media</select></td>|;
1514   if (scalar(keys (%{ $form->{printers} })) !=0) {
1515   print qq|
1516           <td>$printer_select</select></td>
1517 |;
1518   }
1519
1520   if (scalar(keys (%{ $form->{printers} })) !=0 && $latex_templates && $form->{media} ne 'email') {
1521     print qq|
1522           <td>| . $locale->text('Copies') . qq|
1523           <input name=copies size=2 value=$form->{copies}></td>
1524 |;
1525   }
1526
1527   $form->{groupitems} = "checked" if $form->{groupitems};
1528
1529   print qq|
1530           <td>| . $locale->text('Group Items') . qq|</td>
1531           <td><input name=groupitems type=checkbox class=checkbox $form->{groupitems}></td>
1532         </tr>
1533       </table>
1534     </td>
1535     <td align=right>
1536       <table>
1537         <tr>
1538 |;
1539
1540   if ($form->{printed} =~ /$form->{formname}/) {
1541     print qq|
1542           <th>\|| . $locale->text('Printed') . qq|\|</th>
1543 |;
1544   }
1545
1546   if ($form->{emailed} =~ /$form->{formname}/) {
1547     print qq|
1548           <th>\|| . $locale->text('E-mailed') . qq|\|</th>
1549 |;
1550   }
1551
1552   if ($form->{queued} =~ /$form->{formname}/) {
1553     print qq|
1554           <th>\|| . $locale->text('Queued') . qq|\|</th>
1555 |;
1556   }
1557
1558   print qq|
1559         </tr>
1560       </table>
1561     </td>
1562   </tr>
1563 </table>
1564 |;
1565
1566   $lxdebug->leave_sub();
1567 }
1568
1569 sub print {
1570   $lxdebug->enter_sub();
1571
1572   # if this goes to the printer pass through
1573   if ($form->{media} eq 'printer' || $form->{media} eq 'queue') {
1574     $form->error($locale->text('Select postscript or PDF!'))
1575       if ($form->{format} !~ /(postscript|pdf)/);
1576
1577     $old_form = new Form;
1578     map { $old_form->{$_} = $form->{$_} } keys %$form;
1579   }
1580
1581   if (!$form->{id} || (($form->{formname} eq "proforma") && !$form->{proforma} && (($form->{type} =~ /_order$/) || ($form->{type} =~ /_quotation$/)))) {
1582     if ($form->{formname} eq "proforma") {
1583       $form->{proforma} = 1;
1584     }
1585     $form->{print_and_save} = 1;
1586     my $formname = $form->{formname};
1587     &save();
1588     $form->{formname} = $formname;
1589     &edit();
1590     exit;
1591   }
1592
1593   &print_form($old_form);
1594
1595   $lxdebug->leave_sub();
1596 }
1597
1598 sub print_form {
1599   $lxdebug->enter_sub();
1600   my ($old_form) = @_;
1601
1602   $inv       = "inv";
1603   $due       = "due";
1604   $numberfld = "invnumber";
1605
1606   $display_form =
1607     ($form->{display_form}) ? $form->{display_form} : "display_form";
1608
1609   # $form->{"notes"} will be overridden by the customer's/vendor's "notes" field. So save it here.
1610   $form->{ $form->{"formname"} . "notes" } = $form->{"notes"};
1611
1612   if ($form->{formname} eq "invoice") {
1613     $form->{label} = $locale->text('Invoice');
1614   }
1615   if ($form->{formname} eq "packing_list") {
1616
1617     # this is from an invoice
1618     $form->{label} = $locale->text('Packing List');
1619   }
1620   if (($form->{formname} eq 'sales_order') || ($form->{formname} eq 'agb') || ($form->{formname} eq 'bunker_receipt')) {
1621     $inv                  = "ord";
1622     $due                  = "req";
1623     $form->{"${inv}date"} = $form->{transdate};
1624     $form->{label}        = $locale->text('Sales Order');
1625     $numberfld            = "sonumber";
1626     $order                = 1;
1627   }
1628
1629   if (($form->{type} eq 'invoice') && ($form->{formname} eq 'proforma') ) {
1630     $inv                  = "inv";
1631     $due                  = "due";
1632     $form->{"${inv}date"} = $form->{transdate};
1633     $form->{"invdate"}    = $form->{transdate};
1634     $form->{label}        = $locale->text('Proforma Invoice');
1635     $numberfld            = "sonumber";
1636     $order                = 0;
1637   }
1638
1639   if (($form->{type} eq 'sales_order') && ($form->{formname} eq 'proforma') ) {
1640     $inv                  = "inv";
1641     $due                  = "due";
1642     $form->{"${inv}date"} = $form->{transdate};
1643     $form->{"invdate"}    = $form->{transdate};
1644     $form->{invnumber}    = $form->{ordnumber};
1645     $form->{label}        = $locale->text('Proforma Invoice');
1646     $numberfld            = "sonumber";
1647     $order                = 1;
1648   }
1649
1650   if ($form->{formname} eq 'packing_list' && $form->{type} ne 'invoice') {
1651
1652     # we use the same packing list as from an invoice
1653     $inv = "ord";
1654     $due = "req";
1655     $form->{invdate} = $form->{"${inv}date"} = $form->{transdate};
1656     $form->{label} = $locale->text('Packing List');
1657     $order = 1;
1658   }
1659   if ($form->{formname} eq 'pick_list') {
1660     $inv                  = "ord";
1661     $due                  = "req";
1662     $form->{"${inv}date"} =
1663       ($form->{transdate}) ? $form->{transdate} : $form->{invdate};
1664     $form->{label} = $locale->text('Pick List');
1665     $order = 1 unless $form->{type} eq 'invoice';
1666   }
1667   if ($form->{formname} eq 'purchase_order') {
1668     $inv                  = "ord";
1669     $due                  = "req";
1670     $form->{"${inv}date"} = $form->{transdate};
1671     $form->{label}        = $locale->text('Purchase Order');
1672     $numberfld            = "ponumber";
1673     $order                = 1;
1674   }
1675   if ($form->{formname} eq 'bin_list') {
1676     $inv                  = "ord";
1677     $due                  = "req";
1678     $form->{"${inv}date"} = $form->{transdate};
1679     $form->{label}        = $locale->text('Bin List');
1680     $order                = 1;
1681   }
1682   if ($form->{formname} eq 'sales_quotation') {
1683     $inv                  = "quo";
1684     $due                  = "req";
1685     $form->{"${inv}date"} = $form->{transdate};
1686     $form->{label}        = $locale->text('Quotation');
1687     $numberfld            = "sqnumber";
1688     $order                = 1;
1689   }
1690
1691   if (($form->{type} eq 'sales_quotation') && ($form->{formname} eq 'proforma') ) {
1692     $inv                  = "quo";
1693     $due                  = "req";
1694     $form->{"${inv}date"} = $form->{transdate};
1695     $form->{"invdate"} = $form->{transdate};
1696     $form->{label}        = $locale->text('Proforma Invoice');
1697     $numberfld            = "sqnumber";
1698     $order                = 1;
1699   }
1700
1701   if ($form->{formname} eq 'request_quotation') {
1702     $inv                  = "quo";
1703     $due                  = "req";
1704     $form->{"${inv}date"} = $form->{transdate};
1705     $form->{label}        = $locale->text('Quotation');
1706     $numberfld            = "rfqnumber";
1707     $order                = 1;
1708   }
1709
1710   $form->isblank("email", $locale->text('E-mail address missing!'))
1711     if ($form->{media} eq 'email');
1712   $form->isblank("${inv}date",
1713                  $locale->text($form->{label} . ' Date missing!'));
1714
1715   # $locale->text('Invoice Number missing!')
1716   # $locale->text('Invoice Date missing!')
1717   # $locale->text('Packing List Number missing!')
1718   # $locale->text('Packing List Date missing!')
1719   # $locale->text('Order Number missing!')
1720   # $locale->text('Order Date missing!')
1721   # $locale->text('Quotation Number missing!')
1722   # $locale->text('Quotation Date missing!')
1723
1724   # assign number
1725   if (!$form->{"${inv}number"} && !$form->{preview}) {
1726     $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
1727     if ($form->{media} ne 'email') {
1728
1729       # get pricegroups for parts
1730       IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1731
1732       # build up html code for prices_$i
1733       set_pricegroup($form->{rowcount});
1734
1735       $form->{rowcount}--;
1736
1737       &{"$display_form"};
1738       exit;
1739     }
1740   }
1741
1742   &validate_items;
1743
1744   # Save the email address given in the form because it should override the setting saved for the customer/vendor.
1745   my ($saved_email, $saved_cc, $saved_bcc) =
1746     ($form->{"email"}, $form->{"cc"}, $form->{"bcc"});
1747
1748   $language_saved = $form->{language_id};
1749   &{"$form->{vc}_details"};
1750   $form->{language_id} = $language_saved;
1751
1752   $form->{"email"} = $saved_email if ($saved_email);
1753   $form->{"cc"}    = $saved_cc    if ($saved_cc);
1754   $form->{"bcc"}   = $saved_bcc   if ($saved_bcc);
1755
1756   # format payment dates
1757   for $i (1 .. $form->{paidaccounts} - 1) {
1758     $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"});
1759   }
1760
1761   ($form->{employee}) = split /--/, $form->{employee};
1762   ($form->{warehouse}, $form->{warehouse_id}) = split /--/, $form->{warehouse};
1763
1764   # create the form variables
1765   if ($order) {
1766     OE->order_details(\%myconfig, \%$form);
1767   } else {
1768     IS->invoice_details(\%myconfig, \%$form, $locale);
1769   }
1770
1771   # format global dates
1772   map { $form->{$_} = $locale->date(\%myconfig, $form->{$_}, 1) }
1773     ("${inv}date", "${due}date", "shippingdate", "deliverydate");
1774
1775   # format item dates
1776   for my $field (qw(transdate_oe deliverydate_oe)) {
1777     map {
1778       $form->{$field}[$_] = $locale->date(\%myconfig, $form->{$field}[$_], 1);
1779     } 0 .. $#{ $form->{$field} };
1780   }
1781
1782   if ($form->{shipto_id}) {
1783     $form->get_shipto(\%myconfig);
1784   }
1785
1786   @a = qw(name street zipcode city country);
1787
1788   $shipto = 1;
1789
1790   # if there is no shipto fill it in from billto
1791   foreach $item (@a) {
1792     if ($form->{"shipto$item"}) {
1793       $shipto = 0;
1794       last;
1795     }
1796   }
1797
1798   if ($shipto) {
1799     if (   $form->{formname} eq 'purchase_order'
1800         || $form->{formname} eq 'request_quotation') {
1801       $form->{shiptoname}   = $myconfig{company};
1802       $form->{shiptostreet} = $myconfig{address};
1803         } else {
1804       map { $form->{"shipto$_"} = $form->{$_} } @a;
1805     }
1806   }
1807
1808   $form->{notes} =~ s/^\s+//g;
1809
1810   $form->{templates} = "$myconfig{templates}";
1811
1812   $form->{language} = $form->get_template_language(\%myconfig);
1813   $form->{printer_code} = $form->get_printer_code(\%myconfig);
1814
1815   if ($form->{language} ne "") {
1816     $form->{language} = "_" . $form->{language};
1817   }
1818
1819   if ($form->{printer_code} ne "") {
1820     $form->{printer_code} = "_" . $form->{printer_code};
1821   }
1822
1823   $form->{IN} = "$form->{formname}$form->{language}$form->{printer_code}.html";
1824   if ($form->{format} eq 'postscript') {
1825     $form->{postscript} = 1;
1826     $form->{IN} =~ s/html$/tex/;
1827   } elsif ($form->{"format"} =~ /pdf/) {
1828     $form->{pdf} = 1;
1829     if ($form->{"format"} =~ /opendocument/) {
1830       $form->{IN} =~ s/html$/odt/;
1831     } else {
1832       $form->{IN} =~ s/html$/tex/;
1833     }
1834   } elsif ($form->{"format"} =~ /opendocument/) {
1835     $form->{"opendocument"} = 1;
1836     $form->{"IN"} =~ s/html$/odt/;
1837   }
1838
1839   if ($form->{media} eq 'printer') {
1840     $form->{OUT} = "| $form->{printer_command} &>/dev/null";
1841     $form->{printed} .= " $form->{formname}";
1842     $form->{printed} =~ s/^ //;
1843   }
1844   $printed = $form->{printed};
1845
1846   if ($form->{media} eq 'email') {
1847     $form->{subject} = qq|$form->{label} $form->{"${inv}number"}|
1848       unless $form->{subject};
1849
1850     $form->{OUT} = "$sendmail";
1851
1852     $form->{emailed} .= " $form->{formname}";
1853     $form->{emailed} =~ s/^ //;
1854   }
1855   $emailed = $form->{emailed};
1856
1857   if ($form->{media} eq 'queue') {
1858     %queued = split / /, $form->{queued};
1859
1860     if ($filename = $queued{ $form->{formname} }) {
1861       $form->{queued} =~ s/$form->{formname} $filename//;
1862       unlink "$spool/$filename";
1863       $filename =~ s/\..*$//g;
1864     } else {
1865       $filename = time;
1866       $filename .= $$;
1867     }
1868
1869     $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
1870     $form->{OUT} = ">$spool/$filename";
1871
1872     # add type
1873     $form->{queued} .= " $form->{formname} $filename";
1874
1875     $form->{queued} =~ s/^ //;
1876   }
1877   $queued = $form->{queued};
1878
1879   $form->parse_template(\%myconfig, $userspath);
1880
1881   $form->{callback} = "";
1882
1883   if ($form->{media} eq 'email') {
1884     $form->{message} = $locale->text('sent') unless $form->{message};
1885   }
1886   $message = $form->{message};
1887
1888   # if we got back here restore the previous form
1889   if ($form->{media} =~ /(printer|email|queue)/) {
1890
1891     $form->update_status(\%myconfig)
1892       if ($form->{media} eq 'queue' && $form->{id});
1893
1894     if ($old_form) {
1895
1896       $old_form->{"${inv}number"} = $form->{"${inv}number"};
1897
1898       # restore and display form
1899       map { $form->{$_} = $old_form->{$_} } keys %$old_form;
1900
1901       $form->{queued}  = $queued;
1902       $form->{printed} = $printed;
1903       $form->{emailed} = $emailed;
1904       $form->{message} = $message;
1905
1906       $form->{rowcount}--;
1907       map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1908         qw(exchangerate creditlimit creditremaining);
1909
1910       for $i (1 .. $form->{paidaccounts}) {
1911         map {
1912           $form->{"${_}_$i"} =
1913             $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
1914         } qw(paid exchangerate);
1915       }
1916
1917       &{"$display_form"};
1918       exit;
1919     }
1920
1921     $msg =
1922       ($form->{media} eq 'printer')
1923       ? $locale->text('sent to printer')
1924       : $locale->text('emailed to') . " $form->{email}";
1925     $form->redirect(qq|$form->{label} $form->{"${inv}number"} $msg|);
1926   }
1927   if ($form->{printing}) {
1928    &{"$display_form"};
1929    exit; 
1930   }
1931
1932   $lxdebug->leave_sub();
1933 }
1934
1935 sub customer_details {
1936   $lxdebug->enter_sub();
1937   IS->customer_details(\%myconfig, \%$form);
1938   $lxdebug->leave_sub();
1939 }
1940
1941 sub vendor_details {
1942   $lxdebug->enter_sub();
1943
1944   IR->vendor_details(\%myconfig, \%$form);
1945
1946   $lxdebug->leave_sub();
1947 }
1948
1949 sub post_as_new {
1950   $lxdebug->enter_sub();
1951
1952   $form->{postasnew} = 1;
1953   map { delete $form->{$_} } qw(printed emailed queued);
1954
1955   &post;
1956
1957   $lxdebug->leave_sub();
1958 }
1959
1960 sub ship_to {
1961   $lxdebug->enter_sub();
1962   if ($form->{second_run}) {
1963     $form->{print_and_post} = 0;
1964   }
1965
1966   $title = $form->{title};
1967   $form->{title} = $locale->text('Ship to');
1968
1969   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1970     qw(exchangerate creditlimit creditremaining);
1971
1972   # get details for name
1973   &{"$form->{vc}_details"};
1974
1975   $number =
1976     ($form->{vc} eq 'customer')
1977     ? $locale->text('Customer Number')
1978     : $locale->text('Vendor Number');
1979
1980   # get pricegroups for parts
1981   IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1982
1983   # build up html code for prices_$i
1984   set_pricegroup($form->{rowcount});
1985
1986   $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
1987
1988   $form->{rowcount}--;
1989
1990   $form->header;
1991
1992   print qq|
1993 <body>
1994
1995 <form method=post action=$form->{script}>
1996
1997 <table width=100%>
1998   <tr>
1999     <td>
2000       <table>
2001         <tr class=listheading>
2002           <th class=listheading colspan=2 width=50%>|
2003     . $locale->text('Billing Address') . qq|</th>
2004           <th class=listheading width=50%>|
2005     . $locale->text('Shipping Address') . qq|</th>
2006         </tr>
2007         <tr height="5"></tr>
2008         <tr>
2009           <th align=right nowrap>$number</th>
2010           <td>$form->{"$form->{vc}number"}</td>
2011         </tr>
2012         <tr>
2013           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
2014           <td>$form->{name}</td>
2015           <td><input name=shiptoname size=35 value="$form->{shiptoname}"></td>
2016         </tr>
2017         <tr>
2018           <th align=right nowrap>| . $locale->text('Street') . qq|</th>
2019           <td>$form->{street}</td>
2020           <td><input name=shiptostreet size=35 value="$form->{shiptostreet}"></td>
2021         </tr>
2022         <tr>
2023           <th align=right nowrap>| . $locale->text('Zipcode') . qq|</th>
2024           <td>$form->{zipcode}</td>
2025           <td><input name=shiptozipcode size=35 value="$form->{shiptozipcode}"></td>
2026         </tr>
2027         <tr>
2028           <th align=right nowrap>| . $locale->text('City') . qq|</th>
2029           <td>$form->{city}</td>
2030           <td><input name=shiptocity size=35 value="$form->{shiptocity}"></td>
2031         </tr>
2032         <tr>
2033           <th align=right nowrap>| . $locale->text('Country') . qq|</th>
2034           <td>$form->{country}</td>
2035           <td><input name=shiptocountry size=35 value="$form->{shiptocountry}"></td>
2036         </tr>
2037         <tr>
2038           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
2039           <td>$form->{contact}</td>
2040           <td><input name=shiptocontact size=35 value="$form->{shiptocontact}"></td>
2041         </tr>
2042         <tr>
2043           <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
2044           <td>$form->{"$form->{vc}phone"}</td>
2045           <td><input name=shiptophone size=20 value="$form->{shiptophone}"></td>
2046         </tr>
2047         <tr>
2048           <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
2049           <td>$form->{"$form->{vc}fax"}</td>
2050           <td><input name=shiptofax size=20 value="$form->{shiptofax}"></td>
2051         </tr>
2052         <tr>
2053           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
2054           <td>$form->{email}</td>
2055           <td><input name=shiptoemail size=35 value="$form->{shiptoemail}"></td>
2056         </tr>
2057       </table>
2058     </td>
2059   </tr>
2060 </table>
2061
2062 <input type=hidden name=nextsub value=$nextsub>
2063 |;
2064
2065   # delete shipto
2066   map { delete $form->{$_} }
2067     qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax shiptoemail header);
2068   $form->{title} = $title;
2069
2070   foreach $key (keys %$form) {
2071     $form->{$key} =~ s/\"/&quot;/g;
2072     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2073   }
2074
2075   print qq|
2076
2077 <hr size=3 noshade>
2078
2079 <br>
2080 <input class=submit type=submit name=action value="|
2081     . $locale->text('Continue') . qq|">
2082 </form>
2083
2084 </body>
2085 </html>
2086 |;
2087
2088   $lxdebug->leave_sub();
2089 }
2090
2091 sub new_license {
2092   $lxdebug->enter_sub();
2093
2094   my $row = shift;
2095
2096   # change callback
2097   $form->{old_callback} = $form->escape($form->{callback}, 1);
2098   $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
2099   $form->{old_callback} = $form->escape($form->{old_callback}, 1);
2100
2101   # delete action
2102   delete $form->{action};
2103   $customer = $form->{customer};
2104   map { $form->{"old_$_"} = $form->{"${_}_$row"} } qw(partnumber description);
2105
2106   # save all other form variables in a previousform variable
2107   $form->{row} = $row;
2108   foreach $key (keys %$form) {
2109
2110     # escape ampersands
2111     $form->{$key} =~ s/&/%26/g;
2112     $previousform .= qq|$key=$form->{$key}&|;
2113   }
2114   chop $previousform;
2115   $previousform = $form->escape($previousform, 1);
2116
2117   $form->{script} = "licenses.pl";
2118
2119   map { $form->{$_} = $form->{"old_$_"} } qw(partnumber description);
2120   map { $form->{$_} = $form->escape($form->{$_}, 1) }
2121     qw(partnumber description);
2122   $form->{callback} =
2123     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|;
2124   $form->redirect;
2125
2126   $lxdebug->leave_sub();
2127 }
2128