Überflüssigen Code bzgl. salesman entfernt (wird eh nicht benutzt, wenn Auswahl über...
[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 require "bin/mozilla/common.pl";
46
47 1;
48
49 # end of main
50
51 sub add {
52   $lxdebug->enter_sub();
53
54   $form->{title} = "Add";
55
56   $form->{callback} =
57     "$form->{script}?action=add&db=$form->{db}&path=$form->{path}&login=$form->{login}&password=$form->{password}"
58     unless $form->{callback};
59
60   CT->taxaccounts(\%myconfig, \%$form);
61
62   &form_header;
63   &form_footer;
64
65   $lxdebug->leave_sub();
66 }
67
68 sub search {
69   $lxdebug->enter_sub();
70
71   $label = ucfirst $form->{db};
72   $form->{title} = $locale->text($label . "s");
73
74   if ($form->{db} eq 'vendor') {
75     $gifi = qq|
76                 <td><input name="l_gifi_accno" type=checkbox class=checkbox value=Y> |
77       . $locale->text('GIFI') . qq|</td>
78 |;
79   }
80
81   $form->header;
82
83   print qq|
84 <body>
85
86 <form method=post action=$form->{script}>
87
88 <input type=hidden name=db value=$form->{db}>
89
90 <table width=100%>
91   <tr>
92     <th class=listtop>$form->{title}</th>
93   </tr>
94   <tr height="5"></tr>
95   <tr valign=top>
96     <td>
97       <table>
98         <tr>
99           <th align=right nowrap>| . $locale->text($label . ' Number') . qq|</th>
100           <td><input name=$form->{db}number size=35></td>
101         </tr>
102         <tr>
103           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
104           <td><input name=name size=35></td>
105         </tr>
106         <tr>
107           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
108           <td><input name=contact size=35></td>
109         </tr>
110         <tr>
111           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
112           <td><input name=email size=35></td>
113         </tr>
114         <tr>
115           <td></td>
116           <td><input name=status class=radio type=radio value=all checked>&nbsp;|
117     . $locale->text('All') . qq|
118           <input name=status class=radio type=radio value=orphaned>&nbsp;|
119     . $locale->text('Orphaned') . qq|</td>
120         </tr>
121         <tr>
122           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
123           <td>
124             <table>
125               <tr>
126                 <td><input name="l_id" type=checkbox class=checkbox value=Y> |
127     . $locale->text('ID') . qq|</td>
128                 <td><input name="l_$form->{db}number" type=checkbox class=checkbox value=Y> |
129     . $locale->text($label . ' Number') . qq|</td>
130                 <td><input name="l_name" type=checkbox class=checkbox value=Y checked> |
131     . $locale->text('Company Name') . qq|</td>
132                 <td><input name="l_address" type=checkbox class=checkbox value=Y> |
133     . $locale->text('Address') . qq|</td>
134               </tr>
135               <tr>
136                 <td><input name="l_contact" type=checkbox class=checkbox value=Y checked> |
137     . $locale->text('Contact') . qq|</td>
138                 <td><input name="l_phone" type=checkbox class=checkbox value=Y checked> |
139     . $locale->text('Phone') . qq|</td>
140                 <td><input name="l_fax" type=checkbox class=checkbox value=Y> |
141     . $locale->text('Fax') . qq|</td>
142                 <td><input name="l_email" type=checkbox class=checkbox value=Y checked> |
143     . $locale->text('E-mail') . qq|</td>
144               </tr>
145               <tr>
146                 <td><input name="l_taxnumber" type=checkbox class=checkbox value=Y> |
147     . $locale->text('Tax Number') . qq|</td>
148                 $gifi
149                 <td><input name="l_sic_code" type=checkbox class=checkbox value=Y> |
150     . $locale->text('SIC') . qq|</td>
151                 <td><input name="l_business" type=checkbox class=checkbox value=Y> |
152     . $locale->text('Type of Business') . qq|</td>
153               </tr>
154               <tr>
155                 <td><input name="l_invnumber" type=checkbox class=checkbox value=Y> |
156     . $locale->text('Invoices') . qq|</td>
157                 <td><input name="l_ordnumber" type=checkbox class=checkbox value=Y> |
158     . $locale->text('Orders') . qq|</td>
159                 <td><input name="l_quonumber" type=checkbox class=checkbox value=Y> |
160     . $locale->text('Quotations') . qq|</td>
161               </tr>
162             </table>
163           </td>
164         </tr>
165       </table>
166     </td>
167   </tr>
168   <tr>
169     <td><hr size=3 noshade></td>
170   </tr>
171 </table>
172
173 <input type=hidden name=nextsub value=list_names>
174
175 <input type=hidden name=path value=$form->{path}>
176 <input type=hidden name=login value=$form->{login}>
177 <input type=hidden name=password value=$form->{password}>
178
179 <br>
180 <input type=submit class=submit name=action value="|
181     . $locale->text('Continue') . qq|">
182 </form>
183
184 </body>
185 </html>
186 |;
187   $lxdebug->leave_sub();
188 }
189
190 sub search_delivery {
191   $lxdebug->enter_sub();
192
193   $label = ucfirst $form->{db};
194   $form->{title} = $locale->text($label . "s");
195
196   if ($form->{db} eq 'vendor') {
197     $gifi = qq|
198                 <td><input name="l_gifi_accno" type=checkbox class=checkbox value=Y> |
199       . $locale->text('GIFI') . qq|</td>
200 |;
201   }
202
203   $form->header;
204
205   print qq|
206 <body>
207
208 <form method=post action=$form->{script}>
209
210 <input type=hidden name=db value=$form->{db}>
211
212 <table width=100%>
213   <tr>
214     <th class=listtop>$form->{title}</th>
215   </tr>
216   <tr height="5"></tr>
217   <tr valign=top>
218     <td>
219       <table>
220         <tr>
221           <th align=right nowrap>| . $locale->text($label . ' Number') . qq|</th>
222           <td><input name=$form->{db}number size=35></td>
223         </tr>
224         <tr>
225           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
226           <td><input name=name size=35></td>
227         </tr>
228         <tr>
229           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
230           <td><input name=contact size=35></td>
231         </tr>
232         <tr>
233           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
234           <td><input name=email size=35></td>
235         </tr>
236         <tr>
237           <td></td>
238           <td><input name=status class=radio type=radio value=all checked>&nbsp;|
239     . $locale->text('All') . qq|
240           <input name=status class=radio type=radio value=orphaned>&nbsp;|
241     . $locale->text('Orphaned') . qq|</td>
242         </tr>
243         <tr>
244           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
245           <td>
246             <table>
247               <tr>
248                 <td><input name="l_id" type=checkbox class=checkbox value=Y> |
249     . $locale->text('ID') . qq|</td>
250                 <td><input name="l_$form->{db}number" type=checkbox class=checkbox value=Y> |
251     . $locale->text($label . ' Number') . qq|</td>
252                 <td><input name="l_name" type=checkbox class=checkbox value=Y checked> |
253     . $locale->text('Company Name') . qq|</td>
254                 <td><input name="l_address" type=checkbox class=checkbox value=Y> |
255     . $locale->text('Address') . qq|</td>
256               </tr>
257               <tr>
258                 <td><input name="l_contact" type=checkbox class=checkbox value=Y checked> |
259     . $locale->text('Contact') . qq|</td>
260                 <td><input name="l_phone" type=checkbox class=checkbox value=Y checked> |
261     . $locale->text('Phone') . qq|</td>
262                 <td><input name="l_fax" type=checkbox class=checkbox value=Y> |
263     . $locale->text('Fax') . qq|</td>
264                 <td><input name="l_email" type=checkbox class=checkbox value=Y checked> |
265     . $locale->text('E-mail') . qq|</td>
266               </tr>
267               <tr>
268                 <td><input name="l_taxnumber" type=checkbox class=checkbox value=Y> |
269     . $locale->text('Tax Number') . qq|</td>
270                 $gifi
271                 <td><input name="l_sic_code" type=checkbox class=checkbox value=Y> |
272     . $locale->text('SIC') . qq|</td>
273                 <td><input name="l_business" type=checkbox class=checkbox value=Y> |
274     . $locale->text('Type of Business') . qq|</td>
275               </tr>
276               <tr>
277                 <td><input name="l_invnumber" type=checkbox class=checkbox value=Y> |
278     . $locale->text('Invoices') . qq|</td>
279                 <td><input name="l_ordnumber" type=checkbox class=checkbox value=Y> |
280     . $locale->text('Orders') . qq|</td>
281                 <td><input name="l_quonumber" type=checkbox class=checkbox value=Y> |
282     . $locale->text('Quotations') . qq|</td>
283               </tr>
284             </table>
285           </td>
286         </tr>
287       </table>
288     </td>
289   </tr>
290   <tr>
291     <td><hr size=3 noshade></td>
292   </tr>
293 </table>
294
295 <input type=hidden name=nextsub value=list_names>
296
297 <input type=hidden name=path value=$form->{path}>
298 <input type=hidden name=login value=$form->{login}>
299 <input type=hidden name=password value=$form->{password}>
300
301 <br>
302 <input type=submit class=submit name=action value="|
303     . $locale->text('Continue') . qq|">
304 </form>
305
306 </body>
307 </html>
308 |;
309   $lxdebug->leave_sub();
310 }
311
312 sub list_names {
313   $lxdebug->enter_sub();
314
315   CT->search(\%myconfig, \%$form);
316
317   $callback =
318     "$form->{script}?action=list_names&db=$form->{db}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}";
319   $href = $callback;
320
321   @columns =
322     $form->sort_columns(id, name,
323                         "$form->{db}number", address,
324                         contact,             phone,
325                         fax,                 email,
326                         taxnumber,           gifi_accno,
327                         sic_code,            business,
328                         invnumber,           ordnumber,
329                         quonumber);
330
331   foreach $item (@columns) {
332     if ($form->{"l_$item"} eq "Y") {
333       push @column_index, $item;
334
335       # add column to href and callback
336       $callback .= "&l_$item=Y";
337       $href     .= "&l_$item=Y";
338     }
339   }
340   $number =
341     ($form->{db} eq "customer")
342     ? $locale->text('Customer Number')
343     : $locale->text('Vendor Number');
344
345   if ($form->{status} eq 'all') {
346     $option = $locale->text('All');
347   }
348   if ($form->{status} eq 'orphaned') {
349     $option .= $locale->text('Orphaned');
350   }
351   if ($form->{name}) {
352     $callback .= "&name=" . $form->escape($form->{name}, 1);
353     $href .= "&name=" . $form->escape($form->{name});
354     $option .= "\n<br>" . $locale->text('Name') . " : $form->{name}";
355   }
356   if ($form->{contact}) {
357     $callback .= "&contact=" . $form->escape($form->{contact}, 1);
358     $href .= "&contact=" . $form->escape($form->{contact});
359     $option .= "\n<br>" . $locale->text('Contact') . " : $form->{contact}";
360   }
361   if ($form->{"$form->{db}number"}) {
362     $callback .=
363       qq|&$form->{db}number=| . $form->escape($form->{"$form->{db}number"}, 1);
364     $href .=
365       "&$form->{db}number=" . $form->escape($form->{"$form->{db}number"});
366     $option .=
367       "\n<br>" . $locale->text('Number') . qq| : $form->{"$form->{db}number"}|;
368   }
369   if ($form->{email}) {
370     $callback .= "&email=" . $form->escape($form->{email}, 1);
371     $href .= "&email=" . $form->escape($form->{email});
372     $option .= "\n<br>" . $locale->text('E-mail') . " : $form->{email}";
373   }
374
375   $form->{callback} = "$callback&sort=$form->{sort}";
376   $callback = $form->escape($form->{callback});
377
378   $column_header{id} =
379     qq|<th class=listheading>| . $locale->text('ID') . qq|</th>|;
380   $column_header{"$form->{db}number"} =
381     qq|<th><a class=listheading href=$href&sort=$form->{db}number>$number</a></th>|;
382   $column_header{name} =
383       qq|<th><a class=listheading href=$href&sort=name>|
384     . $locale->text('Name')
385     . qq|</a></th>|;
386   $column_header{address} =
387       qq|<th><a class=listheading href=$href&sort=address>|
388     . $locale->text('Address')
389     . qq|</a></th>|;
390   $column_header{contact} =
391       qq|<th><a class=listheading href=$href&sort=contact>|
392     . $locale->text('Contact')
393     . qq|</a></th>|;
394   $column_header{phone} =
395       qq|<th><a class=listheading href=$href&sort=phone>|
396     . $locale->text('Phone')
397     . qq|</a></th>|;
398   $column_header{fax} =
399       qq|<th><a class=listheading href=$href&sort=fax>|
400     . $locale->text('Fax')
401     . qq|</a></th>|;
402   $column_header{email} =
403       qq|<th><a class=listheading href=$href&sort=email>|
404     . $locale->text('E-mail')
405     . qq|</a></th>|;
406   $column_header{cc} =
407       qq|<th><a class=listheading href=$href&sort=cc>|
408     . $locale->text('Cc')
409     . qq|</a></th>|;
410
411   $column_header{taxnumber} =
412       qq|<th><a class=listheading href=$href&sort=taxnumber>|
413     . $locale->text('Tax Number')
414     . qq|</a></th>|;
415   $column_header{gifi_accno} =
416       qq|<th><a class=listheading href=$href&sort=gifi_accno>|
417     . $locale->text('GIFI')
418     . qq|</a></th>|;
419   $column_header{sic_code} =
420       qq|<th><a class=listheading href=$href&sort=sic_code>|
421     . $locale->text('SIC')
422     . qq|</a></th>|;
423   $column_header{business} =
424       qq|<th><a class=listheading href=$href&sort=business>|
425     . $locale->text('Type of Business')
426     . qq|</a></th>|;
427
428   $column_header{invnumber} =
429       qq|<th><a class=listheading href=$href&sort=invnumber>|
430     . $locale->text('Invoice')
431     . qq|</a></th>|;
432   $column_header{ordnumber} =
433       qq|<th><a class=listheading href=$href&sort=ordnumber>|
434     . $locale->text('Order')
435     . qq|</a></th>|;
436   $column_header{quonumber} =
437       qq|<th><a class=listheading href=$href&sort=quonumber>|
438     . $locale->text('Quotation')
439     . qq|</a></th>|;
440
441   $label = ucfirst $form->{db} . "s";
442   $form->{title} = $locale->text($label);
443
444   $form->header;
445
446   print qq|
447 <body>
448
449 <table width=100%>
450   <tr>
451     <th class=listtop>$form->{title}</th>
452   </tr>
453   <tr height="5"></tr>
454   <tr>
455     <td>$option</td>
456   </tr>
457   <tr>
458     <td>
459       <table width=100%>
460         <tr class=listheading>
461 |;
462
463   map { print "$column_header{$_}\n" } @column_index;
464
465   print qq|
466         </tr>
467 |;
468
469   $ordertype = ($form->{db} eq 'customer') ? 'sales_order' : 'purchase_order';
470   $quotationtype =
471     ($form->{db} eq 'customer') ? 'sales_quotation' : 'request_quotation';
472
473   foreach $ref (@{ $form->{CT} }) {
474
475     if ($ref->{id} eq $sameid) {
476       map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
477     } else {
478       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
479
480       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
481         (invnumber, ordnumber, quonumber);
482
483       $column_data{name} =
484         "<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>";
485
486       if ($ref->{email}) {
487         $email = $ref->{email};
488         $email =~ s/</\&lt;/;
489         $email =~ s/>/\&gt;/;
490
491         $column_data{email} =
492           qq|<td><a href="mailto:$ref->{email}">$email</a></td>|;
493       }
494
495     }
496
497     if ($ref->{formtype} eq 'invoice') {
498       $column_data{invnumber} =
499         "<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>";
500     }
501
502     if ($ref->{formtype} eq 'order') {
503       $column_data{ordnumber} =
504         "<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>";
505     }
506
507     if ($ref->{formtype} eq 'quotation') {
508       $column_data{quonumber} =
509         "<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>";
510     }
511
512     $i++;
513     $i %= 2;
514     print "
515         <tr class=listrow$i>
516 ";
517
518     map { print "$column_data{$_}\n" } @column_index;
519
520     print qq|
521         </tr>
522 |;
523
524     $sameid = $ref->{id};
525
526   }
527
528   print qq|
529       </table>
530     </td>
531   </tr>
532   <tr>
533     <td><hr size=3 noshade></td>
534   </tr>
535 </table>
536
537 <br>
538 <form method=post action=$form->{script}>
539
540 <input name=callback type=hidden value="$form->{callback}">
541 <input name=db type=hidden value=$form->{db}>
542
543 <input type=hidden name=path value=$form->{path}>
544 <input type=hidden name=login value=$form->{login}>
545 <input type=hidden name=password value=$form->{password}>
546
547 <input class=submit type=submit name=action value="|
548     . $locale->text('Add') . qq|">
549
550   </form>
551
552 </body>
553 </html>
554 |;
555
556   $lxdebug->leave_sub();
557 }
558
559 sub edit {
560   $lxdebug->enter_sub();
561
562   # show history button
563   $form->{javascript} = qq|<script type=text/javascript src=js/show_history.js></script>|;
564   #/show hhistory button
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->get_lists("employees" => "ALL_SALESMEN");
589
590   $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
591   $form->{creditlimit} =
592     $form->format_amount(\%myconfig, $form->{creditlimit}, 0);
593   $form->{discount} = $form->format_amount(\%myconfig, $form->{discount});
594
595   if ($myconfig{role} eq 'admin') {
596     $bcc = qq|
597         <tr>
598           <th align=right nowrap>| . $locale->text('Bcc') . qq|</th>
599           <td><input name=bcc size=35 value="$form->{bcc}"></td>
600         </tr>
601 |;
602   }
603   $form->{obsolete} = "checked" if $form->{obsolete};
604
605   $lang = qq|<option value=""></option>|;
606   foreach $item (@{ $form->{languages} }) {
607     if ($form->{language_id} eq $item->{id}) {
608       $lang .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
609     } else {
610       $lang .= qq|<option value="$item->{id}">$item->{description}</option>|;
611     }
612   }
613
614   $payment = qq|<option value=""></option>|;
615   foreach $item (@{ $form->{payment_terms} }) {
616     if ($form->{payment_id} eq $item->{id}) {
617       $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
618     } else {
619       $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
620     }
621   }
622
623   if (!$form->{id}) {
624     if ($form->{db} eq "customer") {
625       $form->{taxzone_id} = 0;
626     } else {
627       $form->{taxzone_id} = 0;
628     }
629   }
630
631   if (@{ $form->{TAXZONE} }) {
632     foreach $item (@{ $form->{TAXZONE} }) {
633       if ($item->{id} == $form->{taxzone_id}) {
634         $form->{selecttaxzone} .=
635           "<option value=$item->{id} selected>$item->{description}\n";
636       } else {
637         $form->{selecttaxzone} .=
638           "<option value=$item->{id}>$item->{description}\n";
639       }
640
641     }
642   }
643
644   $taxzone = qq|
645                 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
646                 <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
647                 <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
648 |;
649
650   $get_contact_url =
651     "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=get_contact";
652
653   my $pjx = new CGI::Ajax( 'get_contact' => $get_contact_url );
654   $form->{selectcontact} = "<option value=0></option>";
655   if (@{ $form->{CONTACTS} }) {
656     foreach $item (@{ $form->{CONTACTS} }) {
657       if ($item->{cp_id} == $form->{cp_id}) {
658         $form->{selectcontact} .=
659           qq|<option value=$item->{cp_id} selected>$item->{cp_name}</option>\n|;
660       } else {
661         $form->{selectcontact} .=
662           qq|<option value=$item->{cp_id}>$item->{cp_name}</option>\n|;
663       }
664
665     }
666   }
667   push(@ { $form->{AJAX} }, $pjx);
668   $ansprechpartner = qq|
669               <tr>
670                 <th align=right>| . $locale->text('Ansprechpartner') . qq|</th>
671                 <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>
672                 <input type=hidden name=selectcontact value="$form->{selectcontact}">
673               </tr>|;
674   $get_shipto_url =
675     "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=get_shipto";
676
677   my $pjy = new CGI::Ajax( 'get_shipto' => $get_shipto_url );
678   $form->{selectshipto} = "<option value=0></option>";
679   $form->{selectshipto} .= "<option value=0>Alle</option>";
680   if (@{ $form->{SHIPTO} }) {
681     foreach $item (@{ $form->{SHIPTO} }) {
682       if ($item->{shipto_id} == $form->{shipto_id}) {
683         $form->{selectshipto} .=
684           "<option value=$item->{shipto_id} selected>$item->{shiptoname} $item->{shiptodepartment_1}\n";
685       } else {
686         $form->{selectshipto} .=
687           "<option value=$item->{shipto_id}>$item->{shiptoname} $item->{shiptodepartment_1}\n";
688       }
689
690     }
691   }
692   push(@ { $form->{AJAX} }, $pjy);
693
694   $shipto = qq|
695               <tr>
696                 <th align=right>| . $locale->text('Shipping Address') . qq|</th>
697                 <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>
698                 <input type=hidden name=selectshipto value="$form->{selectshipto}">
699               </tr>|;
700
701
702   $get_delivery_url =
703     "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=get_delivery";
704
705   my $pjz = new CGI::Ajax( 'get_delivery' => $get_delivery_url );
706
707   push(@ { $form->{AJAX} }, $pjz);
708
709   $delivery = qq|
710               <tr>
711                 <th align=right>| . $locale->text('Shipping Address') . qq|</th>
712                 <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>
713               </tr>|;
714
715   foreach $item (split / /, $form->{taxaccounts}) {
716     if (($form->{tax}{$item}{taxable}) || !($form->{id})) {
717       $taxable .=
718         qq| <input name="tax_$item" value=1 class=checkbox type=checkbox checked>&nbsp;<b>$form->{tax}{$item}{description}</b>|;
719     } else {
720       $taxable .=
721         qq| <input name="tax_$item" value=1 class=checkbox type=checkbox>&nbsp;<b>$form->{tax}{$item}{description}</b>|;
722     }
723   }
724
725 ##LINET
726   $taxable = "";
727
728   if ($taxable) {
729     $tax = qq|
730   <tr>
731     <th align=right>| . $locale->text('Taxable') . qq|</th>
732     <td colspan=2>
733       <table>
734         <tr>
735           <td>$taxable</td>
736           <td><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
737           <th align=left>| . $locale->text('Tax Included') . qq|</th>
738         </tr>
739       </table>
740     </td>
741   </tr>
742 |;
743   }
744   $form->{selectbusiness} = qq|<option>\n|;
745   map {
746     $form->{selectbusiness} .=
747       qq|<option value=$_->{id}>$_->{description}\n|
748   } @{ $form->{all_business} };
749   if ($form->{business_save}) {
750     $form->{selectbusiness} = $form->{business_save};
751   }
752   $form->{selectbusiness} =~
753     s/<option value=$form->{business}>/<option value=$form->{business} selected>/;
754
755   $label = ucfirst $form->{db};
756   if ($form->{title} eq "Edit") {
757     $form->{title} = $locale->text("$form->{title} $label") . " $form->{name}";
758   } else  {
759     $form->{title} = $locale->text("$form->{title} $label");
760   }
761   if ($form->{title_save}) {
762     $form->{title} = $form->{title_save};
763   }
764   if ($form->{db} eq 'vendor') {
765     $customer = qq|
766            <th align=right>| . $locale->text('Kundennummer') . qq|</th>
767            <td><input name=v_customer_id size=10 tabindex=18 maxlength=35 value="$form->{v_customer_id}"></td>
768 |;
769   }
770
771   if ($form->{db} eq 'customer') {
772
773     $customer = qq|
774            <th align=right>| . $locale->text('KNr. beim Kunden') . qq|</th>
775            <td><input name=c_vendor_id size=10 tabindex=18 maxlength=35 value="$form->{c_vendor_id}"></td>
776 |;
777   }
778
779   $business = qq|
780           <th align=right>| . $locale->text('Type of Business') . qq|</th>
781           <td><select name=business tabindex=22>$form->{selectbusiness}</select></td>
782       |;
783
784   $salesman = "";
785
786   if ($form->{db} eq "customer") {
787     my (@salesman_values, %salesman_labels);
788     push(@salesman_values, undef);
789     foreach my $item (@{ $form->{ALL_SALESMEN} }) {
790       push(@salesman_values, $item->{id});
791       $salesman_labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
792     }
793
794     $salesman =
795       qq| <th align="right">| . $locale->text('Salesman') . qq|</th>
796           <td>| .
797       NTI($cgi->popup_menu('-name' => 'salesman_id', '-default' => $form->{salesman_id},
798                            '-values' => \@salesman_values, '-labels' => \%salesman_labels))
799       . qq|</td>|;
800   }
801
802 ## LINET: Create a drop-down box with all prior titles and greetings.
803   CT->query_titles_and_greetings(\%myconfig, \%$form);
804
805   $select_title = qq|&nbsp;<select name=selected_cp_title><option></option>|;
806   map({ $select_title .= qq|<option>$_</option>|; } @{ $form->{TITLES} });
807   $select_title .= qq|</select>|;
808
809   $select_greeting =
810     qq|&nbsp;<select name=selected_cp_greeting><option></option>|;
811   map(
812      { $select_greeting .= qq|<option>$_</option>|; } @{ $form->{GREETINGS} });
813   $select_greeting .= qq|</select>|;
814
815   $select_company_greeting =
816     qq|&nbsp;<select name=selected_company_greeting><option></option>|;
817   map(
818      { $select_company_greeting .= qq|<option>$_</option>|; } @{ $form->{COMPANY_GREETINGS} });
819   $select_company_greeting .= qq|</select>|;
820
821   $select_department =
822     qq|&nbsp;<select name=selected_cp_abteilung><option></option>|;
823   map(
824      { $select_department .= qq|<option>$_</option>|; } @{ $form->{DEPARTMENT} });
825   $select_department .= qq|</select>|;
826 ## /LINET
827
828   if ($form->{db} eq 'customer') {
829
830     #get pricegroup and form it
831     $form->get_pricegroup(\%myconfig, { all => 1 });
832
833     $form->{pricegroup}    = "$form->{klass}";
834     $form->{pricegroup_id} = "$form->{klass}";
835
836     if (@{ $form->{all_pricegroup} }) {
837
838       $form->{selectpricegroup} = qq|<option>\n|;
839       map {
840         $form->{selectpricegroup} .=
841           qq|<option value="$_->{id}">$_->{pricegroup}\n|
842       } @{ $form->{all_pricegroup} };
843     }
844
845     if ($form->{selectpricegroup}) {
846       $form->{selectpricegroup} = $form->unescape($form->{selectpricegroup});
847
848       $pricegroup =
849         qq|<input type=hidden name=selectpricegroup value="|
850         . $form->escape($form->{selectpricegroup}, 1) . qq|">|;
851
852       $form->{selectpricegroup} =~
853         s/(<option value="\Q$form->{klass}\E")/$1 selected/;
854
855       $pricegroup .=
856         qq|<select name=klass tabindex=24>$form->{selectpricegroup}</select>|;
857
858     }
859   }
860
861   # $locale->text('Customer Number')
862   # $locale->text('Vendor Number')
863   $form->{fokus} = "ct.greeting";
864   $form->{jsscript} = 1;
865   $form->header;
866
867   print qq|
868 <body onLoad="fokus()">
869 <table width=100%>
870   <tr>
871     <th class=listtop>$form->{title}</th>
872   </tr>
873 </table>
874
875
876 <form method=post name="ct" action=$form->{script} onKeyUp="highlight(event)" onClick="highlight(event)">
877
878
879
880 <ul id="maintab" class="shadetabs">
881 <li class="selected"><a href="#" rel="billing">|
882     . $locale->text('Billing Address') . qq|</a></li>
883 <li><a href="#" rel="shipto">|
884     . $locale->text('Shipping Address') . qq|</a></li>
885 <li><a href="#" rel="contacts">Ansprechpartner</a></li>
886 <li><a href="#" rel="deliveries">|
887     . $locale->text('Lieferungen') . qq|</a></li>
888
889 </ul>
890
891 <div class="tabcontentstyle">
892
893 <div id="billing" class="tabcontent">
894
895       <table width=100%>
896         <tr height="5"></tr>
897         <tr>
898           <th align=right nowrap>| . $locale->text($label . ' Number') . qq|</th>
899           <td><input name="$form->{db}number" size=35 maxlength=35 value="$form->{"$form->{db}number"}"></td>
900         </tr>
901         <tr>
902           <th align=right nowrap>| . $locale->text('Greeting') . qq|</th>
903           <td><input id=greeting name=greeting size=30 maxlength=30 value="$form->{greeting}">&nbsp;
904           $select_company_greeting</td>
905         </tr>
906         <tr>
907           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
908           <td><input name=name size=35 maxlength=75 value="$form->{name}"></td>
909         </tr>
910         <tr>
911           <th align=right nowrap>| . $locale->text('Abteilung') . qq|</th>
912           <td><input name=department_1 size=16 maxlength=75 value="$form->{department_1}">
913           <input name=department_2 size=16 maxlength=75 value="$form->{department_2}"></td>
914         </tr>
915         <tr>
916           <th align=right nowrap>| . $locale->text('Street') . qq|</th>
917           <td><input name=street size=35 maxlength=75 value="$form->{street}"></td>
918         </tr>
919         <tr>
920           <th align=right nowrap>|
921     . $locale->text('Zipcode') . "/" . $locale->text('City') . qq|</th>
922           <td><input name=zipcode size=5 maxlength=10 value="$form->{zipcode}">
923           <input name=city size=30 maxlength=75 value="$form->{city}"></td>
924         </tr>
925         <tr>
926           <th align=right nowrap>| . $locale->text('Country') . qq|</th>
927           <td><input name=country size=35 maxlength=75 value="$form->{country}"></td>
928         </tr>
929         <tr>
930           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
931           <td><input name=contact size=28 maxlength=75 value="$form->{contact}"></td>
932         </tr>
933         <tr>
934           <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
935           <td><input name=phone size=30 maxlength=30 value="$form->{phone}"></td>
936         </tr>
937         <tr>
938           <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
939           <td><input name=fax size=30 maxlength=30 value="$form->{fax}"></td>
940         </tr>
941         <tr>
942           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
943           <td><input name=email size=45 value="$form->{email}"></td>
944         </tr>
945         <tr>
946           <th align=right nowrap>| . $locale->text('Homepage') . qq|</th>
947           <td><input name=homepage size=45 value="$form->{homepage}"></td>
948         </tr>
949 </table>
950 <table>
951         <tr>
952           <th align=right>| . $locale->text('Credit Limit') . qq|</th>
953           <td><input name=creditlimit size=9 value="$form->{creditlimit}"></td>
954           <input type="hidden" name="terms" value="$form->{terms}">
955           <th align=right>| . $locale->text('Payment Terms') . qq|</th>
956           <td><select name=payment_id>$payment</select></td>
957           <th align=right>| . $locale->text('Discount') . qq|</th>
958           <td><input name=discount size=4 value="$form->{discount}">
959           %</td>
960         </tr>
961         <tr>
962           <th align=right>| . $locale->text('Tax Number / SSN') . qq|</th>
963           <td><input name=taxnumber size=20 value="$form->{taxnumber}"></td>
964           <th align=right>| . $locale->text('USt-IdNr.') . qq|</th>
965           <td><input name="ustid" maxlength="14" size="20" value="$form->{ustid}"></td>
966           $customer
967         </tr>
968         <tr>
969           <th align=right>| . $locale->text('Account Number') . qq|</th>
970           <td><input name=account_number size=10 value="$form->{account_number}"></td>
971           <th align=right>| . $locale->text('Bank Code Number') . qq|</th>
972           <td><input name=bank_code size=10 value="$form->{bank_code}"></td>
973           <th align=right>| . $locale->text('Bank') . qq|</th>
974           <td><input name=bank size=30 value="$form->{bank}"></td>
975         </tr>
976         <tr>
977           $business
978           <th align=right>| . $locale->text('Language') . qq|</th>
979           <td><select name=language_id tabindex=23>$lang
980                           </select></td>|;
981
982   if ($form->{db} eq 'customer') {
983
984     print qq|
985           <th align=right>| . $locale->text('Preisklasse') . qq|</th>
986           <td>$pricegroup</td>|;
987   }
988   print qq|        </tr>
989         <tr>
990           <td align=right>| . $locale->text('Obsolete') . qq|</td>
991           <td><input name=obsolete class=checkbox type=checkbox value=1 $form->{obsolete}></td>
992         </tr>
993         <tr>
994           $taxzone
995           $salesman
996         </tr>
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}">
1169         <input type="button" name="fromB" id="trigger_from" value="?"></td>
1170       <th align=left nowrap>| . $locale->text('To (time)') . qq|</th>
1171       <td><input id=to name=to size=10 maxlength=10 value="$form->{to}">
1172         <input type="button" name="toB" id="trigger_to" value="?"></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 | . $form->write_trigger(\%myconfig, 2, "fromB", "BL", "trigger_from",
1186                          "toB", "BL", "trigger_to");
1187
1188   $lxdebug->leave_sub();
1189 }
1190
1191 sub form_footer {
1192   $lxdebug->enter_sub();
1193
1194   $label     = ucfirst $form->{db};
1195   $quotation =
1196     ($form->{db} eq 'customer')
1197     ? $locale->text('Save and Quotation')
1198     : $locale->text('Save and RFQ');
1199   $arap =
1200     ($form->{db} eq 'customer')
1201     ? $locale->text('Save and AR Transaction')
1202     : $locale->text('Save and AP Transaction');
1203
1204 ##<input class=submit type=submit name=action value="|.$locale->text("Save and Quotation").qq|">
1205 ##<input class=submit type=submit name=action value="|.$locale->text("Save and RFQ").qq|">
1206 ##<input class=submit type=submit name=action value="|.$locale->text("Save and AR Transaction").qq|">
1207 ##<input class=submit type=submit name=action value="|.$locale->text("Save and AP Transaction").qq|">
1208
1209   print qq|
1210 <input name=id type=hidden id=cvid value=$form->{id}>
1211 <input name=taxaccounts type=hidden value="$form->{taxaccounts}">
1212 <input name=business_save type=hidden value="$form->{selectbusiness}">
1213 <input name=title_save type=hidden value="$form->{title}">
1214
1215 <input type=hidden name=path value=$form->{path}>
1216 <input type=hidden name=login value=$form->{login}>
1217 <input type=hidden name=password value=$form->{password}>
1218
1219 <input type=hidden name=callback value="$form->{callback}">
1220 <input type=hidden name=db id=db value=$form->{db}>
1221
1222
1223
1224 <br>
1225 <input class=submit type=submit name=action accesskey="s" value="|
1226     . $locale->text("Save") . qq|">
1227 <input class=submit type=submit name=action accesskey="s" value="|
1228     . $locale->text("Save and Close") . qq|">
1229 <input class=submit type=submit name=action value="$arap">
1230 <input class=submit type=submit name=action value="|
1231     . $locale->text("Save and Invoice") . qq|">
1232 <input class=submit type=submit name=action value="|
1233     . $locale->text("Save and Order") . qq|">
1234 <input class=submit type=submit name=action value="$quotation">
1235 |;
1236
1237   if ($form->{id} && $form->{status} eq 'orphaned') {
1238     print qq|<input class=submit type=submit name=action value="|
1239       . $locale->text('Delete')
1240       . qq|">\n|;
1241   }
1242
1243   # button for saving history
1244   if($form->{id} ne "") {
1245     print qq|
1246           <input type=button class=submit onclick=set_history_window(|
1247           . $form->{id} 
1248           . qq|); name=history id=history value=|
1249           . $locale->text('history') 
1250           . qq|>|;
1251   }
1252   # /button for saving history
1253
1254   print qq|
1255
1256   </form>
1257 <script type="text/javascript">
1258 //Start Tab Content script for UL with id="maintab" Separate multiple ids each with a comma.
1259 initializetabcontent("maintab")
1260 </script>
1261 </body>
1262 </html>
1263 |;
1264
1265   $lxdebug->leave_sub();
1266 }
1267
1268 sub add_transaction {
1269   $lxdebug->enter_sub();
1270
1271 #  # saving the history
1272 #  if(!exists $form->{addition}) {
1273 #       $form->{addition} = "ADD TRANSACTION";
1274 #       $form->save_history($form->dbconnect(\%myconfig));
1275 #  }
1276 #  # /saving the history
1277   
1278   $form->isblank("name", $locale->text("Name missing!"));
1279   &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
1280
1281   $form->{callback} = $form->escape($form->{callback}, 1);
1282   $name = $form->escape("$form->{name}", 1);
1283
1284   $form->{callback} =
1285     "$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}";
1286   $form->redirect;
1287
1288   $lxdebug->leave_sub();
1289 }
1290
1291 sub save_and_ap_transaction {
1292   $lxdebug->enter_sub();
1293
1294   $form->{script} = "ap.pl";
1295   # saving the history
1296   if(!exists $form->{addition}) {
1297         $form->{addition} = "SAVED";
1298         $form->save_history($form->dbconnect(\%myconfig));
1299   }
1300   # /saving the history
1301   &add_transaction;
1302   $lxdebug->leave_sub();
1303 }
1304
1305 sub save_and_ar_transaction {
1306   $lxdebug->enter_sub();
1307
1308   $form->{script} = "ar.pl";
1309   # saving the history
1310   if(!exists $form->{addition}) {
1311         $form->{addition} = "SAVED";
1312         $form->save_history($form->dbconnect(\%myconfig));
1313   }
1314   # /saving the history
1315   &add_transaction;
1316   $lxdebug->leave_sub();
1317 }
1318
1319 sub save_and_invoice {
1320   $lxdebug->enter_sub();
1321
1322   $form->{script} = ($form->{db} eq 'customer') ? "is.pl" : "ir.pl";
1323   $form->{type} = "invoice";
1324   # saving the history
1325   if(!exists $form->{addition}) {
1326         $form->{addition} = "SAVED";
1327         $form->save_history($form->dbconnect(\%myconfig));
1328   }
1329   # /saving the history
1330   &add_transaction;
1331   $lxdebug->leave_sub();
1332 }
1333
1334 sub save_and_rfq {
1335   $lxdebug->enter_sub();
1336
1337   $form->{script} = "oe.pl";
1338   $form->{type}   = "request_quotation";
1339   # saving the history
1340   if(!exists $form->{addition}) {
1341         $form->{addition} = "SAVED";
1342         $form->save_history($form->dbconnect(\%myconfig));
1343   }
1344   # /saving the history
1345   &add_transaction;
1346   $lxdebug->leave_sub();
1347 }
1348
1349 sub save_and_quotation {
1350   $lxdebug->enter_sub();
1351
1352   $form->{script} = "oe.pl";
1353   $form->{type}   = "sales_quotation";
1354   # saving the history
1355   if(!exists $form->{addition}) {
1356         $form->{addition} = "SAVED";
1357         $form->save_history($form->dbconnect(\%myconfig));
1358   }
1359   # /saving the history
1360   &add_transaction;
1361   $lxdebug->leave_sub();
1362 }
1363
1364 sub save_and_order {
1365   $lxdebug->enter_sub();
1366
1367   $form->{script} = "oe.pl";
1368   $form->{type}   =
1369     ($form->{db} eq 'customer') ? "sales_order" : "purchase_order";
1370   # saving the history
1371   if(!exists $form->{addition}) {
1372         $form->{addition} = "SAVED";
1373         $form->save_history($form->dbconnect(\%myconfig));
1374   }
1375   # /saving the history
1376   &add_transaction;
1377   $lxdebug->leave_sub();
1378 }
1379
1380 sub save_and_close {
1381   $lxdebug->enter_sub();
1382
1383   # $locale->text('Customer saved!')
1384   # $locale->text('Vendor saved!')
1385
1386   $msg = ucfirst $form->{db};
1387   $imsg .= " saved!";
1388
1389   $form->isblank("name", $locale->text("Name missing!"));
1390   $rc = &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
1391   if ($rc == 3) {
1392     $form->error($locale->text('customernumber not unique!'));
1393   }
1394   # saving the history
1395   if(!exists $form->{addition}) {
1396         $form->{addition} = "SAVED";
1397         $form->save_history($form->dbconnect(\%myconfig));
1398   }
1399   # /saving the history
1400   $form->redirect($locale->text($msg));
1401
1402   $lxdebug->leave_sub();
1403 }
1404
1405 sub save {
1406   $lxdebug->enter_sub();
1407
1408   # $locale->text('Customer saved!')
1409   # $locale->text('Vendor saved!')
1410
1411   $msg = ucfirst $form->{db};
1412   $imsg .= " saved!";
1413
1414   $form->isblank("name", $locale->text("Name missing!"));
1415
1416   my $res = &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
1417
1418   if (3 == $res) {
1419     if ($form->{"db"} eq "customer") {
1420       $form->error($locale->text('This customer number is already in use.'));
1421     } else {
1422       $form->error($locale->text('This vendor number is already in use.'));
1423     }
1424   }
1425   # saving the history
1426   if(!exists $form->{addition}) {
1427         $form->{addition} = "SAVED";
1428         $form->save_history($form->dbconnect(\%myconfig));
1429   }
1430   # /saving the history
1431   &edit;
1432   exit;
1433   $lxdebug->leave_sub();
1434 }
1435
1436 sub delete {
1437   $lxdebug->enter_sub();
1438
1439   # $locale->text('Customer deleted!')
1440   # $locale->text('Cannot delete customer!')
1441   # $locale->text('Vendor deleted!')
1442   # $locale->text('Cannot delete vendor!')
1443
1444   CT->delete(\%myconfig, \%$form);
1445
1446   $msg = ucfirst $form->{db};
1447   $msg .= " deleted!";
1448   # saving the history
1449   if(!exists $form->{addition}) {
1450         $form->{addition} = "DELETED";
1451         $form->save_history($form->dbconnect(\%myconfig));
1452   }
1453   # /saving the history 
1454   $form->redirect($locale->text($msg));
1455
1456   $msg = "Cannot delete $form->{db}";
1457   $form->error($locale->text($msg));
1458
1459   $lxdebug->leave_sub();
1460 }
1461
1462 sub display {
1463   $lxdebug->enter_sub();
1464
1465   &form_header();
1466   &form_footer();
1467
1468   $lxdebug->leave_sub();
1469 }
1470
1471 sub update {
1472   $lxdebug->enter_sub();
1473
1474   &display();
1475   $lxdebug->leave_sub();
1476 }
1477
1478 sub get_contact {
1479   $lxdebug->enter_sub();
1480
1481   CT->get_contact(\%myconfig, \%$form);
1482
1483   my $q = new CGI;
1484   $result = "$form->{cp_name}";
1485   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);
1486   print $q->header();
1487   print $result;
1488   $lxdebug->leave_sub();
1489
1490 }
1491
1492 sub get_shipto {
1493   $lxdebug->enter_sub();
1494
1495   CT->get_shipto(\%myconfig, \%$form);
1496
1497   my $q = new CGI;
1498   $result = "$form->{shiptoname}";
1499   map { $result .= "__pjx__" . $form->{$_} } qw(shiptodepartment_1 shiptodepartment_2 shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax shiptoemail);
1500   print $q->header();
1501   print $result;
1502   $lxdebug->leave_sub();
1503
1504 }
1505
1506 sub get_delivery {
1507   $lxdebug->enter_sub();
1508
1509   CT->get_delivery(\%myconfig, \%$form );
1510
1511   @column_index =
1512     $form->sort_columns(shiptoname,
1513                         invnumber,
1514                         ordnumber,
1515                         transdate,
1516                         description,
1517                         qty,
1518                         unit);
1519
1520
1521
1522   $column_header{shiptoname} =
1523     qq|<th class=listheading>| . $locale->text('Shipping Address') . qq|</th>|;
1524   $column_header{invnumber} =
1525       qq|<th class=listheading>|. $locale->text('Invoice'). qq|</th>|;
1526   $column_header{ordnumber} =
1527       qq|<th class=listheading>|. $locale->text('Order'). qq|</th>|;
1528   $column_header{transdate} =
1529     qq|<th class=listheading>| . $locale->text('Invdate') . qq|</th>|;
1530   $column_header{description} =
1531     qq|<th class=listheading>| . $locale->text('Description') . qq|</th>|;
1532   $column_header{qty} =
1533     qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
1534   $column_header{unit} =
1535     qq|<th class=listheading>| . $locale->text('Unit') . qq|</th>|;
1536   $result .= qq|
1537
1538 <table width=100%>
1539   <tr>
1540     <td>
1541       <table width=100%>
1542         <tr class=listheading>
1543 |;
1544
1545   map { $result .= "$column_header{$_}\n" } @column_index;
1546
1547   $result .= qq|
1548         </tr>
1549 |;
1550
1551
1552   foreach $ref (@{ $form->{DELIVERY} }) {
1553
1554     if ($ref->{shiptoname} eq $sameshiptoname) {
1555       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
1556       $column_data{shiptoname} = "<td>&nbsp;</td>";
1557     } else {
1558       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
1559     }
1560
1561     $i++;
1562     $i %= 2;
1563     $result .= "
1564         <tr class=listrow$i>
1565 ";
1566
1567     map { $result .= "$column_data{$_}\n" } @column_index;
1568
1569     $result .= qq|
1570         </tr>
1571 |;
1572
1573     $sameshiptoname = $ref->{shiptoname};
1574
1575   }
1576
1577   $result .= qq|
1578       </table>
1579 |;
1580
1581
1582   my $q = new CGI;
1583   print $q->header();
1584   print $result;
1585   $lxdebug->leave_sub();
1586
1587 }
1588
1589 sub continue { &{ $form->{nextsub} } }