1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#
# first of all select all records matching the current records
# articleNr from our price table
$where = "WHERE articleNr='".xChop($values{articlenr})."'";
$cmd = "SELECT instock, vendor, price FROM prices $where";
$xret = $dbconn->prepare($cmd);
$xret->execute || $log->debug("$cmd -- could not get items in stock. SQL Error:$DBI::errstr");
$winner = 9999999;
#
# scan them
while(@array = $xret->fetchrow_array) {
#
# and only look at those which refer to articles that are in stock
if(@array[0] eq "1") {
#
# use XChop to remove any trailing blanks and keep
# the vendor in mind
$vendor = xChop(@array[1]);
#
# then get the shippingCost that is usually billed
# by this vendor
$cmd = "SELECT shippingCost FROM vendors ";
$cmd .="WHERE name='$vendor'";
$lret = $dbconn->prepare($cmd);
$lret->execute || $log->debug("could not get shipping cost. SQL Error:$DBI::errstr");
#
# and set our $sh variable accordingly
if(@ldat = $lret->fetchrow_array) {
$sh = @ldat[0];
} else {
$sh = 0.0;
}
#
# now calculate the total price of the article if purchased
# from this vendor
$price = @array[2] + $sh;
#
# and if this was the cheapest go ahead and store
# the reference
if($price > 0 && $price < $winner) {
$winner = $price;
$winnm = $vendor;
}
}
}
#
# finally return our result...
unless ($winnm) {
"0.00 sorry, no price";
} else {
sprintf("%.2f $winnm", $winner);
}
|