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