Revision 3b9c2119
Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt
SL/DO.pm | ||
---|---|---|
39 | 39 |
use SL::AM; |
40 | 40 |
use SL::Common; |
41 | 41 |
use SL::CVar; |
42 |
use SL::DB::DeliveryOrder; |
|
43 |
use SL::DB::Status; |
|
42 | 44 |
use SL::DBUtils; |
43 | 45 |
use SL::RecordLinks; |
44 | 46 |
use SL::IC; |
... | ... | |
507 | 509 |
my $form = $main::form; |
508 | 510 |
my $spool = $::lx_office_conf{paths}->{spool}; |
509 | 511 |
|
510 |
# connect to database |
|
511 |
my $dbh = $form->get_standard_dbh($myconfig); |
|
512 |
|
|
513 |
# delete spool files |
|
514 |
my $query = qq|SELECT s.spoolfile FROM status s WHERE s.trans_id = ?|; |
|
515 |
my $sth = prepare_execute_query($form, $dbh, $query, conv_i($form->{id})); |
|
516 |
|
|
517 |
my $spoolfile; |
|
518 |
my @spoolfiles = (); |
|
519 |
my @values; |
|
520 |
|
|
521 |
while (($spoolfile) = $sth->fetchrow_array) { |
|
522 |
push @spoolfiles, $spoolfile; |
|
523 |
} |
|
524 |
$sth->finish(); |
|
525 |
|
|
526 |
# delete-values |
|
527 |
@values = (conv_i($form->{id})); |
|
528 |
|
|
529 |
# delete status entries |
|
530 |
$query = qq|DELETE FROM status |
|
531 |
WHERE trans_id = ?|; |
|
532 |
do_query($form, $dbh, $query, @values); |
|
512 |
my $rc = SL::DB::Order->new->db->with_transaction(sub { |
|
513 |
my @spoolfiles = grep { $_ } map { $_->spoolfile } @{ SL::DB::Manager::Status->get_all(where => [ trans_id => $form->{id} ]) }; |
|
533 | 514 |
|
534 |
# delete individual entries |
|
535 |
$query = qq|DELETE FROM delivery_order_items_stock |
|
536 |
WHERE delivery_order_item_id IN ( |
|
537 |
SELECT id FROM delivery_order_items |
|
538 |
WHERE delivery_order_id = ? |
|
539 |
)|; |
|
540 |
do_query($form, $dbh, $query, @values); |
|
541 |
|
|
542 |
# delete individual entries |
|
543 |
$query = qq|DELETE FROM delivery_order_items |
|
544 |
WHERE delivery_order_id = ?|; |
|
545 |
do_query($form, $dbh, $query, @values); |
|
546 |
|
|
547 |
# delete DO record |
|
548 |
$query = qq|DELETE FROM delivery_orders |
|
549 |
WHERE id = ?|; |
|
550 |
do_query($form, $dbh, $query, @values); |
|
515 |
SL::DB::DeliveryOrder->new(id => $form->{id})->delete; |
|
551 | 516 |
|
552 |
$query = qq|DELETE FROM shipto |
|
553 |
WHERE trans_id = ? AND module = 'DO'|; |
|
554 |
do_query($form, $dbh, $query, @values); |
|
555 |
|
|
556 |
my $rc = $dbh->commit(); |
|
517 |
my $spool = $::lx_office_conf{paths}->{spool}; |
|
518 |
unlink map { "$spool/$_" } @spoolfiles if $spool; |
|
557 | 519 |
|
558 |
if ($rc) { |
|
559 |
foreach $spoolfile (@spoolfiles) { |
|
560 |
unlink "$spool/$spoolfile" if $spoolfile; |
|
561 |
} |
|
562 |
} |
|
520 |
1; |
|
521 |
}); |
|
563 | 522 |
|
564 | 523 |
$main::lxdebug->leave_sub(); |
565 | 524 |
|
Auch abrufbar als: Unified diff
Abhängigkeiten von Lieferscheinen und Aufträgen/Angeboten in der Datenbank löschen
und nicht mehr programmseitig. Das geschieht durch Verwendung von
sinnvollen 'ON DELETE CASCADE/SET NULL'-Foreign-Key-Anweisungen und
Triggern, die aus diejenigen Tabellen löschen, in denen eine
trans_id-Spalte auf mehrere Tabellen verweisen kann (status, ship_to).