Revision fdd6ef43
Von Werner Hahn vor fast 2 Jahren hinzugefügt
SL/Controller/Order.pm | ||
---|---|---|
42 | 42 |
use SL::Helper::UserPreferences::UpdatePositions; |
43 | 43 |
|
44 | 44 |
use SL::Controller::Helper::GetModels; |
45 |
use SL::Model::Record; |
|
45 | 46 |
|
46 | 47 |
use List::Util qw(first sum0); |
47 | 48 |
use List::UtilsBy qw(sort_by uniq_by); |
... | ... | |
195 | 196 |
sub action_delete { |
196 | 197 |
my ($self) = @_; |
197 | 198 |
|
198 |
my $errors = $self->delete(); |
|
199 |
|
|
200 |
if (scalar @{ $errors }) { |
|
201 |
$self->js->flash('error', $_) foreach @{ $errors }; |
|
202 |
return $self->js->render(); |
|
203 |
} |
|
204 |
|
|
199 |
my $number_type = $self->order->type =~ m{order} ? 'ordnumber' : 'quonumber'; |
|
200 |
my %history = (snumbers => $number_type . '_' . $self->order->$number_type); |
|
201 |
my %params = (history => \%history); |
|
202 |
SL::Model::Record->delete($self->order, %params); |
|
205 | 203 |
my $text = $self->type eq sales_order_type() ? $::locale->text('The order has been deleted') |
206 | 204 |
: $self->type eq purchase_order_type() ? $::locale->text('The order has been deleted') |
207 | 205 |
: $self->type eq sales_quotation_type() ? $::locale->text('The quotation has been deleted') |
... | ... | |
2099 | 2097 |
} |
2100 | 2098 |
} |
2101 | 2099 |
|
2102 |
# delete the order |
|
2103 |
# |
|
2104 |
# And remove related files in the spool directory |
|
2105 |
sub delete { |
|
2106 |
my ($self) = @_; |
|
2107 |
|
|
2108 |
my $errors = []; |
|
2109 |
my $db = $self->order->db; |
|
2110 |
|
|
2111 |
$db->with_transaction( |
|
2112 |
sub { |
|
2113 |
my @spoolfiles = grep { $_ } map { $_->spoolfile } @{ SL::DB::Manager::Status->get_all(where => [ trans_id => $self->order->id ]) }; |
|
2114 |
$self->order->delete; |
|
2115 |
my $spool = $::lx_office_conf{paths}->{spool}; |
|
2116 |
unlink map { "$spool/$_" } @spoolfiles if $spool; |
|
2117 |
|
|
2118 |
$self->save_history('DELETED'); |
|
2119 |
|
|
2120 |
1; |
|
2121 |
}) || push(@{$errors}, $db->error); |
|
2122 |
|
|
2123 |
return $errors; |
|
2124 |
} |
|
2125 |
|
|
2126 | 2100 |
# save the order |
2127 | 2101 |
# |
2128 | 2102 |
# And delete items that are deleted in the form. |
Auch abrufbar als: Unified diff
OrderController delete auf SL/Model/Record->delete gemapt