From 91e41f109ee56558b4fd9acd78ade5e5f203e4c2 Mon Sep 17 00:00:00 2001 From: ragu Date: Thu, 13 Apr 2023 15:35:29 +0200 Subject: [PATCH] new method count_freedrental --- copri4/main/src/Mod/APIfunc.pm | 86 +++++++++++-------- copri4/main/src/Mod/DBtank.pm | 6 +- copri4/main/src/Mod/Indexsharee.pm | 4 +- copri4/main/src/Mod/Shareework.pm | 23 ++--- copri4/main/src/Tpl/TransPositionen.pm | 1 + copri4/shareeapp-operator/src/Tpl/FormEdit.pm | 2 - 6 files changed, 70 insertions(+), 52 deletions(-) diff --git a/copri4/main/src/Mod/APIfunc.pm b/copri4/main/src/Mod/APIfunc.pm index 739ba99..ad58d47 100755 --- a/copri4/main/src/Mod/APIfunc.pm +++ b/copri4/main/src/Mod/APIfunc.pm @@ -1003,36 +1003,64 @@ sub booking_request(){ return $return; } -#for free rental +#for one freed rental #depends on operator, only 1 rental get freed_time sub count_freedrental { my $self = shift; + my $q = shift || ""; my $varenv = shift; my $auth = shift; + my $rental_minute_all = shift || 0; + my $pos = shift || {}; + my $freed_count = 0; + my $dbh = ""; - my $pref_pos = { + my $debug=1; + open(FILE,">>$varenv->{logdir}/count_freedrental.log") if($debug); + print FILE "\n*-->$now_dt $varenv->{dbname}\n" if($debug); + print FILE Dumper($q) if($debug); + print FILE "--> c_id:$pos->{c_id} rental_minute_all: $rental_minute_all > 0\n" if($debug); + + #freed mangement will be only dony on accountable rental + if($rental_minute_all > 0){ + 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++; + #one freed time with three parallel rentals + if($dbt->{operator}->{$varenv->{dbname}}->{project} eq "Konstanz"){ + $pref_pos->{int10} = "3"; + } + #one freed time per day + 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' OR int10=3)"; + } + my $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); + } + } } - return $active_count; + close(FILE) if($debug); + + return; } #int03=1 if sepa, 2=CC @@ -1229,9 +1257,8 @@ sub booking_update(){ $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); + #on occupied, we don't really know if will be a accountable rental, we try it + $self->count_freedrental($q,$varenv,$auth,0,$update_pos); $rows = $dbt->update_record($dbh,$update_pos,$record_pos); @@ -1301,21 +1328,8 @@ 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); - + #in real, we can get only freed accountable rentals only on rental end's + $self->count_freedrental($q,$varenv,$auth,$pricing->{rentalog}->{rental_minute_all},$update_pos); $rows_end = $dbt->update_record($dbh,$update_pos,$record_pos); if($rows_end > 0){ @@ -1799,8 +1813,10 @@ sub rentals(){ foreach my $id (sort { $record->{$a}->{end_time} cmp $record->{$b}->{end_time} } keys (%$record)){ - #new sharee_pricing + #$pricing (my $return_counting->{$id}, my $counting) = $pri->counting_rental(\%varenv,$record->{$id},""); + #adjusting freed time rental by often called bikes_occupied, only viewable after second call + $self->count_freedrental("rentals by user_bikes_occupied",\%varenv,$auth,$return_counting->{$id}->{rentalog}->{rental_minute_all},$record->{$id}); #$bw->log("rentals-rentalog",$return_counting->{$id}->{rentalog},""); $return_counting->{$id}->{rentalog} = "";#just for debuggiog, removed to reduce data in json my $return_feed->{$id} = $pri->fetch_rentalfeed(\%varenv,$record->{$id},$return_counting->{$id}); diff --git a/copri4/main/src/Mod/DBtank.pm b/copri4/main/src/Mod/DBtank.pm index 563166d..5879780 100755 --- a/copri4/main/src/Mod/DBtank.pm +++ b/copri4/main/src/Mod/DBtank.pm @@ -258,7 +258,7 @@ sub channel_map(){ #175 => "cronjob cpdate", 176 => "Mein konrad App",#mig 177 => "LastenradBay App",#mig - #178 => "payone API", + 178 => "payone API", 179 => "cronjob payone", #181 => "SMS API", #182 => "velofactur API", @@ -819,7 +819,7 @@ sub fetch_tablerecord(){ $where .= " and $key $op '$value'"; }elsif($key =~ /time$/ && $value && $value =~ /interval/){#<= (now() - interval '15 minutes') $where .= " and $key $op $value"; - }elsif($key =~ /time$/ && $value){ + }elsif($key =~ /time$|time\d+/ && $value){ $where .= " and $key $op '$value'"; }elsif($key eq "time_range"){#used for freed_time on request $where .= " and $value"; @@ -1073,7 +1073,7 @@ sub insert_contentoid { $values .= "'$insert->{$key}',"; } } - elsif($key =~ /^c_id|ct_name|barcode|txt|int|time|owner/ && ($insert->{$key} || looks_like_number($insert->{$key}))){ + elsif($key =~ /^c_id|ct_name|barcode|txt|int|time|owner|byte/ && ($insert->{$key} || looks_like_number($insert->{$key}))){ $columns .= "$key,"; if($key =~ /_id|barcode|int|owner/ && !looks_like_number($insert->{$key})){ $values .= "null,"; diff --git a/copri4/main/src/Mod/Indexsharee.pm b/copri4/main/src/Mod/Indexsharee.pm index 3f0423f..3292e9c 100755 --- a/copri4/main/src/Mod/Indexsharee.pm +++ b/copri4/main/src/Mod/Indexsharee.pm @@ -341,11 +341,11 @@ sub handler { if($users_dms->{u_id} && $users_dms->{int07} == 2){ if($R::u_id && $R::base_edit eq "remove_chk4rel"){#users my $delete_key = "delete_dmsusers"; - $return = "failure::Datensatz wirklich löschen. ::?base_edit=$delete_key\&exit_box2=1\&u_id=$R::u_id ::löschen"; + $feedb->{message} = "failure::Datensatz wirklich löschen. ::?base_edit=$delete_key\&exit_box2=1\&u_id=$R::u_id ::löschen"; }elsif(($R::u_id || $R::c_idadr) && $R::base_edit =~ /_dmsusers/){ my $u_id = $1 if($R::u_id && $R::u_id =~ /(\d+)/); $u_id = $1 if($R::c_idadr && $R::c_idadr =~ /(\d+)/ && $R::base_edit eq "new_dmsusers"); - $return = $tk->manage_dmsusers($q,$R::base_edit,$u_id,$users_dms); + $feedb = $tk->manage_dmsusers($q,\%varenv,$R::base_edit,$u_id,$users_dms); } }else{ $feedb->{message} = "failure::Abbruch. Schreibender Zugriff \"DMS-Account\" verweigert."; diff --git a/copri4/main/src/Mod/Shareework.pm b/copri4/main/src/Mod/Shareework.pm index 140acc6..1c2697f 100755 --- a/copri4/main/src/Mod/Shareework.pm +++ b/copri4/main/src/Mod/Shareework.pm @@ -585,6 +585,7 @@ sub save_account(){ sub manage_dmsusers { my $self = shift; my $q = shift; + my $varenv = shift; my $base_edit = shift; my $u_id = shift; my $users_dms = shift || {}; @@ -594,17 +595,17 @@ sub manage_dmsusers { my @keywords = $q->param; my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime; - my %varenv = $cf->envonline(); + my $feedb = { message => "", i_rows => 0, u_rows => 0, d_rows => 0 }; $bw->log("manage_dmsusers",$q,""); my $dbh = ""; - my $authref = { + my $adref = { table => "contentadr", fetch => "one", template_id => "202", c_id => "$u_id", }; - my $ctadr = $dbt->fetch_record($dbh,$authref); + my $ctadr = $dbt->fetch_record($dbh,$adref); #users have to be exist only if DMS activated my $uref = { @@ -623,10 +624,11 @@ sub manage_dmsusers { }; if(ref($users) eq "HASH" && $users->{u_id} && (!$ctadr->{c_id} || $base_edit eq "delete_dmsusers")){ - $bw->log("delete DMS user from $varenv{dbname}",$ctadr->{c_id},""); - $d_rows += $dbt->delete_content($dbh,"users",$u_id); + $bw->log("delete DMS user from $varenv->{dbname}",$ctadr->{c_id},""); + $feedb->{d_rows} = $dbt->delete_content($dbh,"users",$u_id); + $dbt->update_one($dbh,$adref,"int07=null"); }elsif(ref($users) eq "HASH" && $users->{u_id} && $ctadr->{c_id} && $ctadr->{c_id} == $users->{u_id} && $base_edit eq "save_dmsusers"){ - $bw->log("update DMS user to $varenv{dbname}",$ctadr->{c_id},""); + $bw->log("update DMS user to $varenv->{dbname}",$ctadr->{c_id},""); foreach(@keywords){ my $val = $q->param($_); my $valxx = $q->escapeHTML("$val"); @@ -635,16 +637,17 @@ sub manage_dmsusers { $valxx =~ s/,/./g; #$valxx = "null" if(!looks_like_number($valxx));#empty $valxx = 0 if(!looks_like_number($valxx));# set to 0 for using == operator - $u_rows = $dbt->update_one($dbh,$dmsusers,"$_=$valxx"); + $feedb->{u_rows} = $dbt->update_one($dbh,$dmsusers,"$_=$valxx"); } } }elsif($ctadr->{c_id} && !$users->{u_id} && $base_edit eq "new_dmsusers"){ - $bw->log("insert DMS user to $varenv{dbname}",$ctadr->{c_id},""); - $i_rows = $dbt->insert_users($dbh,$ctadr->{c_id},$owner); + $bw->log("insert DMS user to $varenv->{dbname}",$ctadr->{c_id},""); + $feedb->{i_rows} = $dbt->insert_users($dbh,$ctadr->{c_id},$owner); + $dbt->update_one($dbh,$adref,"int07=100"); } - return "$i_rows-$u_rows-$d_rows"; + return $feedb; } diff --git a/copri4/main/src/Tpl/TransPositionen.pm b/copri4/main/src/Tpl/TransPositionen.pm index b647c57..71801c8 100755 --- a/copri4/main/src/Tpl/TransPositionen.pm +++ b/copri4/main/src/Tpl/TransPositionen.pm @@ -177,6 +177,7 @@ EOF if($cttpos->{$id}->{int35} && $cttpos->{$id}->{start_time} && $cttpos->{$id}->{end_time}){ $cttpos->{$id}->{end_time} = $now_dt if($cttpos->{$id}->{int10} == 3); ($pricing,$counting) = $pri->counting_rental(\%varenv,$cttpos->{$id},"calc_price"); + $apif->count_freedrental($q,\%varenv,$ctadr,$pricing->{rentalog}->{rental_minute_all},$cttpos->{$id}); $rental_feed = $pri->fetch_rentalfeed(\%varenv,$cttpos->{$id},$counting); $sum_parts19 += $pricing->{total_price}; $gesamt = $pri->round($pricing->{total_price}); diff --git a/copri4/shareeapp-operator/src/Tpl/FormEdit.pm b/copri4/shareeapp-operator/src/Tpl/FormEdit.pm index c3617dc..60ba3dc 100755 --- a/copri4/shareeapp-operator/src/Tpl/FormEdit.pm +++ b/copri4/shareeapp-operator/src/Tpl/FormEdit.pm @@ -361,10 +361,8 @@ Nach Abschluss der Registrierung erhalten Sie sowohl auf die von Ihnen hinterleg my $pricing = {}; my $counting = {}; - my $rental_feed = {}; if($cttpos->{$id}->{int35} && $cttpos->{$id}->{start_time} && $cttpos->{$id}->{end_time}){ ($pricing,$counting) = $pri->counting_rental($varenv,$cttpos->{$id},"calc_price"); - $rental_feed = $pri->fetch_rentalfeed($varenv,$cttpos->{$id},$counting); } print $q->Tr(),"\n";