Merge von 641,653 aus unstable: Preisgruppen Teil 3
[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
42 1;
43
44 # end of main
45
46 sub add {
47   $lxdebug->enter_sub();
48
49   $form->{title} = "Add";
50
51   $form->{callback} =
52     "$form->{script}?action=add&db=$form->{db}&path=$form->{path}&login=$form->{login}&password=$form->{password}"
53     unless $form->{callback};
54
55   CT->taxaccounts(\%myconfig, \%$form);
56
57   &form_header;
58   &form_footer;
59
60   $lxdebug->leave_sub();
61 }
62
63 sub search {
64   $lxdebug->enter_sub();
65
66   $label = ucfirst $form->{db};
67   $form->{title} = $locale->text($label . "s");
68
69   if ($form->{db} eq 'vendor') {
70     $gifi = qq|
71                 <td><input name="l_gifi_accno" type=checkbox class=checkbox value=Y> |
72       . $locale->text('GIFI') . qq|</td>
73 |;
74   }
75
76   $form->header;
77
78   print qq|
79 <body>
80
81 <form method=post action=$form->{script}>
82
83 <input type=hidden name=db value=$form->{db}>
84
85 <table width=100%>
86   <tr>
87     <th class=listtop>$form->{title}</th>
88   </tr>
89   <tr height="5"></tr>
90   <tr valign=top>
91     <td>
92       <table>
93         <tr>
94           <th align=right nowrap>| . $locale->text($label . ' Number') . qq|</th>
95           <td><input name=$form->{db}number size=35></td>
96         </tr>
97         <tr>
98           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
99           <td><input name=name size=35></td>
100         </tr>
101         <tr>
102           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
103           <td><input name=contact size=35></td>
104         </tr>
105         <tr>
106           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
107           <td><input name=email size=35></td>
108         </tr>
109         <tr>
110           <td></td>
111           <td><input name=status class=radio type=radio value=all checked>&nbsp;|
112     . $locale->text('All') . qq|
113           <input name=status class=radio type=radio value=orphaned>&nbsp;|
114     . $locale->text('Orphaned') . qq|</td>
115         </tr>
116         <tr>
117           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
118           <td>
119             <table>
120               <tr>
121                 <td><input name="l_id" type=checkbox class=checkbox value=Y> |
122     . $locale->text('ID') . qq|</td>
123                 <td><input name="l_$form->{db}number" type=checkbox class=checkbox value=Y> |
124     . $locale->text($label . ' Number') . qq|</td>
125                 <td><input name="l_name" type=checkbox class=checkbox value=Y checked> |
126     . $locale->text('Company Name') . qq|</td>
127                 <td><input name="l_address" type=checkbox class=checkbox value=Y> |
128     . $locale->text('Address') . qq|</td>
129               </tr>
130               <tr>
131                 <td><input name="l_contact" type=checkbox class=checkbox value=Y checked> |
132     . $locale->text('Contact') . qq|</td>
133                 <td><input name="l_phone" type=checkbox class=checkbox value=Y checked> |
134     . $locale->text('Phone') . qq|</td>
135                 <td><input name="l_fax" type=checkbox class=checkbox value=Y> |
136     . $locale->text('Fax') . qq|</td>
137                 <td><input name="l_email" type=checkbox class=checkbox value=Y checked> |
138     . $locale->text('E-mail') . qq|</td>
139               </tr>
140               <tr>
141                 <td><input name="l_taxnumber" type=checkbox class=checkbox value=Y> |
142     . $locale->text('Tax Number') . qq|</td>
143                 $gifi
144                 <td><input name="l_sic_code" type=checkbox class=checkbox value=Y> |
145     . $locale->text('SIC') . qq|</td>
146                 <td><input name="l_business" type=checkbox class=checkbox value=Y> |
147     . $locale->text('Type of Business') . qq|</td>
148               </tr>
149               <tr>
150                 <td><input name="l_invnumber" type=checkbox class=checkbox value=Y> |
151     . $locale->text('Invoices') . qq|</td>
152                 <td><input name="l_ordnumber" type=checkbox class=checkbox value=Y> |
153     . $locale->text('Orders') . qq|</td>
154                 <td><input name="l_quonumber" type=checkbox class=checkbox value=Y> |
155     . $locale->text('Quotations') . qq|</td>
156               </tr>
157             </table>
158           </td>
159         </tr>
160       </table>
161     </td>
162   </tr>
163   <tr>
164     <td><hr size=3 noshade></td>
165   </tr>
166 </table>
167
168 <input type=hidden name=nextsub value=list_names>
169
170 <input type=hidden name=path value=$form->{path}>
171 <input type=hidden name=login value=$form->{login}>
172 <input type=hidden name=password value=$form->{password}>
173
174 <br>
175 <input type=submit class=submit name=action value="|
176     . $locale->text('Continue') . qq|">
177 </form>
178
179 </body>
180 </html>
181 |;
182   $lxdebug->leave_sub();
183 }
184
185 sub list_names {
186   $lxdebug->enter_sub();
187
188   CT->search(\%myconfig, \%$form);
189
190   $callback =
191     "$form->{script}?action=list_names&db=$form->{db}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}";
192   $href = $callback;
193
194   @columns =
195     $form->sort_columns(id, name,
196                         "$form->{db}number", address,
197                         contact,             phone,
198                         fax,                 email,
199                         taxnumber,           gifi_accno,
200                         sic_code,            business,
201                         invnumber,           ordnumber,
202                         quonumber);
203
204   foreach $item (@columns) {
205     if ($form->{"l_$item"} eq "Y") {
206       push @column_index, $item;
207
208       # add column to href and callback
209       $callback .= "&l_$item=Y";
210       $href     .= "&l_$item=Y";
211     }
212   }
213   $number =
214     ($form->{db} eq "customer")
215     ? $locale->text('Customer Number')
216     : $locale->text('Vendor Number');
217
218   if ($form->{status} eq 'all') {
219     $option = $locale->text('All');
220   }
221   if ($form->{status} eq 'orphaned') {
222     $option .= $locale->text('Orphaned');
223   }
224   if ($form->{name}) {
225     $callback .= "&name=" . $form->escape($form->{name}, 1);
226     $href .= "&name=" . $form->escape($form->{name});
227     $option .= "\n<br>" . $locale->text('Name') . " : $form->{name}";
228   }
229   if ($form->{contact}) {
230     $callback .= "&contact=" . $form->escape($form->{contact}, 1);
231     $href .= "&contact=" . $form->escape($form->{contact});
232     $option .= "\n<br>" . $locale->text('Contact') . " : $form->{contact}";
233   }
234   if ($form->{"$form->{db}number"}) {
235     $callback .=
236       qq|&$form->{db}number=| . $form->escape($form->{"$form->{db}number"}, 1);
237     $href .=
238       "&$form->{db}number=" . $form->escape($form->{"$form->{db}number"});
239     $option .=
240       "\n<br>" . $locale->text('Number') . qq| : $form->{"$form->{db}number"}|;
241   }
242   if ($form->{email}) {
243     $callback .= "&email=" . $form->escape($form->{email}, 1);
244     $href .= "&email=" . $form->escape($form->{email});
245     $option .= "\n<br>" . $locale->text('E-mail') . " : $form->{email}";
246   }
247
248   $form->{callback} = "$callback&sort=$form->{sort}";
249   $callback = $form->escape($form->{callback});
250
251   $column_header{id} =
252     qq|<th class=listheading>| . $locale->text('ID') . qq|</th>|;
253   $column_header{"$form->{db}number"} =
254     qq|<th><a class=listheading href=$href&sort=$form->{db}number>$number</a></th>|;
255   $column_header{name} =
256       qq|<th><a class=listheading href=$href&sort=name>|
257     . $locale->text('Name')
258     . qq|</a></th>|;
259   $column_header{address} =
260       qq|<th><a class=listheading href=$href&sort=address>|
261     . $locale->text('Address')
262     . qq|</a></th>|;
263   $column_header{contact} =
264       qq|<th><a class=listheading href=$href&sort=contact>|
265     . $locale->text('Contact')
266     . qq|</a></th>|;
267   $column_header{phone} =
268       qq|<th><a class=listheading href=$href&sort=phone>|
269     . $locale->text('Phone')
270     . qq|</a></th>|;
271   $column_header{fax} =
272       qq|<th><a class=listheading href=$href&sort=fax>|
273     . $locale->text('Fax')
274     . qq|</a></th>|;
275   $column_header{email} =
276       qq|<th><a class=listheading href=$href&sort=email>|
277     . $locale->text('E-mail')
278     . qq|</a></th>|;
279   $column_header{cc} =
280       qq|<th><a class=listheading href=$href&sort=cc>|
281     . $locale->text('Cc')
282     . qq|</a></th>|;
283
284   $column_header{taxnumber} =
285       qq|<th><a class=listheading href=$href&sort=taxnumber>|
286     . $locale->text('Tax Number')
287     . qq|</a></th>|;
288   $column_header{gifi_accno} =
289       qq|<th><a class=listheading href=$href&sort=gifi_accno>|
290     . $locale->text('GIFI')
291     . qq|</a></th>|;
292   $column_header{sic_code} =
293       qq|<th><a class=listheading href=$href&sort=sic_code>|
294     . $locale->text('SIC')
295     . qq|</a></th>|;
296   $column_header{business} =
297       qq|<th><a class=listheading href=$href&sort=business>|
298     . $locale->text('Type of Business')
299     . qq|</a></th>|;
300
301   $column_header{invnumber} =
302       qq|<th><a class=listheading href=$href&sort=invnumber>|
303     . $locale->text('Invoice')
304     . qq|</a></th>|;
305   $column_header{ordnumber} =
306       qq|<th><a class=listheading href=$href&sort=ordnumber>|
307     . $locale->text('Order')
308     . qq|</a></th>|;
309   $column_header{quonumber} =
310       qq|<th><a class=listheading href=$href&sort=quonumber>|
311     . $locale->text('Quotation')
312     . qq|</a></th>|;
313
314   $label = ucfirst $form->{db} . "s";
315   $form->{title} = $locale->text($label);
316
317   $form->header;
318
319   print qq|
320 <body>
321
322 <table width=100%>
323   <tr>
324     <th class=listtop>$form->{title}</th>
325   </tr>
326   <tr height="5"></tr>
327   <tr>
328     <td>$option</td>
329   </tr>
330   <tr>
331     <td>
332       <table width=100%>
333         <tr class=listheading>
334 |;
335
336   map { print "$column_header{$_}\n" } @column_index;
337
338   print qq|
339         </tr>
340 |;
341
342   $ordertype = ($form->{db} eq 'customer') ? 'sales_order' : 'purchase_order';
343   $quotationtype =
344     ($form->{db} eq 'customer') ? 'sales_quotation' : 'request_quotation';
345
346   foreach $ref (@{ $form->{CT} }) {
347
348     if ($ref->{id} eq $sameid) {
349       map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
350     } else {
351       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
352
353       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
354         (invnumber, ordnumber, quonumber);
355
356       $column_data{name} =
357         "<td align=left><a href=$form->{script}?action=edit&id=$ref->{id}&db=$form->{db}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}&callback=$callback>$ref->{name}&nbsp;</td>";
358
359       if ($ref->{email}) {
360         $email = $ref->{email};
361         $email =~ s/</\&lt;/;
362         $email =~ s/>/\&gt;/;
363
364         $column_data{email} =
365           qq|<td><a href="mailto:$ref->{email}">$email</a></td>|;
366       }
367
368     }
369
370     if ($ref->{formtype} eq 'invoice') {
371       $column_data{invnumber} =
372         "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{invid}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{invnumber}&nbsp;</td>";
373     }
374
375     if ($ref->{formtype} eq 'order') {
376       $column_data{ordnumber} =
377         "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{invid}&type=$ordertype&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{ordnumber}&nbsp;</td>";
378     }
379
380     if ($ref->{formtype} eq 'quotation') {
381       $column_data{quonumber} =
382         "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{invid}&type=$quotationtype&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{quonumber}&nbsp;</td>";
383     }
384
385     $i++;
386     $i %= 2;
387     print "
388         <tr class=listrow$i>
389 ";
390
391     map { print "$column_data{$_}\n" } @column_index;
392
393     print qq|
394         </tr>
395 |;
396
397     $sameid = $ref->{id};
398
399   }
400
401   print qq|
402       </table>
403     </td>
404   </tr>
405   <tr>
406     <td><hr size=3 noshade></td>
407   </tr>
408 </table>
409
410 <br>
411 <form method=post action=$form->{script}>
412
413 <input name=callback type=hidden value="$form->{callback}">
414 <input name=db type=hidden value=$form->{db}>
415
416 <input type=hidden name=path value=$form->{path}>
417 <input type=hidden name=login value=$form->{login}>
418 <input type=hidden name=password value=$form->{password}>
419
420 <input class=submit type=submit name=action value="|
421     . $locale->text('Add') . qq|">|;
422
423   if ($form->{menubar}) {
424     require "$form->{path}/menu.pl";
425     &menubar;
426   }
427
428   print qq|
429   </form>
430
431 </body>
432 </html>
433 |;
434
435   $lxdebug->leave_sub();
436 }
437
438 sub edit {
439   $lxdebug->enter_sub();
440
441   # $locale->text('Edit Customer')
442   # $locale->text('Edit Vendor')
443
444   CT->get_tuple(\%myconfig, \%$form);
445
446   # format " into &quot;
447   map { $form->{$_} =~ s/\"/&quot;/g } keys %$form;
448
449   $form->{title} = "Edit";
450
451   # format discount
452   $form->{discount} *= 100;
453
454   &form_header;
455   &form_footer;
456
457   $lxdebug->leave_sub();
458 }
459
460 sub form_header {
461   $lxdebug->enter_sub();
462
463   $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
464   $form->{creditlimit} =
465     $form->format_amount(\%myconfig, $form->{creditlimit}, 0);
466
467   if ($myconfig{role} eq 'admin') {
468     $bcc = qq|
469         <tr>
470           <th align=right nowrap>| . $locale->text('Bcc') . qq|</th>
471           <td><input name=bcc size=35 value="$form->{bcc}"></td>
472         </tr>
473 |;
474   }
475   $form->{obsolete} = "checked" if $form->{obsolete};
476   %langs = (de => "deutsch", en => "englisch", fr => "französisch");
477   $lang = qq|<option value=""></option>|;
478   foreach $item (keys %langs) {
479     if ($form->{language} eq $item) {
480       $lang .= qq|<option value="$item" selected>$langs{$item}</option>|;
481     } else {
482       $lang .= qq|<option value="$item">$langs{$item}</option>|;
483     }
484   }
485
486   foreach $item (split / /, $form->{taxaccounts}) {
487     if (($form->{tax}{$item}{taxable}) || !($form->{id})) {
488       $taxable .=
489         qq| <input name="tax_$item" value=1 class=checkbox type=checkbox checked>&nbsp;<b>$form->{tax}{$item}{description}</b>|;
490     } else {
491       $taxable .=
492         qq| <input name="tax_$item" value=1 class=checkbox type=checkbox>&nbsp;<b>$form->{tax}{$item}{description}</b>|;
493     }
494   }
495
496 ##LINET
497   $taxable = "";
498
499   if ($taxable) {
500     $tax = qq|
501   <tr>
502     <th align=right>| . $locale->text('Taxable') . qq|</th>
503     <td colspan=2>
504       <table>
505         <tr>
506           <td>$taxable</td>
507           <td><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
508           <th align=left>| . $locale->text('Tax Included') . qq|</th>
509         </tr>
510       </table>
511     </td>
512   </tr>
513 |;
514   }
515   $form->{selectbusiness} = qq|<option>\n|;
516   map {
517     $form->{selectbusiness} .=
518       qq|<option value=$_->{id}>$_->{description}\n|
519   } @{ $form->{all_business} };
520   if ($form->{business_save}) {
521     $form->{selectbusiness} = $form->{business_save};
522   }
523   $form->{selectbusiness} =~
524     s/<option value=$form->{business}>/<option value=$form->{business} selected>/;
525
526   $label = ucfirst $form->{db};
527   $form->{title} = $locale->text("$form->{title} $label");
528   if ($form->{title_save}) {
529     $form->{title} = $form->{title_save};
530   }
531   if ($form->{db} eq 'vendor') {
532     $customer = qq|
533            <th align=right>| . $locale->text('Kundennummer') . qq|</th>
534            <td><input name=v_customer_id size=10 tabindex=18 maxlength=35 value="$form->{v_customer_id}"></td>
535 |;
536   }
537
538   if ($form->{db} eq 'customer') {
539
540     $customer = qq|
541            <th align=right>| . $locale->text('KNr. beim Kunden') . qq|</th>
542            <td><input name=c_vendor_id size=10 tabindex=18 maxlength=35 value="$form->{c_vendor_id}"></td>
543 |;
544   }
545   $business_salesman = "";
546   $business          = "<th></th><td></td>";
547   if ($vertreter) {
548     $business_salesman = qq|
549         <tr>
550           <td colspan=3>
551             <table>
552              <th align=right>| . $locale->text('Type of Business') . qq|</th>
553              <td><select name=business tabindex=1>$form->{selectbusiness}</select></td>
554              <th align=right>| . $locale->text('Salesman') . qq|</th>
555              <td><input name=salesman tabindex=2 value="$form->{salesman}"></td>
556              <input type=hidden name=salesman_id value="$form->{salesman_id}">
557              <input type=hidden name=oldsalesman value="$form->{oldsalesman}">
558             </table>
559           </td>
560        <tr>|;
561     $business = qq|
562              <th align=right>| . $locale->text('Username') . qq|</th>
563              <td><input name=username maxlength=50 tabindex=22 value="$form->{username}"></td>
564              <th align=right>| . $locale->text('Password') . qq|</th>
565              <td><input name=user_password maxlength=12 tabindex=23 value="$form->{user_password}"></td>|;
566   } else {
567     $business = qq|
568           <th align=right>| . $locale->text('Type of Business') . qq|</th>
569           <td><select name=business tabindex=22>$form->{selectbusiness}</select></td>
570       |;
571   }
572
573 ## LINET: Create a drop-down box with all prior titles and greetings.
574   CT->query_titles_and_greetings(\%myconfig, \%$form);
575
576   $select_title = qq|&nbsp;<select name=selected_cp_title><option></option>|;
577   map({ $select_title .= qq|<option>$_</option>|; } @{ $form->{TITLES} });
578   $select_title .= qq|</select>|;
579
580   $select_greeting =
581     qq|&nbsp;<select name=selected_cp_greeting><option></option>|;
582   map(
583      { $select_greeting .= qq|<option>$_</option>|; } @{ $form->{GREETINGS} });
584   $select_greeting .= qq|</select>|;
585 ## /LINET
586
587   if ($form->{db} eq 'customer') {
588   #get pricegroup and form it
589   $form->get_pricegroup(\%myconfig, { all => 1 });
590
591   $form->{pricegroup}    = "$form->{klass}";
592   $form->{pricegroup_id} = "$form->{klass}";
593
594   if (@{ $form->{all_pricegroup} }) {
595
596     $form->{selectpricegroup} = qq|<option>\n|;
597     map {
598       $form->{selectpricegroup} .=
599         qq|<option value="$_->{id}">$_->{pricegroup}\n|
600     } @{ $form->{all_pricegroup} };
601   }
602
603   if ($form->{selectpricegroup}) {
604     $form->{selectpricegroup} = $form->unescape($form->{selectpricegroup});
605
606     $pricegroup =
607       qq|<input type=hidden name=selectpricegroup value="|
608       . $form->escape($form->{selectpricegroup}, 1) . qq|">|;
609
610     $form->{selectpricegroup} =~
611       s/(<option value="\Q$form->{klass}\E")/$1 selected/;
612
613     $pricegroup .= qq|<select name=klass>$form->{selectpricegroup}</select>|;
614
615   }
616  }
617   # $locale->text('Customer Number')
618   # $locale->text('Vendor Number')
619   $form->{fokus} = "ct.name";
620   $form->header;
621
622   print qq|
623 <body onLoad="fokus()">
624 <form method=post name="ct" action=$form->{script}>
625
626 <table width=100%>
627   <tr>
628     <th class=listtop>$form->{title}</th>
629   </tr>
630   <tr>
631     <td>
632       <table width=100%>
633         <tr class=listheading>
634           <th class=listheading colspan=2 width=50%>|
635     . $locale->text('Billing Address') . qq|</th>
636           <th class=listheading width=50%>|
637     . $locale->text('Shipping Address') . qq|</th>
638         </tr>
639         <tr height="5"></tr>
640         $business_salesman
641         <tr>
642           <th align=right nowrap>| . $locale->text($label . ' Number') . qq|</th>
643           <td><input name="$form->{db}number" size=35 maxlength=35 value="$form->{"$form->{db}number"}"></td>
644         </tr>
645         <tr>
646           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
647           <td><input name=name size=35 maxlength=35 tabindex=1 value="$form->{name}"></td>
648           <td><input name=shiptoname size=35 maxlength=75 value="$form->{shiptoname}"></td>
649         </tr>
650         <tr>
651           <th align=right nowrap>| . $locale->text('Abteilung') . qq|</th>
652           <td><input name=department_1 size=16 maxlength=75 tabindex=2 value="$form->{department_1}">
653           <input name=department_2 size=16 maxlength=75 tabindex=3 value="$form->{department_2}"></td>
654           <td><input name=shiptodepartment_1 size=16 maxlength=75 value="$form->{shiptodepartment_1}">
655           <input name=shiptodepartment_2 size=16 maxlength=75 value="$form->{shiptodepartment_2}"></td>
656         </tr>
657         <tr>
658           <th align=right nowrap>| . $locale->text('Street') . qq|</th>
659           <td><input name=street size=35 tabindex=4 maxlength=75 value="$form->{street}"></td>
660           <td><input name=shiptostreet size=35 maxlength=35 value="$form->{shiptostreet}"></td>
661         </tr>
662         <tr>
663           <th align=right nowrap>|
664     . $locale->text('Zipcode') . "/" . $locale->text('City') . qq|</th>
665           <td><input name=zipcode size=5 tabindex=5 maxlength=10 value="$form->{zipcode}">
666           <input name=city size=30 tabindex=6 maxlength=75 value="$form->{city}"></td>
667           <td><input name=shiptozipcode size=5 maxlength=10 value="$form->{shiptozipcode}">
668           <input name=shiptocity size=30 maxlength=75 value="$form->{shiptocity}"></td>
669         </tr>
670         <tr>
671           <th align=right nowrap>| . $locale->text('Country') . qq|</th>
672           <td><input name=country size=35 tabindex=7 maxlength=75 value="$form->{country}"></td>
673           <td><input name=shiptocountry size=35 maxlength=35 value="$form->{shiptocountry}"></td>
674         </tr>
675         <tr>
676           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
677           <td><input name=contact size=28 tabindex=8 maxlength=75 value="$form->{contact}"></td>
678           <td><input name=shiptocontact size=30 maxlength=75 value="$form->{shiptocontact}"></td>
679         </tr>
680         <tr>
681           <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
682           <td><input name=phone size=30 tabindex=9 maxlength=30 value="$form->{phone}"></td>
683           <td><input name=shiptophone size=30 maxlength=30 value="$form->{shiptophone}"></td>
684         </tr>
685         <tr>
686           <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
687           <td><input name=fax size=30 tabindex=10 maxlength=30 value="$form->{fax}"></td>
688           <td><input name=shiptofax size=30 maxlength=30 value="$form->{shiptofax}"></td>
689         </tr>
690         <tr>
691           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
692           <td><input name=email tabindex=11 size=45 value="$form->{email}"></td>
693           <td><input name=shiptoemail size=45 value="$form->{shiptoemail}"></td>
694         </tr>
695         <tr>
696           <th align=right nowrap>| . $locale->text('Homepage') . qq|</th>
697           <td><input name=homepage tabindex=12 size=45 value="$form->{homepage}"></td>
698         </tr>
699         <tr>
700         </tr>|;
701 ##LINET - added fields for contact person
702   print qq|       <tr>
703          <td colspan=3>
704                 <input type=hidden name=cp_id value=$form->{cp_id}>
705                 <table>
706                 <tr>
707                   <th align=right nowrap>|
708     . $locale->text('Contact Person') . qq|</th>
709                 </tr>
710                 <tr>
711                   <th></th>
712                   <th align=left nowrap>| . $locale->text('Greeting') . qq|</th>
713                   <td><input name=cp_greeting size=30 maxlength=30 value="$form->{cp_greeting}">&nbsp;
714                   $select_greeting</td>
715                   <th align=left nowrap>| . $locale->text('Title') . qq|</th>
716                   <td><input name=cp_title size=30 maxlength=30 value="$form->{cp_title}">&nbsp;
717                   $select_title</td>
718                 </tr>
719                 <tr>
720                   <th></th>
721                   <th align=left nowrap>|
722     . $locale->text('Given Name') . qq|</th>
723                   <td><input name=cp_givenname size=30 maxlength=40 value="$form->{cp_givenname}"></td>
724                   <th align=left nowrap>| . $locale->text('Name') . qq|</th>
725                   <td><input name=cp_name size=30 maxlength=40 value="$form->{cp_name}"></td>
726                 </tr>
727                 <tr>
728                   <th></th>
729                   <th align=left nowrap>| . $locale->text('Phone1') . qq|</th>
730                   <td><input name=cp_phone1 size=30 maxlength=30 value="$form->{cp_phone1}"></td>
731                   <th align=left nowrap>| . $locale->text('Phone2') . qq|</th>
732                   <td><input name=cp_phone2 size=30 maxlength=30 value="$form->{cp_phone2}"></td>
733                 </tr>
734                 <tr>
735                   <th></th>
736                   <th align=left nowrap>| . $locale->text('E-mail') . qq|</th>
737                   <td><input name=cp_email size=30 maxlength=40 value="$form->{cp_email}"></td>
738                   <th></th>
739                   <th></th>
740                 </tr>                </table>
741         </td>
742         </tr>
743         <tr height="5"></tr>|;
744 ##/LINET
745   print qq|        $bcc
746         $tax
747       </table>
748     </td>
749   </tr>
750   <tr>
751     <td>
752       <table>
753         <tr>
754           <th align=right>| . $locale->text('Credit Limit') . qq|</th>
755           <td><input name=creditlimit tabindex=13 size=9 value="$form->{creditlimit}"></td>
756           <th align=right>| . $locale->text('Terms: Net') . qq|</th>
757           <td><input name=terms tabindex=14 size=2 value="$form->{terms}">|
758     . $locale->text('days') . qq|</td>
759           <th align=right>| . $locale->text('Discount') . qq|</th>
760           <td><input name=discount tabindex=15 size=4 value="$form->{discount}">
761           %</td>
762         </tr>
763         <tr>
764           <th align=right>| . $locale->text('Tax Number / SSN') . qq|</th>
765           <td><input name=taxnumber tabindex=16 size=20 value="$form->{taxnumber}"></td>
766           <th align=right>| . $locale->text('USt-IdNr.') . qq|</th>
767           <td><input name=ustid tabindex=17 size=20 value="$form->{ustid}"></td>
768           $customer
769         </tr>
770         <tr>
771           <th align=right>| . $locale->text('Account Number') . qq|</th>
772           <td><input name=account_number size=10 tabindex=19 value="$form->{account_number}"></td>
773           <th align=right>| . $locale->text('Bank Code Number') . qq|</th>
774           <td><input name=bank_code size=10 tabindex=20 value="$form->{bank_code}"></td>
775           <th align=right>| . $locale->text('Bank') . qq|</th>
776           <td><input name=bank size=30 tabindex=21 value="$form->{bank}"></td>
777         </tr>
778         <tr>
779           $business
780           <th align=right>| . $locale->text('Language') . qq|</th>
781           <td><select name=language tabindex=23>$lang
782                           </select></td>|;
783 if ($form->{db} eq 'customer'){
784
785 print qq|
786           <th align=right>| . $locale->text('Preisklasse') . qq|</th>
787           <td>$pricegroup</td>|;
788 }
789   print qq|        </tr>
790         <tr>
791           <td align=right>| . $locale->text('Obsolete') . qq|</td>
792           <td><input name=obsolete class=checkbox type=checkbox value=1 $form->{obsolete}></td>
793         </tr>
794       </table>
795     </td>
796   </tr>
797   <tr>
798     <th align=left nowrap>| . $locale->text('Notes') . qq|</th>
799   </tr>
800   <tr>
801     <td><textarea name=notes rows=3 cols=60 wrap=soft>$form->{notes}</textarea></td>
802   </tr>
803   <tr>
804     <td><hr size=3 noshade></td>
805   </tr>
806 </table>
807 |;
808
809   $lxdebug->leave_sub();
810 }
811
812 sub form_footer {
813   $lxdebug->enter_sub();
814
815   $label     = ucfirst $form->{db};
816   $quotation =
817     ($form->{db} eq 'customer')
818     ? $locale->text('Save and Quotation')
819     : $locale->text('Save and RFQ');
820   $arap =
821     ($form->{db} eq 'customer')
822     ? $locale->text('Save and AR Transaction')
823     : $locale->text('Save and AP Transaction');
824   if ($vertreter) {
825     $update_button =
826       qq|<input class=submit type=submit name=action accesskey="u" value="|
827       . $locale->text("Update") . qq|">|;
828   } else {
829     $update_button = "";
830   }
831
832 ##<input class=submit type=submit name=action value="|.$locale->text("Save and Quotation").qq|">
833 ##<input class=submit type=submit name=action value="|.$locale->text("Save and RFQ").qq|">
834 ##<input class=submit type=submit name=action value="|.$locale->text("Save and AR Transaction").qq|">
835 ##<input class=submit type=submit name=action value="|.$locale->text("Save and AP Transaction").qq|">
836
837   print qq|
838 <input name=id type=hidden value=$form->{id}>
839 <input name=taxaccounts type=hidden value="$form->{taxaccounts}">
840 <input name=business_save type=hidden value="$form->{selectbusiness}">
841 <input name=title_save type=hidden value="$form->{title}">
842
843 <input type=hidden name=path value=$form->{path}>
844 <input type=hidden name=login value=$form->{login}>
845 <input type=hidden name=password value=$form->{password}>
846
847 <input type=hidden name=callback value="$form->{callback}">
848 <input type=hidden name=db value=$form->{db}>
849
850
851
852 <br>
853 $update_button
854 <input class=submit type=submit name=action accesskey="s" value="|
855     . $locale->text("Save") . qq|">
856 <input class=submit type=submit name=action value="$arap">
857 <input class=submit type=submit name=action value="|
858     . $locale->text("Save and Invoice") . qq|">
859 <input class=submit type=submit name=action value="|
860     . $locale->text("Save and Order") . qq|">
861 <input class=submit type=submit name=action value="$quotation">
862 |;
863
864   if ($form->{id} && $form->{status} eq 'orphaned') {
865     print qq|<input class=submit type=submit name=action value="|
866       . $locale->text('Delete')
867       . qq|">\n|;
868   }
869
870   if ($form->{menubar}) {
871     require "$form->{path}/menu.pl";
872     &menubar;
873   }
874
875   print qq|
876
877   </form>
878
879 </body>
880 </html>
881 |;
882
883   $lxdebug->leave_sub();
884 }
885
886 sub add_transaction {
887   $lxdebug->enter_sub();
888
889   $form->isblank("name", $locale->text("Name missing!"));
890   &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
891
892   $form->{callback} = $form->escape($form->{callback}, 1);
893   $name = $form->escape("$form->{name}", 1);
894
895   $form->{callback} =
896     "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=add&vc=$form->{db}&$form->{db}_id=$form->{id}&$form->{db}=$name&type=$form->{type}&callback=$form->{callback}";
897
898   $form->redirect;
899
900   $lxdebug->leave_sub();
901 }
902
903 sub save_and_ap_transaction {
904   $lxdebug->enter_sub();
905
906   $form->{script} = "ap.pl";
907   &add_transaction;
908
909   $lxdebug->leave_sub();
910 }
911
912 sub save_and_ar_transaction {
913   $lxdebug->enter_sub();
914
915   $form->{script} = "ar.pl";
916   &add_transaction;
917
918   $lxdebug->leave_sub();
919 }
920
921 sub save_and_invoice {
922   $lxdebug->enter_sub();
923
924   $form->{script} = ($form->{db} eq 'customer') ? "is.pl" : "ir.pl";
925   $form->{type} = "invoice";
926   &add_transaction;
927
928   $lxdebug->leave_sub();
929 }
930
931 sub save_and_rfq {
932   $lxdebug->enter_sub();
933
934   $form->{script} = "oe.pl";
935   $form->{type}   = "request_quotation";
936   &add_transaction;
937
938   $lxdebug->leave_sub();
939 }
940
941 sub save_and_quotation {
942   $lxdebug->enter_sub();
943
944   $form->{script} = "oe.pl";
945   $form->{type}   = "sales_quotation";
946   &add_transaction;
947
948   $lxdebug->leave_sub();
949 }
950
951 sub save_and_order {
952   $lxdebug->enter_sub();
953
954   $form->{script} = "oe.pl";
955   $form->{type}   =
956     ($form->{db} eq 'customer') ? "sales_order" : "purchase_order";
957   &add_transaction;
958
959   $lxdebug->leave_sub();
960 }
961
962 sub save {
963   $lxdebug->enter_sub();
964
965   # $locale->text('Customer saved!')
966   # $locale->text('Vendor saved!')
967
968   $msg = ucfirst $form->{db};
969   $imsg .= " saved!";
970
971   $form->isblank("name", $locale->text("Name missing!"));
972   if ($vertreter && $form->{db} eq "customer") {
973     $form->isblank("salesman_id", $locale->text("Salesman missing!"));
974   }
975   &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
976
977   $form->redirect($locale->text($msg));
978
979   $lxdebug->leave_sub();
980 }
981
982 sub delete {
983   $lxdebug->enter_sub();
984
985   # $locale->text('Customer deleted!')
986   # $locale->text('Cannot delete customer!')
987   # $locale->text('Vendor deleted!')
988   # $locale->text('Cannot delete vendor!')
989
990   CT->delete(\%myconfig, \%$form);
991
992   $msg = ucfirst $form->{db};
993   $msg .= " deleted!";
994   $form->redirect($locale->text($msg));
995
996   $msg = "Cannot delete $form->{db}";
997   $form->error($locale->text($msg));
998
999   $lxdebug->leave_sub();
1000 }
1001
1002 sub display {
1003   $lxdebug->enter_sub();
1004
1005   &form_header();
1006   &form_footer();
1007
1008   $lxdebug->leave_sub();
1009 }
1010
1011 sub update {
1012   $lxdebug->enter_sub();
1013
1014   &check_salesman($form->{salesman});
1015
1016   #  $form->get_salesman(\%myconfig, $form->{salesman});
1017   &display();
1018   $lxdebug->leave_sub();
1019 }
1020
1021 sub check_salesman {
1022   $lxdebug->enter_sub();
1023
1024   my ($name) = @_;
1025
1026   my ($new_name, $new_id) = split /--/, $form->{$name};
1027   my $i = 0;
1028
1029   # check name, combine name and id
1030   if ($form->{"oldsalesman"} ne $form->{"salesman"}) {
1031
1032     # return one name or a list of names in $form->{name_list}
1033     if (($i = $form->get_salesman(\%myconfig, $name)) > 1) {
1034       &select_salesman($name);
1035       exit;
1036     }
1037
1038     if ($i == 1) {
1039
1040       # we got one name
1041       $form->{"salesman_id"} = $form->{salesman_list}[0]->{id};
1042       $form->{salesman}      = $form->{salesman_list}[0]->{name};
1043       $form->{"oldsalesman"} = $form->{salesman};
1044
1045     } else {
1046
1047       # name is not on file
1048       # $locale->text('Customer not on file!')
1049       # $locale->text('Vendor not on file!')
1050       $msg = ucfirst $name . " not on file or locked!";
1051       $form->error($locale->text($msg));
1052     }
1053   }
1054
1055   $lxdebug->leave_sub();
1056
1057   return $i;
1058 }
1059
1060 sub select_salesman {
1061   $lxdebug->enter_sub();
1062
1063   my ($table) = @_;
1064
1065   @column_index = qw(ndx name);
1066
1067   $label             = ucfirst $table;
1068   $column_data{ndx}  = qq|<th>&nbsp;</th>|;
1069   $column_data{name} =
1070     qq|<th class=listheading>| . $locale->text($label) . qq|</th>|;
1071
1072   # list items with radio button on a form
1073   $form->header;
1074
1075   $title = $locale->text('Select from one of the names below');
1076
1077   print qq|
1078 <body>
1079
1080 <form method=post action=$form->{script}>
1081
1082 <table width=100%>
1083   <tr>
1084     <th class=listtop>$title</th>
1085   </tr>
1086   <tr space=5></tr>
1087   <tr>
1088     <td>
1089       <table width=100%>
1090         <tr class=listheading>|;
1091
1092   map { print "\n$column_data{$_}" } @column_index;
1093
1094   print qq|
1095         </tr>
1096 |;
1097
1098   my $i = 0;
1099   foreach $ref (@{ $form->{salesman_list} }) {
1100     $checked = ($i++) ? "" : "checked";
1101
1102     $ref->{name} =~ s/\"/&quot;/g;
1103
1104     $column_data{ndx} =
1105       qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
1106     $column_data{name} =
1107       qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
1108
1109     $j++;
1110     $j %= 2;
1111     print qq|
1112         <tr class=listrow$j>|;
1113
1114     map { print "\n$column_data{$_}" } @column_index;
1115
1116     print qq|
1117         </tr>
1118
1119 <input name="new_id_$i" type=hidden value=$ref->{id}>
1120
1121 |;
1122
1123   }
1124
1125   print qq|
1126       </table>
1127     </td>
1128   </tr>
1129   <tr>
1130     <td><hr size=3 noshade></td>
1131   </tr>
1132 </table>
1133
1134 <input name=lastndx type=hidden value=$i>
1135
1136 |;
1137
1138   # delete variables
1139   map { delete $form->{$_} } qw(action name_list header);
1140
1141   # save all other form variables
1142   foreach $key (keys %${form}) {
1143     $form->{$key} =~ s/\"/&quot;/g;
1144     print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
1145   }
1146
1147   print qq|
1148 <input type=hidden name=nextsub value=salesman_selected>
1149
1150 <input type=hidden name=vc value=$table>
1151 <br>
1152 <input class=submit type=submit name=action value="|
1153     . $locale->text('Continue') . qq|">
1154 </form>
1155
1156 </body>
1157 </html>
1158 |;
1159
1160   $lxdebug->leave_sub();
1161 }
1162
1163 sub salesman_selected {
1164   $lxdebug->enter_sub();
1165
1166   # replace the variable with the one checked
1167
1168   # index for new item
1169   $i = $form->{ndx};
1170
1171   $form->{salesman}      = $form->{"new_name_$i"};
1172   $form->{"salesman_id"} = $form->{"new_id_$i"};
1173   $form->{"oldsalesman"} = $form->{salesman};
1174
1175   # delete all the new_ variables
1176   for $i (1 .. $form->{lastndx}) {
1177     map { delete $form->{"new_${_}_$i"} } (id, name);
1178   }
1179
1180   map { delete $form->{$_} } qw(ndx lastndx nextsub);
1181
1182   &update(1);
1183
1184   $lxdebug->leave_sub();
1185 }
1186
1187 sub continue { &{ $form->{nextsub} } }