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