changing rental freed_time fix

This commit is contained in:
ragu 2023-04-12 16:12:19 +02:00
parent 94fcafaff3
commit 8200270e93
6 changed files with 70 additions and 46 deletions

View file

@ -928,33 +928,6 @@ sub booking_request(){
close_time => "is::null",
};
#for free rental
#depends on operator, only 1 rental get freed_time
my $pref_pos = {
table => "contenttranspos",
fetch => "all",
keyfield => "c_id",
ca_id => "$auth->{c_id}",
};
if($dbt->{operator}->{$varenv->{dbname}}->{project} eq "Konstanz"){
$pref_pos->{int10} = "IN::(2,3)";
}else{
my $day = strftime "%d", localtime;
my $mon = strftime "%m", localtime;
my $year = strftime "%Y", localtime;
my ($nyear,$nmon,$nday) = Add_Delta_YMD($year,$mon,$day, 0,0,1);
$pref_pos->{time_range} = "start_time >= '$year-$mon-$day' and start_time < '$nyear-$nmon-$nday'";
}
my $record_pos = $dbt->fetch_tablerecord($dbh,$pref_pos);
my $activ_count=1;#+1 because counting before insert.
foreach my $pid (sort { $record_pos->{$a}->{c_id} <=> $record_pos->{$b}->{c_id} } keys (%$record_pos)){
$activ_count++;
}
if($activ_count > 1){
delete $ct_tariff->{time02};
}
#if bike and tariff
if($ct_bike->{barcode} && $ct_tariff->{barcode}){
my $ctt = {};
@ -988,7 +961,7 @@ sub booking_request(){
if($ctt->{c_id}){
#2 = "requested"
$pos_id = $dbt->insert_pos($dbh,$ctt->{c_id},$ct_bike,$ct_station,$auth,$ct_tariff,$now_dt,$bike,"2",$owner,$sig_book,$activ_count);
$pos_id = $dbt->insert_pos($dbh,$ctt->{c_id},$ct_bike,$ct_station,$auth,$ct_tariff,$now_dt,$bike,"2",$owner,$sig_book);
$bw->log("booking_request insert_pos:",$pos_id,"");
if($pos_id){
@ -1030,6 +1003,38 @@ sub booking_request(){
return $return;
}
#for free rental
#depends on operator, only 1 rental get freed_time
sub count_freedrental {
my $self = shift;
my $varenv = shift;
my $auth = shift;
my $pref_pos = {
table => "contenttranspos",
fetch => "all",
keyfield => "c_id",
ca_id => "$auth->{c_id}",
time02 => ">::00:00",
};
if($dbt->{operator}->{$varenv->{dbname}}->{project} eq "Konstanz"){
$pref_pos->{int10} = "3";
}else{
my $day = strftime "%d", localtime;
my $mon = strftime "%m", localtime;
my $year = strftime "%Y", localtime;
my ($nyear,$nmon,$nday) = Add_Delta_YMD($year,$mon,$day, 0,0,1);
$pref_pos->{time_range} = "start_time >= '$year-$mon-$day' and start_time < '$nyear-$nmon-$nday'";
}
my $record_pos = $dbt->fetch_tablerecord($dbh,$pref_pos);
my $active_count=0;
foreach my $pid (sort { $record_pos->{$a}->{c_id} <=> $record_pos->{$b}->{c_id} } keys (%$record_pos)){
$active_count++;
}
return $active_count;
}
#int03=1 if sepa, 2=CC
#int04==1 if email Ack
#int13==1 if sms Ack
@ -1223,6 +1228,11 @@ sub booking_update(){
$update_pos->{int10} = 3;
$update_pos->{txt11} = "$sig_book->{rentalId}" if($sig_book->{rentalId});
$update_pos->{txt22} = "$sig_book->{bikeId}" if($sig_book->{bikeId});
#on occupied, we don't know if will be a accountable rental. disabled
#my $active_count = $self->count_freedrental($varenv,$auth);
#$update_pos->{time02} = "00:00" if($active_count > 1);
$rows = $dbt->update_record($dbh,$update_pos,$record_pos);
if($rows > 0){
@ -1291,6 +1301,21 @@ sub booking_update(){
$update_pos->{int40} = "$counting->{int40}" if(looks_like_number($counting->{int40}));
$update_pos->{int41} = "$counting->{int41}" if(looks_like_number($counting->{int41}));
#we can get only freed accountable rentals only on rental end's
#testing, if works change prcing methode
my $debug=1;
open(FILE,">>$varenv{logdir}/count_freedrental.log") if($debug);
print FILE "\n*-->$now_dt $varenv->{dbname}\n$bike | $state | $lock_state, auth:$auth->{c_id}\n" if($debug);
print FILE "rental_minute_all: $pricing->{rentalog}->{rental_minute_all} > 0\n" if($debug);
if($pricing->{rentalog}->{rental_minute_all} > 0){
my $active_count = $self->count_freedrental($varenv,$auth);
if($active_count > 1){
$update_pos->{time02} = "00:00";
}
print FILE "if active_count > $active_count then update time02:$update_pos->{time02}\n" if($debug);
}
close(FILE) if($debug);
$rows_end = $dbt->update_record($dbh,$update_pos,$record_pos);
if($rows_end > 0){