mirror of
https://gitlab.com/t6353/sharee.bike.git
synced 2025-05-13 15:16:38 +02:00
Adding prepaid payment methode and prepaid accounting with api interface
This commit is contained in:
parent
da31898968
commit
2dc53f4087
22 changed files with 815 additions and 236 deletions
|
@ -930,8 +930,7 @@ sub booking_request(){
|
|||
if($ct_bike->{barcode} && $ct_tariff->{barcode}){
|
||||
my $ctt = {};
|
||||
my $rentable_check=0;
|
||||
$rentable_check = $bw->isuser_rentable($auth,$varenv);
|
||||
|
||||
$rentable_check = $bw->isuser_rentable($auth,$varenv);
|
||||
$bw->log("booking_request isuser_rentable:",$rentable_check,"");
|
||||
|
||||
if($rentable_check == 2){
|
||||
|
@ -957,7 +956,38 @@ sub booking_request(){
|
|||
|
||||
#if invoice exist
|
||||
if($ctt->{c_id}){
|
||||
|
||||
#if payment-type prepaid, then check whether balance positive
|
||||
my $sum_balance = 0;
|
||||
if($auth->{int03} && $auth->{int03} == 3){
|
||||
|
||||
my $dbh_primary = $dbt->dbconnect_extern($dbt->{primary}->{sharee_primary}->{database}->{dbname});
|
||||
my $adref = {
|
||||
table => "contentadr",
|
||||
fetch => "one",
|
||||
c_id => "$auth->{c_id}",
|
||||
};
|
||||
my $auth_prim = $dbt->fetch_tablerecord($dbh_primary,$adref);
|
||||
|
||||
#get prepaid balance, like in users App RentalData
|
||||
#collects all open (not captured) positions incl. primary-prepaid to get saldo
|
||||
my ($cttpos,$operator_hash) = $self->user_rentals_history($q,$auth_prim,0,1);
|
||||
foreach my $id (keys(%$cttpos)){
|
||||
if($cttpos->{$id}->{int35} && $cttpos->{$id}->{start_time} && $cttpos->{$id}->{end_time}){
|
||||
my $pricing = { total_price => 0 };
|
||||
($pricing, my $counting) = $pri->counting_rental($varenv,$cttpos->{$id});
|
||||
$sum_balance += $pricing->{total_price};
|
||||
}else{
|
||||
my $total_price = 0;
|
||||
($total_price,my $rabatt) = $pri->price2calc($cttpos->{$id});
|
||||
#prepaid * -1
|
||||
$total_price *= -1 if($cttpos->{$id}->{template_id} && $cttpos->{$id}->{template_id} == 219);
|
||||
$sum_balance += $total_price;
|
||||
}
|
||||
}
|
||||
$bw->log("booking_request prepaid balance sum: $sum_balance, userID: $auth->{c_id} ",$sum_balance,"");
|
||||
}
|
||||
#Rental is only permitted if sum_balance <= 0 (in primary prepaid context positive)
|
||||
if($sum_balance <= 1){
|
||||
#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);
|
||||
$bw->log("booking_request insert_pos:",$pos_id,"");
|
||||
|
@ -1009,6 +1039,10 @@ sub booking_request(){
|
|||
$response_state="Failure 1007: booking request fails";
|
||||
$response_text="Entschuldigung, es ist ein Fehler aufgetreten. Bitte kontaktieren Sie unsere hotline damit wir das Problem lösen können";
|
||||
}
|
||||
}else{
|
||||
$response_state="Failure 1593: rental is prohibited because of prepaid balance - $sum_balance";
|
||||
$response_text="Bitte überprüfen Sie Ihren Prepaid/Vorkasse Kontostand, aktuell: - $sum_balance €. Nur bei positiven Kontostand können wir das Mietradsystem für Sie freischalten.";
|
||||
}#end if $sum_balance
|
||||
}
|
||||
}elsif($rentable_check == 1){
|
||||
$response_state="Failure 1006: rental is prohibited because of user profil";
|
||||
|
@ -1641,6 +1675,7 @@ sub user_rentals_history(){
|
|||
my $q = shift || "";
|
||||
my $auth = shift;
|
||||
my $daily = shift || 0;
|
||||
my $allop = shift || 0;
|
||||
|
||||
my %varenv = $cf->envonline();
|
||||
my $today = strftime("%Y-%m-%d",localtime(time));
|
||||
|
@ -1662,23 +1697,31 @@ sub user_rentals_history(){
|
|||
my $month = $q->param('month');
|
||||
$pref->{mtime} = ">=::(now() - interval '$month month')";
|
||||
}else{
|
||||
#2021-06-18, list only postions which are not invoiced (Form Buchungsdaten)
|
||||
#$pref->{close_time} = "is::null";
|
||||
$pref->{'ct.state'} = "is::null";
|
||||
$pref->{'ct.int14'} = "is::null";
|
||||
#2024-01-08 list not succesfully captured positions by also using ct.int14 >= 1
|
||||
$pref->{'ct.state'} = "is::null";# OR ct.int14 >= 1
|
||||
#$pref->{'ct.int14'} = "is::null";
|
||||
}
|
||||
|
||||
if($varenv{dbname} eq $dbt->{primary}->{sharee_primary}->{database}->{dbname}){
|
||||
if($allop || $varenv{dbname} eq $dbt->{primary}->{sharee_primary}->{database}->{dbname}){
|
||||
#$bw->log("user_rentals_history userID: $auth->{c_id} with operators",$auth->{txt17},"");
|
||||
|
||||
if($auth->{txt17}){
|
||||
if($auth->{txt17} =~ /\w\s\w/){
|
||||
%operator_hash = map { $_ => "$dbt->{operator}{$_}->{operatorApp}" } split(/\s+/,$auth->{txt17});
|
||||
}else{
|
||||
$operator_hash{$auth->{txt17}} = "$dbt->{operator}{$auth->{txt17}}->{operatorApp}";
|
||||
}
|
||||
#adding primary to get prepaid
|
||||
#$operator_hash{sharee_primary} = "$dbt->{primary}{sharee_primary}->{primaryApp}";
|
||||
|
||||
foreach my $sharee_operator (keys (%operator_hash)){
|
||||
my $dbh_operator = $dbt->dbconnect_extern("$sharee_operator");
|
||||
my $cttpos = $dbt->collect_post($dbh_operator,$pref);
|
||||
$record_all = { %$record_all, %$cttpos };
|
||||
#$bw->log("operator_hash sharee_operator: $sharee_operator",$sharee_operator,"");
|
||||
my $dbh_operator = "";
|
||||
$dbh_operator = $dbt->dbconnect_extern("$sharee_operator");
|
||||
if($dbh_operator){
|
||||
my $cttpos = $dbt->collect_post($dbh_operator,$pref);
|
||||
$record_all = { %$record_all, %$cttpos };
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
|
@ -1892,7 +1935,7 @@ sub bikes_available(){
|
|||
#return list of occupied/requested bikes
|
||||
my $adjust_freedtime = 0;
|
||||
my $further_freedtime_available = 1;
|
||||
my ($cttpos,$operator_hash) = $self->user_rentals_history($q,$auth,1);
|
||||
my ($cttpos,$operator_hash) = $self->user_rentals_history($q,$auth,1,0);
|
||||
foreach my $id (sort { lc($cttpos->{$b}->{itime}) cmp lc($cttpos->{$a}->{itime}) } keys(%$cttpos)){
|
||||
$further_freedtime_available = $pri->count_freedrental("rentals by bikes_available",$varenv,$auth->{c_id},$cttpos->{$id},$adjust_freedtime);
|
||||
}
|
||||
|
@ -2291,12 +2334,15 @@ sub stations_available(){
|
|||
$record->{$id}->{txt06} =~ s/\s//g if($record->{$id}->{txt06});
|
||||
if($record->{$id}->{txt06} && $record->{$id}->{txt06} =~ /\d+\.\d+\,\d+\.\d+/){
|
||||
my $bike_count = 0;
|
||||
my @bike_ids = ();
|
||||
foreach my $b_id (keys (%$record_bikes)){
|
||||
if($record->{$id}->{int04} == $record_bikes->{$b_id}->{int04}){
|
||||
push @bike_ids,$dbt->{operator}->{$varenv->{dbname}}->{oprefix} . $record_bikes->{$b_id}->{barcode};
|
||||
$bike_count++;
|
||||
}
|
||||
}
|
||||
$return->{$id}->{bike_count} = "$bike_count";
|
||||
$return->{$id}->{bike_ids} = [@bike_ids];
|
||||
|
||||
$return->{$id}->{authed} = "$authed";
|
||||
$return->{$id}->{capacity} = "$record->{$id}->{int05}" || "1";
|
||||
|
@ -2911,7 +2957,7 @@ sub auth_verify(){
|
|||
|
||||
#first, save operator array which are used
|
||||
my %operator_hash = ();#local DB
|
||||
#$bw->log("booking_request auth_verified by dbname $varenv{dbname}",$auth_primary->{c_id},"");
|
||||
$bw->log("booking_request auth_verified by dbname $varenv{dbname}",$auth_primary->{c_id},"");
|
||||
print FILE "booking_request auth_verified by dbname $varenv{dbname} | pri $auth_primary->{c_id}\n" if($debug);
|
||||
|
||||
if($auth_primary->{txt17} && $auth_primary->{txt17} =~ /\w\s\w/){#append DB's
|
||||
|
@ -2940,7 +2986,7 @@ sub auth_verify(){
|
|||
$update_primary->{txt26} = $q->escapeHTML($user_agent) if($user_agent);
|
||||
}
|
||||
|
||||
#check prepaid account
|
||||
#first prepaid account check (not save because without rental history)
|
||||
if($auth_primary->{int03} == 3){
|
||||
my $prepaidhash = { prepaid_total => 0 };
|
||||
$prepaidhash = $pri->collect_prepaid($dbh_primary,$auth_primary) if($auth_primary->{c_id});
|
||||
|
@ -2948,6 +2994,7 @@ sub auth_verify(){
|
|||
my $vde = $auth_primary->{int12} || 1;
|
||||
$update_primary->{int12} = $vde;
|
||||
}
|
||||
$bw->log("auth_verify booking_request prepaid check",$update_primary,"");
|
||||
}
|
||||
|
||||
my $rows = $dbt->update_record($dbh_primary,$update_primary,$auth_primary);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue