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