0e1df522a0b0ba12d3903b13d1b948cf28f2d6fc
[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({ $select_greeting .= qq|<option>$_</option>|; } @{ $form->{GREETINGS} });
599   $select_greeting .= qq|</select>|;
600 ## /LINET
601
602   # $locale->text('Customer Number')
603   # $locale->text('Vendor Number')
604   $form->{fokus} = "ct.name";
605   $form->header;
606
607   print qq|
608 <body onLoad="fokus()">
609 <form method=post name="ct" action=$form->{script}>
610
611 <table width=100%>
612   <tr>
613     <th class=listtop>$form->{title}</th>
614   </tr>
615   <tr>
616     <td>
617       <table width=100%>
618         <tr class=listheading>
619           <th class=listheading colspan=2 width=50%>|
620     . $locale->text('Billing Address')
621     . qq|</th>
622           <th class=listheading width=50%>|
623     . $locale->text('Shipping Address')
624     . qq|</th>
625         </tr>
626         <tr height="5"></tr>
627         $business_salesman
628         <tr>
629           <th align=right nowrap>| . $locale->text($label . ' Number') . qq|</th>
630           <td><input name="$form->{db}number" size=35 maxlength=35 value="$form->{"$form->{db}number"}"></td>
631         </tr>
632         <tr>
633           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
634           <td><input name=name size=35 maxlength=35 tabindex=1 value="$form->{name}"></td>
635           <td><input name=shiptoname size=35 maxlength=75 value="$form->{shiptoname}"></td>
636         </tr>
637         <tr>
638           <th align=right nowrap>| . $locale->text('Abteilung') . qq|</th>
639           <td><input name=department_1 size=16 maxlength=75 tabindex=2 value="$form->{department_1}">
640           <input name=department_2 size=16 maxlength=75 tabindex=3 value="$form->{department_2}"></td>
641           <td><input name=shiptodepartment_1 size=16 maxlength=75 value="$form->{shiptodepartment_1}">
642           <input 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 name=street size=35 tabindex=4 maxlength=75 value="$form->{street}"></td>
647           <td><input name=shiptostreet size=35 maxlength=35 value="$form->{shiptostreet}"></td>
648         </tr>
649         <tr>
650           <th align=right nowrap>|
651     . $locale->text('Zipcode') . "/"
652     . $locale->text('City')
653     . qq|</th>
654           <td><input name=zipcode size=5 tabindex=5 maxlength=10 value="$form->{zipcode}">
655           <input name=city size=30 tabindex=6 maxlength=75 value="$form->{city}"></td>
656           <td><input name=shiptozipcode size=5 maxlength=10 value="$form->{shiptozipcode}">
657           <input name=shiptocity size=30 maxlength=75 value="$form->{shiptocity}"></td>
658         </tr>
659         <tr>
660           <th align=right nowrap>| . $locale->text('Country') . qq|</th>
661           <td><input name=country size=35 tabindex=7 maxlength=75 value="$form->{country}"></td>
662           <td><input name=shiptocountry size=35 maxlength=35 value="$form->{shiptocountry}"></td>
663         </tr>
664         <tr>
665           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
666           <td><input name=contact size=28 tabindex=8 maxlength=75 value="$form->{contact}"></td>
667           <td><input name=shiptocontact size=30 maxlength=75 value="$form->{shiptocontact}"></td>
668         </tr>
669         <tr>
670           <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
671           <td><input name=phone size=30 tabindex=9 maxlength=30 value="$form->{phone}"></td>
672           <td><input name=shiptophone size=30 maxlength=30 value="$form->{shiptophone}"></td>
673         </tr>
674         <tr>
675           <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
676           <td><input name=fax size=30 tabindex=10 maxlength=30 value="$form->{fax}"></td>
677           <td><input name=shiptofax size=30 maxlength=30 value="$form->{shiptofax}"></td>
678         </tr>
679         <tr>
680           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
681           <td><input name=email tabindex=11 size=45 value="$form->{email}"></td>
682           <td><input name=shiptoemail size=45 value="$form->{shiptoemail}"></td>
683         </tr>
684         <tr>
685           <th align=right nowrap>| . $locale->text('Homepage') . qq|</th>
686           <td><input name=homepage tabindex=12 size=45 value="$form->{homepage}"></td>
687         </tr>
688         <tr>
689         </tr>|;
690 ##LINET - added fields for contact person
691   print qq|       <tr>
692          <td colspan=3>
693                 <input type=hidden name=cp_id value=$form->{cp_id}>
694                 <table>
695                 <tr>
696                   <th align=right nowrap>|
697     . $locale->text('Contact Person')
698     . qq|</th>
699                 </tr>
700                 <tr>
701                   <th></th>
702                   <th align=left nowrap>| . $locale->text('Greeting') . qq|</th>
703                   <td><input name=cp_greeting size=30 maxlength=30 value="$form->{cp_greeting}">&nbsp;
704                   $select_greeting</td>
705                   <th align=left nowrap>| . $locale->text('Title') . qq|</th>
706                   <td><input name=cp_title size=30 maxlength=30 value="$form->{cp_title}">&nbsp;
707                   $select_title</td>
708                 </tr>
709                 <tr>
710                   <th></th>
711                   <th align=left nowrap>|
712     . $locale->text('Given Name')
713     . qq|</th>
714                   <td><input name=cp_givenname size=30 maxlength=40 value="$form->{cp_givenname}"></td>
715                   <th align=left nowrap>| . $locale->text('Name') . qq|</th>
716                   <td><input name=cp_name size=30 maxlength=40 value="$form->{cp_name}"></td>
717                 </tr>
718                 <tr>
719                   <th></th>
720                   <th align=left nowrap>| . $locale->text('Phone1') . qq|</th>
721                   <td><input name=cp_phone1 size=30 maxlength=30 value="$form->{cp_phone1}"></td>
722                   <th align=left nowrap>| . $locale->text('Phone2') . qq|</th>
723                   <td><input name=cp_phone2 size=30 maxlength=30 value="$form->{cp_phone2}"></td>
724                 </tr>
725                 <tr>
726                   <th></th>
727                   <th align=left nowrap>| . $locale->text('E-mail') . qq|</th>
728                   <td><input name=cp_email size=30 maxlength=40 value="$form->{cp_email}"></td>
729                   <th></th>
730                   <th></th>
731                 </tr>                </table>
732         </td>
733         </tr>
734         <tr height="5"></tr>|;
735 ##/LINET
736   print qq|        $bcc
737         $tax
738       </table>
739     </td>
740   </tr>
741   <tr>
742     <td>
743       <table>
744         <tr>
745           <th align=right>| . $locale->text('Credit Limit') . qq|</th>
746           <td><input name=creditlimit tabindex=13 size=9 value="$form->{creditlimit}"></td>
747           <th align=right>| . $locale->text('Terms: Net') . qq|</th>
748           <td><input name=terms tabindex=14 size=2 value="$form->{terms}">|
749     . $locale->text('days')
750     . qq|</td>
751           <th align=right>| . $locale->text('Discount') . qq|</th>
752           <td><input name=discount tabindex=15 size=4 value="$form->{discount}">
753           %</td>
754         </tr>
755         <tr>
756           <th align=right>| . $locale->text('Tax Number / SSN') . qq|</th>
757           <td><input name=taxnumber tabindex=16 size=20 value="$form->{taxnumber}"></td>
758           <th align=right>| . $locale->text('USt-IdNr.') . qq|</th>
759           <td><input name=ustid tabindex=17 size=20 value="$form->{ustid}"></td>
760           $customer
761         </tr>
762         <tr>
763           <th align=right>| . $locale->text('Account Number') . qq|</th>
764           <td><input name=account_number size=10 tabindex=19 value="$form->{account_number}"></td>
765           <th align=right>| . $locale->text('Bank Code Number') . qq|</th>
766           <td><input name=bank_code size=10 tabindex=20 value="$form->{bank_code}"></td>
767           <th align=right>| . $locale->text('Bank') . qq|</th>
768           <td><input name=bank size=30 tabindex=21 value="$form->{bank}"></td>
769         </tr>
770         <tr>
771           $business
772           <th align=right>| . $locale->text('Language') . qq|</th>
773           <td><select name=language tabindex=23>$lang
774                           </select></td>|;
775
776   print qq|        </tr>
777         <tr>
778           <td align=right>| . $locale->text('Obsolete') . qq|</td>
779           <td><input name=obsolete class=checkbox type=checkbox value=1 $form->{obsolete}></td>
780         </tr>
781       </table>
782     </td>
783   </tr>
784   <tr>
785     <th align=left nowrap>| . $locale->text('Notes') . qq|</th>
786   </tr>
787   <tr>
788     <td><textarea name=notes rows=3 cols=60 wrap=soft>$form->{notes}</textarea></td>
789   </tr>
790   <tr>
791     <td><hr size=3 noshade></td>
792   </tr>
793 </table>
794 |;
795
796   $lxdebug->leave_sub();
797 }
798
799 sub form_footer {
800   $lxdebug->enter_sub();
801
802   $label     = ucfirst $form->{db};
803   $quotation =
804     ($form->{db} eq 'customer')
805     ? $locale->text('Save and Quotation')
806     : $locale->text('Save and RFQ');
807   $arap =
808     ($form->{db} eq 'customer')
809     ? $locale->text('Save and AR Transaction')
810     : $locale->text('Save and AP Transaction');
811   if ($vertreter) {
812     $update_button =
813       qq|<input class=submit type=submit name=action accesskey="u" value="|
814       . $locale->text("Update") . qq|">|;
815   } else {
816     $update_button = "";
817   }
818
819 ##<input class=submit type=submit name=action value="|.$locale->text("Save and Quotation").qq|">
820 ##<input class=submit type=submit name=action value="|.$locale->text("Save and RFQ").qq|">
821 ##<input class=submit type=submit name=action value="|.$locale->text("Save and AR Transaction").qq|">
822 ##<input class=submit type=submit name=action value="|.$locale->text("Save and AP Transaction").qq|">
823
824   print qq|
825 <input name=id type=hidden value=$form->{id}>
826 <input name=taxaccounts type=hidden value="$form->{taxaccounts}">
827 <input name=business_save type=hidden value="$form->{selectbusiness}">
828 <input name=title_save type=hidden value="$form->{title}">
829
830 <input type=hidden name=path value=$form->{path}>
831 <input type=hidden name=login value=$form->{login}>
832 <input type=hidden name=password value=$form->{password}>
833
834 <input type=hidden name=callback value="$form->{callback}">
835 <input type=hidden name=db value=$form->{db}>
836
837 <br>
838 $update_button
839 <input class=submit type=submit name=action accesskey="s" value="|
840     . $locale->text("Save") . qq|">
841 <input class=submit type=submit name=action value="$arap">
842 <input class=submit type=submit name=action value="|
843     . $locale->text("Save and Invoice") . qq|">
844 <input class=submit type=submit name=action value="|
845     . $locale->text("Save and Order") . qq|">
846 <input class=submit type=submit name=action value="$quotation">
847 |;
848
849   if ($form->{id} && $form->{status} eq 'orphaned') {
850     print qq|<input class=submit type=submit name=action value="|
851       . $locale->text('Delete')
852       . qq|">\n|;
853   }
854
855   if ($form->{menubar}) {
856     require "$form->{path}/menu.pl";
857     &menubar;
858   }
859
860   print qq|
861
862   </form>
863
864 </body>
865 </html>
866 |;
867
868   $lxdebug->leave_sub();
869 }
870
871 sub add_transaction {
872   $lxdebug->enter_sub();
873
874   $form->isblank("name", $locale->text("Name missing!"));
875   &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
876
877   $form->{callback} = $form->escape($form->{callback}, 1);
878   $name = $form->escape("$form->{name}", 1);
879
880   $form->{callback} =
881     "$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}";
882
883   $form->redirect;
884
885   $lxdebug->leave_sub();
886 }
887
888 sub save_and_ap_transaction {
889   $lxdebug->enter_sub();
890
891   $form->{script} = "ap.pl";
892   &add_transaction;
893
894   $lxdebug->leave_sub();
895 }
896
897 sub save_and_ar_transaction {
898   $lxdebug->enter_sub();
899
900   $form->{script} = "ar.pl";
901   &add_transaction;
902
903   $lxdebug->leave_sub();
904 }
905
906 sub save_and_invoice {
907   $lxdebug->enter_sub();
908
909   $form->{script} = ($form->{db} eq 'customer') ? "is.pl" : "ir.pl";
910   $form->{type} = "invoice";
911   &add_transaction;
912
913   $lxdebug->leave_sub();
914 }
915
916 sub save_and_rfq {
917   $lxdebug->enter_sub();
918
919   $form->{script} = "oe.pl";
920   $form->{type}   = "request_quotation";
921   &add_transaction;
922
923   $lxdebug->leave_sub();
924 }
925
926 sub save_and_quotation {
927   $lxdebug->enter_sub();
928
929   $form->{script} = "oe.pl";
930   $form->{type}   = "sales_quotation";
931   &add_transaction;
932
933   $lxdebug->leave_sub();
934 }
935
936 sub save_and_order {
937   $lxdebug->enter_sub();
938
939   $form->{script} = "oe.pl";
940   $form->{type}   =
941     ($form->{db} eq 'customer') ? "sales_order" : "purchase_order";
942   &add_transaction;
943
944   $lxdebug->leave_sub();
945 }
946
947 sub save {
948   $lxdebug->enter_sub();
949
950   # $locale->text('Customer saved!')
951   # $locale->text('Vendor saved!')
952
953   $msg = ucfirst $form->{db};
954   $imsg .= " saved!";
955
956   $form->isblank("name", $locale->text("Name missing!"));
957   if ($vertreter && $form->{db} eq "customer") {
958     $form->isblank("salesman_id", $locale->text("Salesman missing!"));
959   }
960   &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
961
962   $form->redirect($locale->text($msg));
963
964   $lxdebug->leave_sub();
965 }
966
967 sub delete {
968   $lxdebug->enter_sub();
969
970   # $locale->text('Customer deleted!')
971   # $locale->text('Cannot delete customer!')
972   # $locale->text('Vendor deleted!')
973   # $locale->text('Cannot delete vendor!')
974
975   CT->delete(\%myconfig, \%$form);
976
977   $msg = ucfirst $form->{db};
978   $msg .= " deleted!";
979   $form->redirect($locale->text($msg));
980
981   $msg = "Cannot delete $form->{db}";
982   $form->error($locale->text($msg));
983
984   $lxdebug->leave_sub();
985 }
986
987 sub display {
988   $lxdebug->enter_sub();
989
990   &form_header();
991   &form_footer();
992
993   $lxdebug->leave_sub();
994 }
995
996 sub update {
997   $lxdebug->enter_sub();
998
999   &check_salesman($form->{salesman});
1000
1001   #  $form->get_salesman(\%myconfig, $form->{salesman});
1002   &display();
1003   $lxdebug->leave_sub();
1004 }
1005
1006 sub check_salesman {
1007   $lxdebug->enter_sub();
1008
1009   my ($name) = @_;
1010
1011   my ($new_name, $new_id) = split /--/, $form->{$name};
1012   my $i = 0;
1013
1014   # check name, combine name and id
1015   if ($form->{"oldsalesman"} ne $form->{"salesman"}) {
1016
1017     # return one name or a list of names in $form->{name_list}
1018     if (($i = $form->get_salesman(\%myconfig, $name)) > 1) {
1019       &select_salesman($name);
1020       exit;
1021     }
1022
1023     if ($i == 1) {
1024
1025       # we got one name
1026       $form->{"salesman_id"} = $form->{salesman_list}[0]->{id};
1027       $form->{salesman}      = $form->{salesman_list}[0]->{name};
1028       $form->{"oldsalesman"} = $form->{salesman};
1029
1030     } else {
1031
1032       # name is not on file
1033       # $locale->text('Customer not on file!')
1034       # $locale->text('Vendor not on file!')
1035       $msg = ucfirst $name . " not on file or locked!";
1036       $form->error($locale->text($msg));
1037     }
1038   }
1039
1040   $lxdebug->leave_sub();
1041
1042   return $i;
1043 }
1044
1045 sub select_salesman {
1046   $lxdebug->enter_sub();
1047
1048   my ($table) = @_;
1049
1050   @column_index = qw(ndx name);
1051
1052   $label             = ucfirst $table;
1053   $column_data{ndx}  = qq|<th>&nbsp;</th>|;
1054   $column_data{name} =
1055     qq|<th class=listheading>| . $locale->text($label) . qq|</th>|;
1056
1057   # list items with radio button on a form
1058   $form->header;
1059
1060   $title = $locale->text('Select from one of the names below');
1061
1062   print qq|
1063 <body>
1064
1065 <form method=post action=$form->{script}>
1066
1067 <table width=100%>
1068   <tr>
1069     <th class=listtop>$title</th>
1070   </tr>
1071   <tr space=5></tr>
1072   <tr>
1073     <td>
1074       <table width=100%>
1075         <tr class=listheading>|;
1076
1077   map { print "\n$column_data{$_}" } @column_index;
1078
1079   print qq|
1080         </tr>
1081 |;
1082
1083   my $i = 0;
1084   foreach $ref (@{ $form->{salesman_list} }) {
1085     $checked = ($i++) ? "" : "checked";
1086
1087     $ref->{name} =~ s/\"/&quot;/g;
1088
1089     $column_data{ndx} =
1090       qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
1091     $column_data{name} =
1092       qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
1093
1094     $j++;
1095     $j %= 2;
1096     print qq|
1097         <tr class=listrow$j>|;
1098
1099     map { print "\n$column_data{$_}" } @column_index;
1100
1101     print qq|
1102         </tr>
1103
1104 <input name="new_id_$i" type=hidden value=$ref->{id}>
1105
1106 |;
1107
1108   }
1109
1110   print qq|
1111       </table>
1112     </td>
1113   </tr>
1114   <tr>
1115     <td><hr size=3 noshade></td>
1116   </tr>
1117 </table>
1118
1119 <input name=lastndx type=hidden value=$i>
1120
1121 |;
1122
1123   # delete variables
1124   map { delete $form->{$_} } qw(action name_list header);
1125
1126   # save all other form variables
1127   foreach $key (keys %${form}) {
1128     $form->{$key} =~ s/\"/&quot;/g;
1129     print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
1130   }
1131
1132   print qq|
1133 <input type=hidden name=nextsub value=salesman_selected>
1134
1135 <input type=hidden name=vc value=$table>
1136 <br>
1137 <input class=submit type=submit name=action value="|
1138     . $locale->text('Continue') . qq|">
1139 </form>
1140
1141 </body>
1142 </html>
1143 |;
1144
1145   $lxdebug->leave_sub();
1146 }
1147
1148 sub salesman_selected {
1149   $lxdebug->enter_sub();
1150
1151   # replace the variable with the one checked
1152
1153   # index for new item
1154   $i = $form->{ndx};
1155
1156   $form->{salesman}      = $form->{"new_name_$i"};
1157   $form->{"salesman_id"} = $form->{"new_id_$i"};
1158   $form->{"oldsalesman"} = $form->{salesman};
1159
1160   # delete all the new_ variables
1161   for $i (1 .. $form->{lastndx}) {
1162     map { delete $form->{"new_${_}_$i"} } (id, name);
1163   }
1164
1165   map { delete $form->{$_} } qw(ndx lastndx nextsub);
1166
1167   &update(1);
1168
1169   $lxdebug->leave_sub();
1170 }
1171
1172 sub continue { &{ $form->{nextsub} } }