new method count_freedrental

This commit is contained in:
ragu 2023-04-13 15:35:29 +02:00
parent 8200270e93
commit 91e41f109e
6 changed files with 70 additions and 52 deletions

View file

@ -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});

View file

@ -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,";

View file

@ -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.";

View file

@ -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;
}

View file

@ -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});

View file

@ -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";