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