Entfernung von totem Code: Die Funktion menubar() gibt es schon lange nicht mehr.
[kivitendo-erp.git] / bin / mozilla / ct.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 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (c) 1998-2002
10 #
11 #  Author: Dieter Simader
12 #   Email: dsimader@sql-ledger.org
13 #     Web: http://www.sql-ledger.org
14 #
15 #  Contributors: Reed White <alta@alta-research.com>
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 # customer/vendor module
32 #
33 #======================================================================
34
35 # $locale->text('Customers')
36 # $locale->text('Vendors')
37 # $locale->text('Add Customer')
38 # $locale->text('Add Vendor')
39
40 use SL::CT;
41 use CGI::Ajax;
42 use CGI;
43 use Data::Dumper;
44
45 1;
46
47 # end of main
48
49 sub add {
50   $lxdebug->enter_sub();
51
52   $form->{title} = "Add";
53
54   $form->{callback} =
55     "$form->{script}?action=add&db=$form->{db}&path=$form->{path}&login=$form->{login}&password=$form->{password}"
56     unless $form->{callback};
57
58   CT->taxaccounts(\%myconfig, \%$form);
59
60   &form_header;
61   &form_footer;
62
63   $lxdebug->leave_sub();
64 }
65
66 sub search {
67   $lxdebug->enter_sub();
68
69   $label = ucfirst $form->{db};
70   $form->{title} = $locale->text($label . "s");
71
72   if ($form->{db} eq 'vendor') {
73     $gifi = qq|
74                 <td><input name="l_gifi_accno" type=checkbox class=checkbox value=Y> |
75       . $locale->text('GIFI') . qq|</td>
76 |;
77   }
78
79   $form->header;
80
81   print qq|
82 <body>
83
84 <form method=post action=$form->{script}>
85
86 <input type=hidden name=db value=$form->{db}>
87
88 <table width=100%>
89   <tr>
90     <th class=listtop>$form->{title}</th>
91   </tr>
92   <tr height="5"></tr>
93   <tr valign=top>
94     <td>
95       <table>
96         <tr>
97           <th align=right nowrap>| . $locale->text($label . ' Number') . qq|</th>
98           <td><input name=$form->{db}number size=35></td>
99         </tr>
100         <tr>
101           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
102           <td><input name=name size=35></td>
103         </tr>
104         <tr>
105           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
106           <td><input name=contact size=35></td>
107         </tr>
108         <tr>
109           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
110           <td><input name=email size=35></td>
111         </tr>
112         <tr>
113           <td></td>
114           <td><input name=status class=radio type=radio value=all checked>&nbsp;|
115     . $locale->text('All') . qq|
116           <input name=status class=radio type=radio value=orphaned>&nbsp;|
117     . $locale->text('Orphaned') . qq|</td>
118         </tr>
119         <tr>
120           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
121           <td>
122             <table>
123               <tr>
124                 <td><input name="l_id" type=checkbox class=checkbox value=Y> |
125     . $locale->text('ID') . qq|</td>
126                 <td><input name="l_$form->{db}number" type=checkbox class=checkbox value=Y> |
127     . $locale->text($label . ' Number') . qq|</td>
128                 <td><input name="l_name" type=checkbox class=checkbox value=Y checked> |
129     . $locale->text('Company Name') . qq|</td>
130                 <td><input name="l_address" type=checkbox class=checkbox value=Y> |
131     . $locale->text('Address') . qq|</td>
132               </tr>
133               <tr>
134                 <td><input name="l_contact" type=checkbox class=checkbox value=Y checked> |
135     . $locale->text('Contact') . qq|</td>
136                 <td><input name="l_phone" type=checkbox class=checkbox value=Y checked> |
137     . $locale->text('Phone') . qq|</td>
138                 <td><input name="l_fax" type=checkbox class=checkbox value=Y> |
139     . $locale->text('Fax') . qq|</td>
140                 <td><input name="l_email" type=checkbox class=checkbox value=Y checked> |
141     . $locale->text('E-mail') . qq|</td>
142               </tr>
143               <tr>
144                 <td><input name="l_taxnumber" type=checkbox class=checkbox value=Y> |
145     . $locale->text('Tax Number') . qq|</td>
146                 $gifi
147                 <td><input name="l_sic_code" type=checkbox class=checkbox value=Y> |
148     . $locale->text('SIC') . qq|</td>
149                 <td><input name="l_business" type=checkbox class=checkbox value=Y> |
150     . $locale->text('Type of Business') . qq|</td>
151               </tr>
152               <tr>
153                 <td><input name="l_invnumber" type=checkbox class=checkbox value=Y> |
154     . $locale->text('Invoices') . qq|</td>
155                 <td><input name="l_ordnumber" type=checkbox class=checkbox value=Y> |
156     . $locale->text('Orders') . qq|</td>
157                 <td><input name="l_quonumber" type=checkbox class=checkbox value=Y> |
158     . $locale->text('Quotations') . qq|</td>
159               </tr>
160             </table>
161           </td>
162         </tr>
163       </table>
164     </td>
165   </tr>
166   <tr>
167     <td><hr size=3 noshade></td>
168   </tr>
169 </table>
170
171 <input type=hidden name=nextsub value=list_names>
172
173 <input type=hidden name=path value=$form->{path}>
174 <input type=hidden name=login value=$form->{login}>
175 <input type=hidden name=password value=$form->{password}>
176
177 <br>
178 <input type=submit class=submit name=action value="|
179     . $locale->text('Continue') . qq|">
180 </form>
181
182 </body>
183 </html>
184 |;
185   $lxdebug->leave_sub();
186 }
187
188 sub search_delivery {
189   $lxdebug->enter_sub();
190
191   $label = ucfirst $form->{db};
192   $form->{title} = $locale->text($label . "s");
193
194   if ($form->{db} eq 'vendor') {
195     $gifi = qq|
196                 <td><input name="l_gifi_accno" type=checkbox class=checkbox value=Y> |
197       . $locale->text('GIFI') . qq|</td>
198 |;
199   }
200
201   $form->header;
202
203   print qq|
204 <body>
205
206 <form method=post action=$form->{script}>
207
208 <input type=hidden name=db value=$form->{db}>
209
210 <table width=100%>
211   <tr>
212     <th class=listtop>$form->{title}</th>
213   </tr>
214   <tr height="5"></tr>
215   <tr valign=top>
216     <td>
217       <table>
218         <tr>
219           <th align=right nowrap>| . $locale->text($label . ' Number') . qq|</th>
220           <td><input name=$form->{db}number size=35></td>
221         </tr>
222         <tr>
223           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
224           <td><input name=name size=35></td>
225         </tr>
226         <tr>
227           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
228           <td><input name=contact size=35></td>
229         </tr>
230         <tr>
231           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
232           <td><input name=email size=35></td>
233         </tr>
234         <tr>
235           <td></td>
236           <td><input name=status class=radio type=radio value=all checked>&nbsp;|
237     . $locale->text('All') . qq|
238           <input name=status class=radio type=radio value=orphaned>&nbsp;|
239     . $locale->text('Orphaned') . qq|</td>
240         </tr>
241         <tr>
242           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
243           <td>
244             <table>
245               <tr>
246                 <td><input name="l_id" type=checkbox class=checkbox value=Y> |
247     . $locale->text('ID') . qq|</td>
248                 <td><input name="l_$form->{db}number" type=checkbox class=checkbox value=Y> |
249     . $locale->text($label . ' Number') . qq|</td>
250                 <td><input name="l_name" type=checkbox class=checkbox value=Y checked> |
251     . $locale->text('Company Name') . qq|</td>
252                 <td><input name="l_address" type=checkbox class=checkbox value=Y> |
253     . $locale->text('Address') . qq|</td>
254               </tr>
255               <tr>
256                 <td><input name="l_contact" type=checkbox class=checkbox value=Y checked> |
257     . $locale->text('Contact') . qq|</td>
258                 <td><input name="l_phone" type=checkbox class=checkbox value=Y checked> |
259     . $locale->text('Phone') . qq|</td>
260                 <td><input name="l_fax" type=checkbox class=checkbox value=Y> |
261     . $locale->text('Fax') . qq|</td>
262                 <td><input name="l_email" type=checkbox class=checkbox value=Y checked> |
263     . $locale->text('E-mail') . qq|</td>
264               </tr>
265               <tr>
266                 <td><input name="l_taxnumber" type=checkbox class=checkbox value=Y> |
267     . $locale->text('Tax Number') . qq|</td>
268                 $gifi
269                 <td><input name="l_sic_code" type=checkbox class=checkbox value=Y> |
270     . $locale->text('SIC') . qq|</td>
271                 <td><input name="l_business" type=checkbox class=checkbox value=Y> |
272     . $locale->text('Type of Business') . qq|</td>
273               </tr>
274               <tr>
275                 <td><input name="l_invnumber" type=checkbox class=checkbox value=Y> |
276     . $locale->text('Invoices') . qq|</td>
277                 <td><input name="l_ordnumber" type=checkbox class=checkbox value=Y> |
278     . $locale->text('Orders') . qq|</td>
279                 <td><input name="l_quonumber" type=checkbox class=checkbox value=Y> |
280     . $locale->text('Quotations') . qq|</td>
281               </tr>
282             </table>
283           </td>
284         </tr>
285       </table>
286     </td>
287   </tr>
288   <tr>
289     <td><hr size=3 noshade></td>
290   </tr>
291 </table>
292
293 <input type=hidden name=nextsub value=list_names>
294
295 <input type=hidden name=path value=$form->{path}>
296 <input type=hidden name=login value=$form->{login}>
297 <input type=hidden name=password value=$form->{password}>
298
299 <br>
300 <input type=submit class=submit name=action value="|
301     . $locale->text('Continue') . qq|">
302 </form>
303
304 </body>
305 </html>
306 |;
307   $lxdebug->leave_sub();
308 }
309
310 sub list_names {
311   $lxdebug->enter_sub();
312
313   CT->search(\%myconfig, \%$form);
314
315   $callback =
316     "$form->{script}?action=list_names&db=$form->{db}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}";
317   $href = $callback;
318
319   @columns =
320     $form->sort_columns(id, name,
321                         "$form->{db}number", address,
322                         contact,             phone,
323                         fax,                 email,
324                         taxnumber,           gifi_accno,
325                         sic_code,            business,
326                         invnumber,           ordnumber,
327                         quonumber);
328
329   foreach $item (@columns) {
330     if ($form->{"l_$item"} eq "Y") {
331       push @column_index, $item;
332
333       # add column to href and callback
334       $callback .= "&l_$item=Y";
335       $href     .= "&l_$item=Y";
336     }
337   }
338   $number =
339     ($form->{db} eq "customer")
340     ? $locale->text('Customer Number')
341     : $locale->text('Vendor Number');
342
343   if ($form->{status} eq 'all') {
344     $option = $locale->text('All');
345   }
346   if ($form->{status} eq 'orphaned') {
347     $option .= $locale->text('Orphaned');
348   }
349   if ($form->{name}) {
350     $callback .= "&name=" . $form->escape($form->{name}, 1);
351     $href .= "&name=" . $form->escape($form->{name});
352     $option .= "\n<br>" . $locale->text('Name') . " : $form->{name}";
353   }
354   if ($form->{contact}) {
355     $callback .= "&contact=" . $form->escape($form->{contact}, 1);
356     $href .= "&contact=" . $form->escape($form->{contact});
357     $option .= "\n<br>" . $locale->text('Contact') . " : $form->{contact}";
358   }
359   if ($form->{"$form->{db}number"}) {
360     $callback .=
361       qq|&$form->{db}number=| . $form->escape($form->{"$form->{db}number"}, 1);
362     $href .=
363       "&$form->{db}number=" . $form->escape($form->{"$form->{db}number"});
364     $option .=
365       "\n<br>" . $locale->text('Number') . qq| : $form->{"$form->{db}number"}|;
366   }
367   if ($form->{email}) {
368     $callback .= "&email=" . $form->escape($form->{email}, 1);
369     $href .= "&email=" . $form->escape($form->{email});
370     $option .= "\n<br>" . $locale->text('E-mail') . " : $form->{email}";
371   }
372
373   $form->{callback} = "$callback&sort=$form->{sort}";
374   $callback = $form->escape($form->{callback});
375
376   $column_header{id} =
377     qq|<th class=listheading>| . $locale->text('ID') . qq|</th>|;
378   $column_header{"$form->{db}number"} =
379     qq|<th><a class=listheading href=$href&sort=$form->{db}number>$number</a></th>|;
380   $column_header{name} =
381       qq|<th><a class=listheading href=$href&sort=name>|
382     . $locale->text('Name')
383     . qq|</a></th>|;
384   $column_header{address} =
385       qq|<th><a class=listheading href=$href&sort=address>|
386     . $locale->text('Address')
387     . qq|</a></th>|;
388   $column_header{contact} =
389       qq|<th><a class=listheading href=$href&sort=contact>|
390     . $locale->text('Contact')
391     . qq|</a></th>|;
392   $column_header{phone} =
393       qq|<th><a class=listheading href=$href&sort=phone>|
394     . $locale->text('Phone')
395     . qq|</a></th>|;
396   $column_header{fax} =
397       qq|<th><a class=listheading href=$href&sort=fax>|
398     . $locale->text('Fax')
399     . qq|</a></th>|;
400   $column_header{email} =
401       qq|<th><a class=listheading href=$href&sort=email>|
402     . $locale->text('E-mail')
403     . qq|</a></th>|;
404   $column_header{cc} =
405       qq|<th><a class=listheading href=$href&sort=cc>|
406     . $locale->text('Cc')
407     . qq|</a></th>|;
408
409   $column_header{taxnumber} =
410       qq|<th><a class=listheading href=$href&sort=taxnumber>|
411     . $locale->text('Tax Number')
412     . qq|</a></th>|;
413   $column_header{gifi_accno} =
414       qq|<th><a class=listheading href=$href&sort=gifi_accno>|
415     . $locale->text('GIFI')
416     . qq|</a></th>|;
417   $column_header{sic_code} =
418       qq|<th><a class=listheading href=$href&sort=sic_code>|
419     . $locale->text('SIC')
420     . qq|</a></th>|;
421   $column_header{business} =
422       qq|<th><a class=listheading href=$href&sort=business>|
423     . $locale->text('Type of Business')
424     . qq|</a></th>|;
425
426   $column_header{invnumber} =
427       qq|<th><a class=listheading href=$href&sort=invnumber>|
428     . $locale->text('Invoice')
429     . qq|</a></th>|;
430   $column_header{ordnumber} =
431       qq|<th><a class=listheading href=$href&sort=ordnumber>|
432     . $locale->text('Order')
433     . qq|</a></th>|;
434   $column_header{quonumber} =
435       qq|<th><a class=listheading href=$href&sort=quonumber>|
436     . $locale->text('Quotation')
437     . qq|</a></th>|;
438
439   $label = ucfirst $form->{db} . "s";
440   $form->{title} = $locale->text($label);
441
442   $form->header;
443
444   print qq|
445 <body>
446
447 <table width=100%>
448   <tr>
449     <th class=listtop>$form->{title}</th>
450   </tr>
451   <tr height="5"></tr>
452   <tr>
453     <td>$option</td>
454   </tr>
455   <tr>
456     <td>
457       <table width=100%>
458         <tr class=listheading>
459 |;
460
461   map { print "$column_header{$_}\n" } @column_index;
462
463   print qq|
464         </tr>
465 |;
466
467   $ordertype = ($form->{db} eq 'customer') ? 'sales_order' : 'purchase_order';
468   $quotationtype =
469     ($form->{db} eq 'customer') ? 'sales_quotation' : 'request_quotation';
470
471   foreach $ref (@{ $form->{CT} }) {
472
473     if ($ref->{id} eq $sameid) {
474       map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
475     } else {
476       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
477
478       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
479         (invnumber, ordnumber, quonumber);
480
481       $column_data{name} =
482         "<td align=left><a href=$form->{script}?action=edit&id=$ref->{id}&db=$form->{db}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}&callback=$callback>$ref->{name}&nbsp;</td>";
483
484       if ($ref->{email}) {
485         $email = $ref->{email};
486         $email =~ s/</\&lt;/;
487         $email =~ s/>/\&gt;/;
488
489         $column_data{email} =
490           qq|<td><a href="mailto:$ref->{email}">$email</a></td>|;
491       }
492
493     }
494
495     if ($ref->{formtype} eq 'invoice') {
496       $column_data{invnumber} =
497         "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{invid}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{invnumber}&nbsp;</td>";
498     }
499
500     if ($ref->{formtype} eq 'order') {
501       $column_data{ordnumber} =
502         "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{invid}&type=$ordertype&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{ordnumber}&nbsp;</td>";
503     }
504
505     if ($ref->{formtype} eq 'quotation') {
506       $column_data{quonumber} =
507         "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{invid}&type=$quotationtype&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{quonumber}&nbsp;</td>";
508     }
509
510     $i++;
511     $i %= 2;
512     print "
513         <tr class=listrow$i>
514 ";
515
516     map { print "$column_data{$_}\n" } @column_index;
517
518     print qq|
519         </tr>
520 |;
521
522     $sameid = $ref->{id};
523
524   }
525
526   print qq|
527       </table>
528     </td>
529   </tr>
530   <tr>
531     <td><hr size=3 noshade></td>
532   </tr>
533 </table>
534
535 <br>
536 <form method=post action=$form->{script}>
537
538 <input name=callback type=hidden value="$form->{callback}">
539 <input name=db type=hidden value=$form->{db}>
540
541 <input type=hidden name=path value=$form->{path}>
542 <input type=hidden name=login value=$form->{login}>
543 <input type=hidden name=password value=$form->{password}>
544
545 <input class=submit type=submit name=action value="|
546     . $locale->text('Add') . qq|">
547
548   </form>
549
550 </body>
551 </html>
552 |;
553
554   $lxdebug->leave_sub();
555 }
556
557 sub edit {
558   $lxdebug->enter_sub();
559
560   # $locale->text('Edit Customer')
561   # $locale->text('Edit Vendor')
562
563   CT->get_tuple(\%myconfig, \%$form);
564
565   # format " into &quot;
566   map { $form->{$_} =~ s/\"/&quot;/g } keys %$form;
567
568   $form->{title} = "Edit";
569
570   # format discount
571   $form->{discount} *= 100;
572
573   &form_header;
574   &form_footer;
575
576   $lxdebug->leave_sub();
577 }
578
579 sub form_header {
580   $lxdebug->enter_sub();
581
582   $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
583   $form->{creditlimit} =
584     $form->format_amount(\%myconfig, $form->{creditlimit}, 0);
585   $form->{discount} = $form->format_amount(\%myconfig, $form->{discount});
586
587   if ($myconfig{role} eq 'admin') {
588     $bcc = qq|
589         <tr>
590           <th align=right nowrap>| . $locale->text('Bcc') . qq|</th>
591           <td><input name=bcc size=35 value="$form->{bcc}"></td>
592         </tr>
593 |;
594   }
595   $form->{obsolete} = "checked" if $form->{obsolete};
596
597   $lang = qq|<option value=""></option>|;
598   foreach $item (@{ $form->{languages} }) {
599     if ($form->{language_id} eq $item->{id}) {
600       $lang .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
601     } else {
602       $lang .= qq|<option value="$item->{id}">$item->{description}</option>|;
603     }
604   }
605
606   $payment = qq|<option value=""></option>|;
607   foreach $item (@{ $form->{payment_terms} }) {
608     if ($form->{payment_id} eq $item->{id}) {
609       $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
610     } else {
611       $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
612     }
613   }
614
615   if (!$form->{id}) {
616     if ($form->{db} eq "customer") {
617       $form->{taxzone_id} = 0;
618     } else {
619       $form->{taxzone_id} = 0;
620     }
621   }
622
623   if (@{ $form->{TAXZONE} }) {
624     foreach $item (@{ $form->{TAXZONE} }) {
625       if ($item->{id} == $form->{taxzone_id}) {
626         $form->{selecttaxzone} .=
627           "<option value=$item->{id} selected>$item->{description}\n";
628       } else {
629         $form->{selecttaxzone} .=
630           "<option value=$item->{id}>$item->{description}\n";
631       }
632
633     }
634   }
635
636   $taxzone = qq|
637               <tr>
638                 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
639                 <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
640                 <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
641               </tr>|;
642
643   $get_contact_url =
644     "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=get_contact";
645
646   my $pjx = new CGI::Ajax( 'get_contact' => $get_contact_url );
647   $form->{selectcontact} = "<option value=0></option>";
648   if (@{ $form->{CONTACTS} }) {
649     foreach $item (@{ $form->{CONTACTS} }) {
650       if ($item->{cp_id} == $form->{cp_id}) {
651         $form->{selectcontact} .=
652           qq|<option value=$item->{cp_id} selected>$item->{cp_name}</option>\n|;
653       } else {
654         $form->{selectcontact} .=
655           qq|<option value=$item->{cp_id}>$item->{cp_name}</option>\n|;
656       }
657
658     }
659   }
660   push(@ { $form->{AJAX} }, $pjx);
661   $ansprechpartner = qq|
662               <tr>
663                 <th align=right>| . $locale->text('Ansprechpartner') . qq|</th>
664                 <td><select id=cp_id name=cp_id onChange="get_contact(['cp_id__' + this.value], ['cp_name', 'cp_greeting', 'cp_title', 'cp_givenname', 'cp_phone1', 'cp_phone2', 'cp_email', 'cp_abteilung', 'cp_fax', 'cp_mobile1', 'cp_mobile2', 'cp_satphone', 'cp_satfax', 'cp_project', 'cp_privatphone', 'cp_privatemail', 'cp_birthday'])">$form->{selectcontact}</select></td>
665                 <input type=hidden name=selectcontact value="$form->{selectcontact}">
666               </tr>|;
667   $get_shipto_url =
668     "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=get_shipto";
669
670   my $pjy = new CGI::Ajax( 'get_shipto' => $get_shipto_url );
671   $form->{selectshipto} = "<option value=0></option>";
672   $form->{selectshipto} .= "<option value=0>Alle</option>";
673   if (@{ $form->{SHIPTO} }) {
674     foreach $item (@{ $form->{SHIPTO} }) {
675       if ($item->{shipto_id} == $form->{shipto_id}) {
676         $form->{selectshipto} .=
677           "<option value=$item->{shipto_id} selected>$item->{shiptoname} $item->{shiptodepartment_1}\n";
678       } else {
679         $form->{selectshipto} .=
680           "<option value=$item->{shipto_id}>$item->{shiptoname} $item->{shiptodepartment_1}\n";
681       }
682
683     }
684   }
685   push(@ { $form->{AJAX} }, $pjy);
686
687   $shipto = qq|
688               <tr>
689                 <th align=right>| . $locale->text('Shipping Address') . qq|</th>
690                 <td><select id=shipto_id name=shipto_id onChange="get_shipto(['shipto_id__' + this.value], ['shiptoname','shiptodepartment_1', 'shiptodepartment_2','shiptostreet','shiptozipcode','shiptocity','shiptocountry','shiptocontact','shiptophone','shiptofax','shiptoemail'])">$form->{selectshipto}</select></td>
691                 <input type=hidden name=selectshipto value="$form->{selectshipto}">
692               </tr>|;
693
694
695   $get_delivery_url =
696     "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=get_delivery";
697
698   my $pjz = new CGI::Ajax( 'get_delivery' => $get_delivery_url );
699
700   push(@ { $form->{AJAX} }, $pjz);
701
702   $delivery = qq|
703               <tr>
704                 <th align=right>| . $locale->text('Shipping Address') . qq|</th>
705                 <td><select id=delivery_id name=delivery_id onChange="get_delivery(['shipto_id__' + this.value, 'from__' + from.value, 'to__' + to.value, 'id__' + cvid.value, 'db__' + db.value], ['delivery'])">$form->{selectshipto}</select></td>
706               </tr>|;
707
708   foreach $item (split / /, $form->{taxaccounts}) {
709     if (($form->{tax}{$item}{taxable}) || !($form->{id})) {
710       $taxable .=
711         qq| <input name="tax_$item" value=1 class=checkbox type=checkbox checked>&nbsp;<b>$form->{tax}{$item}{description}</b>|;
712     } else {
713       $taxable .=
714         qq| <input name="tax_$item" value=1 class=checkbox type=checkbox>&nbsp;<b>$form->{tax}{$item}{description}</b>|;
715     }
716   }
717
718 ##LINET
719   $taxable = "";
720
721   if ($taxable) {
722     $tax = qq|
723   <tr>
724     <th align=right>| . $locale->text('Taxable') . qq|</th>
725     <td colspan=2>
726       <table>
727         <tr>
728           <td>$taxable</td>
729           <td><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
730           <th align=left>| . $locale->text('Tax Included') . qq|</th>
731         </tr>
732       </table>
733     </td>
734   </tr>
735 |;
736   }
737   $form->{selectbusiness} = qq|<option>\n|;
738   map {
739     $form->{selectbusiness} .=
740       qq|<option value=$_->{id}>$_->{description}\n|
741   } @{ $form->{all_business} };
742   if ($form->{business_save}) {
743     $form->{selectbusiness} = $form->{business_save};
744   }
745   $form->{selectbusiness} =~
746     s/<option value=$form->{business}>/<option value=$form->{business} selected>/;
747
748   $label = ucfirst $form->{db};
749   if ($form->{title} eq "Edit") {
750     $form->{title} = $locale->text("$form->{title} $label") . " $form->{name}";
751   } else  {
752     $form->{title} = $locale->text("$form->{title} $label");
753   }
754   if ($form->{title_save}) {
755     $form->{title} = $form->{title_save};
756   }
757   if ($form->{db} eq 'vendor') {
758     $customer = qq|
759            <th align=right>| . $locale->text('Kundennummer') . qq|</th>
760            <td><input name=v_customer_id size=10 tabindex=18 maxlength=35 value="$form->{v_customer_id}"></td>
761 |;
762   }
763
764   if ($form->{db} eq 'customer') {
765
766     $customer = qq|
767            <th align=right>| . $locale->text('KNr. beim Kunden') . qq|</th>
768            <td><input name=c_vendor_id size=10 tabindex=18 maxlength=35 value="$form->{c_vendor_id}"></td>
769 |;
770   }
771   $business_salesman = "";
772   $business          = "<th></th><td></td>";
773   if ($vertreter) {
774     $business_salesman = qq|
775         <tr>
776           <td colspan=3>
777             <table>
778              <th align=right>| . $locale->text('Type of Business') . qq|</th>
779              <td><select name=business tabindex=1>$form->{selectbusiness}</select></td>
780              <th align=right>| . $locale->text('Salesman') . qq|</th>
781              <td><input name=salesman tabindex=2 value="$form->{salesman}"></td>
782              <input type=hidden name=salesman_id value="$form->{salesman_id}">
783              <input type=hidden name=oldsalesman value="$form->{oldsalesman}">
784             </table>
785           </td>
786        <tr>|;
787     $business = qq|
788              <th align=right>| . $locale->text('Username') . qq|</th>
789              <td><input name=username maxlength=50 tabindex=22 value="$form->{username}"></td>
790              <th align=right>| . $locale->text('Password') . qq|</th>
791              <td><input name=user_password maxlength=12 tabindex=23 value="$form->{user_password}"></td>|;
792   } else {
793     $business = qq|
794           <th align=right>| . $locale->text('Type of Business') . qq|</th>
795           <td><select name=business tabindex=22>$form->{selectbusiness}</select></td>
796       |;
797   }
798
799 ## LINET: Create a drop-down box with all prior titles and greetings.
800   CT->query_titles_and_greetings(\%myconfig, \%$form);
801
802   $select_title = qq|&nbsp;<select name=selected_cp_title><option></option>|;
803   map({ $select_title .= qq|<option>$_</option>|; } @{ $form->{TITLES} });
804   $select_title .= qq|</select>|;
805
806   $select_greeting =
807     qq|&nbsp;<select name=selected_cp_greeting><option></option>|;
808   map(
809      { $select_greeting .= qq|<option>$_</option>|; } @{ $form->{GREETINGS} });
810   $select_greeting .= qq|</select>|;
811
812   $select_company_greeting =
813     qq|&nbsp;<select name=selected_company_greeting><option></option>|;
814   map(
815      { $select_company_greeting .= qq|<option>$_</option>|; } @{ $form->{COMPANY_GREETINGS} });
816   $select_company_greeting .= qq|</select>|;
817
818   $select_department =
819     qq|&nbsp;<select name=selected_cp_abteilung><option></option>|;
820   map(
821      { $select_department .= qq|<option>$_</option>|; } @{ $form->{DEPARTMENT} });
822   $select_department .= qq|</select>|;
823 ## /LINET
824
825   if ($form->{db} eq 'customer') {
826
827     #get pricegroup and form it
828     $form->get_pricegroup(\%myconfig, { all => 1 });
829
830     $form->{pricegroup}    = "$form->{klass}";
831     $form->{pricegroup_id} = "$form->{klass}";
832
833     if (@{ $form->{all_pricegroup} }) {
834
835       $form->{selectpricegroup} = qq|<option>\n|;
836       map {
837         $form->{selectpricegroup} .=
838           qq|<option value="$_->{id}">$_->{pricegroup}\n|
839       } @{ $form->{all_pricegroup} };
840     }
841
842     if ($form->{selectpricegroup}) {
843       $form->{selectpricegroup} = $form->unescape($form->{selectpricegroup});
844
845       $pricegroup =
846         qq|<input type=hidden name=selectpricegroup value="|
847         . $form->escape($form->{selectpricegroup}, 1) . qq|">|;
848
849       $form->{selectpricegroup} =~
850         s/(<option value="\Q$form->{klass}\E")/$1 selected/;
851
852       $pricegroup .=
853         qq|<select name=klass tabindex=24>$form->{selectpricegroup}</select>|;
854
855     }
856   }
857
858   # $locale->text('Customer Number')
859   # $locale->text('Vendor Number')
860   $form->{fokus} = "ct.greeting";
861   $form->{jsscript} = 1;
862   $form->header;
863
864   print qq|
865 <body onLoad="fokus()">
866 <table width=100%>
867   <tr>
868     <th class=listtop>$form->{title}</th>
869   </tr>
870 </table>
871
872
873 <form method=post name="ct" action=$form->{script} onKeyUp="highlight(event)" onClick="highlight(event)">
874
875
876
877 <ul id="maintab" class="shadetabs">
878 <li class="selected"><a href="#" rel="billing">|
879     . $locale->text('Billing Address') . qq|</a></li>
880 <li><a href="#" rel="shipto">|
881     . $locale->text('Shipping Address') . qq|</a></li>
882 <li><a href="#" rel="contacts">Ansprechpartner</a></li>
883 <li><a href="#" rel="deliveries">|
884     . $locale->text('Lieferungen') . qq|</a></li>
885
886 </ul>
887
888 <div class="tabcontentstyle">
889
890 <div id="billing" class="tabcontent">
891
892       <table width=100%>
893         <tr height="5"></tr>
894         $business_salesman
895         <tr>
896           <th align=right nowrap>| . $locale->text($label . ' Number') . qq|</th>
897           <td><input name="$form->{db}number" size=35 maxlength=35 value="$form->{"$form->{db}number"}"></td>
898         </tr>
899         <tr>
900           <th align=right nowrap>| . $locale->text('Greeting') . qq|</th>
901           <td><input id=greeting name=greeting size=30 maxlength=30 value="$form->{greeting}">&nbsp;
902           $select_company_greeting</td>
903         </tr>
904         <tr>
905           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
906           <td><input name=name size=35 maxlength=75 value="$form->{name}"></td>
907         </tr>
908         <tr>
909           <th align=right nowrap>| . $locale->text('Abteilung') . qq|</th>
910           <td><input name=department_1 size=16 maxlength=75 value="$form->{department_1}">
911           <input name=department_2 size=16 maxlength=75 value="$form->{department_2}"></td>
912         </tr>
913         <tr>
914           <th align=right nowrap>| . $locale->text('Street') . qq|</th>
915           <td><input name=street size=35 maxlength=75 value="$form->{street}"></td>
916         </tr>
917         <tr>
918           <th align=right nowrap>|
919     . $locale->text('Zipcode') . "/" . $locale->text('City') . qq|</th>
920           <td><input name=zipcode size=5 maxlength=10 value="$form->{zipcode}">
921           <input name=city size=30 maxlength=75 value="$form->{city}"></td>
922         </tr>
923         <tr>
924           <th align=right nowrap>| . $locale->text('Country') . qq|</th>
925           <td><input name=country size=35 maxlength=75 value="$form->{country}"></td>
926         </tr>
927         <tr>
928           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
929           <td><input name=contact size=28 maxlength=75 value="$form->{contact}"></td>
930         </tr>
931         <tr>
932           <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
933           <td><input name=phone size=30 maxlength=30 value="$form->{phone}"></td>
934         </tr>
935         <tr>
936           <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
937           <td><input name=fax size=30 maxlength=30 value="$form->{fax}"></td>
938         </tr>
939         <tr>
940           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
941           <td><input name=email size=45 value="$form->{email}"></td>
942         </tr>
943         <tr>
944           <th align=right nowrap>| . $locale->text('Homepage') . qq|</th>
945           <td><input name=homepage size=45 value="$form->{homepage}"></td>
946         </tr>
947 </table>
948 <table>
949         <tr>
950           <th align=right>| . $locale->text('Credit Limit') . qq|</th>
951           <td><input name=creditlimit size=9 value="$form->{creditlimit}"></td>
952           <input type="hidden" name="terms" value="$form->{terms}">
953           <th align=right>| . $locale->text('Payment Terms') . qq|</th>
954           <td><select name=payment_id>$payment</select></td>
955           <th align=right>| . $locale->text('Discount') . qq|</th>
956           <td><input name=discount size=4 value="$form->{discount}">
957           %</td>
958         </tr>
959         <tr>
960           <th align=right>| . $locale->text('Tax Number / SSN') . qq|</th>
961           <td><input name=taxnumber size=20 value="$form->{taxnumber}"></td>
962           <th align=right>| . $locale->text('USt-IdNr.') . qq|</th>
963           <td><input name="ustid" maxlength="14" size="20" value="$form->{ustid}"></td>
964           $customer
965         </tr>
966         <tr>
967           <th align=right>| . $locale->text('Account Number') . qq|</th>
968           <td><input name=account_number size=10 value="$form->{account_number}"></td>
969           <th align=right>| . $locale->text('Bank Code Number') . qq|</th>
970           <td><input name=bank_code size=10 value="$form->{bank_code}"></td>
971           <th align=right>| . $locale->text('Bank') . qq|</th>
972           <td><input name=bank size=30 value="$form->{bank}"></td>
973         </tr>
974         <tr>
975           $business
976           <th align=right>| . $locale->text('Language') . qq|</th>
977           <td><select name=language_id tabindex=23>$lang
978                           </select></td>|;
979
980   if ($form->{db} eq 'customer') {
981
982     print qq|
983           <th align=right>| . $locale->text('Preisklasse') . qq|</th>
984           <td>$pricegroup</td>|;
985   }
986   print qq|        </tr>
987         <tr>
988           <td align=right>| . $locale->text('Obsolete') . qq|</td>
989           <td><input name=obsolete class=checkbox type=checkbox value=1 $form->{obsolete}></td>
990         </tr>
991         $taxzone
992       </table>
993   <table>
994   <tr>
995     <th align=left nowrap>| . $locale->text('Notes') . qq|</th>
996   </tr>
997   <tr>
998     <td><textarea name=notes rows=3 cols=60 wrap=soft>$form->{notes}</textarea></td>
999   </tr>
1000
1001             </table>
1002           </td>
1003         </tr>
1004 </table>
1005 <br style="clear: left" /></div>|;
1006
1007 print qq|
1008       <div id="shipto" class="tabcontent">
1009
1010       <table width=100%>
1011 $shipto
1012         <tr>
1013           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
1014           <td><input id=shiptoname name=shiptoname size=35 maxlength=75 value="$form->{shiptoname}"></td>
1015         </tr>
1016         <tr>
1017           <th align=right nowrap>| . $locale->text('Abteilung') . qq|</th>
1018           <td><input id=shiptodepartment_1 name=shiptodepartment_1 size=16 maxlength=75 value="$form->{shiptodepartment_1}">
1019           <input id=shiptodepartment_2 name=shiptodepartment_2 size=16 maxlength=75 value="$form->{shiptodepartment_2}"></td>
1020         </tr>
1021         <tr>
1022           <th align=right nowrap>| . $locale->text('Street') . qq|</th>
1023           <td><input id=shiptostreet name=shiptostreet size=35 maxlength=75 value="$form->{shiptostreet}"></td>
1024         </tr>
1025         <tr>
1026           <th align=right nowrap>|
1027     . $locale->text('Zipcode') . "/" . $locale->text('City') . qq|</th>
1028           <td><input id=shiptozipcode name=shiptozipcode size=5 maxlength=10 value="$form->{shiptozipcode}">
1029           <input id=shiptocity name=shiptocity size=30 maxlength=75 value="$form->{shiptocity}"></td>
1030         </tr>
1031         <tr>
1032           <th align=right nowrap>| . $locale->text('Country') . qq|</th>
1033           <td><input id=shiptocountry name=shiptocountry size=35 maxlength=35 value="$form->{shiptocountry}"></td>
1034         </tr>
1035         <tr>
1036           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
1037           <td><input id=shiptocontact name=shiptocontact size=30 maxlength=75 value="$form->{shiptocontact}"></td>
1038         </tr>
1039         <tr>
1040           <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
1041           <td><input id=shiptophone name=shiptophone size=30 maxlength=30 value="$form->{shiptophone}"></td>
1042         </tr>
1043         <tr>
1044           <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
1045           <td><input id=shiptofax name=shiptofax size=30 maxlength=30 value="$form->{shiptofax}"></td>
1046         </tr>
1047         <tr>
1048           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
1049           <td><input id=shiptoemail name=shiptoemail size=45 value="$form->{shiptoemail}"></td>
1050         </tr>
1051         <tr>
1052           <td>&nbsp;</td>
1053         </tr>
1054         <tr>
1055            <td>&nbsp;</td>
1056        </tr>
1057
1058     </table>
1059 <br style="clear: left" /></div>|;
1060
1061
1062 ##LINET - added fields for contact person
1063   print qq|   
1064 <div id="contacts" class="tabcontent">
1065 <table>
1066     <tr>
1067          <td colspan=3>
1068                 <input type=hidden name=cp_id value=$form->{cp_id}>
1069                 <table>
1070                 $ansprechpartner
1071                 <tr>
1072                   <th align=left nowrap>| . $locale->text('Greeting') . qq|</th>
1073                   <td><input id=cp_greeting name=cp_greeting size=30 maxlength=30 value="$form->{cp_greeting}">&nbsp;
1074                   $select_greeting</td>
1075                 </tr>
1076                 <tr>
1077                   <th align=left nowrap>| . $locale->text('Title') . qq|</th>
1078                   <td><input id=cp_title name=cp_title size=30 maxlength=30 value="$form->{cp_title}">&nbsp;
1079                   $select_title</td>
1080                 </tr>
1081                 <tr>
1082                   <th align=left nowrap>| . $locale->text('Department') . qq|</th>
1083                   <td><input id=cp_abteilung name=cp_abteilung size=30 maxlength=40 value="$form->{cp_abteilung}">&nbsp;
1084                   $select_department</td>
1085                 </tr>
1086                 <tr>
1087                   <th align=left nowrap>|
1088     . $locale->text('Given Name') . qq|</th>
1089                   <td><input id=cp_givenname name=cp_givenname size=30 maxlength=40 value="$form->{cp_givenname}"></td>
1090                 </tr>
1091                 <tr>
1092                   <th align=left nowrap>| . $locale->text('Name') . qq|</th>
1093                   <td><input id=cp_name name=cp_name size=30 maxlength=40 value="$form->{cp_name}"></td>
1094                 </tr>
1095                 <tr>
1096                   <th align=left nowrap>| . $locale->text('Phone1') . qq|</th>
1097                   <td><input id=cp_phone1 name=cp_phone1 size=30 maxlength=30 value="$form->{cp_phone1}"></td>
1098                 </tr>
1099                 <tr>
1100                   <th align=left nowrap>| . $locale->text('Phone2') . qq|</th>
1101                   <td><input id=cp_phone2 name=cp_phone2 size=30 maxlength=30 value="$form->{cp_phone2}"></td>
1102                 </tr>
1103                 <tr>
1104                   <th align=left nowrap>| . $locale->text('Fax') . qq|</th>
1105                   <td><input id=cp_fax name=cp_fax size=30 maxlength=30 value="$form->{cp_fax}"></td>
1106                 </tr>
1107                 <tr>
1108                   <th align=left nowrap>| . $locale->text('Mobile1') . qq|</th>
1109                   <td><input id=cp_mobile1 name=cp_mobile1 size=30 maxlength=30 value="$form->{cp_mobile1}"></td>
1110                 </tr>
1111                 <tr>
1112                   <th align=left nowrap>| . $locale->text('Mobile2') . qq|</th>
1113                   <td><input id=cp_mobile2 name=cp_mobile2 size=30 maxlength=30 value="$form->{cp_mobile2}"></td>
1114                 </tr>
1115                 <tr>
1116                   <th align=left nowrap>| . $locale->text('Sat. Phone') . qq|</th>
1117                   <td><input id=cp_satphone name=cp_satphone size=30 maxlength=30 value="$form->{cp_satphone}"></td>
1118                 </tr>
1119                 <tr>
1120                   <th align=left nowrap>| . $locale->text('Sat. Fax') . qq|</th>
1121                   <td><input id=cp_satfax name=cp_satfax size=30 maxlength=30 value="$form->{cp_satfax}"></td>
1122                 </tr>
1123                 <tr>
1124                   <th align=left nowrap>| . $locale->text('Project') . qq|</th>
1125                   <td><input id=cp_project name=cp_project size=30 maxlength=40 value="$form->{cp_project}"></td>
1126                 </tr>
1127                 <tr>
1128                   <th align=left nowrap>| . $locale->text('E-mail') . qq|</th>
1129                   <td><input id=cp_email name=cp_email size=30 maxlength=40 value="$form->{cp_email}"></td>
1130                 </tr>
1131                 <tr>
1132                   <th align=left nowrap>| . $locale->text('Private Phone') . qq|</th>
1133                   <td><input id=cp_privatphone name=cp_privatphone size=30 maxlength=40 value="$form->{cp_privatphone}"></td>
1134                 </tr>
1135                 <tr>
1136                   <th align=left nowrap>| . $locale->text('Private E-mail') . qq|</th>
1137                   <td><input id=cp_privatemail name=cp_privatemail size=30 maxlength=40 value="$form->{cp_privatemail}"></td>
1138                 </tr>
1139                 <tr>
1140                   <th align=left nowrap>| . $locale->text('Birthday') . qq|</th>
1141                   <td><input id=cp_birthday name=cp_birthday size=30 maxlength=40 value="$form->{cp_birthday}"></td>
1142                 </tr>
1143                 
1144           </table>
1145         </td>
1146         </tr>
1147         <tr height="5"></tr>|;
1148 ##/LINET
1149   print qq|        $bcc
1150         $tax
1151       </table>
1152     </td>
1153   </tr>
1154   <tr>
1155     <td>
1156       
1157 <br style="clear: left" /></div>
1158 <div id="deliveries" class="tabcontent">
1159   <table>
1160     $delivery
1161     <tr>
1162       <th align=left nowrap>| . $locale->text('From') . qq|</th>
1163       <td><input id=from name=from size=10 maxlength=10 value="$form->{from}">
1164         <input type="button" name="fromB" id="trigger_from" value="?"></td>
1165       <th align=left nowrap>| . $locale->text('To (time)') . qq|</th>
1166       <td><input id=to name=to size=10 maxlength=10 value="$form->{to}">
1167         <input type="button" name="toB" id="trigger_to" value="?"></td>
1168     </tr>       
1169     <tr>
1170      <td colspan=4>
1171       <div id=delivery>
1172       </div>
1173       </td>
1174     </tr>
1175   </table>
1176 <br style="clear: left" /></div>
1177
1178 </div>
1179
1180 | . $form->write_trigger(\%myconfig, 2, "fromB", "BL", "trigger_from",
1181                          "toB", "BL", "trigger_to");
1182
1183   $lxdebug->leave_sub();
1184 }
1185
1186 sub form_footer {
1187   $lxdebug->enter_sub();
1188
1189   $label     = ucfirst $form->{db};
1190   $quotation =
1191     ($form->{db} eq 'customer')
1192     ? $locale->text('Save and Quotation')
1193     : $locale->text('Save and RFQ');
1194   $arap =
1195     ($form->{db} eq 'customer')
1196     ? $locale->text('Save and AR Transaction')
1197     : $locale->text('Save and AP Transaction');
1198   if ($vertreter) {
1199     $update_button =
1200       qq|<input class=submit type=submit name=action accesskey="u" value="|
1201       . $locale->text("Update") . qq|">|;
1202   } else {
1203     $update_button = "";
1204   }
1205
1206 ##<input class=submit type=submit name=action value="|.$locale->text("Save and Quotation").qq|">
1207 ##<input class=submit type=submit name=action value="|.$locale->text("Save and RFQ").qq|">
1208 ##<input class=submit type=submit name=action value="|.$locale->text("Save and AR Transaction").qq|">
1209 ##<input class=submit type=submit name=action value="|.$locale->text("Save and AP Transaction").qq|">
1210
1211   print qq|
1212 <input name=id type=hidden id=cvid value=$form->{id}>
1213 <input name=taxaccounts type=hidden value="$form->{taxaccounts}">
1214 <input name=business_save type=hidden value="$form->{selectbusiness}">
1215 <input name=title_save type=hidden value="$form->{title}">
1216
1217 <input type=hidden name=path value=$form->{path}>
1218 <input type=hidden name=login value=$form->{login}>
1219 <input type=hidden name=password value=$form->{password}>
1220
1221 <input type=hidden name=callback value="$form->{callback}">
1222 <input type=hidden name=db id=db value=$form->{db}>
1223
1224
1225
1226 <br>
1227 $update_button
1228 <input class=submit type=submit name=action accesskey="s" value="|
1229     . $locale->text("Save") . qq|">
1230 <input class=submit type=submit name=action accesskey="s" value="|
1231     . $locale->text("Save and Close") . qq|">
1232 <input class=submit type=submit name=action value="$arap">
1233 <input class=submit type=submit name=action value="|
1234     . $locale->text("Save and Invoice") . qq|">
1235 <input class=submit type=submit name=action value="|
1236     . $locale->text("Save and Order") . qq|">
1237 <input class=submit type=submit name=action value="$quotation">
1238 |;
1239
1240   if ($form->{id} && $form->{status} eq 'orphaned') {
1241     print qq|<input class=submit type=submit name=action value="|
1242       . $locale->text('Delete')
1243       . qq|">\n|;
1244   }
1245
1246   print qq|
1247
1248   </form>
1249 <script type="text/javascript">
1250 //Start Tab Content script for UL with id="maintab" Separate multiple ids each with a comma.
1251 initializetabcontent("maintab")
1252 </script>
1253 </body>
1254 </html>
1255 |;
1256
1257   $lxdebug->leave_sub();
1258 }
1259
1260 sub add_transaction {
1261   $lxdebug->enter_sub();
1262
1263   $form->isblank("name", $locale->text("Name missing!"));
1264   if ($vertreter && $form->{db} eq "customer") {
1265     $form->isblank("salesman_id", $locale->text("Salesman missing!"));
1266   }
1267   &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
1268
1269   $form->{callback} = $form->escape($form->{callback}, 1);
1270   $name = $form->escape("$form->{name}", 1);
1271
1272   $form->{callback} =
1273     "$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}&callback=$form->{callback}";
1274
1275   $form->redirect;
1276
1277   $lxdebug->leave_sub();
1278 }
1279
1280 sub save_and_ap_transaction {
1281   $lxdebug->enter_sub();
1282
1283   $form->{script} = "ap.pl";
1284   &add_transaction;
1285
1286   $lxdebug->leave_sub();
1287 }
1288
1289 sub save_and_ar_transaction {
1290   $lxdebug->enter_sub();
1291
1292   $form->{script} = "ar.pl";
1293   &add_transaction;
1294
1295   $lxdebug->leave_sub();
1296 }
1297
1298 sub save_and_invoice {
1299   $lxdebug->enter_sub();
1300
1301   $form->{script} = ($form->{db} eq 'customer') ? "is.pl" : "ir.pl";
1302   $form->{type} = "invoice";
1303   &add_transaction;
1304
1305   $lxdebug->leave_sub();
1306 }
1307
1308 sub save_and_rfq {
1309   $lxdebug->enter_sub();
1310
1311   $form->{script} = "oe.pl";
1312   $form->{type}   = "request_quotation";
1313   &add_transaction;
1314
1315   $lxdebug->leave_sub();
1316 }
1317
1318 sub save_and_quotation {
1319   $lxdebug->enter_sub();
1320
1321   $form->{script} = "oe.pl";
1322   $form->{type}   = "sales_quotation";
1323   &add_transaction;
1324
1325   $lxdebug->leave_sub();
1326 }
1327
1328 sub save_and_order {
1329   $lxdebug->enter_sub();
1330
1331   $form->{script} = "oe.pl";
1332   $form->{type}   =
1333     ($form->{db} eq 'customer') ? "sales_order" : "purchase_order";
1334   &add_transaction;
1335
1336   $lxdebug->leave_sub();
1337 }
1338
1339 sub save_and_close {
1340   $lxdebug->enter_sub();
1341
1342   # $locale->text('Customer saved!')
1343   # $locale->text('Vendor saved!')
1344
1345   $msg = ucfirst $form->{db};
1346   $imsg .= " saved!";
1347
1348   $form->isblank("name", $locale->text("Name missing!"));
1349   if ($vertreter && $form->{db} eq "customer") {
1350     $form->isblank("salesman_id", $locale->text("Salesman missing!"));
1351   }
1352   $rc = &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
1353   if ($rc == 3) {
1354     $form->error($locale->text('customernumber not unique!'));
1355   }
1356   $form->redirect($locale->text($msg));
1357
1358   $lxdebug->leave_sub();
1359 }
1360
1361 sub save {
1362   $lxdebug->enter_sub();
1363
1364   # $locale->text('Customer saved!')
1365   # $locale->text('Vendor saved!')
1366
1367   $msg = ucfirst $form->{db};
1368   $imsg .= " saved!";
1369
1370   $form->isblank("name", $locale->text("Name missing!"));
1371   if ($vertreter && $form->{db} eq "customer") {
1372     $form->isblank("salesman_id", $locale->text("Salesman missing!"));
1373   }
1374   print(STDERR "SHIPTO in sub save $form->{shipto_id}\n");
1375   &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
1376
1377   &edit;
1378   exit;
1379   $lxdebug->leave_sub();
1380 }
1381
1382 sub delete {
1383   $lxdebug->enter_sub();
1384
1385   # $locale->text('Customer deleted!')
1386   # $locale->text('Cannot delete customer!')
1387   # $locale->text('Vendor deleted!')
1388   # $locale->text('Cannot delete vendor!')
1389
1390   CT->delete(\%myconfig, \%$form);
1391
1392   $msg = ucfirst $form->{db};
1393   $msg .= " deleted!";
1394   $form->redirect($locale->text($msg));
1395
1396   $msg = "Cannot delete $form->{db}";
1397   $form->error($locale->text($msg));
1398
1399   $lxdebug->leave_sub();
1400 }
1401
1402 sub display {
1403   $lxdebug->enter_sub();
1404
1405   &form_header();
1406   &form_footer();
1407
1408   $lxdebug->leave_sub();
1409 }
1410
1411 sub update {
1412   $lxdebug->enter_sub();
1413
1414   &check_salesman($form->{salesman});
1415
1416   #  $form->get_salesman(\%myconfig, $form->{salesman});
1417   &display();
1418   $lxdebug->leave_sub();
1419 }
1420
1421 sub check_salesman {
1422   $lxdebug->enter_sub();
1423
1424   my ($name) = @_;
1425
1426   my ($new_name, $new_id) = split /--/, $form->{$name};
1427   my $i = 0;
1428
1429   # check name, combine name and id
1430   if ($form->{"oldsalesman"} ne $form->{"salesman"}) {
1431
1432     # return one name or a list of names in $form->{name_list}
1433     if (($i = $form->get_salesman(\%myconfig, $name)) > 1) {
1434       &select_salesman($name);
1435       exit;
1436     }
1437
1438     if ($i == 1) {
1439
1440       # we got one name
1441       $form->{"salesman_id"} = $form->{salesman_list}[0]->{id};
1442       $form->{salesman}      = $form->{salesman_list}[0]->{name};
1443       $form->{"oldsalesman"} = $form->{salesman};
1444
1445     } else {
1446
1447       # name is not on file
1448       # $locale->text('Customer not on file!')
1449       # $locale->text('Vendor not on file!')
1450       $msg = ucfirst $name . " not on file or locked!";
1451       $form->error($locale->text($msg));
1452     }
1453   }
1454
1455   $lxdebug->leave_sub();
1456
1457   return $i;
1458 }
1459
1460 sub select_salesman {
1461   $lxdebug->enter_sub();
1462
1463   my ($table) = @_;
1464
1465   @column_index = qw(ndx name);
1466
1467   $label             = ucfirst $table;
1468   $column_data{ndx}  = qq|<th>&nbsp;</th>|;
1469   $column_data{name} =
1470     qq|<th class=listheading>| . $locale->text($label) . qq|</th>|;
1471
1472   # list items with radio button on a form
1473   $form->header;
1474
1475   $title = $locale->text('Select from one of the names below');
1476
1477   print qq|
1478 <body>
1479
1480 <form method=post action=$form->{script}>
1481
1482 <table width=100%>
1483   <tr>
1484     <th class=listtop>$title</th>
1485   </tr>
1486   <tr space=5></tr>
1487   <tr>
1488     <td>
1489       <table width=100%>
1490         <tr class=listheading>|;
1491
1492   map { print "\n$column_data{$_}" } @column_index;
1493
1494   print qq|
1495         </tr>
1496 |;
1497
1498   my $i = 0;
1499   foreach $ref (@{ $form->{salesman_list} }) {
1500     $checked = ($i++) ? "" : "checked";
1501
1502     $ref->{name} =~ s/\"/&quot;/g;
1503
1504     $column_data{ndx} =
1505       qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
1506     $column_data{name} =
1507       qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
1508
1509     $j++;
1510     $j %= 2;
1511     print qq|
1512         <tr class=listrow$j>|;
1513
1514     map { print "\n$column_data{$_}" } @column_index;
1515
1516     print qq|
1517         </tr>
1518
1519 <input name="new_id_$i" type=hidden value=$ref->{id}>
1520
1521 |;
1522
1523   }
1524
1525   print qq|
1526       </table>
1527     </td>
1528   </tr>
1529   <tr>
1530     <td><hr size=3 noshade></td>
1531   </tr>
1532 </table>
1533
1534 <input name=lastndx type=hidden value=$i>
1535
1536 |;
1537
1538   # delete variables
1539   map { delete $form->{$_} } qw(action name_list header);
1540
1541   # save all other form variables
1542   foreach $key (keys %${form}) {
1543     $form->{$key} =~ s/\"/&quot;/g;
1544     print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
1545   }
1546
1547   print qq|
1548 <input type=hidden name=nextsub value=salesman_selected>
1549
1550 <input type=hidden name=vc value=$table>
1551 <br>
1552 <input class=submit type=submit name=action value="|
1553     . $locale->text('Continue') . qq|">
1554 </form>
1555
1556 </body>
1557 </html>
1558 |;
1559
1560   $lxdebug->leave_sub();
1561 }
1562
1563 sub salesman_selected {
1564   $lxdebug->enter_sub();
1565
1566   # replace the variable with the one checked
1567
1568   # index for new item
1569   $i = $form->{ndx};
1570
1571   $form->{salesman}      = $form->{"new_name_$i"};
1572   $form->{"salesman_id"} = $form->{"new_id_$i"};
1573   $form->{"oldsalesman"} = $form->{salesman};
1574
1575   # delete all the new_ variables
1576   for $i (1 .. $form->{lastndx}) {
1577     map { delete $form->{"new_${_}_$i"} } (id, name);
1578   }
1579
1580   map { delete $form->{$_} } qw(ndx lastndx nextsub);
1581
1582   &update(1);
1583
1584   $lxdebug->leave_sub();
1585 }
1586
1587 sub get_contact {
1588   $lxdebug->enter_sub();
1589
1590   CT->get_contact(\%myconfig, \%$form);
1591
1592   my $q = new CGI;
1593   $result = "$form->{cp_name}";
1594   map { $result .= "__pjx__" . $form->{$_} } qw(cp_greeting cp_title cp_givenname cp_phone1 cp_phone2 cp_email cp_abteilung cp_fax cp_mobile1 cp_mobile2 cp_satphone cp_satfax cp_project cp_privatphone cp_privatemail cp_birthday);
1595   print $q->header();
1596   print $result;
1597   $lxdebug->leave_sub();
1598
1599 }
1600
1601
1602 sub get_shipto {
1603   $lxdebug->enter_sub();
1604
1605   CT->get_shipto(\%myconfig, \%$form);
1606
1607   my $q = new CGI;
1608   $result = "$form->{shiptoname}";
1609   map { $result .= "__pjx__" . $form->{$_} } qw(shiptodepartment_1 shiptodepartment_2 shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax shiptoemail);
1610   print $q->header();
1611   print $result;
1612   $lxdebug->leave_sub();
1613
1614 }
1615
1616 sub get_delivery {
1617   $lxdebug->enter_sub();
1618
1619   CT->get_delivery(\%myconfig, \%$form );
1620
1621   @column_index =
1622     $form->sort_columns(shiptoname,
1623                         invnumber,
1624                         ordnumber,
1625                         transdate,
1626                         description,
1627                         qty,
1628                         unit);
1629
1630
1631
1632   $column_header{shiptoname} =
1633     qq|<th class=listheading>| . $locale->text('Shipping Address') . qq|</th>|;
1634   $column_header{invnumber} =
1635       qq|<th class=listheading>|. $locale->text('Invoice'). qq|</th>|;
1636   $column_header{ordnumber} =
1637       qq|<th class=listheading>|. $locale->text('Order'). qq|</th>|;
1638   $column_header{transdate} =
1639     qq|<th class=listheading>| . $locale->text('Invdate') . qq|</th>|;
1640   $column_header{description} =
1641     qq|<th class=listheading>| . $locale->text('Description') . qq|</th>|;
1642   $column_header{qty} =
1643     qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
1644   $column_header{unit} =
1645     qq|<th class=listheading>| . $locale->text('Unit') . qq|</th>|;
1646   $result .= qq|
1647
1648 <table width=100%>
1649   <tr>
1650     <td>
1651       <table width=100%>
1652         <tr class=listheading>
1653 |;
1654
1655   map { $result .= "$column_header{$_}\n" } @column_index;
1656
1657   $result .= qq|
1658         </tr>
1659 |;
1660
1661
1662   foreach $ref (@{ $form->{DELIVERY} }) {
1663
1664     if ($ref->{shiptoname} eq $sameshiptoname) {
1665       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
1666       $column_data{shiptoname} = "<td>&nbsp;</td>";
1667     } else {
1668       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
1669     }
1670
1671     $i++;
1672     $i %= 2;
1673     $result .= "
1674         <tr class=listrow$i>
1675 ";
1676
1677     map { $result .= "$column_data{$_}\n" } @column_index;
1678
1679     $result .= qq|
1680         </tr>
1681 |;
1682
1683     $sameshiptoname = $ref->{shiptoname};
1684
1685   }
1686
1687   $result .= qq|
1688       </table>
1689 |;
1690
1691
1692   my $q = new CGI;
1693   print $q->header();
1694   print $result;
1695   $lxdebug->leave_sub();
1696
1697 }
1698
1699 sub continue { &{ $form->{nextsub} } }