Tariff rentalog and tariff_description2

This commit is contained in:
ragu 2022-04-21 21:15:01 +02:00
parent b2e5d72c51
commit 4108673ef1
5 changed files with 188 additions and 44 deletions

View file

@ -1163,8 +1163,12 @@ sub booking_update(){
if($record_pos->{int24}){
$update_pos->{owner_end} = "$owner";
$update_pos->{end_time} = "now()";
#return after booking_update
my $pricing = $pri->sharee_pricing($record_pos,"calc_price");
#my $pricing = $pri->sharee_pricing($record_pos,"calc_price");
#new sharee_pricing
my $pricing = $pri->counting_rental(\%varenv,$record_pos,"calc_price");
$update_pos->{int03} = "$pricing->{computed_hours}" if(looks_like_number($pricing->{computed_hours}));
$update_pos->{int10} = "$state_key";
@ -1214,8 +1218,12 @@ sub booking_update(){
$update_pos->{txt13} = "$dbt->{operator}->{$varenv{dbname}}->{oprefix}";
#end-Station prefix
$update_cc->{txt13} = "$dbt->{operator}->{$varenv{dbname}}->{oprefix}";
#return after booking_update
my $pricing = $pri->sharee_pricing($record_pos,"calc_price");
#my $pricing = $pri->sharee_pricing($record_pos,"calc_price");
#new sharee_pricing
my $pricing = $pri->counting_rental(\%varenv,$record_pos,"calc_price");
$update_pos->{int03} = "$pricing->{computed_hours}" if(looks_like_number($pricing->{computed_hours}));
$rows = $dbt->update_record($dbh,$update_pos,$record_pos);
@ -1242,8 +1250,12 @@ sub booking_update(){
$update_pos->{txt13} = "$dbt->{operator}->{$varenv{dbname}}->{oprefix}";
#end-Station prefix
$update_cc->{txt13} = "$dbt->{operator}->{$varenv{dbname}}->{oprefix}";
#return after booking_update
my $pricing = $pri->sharee_pricing($record_pos,"calc_price");
#my $pricing = $pri->sharee_pricing($record_pos,"calc_price");
#new sharee_pricing
my $pricing = $pri->counting_rental(\%varenv,$record_pos,"calc_price");
$update_pos->{int03} = "$pricing->{computed_hours}" if(looks_like_number($pricing->{computed_hours}));
$rows = $dbt->update_record($dbh,$update_pos,$record_pos);
@ -1650,12 +1662,12 @@ sub rentals(){
foreach my $id (sort { $record->{$a}->{end_time} cmp $record->{$b}->{end_time} } keys (%$record)){
#last
$return->{$id} = $pri->sharee_pricing($record->{$id},"readonly");
#$return->{$id} = $pri->sharee_pricing($record->{$id},"readonly");
#new sharee_pricing
#my $return_counting->{$id} = $pri->counting_rental(\%varenv,$record->{$id},"readonly");
#my $return_feed->{$id} = $pri->fetch_rentalfeed(\%varenv,$record->{$id});
#$return->{$id} = { %{ $return_counting->{$id} }, %{ $return_feed->{$id} } };
my $return_counting->{$id} = $pri->counting_rental(\%varenv,$record->{$id},"readonly");
my $return_feed->{$id} = $pri->fetch_rentalfeed(\%varenv,$record->{$id});
$return->{$id} = { %{ $return_counting->{$id} }, %{ $return_feed->{$id} } };
my $bike_id = $return->{$id}->{bike};
$bike_id = $1 if($bike_id =~ /(\d+)/);
@ -1725,6 +1737,8 @@ sub bikes_available(){
}
}
my $td_template = $dbt->tariff_description2_template();
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}";
@ -1763,6 +1777,7 @@ sub bikes_available(){
if($record->{$id}->{main_id} == $tariff_content->{$tid}->{int12} && $_ == $tariff_content->{$tid}->{barcode}){
$bw->log("bikes_available for user c_id: $auth->{c_id} if($record->{$id}->{main_id} == $tariff_content->{$tid}->{int12} && $_ == $tariff_content->{$tid}->{barcode}) on BIKE:",$return->{$id}->{bike},"");
#deprecated
$return->{$id}->{tariff_description}->{name} = "$tariff_content->{$tid}->{ct_name}";
$return->{$id}->{tariff_description}->{number} = "$tariff_content->{$tid}->{barcode}";
$return->{$id}->{tariff_description}->{eur_per_hour} = "$tariff_content->{$tid}->{int02}" || "0";
@ -1771,6 +1786,34 @@ sub bikes_available(){
$return->{$id}->{tariff_description}->{abo_eur_per_month} = "$tariff_content->{$tid}->{int15}" if($tariff_content->{$tid}->{int15});
#TODO, have to be set on Tarif table
$return->{$id}->{tariff_description}->{operator_agb} = "Mit der Mietrad Anmietung wird folgender Betreiber <a href='$varenv->{wwwhost}/site/agb.html' target='_blank'>AGB</a> zugestimmt (als Demo sharee AGB)." if($auth->{c_id} && ($auth->{c_id} == 1842 || $auth->{c_id} == 5781 || $auth->{c_id} == 22262));
#new tariff_description2
$return->{$id}->{tariff_description2}->{name} = "$tariff_content->{$tid}->{ct_name}";
$return->{$id}->{tariff_description2}->{number} = "$tariff_content->{$tid}->{barcode}";
$return->{$id}->{tariff_description2}->{track_info} = "Ich stimme der Speicherung (Tracking) meiner Fahrstrecke zwecks wissenschaftlicher Auswertung und Berechnung der CO2-Einsparung zu!" if($record->{$id}->{int25});
$return->{$id}->{tariff_description2}->{operator_agb} = "Mit der Mietrad Anmietung wird folgender Betreiber <a href='$varenv->{wwwhost}/site/agb.html' target='_blank'>AGB</a> zugestimmt (als Demo sharee AGB)." if($auth->{c_id} && ($auth->{c_id} == 1842 || $auth->{c_id} == 5781 || $auth->{c_id} == 22262));
my $i = 0;
foreach my $td (keys (%$td_template)){
my $time_unit = "";
$tariff_content->{$tid}->{$td} =~ s/\./,/ if($td =~ /int\d+/);
if($td eq "int02" && $tariff_content->{$tid}->{int02} && $tariff_content->{$tid}->{int02} > 0){
$i++;
$time_unit = $dbt->time_format($tariff_content->{$tid}->{time01});
$return->{$id}->{tariff_description2}->{$i} = ["$td_template->{$td}","$tariff_content->{$tid}->{$td} € / $time_unit"];
}elsif($td eq "int15" && $tariff_content->{$tid}->{int15} && $tariff_content->{$tid}->{int15} > 0){
$i++;
$return->{$id}->{tariff_description2}->{$i} = ["$td_template->{$td}", "$tariff_content->{$tid}->{$td} € / Std"];
}elsif($td eq "int17" && $tariff_content->{$tid}->{int17} && $tariff_content->{$tid}->{int17} > 0){
$i++;
$return->{$id}->{tariff_description2}->{$i} = ["$td_template->{$td}","$tariff_content->{$tid}->{$td} € / Tag"];
}elsif($td eq "time02" && $tariff_content->{$tid}->{time02}){
$i++;
$time_unit = $dbt->time_format($tariff_content->{$tid}->{time02});
$return->{$id}->{tariff_description2}->{$i} = ["$td_template->{$td}","$time_unit / Tag"];
}
}#end new tariff_description2
}
}
}

View file

@ -77,6 +77,7 @@ sub sigo_available {
c_id => "1",
};
my $hotline_data = $dbt->fetch_record($dbh,$hotline_hash);
my $td_template = $dbt->tariff_description2_template();
open(FILE,">>$varenv->{logdir}/APIsigo_client.log");
print FILE "\n*** $now_dt 'sigo_available' \n";
@ -184,16 +185,45 @@ sub sigo_available {
$response_out->{$bike}->{bike_group} = ["SX300102"];#E-Lastenrad
$response_out->{$bike}->{unlock_allowed} = "1";
$response_out->{$bike}->{tariff_description} = {};
$response_out->{$bike}->{tariff_description2} = {};
if(ref($tariff_content) eq "HASH"){
foreach my $tid (sort { $tariff_content->{$a}->{barcode} <=> $tariff_content->{$b}->{barcode} } keys (%$tariff_content)){
#deprecated
$response_out->{$bike}->{tariff_description}->{name} = "$tariff_content->{$tid}->{ct_name}";
$response_out->{$bike}->{tariff_description}->{number} = "$tariff_content->{$tid}->{barcode}";
$response_out->{$bike}->{tariff_description}->{eur_per_hour} = "$tariff_content->{$tid}->{int02}" || "0";
$response_out->{$bike}->{tariff_description}->{max_eur_per_day} = "$tariff_content->{$tid}->{int17}" if($tariff_content->{$tid}->{int17});
$response_out->{$bike}->{tariff_description}->{free_hours} = "$tariff_content->{$tid}->{int16}" if($tariff_content->{$tid}->{int16});
$response_out->{$bike}->{tariff_description}->{abo_eur_per_month} = "$tariff_content->{$tid}->{int15}" if($tariff_content->{$tid}->{int15});
#TODO, have to be set on Tarif table
$response_out->{$bike}->{tariff_description}->{operator_agb} = "Mit der Mietrad Anmietung wird folgender Betreiber <a href='$dbt->{operator}->{$varenv->{dbname}}->{operatorApp}/site/agb.html' target='_blank'>AGB</a> zugestimmt (Demo)." if($auth->{c_id} && ($auth->{c_id} == 1842 || $auth->{c_id} == 5781 || $auth->{c_id} == 22262));
#new tariff_description2
$response_out->{$bike}->{tariff_description2}->{name} = "$tariff_content->{$tid}->{ct_name}";
$response_out->{$bike}->{tariff_description2}->{number} = "$tariff_content->{$tid}->{barcode}";
$response_out->{$bike}->{tariff_description2}->{track_info} = "Ich stimme der Speicherung (Tracking) meiner Fahrstrecke zwecks wissenschaftlicher Auswertung und Berechnung der CO2-Einsparung zu!";# if($record->{$id}->{int25});
$response_out->{$bike}->{tariff_description2}->{operator_agb} = "Mit der Mietrad Anmietung wird folgender Betreiber <a href='$varenv->{wwwhost}/site/agb.html' target='_blank'>AGB</a> zugestimmt (als Demo sharee AGB)." if($auth->{c_id} && ($auth->{c_id} == 1842 || $auth->{c_id} == 5781 || $auth->{c_id} == 22262));
my $i = 0;
foreach my $td (keys (%$td_template)){
my $time_unit = "";
$tariff_content->{$tid}->{$td} =~ s/\./,/ if($td =~ /int\d+/);
if($td eq "int02" && $tariff_content->{$tid}->{int02} && $tariff_content->{$tid}->{int02} > 0){
$i++;
$time_unit = $dbt->time_format($tariff_content->{$tid}->{time01});
$response_out->{$bike}->{tariff_description2}->{$i} = ["$td_template->{$td}","$tariff_content->{$tid}->{$td} € / $time_unit"];
}elsif($td eq "int15" && $tariff_content->{$tid}->{int15} && $tariff_content->{$tid}->{int15} > 0){
$i++;
$response_out->{$bike}->{tariff_description2}->{$i} = ["$td_template->{$td}", "$tariff_content->{$tid}->{$td} € / Std"];
}elsif($td eq "int17" && $tariff_content->{$tid}->{int17} && $tariff_content->{$tid}->{int17} > 0){
$i++;
$response_out->{$bike}->{tariff_description2}->{$i} = ["$td_template->{$td}","$tariff_content->{$tid}->{$td} € / Tag"];
}elsif($td eq "time02" && $tariff_content->{$tid}->{time02}){
$i++;
$time_unit = $dbt->time_format($tariff_content->{$tid}->{time02});
$response_out->{$bike}->{tariff_description2}->{$i} = ["$td_template->{$td}","$time_unit / Tag"];
}
}#end new tariff_description2
}
}
#just like caching
@ -279,7 +309,7 @@ sub sigo_booking {
eval {
$sigo_book = decode_json($ret_json);
print FILE "<--- sigo_post $todo response_in:\n" . Dumper($sigo_book);
#print $ret_json . "\n";
print $ret_json . "\n";
};
if ($@){

View file

@ -1217,6 +1217,31 @@ sub get_freetpl(){
}
#
sub tariff_description2_template {
my $self = shift;
my $tpl_order = {
int02 => "Mietgebühr",
int15 => "Mietgebühr ab 2. Tag",
#int16 => "Grundgebühr",
int17 => "Max Gebühr",
time01 => "Zeiteinheit",
time02 => "Gratis Mietzeit",
};
return $tpl_order;
}
sub time_format {
my $self = shift;
my $time = shift;
my $time_unit = "";
my ($std,$min,$sec) = split(/:/,$time);
$std =~ s/^0//;
$min =~ s/^0//;
$time_unit = "$std Std " if($std > 0);
$time_unit .= "$min Min" if($min > 0);
return $time_unit;
}
# copy template
sub copy_template(){
my $self = shift;
@ -1283,10 +1308,10 @@ sub insert_pos(){
$rabatt = $ctadr->{int07} || 0;
$unit_price1 = $ct_tariff->{int02} || 0;
$unit_price2 = $ct_tariff->{int15} || 0;
$startup_price = $ct_tariff->{int16} || 0;#not yet implemented (OLD Gratis Std/Rad --> migrate to time02)
$daymax_price = $ct_tariff->{int17} || 0;
$tariff_nr = $ct_tariff->{barcode} || 0;
$tariff_desc = $ct_tariff->{ct_name};
$daymax_price = $ct_tariff->{int17} || 0;
$startup_price = $ct_tariff->{int16} || 0;
$unit_time = $ct_tariff->{time01} || "00:00";
$fee_time = $ct_tariff->{time02} || "00:00";
$sharing_type = $ct_tariff->{int18} || 0;

View file

@ -144,11 +144,12 @@ sub counting_rental {
my $rental_units = 0;
my $price_by_allunits = 0;
my $max_daily_unit = 0;#how many rental_minute is one daily_unit
my $fee_daily_minutes = 0;
my $rental_days_price = 0;
my $fee_daily_minute = 0;
my $rental_day_price = 0;
my $restal_minute = 0;
my $rental_time_price = 0;
my $rounded_time_factor = 0;
my $rental_units_rounded = 0;
my $used_max_fee = "off";
#readonly if bike available then take saved $total_price
if($ctpos->{int10} && $ctpos->{int10} == 1 && $todo eq "readonly"){
@ -163,54 +164,62 @@ sub counting_rental {
#max fee per day (day = 1440 minutes)
if($ctpos->{int17} && $price_by_allunits >= $ctpos->{int17}){
$used_max_fee = "on";
$max_daily_unit = $ctpos->{int17} / $ctpos->{int02};
$fee_daily_minutes = $max_daily_unit * $tariff_unitbyminute;
$fee_daily_minute = $max_daily_unit * $tariff_unitbyminute;
my $days_dec = $rental_minute / 1440;
my ($days,$ddec) = split(/\./, $days_dec) if($days_dec =~ /\.\d/);
$rental_days_price = $days * $ctpos->{int17} if($days > 0);
$rental_day_price = $days * $ctpos->{int17} if($days > 0);
$restal_minute = $rental_minute - $days * 1440;
if($restal_minute >= $fee_daily_minutes){
$rental_days_price += $ctpos->{int17};
if($restal_minute >= $fee_daily_minute){
$rental_day_price += $ctpos->{int17};
}else{
my $rental_time_factor = $restal_minute / $tariff_unitbyminute;
$rounded_time_factor = $rental_time_factor;
if($rental_time_factor =~ /(\d+)\.(\d+)/){
$rounded_time_factor = $1 + 1;
$rental_units = $rental_minute / $tariff_unitbyminute;
$rental_units_rounded = $rental_units;
if($rental_units =~ /(\d+)\.(\d+)/){
$rental_units_rounded = $1 + 1;
}
$rental_time_price = $rounded_time_factor * $ctpos->{int02};
$rental_time_price = $rental_units_rounded * $ctpos->{int02};
}
}else{
my $rental_time_factor = $rental_minute / $tariff_unitbyminute;
$rounded_time_factor = $rental_time_factor;
if($rental_time_factor =~ /(\d+)\.(\d+)/){
$rounded_time_factor = $1 + 1;
$rental_units = $rental_minute / $tariff_unitbyminute;
$rental_units_rounded = $rental_units;
if($rental_units =~ /(\d+)\.(\d+)/){
$rental_units_rounded = $1 + 1;
}
$rental_time_price = $rounded_time_factor * $ctpos->{int02};
$rental_time_price = $rental_units_rounded * $ctpos->{int02};
}
}
$total_price = $rental_days_price + $rental_time_price;
my $computed_hours = $rental_minute / 60;
$total_price = $rental_day_price + $rental_time_price;
$total_price = sprintf('%.2f', $total_price);
$return->{start_time} = "$ctpos->{start_time}";
$return->{end_time} = "$computed_end_time";
$return->{real_hours} = "$real_clock";
$return->{computed_hours} = "$computed_clock";
#$return->{real_clock} = "$real_clock";
#$return->{computed_clock} = "$computed_clock";
$return->{computed_hours} = "$computed_hours";
$return->{unit_price} = "$ctpos->{int02}";
$return->{total_price} = "$total_price";
$return->{rentalog}->{real_hours} = "$real_clock";
$return->{rentalog}->{computed_hours} = "$computed_clock";
$return->{rentalog}->{real_clock} = "$real_clock";
$return->{rentalog}->{computed_clock} = "$computed_clock";
$return->{rentalog}->{computed_hours} = "$computed_hours";
$return->{rentalog}->{rental_minute} = "$rental_minute";
$return->{rentalog}->{rental_units} = "$rental_units";
$return->{rentalog}->{fee_daily_minute} = "$fee_daily_minute";
$return->{rentalog}->{tariff_unitbyminute} = "$tariff_unitbyminute";
$return->{rentalog}->{restal_minute} = "$restal_minute";
$return->{rentalog}->{rounded_time_factor} = "$rounded_time_factor";
$return->{rentalog}->{rental_units_rounded} = "$rental_units_rounded";
$return->{rentalog}->{rental_units} = "$rental_units";
$return->{rentalog}->{price_by_allunits} = "$price_by_allunits";
$return->{rentalog}->{rental_days_price} = "$rental_days_price";
$return->{rentalog}->{rental_day_price} = "$rental_day_price";
$return->{rentalog}->{total_price} = "$total_price";
$return->{rentalog}->{rental_time_price} = "$rental_time_price";
$return->{rentalog}->{ctpos_freed} = "$ctpos_freed->{c_id}";
$return->{rentalog}->{used_max_fee} = "$used_max_fee";
$bw->log("Pricing counting_rental return:",$return,"");
return $return;
@ -222,6 +231,7 @@ sub fetch_rentalfeed {
my $varenv = shift;
my $ctpos = shift;
my $td_template = $dbt->tariff_description2_template();
my $bike_group = "$dbt->{operator}->{$varenv->{dbname}}->{oprefix}$ctpos->{int12}" || "";
my $return = {};
@ -241,6 +251,8 @@ sub fetch_rentalfeed {
#if($ctpos->{txt10} =~ /requested|occupied/)
if($ctpos->{int10} == 2 || $ctpos->{int10} == 3){
#deprecated
$return->{tariff_description}->{name} = "$ctpos->{txt04}";
$return->{tariff_description}->{number} = "$ctpos->{int09}";
$return->{tariff_description}->{eur_per_hour} = "$ctpos->{int02}" || "0";
@ -250,6 +262,33 @@ sub fetch_rentalfeed {
$return->{tariff_description}->{track_info} = "Ich stimme der Speicherung (Tracking) meiner Fahrstrecke zwecks wissenschaftlicher Auswertung und Berechnung der CO2-Einsparung zu!" if($ctpos->{int25});
$return->{tariff_description}->{operator_agb} = "Mit der Mietrad Anmietung wird folgender Betreiber <a href='$varenv->{wwwhost}/site/agb.html' target='_blank'>AGB</a> zugestimmt (als Demo sharee AGB)." if($ctpos->{ca_id} == 1842 || $ctpos->{ca_id} == 5781);
#new tariff_description2
$return->{tariff_description2}->{name} = "$ctpos->{txt04}";
$return->{tariff_description2}->{number} = "$ctpos->{int09}";
$return->{tariff_description2}->{track_info} = "Ich stimme der Speicherung (Tracking) meiner Fahrstrecke zwecks wissenschaftlicher Auswertung und Berechnung der CO2-Einsparung zu!" if($ctpos->{int25});
$return->{tariff_description2}->{operator_agb} = "Mit der Mietrad Anmietung wird folgender Betreiber <a href='$varenv->{wwwhost}/site/agb.html' target='_blank'>AGB</a> zugestimmt (als Demo sharee AGB)." if($ctpos->{ca_id} == 1842 || $ctpos->{ca_id} == 5781);
my $i = 0;
foreach my $td (keys (%$td_template)){
my $time_unit = "";
$ctpos->{$td} =~ s/\./,/ if($td =~ /int\d+/);
if($td eq "int02" && $ctpos->{int02} && $ctpos->{int02} > 0){
$i++;
$time_unit = $dbt->time_format($ctpos->{time01});
$return->{tariff_description2}->{$i} = ["$td_template->{$td}","$ctpos->{$td} € / $time_unit"];
}elsif($td eq "int15" && $ctpos->{int15} && $ctpos->{int15} > 0){
$i++;
$return->{tariff_description2}->{$i} = ["$td_template->{$td}", "$ctpos->{$td} € / Std"];
}elsif($td eq "int17" && $ctpos->{int17} && $ctpos->{int17} > 0){
$i++;
$return->{tariff_description2}->{$i} = ["$td_template->{$td}","$ctpos->{$td} € / Tag"];
}elsif($td eq "time02" && $ctpos->{time02}){
$i++;
$time_unit = $dbt->time_format($ctpos->{time02});
$return->{tariff_description2}->{$i} = ["$td_template->{$td}","$time_unit / Tag"];
}
}#end new tariff_description2
$return->{Ilockit_GUID} = "$ctpos->{txt17}" if($ctpos->{int11} == 2);
$return->{Ilockit_ID} = "$ctpos->{txt18}" if($ctpos->{int11} == 2);
($return->{gps}->{latitude},$return->{gps}->{longitude}) = split(/,/,$ctpos->{txt06});

View file

@ -3,9 +3,10 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
#
# sudo su www-data -c "./src/scripts/sigo_client.pl shareeapp-sx sigo_available"
# sudo su www-data -c "./src/scripts/sigo_client.pl shareeapp-sx available"
#
# sudo su www-data -c "./src/scripts/sigo_client.pl shareeapp-sx sigo_reserve"
# sudo su www-data -c "./src/scripts/sigo_client.pl shareeapp-sx reserve"
# sudo su www-data -c "./src/scripts/sigo_client.pl shareeapp-sx rental"
#
use vars qw($syshost);
@ -32,20 +33,26 @@ my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
my $todo = $ARGV[1];
if($todo eq "sigo_available"){
if($todo eq "available"){
$q->param(-name=>'request',-value=>"bikes_available");
my $auth = { c_id => 0 };
my $return = $si->sigo_available($q,\%varenv,$auth);
print $0 . Dumper($return) . "\n";
}
if($todo eq "sigo_booking"){
if($todo eq "reserve"){
my $auth = { c_id => 1842 };
#my $bikeId = "380116b5-0522-43da-ab66-477744a731a3";# bike 1150
my $bike = "SX1150";# bike 1150 from app booking_request
my $return = $si->sigo_reserve(\%varenv,$auth,$bike);
my $bike = { txt22 => "380116b5-0522-43da-ab66-477744a731a3" };# bike 1150
#my $bike = "SX1150";# bike 1150 from app booking_request
my $return = $si->sigo_booking(\%varenv,$auth,$bike,$todo);
print $0 . Dumper($return) . "\n";
}
if($todo eq "rental"){
my $auth = { c_id => 1842 };
my $bike = { txt22 => "380116b5-0522-43da-ab66-477744a731a3" };# bike 1150
#my $bike = "SX1150";# bike 1150 from app booking_request
my $return = $si->sigo_booking(\%varenv,$auth,$bike,$todo);
print $0 . Dumper($return) . "\n";
}