bazz
05-21-2008, 01:06 PM
Hi,
Gradually, I am moving forwards with this.
The following select query brings in room prices by date. Each date may have a priority of 'a' but, it always has a priority of b.
If priority eq 'a' put it into the array
if priority eq 'b' and there was no 'a' put it into the array.
priority 'a' means that there is a date-specific price.
the selection for the array should revert to the high season default price (priority 'b') if there is no 'a'.
Can anyone please help me to achieve this. Currently, it still puts all prices into the array irrespective of priority code.
I tried without success to make the select do it. Then I tried fiddling with the output/processing of the array and now I have tried to filter what is put into the array.
bazz
here is the code
my $count = 0;
sub get_average_price {
my @prices=();
$count++;
foreach my $timestamp (sort @daylist) # run the loop for each date of the visit
{
my $iso = convert_to_iso($timestamp); # converts to iso format to match with db values
my ( $year, $month, $date ) = split "-", $iso, 3; # no longer needed (check)
my $day_number = get_day_number($timestamp);
#print qq( dn=$day_number<br /> ); # outputs correctly
my $sth = $bookings_db_connect->prepare ("SELECT
RR.price,
RR.priority
FROM tbl_room_rates RR
WHERE RR.room_type_id = ?
AND RR.business_id = ?
AND RR.period_start <= ?
AND RR.period_end >= ?
AND RR.day_start <= ?
AND RR.day_end >= ?
") or die "prepare statement failed: $DBI::errstr\n";
$sth->execute($room_type_id, $business_id, $iso, $iso, $day_number, $day_number );
while (my @fields = $sth->fetchrow_array )
{
if ($fields[1] eq 'a')
{
push (@prices, @fields[0]);
}
elsif ($fields[1] eq 'b')
{
push (@prices, $fields[0]);
}
}
}
foreach my $price (sort @prices)
{
if ($count > $count_after_running) zero the total between loop runs
{
$price_total = 0;
}
print qq(price = $price <br /> );
$price_total = $price_total + $price;
}
$average_price = $price_total / $number_of_nights;
$count_after_running = $count;
my $rounded_average_price = sprintf("%.2f", $average_price);
return $rounded_average_price;
}
Gradually, I am moving forwards with this.
The following select query brings in room prices by date. Each date may have a priority of 'a' but, it always has a priority of b.
If priority eq 'a' put it into the array
if priority eq 'b' and there was no 'a' put it into the array.
priority 'a' means that there is a date-specific price.
the selection for the array should revert to the high season default price (priority 'b') if there is no 'a'.
Can anyone please help me to achieve this. Currently, it still puts all prices into the array irrespective of priority code.
I tried without success to make the select do it. Then I tried fiddling with the output/processing of the array and now I have tried to filter what is put into the array.
bazz
here is the code
my $count = 0;
sub get_average_price {
my @prices=();
$count++;
foreach my $timestamp (sort @daylist) # run the loop for each date of the visit
{
my $iso = convert_to_iso($timestamp); # converts to iso format to match with db values
my ( $year, $month, $date ) = split "-", $iso, 3; # no longer needed (check)
my $day_number = get_day_number($timestamp);
#print qq( dn=$day_number<br /> ); # outputs correctly
my $sth = $bookings_db_connect->prepare ("SELECT
RR.price,
RR.priority
FROM tbl_room_rates RR
WHERE RR.room_type_id = ?
AND RR.business_id = ?
AND RR.period_start <= ?
AND RR.period_end >= ?
AND RR.day_start <= ?
AND RR.day_end >= ?
") or die "prepare statement failed: $DBI::errstr\n";
$sth->execute($room_type_id, $business_id, $iso, $iso, $day_number, $day_number );
while (my @fields = $sth->fetchrow_array )
{
if ($fields[1] eq 'a')
{
push (@prices, @fields[0]);
}
elsif ($fields[1] eq 'b')
{
push (@prices, $fields[0]);
}
}
}
foreach my $price (sort @prices)
{
if ($count > $count_after_running) zero the total between loop runs
{
$price_total = 0;
}
print qq(price = $price <br /> );
$price_total = $price_total + $price;
}
$average_price = $price_total / $number_of_nights;
$count_after_running = $count;
my $rounded_average_price = sprintf("%.2f", $average_price);
return $rounded_average_price;
}