mirror of
https://gitlab.com/t6353/sharee.bike.git
synced 2025-05-10 05:56:27 +02:00
Invoice refactoring
This commit is contained in:
parent
74ecbbd2a8
commit
b3fb4e2143
9 changed files with 220 additions and 441 deletions
|
@ -746,257 +746,6 @@ sub save_transact(){
|
|||
}#end save_transact
|
||||
|
||||
|
||||
#online net bike booking
|
||||
#deprecated, use apif->booking_request
|
||||
sub net_booking(){
|
||||
my $self = shift;
|
||||
my $auth = shift;#API auth
|
||||
my $bikeIDin = shift;#API request
|
||||
my $owner = shift;
|
||||
my $gps = shift || "";
|
||||
|
||||
my %varenv = $cf->envonline();
|
||||
$bikeIDin =~ s/\s//g;
|
||||
my $bikeID = $q->escapeHTML($bikeIDin) if($bikeIDin =~ /\d+$/);
|
||||
my $db_bike = $bikeID;
|
||||
$db_bike = $1 if($db_bike =~ /(\d+)/);
|
||||
|
||||
my $pos_id="";
|
||||
my $return=0;
|
||||
my $now_dt = strftime "%Y-%m-%d %H:%M", localtime;
|
||||
my $dbh = "";
|
||||
my $response_state = "OK";
|
||||
my $response_text = "";
|
||||
|
||||
$bw->log("net_booking booking_request bikeIDin $bikeIDin, authID $auth->{c_id}",$bikeIDin,"");
|
||||
|
||||
my $ctadr = $db->get_contentrow("contentadr",$auth->{c_id});
|
||||
|
||||
my $update_adr = {
|
||||
table => "contentadr",
|
||||
mtime => "now()",
|
||||
owner => "$owner",
|
||||
c_id => "$ctadr->{c_id}",
|
||||
};
|
||||
|
||||
my $pref = {
|
||||
table => "contenttrans",
|
||||
fetch => "one",
|
||||
main_id => 300008,
|
||||
template_id => 218,
|
||||
#ca_id => "$ctadr->{c_id}",#TODO
|
||||
int10 => "$ctadr->{c_id}",
|
||||
state => "null",
|
||||
close_time => "is::null",
|
||||
};
|
||||
|
||||
|
||||
my $main_ids;
|
||||
my ($bike_group,$user_group,$tariff_content,$user_tour) = $apif->fetch_tariff($varenv{dbname},$ctadr,"");
|
||||
$main_ids = join(",",@{$bike_group});
|
||||
$main_ids =~ s/[a-z_]+//ig;
|
||||
my $ct = {};
|
||||
my $pref_cc = {
|
||||
table => "content",
|
||||
fetch => "one",
|
||||
main_id => "IN::($main_ids)",
|
||||
barcode => $db_bike,
|
||||
int10 => 1,
|
||||
};
|
||||
|
||||
$ct = $dbt->fetch_record($dbh,$pref_cc) if($main_ids);
|
||||
|
||||
|
||||
|
||||
#$tariff_nr in contentadr are saved by COPRI OR user Tarif-Select!!!
|
||||
#This is the automatic user tariff setter
|
||||
my $tariff_nr = "";
|
||||
my @adr_tariff = ();
|
||||
if($ctadr->{txt30}){
|
||||
@adr_tariff = ("$ctadr->{txt30}");
|
||||
@adr_tariff = split(/\s+/,$ctadr->{txt30}) if($ctadr->{txt30} =~ /\w\s+\w/);
|
||||
}
|
||||
if(ref($ct) eq "HASH" && $ct->{main_id}){
|
||||
foreach my $id (keys (%$tariff_content)){
|
||||
foreach(@adr_tariff){
|
||||
$bw->log("adr_tariff array form $ctadr->{txt30}",$_,"");
|
||||
if($tariff_content->{$id}->{int12} && $tariff_content->{$id}->{int12} == $ct->{main_id} && $tariff_content->{$id}->{barcode} && $_ == $tariff_content->{$id}->{barcode}){
|
||||
$bw->log("1. net_booking tariff loop matches:",$tariff_content->{$id}->{barcode},"");
|
||||
$tariff_nr = $tariff_content->{$id}->{barcode};
|
||||
}
|
||||
}
|
||||
}
|
||||
#2021-07-10, if no tarif then update user account to fallback default public or private or hidden tarif
|
||||
#if(!$tariff_nr && !$ctadr->{txt30})
|
||||
if(!$tariff_nr){
|
||||
my @txt30 = ();
|
||||
foreach my $id (keys (%$tariff_content)){
|
||||
# #int18
|
||||
#<sharing_type>
|
||||
# 2 = "public"
|
||||
# 3 = "private"
|
||||
# 4 = "hidden-lv"
|
||||
#</sharing_type>
|
||||
if($tariff_content->{$id}->{int18} && ($tariff_content->{$id}->{int18} == 2 || $tariff_content->{$id}->{int18} == 3 || $tariff_content->{$id}->{int18} == 4)){
|
||||
#auto set tarif if requested bike matches flot
|
||||
if($tariff_content->{$id}->{int12} && $tariff_content->{$id}->{int12} == $ct->{main_id} && $tariff_content->{$id}->{barcode}){
|
||||
$bw->log("2. net_booking tariff loop matches:",$tariff_content->{$id}->{barcode},"");
|
||||
$tariff_nr = $tariff_content->{$id}->{barcode};
|
||||
push(@txt30, "$tariff_content->{$id}->{barcode}");
|
||||
}#add also other public tarif
|
||||
elsif($tariff_content->{$id}->{int18} && $tariff_content->{$id}->{int18} == 2 && $tariff_content->{$id}->{int12} && $tariff_content->{$id}->{barcode}){
|
||||
push(@txt30, "$tariff_content->{$id}->{barcode}");
|
||||
}
|
||||
}
|
||||
}
|
||||
$bw->log("--> NO user tariff defined, update user account to fallback default public or private or hidden",\@txt30,"");
|
||||
$dbt->update_one($dbh,$update_adr,"txt30='@txt30'");
|
||||
}else{
|
||||
$bw->log("--> user tariff selected",$tariff_nr,"");
|
||||
}
|
||||
}
|
||||
|
||||
$bw->log("---> bike $ct->{barcode} matching by bike_group: @{$bike_group} main_ids:$main_ids | user_group:@{$user_group} | Tarif selected: $tariff_nr",$tariff_content->{$tariff_nr},"");
|
||||
|
||||
if($ct->{c_id} && $tariff_nr){
|
||||
my $ctt;
|
||||
my $payoneable_check=0;
|
||||
if(($ctadr->{int03} == 1 && $ctadr->{ct_name} =~ /\w{2}-\d+/ && $ctadr->{ct_name} !~ /LV-\d+/) || ($ctadr->{int03} == 2 && length($ctadr->{ct_name}) >= 19) || ($ctadr->{int03} == 1 && $varenv{dbname} eq "sharee_lv" && $ctadr->{ct_name} =~ /LV-\d+/)){
|
||||
$payoneable_check=1;
|
||||
}else{
|
||||
$response_state="Failure 1006: There is no valid payment methode";
|
||||
$response_text="Bitte überprüfen Sie Ihre Profildaten auf Vollständigkeit, nur dann können wir das Fahrradmietsystem für Sie freischalten";
|
||||
}
|
||||
|
||||
$bw->log("--->0. payable_check=$payoneable_check for $ctadr->{txt08} int01=$ctadr->{int01}|int03=$ctadr->{int03}|int04=$ctadr->{int04}|int13=$ctadr->{int13}|int12=$ctadr->{int12}|$ctadr->{ct_name}|length($ctadr->{ct_name}) >= 19\n","","");
|
||||
|
||||
#int04==1 if email Ack
|
||||
#int13==1 if sms Ack
|
||||
#int12!=1|2|3 if Vde
|
||||
#int14==1 if AGB
|
||||
if($ctadr->{txt08} && $ctadr->{int04} == 1 && $ctadr->{int13} == 1 && !$ctadr->{int12} && $ctadr->{int14} && $payoneable_check){
|
||||
|
||||
$bw->log("---> net_booking select Tarif ct->{main_id}:$ct->{main_id}| tariff_nr:$tariff_nr| ct_tariff --> Tarif-Nr:$tariff_content->{$tariff_nr}->{barcode}|Tarif desc:$tariff_content->{$tariff_nr}->{ct_name}|unit_price:$tariff_content->{$tariff_nr}->{int02}|max EUR/Tag:$tariff_content->{$tariff_nr}->{int17}|Abo EUR:$tariff_content->{$tariff_nr}->{int15}|Gratis Std/Rad:$tariff_content->{$tariff_nr}->{int16}\n","","");
|
||||
|
||||
$ctt = $dbt->fetch_record($dbh,$pref);
|
||||
#if invoice exist
|
||||
if($ctt->{c_id}){
|
||||
my $ctpos = {};
|
||||
if($bikeID && $ctadr->{c_id}){
|
||||
my $booking_pos = {
|
||||
table => "contenttranspos",
|
||||
fetch => "one",
|
||||
barcode => "$db_bike",
|
||||
int10 => "IN::('2','3')",
|
||||
ca_id => "$ctadr->{c_id}",
|
||||
};
|
||||
$ctpos = $dbt->fetch_tablerecord($dbh,$booking_pos);
|
||||
}
|
||||
if(!$ctpos->{c_id}){
|
||||
#2 = "requested"
|
||||
$pos_id = $dbt->insert_pos($dbh,$ctt->{c_id},$ct,$ctadr,$tariff_content->{$tariff_nr},$now_dt,"$bikeID","2","$owner");
|
||||
if($pos_id){
|
||||
$response_state = "OK, bike " . $bikeID . " succesfully requested";
|
||||
$response_text = "Fahrrad Nr. $bikeID wurde erfolgreich für 15 Min. reserviert";
|
||||
$bw->log("--->2. (insert contenttranspos pos_id: $pos_id\n","","");
|
||||
#require "Mod/KMLout.pm";
|
||||
#my $kmlfile = Mod::KMLout::kmlGenerator($ctadr,"");
|
||||
|
||||
$db->updater("contenttrans","c_id",$ctt->{c_id},"start_time","$now_dt",$owner);
|
||||
$db->updater("contenttrans","c_id",$ctt->{c_id},"end_time","$now_dt",$owner);
|
||||
}else{
|
||||
$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 if invoice does not exist, generate one
|
||||
}else{
|
||||
my $ct_id;
|
||||
if($ctt->{c_id}){
|
||||
$ct_id = $ctt->{c_id};
|
||||
}else{
|
||||
$ct_id = $dbt->insert_contenttrans($dbh,$ctadr,"300008","218","----","$owner");
|
||||
$ctt = $dbt->fetch_record($dbh,$pref);
|
||||
}
|
||||
$ctt = $dbt->fetch_record($dbh,$pref);
|
||||
|
||||
#TODO refactory, routines douple definend
|
||||
if($ctt->{c_id}){
|
||||
my $ctpos = {};
|
||||
if($bikeID && $ctadr->{c_id}){
|
||||
my $booking_pos = {
|
||||
table => "contenttranspos",
|
||||
fetch => "one",
|
||||
barcode => "$db_bike",
|
||||
int10 => "IN::('2','3')",
|
||||
ca_id => "$ctadr->{c_id}",
|
||||
};
|
||||
$ctpos = $dbt->fetch_tablerecord($dbh,$booking_pos);
|
||||
}
|
||||
if(!$ctpos->{c_id}){
|
||||
#2 = "requested"
|
||||
$pos_id = $dbt->insert_pos($dbh,$ctt->{c_id},$ct,$ctadr,$tariff_content->{$tariff_nr},$now_dt,"$bikeID","2","$owner");
|
||||
if($pos_id){
|
||||
$response_state = "OK, bike " . $bikeID . " succesfully requested";
|
||||
$response_text = "Fahrrad Nr. $bikeID wurde erfolgreich für 15 Min. reserviert";
|
||||
$bw->log("--->3. (insert contenttranspos pos_id: $pos_id\n","","");
|
||||
#require "Mod/KMLout.pm";
|
||||
#my $kmlfile = Mod::KMLout::kmlGenerator($ctadr,"");
|
||||
|
||||
$db->updater("contenttrans","c_id",$ctt->{c_id},"start_time","$now_dt",$owner);
|
||||
$db->updater("contenttrans","c_id",$ctt->{c_id},"end_time","$now_dt",$owner);
|
||||
}else{
|
||||
$response_state="Failure 1008: 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{#end Vde AGB and payable_check
|
||||
$response_state="Failure 1005: user-account deactivated because of failing data";
|
||||
$response_text="Bitte überprüfen Sie Ihre Profildaten auf Vollständigkeit, nur dann können wir das Fahrradmietsystem für Sie freischalten";
|
||||
}
|
||||
|
||||
}else{
|
||||
my $ctpos = {};
|
||||
my $booking_pos = {
|
||||
table => "contenttranspos",
|
||||
fetch => "one",
|
||||
barcode => "$db_bike",
|
||||
int10 => "IN::('2','3')",
|
||||
ca_id => "$ctadr->{c_id}",
|
||||
};
|
||||
$ctpos = $dbt->fetch_tablerecord($dbh,$booking_pos) if($bikeID && $ctadr->{c_id});
|
||||
if($ctpos->{c_id}){
|
||||
$response_state = "OK, bike " . $bikeID . " already requested or occupied";
|
||||
$response_text = "Fahrrad Nr. " . $bikeID . " ist bereits reserviert";
|
||||
}elsif($ct->{c_id} && !$tariff_nr){
|
||||
$response_state="Failure 2089: booking bike $bikeID fails, no user tariff available";
|
||||
$response_text="Reservierungsfehler Fahrrad Nr. $bikeID. Es konnte kein Mietrad Tarif gefunden werden.";
|
||||
}else{
|
||||
$response_state="Failure 2001: booking bike $bikeID fails, bike not available";
|
||||
$response_text="Fahrrad Nr. $bikeID ist leider nicht verfügbar. U.U. ist die Fahrrad Flotte für Sie nicht freigeschaltet. Bitte überprüfen Sie Ihre Profildaten auf Vollständigkeit";
|
||||
}
|
||||
}
|
||||
$bw->log("response_state:$response_state\n","","");
|
||||
|
||||
if(ref($auth) eq "HASH"){
|
||||
$return = {
|
||||
bike => "$bikeID",
|
||||
state => "requested",
|
||||
response_state => "$response_state",
|
||||
response_text => "$response_text"
|
||||
};
|
||||
}else{
|
||||
if($response_state =~ /Failure/){
|
||||
$return = "failure::int01 $response_state";
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}#end net_booking
|
||||
|
||||
|
||||
#Send sms after payable check and !int13
|
||||
sub smsack(){
|
||||
my $self = shift;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue