Historie eingefügt
[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 use CGI::Ajax;
42 use CGI;
43 use Data::Dumper;
44
45 1;
46
47 # end of main
48
49 sub add {
50   $lxdebug->enter_sub();
51
52   $form->{title} = "Add";
53
54   $form->{callback} =
55     "$form->{script}?action=add&db=$form->{db}&path=$form->{path}&login=$form->{login}&password=$form->{password}"
56     unless $form->{callback};
57
58   CT->taxaccounts(\%myconfig, \%$form);
59
60   &form_header;
61   &form_footer;
62
63   $lxdebug->leave_sub();
64 }
65
66 sub search {
67   $lxdebug->enter_sub();
68
69   $label = ucfirst $form->{db};
70   $form->{title} = $locale->text($label . "s");
71
72   if ($form->{db} eq 'vendor') {
73     $gifi = qq|
74                 <td><input name="l_gifi_accno" type=checkbox class=checkbox value=Y> |
75       . $locale->text('GIFI') . qq|</td>
76 |;
77   }
78
79   $form->header;
80
81   print qq|
82 <body>
83
84 <form method=post action=$form->{script}>
85
86 <input type=hidden name=db value=$form->{db}>
87
88 <table width=100%>
89   <tr>
90     <th class=listtop>$form->{title}</th>
91   </tr>
92   <tr height="5"></tr>
93   <tr valign=top>
94     <td>
95       <table>
96         <tr>
97           <th align=right nowrap>| . $locale->text($label . ' Number') . qq|</th>
98           <td><input name=$form->{db}number size=35></td>
99         </tr>
100         <tr>
101           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
102           <td><input name=name size=35></td>
103         </tr>
104         <tr>
105           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
106           <td><input name=contact size=35></td>
107         </tr>
108         <tr>
109           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
110           <td><input name=email size=35></td>
111         </tr>
112         <tr>
113           <td></td>
114           <td><input name=status class=radio type=radio value=all checked>&nbsp;|
115     . $locale->text('All') . qq|
116           <input name=status class=radio type=radio value=orphaned>&nbsp;|
117     . $locale->text('Orphaned') . qq|</td>
118         </tr>
119         <tr>
120           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
121           <td>
122             <table>
123               <tr>
124                 <td><input name="l_id" type=checkbox class=checkbox value=Y> |
125     . $locale->text('ID') . qq|</td>
126                 <td><input name="l_$form->{db}number" type=checkbox class=checkbox value=Y> |
127     . $locale->text($label . ' Number') . qq|</td>
128                 <td><input name="l_name" type=checkbox class=checkbox value=Y checked> |
129     . $locale->text('Company Name') . qq|</td>
130                 <td><input name="l_address" type=checkbox class=checkbox value=Y> |
131     . $locale->text('Address') . qq|</td>
132               </tr>
133               <tr>
134                 <td><input name="l_contact" type=checkbox class=checkbox value=Y checked> |
135     . $locale->text('Contact') . qq|</td>
136                 <td><input name="l_phone" type=checkbox class=checkbox value=Y checked> |
137     . $locale->text('Phone') . qq|</td>
138                 <td><input name="l_fax" type=checkbox class=checkbox value=Y> |
139     . $locale->text('Fax') . qq|</td>
140                 <td><input name="l_email" type=checkbox class=checkbox value=Y checked> |
141     . $locale->text('E-mail') . qq|</td>
142               </tr>
143               <tr>
144                 <td><input name="l_taxnumber" type=checkbox class=checkbox value=Y> |
145     . $locale->text('Tax Number') . qq|</td>
146                 $gifi
147                 <td><input name="l_sic_code" type=checkbox class=checkbox value=Y> |
148     . $locale->text('SIC') . qq|</td>
149                 <td><input name="l_business" type=checkbox class=checkbox value=Y> |
150     . $locale->text('Type of Business') . qq|</td>
151               </tr>
152               <tr>
153                 <td><input name="l_invnumber" type=checkbox class=checkbox value=Y> |
154     . $locale->text('Invoices') . qq|</td>
155                 <td><input name="l_ordnumber" type=checkbox class=checkbox value=Y> |
156     . $locale->text('Orders') . qq|</td>
157                 <td><input name="l_quonumber" type=checkbox class=checkbox value=Y> |
158     . $locale->text('Quotations') . qq|</td>
159               </tr>
160             </table>
161           </td>
162         </tr>
163       </table>
164     </td>
165   </tr>
166   <tr>
167     <td><hr size=3 noshade></td>
168   </tr>
169 </table>
170
171 <input type=hidden name=nextsub value=list_names>
172
173 <input type=hidden name=path value=$form->{path}>
174 <input type=hidden name=login value=$form->{login}>
175 <input type=hidden name=password value=$form->{password}>
176
177 <br>
178 <input type=submit class=submit name=action value="|
179     . $locale->text('Continue') . qq|">
180 </form>
181
182 </body>
183 </html>
184 |;
185   $lxdebug->leave_sub();
186 }
187
188 sub search_delivery {
189   $lxdebug->enter_sub();
190
191   $label = ucfirst $form->{db};
192   $form->{title} = $locale->text($label . "s");
193
194   if ($form->{db} eq 'vendor') {
195     $gifi = qq|
196                 <td><input name="l_gifi_accno" type=checkbox class=checkbox value=Y> |
197       . $locale->text('GIFI') . qq|</td>
198 |;
199   }
200
201   $form->header;
202
203   print qq|
204 <body>
205
206 <form method=post action=$form->{script}>
207
208 <input type=hidden name=db value=$form->{db}>
209
210 <table width=100%>
211   <tr>
212     <th class=listtop>$form->{title}</th>
213   </tr>
214   <tr height="5"></tr>
215   <tr valign=top>
216     <td>
217       <table>
218         <tr>
219           <th align=right nowrap>| . $locale->text($label . ' Number') . qq|</th>
220           <td><input name=$form->{db}number size=35></td>
221         </tr>
222         <tr>
223           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
224           <td><input name=name size=35></td>
225         </tr>
226         <tr>
227           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
228           <td><input name=contact size=35></td>
229         </tr>
230         <tr>
231           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
232           <td><input name=email size=35></td>
233         </tr>
234         <tr>
235           <td></td>
236           <td><input name=status class=radio type=radio value=all checked>&nbsp;|
237     . $locale->text('All') . qq|
238           <input name=status class=radio type=radio value=orphaned>&nbsp;|
239     . $locale->text('Orphaned') . qq|</td>
240         </tr>
241         <tr>
242           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
243           <td>
244             <table>
245               <tr>
246                 <td><input name="l_id" type=checkbox class=checkbox value=Y> |
247     . $locale->text('ID') . qq|</td>
248                 <td><input name="l_$form->{db}number" type=checkbox class=checkbox value=Y> |
249     . $locale->text($label . ' Number') . qq|</td>
250                 <td><input name="l_name" type=checkbox class=checkbox value=Y checked> |
251     . $locale->text('Company Name') . qq|</td>
252                 <td><input name="l_address" type=checkbox class=checkbox value=Y> |
253     . $locale->text('Address') . qq|</td>
254               </tr>
255               <tr>
256                 <td><input name="l_contact" type=checkbox class=checkbox value=Y checked> |
257     . $locale->text('Contact') . qq|</td>
258                 <td><input name="l_phone" type=checkbox class=checkbox value=Y checked> |
259     . $locale->text('Phone') . qq|</td>
260                 <td><input name="l_fax" type=checkbox class=checkbox value=Y> |
261     . $locale->text('Fax') . qq|</td>
262                 <td><input name="l_email" type=checkbox class=checkbox value=Y checked> |
263     . $locale->text('E-mail') . qq|</td>
264               </tr>
265               <tr>
266                 <td><input name="l_taxnumber" type=checkbox class=checkbox value=Y> |
267     . $locale->text('Tax Number') . qq|</td>
268                 $gifi
269                 <td><input name="l_sic_code" type=checkbox class=checkbox value=Y> |
270     . $locale->text('SIC') . qq|</td>
271                 <td><input name="l_business" type=checkbox class=checkbox value=Y> |
272     . $locale->text('Type of Business') . qq|</td>
273               </tr>
274               <tr>
275                 <td><input name="l_invnumber" type=checkbox class=checkbox value=Y> |
276     . $locale->text('Invoices') . qq|</td>
277                 <td><input name="l_ordnumber" type=checkbox class=checkbox value=Y> |
278     . $locale->text('Orders') . qq|</td>
279                 <td><input name="l_quonumber" type=checkbox class=checkbox value=Y> |
280     . $locale->text('Quotations') . qq|</td>
281               </tr>
282             </table>
283           </td>
284         </tr>
285       </table>
286     </td>
287   </tr>
288   <tr>
289     <td><hr size=3 noshade></td>
290   </tr>
291 </table>
292
293 <input type=hidden name=nextsub value=list_names>
294
295 <input type=hidden name=path value=$form->{path}>
296 <input type=hidden name=login value=$form->{login}>
297 <input type=hidden name=password value=$form->{password}>
298
299 <br>
300 <input type=submit class=submit name=action value="|
301     . $locale->text('Continue') . qq|">
302 </form>
303
304 </body>
305 </html>
306 |;
307   $lxdebug->leave_sub();
308 }
309
310 sub list_names {
311   $lxdebug->enter_sub();
312
313   CT->search(\%myconfig, \%$form);
314
315   $callback =
316     "$form->{script}?action=list_names&db=$form->{db}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}";
317   $href = $callback;
318
319   @columns =
320     $form->sort_columns(id, name,
321                         "$form->{db}number", address,
322                         contact,             phone,
323                         fax,                 email,
324                         taxnumber,           gifi_accno,
325                         sic_code,            business,
326                         invnumber,           ordnumber,
327                         quonumber);
328
329   foreach $item (@columns) {
330     if ($form->{"l_$item"} eq "Y") {
331       push @column_index, $item;
332
333       # add column to href and callback
334       $callback .= "&l_$item=Y";
335       $href     .= "&l_$item=Y";
336     }
337   }
338   $number =
339     ($form->{db} eq "customer")
340     ? $locale->text('Customer Number')
341     : $locale->text('Vendor Number');
342
343   if ($form->{status} eq 'all') {
344     $option = $locale->text('All');
345   }
346   if ($form->{status} eq 'orphaned') {
347     $option .= $locale->text('Orphaned');
348   }
349   if ($form->{name}) {
350     $callback .= "&name=" . $form->escape($form->{name}, 1);
351     $href .= "&name=" . $form->escape($form->{name});
352     $option .= "\n<br>" . $locale->text('Name') . " : $form->{name}";
353   }
354   if ($form->{contact}) {
355     $callback .= "&contact=" . $form->escape($form->{contact}, 1);
356     $href .= "&contact=" . $form->escape($form->{contact});
357     $option .= "\n<br>" . $locale->text('Contact') . " : $form->{contact}";
358   }
359   if ($form->{"$form->{db}number"}) {
360     $callback .=
361       qq|&$form->{db}number=| . $form->escape($form->{"$form->{db}number"}, 1);
362     $href .=
363       "&$form->{db}number=" . $form->escape($form->{"$form->{db}number"});
364     $option .=
365       "\n<br>" . $locale->text('Number') . qq| : $form->{"$form->{db}number"}|;
366   }
367   if ($form->{email}) {
368     $callback .= "&email=" . $form->escape($form->{email}, 1);
369     $href .= "&email=" . $form->escape($form->{email});
370     $option .= "\n<br>" . $locale->text('E-mail') . " : $form->{email}";
371   }
372
373   $form->{callback} = "$callback&sort=$form->{sort}";
374   $callback = $form->escape($form->{callback});
375
376   $column_header{id} =
377     qq|<th class=listheading>| . $locale->text('ID') . qq|</th>|;
378   $column_header{"$form->{db}number"} =
379     qq|<th><a class=listheading href=$href&sort=$form->{db}number>$number</a></th>|;
380   $column_header{name} =
381       qq|<th><a class=listheading href=$href&sort=name>|
382     . $locale->text('Name')
383     . qq|</a></th>|;
384   $column_header{address} =
385       qq|<th><a class=listheading href=$href&sort=address>|
386     . $locale->text('Address')
387     . qq|</a></th>|;
388   $column_header{contact} =
389       qq|<th><a class=listheading href=$href&sort=contact>|
390     . $locale->text('Contact')
391     . qq|</a></th>|;
392   $column_header{phone} =
393       qq|<th><a class=listheading href=$href&sort=phone>|
394     . $locale->text('Phone')
395     . qq|</a></th>|;
396   $column_header{fax} =
397       qq|<th><a class=listheading href=$href&sort=fax>|
398     . $locale->text('Fax')
399     . qq|</a></th>|;
400   $column_header{email} =
401       qq|<th><a class=listheading href=$href&sort=email>|
402     . $locale->text('E-mail')
403     . qq|</a></th>|;
404   $column_header{cc} =
405       qq|<th><a class=listheading href=$href&sort=cc>|
406     . $locale->text('Cc')
407     . qq|</a></th>|;
408
409   $column_header{taxnumber} =
410       qq|<th><a class=listheading href=$href&sort=taxnumber>|
411     . $locale->text('Tax Number')
412     . qq|</a></th>|;
413   $column_header{gifi_accno} =
414       qq|<th><a class=listheading href=$href&sort=gifi_accno>|
415     . $locale->text('GIFI')
416     . qq|</a></th>|;
417   $column_header{sic_code} =
418       qq|<th><a class=listheading href=$href&sort=sic_code>|
419     . $locale->text('SIC')
420     . qq|</a></th>|;
421   $column_header{business} =
422       qq|<th><a class=listheading href=$href&sort=business>|
423     . $locale->text('Type of Business')
424     . qq|</a></th>|;
425
426   $column_header{invnumber} =
427       qq|<th><a class=listheading href=$href&sort=invnumber>|
428     . $locale->text('Invoice')
429     . qq|</a></th>|;
430   $column_header{ordnumber} =
431       qq|<th><a class=listheading href=$href&sort=ordnumber>|
432     . $locale->text('Order')
433     . qq|</a></th>|;
434   $column_header{quonumber} =
435       qq|<th><a class=listheading href=$href&sort=quonumber>|
436     . $locale->text('Quotation')
437     . qq|</a></th>|;
438
439   $label = ucfirst $form->{db} . "s";
440   $form->{title} = $locale->text($label);
441
442   $form->header;
443
444   print qq|
445 <body>
446
447 <table width=100%>
448   <tr>
449     <th class=listtop>$form->{title}</th>
450   </tr>
451   <tr height="5"></tr>
452   <tr>
453     <td>$option</td>
454   </tr>
455   <tr>
456     <td>
457       <table width=100%>
458         <tr class=listheading>
459 |;
460
461   map { print "$column_header{$_}\n" } @column_index;
462
463   print qq|
464         </tr>
465 |;
466
467   $ordertype = ($form->{db} eq 'customer') ? 'sales_order' : 'purchase_order';
468   $quotationtype =
469     ($form->{db} eq 'customer') ? 'sales_quotation' : 'request_quotation';
470
471   foreach $ref (@{ $form->{CT} }) {
472
473     if ($ref->{id} eq $sameid) {
474       map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
475     } else {
476       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
477
478       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
479         (invnumber, ordnumber, quonumber);
480
481       $column_data{name} =
482         "<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>";
483
484       if ($ref->{email}) {
485         $email = $ref->{email};
486         $email =~ s/</\&lt;/;
487         $email =~ s/>/\&gt;/;
488
489         $column_data{email} =
490           qq|<td><a href="mailto:$ref->{email}">$email</a></td>|;
491       }
492
493     }
494
495     if ($ref->{formtype} eq 'invoice') {
496       $column_data{invnumber} =
497         "<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>";
498     }
499
500     if ($ref->{formtype} eq 'order') {
501       $column_data{ordnumber} =
502         "<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>";
503     }
504
505     if ($ref->{formtype} eq 'quotation') {
506       $column_data{quonumber} =
507         "<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>";
508     }
509
510     $i++;
511     $i %= 2;
512     print "
513         <tr class=listrow$i>
514 ";
515
516     map { print "$column_data{$_}\n" } @column_index;
517
518     print qq|
519         </tr>
520 |;
521
522     $sameid = $ref->{id};
523
524   }
525
526   print qq|
527       </table>
528     </td>
529   </tr>
530   <tr>
531     <td><hr size=3 noshade></td>
532   </tr>
533 </table>
534
535 <br>
536 <form method=post action=$form->{script}>
537
538 <input name=callback type=hidden value="$form->{callback}">
539 <input name=db type=hidden value=$form->{db}>
540
541 <input type=hidden name=path value=$form->{path}>
542 <input type=hidden name=login value=$form->{login}>
543 <input type=hidden name=password value=$form->{password}>
544
545 <input class=submit type=submit name=action value="|
546     . $locale->text('Add') . qq|">
547
548   </form>
549
550 </body>
551 </html>
552 |;
553
554   $lxdebug->leave_sub();
555 }
556
557 sub edit {
558   $lxdebug->enter_sub();
559
560   # show history button
561   $form->{javascript} = qq|<script type=text/javascript src=js/show_history.js></script>|;
562   #/show hhistory button
563   
564   # $locale->text('Edit Customer')
565   # $locale->text('Edit Vendor')
566
567   CT->get_tuple(\%myconfig, \%$form);
568
569   # format " into &quot;
570   map { $form->{$_} =~ s/\"/&quot;/g } keys %$form;
571
572   $form->{title} = "Edit";
573
574   # format discount
575   $form->{discount} *= 100;
576
577   &form_header;
578   &form_footer;
579
580   $lxdebug->leave_sub();
581 }
582
583 sub form_header {
584   $lxdebug->enter_sub();
585
586   $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
587   $form->{creditlimit} =
588     $form->format_amount(\%myconfig, $form->{creditlimit}, 0);
589   $form->{discount} = $form->format_amount(\%myconfig, $form->{discount});
590
591   if ($myconfig{role} eq 'admin') {
592     $bcc = qq|
593         <tr>
594           <th align=right nowrap>| . $locale->text('Bcc') . qq|</th>
595           <td><input name=bcc size=35 value="$form->{bcc}"></td>
596         </tr>
597 |;
598   }
599   $form->{obsolete} = "checked" if $form->{obsolete};
600
601   $lang = qq|<option value=""></option>|;
602   foreach $item (@{ $form->{languages} }) {
603     if ($form->{language_id} eq $item->{id}) {
604       $lang .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
605     } else {
606       $lang .= qq|<option value="$item->{id}">$item->{description}</option>|;
607     }
608   }
609
610   $payment = qq|<option value=""></option>|;
611   foreach $item (@{ $form->{payment_terms} }) {
612     if ($form->{payment_id} eq $item->{id}) {
613       $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
614     } else {
615       $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
616     }
617   }
618
619   if (!$form->{id}) {
620     if ($form->{db} eq "customer") {
621       $form->{taxzone_id} = 0;
622     } else {
623       $form->{taxzone_id} = 0;
624     }
625   }
626
627   if (@{ $form->{TAXZONE} }) {
628     foreach $item (@{ $form->{TAXZONE} }) {
629       if ($item->{id} == $form->{taxzone_id}) {
630         $form->{selecttaxzone} .=
631           "<option value=$item->{id} selected>$item->{description}\n";
632       } else {
633         $form->{selecttaxzone} .=
634           "<option value=$item->{id}>$item->{description}\n";
635       }
636
637     }
638   }
639
640   $taxzone = qq|
641               <tr>
642                 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
643                 <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
644                 <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
645               </tr>|;
646
647   $get_contact_url =
648     "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=get_contact";
649
650   my $pjx = new CGI::Ajax( 'get_contact' => $get_contact_url );
651   $form->{selectcontact} = "<option value=0></option>";
652   if (@{ $form->{CONTACTS} }) {
653     foreach $item (@{ $form->{CONTACTS} }) {
654       if ($item->{cp_id} == $form->{cp_id}) {
655         $form->{selectcontact} .=
656           qq|<option value=$item->{cp_id} selected>$item->{cp_name}</option>\n|;
657       } else {
658         $form->{selectcontact} .=
659           qq|<option value=$item->{cp_id}>$item->{cp_name}</option>\n|;
660       }
661
662     }
663   }
664   push(@ { $form->{AJAX} }, $pjx);
665   $ansprechpartner = qq|
666               <tr>
667                 <th align=right>| . $locale->text('Ansprechpartner') . qq|</th>
668                 <td><select id=cp_id name=cp_id onChange="get_contact(['cp_id__' + this.value], ['cp_name', 'cp_greeting', 'cp_title', 'cp_givenname', 'cp_phone1', 'cp_phone2', 'cp_email', 'cp_abteilung', 'cp_fax', 'cp_mobile1', 'cp_mobile2', 'cp_satphone', 'cp_satfax', 'cp_project', 'cp_privatphone', 'cp_privatemail', 'cp_birthday'])">$form->{selectcontact}</select></td>
669                 <input type=hidden name=selectcontact value="$form->{selectcontact}">
670               </tr>|;
671   $get_shipto_url =
672     "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=get_shipto";
673
674   my $pjy = new CGI::Ajax( 'get_shipto' => $get_shipto_url );
675   $form->{selectshipto} = "<option value=0></option>";
676   $form->{selectshipto} .= "<option value=0>Alle</option>";
677   if (@{ $form->{SHIPTO} }) {
678     foreach $item (@{ $form->{SHIPTO} }) {
679       if ($item->{shipto_id} == $form->{shipto_id}) {
680         $form->{selectshipto} .=
681           "<option value=$item->{shipto_id} selected>$item->{shiptoname} $item->{shiptodepartment_1}\n";
682       } else {
683         $form->{selectshipto} .=
684           "<option value=$item->{shipto_id}>$item->{shiptoname} $item->{shiptodepartment_1}\n";
685       }
686
687     }
688   }
689   push(@ { $form->{AJAX} }, $pjy);
690
691   $shipto = qq|
692               <tr>
693                 <th align=right>| . $locale->text('Shipping Address') . qq|</th>
694                 <td><select id=shipto_id name=shipto_id onChange="get_shipto(['shipto_id__' + this.value], ['shiptoname','shiptodepartment_1', 'shiptodepartment_2','shiptostreet','shiptozipcode','shiptocity','shiptocountry','shiptocontact','shiptophone','shiptofax','shiptoemail'])">$form->{selectshipto}</select></td>
695                 <input type=hidden name=selectshipto value="$form->{selectshipto}">
696               </tr>|;
697
698
699   $get_delivery_url =
700     "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=get_delivery";
701
702   my $pjz = new CGI::Ajax( 'get_delivery' => $get_delivery_url );
703
704   push(@ { $form->{AJAX} }, $pjz);
705
706   $delivery = qq|
707               <tr>
708                 <th align=right>| . $locale->text('Shipping Address') . qq|</th>
709                 <td><select id=delivery_id name=delivery_id onChange="get_delivery(['shipto_id__' + this.value, 'from__' + from.value, 'to__' + to.value, 'id__' + cvid.value, 'db__' + db.value], ['delivery'])">$form->{selectshipto}</select></td>
710               </tr>|;
711
712   foreach $item (split / /, $form->{taxaccounts}) {
713     if (($form->{tax}{$item}{taxable}) || !($form->{id})) {
714       $taxable .=
715         qq| <input name="tax_$item" value=1 class=checkbox type=checkbox checked>&nbsp;<b>$form->{tax}{$item}{description}</b>|;
716     } else {
717       $taxable .=
718         qq| <input name="tax_$item" value=1 class=checkbox type=checkbox>&nbsp;<b>$form->{tax}{$item}{description}</b>|;
719     }
720   }
721
722 ##LINET
723   $taxable = "";
724
725   if ($taxable) {
726     $tax = qq|
727   <tr>
728     <th align=right>| . $locale->text('Taxable') . qq|</th>
729     <td colspan=2>
730       <table>
731         <tr>
732           <td>$taxable</td>
733           <td><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
734           <th align=left>| . $locale->text('Tax Included') . qq|</th>
735         </tr>
736       </table>
737     </td>
738   </tr>
739 |;
740   }
741   $form->{selectbusiness} = qq|<option>\n|;
742   map {
743     $form->{selectbusiness} .=
744       qq|<option value=$_->{id}>$_->{description}\n|
745   } @{ $form->{all_business} };
746   if ($form->{business_save}) {
747     $form->{selectbusiness} = $form->{business_save};
748   }
749   $form->{selectbusiness} =~
750     s/<option value=$form->{business}>/<option value=$form->{business} selected>/;
751
752   $label = ucfirst $form->{db};
753   if ($form->{title} eq "Edit") {
754     $form->{title} = $locale->text("$form->{title} $label") . " $form->{name}";
755   } else  {
756     $form->{title} = $locale->text("$form->{title} $label");
757   }
758   if ($form->{title_save}) {
759     $form->{title} = $form->{title_save};
760   }
761   if ($form->{db} eq 'vendor') {
762     $customer = qq|
763            <th align=right>| . $locale->text('Kundennummer') . qq|</th>
764            <td><input name=v_customer_id size=10 tabindex=18 maxlength=35 value="$form->{v_customer_id}"></td>
765 |;
766   }
767
768   if ($form->{db} eq 'customer') {
769
770     $customer = qq|
771            <th align=right>| . $locale->text('KNr. beim Kunden') . qq|</th>
772            <td><input name=c_vendor_id size=10 tabindex=18 maxlength=35 value="$form->{c_vendor_id}"></td>
773 |;
774   }
775   $business_salesman = "";
776   $business          = "<th></th><td></td>";
777   if ($vertreter) {
778     $business_salesman = qq|
779         <tr>
780           <td colspan=3>
781             <table>
782              <th align=right>| . $locale->text('Type of Business') . qq|</th>
783              <td><select name=business tabindex=1>$form->{selectbusiness}</select></td>
784              <th align=right>| . $locale->text('Salesman') . qq|</th>
785              <td><input name=salesman tabindex=2 value="$form->{salesman}"></td>
786              <input type=hidden name=salesman_id value="$form->{salesman_id}">
787              <input type=hidden name=oldsalesman value="$form->{oldsalesman}">
788             </table>
789           </td>
790        <tr>|;
791     $business = qq|
792              <th align=right>| . $locale->text('Username') . qq|</th>
793              <td><input name=username maxlength=50 tabindex=22 value="$form->{username}"></td>
794              <th align=right>| . $locale->text('Password') . qq|</th>
795              <td><input name=user_password maxlength=12 tabindex=23 value="$form->{user_password}"></td>|;
796   } else {
797     $business = qq|
798           <th align=right>| . $locale->text('Type of Business') . qq|</th>
799           <td><select name=business tabindex=22>$form->{selectbusiness}</select></td>
800       |;
801   }
802
803 ## LINET: Create a drop-down box with all prior titles and greetings.
804   CT->query_titles_and_greetings(\%myconfig, \%$form);
805
806   $select_title = qq|&nbsp;<select name=selected_cp_title><option></option>|;
807   map({ $select_title .= qq|<option>$_</option>|; } @{ $form->{TITLES} });
808   $select_title .= qq|</select>|;
809
810   $select_greeting =
811     qq|&nbsp;<select name=selected_cp_greeting><option></option>|;
812   map(
813      { $select_greeting .= qq|<option>$_</option>|; } @{ $form->{GREETINGS} });
814   $select_greeting .= qq|</select>|;
815
816   $select_company_greeting =
817     qq|&nbsp;<select name=selected_company_greeting><option></option>|;
818   map(
819      { $select_company_greeting .= qq|<option>$_</option>|; } @{ $form->{COMPANY_GREETINGS} });
820   $select_company_greeting .= qq|</select>|;
821
822   $select_department =
823     qq|&nbsp;<select name=selected_cp_abteilung><option></option>|;
824   map(
825      { $select_department .= qq|<option>$_</option>|; } @{ $form->{DEPARTMENT} });
826   $select_department .= qq|</select>|;
827 ## /LINET
828
829   if ($form->{db} eq 'customer') {
830
831     #get pricegroup and form it
832     $form->get_pricegroup(\%myconfig, { all => 1 });
833
834     $form->{pricegroup}    = "$form->{klass}";
835     $form->{pricegroup_id} = "$form->{klass}";
836
837     if (@{ $form->{all_pricegroup} }) {
838
839       $form->{selectpricegroup} = qq|<option>\n|;
840       map {
841         $form->{selectpricegroup} .=
842           qq|<option value="$_->{id}">$_->{pricegroup}\n|
843       } @{ $form->{all_pricegroup} };
844     }
845
846     if ($form->{selectpricegroup}) {
847       $form->{selectpricegroup} = $form->unescape($form->{selectpricegroup});
848
849       $pricegroup =
850         qq|<input type=hidden name=selectpricegroup value="|
851         . $form->escape($form->{selectpricegroup}, 1) . qq|">|;
852
853       $form->{selectpricegroup} =~
854         s/(<option value="\Q$form->{klass}\E")/$1 selected/;
855
856       $pricegroup .=
857         qq|<select name=klass tabindex=24>$form->{selectpricegroup}</select>|;
858
859     }
860   }
861
862   # $locale->text('Customer Number')
863   # $locale->text('Vendor Number')
864   $form->{fokus} = "ct.greeting";
865   $form->{jsscript} = 1;
866   $form->header;
867
868   print qq|
869 <body onLoad="fokus()">
870 <table width=100%>
871   <tr>
872     <th class=listtop>$form->{title}</th>
873   </tr>
874 </table>
875
876
877 <form method=post name="ct" action=$form->{script} onKeyUp="highlight(event)" onClick="highlight(event)">
878
879
880
881 <ul id="maintab" class="shadetabs">
882 <li class="selected"><a href="#" rel="billing">|
883     . $locale->text('Billing Address') . qq|</a></li>
884 <li><a href="#" rel="shipto">|
885     . $locale->text('Shipping Address') . qq|</a></li>
886 <li><a href="#" rel="contacts">Ansprechpartner</a></li>
887 <li><a href="#" rel="deliveries">|
888     . $locale->text('Lieferungen') . qq|</a></li>
889
890 </ul>
891
892 <div class="tabcontentstyle">
893
894 <div id="billing" class="tabcontent">
895
896       <table width=100%>
897         <tr height="5"></tr>
898         $business_salesman
899         <tr>
900           <th align=right nowrap>| . $locale->text($label . ' Number') . qq|</th>
901           <td><input name="$form->{db}number" size=35 maxlength=35 value="$form->{"$form->{db}number"}"></td>
902         </tr>
903         <tr>
904           <th align=right nowrap>| . $locale->text('Greeting') . qq|</th>
905           <td><input id=greeting name=greeting size=30 maxlength=30 value="$form->{greeting}">&nbsp;
906           $select_company_greeting</td>
907         </tr>
908         <tr>
909           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
910           <td><input name=name size=35 maxlength=75 value="$form->{name}"></td>
911         </tr>
912         <tr>
913           <th align=right nowrap>| . $locale->text('Abteilung') . qq|</th>
914           <td><input name=department_1 size=16 maxlength=75 value="$form->{department_1}">
915           <input name=department_2 size=16 maxlength=75 value="$form->{department_2}"></td>
916         </tr>
917         <tr>
918           <th align=right nowrap>| . $locale->text('Street') . qq|</th>
919           <td><input name=street size=35 maxlength=75 value="$form->{street}"></td>
920         </tr>
921         <tr>
922           <th align=right nowrap>|
923     . $locale->text('Zipcode') . "/" . $locale->text('City') . qq|</th>
924           <td><input name=zipcode size=5 maxlength=10 value="$form->{zipcode}">
925           <input name=city size=30 maxlength=75 value="$form->{city}"></td>
926         </tr>
927         <tr>
928           <th align=right nowrap>| . $locale->text('Country') . qq|</th>
929           <td><input name=country size=35 maxlength=75 value="$form->{country}"></td>
930         </tr>
931         <tr>
932           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
933           <td><input name=contact size=28 maxlength=75 value="$form->{contact}"></td>
934         </tr>
935         <tr>
936           <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
937           <td><input name=phone size=30 maxlength=30 value="$form->{phone}"></td>
938         </tr>
939         <tr>
940           <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
941           <td><input name=fax size=30 maxlength=30 value="$form->{fax}"></td>
942         </tr>
943         <tr>
944           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
945           <td><input name=email size=45 value="$form->{email}"></td>
946         </tr>
947         <tr>
948           <th align=right nowrap>| . $locale->text('Homepage') . qq|</th>
949           <td><input name=homepage size=45 value="$form->{homepage}"></td>
950         </tr>
951 </table>
952 <table>
953         <tr>
954           <th align=right>| . $locale->text('Credit Limit') . qq|</th>
955           <td><input name=creditlimit size=9 value="$form->{creditlimit}"></td>
956           <input type="hidden" name="terms" value="$form->{terms}">
957           <th align=right>| . $locale->text('Payment Terms') . qq|</th>
958           <td><select name=payment_id>$payment</select></td>
959           <th align=right>| . $locale->text('Discount') . qq|</th>
960           <td><input name=discount size=4 value="$form->{discount}">
961           %</td>
962         </tr>
963         <tr>
964           <th align=right>| . $locale->text('Tax Number / SSN') . qq|</th>
965           <td><input name=taxnumber size=20 value="$form->{taxnumber}"></td>
966           <th align=right>| . $locale->text('USt-IdNr.') . qq|</th>
967           <td><input name="ustid" maxlength="14" size="20" value="$form->{ustid}"></td>
968           $customer
969         </tr>
970         <tr>
971           <th align=right>| . $locale->text('Account Number') . qq|</th>
972           <td><input name=account_number size=10 value="$form->{account_number}"></td>
973           <th align=right>| . $locale->text('Bank Code Number') . qq|</th>
974           <td><input name=bank_code size=10 value="$form->{bank_code}"></td>
975           <th align=right>| . $locale->text('Bank') . qq|</th>
976           <td><input name=bank size=30 value="$form->{bank}"></td>
977         </tr>
978         <tr>
979           $business
980           <th align=right>| . $locale->text('Language') . qq|</th>
981           <td><select name=language_id tabindex=23>$lang
982                           </select></td>|;
983
984   if ($form->{db} eq 'customer') {
985
986     print qq|
987           <th align=right>| . $locale->text('Preisklasse') . qq|</th>
988           <td>$pricegroup</td>|;
989   }
990   print qq|        </tr>
991         <tr>
992           <td align=right>| . $locale->text('Obsolete') . qq|</td>
993           <td><input name=obsolete class=checkbox type=checkbox value=1 $form->{obsolete}></td>
994         </tr>
995         $taxzone
996       </table>
997   <table>
998   <tr>
999     <th align=left nowrap>| . $locale->text('Notes') . qq|</th>
1000   </tr>
1001   <tr>
1002     <td><textarea name=notes rows=3 cols=60 wrap=soft>$form->{notes}</textarea></td>
1003   </tr>
1004
1005             </table>
1006           </td>
1007         </tr>
1008 </table>
1009 <br style="clear: left" /></div>|;
1010
1011 print qq|
1012       <div id="shipto" class="tabcontent">
1013
1014       <table width=100%>
1015 $shipto
1016         <tr>
1017           <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
1018           <td><input id=shiptoname name=shiptoname size=35 maxlength=75 value="$form->{shiptoname}"></td>
1019         </tr>
1020         <tr>
1021           <th align=right nowrap>| . $locale->text('Abteilung') . qq|</th>
1022           <td><input id=shiptodepartment_1 name=shiptodepartment_1 size=16 maxlength=75 value="$form->{shiptodepartment_1}">
1023           <input id=shiptodepartment_2 name=shiptodepartment_2 size=16 maxlength=75 value="$form->{shiptodepartment_2}"></td>
1024         </tr>
1025         <tr>
1026           <th align=right nowrap>| . $locale->text('Street') . qq|</th>
1027           <td><input id=shiptostreet name=shiptostreet size=35 maxlength=75 value="$form->{shiptostreet}"></td>
1028         </tr>
1029         <tr>
1030           <th align=right nowrap>|
1031     . $locale->text('Zipcode') . "/" . $locale->text('City') . qq|</th>
1032           <td><input id=shiptozipcode name=shiptozipcode size=5 maxlength=10 value="$form->{shiptozipcode}">
1033           <input id=shiptocity name=shiptocity size=30 maxlength=75 value="$form->{shiptocity}"></td>
1034         </tr>
1035         <tr>
1036           <th align=right nowrap>| . $locale->text('Country') . qq|</th>
1037           <td><input id=shiptocountry name=shiptocountry size=35 maxlength=35 value="$form->{shiptocountry}"></td>
1038         </tr>
1039         <tr>
1040           <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
1041           <td><input id=shiptocontact name=shiptocontact size=30 maxlength=75 value="$form->{shiptocontact}"></td>
1042         </tr>
1043         <tr>
1044           <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
1045           <td><input id=shiptophone name=shiptophone size=30 maxlength=30 value="$form->{shiptophone}"></td>
1046         </tr>
1047         <tr>
1048           <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
1049           <td><input id=shiptofax name=shiptofax size=30 maxlength=30 value="$form->{shiptofax}"></td>
1050         </tr>
1051         <tr>
1052           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
1053           <td><input id=shiptoemail name=shiptoemail size=45 value="$form->{shiptoemail}"></td>
1054         </tr>
1055         <tr>
1056           <td>&nbsp;</td>
1057         </tr>
1058         <tr>
1059            <td>&nbsp;</td>
1060        </tr>
1061
1062     </table>
1063 <br style="clear: left" /></div>|;
1064
1065
1066 ##LINET - added fields for contact person
1067   print qq|   
1068 <div id="contacts" class="tabcontent">
1069 <table>
1070     <tr>
1071          <td colspan=3>
1072                 <input type=hidden name=cp_id value=$form->{cp_id}>
1073                 <table>
1074                 $ansprechpartner
1075                 <tr>
1076                   <th align=left nowrap>| . $locale->text('Greeting') . qq|</th>
1077                   <td><input id=cp_greeting name=cp_greeting size=30 maxlength=30 value="$form->{cp_greeting}">&nbsp;
1078                   $select_greeting</td>
1079                 </tr>
1080                 <tr>
1081                   <th align=left nowrap>| . $locale->text('Title') . qq|</th>
1082                   <td><input id=cp_title name=cp_title size=30 maxlength=30 value="$form->{cp_title}">&nbsp;
1083                   $select_title</td>
1084                 </tr>
1085                 <tr>
1086                   <th align=left nowrap>| . $locale->text('Department') . qq|</th>
1087                   <td><input id=cp_abteilung name=cp_abteilung size=30 maxlength=40 value="$form->{cp_abteilung}">&nbsp;
1088                   $select_department</td>
1089                 </tr>
1090                 <tr>
1091                   <th align=left nowrap>|
1092     . $locale->text('Given Name') . qq|</th>
1093                   <td><input id=cp_givenname name=cp_givenname size=30 maxlength=40 value="$form->{cp_givenname}"></td>
1094                 </tr>
1095                 <tr>
1096                   <th align=left nowrap>| . $locale->text('Name') . qq|</th>
1097                   <td><input id=cp_name name=cp_name size=30 maxlength=40 value="$form->{cp_name}"></td>
1098                 </tr>
1099                 <tr>
1100                   <th align=left nowrap>| . $locale->text('Phone1') . qq|</th>
1101                   <td><input id=cp_phone1 name=cp_phone1 size=30 maxlength=30 value="$form->{cp_phone1}"></td>
1102                 </tr>
1103                 <tr>
1104                   <th align=left nowrap>| . $locale->text('Phone2') . qq|</th>
1105                   <td><input id=cp_phone2 name=cp_phone2 size=30 maxlength=30 value="$form->{cp_phone2}"></td>
1106                 </tr>
1107                 <tr>
1108                   <th align=left nowrap>| . $locale->text('Fax') . qq|</th>
1109                   <td><input id=cp_fax name=cp_fax size=30 maxlength=30 value="$form->{cp_fax}"></td>
1110                 </tr>
1111                 <tr>
1112                   <th align=left nowrap>| . $locale->text('Mobile1') . qq|</th>
1113                   <td><input id=cp_mobile1 name=cp_mobile1 size=30 maxlength=30 value="$form->{cp_mobile1}"></td>
1114                 </tr>
1115                 <tr>
1116                   <th align=left nowrap>| . $locale->text('Mobile2') . qq|</th>
1117                   <td><input id=cp_mobile2 name=cp_mobile2 size=30 maxlength=30 value="$form->{cp_mobile2}"></td>
1118                 </tr>
1119                 <tr>
1120                   <th align=left nowrap>| . $locale->text('Sat. Phone') . qq|</th>
1121                   <td><input id=cp_satphone name=cp_satphone size=30 maxlength=30 value="$form->{cp_satphone}"></td>
1122                 </tr>
1123                 <tr>
1124                   <th align=left nowrap>| . $locale->text('Sat. Fax') . qq|</th>
1125                   <td><input id=cp_satfax name=cp_satfax size=30 maxlength=30 value="$form->{cp_satfax}"></td>
1126                 </tr>
1127                 <tr>
1128                   <th align=left nowrap>| . $locale->text('Project') . qq|</th>
1129                   <td><input id=cp_project name=cp_project size=30 maxlength=40 value="$form->{cp_project}"></td>
1130                 </tr>
1131                 <tr>
1132                   <th align=left nowrap>| . $locale->text('E-mail') . qq|</th>
1133                   <td><input id=cp_email name=cp_email size=30 maxlength=40 value="$form->{cp_email}"></td>
1134                 </tr>
1135                 <tr>
1136                   <th align=left nowrap>| . $locale->text('Private Phone') . qq|</th>
1137                   <td><input id=cp_privatphone name=cp_privatphone size=30 maxlength=40 value="$form->{cp_privatphone}"></td>
1138                 </tr>
1139                 <tr>
1140                   <th align=left nowrap>| . $locale->text('Private E-mail') . qq|</th>
1141                   <td><input id=cp_privatemail name=cp_privatemail size=30 maxlength=40 value="$form->{cp_privatemail}"></td>
1142                 </tr>
1143                 <tr>
1144                   <th align=left nowrap>| . $locale->text('Birthday') . qq|</th>
1145                   <td><input id=cp_birthday name=cp_birthday size=30 maxlength=40 value="$form->{cp_birthday}"></td>
1146                 </tr>
1147                 
1148           </table>
1149         </td>
1150         </tr>
1151         <tr height="5"></tr>|;
1152 ##/LINET
1153   print qq|        $bcc
1154         $tax
1155       </table>
1156     </td>
1157   </tr>
1158   <tr>
1159     <td>
1160       
1161 <br style="clear: left" /></div>
1162 <div id="deliveries" class="tabcontent">
1163   <table>
1164     $delivery
1165     <tr>
1166       <th align=left nowrap>| . $locale->text('From') . qq|</th>
1167       <td><input id=from name=from size=10 maxlength=10 value="$form->{from}">
1168         <input type="button" name="fromB" id="trigger_from" value="?"></td>
1169       <th align=left nowrap>| . $locale->text('To (time)') . qq|</th>
1170       <td><input id=to name=to size=10 maxlength=10 value="$form->{to}">
1171         <input type="button" name="toB" id="trigger_to" value="?"></td>
1172     </tr>       
1173     <tr>
1174      <td colspan=4>
1175       <div id=delivery>
1176       </div>
1177       </td>
1178     </tr>
1179   </table>
1180 <br style="clear: left" /></div>
1181
1182 </div>
1183
1184 | . $form->write_trigger(\%myconfig, 2, "fromB", "BL", "trigger_from",
1185                          "toB", "BL", "trigger_to");
1186
1187   $lxdebug->leave_sub();
1188 }
1189
1190 sub form_footer {
1191   $lxdebug->enter_sub();
1192
1193   $label     = ucfirst $form->{db};
1194   $quotation =
1195     ($form->{db} eq 'customer')
1196     ? $locale->text('Save and Quotation')
1197     : $locale->text('Save and RFQ');
1198   $arap =
1199     ($form->{db} eq 'customer')
1200     ? $locale->text('Save and AR Transaction')
1201     : $locale->text('Save and AP Transaction');
1202   if ($vertreter) {
1203     $update_button =
1204       qq|<input class=submit type=submit name=action accesskey="u" value="|
1205       . $locale->text("Update") . qq|">|;
1206   } else {
1207     $update_button = "";
1208   }
1209
1210 ##<input class=submit type=submit name=action value="|.$locale->text("Save and Quotation").qq|">
1211 ##<input class=submit type=submit name=action value="|.$locale->text("Save and RFQ").qq|">
1212 ##<input class=submit type=submit name=action value="|.$locale->text("Save and AR Transaction").qq|">
1213 ##<input class=submit type=submit name=action value="|.$locale->text("Save and AP Transaction").qq|">
1214
1215   print qq|
1216 <input name=id type=hidden id=cvid value=$form->{id}>
1217 <input name=taxaccounts type=hidden value="$form->{taxaccounts}">
1218 <input name=business_save type=hidden value="$form->{selectbusiness}">
1219 <input name=title_save type=hidden value="$form->{title}">
1220
1221 <input type=hidden name=path value=$form->{path}>
1222 <input type=hidden name=login value=$form->{login}>
1223 <input type=hidden name=password value=$form->{password}>
1224
1225 <input type=hidden name=callback value="$form->{callback}">
1226 <input type=hidden name=db id=db value=$form->{db}>
1227
1228
1229
1230 <br>
1231 $update_button
1232 <input class=submit type=submit name=action accesskey="s" value="|
1233     . $locale->text("Save") . qq|">
1234 <input class=submit type=submit name=action accesskey="s" value="|
1235     . $locale->text("Save and Close") . qq|">
1236 <input class=submit type=submit name=action value="$arap">
1237 <input class=submit type=submit name=action value="|
1238     . $locale->text("Save and Invoice") . qq|">
1239 <input class=submit type=submit name=action value="|
1240     . $locale->text("Save and Order") . qq|">
1241 <input class=submit type=submit name=action value="$quotation">
1242 |;
1243
1244   if ($form->{id} && $form->{status} eq 'orphaned') {
1245     print qq|<input class=submit type=submit name=action value="|
1246       . $locale->text('Delete')
1247       . qq|">\n|;
1248   }
1249
1250   # button for saving history
1251   if($form->{id} ne "") {
1252     print qq|
1253           <input type=button class=submit onclick=set_history_window(|
1254           . $form->{id} 
1255           . qq|); name=history id=history value=|
1256           . $locale->text('history') 
1257           . qq|>|;
1258   }
1259   # /button for saving history
1260
1261   print qq|
1262
1263   </form>
1264 <script type="text/javascript">
1265 //Start Tab Content script for UL with id="maintab" Separate multiple ids each with a comma.
1266 initializetabcontent("maintab")
1267 </script>
1268 </body>
1269 </html>
1270 |;
1271
1272   $lxdebug->leave_sub();
1273 }
1274
1275 sub add_transaction {
1276   $lxdebug->enter_sub();
1277
1278 #  # saving the history
1279 #  if(!exists $form->{addition}) {
1280 #       $form->{addition} = "ADD TRANSACTION";
1281 #       $form->save_history($form->dbconnect(\%myconfig));
1282 #  }
1283 #  # /saving the history
1284   
1285   $form->isblank("name", $locale->text("Name missing!"));
1286   if ($vertreter && $form->{db} eq "customer") {
1287     $form->isblank("salesman_id", $locale->text("Salesman missing!"));
1288   }
1289   &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
1290
1291   $form->{callback} = $form->escape($form->{callback}, 1);
1292   $name = $form->escape("$form->{name}", 1);
1293
1294   $form->{callback} =
1295     "$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}";
1296   $form->redirect;
1297
1298   $lxdebug->leave_sub();
1299 }
1300
1301 sub save_and_ap_transaction {
1302   $lxdebug->enter_sub();
1303
1304   $form->{script} = "ap.pl";
1305   # saving the history
1306   if(!exists $form->{addition}) {
1307         $form->{addition} = "SAVED";
1308         $form->save_history($form->dbconnect(\%myconfig));
1309   }
1310   # /saving the history
1311   &add_transaction;
1312   $lxdebug->leave_sub();
1313 }
1314
1315 sub save_and_ar_transaction {
1316   $lxdebug->enter_sub();
1317
1318   $form->{script} = "ar.pl";
1319   # saving the history
1320   if(!exists $form->{addition}) {
1321         $form->{addition} = "SAVED";
1322         $form->save_history($form->dbconnect(\%myconfig));
1323   }
1324   # /saving the history
1325   &add_transaction;
1326   $lxdebug->leave_sub();
1327 }
1328
1329 sub save_and_invoice {
1330   $lxdebug->enter_sub();
1331
1332   $form->{script} = ($form->{db} eq 'customer') ? "is.pl" : "ir.pl";
1333   $form->{type} = "invoice";
1334   # saving the history
1335   if(!exists $form->{addition}) {
1336         $form->{addition} = "SAVED";
1337         $form->save_history($form->dbconnect(\%myconfig));
1338   }
1339   # /saving the history
1340   &add_transaction;
1341   $lxdebug->leave_sub();
1342 }
1343
1344 sub save_and_rfq {
1345   $lxdebug->enter_sub();
1346
1347   $form->{script} = "oe.pl";
1348   $form->{type}   = "request_quotation";
1349   # saving the history
1350   if(!exists $form->{addition}) {
1351         $form->{addition} = "SAVED";
1352         $form->save_history($form->dbconnect(\%myconfig));
1353   }
1354   # /saving the history
1355   &add_transaction;
1356   $lxdebug->leave_sub();
1357 }
1358
1359 sub save_and_quotation {
1360   $lxdebug->enter_sub();
1361
1362   $form->{script} = "oe.pl";
1363   $form->{type}   = "sales_quotation";
1364   # saving the history
1365   if(!exists $form->{addition}) {
1366         $form->{addition} = "SAVED";
1367         $form->save_history($form->dbconnect(\%myconfig));
1368   }
1369   # /saving the history
1370   &add_transaction;
1371   $lxdebug->leave_sub();
1372 }
1373
1374 sub save_and_order {
1375   $lxdebug->enter_sub();
1376
1377   $form->{script} = "oe.pl";
1378   $form->{type}   =
1379     ($form->{db} eq 'customer') ? "sales_order" : "purchase_order";
1380   # saving the history
1381   if(!exists $form->{addition}) {
1382         $form->{addition} = "SAVED";
1383         $form->save_history($form->dbconnect(\%myconfig));
1384   }
1385   # /saving the history
1386   &add_transaction;
1387   $lxdebug->leave_sub();
1388 }
1389
1390 sub save_and_close {
1391   $lxdebug->enter_sub();
1392
1393   # $locale->text('Customer saved!')
1394   # $locale->text('Vendor saved!')
1395
1396   $msg = ucfirst $form->{db};
1397   $imsg .= " saved!";
1398
1399   $form->isblank("name", $locale->text("Name missing!"));
1400   if ($vertreter && $form->{db} eq "customer") {
1401     $form->isblank("salesman_id", $locale->text("Salesman missing!"));
1402   }
1403   $rc = &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
1404   if ($rc == 3) {
1405     $form->error($locale->text('customernumber not unique!'));
1406   }
1407   # saving the history
1408   if(!exists $form->{addition}) {
1409         $form->{addition} = "SAVED";
1410         $form->save_history($form->dbconnect(\%myconfig));
1411   }
1412   # /saving the history
1413   $form->redirect($locale->text($msg));
1414
1415   $lxdebug->leave_sub();
1416 }
1417
1418 sub save {
1419   $lxdebug->enter_sub();
1420
1421   # $locale->text('Customer saved!')
1422   # $locale->text('Vendor saved!')
1423
1424   $msg = ucfirst $form->{db};
1425   $imsg .= " saved!";
1426
1427   $form->isblank("name", $locale->text("Name missing!"));
1428   if ($vertreter && $form->{db} eq "customer") {
1429     $form->isblank("salesman_id", $locale->text("Salesman missing!"));
1430   }
1431
1432   my $res = &{"CT::save_$form->{db}"}("", \%myconfig, \%$form);
1433
1434   if (3 == $res) {
1435     if ($form->{"db"} eq "customer") {
1436       $form->error($locale->text('This customer number is already in use.'));
1437     } else {
1438       $form->error($locale->text('This vendor number is already in use.'));
1439     }
1440   }
1441   # saving the history
1442   if(!exists $form->{addition}) {
1443         $form->{addition} = "SAVED";
1444         $form->save_history($form->dbconnect(\%myconfig));
1445   }
1446   # /saving the history
1447   &edit;
1448   exit;
1449   $lxdebug->leave_sub();
1450 }
1451
1452 sub delete {
1453   $lxdebug->enter_sub();
1454
1455   # $locale->text('Customer deleted!')
1456   # $locale->text('Cannot delete customer!')
1457   # $locale->text('Vendor deleted!')
1458   # $locale->text('Cannot delete vendor!')
1459
1460   CT->delete(\%myconfig, \%$form);
1461
1462   $msg = ucfirst $form->{db};
1463   $msg .= " deleted!";
1464   # saving the history
1465   if(!exists $form->{addition}) {
1466         $form->{addition} = "DELETED";
1467         $form->save_history($form->dbconnect(\%myconfig));
1468   }
1469   # /saving the history 
1470   $form->redirect($locale->text($msg));
1471
1472   $msg = "Cannot delete $form->{db}";
1473   $form->error($locale->text($msg));
1474
1475   $lxdebug->leave_sub();
1476 }
1477
1478 sub display {
1479   $lxdebug->enter_sub();
1480
1481   &form_header();
1482   &form_footer();
1483
1484   $lxdebug->leave_sub();
1485 }
1486
1487 sub update {
1488   $lxdebug->enter_sub();
1489
1490   &check_salesman($form->{salesman});
1491
1492   #  $form->get_salesman(\%myconfig, $form->{salesman});
1493   &display();
1494   $lxdebug->leave_sub();
1495 }
1496
1497 sub check_salesman {
1498   $lxdebug->enter_sub();
1499
1500   my ($name) = @_;
1501
1502   my ($new_name, $new_id) = split /--/, $form->{$name};
1503   my $i = 0;
1504
1505   # check name, combine name and id
1506   if ($form->{"oldsalesman"} ne $form->{"salesman"}) {
1507
1508     # return one name or a list of names in $form->{name_list}
1509     if (($i = $form->get_salesman(\%myconfig, $name)) > 1) {
1510       &select_salesman($name);
1511       exit;
1512     }
1513
1514     if ($i == 1) {
1515
1516       # we got one name
1517       $form->{"salesman_id"} = $form->{salesman_list}[0]->{id};
1518       $form->{salesman}      = $form->{salesman_list}[0]->{name};
1519       $form->{"oldsalesman"} = $form->{salesman};
1520
1521     } else {
1522
1523       # name is not on file
1524       # $locale->text('Customer not on file!')
1525       # $locale->text('Vendor not on file!')
1526       $msg = ucfirst $name . " not on file or locked!";
1527       $form->error($locale->text($msg));
1528     }
1529   }
1530
1531   $lxdebug->leave_sub();
1532
1533   return $i;
1534 }
1535
1536 sub select_salesman {
1537   $lxdebug->enter_sub();
1538
1539   my ($table) = @_;
1540
1541   @column_index = qw(ndx name);
1542
1543   $label             = ucfirst $table;
1544   $column_data{ndx}  = qq|<th>&nbsp;</th>|;
1545   $column_data{name} =
1546     qq|<th class=listheading>| . $locale->text($label) . qq|</th>|;
1547
1548   # list items with radio button on a form
1549   $form->header;
1550
1551   $title = $locale->text('Select from one of the names below');
1552
1553   print qq|
1554 <body>
1555
1556 <form method=post action=$form->{script}>
1557
1558 <table width=100%>
1559   <tr>
1560     <th class=listtop>$title</th>
1561   </tr>
1562   <tr space=5></tr>
1563   <tr>
1564     <td>
1565       <table width=100%>
1566         <tr class=listheading>|;
1567
1568   map { print "\n$column_data{$_}" } @column_index;
1569
1570   print qq|
1571         </tr>
1572 |;
1573
1574   my $i = 0;
1575   foreach $ref (@{ $form->{salesman_list} }) {
1576     $checked = ($i++) ? "" : "checked";
1577
1578     $ref->{name} =~ s/\"/&quot;/g;
1579
1580     $column_data{ndx} =
1581       qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
1582     $column_data{name} =
1583       qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
1584
1585     $j++;
1586     $j %= 2;
1587     print qq|
1588         <tr class=listrow$j>|;
1589
1590     map { print "\n$column_data{$_}" } @column_index;
1591
1592     print qq|
1593         </tr>
1594
1595 <input name="new_id_$i" type=hidden value=$ref->{id}>
1596
1597 |;
1598
1599   }
1600
1601   print qq|
1602       </table>
1603     </td>
1604   </tr>
1605   <tr>
1606     <td><hr size=3 noshade></td>
1607   </tr>
1608 </table>
1609
1610 <input name=lastndx type=hidden value=$i>
1611
1612 |;
1613
1614   # delete variables
1615   map { delete $form->{$_} } qw(action name_list header);
1616
1617   # save all other form variables
1618   foreach $key (keys %${form}) {
1619     $form->{$key} =~ s/\"/&quot;/g;
1620     print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
1621   }
1622
1623   print qq|
1624 <input type=hidden name=nextsub value=salesman_selected>
1625
1626 <input type=hidden name=vc value=$table>
1627 <br>
1628 <input class=submit type=submit name=action value="|
1629     . $locale->text('Continue') . qq|">
1630 </form>
1631
1632 </body>
1633 </html>
1634 |;
1635
1636   $lxdebug->leave_sub();
1637 }
1638
1639 sub salesman_selected {
1640   $lxdebug->enter_sub();
1641
1642   # replace the variable with the one checked
1643
1644   # index for new item
1645   $i = $form->{ndx};
1646
1647   $form->{salesman}      = $form->{"new_name_$i"};
1648   $form->{"salesman_id"} = $form->{"new_id_$i"};
1649   $form->{"oldsalesman"} = $form->{salesman};
1650
1651   # delete all the new_ variables
1652   for $i (1 .. $form->{lastndx}) {
1653     map { delete $form->{"new_${_}_$i"} } (id, name);
1654   }
1655
1656   map { delete $form->{$_} } qw(ndx lastndx nextsub);
1657
1658   &update(1);
1659
1660   $lxdebug->leave_sub();
1661 }
1662
1663 sub get_contact {
1664   $lxdebug->enter_sub();
1665
1666   CT->get_contact(\%myconfig, \%$form);
1667
1668   my $q = new CGI;
1669   $result = "$form->{cp_name}";
1670   map { $result .= "__pjx__" . $form->{$_} } qw(cp_greeting cp_title cp_givenname cp_phone1 cp_phone2 cp_email cp_abteilung cp_fax cp_mobile1 cp_mobile2 cp_satphone cp_satfax cp_project cp_privatphone cp_privatemail cp_birthday);
1671   print $q->header();
1672   print $result;
1673   $lxdebug->leave_sub();
1674
1675 }
1676
1677 sub get_shipto {
1678   $lxdebug->enter_sub();
1679
1680   CT->get_shipto(\%myconfig, \%$form);
1681
1682   my $q = new CGI;
1683   $result = "$form->{shiptoname}";
1684   map { $result .= "__pjx__" . $form->{$_} } qw(shiptodepartment_1 shiptodepartment_2 shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax shiptoemail);
1685   print $q->header();
1686   print $result;
1687   $lxdebug->leave_sub();
1688
1689 }
1690
1691 sub get_delivery {
1692   $lxdebug->enter_sub();
1693
1694   CT->get_delivery(\%myconfig, \%$form );
1695
1696   @column_index =
1697     $form->sort_columns(shiptoname,
1698                         invnumber,
1699                         ordnumber,
1700                         transdate,
1701                         description,
1702                         qty,
1703                         unit);
1704
1705
1706
1707   $column_header{shiptoname} =
1708     qq|<th class=listheading>| . $locale->text('Shipping Address') . qq|</th>|;
1709   $column_header{invnumber} =
1710       qq|<th class=listheading>|. $locale->text('Invoice'). qq|</th>|;
1711   $column_header{ordnumber} =
1712       qq|<th class=listheading>|. $locale->text('Order'). qq|</th>|;
1713   $column_header{transdate} =
1714     qq|<th class=listheading>| . $locale->text('Invdate') . qq|</th>|;
1715   $column_header{description} =
1716     qq|<th class=listheading>| . $locale->text('Description') . qq|</th>|;
1717   $column_header{qty} =
1718     qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
1719   $column_header{unit} =
1720     qq|<th class=listheading>| . $locale->text('Unit') . qq|</th>|;
1721   $result .= qq|
1722
1723 <table width=100%>
1724   <tr>
1725     <td>
1726       <table width=100%>
1727         <tr class=listheading>
1728 |;
1729
1730   map { $result .= "$column_header{$_}\n" } @column_index;
1731
1732   $result .= qq|
1733         </tr>
1734 |;
1735
1736
1737   foreach $ref (@{ $form->{DELIVERY} }) {
1738
1739     if ($ref->{shiptoname} eq $sameshiptoname) {
1740       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
1741       $column_data{shiptoname} = "<td>&nbsp;</td>";
1742     } else {
1743       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
1744     }
1745
1746     $i++;
1747     $i %= 2;
1748     $result .= "
1749         <tr class=listrow$i>
1750 ";
1751
1752     map { $result .= "$column_data{$_}\n" } @column_index;
1753
1754     $result .= qq|
1755         </tr>
1756 |;
1757
1758     $sameshiptoname = $ref->{shiptoname};
1759
1760   }
1761
1762   $result .= qq|
1763       </table>
1764 |;
1765
1766
1767   my $q = new CGI;
1768   print $q->header();
1769   print $result;
1770   $lxdebug->leave_sub();
1771
1772 }
1773
1774 sub continue { &{ $form->{nextsub} } }