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