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