Anordnung links wie auch die Firmennummer. Kam durch Entfernen der Gewichtseinheit.
[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 list_names {
311   $lxdebug->enter_sub();
312
313   CT->search(\%myconfig, \%$form);
314
315   $callback =
316     "$form->{script}?action=list_names&db=$form->{db}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}";
317   $href = $callback;
318
319   @columns =
320     $form->sort_columns(id, name,
321                         "$form->{db}number", address,
322                         contact,             phone,
323                         fax,                 email,
324                         taxnumber,           gifi_accno,
325                         sic_code,            business,
326                         invnumber,           ordnumber,
327                         quonumber);
328
329   foreach $item (@columns) {
330     if ($form->{"l_$item"} eq "Y") {
331       push @column_index, $item;
332
333       # add column to href and callback
334       $callback .= "&l_$item=Y";
335       $href     .= "&l_$item=Y";
336     }
337   }
338   $number =
339     ($form->{db} eq "customer")
340     ? $locale->text('Customer Number')
341     : $locale->text('Vendor Number');
342
343   if ($form->{status} eq 'all') {
344     $option = $locale->text('All');
345   }
346   if ($form->{status} eq 'orphaned') {
347     $option .= $locale->text('Orphaned');
348   }
349   if ($form->{name}) {
350     $callback .= "&name=" . $form->escape($form->{name}, 1);
351     $href .= "&name=" . $form->escape($form->{name});
352     $option .= "\n<br>" . $locale->text('Name') . " : $form->{name}";
353   }
354   if ($form->{contact}) {
355     $callback .= "&contact=" . $form->escape($form->{contact}, 1);
356     $href .= "&contact=" . $form->escape($form->{contact});
357     $option .= "\n<br>" . $locale->text('Contact') . " : $form->{contact}";
358   }
359   if ($form->{"$form->{db}number"}) {
360     $callback .=
361       qq|&$form->{db}number=| . $form->escape($form->{"$form->{db}number"}, 1);
362     $href .=
363       "&$form->{db}number=" . $form->escape($form->{"$form->{db}number"});
364     $option .=
365       "\n<br>" . $locale->text('Number') . qq| : $form->{"$form->{db}number"}|;
366   }
367   if ($form->{email}) {
368     $callback .= "&email=" . $form->escape($form->{email}, 1);
369     $href .= "&email=" . $form->escape($form->{email});
370     $option .= "\n<br>" . $locale->text('E-mail') . " : $form->{email}";
371   }
372
373   $form->{callback} = "$callback&sort=$form->{sort}";
374   $callback = $form->escape($form->{callback});
375
376   $column_header{id} =
377     qq|<th class=listheading>| . $locale->text('ID') . qq|</th>|;
378   $column_header{"$form->{db}number"} =
379     qq|<th><a class=listheading href=$href&sort=$form->{db}number>$number</a></th>|;
380   $column_header{name} =
381       qq|<th><a class=listheading href=$href&sort=name>|
382     . $locale->text('Name')
383     . qq|</a></th>|;
384   $column_header{address} =
385       qq|<th><a class=listheading href=$href&sort=address>|
386     . $locale->text('Address')
387     . qq|</a></th>|;
388   $column_header{contact} =
389       qq|<th><a class=listheading href=$href&sort=contact>|
390     . $locale->text('Contact')
391     . qq|</a></th>|;
392   $column_header{phone} =
393       qq|<th><a class=listheading href=$href&sort=phone>|
394     . $locale->text('Phone')
395     . qq|</a></th>|;
396   $column_header{fax} =
397       qq|<th><a class=listheading href=$href&sort=fax>|
398     . $locale->text('Fax')
399     . qq|</a></th>|;
400   $column_header{email} =
401       qq|<th><a class=listheading href=$href&sort=email>|
402     . $locale->text('E-mail')
403     . qq|</a></th>|;
404   $column_header{cc} =
405       qq|<th><a class=listheading href=$href&sort=cc>|
406     . $locale->text('Cc')
407     . qq|</a></th>|;
408
409   $column_header{taxnumber} =
410       qq|<th><a class=listheading href=$href&sort=taxnumber>|
411     . $locale->text('Tax Number')
412     . qq|</a></th>|;
413   $column_header{gifi_accno} =
414       qq|<th><a class=listheading href=$href&sort=gifi_accno>|
415     . $locale->text('GIFI')
416     . qq|</a></th>|;
417   $column_header{sic_code} =
418       qq|<th><a class=listheading href=$href&sort=sic_code>|
419     . $locale->text('SIC')
420     . qq|</a></th>|;
421   $column_header{business} =
422       qq|<th><a class=listheading href=$href&sort=business>|
423     . $locale->text('Type of Business')
424     . qq|</a></th>|;
425
426   $column_header{invnumber} =
427       qq|<th><a class=listheading href=$href&sort=invnumber>|
428     . $locale->text('Invoice')
429     . qq|</a></th>|;
430   $column_header{ordnumber} =
431       qq|<th><a class=listheading href=$href&sort=ordnumber>|
432     . $locale->text('Order')
433     . qq|</a></th>|;
434   $column_header{quonumber} =
435       qq|<th><a class=listheading href=$href&sort=quonumber>|
436     . $locale->text('Quotation')
437     . qq|</a></th>|;
438
439   $label = ucfirst $form->{db} . "s";
440   $form->{title} = $locale->text($label);
441
442   $form->header;
443
444   print qq|
445 <body>
446
447 <table width=100%>
448   <tr>
449     <th class=listtop>$form->{title}</th>
450   </tr>
451   <tr height="5"></tr>
452   <tr>
453     <td>$option</td>
454   </tr>
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   $ordertype = ($form->{db} eq 'customer') ? 'sales_order' : 'purchase_order';
468   $quotationtype =
469     ($form->{db} eq 'customer') ? 'sales_quotation' : 'request_quotation';
470
471   foreach $ref (@{ $form->{CT} }) {
472
473     if ($ref->{id} eq $sameid) {
474       map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
475     } else {
476       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
477
478       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
479         (invnumber, ordnumber, quonumber);
480
481       $column_data{name} =
482         "<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>";
483
484       if ($ref->{email}) {
485         $email = $ref->{email};
486         $email =~ s/</\&lt;/;
487         $email =~ s/>/\&gt;/;
488
489         $column_data{email} =
490           qq|<td><a href="mailto:$ref->{email}">$email</a></td>|;
491       }
492
493     }
494
495     if ($ref->{formtype} eq 'invoice') {
496       $column_data{invnumber} =
497         "<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>";
498     }
499
500     if ($ref->{formtype} eq 'order') {
501       $column_data{ordnumber} =
502         "<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>";
503     }
504
505     if ($ref->{formtype} eq 'quotation') {
506       $column_data{quonumber} =
507         "<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>";
508     }
509
510     $i++;
511     $i %= 2;
512     print "
513         <tr class=listrow$i>
514 ";
515
516     map { print "$column_data{$_}\n" } @column_index;
517
518     print qq|
519         </tr>
520 |;
521
522     $sameid = $ref->{id};
523
524   }
525
526   print qq|
527       </table>
528     </td>
529   </tr>
530   <tr>
531     <td><hr size=3 noshade></td>
532   </tr>
533 </table>
534
535 <br>
536 <form method=post action=$form->{script}>
537
538 <input name=callback type=hidden value="$form->{callback}">
539 <input name=db type=hidden value=$form->{db}>
540
541 <input type=hidden name=path value=$form->{path}>
542 <input type=hidden name=login value=$form->{login}>
543 <input type=hidden name=password value=$form->{password}>
544
545 <input class=submit type=submit name=action value="|
546     . $locale->text('Add') . qq|">|;
547
548   if ($form->{menubar}) {
549     require "$form->{path}/menu.pl";
550     &menubar;
551   }
552
553   print qq|
554   </form>
555
556 </body>
557 </html>
558 |;
559
560   $lxdebug->leave_sub();
561 }
562
563 sub edit {
564   $lxdebug->enter_sub();
565
566   # $locale->text('Edit Customer')
567   # $locale->text('Edit Vendor')
568
569   CT->get_tuple(\%myconfig, \%$form);
570
571   # format " into &quot;
572   map { $form->{$_} =~ s/\"/&quot;/g } keys %$form;
573
574   $form->{title} = "Edit";
575
576   # format discount
577   $form->{discount} *= 100;
578
579   &form_header;
580   &form_footer;
581
582   $lxdebug->leave_sub();
583 }
584
585 sub form_header {
586   $lxdebug->enter_sub();
587
588   $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
589   $form->{creditlimit} =
590     $form->format_amount(\%myconfig, $form->{creditlimit}, 0);
591   $form->{discount} = $form->format_amount(\%myconfig, $form->{discount});
592
593   if ($myconfig{role} eq 'admin') {
594     $bcc = qq|
595         <tr>
596           <th align=right nowrap>| . $locale->text('Bcc') . qq|</th>
597           <td><input name=bcc size=35 value="$form->{bcc}"></td>
598         </tr>
599 |;
600   }
601   $form->{obsolete} = "checked" if $form->{obsolete};
602
603   $lang = qq|<option value=""></option>|;
604   foreach $item (@{ $form->{languages} }) {
605     if ($form->{language_id} eq $item->{id}) {
606       $lang .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
607     } else {
608       $lang .= qq|<option value="$item->{id}">$item->{description}</option>|;
609     }
610   }
611
612   $payment = qq|<option value=""></option>|;
613   foreach $item (@{ $form->{payment_terms} }) {
614     if ($form->{payment_id} eq $item->{id}) {
615       $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
616     } else {
617       $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
618     }
619   }
620
621   if (!$form->{id}) {
622     if ($form->{db} eq "customer") {
623       $form->{taxzone_id} = 0;
624     } else {
625       $form->{taxzone_id} = 0;
626     }
627   }
628
629   if (@{ $form->{TAXZONE} }) {
630     foreach $item (@{ $form->{TAXZONE} }) {
631       if ($item->{id} == $form->{taxzone_id}) {
632         $form->{selecttaxzone} .=
633           "<option value=$item->{id} selected>$item->{description}\n";
634       } else {
635         $form->{selecttaxzone} .=
636           "<option value=$item->{id}>$item->{description}\n";
637       }
638
639     }
640   }
641
642   $taxzone = qq|
643               <tr>
644                 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
645                 <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
646                 <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
647               </tr>|;
648
649   $get_contact_url =
650     "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=get_contact";
651
652   my $pjx = new CGI::Ajax( 'get_contact' => $get_contact_url );
653   $form->{selectcontact} = "<option value=0></option>";
654   if (@{ $form->{CONTACTS} }) {
655     foreach $item (@{ $form->{CONTACTS} }) {
656       if ($item->{cp_id} == $form->{cp_id}) {
657         $form->{selectcontact} .=
658           qq|<option value=$item->{cp_id} selected>$item->{cp_name}</option>\n|;
659       } else {
660         $form->{selectcontact} .=
661           qq|<option value=$item->{cp_id}>$item->{cp_name}</option>\n|;
662       }
663
664     }
665   }
666   push(@ { $form->{AJAX} }, $pjx);
667   $ansprechpartner = qq|
668               <tr>
669                 <th align=right>| . $locale->text('Ansprechpartner') . qq|</th>
670                 <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>
671                 <input type=hidden name=selectcontact value="$form->{selectcontact}">
672               </tr>|;
673   $get_shipto_url =
674     "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=get_shipto";
675
676   my $pjy = new CGI::Ajax( 'get_shipto' => $get_shipto_url );
677   $form->{selectshipto} = "<option value=0></option>";
678   $form->{selectshipto} .= "<option value=0>Alle</option>";
679   if (@{ $form->{SHIPTO} }) {
680     foreach $item (@{ $form->{SHIPTO} }) {
681       if ($item->{shipto_id} == $form->{shipto_id}) {
682         $form->{selectshipto} .=
683           "<option value=$item->{shipto_id} selected>$item->{shiptoname} $item->{shiptodepartment_1}\n";
684       } else {
685         $form->{selectshipto} .=
686           "<option value=$item->{shipto_id}>$item->{shiptoname} $item->{shiptodepartment_1}\n";
687       }
688
689     }
690   }
691   push(@ { $form->{AJAX} }, $pjy);
692
693   $shipto = qq|
694               <tr>
695                 <th align=right>| . $locale->text('Shipping Address') . qq|</th>
696                 <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>
697                 <input type=hidden name=selectshipto value="$form->{selectshipto}">
698               </tr>|;
699
700
701   $get_delivery_url =
702     "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=get_delivery";
703
704   my $pjz = new CGI::Ajax( 'get_delivery' => $get_delivery_url );
705
706   push(@ { $form->{AJAX} }, $pjz);
707
708   $delivery = qq|
709               <tr>
710                 <th align=right>| . $locale->text('Shipping Address') . qq|</th>
711                 <td><select id=delivery_id name=delivery_id onChange="get_delivery(['shipto_id__' + this.value, 'from__' + from.value, 'to__' + to.value, 'id__' + cvid.value, 'db__' + db.value], ['delivery'])">$form->{selectshipto}</select></td>
712               </tr>|;
713
714   foreach $item (split / /, $form->{taxaccounts}) {
715     if (($form->{tax}{$item}{taxable}) || !($form->{id})) {
716       $taxable .=
717         qq| <input name="tax_$item" value=1 class=checkbox type=checkbox checked>&nbsp;<b>$form->{tax}{$item}{description}</b>|;
718     } else {
719       $taxable .=
720         qq| <input name="tax_$item" value=1 class=checkbox type=checkbox>&nbsp;<b>$form->{tax}{$item}{description}</b>|;
721     }
722   }
723
724 ##LINET
725   $taxable = "";
726
727   if ($taxable) {
728     $tax = qq|
729   <tr>
730     <th align=right>| . $locale->text('Taxable') . qq|</th>
731     <td colspan=2>
732       <table>
733         <tr>
734           <td>$taxable</td>
735           <td><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
736           <th align=left>| . $locale->text('Tax Included') . qq|</th>
737         </tr>
738       </table>
739     </td>
740   </tr>
741 |;
742   }
743   $form->{selectbusiness} = qq|<option>\n|;
744   map {
745     $form->{selectbusiness} .=
746       qq|<option value=$_->{id}>$_->{description}\n|
747   } @{ $form->{all_business} };
748   if ($form->{business_save}) {
749     $form->{selectbusiness} = $form->{business_save};
750   }
751   $form->{selectbusiness} =~
752     s/<option value=$form->{business}>/<option value=$form->{business} selected>/;
753
754   $label = ucfirst $form->{db};
755   if ($form->{title} eq "Edit") {
756     $form->{title} = $locale->text("$form->{title} $label") . " $form->{name}";
757   } else  {
758     $form->{title} = $locale->text("$form->{title} $label");
759   }
760   if ($form->{title_save}) {
761     $form->{title} = $form->{title_save};
762   }
763   if ($form->{db} eq 'vendor') {
764     $customer = qq|
765            <th align=right>| . $locale->text('Kundennummer') . qq|</th>
766            <td><input name=v_customer_id size=10 tabindex=18 maxlength=35 value="$form->{v_customer_id}"></td>
767 |;
768   }
769
770   if ($form->{db} eq 'customer') {
771
772     $customer = qq|
773            <th align=right>| . $locale->text('KNr. beim Kunden') . qq|</th>
774            <td><input name=c_vendor_id size=10 tabindex=18 maxlength=35 value="$form->{c_vendor_id}"></td>
775 |;
776   }
777   $business_salesman = "";
778   $business          = "<th></th><td></td>";
779   if ($vertreter) {
780     $business_salesman = qq|
781         <tr>
782           <td colspan=3>
783             <table>
784              <th align=right>| . $locale->text('Type of Business') . qq|</th>
785              <td><select name=business tabindex=1>$form->{selectbusiness}</select></td>
786              <th align=right>| . $locale->text('Salesman') . qq|</th>
787              <td><input name=salesman tabindex=2 value="$form->{salesman}"></td>
788              <input type=hidden name=salesman_id value="$form->{salesman_id}">
789              <input type=hidden name=oldsalesman value="$form->{oldsalesman}">
790             </table>
791           </td>
792        <tr>|;
793     $business = qq|
794              <th align=right>| . $locale->text('Username') . qq|</th>
795              <td><input name=username maxlength=50 tabindex=22 value="$form->{username}"></td>
796              <th align=right>| . $locale->text('Password') . qq|</th>
797              <td><input name=user_password maxlength=12 tabindex=23 value="$form->{user_password}"></td>|;
798   } else {
799     $business = qq|
800           <th align=right>| . $locale->text('Type of Business') . qq|</th>
801           <td><select name=business tabindex=22>$form->{selectbusiness}</select></td>
802       |;
803   }
804
805 ## LINET: Create a drop-down box with all prior titles and greetings.
806   CT->query_titles_and_greetings(\%myconfig, \%$form);
807
808   $select_title = qq|&nbsp;<select name=selected_cp_title><option></option>|;
809   map({ $select_title .= qq|<option>$_</option>|; } @{ $form->{TITLES} });
810   $select_title .= qq|</select>|;
811
812   $select_greeting =
813     qq|&nbsp;<select name=selected_cp_greeting><option></option>|;
814   map(
815      { $select_greeting .= qq|<option>$_</option>|; } @{ $form->{GREETINGS} });
816   $select_greeting .= qq|</select>|;
817
818   $select_company_greeting =
819     qq|&nbsp;<select name=selected_company_greeting><option></option>|;
820   map(
821      { $select_company_greeting .= qq|<option>$_</option>|; } @{ $form->{COMPANY_GREETINGS} });
822   $select_company_greeting .= qq|</select>|;
823
824   $select_department =
825     qq|&nbsp;<select name=selected_cp_abteilung><option></option>|;
826   map(
827      { $select_department .= qq|<option>$_</option>|; } @{ $form->{DEPARTMENT} });
828   $select_department .= qq|</select>|;
829 ## /LINET
830
831   if ($form->{db} eq 'customer') {
832
833     #get pricegroup and form it
834     $form->get_pricegroup(\%myconfig, { all => 1 });
835
836     $form->{pricegroup}    = "$form->{klass}";
837     $form->{pricegroup_id} = "$form->{klass}";
838
839     if (@{ $form->{all_pricegroup} }) {
840
841       $form->{selectpricegroup} = qq|<option>\n|;
842       map {
843         $form->{selectpricegroup} .=
844           qq|<option value="$_->{id}">$_->{pricegroup}\n|
845       } @{ $form->{all_pricegroup} };
846     }
847
848     if ($form->{selectpricegroup}) {
849       $form->{selectpricegroup} = $form->unescape($form->{selectpricegroup});
850
851       $pricegroup =
852         qq|<input type=hidden name=selectpricegroup value="|
853         . $form->escape($form->{selectpricegroup}, 1) . qq|">|;
854
855       $form->{selectpricegroup} =~
856         s/(<option value="\Q$form->{klass}\E")/$1 selected/;
857
858       $pricegroup .=
859         qq|<select name=klass tabindex=24>$form->{selectpricegroup}</select>|;
860
861     }
862   }
863
864   # $locale->text('Customer Number')
865   # $locale->text('Vendor Number')
866   $form->{fokus} = "ct.greeting";
867   $form->{jsscript} = 1;
868   $form->header;
869
870   print qq|
871 <body onLoad="fokus()">
872 <table width=100%>
873   <tr>
874     <th class=listtop>$form->{title}</th>
875   </tr>
876 </table>
877
878
879 <form method=post name="ct" action=$form->{script} onKeyUp="highlight(event)" onClick="highlight(event)">
880
881
882
883 <ul id="maintab" class="shadetabs">
884 <li class="selected"><a href="#" rel="billing">|
885     . $locale->text('Billing Address') . qq|</a></li>
886 <li><a href="#" rel="shipto">|
887     . $locale->text('Shipping Address') . qq|</a></li>
888 <li><a href="#" rel="contacts">Ansprechpartner</a></li>
889 <li><a href="#" rel="deliveries">|
890     . $locale->text('Lieferungen') . qq|</a></li>
891
892 </ul>
893
894 <div class="tabcontentstyle">
895
896 <div id="billing" class="tabcontent">
897
898       <table width=100%>
899         <tr height="5"></tr>
900         $business_salesman
901         <tr>
902           <th align=right nowrap>| . $locale->text($label . ' Number') . qq|</th>
903           <td><input name="$form->{db}number" size=35 maxlength=35 value="$form->{"$form->{db}number"}"></td>
904         </tr>
905         <tr>
906           <th align=right nowrap>| . $locale->text('Greeting') . qq|</th>
907           <td><input id=greeting name=greeting size=30 maxlength=30 value="$form->{greeting}">&nbsp;
908           $select_company_greeting</td>
909         </tr>
910         <tr>
911           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
912           <td><input name=name size=35 maxlength=75 value="$form->{name}"></td>
913         </tr>
914         <tr>
915           <th align=right nowrap>| . $locale->text('Abteilung') . qq|</th>
916           <td><input name=department_1 size=16 maxlength=75 value="$form->{department_1}">
917           <input name=department_2 size=16 maxlength=75 value="$form->{department_2}"></td>
918         </tr>
919         <tr>
920           <th align=right nowrap>| . $locale->text('Street') . qq|</th>
921           <td><input name=street size=35 maxlength=75 value="$form->{street}"></td>
922         </tr>
923         <tr>
924           <th align=right nowrap>|
925     . $locale->text('Zipcode') . "/" . $locale->text('City') . qq|</th>
926           <td><input name=zipcode size=5 maxlength=10 value="$form->{zipcode}">
927           <input name=city size=30 maxlength=75 value="$form->{city}"></td>
928         </tr>
929         <tr>
930           <th align=right nowrap>| . $locale->text('Country') . qq|</th>
931           <td><input name=country size=35 maxlength=75 value="$form->{country}"></td>
932         </tr>
933         <tr>
934           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
935           <td><input name=contact size=28 maxlength=75 value="$form->{contact}"></td>
936         </tr>
937         <tr>
938           <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
939           <td><input name=phone size=30 maxlength=30 value="$form->{phone}"></td>
940         </tr>
941         <tr>
942           <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
943           <td><input name=fax size=30 maxlength=30 value="$form->{fax}"></td>
944         </tr>
945         <tr>
946           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
947           <td><input name=email size=45 value="$form->{email}"></td>
948         </tr>
949         <tr>
950           <th align=right nowrap>| . $locale->text('Homepage') . qq|</th>
951           <td><input name=homepage size=45 value="$form->{homepage}"></td>
952         </tr>
953 </table>
954 <table>
955         <tr>
956           <th align=right>| . $locale->text('Credit Limit') . qq|</th>
957           <td><input name=creditlimit size=9 value="$form->{creditlimit}"></td>
958           <input type="hidden" name="terms" value="$form->{terms}">
959           <th align=right>| . $locale->text('Payment Terms') . qq|</th>
960           <td><select name=payment_id>$payment</select></td>
961           <th align=right>| . $locale->text('Discount') . qq|</th>
962           <td><input name=discount size=4 value="$form->{discount}">
963           %</td>
964         </tr>
965         <tr>
966           <th align=right>| . $locale->text('Tax Number / SSN') . qq|</th>
967           <td><input name=taxnumber size=20 value="$form->{taxnumber}"></td>
968           <th align=right>| . $locale->text('USt-IdNr.') . qq|</th>
969           <td><input name="ustid" maxlength="14" size="20" value="$form->{ustid}"></td>
970           $customer
971         </tr>
972         <tr>
973           <th align=right>| . $locale->text('Account Number') . qq|</th>
974           <td><input name=account_number size=10 value="$form->{account_number}"></td>
975           <th align=right>| . $locale->text('Bank Code Number') . qq|</th>
976           <td><input name=bank_code size=10 value="$form->{bank_code}"></td>
977           <th align=right>| . $locale->text('Bank') . qq|</th>
978           <td><input name=bank size=30 value="$form->{bank}"></td>
979         </tr>
980         <tr>
981           $business
982           <th align=right>| . $locale->text('Language') . qq|</th>
983           <td><select name=language_id tabindex=23>$lang
984                           </select></td>|;
985
986   if ($form->{db} eq 'customer') {
987
988     print qq|
989           <th align=right>| . $locale->text('Preisklasse') . qq|</th>
990           <td>$pricegroup</td>|;
991   }
992   print qq|        </tr>
993         <tr>
994           <td align=right>| . $locale->text('Obsolete') . qq|</td>
995           <td><input name=obsolete class=checkbox type=checkbox value=1 $form->{obsolete}></td>
996         </tr>
997         $taxzone
998       </table>
999   <table>
1000   <tr>
1001     <th align=left nowrap>| . $locale->text('Notes') . qq|</th>
1002   </tr>
1003   <tr>
1004     <td><textarea name=notes rows=3 cols=60 wrap=soft>$form->{notes}</textarea></td>
1005   </tr>
1006
1007             </table>
1008           </td>
1009         </tr>
1010 </table>
1011 <br style="clear: left" /></div>|;
1012
1013 print qq|
1014       <div id="shipto" class="tabcontent">
1015
1016       <table width=100%>
1017 $shipto
1018         <tr>
1019           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
1020           <td><input id=shiptoname name=shiptoname size=35 maxlength=75 value="$form->{shiptoname}"></td>
1021         </tr>
1022         <tr>
1023           <th align=right nowrap>| . $locale->text('Abteilung') . qq|</th>
1024           <td><input id=shiptodepartment_1 name=shiptodepartment_1 size=16 maxlength=75 value="$form->{shiptodepartment_1}">
1025           <input id=shiptodepartment_2 name=shiptodepartment_2 size=16 maxlength=75 value="$form->{shiptodepartment_2}"></td>
1026         </tr>
1027         <tr>
1028           <th align=right nowrap>| . $locale->text('Street') . qq|</th>
1029           <td><input id=shiptostreet name=shiptostreet size=35 maxlength=75 value="$form->{shiptostreet}"></td>
1030         </tr>
1031         <tr>
1032           <th align=right nowrap>|
1033     . $locale->text('Zipcode') . "/" . $locale->text('City') . qq|</th>
1034           <td><input id=shiptozipcode name=shiptozipcode size=5 maxlength=10 value="$form->{shiptozipcode}">
1035           <input id=shiptocity name=shiptocity size=30 maxlength=75 value="$form->{shiptocity}"></td>
1036         </tr>
1037         <tr>
1038           <th align=right nowrap>| . $locale->text('Country') . qq|</th>
1039           <td><input id=shiptocountry name=shiptocountry size=35 maxlength=35 value="$form->{shiptocountry}"></td>
1040         </tr>
1041         <tr>
1042           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
1043           <td><input id=shiptocontact name=shiptocontact size=30 maxlength=75 value="$form->{shiptocontact}"></td>
1044         </tr>
1045         <tr>
1046           <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
1047           <td><input id=shiptophone name=shiptophone size=30 maxlength=30 value="$form->{shiptophone}"></td>
1048         </tr>
1049         <tr>
1050           <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
1051           <td><input id=shiptofax name=shiptofax size=30 maxlength=30 value="$form->{shiptofax}"></td>
1052         </tr>
1053         <tr>
1054           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
1055           <td><input id=shiptoemail name=shiptoemail size=45 value="$form->{shiptoemail}"></td>
1056         </tr>
1057         <tr>
1058           <td>&nbsp;</td>
1059         </tr>
1060         <tr>
1061            <td>&nbsp;</td>
1062        </tr>
1063
1064     </table>
1065 <br style="clear: left" /></div>|;
1066
1067
1068 ##LINET - added fields for contact person
1069   print qq|   
1070 <div id="contacts" class="tabcontent">
1071 <table>
1072     <tr>
1073          <td colspan=3>
1074                 <input type=hidden name=cp_id value=$form->{cp_id}>
1075                 <table>
1076                 $ansprechpartner
1077                 <tr>
1078                   <th align=left nowrap>| . $locale->text('Greeting') . qq|</th>
1079                   <td><input id=cp_greeting name=cp_greeting size=30 maxlength=30 value="$form->{cp_greeting}">&nbsp;
1080                   $select_greeting</td>
1081                 </tr>
1082                 <tr>
1083                   <th align=left nowrap>| . $locale->text('Title') . qq|</th>
1084                   <td><input id=cp_title name=cp_title size=30 maxlength=30 value="$form->{cp_title}">&nbsp;
1085                   $select_title</td>
1086                 </tr>
1087                 <tr>
1088                   <th align=left nowrap>| . $locale->text('Department') . qq|</th>
1089                   <td><input id=cp_abteilung name=cp_abteilung size=30 maxlength=40 value="$form->{cp_abteilung}">&nbsp;
1090                   $select_department</td>
1091                 </tr>
1092                 <tr>
1093                   <th align=left nowrap>|
1094     . $locale->text('Given Name') . qq|</th>
1095                   <td><input id=cp_givenname name=cp_givenname size=30 maxlength=40 value="$form->{cp_givenname}"></td>
1096                 </tr>
1097                 <tr>
1098                   <th align=left nowrap>| . $locale->text('Name') . qq|</th>
1099                   <td><input id=cp_name name=cp_name size=30 maxlength=40 value="$form->{cp_name}"></td>
1100                 </tr>
1101                 <tr>
1102                   <th align=left nowrap>| . $locale->text('Phone1') . qq|</th>
1103                   <td><input id=cp_phone1 name=cp_phone1 size=30 maxlength=30 value="$form->{cp_phone1}"></td>
1104                 </tr>
1105                 <tr>
1106                   <th align=left nowrap>| . $locale->text('Phone2') . qq|</th>
1107                   <td><input id=cp_phone2 name=cp_phone2 size=30 maxlength=30 value="$form->{cp_phone2}"></td>
1108                 </tr>
1109                 <tr>
1110                   <th align=left nowrap>| . $locale->text('Fax') . qq|</th>
1111                   <td><input id=cp_fax name=cp_fax size=30 maxlength=30 value="$form->{cp_fax}"></td>
1112                 </tr>
1113                 <tr>
1114                   <th align=left nowrap>| . $locale->text('Mobile1') . qq|</th>
1115                   <td><input id=cp_mobile1 name=cp_mobile1 size=30 maxlength=30 value="$form->{cp_mobile1}"></td>
1116                 </tr>
1117                 <tr>
1118                   <th align=left nowrap>| . $locale->text('Mobile2') . qq|</th>
1119                   <td><input id=cp_mobile2 name=cp_mobile2 size=30 maxlength=30 value="$form->{cp_mobile2}"></td>
1120                 </tr>
1121                 <tr>
1122                   <th align=left nowrap>| . $locale->text('Sat. Phone') . qq|</th>
1123                   <td><input id=cp_satphone name=cp_satphone size=30 maxlength=30 value="$form->{cp_satphone}"></td>
1124                 </tr>
1125                 <tr>
1126                   <th align=left nowrap>| . $locale->text('Sat. Fax') . qq|</th>
1127                   <td><input id=cp_satfax name=cp_satfax size=30 maxlength=30 value="$form->{cp_satfax}"></td>
1128                 </tr>
1129                 <tr>
1130                   <th align=left nowrap>| . $locale->text('Project') . qq|</th>
1131                   <td><input id=cp_project name=cp_project size=30 maxlength=40 value="$form->{cp_project}"></td>
1132                 </tr>
1133                 <tr>
1134                   <th align=left nowrap>| . $locale->text('E-mail') . qq|</th>
1135                   <td><input id=cp_email name=cp_email size=30 maxlength=40 value="$form->{cp_email}"></td>
1136                 </tr>
1137                 <tr>
1138                   <th align=left nowrap>| . $locale->text('Private Phone') . qq|</th>
1139                   <td><input id=cp_privatphone name=cp_privatphone size=30 maxlength=40 value="$form->{cp_privatphone}"></td>
1140                 </tr>
1141                 <tr>
1142                   <th align=left nowrap>| . $locale->text('Private E-mail') . qq|</th>
1143                   <td><input id=cp_privatemail name=cp_privatemail size=30 maxlength=40 value="$form->{cp_privatemail}"></td>
1144                 </tr>
1145                 <tr>
1146                   <th align=left nowrap>| . $locale->text('Birthday') . qq|</th>
1147                   <td><input id=cp_birthday name=cp_birthday size=30 maxlength=40 value="$form->{cp_birthday}"></td>
1148                 </tr>
1149                 
1150           </table>
1151         </td>
1152         </tr>
1153         <tr height="5"></tr>|;
1154 ##/LINET
1155   print qq|        $bcc
1156         $tax
1157       </table>
1158     </td>
1159   </tr>
1160   <tr>
1161     <td>
1162       
1163 <br style="clear: left" /></div>
1164 <div id="deliveries" class="tabcontent">
1165   <table>
1166     $delivery
1167     <tr>
1168       <th align=left nowrap>| . $locale->text('From') . qq|</th>
1169       <td><input id=from name=from size=10 maxlength=10 value="$form->{from}">
1170         <input type="button" name="from" id="trigger_from" value="?"></td>
1171       <th align=left nowrap>| . $locale->text('To (time)') . qq|</th>
1172       <td><input id=to name=to size=10 maxlength=10 value="$form->{to}">
1173         <input type="button" name="to" id="trigger_to" value="?"></td>
1174     </tr>       
1175     <tr>
1176      <td colspan=4>
1177       <div id=delivery>
1178       </div>
1179       </td>
1180     </tr>
1181   </table>
1182 <br style="clear: left" /></div>
1183
1184 </div>
1185
1186 | . $form->write_trigger(\%myconfig, 2, "from", "BL", "trigger_from",
1187                          "to", "BL", "trigger_to");
1188
1189   $lxdebug->leave_sub();
1190 }
1191
1192 sub form_footer {
1193   $lxdebug->enter_sub();
1194
1195   $label     = ucfirst $form->{db};
1196   $quotation =
1197     ($form->{db} eq 'customer')
1198     ? $locale->text('Save and Quotation')
1199     : $locale->text('Save and RFQ');
1200   $arap =
1201     ($form->{db} eq 'customer')
1202     ? $locale->text('Save and AR Transaction')
1203     : $locale->text('Save and AP Transaction');
1204   if ($vertreter) {
1205     $update_button =
1206       qq|<input class=submit type=submit name=action accesskey="u" value="|
1207       . $locale->text("Update") . qq|">|;
1208   } else {
1209     $update_button = "";
1210   }
1211
1212 ##<input class=submit type=submit name=action value="|.$locale->text("Save and Quotation").qq|">
1213 ##<input class=submit type=submit name=action value="|.$locale->text("Save and RFQ").qq|">
1214 ##<input class=submit type=submit name=action value="|.$locale->text("Save and AR Transaction").qq|">
1215 ##<input class=submit type=submit name=action value="|.$locale->text("Save and AP Transaction").qq|">
1216
1217   print qq|
1218 <input name=id type=hidden id=cvid value=$form->{id}>
1219 <input name=taxaccounts type=hidden value="$form->{taxaccounts}">
1220 <input name=business_save type=hidden value="$form->{selectbusiness}">
1221 <input name=title_save type=hidden value="$form->{title}">
1222
1223 <input type=hidden name=path value=$form->{path}>
1224 <input type=hidden name=login value=$form->{login}>
1225 <input type=hidden name=password value=$form->{password}>
1226
1227 <input type=hidden name=callback value="$form->{callback}">
1228 <input type=hidden name=db id=db value=$form->{db}>
1229
1230
1231
1232 <br>
1233 $update_button
1234 <input class=submit type=submit name=action accesskey="s" value="|
1235     . $locale->text("Save") . qq|">
1236 <input class=submit type=submit name=action accesskey="s" value="|
1237     . $locale->text("Save and Close") . qq|">
1238 <input class=submit type=submit name=action value="$arap">
1239 <input class=submit type=submit name=action value="|
1240     . $locale->text("Save and Invoice") . qq|">
1241 <input class=submit type=submit name=action value="|
1242     . $locale->text("Save and Order") . qq|">
1243 <input class=submit type=submit name=action value="$quotation">
1244 |;
1245
1246   if ($form->{id} && $form->{status} eq 'orphaned') {
1247     print qq|<input class=submit type=submit name=action value="|
1248       . $locale->text('Delete')
1249       . qq|">\n|;
1250   }
1251
1252   if ($form->{menubar}) {
1253     require "$form->{path}/menu.pl";
1254     &menubar;
1255   }
1256
1257   print qq|
1258
1259   </form>
1260 <script type="text/javascript">
1261 //Start Tab Content script for UL with id="maintab" Separate multiple ids each with a comma.
1262 initializetabcontent("maintab")
1263 </script>
1264 </body>
1265 </html>
1266 |;
1267
1268   $lxdebug->leave_sub();
1269 }
1270
1271 sub add_transaction {
1272   $lxdebug->enter_sub();
1273
1274   $form->isblank("name", $locale->text("Name missing!"));
1275   if ($vertreter && $form->{db} eq "customer") {
1276     $form->isblank("salesman_id", $locale->text("Salesman missing!"));
1277   }
1278   &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
1279
1280   $form->{callback} = $form->escape($form->{callback}, 1);
1281   $name = $form->escape("$form->{name}", 1);
1282
1283   $form->{callback} =
1284     "$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}";
1285
1286   $form->redirect;
1287
1288   $lxdebug->leave_sub();
1289 }
1290
1291 sub save_and_ap_transaction {
1292   $lxdebug->enter_sub();
1293
1294   $form->{script} = "ap.pl";
1295   &add_transaction;
1296
1297   $lxdebug->leave_sub();
1298 }
1299
1300 sub save_and_ar_transaction {
1301   $lxdebug->enter_sub();
1302
1303   $form->{script} = "ar.pl";
1304   &add_transaction;
1305
1306   $lxdebug->leave_sub();
1307 }
1308
1309 sub save_and_invoice {
1310   $lxdebug->enter_sub();
1311
1312   $form->{script} = ($form->{db} eq 'customer') ? "is.pl" : "ir.pl";
1313   $form->{type} = "invoice";
1314   &add_transaction;
1315
1316   $lxdebug->leave_sub();
1317 }
1318
1319 sub save_and_rfq {
1320   $lxdebug->enter_sub();
1321
1322   $form->{script} = "oe.pl";
1323   $form->{type}   = "request_quotation";
1324   &add_transaction;
1325
1326   $lxdebug->leave_sub();
1327 }
1328
1329 sub save_and_quotation {
1330   $lxdebug->enter_sub();
1331
1332   $form->{script} = "oe.pl";
1333   $form->{type}   = "sales_quotation";
1334   &add_transaction;
1335
1336   $lxdebug->leave_sub();
1337 }
1338
1339 sub save_and_order {
1340   $lxdebug->enter_sub();
1341
1342   $form->{script} = "oe.pl";
1343   $form->{type}   =
1344     ($form->{db} eq 'customer') ? "sales_order" : "purchase_order";
1345   &add_transaction;
1346
1347   $lxdebug->leave_sub();
1348 }
1349
1350 sub save_and_close {
1351   $lxdebug->enter_sub();
1352
1353   # $locale->text('Customer saved!')
1354   # $locale->text('Vendor saved!')
1355
1356   $msg = ucfirst $form->{db};
1357   $imsg .= " saved!";
1358
1359   $form->isblank("name", $locale->text("Name missing!"));
1360   if ($vertreter && $form->{db} eq "customer") {
1361     $form->isblank("salesman_id", $locale->text("Salesman missing!"));
1362   }
1363   $rc = &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
1364   if ($rc == 3) {
1365     $form->error($locale->text('customernumber not unique!'));
1366   }
1367   $form->redirect($locale->text($msg));
1368
1369   $lxdebug->leave_sub();
1370 }
1371
1372 sub save {
1373   $lxdebug->enter_sub();
1374
1375   # $locale->text('Customer saved!')
1376   # $locale->text('Vendor saved!')
1377
1378   $msg = ucfirst $form->{db};
1379   $imsg .= " saved!";
1380
1381   $form->isblank("name", $locale->text("Name missing!"));
1382   if ($vertreter && $form->{db} eq "customer") {
1383     $form->isblank("salesman_id", $locale->text("Salesman missing!"));
1384   }
1385   print(STDERR "SHIPTO in sub save $form->{shipto_id}\n");
1386   &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
1387
1388   &edit;
1389   exit;
1390   $lxdebug->leave_sub();
1391 }
1392
1393 sub delete {
1394   $lxdebug->enter_sub();
1395
1396   # $locale->text('Customer deleted!')
1397   # $locale->text('Cannot delete customer!')
1398   # $locale->text('Vendor deleted!')
1399   # $locale->text('Cannot delete vendor!')
1400
1401   CT->delete(\%myconfig, \%$form);
1402
1403   $msg = ucfirst $form->{db};
1404   $msg .= " deleted!";
1405   $form->redirect($locale->text($msg));
1406
1407   $msg = "Cannot delete $form->{db}";
1408   $form->error($locale->text($msg));
1409
1410   $lxdebug->leave_sub();
1411 }
1412
1413 sub display {
1414   $lxdebug->enter_sub();
1415
1416   &form_header();
1417   &form_footer();
1418
1419   $lxdebug->leave_sub();
1420 }
1421
1422 sub update {
1423   $lxdebug->enter_sub();
1424
1425   &check_salesman($form->{salesman});
1426
1427   #  $form->get_salesman(\%myconfig, $form->{salesman});
1428   &display();
1429   $lxdebug->leave_sub();
1430 }
1431
1432 sub check_salesman {
1433   $lxdebug->enter_sub();
1434
1435   my ($name) = @_;
1436
1437   my ($new_name, $new_id) = split /--/, $form->{$name};
1438   my $i = 0;
1439
1440   # check name, combine name and id
1441   if ($form->{"oldsalesman"} ne $form->{"salesman"}) {
1442
1443     # return one name or a list of names in $form->{name_list}
1444     if (($i = $form->get_salesman(\%myconfig, $name)) > 1) {
1445       &select_salesman($name);
1446       exit;
1447     }
1448
1449     if ($i == 1) {
1450
1451       # we got one name
1452       $form->{"salesman_id"} = $form->{salesman_list}[0]->{id};
1453       $form->{salesman}      = $form->{salesman_list}[0]->{name};
1454       $form->{"oldsalesman"} = $form->{salesman};
1455
1456     } else {
1457
1458       # name is not on file
1459       # $locale->text('Customer not on file!')
1460       # $locale->text('Vendor not on file!')
1461       $msg = ucfirst $name . " not on file or locked!";
1462       $form->error($locale->text($msg));
1463     }
1464   }
1465
1466   $lxdebug->leave_sub();
1467
1468   return $i;
1469 }
1470
1471 sub select_salesman {
1472   $lxdebug->enter_sub();
1473
1474   my ($table) = @_;
1475
1476   @column_index = qw(ndx name);
1477
1478   $label             = ucfirst $table;
1479   $column_data{ndx}  = qq|<th>&nbsp;</th>|;
1480   $column_data{name} =
1481     qq|<th class=listheading>| . $locale->text($label) . qq|</th>|;
1482
1483   # list items with radio button on a form
1484   $form->header;
1485
1486   $title = $locale->text('Select from one of the names below');
1487
1488   print qq|
1489 <body>
1490
1491 <form method=post action=$form->{script}>
1492
1493 <table width=100%>
1494   <tr>
1495     <th class=listtop>$title</th>
1496   </tr>
1497   <tr space=5></tr>
1498   <tr>
1499     <td>
1500       <table width=100%>
1501         <tr class=listheading>|;
1502
1503   map { print "\n$column_data{$_}" } @column_index;
1504
1505   print qq|
1506         </tr>
1507 |;
1508
1509   my $i = 0;
1510   foreach $ref (@{ $form->{salesman_list} }) {
1511     $checked = ($i++) ? "" : "checked";
1512
1513     $ref->{name} =~ s/\"/&quot;/g;
1514
1515     $column_data{ndx} =
1516       qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
1517     $column_data{name} =
1518       qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
1519
1520     $j++;
1521     $j %= 2;
1522     print qq|
1523         <tr class=listrow$j>|;
1524
1525     map { print "\n$column_data{$_}" } @column_index;
1526
1527     print qq|
1528         </tr>
1529
1530 <input name="new_id_$i" type=hidden value=$ref->{id}>
1531
1532 |;
1533
1534   }
1535
1536   print qq|
1537       </table>
1538     </td>
1539   </tr>
1540   <tr>
1541     <td><hr size=3 noshade></td>
1542   </tr>
1543 </table>
1544
1545 <input name=lastndx type=hidden value=$i>
1546
1547 |;
1548
1549   # delete variables
1550   map { delete $form->{$_} } qw(action name_list header);
1551
1552   # save all other form variables
1553   foreach $key (keys %${form}) {
1554     $form->{$key} =~ s/\"/&quot;/g;
1555     print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
1556   }
1557
1558   print qq|
1559 <input type=hidden name=nextsub value=salesman_selected>
1560
1561 <input type=hidden name=vc value=$table>
1562 <br>
1563 <input class=submit type=submit name=action value="|
1564     . $locale->text('Continue') . qq|">
1565 </form>
1566
1567 </body>
1568 </html>
1569 |;
1570
1571   $lxdebug->leave_sub();
1572 }
1573
1574 sub salesman_selected {
1575   $lxdebug->enter_sub();
1576
1577   # replace the variable with the one checked
1578
1579   # index for new item
1580   $i = $form->{ndx};
1581
1582   $form->{salesman}      = $form->{"new_name_$i"};
1583   $form->{"salesman_id"} = $form->{"new_id_$i"};
1584   $form->{"oldsalesman"} = $form->{salesman};
1585
1586   # delete all the new_ variables
1587   for $i (1 .. $form->{lastndx}) {
1588     map { delete $form->{"new_${_}_$i"} } (id, name);
1589   }
1590
1591   map { delete $form->{$_} } qw(ndx lastndx nextsub);
1592
1593   &update(1);
1594
1595   $lxdebug->leave_sub();
1596 }
1597
1598 sub get_contact {
1599   $lxdebug->enter_sub();
1600
1601   CT->get_contact(\%myconfig, \%$form);
1602
1603   my $q = new CGI;
1604   $result = "$form->{cp_name}";
1605   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);
1606   print $q->header();
1607   print $result;
1608   $lxdebug->leave_sub();
1609
1610 }
1611
1612
1613 sub get_shipto {
1614   $lxdebug->enter_sub();
1615
1616   CT->get_shipto(\%myconfig, \%$form);
1617
1618   my $q = new CGI;
1619   $result = "$form->{shiptoname}";
1620   map { $result .= "__pjx__" . $form->{$_} } qw(shiptodepartment_1 shiptodepartment_2 shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax shiptoemail);
1621   print $q->header();
1622   print $result;
1623   $lxdebug->leave_sub();
1624
1625 }
1626
1627 sub get_delivery {
1628   $lxdebug->enter_sub();
1629
1630   CT->get_delivery(\%myconfig, \%$form );
1631
1632   @column_index =
1633     $form->sort_columns(shiptoname,
1634                         invnumber,
1635                         ordnumber,
1636                         transdate,
1637                         description,
1638                         qty,
1639                         unit);
1640
1641
1642
1643   $column_header{shiptoname} =
1644     qq|<th class=listheading>| . $locale->text('Shipping Address') . qq|</th>|;
1645   $column_header{invnumber} =
1646       qq|<th class=listheading>|. $locale->text('Invoice'). qq|</th>|;
1647   $column_header{ordnumber} =
1648       qq|<th class=listheading>|. $locale->text('Order'). qq|</th>|;
1649   $column_header{transdate} =
1650     qq|<th class=listheading>| . $locale->text('Invdate') . qq|</th>|;
1651   $column_header{description} =
1652     qq|<th class=listheading>| . $locale->text('Description') . qq|</th>|;
1653   $column_header{qty} =
1654     qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
1655   $column_header{unit} =
1656     qq|<th class=listheading>| . $locale->text('Unit') . qq|</th>|;
1657   $result .= qq|
1658
1659 <table width=100%>
1660   <tr>
1661     <td>
1662       <table width=100%>
1663         <tr class=listheading>
1664 |;
1665
1666   map { $result .= "$column_header{$_}\n" } @column_index;
1667
1668   $result .= qq|
1669         </tr>
1670 |;
1671
1672
1673   foreach $ref (@{ $form->{DELIVERY} }) {
1674
1675     if ($ref->{shiptoname} eq $sameshiptoname) {
1676       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
1677       $column_data{shiptoname} = "<td>&nbsp;</td>";
1678     } else {
1679       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
1680     }
1681
1682     $i++;
1683     $i %= 2;
1684     $result .= "
1685         <tr class=listrow$i>
1686 ";
1687
1688     map { $result .= "$column_data{$_}\n" } @column_index;
1689
1690     $result .= qq|
1691         </tr>
1692 |;
1693
1694     $sameshiptoname = $ref->{shiptoname};
1695
1696   }
1697
1698   $result .= qq|
1699       </table>
1700 |;
1701
1702
1703   my $q = new CGI;
1704   print $q->header();
1705   print $result;
1706   $lxdebug->leave_sub();
1707
1708 }
1709
1710 sub continue { &{ $form->{nextsub} } }