projects
/
kivitendo-erp.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
e549422
)
Den Test, ob ein Artikel noch nicht benutzt wurde und deshalb gelöscht werden kann...
author
Moritz Bunkus
<m.bunkus@linet-services.de>
Mon, 19 Nov 2007 08:28:57 +0000
(08:28 +0000)
committer
Moritz Bunkus
<m.bunkus@linet-services.de>
Mon, 19 Nov 2007 08:28:57 +0000
(08:28 +0000)
SL/IC.pm
patch
|
blob
|
history
diff --git
a/SL/IC.pm
b/SL/IC.pm
index
5dfcad8
..
62af112
100644
(file)
--- a/
SL/IC.pm
+++ b/
SL/IC.pm
@@
-203,37
+203,25
@@
sub get_part {
$sth->finish;
# is it an orphan
$sth->finish;
# is it an orphan
- $query =
- qq|SELECT i.parts_id
- FROM invoice i
- WHERE (i.parts_id = ?)
-
- UNION
-
- SELECT o.parts_id
- FROM orderitems o
- WHERE (o.parts_id = ?)
+ my @referencing_tables = qw(invoice orderitems invoice inventory rmaitems);
+ my %column_map = ( );
+ my $parts_id = conv_i($form->{id});
- UNION
+ $form->{orphaned} = 1;
- SELECT a.parts_id
- FROM assembly a
- WHERE (a.parts_id = ?)|;
- @values = (conv_i($form->{id}), conv_i($form->{id}), conv_i($form->{id}));
- ($form->{orphaned}) = selectrow_query($form, $dbh, $query, @values);
- $form->{orphaned} = !$form->{orphaned};
+ foreach my $table (@referencing_tables) {
+ my $column = $column_map{$table} || 'parts_id';
+ $query = qq|SELECT $column FROM $table WHERE $column = ? LIMIT 1|;
+ my ($found) = selectrow_query($form, $dbh, $query, $parts_id);
- $form->{"unit_changeable"} = 1;
- foreach my $table (qw(invoice assembly orderitems inventory license)) {
- $query = qq|SELECT COUNT(*) FROM $table WHERE parts_id = ?|;
- my ($count) = selectrow_query($form, $dbh, $query, conv_i($form->{"id"}));
-
- if ($count) {
- $form->{"unit_changeable"} = 0;
+ if ($found) {
+ $form->{orphaned} = 0;
last;
}
}
last;
}
}
+ $form->{"unit_changeable"} = $form->{orphaned};
+
$dbh->disconnect;
$main::lxdebug->leave_sub();
$dbh->disconnect;
$main::lxdebug->leave_sub();
@@
-724,9
+712,9
@@
sub delete {
# connect to database, turn off AutoCommit
my $dbh = $form->dbconnect_noauto($myconfig);
# connect to database, turn off AutoCommit
my $dbh = $form->dbconnect_noauto($myconfig);
- my %columns = ( "assembly" => "id", "
alternate" => "id", "
parts" => "id" );
+ my %columns = ( "assembly" => "id", "parts" => "id" );
- for my $table (qw(prices partstax makemodel inventory assembly parts)) {
+ for my $table (qw(prices partstax makemodel inventory assembly
license translation
parts)) {
my $column = defined($columns{$table}) ? $columns{$table} : "parts_id";
do_query($form, $dbh, qq|DELETE FROM $table WHERE $column = ?|, @values);
}
my $column = defined($columns{$table}) ? $columns{$table} : "parts_id";
do_query($form, $dbh, qq|DELETE FROM $table WHERE $column = ?|, @values);
}