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