Recommit von r1169 von skoehler: Bugfix Tabindex in Kundenerfassenmaske fuer Preisgruppe
[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 1;
46
47 # end of main
48
49 sub add {
50   $lxdebug->enter_sub();
51
52   $form->{title} = "Add";
53
54   $form->{callback} =
55     "$form->{script}?action=add&db=$form->{db}&path=$form->{path}&login=$form->{login}&password=$form->{password}"
56     unless $form->{callback};
57
58   CT->taxaccounts(\%myconfig, \%$form);
59
60   &form_header;
61   &form_footer;
62
63   $lxdebug->leave_sub();
64 }
65
66 sub search {
67   $lxdebug->enter_sub();
68
69   $label = ucfirst $form->{db};
70   $form->{title} = $locale->text($label . "s");
71
72   if ($form->{db} eq 'vendor') {
73     $gifi = qq|
74                 <td><input name="l_gifi_accno" type=checkbox class=checkbox value=Y> |
75       . $locale->text('GIFI') . qq|</td>
76 |;
77   }
78
79   $form->header;
80
81   print qq|
82 <body>
83
84 <form method=post action=$form->{script}>
85
86 <input type=hidden name=db value=$form->{db}>
87
88 <table width=100%>
89   <tr>
90     <th class=listtop>$form->{title}</th>
91   </tr>
92   <tr height="5"></tr>
93   <tr valign=top>
94     <td>
95       <table>
96         <tr>
97           <th align=right nowrap>| . $locale->text($label . ' Number') . qq|</th>
98           <td><input name=$form->{db}number size=35></td>
99         </tr>
100         <tr>
101           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
102           <td><input name=name size=35></td>
103         </tr>
104         <tr>
105           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
106           <td><input name=contact size=35></td>
107         </tr>
108         <tr>
109           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
110           <td><input name=email size=35></td>
111         </tr>
112         <tr>
113           <td></td>
114           <td><input name=status class=radio type=radio value=all checked>&nbsp;|
115     . $locale->text('All') . qq|
116           <input name=status class=radio type=radio value=orphaned>&nbsp;|
117     . $locale->text('Orphaned') . qq|</td>
118         </tr>
119         <tr>
120           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
121           <td>
122             <table>
123               <tr>
124                 <td><input name="l_id" type=checkbox class=checkbox value=Y> |
125     . $locale->text('ID') . qq|</td>
126                 <td><input name="l_$form->{db}number" type=checkbox class=checkbox value=Y> |
127     . $locale->text($label . ' Number') . qq|</td>
128                 <td><input name="l_name" type=checkbox class=checkbox value=Y checked> |
129     . $locale->text('Company Name') . qq|</td>
130                 <td><input name="l_address" type=checkbox class=checkbox value=Y> |
131     . $locale->text('Address') . qq|</td>
132               </tr>
133               <tr>
134                 <td><input name="l_contact" type=checkbox class=checkbox value=Y checked> |
135     . $locale->text('Contact') . qq|</td>
136                 <td><input name="l_phone" type=checkbox class=checkbox value=Y checked> |
137     . $locale->text('Phone') . qq|</td>
138                 <td><input name="l_fax" type=checkbox class=checkbox value=Y> |
139     . $locale->text('Fax') . qq|</td>
140                 <td><input name="l_email" type=checkbox class=checkbox value=Y checked> |
141     . $locale->text('E-mail') . qq|</td>
142               </tr>
143               <tr>
144                 <td><input name="l_taxnumber" type=checkbox class=checkbox value=Y> |
145     . $locale->text('Tax Number') . qq|</td>
146                 $gifi
147                 <td><input name="l_sic_code" type=checkbox class=checkbox value=Y> |
148     . $locale->text('SIC') . qq|</td>
149                 <td><input name="l_business" type=checkbox class=checkbox value=Y> |
150     . $locale->text('Type of Business') . qq|</td>
151               </tr>
152               <tr>
153                 <td><input name="l_invnumber" type=checkbox class=checkbox value=Y> |
154     . $locale->text('Invoices') . qq|</td>
155                 <td><input name="l_ordnumber" type=checkbox class=checkbox value=Y> |
156     . $locale->text('Orders') . qq|</td>
157                 <td><input name="l_quonumber" type=checkbox class=checkbox value=Y> |
158     . $locale->text('Quotations') . qq|</td>
159               </tr>
160             </table>
161           </td>
162         </tr>
163       </table>
164     </td>
165   </tr>
166   <tr>
167     <td><hr size=3 noshade></td>
168   </tr>
169 </table>
170
171 <input type=hidden name=nextsub value=list_names>
172
173 <input type=hidden name=path value=$form->{path}>
174 <input type=hidden name=login value=$form->{login}>
175 <input type=hidden name=password value=$form->{password}>
176
177 <br>
178 <input type=submit class=submit name=action value="|
179     . $locale->text('Continue') . qq|">
180 </form>
181
182 </body>
183 </html>
184 |;
185   $lxdebug->leave_sub();
186 }
187
188 sub search_delivery {
189   $lxdebug->enter_sub();
190
191   $label = ucfirst $form->{db};
192   $form->{title} = $locale->text($label . "s");
193
194   if ($form->{db} eq 'vendor') {
195     $gifi = qq|
196                 <td><input name="l_gifi_accno" type=checkbox class=checkbox value=Y> |
197       . $locale->text('GIFI') . qq|</td>
198 |;
199   }
200
201   $form->header;
202
203   print qq|
204 <body>
205
206 <form method=post action=$form->{script}>
207
208 <input type=hidden name=db value=$form->{db}>
209
210 <table width=100%>
211   <tr>
212     <th class=listtop>$form->{title}</th>
213   </tr>
214   <tr height="5"></tr>
215   <tr valign=top>
216     <td>
217       <table>
218         <tr>
219           <th align=right nowrap>| . $locale->text($label . ' Number') . qq|</th>
220           <td><input name=$form->{db}number size=35></td>
221         </tr>
222         <tr>
223           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
224           <td><input name=name size=35></td>
225         </tr>
226         <tr>
227           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
228           <td><input name=contact size=35></td>
229         </tr>
230         <tr>
231           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
232           <td><input name=email size=35></td>
233         </tr>
234         <tr>
235           <td></td>
236           <td><input name=status class=radio type=radio value=all checked>&nbsp;|
237     . $locale->text('All') . qq|
238           <input name=status class=radio type=radio value=orphaned>&nbsp;|
239     . $locale->text('Orphaned') . qq|</td>
240         </tr>
241         <tr>
242           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
243           <td>
244             <table>
245               <tr>
246                 <td><input name="l_id" type=checkbox class=checkbox value=Y> |
247     . $locale->text('ID') . qq|</td>
248                 <td><input name="l_$form->{db}number" type=checkbox class=checkbox value=Y> |
249     . $locale->text($label . ' Number') . qq|</td>
250                 <td><input name="l_name" type=checkbox class=checkbox value=Y checked> |
251     . $locale->text('Company Name') . qq|</td>
252                 <td><input name="l_address" type=checkbox class=checkbox value=Y> |
253     . $locale->text('Address') . qq|</td>
254               </tr>
255               <tr>
256                 <td><input name="l_contact" type=checkbox class=checkbox value=Y checked> |
257     . $locale->text('Contact') . qq|</td>
258                 <td><input name="l_phone" type=checkbox class=checkbox value=Y checked> |
259     . $locale->text('Phone') . qq|</td>
260                 <td><input name="l_fax" type=checkbox class=checkbox value=Y> |
261     . $locale->text('Fax') . qq|</td>
262                 <td><input name="l_email" type=checkbox class=checkbox value=Y checked> |
263     . $locale->text('E-mail') . qq|</td>
264               </tr>
265               <tr>
266                 <td><input name="l_taxnumber" type=checkbox class=checkbox value=Y> |
267     . $locale->text('Tax Number') . qq|</td>
268                 $gifi
269                 <td><input name="l_sic_code" type=checkbox class=checkbox value=Y> |
270     . $locale->text('SIC') . qq|</td>
271                 <td><input name="l_business" type=checkbox class=checkbox value=Y> |
272     . $locale->text('Type of Business') . qq|</td>
273               </tr>
274               <tr>
275                 <td><input name="l_invnumber" type=checkbox class=checkbox value=Y> |
276     . $locale->text('Invoices') . qq|</td>
277                 <td><input name="l_ordnumber" type=checkbox class=checkbox value=Y> |
278     . $locale->text('Orders') . qq|</td>
279                 <td><input name="l_quonumber" type=checkbox class=checkbox value=Y> |
280     . $locale->text('Quotations') . qq|</td>
281               </tr>
282             </table>
283           </td>
284         </tr>
285       </table>
286     </td>
287   </tr>
288   <tr>
289     <td><hr size=3 noshade></td>
290   </tr>
291 </table>
292
293 <input type=hidden name=nextsub value=list_names>
294
295 <input type=hidden name=path value=$form->{path}>
296 <input type=hidden name=login value=$form->{login}>
297 <input type=hidden name=password value=$form->{password}>
298
299 <br>
300 <input type=submit class=submit name=action value="|
301     . $locale->text('Continue') . qq|">
302 </form>
303
304 </body>
305 </html>
306 |;
307   $lxdebug->leave_sub();
308 }
309
310 sub search_adr {
311   $lxdebug->enter_sub();
312
313   $form->{title} = $locale->text('ADR Report');
314
315   # use JavaScript Calendar or not
316   $form->{jsscript} = $jscalendar;
317   $jsscript = "";
318
319   if ($form->{jsscript}) {
320
321     # with JavaScript Calendar
322     $button1 = qq|
323        <td><input name=from id=from size=11 title="$myconfig{dateformat}" value=$form->{from}></td>
324        <td><input type=button name=from id="trigger1" value=|
325       . $locale->text('button') . qq|></td>
326        |;
327     $button2 = qq|
328        <td width="13"><input name=to id=to size=11 title="$myconfig{dateformat}" value=$form->{to}></td>
329        <td width="4"><input type=button name=to id="trigger2" value=|
330       . $locale->text('button') . qq|></td></td>
331      |;
332
333
334     #write Trigger
335     $jsscript =
336       Form->write_trigger(\%myconfig,     "2",
337                           "from",      "BL",
338                           "trigger1",     "to",
339                           "BL",           "trigger2");
340   } else {
341
342     # without JavaScript Calendar
343     $button1 =
344       qq|<td><input name=from size=11 title="$myconfig{dateformat}" value=$form->{from}></td>|;
345     $button2 =
346       qq|<td width="13"><input name=to size=11 title="$myconfig{dateformat}" value=$form->{to}></td>|;
347   }
348
349   $form->header;
350
351   print qq|
352 <body>
353
354 <form method=post action=$form->{script}>
355
356
357 <table width=100%>
358   <tr>
359     <th class=listtop>$form->{title}</th>
360   </tr>
361   <tr height="5"></tr>
362   <tr valign=top>
363     <td>
364       <table>
365         <tr>
366           <th align=right nowrap>| . $locale->text('Year') . qq|</th>
367           <td><input name=year type=input value=$form->{year}></td>
368         <tr>
369           <th align=right nowrap>| . $locale->text('From') . qq|</th>
370           $button1
371         </tr>
372         <tr>
373           <th align=right nowrap>| . $locale->text('Bis') . qq|</th>
374           $button2
375         </tr>
376         <tr>
377           <td></td>
378           <td><input name=format class=radio type=radio value=html checked>&nbsp;|
379     . $locale->text('HTML') . qq|
380           <input name=format class=radio type=radio value=csv>&nbsp;|
381     . $locale->text('CSV') . qq|</td>
382         </tr>
383       </table>
384     </td>
385   </tr>
386   <tr>
387     <td><hr size=3 noshade></td>
388   </tr>
389 </table>
390 $jsscript
391 <input type=hidden name=nextsub value=adr_report>
392
393 <input type=hidden name=path value=$form->{path}>
394 <input type=hidden name=login value=$form->{login}>
395 <input type=hidden name=password value=$form->{password}>
396
397 <br>
398 <input type=submit class=submit name=action value="|
399     . $locale->text('Continue') . qq|">
400 </form>
401
402 </body>
403 </html>
404 |;
405   $lxdebug->leave_sub();
406 }
407 sub adr_report {
408   $lxdebug->enter_sub();
409
410   CT->adr(\%myconfig, \%$form);
411
412   $form->{title} =  $locale->text('ADR Report');
413   if ($form->{from} || $form->{to}) {
414     $option = "Für den Zeitraum $form->{from} bis $form->{to}";
415   } elsif ($form->{year}) {
416     $option = "Für das Jahr $form->{year}";
417   }
418
419   if ($form->{format} eq "html") {
420       $form->header();
421       print qq|
422 <body>
423
424 <table width=100%>
425   <tr>
426     <th class=listtop>$form->{title}</th>
427   </tr>
428   <tr height="5"></tr>
429   <tr>
430     <td>$option</td>
431   </tr>
432 </table>|;
433
434
435   @column_index =
436     $form->sort_columns(adr_code,
437                         adr_description,
438                         sum,
439                         unit);
440
441
442
443   $column_header{adr_code} =
444     qq|<th class=listheading>| . $locale->text('ADR Code') . qq|</th>|;
445   $column_header{adr_description} =
446       qq|<th class=listheading>|. $locale->text('ADR Description'). qq|</th>|;
447   $column_header{sum} =
448       qq|<th class=listheading>|. $locale->text('Quantity'). qq|</th>|;
449   $column_header{unit} =
450     qq|<th class=listheading>| . $locale->text('Unit') . qq|</th>|;
451
452   print qq|
453
454 <table width=100%>
455   <tr>
456     <td>
457       <table width=100%>
458         <tr class=listheading>
459 |;
460
461   map { print "$column_header{$_}\n" } @column_index;
462
463   print qq|
464         </tr>
465 |;
466
467
468   foreach $ref (@{ $form->{ADR} }) {
469
470     map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
471
472
473     $i++;
474     $i %= 2;
475     print "
476         <tr class=listrow$i>
477 ";
478
479     map { print "$column_data{$_}\n" } @column_index;
480
481     print qq|
482         </tr>
483 |;
484
485
486   }
487
488   print qq|
489 </table>
490 </body>
491 </html>
492 |;
493   } else {
494   my $filename = "adr-report-$form->{from}-$form->{to}.csv";
495   if ($form->{year}) {
496     $filename = "adr-report-$form->{year}.csv";
497   }
498   @column_index =
499   $form->sort_columns(adr_code,
500                       adr_description,
501                       sum,
502                       unit);
503
504   $tmpfile = qq|ADR Code;ADR Beschreibung;Menge;Einheit\n|;
505     foreach $ref (@{ $form->{ADR} }) {
506   
507       map { $column_data{$_} = qq|"$ref->{$_}"| } @column_index;
508
509       $line = "";
510       map { $line .= "$column_data{$_};" } @column_index;
511       chomp($line);
512       $tmpfile .= qq|$line\n|;;
513     }
514   
515   my $size = length($tmpfile);
516   # launch application
517   print qq|Content-Type: application/csv
518 Content-Disposition: attachment; filename="$filename"
519 Content-Length: $size
520
521 $tmpfile
522 |;
523   }
524
525   $lxdebug->leave_sub();
526 }
527
528 sub list_names {
529   $lxdebug->enter_sub();
530
531   CT->search(\%myconfig, \%$form);
532
533   $callback =
534     "$form->{script}?action=list_names&db=$form->{db}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}";
535   $href = $callback;
536
537   @columns =
538     $form->sort_columns(id, name,
539                         "$form->{db}number", address,
540                         contact,             phone,
541                         fax,                 email,
542                         taxnumber,           gifi_accno,
543                         sic_code,            business,
544                         invnumber,           ordnumber,
545                         quonumber);
546
547   foreach $item (@columns) {
548     if ($form->{"l_$item"} eq "Y") {
549       push @column_index, $item;
550
551       # add column to href and callback
552       $callback .= "&l_$item=Y";
553       $href     .= "&l_$item=Y";
554     }
555   }
556   $number =
557     ($form->{db} eq "customer")
558     ? $locale->text('Customer Number')
559     : $locale->text('Vendor Number');
560
561   if ($form->{status} eq 'all') {
562     $option = $locale->text('All');
563   }
564   if ($form->{status} eq 'orphaned') {
565     $option .= $locale->text('Orphaned');
566   }
567   if ($form->{name}) {
568     $callback .= "&name=" . $form->escape($form->{name}, 1);
569     $href .= "&name=" . $form->escape($form->{name});
570     $option .= "\n<br>" . $locale->text('Name') . " : $form->{name}";
571   }
572   if ($form->{contact}) {
573     $callback .= "&contact=" . $form->escape($form->{contact}, 1);
574     $href .= "&contact=" . $form->escape($form->{contact});
575     $option .= "\n<br>" . $locale->text('Contact') . " : $form->{contact}";
576   }
577   if ($form->{"$form->{db}number"}) {
578     $callback .=
579       qq|&$form->{db}number=| . $form->escape($form->{"$form->{db}number"}, 1);
580     $href .=
581       "&$form->{db}number=" . $form->escape($form->{"$form->{db}number"});
582     $option .=
583       "\n<br>" . $locale->text('Number') . qq| : $form->{"$form->{db}number"}|;
584   }
585   if ($form->{email}) {
586     $callback .= "&email=" . $form->escape($form->{email}, 1);
587     $href .= "&email=" . $form->escape($form->{email});
588     $option .= "\n<br>" . $locale->text('E-mail') . " : $form->{email}";
589   }
590
591   $form->{callback} = "$callback&sort=$form->{sort}";
592   $callback = $form->escape($form->{callback});
593
594   $column_header{id} =
595     qq|<th class=listheading>| . $locale->text('ID') . qq|</th>|;
596   $column_header{"$form->{db}number"} =
597     qq|<th><a class=listheading href=$href&sort=$form->{db}number>$number</a></th>|;
598   $column_header{name} =
599       qq|<th><a class=listheading href=$href&sort=name>|
600     . $locale->text('Name')
601     . qq|</a></th>|;
602   $column_header{address} =
603       qq|<th><a class=listheading href=$href&sort=address>|
604     . $locale->text('Address')
605     . qq|</a></th>|;
606   $column_header{contact} =
607       qq|<th><a class=listheading href=$href&sort=contact>|
608     . $locale->text('Contact')
609     . qq|</a></th>|;
610   $column_header{phone} =
611       qq|<th><a class=listheading href=$href&sort=phone>|
612     . $locale->text('Phone')
613     . qq|</a></th>|;
614   $column_header{fax} =
615       qq|<th><a class=listheading href=$href&sort=fax>|
616     . $locale->text('Fax')
617     . qq|</a></th>|;
618   $column_header{email} =
619       qq|<th><a class=listheading href=$href&sort=email>|
620     . $locale->text('E-mail')
621     . qq|</a></th>|;
622   $column_header{cc} =
623       qq|<th><a class=listheading href=$href&sort=cc>|
624     . $locale->text('Cc')
625     . qq|</a></th>|;
626
627   $column_header{taxnumber} =
628       qq|<th><a class=listheading href=$href&sort=taxnumber>|
629     . $locale->text('Tax Number')
630     . qq|</a></th>|;
631   $column_header{gifi_accno} =
632       qq|<th><a class=listheading href=$href&sort=gifi_accno>|
633     . $locale->text('GIFI')
634     . qq|</a></th>|;
635   $column_header{sic_code} =
636       qq|<th><a class=listheading href=$href&sort=sic_code>|
637     . $locale->text('SIC')
638     . qq|</a></th>|;
639   $column_header{business} =
640       qq|<th><a class=listheading href=$href&sort=business>|
641     . $locale->text('Type of Business')
642     . qq|</a></th>|;
643
644   $column_header{invnumber} =
645       qq|<th><a class=listheading href=$href&sort=invnumber>|
646     . $locale->text('Invoice')
647     . qq|</a></th>|;
648   $column_header{ordnumber} =
649       qq|<th><a class=listheading href=$href&sort=ordnumber>|
650     . $locale->text('Order')
651     . qq|</a></th>|;
652   $column_header{quonumber} =
653       qq|<th><a class=listheading href=$href&sort=quonumber>|
654     . $locale->text('Quotation')
655     . qq|</a></th>|;
656
657   $label = ucfirst $form->{db} . "s";
658   $form->{title} = $locale->text($label);
659
660   $form->header;
661
662   print qq|
663 <body>
664
665 <table width=100%>
666   <tr>
667     <th class=listtop>$form->{title}</th>
668   </tr>
669   <tr height="5"></tr>
670   <tr>
671     <td>$option</td>
672   </tr>
673   <tr>
674     <td>
675       <table width=100%>
676         <tr class=listheading>
677 |;
678
679   map { print "$column_header{$_}\n" } @column_index;
680
681   print qq|
682         </tr>
683 |;
684
685   $ordertype = ($form->{db} eq 'customer') ? 'sales_order' : 'purchase_order';
686   $quotationtype =
687     ($form->{db} eq 'customer') ? 'sales_quotation' : 'request_quotation';
688
689   foreach $ref (@{ $form->{CT} }) {
690
691     if ($ref->{id} eq $sameid) {
692       map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
693     } else {
694       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
695
696       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
697         (invnumber, ordnumber, quonumber);
698
699       $column_data{name} =
700         "<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>";
701
702       if ($ref->{email}) {
703         $email = $ref->{email};
704         $email =~ s/</\&lt;/;
705         $email =~ s/>/\&gt;/;
706
707         $column_data{email} =
708           qq|<td><a href="mailto:$ref->{email}">$email</a></td>|;
709       }
710
711     }
712
713     if ($ref->{formtype} eq 'invoice') {
714       $column_data{invnumber} =
715         "<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>";
716     }
717
718     if ($ref->{formtype} eq 'order') {
719       $column_data{ordnumber} =
720         "<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>";
721     }
722
723     if ($ref->{formtype} eq 'quotation') {
724       $column_data{quonumber} =
725         "<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>";
726     }
727
728     $i++;
729     $i %= 2;
730     print "
731         <tr class=listrow$i>
732 ";
733
734     map { print "$column_data{$_}\n" } @column_index;
735
736     print qq|
737         </tr>
738 |;
739
740     $sameid = $ref->{id};
741
742   }
743
744   print qq|
745       </table>
746     </td>
747   </tr>
748   <tr>
749     <td><hr size=3 noshade></td>
750   </tr>
751 </table>
752
753 <br>
754 <form method=post action=$form->{script}>
755
756 <input name=callback type=hidden value="$form->{callback}">
757 <input name=db type=hidden value=$form->{db}>
758
759 <input type=hidden name=path value=$form->{path}>
760 <input type=hidden name=login value=$form->{login}>
761 <input type=hidden name=password value=$form->{password}>
762
763 <input class=submit type=submit name=action value="|
764     . $locale->text('Add') . qq|">|;
765
766   if ($form->{menubar}) {
767     require "$form->{path}/menu.pl";
768     &menubar;
769   }
770
771   print qq|
772   </form>
773
774 </body>
775 </html>
776 |;
777
778   $lxdebug->leave_sub();
779 }
780
781 sub edit {
782   $lxdebug->enter_sub();
783
784   # $locale->text('Edit Customer')
785   # $locale->text('Edit Vendor')
786
787   CT->get_tuple(\%myconfig, \%$form);
788
789   # format " into &quot;
790   map { $form->{$_} =~ s/\"/&quot;/g } keys %$form;
791
792   $form->{title} = "Edit";
793
794   # format discount
795   $form->{discount} *= 100;
796
797   &form_header;
798   &form_footer;
799
800   $lxdebug->leave_sub();
801 }
802
803 sub form_header {
804   $lxdebug->enter_sub();
805
806   $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
807   $form->{creditlimit} =
808     $form->format_amount(\%myconfig, $form->{creditlimit}, 0);
809   $form->{discount} = $form->format_amount(\%myconfig, $form->{discount});
810
811   if ($myconfig{role} eq 'admin') {
812     $bcc = qq|
813         <tr>
814           <th align=right nowrap>| . $locale->text('Bcc') . qq|</th>
815           <td><input name=bcc size=35 value="$form->{bcc}"></td>
816         </tr>
817 |;
818   }
819   $form->{obsolete} = "checked" if $form->{obsolete};
820
821   $lang = qq|<option value=""></option>|;
822   foreach $item (@{ $form->{languages} }) {
823     if ($form->{language_id} eq $item->{id}) {
824       $lang .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
825     } else {
826       $lang .= qq|<option value="$item->{id}">$item->{description}</option>|;
827     }
828   }
829
830   $payment = qq|<option value=""></option>|;
831   foreach $item (@{ $form->{payment_terms} }) {
832     if ($form->{payment_id} eq $item->{id}) {
833       $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
834     } else {
835       $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
836     }
837   }
838
839   if (!$form->{id}) {
840     if ($form->{db} eq "customer") {
841       $form->{taxzone_id} = 0;
842     } else {
843       $form->{taxzone_id} = 0;
844     }
845   }
846
847   if (@{ $form->{TAXZONE} }) {
848     foreach $item (@{ $form->{TAXZONE} }) {
849       if ($item->{id} == $form->{taxzone_id}) {
850         $form->{selecttaxzone} .=
851           "<option value=$item->{id} selected>$item->{description}\n";
852       } else {
853         $form->{selecttaxzone} .=
854           "<option value=$item->{id}>$item->{description}\n";
855       }
856
857     }
858   }
859
860   $taxzone = qq|
861               <tr>
862                 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
863                 <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
864                 <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
865               </tr>|;
866
867   $get_contact_url =
868     "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=get_contact";
869
870   my $pjx = new CGI::Ajax( 'get_contact' => $get_contact_url );
871   $form->{selectcontact} = "<option value=0></option>";
872   if (@{ $form->{CONTACTS} }) {
873     foreach $item (@{ $form->{CONTACTS} }) {
874       if ($item->{cp_id} == $form->{cp_id}) {
875         $form->{selectcontact} .=
876           qq|<option value=$item->{cp_id} selected>$item->{cp_name}</option>\n|;
877       } else {
878         $form->{selectcontact} .=
879           qq|<option value=$item->{cp_id}>$item->{cp_name}</option>\n|;
880       }
881
882     }
883   }
884   push(@ { $form->{AJAX} }, $pjx);
885   $ansprechpartner = qq|
886               <tr>
887                 <th align=right>| . $locale->text('Ansprechpartner') . qq|</th>
888                 <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>
889                 <input type=hidden name=selectcontact value="$form->{selectcontact}">
890               </tr>|;
891   $get_shipto_url =
892     "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=get_shipto";
893
894   my $pjy = new CGI::Ajax( 'get_shipto' => $get_shipto_url );
895   $form->{selectshipto} = "<option value=0></option>";
896   if (@{ $form->{SHIPTO} }) {
897     foreach $item (@{ $form->{SHIPTO} }) {
898       if ($item->{id} == $form->{shipto_id}) {
899         $form->{selectshipto} .=
900           "<option value=$item->{id} selected>$item->{shiptoname}\n";
901       } else {
902         $form->{selectshipto} .=
903           "<option value=$item->{id}>$item->{shiptoname}\n";
904       }
905
906     }
907   }
908   push(@ { $form->{AJAX} }, $pjy);
909
910   $shipto = qq|
911               <tr>
912                 <th align=right>| . $locale->text('Shipping Address') . qq|</th>
913                 <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>
914                 <input type=hidden name=selectshipto value="$form->{selectshipto}">
915               </tr>|;
916
917
918   $get_delivery_url =
919     "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=get_delivery";
920
921   my $pjz = new CGI::Ajax( 'get_delivery' => $get_delivery_url );
922
923   push(@ { $form->{AJAX} }, $pjz);
924
925   $delivery = qq|
926               <tr>
927                 <th align=right>| . $locale->text('Shipping Address') . qq|</th>
928                 <td><select id=delivery_id name=delivery_id onChange="get_delivery(['shipto_id__' + this.value, 'from__' + from.value, 'to__' + to.value], ['delivery'])">$form->{selectshipto}</select></td>
929               </tr>|;
930
931   foreach $item (split / /, $form->{taxaccounts}) {
932     if (($form->{tax}{$item}{taxable}) || !($form->{id})) {
933       $taxable .=
934         qq| <input name="tax_$item" value=1 class=checkbox type=checkbox checked>&nbsp;<b>$form->{tax}{$item}{description}</b>|;
935     } else {
936       $taxable .=
937         qq| <input name="tax_$item" value=1 class=checkbox type=checkbox>&nbsp;<b>$form->{tax}{$item}{description}</b>|;
938     }
939   }
940
941 ##LINET
942   $taxable = "";
943
944   if ($taxable) {
945     $tax = qq|
946   <tr>
947     <th align=right>| . $locale->text('Taxable') . qq|</th>
948     <td colspan=2>
949       <table>
950         <tr>
951           <td>$taxable</td>
952           <td><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
953           <th align=left>| . $locale->text('Tax Included') . qq|</th>
954         </tr>
955       </table>
956     </td>
957   </tr>
958 |;
959   }
960   $form->{selectbusiness} = qq|<option>\n|;
961   map {
962     $form->{selectbusiness} .=
963       qq|<option value=$_->{id}>$_->{description}\n|
964   } @{ $form->{all_business} };
965   if ($form->{business_save}) {
966     $form->{selectbusiness} = $form->{business_save};
967   }
968   $form->{selectbusiness} =~
969     s/<option value=$form->{business}>/<option value=$form->{business} selected>/;
970
971   $label = ucfirst $form->{db};
972   if ($form->{title} eq "Edit") {
973     $form->{title} = $locale->text("$form->{title} $label") . " $form->{name}";
974   } else  {
975     $form->{title} = $locale->text("$form->{title} $label");
976   }
977   if ($form->{title_save}) {
978     $form->{title} = $form->{title_save};
979   }
980   if ($form->{db} eq 'vendor') {
981     $customer = qq|
982            <th align=right>| . $locale->text('Kundennummer') . qq|</th>
983            <td><input name=v_customer_id size=10 tabindex=18 maxlength=35 value="$form->{v_customer_id}"></td>
984 |;
985   }
986
987   if ($form->{db} eq 'customer') {
988
989     $customer = qq|
990            <th align=right>| . $locale->text('KNr. beim Kunden') . qq|</th>
991            <td><input name=c_vendor_id size=10 tabindex=18 maxlength=35 value="$form->{c_vendor_id}"></td>
992 |;
993   }
994   $business_salesman = "";
995   $business          = "<th></th><td></td>";
996   if ($vertreter) {
997     $business_salesman = qq|
998         <tr>
999           <td colspan=3>
1000             <table>
1001              <th align=right>| . $locale->text('Type of Business') . qq|</th>
1002              <td><select name=business tabindex=1>$form->{selectbusiness}</select></td>
1003              <th align=right>| . $locale->text('Salesman') . qq|</th>
1004              <td><input name=salesman tabindex=2 value="$form->{salesman}"></td>
1005              <input type=hidden name=salesman_id value="$form->{salesman_id}">
1006              <input type=hidden name=oldsalesman value="$form->{oldsalesman}">
1007             </table>
1008           </td>
1009        <tr>|;
1010     $business = qq|
1011              <th align=right>| . $locale->text('Username') . qq|</th>
1012              <td><input name=username maxlength=50 tabindex=22 value="$form->{username}"></td>
1013              <th align=right>| . $locale->text('Password') . qq|</th>
1014              <td><input name=user_password maxlength=12 tabindex=23 value="$form->{user_password}"></td>|;
1015   } else {
1016     $business = qq|
1017           <th align=right>| . $locale->text('Type of Business') . qq|</th>
1018           <td><select name=business tabindex=22>$form->{selectbusiness}</select></td>
1019       |;
1020   }
1021
1022 ## LINET: Create a drop-down box with all prior titles and greetings.
1023   CT->query_titles_and_greetings(\%myconfig, \%$form);
1024
1025   $select_title = qq|&nbsp;<select name=selected_cp_title><option></option>|;
1026   map({ $select_title .= qq|<option>$_</option>|; } @{ $form->{TITLES} });
1027   $select_title .= qq|</select>|;
1028
1029   $select_greeting =
1030     qq|&nbsp;<select name=selected_cp_greeting><option></option>|;
1031   map(
1032      { $select_greeting .= qq|<option>$_</option>|; } @{ $form->{GREETINGS} });
1033   $select_greeting .= qq|</select>|;
1034
1035   $select_company_greeting =
1036     qq|&nbsp;<select name=selected_company_greeting><option></option>|;
1037   map(
1038      { $select_company_greeting .= qq|<option>$_</option>|; } @{ $form->{COMPANY_GREETINGS} });
1039   $select_company_greeting .= qq|</select>|;
1040
1041   $select_department =
1042     qq|&nbsp;<select name=selected_cp_abteilung><option></option>|;
1043   map(
1044      { $select_department .= qq|<option>$_</option>|; } @{ $form->{DEPARTMENT} });
1045   $select_department .= qq|</select>|;
1046 ## /LINET
1047
1048   if ($form->{db} eq 'customer') {
1049
1050     #get pricegroup and form it
1051     $form->get_pricegroup(\%myconfig, { all => 1 });
1052
1053     $form->{pricegroup}    = "$form->{klass}";
1054     $form->{pricegroup_id} = "$form->{klass}";
1055
1056     if (@{ $form->{all_pricegroup} }) {
1057
1058       $form->{selectpricegroup} = qq|<option>\n|;
1059       map {
1060         $form->{selectpricegroup} .=
1061           qq|<option value="$_->{id}">$_->{pricegroup}\n|
1062       } @{ $form->{all_pricegroup} };
1063     }
1064
1065     if ($form->{selectpricegroup}) {
1066       $form->{selectpricegroup} = $form->unescape($form->{selectpricegroup});
1067
1068       $pricegroup =
1069         qq|<input type=hidden name=selectpricegroup value="|
1070         . $form->escape($form->{selectpricegroup}, 1) . qq|">|;
1071
1072       $form->{selectpricegroup} =~
1073         s/(<option value="\Q$form->{klass}\E")/$1 selected/;
1074
1075       $pricegroup .=
1076         qq|<select name=klass tabindex=24>$form->{selectpricegroup}</select>|;
1077
1078     }
1079   }
1080
1081   # $locale->text('Customer Number')
1082   # $locale->text('Vendor Number')
1083   $form->{fokus} = "ct.greeting";
1084   $form->header;
1085
1086   print qq|
1087 <body onLoad="fokus()">
1088 <table width=100%>
1089   <tr>
1090     <th class=listtop>$form->{title}</th>
1091   </tr>
1092 </table>
1093
1094
1095 <form method=post name="ct" action=$form->{script} onKeyUp="highlight(event)" onClick="highlight(event)">
1096
1097
1098
1099 <ul id="maintab" class="shadetabs">
1100 <li class="selected"><a href="#" rel="billing">|
1101     . $locale->text('Billing Address') . qq|</a></li>
1102 <li><a href="#" rel="shipto">|
1103     . $locale->text('Shipping Address') . qq|</a></li>
1104 <li><a href="#" rel="contacts">Ansprechpartner</a></li>
1105 <li><a href="#" rel="deliveries">|
1106     . $locale->text('Lieferungen') . qq|</a></li>
1107
1108 </ul>
1109
1110 <div class="tabcontentstyle">
1111
1112 <div id="billing" class="tabcontent">
1113
1114       <table width=100%>
1115         <tr height="5"></tr>
1116         $business_salesman
1117         <tr>
1118           <th align=right nowrap>| . $locale->text($label . ' Number') . qq|</th>
1119           <td><input name="$form->{db}number" size=35 maxlength=35 value="$form->{"$form->{db}number"}"></td>
1120         </tr>
1121         <tr>
1122           <th align=right nowrap>| . $locale->text('Greeting') . qq|</th>
1123           <td><input id=greeting name=greeting size=30 maxlength=30 value="$form->{greeting}">&nbsp;
1124           $select_company_greeting</td>
1125         </tr>
1126         <tr>
1127           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
1128           <td><input name=name size=35 maxlength=75 value="$form->{name}"></td>
1129         </tr>
1130         <tr>
1131           <th align=right nowrap>| . $locale->text('Abteilung') . qq|</th>
1132           <td><input name=department_1 size=16 maxlength=75 value="$form->{department_1}">
1133           <input name=department_2 size=16 maxlength=75 value="$form->{department_2}"></td>
1134         </tr>
1135         <tr>
1136           <th align=right nowrap>| . $locale->text('Street') . qq|</th>
1137           <td><input name=street size=35 maxlength=75 value="$form->{street}"></td>
1138         </tr>
1139         <tr>
1140           <th align=right nowrap>|
1141     . $locale->text('Zipcode') . "/" . $locale->text('City') . qq|</th>
1142           <td><input name=zipcode size=5 maxlength=10 value="$form->{zipcode}">
1143           <input name=city size=30 maxlength=75 value="$form->{city}"></td>
1144         </tr>
1145         <tr>
1146           <th align=right nowrap>| . $locale->text('Country') . qq|</th>
1147           <td><input name=country size=35 maxlength=75 value="$form->{country}"></td>
1148         </tr>
1149         <tr>
1150           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
1151           <td><input name=contact size=28 maxlength=75 value="$form->{contact}"></td>
1152         </tr>
1153         <tr>
1154           <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
1155           <td><input name=phone size=30 maxlength=30 value="$form->{phone}"></td>
1156         </tr>
1157         <tr>
1158           <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
1159           <td><input name=fax size=30 maxlength=30 value="$form->{fax}"></td>
1160         </tr>
1161         <tr>
1162           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
1163           <td><input name=email size=45 value="$form->{email}"></td>
1164         </tr>
1165         <tr>
1166           <th align=right nowrap>| . $locale->text('Homepage') . qq|</th>
1167           <td><input name=homepage size=45 value="$form->{homepage}"></td>
1168         </tr>
1169 </table>
1170 <table>
1171         <tr>
1172           <th align=right>| . $locale->text('Credit Limit') . qq|</th>
1173           <td><input name=creditlimit size=9 value="$form->{creditlimit}"></td>
1174           <th align=right>| . $locale->text('Terms: Net') . qq|</th>
1175           <td><input name=terms size=2 value="$form->{terms}">|
1176     . $locale->text('days') . qq|</td>
1177           <th align=right>| . $locale->text('Discount') . qq|</th>
1178           <td><input name=discount size=4 value="$form->{discount}">
1179           %</td>
1180         </tr>
1181         <tr>
1182           <th align=right>| . $locale->text('Tax Number / SSN') . qq|</th>
1183           <td><input name=taxnumber size=20 value="$form->{taxnumber}"></td>
1184           <th align=right>| . $locale->text('USt-IdNr.') . qq|</th>
1185           <td><input name=ustid size=20 value="$form->{ustid}"></td>
1186           $customer
1187         </tr>
1188         <tr>
1189           <th align=right>| . $locale->text('Account Number') . qq|</th>
1190           <td><input name=account_number size=10 value="$form->{account_number}"></td>
1191           <th align=right>| . $locale->text('Bank Code Number') . qq|</th>
1192           <td><input name=bank_code size=10 value="$form->{bank_code}"></td>
1193           <th align=right>| . $locale->text('Bank') . qq|</th>
1194           <td><input name=bank size=30 value="$form->{bank}"></td>
1195         </tr>
1196         <tr>
1197           $business
1198           <th align=right>| . $locale->text('Language') . qq|</th>
1199           <td><select name=language_id tabindex=23>$lang
1200                           </select></td>|;
1201
1202   if ($form->{db} eq 'customer') {
1203
1204     print qq|
1205           <th align=right>| . $locale->text('Preisklasse') . qq|</th>
1206           <td>$pricegroup</td>|;
1207   }
1208   print qq|        </tr>
1209         <tr>
1210           <td align=right>| . $locale->text('Obsolete') . qq|</td>
1211           <td><input name=obsolete class=checkbox type=checkbox value=1 $form->{obsolete}></td>
1212           <th align=right>| . $locale->text('Payment Terms') . qq|</th>
1213           <td><select name=payment_id>$payment
1214                           </select></td>
1215         </tr>
1216         $taxzone
1217       </table>
1218   <table>
1219   <tr>
1220     <th align=left nowrap>| . $locale->text('Notes') . qq|</th>
1221   </tr>
1222   <tr>
1223     <td><textarea name=notes rows=3 cols=60 wrap=soft>$form->{notes}</textarea></td>
1224   </tr>
1225
1226             </table>
1227           </td>
1228         </tr>
1229 </table>
1230 <br style="clear: left" /></div>|;
1231
1232 print qq|
1233       <div id="shipto" class="tabcontent">
1234
1235       <table width=100%>
1236 $shipto
1237         <tr>
1238           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
1239           <td><input id=shiptoname name=shiptoname size=35 maxlength=75 value="$form->{shiptoname}"></td>
1240         </tr>
1241         <tr>
1242           <th align=right nowrap>| . $locale->text('Abteilung') . qq|</th>
1243           <td><input id=shiptodepartment_1 name=shiptodepartment_1 size=16 maxlength=75 value="$form->{shiptodepartment_1}">
1244           <input id=shiptodepartment_2 name=shiptodepartment_2 size=16 maxlength=75 value="$form->{shiptodepartment_2}"></td>
1245         </tr>
1246         <tr>
1247           <th align=right nowrap>| . $locale->text('Street') . qq|</th>
1248           <td><input id=shiptostreet name=shiptostreet size=35 maxlength=75 value="$form->{shiptostreet}"></td>
1249         </tr>
1250         <tr>
1251           <th align=right nowrap>|
1252     . $locale->text('Zipcode') . "/" . $locale->text('City') . qq|</th>
1253           <td><input id=shiptozipcode name=shiptozipcode size=5 maxlength=10 value="$form->{shiptozipcode}">
1254           <input id=shiptocity name=shiptocity size=30 maxlength=75 value="$form->{shiptocity}"></td>
1255         </tr>
1256         <tr>
1257           <th align=right nowrap>| . $locale->text('Country') . qq|</th>
1258           <td><input id=shiptocountry name=shiptocountry size=35 maxlength=35 value="$form->{shiptocountry}"></td>
1259         </tr>
1260         <tr>
1261           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
1262           <td><input id=shiptocontact name=shiptocontact size=30 maxlength=75 value="$form->{shiptocontact}"></td>
1263         </tr>
1264         <tr>
1265           <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
1266           <td><input id=shiptophone name=shiptophone size=30 maxlength=30 value="$form->{shiptophone}"></td>
1267         </tr>
1268         <tr>
1269           <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
1270           <td><input id=shiptofax name=shiptofax size=30 maxlength=30 value="$form->{shiptofax}"></td>
1271         </tr>
1272         <tr>
1273           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
1274           <td><input id=shiptoemail name=shiptoemail size=45 value="$form->{shiptoemail}"></td>
1275         </tr>
1276         <tr>
1277           <td>&nbsp;</td>
1278         </tr>
1279         <tr>
1280            <td>&nbsp;</td>
1281        </tr>
1282
1283     </table>
1284 <br style="clear: left" /></div>|;
1285
1286
1287 ##LINET - added fields for contact person
1288   print qq|   
1289 <div id="contacts" class="tabcontent">
1290 <table>
1291     <tr>
1292          <td colspan=3>
1293                 <input type=hidden name=cp_id value=$form->{cp_id}>
1294                 <table>
1295                 $ansprechpartner
1296                 <tr>
1297                   <th align=left nowrap>| . $locale->text('Greeting') . qq|</th>
1298                   <td><input id=cp_greeting name=cp_greeting size=30 maxlength=30 value="$form->{cp_greeting}">&nbsp;
1299                   $select_greeting</td>
1300                 </tr>
1301                 <tr>
1302                   <th align=left nowrap>| . $locale->text('Title') . qq|</th>
1303                   <td><input id=cp_title name=cp_title size=30 maxlength=30 value="$form->{cp_title}">&nbsp;
1304                   $select_title</td>
1305                 </tr>
1306                 <tr>
1307                   <th align=left nowrap>| . $locale->text('Department') . qq|</th>
1308                   <td><input id=cp_abteilung name=cp_abteilung size=30 maxlength=40 value="$form->{cp_abteilung}">&nbsp;
1309                   $select_department</td>
1310                 </tr>
1311                 <tr>
1312                   <th align=left nowrap>|
1313     . $locale->text('Given Name') . qq|</th>
1314                   <td><input id=cp_givenname name=cp_givenname size=30 maxlength=40 value="$form->{cp_givenname}"></td>
1315                 </tr>
1316                 <tr>
1317                   <th align=left nowrap>| . $locale->text('Name') . qq|</th>
1318                   <td><input id=cp_name name=cp_name size=30 maxlength=40 value="$form->{cp_name}"></td>
1319                 </tr>
1320                 <tr>
1321                   <th align=left nowrap>| . $locale->text('Phone1') . qq|</th>
1322                   <td><input id=cp_phone1 name=cp_phone1 size=30 maxlength=30 value="$form->{cp_phone1}"></td>
1323                 </tr>
1324                 <tr>
1325                   <th align=left nowrap>| . $locale->text('Phone2') . qq|</th>
1326                   <td><input id=cp_phone2 name=cp_phone2 size=30 maxlength=30 value="$form->{cp_phone2}"></td>
1327                 </tr>
1328                 <tr>
1329                   <th align=left nowrap>| . $locale->text('Fax') . qq|</th>
1330                   <td><input id=cp_fax name=cp_fax size=30 maxlength=30 value="$form->{cp_fax}"></td>
1331                 </tr>
1332                 <tr>
1333                   <th align=left nowrap>| . $locale->text('Mobile1') . qq|</th>
1334                   <td><input id=cp_mobile1 name=cp_mobile1 size=30 maxlength=30 value="$form->{cp_mobile1}"></td>
1335                 </tr>
1336                 <tr>
1337                   <th align=left nowrap>| . $locale->text('Mobile2') . qq|</th>
1338                   <td><input id=cp_mobile2 name=cp_mobile2 size=30 maxlength=30 value="$form->{cp_mobile2}"></td>
1339                 </tr>
1340                 <tr>
1341                   <th align=left nowrap>| . $locale->text('Sat. Phone') . qq|</th>
1342                   <td><input id=cp_satphone name=cp_satphone size=30 maxlength=30 value="$form->{cp_satphone}"></td>
1343                 </tr>
1344                 <tr>
1345                   <th align=left nowrap>| . $locale->text('Sat. Fax') . qq|</th>
1346                   <td><input id=cp_satfax name=cp_satfax size=30 maxlength=30 value="$form->{cp_satfax}"></td>
1347                 </tr>
1348                 <tr>
1349                   <th align=left nowrap>| . $locale->text('Project') . qq|</th>
1350                   <td><input id=cp_project name=cp_project size=30 maxlength=40 value="$form->{cp_project}"></td>
1351                 </tr>
1352                 <tr>
1353                   <th align=left nowrap>| . $locale->text('E-mail') . qq|</th>
1354                   <td><input id=cp_email name=cp_email size=30 maxlength=40 value="$form->{cp_email}"></td>
1355                 </tr>
1356                 <tr>
1357                   <th align=left nowrap>| . $locale->text('Private Phone') . qq|</th>
1358                   <td><input id=cp_privatphone name=cp_privatphone size=30 maxlength=40 value="$form->{cp_privatphone}"></td>
1359                 </tr>
1360                 <tr>
1361                   <th align=left nowrap>| . $locale->text('Private E-mail') . qq|</th>
1362                   <td><input id=cp_privatemail name=cp_privatemail size=30 maxlength=40 value="$form->{cp_privatemail}"></td>
1363                 </tr>
1364                 <tr>
1365                   <th align=left nowrap>| . $locale->text('Birthday') . qq|</th>
1366                   <td><input id=cp_birthday name=cp_birthday size=30 maxlength=40 value="$form->{cp_birthday}"></td>
1367                 </tr>
1368                 
1369           </table>
1370         </td>
1371         </tr>
1372         <tr height="5"></tr>|;
1373 ##/LINET
1374   print qq|        $bcc
1375         $tax
1376       </table>
1377     </td>
1378   </tr>
1379   <tr>
1380     <td>
1381       
1382 <br style="clear: left" /></div>
1383 <div id="deliveries" class="tabcontent">
1384   <table>
1385     $delivery
1386     <tr>
1387       <th align=left nowrap>| . $locale->text('From') . qq|</th>
1388       <td><input id=from name=from size=10 maxlength=10 value="$form->{from}"></td>
1389       <th align=left nowrap>| . $locale->text('Bis') . qq|</th>
1390       <td><input id=to name=to size=10 maxlength=10 value="$form->{to}"></td>
1391     </tr>       
1392     <tr>
1393      <td colspan=4>
1394       <div id=delivery>
1395       </div>
1396       </td>
1397     </tr>
1398   </table>
1399 <br style="clear: left" /></div>
1400
1401 </div>
1402
1403 |;
1404
1405   $lxdebug->leave_sub();
1406 }
1407
1408 sub form_footer {
1409   $lxdebug->enter_sub();
1410
1411   $label     = ucfirst $form->{db};
1412   $quotation =
1413     ($form->{db} eq 'customer')
1414     ? $locale->text('Save and Quotation')
1415     : $locale->text('Save and RFQ');
1416   $arap =
1417     ($form->{db} eq 'customer')
1418     ? $locale->text('Save and AR Transaction')
1419     : $locale->text('Save and AP Transaction');
1420   if ($vertreter) {
1421     $update_button =
1422       qq|<input class=submit type=submit name=action accesskey="u" value="|
1423       . $locale->text("Update") . qq|">|;
1424   } else {
1425     $update_button = "";
1426   }
1427
1428 ##<input class=submit type=submit name=action value="|.$locale->text("Save and Quotation").qq|">
1429 ##<input class=submit type=submit name=action value="|.$locale->text("Save and RFQ").qq|">
1430 ##<input class=submit type=submit name=action value="|.$locale->text("Save and AR Transaction").qq|">
1431 ##<input class=submit type=submit name=action value="|.$locale->text("Save and AP Transaction").qq|">
1432
1433   print qq|
1434 <input name=id type=hidden value=$form->{id}>
1435 <input name=taxaccounts type=hidden value="$form->{taxaccounts}">
1436 <input name=business_save type=hidden value="$form->{selectbusiness}">
1437 <input name=title_save type=hidden value="$form->{title}">
1438
1439 <input type=hidden name=path value=$form->{path}>
1440 <input type=hidden name=login value=$form->{login}>
1441 <input type=hidden name=password value=$form->{password}>
1442
1443 <input type=hidden name=callback value="$form->{callback}">
1444 <input type=hidden name=db value=$form->{db}>
1445
1446
1447
1448 <br>
1449 $update_button
1450 <input class=submit type=submit name=action accesskey="s" value="|
1451     . $locale->text("Save") . qq|">
1452 <input class=submit type=submit name=action accesskey="s" value="|
1453     . $locale->text("Save and Close") . qq|">
1454 <input class=submit type=submit name=action value="$arap">
1455 <input class=submit type=submit name=action value="|
1456     . $locale->text("Save and Invoice") . qq|">
1457 <input class=submit type=submit name=action value="|
1458     . $locale->text("Save and Order") . qq|">
1459 <input class=submit type=submit name=action value="$quotation">
1460 |;
1461
1462   if ($form->{id} && $form->{status} eq 'orphaned') {
1463     print qq|<input class=submit type=submit name=action value="|
1464       . $locale->text('Delete')
1465       . qq|">\n|;
1466   }
1467
1468   if ($form->{menubar}) {
1469     require "$form->{path}/menu.pl";
1470     &menubar;
1471   }
1472
1473   print qq|
1474
1475   </form>
1476 <script type="text/javascript">
1477 //Start Tab Content script for UL with id="maintab" Separate multiple ids each with a comma.
1478 initializetabcontent("maintab")
1479 </script>
1480 </body>
1481 </html>
1482 |;
1483
1484   $lxdebug->leave_sub();
1485 }
1486
1487 sub add_transaction {
1488   $lxdebug->enter_sub();
1489
1490   $form->isblank("name", $locale->text("Name missing!"));
1491   &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
1492
1493   $form->{callback} = $form->escape($form->{callback}, 1);
1494   $name = $form->escape("$form->{name}", 1);
1495
1496   $form->{callback} =
1497     "$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}";
1498
1499   $form->redirect;
1500
1501   $lxdebug->leave_sub();
1502 }
1503
1504 sub save_and_ap_transaction {
1505   $lxdebug->enter_sub();
1506
1507   $form->{script} = "ap.pl";
1508   &add_transaction;
1509
1510   $lxdebug->leave_sub();
1511 }
1512
1513 sub save_and_ar_transaction {
1514   $lxdebug->enter_sub();
1515
1516   $form->{script} = "ar.pl";
1517   &add_transaction;
1518
1519   $lxdebug->leave_sub();
1520 }
1521
1522 sub save_and_invoice {
1523   $lxdebug->enter_sub();
1524
1525   $form->{script} = ($form->{db} eq 'customer') ? "is.pl" : "ir.pl";
1526   $form->{type} = "invoice";
1527   &add_transaction;
1528
1529   $lxdebug->leave_sub();
1530 }
1531
1532 sub save_and_rfq {
1533   $lxdebug->enter_sub();
1534
1535   $form->{script} = "oe.pl";
1536   $form->{type}   = "request_quotation";
1537   &add_transaction;
1538
1539   $lxdebug->leave_sub();
1540 }
1541
1542 sub save_and_quotation {
1543   $lxdebug->enter_sub();
1544
1545   $form->{script} = "oe.pl";
1546   $form->{type}   = "sales_quotation";
1547   &add_transaction;
1548
1549   $lxdebug->leave_sub();
1550 }
1551
1552 sub save_and_order {
1553   $lxdebug->enter_sub();
1554
1555   $form->{script} = "oe.pl";
1556   $form->{type}   =
1557     ($form->{db} eq 'customer') ? "sales_order" : "purchase_order";
1558   &add_transaction;
1559
1560   $lxdebug->leave_sub();
1561 }
1562
1563 sub save_and_close {
1564   $lxdebug->enter_sub();
1565
1566   # $locale->text('Customer saved!')
1567   # $locale->text('Vendor saved!')
1568
1569   $msg = ucfirst $form->{db};
1570   $imsg .= " saved!";
1571
1572   $form->isblank("name", $locale->text("Name missing!"));
1573   if ($vertreter && $form->{db} eq "customer") {
1574     $form->isblank("salesman_id", $locale->text("Salesman missing!"));
1575   }
1576   $rc = &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
1577   if ($rc == 3) {
1578     $form->error($locale->text('customernumber not unique!'));
1579   }
1580   $form->redirect($locale->text($msg));
1581
1582   $lxdebug->leave_sub();
1583 }
1584
1585 sub save {
1586   $lxdebug->enter_sub();
1587
1588   # $locale->text('Customer saved!')
1589   # $locale->text('Vendor saved!')
1590
1591   $msg = ucfirst $form->{db};
1592   $imsg .= " saved!";
1593
1594   $form->isblank("name", $locale->text("Name missing!"));
1595   if ($vertreter && $form->{db} eq "customer") {
1596     $form->isblank("salesman_id", $locale->text("Salesman missing!"));
1597   }
1598   print(STDERR "SHIPTO in sub save $form->{shipto_id}\n");
1599   &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
1600
1601   &edit;
1602   exit;
1603   $lxdebug->leave_sub();
1604 }
1605
1606 sub delete {
1607   $lxdebug->enter_sub();
1608
1609   # $locale->text('Customer deleted!')
1610   # $locale->text('Cannot delete customer!')
1611   # $locale->text('Vendor deleted!')
1612   # $locale->text('Cannot delete vendor!')
1613
1614   CT->delete(\%myconfig, \%$form);
1615
1616   $msg = ucfirst $form->{db};
1617   $msg .= " deleted!";
1618   $form->redirect($locale->text($msg));
1619
1620   $msg = "Cannot delete $form->{db}";
1621   $form->error($locale->text($msg));
1622
1623   $lxdebug->leave_sub();
1624 }
1625
1626 sub display {
1627   $lxdebug->enter_sub();
1628
1629   &form_header();
1630   &form_footer();
1631
1632   $lxdebug->leave_sub();
1633 }
1634
1635 sub update {
1636   $lxdebug->enter_sub();
1637
1638   &check_salesman($form->{salesman});
1639
1640   #  $form->get_salesman(\%myconfig, $form->{salesman});
1641   &display();
1642   $lxdebug->leave_sub();
1643 }
1644
1645 sub check_salesman {
1646   $lxdebug->enter_sub();
1647
1648   my ($name) = @_;
1649
1650   my ($new_name, $new_id) = split /--/, $form->{$name};
1651   my $i = 0;
1652
1653   # check name, combine name and id
1654   if ($form->{"oldsalesman"} ne $form->{"salesman"}) {
1655
1656     # return one name or a list of names in $form->{name_list}
1657     if (($i = $form->get_salesman(\%myconfig, $name)) > 1) {
1658       &select_salesman($name);
1659       exit;
1660     }
1661
1662     if ($i == 1) {
1663
1664       # we got one name
1665       $form->{"salesman_id"} = $form->{salesman_list}[0]->{id};
1666       $form->{salesman}      = $form->{salesman_list}[0]->{name};
1667       $form->{"oldsalesman"} = $form->{salesman};
1668
1669     } else {
1670
1671       # name is not on file
1672       # $locale->text('Customer not on file!')
1673       # $locale->text('Vendor not on file!')
1674       $msg = ucfirst $name . " not on file or locked!";
1675       $form->error($locale->text($msg));
1676     }
1677   }
1678
1679   $lxdebug->leave_sub();
1680
1681   return $i;
1682 }
1683
1684 sub select_salesman {
1685   $lxdebug->enter_sub();
1686
1687   my ($table) = @_;
1688
1689   @column_index = qw(ndx name);
1690
1691   $label             = ucfirst $table;
1692   $column_data{ndx}  = qq|<th>&nbsp;</th>|;
1693   $column_data{name} =
1694     qq|<th class=listheading>| . $locale->text($label) . qq|</th>|;
1695
1696   # list items with radio button on a form
1697   $form->header;
1698
1699   $title = $locale->text('Select from one of the names below');
1700
1701   print qq|
1702 <body>
1703
1704 <form method=post action=$form->{script}>
1705
1706 <table width=100%>
1707   <tr>
1708     <th class=listtop>$title</th>
1709   </tr>
1710   <tr space=5></tr>
1711   <tr>
1712     <td>
1713       <table width=100%>
1714         <tr class=listheading>|;
1715
1716   map { print "\n$column_data{$_}" } @column_index;
1717
1718   print qq|
1719         </tr>
1720 |;
1721
1722   my $i = 0;
1723   foreach $ref (@{ $form->{salesman_list} }) {
1724     $checked = ($i++) ? "" : "checked";
1725
1726     $ref->{name} =~ s/\"/&quot;/g;
1727
1728     $column_data{ndx} =
1729       qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
1730     $column_data{name} =
1731       qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
1732
1733     $j++;
1734     $j %= 2;
1735     print qq|
1736         <tr class=listrow$j>|;
1737
1738     map { print "\n$column_data{$_}" } @column_index;
1739
1740     print qq|
1741         </tr>
1742
1743 <input name="new_id_$i" type=hidden value=$ref->{id}>
1744
1745 |;
1746
1747   }
1748
1749   print qq|
1750       </table>
1751     </td>
1752   </tr>
1753   <tr>
1754     <td><hr size=3 noshade></td>
1755   </tr>
1756 </table>
1757
1758 <input name=lastndx type=hidden value=$i>
1759
1760 |;
1761
1762   # delete variables
1763   map { delete $form->{$_} } qw(action name_list header);
1764
1765   # save all other form variables
1766   foreach $key (keys %${form}) {
1767     $form->{$key} =~ s/\"/&quot;/g;
1768     print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
1769   }
1770
1771   print qq|
1772 <input type=hidden name=nextsub value=salesman_selected>
1773
1774 <input type=hidden name=vc value=$table>
1775 <br>
1776 <input class=submit type=submit name=action value="|
1777     . $locale->text('Continue') . qq|">
1778 </form>
1779
1780 </body>
1781 </html>
1782 |;
1783
1784   $lxdebug->leave_sub();
1785 }
1786
1787 sub salesman_selected {
1788   $lxdebug->enter_sub();
1789
1790   # replace the variable with the one checked
1791
1792   # index for new item
1793   $i = $form->{ndx};
1794
1795   $form->{salesman}      = $form->{"new_name_$i"};
1796   $form->{"salesman_id"} = $form->{"new_id_$i"};
1797   $form->{"oldsalesman"} = $form->{salesman};
1798
1799   # delete all the new_ variables
1800   for $i (1 .. $form->{lastndx}) {
1801     map { delete $form->{"new_${_}_$i"} } (id, name);
1802   }
1803
1804   map { delete $form->{$_} } qw(ndx lastndx nextsub);
1805
1806   &update(1);
1807
1808   $lxdebug->leave_sub();
1809 }
1810
1811 sub get_contact {
1812   $lxdebug->enter_sub();
1813
1814   CT->get_contact(\%myconfig, \%$form);
1815
1816   my $q = new CGI;
1817   $result = "$form->{cp_name}";
1818   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);
1819   print $q->header();
1820   print $result;
1821   $lxdebug->leave_sub();
1822
1823 }
1824
1825
1826 sub get_shipto {
1827   $lxdebug->enter_sub();
1828
1829   CT->get_shipto(\%myconfig, \%$form);
1830
1831   my $q = new CGI;
1832   $result = "$form->{shiptoname}";
1833   map { $result .= "__pjx__" . $form->{$_} } qw(shiptodepartment_1 shiptodepartment_2 shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax shiptoemail);
1834   print $q->header();
1835   print $result;
1836   $lxdebug->leave_sub();
1837
1838 }
1839
1840 sub get_delivery {
1841   $lxdebug->enter_sub();
1842
1843   CT->get_delivery(\%myconfig, \%$form);
1844
1845   @column_index =
1846     $form->sort_columns(shiptoname,
1847                         invnumber,
1848                         ordnumber,
1849                         transdate,
1850                         description,
1851                         adr_code,
1852                         qty,
1853                         unit);
1854
1855
1856
1857   $column_header{shiptoname} =
1858     qq|<th class=listheading>| . $locale->text('Shipping Address') . qq|</th>|;
1859   $column_header{invnumber} =
1860       qq|<th class=listheading>|. $locale->text('Invoice'). qq|</th>|;
1861   $column_header{ordnumber} =
1862       qq|<th class=listheading>|. $locale->text('Order'). qq|</th>|;
1863   $column_header{transdate} =
1864     qq|<th class=listheading>| . $locale->text('Invdate') . qq|</th>|;
1865   $column_header{description} =
1866     qq|<th class=listheading>| . $locale->text('Description') . qq|</th>|;
1867   $column_header{adr_code} =
1868     qq|<th class=listheading>| . $locale->text('ADR') . qq|</th>|;
1869   $column_header{qty} =
1870     qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
1871   $column_header{unit} =
1872     qq|<th class=listheading>| . $locale->text('Unit') . qq|</th>|;
1873   $result .= qq|
1874
1875 <table width=100%>
1876   <tr>
1877     <td>
1878       <table width=100%>
1879         <tr class=listheading>
1880 |;
1881
1882   map { $result .= "$column_header{$_}\n" } @column_index;
1883
1884   $result .= qq|
1885         </tr>
1886 |;
1887
1888
1889   foreach $ref (@{ $form->{DELIVERY} }) {
1890
1891     if ($ref->{shiptoname} eq $sameshiptoname) {
1892       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
1893       $column_data{shiptoname} = "<td>&nbsp;</td>";
1894     } else {
1895       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
1896     }
1897
1898     $i++;
1899     $i %= 2;
1900     $result .= "
1901         <tr class=listrow$i>
1902 ";
1903
1904     map { $result .= "$column_data{$_}\n" } @column_index;
1905
1906     $result .= qq|
1907         </tr>
1908 |;
1909
1910     $sameshiptoname = $ref->{shiptoname};
1911
1912   }
1913
1914   $result .= qq|
1915       </table>
1916 |;
1917
1918
1919   my $q = new CGI;
1920   print $q->header();
1921   print $result;
1922   $lxdebug->leave_sub();
1923
1924 }
1925
1926 sub continue { &{ $form->{nextsub} } }