From da55cfa09e13cf37260b2baa4c9b53fd03ec8f0e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Mon, 25 Jan 2016 15:29:03 +0100 Subject: [PATCH] =?utf8?q?Auftrags-Controller:=20Auftrag=20l=C3=B6schen=20?= =?utf8?q?k=C3=B6nnen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/Order.pm | 39 ++++++++++++++++++++++++++++++ locale/de/all | 1 + templates/webpages/order/form.html | 10 ++++++++ 3 files changed, 50 insertions(+) diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index 759334155..0e89bfea1 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -81,6 +81,25 @@ sub action_update { ); } +sub action_delete { + my ($self) = @_; + + my $errors = $self->_delete(); + + if (scalar @{ $errors }) { + $self->js->flash('error', $_) foreach @{ $errors }; + return $self->js->render(); + } + + flash_later('info', $::locale->text('The order has been deleted')); + my @redirect_params = ( + action => 'edit', + type => $self->type, + ); + + $self->redirect_to(@redirect_params); +} + sub action_save { my ($self) = @_; @@ -343,6 +362,26 @@ sub _get_unalterable_data { } +sub _delete { + my ($self) = @_; + + my $errors = []; + my $db = $self->order->db; + + $db->do_transaction( + sub { + my @spoolfiles = grep { $_ } map { $_->spoolfile } @{ SL::DB::Manager::Status->get_all(where => [ trans_id => $self->order->id ]) }; + $self->order->delete; + my $spool = $::lx_office_conf{paths}->{spool}; + unlink map { "$spool/$_" } @spoolfiles if $spool; + + 1; + }) || push(@{$errors}, $db->error); + + return $errors; +} + + sub _save { my ($self) = @_; diff --git a/locale/de/all b/locale/de/all index 219ad76ac..5a47fe8c4 100755 --- a/locale/de/all +++ b/locale/de/all @@ -2839,6 +2839,7 @@ $self->{texts} = { 'The number of days for full payment' => 'Die Anzahl Tage, bis die Rechnung in voller Höhe bezahlt werden muss', 'The numbering will start at 1 with each requirement spec.' => 'Die Nummerierung beginnt bei jedem Pflichtenheft bei 1.', 'The option field is empty.' => 'Das Optionsfeld ist leer.', + 'The order has been deleted' => 'Der Auftrag wurde gelöscht.', 'The order has been saved' => 'Der Auftrag wurde gespeichert.', 'The package name is invalid.' => 'Der Paketname ist ungültig.', 'The parts for this delivery order have already been transferred in.' => 'Die Artikel dieses Lieferscheins wurden bereits eingelagert.', diff --git a/templates/webpages/order/form.html b/templates/webpages/order/form.html index 62225e2eb..977d41f59 100644 --- a/templates/webpages/order/form.html +++ b/templates/webpages/order/form.html @@ -31,12 +31,22 @@ [% L.hidden_tag('action', 'Order/dispatch') %] [% L.button_tag('save()', LxERP.t8('Save')) %] +[%- IF SELF.order.id && ( (SELF.cv == 'customer' && INSTANCE_CONF.get_sales_order_show_delete) || (SELF.cv == 'vendor' && INSTANCE_CONF.get_purchase_order_show_delete) ) %] + [% L.button_tag('delete_order()', LxERP.t8('Delete'), confirm=LxERP.t8("Are you sure?")) %] +[%- END %]