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", 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 bike and tariff
if($ct_bike->{barcode} && $ct_tariff->{barcode}){ if($ct_bike->{barcode} && $ct_tariff->{barcode}){
my $ctt = {}; my $ctt = {};
@ -988,7 +961,7 @@ sub booking_request(){
if($ctt->{c_id}){ if($ctt->{c_id}){
#2 = "requested" #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,""); $bw->log("booking_request insert_pos:",$pos_id,"");
if($pos_id){ if($pos_id){
@ -1030,6 +1003,38 @@ sub booking_request(){
return $return; 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 #int03=1 if sepa, 2=CC
#int04==1 if email Ack #int04==1 if email Ack
#int13==1 if sms Ack #int13==1 if sms Ack
@ -1223,6 +1228,11 @@ sub booking_update(){
$update_pos->{int10} = 3; $update_pos->{int10} = 3;
$update_pos->{txt11} = "$sig_book->{rentalId}" if($sig_book->{rentalId}); $update_pos->{txt11} = "$sig_book->{rentalId}" if($sig_book->{rentalId});
$update_pos->{txt22} = "$sig_book->{bikeId}" if($sig_book->{bikeId}); $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); $rows = $dbt->update_record($dbh,$update_pos,$record_pos);
if($rows > 0){ if($rows > 0){
@ -1291,6 +1301,21 @@ sub booking_update(){
$update_pos->{int40} = "$counting->{int40}" if(looks_like_number($counting->{int40})); $update_pos->{int40} = "$counting->{int40}" if(looks_like_number($counting->{int40}));
$update_pos->{int41} = "$counting->{int41}" if(looks_like_number($counting->{int41})); $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); $rows_end = $dbt->update_record($dbh,$update_pos,$record_pos);
if($rows_end > 0){ if($rows_end > 0){

View file

@ -73,15 +73,15 @@ sub handler {
my $update_adr = { my $update_adr = {
table => "contentadr", table => "contentadr",
mtime => "now()", pay_time => "now()",
owner => $owner #owner => $owner
}; };
my $update_ctt = { my $update_ctt = {
table => "contenttrans", table => "contenttrans",
mtime => "now()", mtime => "now()",
pay_time => "now()", pay_time => "now()",
owner => $owner, #owner => $owner,
int14 => 0,#OPOS int14 => 0,#OPOS
int16 => 0,#balance int16 => 0,#balance
int18 => 0,#sequencenumber int18 => 0,#sequencenumber

View file

@ -255,10 +255,10 @@ sub channel_map(){
172 => "reserve timeout", 172 => "reserve timeout",
#173 => "merchant fallback",#mig #173 => "merchant fallback",#mig
174 => "cronjob bonus", 174 => "cronjob bonus",
175 => "cronjob cpdate", #175 => "cronjob cpdate",
176 => "Mein konrad App",#mig 176 => "Mein konrad App",#mig
177 => "LastenradBay App",#mig 177 => "LastenradBay App",#mig
178 => "payone API", #178 => "payone API",
179 => "cronjob payone", 179 => "cronjob payone",
#181 => "SMS API", #181 => "SMS API",
#182 => "velofactur API", #182 => "velofactur API",
@ -957,7 +957,7 @@ sub update_record(){
$set .= " $key='$value',"; $set .= " $key='$value',";
} }
} }
if($key =~ /^(barcode|contentadr_id|int\d+|time\d+|owner|owner_end|start_at\d+|end_at\d+)$/){ if($key =~ /^(barcode|contentadr_id|int\d+|time\d+|owner|start_at\d+|end_at\d+)$/){
$value =~ s/,/\./ if($value); $value =~ s/,/\./ if($value);
if($key =~ /int\d+|time\d+|start_at\d+|end_at\d+/ && $value && $value =~ /\d+:\d+/){#azn time format if($key =~ /int\d+|time\d+|start_at\d+|end_at\d+/ && $value && $value =~ /\d+:\d+/){#azn time format
$set .= " $key='$value',"; $set .= " $key='$value',";
@ -1443,7 +1443,6 @@ sub insert_pos(){
my $status = shift || ""; my $status = shift || "";
my $owner = shift || ""; my $owner = shift || "";
my $sig_book = shift || {}; my $sig_book = shift || {};
my $activ_count = shift || 1;
my $aa_station = $ct_station->{int42} || 0; my $aa_station = $ct_station->{int42} || 0;
@ -1498,7 +1497,7 @@ sub insert_pos(){
my $sth; my $sth;
#Verleihräder #Verleihräder
if($ct->{template_id} && $ct->{template_id} == 205){#Leihrad_list if($ct->{template_id} && $ct->{template_id} == 205){#Leihrad_list
$sth = $dbh->prepare("INSERT INTO contenttranspos (ct_id,cc_id,ca_id,ct_name,barcode,txt01,txt08,txt02,txt09,txt12,itime,start_time,end_time,int01,int02,int03,int06,int04,txt05,txt06,txt07,int10,int12,template_id,int13,owner,int07,txt04,int09,int17,int15,int16,int11,int18,int19,txt17,txt18,int20,int25,int29,int34,txt22,txt11,int35,int36,int37,int42,time01,time02) VALUES ('$ctt_id','$ct->{c_id}','$ctadr->{c_id}','$ct_name','$ct->{barcode}','$ct->{txt01}','$user_name','$ct->{txt02}','$ctadr->{txt09}','$prefix',now(),now(),'$endRental','1','$unit_price','$menge','$station','$station','$ct->{txt06}','$ct->{txt06}','$ct->{txt07}','$status','$from_main_id','$from_template_id','$deviceId','$owner','$rabatt','$tariff_desc','$tariff_nr','$daymax_price','$abo_price','$activ_count','$ct->{int11}','$sharing_type','$bike_charge','$ct->{txt17}','$ct->{txt18}','1','$trackon','$bike_type_id','$staff','$sig_book->{bikeId}','$sig_book->{rentalId}','$unit_price1','$unit_price2','$start_price','$aa_station','$unit_time','$free_time') RETURNING c_id"); $sth = $dbh->prepare("INSERT INTO contenttranspos (ct_id,cc_id,ca_id,ct_name,barcode,txt01,txt08,txt02,txt09,txt12,itime,start_time,end_time,int01,int02,int03,int06,int04,txt05,txt06,txt07,int10,int12,template_id,int13,owner,int07,txt04,int09,int17,int15,int11,int18,int19,txt17,txt18,int20,int25,int29,int34,txt22,txt11,int35,int36,int37,int42,time01,time02) VALUES ('$ctt_id','$ct->{c_id}','$ctadr->{c_id}','$ct_name','$ct->{barcode}','$ct->{txt01}','$user_name','$ct->{txt02}','$ctadr->{txt09}','$prefix',now(),now(),'$endRental','1','$unit_price','$menge','$station','$station','$ct->{txt06}','$ct->{txt06}','$ct->{txt07}','$status','$from_main_id','$from_template_id','$deviceId','$owner','$rabatt','$tariff_desc','$tariff_nr','$daymax_price','$abo_price','$ct->{int11}','$sharing_type','$bike_charge','$ct->{txt17}','$ct->{txt18}','1','$trackon','$bike_type_id','$staff','$sig_book->{bikeId}','$sig_book->{rentalId}','$unit_price1','$unit_price2','$start_price','$aa_station','$unit_time','$free_time') RETURNING c_id");
}else{ }else{
$sth = $dbh->prepare("INSERT INTO contenttranspos (ct_id,cc_id,ca_id,ct_name,barcode,txt08,txt09,itime,int01,int02,int03,txt01,txt06,txt07,int10,int12,template_id,owner) VALUES ('$ctt_id','$ct->{c_id}','$ctadr->{c_id}','$ct_name','$ct->{barcode}','$user_name','$ctadr->{txt09}',now(),'1','$unit_price','1','$ct->{txt01}','$ct->{txt06}','$ct->{txt07}','0','$from_main_id','$from_template_id','$owner') RETURNING c_id"); $sth = $dbh->prepare("INSERT INTO contenttranspos (ct_id,cc_id,ca_id,ct_name,barcode,txt08,txt09,itime,int01,int02,int03,txt01,txt06,txt07,int10,int12,template_id,owner) VALUES ('$ctt_id','$ct->{c_id}','$ctadr->{c_id}','$ct_name','$ct->{barcode}','$user_name','$ctadr->{txt09}',now(),'1','$unit_price','1','$ct->{txt01}','$ct->{txt06}','$ct->{txt07}','0','$from_main_id','$from_template_id','$owner') RETURNING c_id");
} }

View file

@ -1299,6 +1299,7 @@ sub export_csv {
my %varenv = $cf->envonline(); my %varenv = $cf->envonline();
my $scol = "c_id"; my $scol = "c_id";
my $feedb = { message => "" }; my $feedb = { message => "" };
$node_meta->{tpl_order} =~ s/txt06=[\w\s=]+,/byte01=Ilockit Token,/ if($node_meta->{tpl_id} == 205);
my @tpl_order = split(/,/,$node_meta->{tpl_order}); my @tpl_order = split(/,/,$node_meta->{tpl_order});
my $csv_export = Text::CSV_XS->new ({ binary => 1, sep_char => ";", eol => "\r\n" }); my $csv_export = Text::CSV_XS->new ({ binary => 1, sep_char => ";", eol => "\r\n" });
@ -1331,8 +1332,13 @@ sub export_csv {
my @line = (); my @line = ();
foreach (@tpl_order){ foreach (@tpl_order){
my ($key,$val,$size,$title) = split /=/,$_; my ($key,$val,$size,$title) = split /=/,$_;
if($key =~ /byte/){
my $K_int = unpack "H*", $ct4rel->{$id}->{$key};
push @line, $K_int;
}else{
push @line, $ct4rel->{$id}->{$key}; push @line, $ct4rel->{$id}->{$key};
} }
}
$csv_export->print($csv, \@line); $csv_export->print($csv, \@line);
} }

View file

@ -216,9 +216,6 @@ sub preinit(){
} }
if($ct->{barcode} && $ct->{barcode} > 0 && $rel->{content_id}){ if($ct->{barcode} && $ct->{barcode} > 0 && $rel->{content_id}){
my $partnr = "$ct_name / $ct->{barcode}";
$partnr = "$ct_name" if("$ct_name" eq "$ct->{barcode}" || !$ct->{barcode});
my $bezeichnung = "$ct->{txt01}";
$ct->{int02} = $ct->{int02} * -1 if($ct->{template_id} == 224 && $ct->{int02} > 0);#Gutscheine $ct->{int02} = $ct->{int02} * -1 if($ct->{template_id} == 224 && $ct->{int02} > 0);#Gutscheine
#Add Parts from content to contenttranspos################# #Add Parts from content to contenttranspos#################
@ -226,13 +223,11 @@ sub preinit(){
my $ctt = $db->get_content1("contenttrans",$R::c_id4trans); my $ctt = $db->get_content1("contenttrans",$R::c_id4trans);
my $ctadr = $db->get_content1("contentadr",$ctt->{int10}); my $ctadr = $db->get_content1("contentadr",$ctt->{int10});
$pos_id = $dbt->insert_pos($dbh,$ctt->{c_id},$ct,"",$ctadr,"","",$partnr,"0",$users_dms->{u_id},""); $pos_id = $dbt->insert_pos($dbh,$ctt->{c_id},$ct,"",$ctadr,"","","","0",$users_dms->{u_id},"");
$i_rows += 1 if($pos_id > 0); $i_rows += 1 if($pos_id > 0);
$dbt->update_content4comp($dbh,$ct->{c_id},"-","1"); $dbt->update_content4comp($dbh,$ct->{c_id},"-","1");
return "pos_id=$pos_id";#new return-code to get opened Part-Position in Transposition return "pos_id=$pos_id";#new return-code to get opened Part-Position in Transposition
}elsif($ct_name && !$rel->{content_id}){
return "failure::Für die Terminzuordnung bitte zuerst einen Verkauf Vorgang öffnen oder neu erzeugen.<br /> ::$varenv{wwwhost}/Verkauf::Zum Verkauf";
}else{ }else{
return "failure::Die Artikelnummer konnte nicht gefunden werden.<br /> ::$varenv{wwwhost}/DMS/Waren::Waren verwalten"; return "failure::Die Artikelnummer konnte nicht gefunden werden.<br /> ::$varenv{wwwhost}/DMS/Waren::Waren verwalten";
} }

View file

@ -125,9 +125,9 @@ sub counting_rental {
} }
#substract free time from rental time ex. 00:30 Min/Gratis #substract free time from rental time ex. 00:30 Min/Gratis
#only if $activ_count==1 rental get freed_time #freed_time depends on operator and will be set by rental end "count_freedrental"
my $freed_time = ""; my $freed_time = "";
if($ctpos->{int16} && $ctpos->{int16} == 1 && $ctpos->{time02} && $ctpos->{time02} =~ /[1-9]/){ if($ctpos->{time02} && $ctpos->{time02} =~ /[1-9]/){
#$ctpos_freed = $self->only_first_free($ctpos); #$ctpos_freed = $self->only_first_free($ctpos);
#if(!$ctpos_freed->{c_id}){ #if(!$ctpos_freed->{c_id}){
my ($dhh,$dmm) = split(/:/,$ctpos->{time02}); my ($dhh,$dmm) = split(/:/,$ctpos->{time02});
@ -258,7 +258,6 @@ sub counting_rental {
$return->{rentalog}->{real_clock} = "$real_clock"; $return->{rentalog}->{real_clock} = "$real_clock";
$return->{rentalog}->{freed_time} = "$freed_time"; $return->{rentalog}->{freed_time} = "$freed_time";
$return->{rentalog}->{activ_count} = "$ctpos->{int16}";
$return->{rentalog}->{computed_clock} = "$computed_clock"; $return->{rentalog}->{computed_clock} = "$computed_clock";
$return->{rentalog}->{computed_hours} = "$computed_hours"; $return->{rentalog}->{computed_hours} = "$computed_hours";
$return->{rentalog}->{rental_minute} = "$rental_minute"; $return->{rentalog}->{rental_minute} = "$rental_minute";