my $action = param("ACTION"); if($action) { #Bond the built-in and accessory components to the parent. if($action eq "BOND") { my $main = param("MAIN"); my @built = param("BUILT"); my @acc = param("ACC"); my $query = "SELECT location FROM demstock2 WHERE ds_id=$main"; my $sth = $db->prepare($query); $sth->execute or print "Can't execute
$query
: " . $db->errstr . "
\n"; my $mainlocation = $sth->fetchrow_hashref; if($mainlocation->{"location"} ne "STOCK") { print b("Refusing to bond items to $main, as it isn't in main stock") . br(); } else { $sth->finish(); for my $acc (@acc) { my $query = "SELECT curr_parent_id FROM demstock2 WHERE ds_id=$acc"; my $sth = $db->prepare($query); $sth->execute() or print "Can't execute $query: " . $sth->errstr . "
\n"; my $current_status = $sth->fetchrow_hashref; $sth->finish(); if($current_status->{"curr_parent_id"} != 0) { print "Refusing to modify the status of demstock $acc. It has already been moved
\n"; } else { my $query = "UPDATE demstock2 SET curr_parent_id=$main WHERE ds_id=$acc"; my $sth = $db->prepare($query); $sth->execute or print "Can't execute
$query
: " . $db->errstr . "
\n"; $sth->finish(); $query = "INSERT INTO action "; $query .= "(action_id, action_type, ds_id, occurred, ref_no, staff_id) VALUES" ; $query .= "(NULL, 'MOVE', $acc, CURRENT_TIMESTAMP, \"0,$main\", $caluser)"; $sth = $db->prepare($query); $sth->execute or print "Can't execute
$query
: " . $db->errstr . "
\n"; $sth->finish; } } for my $built (@built) { my $query = "SELECT curr_parent_id FROM demstock2 WHERE ds_id=$built"; my $sth = $db->prepare($query); $sth->execute() or print "Can't execute $query: " . $sth->errstr . "
\n"; my $current_status = $sth->fetchrow_hashref; $sth->finish(); if($current_status->{"curr_parent_id"} != 0) { print "Refusing to modify the status of demstock $built. It has already been moved
\n"; } else { my $query = "UPDATE demstock2 SET curr_parent_id=$main WHERE ds_id=$built"; my $sth = $db->prepare($query); $sth->execute() or print "Can't execute $query: " . $sth->errstr . "
\n"; $sth->finish(); $query = "INSERT INTO action "; $query .= "(action_id, action_type, ds_id, occurred, ref_no, staff_id) VALUES" ; $query .= "(NULL, 'MOVE', $built, CURRENT_TIMESTAMP, \"0,$main\", $caluser)"; $sth = $db->prepare($query); $sth->execute or print "Can't execute
$query
: " . $sth->errstr . "
\n"; $sth->finish; } } } } }