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