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