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