Kosmetik.
[kivitendo-erp.git] / bin / mozilla / gl.pl
index 0fd863e..01d0114 100644 (file)
 #======================================================================
 
 use POSIX qw(strftime);
+use List::Util qw(sum);
 
+use SL::FU;
 use SL::GL;
 use SL::IS;
 use SL::PE;
 use SL::ReportGenerator;
 
-require "bin/mozilla/arap.pl";
 require "bin/mozilla/common.pl";
-require "bin/mozilla/report_generator.pl";
+require "bin/mozilla/reportgenerator.pl";
 
 1;
 
@@ -77,11 +78,11 @@ require "bin/mozilla/report_generator.pl";
 sub add {
   $lxdebug->enter_sub();
 
+  $auth->assert('general_ledger');
+
   $form->{title} = "Add";
 
-  $form->{callback} =
-    "$form->{script}?action=add&login=$form->{login}&password=$form->{password}"
-    unless $form->{callback};
+  $form->{callback} = "gl.pl?action=add" unless $form->{callback};
 
   # we use this only to set a default date
   GL->transaction(\%myconfig, \%$form);
@@ -119,6 +120,8 @@ sub add {
 sub prepare_transaction {
   $lxdebug->enter_sub();
 
+  $auth->assert('general_ledger');
+
   GL->transaction(\%myconfig, \%$form);
 
   map {
@@ -191,6 +194,8 @@ sub prepare_transaction {
 sub edit {
   $lxdebug->enter_sub();
 
+  $auth->assert('general_ledger');
+
   prepare_transaction();
 
   $form->{title} = "Edit";
@@ -208,6 +213,8 @@ sub edit {
 sub search {
   $lxdebug->enter_sub();
 
+  $auth->assert('general_ledger');
+
   $form->{title} = $locale->text('Journal');
 
   $form->all_departments(\%myconfig);
@@ -281,7 +288,7 @@ sub search {
   print qq|
 <body onLoad="$onload">
 
-<form method=post action=$form->{script}>
+<form method=post action=gl.pl>
 
 <input type=hidden name=sort value=transdate>
 
@@ -382,9 +389,6 @@ $jsscript
 
 <input type=hidden name=nextsub value=generate_report>
 
-<input type=hidden name=login value=$form->{login}>
-<input type=hidden name=password value=$form->{password}>
-
 <br>
 <input class=submit type=submit name=action value="|
     . $locale->text('Continue') . qq|">
@@ -415,6 +419,8 @@ sub create_subtotal_row {
 sub generate_report {
   $lxdebug->enter_sub();
 
+  $auth->assert('general_ledger');
+
   $form->{sort} ||= "transdate";
 
   GL->all_transactions(\%myconfig, \%$form);
@@ -445,36 +451,22 @@ sub generate_report {
   my @hidden_variables = qw(accno source reference department description notes project_id datefrom dateto category l_subtotal);
   push @hidden_variables, map { "l_${_}" } @columns;
 
-  my (@options, $date_option);
-  if ($form->{accno}) {
-    push @options, $locale->text('Account') . " : $form->{accno} $form->{account_description}";
-  }
-  if ($form->{source}) {
-    push @options, $locale->text('Source') . " : $form->{source}";
-  }
-  if ($form->{reference}) {
-    push @options, $locale->text('Reference') . " : $form->{reference}";
-  }
+  my (@options, @date_options);
+  push @options,      $locale->text('Account')     . " : $form->{accno} $form->{account_description}" if ($form->{accno});
+  push @options,      $locale->text('Source')      . " : $form->{source}"                             if ($form->{source});
+  push @options,      $locale->text('Reference')   . " : $form->{reference}"                          if ($form->{reference});
+  push @options,      $locale->text('Description') . " : $form->{description}"                        if ($form->{description});
+  push @options,      $locale->text('Notes')       . " : $form->{notes}"                              if ($form->{notes});
+
+  push @date_options, $locale->text('From'), $locale->date(\%myconfig, $form->{datefrom}, 1)          if ($form->{datefrom});
+  push @date_options, $locale->text('Bis'),  $locale->date(\%myconfig, $form->{dateto},   1)          if ($form->{dateto});
+  push @options,      join(' ', @date_options)                                                        if (scalar @date_options);
+
   if ($form->{department}) {
     my ($department) = split /--/, $form->{department};
     push @options, $locale->text('Department') . " : $department";
   }
-  if ($form->{description}) {
-    push @options, $locale->text('Description') . " : $form->{description}";
-  }
-  if ($form->{notes}) {
-    push @options, $locale->text('Notes') . " : $form->{notes}";
-  }
-  if ($form->{datefrom}) {
-    $date_option = $locale->text('From') . " " . $locale->date(\%myconfig, $form->{datefrom}, 1);
-  }
-  if ($form->{dateto}) {
-    if ($form->{datefrom}) {
-      $date_option .= " ";
-    }
-    $date_option .= $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{dateto}, 1);
-  }
-  push @options, $date_option if $date_option;
+
 
   my $callback = build_std_url('action=generate_report', @hidden_variables);
 
@@ -580,18 +572,14 @@ sub generate_report {
 
     map { $row->{$_}->{data} = $ref->{$_} } qw(id reference description source notes);
 
-    map { $row->{$_}->{data} = join "\n", @{ $rows{$_} }; } qw(transdate debit credit);
-
-    map { $row->{$_}->{data} = join "\n", @{ $rows{$_} } if ($ref->{"${_}_accno"} ne "") } qw(debit_tax credit_tax);
+    map { $row->{$_}->{data} = \@{ $rows{$_} }; } qw(transdate debit credit debit_accno credit_accno debit_tax_accno credit_tax_accno);
 
     foreach my $col (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
-      if (lc $report->{options}->{output_format} eq 'html') {
-        $row->{$col}->{raw_data} = join "<br>", map { "<a href=\"${callback}&accno=" . E($_) . "\">$_</a>" } @{ $rows{$col} };
-      } else {
-        $row->{$col}->{data} = join "\n", @{ $rows{$col} };
-      }
+      $row->{$col}->{link} = [ map { "${callback}&accno=" . E($_) } @{ $rows{$col} } ];
     }
 
+    map { $row->{$_}->{data} = \@{ $rows{$_} } if ($ref->{"${_}_accno"} ne "") } qw(debit_tax credit_tax);
+
     $row->{reference}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'id=' . E($ref->{id}), 'callback');
 
     my $row_set = [ $row ];
@@ -643,6 +631,8 @@ sub generate_report {
 sub update {
   $lxdebug->enter_sub();
 
+  $auth->assert('general_ledger');
+
   $form->{oldtransdate} = $form->{transdate};
 
   my @a           = ();
@@ -749,6 +739,8 @@ sub display_form {
   my ($init) = @_;
   $lxdebug->enter_sub();
 
+  $auth->assert('general_ledger');
+
   &form_header($init);
 
   #   for $i (1 .. $form->{rowcount}) {
@@ -767,6 +759,8 @@ sub display_rows {
   my ($init) = @_;
   $lxdebug->enter_sub();
 
+  $auth->assert('general_ledger');
+
   $form->{debit_1}     = 0 if !$form->{"debit_1"};
   $form->{totaldebit}  = 0;
   $form->{totalcredit} = 0;
@@ -959,6 +953,9 @@ sub display_rows {
 sub form_header {
   my ($init) = @_;
   $lxdebug->enter_sub();
+
+  $auth->assert('general_ledger');
+
   $title         = $form->{title};
   $form->{title} = $locale->text("$title General Ledger Transaction");
   $readonly      = ($form->{id}) ? "readonly" : "";
@@ -1059,7 +1056,10 @@ sub form_header {
   print qq|
 <body onLoad="fokus()">
 
-<form method=post name="gl" action=$form->{script}>
+<script type="text/javascript" src="js/common.js"></script>
+<script type="text/javascript" src="js/follow_up.js"></script>
+
+<form method=post name="gl" action=gl.pl>
 |;
 
   $form->hide_form(qw(id closedto locked storno storno_id previous_id previous_gldate));
@@ -1067,6 +1067,10 @@ sub form_header {
   print qq|
 <input type=hidden name=title value="$title">
 
+<input type="hidden" name="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
+<input type="hidden" name="follow_up_trans_type_1" value="gl_transaction">
+<input type="hidden" name="follow_up_trans_info_1" value="| . H($form->{id}) . qq|">
+<input type="hidden" name="follow_up_rowcount" value="1">
 
 <table width=100%>
   <tr>
@@ -1193,6 +1197,19 @@ $jsscript
 
 sub form_footer {
   $lxdebug->enter_sub();
+
+  $auth->assert('general_ledger');
+
+  my $follow_ups_block;
+  if ($form->{id}) {
+    my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
+
+    if (@{ $follow_ups} ) {
+      my $num_due       = sum map { $_->{due} * 1 } @{ $follow_ups };
+      $follow_ups_block = qq|<p>| . $locale->text("There are #1 unfinished follow-ups of which #2 are due.", scalar @{ $follow_ups }, $num_due) . qq|</p>|;
+    }
+  }
+
   ($dec) = ($form->{totaldebit} =~ /\.(\d+)/);
   $dec = length $dec;
   $decimalplaces = ($dec > 2) ? $dec : 2;
@@ -1214,11 +1231,10 @@ sub form_footer {
   </tr>
 </table>
 
-<input type=hidden name=login value=$form->{login}>
-<input type=hidden name=password value=$form->{password}>
-
 <input name=callback type=hidden value="$form->{callback}">
 
+$follow_ups_block
+
 <br>
 |;
 
@@ -1238,6 +1254,11 @@ sub form_footer {
         <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|">|;
     }
 
+    print qq|
+        <input type="button" class="submit" onclick="follow_up_window()" value="|
+      . $locale->text('Follow-Up')
+      . qq|"> |;
+
   } else {
     if ($transdate > $closedto) {
       print qq|
@@ -1264,7 +1285,7 @@ sub delete {
   print qq|
 <body>
 
-<form method=post action=$form->{script}>
+<form method=post action=gl.pl>
 |;
 
   map { $form->{$_} =~ s/\"/&quot;/g } qw(reference description);
@@ -1272,6 +1293,7 @@ sub delete {
   delete $form->{header};
 
   foreach $key (keys %$form) {
+    next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
     print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
   }
 
@@ -1468,6 +1490,8 @@ sub post_transaction {
 sub post {
   $lxdebug->enter_sub();
 
+  $auth->assert('general_ledger');
+
   $form->{title}  = $locale->text("$form->{title} General Ledger Transaction");
   $form->{storno} = 0;
 
@@ -1482,6 +1506,8 @@ sub post {
 sub post_as_new {
   $lxdebug->enter_sub();
 
+  $auth->assert('general_ledger');
+
   $form->{id} = 0;
   &add;
   $lxdebug->leave_sub();
@@ -1491,6 +1517,8 @@ sub post_as_new {
 sub storno {
   $lxdebug->enter_sub();
 
+  $auth->assert('general_ledger');
+
   # don't cancel cancelled transactions
   if (IS->has_storno(\%myconfig, $form, 'gl')) {
     $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
@@ -1512,3 +1540,6 @@ sub storno {
   $lxdebug->leave_sub();
 }
 
+sub continue {
+  call_sub($form->{nextsub});
+}