new rental editor

This commit is contained in:
ragu 2022-06-02 10:34:03 +02:00
parent 46f86f6c05
commit aceda57b50
23 changed files with 548 additions and 162 deletions

View file

@ -53,9 +53,15 @@ sub handler {
my $debug=1;
my $user_agent = $q->user_agent();
$bw->log("APIjsonserver request:\n--> user-agent '$user_agent'",$q,"");
#my %headers = map { $_ => $q->http($_) } $q->http();
#$bw->log("headers:",\%headers,"");
$bw->log("APIjsonserver request:\n--> user-agent '$user_agent' ",$q,"");
print $q->header(-type => "application/json", -charset => "utf-8", -'Access-Control-Allow-Origin' => "*");
#for my $header ( keys %headers ) {
# print "$header: $headers{$header}\n";
#}
my $respreq = $q->param('request') || "";
my $apiserver = $q->url(-base=>1) || "";
@ -249,6 +255,7 @@ elsif($q->param('request') eq "booking_request"){
my $ct_tariff = {};
($ct_bike,$ct_tariff) = $apif->fetch_bike_tariff(\%varenv,$authraw,$bike,$aowner);
#sig booking_request
my $sig_book = {
bikeId => "$ct_bike->{txt22}",
rentalId => "",
@ -258,7 +265,7 @@ elsif($q->param('request') eq "booking_request"){
if($ct_bike->{barcode} && $ct_tariff->{barcode}){
#sig reservation. not mandatory
if($ct_bike->{int11} == 3){
$sig_book = $si->sig_booking(\%varenv,$authraw,$ct_bike,"","reserve");
$sig_book = $si->sig_booking(\%varenv,"reserve",$authraw,$ct_bike,"");
$sig_book->{bikeId} = "$ct_bike->{txt22}";
}
$response_book = $apif->booking_request($q,\%varenv,$authraw,$bike,$ct_bike,$ct_tariff,$aowner,$gps,$sig_book);
@ -286,8 +293,8 @@ elsif($q->param('request') eq "booking_request"){
#sig booking
if($ctpos->{int11} == 3){
#usecase with reservationId (in ctpos) is in sig not defined, thats because using ct_bike.txt22
#$sig_book = $si->sig_booking(\%varenv,$authraw,$ct_bike,$ctpos,"rental");
system("$varenv{basedir}/src/scripts/sig_client.pl $varenv{syshost} 'rental' $authraw->{c_id} $ctpos->{c_id} &");
#$sig_book = $si->sig_booking(\%varenv,"rental",$authraw,$ct_bike,$ctpos);
system("$varenv{basedir}/src/scripts/sig_client.pl $varenv{syshost} 'rental' $authraw->{c_id} '' $ctpos->{c_id} &");
($rows, $booking_values) = $apif->booking_update($q,\%varenv,$authraw,$aowner,$sig_book);
$response = {%$response, %$booking_values};
}else{
@ -358,7 +365,7 @@ elsif($q->param('request') eq "booking_cancel" || $q->param('request') eq "booki
#this sig request is still not defined
#$response->{response_state} = "Failure: sig bike reservation can not be canceled on sig";
#$response->{response_text} = "Abbruch, die Reservierung kann nicht storniert werden";
$sig_book = $si->sig_booking(\%varenv,$authraw,"",$ctpos,"reserve_end");
$sig_book = $si->sig_booking(\%varenv,"reserve_end",$authraw,"",$ctpos);
($rows, $booking_values) = $apif->booking_update($q,\%varenv,$authraw,$aowner,$sig_book);
}else{
($rows, $booking_values) = $apif->booking_update($q,\%varenv,$authraw,$aowner,"");
@ -370,12 +377,12 @@ elsif($q->param('request') eq "booking_cancel" || $q->param('request') eq "booki
if($ctpos->{int11} == 3){
if($q->param('state') eq "occupied"){
#$sig_book = $si->sig_booking(\%varenv,$authraw,"",$ctpos,"rental");
system("$varenv{basedir}/src/scripts/sig_client.pl $varenv{syshost} 'rental' $authraw->{c_id} $ctpos->{c_id} &");
#$sig_book = $si->sig_booking(\%varenv,"rental",$authraw,"",$ctpos);
system("$varenv{basedir}/src/scripts/sig_client.pl $varenv{syshost} 'rental' $authraw->{c_id} '' $ctpos->{c_id} &");
}
if($q->param('state') eq "available"){
#$sig_book = $si->sig_booking(\%varenv,$authraw,"",$ctpos,"rental_end");
system("$varenv{basedir}/src/scripts/sig_client.pl $varenv{syshost} 'rental_end' $authraw->{c_id} $ctpos->{c_id} &");
#$sig_book = $si->sig_booking(\%varenv,"rental_end",$authraw,"",$ctpos);
system("$varenv{basedir}/src/scripts/sig_client.pl $varenv{syshost} 'rental_end' $authraw->{c_id} '' $ctpos->{c_id} &");
}
($rows, $booking_values) = $apif->booking_update($q,\%varenv,$authraw,$aowner,$sig_book);

View file

@ -278,10 +278,10 @@ sub sig_available {
sub sig_booking {
my $self = shift;
my $varenv = shift || {};
my $todo = shift || "";
my $ctadr = shift || {};
my $ct_bike = shift || {};
my $ctpos = shift || {};
my $todo = shift || "";
my $dbh = "";
my $owner = 169;
@ -314,7 +314,8 @@ sub sig_booking {
#int10 state will be set on main booking_update
elsif($todo eq "rental"){
$endpoint .= "rental";
my $sig_bikeId = $ctpos->{txt22} || $ct_bike->{txt22};
#my $sig_bikeId = $ctpos->{txt22} || $ct_bike->{txt22};
my $sig_bikeId = "380116b5-0522-43da-ab66-477744a731a3";
%json = (
bikeId => "$sig_bikeId",
email => "$ctadr->{txt08}"
@ -329,6 +330,15 @@ sub sig_booking {
);
#keep in mind, it will return no json, just text: "Rental Ended"
}
#rentals running
#TODO, execute it before user_bikes_occupied
elsif($todo eq "rentals_running"){
$endpoint .= "rentals/running";
%json = (
email => "$ctadr->{txt08}"
);
}
else{
print "Failure, request $todo not defined\n";
@ -352,6 +362,9 @@ sub sig_booking {
#warn $@;
print FILE "warn:" . $@ . "\n";
}
#save always API return state for documentation
$sig_book->{return_state} = "$now_dt $todo: $ret_status";
}
if(ref($sig_book) ne "HASH"){
@ -387,7 +400,8 @@ sub sig_booking {
#}
$update_pos->{txt10} = "$sig_book->{reservationId}" if($sig_book->{reservationId});
$update_pos->{txt11} = "$sig_book->{rentalId}" if($sig_book->{rentalid});
$update_pos->{txt11} = "$sig_book->{rentalId}" if($sig_book->{rentalId});
$update_pos->{txt25} = "$ctpos->{txt25}\n$sig_book->{return_state}";# if($sig_book->{return_state});
$rows = $dbt->update_record($dbh,$update_pos,$ctpos);
print FILE "<--- rows: $rows, update_pos: $ctpos->{c_id}, with:" . Dumper($update_pos) . "\n";

View file

@ -58,5 +58,38 @@ sub log {
}
#return headline message
sub return_feedback(){
my $self = shift;
my $node_meta = shift;
my $users_dms = shift || {};
my $feedb = shift || {};
my $return = "";
if(ref($feedb) eq "HASH" && $feedb->{message}){
print<<EOF
<script>
\$(document).ready(function(){
\$( "#retm" ).fadeOut(8000);
})
</script>
EOF
;
my $debug = "";
$debug = $feedb->{debug} if($users_dms->{u_id} eq "1842");
if($feedb->{message} =~ /(failure::.*)/){
$return = $1;
}elsif($feedb->{message}){
print $q->div({-id=>'retm'},"$feedb->{message} $debug"),"\n";
}elsif($feedb->{u_rows}){
print $q->div({-id=>'retm'},"$feedb->{u_rows} $node_meta->{node_name} aktualisiert $debug"),"\n";
}
}
return $return;
}
1;

View file

@ -312,7 +312,7 @@ sub selector_class(){
push @selopt, "<option style='$des_style' value='$id'>$value</option>\n";
}
}
my $selret = "<select class='$class' style='$style' name='$column'>@selopt</select>\n";
my $selret = "<select class='$class' style='background-color:white;' name='$column'>@selopt</select>\n";
return $selret;
}

View file

@ -277,6 +277,7 @@ sub channel_map(){
my $self = shift;
my $channel = {
169 => "sig connector",
172 => "cron timeout",
173 => "merchant fallback",#mig
175 => "example App",#mig
176 => "Mein konrad App",#mig
@ -532,13 +533,12 @@ sub select_worktime {
sub collect_contentpos(){
my $self = shift;
my $dbh = shift || $dbh_intern;
my ($table,$c_id) = @_;
my $tb = "contenttrans";
my $tbpos = "contenttranspos";
my $where = "where ctt.c_id=pos.ct_id and ctt.c_id='$c_id'";
my $table = shift;
my $ct_id = shift || "";
my $where = "where ctt.c_id=pos.ct_id and ctt.c_id='$ct_id'";
if($c_id){
my $sth = $dbh->prepare("SELECT pos.* FROM $tbpos pos, $tb ctt $where");
if($ct_id){
my $sth = $dbh->prepare("SELECT pos.* FROM contenttranspos pos, contenttrans ctt $where");
my $rc = $sth->execute();
my $cpos = $sth->fetchall_hashref("c_id");
my $rows = $sth->rows;
@ -633,21 +633,20 @@ sub collect_post(){
}
}
my $sth;
my $sql;
my $sth = "";
my $sql = "";
my $limit = "";
$limit = "LIMIT $count" if(looks_like_number($count));
if($fetch->{catch} && $fetch->{catch} eq "content_contentpos"){
$sql = "SELECT cp.* from $fetch->{table_pos} cp, $fetch->{table} ct where $ctcp_where and $cp_where and $ct_where order by cp.mtime DESC $limit";
$sth = $dbh->prepare($sql);
#+3
}else{
#adapated from search_content3 to get Category-Menue
$sql = "SELECT cp.* FROM $fetch->{table_pos} cp WHERE $cp_where and $poscid IN (SELECT ct.c_id FROM relation rel, $fetch->{table} ct WHERE rel.content_id=ct.c_id and $ct_where) order by cp.mtime ASC";#mtime aufsteigend get last (newest) entry
#rental pos with capture booking ct.state
$sql = "SELECT cp.*, ct.state FROM $fetch->{table_pos} cp, $fetch->{table} ct WHERE $cp_where and $poscid IN (SELECT ct.c_id FROM relation rel, $fetch->{table} ct WHERE rel.content_id=ct.c_id and $ct_where) order by cp.mtime ASC";#mtime aufsteigend get last (newest) entry
$sth = $dbh->prepare($sql);
}
my $rc = $sth->execute();
$bw->log("DBtank collect_post $source",$sql,"") if($debug);
my $rc = $sth->execute();
my $record = { c_id => 0 };
if($fetch->{fetch} eq "all" && $fetch->{keyfield}){

View file

@ -380,6 +380,10 @@ sub handler {
$return = "failure::Abbruch. Schreibender Zugriff \"Faktura\" verweigert.";
}
}
if($node_meta->{ct_table} eq "contenttranspos" && $R::base_edit eq "save_pos"){
$return = $pl->save_contenttranspos($R::c_id,$users_dms->{u_id});
}
$users_dms = $dbt->select_users($dbh,$users_dms->{u_id},"");#just to get update after save
#none DMS hosts ----------------------------------------------------
@ -656,7 +660,6 @@ sub handler {
###
}
my $nodev = $db->get_node("$view_post","$lang");
#Printpreview
if($view =~ /Printpreview/){
require "Mod/Printpreview.pm";
@ -669,13 +672,6 @@ sub handler {
exit 0;
}
#else global REDIRECT. Availability check for redirect
#elsif(!$nodev->{main_id} || ($nodev->{main_id} == 100 && $R::rel_edit eq "save_content")){
#print redirect("$varenv{wwwhost}$session");
#exit 0;
#}
#CSVout
if($R::rel_edit && $R::rel_edit =~ /XLSout/){
$users_dms = $dbt->select_users($dbh,$users_dms->{u_id});
@ -737,6 +733,7 @@ sub handler {
\$( '#datepicker1' ).datepicker({ dateFormat: 'dd.mm.yy', dayNamesMin: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'], monthNames: ['Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember']});
\$( '#datepicker2' ).datepicker({ dateFormat: 'dd.mm.yy', dayNamesMin: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'], monthNames: ['Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember']});
\$( '#datepicker3' ).datepicker({ dateFormat: 'dd.mm.yy', dayNamesMin: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'], monthNames: ['Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember']});
\$( '#datepicker4' ).datepicker({ dateFormat: 'dd.mm.yy', dayNamesMin: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'], monthNames: ['Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember']});
});";
}

View file

@ -44,6 +44,7 @@ sub mobox3(){
$title = "Kunden Editor" if($node_meta->{ct_table} eq "contentadr");
$title = "DMS-Account Zugriffsberechtigung" if($node_meta->{ct_table} eq "users");
$title = "Service Editor" if($node_meta->{ct_table} eq "contentpos");
$title = "Rental Editor" if($node_meta->{ct_table} eq "contenttranspos");
my $height = $node_meta->{tpl_height} || "990";
my $width = $node_meta->{tpl_width} || "990";

View file

@ -13,6 +13,8 @@ use File::Path qw(make_path remove_tree);
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);
use Scalar::Util qw(looks_like_number);
use DateTime;
use DateTime::Format::Pg;
use Lib::Config;
use Mod::Libenzdb;
@ -20,6 +22,7 @@ use Mod::Libenz;
use Mod::DBtank;
use Mod::Basework;
use Mod::APIfunc;
use Mod::Pricing;
use Data::Dumper;
my $cf = new Config;
@ -28,6 +31,7 @@ my $lb = new Libenz;
my $dbt = new DBtank;
my $bw = new Basework;
my $apif = new APIfunc;
my $pri = new Pricing;
my $q = new CGI;
sub new {
@ -46,6 +50,151 @@ my %varenv = $cf->envonline();
my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
my $debug=1;
sub save_contenttranspos {
my $self = shift;
my $c_id = shift;
my $owner = shift;
my $dbh = "";
my $feedb = { message => "" };
if($c_id && $R::start_date =~ /\d{1,2}\.\d{1,2}\.\d{4}/ && $R::end_date =~ /\d{1,2}\.\d{1,2}\.\d{4}/){
my $s_hh = $q->escapeHTML("$R::s_hh") || "0";
my $s_mi = $q->escapeHTML("$R::s_mi") || "0";
my $e_hh = $q->escapeHTML("$R::e_hh") || "0";
my $e_mi = $q->escapeHTML("$R::e_mi") || "0";
$s_hh = "24" if($s_hh > "24");
$e_hh = "24" if($e_hh > "24");
$s_mi = "59" if($s_mi > "59");
$e_mi = "59" if($e_mi > "59");
$s_hh = sprintf('%.2d',$s_hh);
$e_hh = sprintf('%.2d',$e_hh);
$s_mi = sprintf('%.2d',$s_mi);
$e_mi = sprintf('%.2d',$e_mi);
my $start_time="";
my $end_time="";
my $dtnow = DateTime->now( time_zone => "Europe/Berlin" );
my $dt0 = DateTime->now( time_zone => "Europe/Berlin" );
my $dt1 = DateTime->now( time_zone => "Europe/Berlin" );
if($R::start_date =~ /(\d{1,2})\.(\d{1,2})\.(\d{4})/){
$dt0 = DateTime->new(
year => $3,
month => $2,
day => $1,
hour => $s_hh,
minute => $s_mi,
time_zone => 'Europe/Berlin',
);
$start_time = $dt0->strftime("%Y-%m-%d %H:%M:%S");
#print $start_time;
}
if($R::end_date =~ /(\d{1,2})\.(\d{1,2})\.(\d{4})/){
$dt1 = DateTime->new(
year => $3,
month => $2,
day => $1,
hour => $e_hh,
minute => $e_mi,
time_zone => 'Europe/Berlin',
);
$end_time = $dt1->strftime("%Y-%m-%d %H:%M:%S");
}
if($c_id && $start_time && $end_time && $dt0 < $dtnow && $dt1 < $dtnow){
my $pref = {
table => "contenttrans",
table_pos => "contenttranspos",
fetch => "one",
template_id => "218",#Mietjournal tpl_id
c_id => $c_id,
"ct.close_time" => "is::null",
};
my $record_pos = {};
$record_pos = $dbt->collect_post($dbh,$pref);
my $pricing = {};
my $counting = {};
my $update_pos = {
table => "contenttranspos",
start_time => "$start_time",
end_time => "$end_time",
owner_end => $owner,
mtime => "now()",
};
$u_rows += $dbt->update_record($dbh,$update_pos,$record_pos);
#again to get setted date-times
$record_pos = $dbt->collect_post($dbh,$pref);
($pricing,$counting) = $pri->counting_rental(\%varenv,$record_pos,"calc_price");
$update_pos->{int38} = "$counting->{int38}" if(looks_like_number($counting->{int38}));
$update_pos->{int39} = "$counting->{int39}" if(looks_like_number($counting->{int39}));
$update_pos->{int40} = "$counting->{int40}" if(looks_like_number($counting->{int40}));
$update_pos->{int41} = "$counting->{int41}" if(looks_like_number($counting->{int41}));
$update_pos->{int10} = $R::int10 if(looks_like_number($R::int10));
$update_pos->{int20} = $R::int20 if(looks_like_number($R::int20));
$update_pos->{int04} = $R::int04 if(looks_like_number($R::int04));
#before update bike content check if realy last rental
my $pref2ck = {
table => "contenttrans",
table_pos => "contenttranspos",
fetch => "one",
template_id => "218",#Mietjournal tpl_id
start_time => ">::$end_time",
"ct.close_time" => "is::null",
};
my $record_pos2ck = { c_id => 0 };
$record_pos2ck = $dbt->collect_post($dbh,$pref2ck);
#update bike content only if there is no later rental start
if($record_pos->{cc_id} && !$record_pos2ck->{c_id}){
my $ctpref = {
table => "content",
fetch => "one",
c_id => $record_pos->{cc_id},
};
my $ctbike = $dbt->fetch_tablerecord($dbh,$ctpref);
$ctpref->{int10} = $R::int10 if(looks_like_number($R::int10));
$ctpref->{int20} = $R::int20 if(looks_like_number($R::int20));
$ctpref->{int04} = $R::int04 if(looks_like_number($R::int04));
$ctpref->{owner} = $owner;
$ctpref->{mtime} = "now()";
$u_rows += $dbt->update_record($dbh,$ctpref,$ctbike);
$feedb->{message} = "Mietdaten gespeichert und Mietrad Stati in Warenstamm übernommen";
}else{
$feedb->{message} = "Mietdaten gespeichert. Achtung, Mietrad Stati in Warenstamm NICHT übernommen, da es sich nicht um die letzte Miete handelt";
}
$u_rows += $dbt->update_record($dbh,$update_pos,$record_pos);
#
if($record_pos->{ct_id}){
my $ctpref = {
table => "contenttrans",
c_id => $record_pos->{ct_id},
start_time => "$start_time",
end_time => "$end_time",
owner => $owner,
mtime => "now()",
};
$u_rows += $dbt->update_record($dbh,$ctpref,$ctpref);
}
}
}else{
$feedb->{message} = "failure::Fehler, falsche Zeitangaben oder Datensatz nicht gefunden!";
}
$feedb->{u_rows} = $u_rows;
return $feedb;
}#end save_contenttranspos
#set Faktura workflow like Rechnung to Storno
sub set_workflow {
@ -440,6 +589,7 @@ sub set_usertarif {
if(@new_txt30){
print FILE "-3-> txt30: @new_txt30\n" if($debug);
$u_rows = $dbt->update_one($dbh_operator,$adr_bonus,"txt30='@new_txt30'");
$u_rows = $dbt->update_one($dbh_operator,$adr_bonus,"txt15='$adr_bonus->{txt15}'");
}
$ret = "failure::txt30#top2" if(!$adr_bonus->{txt30_array} || $adr_bonus->{txt30_array} !~ /\d/);
}

View file

@ -363,7 +363,7 @@ sub preinit(){
($pricing,$counting) = $pri->counting_rental(\%varenv,$record_pos,"calc_price");
#int03 only used for tarif counting backwards compatibility
$update_pos->{int03} = "$pricing->{computed_hours}" if(looks_like_number($pricing->{computed_hours}));
#$update_pos->{int03} = "$pricing->{computed_hours}" if(looks_like_number($pricing->{computed_hours}));
$update_pos->{int38} = "$counting->{int38}" if(looks_like_number($counting->{int38}));
$update_pos->{int39} = "$counting->{int39}" if(looks_like_number($counting->{int39}));
$update_pos->{int40} = "$counting->{int40}" if(looks_like_number($counting->{int40}));

View file

@ -62,7 +62,7 @@ sub only_first_free(){
int10 => "IN::('1','6')",
"ct.close_time" => "is::null",
};
$pref = { %$pref, time_range => "start_time >= '$ctpos->{start_time}' and start_time < '$ctpos->{end_time}' and start_time != end_time" };
$pref = { %$pref, time_range => "cp.start_time >= '$ctpos->{start_time}' and cp.start_time < '$ctpos->{end_time}' and cp.start_time != cp.end_time" };
my $record = $dbt->collect_post($dbh,$pref);
return $record;

View file

@ -269,7 +269,8 @@ sub save_account(){
$valxx = "KN-$valappend";
print FILE "Prepare SWK Bonusnr by prefix $valxx" . "\n" if($debug);
}
if($valxx && ($valxx =~ /^(\w{2,3})-(\w+)/ || $valxx =~ /^(\w{2,3})(\d+)/)){
#Freischaltcode format can be "CA-Li-hsze789k" or "CA1234567"
if($valxx && ($valxx =~ /^(\w{2,3})-([\w\-]+)/i || $valxx =~ /^(\w{2,3})(\d+)/)){
$valxx =~ s/\s//g;
my $bonus_prefix = uc($1),
my $bonusnr = $2;