am: fehlendes include für Historiensuche(2)
[kivitendo-erp.git] / bin / mozilla / dn.pl
index 6b2cad0..8a10912 100644 (file)
@@ -24,7 +24,8 @@
 # GNU General Public License for more details.
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1335, USA.
 #======================================================================
 #
 # Dunning process module
 use POSIX qw(strftime);
 
 use SL::IS;
-use SL::PE;
 use SL::DN;
+use SL::DB::Dunning;
+use SL::Helper::Flash qw(flash);
+use SL::Locale::String qw(t8);
 use SL::ReportGenerator;
 
 require "bin/mozilla/common.pl";
@@ -130,7 +133,7 @@ sub show_invoices {
     if ($row->{next_dunning_config_id}) {
       map { $_->{SELECTED} = $_->{id} == $row->{next_dunning_config_id} } @{ $row->{DUNNING_CONFIG } };
     }
-    map { $row->{$_} = $form->format_amount(\%myconfig, $row->{$_} * 1, -2) } qw(amount open_amount fee interest);
+    map { $row->{$_} = $form->format_amount(\%myconfig, $row->{$_} * 1, 2) } qw(amount open_amount fee interest);
 
     if ($row->{'language_id'}) {
       $row->{language} = SL::DB::Manager::Language->find_by_or_create('id' => $row->{'language_id'})->{'description'};
@@ -150,6 +153,7 @@ sub show_invoices {
                                           'no_html'         => 1,
                                           'no_opendocument' => 1,);
 
+  $::request->layout->add_javascripts("kivi.Dunning.js");
   $form->header();
   print $form->parse_html_template("dunning/show_invoices");
 
@@ -450,6 +454,7 @@ sub show_dunning {
 
   $report->set_options_from_form();
 
+  $::request->layout->add_javascripts("kivi.Dunning.js");
   $report->generate_with_headers();
 
   $main::lxdebug->leave_sub();
@@ -473,6 +478,29 @@ sub print_dunning {
   $main::lxdebug->leave_sub();
 }
 
+sub delete {
+  $main::auth->assert('dunning_edit');
+
+  my @dunning_ids = map { $::form->{"dunning_id_$_"} } grep { $::form->{"selected_$_"} } (1..$::form->{rowcount});
+
+  if (!scalar @dunning_ids) {
+    $::form->error($::locale->text('No dunnings have been selected for printing.'));
+  }
+
+  my $dunnings = SL::DB::Manager::Dunning->get_all(query => [ dunning_id => \@dunning_ids ]);
+
+  SL::DB::Dunning->new->db->with_transaction(sub {
+    for my $dunning (@$dunnings) {
+      SL::DB::Manager::Invoice->find_by(id => $dunning->trans_id)->update_attributes(dunning_config_id => undef);
+      $dunning->delete;
+    }
+  });
+
+  flash('info', t8('#1 dunnings have been deleted', scalar @$dunnings));
+
+  search();
+}
+
 sub print_multiple {
   $main::lxdebug->enter_sub();
 
@@ -526,4 +554,14 @@ sub continue {
   call_sub($main::form->{nextsub});
 }
 
+sub dispatcher {
+  foreach my $action (qw(delete print_multiple)) {
+    if ($::form->{"action_${action}"}) {
+      call_sub($action);
+      return;
+    }
+  }
+
+  $::form->error($::locale->text('No action defined.'));
+}
 # end of main