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