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