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