Beim Buchen von Rechnungen/Zahlungen das Feld "datepaid" richtig setzen.
[kivitendo-erp.git] / bin / mozilla / common.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 # Stuff that can be used from other modules
9 #
10 ######################################################################
11
12 use SL::Common;
13 use SL::DBUtils;
14 use SL::Form;
15 use SL::MoreCommon;
16
17 use strict;
18
19 sub build_std_url {
20   $main::lxdebug->enter_sub(2);
21
22   my $form     = $main::form;
23
24   my $script = $form->{script};
25
26   my @parts;
27
28   foreach my $key (@_) {
29     next unless ($key);
30
31     if ($key =~ /(.*?)=(.*)/) {
32       if ($1 eq 'script') {
33         $script = $2;
34       } else {
35         push @parts, $key;
36       }
37
38     } else {
39       foreach my $var ($form->flatten_variables($key)) {
40         push @parts, E($var->{key}) . '=' . E($var->{value});
41       }
42     }
43   }
44
45   my $url = "${script}?" . join('&', @parts);
46
47   $main::lxdebug->leave_sub(2);
48
49   return $url;
50 }
51
52 # -------------------------------------------------------------------------
53
54 sub select_part {
55   $main::lxdebug->enter_sub();
56
57   my ($callback_sub, @parts) = @_;
58
59   my $form     = $main::form;
60   my $locale   = $main::locale;
61
62   my $remap_parts_id = 0;
63   if (defined($parts[0]->{parts_id}) && !defined($parts[0]->{id})) {
64     $remap_parts_id = 1;
65     map { $_->{id} = $_->{parts_id}; } @parts;
66   }
67
68   my $remap_partnumber = 0;
69   if (defined($parts[0]->{partnumber}) && !defined($parts[0]->{number})) {
70     $remap_partnumber = 1;
71     map { $_->{number} = $_->{partnumber}; } @parts;
72   }
73
74   my $has_charge = 0;
75   if (defined($parts[0]->{chargenumber})) {
76     $has_charge = 1;
77     map { $_->{has_charge} = 1; } @parts;
78   }
79   my $has_ean = 0;
80   if (defined($parts[0]->{ean})) {
81     $has_ean = 1;
82     map { $_->{has_ean} = 1; } @parts;
83   }
84
85   my $old_form = save_form();
86
87   $form->header();
88   print $form->parse_html_template("generic/select_part",
89                                    { "PARTS"            => \@parts,
90                                      "old_form"         => $old_form,
91                                      "title"            => $locale->text("Select a part"),
92                                      "nextsub"          => "select_part_internal",
93                                      "callback_sub"     => $callback_sub,
94                                      "has_charge"       => $has_charge,
95                                      "has_ean"          => $has_ean,
96                                      "remap_parts_id"   => $remap_parts_id,
97                                      "remap_partnumber" => $remap_partnumber });
98
99   $main::lxdebug->leave_sub();
100 }
101
102 sub select_part_internal {
103   $main::lxdebug->enter_sub();
104
105   my $form     = $main::form;
106
107   my ($new_item, $callback_sub);
108
109   my $re = "^new_.*_$form->{selection}\$";
110
111   foreach (grep /$re/, keys %{ $form }) {
112     my $new_key           =  $_;
113     $new_key              =~ s/^new_//;
114     $new_key              =~ s/_\d+$//;
115     $new_item->{$new_key} =  $form->{$_};
116   }
117
118   if ($form->{remap_parts_id}) {
119     $new_item->{parts_id} = $new_item->{id};
120     delete $new_item->{id};
121   }
122
123   if ($form->{remap_partnumber}) {
124     $new_item->{partnumber} = $new_item->{number};
125     delete $new_item->{number};
126   }
127
128   $callback_sub = $form->{callback_sub};
129
130   restore_form($form->{old_form});
131
132   call_sub($callback_sub, $new_item);
133
134   $main::lxdebug->leave_sub();
135 }
136
137 sub part_selection_internal {
138   $main::lxdebug->enter_sub();
139
140   my $form     = $main::form;
141   my %myconfig = %main::myconfig;
142   my $locale   = $main::locale;
143
144   my $order_by  = "description";
145   $order_by  = $form->{"order_by"} if (defined($form->{"order_by"}));
146   my $order_dir = 1;
147   $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
148
149   my %options;
150
151   foreach my $opt (split m/:/, $form->{options}) {
152     if ($opt =~ /=/) {
153       my ($key, $value) = split m/=/, $opt, 2;
154       $options{$key} = $value;
155
156     } else {
157       $options{$opt} = 1;
158     }
159   }
160
161   map { $form->{$_} = $options{$_} if ($options{$_}) } qw(no_services no_assemblies assemblies click_button);
162
163   my $parts = Common->retrieve_parts(\%myconfig, $form, $order_by, $order_dir);
164   my $onload;
165
166   if (0 == scalar(@{$parts})) {
167     $form->show_generic_information($locale->text("No part was found matching the search parameters."));
168   } elsif (1 == scalar(@{$parts})) {
169     $onload = "part_selected('1')";
170   }
171
172   map { $parts->[$_]->{selected} = $_ ? 0 : 1; } (0..$#{$parts});
173
174   my $callback = build_std_url('action=part_selection_internal', qw(partnumber description input_partnumber input_description input_partsid),
175                                grep({ /^[fl]_/ } keys %{ $form }));
176
177   my @header_sort  = qw(partnumber description);
178   my %header_title = ( "partnumber"  => $locale->text("Part Number"),
179                        "description" => $locale->text("Part description"),
180                        );
181
182   my @header =
183     map(+{ "column_title" => $header_title{$_},
184            "column"       => $_,
185            "callback"     => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
186          },
187         @header_sort);
188
189   $form->{formname} ||= 'Form';
190
191   $form->{title} = $locale->text("Select a part");
192   $form->header();
193   print $form->parse_html_template("generic/part_selection", { "HEADER" => \@header,
194                                                                "PARTS"  => $parts,
195                                                                "onload" => $onload });
196
197   $main::lxdebug->leave_sub();
198 }
199
200 # -------------------------------------------------------------------------
201
202 sub delivery_customer_selection {
203   $main::lxdebug->enter_sub();
204
205   my $form     = $main::form;
206   my %myconfig = %main::myconfig;
207   my $locale   = $main::locale;
208
209   my $order_by = "name";
210   $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
211   my $order_dir = 1;
212   $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
213
214   my $delivery = Common->retrieve_delivery_customer(\%myconfig, $form, $order_by, $order_dir);
215   map({ $delivery->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$delivery}));
216
217   my $onload;
218   if (0 == scalar(@{$delivery})) {
219     $form->show_generic_information($locale->text("No Customer was found matching the search parameters."));
220   } elsif (1 == scalar(@{$delivery})) {
221     $onload = "customer_selected('1')";
222   }
223
224   my $callback = "$form->{script}?action=delivery_customer_selection&";
225   map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
226       (qw(name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
227
228   my @header_sort = qw(name customernumber address);
229   my %header_title = ( "name" => $locale->text("Name"),
230                        "customernumber" => $locale->text("Customer Number"),
231                        "address" => $locale->text("Address"),
232                      );
233
234   my @header =
235     map(+{ "column_title" => $header_title{$_},
236            "column" => $_,
237            "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
238          },
239         @header_sort);
240
241   $form->{"title"} = $locale->text("Select a Customer");
242   $form->header();
243   print $form->parse_html_template("generic/select_delivery_customer", { "HEADER"   => \@header,
244                                                                          "DELIVERY" => $delivery,
245                                                                          "onload"   => $onload });
246
247   $main::lxdebug->leave_sub();
248 }
249
250 # -------------------------------------------------------------------------
251
252 sub vendor_selection {
253   $main::lxdebug->enter_sub();
254
255   my $form     = $main::form;
256   my %myconfig = %main::myconfig;
257   my $locale   = $main::locale;
258
259   my $order_by = "name";
260   $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
261   my $order_dir = 1;
262   $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
263
264   my $vendor = Common->retrieve_vendor(\%myconfig, $form, $order_by, $order_dir);
265   map({ $vendor->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$vendor}));
266
267   my $onload;
268   if (0 == scalar(@{$vendor})) {
269     $form->show_generic_information($locale->text("No Vendor was found matching the search parameters."));
270   } elsif (1 == scalar(@{$vendor})) {
271     $onload = "vendor_selected('1')";
272   }
273
274   my $callback = "$form->{script}?action=vendor_selection&";
275   map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
276       (qw(name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
277
278   my @header_sort = qw(name customernumber address);
279   my %header_title = ( "name" => $locale->text("Name"),
280                        "customernumber" => $locale->text("Customer Number"),
281                        "address" => $locale->text("Address"),
282                      );
283
284   my @header =
285     map(+{ "column_title" => $header_title{$_},
286            "column" => $_,
287            "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
288          },
289         @header_sort);
290
291   $form->{"title"} = $locale->text("Select a Customer");
292   $form->header();
293   print $form->parse_html_template("generic/select_vendor", { "HEADER" => \@header,
294                                                               "VENDOR" => $vendor,
295                                                               "onload" => $onload });
296
297   $main::lxdebug->leave_sub();
298 }
299
300 # -------------------------------------------------------------------------
301
302 sub calculate_qty {
303   $main::lxdebug->enter_sub();
304
305   my $form     = $main::form;
306   my $locale   = $main::locale;
307
308   $form->{formel} =~ s/\r\n//g;
309
310   my ($variable_string, $formel) = split /###/,$form->{formel};
311   my @variable;
312   my $onload; # note! this sub is mostly called over a javascript invocation, and it's unlikey that onload is set.
313
314   foreach my $item (split m/;/, $variable_string) {
315     next unless $item =~ m/^ \s* (\w+) \s* = \s* (\w+) \s* (\w+) \s* $/x;
316     push @variable, {
317       description => $1,
318       name        => $2,
319       unit        => $3,
320     };
321   }
322
323   my @header_sort = qw(variable value unit);
324   my %header_title = (
325     variable => $locale->text("Variable"),
326     value    => $locale->text("Value"),
327     unit     => $locale->text("Unit"),
328   );
329   my @header = map +{
330     column_title => $header_title{$_},
331     column       => $_,
332   }, @header_sort;
333
334   $form->{formel} = $formel;
335   $form->{title}  = $locale->text("Please enter values");
336   $form->header();
337   print $form->parse_html_template("generic/calculate_qty", { "HEADER"    => \@header,
338                                                               "VARIABLES" => \@variable,
339                                                               "onload"    => $onload });
340
341   $main::lxdebug->leave_sub();
342 }
343
344 # -------------------------------------------------------------------------
345
346 sub set_longdescription {
347   $main::lxdebug->enter_sub();
348
349   my $form     = $main::form;
350   my $locale   = $main::locale;
351
352   $form->{title} = $locale->text("Enter longdescription");
353   $form->header();
354   print $form->parse_html_template("generic/set_longdescription");
355
356   $main::lxdebug->leave_sub();
357 }
358
359 # -------------------------------------------------------------------------
360
361 sub H {
362   return $main::locale->quote_special_chars('HTML', $_[0]);
363 }
364
365 sub Q {
366   return $main::locale->quote_special_chars('URL@HTML', $_[0]);
367 }
368
369 sub E {
370   return $main::form->escape($_[0]);
371 }
372
373 sub NTI {
374   my ($element) = @_;
375
376   $element =~ s/tabindex\s*=\s*"\d+"//;
377   return $element;
378 }
379
380 sub format_dates {
381   $main::lxdebug->enter_sub();
382
383   my ($dateformat, $longformat, @indices) = @_;
384
385   my $form     = $main::form;
386   my %myconfig = %main::myconfig;
387   my $locale   = $main::locale;
388
389   $dateformat = $myconfig{"dateformat"} unless ($dateformat);
390
391   foreach my $idx (@indices) {
392     if ($form->{TEMPLATE_ARRAYS} && (ref($form->{TEMPLATE_ARRAYS}->{$idx}) eq "ARRAY")) {
393       for (my $i = 0; $i < scalar(@{$form->{TEMPLATE_ARRAYS}->{$idx}}); $i++) {
394         $form->{TEMPLATE_ARRAYS}->{$idx}->[$i] =
395           $locale->reformat_date(\%myconfig, $form->{TEMPLATE_ARRAYS}->{$idx}->[$i],
396                                  $dateformat, $longformat);
397       }
398     }
399
400     next unless (defined($form->{$idx}));
401
402     if (!ref($form->{$idx})) {
403       $form->{$idx} = $locale->reformat_date(\%myconfig, $form->{$idx},
404                                              $dateformat, $longformat);
405
406     } elsif (ref($form->{$idx}) eq "ARRAY") {
407       for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) {
408         $form->{$idx}->[$i] =
409           $locale->reformat_date(\%myconfig, $form->{$idx}->[$i],
410                                  $dateformat, $longformat);
411       }
412     }
413   }
414
415   $main::lxdebug->leave_sub();
416 }
417
418 sub reformat_numbers {
419   $main::lxdebug->enter_sub();
420
421   my ($numberformat, $places, @indices) = @_;
422
423   my $form     = $main::form;
424   my %myconfig = %main::myconfig;
425
426   return $main::lxdebug->leave_sub()
427     if (!$numberformat || ($numberformat eq $myconfig{"numberformat"}));
428
429   foreach my $idx (@indices) {
430     if ($form->{TEMPLATE_ARRAYS} && (ref($form->{TEMPLATE_ARRAYS}->{$idx}) eq "ARRAY")) {
431       for (my $i = 0; $i < scalar(@{$form->{TEMPLATE_ARRAYS}->{$idx}}); $i++) {
432         $form->{TEMPLATE_ARRAYS}->{$idx}->[$i] = $form->parse_amount(\%myconfig, $form->{TEMPLATE_ARRAYS}->{$idx}->[$i]);
433       }
434     }
435
436     next unless (defined($form->{$idx}));
437
438     if (!ref($form->{$idx})) {
439       $form->{$idx} = $form->parse_amount(\%myconfig, $form->{$idx});
440
441     } elsif (ref($form->{$idx}) eq "ARRAY") {
442       for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) {
443         $form->{$idx}->[$i] =
444           $form->parse_amount(\%myconfig, $form->{$idx}->[$i]);
445       }
446     }
447   }
448
449   my $saved_numberformat = $myconfig{"numberformat"};
450   $myconfig{"numberformat"} = $numberformat;
451
452   foreach my $idx (@indices) {
453     if ($form->{TEMPLATE_ARRAYS} && (ref($form->{TEMPLATE_ARRAYS}->{$idx}) eq "ARRAY")) {
454       for (my $i = 0; $i < scalar(@{$form->{TEMPLATE_ARRAYS}->{$idx}}); $i++) {
455         $form->{TEMPLATE_ARRAYS}->{$idx}->[$i] = $form->format_amount(\%myconfig, $form->{TEMPLATE_ARRAYS}->{$idx}->[$i], $places);
456       }
457     }
458
459     next unless (defined($form->{$idx}));
460
461     if (!ref($form->{$idx})) {
462       $form->{$idx} = $form->format_amount(\%myconfig, $form->{$idx}, $places);
463
464     } elsif (ref($form->{$idx}) eq "ARRAY") {
465       for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) {
466         $form->{$idx}->[$i] =
467           $form->format_amount(\%myconfig, $form->{$idx}->[$i], $places);
468       }
469     }
470   }
471
472   $myconfig{"numberformat"} = $saved_numberformat;
473
474   $main::lxdebug->leave_sub();
475 }
476
477 # -------------------------------------------------------------------------
478
479 sub show_history {
480         $main::lxdebug->enter_sub();
481
482   my $form     = $main::form;
483   my %myconfig = %main::myconfig;
484   my $locale   = $main::locale;
485
486         my $dbh = $form->dbconnect(\%myconfig);
487         my ($sort, $sortby) = split(/\-\-/, $form->{order});
488   $sort =~ s/.*\.(.*)/$1/;
489
490         $form->{title} = $locale->text("History");
491     $form->header();
492     print $form->parse_html_template( "common/show_history", {
493         "DATEN" => $form->get_history($dbh,$form->{input_name},"",$form->{order}),
494         "SUCCESS" => ($form->get_history($dbh,$form->{input_name}) ne "0"),
495       uc($sort) => 1,
496       uc($sort)."BY" => $sortby
497         } );
498
499         $dbh->disconnect();
500         $main::lxdebug->leave_sub();
501 }
502
503 # -------------------------------------------------------------------------
504
505 sub call_sub {
506   $main::lxdebug->enter_sub();
507
508   my $name = shift;
509
510   my $form     = $main::form;
511   my $locale   = $main::locale;
512
513   if (!$name) {
514     $form->error($locale->text("Trying to call a sub without a name"));
515   }
516
517   $name =~ s/[^a-zA-Z0-9_]//g;
518
519   if (!defined(&{ $name })) {
520     $form->error(sprintf($locale->text("Attempt to call an undefined sub named '%s'"), $name));
521   }
522
523   {
524     no strict "refs";
525     &{ $name }(@_);
526   }
527
528   $main::lxdebug->leave_sub();
529 }
530
531 # -------------------------------------------------------------------------
532
533 sub show_vc_details {
534         $main::lxdebug->enter_sub();
535
536   my $form     = $main::form;
537   my %myconfig = %main::myconfig;
538   my $locale   = $main::locale;
539
540   $form->{vc} = $form->{vc} eq "customer" ? "customer" : "vendor";
541   $form->isblank("vc_id",
542                  $form->{vc} eq "customer" ?
543                  $locale->text("No customer has been selected yet.") :
544                  $locale->text("No vendor has been selected yet."));
545
546   Common->get_vc_details(\%myconfig, $form, $form->{vc}, $form->{vc_id});
547
548   $form->{title} = $form->{vc} eq "customer" ?
549     $locale->text("Customer details") : $locale->text("Vendor details");
550   $form->header();
551   print $form->parse_html_template("common/show_vc_details", { "is_customer" => $form->{vc} eq "customer" });
552
553         $main::lxdebug->leave_sub();
554 }
555
556 # -------------------------------------------------------------------------
557
558 sub retrieve_partunits {
559   $main::lxdebug->enter_sub();
560
561   my $form     = $main::form;
562
563   my @part_ids = grep { $_ } map { $form->{"id_${_}"} } (1..$form->{rowcount});
564
565   if (@part_ids) {
566     my %partunits = IO->retrieve_partunits('part_ids' => \@part_ids);
567
568     foreach my $i (1..$form->{rowcount}) {
569       next unless ($form->{"id_${i}"});
570       $form->{"partunit_${i}"} = $partunits{$form->{"id_${i}"}};
571     }
572   }
573
574   $main::lxdebug->leave_sub();
575 }
576
577 # -------------------------------------------------------------------------
578
579 sub mark_as_paid_common {
580   $main::lxdebug->enter_sub();
581
582   my ($myconfig, $db_name) = @_;
583
584   my $form     = $main::form;
585   my $locale   = $main::locale;
586
587   if($form->{mark_as_paid}) {
588     my $dbh ||= $form->get_standard_dbh($myconfig);
589     my $query = qq|UPDATE $db_name SET paid = amount, datepaid = current_date WHERE id = ?|;
590     do_query($form, $dbh, $query, $form->{id});
591     $dbh->commit();
592     $form->redirect($locale->text("Marked as paid"));
593
594   } else {
595     my $referer = $ENV{HTTP_REFERER};
596     my $script;
597     my $callback;
598     if ($referer =~ /action/) {
599       $referer =~ /^(.*)\?action\=[^\&]*(\&.*)$/;
600       $script = $1;
601       $callback = $2;
602     } else {
603       $script = $referer;
604       $callback = "";
605     }
606     $referer = $script . "?action=mark_as_paid&mark_as_paid=1&id=$form->{id}" . $callback;
607     $form->header();
608     print qq|<body>|;
609     print qq|<p><b>|.$locale->text('Mark as paid?').qq|</b></p>|;
610     print qq|<input type="button" value="|.$locale->text('yes').qq|" onclick="document.location.href='|.$referer.qq|'">&nbsp;|;
611     print qq|<input type="button" value="|.$locale->text('no').qq|" onclick="javascript:history.back();">|;
612     print qq|</body></html>|;
613   }
614
615   $main::lxdebug->leave_sub();
616 }
617
618 sub cov_selection_internal {
619   $main::lxdebug->enter_sub();
620
621   my $form     = $main::form;
622   my %myconfig = %main::myconfig;
623   my $locale   = $main::locale;
624
625   my $order_by = "name";
626   $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
627   my $order_dir = 1;
628   $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
629
630   my $type = $form->{"is_vendor"} ? $locale->text("vendor") : $locale->text("customer");
631
632   my $covs = Common->retrieve_customers_or_vendors(\%myconfig, $form, $order_by, $order_dir, $form->{"is_vendor"}, $form->{"allow_both"});
633   map({ $covs->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$covs}));
634
635   my $onload;
636   if (0 == scalar(@{$covs})) {
637     $form->show_generic_information(sprintf($locale->text("No %s was found matching the search parameters."), $type));
638   } elsif (1 == scalar(@{$covs})) {
639     $onload = "cov_selected('1')";
640   }
641
642   my $callback = "$form->{script}?action=cov_selection_internal&";
643   map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
644       (qw(name input_name input_id is_vendor allow_both), grep({ /^[fl]_/ } keys %$form)));
645
646   my @header_sort = qw(name address contact);
647   my %header_title = ( "name" => $locale->text("Name"),
648                        "address" => $locale->text("Address"),
649                        "contact" => $locale->text("Contact"),
650                        );
651
652   my @header =
653     map(+{ "column_title" => $header_title{$_},
654            "column" => $_,
655            "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
656          },
657         @header_sort);
658
659   foreach my $cov (@{ $covs }) {
660     $cov->{address} = "$cov->{street}, $cov->{zipcode} $cov->{city}";
661     $cov->{address} =~ s{^,}{}x;
662     $cov->{address} =~ s{\ +}{\ }gx;
663
664     $cov->{contact} = join " ", map { $cov->{$_} } qw(cp_gender cp_title cp_givenname cp_name);
665     $cov->{contact} =~ s{\ +}{\ }gx;
666   }
667
668   $form->{"title"} = $form->{is_vendor} ? $locale->text("Select a vendor") : $locale->text("Select a customer");
669   $form->header();
670   print($form->parse_html_template("generic/cov_selection", { "HEADER" => \@header,
671                                                               "COVS" => $covs,
672                                                               "onload" => $onload }));
673
674   $main::lxdebug->leave_sub();
675 }
676
677
678 # Functions to call add routines beneath different reports
679
680 sub sales_invoice {
681   $main::lxdebug->enter_sub();
682
683   $main::auth->assert('invoice_edit');
684
685   my $form     = $main::form;
686   my %myconfig = %main::myconfig;
687   my $locale   = $main::locale;
688
689   $form->{script} = 'is.pl';
690   my $script      = "is";
691   $form->{type} = "invoice";
692   $locale = new Locale "$myconfig{countrycode}", "$script";
693
694   require "bin/mozilla/$form->{script}";
695   &add;
696
697   $main::lxdebug->leave_sub();
698 }
699
700 sub ar_transaction {
701   $main::lxdebug->enter_sub();
702
703   $main::auth->assert('general_ledger');
704
705   my $form     = $main::form;
706   my %myconfig = %main::myconfig;
707   my $locale   = $main::locale;
708
709   $form->{script} = 'ar.pl';
710   my $script      = "ar";
711   $locale = new Locale "$myconfig{countrycode}", "$script";
712
713   require "bin/mozilla/$form->{script}";
714   &add;
715
716   $main::lxdebug->leave_sub();
717 }
718
719 sub vendor_invoice {
720   $main::lxdebug->enter_sub();
721
722   $main::auth->assert('invoice_edit');
723
724   my $form     = $main::form;
725   my %myconfig = %main::myconfig;
726   my $locale   = $main::locale;
727
728   $form->{script} = 'ir.pl';
729   my $script      = "ir";
730   $form->{type} = "invoice";
731   $locale = new Locale "$myconfig{countrycode}", "$script";
732
733   require "bin/mozilla/$form->{script}";
734   &add;
735
736   $main::lxdebug->leave_sub();
737 }
738
739 sub ap_transaction {
740   $main::lxdebug->enter_sub();
741
742   $main::auth->assert('general_ledger');
743
744   my $form     = $main::form;
745   my %myconfig = %main::myconfig;
746   my $locale   = $main::locale;
747
748   $form->{script} = 'ap.pl';
749   my $script      = "ap";
750   $locale = new Locale "$myconfig{countrycode}", "$script";
751
752   require "bin/mozilla/$form->{script}";
753   &add;
754
755   $main::lxdebug->leave_sub();
756 }
757
758 sub gl_transaction {
759   $main::lxdebug->enter_sub();
760
761   $main::auth->assert('general_ledger');
762
763   my $form     = $main::form;
764   my %myconfig = %main::myconfig;
765   my $locale   = $main::locale;
766
767   $form->{script} = 'gl.pl';
768   my $script      = "gl";
769   $locale = new Locale "$myconfig{countrycode}", "$script";
770
771   require "bin/mozilla/$form->{script}";
772   &add;
773
774   $main::lxdebug->leave_sub();
775 }
776
777 1;