d94b9b19a04bfe3abe1b758eceefb55c690b2c5b
[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->header;
868
869   print qq|
870 <body onLoad="fokus()">
871 <table width=100%>
872   <tr>
873     <th class=listtop>$form->{title}</th>
874   </tr>
875 </table>
876
877
878 <form method=post name="ct" action=$form->{script} onKeyUp="highlight(event)" onClick="highlight(event)">
879
880
881
882 <ul id="maintab" class="shadetabs">
883 <li class="selected"><a href="#" rel="billing">|
884     . $locale->text('Billing Address') . qq|</a></li>
885 <li><a href="#" rel="shipto">|
886     . $locale->text('Shipping Address') . qq|</a></li>
887 <li><a href="#" rel="contacts">Ansprechpartner</a></li>
888 <li><a href="#" rel="deliveries">|
889     . $locale->text('Lieferungen') . qq|</a></li>
890
891 </ul>
892
893 <div class="tabcontentstyle">
894
895 <div id="billing" class="tabcontent">
896
897       <table width=100%>
898         <tr height="5"></tr>
899         $business_salesman
900         <tr>
901           <th align=right nowrap>| . $locale->text($label . ' Number') . qq|</th>
902           <td><input name="$form->{db}number" size=35 maxlength=35 value="$form->{"$form->{db}number"}"></td>
903         </tr>
904         <tr>
905           <th align=right nowrap>| . $locale->text('Greeting') . qq|</th>
906           <td><input id=greeting name=greeting size=30 maxlength=30 value="$form->{greeting}">&nbsp;
907           $select_company_greeting</td>
908         </tr>
909         <tr>
910           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
911           <td><input name=name size=35 maxlength=75 value="$form->{name}"></td>
912         </tr>
913         <tr>
914           <th align=right nowrap>| . $locale->text('Abteilung') . qq|</th>
915           <td><input name=department_1 size=16 maxlength=75 value="$form->{department_1}">
916           <input name=department_2 size=16 maxlength=75 value="$form->{department_2}"></td>
917         </tr>
918         <tr>
919           <th align=right nowrap>| . $locale->text('Street') . qq|</th>
920           <td><input name=street size=35 maxlength=75 value="$form->{street}"></td>
921         </tr>
922         <tr>
923           <th align=right nowrap>|
924     . $locale->text('Zipcode') . "/" . $locale->text('City') . qq|</th>
925           <td><input name=zipcode size=5 maxlength=10 value="$form->{zipcode}">
926           <input name=city size=30 maxlength=75 value="$form->{city}"></td>
927         </tr>
928         <tr>
929           <th align=right nowrap>| . $locale->text('Country') . qq|</th>
930           <td><input name=country size=35 maxlength=75 value="$form->{country}"></td>
931         </tr>
932         <tr>
933           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
934           <td><input name=contact size=28 maxlength=75 value="$form->{contact}"></td>
935         </tr>
936         <tr>
937           <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
938           <td><input name=phone size=30 maxlength=30 value="$form->{phone}"></td>
939         </tr>
940         <tr>
941           <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
942           <td><input name=fax size=30 maxlength=30 value="$form->{fax}"></td>
943         </tr>
944         <tr>
945           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
946           <td><input name=email size=45 value="$form->{email}"></td>
947         </tr>
948         <tr>
949           <th align=right nowrap>| . $locale->text('Homepage') . qq|</th>
950           <td><input name=homepage size=45 value="$form->{homepage}"></td>
951         </tr>
952 </table>
953 <table>
954         <tr>
955           <th align=right>| . $locale->text('Credit Limit') . qq|</th>
956           <td><input name=creditlimit size=9 value="$form->{creditlimit}"></td>
957           <input type="hidden" name="terms" value="$form->{terms}">
958           <th align=right>| . $locale->text('Payment Terms') . qq|</th>
959           <td><select name=payment_id>$payment</select></td>
960           <th align=right>| . $locale->text('Discount') . qq|</th>
961           <td><input name=discount size=4 value="$form->{discount}">
962           %</td>
963         </tr>
964         <tr>
965           <th align=right>| . $locale->text('Tax Number / SSN') . qq|</th>
966           <td><input name=taxnumber size=20 value="$form->{taxnumber}"></td>
967           <th align=right>| . $locale->text('USt-IdNr.') . qq|</th>
968           <td><input name="ustid" maxlength="14" size="20" value="$form->{ustid}"></td>
969           $customer
970         </tr>
971         <tr>
972           <th align=right>| . $locale->text('Account Number') . qq|</th>
973           <td><input name=account_number size=10 value="$form->{account_number}"></td>
974           <th align=right>| . $locale->text('Bank Code Number') . qq|</th>
975           <td><input name=bank_code size=10 value="$form->{bank_code}"></td>
976           <th align=right>| . $locale->text('Bank') . qq|</th>
977           <td><input name=bank size=30 value="$form->{bank}"></td>
978         </tr>
979         <tr>
980           $business
981           <th align=right>| . $locale->text('Language') . qq|</th>
982           <td><select name=language_id tabindex=23>$lang
983                           </select></td>|;
984
985   if ($form->{db} eq 'customer') {
986
987     print qq|
988           <th align=right>| . $locale->text('Preisklasse') . qq|</th>
989           <td>$pricegroup</td>|;
990   }
991   print qq|        </tr>
992         <tr>
993           <td align=right>| . $locale->text('Obsolete') . qq|</td>
994           <td><input name=obsolete class=checkbox type=checkbox value=1 $form->{obsolete}></td>
995         </tr>
996         $taxzone
997       </table>
998   <table>
999   <tr>
1000     <th align=left nowrap>| . $locale->text('Notes') . qq|</th>
1001   </tr>
1002   <tr>
1003     <td><textarea name=notes rows=3 cols=60 wrap=soft>$form->{notes}</textarea></td>
1004   </tr>
1005
1006             </table>
1007           </td>
1008         </tr>
1009 </table>
1010 <br style="clear: left" /></div>|;
1011
1012 print qq|
1013       <div id="shipto" class="tabcontent">
1014
1015       <table width=100%>
1016 $shipto
1017         <tr>
1018           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
1019           <td><input id=shiptoname name=shiptoname size=35 maxlength=75 value="$form->{shiptoname}"></td>
1020         </tr>
1021         <tr>
1022           <th align=right nowrap>| . $locale->text('Abteilung') . qq|</th>
1023           <td><input id=shiptodepartment_1 name=shiptodepartment_1 size=16 maxlength=75 value="$form->{shiptodepartment_1}">
1024           <input id=shiptodepartment_2 name=shiptodepartment_2 size=16 maxlength=75 value="$form->{shiptodepartment_2}"></td>
1025         </tr>
1026         <tr>
1027           <th align=right nowrap>| . $locale->text('Street') . qq|</th>
1028           <td><input id=shiptostreet name=shiptostreet size=35 maxlength=75 value="$form->{shiptostreet}"></td>
1029         </tr>
1030         <tr>
1031           <th align=right nowrap>|
1032     . $locale->text('Zipcode') . "/" . $locale->text('City') . qq|</th>
1033           <td><input id=shiptozipcode name=shiptozipcode size=5 maxlength=10 value="$form->{shiptozipcode}">
1034           <input id=shiptocity name=shiptocity size=30 maxlength=75 value="$form->{shiptocity}"></td>
1035         </tr>
1036         <tr>
1037           <th align=right nowrap>| . $locale->text('Country') . qq|</th>
1038           <td><input id=shiptocountry name=shiptocountry size=35 maxlength=35 value="$form->{shiptocountry}"></td>
1039         </tr>
1040         <tr>
1041           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
1042           <td><input id=shiptocontact name=shiptocontact size=30 maxlength=75 value="$form->{shiptocontact}"></td>
1043         </tr>
1044         <tr>
1045           <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
1046           <td><input id=shiptophone name=shiptophone size=30 maxlength=30 value="$form->{shiptophone}"></td>
1047         </tr>
1048         <tr>
1049           <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
1050           <td><input id=shiptofax name=shiptofax size=30 maxlength=30 value="$form->{shiptofax}"></td>
1051         </tr>
1052         <tr>
1053           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
1054           <td><input id=shiptoemail name=shiptoemail size=45 value="$form->{shiptoemail}"></td>
1055         </tr>
1056         <tr>
1057           <td>&nbsp;</td>
1058         </tr>
1059         <tr>
1060            <td>&nbsp;</td>
1061        </tr>
1062
1063     </table>
1064 <br style="clear: left" /></div>|;
1065
1066
1067 ##LINET - added fields for contact person
1068   print qq|   
1069 <div id="contacts" class="tabcontent">
1070 <table>
1071     <tr>
1072          <td colspan=3>
1073                 <input type=hidden name=cp_id value=$form->{cp_id}>
1074                 <table>
1075                 $ansprechpartner
1076                 <tr>
1077                   <th align=left nowrap>| . $locale->text('Greeting') . qq|</th>
1078                   <td><input id=cp_greeting name=cp_greeting size=30 maxlength=30 value="$form->{cp_greeting}">&nbsp;
1079                   $select_greeting</td>
1080                 </tr>
1081                 <tr>
1082                   <th align=left nowrap>| . $locale->text('Title') . qq|</th>
1083                   <td><input id=cp_title name=cp_title size=30 maxlength=30 value="$form->{cp_title}">&nbsp;
1084                   $select_title</td>
1085                 </tr>
1086                 <tr>
1087                   <th align=left nowrap>| . $locale->text('Department') . qq|</th>
1088                   <td><input id=cp_abteilung name=cp_abteilung size=30 maxlength=40 value="$form->{cp_abteilung}">&nbsp;
1089                   $select_department</td>
1090                 </tr>
1091                 <tr>
1092                   <th align=left nowrap>|
1093     . $locale->text('Given Name') . qq|</th>
1094                   <td><input id=cp_givenname name=cp_givenname size=30 maxlength=40 value="$form->{cp_givenname}"></td>
1095                 </tr>
1096                 <tr>
1097                   <th align=left nowrap>| . $locale->text('Name') . qq|</th>
1098                   <td><input id=cp_name name=cp_name size=30 maxlength=40 value="$form->{cp_name}"></td>
1099                 </tr>
1100                 <tr>
1101                   <th align=left nowrap>| . $locale->text('Phone1') . qq|</th>
1102                   <td><input id=cp_phone1 name=cp_phone1 size=30 maxlength=30 value="$form->{cp_phone1}"></td>
1103                 </tr>
1104                 <tr>
1105                   <th align=left nowrap>| . $locale->text('Phone2') . qq|</th>
1106                   <td><input id=cp_phone2 name=cp_phone2 size=30 maxlength=30 value="$form->{cp_phone2}"></td>
1107                 </tr>
1108                 <tr>
1109                   <th align=left nowrap>| . $locale->text('Fax') . qq|</th>
1110                   <td><input id=cp_fax name=cp_fax size=30 maxlength=30 value="$form->{cp_fax}"></td>
1111                 </tr>
1112                 <tr>
1113                   <th align=left nowrap>| . $locale->text('Mobile1') . qq|</th>
1114                   <td><input id=cp_mobile1 name=cp_mobile1 size=30 maxlength=30 value="$form->{cp_mobile1}"></td>
1115                 </tr>
1116                 <tr>
1117                   <th align=left nowrap>| . $locale->text('Mobile2') . qq|</th>
1118                   <td><input id=cp_mobile2 name=cp_mobile2 size=30 maxlength=30 value="$form->{cp_mobile2}"></td>
1119                 </tr>
1120                 <tr>
1121                   <th align=left nowrap>| . $locale->text('Sat. Phone') . qq|</th>
1122                   <td><input id=cp_satphone name=cp_satphone size=30 maxlength=30 value="$form->{cp_satphone}"></td>
1123                 </tr>
1124                 <tr>
1125                   <th align=left nowrap>| . $locale->text('Sat. Fax') . qq|</th>
1126                   <td><input id=cp_satfax name=cp_satfax size=30 maxlength=30 value="$form->{cp_satfax}"></td>
1127                 </tr>
1128                 <tr>
1129                   <th align=left nowrap>| . $locale->text('Project') . qq|</th>
1130                   <td><input id=cp_project name=cp_project size=30 maxlength=40 value="$form->{cp_project}"></td>
1131                 </tr>
1132                 <tr>
1133                   <th align=left nowrap>| . $locale->text('E-mail') . qq|</th>
1134                   <td><input id=cp_email name=cp_email size=30 maxlength=40 value="$form->{cp_email}"></td>
1135                 </tr>
1136                 <tr>
1137                   <th align=left nowrap>| . $locale->text('Private Phone') . qq|</th>
1138                   <td><input id=cp_privatphone name=cp_privatphone size=30 maxlength=40 value="$form->{cp_privatphone}"></td>
1139                 </tr>
1140                 <tr>
1141                   <th align=left nowrap>| . $locale->text('Private E-mail') . qq|</th>
1142                   <td><input id=cp_privatemail name=cp_privatemail size=30 maxlength=40 value="$form->{cp_privatemail}"></td>
1143                 </tr>
1144                 <tr>
1145                   <th align=left nowrap>| . $locale->text('Birthday') . qq|</th>
1146                   <td><input id=cp_birthday name=cp_birthday size=30 maxlength=40 value="$form->{cp_birthday}"></td>
1147                 </tr>
1148                 
1149           </table>
1150         </td>
1151         </tr>
1152         <tr height="5"></tr>|;
1153 ##/LINET
1154   print qq|        $bcc
1155         $tax
1156       </table>
1157     </td>
1158   </tr>
1159   <tr>
1160     <td>
1161       
1162 <br style="clear: left" /></div>
1163 <div id="deliveries" class="tabcontent">
1164   <table>
1165     $delivery
1166     <tr>
1167       <th align=left nowrap>| . $locale->text('From') . qq|</th>
1168       <td><input id=from name=from size=10 maxlength=10 value="$form->{from}"></td>
1169       <th align=left nowrap>| . $locale->text('Bis') . qq|</th>
1170       <td><input id=to name=to size=10 maxlength=10 value="$form->{to}"></td>
1171     </tr>       
1172     <tr>
1173      <td colspan=4>
1174       <div id=delivery>
1175       </div>
1176       </td>
1177     </tr>
1178   </table>
1179 <br style="clear: left" /></div>
1180
1181 </div>
1182
1183 |;
1184
1185   $lxdebug->leave_sub();
1186 }
1187
1188 sub form_footer {
1189   $lxdebug->enter_sub();
1190
1191   $label     = ucfirst $form->{db};
1192   $quotation =
1193     ($form->{db} eq 'customer')
1194     ? $locale->text('Save and Quotation')
1195     : $locale->text('Save and RFQ');
1196   $arap =
1197     ($form->{db} eq 'customer')
1198     ? $locale->text('Save and AR Transaction')
1199     : $locale->text('Save and AP Transaction');
1200   if ($vertreter) {
1201     $update_button =
1202       qq|<input class=submit type=submit name=action accesskey="u" value="|
1203       . $locale->text("Update") . qq|">|;
1204   } else {
1205     $update_button = "";
1206   }
1207
1208 ##<input class=submit type=submit name=action value="|.$locale->text("Save and Quotation").qq|">
1209 ##<input class=submit type=submit name=action value="|.$locale->text("Save and RFQ").qq|">
1210 ##<input class=submit type=submit name=action value="|.$locale->text("Save and AR Transaction").qq|">
1211 ##<input class=submit type=submit name=action value="|.$locale->text("Save and AP Transaction").qq|">
1212
1213   print qq|
1214 <input name=id type=hidden id=cvid value=$form->{id}>
1215 <input name=taxaccounts type=hidden value="$form->{taxaccounts}">
1216 <input name=business_save type=hidden value="$form->{selectbusiness}">
1217 <input name=title_save type=hidden value="$form->{title}">
1218
1219 <input type=hidden name=path value=$form->{path}>
1220 <input type=hidden name=login value=$form->{login}>
1221 <input type=hidden name=password value=$form->{password}>
1222
1223 <input type=hidden name=callback value="$form->{callback}">
1224 <input type=hidden name=db id=db value=$form->{db}>
1225
1226
1227
1228 <br>
1229 $update_button
1230 <input class=submit type=submit name=action accesskey="s" value="|
1231     . $locale->text("Save") . qq|">
1232 <input class=submit type=submit name=action accesskey="s" value="|
1233     . $locale->text("Save and Close") . qq|">
1234 <input class=submit type=submit name=action value="$arap">
1235 <input class=submit type=submit name=action value="|
1236     . $locale->text("Save and Invoice") . qq|">
1237 <input class=submit type=submit name=action value="|
1238     . $locale->text("Save and Order") . qq|">
1239 <input class=submit type=submit name=action value="$quotation">
1240 |;
1241
1242   if ($form->{id} && $form->{status} eq 'orphaned') {
1243     print qq|<input class=submit type=submit name=action value="|
1244       . $locale->text('Delete')
1245       . qq|">\n|;
1246   }
1247
1248   if ($form->{menubar}) {
1249     require "$form->{path}/menu.pl";
1250     &menubar;
1251   }
1252
1253   print qq|
1254
1255   </form>
1256 <script type="text/javascript">
1257 //Start Tab Content script for UL with id="maintab" Separate multiple ids each with a comma.
1258 initializetabcontent("maintab")
1259 </script>
1260 </body>
1261 </html>
1262 |;
1263
1264   $lxdebug->leave_sub();
1265 }
1266
1267 sub add_transaction {
1268   $lxdebug->enter_sub();
1269
1270   $form->isblank("name", $locale->text("Name missing!"));
1271   if ($vertreter && $form->{db} eq "customer") {
1272     $form->isblank("salesman_id", $locale->text("Salesman missing!"));
1273   }
1274   &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
1275
1276   $form->{callback} = $form->escape($form->{callback}, 1);
1277   $name = $form->escape("$form->{name}", 1);
1278
1279   $form->{callback} =
1280     "$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}";
1281
1282   $form->redirect;
1283
1284   $lxdebug->leave_sub();
1285 }
1286
1287 sub save_and_ap_transaction {
1288   $lxdebug->enter_sub();
1289
1290   $form->{script} = "ap.pl";
1291   &add_transaction;
1292
1293   $lxdebug->leave_sub();
1294 }
1295
1296 sub save_and_ar_transaction {
1297   $lxdebug->enter_sub();
1298
1299   $form->{script} = "ar.pl";
1300   &add_transaction;
1301
1302   $lxdebug->leave_sub();
1303 }
1304
1305 sub save_and_invoice {
1306   $lxdebug->enter_sub();
1307
1308   $form->{script} = ($form->{db} eq 'customer') ? "is.pl" : "ir.pl";
1309   $form->{type} = "invoice";
1310   &add_transaction;
1311
1312   $lxdebug->leave_sub();
1313 }
1314
1315 sub save_and_rfq {
1316   $lxdebug->enter_sub();
1317
1318   $form->{script} = "oe.pl";
1319   $form->{type}   = "request_quotation";
1320   &add_transaction;
1321
1322   $lxdebug->leave_sub();
1323 }
1324
1325 sub save_and_quotation {
1326   $lxdebug->enter_sub();
1327
1328   $form->{script} = "oe.pl";
1329   $form->{type}   = "sales_quotation";
1330   &add_transaction;
1331
1332   $lxdebug->leave_sub();
1333 }
1334
1335 sub save_and_order {
1336   $lxdebug->enter_sub();
1337
1338   $form->{script} = "oe.pl";
1339   $form->{type}   =
1340     ($form->{db} eq 'customer') ? "sales_order" : "purchase_order";
1341   &add_transaction;
1342
1343   $lxdebug->leave_sub();
1344 }
1345
1346 sub save_and_close {
1347   $lxdebug->enter_sub();
1348
1349   # $locale->text('Customer saved!')
1350   # $locale->text('Vendor saved!')
1351
1352   $msg = ucfirst $form->{db};
1353   $imsg .= " saved!";
1354
1355   $form->isblank("name", $locale->text("Name missing!"));
1356   if ($vertreter && $form->{db} eq "customer") {
1357     $form->isblank("salesman_id", $locale->text("Salesman missing!"));
1358   }
1359   $rc = &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
1360   if ($rc == 3) {
1361     $form->error($locale->text('customernumber not unique!'));
1362   }
1363   $form->redirect($locale->text($msg));
1364
1365   $lxdebug->leave_sub();
1366 }
1367
1368 sub save {
1369   $lxdebug->enter_sub();
1370
1371   # $locale->text('Customer saved!')
1372   # $locale->text('Vendor saved!')
1373
1374   $msg = ucfirst $form->{db};
1375   $imsg .= " saved!";
1376
1377   $form->isblank("name", $locale->text("Name missing!"));
1378   if ($vertreter && $form->{db} eq "customer") {
1379     $form->isblank("salesman_id", $locale->text("Salesman missing!"));
1380   }
1381   print(STDERR "SHIPTO in sub save $form->{shipto_id}\n");
1382   &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
1383
1384   &edit;
1385   exit;
1386   $lxdebug->leave_sub();
1387 }
1388
1389 sub delete {
1390   $lxdebug->enter_sub();
1391
1392   # $locale->text('Customer deleted!')
1393   # $locale->text('Cannot delete customer!')
1394   # $locale->text('Vendor deleted!')
1395   # $locale->text('Cannot delete vendor!')
1396
1397   CT->delete(\%myconfig, \%$form);
1398
1399   $msg = ucfirst $form->{db};
1400   $msg .= " deleted!";
1401   $form->redirect($locale->text($msg));
1402
1403   $msg = "Cannot delete $form->{db}";
1404   $form->error($locale->text($msg));
1405
1406   $lxdebug->leave_sub();
1407 }
1408
1409 sub display {
1410   $lxdebug->enter_sub();
1411
1412   &form_header();
1413   &form_footer();
1414
1415   $lxdebug->leave_sub();
1416 }
1417
1418 sub update {
1419   $lxdebug->enter_sub();
1420
1421   &check_salesman($form->{salesman});
1422
1423   #  $form->get_salesman(\%myconfig, $form->{salesman});
1424   &display();
1425   $lxdebug->leave_sub();
1426 }
1427
1428 sub check_salesman {
1429   $lxdebug->enter_sub();
1430
1431   my ($name) = @_;
1432
1433   my ($new_name, $new_id) = split /--/, $form->{$name};
1434   my $i = 0;
1435
1436   # check name, combine name and id
1437   if ($form->{"oldsalesman"} ne $form->{"salesman"}) {
1438
1439     # return one name or a list of names in $form->{name_list}
1440     if (($i = $form->get_salesman(\%myconfig, $name)) > 1) {
1441       &select_salesman($name);
1442       exit;
1443     }
1444
1445     if ($i == 1) {
1446
1447       # we got one name
1448       $form->{"salesman_id"} = $form->{salesman_list}[0]->{id};
1449       $form->{salesman}      = $form->{salesman_list}[0]->{name};
1450       $form->{"oldsalesman"} = $form->{salesman};
1451
1452     } else {
1453
1454       # name is not on file
1455       # $locale->text('Customer not on file!')
1456       # $locale->text('Vendor not on file!')
1457       $msg = ucfirst $name . " not on file or locked!";
1458       $form->error($locale->text($msg));
1459     }
1460   }
1461
1462   $lxdebug->leave_sub();
1463
1464   return $i;
1465 }
1466
1467 sub select_salesman {
1468   $lxdebug->enter_sub();
1469
1470   my ($table) = @_;
1471
1472   @column_index = qw(ndx name);
1473
1474   $label             = ucfirst $table;
1475   $column_data{ndx}  = qq|<th>&nbsp;</th>|;
1476   $column_data{name} =
1477     qq|<th class=listheading>| . $locale->text($label) . qq|</th>|;
1478
1479   # list items with radio button on a form
1480   $form->header;
1481
1482   $title = $locale->text('Select from one of the names below');
1483
1484   print qq|
1485 <body>
1486
1487 <form method=post action=$form->{script}>
1488
1489 <table width=100%>
1490   <tr>
1491     <th class=listtop>$title</th>
1492   </tr>
1493   <tr space=5></tr>
1494   <tr>
1495     <td>
1496       <table width=100%>
1497         <tr class=listheading>|;
1498
1499   map { print "\n$column_data{$_}" } @column_index;
1500
1501   print qq|
1502         </tr>
1503 |;
1504
1505   my $i = 0;
1506   foreach $ref (@{ $form->{salesman_list} }) {
1507     $checked = ($i++) ? "" : "checked";
1508
1509     $ref->{name} =~ s/\"/&quot;/g;
1510
1511     $column_data{ndx} =
1512       qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
1513     $column_data{name} =
1514       qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
1515
1516     $j++;
1517     $j %= 2;
1518     print qq|
1519         <tr class=listrow$j>|;
1520
1521     map { print "\n$column_data{$_}" } @column_index;
1522
1523     print qq|
1524         </tr>
1525
1526 <input name="new_id_$i" type=hidden value=$ref->{id}>
1527
1528 |;
1529
1530   }
1531
1532   print qq|
1533       </table>
1534     </td>
1535   </tr>
1536   <tr>
1537     <td><hr size=3 noshade></td>
1538   </tr>
1539 </table>
1540
1541 <input name=lastndx type=hidden value=$i>
1542
1543 |;
1544
1545   # delete variables
1546   map { delete $form->{$_} } qw(action name_list header);
1547
1548   # save all other form variables
1549   foreach $key (keys %${form}) {
1550     $form->{$key} =~ s/\"/&quot;/g;
1551     print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
1552   }
1553
1554   print qq|
1555 <input type=hidden name=nextsub value=salesman_selected>
1556
1557 <input type=hidden name=vc value=$table>
1558 <br>
1559 <input class=submit type=submit name=action value="|
1560     . $locale->text('Continue') . qq|">
1561 </form>
1562
1563 </body>
1564 </html>
1565 |;
1566
1567   $lxdebug->leave_sub();
1568 }
1569
1570 sub salesman_selected {
1571   $lxdebug->enter_sub();
1572
1573   # replace the variable with the one checked
1574
1575   # index for new item
1576   $i = $form->{ndx};
1577
1578   $form->{salesman}      = $form->{"new_name_$i"};
1579   $form->{"salesman_id"} = $form->{"new_id_$i"};
1580   $form->{"oldsalesman"} = $form->{salesman};
1581
1582   # delete all the new_ variables
1583   for $i (1 .. $form->{lastndx}) {
1584     map { delete $form->{"new_${_}_$i"} } (id, name);
1585   }
1586
1587   map { delete $form->{$_} } qw(ndx lastndx nextsub);
1588
1589   &update(1);
1590
1591   $lxdebug->leave_sub();
1592 }
1593
1594 sub get_contact {
1595   $lxdebug->enter_sub();
1596
1597   CT->get_contact(\%myconfig, \%$form);
1598
1599   my $q = new CGI;
1600   $result = "$form->{cp_name}";
1601   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);
1602   print $q->header();
1603   print $result;
1604   $lxdebug->leave_sub();
1605
1606 }
1607
1608
1609 sub get_shipto {
1610   $lxdebug->enter_sub();
1611
1612   CT->get_shipto(\%myconfig, \%$form);
1613
1614   my $q = new CGI;
1615   $result = "$form->{shiptoname}";
1616   map { $result .= "__pjx__" . $form->{$_} } qw(shiptodepartment_1 shiptodepartment_2 shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax shiptoemail);
1617   print $q->header();
1618   print $result;
1619   $lxdebug->leave_sub();
1620
1621 }
1622
1623 sub get_delivery {
1624   $lxdebug->enter_sub();
1625
1626   CT->get_delivery(\%myconfig, \%$form );
1627
1628   @column_index =
1629     $form->sort_columns(shiptoname,
1630                         invnumber,
1631                         ordnumber,
1632                         transdate,
1633                         description,
1634                         qty,
1635                         unit);
1636
1637
1638
1639   $column_header{shiptoname} =
1640     qq|<th class=listheading>| . $locale->text('Shipping Address') . qq|</th>|;
1641   $column_header{invnumber} =
1642       qq|<th class=listheading>|. $locale->text('Invoice'). qq|</th>|;
1643   $column_header{ordnumber} =
1644       qq|<th class=listheading>|. $locale->text('Order'). qq|</th>|;
1645   $column_header{transdate} =
1646     qq|<th class=listheading>| . $locale->text('Invdate') . qq|</th>|;
1647   $column_header{description} =
1648     qq|<th class=listheading>| . $locale->text('Description') . qq|</th>|;
1649   $column_header{qty} =
1650     qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
1651   $column_header{unit} =
1652     qq|<th class=listheading>| . $locale->text('Unit') . qq|</th>|;
1653   $result .= qq|
1654
1655 <table width=100%>
1656   <tr>
1657     <td>
1658       <table width=100%>
1659         <tr class=listheading>
1660 |;
1661
1662   map { $result .= "$column_header{$_}\n" } @column_index;
1663
1664   $result .= qq|
1665         </tr>
1666 |;
1667
1668
1669   foreach $ref (@{ $form->{DELIVERY} }) {
1670
1671     if ($ref->{shiptoname} eq $sameshiptoname) {
1672       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
1673       $column_data{shiptoname} = "<td>&nbsp;</td>";
1674     } else {
1675       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
1676     }
1677
1678     $i++;
1679     $i %= 2;
1680     $result .= "
1681         <tr class=listrow$i>
1682 ";
1683
1684     map { $result .= "$column_data{$_}\n" } @column_index;
1685
1686     $result .= qq|
1687         </tr>
1688 |;
1689
1690     $sameshiptoname = $ref->{shiptoname};
1691
1692   }
1693
1694   $result .= qq|
1695       </table>
1696 |;
1697
1698
1699   my $q = new CGI;
1700   print $q->header();
1701   print $result;
1702   $lxdebug->leave_sub();
1703
1704 }
1705
1706 sub continue { &{ $form->{nextsub} } }