Recommit von r1119 von skoehler: Bugfix - im Lieferschein fehlt Nummer, wenn ueber...
[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
810   if ($myconfig{role} eq 'admin') {
811     $bcc = qq|
812         <tr>
813           <th align=right nowrap>| . $locale->text('Bcc') . qq|</th>
814           <td><input name=bcc size=35 value="$form->{bcc}"></td>
815         </tr>
816 |;
817   }
818   $form->{obsolete} = "checked" if $form->{obsolete};
819
820   $lang = qq|<option value=""></option>|;
821   foreach $item (@{ $form->{languages} }) {
822     if ($form->{language_id} eq $item->{id}) {
823       $lang .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
824     } else {
825       $lang .= qq|<option value="$item->{id}">$item->{description}</option>|;
826     }
827   }
828
829   $payment = qq|<option value=""></option>|;
830   foreach $item (@{ $form->{payment_terms} }) {
831     if ($form->{payment_id} eq $item->{id}) {
832       $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
833     } else {
834       $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
835     }
836   }
837
838   if (!$form->{id}) {
839     if ($form->{db} eq "customer") {
840       $form->{taxzone_id} = 0;
841     } else {
842       $form->{taxzone_id} = 0;
843     }
844   }
845
846   if (@{ $form->{TAXZONE} }) {
847     foreach $item (@{ $form->{TAXZONE} }) {
848       if ($item->{id} == $form->{taxzone_id}) {
849         $form->{selecttaxzone} .=
850           "<option value=$item->{id} selected>$item->{description}\n";
851       } else {
852         $form->{selecttaxzone} .=
853           "<option value=$item->{id}>$item->{description}\n";
854       }
855
856     }
857   }
858
859   $taxzone = qq|
860               <tr>
861                 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
862                 <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
863                 <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
864               </tr>|;
865
866   $get_contact_url =
867     "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=get_contact";
868
869   my $pjx = new CGI::Ajax( 'get_contact' => $get_contact_url );
870   $form->{selectcontact} = "<option value=0></option>";
871   if (@{ $form->{CONTACTS} }) {
872     foreach $item (@{ $form->{CONTACTS} }) {
873       if ($item->{cp_id} == $form->{cp_id}) {
874         $form->{selectcontact} .=
875           qq|<option value=$item->{cp_id} selected>$item->{cp_name}</option>\n|;
876       } else {
877         $form->{selectcontact} .=
878           qq|<option value=$item->{cp_id}>$item->{cp_name}</option>\n|;
879       }
880
881     }
882   }
883   push(@ { $form->{AJAX} }, $pjx);
884   $ansprechpartner = qq|
885               <tr>
886                 <th align=right>| . $locale->text('Ansprechpartner') . qq|</th>
887                 <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>
888                 <input type=hidden name=selectcontact value="$form->{selectcontact}">
889               </tr>|;
890   $get_shipto_url =
891     "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=get_shipto";
892
893   my $pjy = new CGI::Ajax( 'get_shipto' => $get_shipto_url );
894   $form->{selectshipto} = "<option value=0></option>";
895   if (@{ $form->{SHIPTO} }) {
896     foreach $item (@{ $form->{SHIPTO} }) {
897       if ($item->{id} == $form->{shipto_id}) {
898         $form->{selectshipto} .=
899           "<option value=$item->{id} selected>$item->{shiptoname}\n";
900       } else {
901         $form->{selectshipto} .=
902           "<option value=$item->{id}>$item->{shiptoname}\n";
903       }
904
905     }
906   }
907   push(@ { $form->{AJAX} }, $pjy);
908
909   $shipto = qq|
910               <tr>
911                 <th align=right>| . $locale->text('Shipping Address') . qq|</th>
912                 <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>
913                 <input type=hidden name=selectshipto value="$form->{selectshipto}">
914               </tr>|;
915
916
917   $get_delivery_url =
918     "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=get_delivery";
919
920   my $pjz = new CGI::Ajax( 'get_delivery' => $get_delivery_url );
921
922   push(@ { $form->{AJAX} }, $pjz);
923
924   $delivery = qq|
925               <tr>
926                 <th align=right>| . $locale->text('Shipping Address') . qq|</th>
927                 <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>
928               </tr>|;
929
930   foreach $item (split / /, $form->{taxaccounts}) {
931     if (($form->{tax}{$item}{taxable}) || !($form->{id})) {
932       $taxable .=
933         qq| <input name="tax_$item" value=1 class=checkbox type=checkbox checked>&nbsp;<b>$form->{tax}{$item}{description}</b>|;
934     } else {
935       $taxable .=
936         qq| <input name="tax_$item" value=1 class=checkbox type=checkbox>&nbsp;<b>$form->{tax}{$item}{description}</b>|;
937     }
938   }
939
940 ##LINET
941   $taxable = "";
942
943   if ($taxable) {
944     $tax = qq|
945   <tr>
946     <th align=right>| . $locale->text('Taxable') . qq|</th>
947     <td colspan=2>
948       <table>
949         <tr>
950           <td>$taxable</td>
951           <td><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
952           <th align=left>| . $locale->text('Tax Included') . qq|</th>
953         </tr>
954       </table>
955     </td>
956   </tr>
957 |;
958   }
959   $form->{selectbusiness} = qq|<option>\n|;
960   map {
961     $form->{selectbusiness} .=
962       qq|<option value=$_->{id}>$_->{description}\n|
963   } @{ $form->{all_business} };
964   if ($form->{business_save}) {
965     $form->{selectbusiness} = $form->{business_save};
966   }
967   $form->{selectbusiness} =~
968     s/<option value=$form->{business}>/<option value=$form->{business} selected>/;
969
970   $label = ucfirst $form->{db};
971   if ($form->{title} eq "Edit") {
972     $form->{title} = $locale->text("$form->{title} $label") . " $form->{name}";
973   } else  {
974     $form->{title} = $locale->text("$form->{title} $label");
975   }
976   if ($form->{title_save}) {
977     $form->{title} = $form->{title_save};
978   }
979   if ($form->{db} eq 'vendor') {
980     $customer = qq|
981            <th align=right>| . $locale->text('Kundennummer') . qq|</th>
982            <td><input name=v_customer_id size=10 tabindex=18 maxlength=35 value="$form->{v_customer_id}"></td>
983 |;
984   }
985
986   if ($form->{db} eq 'customer') {
987
988     $customer = qq|
989            <th align=right>| . $locale->text('KNr. beim Kunden') . qq|</th>
990            <td><input name=c_vendor_id size=10 tabindex=18 maxlength=35 value="$form->{c_vendor_id}"></td>
991 |;
992   }
993   $business_salesman = "";
994   $business          = "<th></th><td></td>";
995   if ($vertreter) {
996     $business_salesman = qq|
997         <tr>
998           <td colspan=3>
999             <table>
1000              <th align=right>| . $locale->text('Type of Business') . qq|</th>
1001              <td><select name=business tabindex=1>$form->{selectbusiness}</select></td>
1002              <th align=right>| . $locale->text('Salesman') . qq|</th>
1003              <td><input name=salesman tabindex=2 value="$form->{salesman}"></td>
1004              <input type=hidden name=salesman_id value="$form->{salesman_id}">
1005              <input type=hidden name=oldsalesman value="$form->{oldsalesman}">
1006             </table>
1007           </td>
1008        <tr>|;
1009     $business = qq|
1010              <th align=right>| . $locale->text('Username') . qq|</th>
1011              <td><input name=username maxlength=50 tabindex=22 value="$form->{username}"></td>
1012              <th align=right>| . $locale->text('Password') . qq|</th>
1013              <td><input name=user_password maxlength=12 tabindex=23 value="$form->{user_password}"></td>|;
1014   } else {
1015     $business = qq|
1016           <th align=right>| . $locale->text('Type of Business') . qq|</th>
1017           <td><select name=business tabindex=22>$form->{selectbusiness}</select></td>
1018       |;
1019   }
1020
1021 ## LINET: Create a drop-down box with all prior titles and greetings.
1022   CT->query_titles_and_greetings(\%myconfig, \%$form);
1023
1024   $select_title = qq|&nbsp;<select name=selected_cp_title><option></option>|;
1025   map({ $select_title .= qq|<option>$_</option>|; } @{ $form->{TITLES} });
1026   $select_title .= qq|</select>|;
1027
1028   $select_greeting =
1029     qq|&nbsp;<select name=selected_cp_greeting><option></option>|;
1030   map(
1031      { $select_greeting .= qq|<option>$_</option>|; } @{ $form->{GREETINGS} });
1032   $select_greeting .= qq|</select>|;
1033
1034   $select_company_greeting =
1035     qq|&nbsp;<select name=selected_company_greeting><option></option>|;
1036   map(
1037      { $select_company_greeting .= qq|<option>$_</option>|; } @{ $form->{COMPANY_GREETINGS} });
1038   $select_company_greeting .= qq|</select>|;
1039
1040   $select_department =
1041     qq|&nbsp;<select name=selected_cp_abteilung><option></option>|;
1042   map(
1043      { $select_department .= qq|<option>$_</option>|; } @{ $form->{DEPARTMENT} });
1044   $select_department .= qq|</select>|;
1045 ## /LINET
1046
1047   if ($form->{db} eq 'customer') {
1048
1049     #get pricegroup and form it
1050     $form->get_pricegroup(\%myconfig, { all => 1 });
1051
1052     $form->{pricegroup}    = "$form->{klass}";
1053     $form->{pricegroup_id} = "$form->{klass}";
1054
1055     if (@{ $form->{all_pricegroup} }) {
1056
1057       $form->{selectpricegroup} = qq|<option>\n|;
1058       map {
1059         $form->{selectpricegroup} .=
1060           qq|<option value="$_->{id}">$_->{pricegroup}\n|
1061       } @{ $form->{all_pricegroup} };
1062     }
1063
1064     if ($form->{selectpricegroup}) {
1065       $form->{selectpricegroup} = $form->unescape($form->{selectpricegroup});
1066
1067       $pricegroup =
1068         qq|<input type=hidden name=selectpricegroup value="|
1069         . $form->escape($form->{selectpricegroup}, 1) . qq|">|;
1070
1071       $form->{selectpricegroup} =~
1072         s/(<option value="\Q$form->{klass}\E")/$1 selected/;
1073
1074       $pricegroup .= qq|<select name=klass>$form->{selectpricegroup}</select>|;
1075
1076     }
1077   }
1078
1079   # $locale->text('Customer Number')
1080   # $locale->text('Vendor Number')
1081   $form->{fokus} = "ct.greeting";
1082   $form->header;
1083
1084   print qq|
1085 <body onLoad="fokus()">
1086 <table width=100%>
1087   <tr>
1088     <th class=listtop>$form->{title}</th>
1089   </tr>
1090 </table>
1091
1092
1093 <form method=post name="ct" action=$form->{script} onKeyUp="highlight(event)" onClick="highlight(event)">
1094
1095
1096
1097 <ul id="maintab" class="shadetabs">
1098 <li class="selected"><a href="#" rel="billing">|
1099     . $locale->text('Billing Address') . qq|</a></li>
1100 <li><a href="#" rel="shipto">|
1101     . $locale->text('Shipping Address') . qq|</a></li>
1102 <li><a href="#" rel="contacts">Ansprechpartner</a></li>
1103 <li><a href="#" rel="deliveries">|
1104     . $locale->text('Lieferungen') . qq|</a></li>
1105
1106 </ul>
1107
1108 <div class="tabcontentstyle">
1109
1110 <div id="billing" class="tabcontent">
1111
1112       <table width=100%>
1113         <tr height="5"></tr>
1114         $business_salesman
1115         <tr>
1116           <th align=right nowrap>| . $locale->text($label . ' Number') . qq|</th>
1117           <td><input name="$form->{db}number" size=35 maxlength=35 value="$form->{"$form->{db}number"}"></td>
1118         </tr>
1119         <tr>
1120           <th align=right nowrap>| . $locale->text('Greeting') . qq|</th>
1121           <td><input id=greeting name=greeting size=30 maxlength=30 value="$form->{greeting}">&nbsp;
1122           $select_company_greeting</td>
1123         </tr>
1124         <tr>
1125           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
1126           <td><input name=name size=35 maxlength=75 value="$form->{name}"></td>
1127         </tr>
1128         <tr>
1129           <th align=right nowrap>| . $locale->text('Abteilung') . qq|</th>
1130           <td><input name=department_1 size=16 maxlength=75 value="$form->{department_1}">
1131           <input name=department_2 size=16 maxlength=75 value="$form->{department_2}"></td>
1132         </tr>
1133         <tr>
1134           <th align=right nowrap>| . $locale->text('Street') . qq|</th>
1135           <td><input name=street size=35 maxlength=75 value="$form->{street}"></td>
1136         </tr>
1137         <tr>
1138           <th align=right nowrap>|
1139     . $locale->text('Zipcode') . "/" . $locale->text('City') . qq|</th>
1140           <td><input name=zipcode size=5 maxlength=10 value="$form->{zipcode}">
1141           <input name=city size=30 maxlength=75 value="$form->{city}"></td>
1142         </tr>
1143         <tr>
1144           <th align=right nowrap>| . $locale->text('Country') . qq|</th>
1145           <td><input name=country size=35 maxlength=75 value="$form->{country}"></td>
1146         </tr>
1147         <tr>
1148           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
1149           <td><input name=contact size=28 maxlength=75 value="$form->{contact}"></td>
1150         </tr>
1151         <tr>
1152           <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
1153           <td><input name=phone size=30 maxlength=30 value="$form->{phone}"></td>
1154         </tr>
1155         <tr>
1156           <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
1157           <td><input name=fax size=30 maxlength=30 value="$form->{fax}"></td>
1158         </tr>
1159         <tr>
1160           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
1161           <td><input name=email size=45 value="$form->{email}"></td>
1162         </tr>
1163         <tr>
1164           <th align=right nowrap>| . $locale->text('Homepage') . qq|</th>
1165           <td><input name=homepage size=45 value="$form->{homepage}"></td>
1166         </tr>
1167 </table>
1168 <table>
1169         <tr>
1170           <th align=right>| . $locale->text('Credit Limit') . qq|</th>
1171           <td><input name=creditlimit size=9 value="$form->{creditlimit}"></td>
1172           <th align=right>| . $locale->text('Terms: Net') . qq|</th>
1173           <td><input name=terms size=2 value="$form->{terms}">|
1174     . $locale->text('days') . qq|</td>
1175           <th align=right>| . $locale->text('Discount') . qq|</th>
1176           <td><input name=discount size=4 value="$form->{discount}">
1177           %</td>
1178         </tr>
1179         <tr>
1180           <th align=right>| . $locale->text('Tax Number / SSN') . qq|</th>
1181           <td><input name=taxnumber size=20 value="$form->{taxnumber}"></td>
1182           <th align=right>| . $locale->text('USt-IdNr.') . qq|</th>
1183           <td><input name=ustid size=20 value="$form->{ustid}"></td>
1184           $customer
1185         </tr>
1186         <tr>
1187           <th align=right>| . $locale->text('Account Number') . qq|</th>
1188           <td><input name=account_number size=10 value="$form->{account_number}"></td>
1189           <th align=right>| . $locale->text('Bank Code Number') . qq|</th>
1190           <td><input name=bank_code size=10 value="$form->{bank_code}"></td>
1191           <th align=right>| . $locale->text('Bank') . qq|</th>
1192           <td><input name=bank size=30 value="$form->{bank}"></td>
1193         </tr>
1194         <tr>
1195           $business
1196           <th align=right>| . $locale->text('Language') . qq|</th>
1197           <td><select name=language_id tabindex=23>$lang
1198                           </select></td>|;
1199
1200   if ($form->{db} eq 'customer') {
1201
1202     print qq|
1203           <th align=right>| . $locale->text('Preisklasse') . qq|</th>
1204           <td>$pricegroup</td>|;
1205   }
1206   print qq|        </tr>
1207         <tr>
1208           <td align=right>| . $locale->text('Obsolete') . qq|</td>
1209           <td><input name=obsolete class=checkbox type=checkbox value=1 $form->{obsolete}></td>
1210           <th align=right>| . $locale->text('Payment Terms') . qq|</th>
1211           <td><select name=payment_id>$payment
1212                           </select></td>
1213         </tr>
1214         $taxzone
1215       </table>
1216   <table>
1217   <tr>
1218     <th align=left nowrap>| . $locale->text('Notes') . qq|</th>
1219   </tr>
1220   <tr>
1221     <td><textarea name=notes rows=3 cols=60 wrap=soft>$form->{notes}</textarea></td>
1222   </tr>
1223
1224             </table>
1225           </td>
1226         </tr>
1227 </table>
1228 <br style="clear: left" /></div>|;
1229
1230 print qq|
1231       <div id="shipto" class="tabcontent">
1232
1233       <table width=100%>
1234 $shipto
1235         <tr>
1236           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
1237           <td><input id=shiptoname name=shiptoname size=35 maxlength=75 value="$form->{shiptoname}"></td>
1238         </tr>
1239         <tr>
1240           <th align=right nowrap>| . $locale->text('Abteilung') . qq|</th>
1241           <td><input id=shiptodepartment_1 name=shiptodepartment_1 size=16 maxlength=75 value="$form->{shiptodepartment_1}">
1242           <input id=shiptodepartment_2 name=shiptodepartment_2 size=16 maxlength=75 value="$form->{shiptodepartment_2}"></td>
1243         </tr>
1244         <tr>
1245           <th align=right nowrap>| . $locale->text('Street') . qq|</th>
1246           <td><input id=shiptostreet name=shiptostreet size=35 maxlength=75 value="$form->{shiptostreet}"></td>
1247         </tr>
1248         <tr>
1249           <th align=right nowrap>|
1250     . $locale->text('Zipcode') . "/" . $locale->text('City') . qq|</th>
1251           <td><input id=shiptozipcode name=shiptozipcode size=5 maxlength=10 value="$form->{shiptozipcode}">
1252           <input id=shiptocity name=shiptocity size=30 maxlength=75 value="$form->{shiptocity}"></td>
1253         </tr>
1254         <tr>
1255           <th align=right nowrap>| . $locale->text('Country') . qq|</th>
1256           <td><input id=shiptocountry name=shiptocountry size=35 maxlength=35 value="$form->{shiptocountry}"></td>
1257         </tr>
1258         <tr>
1259           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
1260           <td><input id=shiptocontact name=shiptocontact size=30 maxlength=75 value="$form->{shiptocontact}"></td>
1261         </tr>
1262         <tr>
1263           <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
1264           <td><input id=shiptophone name=shiptophone size=30 maxlength=30 value="$form->{shiptophone}"></td>
1265         </tr>
1266         <tr>
1267           <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
1268           <td><input id=shiptofax name=shiptofax size=30 maxlength=30 value="$form->{shiptofax}"></td>
1269         </tr>
1270         <tr>
1271           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
1272           <td><input id=shiptoemail name=shiptoemail size=45 value="$form->{shiptoemail}"></td>
1273         </tr>
1274         <tr>
1275           <td>&nbsp;</td>
1276         </tr>
1277         <tr>
1278            <td>&nbsp;</td>
1279        </tr>
1280
1281     </table>
1282 <br style="clear: left" /></div>|;
1283
1284
1285 ##LINET - added fields for contact person
1286   print qq|   
1287 <div id="contacts" class="tabcontent">
1288 <table>
1289     <tr>
1290          <td colspan=3>
1291                 <input type=hidden name=cp_id value=$form->{cp_id}>
1292                 <table>
1293                 $ansprechpartner
1294                 <tr>
1295                   <th align=left nowrap>| . $locale->text('Greeting') . qq|</th>
1296                   <td><input id=cp_greeting name=cp_greeting size=30 maxlength=30 value="$form->{cp_greeting}">&nbsp;
1297                   $select_greeting</td>
1298                 </tr>
1299                 <tr>
1300                   <th align=left nowrap>| . $locale->text('Title') . qq|</th>
1301                   <td><input id=cp_title name=cp_title size=30 maxlength=30 value="$form->{cp_title}">&nbsp;
1302                   $select_title</td>
1303                 </tr>
1304                 <tr>
1305                   <th align=left nowrap>| . $locale->text('Department') . qq|</th>
1306                   <td><input id=cp_abteilung name=cp_abteilung size=30 maxlength=40 value="$form->{cp_abteilung}">&nbsp;
1307                   $select_department</td>
1308                 </tr>
1309                 <tr>
1310                   <th align=left nowrap>|
1311     . $locale->text('Given Name') . qq|</th>
1312                   <td><input id=cp_givenname name=cp_givenname size=30 maxlength=40 value="$form->{cp_givenname}"></td>
1313                 </tr>
1314                 <tr>
1315                   <th align=left nowrap>| . $locale->text('Name') . qq|</th>
1316                   <td><input id=cp_name name=cp_name size=30 maxlength=40 value="$form->{cp_name}"></td>
1317                 </tr>
1318                 <tr>
1319                   <th align=left nowrap>| . $locale->text('Phone1') . qq|</th>
1320                   <td><input id=cp_phone1 name=cp_phone1 size=30 maxlength=30 value="$form->{cp_phone1}"></td>
1321                 </tr>
1322                 <tr>
1323                   <th align=left nowrap>| . $locale->text('Phone2') . qq|</th>
1324                   <td><input id=cp_phone2 name=cp_phone2 size=30 maxlength=30 value="$form->{cp_phone2}"></td>
1325                 </tr>
1326                 <tr>
1327                   <th align=left nowrap>| . $locale->text('Fax') . qq|</th>
1328                   <td><input id=cp_fax name=cp_fax size=30 maxlength=30 value="$form->{cp_fax}"></td>
1329                 </tr>
1330                 <tr>
1331                   <th align=left nowrap>| . $locale->text('Mobile1') . qq|</th>
1332                   <td><input id=cp_mobile1 name=cp_mobile1 size=30 maxlength=30 value="$form->{cp_mobile1}"></td>
1333                 </tr>
1334                 <tr>
1335                   <th align=left nowrap>| . $locale->text('Mobile2') . qq|</th>
1336                   <td><input id=cp_mobile2 name=cp_mobile2 size=30 maxlength=30 value="$form->{cp_mobile2}"></td>
1337                 </tr>
1338                 <tr>
1339                   <th align=left nowrap>| . $locale->text('Sat. Phone') . qq|</th>
1340                   <td><input id=cp_satphone name=cp_satphone size=30 maxlength=30 value="$form->{cp_satphone}"></td>
1341                 </tr>
1342                 <tr>
1343                   <th align=left nowrap>| . $locale->text('Sat. Fax') . qq|</th>
1344                   <td><input id=cp_satfax name=cp_satfax size=30 maxlength=30 value="$form->{cp_satfax}"></td>
1345                 </tr>
1346                 <tr>
1347                   <th align=left nowrap>| . $locale->text('Project') . qq|</th>
1348                   <td><input id=cp_project name=cp_project size=30 maxlength=40 value="$form->{cp_project}"></td>
1349                 </tr>
1350                 <tr>
1351                   <th align=left nowrap>| . $locale->text('E-mail') . qq|</th>
1352                   <td><input id=cp_email name=cp_email size=30 maxlength=40 value="$form->{cp_email}"></td>
1353                 </tr>
1354                 <tr>
1355                   <th align=left nowrap>| . $locale->text('Private Phone') . qq|</th>
1356                   <td><input id=cp_privatphone name=cp_privatphone size=30 maxlength=40 value="$form->{cp_privatphone}"></td>
1357                 </tr>
1358                 <tr>
1359                   <th align=left nowrap>| . $locale->text('Private E-mail') . qq|</th>
1360                   <td><input id=cp_privatemail name=cp_privatemail size=30 maxlength=40 value="$form->{cp_privatemail}"></td>
1361                 </tr>
1362                 <tr>
1363                   <th align=left nowrap>| . $locale->text('Birthday') . qq|</th>
1364                   <td><input id=cp_birthday name=cp_birthday size=30 maxlength=40 value="$form->{cp_birthday}"></td>
1365                 </tr>
1366                 
1367           </table>
1368         </td>
1369         </tr>
1370         <tr height="5"></tr>|;
1371 ##/LINET
1372   print qq|        $bcc
1373         $tax
1374       </table>
1375     </td>
1376   </tr>
1377   <tr>
1378     <td>
1379       
1380 <br style="clear: left" /></div>
1381 <div id="deliveries" class="tabcontent">
1382   <table>
1383     $delivery
1384     <tr>
1385       <th align=left nowrap>| . $locale->text('From') . qq|</th>
1386       <td><input id=from name=from size=10 maxlength=10 value="$form->{from}"></td>
1387       <th align=left nowrap>| . $locale->text('Bis') . qq|</th>
1388       <td><input id=to name=to size=10 maxlength=10 value="$form->{to}"></td>
1389     </tr>       
1390     <tr>
1391      <td colspan=4>
1392       <div id=delivery>
1393       </div>
1394       </td>
1395     </tr>
1396   </table>
1397 <br style="clear: left" /></div>
1398
1399 </div>
1400
1401 |;
1402
1403   $lxdebug->leave_sub();
1404 }
1405
1406 sub form_footer {
1407   $lxdebug->enter_sub();
1408
1409   $label     = ucfirst $form->{db};
1410   $quotation =
1411     ($form->{db} eq 'customer')
1412     ? $locale->text('Save and Quotation')
1413     : $locale->text('Save and RFQ');
1414   $arap =
1415     ($form->{db} eq 'customer')
1416     ? $locale->text('Save and AR Transaction')
1417     : $locale->text('Save and AP Transaction');
1418   if ($vertreter) {
1419     $update_button =
1420       qq|<input class=submit type=submit name=action accesskey="u" value="|
1421       . $locale->text("Update") . qq|">|;
1422   } else {
1423     $update_button = "";
1424   }
1425
1426 ##<input class=submit type=submit name=action value="|.$locale->text("Save and Quotation").qq|">
1427 ##<input class=submit type=submit name=action value="|.$locale->text("Save and RFQ").qq|">
1428 ##<input class=submit type=submit name=action value="|.$locale->text("Save and AR Transaction").qq|">
1429 ##<input class=submit type=submit name=action value="|.$locale->text("Save and AP Transaction").qq|">
1430
1431   print qq|
1432 <input name=id type=hidden value=$form->{id}>
1433 <input name=taxaccounts type=hidden value="$form->{taxaccounts}">
1434 <input name=business_save type=hidden value="$form->{selectbusiness}">
1435 <input name=title_save type=hidden value="$form->{title}">
1436
1437 <input type=hidden name=path value=$form->{path}>
1438 <input type=hidden name=login value=$form->{login}>
1439 <input type=hidden name=password value=$form->{password}>
1440
1441 <input type=hidden name=callback value="$form->{callback}">
1442 <input type=hidden name=db value=$form->{db}>
1443
1444
1445
1446 <br>
1447 $update_button
1448 <input class=submit type=submit name=action accesskey="s" value="|
1449     . $locale->text("Save") . qq|">
1450 <input class=submit type=submit name=action accesskey="s" value="|
1451     . $locale->text("Save and Close") . qq|">
1452 <input class=submit type=submit name=action value="$arap">
1453 <input class=submit type=submit name=action value="|
1454     . $locale->text("Save and Invoice") . qq|">
1455 <input class=submit type=submit name=action value="|
1456     . $locale->text("Save and Order") . qq|">
1457 <input class=submit type=submit name=action value="$quotation">
1458 |;
1459
1460   if ($form->{id} && $form->{status} eq 'orphaned') {
1461     print qq|<input class=submit type=submit name=action value="|
1462       . $locale->text('Delete')
1463       . qq|">\n|;
1464   }
1465
1466   if ($form->{menubar}) {
1467     require "$form->{path}/menu.pl";
1468     &menubar;
1469   }
1470
1471   print qq|
1472
1473   </form>
1474 <script type="text/javascript">
1475 //Start Tab Content script for UL with id="maintab" Separate multiple ids each with a comma.
1476 initializetabcontent("maintab")
1477 </script>
1478 </body>
1479 </html>
1480 |;
1481
1482   $lxdebug->leave_sub();
1483 }
1484
1485 sub add_transaction {
1486   $lxdebug->enter_sub();
1487
1488   $form->isblank("name", $locale->text("Name missing!"));
1489   &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
1490
1491   $form->{callback} = $form->escape($form->{callback}, 1);
1492   $name = $form->escape("$form->{name}", 1);
1493
1494   $form->{callback} =
1495     "$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}";
1496
1497   $form->redirect;
1498
1499   $lxdebug->leave_sub();
1500 }
1501
1502 sub save_and_ap_transaction {
1503   $lxdebug->enter_sub();
1504
1505   $form->{script} = "ap.pl";
1506   &add_transaction;
1507
1508   $lxdebug->leave_sub();
1509 }
1510
1511 sub save_and_ar_transaction {
1512   $lxdebug->enter_sub();
1513
1514   $form->{script} = "ar.pl";
1515   &add_transaction;
1516
1517   $lxdebug->leave_sub();
1518 }
1519
1520 sub save_and_invoice {
1521   $lxdebug->enter_sub();
1522
1523   $form->{script} = ($form->{db} eq 'customer') ? "is.pl" : "ir.pl";
1524   $form->{type} = "invoice";
1525   &add_transaction;
1526
1527   $lxdebug->leave_sub();
1528 }
1529
1530 sub save_and_rfq {
1531   $lxdebug->enter_sub();
1532
1533   $form->{script} = "oe.pl";
1534   $form->{type}   = "request_quotation";
1535   &add_transaction;
1536
1537   $lxdebug->leave_sub();
1538 }
1539
1540 sub save_and_quotation {
1541   $lxdebug->enter_sub();
1542
1543   $form->{script} = "oe.pl";
1544   $form->{type}   = "sales_quotation";
1545   &add_transaction;
1546
1547   $lxdebug->leave_sub();
1548 }
1549
1550 sub save_and_order {
1551   $lxdebug->enter_sub();
1552
1553   $form->{script} = "oe.pl";
1554   $form->{type}   =
1555     ($form->{db} eq 'customer') ? "sales_order" : "purchase_order";
1556   &add_transaction;
1557
1558   $lxdebug->leave_sub();
1559 }
1560
1561 sub save_and_close {
1562   $lxdebug->enter_sub();
1563
1564   # $locale->text('Customer saved!')
1565   # $locale->text('Vendor saved!')
1566
1567   $msg = ucfirst $form->{db};
1568   $imsg .= " saved!";
1569
1570   $form->isblank("name", $locale->text("Name missing!"));
1571   if ($vertreter && $form->{db} eq "customer") {
1572     $form->isblank("salesman_id", $locale->text("Salesman missing!"));
1573   }
1574   &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
1575
1576   $form->redirect($locale->text($msg));
1577
1578   $lxdebug->leave_sub();
1579 }
1580
1581 sub save {
1582   $lxdebug->enter_sub();
1583
1584   # $locale->text('Customer saved!')
1585   # $locale->text('Vendor saved!')
1586
1587   $msg = ucfirst $form->{db};
1588   $imsg .= " saved!";
1589
1590   $form->isblank("name", $locale->text("Name missing!"));
1591   if ($vertreter && $form->{db} eq "customer") {
1592     $form->isblank("salesman_id", $locale->text("Salesman missing!"));
1593   }
1594   print(STDERR "SHIPTO in sub save $form->{shipto_id}\n");
1595   &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
1596
1597   &edit;
1598   exit;
1599   $lxdebug->leave_sub();
1600 }
1601
1602 sub delete {
1603   $lxdebug->enter_sub();
1604
1605   # $locale->text('Customer deleted!')
1606   # $locale->text('Cannot delete customer!')
1607   # $locale->text('Vendor deleted!')
1608   # $locale->text('Cannot delete vendor!')
1609
1610   CT->delete(\%myconfig, \%$form);
1611
1612   $msg = ucfirst $form->{db};
1613   $msg .= " deleted!";
1614   $form->redirect($locale->text($msg));
1615
1616   $msg = "Cannot delete $form->{db}";
1617   $form->error($locale->text($msg));
1618
1619   $lxdebug->leave_sub();
1620 }
1621
1622 sub display {
1623   $lxdebug->enter_sub();
1624
1625   &form_header();
1626   &form_footer();
1627
1628   $lxdebug->leave_sub();
1629 }
1630
1631 sub update {
1632   $lxdebug->enter_sub();
1633
1634   &check_salesman($form->{salesman});
1635
1636   #  $form->get_salesman(\%myconfig, $form->{salesman});
1637   &display();
1638   $lxdebug->leave_sub();
1639 }
1640
1641 sub check_salesman {
1642   $lxdebug->enter_sub();
1643
1644   my ($name) = @_;
1645
1646   my ($new_name, $new_id) = split /--/, $form->{$name};
1647   my $i = 0;
1648
1649   # check name, combine name and id
1650   if ($form->{"oldsalesman"} ne $form->{"salesman"}) {
1651
1652     # return one name or a list of names in $form->{name_list}
1653     if (($i = $form->get_salesman(\%myconfig, $name)) > 1) {
1654       &select_salesman($name);
1655       exit;
1656     }
1657
1658     if ($i == 1) {
1659
1660       # we got one name
1661       $form->{"salesman_id"} = $form->{salesman_list}[0]->{id};
1662       $form->{salesman}      = $form->{salesman_list}[0]->{name};
1663       $form->{"oldsalesman"} = $form->{salesman};
1664
1665     } else {
1666
1667       # name is not on file
1668       # $locale->text('Customer not on file!')
1669       # $locale->text('Vendor not on file!')
1670       $msg = ucfirst $name . " not on file or locked!";
1671       $form->error($locale->text($msg));
1672     }
1673   }
1674
1675   $lxdebug->leave_sub();
1676
1677   return $i;
1678 }
1679
1680 sub select_salesman {
1681   $lxdebug->enter_sub();
1682
1683   my ($table) = @_;
1684
1685   @column_index = qw(ndx name);
1686
1687   $label             = ucfirst $table;
1688   $column_data{ndx}  = qq|<th>&nbsp;</th>|;
1689   $column_data{name} =
1690     qq|<th class=listheading>| . $locale->text($label) . qq|</th>|;
1691
1692   # list items with radio button on a form
1693   $form->header;
1694
1695   $title = $locale->text('Select from one of the names below');
1696
1697   print qq|
1698 <body>
1699
1700 <form method=post action=$form->{script}>
1701
1702 <table width=100%>
1703   <tr>
1704     <th class=listtop>$title</th>
1705   </tr>
1706   <tr space=5></tr>
1707   <tr>
1708     <td>
1709       <table width=100%>
1710         <tr class=listheading>|;
1711
1712   map { print "\n$column_data{$_}" } @column_index;
1713
1714   print qq|
1715         </tr>
1716 |;
1717
1718   my $i = 0;
1719   foreach $ref (@{ $form->{salesman_list} }) {
1720     $checked = ($i++) ? "" : "checked";
1721
1722     $ref->{name} =~ s/\"/&quot;/g;
1723
1724     $column_data{ndx} =
1725       qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
1726     $column_data{name} =
1727       qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
1728
1729     $j++;
1730     $j %= 2;
1731     print qq|
1732         <tr class=listrow$j>|;
1733
1734     map { print "\n$column_data{$_}" } @column_index;
1735
1736     print qq|
1737         </tr>
1738
1739 <input name="new_id_$i" type=hidden value=$ref->{id}>
1740
1741 |;
1742
1743   }
1744
1745   print qq|
1746       </table>
1747     </td>
1748   </tr>
1749   <tr>
1750     <td><hr size=3 noshade></td>
1751   </tr>
1752 </table>
1753
1754 <input name=lastndx type=hidden value=$i>
1755
1756 |;
1757
1758   # delete variables
1759   map { delete $form->{$_} } qw(action name_list header);
1760
1761   # save all other form variables
1762   foreach $key (keys %${form}) {
1763     $form->{$key} =~ s/\"/&quot;/g;
1764     print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
1765   }
1766
1767   print qq|
1768 <input type=hidden name=nextsub value=salesman_selected>
1769
1770 <input type=hidden name=vc value=$table>
1771 <br>
1772 <input class=submit type=submit name=action value="|
1773     . $locale->text('Continue') . qq|">
1774 </form>
1775
1776 </body>
1777 </html>
1778 |;
1779
1780   $lxdebug->leave_sub();
1781 }
1782
1783 sub salesman_selected {
1784   $lxdebug->enter_sub();
1785
1786   # replace the variable with the one checked
1787
1788   # index for new item
1789   $i = $form->{ndx};
1790
1791   $form->{salesman}      = $form->{"new_name_$i"};
1792   $form->{"salesman_id"} = $form->{"new_id_$i"};
1793   $form->{"oldsalesman"} = $form->{salesman};
1794
1795   # delete all the new_ variables
1796   for $i (1 .. $form->{lastndx}) {
1797     map { delete $form->{"new_${_}_$i"} } (id, name);
1798   }
1799
1800   map { delete $form->{$_} } qw(ndx lastndx nextsub);
1801
1802   &update(1);
1803
1804   $lxdebug->leave_sub();
1805 }
1806
1807 sub get_contact {
1808   $lxdebug->enter_sub();
1809
1810   CT->get_contact(\%myconfig, \%$form);
1811
1812   my $q = new CGI;
1813   $result = "$form->{cp_name}";
1814   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);
1815   print $q->header();
1816   print $result;
1817   $lxdebug->leave_sub();
1818
1819 }
1820
1821
1822 sub get_shipto {
1823   $lxdebug->enter_sub();
1824
1825   CT->get_shipto(\%myconfig, \%$form);
1826
1827   my $q = new CGI;
1828   $result = "$form->{shiptoname}";
1829   map { $result .= "__pjx__" . $form->{$_} } qw(shiptodepartment_1 shiptodepartment_2 shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax shiptoemail);
1830   print $q->header();
1831   print $result;
1832   $lxdebug->leave_sub();
1833
1834 }
1835
1836 sub get_delivery {
1837   $lxdebug->enter_sub();
1838
1839   CT->get_delivery(\%myconfig, \%$form);
1840
1841   @column_index =
1842     $form->sort_columns(shiptoname,
1843                         invnumber,
1844                         ordnumber,
1845                         transdate,
1846                         description,
1847                         adr_code,
1848                         qty,
1849                         unit);
1850
1851
1852
1853   $column_header{shiptoname} =
1854     qq|<th class=listheading>| . $locale->text('Shipping Address') . qq|</th>|;
1855   $column_header{invnumber} =
1856       qq|<th class=listheading>|. $locale->text('Invoice'). qq|</th>|;
1857   $column_header{ordnumber} =
1858       qq|<th class=listheading>|. $locale->text('Order'). qq|</th>|;
1859   $column_header{transdate} =
1860     qq|<th class=listheading>| . $locale->text('Invdate') . qq|</th>|;
1861   $column_header{description} =
1862     qq|<th class=listheading>| . $locale->text('Description') . qq|</th>|;
1863   $column_header{adr_code} =
1864     qq|<th class=listheading>| . $locale->text('ADR') . qq|</th>|;
1865   $column_header{qty} =
1866     qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
1867   $column_header{unit} =
1868     qq|<th class=listheading>| . $locale->text('Unit') . qq|</th>|;
1869   $result .= qq|
1870
1871 <table width=100%>
1872   <tr>
1873     <td>
1874       <table width=100%>
1875         <tr class=listheading>
1876 |;
1877
1878   map { $result .= "$column_header{$_}\n" } @column_index;
1879
1880   $result .= qq|
1881         </tr>
1882 |;
1883
1884
1885   foreach $ref (@{ $form->{DELIVERY} }) {
1886
1887     if ($ref->{shiptoname} eq $sameshiptoname) {
1888       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
1889       $column_data{shiptoname} = "<td>&nbsp;</td>";
1890     } else {
1891       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
1892     }
1893
1894     $i++;
1895     $i %= 2;
1896     $result .= "
1897         <tr class=listrow$i>
1898 ";
1899
1900     map { $result .= "$column_data{$_}\n" } @column_index;
1901
1902     $result .= qq|
1903         </tr>
1904 |;
1905
1906     $sameshiptoname = $ref->{shiptoname};
1907
1908   }
1909
1910   $result .= qq|
1911       </table>
1912 |;
1913
1914
1915   my $q = new CGI;
1916   print $q->header();
1917   print $result;
1918   $lxdebug->leave_sub();
1919
1920 }
1921
1922 sub continue { &{ $form->{nextsub} } }