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