booking calendar adding pos.reserv_time and some fixes

This commit is contained in:
ragu 2024-05-07 20:20:19 +02:00
parent d5a98d0c54
commit 1112b2c2b5
5 changed files with 63 additions and 44 deletions

View file

@ -49,10 +49,8 @@ sub new {
return $self;
}
my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
my $now_date = strftime "%Y-%m-%d", localtime;
my $strp = DateTime::Format::Strptime->new(
pattern => '%Y-%m-%dT%H:%M:%S',
pattern => '%Y-%m-%dT%H:%M',
locale => 'de_DE',
time_zone => 'Europe/Berlin',
on_error => 'croak',
@ -909,13 +907,13 @@ sub booking_request(){
my $lock_state = $q->escapeHTML($q->param('lock_state')) || "";
my $now_dt = DateTime->now( time_zone => "Europe/Berlin" );
my $reserv_starttime = $q->escapeHTML($q->param('reserv_starttime')) || $now_dt;
my $reserv_endtime = $q->escapeHTML($q->param('reserv_endtime')) || $now_dt;
my $reserv_starttime = $q->escapeHTML($q->param('reserv_starttime')) || "";
my $reserv_endtime = $q->escapeHTML($q->param('reserv_endtime')) || "";
my $calreserv = $q->escapeHTML($q->param('calreserv')) || 0;
my $request_para = {
start_time => $reserv_starttime,
end_time => $reserv_endtime,
start_time => "now()",
end_time => "now()",
calreserv => "$calreserv",
};
my $dbh = "";
@ -1020,28 +1018,41 @@ sub booking_request(){
if($sum_balance <= 1 && !$ctt_opos->{c_id}){
my $booking_state = 2;
$booking_state = 7 if($calreserv);
my $timestamp = DateTime->now( time_zone => "Europe/Berlin" );
my $now_time = $strp->parse_datetime($timestamp);
my $dtstart = $strp->parse_datetime($reserv_starttime);
my $dtend = $strp->parse_datetime($reserv_endtime);
if($reserv_starttime && $reserv_endtime){
my $timestamp = DateTime->now( time_zone => "Europe/Berlin" );
my $now_time = $strp->parse_datetime($timestamp);
my $start_loc = $dtstart->strftime("%d.%m.%Y %H:%M");
my $end_loc = $dtend->strftime("%d.%m.%Y %H:%M");
my $dtstart = $strp->parse_datetime($reserv_starttime);
my $dtend = $strp->parse_datetime($reserv_endtime);
if($dtend >= $now_time){
my $until_time = $now_time->add( weeks => 4 );
#max allowed future rental
if($dtend > $until_time){
$response_state = "Failure 4261, 4 weeks reserv timerange";
$response_text = "Abbruch, Reservierungen sind maximal 4 Wochen im voraus erlaubt";
}else{
$pos_id = $dbt->insert_pos($dbh,$ctt->{c_id},$ct_bike,$ct_station,$auth,$ct_tariff,$request_para,$bike,$booking_state,$owner,$sig_book);
$bw->log("booking_request insert_pos:",$pos_id,"");
}
my $start_loc = $dtstart->strftime("%d.%m.%Y %H:%M");
my $end_loc = $dtend->strftime("%d.%m.%Y %H:%M");
if($dtend >= $now_time){
my $until_time = $now_time->add( weeks => 4 );
#max allowed future rental
if($dtend > $until_time){
$response_state = "Failure 4261, 4 weeks reserv timerange";
$response_text = "Abbruch, Reservierungen sind maximal 4 Wochen im voraus erlaubt";
}else{
$request_para = {
start_time => "$reserv_starttime",
end_time => "$reserv_endtime",
calreserv => "$calreserv",
};
$pos_id = $dbt->insert_pos($dbh,$ctt->{c_id},$ct_bike,$ct_station,$auth,$ct_tariff,$request_para,$bike,$booking_state,$owner,$sig_book);
$bw->log("booking_request reserved insert_pos:",$pos_id,"");
$response_state = "OK, bike " . $bike . " succesfully reserved";
$response_text = "Erfolgreiche Buchung: $start_loc - $end_loc.";
}
}else{
$response_state = "Failure 4260, reserv timerange";
$response_text = "Abbruch, die Mietzeit liegt in der Vergangenheit";
}
}else{
$response_state = "Failure 4260, reserv timerange";
$response_text = "Abbruch, die Mietzeit liegt in der Vergangenheit";
$pos_id = $dbt->insert_pos($dbh,$ctt->{c_id},$ct_bike,$ct_station,$auth,$ct_tariff,$request_para,$bike,$booking_state,$owner,$sig_book);
$bw->log("booking_request insert_pos:",$pos_id,"");
}
if($pos_id){
@ -1055,19 +1066,15 @@ sub booking_request(){
};
$dbt->update_one($dbh,$update_ctt,"start_time='$now_dt'");
# state=7 meens reserved, prevents auto available after 15min
if($calreserv){
$response_state = "OK, bike " . $bike . " succesfully reserved";
$response_text = "Erfolgreiche Buchung: $start_loc - $end_loc.";
}
#update waren bike state only if adhock booking
elsif(!$calreserv){
if(!$calreserv){
my $update_ct = {
table => "content",
c_id => $ct_bike->{c_id},
mtime => "now()",
owner => $owner,
};
$dbt->update_one($dbh,$update_ct,"int10='2'");
$response_state = "OK, bike " . $bike . " succesfully adhock requested";
$response_text = "Rad $bike wurde erfolgreich für 15 Min. adhock reserviert";
}
@ -1142,8 +1149,24 @@ sub booking_request(){
};
$bw->log("booking_request response_state:",$return,"");
#final booking request update
if($pos_id){
my $update_pos = {
table => "contenttranspos",
mtime => "now()",
};
if($calreserv && $reserv_starttime && $reserv_endtime && $reserv_starttime =~ /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/ && $reserv_endtime =~ /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/){
$update_pos->{reserv_starttime} = $reserv_starttime;
$update_pos->{reserv_endtime} = "$reserv_endtime";
}
my $logvalues = "pos_id=$pos_id, state=$state, start_time=$request_para->{start_time}, end_time=$request_para->{end_time}, calreserv=$request_para->{calreserv}, response_state=$response_state";
my $log_stamp = strftime "%d.%m.%Y %H:%M:%S", localtime;
$update_pos->{txt24} = "\n- $log_stamp $logvalues";
$dbt->update_record($dbh,$update_pos,{ c_id => $pos_id });
}
return $return;
}
}#end booking_request
#booking_cancel changed to booking_update
sub booking_update {
@ -1356,7 +1379,7 @@ sub booking_update {
if(($state_key == 3 && ($record_pos->{int10} == 2 || $record_pos->{int10} == 7)) || ($state_key == 3 && $record_pos->{int10} == 3 && $q->param('genkey') eq "1")){
$update_pos->{start_time} = "now()";
#$update_pos->{end_time} = "now()";#don't set anymore because of revserv time
$update_pos->{end_time} = "now()" if(!$record_pos->{reserv_endtime});
$update_pos->{txt05} = "$record_cc->{txt06}";#pos start GPS from content end GPS
$update_pos->{int06} = "$record_cc->{int04}";#pos start station from content station
$update_pos->{txt12} = "$dbt->{operator}->{$varenv->{dbname}}->{oprefix}";#pos start station prefix
@ -1970,11 +1993,6 @@ sub user_bikes_occupied {
$pref->{end_time} = ">=::now()";
}
if($q->param('request') eq "booking_request"){
$pref->{int10} = "IN::('2','3','7')";
$pref->{start_time} = ">=::now()";
}
$pref->{int06} = $station if($station);#pos start-station
my $record = {};

View file

@ -323,6 +323,7 @@ elsif($q->param('request') eq "booking_request"){
$apif->stations_caching($q,\%varenv,$authraw);
}
$bw->log("booking_request response_book:",$response_book,"");
#just in time booking
if(ref($response_book) eq "HASH" && $response_book->{response_state} =~ /OK/ && $q->param('state') && $q->param('state') =~ /occupied/){
my $booking_values = {};

View file

@ -704,6 +704,8 @@ sub collect_post(){
}else{
$cp_where .= " and cp.$key $op '$value'";
}
}elsif($key eq "int10" && $value){
$cp_where .= " and (cp.$key $op $value OR (cp.int10 = 7 and now() BETWEEN cp.start_time and cp.end_time))";
}elsif($key =~ /^(c_id|ca_id|ct_id|owner|barcode|int\d+)$/ && $value){
if($value eq "null"){
$cp_where .= " and (cp.$key is null OR cp.$key = 0)";
@ -712,8 +714,6 @@ sub collect_post(){
}
}elsif($fetch->{catch} && $key eq "template_id" && $value){
$cp_where .= " and cp.$key $op $value";
#}elsif(!$fetch->{catch} && $key =~ /main_id|template_id/ && $value){
#$ct_where .= " and rel.$key $op $value";
}
}
}
@ -1025,7 +1025,7 @@ sub update_record(){
$update->{$key} =~ s/\s$//g if($update->{$key});
my $value = $update->{$key} || "";
$value = "$update->{$key}" if(looks_like_number($update->{$key}));
if($key =~ /^(ct_name$|txt\d+|state|start_time|end_time|byte)/){
if($key =~ /^(ct_name$|txt\d+|state|start_time|end_time|reserv_starttime|reserv_endtime|byte)/){
if($value && $value eq "null"){
$set .= " $key=$value,";
}else{

View file

@ -477,7 +477,7 @@ EOF
}elsif($key =~ /int10/ && "$size" eq "select"){#bike_state
my @_lock_valxx = ();
foreach my $s_key (sort keys (%{ $dbt->{copri_conf}->{bike_state} })) {
push @_lock_valxx, "$s_key:$dbt->{copri_conf}->{bike_state}->{$s_key}" if($s_key =~ /1|2|3/);
push @_lock_valxx, "$s_key:$dbt->{copri_conf}->{bike_state}->{$s_key}" if($s_key =~ /1|2|3|7/);
}
print $q->Tr();
print $q->td({-class=>'left_italic_cms'},"$des"),"\n";

View file

@ -354,7 +354,7 @@ sub tpl(){
($year_st,$mon_st,$day_st,$hh_st,$mm_st) = $lb->split_date($cttpos->{$pid}->{itime});
}
if($cttpos->{$pid}->{end_time}){
$cttpos->{$pid}->{end_time} = $now_dt if($node_meta->{ct_table} eq "contenttranspos" && $cttpos->{$pid}->{start_time} eq $cttpos->{$pid}->{end_time} );
$cttpos->{$pid}->{end_time} = $now_dt if($node_meta->{ct_table} eq "contenttranspos" && $cttpos->{$pid}->{int10} == 3 && !$cttpos->{$pid}->{reserv_endtime});
($year_en,$mon_en,$day_en,$hh_en,$mm_en) = $lb->split_date($cttpos->{$pid}->{end_time});
}else{
($year_en,$mon_en,$day_en,$hh_en,$mm_en) = $lb->split_date($cttpos->{$pid}->{itime});