From 9026241a244aa3477cf5f60523aacc665caf9d5d Mon Sep 17 00:00:00 2001 From: ragu Date: Fri, 24 Jun 2022 14:38:22 +0200 Subject: [PATCH] sig copri available --- copri4/main/src/Mod/APIjsonserver.pm | 5 +-- copri4/main/src/Mod/APIsigclient.pm | 11 +++--- copri4/main/src/Mod/DBtank.pm | 4 +-- copri4/main/src/Mod/Prelib.pm | 47 +++++++++++++++++------- copri4/main/src/Tpl/Liste3.pm | 53 +++++++++++++++++----------- 5 files changed, 75 insertions(+), 45 deletions(-) diff --git a/copri4/main/src/Mod/APIjsonserver.pm b/copri4/main/src/Mod/APIjsonserver.pm index 651018c..7312211 100755 --- a/copri4/main/src/Mod/APIjsonserver.pm +++ b/copri4/main/src/Mod/APIjsonserver.pm @@ -257,8 +257,7 @@ elsif($q->param('request') eq "booking_request"){ my $sig_book = { bikeId => "", rentalId => "", - reservationId => "" - }; + }; if($ct_bike->{barcode} && $ct_tariff->{barcode}){ #sig reservation. not mandatory, disabled because sig seems to get confused @@ -291,7 +290,6 @@ elsif($q->param('request') eq "booking_request"){ $ctpos = $dbt->fetch_tablerecord($dbh,$booking_pos); #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,"rental",$authraw,$ct_bike,$ctpos); #we have to use $ct_bike->{txt22} because we doesn't using sig reserve in this case system("$varenv{basedir}/src/scripts/sig_client.pl '$varenv{syshost}' 'rental' '$authraw->{c_id}' '$ct_bike->{txt22}' '$ctpos->{c_id}' &"); @@ -358,7 +356,6 @@ elsif($q->param('request') eq "booking_cancel" || $q->param('request') eq "booki my $sig_book = { bikeId => $ctpos->{txt22}, rentalId => $ctpos->{txt11}, - reservationId => "" }; if($q->param('request') eq "booking_update" && $q->param('state') && $q->param('state') =~ /canceled/){ diff --git a/copri4/main/src/Mod/APIsigclient.pm b/copri4/main/src/Mod/APIsigclient.pm index 2213f2d..1cdea92 100755 --- a/copri4/main/src/Mod/APIsigclient.pm +++ b/copri4/main/src/Mod/APIsigclient.pm @@ -27,7 +27,6 @@ use Lib::Config; use Mod::DBtank; use Mod::Basework; use Mod::APIfunc; -use Mod::Shareework; use Data::Dumper; my $q = new CGI; @@ -35,7 +34,6 @@ my $json = JSON->new->allow_nonref; my $cf = new Config; my $dbt = new DBtank; my $apif = new APIfunc; -my $tk = new Shareework; my $bw = new Basework; sub new { @@ -83,7 +81,7 @@ sub sig_available { my $td_template = $dbt->rental_description_template(); open(FILE,">>$varenv->{logdir}/APIsigclient.log"); - print FILE "\n0. *** $now_dt 'sig_available' \n"; + print FILE "\n0. *** $now_dt 'sig_available' ctadr: $ctadr->{c_id}\n"; #my $endpoint = "https://sigo.dev.sigo.green/api/v1/bikes"; my $endpoint = "$dbt->{operator}->{$varenv->{dbname}}->{endpoint}/bikes"; @@ -99,7 +97,7 @@ sub sig_available { if(ref($response_in) eq "HASH"){ foreach my $resp (@{ $response_in->{items} }) { - print FILE "response_in loop\n" . Dumper($resp) . "\n"; + print FILE "response_in loop $dbt->{operator}->{$varenv->{dbname}}->{operatorApp}\n" . $q->param('request') . "\n" . Dumper($resp) . "\n"; if(ref($resp->{site}) eq "HASH" && $dbt->{operator}->{$varenv->{dbname}}->{operatorApp} && $q->param('request') eq "stations_available"){ @@ -151,8 +149,7 @@ sub sig_available { $return2copri->{$station}->{int10} = $key; } } - #TODO, disabled for workaround to see what happens. 22.06.2022 - #delete $response_out->{$station} if(uc($resp->{site}->{status}) ne "ACTIVE" || !$resp->{site}->{lat} || !$resp->{site}->{lon}); + delete $response_out->{$station} if(uc($resp->{site}->{status}) ne "ACTIVE" || !$resp->{site}->{lat} || !$resp->{site}->{lon}); } }#end stations_available @@ -165,6 +162,7 @@ sub sig_available { $bike_id =~ s/S[1-9]X/SX/; $bike_id = $1 if($bike_id =~ /(\d+)/); + print FILE "bike_group $bike_id | $resp->{site}->{id} | @{$bike_group}[0]\n"; if($bike && looks_like_number($bike_id) && looks_like_number($resp->{site}->{id}) && ref($bike_group) eq "ARRAY" && @{$bike_group}[0]){ print FILE "Bike: $bike\n"; $response_out->{$bike}->{bike} = "$bike"; @@ -441,7 +439,6 @@ sub sig_booking { $sig_book = { bikeId => "", rentalId => "", - reservationId => "" }; print FILE "<--- $now_dt failure sig_booking sig_post $todo , reset sig_book hash to empty\n"; } diff --git a/copri4/main/src/Mod/DBtank.pm b/copri4/main/src/Mod/DBtank.pm index 8c322f0..bea554c 100755 --- a/copri4/main/src/Mod/DBtank.pm +++ b/copri4/main/src/Mod/DBtank.pm @@ -278,7 +278,7 @@ sub channel_map(){ my $channel = { 167 => "sig cmd", 168 => "shareeio", - 169 => "sig connector", + 169 => "sigo connector", 172 => "reserve timeout", #173 => "merchant fallback",#mig #175 => "example App",#mig @@ -1375,7 +1375,7 @@ sub insert_pos(){ my $sth; #Verleihräder 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,int02,int03,int06,int04,txt05,txt06,txt07,int10,int12,int13,owner,int07,txt04,int09,int17,int15,int16,int11,int18,int19,txt17,txt18,int20,int25,int34,txt22,txt10,txt11,int35,int36,int37,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','$unit_price','$menge','$station','$station','$ct->{txt06}','$ct->{txt06}','$ct->{txt07}','$status','$from_main_id','$deviceId','$owner','$rabatt','$tariff_desc','$tariff_nr','$daymax_price','$abo_price','$free_hours','$ct->{int11}','$sharing_type','$bike_charge','$ct->{txt17}','$ct->{txt18}','$ct->{int20}','$trackon','$staff','$sig_book->{bikeId}','$sig_book->{reservationId}','$sig_book->{rentalId}','$unit_price1','$unit_price2','$start_price','$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,int02,int03,int06,int04,txt05,txt06,txt07,int10,int12,int13,owner,int07,txt04,int09,int17,int15,int16,int11,int18,int19,txt17,txt18,int20,int25,int34,txt22,txt11,int35,int36,int37,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','$unit_price','$menge','$station','$station','$ct->{txt06}','$ct->{txt06}','$ct->{txt07}','$status','$from_main_id','$deviceId','$owner','$rabatt','$tariff_desc','$tariff_nr','$daymax_price','$abo_price','$free_hours','$ct->{int11}','$sharing_type','$bike_charge','$ct->{txt17}','$ct->{txt18}','$ct->{int20}','$trackon','$staff','$sig_book->{bikeId}','$sig_book->{rentalId}','$unit_price1','$unit_price2','$start_price','$unit_time','$free_time') RETURNING c_id"); }else{ $sth = $dbh->prepare("INSERT INTO contenttranspos (ct_id,cc_id,ca_id,ct_name,barcode,txt08,txt09,itime,int02,int03,txt01,txt06,txt07,int10,int12,owner) VALUES ('$ctt_id','$ct->{c_id}','$ctadr->{c_id}','$ct_name','0','$user_name','$ctadr->{txt09}',now(),'$unit_price','1','$ct->{txt01}','$ct->{txt06}','$ct->{txt07}','0','$from_main_id','$owner') RETURNING c_id"); } diff --git a/copri4/main/src/Mod/Prelib.pm b/copri4/main/src/Mod/Prelib.pm index 3ea5922..beef0c3 100755 --- a/copri4/main/src/Mod/Prelib.pm +++ b/copri4/main/src/Mod/Prelib.pm @@ -23,6 +23,7 @@ use Mod::DBtank; use Mod::Basework; use Mod::APIfunc; use Mod::Pricing; +use Mod::APIsigclient; use Data::Dumper; my $cf = new Config; @@ -32,6 +33,7 @@ my $dbt = new DBtank; my $bw = new Basework; my $apif = new APIfunc; my $pri = new Pricing; +my $si = new APIsigclient; my $q = new CGI; sub new { @@ -113,8 +115,8 @@ sub save_contenttranspos { "ct.close_time" => "is::null", }; - my $record_pos = {}; - $record_pos = $dbt->collect_post($dbh,$pref); + my $ctpos = {}; + $ctpos = $dbt->collect_post($dbh,$pref); my $pricing = {}; my $counting = {}; @@ -125,12 +127,32 @@ sub save_contenttranspos { owner_end => $owner, mtime => "now()", }; - $u_rows += $dbt->update_record($dbh,$update_pos,$record_pos); + #if sig + if($ctpos->{int11} == 3 && $ctpos->{ca_id}){ + #sig booking_request + my $sig_book = { + bikeId => "", + rentalId => "", + }; + if(looks_like_number($R::int10) && $R::int10 == 1){ + my $authref = { + table => "contentadr", + fetch => "one", + template_id => "202", + c_id => "=::$ctpos->{ca_id}", + }; + my $authraw = {}; + $authraw = $dbt->fetch_record($dbh,$authref); + $sig_book = $si->sig_booking(\%varenv,"reserve_end",$authraw,"",$ctpos); + } + }else{ + $u_rows += $dbt->update_record($dbh,$update_pos,$ctpos); + } #again to get setted date-times - $record_pos = $dbt->collect_post($dbh,$pref); + $ctpos = $dbt->collect_post($dbh,$pref); - ($pricing,$counting) = $pri->counting_rental(\%varenv,$record_pos,"calc_price"); + ($pricing,$counting) = $pri->counting_rental(\%varenv,$ctpos,"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})); @@ -153,15 +175,15 @@ sub save_contenttranspos { "ct.close_time" => "is::null", }; - my $record_pos2ck = { c_id => 0 }; - $record_pos2ck = $dbt->collect_post($dbh,$pref2ck); + my $ctpos2ck = { c_id => 0 }; + $ctpos2ck = $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}){ + if($ctpos->{cc_id} && !$ctpos2ck->{c_id}){ my $ctpref = { table => "content", fetch => "one", - c_id => $record_pos->{cc_id}, + c_id => $ctpos->{cc_id}, }; my $ctbike = $dbt->fetch_tablerecord($dbh,$ctpref); @@ -171,19 +193,20 @@ sub save_contenttranspos { $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); + $u_rows += $dbt->update_record($dbh,$update_pos,$ctpos); # - if($record_pos->{ct_id}){ + if($ctpos->{ct_id}){ my $ctpref = { table => "contenttrans", - c_id => $record_pos->{ct_id}, + c_id => $ctpos->{ct_id}, start_time => "$start_time", end_time => "$end_time", owner => $owner, diff --git a/copri4/main/src/Tpl/Liste3.pm b/copri4/main/src/Tpl/Liste3.pm index a816ef0..278b059 100755 --- a/copri4/main/src/Tpl/Liste3.pm +++ b/copri4/main/src/Tpl/Liste3.pm @@ -25,6 +25,9 @@ use Scalar::Util qw(looks_like_number); use Storable; use Mod::APIfunc; use Mod::Pricing; +use Mod::Shareework; +use Mod::APIsigclient; +use Mod::Basework; use Data::Dumper; sub new { @@ -50,6 +53,9 @@ sub tpl(){ my $dbt = new DBtank; my $apif = new APIfunc; my $pri = new Pricing; + my $tk = new Shareework; + my $si = new APIsigclient; + my $bw = new Basework; my %varenv = $cf->envonline(); my $script = $q->script_name(); @@ -423,7 +429,7 @@ sub tpl(){ elsif(!$start_chck && !$end_chck){ #2020-12-01 changed to get last tablecontent, not only 1 by edit #testing state - #if(!$start_chck && !$end_chck){ + #if(!$start_chck && !$end_chck) $rows = $db->count_content($table,"$main_ids","$tplids"); #collect search keys @@ -465,8 +471,23 @@ sub tpl(){ $ct_ids .= "$ct4rel_parts->{$cp_id}->{ct_id}," if($R::detail_search && ($R::s_kontext && $R::s_kontext eq "Waren" || $export eq "FiBu")); } } - - $ct4rel = $db->search_content3($searchref,$table,$dbt->{shareedms_conf}->{parent_id},$node_meta,$users_dms->{u_id},$lang,"$main_ids","$tplids","$ct_ids",$v_journal,$time,$R::s_kontext,$scol,$users_dms->{sort_updown},$offset,$limit,$export,$R::todo,$ck4ex,$opos); + + #reload sig bikes and stations states + #$bw->log("Liste3 condition",$node_meta,""); + if($varenv{syshost} eq "shareedms-sx"){ + my $ctadr = { c_id => $users_dms->{u_id} }; + if($node_meta->{tpl_id} == 205 || $node_meta->{node_name} eq "Waren"){ + $q->param(-name=>'request',-value=>"bikes_available"); + (my $response->{bikes},my $return2copri->{bikes}) = $si->sig_available($q,\%varenv,$ctadr); + #$bw->log("return2copri",$return2copri->{bikes},""); + $tk->sigbike_cupdate($return2copri->{bikes}); + }elsif($node_meta->{tpl_id} == 225){ + $q->param(-name=>'request',-value=>"stations_available"); + (my $response->{stations},my $return2copri->{stations}) = $si->sig_available($q,\%varenv,$ctadr); + $tk->sigbike_cupdate($return2copri->{stations}); + } + } + $ct4rel = $db->search_content3($searchref,$table,$dbt->{shareedms_conf}->{parent_id},$node_meta,$users_dms->{u_id},$lang,"$main_ids","$tplids","$ct_ids",$v_journal,$time,$R::s_kontext,$scol,$users_dms->{sort_updown},$offset,$limit,$export,$R::todo,$ck4ex,$opos); }#end $ct4rel collect }else{ $return = "failure::Abbruch. Keine Zugriffsberechtigung"; @@ -693,6 +714,8 @@ sub tpl(){ my $set_style4nr = ""; my $sum_error = 0; my $ecol=0; + my $lock_system = 2;#defaults to Ilockit + $lock_system = $ct4rel->{$id}->{int11} if($ct4rel->{$id}->{int11}); # check sum_pos and sum_buchen my $sum_pos = 0; @@ -928,11 +951,7 @@ sub tpl(){ if($table =~ /contenttrans|contenttver/){ print $q->td({-class=>'tdint',-style=>"font-weight:normal;$set_style4nr"},$q->a({-class=>"linknav3",-href=>"?ct_trans=open\&mode=manager\&c_id4trans=$ct4rel->{$id}->{c_id}\&tpl_id4trans=$ct4rel->{$id}->{template_id}\&kind_of_trans=$node_meta->{node_name}\&owner=$users_dms->{u_id}\&offset=$offset\&limit=$limit",-title=>"Terminal öffnen"},"$ct4rel->{$id}->{$key}")); }elsif($table =~ /content$|contentadr|contentnel/){ - if($varenv{wwwhost} =~ /regiox/ && $key =~ /ct_name/){ - print $q->td({-class=>"tdtxt",-style=>"font-weight:normal;$set_style4nr"},"$ct4rel->{$id}->{$key}"); - }else{ print $q->td({-class=>"tdint",-style=>"font-weight:normal;$set_style4nr"},$q->a({-class=>"linknav3",-href=>"?node2edit=editpart\&mode=manager\&rel_id=$ct4rel->{$id}->{rel_id}\&offset=$offset\&limit=$limit",-title=>"Terminal öffnen"},"$ct4rel->{$id}->{$key}")),"\n"; - } }elsif(($node_meta->{tpl_order} !~ /barcode/) || ("$ct4rel->{$id}->{$key}" ne "$ct4rel->{$id}->{barcode}")){ print $q->td({-class=>'tdint',-style=>"font-weight:bold;$set_style4nr"},"$ct4rel->{$id}->{$key}"),"\n"; }else{ @@ -941,15 +960,15 @@ sub tpl(){ }elsif($key =~ /txt01/ && $table =~ /contenttrans|contenttver/){ print $q->td({-class=>'tdtxt',-style=>"font-weight:normal;$set_style4nr"},$q->a({-class=>"linknav3",-href=>"?ct_trans=open\&mode=manager\&c_id4trans=$ct4rel->{$id}->{c_id}\&tpl_id4trans=$ct4rel->{$id}->{template_id}\&kind_of_trans=$node_meta->{node_name}\&owner=$users_dms->{u_id}\&offset=$offset\&limit=$limit",-title=>"Terminal öffnen"},"$ct4rel->{$id}->{$key}")),"\n"; - }elsif($key =~ /txt01/ && $table =~ /content$|contentadr/){ + }elsif($key =~ /txt01/ && $table =~ /content$|contentadr/ && $lock_system != 3){ my $txt01 = "---"; $txt01 = "$ct4rel->{$id}->{$key}" if($ct4rel->{$id}->{$key}); print $q->td({-class=>'tdtxt',-style=>"font-weight:normal;$set_style4nr"},$q->a({-class=>"linknav3",-href=>"?node2edit=editpart\&mode=manager\&rel_id=$ct4rel->{$id}->{rel_id}\&offset=$offset\&limit=$limit",-title=>"Terminal öffnen"},"$txt01")),"\n"; - }elsif($key =~ /barcode/ && $table =~ /content$|contentadr/ && $ct4rel->{$id}->{template_id} != 225){ + }elsif($key =~ /barcode/ && $table =~ /content$|contentadr/ && $ct4rel->{$id}->{template_id} != 225 && $lock_system != 3){ print $q->td({-class=>'tdint',-style=>"font-weight:normal;$set_style4nr"},$q->a({-class=>"linknav3",-href=>"?node2edit=editpart\&mode=manager\&rel_id=$ct4rel->{$id}->{rel_id}\&offset=$offset\&limit=$limit",-title=>"Terminal öffnen"},"$ct4rel->{$id}->{$key}")),"\n"; - }elsif($key =~ /int04/ && $table eq "content" && $ct4rel->{$id}->{template_id} == 225){ + }elsif($key =~ /int04/ && $table eq "content" && $ct4rel->{$id}->{template_id} == 225 && $lock_system != 3){ print $q->td({-class=>'tdint',-style=>"font-weight:normal;$set_style4nr"},$q->a({-class=>"linknav3",-href=>"?node2edit=editpart\&mode=manager\&rel_id=$ct4rel->{$id}->{rel_id}\&offset=$offset\&limit=$limit",-title=>"Terminal öffnen"},"$ct4rel->{$id}->{$key}")),"\n"; - }elsif($key =~ /int04/ && $table eq "content" && $ct4rel->{$id}->{template_id} == 205){ + }elsif($key =~ /int04/ && $table eq "content" && $ct4rel->{$id}->{template_id} == 205 && $lock_system != 3){ print $q->td({-class=>'tdint',-style=>"font-weight:normal;"},$q->a({-class=>"linknav3",-style=>"",-href=>"?detail_search=1&s_int04=$ct4rel->{$id}->{$key}",-title=>"Rad Warenstamm nach Station filtern"},"$ct4rel->{$id}->{$key}")); }elsif($key =~ /date_time/){ $ct4rel->{$id}->{start_time} = $lb->time4de($ct4rel->{$id}->{start_time},"1") if($ct4rel->{$id}->{start_time}); @@ -1011,16 +1030,10 @@ sub tpl(){ print $q->td({-class=>'tdtxt',-style=>"$txtstyle $set_style"},"$bonustarif"),"\n"; - }elsif($key =~ /int|save|time$|sort|public/){ - if($key eq "int06" && $ct4rel->{$id}->{int06}){ - $ct4rel->{$id}->{int06} =~ s/,.*//; - } + #for all other withot matching integer type condition + }elsif($key =~ /int|barcode|save|time$|sort|public/){ + print $q->td({-class=>'tdint',-style=>"$txtstyle $set_style"},"$ct4rel->{$id}->{$key}"),"\n"; - #if($colorize && $ct4rel->{$id}->{$key} == 1){ - # print $q->td({-class=>'tdicon',-style=>"$txtstyle $set_style color:$colorize;"},"•"),"\n"; - #}else{ - print $q->td({-class=>'tdint',-style=>"$txtstyle $set_style"},"$ct4rel->{$id}->{$key}"),"\n"; - #} }elsif($key =~ /txt01/ && $v_journal){ my $txt01 = "$ct4rel->{$id}->{$key}"; $txt01 = "$txt01" if($ct4rel->{$id}->{state} eq "Kassenbestand");