unstable-Zweig als Kopie des "alten" trunks erstellt.
[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
45 1;
46 # end of main
47
48
49 # this is for our long dates
50 # $locale->text('January')
51 # $locale->text('February')
52 # $locale->text('March')
53 # $locale->text('April')
54 # $locale->text('May ')
55 # $locale->text('June')
56 # $locale->text('July')
57 # $locale->text('August')
58 # $locale->text('September')
59 # $locale->text('October')
60 # $locale->text('November')
61 # $locale->text('December')
62
63 # this is for our short month
64 # $locale->text('Jan')
65 # $locale->text('Feb')
66 # $locale->text('Mar')
67 # $locale->text('Apr')
68 # $locale->text('May')
69 # $locale->text('Jun')
70 # $locale->text('Jul')
71 # $locale->text('Aug')
72 # $locale->text('Sep')
73 # $locale->text('Oct')
74 # $locale->text('Nov')
75 # $locale->text('Dec')
76 use Data::Dumper;
77 ########################################
78 # Eintrag fuer Version 2.2.0 geaendert #
79 # neue Optik im Rechnungsformular      #
80 ########################################
81 sub display_row {
82   $lxdebug->enter_sub();
83   my $numrows = shift;
84
85
86 if ($lizenzen &&  $form->{vc} eq "customer") {
87   if ($form->{type} =~ /sales_order/) {
88   @column_index = (runningnumber, partnumber, description, ship, qty);
89   }
90   elsif ($form->{type} =~ /sales_quotation/){
91   @column_index = (runningnumber, partnumber, description, qty);
92   }
93   else {
94   @column_index = (runningnumber, partnumber, description, qty);
95   }
96 }
97 else {
98   if (($form->{type} =~ /purchase_order/) || ($form->{type} =~ /sales_order/)) {
99   @column_index = (runningnumber, partnumber, description, ship, qty);
100   }
101   else {
102   @column_index = (runningnumber, partnumber, description, qty);
103   }
104 }
105 ############## ENDE Neueintrag ##################
106
107   push @column_index, qw(unit sellprice);
108
109   if ($form->{vc} eq 'customer') {
110     push @column_index, qw(discount);
111   }
112   
113   push @column_index, "linetotal";
114
115   my $colspan = $#column_index + 1;
116
117      
118   $form->{invsubtotal} = 0;
119   map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
120
121 ########################################
122 # Eintrag fuer Version 2.2.0 geaendert #
123 # neue Optik im Rechnungsformular      #
124 ########################################
125   $column_data{runningnumber} = qq|<th align=left nowrap width=5 class=listheading>|.$locale->text('No.').qq|</th>|;
126   $column_data{partnumber} = qq|<th align=left nowrap width=12 class=listheading>|.$locale->text('Number').qq|</th>|;
127   $column_data{description} = qq|<th align=left nowrap width=30 class=listheading>|.$locale->text('Part Description').qq|</th>|;
128   $column_data{ship} = qq|<th align=left nowrap width=5 class=listheading>|.$locale->text('Ship').qq|</th>|;
129   $column_data{qty} = qq|<th align=left nowrap width=5 class=listheading>|.$locale->text('Qty').qq|</th>|;
130   $column_data{unit} = qq|<th align=left nowrap width=5 class=listheading>|.$locale->text('Unit').qq|</th>|;
131   $column_data{license} = qq|<th align=left nowrap width=10 class=listheading>|.$locale->text('License').qq|</th>|;
132   $column_data{serialnr} = qq|<th align=left nowrap width=10 class=listheading>|.$locale->text('Serial No.').qq|</th>|;
133   $column_data{projectnr} = qq|<th align=left nowrap width=10 class=listheading>|.$locale->text('Project').qq|</th>|;
134   $column_data{sellprice} = qq|<th align=left nowrap width=10 class=listheading>|.$locale->text('Price').qq|</th>|;
135   $column_data{discount} = qq|<th align=left class=listheading>|.$locale->text('Discount').qq|</th>|; 
136   $column_data{linetotal} = qq|<th align=left nowrap width=10 class=listheading>|.$locale->text('Extended').qq|</th>|;
137   $column_data{bin} = qq|<th align=left nowrap width=10 class=listheading>|.$locale->text('Bin').qq|</th>|;
138 ############## ENDE Neueintrag ##################
139
140   print qq|
141   <tr>
142     <td>
143       <table width=100%>
144         <tr class=listheading>|;
145
146   map { print "\n$column_data{$_}" } @column_index;
147
148   print qq|
149         </tr>
150 |;
151
152
153   $runningnumber = $locale->text('No.');
154   $deliverydate = $locale->text('Delivery Date');
155   $serialnumber = $locale->text('Serial No.');
156   $projectnumber = $locale->text('Project');
157   $partsgroup = $locale->text('Group');
158
159   $delvar = 'deliverydate';
160   
161   if ($form->{type} =~ /_order$/ || $form->{type} =~ /_quotation$/) {
162     $deliverydate = $locale->text('Required by');
163     $delvar = 'reqdate';
164   }
165
166  
167   for $i (1 .. $numrows) {
168     # undo formatting
169     map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(qty ship discount sellprice);
170     
171
172     ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
173     $dec = length $dec;
174     $decimalplaces = ($dec > 2) ? $dec : 2;
175     
176     $discount = $form->round_amount($form->{"sellprice_$i"} * $form->{"discount_$i"}/100, $decimalplaces);
177     $linetotal = $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
178     $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
179
180     # convert " to &quot;
181     map { $form->{"${_}_$i"} =~ s/\"/&quot;/g } qw(partnumber description unit);
182
183 ########################################
184 # Eintrag fuer Version 2.2.0 geaendert #
185 # neue Optik im Rechnungsformular      #
186 ########################################
187     $column_data{runningnumber} = qq|<td><input name="runningnumber_$i" size=5 value=$i></td>|; # HuT
188 ############## ENDE Neueintrag ##################
189        
190     $column_data{partnumber} = qq|<td><input name="partnumber_$i" size=12 value="$form->{"partnumber_$i"}"></td>|;
191
192     if (($rows = $form->numtextrows($form->{"description_$i"}, 30, 6)) > 1) {
193       $column_data{description} = qq|<td><textarea name="description_$i" rows=$rows cols=30 wrap=soft>$form->{"description_$i"}</textarea></td>|;
194     } else {
195       $column_data{description} = qq|<td><input name="description_$i" size=30 value="$form->{"description_$i"}"></td>|;
196     }
197
198     $column_data{qty} = qq|<td align=right><input name="qty_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"qty_$i"}).qq|></td>|;
199     $column_data{ship} = qq|<td align=right><input name="ship_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"ship_$i"}).qq|></td>|;
200     $column_data{unit} = qq|<td><input name="unit_$i" size=5 value="$form->{"unit_$i"}"></td>|;
201     $column_data{sellprice} = qq|<td align=right><input name="sellprice_$i" size=9 value=|.$form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces).qq|></td>|;
202     $column_data{discount} = qq|<td align=right><input name="discount_$i" size=3 value=|.$form->format_amount(\%myconfig, $form->{"discount_$i"}).qq|></td>|;
203     $column_data{linetotal} = qq|<td align=right>|.$form->format_amount(\%myconfig, $linetotal, 2).qq|</td>|;
204     $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
205
206
207 ########################################
208 # Eintrag fuer Version 2.2.0 geaendert #
209 # neue Optik im Rechnungsformular      #
210 ########################################    
211 #     if ($lizenzen &&  $form->{type} eq "invoice" &&  $form->{vc} eq "customer") {
212 #     $column_data{license} = qq|<td><select name="licensenumber_$i">$form->{"lizenzen_$i"}></select></td>|;
213 #     }
214
215 #     if ($form->{type} !~ /_quotation/) {
216 #     $column_data{serialnr} = qq|<td><input name="serialnumber_$i" size=10 value="$form->{"serialnumber_$i"}"></td>|;
217 #     }
218
219 #     $column_data{projectnr} = qq|<td><input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}"></td>|;
220 ############## ENDE Neueintrag ##################
221
222     
223     print qq|
224         <tr valign=top>|;
225
226     map { print "\n$column_data{$_}" } @column_index;
227   
228     print qq|
229         </tr>
230
231 <input type=hidden name="orderitems_id_$i" value=$form->{"orderitems_id_$i"}>
232 <input type=hidden name="bo_$i" value=$form->{"bo_$i"}>
233
234 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
235 <input type=hidden name="inventory_accno_$i" value=$form->{"inventory_accno_$i"}>
236 <input type=hidden name="bin_$i" value="$form->{"bin_$i"}">
237 <input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">
238 <input type=hidden name="partnotes_$i" value="$form->{"partnotes_$i"}">
239 <input type=hidden name="income_accno_$i" value=$form->{"income_accno_$i"}>
240 <input type=hidden name="expense_accno_$i" value=$form->{"expense_accno_$i"}>
241 <input type=hidden name="listprice_$i" value="$form->{"listprice_$i"}">
242 <input type=hidden name="assembly_$i" value="$form->{"assembly_$i"}">
243 <input type=hidden name="taxaccounts_$i" value="$form->{"taxaccounts_$i"}">
244
245 |;
246
247 ########################################
248 # Eintrag fuer Version 2.2.0 geaendert #
249 # neue Optik im Rechnungsformular      #
250 ########################################    
251     # print second row
252     print qq|
253         <tr>
254           <td colspan=$colspan>
255 |;
256     if ($lizenzen &&  $form->{type} eq "invoice" &&  $form->{vc} eq "customer") {
257       my $selected = $form->{"licensenumber_$i"};
258       my $lizenzen_quoted;
259       $form->{"lizenzen_$i"} =~ s/ selected//g;
260       $form->{"lizenzen_$i"} =~ s/value="${selected}"\>/value="${selected}" selected\>/;
261       $lizenzen_quoted = $form->{"lizenzen_$i"};
262       $lizenzen_quoted =~ s/\"/&quot;/g;
263       print qq|
264         <b>Lizenz\#</b>&nbsp;<select name="licensenumber_$i" size=1>
265         $form->{"lizenzen_$i"}
266         </select>
267         <input type=hidden name="lizenzen_$i" value="${lizenzen_quoted}">
268 |;
269     }
270     if ($form->{type} !~ /_quotation/) {
271       print qq|
272           <b>$serialnumber</b>&nbsp;<input name="serialnumber_$i" size=15 value="$form->{"serialnumber_$i"}">|;
273     }
274
275     print qq|
276           <b>$projectnumber</b>&nbsp;<input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}">
277                   <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}">
278                   <input type=hidden name="project_id_$i" value="$form->{"project_id_$i"}">
279           </td>
280         </tr>
281
282 |;
283
284 ############## ENDE Neueintrag ##################
285
286
287     map { $form->{"${_}_base"} += $linetotal } (split / /, $form->{"taxaccounts_$i"});
288   
289     $form->{invsubtotal} += $linetotal;
290   }
291
292   print qq|
293       </table>
294     </td>
295   </tr>
296 |;
297
298   $lxdebug->leave_sub();
299 }
300
301
302 sub select_item {
303   $lxdebug->enter_sub();
304   
305   @column_index = qw(ndx partnumber description onhand sellprice);
306
307   $column_data{ndx} = qq|<th>&nbsp;</th>|;
308   $column_data{partnumber} = qq|<th class=listheading>|.$locale->text('Number').qq|</th>|;
309   $column_data{description} = qq|<th class=listheading>|.$locale->text('Part Description').qq|</th>|;
310   $column_data{sellprice} = qq|<th class=listheading>|.$locale->text('Price').qq|</th>|;
311   $column_data{onhand} = qq|<th class=listheading>|.$locale->text('Qty').qq|</th>|;
312   
313   
314   # list items with radio button on a form
315   $form->header;
316
317   $title = $locale->text('Select from one of the items below');
318   $colspan = $#column_index + 1;
319   
320
321
322   print qq|
323 <body>
324
325 <form method=post action=$form->{script}>
326
327 <table width=100%>
328   <tr>
329     <th class=listtop colspan=$colspan>$title</th>
330   </tr>
331   <tr height="5"></tr>
332   <tr class=listheading>|;
333
334   map { print "\n$column_data{$_}" } @column_index;
335   
336   print qq|</tr>|;
337
338   my $i = 0;
339   foreach $ref (@{ $form->{item_list} }) {
340     $checked = ($i++) ? "" : "checked";
341     
342     if ($lizenzen) {
343         if ($ref->{inventory_accno} > 0) {
344           $ref->{"lizenzen"} = qq|<option></option>|;
345           foreach $item (@{ $form->{LIZENZEN}{$ref->{"id"}}}) {
346                   $ref->{"lizenzen"} .= qq|<option value=\"$item->{"id"}\">$item->{"licensenumber"}</option>|;
347           }
348           $ref->{"lizenzen"} .= qq|<option value=-1>Neue Lizenz</option>|;
349           $ref->{"lizenzen"} =~ s/\"/&quot;/g;
350         }
351     }
352     
353
354     map { $ref->{$_} =~ s/\"/&quot;/g } qw(partnumber description unit);
355
356     $ref->{sellprice} = $form->round_amount($ref->{sellprice} * (1 - $form->{tradediscount}), 2);
357
358     $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
359     $column_data{partnumber} = qq|<td><input name="new_partnumber_$i" type=hidden value="$ref->{partnumber}">$ref->{partnumber}</td>|;
360     $column_data{description} = qq|<td><input name="new_description_$i" type=hidden value="$ref->{description}">$ref->{description}</td>|;
361     $column_data{sellprice} = qq|<td align=right><input name="new_sellprice_$i" type=hidden value=$ref->{sellprice}>|.$form->format_amount(\%myconfig, $ref->{sellprice}, 2, "&nbsp;").qq|</td>|;
362     $column_data{onhand} = qq|<td align=right><input name="new_onhand_$i" type=hidden value=$ref->{onhand}>|.$form->format_amount(\%myconfig, $ref->{onhand}, '', "&nbsp;").qq|</td>|;
363     
364     $j++; $j %= 2;
365     print qq|
366 <tr class=listrow$j>|;
367
368     map { print "\n$column_data{$_}" } @column_index;
369
370     print qq|
371 </tr>
372
373 <input name="new_bin_$i" type=hidden value="$ref->{bin}">
374 <input name="new_listprice_$i" type=hidden value=$ref->{listprice}>
375 <input name="new_inventory_accno_$i" type=hidden value=$ref->{inventory_accno}>
376 <input name="new_income_accno_$i" type=hidden value=$ref->{income_accno}>
377 <input name="new_expense_accno_$i" type=hidden value=$ref->{expense_accno}>
378 <input name="new_unit_$i" type=hidden value="$ref->{unit}">
379 <input name="new_weight_$i" type=hidden value="$ref->{weight}">
380 <input name="new_assembly_$i" type=hidden value="$ref->{assembly}">
381 <input name="new_taxaccounts_$i" type=hidden value="$ref->{taxaccounts}">
382 <input name="new_partsgroup_$i" type=hidden value="$ref->{partsgroup}">
383
384 <input name="new_id_$i" type=hidden value=$ref->{id}>
385
386 |;
387   if ($lizenzen) {
388         print qq|
389 <input name="new_lizenzen_$i" type=hidden value="$ref->{lizenzen}">
390 |;
391   }
392
393   }
394   
395   print qq|
396 <tr><td colspan=8><hr size=3 noshade></td></tr>
397 </table>
398
399 <input name=lastndx type=hidden value=$i>
400
401 |;
402
403   # delete action variable
404   map { delete $form->{$_} } qw(action item_list header);
405     
406   # save all other form variables
407   foreach $key (keys %${form}) {
408     $form->{$key} =~ s/\"/&quot;/g;
409     print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
410   }
411
412   print qq|
413 <input type=hidden name=nextsub value=item_selected>
414
415 <br>
416 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
417 </form>
418
419 </body>
420 </html>
421 |;
422
423   $lxdebug->leave_sub();
424 }
425
426
427
428 sub item_selected {
429   $lxdebug->enter_sub();
430
431   # replace the last row with the checked row
432   $i = $form->{rowcount};
433   $i = $form->{assembly_rows} if ($form->{item} eq 'assembly');
434
435   # index for new item
436   $j = $form->{ndx};
437
438   # if there was a price entered, override it
439   $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
440   
441   map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } qw(id partnumber description sellprice listprice inventory_accno income_accno expense_accno bin unit weight assembly taxaccounts partsgroup);
442   
443   if ($lizenzen) {
444         map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } qw(lizenzen);
445   }
446
447   ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
448   $dec = length $dec;
449   $decimalplaces = ($dec > 2) ? $dec : 2;
450
451   if ($sellprice) {
452     $form->{"sellprice_$i"} = $sellprice;
453   } else {
454     # if there is an exchange rate adjust sellprice
455     if (($form->{exchangerate} * 1) != 0) {
456       $form->{"sellprice_$i"} /= $form->{exchangerate};
457       $form->{"sellprice_$i"} = $form->round_amount($form->{"sellprice_$i"}, $decimalplaces);
458     }
459   }
460
461   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(sellprice listprice weight);
462
463   $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
464   $form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"});
465
466   $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"};
467   map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
468   map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
469
470   $form->{creditremaining} -= $amount;
471
472   $form->{"runningnumber_$i"} = $i;
473   
474   # delete all the new_ variables
475   for $i (1 .. $form->{lastndx}) {
476     map { delete $form->{"new_${_}_$i"} } qw(partnumber description sellprice bin listprice inventory_accno income_accno expense_accno unit assembly taxaccounts id);
477   }
478   
479   map { delete $form->{$_} } qw(ndx lastndx nextsub);
480
481   # format amounts
482   map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice) if $form->{item} ne 'assembly';
483
484   &display_form;
485   
486   $lxdebug->leave_sub();
487 }
488
489
490 sub new_item {
491   $lxdebug->enter_sub();
492
493   # change callback
494   $form->{old_callback} = $form->escape($form->{callback},1);
495   $form->{callback} = $form->escape("$form->{script}?action=display_form",1);
496
497   # delete action
498   delete $form->{action};
499
500   # save all other form variables in a previousform variable
501   foreach $key (keys %$form) {
502     # escape ampersands
503     $form->{$key} =~ s/&/%26/g;
504     $previousform .= qq|$key=$form->{$key}&|;
505   }
506   chop $previousform;
507   $previousform = $form->escape($previousform, 1);
508
509   $i = $form->{rowcount};
510   map { $form->{"${_}_$i"} =~ s/\"/&quot;/g } qw(partnumber description);
511
512   $form->header;
513
514   print qq|
515 <body>
516
517 <h4 class=error>|.$locale->text('Item not on file!').qq|
518
519 <p>
520 |.$locale->text('What type of item is this?').qq|</h4>
521
522 <form method=post action=ic.pl>
523
524 <p>
525
526   <input class=radio type=radio name=item value=part checked>&nbsp;|.$locale->text('Part')
527 .qq|<br>
528   <input class=radio type=radio name=item value=service>&nbsp;|.$locale->text('Service')
529
530 .qq|
531 <input type=hidden name=previousform value="$previousform">
532 <input type=hidden name=partnumber value="$form->{"partnumber_$i"}">
533 <input type=hidden name=description value="$form->{"description_$i"}">
534 <input type=hidden name=rowcount value=$form->{rowcount}>
535 <input type=hidden name=taxaccount2 value=$form->{taxaccounts}>
536 <input type=hidden name=vc value=$form->{vc}>
537
538 <input type=hidden name=path value=$form->{path}>
539 <input type=hidden name=login value=$form->{login}>
540 <input type=hidden name=password value=$form->{password}>
541
542 <input type=hidden name=nextsub value=add>
543
544 <p>
545 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
546 </form>
547
548 </body>
549 </html>
550 |;
551
552   $lxdebug->leave_sub();
553 }
554
555
556
557 sub display_form {
558   $lxdebug->enter_sub();
559
560   # if we have a display_form
561   if ($form->{display_form}) {
562     &{ "$form->{display_form}" };
563     exit;
564   }
565   
566   &form_header;
567
568   $numrows = ++$form->{rowcount};
569   $subroutine = "display_row";
570
571   if ($form->{item} eq 'part') {
572     $numrows = ++$form->{makemodel_rows};
573     $subroutine = "makemodel_row";
574   }
575   if ($form->{item} eq 'assembly') {
576     $numrows = ++$form->{makemodel_rows};
577     $subroutine = "makemodel_row";
578   
579     # create makemodel rows
580     &{ $subroutine }($numrows);
581
582     $numrows = ++$form->{assembly_rows};
583     $subroutine = "assembly_row";
584   }
585   if ($form->{item} eq 'service') {
586     $numrows = 0;
587   }
588
589   # create rows
590   &{ $subroutine }($numrows) if $numrows;
591
592   &form_footer;
593
594   $lxdebug->leave_sub();
595 }
596
597
598
599 sub check_form {
600   $lxdebug->enter_sub();
601   
602   my @a = ();
603   my $count = 0;
604   my @flds = (qw(id partnumber description qty ship sellprice unit discount inventory_accno income_accno expense_accno listprice taxaccounts bin assembly weight projectnumber project_id oldprojectnumber runningnumber serialnumber partsgroup));
605
606   # remove any makes or model rows
607   if ($form->{item} eq 'part') {
608     map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(listprice sellprice lastcost weight rop);
609     
610     @flds = (make, model);
611     for my $i (1 .. ($form->{makemodel_rows})) {
612       if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
613         push @a, {};
614         my $j = $#a;
615
616         map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
617         $count++;
618       }
619     }
620
621     $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
622     $form->{makemodel_rows} = $count;
623
624   } elsif ($form->{item} eq 'assembly') {
625
626     $form->{sellprice} = 0;
627     $form->{weight} = 0;
628     map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(listprice rop stock);
629
630     @flds = qw(id qty unit bom partnumber description sellprice weight runningnumber partsgroup);
631     
632     for my $i (1 .. ($form->{assembly_rows} - 1)) {
633       if ($form->{"qty_$i"}) {
634         push @a, {};
635         my $j = $#a;
636
637         $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
638
639         map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
640
641         $form->{sellprice} += ($form->{"qty_$i"} * $form->{"sellprice_$i"});
642         $form->{weight} += ($form->{"qty_$i"} * $form->{"weight_$i"});
643         $count++;
644       }
645     }
646
647     $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
648     
649     $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
650     $form->{assembly_rows} = $count;
651     
652     $count = 0;
653     @flds = qw(make model);
654     @a = ();
655     
656     for my $i (1 .. ($form->{makemodel_rows})) {
657       if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
658         push @a, {};
659         my $j = $#a;
660
661         map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
662         $count++;
663       }
664     }
665
666     $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
667     $form->{makemodel_rows} = $count;
668
669   } else {
670
671     # this section applies to invoices and orders
672     # remove any empty numbers
673     if ($form->{rowcount}) {
674       for my $i (1 .. $form->{rowcount} - 1) {
675         if ($form->{"partnumber_$i"}) {
676           push @a, {};
677           my $j = $#a;
678
679           map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
680           $count++;
681           if ($lizenzen) {
682                 if ($form->{"licensenumber_$i"} == -1) {
683                         &new_license($i);
684                         exit;
685                 }
686           }
687         }
688       }
689       
690       $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
691       $form->{rowcount} = $count;
692
693       $form->{creditremaining} -= &invoicetotal;
694       
695     }
696   }
697
698   &display_form;
699
700   $lxdebug->leave_sub();
701 }
702
703
704 sub invoicetotal {
705   $lxdebug->enter_sub();
706
707   $form->{oldinvtotal} = 0;
708   # add all parts and deduct paid
709   map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
710
711   my ($amount, $sellprice, $discount, $qty);
712   
713   for my $i (1 .. $form->{rowcount}) {
714     $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
715     $discount = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
716     $qty = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
717
718     $amount = $sellprice * (1 - $discount / 100) * $qty;
719     map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
720     $form->{oldinvtotal} += $amount;
721   }
722
723   map { $form->{oldinvtotal} += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{taxaccounts} if !$form->{taxincluded};
724   
725   $form->{oldtotalpaid} = 0;
726   for $i (1 .. $form->{paidaccounts}) {
727     $form->{oldtotalpaid} += $form->{"paid_$i"};
728   }
729   
730   $lxdebug->leave_sub();
731
732   # return total
733   return ($form->{oldinvtotal} - $form->{oldtotalpaid});
734 }
735
736
737 sub validate_items {
738   $lxdebug->enter_sub();
739   
740   # check if items are valid
741   if ($form->{rowcount} == 1) {
742     &update;
743     exit;
744   }
745     
746   for $i (1 .. $form->{rowcount} - 1) {
747     $form->isblank("partnumber_$i", $locale->text('Number missing in Row') . " $i");
748   }
749
750   $lxdebug->leave_sub();
751 }
752
753
754 sub order {
755   $lxdebug->enter_sub();
756
757   $form->{ordnumber} = $form->{invnumber};
758
759
760   map { delete $form->{$_} } qw(id printed emailed queued);  
761
762   if ($form->{script} eq 'ir.pl' || $form->{type} eq 'request_quotation') {
763     $form->{title} = $locale->text('Add Purchase Order');
764     $form->{vc} = 'vendor';
765     $form->{type} = 'purchase_order';
766     $buysell = 'sell';
767   }
768   if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_quotation') {
769     $form->{title} = $locale->text('Add Sales Order');
770     $form->{vc} = 'customer';
771     $form->{type} = 'sales_order';
772     $buysell = 'buy';
773   }
774   $form->{script} = 'oe.pl';
775
776   $form->{shipto} = 1;
777   
778   $form->{rowcount}--;
779   
780   ($null, $form->{cp_id}) = split /--/, $form->{contact};
781   $form->{cp_id} *= 1;
782   
783   require "$form->{path}/$form->{script}";
784
785   map { $form->{"select$_"} = "" } ($form->{vc}, currency);
786   
787   $currency = $form->{currency};
788
789   &order_links;
790
791   $form->{currency} = $currency;
792   $form->{exchangerate} = "";
793   $form->{forex} = "";
794   $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell))); 
795   
796   &prepare_order;
797   &display_form;
798
799   $lxdebug->leave_sub();
800 }
801
802
803 sub quotation {
804   $lxdebug->enter_sub();
805
806   map { delete $form->{$_} } qw(id printed emailed queued);
807   
808   if ($form->{script} eq 'ir.pl' || $form->{type} eq 'purchase_order') {
809     $form->{title} = $locale->text('Add Request for Quotation');
810     $form->{vc} = 'vendor';
811     $form->{type} = 'request_quotation';
812     $buysell = 'sell';
813   }
814   if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_order') {
815     $form->{title} = $locale->text('Add Quotation');
816     $form->{vc} = 'customer';
817     $form->{type} = 'sales_quotation';
818     $buysell = 'buy';
819   }
820   
821   ($null, $form->{cp_id}) = split /--/, $form->{contact};
822   $form->{cp_id} *= 1;
823   
824   $form->{script} = 'oe.pl';
825
826   $form->{shipto} = 1;
827   
828   $form->{rowcount}--;
829
830   require "$form->{path}/$form->{script}";
831
832   map { $form->{"select$_"} = "" } ($form->{vc}, currency);
833   
834   $currency = $form->{currency};
835   
836   &order_links;
837
838   $form->{currency} = $currency;
839   $form->{exchangerate} = "";
840   $form->{forex} = "";
841   $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell))); 
842   
843   &prepare_order;
844   &display_form;
845
846   $lxdebug->leave_sub();
847 }
848
849
850
851 sub e_mail {
852   $lxdebug->enter_sub();
853
854   if ($myconfig{role} eq 'admin') {
855     $bcc = qq|
856           <th align=right nowrap=true>|.$locale->text('Bcc').qq|</th>
857           <td><input name=bcc size=30 value="$form->{bcc}"></td>
858 |;
859   }
860
861   if ($form->{formname} =~ /(pick|packing|bin)_list/) {
862     $form->{email} = $form->{shiptoemail} if $form->{shiptoemail};
863   }
864
865   $name = $form->{$form->{vc}};
866   $name =~ s/--.*//g;
867   $title = $locale->text('E-mail')." $name";
868   
869   $form->{oldmedia} = $form->{media};
870   $form->{media} = "email";
871   
872   $form->header;
873
874   print qq|
875 <body>
876
877 <form method=post action=$form->{script}>
878
879 <table width=100%>
880   <tr class=listtop>
881     <th class=listtop>$title</th>
882   </tr>
883   <tr height="5"></tr>
884   <tr>
885     <td>
886       <table width=100%>
887         <tr>
888           <th align=right nowrap>|.$locale->text('To').qq|</th>
889           <td><input name=email size=30 value="$form->{email}"></td>
890           <th align=right nowrap>|.$locale->text('Cc').qq|</th>
891           <td><input name=cc size=30 value="$form->{cc}"></td>
892         </tr>
893         <tr>
894           <th align=right nowrap>|.$locale->text('Subject').qq|</th>
895           <td><input name=subject size=30 value="$form->{subject}"></td>
896           $bcc
897         </tr>
898       </table>
899     </td>
900   </tr>
901   <tr>
902     <td>
903       <table width=100%>
904         <tr>
905           <th align=left nowrap>|.$locale->text('Message').qq|</th>
906         </tr>
907         <tr>
908           <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
909         </tr>
910       </table>
911     </td>
912   </tr>
913   <tr>
914     <td>
915 |;
916
917   &print_options;
918   
919   map { delete $form->{$_} } qw(action email cc bcc subject message formname sendmode format header override);
920   
921   # save all other variables
922   foreach $key (keys %$form) {
923     $form->{$key} =~ s/\"/&quot;/g;
924     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
925   }
926
927   print qq|
928     </td>
929   </tr>
930   <tr>
931     <td><hr size=3 noshade></td>
932   </tr>
933 </table>
934
935 <input type=hidden name=nextsub value=send_email>
936
937 <br>
938 <input name=action class=submit type=submit value="|.$locale->text('Continue').qq|">
939 </form>
940
941 </body>
942 </html>
943 |;
944
945   $lxdebug->leave_sub();
946 }
947
948
949 sub send_email {
950   $lxdebug->enter_sub();
951
952   $old_form = new Form;
953   
954   map { $old_form->{$_} = $form->{$_} } keys %$form;
955   $old_form->{media} = $form->{oldmedia};
956   
957   &print_form($old_form);
958   
959   $lxdebug->leave_sub();
960 }
961   
962
963  
964 sub print_options {
965   $lxdebug->enter_sub();
966
967   $form->{sendmode} = "attachment";
968   $form->{copies} = 3 unless $form->{copies};
969   
970   $form->{PD}{$form->{formname}} = "selected";
971   $form->{DF}{$form->{format}} = "";
972   $form->{OP}{$form->{media}} = "selected";
973   $form->{SM}{$form->{sendmode}} = "selected";
974   
975   
976   if ($form->{type} eq 'purchase_order') {
977     $type = qq|<select name=formname>
978             <option value=purchase_order $form->{PD}{purchase_order}>|.$locale->text('Purchase Order').qq|
979             <option value=bin_list $form->{PD}{bin_list}>|.$locale->text('Bin List');
980   }
981   
982   if ($form->{type} eq 'sales_order') {
983     $type = qq|<select name=formname>
984             <option value=sales_order $form->{PD}{sales_order}>|.$locale->text('Confirmation').qq|
985             <option value=pick_list $form->{PD}{pick_list}>|.$locale->text('Pick List').qq|
986             <option value=packing_list $form->{PD}{packing_list}>|.$locale->text('Packing List');
987   }
988   
989   if ($form->{type} =~ /_quotation$/) {
990     $type = qq|<select name=formname>
991             <option value="$`_quotation" $form->{PD}{"$`_quotation"}>|.$locale->text('Quotation').qq|
992 |;
993   }
994   
995   if ($form->{type} eq 'invoice') {
996     $type = qq|<select name=formname>
997             <option value=invoice $form->{PD}{invoice}>|.$locale->text('Invoice');
998   }
999   
1000   if ($form->{type} eq 'ship_order') {
1001     $type = qq|<select name=formname>
1002             <option value=pick_list $form->{PD}{pick_list}>|.$locale->text('Pick List').qq|
1003             <option value=packing_list $form->{PD}{packing_list}>|.$locale->text('Packing List');
1004   }
1005   
1006   if ($form->{type} eq 'receive_order') {
1007     $type = qq|<select name=formname>
1008             <option value=bin_list $form->{PD}{bin_list}>|.$locale->text('Bin List');
1009   }
1010  
1011   if ($form->{media} eq 'email') {
1012     $media = qq|<select name=sendmode>
1013             <option value=attachment $form->{SM}{attachment}>|.$locale->text('Attachment').qq|
1014             <option value=inline $form->{SM}{inline}>|.$locale->text('In-line');
1015   } else {
1016     $media = qq|<select name=media>
1017             <option value=screen $form->{OP}{screen}>|.$locale->text('Screen');
1018     if ($myconfig{printer} && $latex) {
1019       $media .= qq|
1020             <option value=printer $form->{OP}{printer}>|.$locale->text('Printer');
1021     }
1022     if ($latex) {
1023       $media .= qq|
1024             <option value=queue $form->{OP}{queue}>|.$locale->text('Queue');
1025     }
1026   }
1027
1028   $format = qq|<select name=format>
1029             <option value=html $form->{DF}{html}>html|;
1030
1031   if ($latex) {
1032     $format = qq|<select name=format>
1033             <option value=pdf $form->{DF}{pdf}>|.$locale->text('PDF').qq|
1034             <option value=html $form->{DF}{html}>html
1035             <option value=postscript $form->{DF}{postscript}>|.$locale->text('Postscript');
1036   }
1037   
1038   $language = qq|<select name=language>
1039                  <option value=""></option>|;
1040   %lang = (de=>"deutsch", en=>"englisch", fr=>"französisch");
1041   foreach $item (keys %lang) {
1042     if ($form->{language} eq $item) {
1043       $language .= qq|<option value="$item" selected>$lang{$item}</option>|;
1044     } else {
1045       $language .= qq|<option value="$item">$lang{$item}</option>|;
1046     }
1047   }
1048
1049   print qq|
1050 <table width=100% cellspacing=0 cellpadding=0>
1051   <tr>
1052     <td>
1053       <table>
1054         <tr>
1055           <td>$type</select></td>
1056           <td>$language</select</td>
1057           <td>$format</select></td>
1058           <td>$media</select></td>
1059 |;
1060
1061   if ($myconfig{printer} && $latex && $form->{media} ne 'email') {
1062     print qq|
1063           <td>|.$locale->text('Copies').qq|
1064           <input name=copies size=2 value=$form->{copies}></td>
1065 |;
1066   }
1067
1068   $form->{groupitems} = "checked" if $form->{groupitems};
1069
1070   print qq|
1071           <td>|.$locale->text('Group Items').qq|</td>
1072           <td><input name=groupitems type=checkbox class=checkbox $form->{groupitems}></td>
1073         </tr>
1074       </table>
1075     </td>
1076     <td align=right>
1077       <table>
1078         <tr>
1079 |;
1080
1081   if ($form->{printed} =~ /$form->{formname}/) {
1082     print qq|
1083           <th>\||.$locale->text('Printed').qq|\|</th>
1084 |;
1085   }
1086   
1087   if ($form->{emailed} =~ /$form->{formname}/) {
1088     print qq|
1089           <th>\||.$locale->text('E-mailed').qq|\|</th>
1090 |;
1091   }
1092   
1093   if ($form->{queued} =~ /$form->{formname}/) {
1094     print qq|
1095           <th>\||.$locale->text('Queued').qq|\|</th>
1096 |;
1097   }
1098   
1099   print qq|
1100         </tr>
1101       </table>
1102     </td>
1103   </tr>
1104 </table>
1105 |;
1106
1107
1108   $lxdebug->leave_sub();
1109 }
1110
1111
1112
1113 sub print {
1114   $lxdebug->enter_sub();
1115
1116   # if this goes to the printer pass through
1117   if ($form->{media} eq 'printer' || $form->{media} eq 'queue') {
1118     $form->error($locale->text('Select postscript or PDF!')) if ($form->{format} !~ /(postscript|pdf)/);
1119
1120     $old_form = new Form;
1121     map { $old_form->{$_} = $form->{$_} } keys %$form;
1122   }
1123
1124   &print_form($old_form);
1125
1126   $lxdebug->leave_sub();
1127 }
1128
1129
1130 sub print_form {
1131   $lxdebug->enter_sub();
1132   my ($old_form) = @_;
1133   
1134   $inv = "inv";
1135   $due = "due";
1136   
1137   $numberfld = "invnumber";
1138
1139   $display_form = ($form->{display_form}) ? $form->{display_form} : "display_form";
1140
1141   # $form->{"notes"} will be overridden by the customer's/vendor's "notes" field. So save it here.
1142   $form->{$form->{"formname"} . "notes"} = $form->{"notes"};
1143
1144   if ($form->{formname} eq "invoice") {
1145     $form->{label} = $locale->text('Invoice');
1146   }
1147   if ($form->{formname} eq "packing_list") {
1148     # this is from an invoice
1149     $form->{label} = $locale->text('Packing List');
1150   }
1151   if ($form->{formname} eq 'sales_order') {
1152     $inv = "ord";
1153     $due = "req";
1154     $form->{"${inv}date"} = $form->{transdate};
1155     $form->{label} = $locale->text('Sales Order');
1156     $numberfld = "sonumber";
1157     $order = 1;
1158   }
1159   if ($form->{formname} eq 'packing_list' && $form->{type} ne 'invoice') {
1160     # we use the same packing list as from an invoice
1161     $inv = "ord";
1162     $due = "req";
1163     $form->{invdate} = $form->{"${inv}date"} = $form->{transdate};
1164     $form->{label} = $locale->text('Packing List');
1165     $order = 1;
1166   }
1167   if ($form->{formname} eq 'pick_list') {
1168     $inv = "ord";
1169     $due = "req";
1170     $form->{"${inv}date"} = ($form->{transdate}) ? $form->{transdate} : $form->{invdate};
1171     $form->{label} = $locale->text('Pick List');
1172     $order = 1 unless $form->{type} eq 'invoice';
1173   }
1174   if ($form->{formname} eq 'purchase_order') {
1175     $inv = "ord";
1176     $due = "req";
1177     $form->{"${inv}date"} = $form->{transdate};
1178     $form->{label} = $locale->text('Purchase Order');
1179     $numberfld = "ponumber";
1180     $order = 1;
1181   }
1182   if ($form->{formname} eq 'bin_list') {
1183     $inv = "ord";
1184     $due = "req";
1185     $form->{"${inv}date"} = $form->{transdate};
1186     $form->{label} = $locale->text('Bin List');
1187     $order = 1;
1188   }
1189   if ($form->{formname} eq 'sales_quotation') {
1190     $inv = "quo";
1191     $due = "req";
1192     $form->{"${inv}date"} = $form->{transdate};
1193     $form->{label} = $locale->text('Quotation');
1194     $numberfld = "sqnumber";
1195     $order = 1;
1196   }
1197   if ($form->{formname} eq 'request_quotation') {
1198     $inv = "quo";
1199     $due = "req";
1200     $form->{"${inv}date"} = $form->{transdate};
1201     $form->{label} = $locale->text('Quotation');
1202     $numberfld = "rfqnumber";
1203     $order = 1;
1204   }
1205
1206   $form->isblank("email", $locale->text('E-mail address missing!')) if ($form->{media} eq 'email');
1207   $form->isblank("${inv}date", $locale->text($form->{label} .' Date missing!'));
1208
1209 # $locale->text('Invoice Number missing!')
1210 # $locale->text('Invoice Date missing!')
1211 # $locale->text('Packing List Number missing!')
1212 # $locale->text('Packing List Date missing!')
1213 # $locale->text('Order Number missing!')
1214 # $locale->text('Order Date missing!')
1215 # $locale->text('Quotation Number missing!')
1216 # $locale->text('Quotation Date missing!')
1217
1218
1219   # assign number
1220   if (! $form->{"${inv}number"}) {
1221     $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
1222     if ($form->{media} ne 'email') {
1223       $form->{rowcount}--;
1224       &{ "$display_form" };
1225       exit;
1226     }
1227   }
1228
1229   &validate_items;
1230
1231   # Save the email address given in the form because it should override the setting saved for the customer/vendor.
1232   my ($saved_email, $saved_cc, $saved_bcc) = ($form->{"email"}, $form->{"cc"}, $form->{"bcc"});
1233   
1234   $language = $form->{language};
1235   &{ "$form->{vc}_details" };
1236   $form->{language} = $language;
1237   
1238   $form->{"email"} = $saved_email if ($saved_email);
1239   $form->{"cc"} = $saved_cc if ($saved_cc);
1240   $form->{"bcc"} = $saved_bcc if ($saved_bcc);
1241   
1242   @a = ();
1243   foreach $i (1 .. $form->{rowcount}) {
1244     push @a, ("partnumber_$i", "description_$i", "partsgroup_$i", "serialnumber_$i", "bin_$i", "unit_$i");
1245   }
1246   map { push @a, "${_}_description" } split / /, $form->{taxaccounts};
1247
1248   $ARAP = ($form->{vc} eq 'customer') ? "AR" : "AP";
1249   push @a, $ARAP;
1250   
1251   # format payment dates
1252   for $i (1 .. $form->{paidaccounts} - 1) {
1253     $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"});
1254     push @a, "${ARAP}_paid_$i", "source_$i", "memo_$i";
1255   }
1256   
1257   $form->format_string(@a);
1258   
1259   ($form->{employee}) = split /--/, $form->{employee};
1260   ($form->{warehouse}, $form->{warehouse_id}) = split /--/, $form->{warehouse};
1261   
1262   # create the form variables
1263   if ($order) {
1264     OE->order_details(\%myconfig, \%$form);
1265   } else {
1266     IS->invoice_details(\%myconfig, \%$form, $locale);
1267   }
1268   
1269   map { $form->{$_} = $locale->date(\%myconfig, $form->{$_}, 1) } ("${inv}date", "${due}date", "shippingdate");
1270   
1271   
1272   @a = qw(name street zipcode city country);
1273  
1274   $shipto = 1;
1275   # if there is no shipto fill it in from billto
1276   foreach $item (@a) {
1277     if ($form->{"shipto$item"}) {
1278       $shipto = 0;
1279       last;
1280     }
1281   }
1282
1283   if ($shipto) {
1284     if ($form->{formname} eq 'purchase_order' || $form->{formname} eq 'request_quotation') {
1285         $form->{shiptoname} = $myconfig{company};
1286         $form->{shiptostreet} = $myconfig{address};
1287     } else {
1288       map { $form->{"shipto$_"} = $form->{$_} } @a;
1289     }
1290   }
1291
1292   $form->{notes} =~ s/^\s+//g;
1293
1294   # some of the stuff could have umlauts so we translate them
1295   push @a, qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptoemail shippingpoint shipvia company address signature employee contact);
1296
1297
1298   push @a, ("${inv}date", "${due}date", email, cc, bcc);
1299
1300   $form->format_string(@a);
1301
1302
1303   $form->{templates} = "$myconfig{templates}";
1304   if ($form->{language} ne "") {
1305     $form->{language} = "_".$form->{language};
1306   }
1307   
1308   $form->{IN} = "$form->{formname}$form->{language}.html";
1309   if ($form->{format} eq 'postscript') {
1310     $form->{postscript} = 1;
1311     $form->{IN} =~ s/html$/tex/;
1312   }
1313   if ($form->{format} eq 'pdf') {
1314     $form->{pdf} = 1;
1315     $form->{IN} =~ s/html$/tex/;
1316   }
1317
1318   if ($form->{media} eq 'printer') {
1319     $form->{OUT} = "| $myconfig{printer}";
1320     $form->{printed} .= " $form->{formname}";
1321     $form->{printed} =~ s/^ //;
1322   }
1323   $printed = $form->{printed};
1324   
1325   if ($form->{media} eq 'email') {
1326     $form->{subject} = qq|$form->{label} $form->{"${inv}number"}| unless $form->{subject};
1327     
1328     $form->{OUT} = "$sendmail";
1329      
1330     $form->{emailed} .= " $form->{formname}";
1331     $form->{emailed} =~ s/^ //;
1332   }
1333   $emailed = $form->{emailed};
1334
1335
1336   if ($form->{media} eq 'queue') {
1337     %queued = split / /, $form->{queued};
1338     
1339     if ($filename = $queued{$form->{formname}}) {
1340       $form->{queued} =~ s/$form->{formname} $filename//;
1341       unlink "$spool/$filename";
1342       $filename =~ s/\..*$//g;
1343     } else {
1344       $filename = time;
1345       $filename .= $$;
1346     }
1347
1348     
1349     $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
1350     $form->{OUT} = ">$spool/$filename";
1351     
1352     # add type
1353     $form->{queued} .= " $form->{formname} $filename";
1354
1355     $form->{queued} =~ s/^ //;
1356   }
1357   $queued = $form->{queued};
1358
1359
1360   $form->parse_template(\%myconfig, $userspath);
1361
1362   $form->{callback} = "";
1363
1364   if ($form->{media} eq 'email') {
1365     $form->{message} = $locale->text('sent') unless $form->{message};
1366   }
1367   $message = $form->{message};
1368   
1369   # if we got back here restore the previous form
1370   if ($form->{media} =~ /(printer|email|queue)/) {
1371
1372     $form->update_status(\%myconfig) if ($form->{media} eq 'queue' && $form->{id});
1373    
1374     if ($old_form) {
1375       
1376       $old_form->{"${inv}number"} = $form->{"${inv}number"};
1377       
1378       # restore and display form
1379       map { $form->{$_} = $old_form->{$_} } keys %$old_form;
1380       
1381       $form->{queued} = $queued;
1382       $form->{printed} = $printed;
1383       $form->{emailed} = $emailed;
1384       $form->{message} = $message;
1385
1386       $form->{rowcount}--;
1387       map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
1388       
1389       for $i (1 .. $form->{paidaccounts}) {
1390         map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
1391       }
1392       
1393       &{ "$display_form" };
1394       exit;
1395     }
1396
1397     $msg = ($form->{media} eq 'printer') ? $locale->text('sent to printer') : $locale->text('emailed to')." $form->{email}";
1398     $form->redirect(qq|$form->{label} $form->{"${inv}number"} $msg|);
1399   }
1400
1401   $lxdebug->leave_sub();
1402 }
1403
1404
1405 sub customer_details {
1406   $lxdebug->enter_sub();
1407    
1408    IS->customer_details(\%myconfig, \%$form);
1409   $lxdebug->leave_sub();
1410 }
1411
1412
1413 sub vendor_details {
1414   $lxdebug->enter_sub();
1415
1416   IR->vendor_details(\%myconfig, \%$form);
1417
1418   $lxdebug->leave_sub();
1419 }
1420
1421
1422 sub post_as_new {
1423   $lxdebug->enter_sub();
1424
1425   $form->{postasnew} = 1;
1426   map { delete $form->{$_} } qw(printed emailed queued);
1427   
1428   &post;
1429
1430   $lxdebug->leave_sub();
1431 }
1432
1433
1434 sub ship_to {
1435   $lxdebug->enter_sub();
1436
1437   $title = $form->{title};
1438   $form->{title} = $locale->text('Ship to');
1439
1440   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
1441
1442   # get details for name
1443   &{ "$form->{vc}_details" };
1444
1445   $number = ($form->{vc} eq 'customer') ? $locale->text('Customer Number') : $locale->text('Vendor Number');
1446
1447   $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
1448
1449   $form->{rowcount}--;
1450
1451   $form->header;
1452
1453   print qq|
1454 <body>
1455
1456 <form method=post action=$form->{script}>
1457
1458 <table width=100%>
1459   <tr>
1460     <td>
1461       <table>
1462         <tr class=listheading>
1463           <th class=listheading colspan=2 width=50%>|.$locale->text('Billing Address').qq|</th>
1464           <th class=listheading width=50%>|.$locale->text('Shipping Address').qq|</th>
1465         </tr>
1466         <tr height="5"></tr>
1467         <tr>
1468           <th align=right nowrap>$number</th>
1469           <td>$form->{"$form->{vc}number"}</td>
1470         </tr>
1471         <tr>
1472           <th align=right nowrap>|.$locale->text('Company Name').qq|</th>
1473           <td>$form->{name}</td>
1474           <td><input name=shiptoname size=35 value="$form->{shiptoname}"></td>
1475         </tr>
1476         <tr>
1477           <th align=right nowrap>|.$locale->text('Street').qq|</th>
1478           <td>$form->{street}</td>
1479           <td><input name=shiptostreet size=35 value="$form->{shiptostreet}"></td>
1480         </tr>
1481         <tr>
1482           <th align=right nowrap>|.$locale->text('Zipcode').qq|</th>
1483           <td>$form->{zipcode}</td>
1484           <td><input name=shiptozipcode size=35 value="$form->{shiptozipcode}"></td>
1485         </tr>
1486         <tr>
1487           <th align=right nowrap>|.$locale->text('City').qq|</th>
1488           <td>$form->{city}</td>
1489           <td><input name=shiptocity size=35 value="$form->{shiptocity}"></td>
1490         </tr>
1491         <tr>
1492           <th align=right nowrap>|.$locale->text('Country').qq|</th>
1493           <td>$form->{country}</td>
1494           <td><input name=shiptocountry size=35 value="$form->{shiptocountry}"></td>
1495         </tr>
1496         <tr>
1497           <th align=right nowrap>|.$locale->text('Contact').qq|</th>
1498           <td>$form->{contact}</td>
1499           <td><input name=shiptocontact size=35 value="$form->{shiptocontact}"></td>
1500         </tr>
1501         <tr>
1502           <th align=right nowrap>|.$locale->text('Phone').qq|</th>
1503           <td>$form->{"$form->{vc}phone"}</td>
1504           <td><input name=shiptophone size=20 value="$form->{shiptophone}"></td>
1505         </tr>
1506         <tr>
1507           <th align=right nowrap>|.$locale->text('Fax').qq|</th>
1508           <td>$form->{"$form->{vc}fax"}</td>
1509           <td><input name=shiptofax size=20 value="$form->{shiptofax}"></td>
1510         </tr>
1511         <tr>
1512           <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
1513           <td>$form->{email}</td>
1514           <td><input name=shiptoemail size=35 value="$form->{shiptoemail}"></td>
1515         </tr>
1516       </table>
1517     </td>
1518   </tr>
1519 </table>
1520
1521 <input type=hidden name=nextsub value=$nextsub>
1522 |;
1523
1524   # delete shipto
1525   map { delete $form->{$_} } qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax shiptoemail header);
1526   $form->{title} = $title;
1527   
1528   foreach $key (keys %$form) {
1529     $form->{$key} =~ s/\"/&quot;/g;
1530     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1531   }
1532
1533   print qq|
1534
1535 <hr size=3 noshade>
1536
1537 <br>
1538 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
1539 </form>
1540
1541 </body>
1542 </html>
1543 |;
1544
1545   $lxdebug->leave_sub();
1546 }
1547
1548
1549 sub new_license {
1550   $lxdebug->enter_sub();
1551   
1552   my $row = shift;
1553
1554   # change callback
1555   $form->{old_callback} = $form->escape($form->{callback},1);
1556   $form->{callback} = $form->escape("$form->{script}?action=display_form",1);
1557   $form->{old_callback} = $form->escape($form->{old_callback},1);
1558   # delete action
1559   delete $form->{action};
1560   $customer = $form->{customer};
1561   map {  $form->{"old_$_"} = $form->{"${_}_$row"} } qw(partnumber description);
1562
1563   # save all other form variables in a previousform variable
1564   $form->{row} = $row;
1565   foreach $key (keys %$form) {
1566     # escape ampersands
1567     $form->{$key} =~ s/&/%26/g;
1568     $previousform .= qq|$key=$form->{$key}&|;
1569   }
1570   chop $previousform;
1571   $previousform = $form->escape($previousform, 1);
1572
1573   $form->{script} = "licenses.pl";
1574   
1575
1576   
1577   map {  $form->{$_} = $form->{"old_$_"} } qw(partnumber description);
1578   map {  $form->{$_} = $form->escape($form->{$_},1) } qw(partnumber description);
1579   $form->{callback} = 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|;
1580   $form->redirect;
1581
1582   $lxdebug->leave_sub();
1583 }
1584
1585
1586