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