From b92f2c6b5c2e1802de3278044b35683cc9889014 Mon Sep 17 00:00:00 2001 From: ragu Date: Tue, 17 Oct 2023 07:32:27 +0200 Subject: [PATCH] rental freed_time and some service staff coding --- copri4/main/src/Mod/APIfunc.pm | 46 +++++++++++------ copri4/main/src/Mod/APIjsonserver.pm | 9 ++-- copri4/main/src/Mod/DBtank.pm | 4 +- copri4/main/src/Mod/Indexsharee.pm | 3 +- copri4/main/src/Mod/Pricing.pm | 68 +++++++++++++++++--------- copri4/main/src/Mod/Printpreview.pm | 4 +- copri4/main/src/Tpl/Calorin.pm | 2 +- copri4/main/src/Tpl/TransPositionen.pm | 2 +- 8 files changed, 91 insertions(+), 47 deletions(-) diff --git a/copri4/main/src/Mod/APIfunc.pm b/copri4/main/src/Mod/APIfunc.pm index 9ed6cd3..042e192 100755 --- a/copri4/main/src/Mod/APIfunc.pm +++ b/copri4/main/src/Mod/APIfunc.pm @@ -975,7 +975,8 @@ sub booking_request(){ $dbt->update_one($dbh,$update_ctt,"start_time='$now_dt'"); #BVB once auto-coupon until 2023-08-31 - if($varenv->{dbname} eq "sharee_bvb"){ + #disabled + if(1==2 && $varenv->{dbname} eq "sharee_bvb"){ #BVB 3-Stunden-Freifahrt my $auto_coupon = "123"; my $pref_co = { @@ -1278,7 +1279,8 @@ sub booking_update(){ #return after booking_update #in real, we know freed accountable rentals only on rental end's - $pri->count_freedrental($q,$varenv,$auth->{c_id},$record_pos); + my $adjust_freedtime = 1; + $pri->count_freedrental($q,$varenv,$auth->{c_id},$record_pos,$adjust_freedtime); my ($pricing,$counting) = $pri->counting_rental($varenv,$record_pos); #int03 only used for tarif counting backwards compatibility @@ -1782,12 +1784,16 @@ sub rentals(){ my $pricing->{$id} = {}; my $counting = {}; #adjusting freed time rental by called bikes_occupied - $pri->count_freedrental("rentals by user_bikes_occupied",\%varenv,$auth->{c_id},$record->{$id}); + #further_freedtime_available will be 0 if no further freed_time + my $adjust_freedtime = 1; + my $further_freedtime_available = 1; + $further_freedtime_available = $pri->count_freedrental("rentals by user_bikes_occupied",\%varenv,$auth->{c_id},$record->{$id},$adjust_freedtime); + $return->{$id}->{further_freedtime_available} = "$further_freedtime_available"; ($pricing->{$id}, $counting) = $pri->counting_rental(\%varenv,$record->{$id}); #$bw->log("rentals-rentalog",$pricing->{$id}->{rentalog},""); $pricing->{$id}->{rentalog} = "";#just for debuggiog, removed to reduce data in json - my $return_feed->{$id} = $pri->fetch_rentalfeed($varenv_prim,\%varenv,$record->{$id},$pricing->{$id}); + my $return_feed->{$id} = $pri->fetch_rentalfeed($varenv_prim,\%varenv,$record->{$id},$pricing->{$id},$further_freedtime_available); $return->{$id} = { %{ $pricing->{$id} }, %{ $return_feed->{$id} } }; my $bike_id = $return->{$id}->{bike}; @@ -1877,6 +1883,13 @@ sub bikes_available(){ my $td_template = $dbt->rental_description_template($varenv_prim); + #return list of occupied/requested bikes + my $rentals_record = {}; + my $rentals_response = {}; + $rentals_record = $self->user_bikes_occupied($dbh,$auth,""); + $rentals_response = $self->rentals($varenv_prim,$rentals_record,$auth,"");#returns JSON rental values + $rentals_response->{further_freedtime_available} = 1 if(!keys (%$rentals_response)); + foreach my $id (sort { $record->{$a}->{barcode} <=> $record->{$b}->{barcode} } keys (%$record)){ $return->{$id}->{authed} = "$authed"; $return->{$id}->{station} = "$dbt->{operator}->{$varenv->{dbname}}->{oprefix}$record->{$id}->{int04}"; @@ -1971,9 +1984,11 @@ sub bikes_available(){ $tariff_content->{$tid}->{int17} =~ s/\./,/ if($lang eq "de"); $return->{$id}->{rental_description}->{tarif_elements}->{$td} = ["$td_template->{$td}->{int17}","$tariff_content->{$tid}->{int17} € / 24 $varenv_prim->{cms}->{'unit-hour'}->{txt}"]; }elsif($td_template->{$td}->{time02} && $tariff_content->{$tid}->{time02} =~ /[1-9]/){ - $time_unit = $dbt->time_format($varenv_prim,$tariff_content->{$tid}->{time02}); - $time_unit .= " / $varenv_prim->{cms}->{'unit-day'}->{txt}" if($dbt->{operator}->{$varenv->{dbname}}->{project} ne "Konstanz"); - $return->{$id}->{rental_description}->{tarif_elements}->{$td} = ["$td_template->{$td}->{time02}","$time_unit"]; + if($rentals_response->{further_freedtime_available} == 1 || !$auth->{c_id}){ + $time_unit = $dbt->time_format($varenv_prim,$tariff_content->{$tid}->{time02}); + $time_unit .= " / $varenv_prim->{cms}->{'unit-day'}->{txt}" if($dbt->{operator}->{$varenv->{dbname}}->{project} ne "Konstanz"); + $return->{$id}->{rental_description}->{tarif_elements}->{$td} = ["$td_template->{$td}->{time02}","$time_unit"]; + } } }#end new rental_description @@ -2172,7 +2187,7 @@ sub stations_available(){ my $station_bike_node = ""; $station_bike_node = $record_pos->{int12} if(ref($record_pos) eq "HASH" && $record_pos->{int12}); - #take start station from pos + #for AA rentals take end- from start-station. my $aa_station = 0; $aa_station = $record_pos->{int06} if(ref($record_pos) eq "HASH" && $record_pos->{int06} && $record_pos->{int42}); @@ -2185,22 +2200,25 @@ sub stations_available(){ int10 => "1",#1 = "available" }; - #group_id must have 6 numbers like 300103 - my $pref_sql = ""; - #select by bike.type_id bike-group on booking update, to get available stations on bike return by filter logic + my $pref_sql = ""; if(ref($record_pos) eq "HASH" && $record_pos->{int29}){ foreach my $type_id (@{$bike_group}){ + #service user can redistribute to all + if($auth->{int09} && !$dbt->{copri_conf}->{betau_id}->{$auth->{c_id}}){ + $pref_sql = ""; + } #A-A rental #on rental-end select only station which is the same as on start and A-A - if($station_group && $type_id =~ /(\d+)/ && $aa_station){ + elsif($station_group && $type_id =~ /(\d+)/ && $aa_station){ my $group_id = $1; if($group_id == $station_group){ $pref_sql = " and ct.int04 = $aa_station and ct.int42=1"; } + } #A-B rental #on rental-end select only stations which are in ststion_group and be A-B - }elsif($station_group && $type_id =~ /(\d+)/){ + elsif($station_group && $type_id =~ /(\d+)/){ my $group_id = $1; if($group_id == $station_group){ $pref_sql = " and ct.txt25 like '%$group_id%' and (ct.int42=0 OR ct.int42 is null)"; @@ -2223,7 +2241,7 @@ sub stations_available(){ $pref_sql = "" if($pref_sql !~ /\d/); - $bw->log("stations_available --> rental station_bike_node:$station_bike_node|rental aa_station:$aa_station|user has access to bike_node:@{$bike_node}|user has access to bike_group:@{$bike_group}|pref_sql:\n",$pref_sql,""); + $bw->log("stations_available --> rental station_bike_node:$station_bike_node|rental aa_station:$aa_station|user has access to bike_node:@{$bike_node}|user has access to bike_group:@{$bike_group}|!$auth->{int09} && !$dbt->{copri_conf}->{betau_id}->{$auth->{c_id}}|pref_sql:\n",$pref_sql,""); my $record = {}; $record = $dbt->fetch_record($dbh,$pref,$pref_sql) if(ref($bike_node) eq "ARRAY" && @{$bike_node}[0]); diff --git a/copri4/main/src/Mod/APIjsonserver.pm b/copri4/main/src/Mod/APIjsonserver.pm index a14cd20..ae48bbe 100755 --- a/copri4/main/src/Mod/APIjsonserver.pm +++ b/copri4/main/src/Mod/APIjsonserver.pm @@ -241,6 +241,8 @@ elsif($q->param('request') eq "booking_request"){ #check count of occcupied/requested bikes my $record = $apif->user_bikes_occupied($dbh,$authraw,""); + my $max_rental_count = 3; + $max_rental_count = 10 if($authraw->{int09}); my $rental_count=0; my $still_requested = 0; foreach my $id (keys(%$record)){ @@ -253,10 +255,9 @@ elsif($q->param('request') eq "booking_request"){ } if(!$still_requested){ - #only if not App debuglevel defined - if(!$authraw->{int11} && $rental_count >= 3){ - $response->{response_state} = "Failure: booking_request declined. max count of 3 occupied bikes has been reached"; - $response->{response_text} = "Die maximale Anzahl von 3 Reservierungen wurde erreicht"; + if($rental_count >= $max_rental_count){ + $response->{response_state} = "Failure: booking_request declined. max count of $rental_count occupied bikes has been reached"; + $response->{response_text} = "Die maximale Anzahl von $rental_count Reservierungen wurde erreicht"; }else{ my $gps = ""; my $latitude = ""; diff --git a/copri4/main/src/Mod/DBtank.pm b/copri4/main/src/Mod/DBtank.pm index f43debc..fd09202 100755 --- a/copri4/main/src/Mod/DBtank.pm +++ b/copri4/main/src/Mod/DBtank.pm @@ -1521,8 +1521,10 @@ sub insert_pos(){ my $user_name = $ctadr->{txt01}; $user_name = $ctadr->{txt08} if(!$user_name || $user_name eq "no name"); + + #int34 is service-staff (no sms message, no aa-station, no max 3 bikes) my $staff = 0; - $staff = 1 if($ctadr->{int09});#service staff (no sms message) + $staff = 1 if($ctadr->{int09}); my $deviceId = $ct->{int13} || 0; my $bike_charge = $ct->{int19} || 0; diff --git a/copri4/main/src/Mod/Indexsharee.pm b/copri4/main/src/Mod/Indexsharee.pm index b7c8c4a..9a10f81 100755 --- a/copri4/main/src/Mod/Indexsharee.pm +++ b/copri4/main/src/Mod/Indexsharee.pm @@ -756,7 +756,8 @@ sub handler { } } #redirect used by App user profile button - elsif($session && $users_sharee->{c_id} && ($path =~ /$varenv{mandant}\/Anmelden|$varenv{mandant}\/$varenv{profile}/)){ + #elsif($session && $users_sharee->{c_id} && ($path =~ /$varenv{mandant}\/Anmelden|$varenv{mandant}\/$varenv{profile}/)){ + elsif(1==1 && $users_sharee->{c_id} && ($path =~ /$varenv{mandant}\/Anmelden|$varenv{mandant}\/$varenv{profile}/)){ if(!$users_sharee->{int14}){ print redirect("$varenv{wwwhost}/$varenv{mandant}/Account/$varenv{accounting_1}?cum=4$session_and\&$returnwww"); exit 0; diff --git a/copri4/main/src/Mod/Pricing.pm b/copri4/main/src/Mod/Pricing.pm index 2ec8894..9c973e9 100755 --- a/copri4/main/src/Mod/Pricing.pm +++ b/copri4/main/src/Mod/Pricing.pm @@ -52,6 +52,9 @@ sub count_freedrental { my $varenv = shift; my $ca_id = shift || 0; my $pos = shift || {}; + my $adjust_freedtime = shift || 0; + + my $further_freedtime_available = 1; my $freed_count = 0; my $dbh = ""; my $today4db = strftime("%Y-%m-%d %H:%M:%S",localtime(time)); @@ -64,10 +67,11 @@ sub count_freedrental { open(FILE,">>$varenv->{logdir}/count_freedrental.log") if($debug); print FILE "\n*-->$today4db $varenv->{dbname}\n" if($debug); print FILE Dumper($q) if($debug); - print FILE "--> pos.c_id:$pos->{c_id}, user:$pos->{ca_id}, bike:$pos->{ct_name} rental_minute_all: $pricing->{rentalog}->{rental_minute_all} > 0\n" if($debug); + print FILE "--> pos.c_id:$pos->{c_id}, user:$pos->{ca_id}, bike:$pos->{ct_name} rental_minute_all: $pricing->{rentalog}->{rental_minute_all} >= 5\n" if($debug); + #2023-10-10 changed from 0min to rental_minute_all >= 5min to keep freed time on rentals >=5min #freed mangement will be only dony on accountable rental - if($pricing->{rentalog}->{rental_minute_all} > 0 && $ca_id == $pos->{ca_id}){ + if($pricing->{rentalog}->{rental_minute_all} >= 5 && $ca_id == $pos->{ca_id}){ my $pref_pos = { table => "contenttranspos", fetch => "all", @@ -76,11 +80,11 @@ sub count_freedrental { time02 => ">::00:00", }; - #one freed time by parallel rentals + ###one freed time by parallel rentals if($dbt->{operator}->{$varenv->{dbname}}->{project} eq "Konstanz"){ $pref_pos->{int10} = "3"; } - #one freed time per day + ###one freed time per day else{ my $day = strftime "%d", localtime; my $mon = strftime "%m", localtime; @@ -88,25 +92,34 @@ sub count_freedrental { 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' and start_time != end_time) OR int10=3)"; } + ### my $record_pos = { c_id => 0 }; $record_pos = $dbt->fetch_tablerecord($dbh,$pref_pos); foreach my $pid (sort { $record_pos->{$a}->{c_id} <=> $record_pos->{$b}->{c_id} } keys (%$record_pos)){ $freed_count++; - print FILE "if($freed_count > 1 && $pos->{c_id} != $record_pos->{$pid}->{c_id})\n" if($debug); if($freed_count > 1 && $pos->{c_id} != $record_pos->{$pid}->{c_id}){ - my $pos_ref = { - table => "contenttranspos", - c_id => $record_pos->{$pid}->{c_id}, - }; - $dbt->update_one($dbh,$pos_ref,"time02='00:00'"); - print FILE "--> delete freed_time on c_id=$record_pos->{$pid}->{c_id} to time02=00:00\n" if($debug); + + $further_freedtime_available = 0; + if($adjust_freedtime){ + my $pos_ref = { + table => "contenttranspos", + c_id => $record_pos->{$pid}->{c_id}, + }; + $dbt->update_one($dbh,$pos_ref,"time02='00:00'"); + print FILE "--> delete freed_time on c_id=$record_pos->{$pid}->{c_id} to time02=00:00\n" if($debug); + }else{ + print FILE "--> NO further freed_time available on c_id=$record_pos->{$pid}->{c_id}\n" if($debug); + } + } + $further_freedtime_available = 0 if($freed_count == 1); + print FILE "if($freed_count > 1 && $pos->{c_id} != $record_pos->{$pid}->{c_id})\nfurther_freedtime_available:$further_freedtime_available\n" if($debug); } } close(FILE) if($debug); - return; + return $further_freedtime_available; }#end count_freedrental @@ -115,18 +128,22 @@ sub counting_rental { my $self = shift; my $varenv = shift; my $ctpos = shift; - my $today4db = strftime("%Y-%m-%d %H:%M:%S",localtime(time)); + #my $today4db = strftime("%Y-%m-%d %H:%M:%S",localtime(time)); + my $timestamp = DateTime->now( time_zone => "Europe/Berlin" ); + $timestamp =~ s/T/ /; my $return = {}; my $counting = { c_id => $ctpos->{c_id} }; - my $computed_end_time = $ctpos->{end_time} || $today4db; - $computed_end_time = $today4db if($ctpos->{int10} && $ctpos->{int10} == 3); - my $computed_start_time = $ctpos->{start_time} || $today4db;#should be only used on parts + my $computed_end_time = $ctpos->{end_time} || $timestamp; + $computed_end_time = $timestamp if($ctpos->{int10} && $ctpos->{int10} == 3); + my $computed_start_time = $ctpos->{start_time} || $timestamp;#should be only used on parts #main counting rental time and convert it to minute my $dt0 = DateTime::Format::Pg->parse_datetime($computed_start_time); my $dt1 = DateTime::Format::Pg->parse_datetime($computed_end_time); + #$return->{rentalog}->{dt1} = "bike $ctpos->{ct_name} computed_end_time:$computed_end_time --> " . Dumper($dt1); + my $dur10 = $dt1->subtract_datetime($dt0); my ($durmonth,$durdd,$durhh,$durmm) = $dur10->in_units( 'months', 'days', 'hours','minutes' ); $durhh = sprintf('%.2d',$durhh); @@ -135,8 +152,10 @@ sub counting_rental { $real_clock = "$durdd day $durhh:$durmm" if($durdd); $real_clock = "$durmonth month $durdd day $durhh:$durmm" if($durmonth); my $computed_clock = $real_clock; - my $dur = $dt0->delta_ms($dt1); - my $rental_minute = $dur->{minutes}; + my $dur = {}; + $dur = $dt0->delta_ms($dt1); + my $rental_minute = 0; + $rental_minute = $dur->{minutes} if($dur->{minutes}); #if end_station == start_station and rental minutes < 5 minutes, then 0 @@ -229,7 +248,7 @@ sub counting_rental { $counting->{int38} = $rental_unit_rounded;#by time $used_methode .= " | $rental_unit_rounded rental_unit_rounded * $ctpos->{int35} int35"; } - #else if price by all unit < max_fee/day + #else if price by all unit < max_fee/day | without int17 }else{ $rental_unit = $rental_minute / $tariff_unitbyminute; $rental_unit = sprintf('%.2f', $rental_unit); @@ -237,7 +256,7 @@ sub counting_rental { if($rental_unit =~ /(\d+)\.(\d+)/){ $rental_unit_rounded = $1 + 1 if($2 > 0); } - if($ctpos->{int36} == 0 && $ctpos->{int17} && $ctpos->{int17} > 0){ + if($ctpos->{int36} == 0){ $counting->{int38} = $rental_unit_rounded;#count by time $rental_time_price = $rental_unit_rounded * $ctpos->{int35}; $used_methode .= " | $rental_unit_rounded rental_unit_rounded * $ctpos->{int35} int35"; @@ -320,6 +339,7 @@ sub fetch_rentalfeed { my $varenv = shift; my $ctpos = shift; my $returned_counting = shift || {}; + my $further_freedtime_available = shift || 0; my $lang = "de"; my $td_template = $dbt->rental_description_template($varenv_prim); @@ -397,9 +417,11 @@ sub fetch_rentalfeed { $ctpos->{int17} =~ s/\./,/ if($lang eq "de"); $return->{rental_description}->{tarif_elements}->{$td} = ["$td_template->{$td}->{int17}","$ctpos->{int17} € / 24 $varenv_prim->{cms}->{'unit-hour'}->{txt}"]; }elsif($td_template->{$td}->{time02} && $ctpos->{time02} =~ /[1-9]/){ - $time_unit = $dbt->time_format($varenv_prim,$ctpos->{time02}); - $time_unit .= " / $varenv_prim->{cms}->{'unit-day'}->{txt}" if($dbt->{operator}->{$varenv->{dbname}}->{project} ne "Konstanz"); - $return->{rental_description}->{tarif_elements}->{$td} = ["$td_template->{$td}->{time02}","$time_unit"]; + if($further_freedtime_available == 1 || ($ctpos->{int10} == 3 && $ctpos->{time02})){ + $time_unit = $dbt->time_format($varenv_prim,$ctpos->{time02}); + $time_unit .= " / $varenv_prim->{cms}->{'unit-day'}->{txt}" if($dbt->{operator}->{$varenv->{dbname}}->{project} ne "Konstanz"); + $return->{rental_description}->{tarif_elements}->{$td} = ["$td_template->{$td}->{time02}","$time_unit"]; + } }elsif($td_template->{$td}->{xduration} && $returned_counting->{real_clock} && $returned_counting->{real_clock} =~ /[1-9]/){ $time_unit = $dbt->time_format($varenv_prim,$returned_counting->{real_clock}); $return->{rental_description}->{tarif_elements}->{$td} = ["$td_template->{$td}->{xduration}","$time_unit"]; diff --git a/copri4/main/src/Mod/Printpreview.pm b/copri4/main/src/Mod/Printpreview.pm index facb1ba..1688d2c 100755 --- a/copri4/main/src/Mod/Printpreview.pm +++ b/copri4/main/src/Mod/Printpreview.pm @@ -227,7 +227,7 @@ td { my $counting = {}; if($cttpos->{$id}->{int35} && $cttpos->{$id}->{start_time} && $cttpos->{$id}->{end_time}){ - $pri->count_freedrental("Printpreview",\%varenv,$ctt->{int10},$cttpos->{$id}); + $pri->count_freedrental("Printpreview",\%varenv,$ctt->{int10},$cttpos->{$id},1); ($pricing,$counting) = $pri->counting_rental(\%varenv,$cttpos->{$id}); $gesamt = $pri->round($pricing->{total_price}); $gesamt = sprintf('%.2f', $gesamt); @@ -699,7 +699,7 @@ td { my $rental_feed = {}; if($cttpos->{$id}->{int35} && $cttpos->{$id}->{start_time} && $cttpos->{$id}->{end_time}){ - $pri->count_freedrental("Printpreview",\%varenv,$ctt->{int10},$cttpos->{$id}); + $pri->count_freedrental("Printpreview",\%varenv,$ctt->{int10},$cttpos->{$id},1); ($pricing,$counting) = $pri->counting_rental($varenv,$cttpos->{$id}); $rental_feed = $pri->fetch_rentalfeed($varenv,$varenv,$cttpos->{$id},$counting); $rabatt = $pricing->{discount}; diff --git a/copri4/main/src/Tpl/Calorin.pm b/copri4/main/src/Tpl/Calorin.pm index b607746..0ae44f8 100755 --- a/copri4/main/src/Tpl/Calorin.pm +++ b/copri4/main/src/Tpl/Calorin.pm @@ -356,7 +356,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 "contenttanspos" && $cttpos->{$pid}->{int10} == 3); + $cttpos->{$pid}->{end_time} = $now_dt if($node_meta->{ct_table} eq "contenttranspos" && $cttpos->{$pid}->{int10} == 3); ($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}); diff --git a/copri4/main/src/Tpl/TransPositionen.pm b/copri4/main/src/Tpl/TransPositionen.pm index 36b4e68..bf3e16d 100755 --- a/copri4/main/src/Tpl/TransPositionen.pm +++ b/copri4/main/src/Tpl/TransPositionen.pm @@ -178,7 +178,7 @@ EOF my $rental_feed = {}; if($cttpos->{$id}->{int35} && $cttpos->{$id}->{start_time} && $cttpos->{$id}->{end_time}){ - $pri->count_freedrental($q,\%varenv,$ctt->{int10},$cttpos->{$id}); + $pri->count_freedrental($q,\%varenv,$ctt->{int10},$cttpos->{$id},1); ($pricing,$counting) = $pri->counting_rental(\%varenv,$cttpos->{$id}); $rental_feed = $pri->fetch_rentalfeed(\%varenv,\%varenv,$cttpos->{$id},$counting);